dolibarr  9.0.0
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 <http://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', 'alpha');
35 $confirm=GETPOST('confirm', 'alpha');
36 
37 // Security check
38 if ($user->societe_id > 0)
39 {
40  $action = '';
41  $socid = $user->societe_id;
42 }
43 
44 $sortfield = GETPOST("sortfield",'alpha');
45 $sortorder = GETPOST("sortorder",'alpha');
46 $page = GETPOST("page",'int');
47 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
48 $offset = $conf->liste_limit * $page ;
49 $pageprev = $page - 1;
50 $pagenext = $page + 1;
51 if (! $sortorder) $sortorder="DESC";
52 if (! $sortfield) $sortfield="dateevent";
53 
54 
55 /*
56  * Actions
57  */
58 
59 // Purge sessions
60 if ($action == 'confirm_purge' && $confirm == 'yes' && $user->admin)
61 {
62  $res=purgeSessions(session_id());
63 }
64 
65 // Lock new sessions
66 if ($action == 'confirm_lock' && $confirm == 'yes' && $user->admin)
67 {
68  if (dolibarr_set_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', $user->login, 'text',1,'Logon is restricted to a particular user', 0) < 0)
69  {
70  dol_print_error($db);
71  }
72 }
73 
74 // Unlock new sessions
75 if ($action == 'confirm_unlock' && $user->admin)
76 {
77  if (dolibarr_del_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', -1) < 0)
78  {
79  dol_print_error($db);
80  }
81 }
82 
83 
84 
85 /*
86 * View
87 */
88 
89 llxHeader();
90 
91 $form=new Form($db);
92 
93 $userstatic=new User($db);
94 $usefilter=0;
95 
96 $listofsessions=listOfSessions();
97 $num=count($listofsessions);
98 
99 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)
100 
101 $savehandler=ini_get("session.save_handler");
102 $savepath=ini_get("session.save_path");
103 $openbasedir=ini_get("open_basedir");
104 $phparray=phpinfo_array();
105 $suhosin=empty($phparray['suhosin']["suhosin.session.encrypt"]["local"])?'':$phparray['suhosin']["suhosin.session.encrypt"]["local"];
106 
107 print '<b>'.$langs->trans("SessionSaveHandler").'</b>: '.$savehandler.'<br>';
108 print '<b>'.$langs->trans("SessionSavePath").'</b>: '.$savepath.'<br>';
109 if ($openbasedir) print '<b>'.$langs->trans("OpenBaseDir").'</b>: '.$openbasedir.'<br>';
110 if ($suhosin) print '<b>'.$langs->trans("SuhosinSessionEncrypt").'</b>: '.$suhosin.'<br>';
111 print '<br>';
112 
113 if ($action == 'purge')
114 {
115  $formquestion=array();
116  print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('PurgeSessions'), $langs->trans('ConfirmPurgeSessions'),'confirm_purge',$formquestion,'no',2);
117 }
118 else if ($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" width="100%">';
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 align="left" class="nowrap">';
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 align="left" class="nowrap">'.dol_print_date($sessionentry['creation'],'%Y-%m-%d %H:%M:%S').'</td>';
152 
153  // Date modification
154  print '<td align="left" class="nowrap">'.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 '.$bc[false].'><td colspan="6">'.$langs->trans("NoSessionFound",$savepath,$openbasedir).'</td></tr>';
171  }
172  print "</table>";
173 }
174 else
175 {
176  print $langs->trans("NoSessionListWithThisHandler");
177 }
178 
179 /*
180  * Buttons
181  */
182 
183 print '<div class="tabsAction">';
184 
185 
186 if (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
187 {
188  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=lock">'.$langs->trans("LockNewSessions").'</a>';
189 }
190 else
191 {
192  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=confirm_unlock">'.$langs->trans("UnlockNewSessions").'</a>';
193 }
194 
195 if ($savehandler == 'files')
196 {
197  if (count($listofsessions))
198  {
199  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=purge">'.$langs->trans("PurgeSessions").'</a>';
200  }
201 }
202 
203 print '</div>';
204 
205 print '<br>';
206 
207 // End of page
208 llxFooter();
209 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
listOfSessions()
Return list of session.
Definition: admin.lib.php:759
purgeSessions($mysessionid)
Purge existing sessions.
Definition: admin.lib.php:817
Class to manage Dolibarr users.
Definition: user.class.php:41
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:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
phpinfo_array()
Return the php_info into an array.
Definition: admin.lib.php:1675
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.