dolibarr 21.0.0-alpha
listsessions.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26if (! defined('CSRFCHECK_WITH_TOKEN')) {
27 define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
28}
29
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33
34
35// Load translation files required by the page
36$langs->loadLangs(array("companies", "install", "users", "other"));
37
38if (!$user->admin) {
40}
41
42$action = GETPOST('action', 'aZ09');
43$confirm = GETPOST('confirm', 'alpha');
44
45// Security check
46if ($user->socid > 0) {
47 $action = '';
48 $socid = $user->socid;
49}
50
51$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
52$sortfield = GETPOST('sortfield', 'aZ09comma');
53$sortorder = GETPOST('sortorder', 'aZ09comma');
54$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
55if (empty($page) || $page == -1) {
56 $page = 0;
57} // If $page is not defined, or '' or -1
58$offset = $limit * $page;
59$pageprev = $page - 1;
60$pagenext = $page + 1;
61if (!$sortorder) {
62 $sortorder = "DESC";
63}
64if (!$sortfield) {
65 $sortfield = "dateevent";
66}
67
68
69/*
70 * Actions
71 */
72
73// Purge sessions
74if ($action == 'confirm_purge' && $confirm == 'yes' && $user->admin) {
75 $res = purgeSessions(session_id());
76}
77
78// Lock new sessions
79if ($action == 'confirm_lock' && $confirm == 'yes' && $user->admin) {
80 if (dolibarr_set_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', $user->login, 'text', 1, 'Logon is restricted to a particular user', 0) < 0) {
81 dol_print_error($db);
82 }
83}
84
85// Unlock new sessions
86if ($action == 'confirm_unlock' && $user->admin) {
87 if (dolibarr_del_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', -1) < 0) {
88 dol_print_error($db);
89 }
90}
91
92
93
94/*
95* View
96*/
97
98llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-tools_listsessions');
99
100$form = new Form($db);
101
102$userstatic = new User($db);
103$usefilter = 0;
104
105$listofsessions = listOfSessions();
106$num = count($listofsessions);
107
108print_barre_liste($langs->trans("Sessions"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, ($num ? $num : ''), 'setup'); // Do not show number (0) if no session found (it means we can't know)
109
110$savehandler = ini_get("session.save_handler");
111$savepath = ini_get("session.save_path");
112$openbasedir = ini_get("open_basedir");
113$phparray = phpinfo_array();
114$suhosin = empty($phparray['suhosin']["suhosin.session.encrypt"]["local"]) ? '' : $phparray['suhosin']["suhosin.session.encrypt"]["local"];
115
116print '<b>'.$langs->trans("SessionSaveHandler").'</b>: '.$savehandler.'<br>';
117print '<b>'.$langs->trans("SessionSavePath").'</b>: '.$savepath.'<br>';
118if ($openbasedir) {
119 print '<b>'.$langs->trans("OpenBaseDir").'</b>: '.$openbasedir.'<br>';
120}
121if ($suhosin) {
122 print '<b>'.$langs->trans("SuhosinSessionEncrypt").'</b>: '.$suhosin.'<br>';
123}
124print '<br>';
125
126if ($action == 'purge') {
127 $formquestion = array();
128 print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('PurgeSessions'), $langs->trans('ConfirmPurgeSessions'), 'confirm_purge', $formquestion, 'no', 2);
129} elseif ($action == 'lock') {
130 $formquestion = array();
131 print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('LockNewSessions'), $langs->trans('ConfirmLockNewSessions', $user->login), 'confirm_lock', $formquestion, 'no', 1);
132}
133
134if ($savehandler == 'files') {
135 print '<table class="liste centpercent">';
136 print '<tr class="liste_titre">';
137 print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "login", "", "", 'align="left"', $sortfield, $sortorder);
138 print_liste_field_titre("SessionId", $_SERVER["PHP_SELF"], "id", "", "", 'align="left"', $sortfield, $sortorder);
139 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", "", "", 'align="left"', $sortfield, $sortorder);
140 print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "datem", "", "", 'align="left"', $sortfield, $sortorder);
141 print_liste_field_titre("Age", $_SERVER["PHP_SELF"], "age", "", "", 'align="left"', $sortfield, $sortorder);
142 print_liste_field_titre("Raw", $_SERVER["PHP_SELF"], "raw", "", "", 'align="left"', $sortfield, $sortorder);
144 print "</tr>\n";
145
146 $i = 0;
147 foreach ($listofsessions as $key => $sessionentry) {
148 print '<tr class="oddeven">';
149
150 // Login
151 print '<td>'.$sessionentry['login'].'</td>';
152
153 // ID
154 print '<td class="nowrap left">';
155 if ("$key" == session_id()) {
156 print $form->textwithpicto($key, $langs->trans("YourSession"));
157 } else {
158 print $key;
159 }
160 print '</td>';
161
162 // Date creation
163 print '<td class="nowrap left">'.dol_print_date($sessionentry['creation'], '%Y-%m-%d %H:%M:%S').'</td>';
164
165 // Date modification
166 print '<td class="nowrap left">'.dol_print_date($sessionentry['modification'], '%Y-%m-%d %H:%M:%S').'</td>';
167
168 // Age
169 print '<td>'.$sessionentry['age'].'</td>';
170
171 // Raw
172 print '<td>'.dol_trunc($sessionentry['raw'], 40, 'middle').'</td>';
173
174 print '<td>&nbsp;</td>';
175
176 print "</tr>\n";
177 $i++;
178 }
179
180 if (count($listofsessions) == 0) {
181 print '<tr class="oddeven"><td colspan="7">'.$langs->trans("NoSessionFound", $savepath, $openbasedir).'</td></tr>';
182 }
183 print "</table>";
184} else {
185 print $langs->trans("NoSessionListWithThisHandler");
186}
187
188/*
189 * Buttons
190 */
191
192print '<div class="tabsAction">';
193
194
195if (!getDolGlobalString('MAIN_ONLY_LOGIN_ALLOWED')) {
196 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=lock&token='.newToken().'">'.$langs->trans("LockNewSessions").'</a>';
197} else {
198 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=confirm_unlock&token='.newToken().'">'.$langs->trans("UnlockNewSessions").'</a>';
199}
200
201if ($savehandler == 'files') {
202 if (count($listofsessions)) {
203 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=purge&token='.newToken().'">'.$langs->trans("PurgeSessions").'</a>';
204 }
205}
206
207print '</div>';
208
209print '<br>';
210
211// End of page
212llxFooter();
213$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
purgeSessions($mysessionid)
Purge existing sessions.
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
listOfSessions()
Return list of session.
phpinfo_array()
Return the php_info into an array.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.