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

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

declare(strict_types=1);

dmorley's avatar
dmorley committed
9
use Carbon\Carbon;
10
use Poduptime\PodStatus;
noplanman's avatar
noplanman committed
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.
David Morley's avatar
David Morley committed
19
$_action           = $_GET['action'] ?? '';
20
$_weight           = $_GET['weight'] ?? 10;
David Morley's avatar
David Morley committed
21 22
$_email            = $_GET['email'] ?? '';
$_podmin_statement = $_GET['podmin_statement'] ?? '';
23
$_podmin_notify    = $_GET['podmin_notify'] ?? 0;
24

noplanman's avatar
noplanman committed
25
require_once __DIR__ . '/../vendor/autoload.php';
26 27
require_once __DIR__ . '/../config.php';

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

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

noplanman's avatar
noplanman committed
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');
dmorley's avatar
dmorley 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');
dmorley's avatar
dmorley committed
58 59 60 61
}

// Un-Pause and exit.
if ('unpause' === $_action) {
62 63 64 65 66 67 68
    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
69
}
70

noplanman's avatar
noplanman committed
71 72
// Save and exit.
if ('save' === $_action) {
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    $_weight <= 10 || die('10 is max weight');

    try {
        $pod['email']            = $_email;
        $pod['weight']           = $_weight;
        $pod['podmin_statement'] = $_podmin_statement;
        $pod['podmin_notify']    = $_podmin_notify;

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

    $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));

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

noplanman's avatar
noplanman committed
95
// Forms.
dmorley's avatar
dmorley committed
96

noplanman's avatar
noplanman committed
97
?>
dmorley's avatar
dmorley committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
Authorized to edit <b><?php echo $_domain; ?></b> for <?php echo (new Carbon($pod['tokenexpire']))->diffForHumans(null, true); ?><br>
<form>
    <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>
    <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>
    <label>Notify if pod falls off the list? <input type="checkbox" name="podmin_notify" <?php echo $pod['podmin_notify'] ? 'checked' : ''; ?> ></label><br>
    <input type="submit" name="action" value="save">
</form>
<br>
<br>Your pod status is currently: <?php echo PodStatus::getKey((int) $pod['status']); ?>
<br>
<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">
    <input type="hidden" name="domain" value="<?php echo $_domain; ?>">
    <input type="hidden" name="token" value="<?php echo $_token; ?>">
    <input type="submit" name="action" value="unpause">
</form>
<button type="button" data-featherlight="/db/pull.php?debug=1&nowrite=1&domain=<?php echo $_domain; ?>">Do a debug test pull of your pod</button>