listsessions.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. /**
  19. * \file htdocs/admin/tools/listsessions.php
  20. * \ingroup core
  21. * \brief List of PHP sessions
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. $langs->load("install");
  26. if (! $user->admin)
  27. accessforbidden();
  28. $action=GETPOST('action', 'alpha');
  29. $confirm=GETPOST('confirm', 'alpha');
  30. // Security check
  31. if ($user->societe_id > 0)
  32. {
  33. $action = '';
  34. $socid = $user->societe_id;
  35. }
  36. $langs->load("companies");
  37. $langs->load("users");
  38. $langs->load("other");
  39. $sortfield = GETPOST("sortfield",'alpha');
  40. $sortorder = GETPOST("sortorder",'alpha');
  41. $page = GETPOST("page",'int');
  42. if ($page == -1) { $page = 0 ; }
  43. $offset = $conf->liste_limit * $page ;
  44. $pageprev = $page - 1;
  45. $pagenext = $page + 1;
  46. if (! $sortorder) $sortorder="DESC";
  47. if (! $sortfield) $sortfield="dateevent";
  48. /*
  49. * Actions
  50. */
  51. // Purge sessions
  52. if ($action == 'confirm_purge' && $confirm == 'yes' && $user->admin)
  53. {
  54. $res=purgeSessions(session_id());
  55. }
  56. // Lock new sessions
  57. if ($action == 'confirm_lock' && $confirm == 'yes' && $user->admin)
  58. {
  59. if (dolibarr_set_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', $user->login, 'text',1,'Logon is restricted to a particular user', 0) < 0)
  60. {
  61. dol_print_error($db);
  62. }
  63. }
  64. // Unlock new sessions
  65. if ($action == 'confirm_unlock' && $user->admin)
  66. {
  67. if (dolibarr_del_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', -1) < 0)
  68. {
  69. dol_print_error($db);
  70. }
  71. }
  72. /*
  73. * View
  74. */
  75. llxHeader();
  76. $form=new Form($db);
  77. $userstatic=new User($db);
  78. $usefilter=0;
  79. $listofsessions=listOfSessions();
  80. $num=count($listofsessions);
  81. print_barre_liste($langs->trans("Sessions"), $page, $_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',$num,0,'setup');
  82. $savehandler=ini_get("session.save_handler");
  83. $savepath=ini_get("session.save_path");
  84. $openbasedir=ini_get("open_basedir");
  85. $phparray=phpinfo_array();
  86. $suhosin=empty($phparray['suhosin']["suhosin.session.encrypt"]["local"])?'':$phparray['suhosin']["suhosin.session.encrypt"]["local"];
  87. print '<b>'.$langs->trans("SessionSaveHandler").'</b>: '.$savehandler.'<br>';
  88. print '<b>'.$langs->trans("SessionSavePath").'</b>: '.$savepath.'<br>';
  89. if ($openbasedir) print '<b>'.$langs->trans("OpenBaseDir").'</b>: '.$openbasedir.'<br>';
  90. if ($suhosin) print '<b>'.$langs->trans("SuhosinSessionEncrypt").'</b>: '.$suhosin.'<br>';
  91. print '<br>';
  92. if ($action == 'purge')
  93. {
  94. $formquestion=array();
  95. print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('PurgeSessions'), $langs->trans('ConfirmPurgeSessions'),'confirm_purge',$formquestion,'no',2);
  96. }
  97. else if ($action == 'lock')
  98. {
  99. $formquestion=array();
  100. print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('LockNewSessions'), $langs->trans('ConfirmLockNewSessions',$user->login),'confirm_lock',$formquestion,'no',1);
  101. }
  102. if ($savehandler == 'files')
  103. {
  104. print '<table class="liste" width="100%">';
  105. print '<tr class="liste_titre">';
  106. print_liste_field_titre($langs->trans("Login"),$_SERVER["PHP_SELF"],"login","","",'align="left"',$sortfield,$sortorder);
  107. print_liste_field_titre($langs->trans("SessionId"),$_SERVER["PHP_SELF"],"id","","",'align="left"',$sortfield,$sortorder);
  108. print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"datec","","",'align="left"',$sortfield,$sortorder);
  109. print_liste_field_titre($langs->trans("DateModification"),$_SERVER["PHP_SELF"],"datem","","",'align="left"',$sortfield,$sortorder);
  110. print_liste_field_titre($langs->trans("Age"),$_SERVER["PHP_SELF"],"age","","",'align="left"',$sortfield,$sortorder);
  111. print_liste_field_titre($langs->trans("Raw"),$_SERVER["PHP_SELF"],"raw","","",'align="left"',$sortfield,$sortorder);
  112. print_liste_field_titre('','','');
  113. print "</tr>\n";
  114. $var=True;
  115. foreach ($listofsessions as $key => $sessionentry)
  116. {
  117. $var=!$var;
  118. print "<tr ".$bc[$var].">";
  119. // Login
  120. print '<td>'.$sessionentry['login'].'</td>';
  121. // ID
  122. print '<td align="left" class="nowrap">';
  123. if ("$key" == session_id()) print $form->textwithpicto($key,$langs->trans("YourSession"));
  124. else print $key;
  125. print '</td>';
  126. // Date creation
  127. print '<td align="left" class="nowrap">'.dol_print_date($sessionentry['creation'],'%Y-%m-%d %H:%M:%S').'</td>';
  128. // Date modification
  129. print '<td align="left" class="nowrap">'.dol_print_date($sessionentry['modification'],'%Y-%m-%d %H:%M:%S').'</td>';
  130. // Age
  131. print '<td>'.$sessionentry['age'].'</td>';
  132. // Raw
  133. print '<td>'.dol_trunc($sessionentry['raw'],40,'middle').'</td>';
  134. print '<td>&nbsp;</td>';
  135. print "</tr>\n";
  136. $i++;
  137. }
  138. if (count($listofsessions) == 0)
  139. {
  140. print '<tr><td colspan="6">'.$langs->trans("NoSessionFound",$savepath,$openbasedir).'</td></tr>';
  141. }
  142. print "</table>";
  143. }
  144. else
  145. {
  146. print $langs->trans("NoSessionListWithThisHandler");
  147. }
  148. /*
  149. * Buttons
  150. */
  151. print '<div class="tabsAction">';
  152. if (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
  153. {
  154. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=lock">'.$langs->trans("LockNewSessions").'</a>';
  155. }
  156. else
  157. {
  158. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=confirm_unlock">'.$langs->trans("UnlockNewSessions").'</a>';
  159. }
  160. if ($savehandler == 'files')
  161. {
  162. if (count($listofsessions))
  163. {
  164. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=purge">'.$langs->trans("PurgeSessions").'</a>';
  165. }
  166. }
  167. print '</div>';
  168. print '<br>';
  169. llxFooter();
  170. $db->close();