edit.php 5.84 KB
Newer Older
1
<?php
2

3 4 5 6 7 8
/**
 * Edit an existing pod.
 */

declare(strict_types=1);

9
use Carbon\Carbon;
10
use Poduptime\PodStatus;
11 12
use RedBeanPHP\R;

13 14 15 16
// 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');
17

18
// Other parameters.
19 20 21 22 23 24
$_action                 = $_GET['action'] ?? '';
$_weight                 = $_GET['weight'] ?? 10;
$_email                  = $_GET['email'] ?? '';
$_podmin_statement       = $_GET['podmin_statement'] ?? '';
$_podmin_notify          = $_GET['podmin_notify'] ?? 0;
$_podmin_notify_level    = $_GET['podmin_notify_level'] ?? 50;
25

26
require_once __DIR__ . '/../boot.php';
David Morley's avatar
David Morley committed
27

28
try {
29 30
    $pod = R::findOne('pods', 'domain = ?', [$_domain]);
    $pod || die('domain not found');
31
} catch (\RedBeanPHP\RedException $e) {
32
    die('Error in SQL query: ' . $e->getMessage());
33
}
34

35 36
$pod['token'] === $_token || die('token mismatch');
$pod['tokenexpire'] >= date('Y-m-d H:i:s') || die('token expired');
37

38 39
// Delete and exit.
if ('delete' === $_action) {
40 41 42 43 44 45 46
    try {
        $pod['status'] = PodStatus::USER_DELETED;
        R::store($pod);
    } catch (\RedBeanPHP\RedException $e) {
        die('Error in SQL query: ' . $e->getMessage());
    }
    die('pod deleted');
David Morley's avatar
David Morley committed
47 48 49 50
}

// Pause and exit.
if ('pause' === $_action) {
51 52 53 54 55 56 57
    try {
        $pod['status'] = PodStatus::PAUSED;
        R::store($pod);
    } catch (\RedBeanPHP\RedException $e) {
        die('Error in SQL query: ' . $e->getMessage());
    }
    die('pod paused');
David Morley's avatar
David Morley committed
58 59 60 61
}

// Un-Pause and exit.
if ('unpause' === $_action) {
62
    try {
David Morley's avatar
David Morley committed
63
        $pod['status'] = PodStatus::RECHECK;
64 65 66 67 68
        R::store($pod);
    } catch (\RedBeanPHP\RedException $e) {
        die('Error in SQL query: ' . $e->getMessage());
    }
    die('pod unpaused');
69
}
70

71 72
// Save and exit.
if ('save' === $_action) {
73 74 75
    $_weight <= 10 || die('10 is max weight');

    try {
76 77 78 79 80 81
        $pod['email']                  = $_email;
        $pod['weight']                 = $_weight;
        $pod['podmin_statement']       = $_podmin_statement;
        $pod['podmin_notify']          = $_podmin_notify;
        $pod['podmin_notify_level']    = $_podmin_notify_level;

82 83 84 85 86 87 88

        R::store($pod);
    } catch (\RedBeanPHP\RedException $e) {
        die('Error in SQL query: ' . $e->getMessage());
    }

    $to      = $_email;
89
    $headers = ['From: ' . c('adminemail'), 'Cc: ' . $pod['email'], 'Bcc: ' . c('adminemail')];
90 91 92 93 94
    $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));

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

97
// Forms.
David Morley's avatar
David Morley committed
98

99
?>
David Morley's avatar
David Morley committed
100 101 102
<script>
    window.onload = function() {
        $("#weight").ionRangeSlider();
103
        $("#podmin_notify_level").ionRangeSlider();
David Morley's avatar
David Morley committed
104 105
    }
</script>
106
Authorized to edit <b><?php echo $_domain; ?></b> for <?php echo (new Carbon($pod['tokenexpire']))->diffForHumans(null, true); ?><br>
David Morley's avatar
David Morley committed
107
<form action="/">
108 109 110 111 112
    <input type="hidden" name="edit">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
    <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>
David Morley's avatar
David Morley committed
113
    <label>Weight <input type="text" data-min="0" data-step="1" data-max="10" name="weight" id="weight" data-from="<?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>
114
    <label>Notify if pod falls off the list? <input type="checkbox" name="podmin_notify" <?php echo $pod['podmin_notify'] ? 'checked' : ''; ?> ></label><br>
115 116
    <label>Notify when your score falls to <input type="text" data-min="1" data-step="1" data-max="99" name="podmin_notify_level" id="podmin_notify_level" data-from="<?php echo $pod['podmin_notify_level']; ?>"></label><br>

117 118 119 120 121
    <input type="submit" name="action" value="save">
</form>
<br>
<br>Your pod status is currently: <?php echo PodStatus::getKey((int) $pod['status']); ?>
<br>
David Morley's avatar
David Morley committed
122
<form action="/">
123 124 125
    <input type="hidden" name="edit">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
David Morley's avatar
David Morley committed
126
    <input type="submit" name="action" value="delete" aria-describedby="delete">
127
</form>
David Morley's avatar
David Morley committed
128 129 130 131
<small id="delete" class="form-text text-muted">
    Stop checking and Stop showing your pod. Can be re-enabled later.
</small>
<form action="/">
132 133 134
    <input type="hidden" name="edit">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
David Morley's avatar
David Morley committed
135
    <input type="submit" name="action" value="pause" aria-describedby="pause">
136
</form>
David Morley's avatar
David Morley committed
137 138 139 140
<small id="pause" class="form-text text-muted">
    Stop checking your pod. Can be re-enabled later.
</small>
<form action="/">
141 142 143
    <input type="hidden" name="edit">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
David Morley's avatar
David Morley committed
144
    <input type="submit" name="action" value="unpause" aria-describedby="undelete">
145
</form>
David Morley's avatar
David Morley committed
146 147 148 149 150 151
<small id="undelete" class="form-text text-muted">
    Unpause/Undelete - Start checking and Start showing your pod.
</small>
<input value="debug" type="button"  aria-describedby="debug" data-featherlight="/db/pull.php?debug=1&nowrite=1&domain=<?php echo $_domain; ?>"/>
<small id="debug" class="form-text text-muted">
    Do a debug pull of your pod. Won't update the database just show what it would look like on a pass.
152
</small>