DisableBody(); } if (preg_match('$/([^/]+)/?([^/]+)?/?([^/]+)?/?([^/]+)?$', $_SERVER['PATH_INFO'] ?? "", $matches, PREG_UNMATCHED_AS_NULL)) { self::$route = $matches[1]; self::$id = $matches[2]; self::$subroute = $matches[3]; self::$subid = $matches[4]; } } public static function ParseInput() { // Clean input if (isset($_SERVER["CONTENT_TYPE"]) && "application/json"==$_SERVER["CONTENT_TYPE"]) { $input = self::cleanInput(json_decode(file_get_contents("php://input"), true)); if (!empty($input)) { self::$input = $input; } } else if (in_array(self::$method, ["HEAD", "GET"])) { self::$filter = isset($_GET["filter"]) ? self::cleanInput(json_decode($_GET["filter"], true)) : []; self::$selected = isset($_GET["selected"]) ? self::cleanInput(json_decode($_GET["selected"], true)) : []; self::$printID = isset($_GET["print"]) ? self::cleanInput($_GET["print"]) : null; self::$detailDepth = \Login::HasRight("ADMIN") && isset($_GET["depth"]) ? self::cleanInput($_GET["depth"]) : null; } } public static function VerifyInputSecToken($verifyToken) { if (!empty(self::$input) && (!isset(self::$input["secToken"]) || self::$input["secToken"]!=$verifyToken)) { //Response::Get()->Message("Wrong or Missing SecToken! Ignoring input."); //self::$input = []; } } public static function IsRoot() {return "/"==self::$route;} public static function IsServeClient() {return self::IsRoot() && "GET"==self::$method/* && "HTML"==self::$accept*/;} public static function IsLogout() {return self::IsRoot() && "DELETE"==self::$method;} public static function IsPrint() {return "HTML"==self::$accept && !is_null(self::$printID);} public static function DetailDepth() {return self::$detailDepth;} public static function IssueNewSecToken() {return in_array(self::$method, ["POST", "PATCH", "DELETE"]);} public static function AllowJwtRenewal() {return "HEAD"!=self::$method && "HTML"!=self::$accept;} /***** Private Static Functions *****/ private static function cleanInput($value) { // Cleans input if (is_null($value)) { return null; } else if (is_array($value)) { $ret = []; foreach ($value as $key => $element) { $ret[$key] = self::cleanInput($element); } return $ret; } else if (is_string($value)) { return DB::Get()->escape_string($value); } else { return intval($value); } } }