Example #1
0
 protected function onShutdown()
 {
     // TODO: Allow client to switch this off
     $files = get_included_files();
     // exclude our own files
     $excluding = false;
     for ($i = 0; $i < count($files); $i++) {
         // TODO: Make this more reliable
         if (preg_match("/\\/FirePHP\\//", $files[$i]) || preg_match("/\\/FirePHPCore\\//", $files[$i]) || preg_match("/\\/Insight\\//", $files[$i]) || preg_match("/\\/Wildfire\\//", $files[$i]) || preg_match("/\\/Zend\\//", $files[$i])) {
             // potentially exclude
             $exclude = false;
             // start excluding when
             if (preg_match("/\\/FirePHP\\/Init.php\$/", $files[$i])) {
                 $excluding = true;
             } else {
                 // stop excluding after
                 if (preg_match("/\\/Wildfire\\/Protocol\\/Component.php\$/", $files[$i]) || -preg_match("/\\/Insight\\/Encoder\\/Default.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Class.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Property.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Method.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Docblock.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Docblock\\/Tag.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Loader.php\$/", $files[$i]) || preg_match("/\\/Zend\\/Reflection\\/Parameter.php\$/", $files[$i])) {
                     $excluding = false;
                     $exclude = true;
                 } else {
                     // always exclude
                     if (preg_match("/\\/FirePHP\\//", $files[$i]) || preg_match("/\\/FirePHPCore\\//", $files[$i]) || preg_match("/\\/Insight\\//", $files[$i]) || preg_match("/\\/Wildfire\\//", $files[$i])) {
                         $exclude = true;
                     }
                 }
             }
             if ($excluding || $exclude) {
                 array_splice($files, $i, 1);
                 $i--;
             }
         }
     }
     Insight_Helper::to('request')->files()->loaded($files);
 }
Example #2
0
 protected function onShutdown()
 {
     if (!$this->info) {
         return;
     }
     if (!$this->request->isClientPresent()) {
         return;
     }
     // only send info to client if it has changed
     $packageInfo = $this->request->getFromClientCache('package-info', false);
     if ($packageInfo == serialize($this->info)) {
         return;
     }
     $this->request->storeInClientCache('package-info', serialize($this->info), false);
     Insight_Helper::to('package')->getMessage()->meta(array("encoder" => "JSON", "target" => "info"))->send($this->info);
 }
Example #3
0
 public function on($name)
 {
     if (strpos($name, '|') !== false) {
         throw new Exception("on() labels may not contain the '|' (pipe) character");
     }
     $parents = isset($this->message->meta['.selective.parents']) ? $this->message->meta['.selective.parents'] : array();
     if (sizeof($parents) === 0 && sizeof($this->openStack) > 0) {
         $parents = explode("|", $this->openStack[sizeof($this->openStack) - 1]);
     }
     if (sizeof($parents) > 0 && $parents[sizeof($parents) - 1] == $name) {
         $parents = array_slice($parents, 0, -1);
     }
     $filter = $this->_getFilter($name, $parents);
     if ($filter['enabled']) {
         array_push($parents, $name);
         return $this->message->meta(array('.selective.parents' => $parents));
     } else {
         return Insight_Helper::getNullMessage();
     }
 }
Example #4
0
 protected function validate()
 {
     $file = $this->rootPath;
     if (!is_dir($file) || !is_readable($file)) {
         throw new Exception('Program root path "' . $file . '" does not exist or is not readable.');
     }
     // Ensure program is declared in a directory we have access to
     if (!Insight_Helper::getInstance()->getServer()->canServeFile($file)) {
         throw new Exception('Program "' . $file . '" cannot be access remotely. You need to configure acces with ["implements"]["cadorn.org/insight/@meta/config/0"]["paths"].');
     }
     $descriptorFile = $file . '/package.json';
     if (!is_file($descriptorFile) || !is_readable($descriptorFile)) {
         throw new Exception('Package descriptor for program not accessbile: ' . $descriptorFile);
     }
     $this->descriptor = $descriptor = json_decode(file_get_contents($descriptorFile), true);
     if (!json_decode(file_get_contents($descriptorFile))) {
         throw new Exception('Package descriptor for program not valid JSON: ' . $descriptorFile);
     }
     if (!isset($descriptor['mappings'])) {
         throw new Exception('Package descriptor must declare "mappings": ' . $descriptorFile);
     }
     if (!isset($descriptor['implements'])) {
         throw new Exception('Package descriptor must declare "implements": ' . $descriptorFile);
     }
     if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0'])) {
         throw new Exception('Package descriptor must declare "implements" -> "cadorn.org/insight/@meta/plugin/0": ' . $descriptorFile);
     }
     if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['options'])) {
         throw new Exception('Package descriptor must declare "implements" -> "cadorn.org/insight/@meta/plugin/0" -> "options": ' . $descriptorFile);
     }
     if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['options']['label'])) {
         throw new Exception('Package descriptor must declare "implements" -> "cadorn.org/insight/@meta/plugin/0" -> "options" -> "label": ' . $descriptorFile);
     }
     if (!isset($descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['main'])) {
         $descriptor['implements']['cadorn.org/insight/@meta/plugin/0']['main'] = 'main';
     }
     return $file;
 }
