aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Christian2016-09-14 11:33:40 +0200
committerMax Christian2016-09-14 11:33:40 +0200
commit151c39e6aa8e9ec9d9cbe31bcca81ada71d9c72b (patch)
tree491a543557a14eed9b8f8a43f83fe14bdab92151
downloadpdnsupdate-151c39e6aa8e9ec9d9cbe31bcca81ada71d9c72b.tar.bz2
pdnsupdate-151c39e6aa8e9ec9d9cbe31bcca81ada71d9c72b.zip
quick and dirty dyndns service
This script updates powerdns entries. It does not permission checks yet and is best described as a proof of concept .
-rw-r--r--update.php93
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
4function print_error()
5{
6 echo 'pg error';
7}
8
9// Connecting, selecting database
10echo "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// }
20echo "gut\n";
21
22// Performing SQL query
23
24$ip = "127.0.0.1";
25if(isset($_GET['ip']))
26{ $ip = $_GET['ip']; }
27
28$ipv6 = "::0";
29if(isset($_GET['ipv6']))
30{ $ipv6 = $_GET['ipv6']; }
31
32
33if(! preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $ip) )
34{ die("illegal ip"); }
35
36
37$user = '';
38if(isset($_GET['user']))
39{ $user = $_GET['user']; }
40
41if(! 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
50if(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
64if(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
74echo '<br/>rows: "'.pg_affected_rows($result).'"';
75echo '<br/>result: "'.$result.'"';
76echo '<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
89pg_free_result($result);
90
91// Closing connection
92pg_close($dbconn);
93?>
..