diff options
Diffstat (limited to 'update.php')
| -rw-r--r-- | update.php | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/update.php b/update.php new file mode 100644 index 0000000..a033d38 --- /dev/null +++ b/update.php | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | <?php | ||
| 2 | // http://info.wireme.de/update.php?ip=<ipaddr>&ipv6=<ip6addr>&domain=<domain>&user=<username>&pass=<pass> | ||
| 3 | |||
| 4 | function print_error() | ||
| 5 | { | ||
| 6 | echo 'pg error'; | ||
| 7 | } | ||
| 8 | |||
| 9 | // Connecting, selecting database | ||
| 10 | echo "content-type: text/html\n\n"; | ||
| 11 | # $conn = pg_connect('host=/var/run/postgresql user=username dbname=databasename'); | ||
| 12 | $dbconn = pg_connect('host=10.0.0.101 user=powerdns dbname=powerdns connect_timeout=5') | ||
| 13 | or die('Could not connect: ' . pg_last_error()); | ||
| 14 | |||
| 15 | // if(!$dbconn) | ||
| 16 | // { | ||
| 17 | // echo "fehler\n"; | ||
| 18 | // die('Could not connect: ' . pg_last_error()); | ||
| 19 | // } | ||
| 20 | echo "gut\n"; | ||
| 21 | |||
| 22 | // Performing SQL query | ||
| 23 | |||
| 24 | $ip = "127.0.0.1"; | ||
| 25 | if(isset($_GET['ip'])) | ||
| 26 | { $ip = $_GET['ip']; } | ||
| 27 | |||
| 28 | $ipv6 = "::0"; | ||
| 29 | if(isset($_GET['ipv6'])) | ||
| 30 | { $ipv6 = $_GET['ipv6']; } | ||
| 31 | |||
| 32 | |||
| 33 | if(! preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $ip) ) | ||
| 34 | { die("illegal ip"); } | ||
| 35 | |||
| 36 | |||
| 37 | $user = ''; | ||
| 38 | if(isset($_GET['user'])) | ||
| 39 | { $user = $_GET['user']; } | ||
| 40 | |||
| 41 | if(! preg_match('/[a-z]+/', $user) ) | ||
| 42 | { die("illegal user"); } | ||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | $stmt = pg_prepare($dbconn, "updatesoa", "update records set content='ns1.first-ns.de postmaster.robot.first-ns.de ".date("U")." 600 300 1800 300' where id=6;") | ||
| 47 | or die('Could not connect: ' . pg_last_error()); | ||
| 48 | $result = pg_execute($dbconn, "updatesoa", array()); | ||
| 49 | |||
| 50 | if(pg_affected_rows($result) != 1) | ||
| 51 | { | ||
| 52 | die("unable to update soa, result: ".pg_affected_rows($result)); | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | #$query = "UPDATE records SET content='$ip' WHERE type='A' AND name='wire-me.de'; "; | ||
| 57 | #echo 'gut'; | ||
| 58 | # $result = pg_query($query) or die('Query failed: ' . pg_last_error()); | ||
| 59 | $stmt = pg_prepare($dbconn, "updatedns", "UPDATE records SET content=$1 WHERE type=$2 AND name=$3;") | ||
| 60 | or die('Could not connect: ' . pg_last_error()); | ||
| 61 | $result = pg_execute($dbconn, "updatedns", array($ip, "A", $user.".wire-me.de")); | ||
| 62 | $result = pg_execute($dbconn, "updatedns", array($ipv6, "AAAA", $user.".wire-me.de")); | ||
| 63 | |||
| 64 | if(pg_affected_rows($result) != 1) | ||
| 65 | { | ||
| 66 | $fh = fopen("error.log", "a+"); | ||
| 67 | fwrite($fh, "IP: $ip; user: $user;\n"); | ||
| 68 | fclose($fh); | ||
| 69 | die("unable to update user"); | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | echo '<br/>rows: "'.pg_affected_rows($result).'"'; | ||
| 75 | echo '<br/>result: "'.$result.'"'; | ||
| 76 | echo '<br/>error: "'.pg_result_error($result).'"'; | ||
| 77 | // Printing results in HTML | ||
| 78 | // echo "<table>\n"; | ||
| 79 | // while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { | ||
| 80 | // echo "\t<tr>\n"; | ||
| 81 | // foreach ($line as $col_value) { | ||
| 82 | // echo "\t\t<td>$col_value</td>\n"; | ||
| 83 | // } | ||
| 84 | // echo "\t</tr>\n"; | ||
| 85 | // } | ||
| 86 | // echo "</table>\n"; | ||
| 87 | |||
| 88 | // Free resultset | ||
| 89 | pg_free_result($result); | ||
| 90 | |||
| 91 | // Closing connection | ||
| 92 | pg_close($dbconn); | ||
| 93 | ?> | ||
