Skip to content
Snippets Groups Projects
Commit 9d732aad authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

First, working version...

Usage:
php ./update.php host example.com
parent a86a7303
No related branches found
No related tags found
No related merge requests found
config.php
<?php
$soap_location = 'https://ispconfig.example.com:8080/remote/index.php';
$soap_uri = 'https://ispconfig.example.com:8080/remote/';
$soap_user = 'username';
$soap_password = 'password';
<?php
require('config.php');
if ($argc<3) {
print "Usage: php ./update.php HOST DOMAIN [IP]\n";
print "If not given, the ip address will be queried from icanhazip.com\n";
die();
}
$ddns_host = $argv[1];
$domain = $argv[2];
if ($argc>3) {
$ip = $argv[3];
} else {
// Figure out the public IP of this host:
$ip = trim(file_get_contents("http://icanhazip.com/"));
if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
die("Unable to retrieve public IP address (icanhazip.com returned $ip)\n");
}
}
// print("Setting DDNS host $ddns_host.$domain to IP $ip\n");
$client = new SoapClient(null,
array('location' => $soap_location,
'uri' => $soap_uri,
'trace' => 1,
'exceptions' => 1));
try {
$session_id = $client->login($soap_user, $soap_password);
$zone_id = $client->dns_zone_get_id($session_id, $domain);
$zone = $client->dns_zone_get($session_id, $zone_id);
$records = $client->dns_rr_get_all_by_zone($session_id, $zone_id);
$dns_record = null;
foreach ($records as $rec) {
if ($rec['type']=='A' && $rec['name']==$ddns_host) {
$dns_record = $rec;
}
}
if (is_null($dns_record)) {
$client->logout($session_id);
die("Unable to find DNS record for host $ddns_host in domain $domain on the server...\n");
}
if ($dns_record['data'] != $ip) {
$dns_record['data'] = $ip;
$dns_record['serial'] = $dns_record['serial']+1;
$client->dns_a_update($session_id, null, $dns_record['id'], $dns_record);
$zone['serial'] = $zone['serial'] + 1;
$client->dns_zone_update($session_id, 0, $zone_id, $zone);
print("Successfully set DNS entry for host $ddns_host in domain $domain to $ip.\n");
} else {
// print("IP address of $ddns_host.$domain already set to $ip.\n");
}
$client->logout($session_id);
} catch (SoapFault $e) {
die('SOAP Error: '.$e->getMessage()."\n");
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment