2009-09-02 00:20:55 +02:00
< ? 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 >
2009-09-02 00:20:55 +02:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2009-09-02 00:20:55 +02:00
* ( 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 />.
2009-09-02 00:20:55 +02:00
*/
/**
2010-07-21 14:35:56 +02:00
* \file htdocs / admin / tools / listsessions . php
2009-09-02 00:20:55 +02:00
* \ingroup core
* \brief List of PHP sessions
*/
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
2009-09-02 00:20:55 +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
2012-08-02 10:07:55 +02:00
if ( ! $user -> admin )
accessforbidden ();
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2009-09-02 00:20:55 +02:00
// Security check
2019-10-31 20:46:31 +01:00
if ( $user -> socid > 0 )
2009-09-02 00:20:55 +02:00
{
2019-10-20 01:09:11 +02:00
$action = '' ;
2019-10-31 20:46:31 +01:00
$socid = $user -> socid ;
2009-09-02 00:20:55 +02:00
}
2019-01-27 11:55:16 +01:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
2017-11-03 19:52:02 +01:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2009-09-02 00:20:55 +02:00
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2010-11-20 14:08:44 +01:00
if ( ! $sortorder ) $sortorder = " DESC " ;
if ( ! $sortfield ) $sortfield = " dateevent " ;
2009-09-02 00:20:55 +02:00
/*
* Actions
*/
// Purge sessions
2012-08-02 10:07:55 +02:00
if ( $action == 'confirm_purge' && $confirm == 'yes' && $user -> admin )
2009-09-02 00:20:55 +02:00
{
$res = purgeSessions ( session_id ());
}
// Lock new sessions
2012-08-02 10:07:55 +02:00
if ( $action == 'confirm_lock' && $confirm == 'yes' && $user -> admin )
2009-09-02 00:20:55 +02:00
{
2019-01-27 11:55:16 +01:00
if ( dolibarr_set_const ( $db , 'MAIN_ONLY_LOGIN_ALLOWED' , $user -> login , 'text' , 1 , 'Logon is restricted to a particular user' , 0 ) < 0 )
2009-09-02 00:20:55 +02:00
{
dol_print_error ( $db );
}
}
// Unlock new sessions
2012-08-02 10:07:55 +02:00
if ( $action == 'confirm_unlock' && $user -> admin )
2009-09-02 00:20:55 +02:00
{
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 ();
2012-08-02 10:07:55 +02:00
$num = count ( $listofsessions );
2009-09-02 00:20:55 +02:00
2019-01-27 11:55:16 +01:00
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)
2009-09-02 00:20:55 +02:00
2009-09-02 16:18:30 +02:00
$savehandler = ini_get ( " session.save_handler " );
$savepath = ini_get ( " session.save_path " );
$openbasedir = ini_get ( " open_basedir " );
2013-01-19 17:56:26 +01:00
$phparray = phpinfo_array ();
$suhosin = empty ( $phparray [ 'suhosin' ][ " suhosin.session.encrypt " ][ " local " ]) ? '' : $phparray [ 'suhosin' ][ " suhosin.session.encrypt " ][ " local " ];
2009-09-02 00:20:55 +02:00
print '<b>' . $langs -> trans ( " SessionSaveHandler " ) . '</b>: ' . $savehandler . '<br>' ;
print '<b>' . $langs -> trans ( " SessionSavePath " ) . '</b>: ' . $savepath . '<br>' ;
2009-09-02 16:18:30 +02:00
if ( $openbasedir ) print '<b>' . $langs -> trans ( " OpenBaseDir " ) . '</b>: ' . $openbasedir . '<br>' ;
2013-01-19 17:56:26 +01:00
if ( $suhosin ) print '<b>' . $langs -> trans ( " SuhosinSessionEncrypt " ) . '</b>: ' . $suhosin . '<br>' ;
2009-09-02 00:20:55 +02:00
print '<br>' ;
2012-08-02 10:07:55 +02:00
if ( $action == 'purge' )
2009-09-02 00:20:55 +02:00
{
$formquestion = array ();
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?noparam=noparam' , $langs -> trans ( 'PurgeSessions' ), $langs -> trans ( 'ConfirmPurgeSessions' ), 'confirm_purge' , $formquestion , 'no' , 2 );
2009-09-02 00:20:55 +02:00
}
2019-01-27 10:49:34 +01:00
elseif ( $action == 'lock' )
2009-09-02 00:20:55 +02:00
{
$formquestion = array ();
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?noparam=noparam' , $langs -> trans ( 'LockNewSessions' ), $langs -> trans ( 'ConfirmLockNewSessions' , $user -> login ), 'confirm_lock' , $formquestion , 'no' , 1 );
2009-09-02 00:20:55 +02:00
}
if ( $savehandler == 'files' )
{
2019-11-05 21:24:41 +01:00
print '<table class="liste centpercent">' ;
2009-09-02 00:20:55 +02:00
print '<tr class="liste_titre">' ;
2019-01-27 11:55:16 +01:00
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 ( '' );
2009-09-02 00:20:55 +02:00
print " </tr> \n " ;
foreach ( $listofsessions as $key => $sessionentry )
{
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-09-02 00:20:55 +02:00
2009-09-15 18:51:15 +02:00
// Login
2009-09-15 18:38:05 +02:00
print '<td>' . $sessionentry [ 'login' ] . '</td>' ;
2010-05-12 01:56:12 +02:00
2009-09-02 00:20:55 +02:00
// ID
2019-03-20 09:35:16 +01:00
print '<td class="nowrap left">' ;
2019-01-27 11:55:16 +01:00
if ( " $key " == session_id ()) print $form -> textwithpicto ( $key , $langs -> trans ( " YourSession " ));
2009-09-02 00:20:55 +02:00
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>' ;
2009-09-02 00:20:55 +02:00
// 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>' ;
2009-09-02 00:20:55 +02:00
// Age
print '<td>' . $sessionentry [ 'age' ] . '</td>' ;
// Raw
2019-01-27 11:55:16 +01:00
print '<td>' . dol_trunc ( $sessionentry [ 'raw' ], 40 , 'middle' ) . '</td>' ;
2009-09-02 00:20:55 +02:00
print '<td> </td>' ;
print " </tr> \n " ;
$i ++ ;
}
2011-09-14 23:50:18 +02:00
if ( count ( $listofsessions ) == 0 )
2009-09-02 00:20:55 +02:00
{
2019-01-27 11:55:16 +01:00
print '<tr ' . $bc [ false ] . '><td colspan="6">' . $langs -> trans ( " NoSessionFound " , $savepath , $openbasedir ) . '</td></tr>' ;
2009-09-02 00:20:55 +02:00
}
print " </table> " ;
}
else
{
print $langs -> trans ( " NoSessionListWithThisHandler " );
}
/*
* Buttons
*/
print '<div class="tabsAction">' ;
if ( empty ( $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ))
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=lock">' . $langs -> trans ( " LockNewSessions " ) . '</a>' ;
}
else
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=confirm_unlock">' . $langs -> trans ( " UnlockNewSessions " ) . '</a>' ;
}
if ( $savehandler == 'files' )
{
2011-09-14 23:50:18 +02:00
if ( count ( $listofsessions ))
2009-09-02 00:20:55 +02:00
{
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?action=purge">' . $langs -> trans ( " PurgeSessions " ) . '</a>' ;
}
}
print '</div>' ;
2009-09-02 16:34:11 +02:00
print '<br>' ;
2009-09-02 00:20:55 +02:00
2018-07-28 14:29:28 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-08-02 10:07:55 +02:00
$db -> close ();