edit.php 4.34 KB
Newer Older
dmorley's avatar
dmorley committed
1
<?php
noplanman's avatar
noplanman committed
2 3

use RedBeanPHP\R;
dmorley's avatar
dmorley committed
4
use CommerceGuys\Enum\AbstractEnum;
noplanman's avatar
noplanman committed
5

6 7 8 9
// 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');
10

11
// Other parameters.
David Morley's avatar
David Morley committed
12
$_action           = $_GET['action'] ?? '';
13
$_weight           = $_GET['weight'] ?? 10;
David Morley's avatar
David Morley committed
14 15
$_email            = $_GET['email'] ?? '';
$_podmin_statement = $_GET['podmin_statement'] ?? '';
16
$_podmin_notify    = $_GET['podmin_notify'] ?? 0;
17

noplanman's avatar
noplanman committed
18
require_once __DIR__ . '/../vendor/autoload.php';
19 20
require_once __DIR__ . '/../config.php';

noplanman's avatar
noplanman committed
21 22 23 24 25 26
try {
  $pod = R::findOne('pods', 'domain = ?', [$_domain]);
  $pod || die('domain not found');
} catch (\RedBeanPHP\RedException $e) {
  die('Error in SQL query: ' . $e->getMessage());
}
27

noplanman's avatar
noplanman committed
28 29
$pod['token'] === $_token || die('token mismatch');
$pod['tokenexpire'] >= date('Y-m-d H:i:s') || die('token expired');
30

noplanman's avatar
noplanman committed
31 32
// Delete and exit.
if ('delete' === $_action) {
dmorley's avatar
dmorley committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  try {
    $pod['status'] = PodStatus::User_Deleted;
    R::store($pod);
  } catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
  }
  die('pod deleted');
}

// Pause and exit.
if ('pause' === $_action) {
  try {
    $pod['status'] = PodStatus::Paused;
    R::store($pod);
  } catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
  }
  die('pod paused');
}

// Un-Pause and exit.
if ('unpause' === $_action) {
  try {
    $pod['status'] = PodStatus::Recheck;
    R::store($pod);
  } catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
  }
  die('pod unpaused');
noplanman's avatar
noplanman committed
62
}
63

noplanman's avatar
noplanman committed
64 65 66
// Save and exit.
if ('save' === $_action) {
  $_weight <= 10 || die('10 is max weight');
67

noplanman's avatar
noplanman committed
68 69 70 71 72
  try {
    $pod['email']            = $_email;
    $pod['weight']           = $_weight;
    $pod['podmin_statement'] = $_podmin_statement;
    $pod['podmin_notify']    = $_podmin_notify;
73

noplanman's avatar
noplanman committed
74 75 76 77
    R::store($pod);
  } catch (\RedBeanPHP\RedException $e) {
    die('Error in SQL query: ' . $e->getMessage());
  }
78

noplanman's avatar
noplanman committed
79 80 81 82 83
  $to      = $_email;
  $headers = ['From: ' . $adminemail, 'Cc: ' . $pod['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));
84

noplanman's avatar
noplanman committed
85 86
  die('Data saved. Will go into effect on next hourly change');
}
dmorley's avatar
dmorley committed
87

noplanman's avatar
noplanman committed
88
// Forms.
dmorley's avatar
dmorley committed
89

noplanman's avatar
noplanman committed
90 91
?>
  Authorized to edit <b><?php echo $_domain; ?></b> until <?php echo $pod['tokenexpire']; ?><br>
dmorley's avatar
dmorley committed
92 93
  <form>
    <input type="hidden" name="edit">
94 95
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
dmorley's avatar
dmorley committed
96 97
    <label>Email <input type="text" size="40" name="email" value="<?php echo $pod['email']; ?>"></label><br>
    <label>Podmin Statement (You can use HTML to include links to your terms and policies and information about your pod you wish to share with users.) <br><textarea cols="150" rows="10" name="podmin_statement"><?php echo $pod['podmin_statement']; ?></textarea></label><br>
noplanman's avatar
noplanman committed
98
    <label>Weight <input type="text" size="2" name="weight" value="<?php echo $pod['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>
David Morley's avatar
David Morley committed
99
    <label>Notify if pod falls to hidden status? <input type="checkbox" name="podmin_notify" <?php echo $pod['podmin_notify'] ? 'checked' : ''; ?> ></label><br>
100 101 102
    <input type="submit" name="action" value="save">
  </form>
  <br>
dmorley's avatar
dmorley committed
103
  <br>Your pod status is currently: <?php echo PodStatus::getKey((int)$pod['status']); ?>
104
  <br>
dmorley's avatar
dmorley committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118
  <form>
    <input type="hidden" name="edit">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
    <input type="submit" name="action" value="delete">
  </form>
  <form>
    <input type="hidden" name="edit">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
    <input type="submit" name="action" value="pause">
  </form>
  <form>
    <input type="hidden" name="edit">
119 120
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
dmorley's avatar
dmorley committed
121
    <input type="submit" name="action" value="unpause">
122
  </form>
noplanman's avatar
noplanman committed
123
<?php