Example #1
0
 public static function dispatch(array $dispatchList, Request $request)
 {
     $uri = $request->abs_path();
     $path = explode(SEPARATOR, $uri);
     // Fix for PHP  it takes the /.. amd adds a space in the first position. We don't need it because all paths will start with /
     if ($path[0] == '') {
         array_shift($path);
     }
     $extraDepth = $uri[strlen($uri) - 1] == SEPARATOR ? 1 : 0;
     list($host, $port) = static::splitHostPort($request->host());
     return static::tryHostBinding($dispatchList, array_reverse($host), $port, $path, $extraDepth, $request);
 }
Example #2
0
 /**
  * 检查用户信息完成度,nickname或logo没有的话都重定向请求OAuth2详细认证获取资料
  * @param array $uinfo
  * @return boolean
  */
 static function checkUserInfoCompleteDegree($uinfo, $refer = '/')
 {
     if (empty($uinfo['nickname']) || empty($uinfo['logo'])) {
         //只要两个其中一个为空,都请求OAuth2详细认证
         if (!isset($_SESSION['wxoauth_reqcnt'])) {
             $_SESSION['wxoauth_reqcnt'] = 0;
         }
         $_SESSION['wxoauth_reqcnt']++;
         if ($_SESSION['wxoauth_reqcnt'] < 4) {
             //最多尝试2次,避免死循环
             (new Weixin())->authorizing('http://' . Request::host() . '/user/oauth/weixin?act=&refer=' . $refer, 'detail');
         }
     }
     return true;
 }
Example #3
0
    /** @var string */
    public static $method;
    /** @var int  0 if not keepalive */
    public static $keepalive;
    /**
     * Complete request URL
     * 
     * @param  bool
     * @param  bool
     * @param  bool
     * @return string
     */
    public static function url($include_query = true, $include_path = true, $include_host = true)
    {
        return (self::$secure ? 'https://' : 'http://') . ($include_host ? self::$host . ((self::$secure and self::$port == 443 or !self::$secure and self::$port == 80) ? '' : ':' . self::$port) . ($include_path ? self::$path . (($include_query and self::$query) ? '?' . self::$query : '') : '') : '');
    }
}
# Initialized at load-time:
Request::$secure = isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on';
Request::$http_version = isset($_SERVER['SERVER_PROTOCOL']) ? substr(strstr($_SERVER['SERVER_PROTOCOL'], '/'), 1) : '1.0';
Request::$host = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
if (($p = strpos(Request::$host, ':')) !== false) {
    Request::$port = intval(substr(Request::$host, $p + 1));
    Request::$host = substr(Request::$host, 0, $p);
} elseif (isset($_SERVER['SERVER_PORT'])) {
    Request::$port = intval($_SERVER['SERVER_PORT']);
}
Request::$query = @$_SERVER['QUERY_STRING'];
Request::$path = Request::$query ? substr(@$_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) : rtrim(@$_SERVER['REQUEST_URI'], '?');
Request::$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
Request::$keepalive = isset($_SERVER['HTTP_KEEP_ALIVE']) ? intval($_SERVER['HTTP_KEEP_ALIVE']) : 0;
Example #4
0
        error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
    }
}
/**
 * Set the default language
 */
I18n::lang('en_US');
if (isset($_SERVER['SERVER_PROTOCOL'])) {
    // Replace the default protocol.
    HTTP::$protocol = $_SERVER['SERVER_PROTOCOL'];
}
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
    Request::$type = 'https';
}
if (isset($_SERVER['HTTP_HOST'])) {
    Request::$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
}
/**
 * InitializeCore, setting the default options.
 *
 * The following options are available:
 *
 * - string   charset     internal character set used for input and output   utf-8
 * - string   cache_dir   set the internal cache directory                   APPPATH/cache
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 */
Kohana::init(array('base_url' => '/', 'index_file' => FALSE, 'cache_dir' => CMSPATH . 'cache', 'caching' => Kohana::$environment < Kohana::DEVELOPMENT, 'profile' => Kohana::$environment > Kohana::PRODUCTION, 'errors' => TRUE));
define('CMS_NAME', 'KodiCMS');
define('CMS_SITE', 'http://www.kodicms.ru');
Example #5
0
 public function testGivesNullWhenServerIsEmpty()
 {
     unset($_SERVER['HTTP_HOST']);
     $this->assertNull(Request::host());
 }
Example #6
0
}
?>
 /> <?php 
echo Lang::txt('COM_TOOLS_FIELD_STATE_DOWN');
?>
</label>
						</div>
					</fieldset>
					<fieldset class="adminform">
						<legend><span><?php 
