dolibarr/htdocs/admin/tools/listsessions.php

211 lines
6.5 KiB
PHP
Raw Normal View History

<?php
2012-08-02 10:07:55 +02:00
/* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
2010-07-21 14:35:56 +02:00
* \file htdocs/admin/tools/listsessions.php
* \ingroup core
* \brief List of PHP sessions
*/
2021-08-04 12:26:38 +02:00
if (! defined('CSRFCHECK_WITH_TOKEN')) {
define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
}
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
2021-08-04 12:26:38 +02:00
2018-09-08 10:30:10 +02:00
// Load translation files required by the page
$langs->loadLangs(array("companies", "install", "users", "other"));
2011-02-07 20:25:32 +01:00
2021-02-26 22:04:03 +01:00
if (!$user->admin) {
2012-08-02 10:07:55 +02:00
accessforbidden();
2021-02-26 22:04:03 +01:00
}
2012-08-02 10:07:55 +02:00
2020-09-16 19:39:50 +02:00
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
// Security check
2021-02-26 22:04:03 +01:00
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
2020-04-20 15:06:27 +02:00
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-02-26 22:04:03 +01:00
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
2020-04-20 15:06:27 +02:00
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
2021-02-26 22:04:03 +01:00
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "dateevent";
}
/*
* Actions
*/
// Purge sessions
2021-02-26 22:04:03 +01:00
if ($action == 'confirm_purge' && $confirm == 'yes' && $user->admin) {
$res = purgeSessions(session_id());
}
// Lock new sessions
2021-02-26 22:04:03 +01:00
if ($action == 'confirm_lock' && $confirm == 'yes' && $user->admin) {
if (dolibarr_set_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', $user->login, 'text', 1, 'Logon is restricted to a particular user', 0) < 0) {
dol_print_error($db);
}
}
// Unlock new sessions
2021-02-26 22:04:03 +01:00
if ($action == 'confirm_unlock' && $user->admin) {
if (dolibarr_del_const($db, 'MAIN_ONLY_LOGIN_ALLOWED', -1) < 0) {
dol_print_error($db);
}
}
/*
* View
*/
llxHeader();
$form = new Form($db);
$userstatic = new User($db);
$usefilter = 0;
$listofsessions = listOfSessions();
$num = count($listofsessions);
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)
$savehandler = ini_get("session.save_handler");
$savepath = ini_get("session.save_path");
$openbasedir = ini_get("open_basedir");
$phparray = phpinfo_array();
$suhosin = empty($phparray['suhosin']["suhosin.session.encrypt"]["local"]) ? '' : $phparray['suhosin']["suhosin.session.encrypt"]["local"];
print '<b>'.$langs->trans("SessionSaveHandler").'</b>: '.$savehandler.'<br>';
print '<b>'.$langs->trans("SessionSavePath").'</b>: '.$savepath.'<br>';
2021-02-26 22:04:03 +01:00
if ($openbasedir) {
print '<b>'.$langs->trans("OpenBaseDir").'</b>: '.$openbasedir.'<br>';
}
if ($suhosin) {
print '<b>'.$langs->trans("SuhosinSessionEncrypt").'</b>: '.$suhosin.'<br>';
}
print '<br>';
2021-02-26 22:04:03 +01:00
if ($action == 'purge') {
$formquestion = array();
print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('PurgeSessions'), $langs->trans('ConfirmPurgeSessions'), 'confirm_purge', $formquestion, 'no', 2);
2021-02-26 22:04:03 +01:00
} elseif ($action == 'lock') {
$formquestion = array();
print $form->formconfirm($_SERVER["PHP_SELF"].'?noparam=noparam', $langs->trans('LockNewSessions'), $langs->trans('ConfirmLockNewSessions', $user->login), 'confirm_lock', $formquestion, 'no', 1);
}
2021-02-26 22:04:03 +01:00
if ($savehandler == 'files') {
2019-11-05 21:24:41 +01:00
print '<table class="liste centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "login", "", "", 'align="left"', $sortfield, $sortorder);
print_liste_field_titre("SessionId", $_SERVER["PHP_SELF"], "id", "", "", 'align="left"', $sortfield, $sortorder);
print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", "", "", 'align="left"', $sortfield, $sortorder);
print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "datem", "", "", 'align="left"', $sortfield, $sortorder);
print_liste_field_titre("Age", $_SERVER["PHP_SELF"], "age", "", "", 'align="left"', $sortfield, $sortorder);
print_liste_field_titre("Raw", $_SERVER["PHP_SELF"], "raw", "", "", 'align="left"', $sortfield, $sortorder);
2015-06-26 06:23:29 +02:00
print_liste_field_titre('');
print "</tr>\n";
2021-02-26 22:04:03 +01:00
foreach ($listofsessions as $key => $sessionentry) {
print '<tr class="oddeven">';
2009-09-15 18:51:15 +02:00
// Login
2009-09-15 18:38:05 +02:00
print '<td>'.$sessionentry['login'].'</td>';
// ID
2019-03-20 09:35:16 +01:00
print '<td class="nowrap left">';
2021-02-26 22:04:03 +01:00
if ("$key" == session_id()) {
print $form->textwithpicto($key, $langs->trans("YourSession"));
} else {
print $key;
}
print '</td>';
// Date creation
2019-03-20 09:35:16 +01:00
print '<td class="nowrap left">'.dol_print_date($sessionentry['creation'], '%Y-%m-%d %H:%M:%S').'</td>';
// Date modification
2019-03-20 09:35:16 +01:00
print '<td class="nowrap left">'.dol_print_date($sessionentry['modification'], '%Y-%m-%d %H:%M:%S').'</td>';
// Age
print '<td>'.$sessionentry['age'].'</td>';
// Raw
print '<td>'.dol_trunc($sessionentry['raw'], 40, 'middle').'</td>';
print '<td>&nbsp;</td>';
print "</tr>\n";
$i++;
}
2021-02-26 22:04:03 +01:00
if (count($listofsessions) == 0) {
2020-03-25 18:24:39 +01:00
print '<tr class="oddeven"><td colspan="7">'.$langs->trans("NoSessionFound", $savepath, $openbasedir).'</td></tr>';
}
print "</table>";
2020-05-21 09:35:30 +02:00
} else {
print $langs->trans("NoSessionListWithThisHandler");
}
/*
* Buttons
*/
print '<div class="tabsAction">';
2021-02-26 22:04:03 +01:00
if (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
2021-08-04 12:26:38 +02:00
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=lock&token='.newToken().'">'.$langs->trans("LockNewSessions").'</a>';
2020-05-21 09:35:30 +02:00
} else {
2021-08-04 12:26:38 +02:00
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=confirm_unlock&token='.newToken().'">'.$langs->trans("UnlockNewSessions").'</a>';
}
2021-02-26 22:04:03 +01:00
if ($savehandler == 'files') {
if (count($listofsessions)) {
2021-08-04 12:26:38 +02:00
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=purge&token='.newToken().'">'.$langs->trans("PurgeSessions").'</a>';
}
}
print '</div>';
print '<br>';
2018-07-28 14:29:28 +02:00
// End of page
llxFooter();
2012-08-02 10:07:55 +02:00
$db->close();