exit(); } connectToDatabase(); if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) { $result = databaseQuery("SELECT * FROM users WHERE username=%s AND level!=0", $_REQUEST['username']); $user = databaseFetchAssoc($result); if ($user!=NULL) { $salt = hex2bin(substr($user['password'], 0, 32)); $password = substr($user['password'], 32); if ($password==hashPassword($_REQUEST['password'], $salt)) { $_MGM['user'] = $user; } } } header("Content-Type: text/plain"); if (!isset($_MGM['user'])) { echo "Invalid Credentials"; closeDatabase(); exit(); } databaseQuery("UPDATE users SET lastmessage=%s WHERE username=%s", $_MGM['time'], $_MGM['user']['username']); $dblast = ""; $nsrecord = ""; if (filter_var($_MGM['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $dblast = "lastv4"; $nsrecord = "A"; } else if (filter_var($_MGM['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { $dblast = "lastv6"; $nsrecord = "AAAA"; } if ($dblast=="") { echo "Invalid IP Address Detected"; closeDatabase(); exit(); } if ($_MGM['user'][$dblast]!=$_MGM['ip']) { echo "New IP: ".$_MGM['ip']."\n\n"; $updateFile = tempnam(sys_get_temp_dir(), 'GeckoDNS'); $fh = fopen($updateFile, 'w'); fwrite($fh, "server ".$_MGM['user']['server']."\n"); fwrite($fh, "debug yes\n"); fwrite($fh, "zone ".$_MGM['user']['zone']."\n"); $hosts = explode(",", $_MGM['user']['hosts']); foreach ($hosts as $host) { $suffix = substr($host, strlen($host)-strlen($_MGM['user']['zone'])); if ($suffix!=$_MGM['user']['zone'] && !preg_match('/^[a-zA-Z0-9.-*]+$/', $host)) { echo "Host: ".$host."\n\n"; echo "Invalid Configuration"; fclose($fh); unlink($updateFile); closeDatabase(); exit(); } fwrite($fh, "update delete ".$host." ".$nsrecord."\n"); fwrite($fh, "update add ".$host." ".$_MGM['defaultTTL']." ".$nsrecord." ".$_MGM['ip']."\n"); } fwrite($fh, "show\n"); fwrite($fh, "send\n"); fclose($fh); $command = $_MGM['nsupdatePath']." -k ".escapeshellarg("keys/".$_MGM['user']['key'])." ".$updateFile; $result = exec($command." 2>&1", $output); if ($_MGM['debug']) { echo "Output: \n"; } $foundReply = false; $status = 0; foreach ($output as $line) { if ($_MGM['debug']) { echo $line."\n"; } if ($foundReply && $status==0) { if (strpos($line, "status: NOERROR")!==false) { $status = 1; } else { $status = 2; } } if (strpos($line, "Reply from update query:")!==false) { $foundReply = true; } } if ($status==1) { echo "\nUpdate Successful"; databaseQuery("UPDATE users SET lastupdate=%s, $dblast=%s WHERE username=%s", $_MGM['time'], $_MGM['ip'], $_MGM['user']['username']); } else { if ($_MGM['debug']) { echo "\nCommand: ".$command."\n"; echo "\nUpdate File:\n"; readfile($updateFile); } echo "\nUpdate Unsuccessful"; } unlink($updateFile); } else { echo "No Update"; } closeDatabase(); ?>