public function setIp() { $ipKey = ServerModel::firstOrNew(array('key' => 'ip')); $ipKey->value = Request::server('REMOTE_ADDR'); $ipKey->save(); return $ipKey->value; }
/** * Create a new job instance. * * @return void */ public function __construct($keywords) { $this->username = \Request::server('PHP_AUTH_USER', 'sampleuser'); $keywords = strip_tags(str_replace("'", " ", $keywords)); $keywords = strtolower($keywords); $this->keywords = $keywords; }
/** * Bootstrap the application events. * * @return void */ public function boot() { $app = $this->app; $configPath = __DIR__ . '/../config/debugbar.php'; $this->publishes([$configPath => $this->getConfigPath()], 'config'); if ($app->runningInConsole()) { if (false === array_key_exists(1, \Request::server('argv')) || true === empty($artisanCommand = \Request::server('argv')[1]) || 'config:cache' !== $artisanCommand) { $this->app['config']->set('debugbar.enabled', false); } } $routeConfig = ['namespace' => 'Barryvdh\\Debugbar\\Controllers', 'prefix' => $this->app['config']->get('debugbar.route_prefix')]; $this->getRouter()->group($routeConfig, function ($router) { $router->get('open', ['uses' => 'OpenHandlerController@handle', 'as' => 'debugbar.openhandler']); $router->get('clockwork/{id}', ['uses' => 'OpenHandlerController@clockwork', 'as' => 'debugbar.clockwork']); $router->get('assets/stylesheets', ['uses' => 'AssetController@css', 'as' => 'debugbar.assets.css']); $router->get('assets/javascript', ['uses' => 'AssetController@js', 'as' => 'debugbar.assets.js']); }); $enabled = $this->app['config']->get('debugbar.enabled'); // If enabled is null, set from the app.debug value if (is_null($enabled)) { $enabled = $this->checkAppDebug(); $this->app['config']->set('debugbar.enabled', $enabled); } if (!$enabled) { return; } /** @var LaravelDebugbar $debugbar */ $debugbar = $this->app['debugbar']; $debugbar->boot(); $this->registerMiddleware('Barryvdh\\Debugbar\\Middleware\\Debugbar'); }
public function contents($model_id = 0, $slug = '') { $network = $this->network; $theme = $network->theme; $theme = check_for_tour_theme($theme); Theme::setActive($theme); $data = $this->data; $model = Model::find($model_id); if ($model) { $contents = $model->contents()->published()->ofNetwork($this->network->id)->orderBy('id', 'desc')->get(); $data['page_title'] = $model->name . ' Contents'; $data['model'] = $model; $data['contents'] = $contents; $content_views = 0; foreach ($contents as $content) { $content_views = $content_views + $content->fake_views; } $data['content_views'] = $content_views; $username = \Request::server('PHP_AUTH_USER', 'sampleuser'); $data['is_favorite'] = $username && Favorite::ofUsername($username)->hasFavorite('Model', $model->id)->count() ? 1 : 0; $this->breadcrumbs->addCrumb('Popular Models', url('models')); $this->breadcrumbs->addCrumb($model->name . ' Contents'); return Theme::view('model.contents', $data); } }
/** * Generates a signature for a packet request response * * @param array $packet * @param int|null $code * @param string|\Exception|null $message * * @return array * */ protected static function signPacket(array $packet, $code = null, $message = null) { $_ex = false; if ($code instanceof \Exception) { $_ex = $code; $code = null; } elseif ($message instanceof \Exception) { $_ex = $message; $message = null; } !$code && ($code = Response::HTTP_OK); $code = $code ?: ($_ex ? $_ex->getCode() : Response::HTTP_OK); $message = $message ?: ($_ex ? $_ex->getMessage() : null); $_startTime = \Request::server('REQUEST_TIME_FLOAT', \Request::server('REQUEST_TIME', $_timestamp = microtime(true))); $_elapsed = $_timestamp - $_startTime; $_id = sha1($_startTime . \Request::server('HTTP_HOST') . \Request::server('REMOTE_ADDR')); // All packets have this $_packet = array_merge($packet, ['error' => false, 'status_code' => $code, 'request' => ['id' => $_id, 'version' => static::PACKET_VERSION, 'signature' => base64_encode(hash_hmac(config('dfe.signature-method'), $_id, $_id, true)), 'verb' => \Request::method(), 'request-uri' => \Request::getRequestUri(), 'start' => date('c', $_startTime), 'elapsed' => (double) number_format($_elapsed, 4)]]); // Update the error entry if there was an error if (!array_get($packet, 'success', false) && !array_get($packet, 'error', false)) { $_packet['error'] = ['code' => $code, 'message' => $message, 'exception' => $_ex ? Json::encode($_ex) : false]; } else { array_forget($_packet, 'error'); } return $_packet; }
/** * Test the Request::server method. * * @group laravel */ public function testServerMethodReturnsFromServerArray() { $this->setServerVar('TEST', 'something'); $this->setServerVar('USER', array('NAME' => 'taylor')); $this->assertEquals('something', Request::server('test')); $this->assertEquals('taylor', Request::server('user.name')); }
/** * @param $initial_hits * @param $exception_type * @return bool */ public function add($initial_hits, $exception_type) { $res = false; try { $remote_address = Request::server('REMOTE_ADDR'); //try to create on cache $this->cache_service->addSingleValue($remote_address, $initial_hits, intval($this->server_configuration_service->getConfigValue("BlacklistSecurityPolicy.BannedIpLifeTimeSeconds"))); $this->tx_service->transaction(function () use($remote_address, $exception_type, $initial_hits, &$res) { $banned_ip = BannedIP::where("ip", "=", $remote_address)->first(); if (!$banned_ip) { $banned_ip = new BannedIP(); $banned_ip->ip = $remote_address; } $banned_ip->exception_type = $exception_type; $banned_ip->hits = $initial_hits; if (Auth::check()) { $banned_ip->user_id = Auth::user()->getId(); } $res = $banned_ip->Save(); }); } catch (Exception $ex) { $this->log_service->error($ex); $res = false; } return $res; }
public function postAdminAccount() { $data = Input::all(); //return View::make('install.done'); try { $user = Sentry::createUser(array('email' => $data['email'], 'password' => $data['password'], 'activated' => true, 'first_name' => $data['first_name'], 'last_name' => $data['last_name'])); $group = Sentry::findGroupByName('admin'); $user->addGroup($group); $quicknote = new \Quicknote(); $quicknote->user_id = $user->id; $quicknote->save(); $userProfile = new \UserProfile(); $userProfile->id = $user->id; $userProfile->save(); $imageResult = App::make('AuthController')->{'createUserImage'}($user->id, $data['first_name'][0], $data['last_name'][0]); $installationDate = date('Y-m-d H:i:s'); $installationHost = Request::server('PATH_INFO'); $new92fiveConfig = new NewConfig(); $new92fiveConfig->toFile(app_path() . '/config/92five.php', ['install' => true, 'version' => '1.0', 'installationDate' => $installationDate, 'installationHost' => $installationHost]); return View::make('install.done'); } catch (Exception $e) { Log::error('Something Went Wrong in Install Controller Repository - addUserWithDetails():' . $e->getMessage()); throw new Exception('Something Went Wrong in Install Controller Repository - addUserWithDetails()'); } }
public function getAsArray($redundantly = false) { if (isset($this->id) && (int) $this->id > 0) { $content = array(); if (!is_null($this->text)) { $content['text'] = $this->text; } else { if (!is_null($this->image_id)) { $domain = 'http' . (Request::server('HTTPS') ? '' : 's') . '://' . Request::server('HTTP_HOST'); $attachment = MessageAttachment::find($this->image_id); $content['image'] = array('id' => (int) $attachment->id, 'thumb' => $domain . '/api/messages/attach/thumb/' . $attachment->id, 'origin' => $domain . '/api/messages/attach/gallery/' . $attachment->id, 'width' => $attachment->width, 'height' => $attachment->height); } else { if (!is_null($this->car_id)) { $car = Car::withTrashed()->find($this->car_id); $content['car'] = array('id' => (int) $car->id, 'mark' => (int) $car->mark, 'model' => (int) $car->model, 'year' => (int) $car->year, 'color' => (int) $car->color, 'vehicle_type' => (int) $car->vehicle_type, 'body_type' => (int) $car->body_type); if (!is_null($this->car_number)) { $content['car']['number'] = $this->car_number; } } else { if (!is_null($this->lat)) { $content['geo'] = array('lat' => (double) $this->lat, 'long' => (double) $this->lng, 'location' => $this->location); } } } } if ($redundantly) { $user = User::find($this->user_id); return array('message_id' => (int) $this->id, 'chat_id' => (int) $this->chat_id, 'user' => array('id' => (int) $user->id, 'name' => $user->name, 'img' => array('middle' => $user->img_middle)), 'content' => $content, 'timestamp' => $this->getTimestamp(), 'delivered_at' => $this->delivered_at, 'viewed_at' => $this->viewed_at); } else { return array('message_id' => (int) $this->id, 'chat_id' => (int) $this->chat_id, 'user_id' => (int) $this->user_id, 'content' => $content, 'timestamp' => $this->getTimestamp(), 'delivered_at' => $this->delivered_at, 'viewed_at' => $this->viewed_at); } } return array(); }
/** * Register University * * @return View */ public function registerUniversity() { if (!is_null(Input::get('g-recaptcha-response'))) { $recaptcha = new \ReCaptcha\ReCaptcha(Config::get('recaptcha.private_key')); $resp = $recaptcha->verify(Input::get('g-recaptcha-response'), Request::server('REMOTE_ADDR')); if ($resp->isSuccess()) { $user = new User(); $user->user = trim(strtolower(Input::get('university_email'))); $user->password = Hash::make(Input::get('university_password')); $user->rank = "university"; $user->last_activity = null; try { $user->save(); } catch (MongoDuplicateKeyException $e) { return Redirect::back()->withErrors(array('error' => Lang::get('register_university.email_duplicated'))); } $user = User::first(['user' => $user->user]); $university = new University(); $university->_id = $user->_id; $university->name = trim(Input::get('university_name')); $university->email = trim(strtolower(Input::get('university_email'))); $university->acronym = strtoupper(trim(Input::get('university_acronym'))); $university->profile_image = null; $university->save(); return Redirect::to('/')->with('message', Lang::get('register_university.register_true')); } else { $errors = $resp->getErrorCodes(); return Redirect::back()->withErrors(array('error' => Lang::get('register_student.message_captcha') . ' [' . $errors[0] . ']')); } } else { return Redirect::back()->withErrors(array('error' => Lang::get('register_student.message_captcha') . ' [ 99 ]')); } }
/** * Create a new job instance. * * @return void */ public function __construct($id) { $this->content = Content::find($id); $this->username = \Request::server('PHP_AUTH_USER'); $referer = \Request::server('HTTP_REFERER'); $this->referrer = $referer ? $referer : ''; }
public function boot(Router $router) { $this->commands(Install::class); foreach ($this->routeMiddleware as $key => $middleware) { $router->middleware($key, $middleware); } $groupOptions = ['namespace' => $this->namespace]; if (config('adminPanel.subDomain')) { $groupOptions['domain'] = config('adminPanel.routePrefix') . '.' . preg_replace("/^(.*?)\\.(.*)\$/", "\$2", \Request::server('SERVER_NAME')); } else { $groupOptions['prefix'] = config('adminPanel.routePrefix'); } $router->group($groupOptions, function (Router $router) { $router->controller('auth', 'Auth\\AuthController', ['getRegister' => 'admin.register', 'getLogin' => 'admin.login', 'getLogout' => 'admin.logout']); $router->group(['middleware' => 'ap.permission', 'permission' => config('adminPanel.ap_permission')], function (Router $route) { $route->get('/', ['as' => 'admin.home', function () { return view('adminPanel::hello'); }]); $route->controller('ajax', 'AjaxController'); $route->resource('user', 'UserController', ['as' => 'admin']); $route->model('role', config('entrust.role')); $route->resource('role', 'RoleController', ['as' => 'admin']); $route->model('permission', config('entrust.permission')); $route->resource('permission', 'PermissionController', ['as' => 'admin']); }); }); $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'adminPanel'); $this->publishes([__DIR__ . '/../../config/config.php' => config_path('adminPanel.php')], 'config'); $this->publishes([__DIR__ . '/../../resources/assets' => base_path('resources/adminAssets')], 'assets'); $this->publishes([__DIR__ . '/../../migrations' => base_path('database/migrations')], 'migrate'); }
public function __construct() { $this->userIp = class_exists('\\Illuminate\\Support\\Facades\\Request') ? \Request::getClientIp() : $_SERVER['REMOTE_ADDR']; $this->userAgent = class_exists('\\Illuminate\\Support\\Facades\\Request') ? \Request::server('HTTP_USER_AGENT') : $_SERVER['HTTP_USER_AGENT']; $this->referrer = class_exists('\\Illuminate\\Support\\Facades\\URL') ? \URL::previous() : $_SERVER['HTTP_REFERER']; $this->permalink = class_exists('\\Illuminate\\Support\\Facades\\Request') ? \Request::url() : $_SERVER['REQUEST_URI']; }
public function addToPopularSearchImages($arrData) { //$query = Request::server('REQUEST_URI'); $query = isset($arrData['query']) ? $arrData['query'] : ""; $request_url = Request::server('REQUEST_URI') != "" && Request::server('REQUEST_URI') != "/" ? Request::server('REQUEST_URI') : $query; return PopularSearchImages::create(array('keyword' => trim($arrData['keyword']), 'image_id' => $arrData['image_id'], 'query' => $request_url)); }
/** * Detect and set application localization environment (language). * NOTE: Don't foreget to ADD/SET/UPDATE the locales array in app/config/app.php! * */ private function configureLocale() { $mLocale = Config::get('app.locale'); if (!Session::has('locale')) { $mFromCookie = Cookie::get('locale', null); if ($mFromCookie != null && in_array($mFromCookie, Config::get('app.locales'))) { $mLocale = $mFromCookie; } else { $mFromURI = Request::segment(1); if ($mFromURI != null && in_array($mFromURI, Config::get('app.locales'))) { $mLocale = $mFromURI; } else { $mFromBrowser = substr(Request::server('http_accept_language'), 0, 2); if ($mFromBrowser != null && in_array($mFromBrowser, Config::get('app.locales'))) { $mLocale = $mFromBrowser; } } } Session::put('locale', $mLocale); Cookie::forever('locale', $mLocale); } else { $mLocale = Session::get('locale'); } App::setLocale($mLocale); }
public function exec() { try { $request = new Request(); $url = new Url($request->server('REQUEST_URI')); $path = $url->path . '/' . $url->file; d('' . $url); if (!isset($this->routing[$path])) { throw new Exception('routing not found'); } $rounting = $this->routing[$path]; // Controllerをrequire require_once implode('/', [PATH_CONTROLLER, $rounting[0] . '.php']); $controller = $rounting[0]; $action = $rounting[1]; // actionを実行 $class = new ReflectionClass($controller); $instance = $class->newInstance($request); $reflMethod = new ReflectionMethod($controller, $action . 'Action'); $reflMethod->invoke($instance); } catch (Exception $e) { d('####### 処理されない例外 #######'); d($e); } }
public function action_index($modelName) { $model = $this->getClassObject($modelName); $columnModel = $model::first(); Input::flash(); if (Input::get($modelName) != null && $this->addConditions($model, $modelName)->first() != null) { $columnModel = $this->addConditions($model, $modelName)->first(); } if ($columnModel == null) { return Redirect::to("/lara_admin/models/{$modelName}/new"); } $columns = $columnModel->columns(); $sort_options = $this->setOrderOptions($columns); $models = $this->addConditions($model, $modelName)->order_by($sort_options["column_order"], $sort_options["sort_direction"])->paginate($model->perPage); $request_uri = Request::server("REQUEST_URI"); $request_uri = preg_replace("/&order=[^&]*/", "", $request_uri); if (!preg_match("/\\?/i", Request::server("REQUEST_URI"))) { $request_uri .= "?"; } //TODO function getCustomAction $name_custom_action = "lara_admin::" . Str::plural(Str::lower($modelName)) . "." . preg_replace("/action_/", "", __FUNCTION__); if (View::exists($name_custom_action) != false) { $view = View::make($name_custom_action, array("sort_options" => $sort_options, "request_uri" => $request_uri, "modelName" => $modelName, "modelInstance" => $model, "models" => $models, "columns" => $columns)); } else { $view = View::make("lara_admin::models.index", array("sort_options" => $sort_options, "request_uri" => $request_uri, "modelName" => $modelName, "modelInstance" => $model, "models" => $models, "columns" => $columns)); } $this->defaultAttrForLayout($modelName, $view); return $this->response_with(array("xml", "json", "csv"), $this->collectionToArray($models->results), true); }
/** * Redirects the user to the secure url */ public static function https() { // get the host and url $host = Request::server('HTTP_HOST'); $url = Request::server('REQUEST_URI'); $https = 'https://' . $host . $url; self::redirect($https); }
public function pathMode() { $path = Request::server('REQUEST_URI'); $pathArr = explode('/', trim($path, '/')); $this->routeInfo['app'] = isset($pathArr[0]) ? $pathArr[0] : ''; $this->routeInfo['controller'] = isset($pathArr[1]) ? $pathArr[1] : ''; $this->routeInfo['action'] = isset($pathArr[2]) ? $pathArr[2] : ''; }
public function index($ads_id = '') { $data['id'] = $ads_id; $data['username'] = \Request::server('PHP_AUTH_USER'); \Queue::push('App\\Jobs\\UpdateAdsClickCount', $data); $ads = Advertisement::find($ads_id); return redirect()->away($ads->url); }
protected function parseRequest(Request $request) { $requestUri = str_replace(base_path(), '', $request->server('REQUEST_URI')); $path = strstr($requestUri, '?', true); if (!$path) { $path = $requestUri; } return $path; }
/** * Get all of the input and files for the request and store them in params. * */ public function setParameters() { $this->params = \Request::all(); $this->CORS = isset($this->params['method']); $this->method = $this->CORS ? $this->params['method'] : \Request::server('REQUEST_METHOD'); if (!isset($this->params['content'])) { $this->params['content'] = file_get_contents("php://input"); } }
public function postAdmin() { $email = preg_replace('/\\s+/', '', Input::get('email')); $password = preg_replace('/\\s+/', '', Input::get('password')); $validation = array('email' => 'required|email', 'password' => 'required|min:6'); $messages = array('password.required' => 'The password is required.', 'password.min' => 'The password must be at least 6 characters(No spaces allowed).'); $validator = Validator::make(array('email' => $email, 'password' => $password), $validation, $messages); if ($validator->fails()) { return Redirect::back()->withInput(Input::except('password'))->withErrors($validator); } try { $user = Sentry::createUser(array('email' => $email, 'password' => $password, 'activated' => true)); // Find the group using the group id $admin_group = Sentry::findGroupByName('Administrator'); // Assign the group to the user $user->addGroup($admin_group); // return Redirect::to('install/complete'); $credentials = array('email' => $email, 'password' => $password); // Authenticate the user $auth = Sentry::authenticate($credentials, false); $data = array('track' => 2); $write = $this->track_obj->writeTrack($data); if ($write) { Log::info('Installation track wrote successfully'); } else { Log::error('Failed to write installation track'); } // TrackReq::get()->send_track($_SERVER['REQUEST_URI']); $ret = TrackReq::get()->sendTrack(Request::server('SERVER_NAME') . $_SERVER['REQUEST_URI']); if ($ret[0]) { Log::info('Installed successfully'); } else { Log::error('Installation failed', ['context' => $ret[1]]); } return Redirect::to('setting'); // return Redirect::to('login/login/1'); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::back()->withInput(Input::except('password'))->with('msg', 'Login field is required'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::back()->withInput(Input::except('password'))->with('msg', 'Password field is required.'); } catch (Cartalyst\Sentry\Users\UserExistsException $e) { return Redirect::back()->withInput(Input::except('password'))->with('msg', 'User with this login already exists.'); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { return Redirect::back()->withInput(Input::except('password'))->with('msg', 'Group was not found.'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::back()->withInput()->with('msg', 'Wrong password, try again.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::back()->withInput()->with('msg', 'User was not found.'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::back()->withInput()->with('msg', 'User is not activated.'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::back()->withInput()->with('msg', 'User is suspended.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::back()->withInput()->with('msg', 'User is banned.'); } }
/** * Check Google ReCaptcha * @param $gReCaptchaResponse * @return bool */ public static function checkRecaptcha($gReCaptchaResponse) { $recaptcha = new \ReCaptcha\ReCaptcha(Config::get('RECAPTCHA_SECRET')); $resp = $recaptcha->verify($gReCaptchaResponse, Request::server('REMOTE_ADDR')); if ($resp->isSuccess()) { return true; } else { return false; } }
/** * Make API navigation for current controller from static::$hateoas * * @param array $links_replace [placeholder > value] Replacements inside hrefs in static::$hateoas * @return mixed */ public static function getHATEOAS(array $links_replace = []) { $links = static::$hateoas; if (!empty($links_replace)) { foreach ($links as $key => $link) { $links[$key]['href'] = str_replace(array_keys($links_replace), array_values($links_replace), $link['href']); } } $links['self'] = ['href' => [\Request::server('REQUEST_URI')], 'methods' => [\Request::server('REQUEST_METHOD')]]; return $links; }
public function testPost() { $req = new Request(); $_POST['test'] = 1; $this->assertEquals($_POST['test'], $req->test); $this->assertTrue(isset($req->test)); $this->assertFalse($req->isPost()); $_SERVER['REQUEST_METHOD'] = 'POST'; $this->assertTrue($req->isPost()); $this->assertEquals($_SERVER['REQUEST_METHOD'], $req->server('REQUEST_METHOD')); }
/** * Insert given mail data to database * * @param Request $request Request object * * @return type */ public function insertMails($request) { $data = $request->all(); foreach ($data as $field => $value) { if (!empty($value)) { $this->mailer->{$field} = $value; } } $this->mailer->referer = $request->server('HTTP_HOST'); $this->mailer->save(); return $this->getOutput(IsMailer::get()); }
private function send_email($user) { if (Request::server('SERVER_NAME') != 'localhost') { Mail::send('emails.auth.authenticate', array('email' => $user->email, 'url' => URL::to('activate') . '/' . $user->activation_token), function ($message) use($user) { $message->to($user->email, 'User')->subject('Please Validate your account - Dispatch Taxi Cab. '); }); } else { Mail::pretend('emails.auth.authenticate', array('email' => $user->email, 'url' => URL::to('activate') . '/' . $user->activation_token), function ($message) use($user) { $message->to($user->email, 'User')->subject('Please Validate your account - Dispatch Taxi Cab. '); }); } }
public static function here($params = array(), $html = true) { $protocol = Request::server()->server_protocol(); $protocol = stripos($protocol, 'https') !== false ? 'https' : 'http'; $host = Request::server()->server_name(); $host = $host ? $host : Request::server()->server_addr(); $here = Request::server()->request_uri(); $here = explode('?', $here); $here = reset($here); $here = $protocol . '://' . $host . $here; return self::url($here, $params, $html); }
/** * According to the specified type to display. * @param $type * @param $msg * @param null $jumpUrl * @param null $timeout * @return \Illuminate\View\View */ public function show($type, $msg, $jumpUrl = null, $timeout = null) { $data = array(); $data['type'] = $type; $data['msg'] = $msg; $data['jumpUrl'] = $jumpUrl === null ? \Request::server('HTTP_REFERER') : $jumpUrl; if (\Config::get('msgbox::auto_jump') != false) { $data['timeout'] = $timeout === null ? \Config::get('msgbox::default_timeout') : $timeout; } else { $data['timeout'] = 0; } return \View::make("msgbox::msg", $data); }