aboutsummaryrefslogtreecommitdiff
path: root/update.php
blob: a033d3800b51391df5ff5850c504a221e5b11981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
// http://info.wireme.de/update.php?ip=<ipaddr>&ipv6=<ip6addr>&domain=<domain>&user=<username>&pass=<pass>

function print_error()
{
  echo 'pg error';
}

// Connecting, selecting database
echo "content-type: text/html\n\n";
# $conn   = pg_connect('host=/var/run/postgresql user=username dbname=databasename');
$dbconn = pg_connect('host=10.0.0.101          user=powerdns dbname=powerdns connect_timeout=5')
  or die('Could not connect: ' . pg_last_error());

// if(!$dbconn)
// {
//   echo "fehler\n";
//   die('Could not connect: ' . pg_last_error());
// }
echo "gut\n";

// Performing SQL query

$ip = "127.0.0.1";
if(isset($_GET['ip']))
{ $ip     = $_GET['ip']; }

$ipv6 = "::0";
if(isset($_GET['ipv6']))
{ $ipv6     = $_GET['ipv6']; }


if(! preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $ip) )
{ die("illegal ip"); }


$user = '';
if(isset($_GET['user']))
{ $user = $_GET['user']; }

if(! preg_match('/[a-z]+/', $user) )
{ die("illegal user"); }



$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;")
  or die('Could not connect: ' . pg_last_error());
$result = pg_execute($dbconn, "updatesoa", array());

if(pg_affected_rows($result) != 1)
{
  die("unable to update soa, result: ".pg_affected_rows($result));
}


#$query  = "UPDATE records SET content='$ip' WHERE type='A' AND name='wire-me.de'; ";
#echo 'gut';
# $result = pg_query($query) or die('Query failed: ' . pg_last_error());
$stmt   = pg_prepare($dbconn, "updatedns", "UPDATE records SET content=$1 WHERE type=$2 AND name=$3;")
  or die('Could not connect: ' . pg_last_error());
$result = pg_execute($dbconn, "updatedns", array($ip, "A", $user.".wire-me.de"));
$result = pg_execute($dbconn, "updatedns", array($ipv6, "AAAA", $user.".wire-me.de"));

if(pg_affected_rows($result) != 1)
{
  $fh = fopen("error.log", "a+");
  fwrite($fh, "IP: $ip; user: $user;\n");
  fclose($fh);
  die("unable to update user");
}



echo '<br/>rows: "'.pg_affected_rows($result).'"';
echo '<br/>result: "'.$result.'"';
echo '<br/>error: "'.pg_result_error($result).'"';
// Printing results in HTML
// echo "<table>\n";
// while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
//     echo "\t<tr>\n";
//     foreach ($line as $col_value) {
//         echo "\t\t<td>$col_value</td>\n";
//     }
//     echo "\t</tr>\n";
// }
// echo "</table>\n";

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);
?>
..