Example #5
0
 protected function loadProgram($class, $file = null)
 {
     if (!class_exists($class, false)) {
         if (!$file) {
             // assuming $class is accessible via autoloader
             new $class();
         } else {
             if (!is_file($file) || !is_readable($file)) {
                 throw new Exception('File not accessible: ' . $file);
             }
             if (!(require_once $file)) {
                 throw new Exception('Error while requiring file: ' . $file);
             }
             if (!class_exists($class, false)) {
                 throw new Exception('Class "' . $class . '" not declared in file: ' . $file);
             }
         }
     }
     $reflectionClass = new ReflectionClass($class);
     // Ensure class is declared in a directory we have access to
     if (!Insight_Helper::getInstance()->getServer()->canServeFile($reflectionClass->getFileName())) {
         throw new Exception('Class "' . $class . '" in file "' . $reflectionClass->getFileName() . ' cannot be access remotely. You need to configure acces with ["implements"]["cadorn.org/insight/@meta/config/0"]["paths"].');
     }
     $program = new $class();
     if (!is_a($program, 'Insight_Program_JavaScript')) {
         throw new Exception('Class "' . $class . '" in file "' . $reflectionClass->getFileName() . '" does not inherit from Insight_Program_JavaScript');
     }
     return $program;
 }
Example #6
0
 // Print all headers to be sent
 $html = array();
 $html[] = '<div class="box">';
 $html[] = '<div class="header">';
 $html[] = 'headers_list()';
 $html[] = '</div>';
 $html[] = '<div id="response-headers-body" class="body">';
 foreach (headers_list() as $header) {
     $html[] = $header . '<br/>';
 }
 $html[] = '</div>';
 $html[] = '</div>';
 echo implode("\n", $html);
 // Print payload to be fetched by client if applicable
 if (class_exists('Insight_Helper', false)) {
     $insight = Insight_Helper::getInstance();
     if ($insight->getEnabled()) {
         $html = array();
         $html[] = '<div class="box">';
         $html[] = '<div class="header">';
         $html[] = 'Payload';
         $html[] = '</div>';
         $html[] = '<div id="payload-body" class="body">';
         $transport = $insight->getChannel()->getTransport();
         $contents = $transport->getData($transport->getLastKey());
         $contents = str_replace("\n", '<br/>', $contents);
         $html[] = $contents;
         $html[] = '</div>';
         $html[] = '</div>';
         echo implode("\n", $html);
     }
Example #7
0
 protected function isClientAuthorized()
 {
     if (php_sapi_name() == 'cli') {
         return true;
     }
     // verify IP
     $authorized = false;
     $ips = $this->config->getIPs();
     if (count($ips) == 1 && $ips[0] == '*') {
         $authorized = true;
     } else {
         $requestIP = Insight_Util::getRequestIP();
         foreach ($ips as $ip) {
             if (substr($requestIP, 0, strlen($ip)) == $ip) {
                 $authorized = true;
                 break;
             }
         }
     }
     if (!$authorized) {
         Insight_Helper::debug('IP "' . Insight_Util::getRequestIP() . '" not authorized in credentials.json file or INSIGHT_IPS constant');
         return false;
     }
     $clientInfo = self::$instance->getClientInfo();
     if (!$clientInfo || $clientInfo['client'] != 'insight') {
         // announce installation
         // NOTE: Only an IP match is required for this. If client is announcing itself ($clientInfo) we do NOT send this header!
         // TODO: Use wildfire for this?
         header('x-insight-installation-id: ' . Insight_Util::getInstallationId());
         return false;
     }
     // verify client key
     $authorized = false;
     if ($clientInfo['client'] == 'insight') {
         $authkeys = $this->config->getAuthkeys();
         if (count($authkeys) == 1 && $authkeys[0] == '*') {
             $authorized = true;
         } else {
             foreach ($authkeys as $authkey) {
                 if (in_array($authkey, $clientInfo['authkeys'])) {
                     $authorized = true;
                     break;
                 }
             }
         }
     }
     if (!$authorized) {
         // IP matched and client announced itself but authkey does not match
         header('x-insight-status: AUTHKEY_NOT_FOUND');
     }
     return $authorized;
 }
Example #8
0
<?php

// NOTE: You must have FirePHP Companion installed (http://www.christophdorn.com/Tools/)
// See FirePHP Companion or Firebug Console for result (depending on $_GET['target'])
define('INSIGHT_CONFIG_PATH', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'package.json');
// force-enable FirePHP
define('FIREPHP_ACTIVATED', true);
require_once 'FirePHP/Init.php';
$console = FirePHP::to('page')->console();
if (isset($_GET['target'])) {
    // set by the drop-down in the reference
    $console = FirePHP::to($_GET['target'])->console();
    if ($_GET['target'] == 'request') {
        FirePHP::to('controller')->triggerInspect();
    }
}
// register a listener
class PayloadListener
{
    public function onPayload($request, $payload)
    {
        echo $payload;
    }
}
Insight_Helper::getInstance()->registerListener('payload', new PayloadListener());
// send a test message
$console->log('Hello World');
Example #9
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);
     }
 }
