Esempio n. 1
0
function get_node_or_exit($node_role)
{
    if (!isset($_REQUEST[$node_role])) {
        exit_with_error_json("The request did not include a " . $node_role . " node.");
    }
    $node = $_REQUEST[$node_role];
    exit_on_bad_node_name($node);
    if (!is_dir(NODE_PATH . $node)) {
        exit_with_error_json("The requested " . $node_role . " node, " . $node . ", does not exist.");
    }
    return $node;
}
Esempio n. 2
0
    }
}
//end of function compare_timestamps
//Check whether the request includes a source from which to copy.
if (isset($_REQUEST[SOURCES])) {
    $sources_string = $_REQUEST[SOURCES];
    $sources = json_decode($sources_string, TRUE);
    //TRUE->force to associative array
    if ($sources === FALSE) {
        exit_with_error_json("Attempt to parse sources " . $sources_string . " failed: " . json_last_error());
    }
    //echo("sources:<br/>");
    //print_r($sources);
    //echo("<br/>");
    foreach ($sources as $source_name => $cutoff) {
        exit_on_bad_node_name($source_name);
        $source_edit_history_path = EDIT_HISTORY_PATH . $source_name;
        //Check that a view with this name exists.
        if (!is_file($source_edit_history_path)) {
            exit_with_error_json("The edit history file \"" . $source_edit_history_path . "\" does not exist.");
        }
        //Read in the contents.
        $source_edits_string = file_get_contents($source_edit_history_path);
        if ($source_edits_string === FALSE) {
            $fgc_error = error_get_last();
            exit_with_error_json("Attempt to read file " . $source_edit_history_path . " failed: " . $fgc_error['message']);
        }
        //Parse the JSON.
        $source_edits = json_decode($source_edits_string, TRUE);
        //TRUE->force to associative array
        if ($source_edits === FALSE) {
Esempio n. 3
0
<?php

//SUMMARY: Given an HTTP request with the name of a view, deletes that view.
require_once 'includes/consts.php';
require_once 'includes/exit_with_error_json.php';
require_once 'includes/exit_on_bad_node_name.php';
//Check that the request includes a name.
if (!isset($_REQUEST[NAME])) {
    exit_with_error_json("The request did not contain a view name.");
}
//end of if no name provided
$name = $_REQUEST[NAME];
//We hold views to the same naming conventions as we do nodes.
exit_on_bad_node_name($name);
$view_path = VIEW_PATH . $name . VIEW_FILE_TYPE;
if (!unlink($view_path)) {
    $unlink_error = error_get_last();
    exit_with_error_json("Deletion of file \"" . $view_path . "\" failed: " . $unlink_error['message']);
}
exit(json_encode(array('success' => TRUE)));
Esempio n. 4
0
//reminder: @ suppresses error output from an expression.
//designed to work with EventSource JavaScript API based on
//https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events
require_once 'includes/consts.php';
require_once 'includes/exit_with_error_json.php';
require_once 'includes/exit_on_bad_node_name.php';
header("Content-Type: text/event-stream\n\n");
header("Cache-Control: no-cache\n\n");
//Check for the view name.
if (isset($_REQUEST[VIEW])) {
    $view = $_REQUEST[VIEW];
} else {
    exit_with_error_json("The request did not contain a view name.");
}
//We hold views to the same naming conventions as we do nodes.
exit_on_bad_node_name($view);
$edit_history_path = EDIT_HISTORY_PATH . $view;
//Check for the edit count.
if (isset($_REQUEST[UPDATE_COUNT])) {
    $update_count = $_REQUEST[UPDATE_COUNT];
} else {
    $update_count = 0;
}
//receiveupdate.php does not seem to be able to read messages from the queue for some reason.
//$listener_id_queue_key = ftok(UPDATE_QUEUE_PATH.$view.UPDATE_QUEUE_SUFFIX, UPDATE_LISTENER_PROJECT_IDENTIFIER);
//$listener_id_queue = msg_get_queue($listener_id_queue_key);
//$update_count_queue_key = ftok(UPDATE_QUEUE_PATH.$view.UPDATE_QUEUE_SUFFIX, UPDATE_COUNT_PROJECT_IDENTIFIER);
//$update_count_queue = msg_get_queue($update_count_queue_key);
////Use this ID as the message type for which to listen so we only get messages intended for this instance:
//$message_listener_id = mt_rand( UPDATE_LISTENER_ID_MESSAGE_TYPE+1, mt_getrandmax() );
//$message_type_received = NULL;