Beispiel #1
0
function checkFile($path, $first = true)
{
    $pattern = "/^(.*)-((?:\\d+)\\.(?:\\d+))\$/";
    if (preg_match($pattern, $path, $matches)) {
        if (checkFileVersion($matches[1], $matches[2])) {
            // If it's a version, then don't check for full path
            // below...
            return;
        }
    }
    $fod = KTBrowseUtil::folderOrDocument($path);
    if ($fod === false) {
        $GLOBALS['aFilesToRemove'][] = $path;
        return;
    }
}
Beispiel #2
0
function checkFlags()
{
    global $config;
    logMessage("Checking remote Flags");
    $post = array('action' => 'getFlags', 'PID' => $config->PID);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $config->serverurl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    logMessage("Got result: " . $result);
    $jsonout = json_decode($result);
    if ($jsonout->takePic == 1) {
        logMessage("Taking pic, say cheese!");
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/0/action/snapshot");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        curl_close($ch);
        sleep(3);
        // just a little delay to take the pic
        uploadNewPics();
    }
    if ($jsonout->changeSettings == 1) {
        changeSettings();
    }
    if (count($jsonout->needPics) > 0) {
        foreach ($jsonout->needPics as $PicID) {
            uploadOnePic($PicID);
        }
    }
    if ($jsonout->takePic || $jsonout->changeSettings || $jsonout->forceReboot) {
        resetFlags();
    }
    foreach ($jsonout->Files as $filename => $version) {
        if (checkFileVersion($filename) < $version) {
            loadNewFile($filename);
            if (basename($filename) == 'interact.php') {
                $str = "/usr/bin/php {$filename}";
                $pidfile = "/dev/shm/naboor.pid";
                exec(sprintf("%s > %s 2>&1 & echo \$! >> %s", $str, "/dev/null", $pidfile));
                die;
            } elseif (basename($filename) == 'parsejson.php') {
                if (is_file("/dev/shm/upload/parsejson.pid")) {
                    $pid = file_get_contents("/dev/shm/upload/parsejson.pid");
                    exec("kill {$pid}");
                    checkParseJsonRunning();
                }
            }
        }
    }
    if (property_exists($jsonout, "command")) {
        //TODO:execute command and upload results to server
    }
    if (property_exists($jsonout, "mayday") && $jsonout->mayday == 1) {
        //TODO:open SSH session
    }
    if ($jsonout->forceReboot == 1) {
        //TODO:Dan, add some code here
        $str = "shutdown -h now";
        exec(sprintf("%s > %s 2>&1 & echo \$! >> %s", $str, "/dev/null", $pidfile));
        die;
        //should never get here
    }
}