Example #1
0
 public static function get_instance()
 {
     if (empty(self::$instance)) {
         self::$instance = new ToroHook();
     }
     return self::$instance;
 }
<?php

require 'Helpers.php';
require 'DBase.php';
require 'Toro.php';
// Require all files in Logic folder
foreach (glob('Logic' . DIRECTORY_SEPARATOR . '*.php') as $file) {
    require $file;
}
ToroHook::add("404", function () {
    new Error("Route not found");
});
Toro::serve(array('/customer' => "Customer", '/customer/:number' => "Customer", '/customer/:number/cars' => "Car", '/customer/:number/cars/:number' => "Car", '/cars' => "Car", '/safetycheck' => "SafetyCheck", '/safetycheck/:number' => "SafetyCheck", '/service' => "Service", '/service/:number' => "Service", '/invoice' => "Invoice", '/invoice/:number' => "Invoice", '/item' => "Item", '/item/:number' => "Item", '/detail' => "Detail", '/detail/:number' => "Detail", '/payment' => "Payment", '/payment/:number' => "Payment"));
Example #3
0
 /**
  *  Autoaction
  *
  * @param string $var
  * @param string $httpMethod
  */
 protected function _autoaction($var, $httpMethod = 'get')
 {
     $method = $this->urlToActionName($var, $httpMethod);
     if (method_exists($this, $method)) {
         return $this->{$method}();
     } else {
         \ToroHook::fire('404', array("error" => "Controller " . get_class($this) . " does not contain {$method} action", "path_info" => $this->_pathInfo));
     }
 }
Example #4
0
/**
 * Hooks
 */
