public function setup() { $this->_ip_address = Input::instance()->ip_address; $this->_user_agent = request::user_agent(); $this->_save = $_SERVER; $_SERVER["HTTP_ACCEPT"] = "HTTP_ACCEPT"; $_SERVER["HTTP_ACCEPT_CHARSET"] = "HTTP_ACCEPT_CHARSET"; $_SERVER["HTTP_ACCEPT_ENCODING"] = "HTTP_ACCEPT_ENCODING"; $_SERVER["HTTP_ACCEPT_LANGUAGE"] = "HTTP_ACCEPT_LANGUAGE"; $_SERVER["HTTP_CONNECTION"] = "HTTP_CONNECTION"; $_SERVER["HTTP_HOST"] = "HTTP_HOST"; $_SERVER["HTTP_REFERER"] = "HTTP_REFERER"; $_SERVER["QUERY_STRING"] = "QUERY_STRING"; $_SERVER["REMOTE_ADDR"] = "REMOTE_ADDR"; $_SERVER["REMOTE_HOST"] = "REMOTE_HOST"; $_SERVER["REMOTE_PORT"] = "REMOTE_PORT"; request::set_user_agent("HTTP_USER_AGENT"); }
/** * See system/helpers/download.php */ private function sendHeaders($filename, $filesize = null) { if (!is_null($filesize)) { header('Content-Length: ' . $filesize); } // Retrieve MIME type by extension $mime = Kohana::config('mimes.' . strtolower(substr(strrchr($filename, '.'), 1))); $mime = empty($mime) ? 'application/octet-stream' : $mime[0]; header("Content-Type: {$mime}"); header('Content-Transfer-Encoding: binary'); // Send headers necessary to invoke a "Save As" dialog header('Content-Disposition: attachment; filename="' . $filename . '"'); // Prevent caching header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); $pragma = 'no-cache'; $cachecontrol = 'no-cache, max-age=0'; // request::user_agent('browser') seems bugged if (request::user_agent('browser') === 'Internet Explorer' || stripos(request::user_agent(), 'msie') !== false || stripos(request::user_agent(), 'internet explorer') !== false) { if (request::protocol() === 'https') { // See http://support.microsoft.com/kb/323308/en-us $pragma = 'cache'; $cachecontrol = 'private'; } else { if (request::user_agent('version') <= '6.0') { $pragma = ''; $cachecontrol = 'must-revalidate, post-check=0, pre-check=0'; } } } header('Pragma: ' . $pragma); header('Cache-Control: ' . $cachecontrol); }
/** * Create a new session. * * @param array variables to set after creation * @param string Force a specific session_id * @return void */ public function create($vars = NULL, $session_id = NULL) { // Destroy any current sessions $this->destroy(); if (Session::$config['driver'] !== 'native') { // Set driver name $driver = 'Session_' . ucfirst(Session::$config['driver']) . '_Driver'; // Load the driver if (!Kohana::auto_load($driver)) { throw new Kohana_Exception('The :driver: driver for the :library: library could not be found', array(':driver:' => Session::$config['driver'], ':library:' => get_class($this))); } // Initialize the driver Session::$driver = new $driver(); // Validate the driver if (!Session::$driver instanceof Session_Driver) { throw new Kohana_Exception('The :driver: driver for the :library: library must implement the :interface: interface', array(':driver:' => Session::$config['driver'], ':library:' => get_class($this), ':interface:' => 'Session_Driver')); } // Register non-native driver as the session handler session_set_save_handler(array(Session::$driver, 'open'), array(Session::$driver, 'close'), array(Session::$driver, 'read'), array(Session::$driver, 'write'), array(Session::$driver, 'destroy'), array(Session::$driver, 'gc')); } // Validate the session name if (!preg_match('~^(?=.*[a-z])[a-z0-9_]++$~iD', Session::$config['name'])) { throw new Kohana_Exception('The session_name, :session:, is invalid. It must contain only alphanumeric characters and underscores. Also at least one letter must be present.', array(':session:' => Session::$config['name'])); } // Name the session, this will also be the name of the cookie session_name(Session::$config['name']); // Set the session cookie parameters session_set_cookie_params(Session::$config['expiration'], Kohana::config('cookie.path'), Kohana::config('cookie.domain'), Kohana::config('cookie.secure'), Kohana::config('cookie.httponly')); $cookie = cookie::get(Session::$config['name']); if ($session_id === NULL) { // Reopen session from signed cookie value. $session_id = $cookie; } // Reopen an existing session if supplied if (!is_null($session_id)) { session_id($session_id); } // Start the session! session_start(); // Put session_id in the session variable $_SESSION['session_id'] = session_id(); // Set defaults if (!isset($_SESSION['_kf_flash_'])) { $_SESSION['total_hits'] = 0; $_SESSION['_kf_flash_'] = array(); $_SESSION['user_agent'] = request::user_agent(); $_SESSION['ip_address'] = $this->input->ip_address(); } // Set up flash variables Session::$flash =& $_SESSION['_kf_flash_']; // Increase total hits $_SESSION['total_hits'] += 1; // Validate data only on hits after one if ($_SESSION['total_hits'] > 1) { // Validate the session foreach (Session::$config['validate'] as $valid) { switch ($valid) { // Check user agent for consistency case 'user_agent': if ($_SESSION[$valid] !== request::user_agent()) { return $this->create(); } break; // Check ip address for consistency // Check ip address for consistency case 'ip_address': if ($_SESSION[$valid] !== $this->input->{$valid}()) { return $this->create(); } break; // Check expiration time to prevent users from manually modifying it // Check expiration time to prevent users from manually modifying it case 'expiration': if (time() - $_SESSION['last_activity'] > ini_get('session.gc_maxlifetime')) { return $this->create(); } break; } } } // Expire flash keys $this->expire_flash(); // Update last activity $_SESSION['last_activity'] = time(); // Set the new data Session::set($vars); }
/** * Call the display context callback for the given item */ static function get_display_context($item) { if (!request::user_agent("robot")) { $args = Cache::instance()->get("display_context_" . ($sid = Session::instance()->id())); $callback = $args[0]; $args[0] = $item; } if (empty($callback)) { $callback = "Albums_Controller::get_display_context"; $args = array($item); } return call_user_func_array($callback, $args); }
public static function reset() { request::$accept_charsets = NULL; request::$accept_encodings = NULL; request::$accept_languages = NULL; request::$accept_types = NULL; request::$user_agent = NULL; }
static function set_user_agent($value) { self::$user_agent = null; $_SERVER["HTTP_USER_AGENT"] = $value; }
/** * This function is called when the Gallery is fully initialized. We relay it to modules as the * "gallery_ready" event. Any module that wants to perform an action at the start of every * request should implement the <module>_event::gallery_ready() handler. */ static function ready() { // Don't keep a session for robots; it's a waste of database space. if (request::user_agent("robot")) { Session::instance()->abort_save(); } module::event("gallery_ready"); }
/** * Retrieves current user agent information * keys: browser, version, platform, mobile, robot * * @param string key * @return mixed NULL or the parsed value */ public static function user_agent($key = 'agent') { // Retrieve raw user agent without parsing if ($key === 'agent') { if (request::$user_agent === NULL) { return request::$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : ''; } if (is_array(request::$user_agent)) { return request::$user_agent['agent']; } return request::$user_agent; } if (!is_array(request::$user_agent)) { request::$user_agent = array(); request::$user_agent['agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : ''; // Parse the user agent and extract basic information foreach (Kohana::config('user_agents') as $type => $data) { foreach ($data as $fragment => $name) { if (stripos(request::$user_agent['agent'], $fragment) !== FALSE) { if ($type === 'browser' and preg_match('|' . preg_quote($fragment) . '[^0-9.]*+([0-9.][0-9.a-z]*)|i', request::$user_agent['agent'], $match)) { // Set the browser version request::$user_agent['version'] = $match[1]; } // Set the agent name request::$user_agent[$type] = $name; break; } } } } return isset(request::$user_agent[$key]) ? request::$user_agent[$key] : NULL; }
/** * Force the download of a file by the user's browser by preventing any * caching. Contains a workaround for Internet Explorer. * * @link http://support.microsoft.com/kb/316431 * @link http://support.microsoft.com/kb/812935 * * @uses download::dialog() * @uses download::send() * * @param string a file path or file name * @param mixed data to be sent if the filename does not exist * @param string suggested filename to display in the download * @return void */ public static function force($filename = NULL, $data = NULL, $nicename = NULL) { download::dialog(empty($nicename) ? $filename : $nicename); // Prevent caching header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); if (request::user_agent('browser') === 'Internet Explorer' and request::user_agent('version') <= '6.0') { // HTTP 1.0 header('Pragma:'); // HTTP 1.1 with IE extensions header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); } else { // HTTP 1.0 header('Pragma: no-cache'); // HTTP 1.1 header('Cache-Control: no-cache, max-age=0'); } if (is_file($filename)) { download::send($filename); } else { download::send($filename, $data); } }