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

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

dmorley's avatar
cleanup  
dmorley committed
15 16
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
17
  die('Error in connection: ' . pg_last_error());
dmorley's avatar
cleanup  
dmorley committed
18 19 20 21
}
$sql = "SELECT domain,email,token,tokenexpire,pingdomurl,weight FROM pods WHERE domain = '$domain'";
$result = pg_query($dbh, $sql);
if (!$result) {
22
  die('Error in SQL query: ' . pg_last_error());
dmorley's avatar
cleanup  
dmorley committed
23 24
}
while ($row = pg_fetch_array($result)) {
25 26
  if ($row['token'] <> $_GET['token']) {
    die('token not a match');
dmorley's avatar
cleanup  
dmorley committed
27
  }
28 29
  if ($row['tokenexpire'] < date('Y-m-d H:i:s', time()))  {
    die('token expired');
dmorley's avatar
cleanup  
dmorley committed
30
  }
David Morley's avatar
David Morley committed
31
  //delete pod
32
  if ($_GET['delete'] == $row['token']){
David Morley's avatar
David Morley committed
33 34 35
  $sql = "DELETE FROM pods WHERE domain = $1";
  $result = pg_query_params($dbh, $sql, array($_GET['domain']));
    if (!$result) {
36
      die('Error in SQL query: ' . pg_last_error());
David Morley's avatar
David Morley committed
37
    } else {
38
      echo 'pod removed from DB';
David Morley's avatar
David Morley committed
39 40
    }
  }
dmorley's avatar
cleanup  
dmorley committed
41
  //save and exit
42
  if ($_GET['save'] == $row['token']){
dmorley's avatar
cleanup  
dmorley committed
43
    if ($_GET['weight'] > 10) {
44
      die('10 is max weight');
dmorley's avatar
cleanup  
dmorley committed
45 46 47 48
    }
    $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) {
49
      die('Error in SQL query: ' . pg_last_error());
dmorley's avatar
cleanup  
dmorley committed
50
    }
51 52 53
    $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";
dmorley's avatar
cleanup  
dmorley committed
54 55 56 57
    $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
cleanup  
dmorley committed
59
  }
dmorley's avatar
dmorley committed
60

dmorley's avatar
cleanup  
dmorley committed
61
  //form     
62
  echo 'Authorized to edit <b>' . $domain . '</b> until ' . $row['tokenexpire'] . '<br>';
noplanman's avatar
noplanman committed
63 64 65 66 67 68 69 70 71 72
  echo '<form action="" method="get">';
  echo '<input type="hidden" name="oldemail" value="' . $row['email'] . '">';
  echo '<input type="hidden" name="save" value="' . $_GET['token'] . '">';
  echo '<input type="hidden" name="token" value="' . $_GET['token'] . '">';
  echo '<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">';
  echo '</form><br><br><br>';
David Morley's avatar
David Morley committed
73

noplanman's avatar
noplanman committed
74 75 76 77 78 79
  echo '<form action="" method="get">';
  echo '<input type="hidden" name="delete" value="' . $_GET['token'] . '">';
  echo '<input type="hidden" name="token" value="' . $_GET['token'] . '">';
  echo '<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">';
  echo '</form><br><br><br>';
dmorley's avatar
dmorley committed
80
}