Exemplo n.º 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;
 }
Exemplo n.º 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']);
     }
 }
Exemplo n.º 3
0
 public function encode($data = self::UNDEFINED, $meta = self::UNDEFINED)
 {
     if ($data !== self::UNDEFINED) {
         $this->setOrigin($data);
     }
     if ($meta !== self::UNDEFINED) {
         $this->setMeta($meta);
     }
     $graph = array();
     if ($this->_origin !== self::UNDEFINED) {
         $graph = $this->_origin;
     }
     // remove encoder options
     foreach ($this->_meta as $name => $value) {
         if ($name == "encoder" || substr($name, 0, 8) == "encoder.") {
             unset($this->_meta[$name]);
         }
     }
     return array(Insight_Util::json_encode($graph), $this->_meta ? $this->_meta : false);
 }
Exemplo n.º 4
0
 public function respond($server, $request)
 {
     if ($request->getAction() == 'ToggleFilter') {
         $this->_loadFilters();
         $key = $request->getArgument('key');
         if (isset($this->filters[$key])) {
             if ($request->hasArgument('enabled')) {
                 $this->filters[$key]['enabled'] = $request->getArgument('enabled');
             } else {
                 $this->filters[$key]['enabled'] = !$this->filters[$key]['enabled'];
             }
         }
         if (!$this->defaultFilters) {
             $this->defaultFilters[$key] = array();
         }
         $this->defaultFilters[$key]['enabled'] = $this->filters[$key]['enabled'];
         $request->storeInClientCache('filters', $this->defaultFilters);
         $request->storeInClientUrlCache('filters', $this->filters);
         return array('type' => 'text/plain', 'data' => Insight_Util::json_encode(array('filters' => $this->filters)));
     }
     return false;
 }
Exemplo n.º 5
0
 public function send($data, $meta = array(), $receiver = false)
 {
     if ($receiver) {
         $this->setReceiverID($receiver);
     }
     list($data, $meta) = $this->getEncoder(isset($meta['encoder']) ? $meta['encoder'] : 'Default')->encode($data, $meta);
     if ($meta) {
         // remove helper options
         foreach ($meta as $name => $value) {
             if (substr($name, 0, 1) == ".") {
                 unset($meta[$name]);
             }
         }
     }
     return $this->sendRaw($data, $meta ? Insight_Util::json_encode($meta) : '');
 }
Exemplo n.º 6
0
 public function getId()
 {
     return Insight_Util::getInstallationId() . '/' . get_class($this);
 }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
 public function table($title, $data, $header = false)
 {
     if (is_object($data)) {
         // convert object to name/value table
         $originalData = $data;
         $data = array();
         foreach ((array) $originalData as $name => $value) {
             $data[] = array($name, $value);
         }
     } else {
         if (is_array($data)) {
             if (Insight_Util::is_list($data)) {
                 // we have a simple list
                 // this means we have a set of rows with cells or just a list where each element should be it's own row
                 $originalData = $data;
                 $isSimple = false;
                 foreach ($originalData as $value) {
                     // if value is not an array we assume we have a list where the value should be it's own row
                     // i.e. we will wrap each value in an array to simulate a row with one cell
                     if (!is_array($value) || !Insight_Util::is_list($value)) {
                         $isSimple = true;
                         break;
                     }
                 }
                 if ($isSimple) {
                     // wrap each element in an array to simulate a row with one cell
                     $data = array();
                     foreach ($originalData as $name => $value) {
                         $data[] = array($value);
                     }
                 }
             } else {
                 // convert associative array to name/value table
                 $originalData = $data;
                 $data = array();
                 foreach ($originalData as $name => $value) {
                     $data[] = array($name, $value);
                 }
             }
         }
     }
     $meta = array('renderer' => 'insight:structures/table', 'encoder.rootDepth' => 4);
     if (isset($this->message->meta['.expand'])) {
         $meta['expand'] = true;
     }
     $this->message->meta($this->_addFileLineMeta($meta))->send(array('title' => $title, 'data' => $data, 'header' => $header));
 }
