dolibarr 25.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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27if (! defined('CSRFCHECK_WITH_TOKEN')) {
28 define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
29}
30
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34
35
44// Load translation files required by the page
45$langs->loadLangs(array("companies", "install", "users", "other"));
46
47if (!$user->admin) {
49}
50
51$action = GETPOST('action', 'aZ09');
52$confirm = GETPOST('confirm', 'alpha');
53
54// Security check
55if ($user->socid > 0) {
56 $action = '';
57 $socid = $user->socid;
58}
59
60$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
61$sortfield = GETPOST('sortfield', 'aZ09comma');
62$sortorder = GETPOST('sortorder', 'aZ09comma');
63$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
64if (empty($page) || $page == -1) {
65 $page = 0;
66} // If $page is not defined, or '' or -1
67$offset = $limit * $page;
68$pageprev = $page - 1;
69$pagenext = $page + 1;
70if (!$sortorder) {
71 $sortorder = "DESC";
72}
73if (!$sortfield) {
74 $sortfield = "dateevent";
75}
76
77
78/*
79 * Actions
80 */
81
82// Purge sessions
83if ($action == 'confirm_purge' && $confirm == 'yes' && $user->admin) {
84 $res = purgeSessions(session_id());
85}
86
87// Lock new sessions
88if ($action == 'confirm_lock' && $confirm == 'yes' && $user->admin) {
89 if (dolibarr_set_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', $user->login, 'text', 1, 'Logon is restricted to a particular user', 0) < 0) {
90 dol_print_error($db);
91 }
92}
93
94// Unlock new sessions
95if ($action == 'confirm_unlock' && $user->admin) {
96 if (dolibarr_del_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', -1) < 0) {
97 dol_print_error($db);
98 }
99}
100
101
102
103/*
104* View
105*/
106
107llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-tools_listsessions');
108
109$form = new Form($db);
110
111$userstatic = new User($db);
112$usefilter = 0;
113
114$listofsessions = listOfSessions();
115$num = count($listofsessions);
116
117print_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)
118
119$savehandler = ini_get("session.save_handler");
120$savepath = ini_get("session.save_path");
121$openbasedir = ini_get("open_basedir");
122$phparray = phpinfo_array();
123$suhosin = empty($phparray['suhosin']["suhosin.session.encrypt"]["local"]) ? '' : $phparray['suhosin']["suhosin.session.encrypt"]["local"];
124
125print '<b>'.$langs->trans("SessionSaveHandler").'</b>: '.$savehandler.'<br>';
126print '<b>'.$langs->trans("SessionSavePath").'</b>: '.$savepath.'<br>';
127if ($openbasedir) {
128 print '<b>'.$langs->trans("OpenBaseDir").'</b>: '.$openbasedir.'<br>';
129}
130if ($suhosin) {
131 print '<b>'.$langs->trans("SuhosinSessionEncrypt").'</b>: '.$suhosin.'<br>';
132}
133print '<br>';
134
135if ($action == 'purge') {
136 $formquestion = array();
137 print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('PurgeSessions'), $langs->trans('ConfirmPurgeSessions'), 'confirm_purge', $formquestion, 'no', 2);
138} elseif ($action == 'lock') {
139 $formquestion = array();
140 print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('LockNewSessions'), $langs->trans('ConfirmLockNewSessions', $user->login), 'confirm_lock', $formquestion, 'no', 1);
141}
142
143if ($savehandler == 'files') {
144 print '<table class="liste centpercent">';
145 print '<tr class="liste_titre">';
146 print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "login", "", "", 'align="left"', $sortfield, $sortorder);
147 print_liste_field_titre("SessionId", $_SERVER["PHP_SELF"], "id", "", "", 'align="left"', $sortfield, $sortorder);
148 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", "", "", 'align="left"', $sortfield, $sortorder);
149 print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "datem", "", "", 'align="left"', $sortfield, $sortorder);
150 print_liste_field_titre("Age", $_SERVER["PHP_SELF"], "age", "", "", 'align="left"', $sortfield, $sortorder);
151 print_liste_field_titre("Raw", $_SERVER["PHP_SELF"], "raw", "", "", 'align="left"', $sortfield, $sortorder);
153 print "</tr>\n";
154
155 $i = 0;
156 foreach ($listofsessions as $key => $sessionentry) {
157 print '<tr class="oddeven">';
158
159 // Login
160 print '<td>'.dol_escape_htmltag($sessionentry['login']).'</td>';
161
162 // ID
163 print '<td class="nowrap left">';
164 if ("$key" == session_id()) {
165 print $form->textwithpicto($key, $langs->trans("YourSession"));
166 } else {
167 print $key;
168 }
169 print '</td>';
170
171 // Date creation
172 print '<td class="nowrap left">'.dol_print_date($sessionentry['creation'], '%Y-%m-%d %H:%M:%S').'</td>';
173
174 // Date modification
175 print '<td class="nowrap left">'.dol_print_date($sessionentry['modification'], '%Y-%m-%d %H:%M:%S').'</td>';
176
177 // Age in seconds
178 print '<td>'.$sessionentry['age'].'</td>';
179
180 // Raw
181 print '<td>'.dol_trunc($sessionentry['raw'], 40, 'middle').'</td>';
182
183 print '<td>&nbsp;</td>';
184
185 print "</tr>\n";
186 $i++;
187 }
188 if (count($listofsessions) == 0) {
189 print '<tr class="oddeven"><td colspan="7">'.$langs->trans("NoSessionFound", $savepath, $openbasedir).'</td></tr>';
190 }
191 print "</table>";
192} elseif ($savehandler == 'user') {
193 print '<table class="liste centpercent">';
194 print '<tr class="liste_titre">';
195 print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "login", "", "", 'align="left"', $sortfield, $sortorder);
196 print_liste_field_titre("SessionId", $_SERVER["PHP_SELF"], "id", "", "", 'align="left"', $sortfield, $sortorder);
197 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", "", "", 'align="left"', $sortfield, $sortorder);
198 print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "datem", "", "", 'align="left"', $sortfield, $sortorder);
199 print_liste_field_titre("Age", $_SERVER["PHP_SELF"], "age", "", "", 'align="left"', $sortfield, $sortorder);
200 print_liste_field_titre("IPAddress", $_SERVER["PHP_SELF"], "raw", "", "", 'align="left"', $sortfield, $sortorder);
201 print_liste_field_titre("UserAgent", $_SERVER["PHP_SELF"], "raw", "", "", 'align="left"', $sortfield, $sortorder);
203 print "</tr>\n";
204
205 $i = 0;
206 foreach ($listofsessions as $key => $sessionentry) {
207 print '<tr class="oddeven">';
208
209 // Login
210 print '<td>'.dol_escape_htmltag($sessionentry['login']).'</td>';
211
212 // ID
213 print '<td class="nowrap left">';
214 if ("$key" == session_id()) {
215 print $form->textwithpicto($key, $langs->trans("YourSession"));
216 } else {
217 print $key;
218 }
219 print '</td>';
220
221 // Date creation
222 print '<td class="nowrap left">'.dol_print_date($sessionentry['creation'], '%Y-%m-%d %H:%M:%S').'</td>';
223
224 // Date modification
225 print '<td class="nowrap left">'.dol_print_date($sessionentry['modification'], '%Y-%m-%d %H:%M:%S').'</td>';
226
227 // Age in seconds
228 print '<td>'.$sessionentry['age'].'</td>';
229
230 // Remote IP
231 print '<td>'.dol_escape_htmltag((string) $sessionentry['remote_ip']).'</td>';
232
233 // User Agent
234 print '<td class="nowrap left">'.dol_escape_htmltag((string) $sessionentry['user_agent']).'</td>';
235 print '<td>&nbsp;</td>';
236 print "</tr>\n";
237 $i++;
238 }
239 if (count($listofsessions) == 0) {
240 print '<tr class="oddeven"><td colspan="7">'.$langs->trans("NoSessionFound", $savepath, $openbasedir).'</td></tr>';
241 }
242 print "</table>";
243} else {
244 print $langs->trans("NoSessionListWithThisHandler");
245}
246
247/*
248 * Buttons
249 */
250
251print '<div class="tabsAction">';
252
253
254if (!getDolGlobalString('MAIN_ONLY_LOGIN_ALLOWED')) {
255 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=lock&token='.newToken().'">'.$langs->trans("LockNewSessions").'</a>';
256} else {
257 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=confirm_unlock&token='.newToken().'">'.$langs->trans("UnlockNewSessions").'</a>';
258}
259
260if ($savehandler == 'files') {
261 if (count($listofsessions)) {
262 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=purge&token='.newToken().'">'.$langs->trans("PurgeSessions").'</a>';
263 }
264}
265
266print '</div>';
267
268print '<br>';
269
270// End of page
271llxFooter();
272$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.