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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2013 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \file class_session.inc
* Source code for class session
*/
/*!
* \brief This class contains all the function needed to manage sessions
*/
class session {
public static function get_session_size()
{
}
public static function get_element_size()
{
}
/*!
* \brief Add channel in the session
*
* \param string $name Name of the new channel
*/
public static function add_channel($name)
{
/* If there's already such kind of channel, skip... */
if (isset($_SESSION[$name])) {
return FALSE;
}
/* Allocate it... */
$_SESSION[$name] = array();
$_POST["_channel_"] = $name;
return TRUE;
}
/*
* \brief Remove a channel from a session
*
* \param string $name Name of the channel to remove
*/
public static function remove_channel($name)
{
/* If there's already such kind of channel, skip... */
if (isset($_SESSION[$name])) {
unset($_SESSION[$name]);
if (isset($_POST["_channel_"])) {
unset($_POST["_channel_"]);
}
return TRUE;
}
return FALSE;
}
/*!
* \brief Check if the name of the session is set
*
* \param string $name The name of the session
*/
public static function is_set($name)
{
$channel = "";
if (isset($_POST['_channel_'])) {
$channel = $_POST['_channel_'];
}
/* Global fallback if not set */
if ($channel == "") {
return isset($_SESSION[$name]);
}
/* Sanity check */
if (!session::channel_exists($channel)) {
msg_dialog::display(_("Internal error"), _("Requested channel does not exist! Please contact your Administrator."), FATAL_ERROR_DIALOG);
}
$channel = "gch_".$channel;
return isset($_SESSION[$channel][$name]);
}
/*!
* \brief Check if a session is defined
*
* \param string $name Name of the session
*/
public static function global_is_set($name)
{
return isset($_SESSION[$name]);
}
/*!
* \brief Set a value in a session
*
* \param string $name Name of the session
*
* \param $value The new value
*/
public static function set($name, $value)
{
$channel = "";
if (isset($_POST['_channel_'])) {
$channel = $_POST['_channel_'];
}
/* Global fallback if not set */
if ($channel == "") {
$_SESSION[$name] = $value;
} else {
/* Sanity check */
if (!session::channel_exists($channel)) {
msg_dialog::display(_("Internal error"), _("Requested channel does not exist! Please contact your Administrator."), FATAL_ERROR_DIALOG);
}
$_SESSION[$channel][$name] = $value;
}
}
/*!
* \brief Set a value in a session
*
* \param string $name Name of the session
*
* \param $value The new value
*/
public static function global_set($name, $value)
{
$_SESSION[$name] = $value;
}
/*!
* \brief Accessor of a session
*
* \param string $name Name of the session
*/
public static function &get($name)
{
$channel = "";
if (isset($_POST['_channel_'])) {
$channel = $_POST['_channel_'];
}
/* Global fallback if not set */
if ($channel == "") {
$ret = &$_SESSION[$name];
return $ret;
}
/* Sanity check */
if (!session::channel_exists($channel)) {
msg_dialog::display(_("Internal error"), _("Requested channel does not exist! Please contact your Administrator."), FATAL_ERROR_DIALOG);
}
$channel = "gch_".$channel;
$ret = &$_SESSION[$channel][$name];
return $ret;
}
/*!
* \brief Accessor of a session
*
* \param string $name Name of the session
*/
public static function &global_get($name)
{
$ret = &$_SESSION[$name];
return $ret;
}
/*!
* \brief Delete a session
*
* \param string $name Name of the session to delete
*/
public static function delete($name)
{
$channel = "";
if (isset($_POST['_channel_'])) {
$channel = $_POST['_channel_'];
}
/* Global fallback if not set */
if ($channel == "") {
if (isset($_SESSION[$name])) {
unset($_SESSION[$name]);
}
} else {
if (isset($_SESSION[$channel][$name])) {
unset($_SESSION[$channel][$name]);
}
}
}
/*!
* \brief Delete a session
*
* \param string $name Name of the session to delete
*/
public static function global_delete($name)
{
if ($_SESSION[$name]) {
unset($_SESSION[$name]);
}
}
/*!
* \brief Unset a session
*
* \param string $name Name of the session to delete
*/
public static function un_set($name)
{
return session::delete($name);
}
/*!
* \brief Unset a session
*
* \param string $name Name of the session to delete
*/
public static function global_un_set($name)
{
return session::global_delete($name);
}
/*!
* \brief Start a session
*/
public static function start($id = NULL)
{
session_name("FusionDirectory");
/* Set cookie lifetime to one day (The parameter is in seconds ) */
session_set_cookie_params(24 * 60 * 60);
/* Set cache limter to one day (parameter is minute !!)*/
session_cache_expire(60 * 24); // default is 180
/* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
!! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from
the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
ini_set("session.gc_maxlifetime", 24 * 60 * 60);
if ($id !== NULL) {
session_id($id);
}
session_start();
/* Check for changed browsers and bail out */
if (isset($_SESSION['HTTP_USER_AGENT'])) {
if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT'])) {
session_destroy();
session_name("FusionDirectory");
session_start();
}
} else {
$_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
}
/* Regenerate ID to increase security */
if (!isset($_SESSION['started'])) {
session_regenerate_id();
$_SESSION['started'] = TRUE;
}
}
/*!
* \brief Destroy a session
*/
public static function destroy()
{
@session_destroy();
}
public static function set_lifetime($seconds = -1)
{
echo "Not implemented yet";
}
/*!
* \brief Get all sessions
*/
public static function &get_all()
{
$ret = &$_SESSION;
return $ret;
}
}
?>
|