dolibarr  16.0.5
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 
25 if (! defined('CSRFCHECK_WITH_TOKEN')) {
26  define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
27 }
28 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("companies", "install", "users", "other"));
35 
36 if (!$user->admin) {
38 }
39 
40 $action = GETPOST('action', 'aZ09');
41 $confirm = GETPOST('confirm', 'alpha');
42 
43 // Security check
44 if ($user->socid > 0) {
45  $action = '';
46  $socid = $user->socid;
47 }
48 
49 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
50 $sortfield = GETPOST('sortfield', 'aZ09comma');
51 $sortorder = GETPOST('sortorder', 'aZ09comma');
52 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
53 if (empty($page) || $page == -1) {
54  $page = 0;
55 } // If $page is not defined, or '' or -1
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
59 if (!$sortorder) {
60  $sortorder = "DESC";
61 }
62 if (!$sortfield) {
63  $sortfield = "dateevent";
64 }
65 
66 
67 /*
68  * Actions
69  */
70 
71 // Purge sessions
72 if ($action == 'confirm_purge' && $confirm == 'yes' && $user->admin) {
73  $res = purgeSessions(session_id());
74 }
75 
76 // Lock new sessions
77 if ($action == 'confirm_lock' && $confirm == 'yes' && $user->admin) {
78  if (dolibarr_set_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', $user->login, 'text', 1, 'Logon is restricted to a particular user', 0) < 0) {
79  dol_print_error($db);
80  }
81 }
82 
83 // Unlock new sessions
84 if ($action == 'confirm_unlock' && $user->admin) {
85  if (dolibarr_del_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', -1) < 0) {
86  dol_print_error($db);
87  }
88 }
89 
90 
91 
92 /*
93 * View
94 */
95 
96 llxHeader();
97 
98 $form = new Form($db);
99 
100 $userstatic = new User($db);
101 $usefilter = 0;
102 
103 $listofsessions = listOfSessions();
104 $num = count($listofsessions);
105 
106 print_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)
107 
108 $savehandler = ini_get("session.save_handler");
109 $savepath = ini_get("session.save_path");
110 $openbasedir = ini_get("open_basedir");
111 $phparray = phpinfo_array();
112 $suhosin = empty($phparray['suhosin']["suhosin.session.encrypt"]["local"]) ? '' : $phparray['suhosin']["suhosin.session.encrypt"]["local"];
113 
114 print '<b>'.$langs->trans("SessionSaveHandler").'</b>: '.$savehandler.'<br>';
115 print '<b>'.$langs->trans("SessionSavePath").'</b>: '.$savepath.'<br>';
116 if ($openbasedir) {
117  print '<b>'.$langs->trans("OpenBaseDir").'</b>: '.$openbasedir.'<br>';
118 }
119 if ($suhosin) {
120  print '<b>'.$langs->trans("SuhosinSessionEncrypt").'</b>: '.$suhosin.'<br>';
121 }
122 print '<br>';
123 
124 if ($action == 'purge') {
125  $formquestion = array();
126  print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('PurgeSessions'), $langs->trans('ConfirmPurgeSessions'), 'confirm_purge', $formquestion, 'no', 2);
127 } elseif ($action == 'lock') {
128  $formquestion = array();
129  print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('LockNewSessions'), $langs->trans('ConfirmLockNewSessions', $user->login), 'confirm_lock', $formquestion, 'no', 1);
130 }
131 
132 if ($savehandler == 'files') {
133  print '<table class="liste centpercent">';
134  print '<tr class="liste_titre">';
135  print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "login", "", "", 'align="left"', $sortfield, $sortorder);
136  print_liste_field_titre("SessionId", $_SERVER["PHP_SELF"], "id", "", "", 'align="left"', $sortfield, $sortorder);
137  print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", "", "", 'align="left"', $sortfield, $sortorder);
138  print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "datem", "", "", 'align="left"', $sortfield, $sortorder);
139  print_liste_field_titre("Age", $_SERVER["PHP_SELF"], "age", "", "", 'align="left"', $sortfield, $sortorder);
140  print_liste_field_titre("Raw", $_SERVER["PHP_SELF"], "raw", "", "", 'align="left"', $sortfield, $sortorder);
142  print "</tr>\n";
143 
144  foreach ($listofsessions as $key => $sessionentry) {
145  print '<tr class="oddeven">';
146 
147  // Login
148  print '<td>'.$sessionentry['login'].'</td>';
149 
150  // ID
151  print '<td class="nowrap left">';
152  if ("$key" == session_id()) {
153  print $form->textwithpicto($key, $langs->trans("YourSession"));
154  } else {
155  print $key;
156  }
157  print '</td>';
158 
159  // Date creation
160  print '<td class="nowrap left">'.dol_print_date($sessionentry['creation'], '%Y-%m-%d %H:%M:%S').'</td>';
161 
162  // Date modification
163  print '<td class="nowrap left">'.dol_print_date($sessionentry['modification'], '%Y-%m-%d %H:%M:%S').'</td>';
164 
165  // Age
166  print '<td>'.$sessionentry['age'].'</td>';
167 
168  // Raw
169  print '<td>'.dol_trunc($sessionentry['raw'], 40, 'middle').'</td>';
170 
171  print '<td>&nbsp;</td>';
172 
173  print "</tr>\n";
174  $i++;
175  }
176 
177  if (count($listofsessions) == 0) {
178  print '<tr class="oddeven"><td colspan="7">'.$langs->trans("NoSessionFound", $savepath, $openbasedir).'</td></tr>';
179  }
180  print "</table>";
181 } else {
182  print $langs->trans("NoSessionListWithThisHandler");
183 }
184 
185 /*
186  * Buttons
187  */
188 
189 print '<div class="tabsAction">';
190 
191 
192 if (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
193  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=lock&token='.newToken().'">'.$langs->trans("LockNewSessions").'</a>';
194 } else {
195  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=confirm_unlock&token='.newToken().'">'.$langs->trans("UnlockNewSessions").'</a>';
196 }
197 
198 if ($savehandler == 'files') {
199  if (count($listofsessions)) {
200  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=purge&token='.newToken().'">'.$langs->trans("PurgeSessions").'</a>';
201  }
202 }
203 
204 print '</div>';
205 
206 print '<br>';
207 
208 // End of page
209 llxFooter();
210 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
phpinfo_array
phpinfo_array()
Return the php_info into an array.
Definition: admin.lib.php:1923
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
print_barre_liste
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.
Definition: functions.lib.php:5257
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
listOfSessions
listOfSessions()
Return list of session.
Definition: admin.lib.php:967
dolibarr_set_const
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).
Definition: admin.lib.php:627
purgeSessions
purgeSessions($mysessionid)
Purge existing sessions.
Definition: admin.lib.php:1023
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59