Beispiel #1
0
 static function php($text, $url = '', $attributes = '')
 {
     $url = (string) $url;
     $a = strpos($url, '#');
     if (false !== $a) {
         $hash = substr($url, $a);
         $url = substr($url, 0, $a);
     } else {
         $hash = '';
     }
     return $url == htmlspecialchars(substr(Patchwork::__HOST__() . substr($_SERVER['REQUEST_URI'], 1), strlen(Patchwork::__BASE__()))) ? '<b class="linkloop">' . $text . '</b>' : '<a href="' . Patchwork::base($url, true) . $hash . '" ' . $attributes . '>' . $text . '</a>';
 }
 static function resolve($agent)
 {
     static $cache = array();
     if (isset($cache[$agent])) {
         return $cache[$agent];
     } else {
         $cache[$agent] =& $trace;
     }
     $args = array();
     $BASE = p::__BASE__();
     $agent = rawurlencode($agent);
     $agent = str_replace(array('%21', '%7E', '%2A', '%28', '%29', '%2C', '%2F', '%3A', '%40', '%24', '%3B'), array('!', '~', '*', '(', ')', ',', '/', ':', '@', '$', ';'), $agent);
     $agent = p::base($agent, true);
     $agent = preg_replace("'^.*?://[^/]*'", '', $agent);
     $h = patchwork_http_socket($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_PORT'], isset($_SERVER['HTTPS']));
     $keys = p::$lang;
     $keys = "GET {$agent}?p:=k:{$keys} HTTP/1.0\r\n";
     $keys .= "Host: {$_SERVER['HTTP_HOST']}\r\n";
     $keys .= "Connection: close\r\n\r\n";
     fwrite($h, $keys);
     $keys = array();
     while (false !== ($a = fgets($h))) {
         $keys[] = $a;
     }
     fclose($h);
     $h = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'';
     $h = "/w\\.k\\((-?[0-9]+),({$h}),({$h}),({$h}),\\[((?:{$h}(?:,{$h})*)?)\\]\\)/su";
     if (!preg_match($h, implode('', $keys), $keys)) {
         user_error('Error while getting meta info data for ' . htmlspecialchars($agent));
         p::disable(true);
     }
     $appId = (int) $keys[1];
     $base = stripcslashes(substr($keys[2], 1, -1));
     $agent = stripcslashes(substr($keys[3], 1, -1));
     $a = stripcslashes(substr($keys[4], 1, -1));
     $keys = eval('return array(' . $keys[5] . ');');
     if ('' !== $a) {
         $args['__0__'] = $a;
         $i = 0;
         foreach (explode('/', $a) as $a) {
             $args['__' . ++$i . '__'] = $a;
         }
     }
     if ($base === $BASE) {
         $appId = $base = false;
     } else {
         p::watch('foreignTrace');
     }
     return $trace = array($appId, $base, $agent, $keys, $args);
 }
Beispiel #3
0
 /**
  * Sends the request to the webserver but don't wait for the response.
  */
 static function touch($url)
 {
     $url = Patchwork::base($url, true);
     if (!preg_match("'^http(s?)://([^:/]*)((?::[0-9]+)?)(/.*)\$'", $url, $h)) {
         throw new Exception('Illegal URL');
     }
     $url = "GET {$h[4]} HTTP/1.0\r\n";
     $url .= "Host: {$h[2]}\r\n";
     $url .= "Connection: close\r\n\r\n";
     try {
         $h = patchwork_http_socket($h[2], substr($h[3], 1), $h[1], 5);
         socket_set_blocking($h, 0);
         do {
             $len = fwrite($h, $url);
             $url = substr($url, $len);
         } while (false !== $len && false !== $url);
         fclose($h);
     } catch (Exception $h) {
         user_error($h->getMessage());
     }
 }
Beispiel #4
0
 static function php($string = '', $noId = false)
 {
     return Patchwork::base((string) $string, $noId);
 }
 static function loadAgent($agent, $args, $is_exo)
 {
     if (null === $agent) {
         return;
     }
     $a =& $_GET;
     if (false === $args) {
         $reset_get = true;
         $cache = '';
         if ('s' === p::$requestMode) {
             ob_start(array(__CLASS__, 'ob_htmlspecialchars'), 32768);
             ++p::$ob_level;
             self::$get = (object) $a;
         } else {
             $args = array();
             if (is_array($a)) {
                 reset($a);
                 while (list($k, $v) = each($a)) {
                     $args[$k] = is_string($v) ? htmlspecialchars($v) : $v;
                 }
             }
             self::$get = (object) $args;
         }
         self::$get->__DEBUG__ = DEBUG ? DEBUG : 0;
         self::$get->__HOST__ = htmlspecialchars(p::__HOST__());
         $cache .= self::$get->__LANG__ = htmlspecialchars(p::__LANG__());
         $cache .= self::$get->__BASE__ = htmlspecialchars(p::__BASE__());
         self::$get->__AGENT__ = 'agent_index' === $agent ? '' : p\Superloader::class2file(substr($agent, 6)) . '/';
         self::$get->__URI__ = htmlspecialchars(p::$uri);
         self::$get->__REFERER__ = isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : '';
         self::$get->__LANG_ALT__ = new \loop_altLang();
         self::$args = self::$get;
         if (!isset(self::$masterCache[$cache])) {
             self::$masterCache[$cache] = array();
         }
         self::$cache =& self::$masterCache[$cache];
     } else {
         $reset_get = false;
         $_GET =& $args;
         if ($agent instanceof \loop && $agent->__toString()) {
             $agent->autoResolve = false;
             while ($i = $agent->loop()) {
                 $data = $i;
             }
             if (!(p::$binaryMode || $agent instanceof LoopFreezed)) {
                 foreach ($data as &$v) {
                     is_string($v) && ($v = htmlspecialchars($v));
                 }
             }
             $agent = $data->{'a$'};
             $args = array_merge((array) $data, $args);
         }
         $BASE = p::__BASE__();
         $agent = p::base($agent, true);
         if (0 === strncmp($agent, $BASE, strlen($BASE))) {
             $agent = substr($agent, strlen($BASE));
             if ($is_exo) {
                 user_error("Patchwork Security Restriction Error: an AGENT ({$agent}) is called with EXOAGENT");
                 $_GET =& $a;
                 return;
             }
         } else {
             if ($is_exo) {
                 $k = $CONFIG['i18n.lang_list'][p::__LANG__()];
                 $agent = implode($k, explode('__', $agent, 2)) . '?p:=s';
                 foreach ($args as $k => $v) {
                     $agent .= '&' . urlencode($k) . '=' . urlencode($v);
                 }
                 if (ini_get_bool('allow_url_fopen')) {
                     $agent = file_get_contents($agent);
                 } else {
                     $agent = new \HTTP_Request($agent);
                     $agent->sendRequest();
                     $agent = $agent->getResponseBody();
                 }
                 echo str_replace(array('&gt;', '&lt;', '&quot;', '&#039;', '&amp;'), array('>', '<', '"', "'", '&'), $agent);
             } else {
                 user_error("Patchwork Security Restriction Error: an EXOAGENT ({$agent}) is called with AGENT");
             }
             $_GET =& $a;
             return;
         }
         try {
             $agent = p::resolveAgentClass($agent, $args);
         } catch (e\StaticResource $agent) {
             readfile($agent->getMessage());
             $_GET =& $a;
             return;
         }
         self::$args = (object) $args;
     }
     self::render($agent);
     $_GET =& $a;
     if ($reset_get) {
         self::$get = false;
     }
 }
Beispiel #6
0
 function setTestMode()
 {
     $log = parent::setTestMode();
     $lang = p::setLang($this->lang);
     $url = p::base($this->agent, true);
     empty($this->args) || ($url .= '?' . http_build_query($this->args));
     p::setLang($lang);
     $log['test-url'] = $url;
     return $log;
 }