ToroHook::add("404", function ($vars = array()) {
    // error_log("vars: ".print_r($vars, true));
    if (empty($vars['message'])) {
        $vars['message'] = "Sorry, we cannot find that page.";
    }
    if (empty($vars['error'])) {
        $vars['error'] = $vars['message'];
    }
    if (!isset($vars['path_info'])) {
        $vars['path_info'] = "";
    }
    Erdiko::log(\Psr\Log\LogLevel::ERROR, "404 {$vars['path_info']} {$vars['error']}");
    // For a simple text only 404 page use this...
    // echo "Sorry, we cannot find that URL";
    // die; // don't let the calling controller continue
    // For a themed 404 page...
    $theme = new \erdiko\core\Theme('bootstrap');
    $theme->addCss('//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
    $theme->addCss('/themes/bootstrap/css/font-awesome-animation.css');
    $response = new \erdiko\core\Response($theme);
    $response->setContent(\Erdiko::getView('404', $vars));
    $response->send();
});
ToroHook::add("500", function ($vars = array()) {
    // error_log("vars: ".print_r($vars, true));
    Erdiko::log(\Psr\Log\LogLevel::ERROR, "500 {$vars['path_info']} {$vars['error']}");
    echo "Sorry, something went wrong";
});
Example #5
0
 /**
  * Oauth post handler.
  */
 public function post()
 {
     ToroHook::fire('405', "GET");
     // method not allowed
 }
Example #6
0
<?php

require "handlers/dashboard_handler.php";
require "handlers/receive_handler.php";
require "handlers/send_handler.php";
require "handlers/stats_handler.php";
require "lib/mysql.php";
require "lib/queries.php";
require "../../src/Toro.php";
ToroHook::add("404", function () {
    echo "Not found";
});
Toro::serve(array("/" => "DashboardHandler", "/send" => "SendHandler", "/receive" => "ReceiveHandler", "/stats" => "StatsHandler"));
Example #7
0
                }
            } else {
                //collector does not exist
                error_log('Invalid collector GUID:' . $request->collectorGUID . ' from IP ' . $_SERVER['REMOTE_ADDR'] . ' at ' . gethostbyaddr($_SERVER['REMOTE_ADDR']));
                //Create the response - return the current server time
                $response = array('serverResponse' => 'BAD_GUID', 'serverEpochTimestamp' => 0, 'serverAvailable' => false, 'collectorEnabled' => false, 'gmt_last_config_update' => 0);
            }
            //Send the response
            echo json_encode($response);
        }
    }
}
$base_dir = "/rest/";
ToroHook::add("404", function () {
    //echo json_encode(array("status"=>"ERROR: REST function not found!!"));
    error_log(__FILE__ . ':' . __LINE__ . ':php://input:' . file_get_contents('php://input'));
    error_log(__FILE__ . ':' . __LINE__ . ':404 REQUEST_URI not found:' . $_SERVER['REQUEST_URI']);
    header("Location: /");
});
Toro::serve(array($base_dir => "defaultHandler", $base_dir . "ping" => "ping", $base_dir . "get_new_device_id" => "get_new_device_id", $base_dir . "upload_drd_data" => "upload_drd_data", $base_dir . "get_collector_base_configuration" => "get_collector_base_configuration", $base_dir . "get_collector_device_configuration" => "get_collector_device_configuration", $base_dir . "get_device_data" => "get_device_data", $base_dir . "get_users_devices" => "get_users_devices", $base_dir . "get_device_params" => "get_device_params", $base_dir . "upload_log_file" => "upload_log_file", $base_dir . "get_event_log_data" => "get_event_log_data", $base_dir . "get_parent_collectors_for_user" => "get_parent_collectors_for_user"));
function check_and_clean_json($check_for_this_if_valid)
{
    //Get and clean the JSON data in the request
    $input = file_get_contents('php://input');
    //error_log(__FUNCTION__." Input: ".$input);
    //error_log(__FUNCTION__." Length of input: ".strlen($input));
    //$request = preg_replace('/.+?({.+}).+/','$1',$input);
    $request = $input;
    //error_log(__FUNCTION__.'Done preg_replace');
    //Decode the JSON received
    $request = json_decode($request);
    if (!$request->{$check_for_this_if_valid}) {
Example #8
0
    $response = new \erdiko\core\Response($theme);
    $response->setContent(\Erdiko::getView('error', $vars));
    $response->send();
});
ToroHook::add("500", function ($vars = array()) {
    // Toro::serve Legacy
    $vars['debug'] = \erdiko\core\ErrorHandler::isDebug();
    $vars['code'] = 500;
    $vars['message'] = "Sorry, something went wrong.";
    Erdiko::log(\Psr\Log\LogLevel::ERROR, "{$vars['code']}: {$vars['path_info']} {$vars['error']}");
    $theme = new \erdiko\core\Theme('bootstrap');
    $theme->addCss('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
    $theme->addCss('font-awesome-animation', '/themes/bootstrap/css/font-awesome-animation.css');
    $response = new \erdiko\core\Response($theme);
    $response->setContent(\Erdiko::getView('error', $vars));
    $response->send();
});
// Error management & beautify output.
ToroHook::add("general_error", function ($vars = array()) {
    $vars['debug'] = \erdiko\core\ErrorHandler::isDebug();
    if (!isset($vars['path_info'])) {
        $vars['path_info'] = $_SERVER['REQUEST_URI'];
    }
    Erdiko::log(\Psr\Log\LogLevel::ERROR, "{$vars['code']}: {$vars['path_info']} {$vars['error']}");
    $theme = new \erdiko\core\Theme('bootstrap');
    $theme->addCss('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
    $theme->addCss('font-awesome-animation', '/themes/bootstrap/css/font-awesome-animation.css');
    $response = new \erdiko\core\Response($theme);
    $response->setContent(\Erdiko::getView('error', $vars));
    $response->send();
});
Example #9
0
<?php

session_start();
define("VERSION", "0.3.9");
define("_LOG_COUNT_MAX_", 20);
date_default_timezone_set('UTC');
require_once 'system/Toro.php';
require_once 'system/classes.php';
require_once 'system/statusreturn.php';
require_once 'system/simple_html_dom.php';
require_once 'system/sitemaps.php';
ToroHook::add("404", function () {
    echo json_encode(StatusReturn::E404('404 Not Found!!'), JSON_NUMERIC_CHECK);
});
ToroHook::add("404Web", function () {
    include_once '404.html';
});
Toro::serve(array('/admin/' => 'Init', '/login/' => 'Login', '/logout/' => 'Logout', '/dash/' => 'Dashboard', '/logs/' => 'Logs', '/nav/' => 'Nav', '/nav/update/' => 'Nav', '/footer/' => 'Footer', '/footer/update/' => 'Footer', '/settings/' => 'Settings', '/settings/update/' => 'Settings', '/analytics/' => 'Analytics', '/analytics/update/' => 'Analytics', '/media/' => 'Media', '/media/update/' => 'Media', '/blog/' => 'Blog', '/blog/:alpha/:string/' => 'BlogPost', '/blog/:alpha/' => 'BlogPost', '/dash/:alpha/' => 'Dashboard', '/page/:alpha/' => 'Pages', '/page/:alpha/update/' => 'Pages', '/page/:alpha/desc/' => 'Description', '/page/:alpha/repeat/:key/' => 'Repeat', '/page/:alpha/repeat/:key/update/' => 'Repeat', '/page/:alpha/repeat-dup/:key/:number/' => 'RepeatDup', '/page/:alpha/repeat-del/:key/:number/' => 'RepeatDel'));
Example #10
0
 public function serve()
 {
     ToroHook::fire('before_request');
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $path_info = '/';
     $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $path_info;
     $path_info = isset($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : $path_info;
     $discovered_handler = NULL;
     $regex_matches = array();
     $method_arguments = NULL;
     foreach ($this->_handler_route_pairs as $handler) {
         list($pattern, $handler_name) = $handler;
         if ($path_info == $pattern) {
             $discovered_handler = $handler_name;
             $regex_matches = array($path_info, preg_replace('/^\\//', '', $path_info));
             $method_arguments = $this->get_argument_overrides($handler);
             break;
         } else {
             $pattern = str_replace('/', '\\/', $pattern);
             if (preg_match('/^\\/' . $pattern . '\\/?$/', $path_info, $matches)) {
                 $discovered_handler = $handler_name;
                 $regex_matches = $matches;
                 $method_arguments = $this->get_argument_overrides($handler);
                 break;
             }
         }
     }
     if ($discovered_handler && class_exists($discovered_handler)) {
         unset($regex_matches[0]);
         $handler_instance = new $discovered_handler();
         if (!$method_arguments) {
             $method_arguments = $regex_matches;
         }
         // XHR (must come first), iPad, mobile catch all
         if ($this->xhr_request() && method_exists($discovered_handler, $request_method . '_xhr')) {
             header('Content-type: application/json');
             header('Pragma: no-cache');
             header('Cache-Control: no-cache, must-revalidate');
             header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
             $request_method .= '_xhr';
         } else {
             if ($this->ipad_request() && method_exists($discovered_handler, $request_method . '_ipad')) {
                 $request_method .= '_ipad';
             } else {
                 if ($this->mobile_request() && method_exists($discovered_handler, $request_method . '_mobile')) {
                     $request_method .= '_mobile';
                 }
             }
         }
         ToroHook::fire('before_handler');
         call_user_func_array(array($handler_instance, $request_method), $method_arguments);
         ToroHook::fire('after_handler');
     } else {
         header('HTTP/1.0 404 Not Found');
         echo '404 Not Found';
         exit;
     }
     ToroHook::fire('after_request');
 }
Example #11
0
<?php

/**
 * This is the index file and it all starts here.
 * 
 * 
 * @package = Scrawler
 * @author = Pranjal Pandey
 * 
 */
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
require_once __DIR__ . '/Scrawler/start.php';
// Temporary ugly error handling for our engine
ToroHook::add("404", function () {
    echo "Scrawler error : page you are trying to load not found";
});
ToroHook::add("403", function () {
    echo "Scrawler error : page you are trying to load not found";
});
Example #12
0
 /**
  * Adds a hook. Maps to ToroHook::add
  *
  * @see ToroHook
  *
  * @param string $hookName Name of hook
  * @param callable $callable
  */
 static function hook($hookName, $callable)
 {
     \ToroHook::add($hookName, $callable);
 }
Example #13
0
        if ($request != null) {
            foreach ($allowed_array as $guid => $server) {
                error_log('$server: ' . print_r($server, true));
                if ($request->collectorGUID == $guid) {
                    $response = array('URL' => $server['URL'], 'LoggingLevel' => $server['LoggingLevel']);
                    //Send the response
                    echo json_encode($response);
                }
            }
            //If no matching GUID, echo nothing
        }
    }
}
ToroHook::add("404", function () {
    echo json_encode(array("status" => "ERROR: REST function not found!! getserverurl:"));
    error_log('404 REQUEST_URI not found:' . $_SERVER['REQUEST_URI']);
    error_log(file_get_contents('php://input'));
});
$base_dir = "/init_REST/";
Toro::serve(array($base_dir => "defaultHandler", "/init_REST/get_server_url" => "get_server_url", "/init_REST/get_server_url2" => "get_server_url2"));
function check_and_clean_json($check_for_this_if_valid)
{
    //Get and clean the JSON data in the request
    $input = file_get_contents('php://input');
    //error_log(__FUNCTION__." Input: ".$input);
    //error_log(__FUNCTION__." Length of input: ".strlen($input));
    //$request = preg_replace('/.+?({.+}).+/','$1',$input);
    $request = $input;
    //error_log(__FUNCTION__.'Done preg_replace');
    //Decode the JSON received
    $request = json_decode($request);
Example #14
0
 public function route_hook($type, $f)
 {
     \ToroHook::add($type, $f);
 }
Example #15
0
<?php

require "handlers/publishHandler.php";
require "handlers/viewHandler.php";
require "lib/mysql.php";
require "lib/queries.php";
require "lib/Toro.php";
ToroHook::add("404", function () {
    header("HTTP/1.0 404 Not Found");
    echo "This isn't the Page you're looking for.";
    exit;
});
Toro::serve(array("/" => "ViewHandler", "/publish/:string" => "PublishHandler", "/view" => "ViewHandler"));