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; }
public function getClientInfo() { if (php_sapi_name() == 'cli') { return false; } static $_cached_info = false; if ($_cached_info !== false) { return $_cached_info; } // Check if insight client is installed if (@preg_match_all('/^http:\\/\\/registry.pinf.org\\/cadorn.org\\/wildfire\\/@meta\\/protocol\\/announce\\/([\\.\\d]*)$/si', Insight_Util::getRequestHeader("x-wf-protocol-1"), $m) && version_compare($m[1][0], '0.1.0', '>=')) { return $_cached_info = array("client" => "insight", "authkeys" => $this->getAnnounceReceiver()->getAuthkeys(), "receivers" => $this->getAnnounceReceiver()->getReceivers()); } else { // Check if FirePHP is installed on client via User-Agent header if (@preg_match_all('/\\sFirePHP\\/([\\.\\d]*)\\s?/si', $this->getUserAgent(), $m) && version_compare($m[1][0], '0.0.6', '>=')) { return $_cached_info = array("client" => "firephp"); } else { // Check if FirePHP is installed on client via X-FirePHP-Version header if (@preg_match_all('/^([\\.\\d]*)$/si', Insight_Util::getRequestHeader("X-FirePHP-Version"), $m) && version_compare($m[1][0], '0.0.6', '>=')) { return $_cached_info = array("client" => "firephp"); } } } return $_cached_info = false; }
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; }
protected static function _logUpgradeClientMessage() { if (self::$upgradeClientMessageLogged) { return; } // x-insight: activate request header is sent and FirePHP Extension detected, but not wildfire/insight client $info = Insight_Helper::getInstance()->getClientInfo(); if ($info['client'] == 'firephp' && Insight_Util::getRequestHeader('x-insight') == 'activate') { self::$upgradeClientMessageLogged = true; $firephp = self::getInstance(); $enabled = $firephp->getEnabled(); $firephp->setEnabled(true); $firephp->info('Your client only supports some features of the FirePHP library being used on the server. See http://upgrade.firephp.org/ for information on how to upgrade your client.'); $firephp->setEnabled($enabled); } }