コード例 #1
0
 /**
  * 	method:	recv
  *
  * 	todo: write documentation
  */
 public static function recv()
 {
     $base64 = Amslib_GET::get("encrypted");
     if (!$base64) {
         self::reply(false, "missing 'encrypted' parameter");
     }
     $encrypted = base64_decode($base64);
     $decrypted = AesCtr::decrypt($encrypted, self::getPassword());
     try {
         $json = json_decode($decrypted, true);
     } catch (Exception $e) {
         //	do nothing
         Amslib_Debug::log("Exception whilst json_decoding content");
     }
     if (!isset($json) || !$json || !isset($json["check"])) {
         self::reply(false, "invalid data");
     }
     if ($json["check"] != self::getCheck()) {
         self::reply(false, "check compare failed");
     }
     unset($json["check"]);
     //	TODO:	the sender might have posted an actual file, so we need to maybe check this and
     //			provide the file data from the $_FILES array
     return $json;
 }
コード例 #2
0
ファイル: Amslib_Router.php プロジェクト: hakosh/amslib
 /**
  * 	method:	initialise
  *
  * 	todo: write documentation
  */
 public static function initialise()
 {
     if (self::$is_initialised) {
         return;
     }
     $search = array_merge($_SERVER, $_GET);
     self::$pathList["__WEBSITE_ROOT__"] = $search["__WEBSITE_ROOT__"];
     self::$path = NULL;
     self::$base = self::getPath("__WEBSITE_ROOT__");
     if (self::$base) {
         //	Obtain the path within the website, without the website base
         //	we use this to calculate the path inside the website, not relative to the document root
         self::$path = Amslib_String::lchop($_SERVER["REQUEST_URI"], self::$base);
         self::$path = Amslib_String::rchop(self::$path, "?");
         self::$path = Amslib_File::reduceSlashes("/" . self::$path . "/");
     }
     //	Now automatically load the amslib routers configuration as the framework system
     //	This allows amslib to add routes the system can use to import/export router configurations
     //	This isn't part of your application, this is part of the system and used to self-configure
     self::load(Amslib::locate() . "/router/router.xml", "xml", "framework");
     self::$is_initialised = true;
     //	remove this from the $_GET superglobal, it's kind of annoying to keep finding it in the application code
     Amslib_GET::delete("__WEBSITE_ROOT__");
 }
コード例 #3
0
ファイル: Amslib_Website.php プロジェクト: hakosh/amslib
 /**
  * 	method:	outputJSON
  *
  * 	todo: write documentation
  *
  * 	note: I hate this function name, I think we should change it to something more elegant
  */
 public static function outputJSON($array, $block = true)
 {
     header("Cache-Control: no-cache");
     header("Content-Type: application/json");
     //	NOTE: perhaps it would be nice to limit this CORS header in the future
     if (isset($_SERVER["HTTP_ORIGIN"])) {
         $origin = $_SERVER["HTTP_ORIGIN"];
         header("Access-Control-Allow-Origin: {$origin}");
         header("Access-Control-Allow-Credentials: true");
     }
     $json = json_encode($array);
     //	if there is a callback specified, wrap up the json into a jsonp format
     $jsonp = Amslib_GET::get("callback");
     if ($jsonp) {
         $json = "{$jsonp}({$json})";
     }
     Amslib_Benchmark::log();
     if ($block === true) {
         die($json);
     }
     if ($block === false) {
         print $json;
     }
     return $json;
 }