listsessions.php 6.6 KB

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