/** * Static convienence method which uses this class to implement the DNS * Update API to allow compatible DDNS clients to set GoDaddy DNS records * using HTTP requests. * * See: http://dyn.com/support/developers/api/perform-update/ * http://dyn.com/support/developers/api/return-codes/ */ public static function ddns($defaults = array()) { // Merge the default request values with those passed into the function argument $defaults = array_merge(array('username' => '', 'password' => '', 'hostname' => '', 'myip' => '', 'offline' => false, 'offline_ip' => '127.0.0.1', 'detect_external_ip' => false), $defaults); // Get request values from HTTP data, falling back to the defaults above $username = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : (isset($_REQUEST['user']) ? $_REQUEST['user'] : $defaults['username']); $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : (isset($_REQUEST['pw']) ? $_REQUEST['pw'] : $defaults['password']); $hostname = isset($_REQUEST['hostname']) ? $_REQUEST['hostname'] : $defaults['hostname']; $myip = isset($_REQUEST['myip']) ? $_REQUEST['myip'] : (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : $defaults['myip']); $offline = isset($_REQUEST['offline']) ? strtoupper($_REQUEST['offline']) == 'YES' : $defaults['offline']; if ($hostname) { if ($username && $password) { // Instantiate the GoDaddyDNS class $dns = new self($defaults); if ($dns->authenticate($username, $password, $hostname)) { if ($offline) { // Use offline IP $myip = $defaults['offline_ip']; } elseif ($defaults['detect_external_ip'] && $dns->isPrivateIp($myip)) { if ($externalip = $dns->getPublicIp($myip)) { // Use detected external IP $myip = $externalip; } } // Attempt to update the hostname's A record if ($result = $dns->setRecord($hostname, $myip, 'A')) { echo ($result['last_ip'] == $result['new_ip'] ? 'nochg' : 'good') . ' ' . $result['new_ip']; } else { header('HTTP/1.1 500 Internal Server Error'); echo '911'; } } else { header('HTTP/1.1 403 Forbidden'); echo 'badauth'; } } else { header('WWW-Authenticate: Basic realm="Dynamic DNS"'); header('HTTP/1.1 401 Unauthorized'); echo 'noauth'; } } else { header('HTTP/1.1 500 Internal Server Error'); echo 'nohost'; } }