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