/usr/share/knowledgeroot/include/class-session.php is in knowledgeroot 0.9.9.5-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | <?php
/**
* This class is for session handling
*
* @package Knowledgeroot
* @author Frank Habermann
* @version $Id
*/
class session {
/**
* array $CLASS global array to access all classes
*/
var $CLASS = array();
/**
* bool $handle enable to handle lifetime and checks of session
*/
var $handle = false;
/**
* int $lifetime session lifetime in minutes
*/
var $lifetime = 60;
/**
* string $name session name
*/
var $name = "";
/**
* string $id session id
*/
var $id = "";
/**
* bool $checkBrowser check session for same browser?
*/
var $checkBrowser = false;
/**
* bool $checkIP check session for same ip?
*/
var $checkIP = false;
/**
* bool $onlyCookie only allow cookies?
*/
var $onlyCookies = false;
/**
* init/start class
* @param array $CLASS reference to class array
*/
function start(&$CLASS) {
$this->CLASS =& $CLASS;
// check if session lifetime and session checking should be enabled
if(isset($this->CLASS['vars']['session']['handle']) && $this->CLASS['vars']['session']['handle'] == 1) {
// check for lifetime
if(isset($this->CLASS['vars']['session']['lifetime']) && is_int($this->CLASS['vars']['session']['lifetime'])) {
$this->lifetime = $this->CLASS['vars']['session']['lifetime'];
}
// check for checkBrowser
if(isset($this->CLASS['vars']['session']['checkBrowser']) && $this->CLASS['vars']['session']['checkBrowser'] == 1) {
$this->checkBrowser = true;
}
// check for checkIP
if(isset($this->CLASS['vars']['session']['checkIP']) && $this->CLASS['vars']['session']['checkIP'] == 1) {
$this->checkIP = true;
}
// check for only allow cookies
if(isset($this->CLASS['vars']['session']['onlyCookies']) && $this->CLASS['vars']['session']['onlyCookies'] == 1) {
$this->onlyCookies = true;
}
}
// set lifetime of session
$this->setLifeTime();
}
/**
* start session
* @param string $name name of session
* @return bool
*/
function startSession($name) {
// check for only allow cookies
if($this->onlyCookies) {
ini_set('session.use_trans_sid',0);
}
// set session name
$this->name = session_name($name);
// set session id
$this->id = session_id();
return session_start();
}
/**
* check session for user
* @return bool will return true if session is ok and false if not
*/
function checkSession() {
// for default session is not ok
$out = false;
// check if lastAccess is set
if(!isset($_SESSION['session']['lastAccess'])) {
$_SESSION['session']['lastAccess'] = time();
}
// check if browser is set
if(!isset($_SESSION['session']['browser']) && isset($_SERVER["HTTP_USER_AGENT"])) {
$_SESSION['session']['browser'] = md5($_SERVER["HTTP_USER_AGENT"]);
}
// check if ip is set
if(!isset($_SESSION['session']['ip']) && isset($_SERVER["REMOTE_ADDR"])) {
$_SESSION['session']['ip'] = $_SERVER["REMOTE_ADDR"];
}
// now check session
if($this->checkLifeTime() && $this->checkBrowser() && $this->checkIP()) {
$out = true;
}
// at the end set lastAccess time new
$_SESSION['session']['lastAccess'] = time();
return $out;
}
/**
* check lifetime of session
* @return bool
*/
function checkLifeTime() {
$out = false;
if($this->handle) {
if(isset($_SESSION['session']['lastAccess']) && $_SESSION['session']['lastAccess'] >= (time() - $this->lifetime*60)) {
$out = true;
}
} else {
// no session lifetime check so session is ok
$out = true;
}
return $out;
}
/**
* check for browser in session
* @return bool
*/
function checkBrowser() {
$out = false;
// now check for browser
if($this->checkBrowser) {
if(isset($_SESSION['session']['browser']) && isset($_SERVER["HTTP_USER_AGENT"]) && $_SESSION['session']['browser'] = md5($_SERVER["HTTP_USER_AGENT"])) {
$out = true;
}
} else {
// no session browser check is needed so session is ok
$out = true;
}
return $out;
}
/**
* check for ip in session
* @return bool
*/
function checkIP() {
$out = false;
// now check for browser
if($this->checkIP) {
if(isset($_SESSION['session']['ip']) && isset($_SERVER["REMOTE_ADDR"]) && $_SESSION['session']['ip'] = $_SERVER["REMOTE_ADDR"]) {
$out = true;
}
} else {
// no session ip check is need so session is ok
$out = true;
}
return $out;
}
/**
* set session lifetime
* @param integer $time time for session timeout in seconds
* @return integer return lifetime of session
*/
function setLifeTime($time = null) {
if($time != null && is_int($time)) {
$this->lifetime = $time;
}
ini_set("session.gc_maxlifetime", $this->lifetime);
return ini_get("session.gc_maxlifetime");
}
}
?>
|