コード例 #1
0
ファイル: alert.php プロジェクト: kaihendry/myresponder
function alert($id)
{
    $ts = time();
    echo "<h3>Time now: " . date("c") . "</h3>";
    if (!file_exists("../m/arm/{$id}")) {
        echo "<p>Your alert was un-armed. No guards were alerted. <a href=mailto:" . getenv("M_EMAIL") . ">Email admin to ask to be ARMED, which sends SMSes out to all responders/guards on duty.</a></p>";
    } else {
        echo "<p>Raising alert to all responders on duty:</p>";
    }
    $alog = "r/{$id}/alert/" . $ts . ".json";
    @mkdir(dirname($alog), 0777, true);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    echo "<ul>";
    $guards = array();
    foreach (glob("../g/r/*.json") as $gj) {
        $g = json_decode(file_get_contents($gj), true);
        // We need both home owner and guard to be armed to get the SMS
        if (file_exists("../m/arm/{$id}") && file_exists("../m/arm/" . $g["ic"])) {
            echo "<li>Alerting " . $g["name"] . " on <a href=\"tel:" . $g["tel"] . "\">" . $g["tel"] . "</a></li>";
            $result = sms(my_number($g["tel"]), "⚠" . $_SESSION["address"] . " tel:" . $_SESSION["tel"] . " " . $_SESSION["name"] . " at " . date("c", $ts));
        } else {
            echo "<li><s>UNARMED: Not alerting " . $g["name"] . " on <a href=\"tel:" . $g["tel"] . "\">" . $g["tel"] . "</a></s></li>";
            unset($result);
        }
        array_push($guards, array("result" => $result, "name" => $g["name"], "ic" => $g["ic"]));
    }
    echo "</ul>";
    curl_close($ch);
    file_put_contents($alog, je(array("ts" => $ts, "guards" => $guards, "raiser" => $_SESSION)));
    if (empty($result)) {
        sesmail($_SESSION["email"], "UNARMED Alert triggered for " . $_SESSION["name"], "Telephone number: " . $_SESSION["tel"] . "\nAlert details: https://h." . getenv('HOST') . "/adisplay/?j=/{$alog}");
    } else {
        sesmail($_SESSION["email"], "ARMED Alert triggered for " . $_SESSION["name"], "Telephone number: " . $_SESSION["tel"] . "\nAlert details: https://h." . getenv('HOST') . "/adisplay/?j=/{$alog}");
    }
    // Now mute until management lift it
    @unlink("../m/arm/{$id}");
}
コード例 #2
0
ファイル: clockin.php プロジェクト: kaihendry/myresponder
        echo '<h1>Welcome ' . e($_SESSION["name"]) . '</h1>';
    }
}
if (file_exists($p)) {
    echo "<p>On call</p>";
    echo "<p>" . display($p) . "</p>";
} else {
    echo "<p>Putting you on call</p>";
    // Clock in
    $ci = $_SESSION;
    $ci["intime"] = time();
    // Save server info (might be useful)
    $ci["sin"] = $_SERVER;
    file_put_contents($p, json_encode($ci, JSON_PRETTY_PRINT));
    try {
        $msgid = sesmail("", "Responder " . $_SESSION["name"] . " registered for duty", "https://g." . getenv('HOST') . "/" . $p);
        echo "<p>Notified admin, reference: " . $msgid . "</p>";
    } catch (Exception $e) {
        die("<h1>ERROR</h1><pre>" . $e->getMessage() . "\n");
    }
    echo "<p>" . display($p) . "</p>";
}
?>

<h1><a href=/clockout.php>Clock out</a></h1>

<h3>Previous clock outs</h3>
<ul>
<?php 
$history = glob($rdir . "/*.json");
rsort($history);