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