edit.php 3.47 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.
David Morley's avatar
David Morley committed
8
$_action           = $_GET['action'] ?? '';
9
$_weight           = $_GET['weight'] ?? 10;
David Morley's avatar
David Morley committed
10 11
$_email            = $_GET['email'] ?? '';
$_podmin_statement = $_GET['podmin_statement'] ?? '';
12
$_podmin_notify    = $_GET['podmin_notify'] ?? 0;
13 14 15

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

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

19
$sql    = 'SELECT domain,email,token,tokenexpire,weight,podmin_statement,podmin_notify FROM pods WHERE domain = $1';
20
$result = pg_query_params($dbh, $sql, [$_domain]);
21 22
$result || die('Error in SQL query: ' . pg_last_error());

dmorley's avatar
dmorley committed
23
while ($row = pg_fetch_array($result)) {
24 25
  $row['token'] === $_token || die('token mismatch');
  $row['tokenexpire'] >= date('Y-m-d H:i:s') || die('token expired');
26

27 28
  // Delete and exit.
  if ('delete' === $_action) {
29 30 31 32 33
    $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
34
  }
35

36 37
  // Save and exit
  if ('save' === $_action) {
38 39
    $_weight <= 10 || die('10 is max weight');

40 41
    $sql    = 'UPDATE pods SET email = $1, weight = $2, podmin_statement = $3, podmin_notify = $4 WHERE domain = $5';
    $result = pg_query_params($dbh, $sql, [$_email, $_weight, $_podmin_statement, $_podmin_notify, $_domain]);
42 43
    $result || die('Error in SQL query: ' . pg_last_error());

44
    $to      = $_email;
45 46 47 48 49
    $headers = ['From: ' . $adminemail, 'Cc: ' . $row['email'], 'Bcc: ' . $adminemail];
    $subject = 'Edit notice from poduptime';
    $message = 'Data for ' . $_domain . ' updated. If it was not you reply and let me know!';
    @mail($to, $subject, $message, implode("\r\n", $headers));

50
    die('Data saved. Will go into effect on next hourly change');
dmorley's avatar
dmorley committed
51
  }
dmorley's avatar
dmorley committed
52

53 54 55 56 57 58 59
  // Forms.
  ?>
  Authorized to edit <b><?php echo $_domain; ?></b> until <?php echo $row['tokenexpire']; ?><br>
  <form action="edit.php" method="get">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
    <label>Email <input type="text" size="20" name="email" value="<?php echo $row['email']; ?>"></label><br>
60
    <label>Podmin Statement (You can include links to your terms and policies and information about your pod you wish to share with users.) <br><textarea cols="100" rows="7" name="podmin_statement"><?php echo $row['podmin_statement']; ?></textarea></label><br>
61
    <label>Weight <input type="text" size="2" name="weight" value="<?php echo $row['weight']; ?>"> This lets you weight your pod lower on the list if you have too much traffic coming in, 10 is the norm use lower to move down the list.</label><br>
62
    <label>Notify if pod falls to hidden status? <input type="checkbox" name="podmin_notify" <?php $row['podmin_notify'] ?? 'CHECKED' ?> ></label><br>
63 64 65 66 67 68 69 70 71 72 73
    <input type="submit" name="action" value="save">
  </form>
  <br>
  <br>
  <br>
  <form action="edit.php" method="get">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
    WARNING: This can not be undone, you will need to add your pod again if you want back on list: <input type="submit" name="action" value="delete">
  </form>
  <?php
74
}