diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4f4773fb3403f3ec4097ab7c7b1fdec23b9aa924 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.php diff --git a/README.md b/README.md deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/config.php.sample b/config.php.sample new file mode 100644 index 0000000000000000000000000000000000000000..afdfda9e46802092d1ec8c58ddecfd32a9402456 --- /dev/null +++ b/config.php.sample @@ -0,0 +1,6 @@ +<?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'; + diff --git a/update.php b/update.php new file mode 100644 index 0000000000000000000000000000000000000000..b113ec167c11e46a57fc1558063b137e8efa364f --- /dev/null +++ b/update.php @@ -0,0 +1,66 @@ +<?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