dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("install");
29 
30 if (! $user->admin)
32 
33 $action=GETPOST('action', 'alpha');
34 $confirm=GETPOST('confirm', 'alpha');
35 
36 // Security check
37 if ($user->societe_id > 0)
38 {
39  $action = '';
40  $socid = $user->societe_id;
41 }
42 
43 $langs->load("companies");
44 $langs->load("users");
45 $langs->load("other");
46 
47 $sortfield = GETPOST("sortfield",'alpha');
48 $sortorder = GETPOST("sortorder",'alpha');
49 $page = GETPOST("page",'int');
50 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
51 $offset = $conf->liste_limit * $page ;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 if (! $sortorder) $sortorder="DESC";
55 if (! $sortfield) $sortfield="dateevent";
56 
57 
58 /*
59  * Actions
60  */
61 
62 // Purge sessions
63 if ($action == 'confirm_purge' && $confirm == 'yes' && $user->admin)
64 {
65  $res=purgeSessions(session_id());
66 }
67 
68 // Lock new sessions
69 if ($action == 'confirm_lock' && $confirm == 'yes' && $user->admin)
70 {
71  if (dolibarr_set_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', $user->login, 'text',1,'Logon is restricted to a particular user', 0) < 0)
72  {
73  dol_print_error($db);
74  }
75 }
76 
77 // Unlock new sessions
78 if ($action == 'confirm_unlock' && $user->admin)
79 {
80  if (dolibarr_del_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', -1) < 0)
81  {
82  dol_print_error($db);
83  }
84 }
85 
86 
87 
88 /*
89 * View
90 */
91 
92 llxHeader();
93 
94 $form=new Form($db);
95 
96 $userstatic=new User($db);
97 $usefilter=0;
98 
99 $listofsessions=listOfSessions();
100 $num=count($listofsessions);
101 
102 print_barre_liste($langs->trans("Sessions"), $page, $_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',$num,0,'setup');
103 
104 $savehandler=ini_get("session.save_handler");
105 $savepath=ini_get("session.save_path");
106 $openbasedir=ini_get("open_basedir");
107 $phparray=phpinfo_array();
108 $suhosin=empty($phparray['suhosin']["suhosin.session.encrypt"]["local"])?'':$phparray['suhosin']["suhosin.session.encrypt"]["local"];
109 
110 print '<b>'.$langs->trans("SessionSaveHandler").'</b>: '.$savehandler.'<br>';
111 print '<b>'.$langs->trans("SessionSavePath").'</b>: '.$savepath.'<br>';
112 if ($openbasedir) print '<b>'.$langs->trans("OpenBaseDir").'</b>: '.$openbasedir.'<br>';
113 if ($suhosin) print '<b>'.$langs->trans("SuhosinSessionEncrypt").'</b>: '.$suhosin.'<br>';
114 print '<br>';
115 
116 if ($action == 'purge')
117 {
118  $formquestion=array();
119  print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('PurgeSessions'), $langs->trans('ConfirmPurgeSessions'),'confirm_purge',$formquestion,'no',2);
120 }
121 else if ($action == 'lock')
122 {
123  $formquestion=array();
124  print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('LockNewSessions'), $langs->trans('ConfirmLockNewSessions',$user->login),'confirm_lock',$formquestion,'no',1);
125 }
126 
127 if ($savehandler == 'files')
128 {
129  print '<table class="liste" width="100%">';
130  print '<tr class="liste_titre">';
131  print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"login","","",'align="left"',$sortfield,$sortorder);
132  print_liste_field_titre("SessionId",$_SERVER["PHP_SELF"],"id","","",'align="left"',$sortfield,$sortorder);
133  print_liste_field_titre("DateCreation",$_SERVER["PHP_SELF"],"datec","","",'align="left"',$sortfield,$sortorder);
134  print_liste_field_titre("DateModification",$_SERVER["PHP_SELF"],"datem","","",'align="left"',$sortfield,$sortorder);
135  print_liste_field_titre("Age",$_SERVER["PHP_SELF"],"age","","",'align="left"',$sortfield,$sortorder);
136  print_liste_field_titre("Raw",$_SERVER["PHP_SELF"],"raw","","",'align="left"',$sortfield,$sortorder);
138  print "</tr>\n";
139 
140  $var=True;
141 
142  foreach ($listofsessions as $key => $sessionentry)
143  {
144 
145 
146  print '<tr class="oddeven">';
147 
148  // Login
149  print '<td>'.$sessionentry['login'].'</td>';
150 
151  // ID
152  print '<td align="left" class="nowrap">';
153  if ("$key" == session_id()) print $form->textwithpicto($key,$langs->trans("YourSession"));
154  else print $key;
155  print '</td>';
156 
157  // Date creation
158  print '<td align="left" class="nowrap">'.dol_print_date($sessionentry['creation'],'%Y-%m-%d %H:%M:%S').'</td>';
159 
160  // Date modification
161  print '<td align="left" class="nowrap">'.dol_print_date($sessionentry['modification'],'%Y-%m-%d %H:%M:%S').'</td>';
162 
163  // Age
164  print '<td>'.$sessionentry['age'].'</td>';
165 
166  // Raw
167  print '<td>'.dol_trunc($sessionentry['raw'],40,'middle').'</td>';
168 
169  print '<td>&nbsp;</td>';
170 
171  print "</tr>\n";
172  $i++;
173  }
174 
175  if (count($listofsessions) == 0)
176  {
177  print '<tr '.$bc[false].'><td colspan="6">'.$langs->trans("NoSessionFound",$savepath,$openbasedir).'</td></tr>';
178  }
179  print "</table>";
180 
181 }
182 else
183 {
184  print $langs->trans("NoSessionListWithThisHandler");
185 }
186 
187 /*
188  * Buttons
189  */
190 
191 print '<div class="tabsAction">';
192 
193 
194 if (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
195 {
196  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=lock">'.$langs->trans("LockNewSessions").'</a>';
197 }
198 else
199 {
200  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=confirm_unlock">'.$langs->trans("UnlockNewSessions").'</a>';
201 }
202 
203 if ($savehandler == 'files')
204 {
205  if (count($listofsessions))
206  {
207  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=purge">'.$langs->trans("PurgeSessions").'</a>';
208  }
209 }
210 
211 print '</div>';
212 
213 print '<br>';
214 
215 llxFooter();
216 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
listOfSessions()
Return list of session.
Definition: admin.lib.php:708
purgeSessions($mysessionid)
Purge existing sessions.
Definition: admin.lib.php:764
Class to manage Dolibarr users.
Definition: user.class.php:39
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:485
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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'une constante dans la base de donnees.
Definition: admin.lib.php:410
llxHeader()
Empty header.
Definition: wrapper.php:46
phpinfo_array()
Return the php_info into an array.
Definition: admin.lib.php:1572
print
Draft customers invoices.
Definition: index.php:91
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.