Esempio n. 1
0
    $datablob = isset($_GET['datablob']) ? $sqliconn->escapestring(htmlspecialchars($_GET['datablob'])) : '';
}
// POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $post = json_decode(file_get_contents('php://input'), true);
    $type = isset($post['type']) ? $sqliconn->escapestring(htmlspecialchars($post['type'])) : '';
    $location = isset($post['location']) ? $sqliconn->escapestring(htmlspecialchars($post['location'])) : die;
    $source = isset($post['source']) ? $sqliconn->escapestring(htmlspecialchars($post['source'])) : '';
    $method = isset($post['method']) ? $sqliconn->escapestring(htmlspecialchars($post['method'])) : 'unknown-web-POST';
    $info = isset($post['info']) ? $sqliconn->escapestring(htmlspecialchars($post['info'])) : '';
    $imgblob = isset($post['imgblob']) ? $sqliconn->escapestring(htmlspecialchars($post['imgblob'])) : '';
    //base64_decode(rawurldecode(
    $datablob = isset($post['datablob']) ? $sqliconn->escapestring(htmlspecialchars($post['datablob'])) : '';
}
// update database
$sql = "INSERT INTO events (uuid, type, location, source, time, method, info, imgblob, datablob) VALUES ('{$uuid}', '{$type}', '{$location}', '{$source}', '{$currenttime}', '{$method}', '{$info}', '{$imgblob}', '{$datablob}')";
//var_dump( $sql );
if ($sqliconn->query($sql) === TRUE) {
    // fire state updater
    $trigger = new Trigger();
    $trigger->update_state_on_event($sqliconn, $uuid, $type, $location, $source, $method, $currenttime);
    if ($type == "motion") {
        $trigger->intruder_check($sqliconn, $uuid, $type, $location, $source, $method, $currenttime);
    }
    //http_response_code(200);
    //echo "all grand";
} else {
    //http_response_code(418);
    echo "Error updating record: test";
    // . $sqliconn->error;
}