|
|
@ -46,104 +46,178 @@ use LWP::UserAgent; |
|
|
|
use HTTP::Request; |
|
|
|
|
|
|
|
our $api_url = "https://pddimp.yandex.ru/api2/admin"; |
|
|
|
our $query_options = Load(<<EOYAML |
|
|
|
our $api_requests = Load(<<EOYAML |
|
|
|
--- |
|
|
|
default_content_type: 'application/x-www-form-urlencoded' |
|
|
|
deputy: |
|
|
|
list: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
add: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, login] |
|
|
|
delete: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, login] |
|
|
|
|
|
|
|
dkim: |
|
|
|
status: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
disable: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
enable: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
|
|
|
|
dns: |
|
|
|
list: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
add: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, type, content] |
|
|
|
del: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, record_id] |
|
|
|
edit: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, record_id] |
|
|
|
|
|
|
|
domain: |
|
|
|
details: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
domains: |
|
|
|
query_type: 'GET' |
|
|
|
registration_status: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
delete: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
register: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
|
|
|
|
logo: |
|
|
|
check: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
del: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
set: |
|
|
|
content_type: 'multipart/form-data' |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, file] |
|
|
|
|
|
|
|
settings: |
|
|
|
set_country: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, country] |
|
|
|
|
|
|
|
email: |
|
|
|
counters: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain, login] |
|
|
|
list: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
add: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, login, password] |
|
|
|
del: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, login] |
|
|
|
edit: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, login] |
|
|
|
get_oauth_token: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, login] |
|
|
|
|
|
|
|
ml: |
|
|
|
list: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
subscribers: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain, maillist] |
|
|
|
add: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, maillist] |
|
|
|
del: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, maillist] |
|
|
|
get_can_send_on_behalf: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, maillist, subscriber] |
|
|
|
set_can_send_on_behalf: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, maillist, subscriber, can_send_on_behalf] |
|
|
|
subscribe: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, maillist, subscriber] |
|
|
|
unsubscribe: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, maillist, subscriber] |
|
|
|
|
|
|
|
import: |
|
|
|
check_imports: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
check_settings: |
|
|
|
query_type: 'GET' |
|
|
|
parameters: |
|
|
|
required: [domain, server, port, method, ssl] |
|
|
|
start_import_file: |
|
|
|
content_type: 'multipart/form-data' |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, file, server, port, method, ssl] |
|
|
|
start_one_import: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain, server, port, method, ssl, ext-login, ext-password] |
|
|
|
stop_all_imports: |
|
|
|
query_type: 'POST' |
|
|
|
parameters: |
|
|
|
required: [domain] |
|
|
|
EOYAML |
|
|
|
); |
|
|
|
|
|
|
@ -165,51 +239,96 @@ our $task = undef; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach my $check ("domain", "token", "service", "query") { |
|
|
|
# Checking general mandatory parameters of the request |
|
|
|
foreach my $check ("query", "service", "token") { |
|
|
|
if (!defined $task->{$check}) { |
|
|
|
die "'$check' is undefined in '$task_file'\n"; |
|
|
|
die "'" . $check . "' is undefined in '" . $task_file . "'\n"; |
|
|
|
} else { |
|
|
|
if (!ref($task->{$check})) { |
|
|
|
if ($task->{$check} =~ /^-?\d+\.?\d*/) { |
|
|
|
die "Incorrect value of '" . $check . "' in '" . $task_file . "'\n"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
die "Incorrect value of '" . $check . "' in '" . $task_file . "'\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
my $request_url = ""; |
|
|
|
my $request_type = ""; |
|
|
|
my $request_content_type = ""; |
|
|
|
my $service = $task->{service}; |
|
|
|
my $sub_service = $task->{sub_service}; |
|
|
|
my $query = $task->{query}; |
|
|
|
my $options = $task->{options}; |
|
|
|
my $api_request = undef; |
|
|
|
my @check_list; |
|
|
|
|
|
|
|
# Checking mandatory parameters of the request |
|
|
|
if (defined $sub_service) { |
|
|
|
$api_request = $api_requests->{$service}->{$sub_service}->{$query}; |
|
|
|
} else { |
|
|
|
$api_request = $api_requests->{$service}->{$query}; |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
my $service = $task->{service}; |
|
|
|
my $sub_service = $task->{sub_service}; |
|
|
|
my $query = $task->{query}; |
|
|
|
|
|
|
|
$request_url = $api_url . "/" . $service; |
|
|
|
$request_url .= (defined $sub_service) ? "/" . $sub_service : ""; |
|
|
|
$request_url .= "/" . $query; |
|
|
|
if (defined $api_request->{parameters}->{required}) { |
|
|
|
@check_list = @{$api_request->{parameters}->{required}}; |
|
|
|
} |
|
|
|
|
|
|
|
if ( $service eq "import" && $query eq "start_import_file" ) { |
|
|
|
$request_url .= "?domain=" . $task->{domain}; |
|
|
|
foreach my $k (keys %{$task->{options}}) { |
|
|
|
$request_url .= "&" . $k . "=" . $task->{options}->{$k}; |
|
|
|
foreach my $check (@check_list) { |
|
|
|
if (defined $task->{$check}) { |
|
|
|
if (!ref($task->{$check})) { |
|
|
|
if ($task->{$check} =~ /^-?\d+\.?\d*/) { |
|
|
|
die "Incorrect value of '" . $check . "' in '" . $task_file . "'\n"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
die "Incorrect value of '" . $check . "' in '" . $task_file . "'\n"; |
|
|
|
} |
|
|
|
} elsif (defined $options->{$check}) { |
|
|
|
if (!ref($options->{$check})) { |
|
|
|
if ($options->{$check} =~ /^-?\d+\.?\d*/) { |
|
|
|
die "Incorrect value of '" . $check . "' in '" . $task_file . "'\n"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
die "Incorrect value of '" . $check . "' in '" . $task_file . "'\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (defined $sub_service) { |
|
|
|
$request_type = $query_options->{$service}->{$sub_service}->{$query}->{query_type}; |
|
|
|
$request_content_type = $query_options->{$service}->{$sub_service}->{$query}->{content_type}; |
|
|
|
} else { |
|
|
|
$request_type = $query_options->{$service}->{$query}->{query_type}; |
|
|
|
$request_content_type = $query_options->{$service}->{$query}->{content_type}; |
|
|
|
die "'" . $check . "' is undefined in '" . $task_file . "'\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$request_url = $api_url . "/" . $service; |
|
|
|
$request_url .= (defined $sub_service) ? "/" . $sub_service : ""; |
|
|
|
$request_url .= "/" . $query; |
|
|
|
|
|
|
|
if (!defined $request_content_type) { |
|
|
|
$request_content_type = $query_options->{default_content_type}; |
|
|
|
if ( $service eq "import" && $query eq "start_import_file" ) { |
|
|
|
$request_url .= "?domain=" . $task->{domain}; |
|
|
|
foreach my $k (keys %{$task->{options}}) { |
|
|
|
$request_url .= "&" . $k . "=" . $task->{options}->{$k}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (defined $sub_service) { |
|
|
|
$request_type = $api_request->{query_type}; |
|
|
|
$request_content_type = $api_request->{content_type}; |
|
|
|
} else { |
|
|
|
$request_type = $api_request->{query_type}; |
|
|
|
$request_content_type = $api_request->{content_type}; |
|
|
|
} |
|
|
|
|
|
|
|
if (!defined $request_content_type) { |
|
|
|
$request_content_type = $api_requests->{default_content_type}; |
|
|
|
} |
|
|
|
if (!defined $sub_service) { |
|
|
|
$sub_service = ""; |
|
|
|
} |
|
|
|
|
|
|
|
my $ua = new LWP::UserAgent; |
|
|
|
my $request = new HTTP::Request($request_type => $request_url); |
|
|
|
|
|
|
|
if ( $task->{service} eq "domain" && |
|
|
|
$task->{sub_service} eq "logo" && |
|
|
|
$task->{query} eq "set" ) { |
|
|
|
if ( $service eq "domain" && |
|
|
|
$sub_service eq "logo" && |
|
|
|
$query eq "set" ) { |
|
|
|
{ |
|
|
|
my $boundary = 'X'; |
|
|
|
my @rand = ('a'..'z', 'A'..'Z'); |
|
|
@ -266,7 +385,11 @@ if ( $task->{service} eq "domain" && |
|
|
|
'Content-type' => $request_content_type |
|
|
|
); |
|
|
|
|
|
|
|
my $request_content = "domain=" . $task->{domain}; |
|
|
|
my $request_content = ""; |
|
|
|
if (defined $task->{domain}) { |
|
|
|
$request_content = "domain=" . $task->{domain}; |
|
|
|
} |
|
|
|
|
|
|
|
foreach my $k (keys %{$task->{options}}) { |
|
|
|
$request_content .= "&" . $k . "="; |
|
|
|
$request_content .= encode("utf8",$task->{options}->{$k}); |
|
|
|