edit.php 3.1 KB
Newer Older
1 2
<?php
if (!$_GET['domain']){
3
  die("no pod domain given");
4 5
}
if (!$_GET['token']){
6
  die("no token given");
7 8
}
if (strlen($_GET['token']) < 6){
9
  die("bad token");
10 11
}
$domain = $_GET['domain'];
12 13 14

require_once __DIR__ . '/../config.php';

dmorley's avatar
dmorley committed
15 16 17 18 19 20 21 22 23 24 25
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
  die("Error in connection: " . pg_last_error());
}
$sql = "SELECT domain,email,token,tokenexpire,pingdomurl,weight FROM pods WHERE domain = '$domain'";
$result = pg_query($dbh, $sql);
if (!$result) {
  die("Error in SQL query: " . pg_last_error());
}
while ($row = pg_fetch_array($result)) {
  if ($row["token"] <> $_GET['token']) {
26
    die("token not a match");
dmorley's avatar
dmorley committed
27 28
  }
  if ($row["tokenexpire"] < date("Y-m-d H:i:s", time()))  {
29
    die("token expired");
dmorley's avatar
dmorley committed
30
  }
David Morley's avatar
David Morley committed
31 32 33 34 35 36 37
  //delete pod
  if ($_GET['delete'] == $row["token"]){
  $sql = "DELETE FROM pods WHERE domain = $1";
  $result = pg_query_params($dbh, $sql, array($_GET['domain']));
    if (!$result) {
      die("Error in SQL query: " . pg_last_error());
    } else {
38
      echo "pod removed from DB";
David Morley's avatar
David Morley committed
39 40
    }
  }
dmorley's avatar
dmorley committed
41 42 43
  //save and exit
  if ($_GET['save'] == $row["token"]){
    if ($_GET['weight'] > 10) {
44
      die("10 is max weight");
dmorley's avatar
dmorley committed
45 46 47 48 49 50 51 52 53 54 55 56 57
    }
    $sql = "UPDATE pods SET email=$1, pingdomurl=$2, weight=$3 WHERE domain = $4";
    $result = pg_query_params($dbh, $sql, array($_GET['email'],$_GET['pingdomurl'],$_GET['weight'],$_GET['domain']));
    if (!$result) {
      die("Error in SQL query: " . pg_last_error());
    }
    $to = $_GET["email"];
    $subject = "Edit notice from poduptime ";
    $message = "Data for " . $_GET["domain"] . " Updated. If it was not you reply and let me know! \n\n";
    $headers = "From: support@diasp.org\r\nCc:support@diasp.org,". $_GET['oldemail'] ."\r\n";
    @mail( $to, $subject, $message, $headers );
    pg_free_result($result);
    pg_close($dbh);
58
    die("Data saved. Will go into effect on next hourly change");
dmorley's avatar
dmorley committed
59
  }
dmorley's avatar
dmorley committed
60

dmorley's avatar
dmorley committed
61 62 63 64 65 66 67
  //form     
  echo "Authorized to edit <b>" . $domain . "</b> until " .$row["tokenexpire"] . "<br>";
  echo "<form action='' method='get'><input type=hidden name=oldemail value=" . $row["email"] . "><input type=hidden name=save value=" . $_GET['token'] . "><input type=hidden name=token value=" . $_GET['token'] . "><input type=hidden name=domain value=" . $_GET['domain'] . ">";
  echo "Stats Key <input type=text size=50 name=pingdomurl value=" .$row["pingdomurl"] . ">Uptimerobot API key for this monitor<br>"; 
  echo "Email <input type=text size=20 name=email value=" .$row["email"] . "><br>";
  echo "Weight <input type=text size=2 name=weight value=" .$row["weight"] . "> This lets you weight your pod lower on the list if you have too much trafic coming in, 10 is the norm use lower to move down the list.<br>";
  echo "<input type=submit name=submit><br><br><br>";
David Morley's avatar
David Morley committed
68 69 70

  echo "<form action='' method='get'><input type=hidden name=delete value=" . $_GET['token'] . "><input type=hidden name=token value=" . $_GET['token'] . "><input type=hidden name=domain value=" . $_GET['domain'] . ">";
  echo "WARNING: This can not be undone, you will need to add your pod again if you want back on list: <input type=submit name=submit value=delete><br><br><br>";
71
}