echo Lang::txt('COM_TOOLS_FIEDSET_ZONES_PARAMS');
?>
</span></legend>

						<?php 
$hn = Request::host();
?>

						<script>
							jQuery(document).ready(function($)
							{
								$('#field-zone-params-websocket-enable').on('click', function()
								{
									$('.websocket').prop('disabled', function(i, v) { return !v; })
									               .toggleClass('opaque');
								});
								$('#field-zone-params-vnc-enable').on('click', function()
								{
									$('.vnc').prop('disabled', function(i, v) { return !v; })
									               .toggleClass('opaque');
								});
Example #7
0
define('kFWSysPath', str_replace(DIRECTORY_SEPARATOR, '/', pathinfo(__FILE__, PATHINFO_DIRNAME)) . '/');
define('kFWCorePath', kFWSysPath . 'core/');
define('kFWAppsPath', kFWSysPath . 'apps/');
define('kFWConfigPath', kFWSysPath . 'config/');
define('kPhpExt', '.php');
define('kTplExt', '.tpl');
include kFWConfigPath . 'Bootstrap' . kPhpExt;
Core::init();
//Display::init();
//echo '<br>'.Request::host(2).'<br>';
foreach ($Apps as $App) {
    $matchedHost = true;
    if (isset($App[kAppsHost]) && $App[kAppsHost] !== null) {
        $matchedHost = false;
        $host = Request::host(isset($App[kAppsHostLevel]) ? $App[kAppsHostLevel] : 0);
        $matched = preg_match($App[kAppsHost], $host);
        if ($matched) {
            $matchedHost = true;
        }
    }
    $matchedPath = true;
    if ($matchedHost && isset($App[kAppsPath]) && $App[kAppsPath] !== null) {
        $matchedPath = false;
        $matched = preg_match($App[kAppsPath], $_SERVER['REQUEST_URI']);
        if ($matched) {
            $matchedPath = true;
        }
    }
    if ($matchedHost && $matchedPath) {
        Core::app($App);
 /**
  * Builds a response to an incoming request by routing
  * it through the application.
  *
  * @param Request $req
  *
  * @return Response
  */
 public function handleRequest(Request $req)
 {
     // set host name from request if not already set
     $config = $this['config'];
     if (!$config->get('app.hostname')) {
         $config->set('app.hostname', $req->host());
     }
     $res = new Response();
     try {
         // determine route by dispatching to router
         $routeInfo = $this['router']->dispatch($req->method(), $req->path());
         $this['routeInfo'] = $routeInfo;
         // set any route arguments on the request
         if (isset($routeInfo[2])) {
             $req->setParams($routeInfo[2]);
         }
         // the dispatch middleware is the final step
         $dispatch = new DispatchMiddleware();
         $dispatch->setApp($this);
         $this->middleware($dispatch);
         // the request is handled by returning the response
         // generated by the middleware chain
         return $this->runMiddleware($req, $res);
     } catch (\Exception $e) {
         return $this['exception_handler']($req, $res, $e);
     } catch (\Error $e) {
         return $this['php_error_handler']($req, $res, $e);
     }
 }
Example #9
0
 /**
  * Return the domain name for the current request. Heuristics are used to
  * detect the the domain name. This will fail horribly for extremely short
  * domain names. A domain name is assumed to be the rightmost part of the
  * full hostname. A test on very short strings is used to detect top level
  * domains such as .com, .nl and double ones like .co.uk. This obviously
  * fails for longer top level domains en extremely short domain names.
  *
  * \return Domain name for the current request.
  */
 static function domain()
 {
     $host = Request::host();
     /* If it looks like an ip address we just return the IP address */
     if (preg_match('/^[0-9]{1,3}(\\.[0-9]{1,3}){3}$/', $host)) {
         return $host;
     }
     $parts = explode('.', $host);
     $num_parts = count($parts);
     if ($num_parts <= 2) {
         /* The hostname doesn't contain a subdomain part, or it is not
          * a canonical hostname after all (eg. localhost). */
         $domain = $host;
     } else {
         /* There's at least 3 parts: xx.yy.zz. Return either:
          * - yy.zz if yy is > 2 characters (example.com)
          * - xx.yy..zz if yy is <= 2 characters (example.co.uk)
          */
         $zz = array_pop($parts);
         $yy = array_pop($parts);
         if (strlen($yy) > 2) {
             $domain = sprintf('%s.%s', $yy, $zz);
         } else {
             $xx = array_pop($parts);
             $domain = sprintf('%s.%s.%s', $xx, $yy, $zz);
         }
     }
     return $domain;
 }