示例#1
0
 public function listen()
 {
     if (Insight_Util::getRequestHeader('x-insight') != 'transport') {
         return false;
     }
     $payload = $_POST['payload'];
     if (get_magic_quotes_gpc()) {
         $payload = stripslashes($payload);
     }
     $payload = Insight_Util::json_decode($payload);
     $file = $this->getPath($payload['key']);
     if (file_exists($file)) {
         readfile($file);
         // delete old files
         // TODO: Only do this periodically
         $time = time();
         foreach (new DirectoryIterator($this->getBasePath()) as $fileInfo) {
             if ($fileInfo->isDot()) {
                 continue;
             }
             if ($fileInfo->getMTime() < $time - self::TTL) {
                 unlink($fileInfo->getPathname());
             }
         }
     }
     return true;
 }
示例#2
0
 public function onMessageReceived(Wildfire_Message $message)
 {
     $data = Insight_Util::json_decode($message->getData());
     if (isset($data['authkey'])) {
         if (!isset($this->data['authkeys'])) {
             $this->data['authkeys'] = array();
         }
         $this->data['authkeys'][] = $data['authkey'];
     }
     if (isset($data['receivers'])) {
         if (!isset($this->data['receivers'])) {
             $this->data['receivers'] = array();
         }
         $this->data['receivers'] = array_merge($this->data['receivers'], $data['receivers']);
         array_unique($this->data['receivers']);
     }
 }
示例#3
0
 protected function loadCredentials($file)
 {
     if (!file_exists($file)) {
         return false;
     }
     try {
         $credentials = Insight_Util::json_decode(file_get_contents($file));
         if (!$credentials) {
             throw new Exception();
         }
     } catch (Exception $e) {
         throw new Exception('Error (' . $this->getJsonError($file) . ') parsing JSON file "' . $file . '". You can validate this file at http://www.jsonlint.com/ to find any errors.');
     }
     $credentials = $this->normalizeCredentials($credentials);
     if (isset($credentials[self::CONFIG_META_URI])) {
         $this->config['implements'][self::CONFIG_META_URI] = Insight_Util::array_merge($this->config['implements'][self::CONFIG_META_URI], $credentials[self::CONFIG_META_URI], 'S');
     }
     return true;
 }
示例#4
0
 public function listen()
 {
     if (Insight_Util::getRequestHeader('x-insight') == 'serve' || isset($_GET['x-insight']) && $_GET['x-insight'] == 'serve') {
         // we can respond
     } else {
         return false;
     }
     //        try {
     $response = false;
     if (isset($_POST['payload'])) {
         $payload = $_POST['payload'];
         if (get_magic_quotes_gpc()) {
             $payload = stripslashes($payload);
         }
         try {
             $response = $this->respond(Insight_Util::json_decode($payload));
         } catch (Exception $e) {
             $response = array('type' => 'error', 'status' => 500);
         }
     } else {
         if (sizeof($_GET) > 0) {
             // TODO: Implement fetching via GET
         }
     }
     if (!$response) {
         header("HTTP/1.0 204 No Content");
         header("Status: 204 No Content");
     } else {
         if (is_string($response)) {
             echo $response;
         } else {
             switch ($response['type']) {
                 case 'error':
                     header("HTTP/1.0 " . $response['status']);
                     header("Status: " . $response['status']);
                     break;
                 case 'json':
                     header("Content-Type: application/json");
                     echo Insight_Util::json_encode($response['data']);
                     break;
                 default:
                     echo $response['data'];
                     break;
             }
         }
     }
     /*
             } catch(Exception $e) {
                 throw $e;
                 header("HTTP/1.0 500 Internal Server Error");
                 header("Status: 500 Internal Server Error");
     
                 echo($e->getMessage());
     
                 // TODO: Log error to insight client
             }
     */
     return true;
 }
示例#5
0
 /**
  * Cache for client key + url
  */
 public function getFromClientUrlCache($name, $decode = true)
 {
     $file = $this->cachePathForName($name, 'clienturl');
     if (!file_exists($file)) {
         return false;
     }
     if (!$decode) {
         return file_get_contents($file);
     }
     return Insight_Util::json_decode(file_get_contents($file));
 }