listsessions.php 6.5 KB

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