/** * Displays the form for account creation * */ public function create() { if (!\Request::secure() && !Utils::isNinjaDev()) { Session::flash('warning', trans('texts.enable_https')); } $account = Auth::user()->account; $accountGatewaysIds = $account->gatewayIds(); $otherProviders = Input::get('other_providers'); if (!Utils::isNinja() || !env('WEPAY_CLIENT_ID') || Gateway::hasStandardGateway($accountGatewaysIds)) { $otherProviders = true; } $data = self::getViewModel(); $data['url'] = 'gateways'; $data['method'] = 'POST'; $data['title'] = trans('texts.add_gateway'); if ($otherProviders) { $availableGatewaysIds = $account->availableGatewaysIds(); $data['primaryGateways'] = Gateway::primary($availableGatewaysIds)->orderBy('name', 'desc')->get(); $data['secondaryGateways'] = Gateway::secondary($availableGatewaysIds)->orderBy('name')->get(); $data['hiddenFields'] = Gateway::$hiddenFields; return View::make('accounts.account_gateway', $data); } else { return View::make('accounts.account_gateway_wepay', $data); } }
/** * This will publish the story to the database */ public function publishStory() { $oRequestInstance = \Request::instance(); $oRouteInstance = \Route::current(); // get the extra custom data supplied by the user $aCustomData = $this->getCustomSuppliedData(); $uri = head($oRouteInstance->methods()) . ' ' . $oRouteInstance->uri(); $aData = ['ip_address' => \Input::getClientIp(), 'domain' => \Request::root(), 'path' => \Request::path(), 'request_method' => $oRequestInstance->getMethod(), 'query_string' => $oRequestInstance->getQueryString(), 'post_string' => \Request::method() == "POST" ? json_encode(\Input::all()) : NULL, 'is_ajax' => \Request::ajax(), 'is_secure' => \Request::secure(), 'route_uri' => $uri ?: '-', 'route_name' => $oRouteInstance->getName() ?: '-', 'route_action' => $oRouteInstance->getActionName() ?: '-', 'class_method' => \Request::method()]; // merge the custom data to the already built data $aData = array_merge($aData, $aCustomData); // save the collected data $this->getSessionManager()->saveCollectedData($aData); }
/** * Displays the form for account creation * */ public function create() { $data = self::getViewModel(); $data['url'] = 'gateways'; $data['method'] = 'POST'; $data['title'] = trans('texts.add_gateway'); $data['selectGateways'] = Gateway::where('payment_library_id', '=', 1)->where('id', '!=', GATEWAY_PAYPAL_EXPRESS)->where('id', '!=', GATEWAY_BITPAY)->where('id', '!=', GATEWAY_GOCARDLESS)->where('id', '!=', GATEWAY_DWOLLA)->orderBy('name')->get(); $data['hiddenFields'] = Gateway::$hiddenFields; if (!\Request::secure() && !Utils::isNinjaDev()) { Session::flash('warning', trans('texts.enable_https')); } return View::make('accounts.account_gateway', $data); }
/** * Set the value of a cookie. * * <code> * // Set the value of the "favorite" cookie * Cookie::put('favorite', 'Laravel'); * * // Set the value of the "favorite" cookie for twenty minutes * Cookie::put('favorite', 'Laravel', 20); * </code> * * @param string $name * @param string $value * @param int $expiration * @param string $path * @param string $domain * @param bool $secure * @return void */ public static function put($name, $value, $expiration = 0, $path = '/', $domain = null, $secure = false) { if ($expiration !== 0) { $expiration = time() + $expiration * 60; } // If the secure option is set to true, yet the request is not over HTTPS // we'll throw an exception to let the developer know that they are // attempting to send a secure cookie over the unsecure HTTP. if ($secure and !Request::secure()) { throw new \Exception("Attempting to set secure cookie over HTTP."); } static::$jar[$name] = compact('name', 'value', 'expiration', 'path', 'domain', 'secure'); }
/** * Generate an application URL to an asset. * * @param string $url * @param bool $https * @return string */ public static function to_asset($url, $https = null) { if (is_null($https)) { $https = Request::secure(); } $url = static::to($url, $https); // Since assets are not served by Laravel, we do not need to come through // the front controller. We'll remove the application index specified in // the application configuration from the generated URL. if (($index = Config::$items['application']['index']) !== '') { $url = str_replace($index . '/', '', $url); } return $url; }
/** * Set the value of a cookie. * * <code> * // Set the value of the "favorite" cookie * Cookie::put('favorite', 'Laravel'); * * // Set the value of the "favorite" cookie for twenty minutes * Cookie::put('favorite', 'Laravel', 20); * </code> * * @param string $name * @param string $value * @param int $expiration * @param string $path * @param string $domain * @param bool $secure * @return void */ public static function put($name, $value, $expiration = 0, $path = '/', $domain = null, $secure = false) { if ($expiration !== 0) { $expiration = time() + $expiration * 60; } $value = static::hash($value) . '+' . $value; // If the developer has explicitly disabled SLL, then we shouldn't force // this cookie over SSL. $secure = $secure && Config::get('application.ssl'); // If the secure option is set to true, yet the request is not over HTTPS // we'll throw an exception to let the developer know that they are // attempting to send a secure cookie over the insecure HTTP. if ($secure and !Request::secure()) { throw new \Exception("Attempting to set secure cookie over HTTP."); } static::$jar[$name] = compact('name', 'value', 'expiration', 'path', 'domain', 'secure'); }
$appDir = base_path() . "/" . Config::get('swagger.app-dir'); $docDir = Config::get('swagger.doc-dir'); if (!File::exists($docDir) || is_writable($docDir)) { // delete all existing documentation if (File::exists($docDir)) { File::deleteDirectory($docDir); } File::makeDirectory($docDir); $excludeDirs = Config::get('swagger.excludes'); $swagger = \Swagger\scan($appDir, ['exclude' => $excludeDirs]); $filename = $docDir . '/api-docs.json'; file_put_contents($filename, $swagger); } } if (Config::get('swagger.behind-reverse-proxy')) { $proxy = Request::server('REMOTE_ADDR'); Request::setTrustedProxies(array($proxy)); } //need the / at the end to avoid CORS errors on Homestead systems. $response = response()->view('swagger.index', array('secure' => Request::secure(), 'urlToDocs' => url('api-docs.json'), 'requestHeaders' => Config::get('swagger.requestHeaders'), 'clientId' => Input::get("client_id"), 'clientSecret' => Input::get("client_secret"), 'realm' => Input::get("realm"), 'appName' => Input::get("appName"))); //need the / at the end to avoid CORS errors on Homestead systems. /*$response = Response::make( View::make('swaggervel::index', array( 'secure' => Request::secure(), 'urlToDocs' => url('api-docs.json'), 'requestHeaders' => Config::get('swaggervel.requestHeaders') ) ), 200 );*/ return $response; });
App::before(function ($request) { // CloudFlare IP addresses to trust // Proxies obtained from https://www.cloudflare.com/ips-v4 // Cached for 1 week try { Request::setTrustedProxies(Cache::remember('cloudflare.ips', 24 * 60 * 7, function () { $request = App::make('guzzle')->get('https://www.cloudflare.com/ips-v4'); return explode("\n", $request->getBody()); })); } catch (Exception $e) { Cache::forget('cloudflare.ips'); Log::error($e); } // If request is not secured and force secured connection is enabled // then we need to redirect the user to a secure link. if (!Request::secure() && Config::get('bfacp.site.ssl') && $_SERVER['REMOTE_ADDR'] != '127.0.0.1' && filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) { $path = Request::path(); if (strlen(Request::server('QUERY_STRING')) > 0) { $path .= '?' . Request::server('QUERY_STRING'); } $status = in_array(Request::getMethod(), ['POST', 'PUT', 'DELETE']) ? 307 : 302; return Redirect::secure($path, $status); } // Check if only authorized users are allowed to access the site. if (Config::get('bfacp.site.auth') && Auth::guest()) { $path = explode('/', Request::path()); if (count($path) > 1) { $route = $path[0] . '/' . $path[1]; } else { $route = $path[0]; }
<?php /** * Gravatar configuration */ return array('size' => 80, 'default_image' => false, 'rating' => 'g', 'secure' => Request::secure());
$memento_service = ServiceLocator::getInstance()->getService(OpenIdServiceCatalog::MementoService); $memento_service->saveCurrentRequest(); }); Route::filter("oauth2.save.request", function () { $memento_service = ServiceLocator::getInstance()->getService(OAuth2ServiceCatalog::MementoService); $memento_service->saveCurrentAuthorizationRequest(); }); Route::filter("oauth2.needs.auth.request", function () { $memento_service = ServiceLocator::getInstance()->getService(OAuth2ServiceCatalog::MementoService); $oauth2_message = $memento_service->getCurrentAuthorizationRequest(); if ($oauth2_message == null || !$oauth2_message->isValid()) { throw new InvalidAuthorizationRequestException(); } }); Route::filter("ssl", function () { if (!Request::secure() && ServerConfigurationService::getConfigValue("SSL.Enable")) { $openid_memento_service = ServiceLocator::getInstance()->getService(OpenIdServiceCatalog::MementoService); $openid_memento_service->saveCurrentRequest(); $oauth2_memento_service = ServiceLocator::getInstance()->getService(OAuth2ServiceCatalog::MementoService); $oauth2_memento_service->saveCurrentAuthorizationRequest(); return Redirect::secure(Request::getRequestUri()); } }); Route::filter("oauth2.enabled", function () { if (!ServerConfigurationService::getConfigValue("OAuth2.Enable")) { return View::make('404'); } }); Route::filter('user.owns.client.policy', function ($route, $request) { try { $authentication_service = ServiceLocator::getInstance()->getService(UtilsServiceCatalog::AuthenticationService);
<?php use Swagger\Swagger; Route::any(Config::get('l5-swagger.doc-route') . '/{page?}', function ($page = 'api-docs.json') { $filePath = Config::get('l5-swagger.doc-dir') . "/{$page}"; if (File::extension($filePath) === "") { $filePath .= ".json"; } if (!File::Exists($filePath)) { App::abort(404, "Cannot find {$filePath}"); } $content = File::get($filePath); return Response::make($content, 200, array('Content-Type' => 'application/json')); }); Route::get('api-docs', function () { if (Config::get('l5-swagger.generateAlways')) { \Darkaonline\L5Swagger\Generator::generateDocs(); } if (Config::get('l5-swagger.behind-reverse-proxy')) { $proxy = Request::server('REMOTE_ADDR'); Request::setTrustedProxies(array($proxy)); } //need the / at the end to avoid CORS errors on Homestead systems. $response = Response::make(view('l5-swagger::index', array('secure' => Request::secure(), 'urlToDocs' => url(Config::get('l5-swagger.doc-route')), 'requestHeaders' => Config::get('l5-swagger.requestHeaders'))), 200); if (Config::has('l5-swagger.viewHeaders')) { foreach (Config::get('l5-swagger.viewHeaders') as $key => $value) { $response->header($key, $value); } } return $response; });
/** * Creates a new request object for the given URI. New requests should be * created using the [Request::instance] or [Request::factory] methods. * * $request = Request::factory($uri); * * If $cache parameter is set, the response for the request will attempt to * be retrieved from the cache. * * @param string $uri URI of the request * @param Cache $cache * @param array $injected_routes an array of routes to use, for testing * @return void * @throws Request_Exception * @uses Route::all * @uses Route::matches */ public static function factory($uri = TRUE, HTTP_Cache $cache = NULL, $injected_routes = array()) { // If this is the initial request if (!Request::$initial) { if (Kohana::$is_cli) { // Default protocol for command line is cli:// $protocol = 'cli'; // Get the command line options $options = CLI::options('uri', 'method', 'get', 'post', 'referrer'); if (isset($options['uri'])) { // Use the specified URI $uri = $options['uri']; } elseif ($uri === TRUE) { $uri = ''; } if (isset($options['method'])) { // Use the specified method $method = strtoupper($options['method']); } else { // Default to GET requests $method = HTTP_Request::GET; } if (isset($options['get'])) { // Overload the global GET data parse_str($options['get'], $_GET); } if (isset($options['post'])) { // Overload the global POST data parse_str($options['post'], $_POST); } if (isset($options['referrer'])) { $referrer = $options['referrer']; } } else { if (isset($_SERVER['SERVER_PROTOCOL'])) { $protocol = $_SERVER['SERVER_PROTOCOL']; } else { $protocol = HTTP::$protocol; } if (isset($_SERVER['REQUEST_METHOD'])) { // Use the server request method $method = $_SERVER['REQUEST_METHOD']; } else { // Default to GET requests $method = HTTP_Request::GET; } if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) { // This request is secure $secure = TRUE; } if (isset($_SERVER['HTTP_REFERER'])) { // There is a referrer for this request $referrer = $_SERVER['HTTP_REFERER']; } if (isset($_SERVER['HTTP_USER_AGENT'])) { // Browser type Request::$user_agent = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { // Typically used to denote AJAX requests $requested_with = $_SERVER['HTTP_X_REQUESTED_WITH']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { // Use the forwarded IP address, typically set when the // client is using a proxy server. // Format: "X-Forwarded-For: client1, proxy1, proxy2" $client_ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['HTTP_CLIENT_IP']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { // Use the forwarded IP address, typically set when the // client is using a proxy server. $client_ips = explode(',', $_SERVER['HTTP_CLIENT_IP']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['REMOTE_ADDR'])) { // The remote IP address Request::$client_ip = $_SERVER['REMOTE_ADDR']; } if ($method !== HTTP_Request::GET) { // Ensure the raw body is saved for future use $body = file_get_contents('php://input'); } if ($uri === TRUE) { // Attempt to guess the proper URI $uri = Request::detect_uri(); } } // Create the instance singleton Request::$initial = $request = new Request($uri, $cache); // Store global GET and POST data in the initial request only $request->protocol($protocol)->query($_GET)->post($_POST); if (isset($secure)) { // Set the request security $request->secure($secure); } if (isset($method)) { // Set the request method $request->method($method); } if (isset($referrer)) { // Set the referrer $request->referrer($referrer); } if (isset($requested_with)) { // Apply the requested with variable $request->requested_with($requested_with); } if (isset($body)) { // Set the request body (probably a PUT type) $request->body($body); } } else { $request = new Request($uri, $cache, $injected_routes); } return $request; }
$defaultApiVersion = Config::get('swaggervel.default-api-version'); $defaultSwaggerVersion = Config::get('swaggervel.default-swagger-version'); $excludeDirs = Config::get('swaggervel.excludes'); $swagger = \Swagger\scan($appDir, ['exclude' => $excludeDirs]); $filename = $docDir . '/api-docs.json'; file_put_contents($filename, $swagger); } } if (Config::get('swaggervel.behind-reverse-proxy')) { $proxy = Request::server('REMOTE_ADDR'); Request::setTrustedProxies(array($proxy)); } Blade::setEscapedContentTags('{{{', '}}}'); Blade::setContentTags('{{', '}}'); //need the / at the end to avoid CORS errors on Homestead systems. $response = response()->view('swaggervel::index', array('secure' => Request::secure(), 'urlToDocs' => url(Config::get('swaggervel.doc-route')), 'requestHeaders' => Config::get('swaggervel.requestHeaders'), 'clientId' => Request::input('client_id'), 'clientSecret' => Request::input('client_secret'), 'realm' => Request::input('realm'), 'appName' => Request::input('appName'))); //need the / at the end to avoid CORS errors on Homestead systems. /*$response = Response::make( View::make('swaggervel::index', array( 'secure' => Request::secure(), 'urlToDocs' => url(Config::get('swaggervel.doc-route')), 'requestHeaders' => Config::get('swaggervel.requestHeaders') ) ), 200 );*/ if (Config::has('swaggervel.viewHeaders')) { foreach (Config::get('swaggervel.viewHeaders') as $key => $value) { $response->header($key, $value); } } return $response;
$resourceOptions = array('output' => 'json', 'defaultSwaggerVersion' => $resourceList['swaggerVersion'], 'defaultBasePath' => $defaultBasePath); $output = array(); foreach ($swagger->getResourceNames() as $resourceName) { $json = $swagger->getResource($resourceName, $resourceOptions); $resourceName = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($resourceName, DIRECTORY_SEPARATOR)); $output[$resourceName] = $json; } $filename = $docDir . '/api-docs.json'; file_put_contents($filename, Swagger::jsonEncode($resourceList, true)); foreach ($output as $name => $json) { $name = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($name, DIRECTORY_SEPARATOR)); $filename = $docDir . '/' . $name . '.json'; file_put_contents($filename, $json); } } } if (Config::get('swaggervel::app.behind-reverse-proxy')) { $proxy = Request::server('REMOTE_ADDR'); Request::setTrustedProxies(array($proxy)); } Blade::setEscapedContentTags('{{{', '}}}'); Blade::setContentTags('{{', '}}'); //need the / at the end to avoid CORS errors on Homestead systems. $response = Response::make(View::make('swaggervel::index', array('secure' => Request::secure(), 'urlToDocs' => url(Config::get('swaggervel::app.doc-route')), 'requestHeaders' => Config::get('swaggervel::app.requestHeaders'))), 200); if (Config::has('swaggervel::app.viewHeaders')) { foreach (Config::get('swaggervel::app.viewHeaders') as $key => $value) { $response->header($key, $value); } } return $response; });
/** * Determine if the request is over HTTPS * * @return boolean */ function zbase_request_is_secure() { return \Request::secure(); }
}); Route::filter('auth.superuser', function () { if (!\Auth::check() || !\Auth::isSuperUser()) { return Redirect::to('/'); } }); // filter to check api app authentication Route::filter('auth.api', function ($route, $request) { // check for application that matches login, password and ip $user = \SeatApiApplication::where('application_login', '=', $request->getUser())->where('application_password', '=', $request->getPassword())->where('application_ip', '=', Request::getClientIp())->exists(); // if we cant find an app with those details, respond to the request if (!$user) { return Response::json(array('error' => true, 'message' => 'Invalid application credentials or request source.'), 401); } // also check to make sure that the request is over https if (!\Request::secure()) { return Response::json(array('error' => true, 'message' => 'API Access is only permitted via HTTPs.'), 401); } }); /* |-------------------------------------------------------------------------- | Guest Filter |-------------------------------------------------------------------------- | | The "guest" filter is the counterpart of the authentication filters as | it simply checks that the current user is not logged in. A redirect | response will be issued if they are, which you may freely change. | */ Route::filter('guest', function () { if (!\Auth::check()) {
$maxNestingLevel = ini_get('xdebug.max_nesting_level'); if (is_null($maxNestingLevel) || $maxNestingLevel === "" || $maxNestingLevel < 200) { // when less than 100 was getting error and think it's related to the eloquent whereHas queries referencing other models with similar queries. // TODO: look into this to make sure it's not some other reason ini_set('xdebug.max_nesting_level', 200); } if (Config::get("ssl.enabled")) { if (!Request::secure()) { return Redirect::secure(Request::path(), 301); // permanent redirect } } Cookie::setDefaultPathAndDomain(Config::get("cookies.path"), Config::get("cookies.domain")); }); App::after(function ($request, $response) { if (Config::get("ssl.enabled") && Request::secure()) { if (method_exists($response, "header")) { $response->header("Strict-Transport-Security", "max-age=5256000"); } } }); App::finish(function () { // now that the response has been sent to the user fire an event so that code that is now listening for this event can execute // depending on the server configuration the response might still not have been sent though as the server software may wait // until the php process finishes before sending the response. Event::fire("app.finish"); }); /* |-------------------------------------------------------------------------- | Authentication Filters |--------------------------------------------------------------------------
|-------------------------------------------------------------------------- | Application & Route Filters |-------------------------------------------------------------------------- | | Below you will find the "before" and "after" events for the application | which may be used to do any work before or after a request into your | application. Here you may also register your custom route filters. | */ App::before(function ($request) { if (Auth::check()) { $count = Session::get(SESSION_COUNTER, 0); Session::put(SESSION_COUNTER, ++$count); } if (App::environment() == ENV_PRODUCTION) { if (!Request::secure()) { return Redirect::secure(Request::getRequestUri()); } } if (Input::has('lang')) { $locale = Input::get('lang'); App::setLocale($locale); Session::set(SESSION_LOCALE, $locale); if (Auth::check()) { if ($language = Language::whereLocale($locale)->first()) { $account = Auth::user()->account; $account->language_id = $language->id; $account->save(); } } } else {
/** * @param string $uri * @param array $client_params * @param bool $allow_external * @param array $injected_routes * @internal param \HTTP_Cache $cache * @return \HAPI_Request|\Request|void */ public static function factory($uri = '', $client_params = array(), $allow_external = TRUE, $injected_routes = array()) { // If this is the initial request if (!Request::$initial) { if (isset($_SERVER['SERVER_PROTOCOL'])) { $protocol = $_SERVER['SERVER_PROTOCOL']; } else { $protocol = HTTP::$protocol; } if (isset($_SERVER['REQUEST_METHOD'])) { // Use the server request method $method = $_SERVER['REQUEST_METHOD']; } else { // Default to GET requests $method = HTTP_Request::GET; } if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) { // This request is secure $secure = TRUE; } if (isset($_SERVER['HTTP_REFERER'])) { // There is a referrer for this request $referrer = $_SERVER['HTTP_REFERER']; } if (isset($_SERVER['HTTP_USER_AGENT'])) { // Browser type Request::$user_agent = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { // Typically used to denote AJAX requests $requested_with = $_SERVER['HTTP_X_REQUESTED_WITH']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { // Use the forwarded IP address, typically set when the // client is using a proxy server. // Format: "X-Forwarded-For: client1, proxy1, proxy2" $client_ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['HTTP_CLIENT_IP']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { // Use the forwarded IP address, typically set when the // client is using a proxy server. $client_ips = explode(',', $_SERVER['HTTP_CLIENT_IP']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['REMOTE_ADDR'])) { // The remote IP address Request::$client_ip = $_SERVER['REMOTE_ADDR']; } if ($method !== HTTP_Request::GET) { // Ensure the raw body is saved for future use $body = file_get_contents('php://input'); } $cookies = array(); if ($cookie_keys = array_keys($_COOKIE)) { foreach ($cookie_keys as $key) { $cookies[$key] = Cookie::get($key); } } // Create the instance singleton Request::$initial = $request = new Request($uri, $client_params, $allow_external, $injected_routes); // Store global GET and POST data in the initial request only $request->protocol($protocol)->query($_GET)->post($_POST); if (isset($secure)) { // Set the request security $request->secure($secure); } if (isset($method)) { // Set the request method $request->method($method); } if (isset($referrer)) { // Set the referrer $request->referrer($referrer); } if (isset($requested_with)) { // Apply the requested with variable $request->requested_with($requested_with); } if (isset($body)) { // Set the request body (probably a PUT type) $request->body($body); } if (isset($cookies)) { $request->cookie($cookies); } } else { $request = new HAPI_Request($uri, $client_params, $allow_external, $injected_routes); } return $request; }
/** @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;
| */ App::before(function ($request) { $access = Config::get('paperwork.access'); $requestServerName = Request::server("SERVER_NAME"); $zones = array('external', 'internal'); App::singleton('paperworkSession', function () { $app = new stdClass(); $app->currentZone = null; return $app; }); $paperworkSession = App::make('paperworkSession'); foreach ($zones as $zone) { if (array_key_exists($zone, $access) && is_array($access[$zone]) && array_key_exists('dns', $access[$zone]) && $access[$zone]['dns'] == $requestServerName) { if (array_key_exists('ports', $access[$zone]) && is_array($access[$zone]['ports']) && array_key_exists('forceHttps', $access[$zone]['ports'])) { if ($access[$zone]['ports']['forceHttps'] === true && !Request::secure()) { return Redirect::secure(Request::path()); } } $paperworkSession->currentZone = $zone; } } View::share('paperworkSession', $paperworkSession); }); App::after(function ($request, $response) { // }); /* |-------------------------------------------------------------------------- | Authentication Filters |--------------------------------------------------------------------------
/** * Create a HTML page link. * * @param int $page * @param string $text * @param string $class * @return string */ protected function link($page, $text, $class) { $query = '?page=' . $page . $this->appendage($this->appends); return '<li' . HTML::attributes(array('class' => $class)) . '>' . HTML::link(URI::current() . $query, $text, array(), Request::secure()) . '</li>'; }
<span class="<?php echo $sortable ? "sortable" : ""; ?> "><?php echo $title; ?> </span><?php echo " "; if ($sortable) { if ($attribute == $active_sort_by && 'ASC' == $active_sort_dir) { echo "↑"; } else { echo HTML::link($sort_url_asc, '↑', array('title' => 'Sort Ascending'), Request::secure()); } echo " "; if ($attribute == $active_sort_by && 'DESC' == $active_sort_dir) { echo "↓"; } else { echo HTML::link($sort_url_desc, '↓', array('title' => 'Sort Descending'), Request::secure()); } } ?>
<?php /* |-------------------------------------------------------------------------- | Application & Route Filters |-------------------------------------------------------------------------- | | Below you will find the "before" and "after" events for the application | which may be used to do any work before or after a request into your | application. Here you may also register your custom route filters. | */ App::before(function ($request) { if (Config::get('enable-https', 0) and !Request::secure()) { return Redirect::secure(Request::path()); } if (Auth::check()) { //use here to update online status of this user Auth::user()->updateOnline(); } }); App::after(function ($request, $response) { // }); /* |-------------------------------------------------------------------------- | Authentication Filters |-------------------------------------------------------------------------- | | The following filters are used to verify that the user of the current | session is logged into this application. The "basic" filter easily
public function render() { $query_params = Input::query(); $query = $this->_get_query(); $active_sort_by = isset($query_params['sort_by']) ? $query_params['sort_by'] : $this->config['default_sort']; if (!empty($active_sort_by) && $this->config['attributes'][$active_sort_by]['sortable']) { $active_sort_dir = Input::query('sort_dir'); if (empty($active_sort_dir)) { $active_sort_dir = $active_sort_by == $this->config['default_sort'] && !empty($this->config['default_sort_dir']) ? $this->config['default_sort_dir'] : 'ASC'; } if (!is_null($this->config['attributes'][$active_sort_by]['decoder_for_sql'])) { $decoder_for_sql = $this->config['attributes'][$active_sort_by]['decoder_for_sql']; $sort_column = is_callable($decoder_for_sql) ? $decoder_for_sql($active_sort_by) : $decoder_for_sql; $sort_column = DB::raw($sort_column); } else { $sort_column = $active_sort_by; } $query = $query->order_by($sort_column, strtolower($active_sort_dir)); } else { $active_sort_by = false; $active_sort_dir = false; } $paginate = isset($this->config['pager_enabled']) ? $this->config['pager_enabled'] : Config::get('autolist::autolist.pager_enabled', true); $per_page = isset($this->config['page_size']) ? $this->config['page_size'] : Config::get('autolist::autolist.page_size', 10); $page_links = FALSE; if ($paginate) { $pager = $query->paginate($per_page); $extra_query_params = $query_params; unset($extra_query_params['page']); $pager->appends($extra_query_params); $page_links = $pager->links(); $items = $pager->results; } else { $items = $query->get(); } $permission_check = isset($this->config['permission_check']) && is_callable($this->config['permission_check']) ? $this->config['permission_check'] : Config::get('autolist::autolist.permission_check'); list($detail_view_action, $detail_view_permission_check) = $this->_get_detail_view_action_details($this->config); $permitted_items = array(); $has_item_actions = false; foreach ($items as $item) { if (!is_null($detail_view_permission_check) && !$detail_view_permission_check($item, $item->{$this->model_key})) { continue; } else { if ($permission_check && is_callable($permission_check) && !$permission_check($detail_view_action, $item, $item->{$this->model_key})) { continue; } } $action_links = array(); foreach ($this->config['item_actions'] as $action => $action_options) { $action_details = $this->_get_action_details($action, $action_options); $action_permitted = true; if (is_callable($action_details['permission_check'])) { $action_permission_check = $action_details['permission_check']; $action_permitted = $action_permission_check($item, $item->{$this->model_key}); } else { if (is_callable($permission_check)) { $action_permitted = $permission_check($action_details['action'], $item, $item->{$this->model_key}); } } if ($action_permitted) { $action_details['id'] = $item->{$this->model_key}; $action_links[$action_details['action']] = render(Config::get('autolist::autolist.views.action_link'), $action_details); $has_item_actions = true; } } $item_data = array(); foreach ($this->config['attributes'] as $attribute => $attribute_details) { $item_data[$attribute] = $this->_get_attribute_value($item, $attribute_details, $detail_view_action); } $item_data['action_links'] = $action_links; $permitted_items[] = $item_data; } $global_action_links = array(); foreach ($this->config['global_actions'] as $action => $action_options) { $action_details = $this->_get_action_details($action, $action_options); $action_permitted = true; if (is_callable($action_details['permission_check'])) { $action_permission_check = $action_details['permission_check']; $action_permitted = $action_permission_check($item); } else { if (is_callable($permission_check)) { $action_permitted = $permission_check($action_details['action'], $item); } } if ($action_permitted) { $action_details['id'] = NULL; $global_action_links[$action_details['action']] = render(Config::get('autolist::autolist.views.action_link'), $action_details); } } $header_columns = array(); foreach ($this->config['attributes'] as $attribute => $attribute_details) { if ($attribute_details['sortable']) { $attribute_details['active_sort_by'] = $active_sort_by; $attribute_details['active_sort_dir'] = $active_sort_dir; $current_link_params = $query_params; $current_link_params['sort_by'] = $attribute; $current_link_params['sort_dir'] = 'ASC'; $attribute_details['sort_url_asc'] = URL::to(URI::current() . "?" . http_build_query($current_link_params), Request::secure()); $current_link_params['sort_dir'] = 'DESC'; $attribute_details['sort_url_desc'] = URL::to(URI::current() . "?" . http_build_query($current_link_params), Request::secure()); } $header_columns[$attribute] = render(Config::get('autolist::autolist.views.header_item'), $attribute_details); } $list_data = array('title' => $this->config['title'], 'header_columns' => $header_columns, 'has_item_actions' => $has_item_actions, 'items' => $permitted_items, 'global_action_links' => $global_action_links, 'page_links' => $page_links); return render(Config::get('autolist::autolist.views.list'), $list_data); }
file_put_contents($filename, Swagger::jsonEncode($resourceList, true)); foreach ($output as $name => $json) { $name = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($name, DIRECTORY_SEPARATOR)); $filename = $docDir . '/' . $name . '.json'; file_put_contents($filename, $json); } } } if (Config::get('swagger.behind-reverse-proxy')) { $proxy = Request::server('REMOTE_ADDR'); Request::setTrustedProxies(array($proxy)); } Blade::setEscapedContentTags('{{{', '}}}'); Blade::setContentTags('{{', '}}'); //need the / at the end to avoid CORS errors on Homestead systems. $response = response()->view('swagger::index', array('secure' => Request::secure(), 'urlToDocs' => url(Config::get('swagger.doc-route')), 'requestHeaders' => Config::get('swagger.requestHeaders'))); //need the / at the end to avoid CORS errors on Homestead systems. /*$response = Response::make( View::make('swaggervel::index', array( 'secure' => Request::secure(), 'urlToDocs' => url(Config::get('swaggervel.doc-route')), 'requestHeaders' => Config::get('swaggervel.requestHeaders') ) ), 200 );*/ if (Config::has('swagger.viewHeaders')) { foreach (Config::get('swagger.viewHeaders') as $key => $value) { $response->header($key, $value); } } return $response;
/** * Create a HTML page link. * * @param int $page * @param string $text * @param string $class * @return string */ protected function link($page, $text, $class) { $query = '?page=' . $page . $this->appendage($this->appends); return HTML::link(URI::current() . $query, $text, compact('class'), Request::secure()); }
public static function factory($uri = TRUE, $client_params = array(), $allow_external = TRUE, $injected_routes = array()) { if (!Request::$initial) { $protocol = HTTP::$protocol; if (isset($_SERVER['REQUEST_METHOD'])) { $method = $_SERVER['REQUEST_METHOD']; } else { $method = HTTP_Request::GET; } if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN) or isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { $secure = TRUE; } if (isset($_SERVER['HTTP_REFERER'])) { $referrer = $_SERVER['HTTP_REFERER']; } if (isset($_SERVER['HTTP_USER_AGENT'])) { Request::$user_agent = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { $requested_with = $_SERVER['HTTP_X_REQUESTED_WITH']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { $client_ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['HTTP_CLIENT_IP']) and isset($_SERVER['REMOTE_ADDR']) and in_array($_SERVER['REMOTE_ADDR'], Request::$trusted_proxies)) { $client_ips = explode(',', $_SERVER['HTTP_CLIENT_IP']); Request::$client_ip = array_shift($client_ips); unset($client_ips); } elseif (isset($_SERVER['REMOTE_ADDR'])) { // The remote IP address Request::$client_ip = $_SERVER['REMOTE_ADDR']; } if ($method !== HTTP_Request::GET) { // Ensure the raw body is saved for future use $body = file_get_contents('php://input'); } if ($uri === TRUE) { // Attempt to guess the proper URI $uri = Request::detect_uri(); } $cookies = array(); if ($cookie_keys = array_keys($_COOKIE)) { foreach ($cookie_keys as $key) { $cookies[$key] = Cookie::get($key); } } // Create the instance singleton Request::$initial = $request = new Request($uri, $client_params, $allow_external, $injected_routes); // Store global GET and POST data in the initial request only $request->protocol($protocol)->query($_GET)->post($_POST); if (isset($secure)) { // Set the request security $request->secure($secure); } if (isset($method)) { // Set the request method $request->method($method); } if (isset($referrer)) { // Set the referrer $request->referrer($referrer); } if (isset($requested_with)) { // Apply the requested with variable $request->requested_with($requested_with); } if (isset($body)) { // Set the request body (probably a PUT type) $request->body($body); } if (isset($cookies)) { $request->cookie($cookies); } } else { $request = new Request($uri, $client_params, $allow_external, $injected_routes); } return $request; }
public static function drawmenu($menus = false) { #Helper::tad($menus); if (!$menus || !is_array($menus) || !count($menus)) { return false; } $return = ''; $current_url = (Request::secure() ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; #Helper::d($_SERVER); $return .= <<<HTML <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <div class="margin-bottom-25 margin-top-10 "> HTML; foreach ($menus as $menu) { $child_exists = isset($menu['child']) && is_array($menu['child']) && count($menu['child']); if ($child_exists) { $return .= '<div class="btn-group margin-bottom-5">'; } if (isset($menu['raw']) && $menu['raw'] != '') { $return .= $menu['raw']; } elseif (isset($menu['link'])) { #Helper::ta($menu); $current = $current_url == @$menu['link']; #Helper::ta($current_url . ' == ' . $menu['link'] . ' => ' . ($current_url == $menu['link'])); #$return .= "\n<!--\n" . $_SERVER['REQUEST_URI'] . "\n" . $menu['link'] . "\n-->\n"; #if (isset($menu['others'])) { # Helper::d(@$menu['others']); # Helper::dd(self::arrayToAttributes($menu['others'])); #} $additional = isset($menu['others']) ? self::arrayToAttributes($menu['others']) : ''; $return .= '<a class="' . @$menu['class'] . ($child_exists ? '' : ' margin-bottom-5') . '" href="' . @$menu['link'] . '" ' . $additional . '>' . ($current ? '<i class="fa fa-check"></i> ' : '') . @$menu['title'] . '</a> '; if ($child_exists) { $return .= '<a class="btn btn-default dropdown-toggle ' . @$menu['class'] . '" dropdown-toggle" data-toggle="dropdown" href="javascript:void(0);"> <span class="caret"></span> </a> <ul class="dropdown-menu text-left dropdown-menu-cutted">'; foreach ($menu['child'] as $child) { $current = $current_url == @$child['link']; #Helper::ta($current_url . ' == ' . $child['link'] . ' => ' . ($current_url == $child['link'])); $el_start = isset($child['link']) ? '<a class="' . @$child['class'] . '" href="' . @$child['link'] . '">' : '<span class="' . @$child['class'] . '">'; $el_end = isset($child['link']) ? '</a>' : '</span>'; $return .= '<li>' . $el_start . ($current ? '<i class="fa fa-check"></i> ' : '') . ($current ? @trim(str_replace(' ', ' ', $child['title'])) : @$child['title']) . $el_end . '</li> '; } $return .= '</ul> '; } } if ($child_exists) { $return .= "</div> "; } } $return .= <<<HTML </div> </div> </div> HTML; return $return; }
public static function createLink($link = NULL) { if (!is_null($link) && $link != "/" && mb_substr($link, 0, 1) != '/') { $link = '/' . $link; } #Helper::dd($link); #return url($link); return $link; $_locale = Session::get('locale'); if (!is_null($_locale)) { $string = $_locale . $link; if (Request::secure()) { return secure_url($string); } else { return url($string); } } else { return url($link); } }