Exemplo n.º 1
0
 public static function load($in_type_name)
 {
     /* determine and sanitise the type and name */
     $parts = explode('/', str_replace('.', '', substr($in_type_name, 0, 1024)));
     if (count($parts) != 2) {
         CinsImpError::malformed('Plugin type-name must be of form: <type>/<name>');
     }
     $type = $parts[0] . 's';
     $name = $parts[1];
     unset($parts);
     /* load the main plugin definition file */
     global $config;
     $plugin_base = $config->base . 'plugins/' . $type . '/' . $name . '/';
     $plugin_file_path = $plugin_base . $name . '.js';
     if (!file_exists($plugin_file_path)) {
         CinsImpError::missing('Plugin', $plugin_file_path);
     }
     $plugin_file = file_get_contents($plugin_file_path);
     /* output the file to the requestor */
     Util::response_is_ajax_only();
     print $plugin_file;
 }
Exemplo n.º 2
0
 public static function handle_request()
 {
     global $g_error_log;
     global $config;
     /* handle debug test mode; ?io=test */
     $debug = false;
     if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == true) {
         $debug = true;
     }
     if (!$config->debug && $debug) {
         Util::respond_with_http_error(403, 'Forbidden');
     }
     if ($_REQUEST['io'] == 'test') {
         $debug = true;
         if (!$config->debug && $debug) {
             Util::respond_with_http_error(403, 'Forbidden');
         }
         Gateway::print_test_form('');
         exit;
     }
     /* normal processing of AJAX request */
     Util::response_is_ajax_only();
     /* log errors with custom handler and process at conclusion of request */
     //set_error_handler(array('Gateway', 'custom_error_handler'));
     /* in testing, it may be useful to be able to submit a request in this way */
     if (isset($_REQUEST['request'])) {
         $inbound = $_REQUEST['request'];
     } else {
         $inbound = '';
     }
     /* invoke the method as specified in the cmd field of the request */
     $outbound = array();
     try {
         if ($inbound != '') {
             $inbound = json_decode($inbound, true);
         } else {
             $inbound = json_decode(@file_get_contents('php://input'), true);
         }
         if ($inbound === null) {
             CinsImpError::malformed('JSON input malformed');
         }
         $outbound['cmd'] = $inbound['cmd'];
         try {
             $action_method = new ReflectionMethod('Gateway', $inbound['cmd']);
         } catch (Exception $err) {
             throw new Exception("Gateway: Command " . $inbound['cmd'] . " unrecognised.");
         }
         $outbound = $action_method->invoke(null, $inbound, $outbound);
     } catch (Exception $err) {
         $err = new CinsImpError($err);
         $outbound = array();
         $outbound['cmd'] = 'error';
         $outbound['msg'] = 'Server: ' . $err->getMessage() . ': ' . $err->getDetail();
         $outbound['cde'] = $err->getID();
     }
     /* if we're debugging the gateway, output the response on the test form,
     		otherwise send a standard JSON response */
     if ($debug) {
         Gateway::print_test_form(json_encode($outbound, JSON_PRETTY_PRINT));
     } else {
         header('Content-type: application/json');
         print json_encode($outbound);
     }
 }
Exemplo n.º 3
0
 public static function keys_required(&$in_array, $in_keys)
 {
     if (!is_array($in_array)) {
         CinsImpError::malformed('Input is not an array');
     }
     foreach ($in_keys as $key) {
         if (!array_key_exists($key, $in_array)) {
             CinsImpError::malformed('"' . $key . '" missing from request');
         }
     }
 }
Exemplo n.º 4
0
 public function zap_all_cards()
 {
     CinsImpError::unimplemented();
     // UNTIL REFACTORED, DISABLED
     $this->stack_will_be_modified();
     $stmt = $this->file_db->prepare('DELETE FROM card');
     Stack::sl_ok($stmt, $this->file_db, 'Deleting All Cards (1)');
     $rows = $stmt->execute();
     Stack::sl_ok($rows, $this->file_db, 'Deleting All Cards (2)');
     $stmt = $this->file_db->prepare('DELETE FROM bkgnd');
     Stack::sl_ok($stmt, $this->file_db, 'Deleting All Cards (3)');
     $rows = $stmt->execute();
     Stack::sl_ok($rows, $this->file_db, 'Deleting All Cards (4)');
 }
Exemplo n.º 5
0
    	Handles the upload of a HyperCard stack and initial preparation for the import
    	of it's content, structure and art in co-operation with the client.
    */
    if (isset($_REQUEST['hcimport'])) {
        Util::response_is_ajax_only();
        require $config->base . 'php/hcimport.php';
        HCImport::handle_upload();
        exit;
    }
    /*
    	Returns a static page for the specified stack, along with appropriate data and
    	instructions to invoke the client-side application if the environment is sufficient.
    
    	The static page is search-engine-friendly.
    */
    if (isset($_REQUEST['stack'])) {
        require $config->base . 'php/application.php';
        Application::open_stack();
        exit;
    }
} catch (Exception $err) {
    if (!is_a($err, 'CinsImpError')) {
        $err = new CinsImpError($err);
    }
    Util::respond_with_http_error($err->getID(), $err->getMessage(), $err->getDetail());
    exit;
}
/*
	If the request is anything else, the client has err'd.
*/
Util::respond_with_http_error(400, 'Bad Request');