1 |
82cd6022
|
PiBa-NL
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
* phpsessionmanager.inc
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2016 Electric Sheep Fencing
|
7 |
8f2f85c3
|
Luiz Otavio O Souza
|
* Copyright (c) 2016-2022 Rubicon Communications, LLC (Netgate)
|
8 |
82cd6022
|
PiBa-NL
|
* All rights reserved.
|
9 |
|
|
*
|
10 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11 |
|
|
* you may not use this file except in compliance with the License.
|
12 |
|
|
* You may obtain a copy of the License at
|
13 |
|
|
*
|
14 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15 |
|
|
*
|
16 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
17 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19 |
|
|
* See the License for the specific language governing permissions and
|
20 |
|
|
* limitations under the License.
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
$session_opencounter = 0;
|
24 |
|
|
$session_write = false;
|
25 |
|
|
$session_action_list = array();
|
26 |
|
|
|
27 |
|
|
function simplestacktrace() {
|
28 |
|
|
$stack = debug_backtrace();
|
29 |
|
|
$str = "";
|
30 |
|
|
foreach($stack as $s) {
|
31 |
|
|
// $s['args']
|
32 |
|
|
$str .= "\n{$s['function']}(..) - {$s['file']}:{$s['line']}";
|
33 |
|
|
}
|
34 |
|
|
return $str;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
function phpsession_begin() {
|
38 |
|
|
global $session_opencounter, $session_action_list;
|
39 |
|
|
$session_action_list[] = "#### phpsession_begin ####" . simplestacktrace();
|
40 |
|
|
if ($session_opencounter == 0) {
|
41 |
|
|
session_start();
|
42 |
|
|
}
|
43 |
|
|
$session_opencounter++;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
function phpsession_destroy() {
|
47 |
|
|
global $session_opencounter, $session_action_list;
|
48 |
|
|
$session_action_list[] = "#### phpsession_destroy ####" . simplestacktrace();
|
49 |
|
|
session_destroy();
|
50 |
|
|
$session_opencounter = 0;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
function phpsession_end($write = false) {
|
54 |
|
|
global $session_opencounter, $session_write, $session_action_list;
|
55 |
|
|
$session_action_list[] = "#### phpsession_end ####" . simplestacktrace();
|
56 |
|
|
$session_write |= $write;
|
57 |
|
|
$session_opencounter--;
|
58 |
|
|
if ($session_opencounter == 0) {
|
59 |
|
|
if ($session_write) {
|
60 |
|
|
session_commit();
|
61 |
|
|
$session_write = false;
|
62 |
|
|
} else {
|
63 |
|
|
session_abort();
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
if ($session_opencounter < 0) {
|
67 |
|
|
$session_opencounter = 0;
|
68 |
dc064879
|
PiBa-NL
|
syslog(LOG_WARNING, "PHPSESSION closed more often than opened!" . simplestacktrace());
|
69 |
82cd6022
|
PiBa-NL
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
function phpsession_cleanupcheck() {
|
73 |
|
|
global $session_opencounter, $session_action_list;
|
74 |
|
|
if ($session_opencounter > 0) {
|
75 |
dc064879
|
PiBa-NL
|
syslog(LOG_WARNING, "PHPSESSION {$session_opencounter} open sessions left at shutdown script!".print_r($session_action_list, true));
|
76 |
82cd6022
|
PiBa-NL
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
dc064879
|
PiBa-NL
|
register_shutdown_function('phpsession_cleanupcheck');
|