Skip to content

Instantly share code, notes, and snippets.

@x-way x-way/index.php
Last active Dec 17, 2015

Embed
What would you like to do?
dyndns server
<?php
$myip = null;
$hostname = null;
$type = null;
$user = null;
$password = null;
$myzone = 'example.com';
$myserver = 'nameserver.example.com';
$AUTH_MAP = array(
"foo.$myzone" => array( 'user' => 'bar', 'password' => 'mysecret', 'ipv6' => false ),
);
if ( isset($_GET['hostname']) ) {
if ( isset($AUTH_MAP[$_GET['hostname']]) ) {
$hostname = $_GET['hostname'];
} else {
echo "nohost\n";
exit;
}
} else {
echo "911\n";
exit;
}
if ( isset($_GET['myip']) && filter_var($_GET['myip'], FILTER_VALIDATE_IP) ) {
$myip = $_GET['myip'];
} else {
$myip = $_SERVER['REMOTE_ADDR'];
}
if ( $AUTH_MAP[$hostname]['ipv6'] && filter_var($myip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ) {
$type = 'AAAA';
} elseif ( filter_var($myip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) {
$type = 'A';
} else {
echo "911\n";
exit;
}
if ( isset($_SERVER['PHP_AUTH_USER']) ) {
$user = $_SERVER['PHP_AUTH_USER'];
} else {
echo "badauth\n";
exit;
}
if ( isset($_SERVER['PHP_AUTH_PW']) ) {
$password = $_SERVER['PHP_AUTH_PW'];
} else {
echo "badauth\n";
exit;
}
if ( ($AUTH_MAP[$hostname]['user'] == $user) && ($AUTH_MAP[$hostname]['password'] == $password) ) {
shell_exec("/usr/bin/nsupdate -k /www/Kexample.com.+247+89651.private <<EOF
server $myserver
zone $myzone
update delete $hostname. $type
update add $hostname. 30 $type $myip
send
EOF
");
echo "good $myip\n";
} else {
echo "badauth\n";
exit;
}
if ( isset($_GET['debug']) ) {
echo "user: $user, password: $password, hostname: $hostname, myip: $myip, type: $type\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.