kill.php 1.91 KB
Newer Older
dmorley's avatar
dmorley committed
1
<?php
2 3 4 5 6 7 8 9

// Required parameters.
($_domain = $_POST['domain'] ?? null) || die('no pod domain given');
($_adminkey = $_POST['adminkey'] ?? null) || die('no token given');
($_action = $_POST['action'] ?? null) || die('no action selected');

// Other parameters.
$_comments = $_POST['comments'] ?? '';
10 11 12

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

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

16 17
$sql    = 'SELECT email FROM pods WHERE domain = $1';
$result = pg_query_params($dbh, $sql, [$_domain]);
18 19
$result || die('one Error in SQL query: ' . pg_last_error());

dmorley's avatar
dmorley committed
20
while ($row = pg_fetch_array($result)) {
21 22
  $adminkey === $_adminkey || die('admin key fail');

dmorley's avatar
dmorley committed
23
  //save and exit
24 25 26 27 28
  if ($_action === 'delete') {
    $sql    = 'DELETE FROM pods WHERE domain = $1';
    $result = pg_query_params($dbh, $sql, [$_domain]);
    $result || die('two Error in SQL query: ' . pg_last_error());

29 30
    if ($row['email']) {
      $to      = $row['email'];
dmorley's avatar
dmorley committed
31 32
      $subject = 'Pod deleted from ' . $_SERVER['HTTP_HOST'];
      $message = 'Pod ' . $_domain . ' was deleted from ' . $_SERVER['HTTP_HOST'] . ' as it was dead on the list. ' . $_comments . " Feel free to add back at any time. \n\n";
33
      $headers = "From: " . $adminemail ."\r\nCc:" . $adminemail . "," . $row['email'] . "\r\n";
34 35 36
      @mail($to, $subject, $message, $headers);
    }
    pg_free_result($result);
37
  } elseif ($_action === 'warn') {
38 39
    if ($row['email']) {
      $to      = $row['email'];
dmorley's avatar
dmorley committed
40
      $subject = 'Pod removal warning from ' . $_SERVER['HTTP_HOST'];
41
      $message = 'Pod ' . $_domain . ' is on the list to be deleted now because:  ' . $_comments . ". \n\n Please let me know if you need help fixing before it is removed. \n\n";
42
      $headers = "From: " . $adminemail ."\r\nCc:" . $adminemail . "," . $row['email'] . "\r\n";
43 44
      @mail($to, $subject, $message, $headers);
    }
dmorley's avatar
dmorley committed
45
  }
46

dmorley's avatar
dmorley committed
47
  echo $result;
dmorley's avatar
dmorley committed
48
}
49 50

pg_close($dbh);