function main() { while (1) { echo "#WAKEUP\n"; $conn = get_conn(); if (!$conn) { log_and_die(mysqli_connect_error()); } $sql = "select mview_id from flexviews.mview_compute_schedule where unix_timestamp(now()) - unix_timestamp(last_computed_at) > compute_interval_seconds"; $stmt = mysqli_query($conn, $sql); if (!$stmt) { log_and_die(mysqli_error($conn)); } echo "#Delta computation phase starting\n"; while ($row = mysqli_fetch_assoc($stmt)) { $pid = pcntl_fork(); echo "#Spawning a child for {$row['mview_id']}\n"; if ($pid == 0) { refresh_mview($row['mview_id'], 'COMPUTE'); exit; } else { $childCount++; } } mysqli_close($conn); while ($childCount) { pcntl_wait($status); --$childCount; echo "#{$childCount} children remain\n"; } $conn = get_conn(); $sql = "select mview_id from flexviews.mview_apply_schedule where unix_timestamp(now()) - unix_timestamp(last_applied_at) > apply_interval_seconds"; $stmt = mysqli_query($conn, $sql); if (!$stmt) { log_and_die(mysqli_error($conn)); } echo "#Delta application phase starting\n"; while ($row = mysqli_fetch_assoc($stmt)) { $pid = pcntl_fork($status); echo "#Spawning a child for {$row['mview_id']}\n"; if ($pid == 0) { refresh_mview($row['mview_id'], 'APPLY'); exit; } else { $childCount++; } } mysqli_close($conn); while ($childCount) { pcntl_wait($status); --$childCount; echo "#{$childCount} children remain\n"; } sleep(60); } }
/** Returns the destination folder path if valid, die otherwise * * creates the folder if non-existent. */ function validate_folder($folder) { global $dirname; // Checks if the selected folder is a child of the photos dir. if (fileinode(parentdir(parentdir($folder))) == fileinode($dirname)) { if (file_exists($folder)) { if (!is_dir($folder)) { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "' . $folder . ' is not a folder."}, "id" : "id"}'); } if (!is_writable($folder)) { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "' . $folder . ' is not writable."}, "id" : "id"}'); } } else { if (!mkdir($folder, 0744, true)) { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Unable to create ' . $folder . '."}, "id" : "id"}'); } } } else { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Illegal destination folder, ' . $folder . ' is not a child of ' . $dirname . '"}, "id" : "id"}'); } return $folder; }
pi_log("CORS skipped, unknown HTTP_ORIGIN"); //pi_log("CORS allowed: " . join(',', $AUTHORIZED_HOSTNAMES)); } // Otherwise probably same origin... out of the scope of CORS session_start(); // Check CSRF token // Credit: http://php.net/manual/en/function.hash-equals.php#119576 if (!function_exists('hash_equals')) { function hash_equals($known_string, $user_string) { $ret = 0; if (strlen($known_string) !== strlen($user_string)) { $user_string = $known_string; $ret = 1; } $res = $known_string ^ $user_string; for ($i = strlen($res) - 1; $i >= 0; --$i) { $ret |= ord($res[$i]); } return !$ret; } } if (!isset($_SESSION['token'], $_POST['token']) || !hash_equals($_SESSION['token'], $_POST['token'])) { log_and_die("Wrong token"); } if (isset($_POST['domain'])) { $validDomain = is_valid_domain_name($_POST['domain']); if (!$validDomain) { log_and_die($_POST['domain'] . ' is not a valid domain'); } }