Exemplo n.º 9
0
 public function getPackageInfo()
 {
     $info = array('links' => array('quick' => array()));
     if (isset($this->config['name'])) {
         $info['name'] = $this->config['name'];
     }
     if (isset($this->config['description'])) {
         $info['description'] = $this->config['description'];
     }
     if (isset($this->config['homepage'])) {
         $info['links']['quick']['Homepage'] = $this->config['homepage'];
     }
     if (isset($this->config['bugs'])) {
         $info['links']['quick']['Bugs'] = $this->config['bugs'];
     }
     if (isset($this->config['implements'][self::PACKAGE_META_URI])) {
         $info = Insight_Util::array_merge($info, $this->config['implements'][self::PACKAGE_META_URI]);
     }
     return $info;
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
 protected function _encodeAssociativeArray($Variable, $ObjectDepth = 1, $ArrayDepth = 1, $MaxDepth = 1)
 {
     if (($ret = $this->_checkDepth('Array', $ArrayDepth, $MaxDepth)) !== false) {
         return $ret;
     }
     $index = 0;
     $maxLength = $this->getOption('maxArrayLength');
     $lengthNoLimit = $this->getOption('lengthNoLimit');
     $isGlobals = false;
     foreach ($Variable as $key => $val) {
         // Encoding the $GLOBALS PHP array causes an infinite loop
         // if the recursion is not reset here as it contains
         // a reference to itself. This is the only way I have come up
         // with to stop infinite recursion in this case.
         if ($key == 'GLOBALS' && is_array($val) && array_key_exists('GLOBALS', $val)) {
             $isGlobals = true;
         }
         if ($isGlobals) {
             switch ($key) {
                 case 'GLOBALS':
                     $val = array(self::SKIP => true, 'encoder.trimmed' => true, 'encoder.notice' => 'Recursion (GLOBALS)');
                     break;
                 case '_ENV':
                 case 'HTTP_ENV_VARS':
                 case '_POST':
                 case 'HTTP_POST_VARS':
                 case '_GET':
                 case 'HTTP_GET_VARS':
                 case '_COOKIE':
                 case 'HTTP_COOKIE_VARS':
                 case '_SERVER':
                 case 'HTTP_SERVER_VARS':
                 case '_FILES':
                 case 'HTTP_POST_FILES':
                 case '_REQUEST':
                     $val = array(self::SKIP => true, 'encoder.trimmed' => true, 'encoder.notice' => 'Automatically Excluded (GLOBALS)');
                     break;
             }
         }
         if ($this->getOption('treatArrayMapAsDictionary')) {
             if (!Insight_Util::is_utf8($key)) {
                 $key = utf8_encode($key);
             }
             $return[$key] = $this->_encodeVariable($val, 1, $ArrayDepth + 1);
         } else {
             $return[] = array($this->_encodeVariable($key), $this->_encodeVariable($val, 1, $ArrayDepth + 1, $MaxDepth + 1));
         }
         $index++;
         if ($maxLength >= 0 && $index >= $maxLength && $lengthNoLimit !== true) {
             if ($this->getOption('treatArrayMapAsDictionary')) {
                 $return['...'] = array('encoder.trimmed' => true, 'encoder.notice' => 'Max Array Length (' . $maxLength . ') ' . (count($Variable) - $maxLength) . ' more');
             } else {
                 $return[] = array(array('encoder.trimmed' => true, 'encoder.notice' => 'Max Array Length (' . $maxLength . ') ' . (count($Variable) - $maxLength) . ' more'), array('encoder.trimmed' => true, 'encoder.notice' => 'Max Array Length (' . $maxLength . ') ' . (count($Variable) - $maxLength) . ' more'));
             }
             break;
         }
     }
     return array('value' => $return);
 }
Exemplo n.º 12
0
 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);
     }
 }
Exemplo n.º 13
0
 /**
  * Store in cache for client key + url
  */
 public function storeInClientUrlCache($name, $object, $encode = true)
 {
     file_put_contents($this->cachePathForName($name, 'clienturl'), $encode ? Insight_Util::json_encode($object) : $object);
 }
Exemplo n.º 14
-1
 public function __call($name, $arguments)
 {
     if (self::$blocks > 0) {
         return Insight_Helper::getNullMessage();
     }
     if ($this->apiOnce) {
         if (!method_exists($this->apiOnce, $name)) {
             throw new Exception('Method "' . $name . '" does not exist in class: ' . get_class($this->apiOnce));
         }
         $api = $this->apiOnce;
         $this->apiOnce = false;
         $oldmsg = $api->setMessage($this);
         $retval = call_user_func_array(array($api, $name), $arguments);
         $api->setMessage($oldmsg);
         return $retval;
     } else {
         if ($this->api && method_exists($this->api, $name)) {
             $oldmsg = $this->api->setMessage($this);
             $retval = call_user_func_array(array($this->api, $name), $arguments);
             $this->api->setMessage($oldmsg);
             return $retval;
         }
     }
     if ($name == 'once') {
         $message = clone $this;
         $message->once = $arguments[0];
         return $message;
     } else {
         if ($name == 'to') {
             $message = clone $this;
             $message->to = $arguments[0];
             return $message;
         } else {
             if ($name == 'is') {
                 if (is_bool($arguments[0])) {
                     return $arguments[0];
                 }
                 throw new Exception('non-boolean is() comparison not supported');
             } else {
                 if ($name == 'api') {
                     $message = clone $this;
                     $api = $arguments[0];
                     if (is_string($api)) {
                         $api = $this->helper->getApi($api);
                     }
                     if (isset($arguments[1]) && $arguments[1] === true) {
                         $message->apiOnce = $api;
                     } else {
                         $message->api = $api;
                     }
                     if (method_exists($api, 'setRequest')) {
                         $api->setRequest($this->helper->getRequest());
                     }
                     return $message;
                 } else {
                     if ($name == 'meta') {
                         $message = clone $this;
                         foreach ($arguments[0] as $name => $value) {
                             if ($value === null) {
                                 unset($message->meta[$name]);
                             } else {
                                 if (isset($message->meta[$name])) {
                                     $message->meta[$name] = Insight_Util::array_merge($message->meta[$name], $value);
                                 } else {
                                     $message->meta[$name] = $value;
                                 }
                             }
                         }
                         return $message;
                     } else {
                         if ($name == 'open') {
                             return $this;
                         } else {
                             if ($name == 'close') {
                                 return $this;
                             }
                         }
                     }
                 }
             }
         }
     }
     throw new Exception("Unknown method: " . $name);
 }