Last active 1734276330

x-way revised this gist 1734276330. Go to revision

No changes

x-way's Avatar Andreas Jaggi revised this gist 1370112896. Go to revision

1 file changed, 1 insertion, 1 deletion

index.php

@@ -1,6 +1,6 @@
1 1 <?php
2 2
3 - $myip = null;
3 + $myip = null;
4 4 $hostname = null;
5 5 $type = null;
6 6 $user = null;

x-way's Avatar Andreas Jaggi revised this gist 1370112860. Go to revision

1 file changed, 0 insertions, 0 deletions

gistfile1.php renamed to index.php

File renamed without changes

x-way's Avatar Andreas Jaggi revised this gist 1370112837. Go to revision

1 file changed, 75 insertions

gistfile1.php(file created)

@@ -0,0 +1,75 @@
1 + <?php
2 +
3 + $myip = null;
4 + $hostname = null;
5 + $type = null;
6 + $user = null;
7 + $password = null;
8 + $myzone = 'example.com';
9 + $myserver = 'nameserver.example.com';
10 +
11 + $AUTH_MAP = array(
12 + "foo.$myzone" => array( 'user' => 'bar', 'password' => 'mysecret', 'ipv6' => false ),
13 + );
14 +
15 + if ( isset($_GET['hostname']) ) {
16 + if ( isset($AUTH_MAP[$_GET['hostname']]) ) {
17 + $hostname = $_GET['hostname'];
18 + } else {
19 + echo "nohost\n";
20 + exit;
21 + }
22 + } else {
23 + echo "911\n";
24 + exit;
25 + }
26 +
27 + if ( isset($_GET['myip']) && filter_var($_GET['myip'], FILTER_VALIDATE_IP) ) {
28 + $myip = $_GET['myip'];
29 + } else {
30 + $myip = $_SERVER['REMOTE_ADDR'];
31 + }
32 +
33 + if ( $AUTH_MAP[$hostname]['ipv6'] && filter_var($myip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ) {
34 + $type = 'AAAA';
35 + } elseif ( filter_var($myip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) {
36 + $type = 'A';
37 + } else {
38 + echo "911\n";
39 + exit;
40 + }
41 +
42 + if ( isset($_SERVER['PHP_AUTH_USER']) ) {
43 + $user = $_SERVER['PHP_AUTH_USER'];
44 + } else {
45 + echo "badauth\n";
46 + exit;
47 + }
48 +
49 + if ( isset($_SERVER['PHP_AUTH_PW']) ) {
50 + $password = $_SERVER['PHP_AUTH_PW'];
51 + } else {
52 + echo "badauth\n";
53 + exit;
54 + }
55 +
56 + if ( ($AUTH_MAP[$hostname]['user'] == $user) && ($AUTH_MAP[$hostname]['password'] == $password) ) {
57 + shell_exec("/usr/bin/nsupdate -k /www/Kexample.com.+247+89651.private <<EOF
58 + server $myserver
59 + zone $myzone
60 + update delete $hostname. $type
61 + update add $hostname. 30 $type $myip
62 + send
63 + EOF
64 + ");
65 + echo "good $myip\n";
66 + } else {
67 + echo "badauth\n";
68 + exit;
69 + }
70 +
71 + if ( isset($_GET['debug']) ) {
72 + echo "user: $user, password: $password, hostname: $hostname, myip: $myip, type: $type\n";
73 + }
74 +
75 + ?>
Newer Older