edit.php 3.56 KB
Newer Older
1
<?php
2 3 4 5
// Required parameters.
($_domain = $_GET['domain'] ?? null) || die('no pod domain given');
($_token = $_GET['token'] ?? null) || die('no token given');
strlen($_token) > 6 || die('bad token');
6

7
// Other parameters.
dmorley's avatar
dmorley committed
8 9 10 11 12 13 14
$_save         = $_GET['save'] ?? '';
$_delete       = $_GET['delete'] ?? '';
$_weight       = $_GET['weight'] ?? '';
$_email        = $_GET['email'] ?? '';
$_oldemail     = $_GET['oldemail'] ?? '';
$_stats_apikey = $_GET['stats_apikey'] ?? '';
$_terms        = $_GET['terms'] ?? '';
15 16 17

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

dmorley's avatar
dmorley committed
18
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
19 20
$dbh || die('Error in connection: ' . pg_last_error());

dmorley's avatar
dmorley committed
21
$sql    = 'SELECT domain,email,token,tokenexpire,stats_apikey,weight,terms FROM pods WHERE domain = $1';
22
$result = pg_query_params($dbh, $sql, [$_domain]);
23 24
$result || die('Error in SQL query: ' . pg_last_error());

dmorley's avatar
dmorley committed
25
while ($row = pg_fetch_array($result)) {
26 27 28
  $row['token'] === $_token || die('token not a match');
  $row['tokenexpire'] >= date('Y-m-d H:i:s', time()) || die('token expired');

David Morley's avatar
David Morley committed
29
  //delete pod
30 31 32 33 34 35
  if ($_delete === $row['token']) {
    $sql    = 'DELETE FROM pods WHERE domain = $1';
    $result = pg_query_params($dbh, $sql, [$_domain]);
    $result || die('Error in SQL query: ' . pg_last_error());

    die('pod removed from DB');
David Morley's avatar
David Morley committed
36
  }
37

dmorley's avatar
dmorley committed
38
  //save and exit
39 40 41
  if ($_save === $row['token']) {
    $_weight <= 10 || die('10 is max weight');

dmorley's avatar
dmorley committed
42 43
    $sql    = 'UPDATE pods SET email = $1, stats_apikey = $2, weight = $3, terms = $4 WHERE domain = $5';
    $result = pg_query_params($dbh, $sql, [$_email, $_stats_apikey, $_weight, $_terms, $_domain]);
dmorley's avatar
dmorley committed
44
    if (!$result) {
45
      die('Error in SQL query: ' . pg_last_error());
dmorley's avatar
dmorley committed
46
    }
47
    $to      = $_email;
48
    $subject = 'Edit notice from poduptime ';
49
    $message = 'Data for ' . $_domain . " Updated. If it was not you reply and let me know! \n\n";
50
    $headers = "From: " . $adminemail . "\r\nCc:" . $adminemail . "," . $_oldemail . "\r\n";
51
    @mail($to, $subject, $message, $headers);
dmorley's avatar
dmorley committed
52 53
    pg_free_result($result);
    pg_close($dbh);
54
    die('Data saved. Will go into effect on next hourly change');
dmorley's avatar
dmorley committed
55
  }
dmorley's avatar
dmorley committed
56

dmorley's avatar
dmorley committed
57
  //form     
58
  echo 'Authorized to edit <b>' . $_domain . '</b> until ' . $row['tokenexpire'] . '<br>';
59 60
  echo '<form action="" method="get">';
  echo '<input type="hidden" name="oldemail" value="' . $row['email'] . '">';
61 62 63
  echo '<input type="hidden" name="save" value="' . $_token . '">';
  echo '<input type="hidden" name="token" value="' . $_token . '">';
  echo '<input type="hidden" name="domain" value="' . $_domain . '">';
dmorley's avatar
dmorley committed
64
  echo 'Stats Key <input type="text" size="50" name="stats_apikey" value="' . $row['stats_apikey'] . '"">Uptimerobot API key for this monitor<br>';
65
  echo 'Email <input type="text" size="20" name="email" value="' . $row['email'] . '"><br>';
66
  echo 'Terms Link <input type="text" size="20" name="terms" value="' . $row['terms'] . '"><br>';
67 68 69
  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
70

71
  echo '<form action="" method="get">';
72 73 74
  echo '<input type="hidden" name="delete" value="' . $_token . '">';
  echo '<input type="hidden" name="token" value="' . $_token . '">';
  echo '<input type="hidden" name="domain" value="' . $_domain . '">';
75 76
  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>';
77
}