Example #10
0
<?php

// NOTE: You must have FirePHP Companion installed (http://www.christophdorn.com/Tools/)
// See Firebug Console for result
define('INSIGHT_CONFIG_PATH', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'package.json');
require_once 'FirePHP/Init.php';
$payload = array();
$payload[] = 'x-wf-protocol-1: http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0';
$payload[] = 'x-wf-1-index: 3';
$payload[] = 'x-wf-1-1-receiver: http://registry.pinf.org/cadorn.org/insight/@meta/receiver/insight/package/0';
$payload[] = 'x-wf-1-1-1-sender: http://registry.pinf.org/cadorn.org/github/firephp-libs/programs/standalone/examples/TestRunner/?lib=cadorn.org/github/firephp-libs/packages/insight@' . FirePHP::VERSION;
$payload[] = 'x-wf-1-1-1-1: 350|{"target":"info"}|{"links":{"quick":{"Homepage":"http:\\/\\/github.com\\/cadorn\\/firephp-libs\\/tree\\/master\\/programs\\/standalone\\/examples\\/","Bugs":"http:\\/\\/github.com\\/cadorn\\/firephp-libs\\/issues","Discuss":"http:\\/\\/groups.google.com\\/group\\/firephp-dev","Follow":"http:\\/\\/twitter.com\\/firephplib"}},"description":"FirePHP Examples: Test Runner"}|';
$payload[] = 'x-wf-1-2-receiver: http://registry.pinf.org/cadorn.org/insight/@meta/receiver/insight/controller/0';
$payload[] = 'x-wf-1-2-1-sender: http://registry.pinf.org/cadorn.org/github/firephp-libs/programs/standalone/examples/TestRunner/?lib=cadorn.org/github/firephp-libs/packages/insight@' . FirePHP::VERSION;
$payload[] = 'x-wf-1-2-1-2: 125||{"serverUrl":"http:\\/\\/reference.developercompanion.com\\/Tools\\/FirePHPCompanion\\/Run\\/Examples\\/TestRunner\\/_insight_.php"}|';
$payload[] = 'x-wf-1-3-receiver: http://registry.pinf.org/cadorn.org/insight/@meta/receiver/console/page/0';
$payload[] = 'x-wf-1-3-1-sender: http://registry.pinf.org/cadorn.org/github/firephp-libs/programs/standalone/examples/TestRunner/?lib=cadorn.org/github/firephp-libs/packages/insight@' . FirePHP::VERSION;
$payload[] = 'x-wf-1-3-1-3: 386|{"context":"page","target":"console","priority":"log","file":"\\/Users\\/cadorn\\/pinf\\/workspaces\\/github.com\\/cadorn\\/firephp-libs\\/programs\\/standalone\\/examples\\/TestRunner\\/insight-devcomp\\/snippets\\/PayloadListener.php","line":33,"lang.id":"registry.pinf.org\\/cadorn.org\\/github\\/renderers\\/packages\\/php\\/master"}|{"origin":{"type":"text","text":"Hello World","lang.type":"string"}}|';
Insight_Helper::getInstance()->relayPayload(implode("\n", $payload));
Example #11
-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);
 }