mirror of https://github.com/MISP/MISP
Merge pull request #8393 from righel/test-if-file-session-conf
chg: show diagnostic issue if session is file basedpull/8435/head
commit
6c2a9ee11e
|
@ -996,7 +996,13 @@ class ServersController extends AppController
|
|||
$gpgErrors = array(0 => __('OK'), 1 => __('FAIL: settings not set'), 2 => __('FAIL: Failed to load GnuPG'), 3 => __('FAIL: Issues with the key/passphrase'), 4 => __('FAIL: sign failed'));
|
||||
$proxyErrors = array(0 => __('OK'), 1 => __('not configured (so not tested)'), 2 => __('Getting URL via proxy failed'));
|
||||
$zmqErrors = array(0 => __('OK'), 1 => __('not enabled (so not tested)'), 2 => __('Python ZeroMQ library not installed correctly.'), 3 => __('ZeroMQ script not running.'));
|
||||
$sessionErrors = array(0 => __('OK'), 1 => __('High'), 2 => __('Alternative setting used'), 3 => __('Test failed'));
|
||||
$sessionErrors = array(
|
||||
0 => __('OK'),
|
||||
1 => __('Too many expired sessions in the database, please clear the expired sessions'),
|
||||
2 => __('PHP session handler is using the default file storage. This is not recommended, please use the redis or database storage'),
|
||||
8 => __('Alternative setting used'),
|
||||
9 => __('Test failed')
|
||||
);
|
||||
$moduleErrors = array(0 => __('OK'), 1 => __('System not enabled'), 2 => __('No modules found'));
|
||||
$backgroundJobsErrors = array(
|
||||
0 => __('OK'),
|
||||
|
@ -1148,10 +1154,8 @@ class ServersController extends AppController
|
|||
$moduleStatus[$type] = $this->Server->moduleDiagnostics($diagnostic_errors, $type);
|
||||
}
|
||||
|
||||
// check the size of the session table
|
||||
$sessionCount = 0;
|
||||
$sessionStatus = $this->Server->sessionDiagnostics($diagnostic_errors, $sessionCount);
|
||||
$this->set('sessionCount', $sessionCount);
|
||||
// get php session diagnostics
|
||||
$sessionStatus = $this->Server->sessionDiagnostics($diagnostic_errors);
|
||||
|
||||
$this->loadModel('AttachmentScan');
|
||||
try {
|
||||
|
|
|
@ -3362,25 +3362,54 @@ class Server extends AppModel
|
|||
return $proxyStatus;
|
||||
}
|
||||
|
||||
public function sessionDiagnostics(&$diagnostic_errors = 0, &$sessionCount = '')
|
||||
public function sessionDiagnostics(&$diagnostic_errors = 0)
|
||||
{
|
||||
if (Configure::read('Session.defaults') !== 'database') {
|
||||
$sessionCount = 'N/A';
|
||||
return 2;
|
||||
$sessionCount = null;
|
||||
$sessionHandler = null;
|
||||
$errorCode = 9;
|
||||
|
||||
switch (Configure::read('Session.defaults')) {
|
||||
case 'php':
|
||||
$sessionHandler = 'php_' . ini_get('session.save_handler');
|
||||
switch ($sessionHandler) {
|
||||
case 'php_files':
|
||||
$diagnostic_errors++;
|
||||
$errorCode = 2;
|
||||
break;
|
||||
case 'php_redis':
|
||||
$errorCode = 0;
|
||||
break;
|
||||
default:
|
||||
$diagnostic_errors++;
|
||||
$errorCode = 8;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'database':
|
||||
$sessionHandler = 'database';
|
||||
$sql = 'SELECT COUNT(id) AS session_count FROM cake_sessions WHERE expires < ' . time() . ';';
|
||||
$sqlResult = $this->query($sql);
|
||||
if (isset($sqlResult[0][0])) {
|
||||
$sessionCount = $sqlResult[0][0]['session_count'];
|
||||
} else {
|
||||
$errorCode = 9;
|
||||
}
|
||||
if ($sessionCount > 1000) {
|
||||
$diagnostic_errors++;
|
||||
$errorCode = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$diagnostic_errors++;
|
||||
$errorCode = 8;
|
||||
break;
|
||||
}
|
||||
$sql = 'SELECT COUNT(id) AS session_count FROM cake_sessions WHERE expires < ' . time() . ';';
|
||||
$sqlResult = $this->query($sql);
|
||||
if (isset($sqlResult[0][0])) {
|
||||
$sessionCount = $sqlResult[0][0]['session_count'];
|
||||
} else {
|
||||
$sessionCount = 'Error';
|
||||
return 3;
|
||||
}
|
||||
if ($sessionCount > 1000) {
|
||||
$diagnostic_errors++;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
return [
|
||||
'handler' => $sessionHandler,
|
||||
'expired_count' => $sessionCount,
|
||||
'error_code' => $errorCode
|
||||
];
|
||||
}
|
||||
|
||||
public function workerDiagnostics(&$workerIssueCount)
|
||||
|
|
|
@ -445,24 +445,21 @@
|
|||
?>
|
||||
</div>
|
||||
|
||||
<h3><?php echo __('Session table');?></h3>
|
||||
<p><?php echo __('This tool checks how large your database\'s session table is. <br />Sessions in CakePHP rely on PHP\'s garbage collection for clean-up and in certain distributions this can be disabled by default resulting in an ever growing cake session table. <br />If you are affected by this, just click the clean session table button below.');?></p>
|
||||
<h3><?php echo __('PHP Sessions');?></h3>
|
||||
<div class="diagnostics-box">
|
||||
<?php
|
||||
$colour = 'green';
|
||||
$message = $sessionErrors[$sessionStatus];
|
||||
$sessionColours = array(0 => 'green', 1 => 'red', 2 => 'orange', 3 => 'red');
|
||||
$colour = $sessionColours[$sessionStatus];
|
||||
echo __('Expired sessions') . '…<span style="color:' . $colour . ';">' . $sessionCount . ' (' . $message . ')' . '</span>';
|
||||
?>
|
||||
<?php
|
||||
$sessionColours = array(0 => 'green', 1 => 'red', 2 => 'orange', 3 => 'red', 9 => 'red');
|
||||
$colour = $sessionColours[$sessionStatus['error_code']];
|
||||
echo sprintf('<p><b>%s:</b> %s</p>', __('Session handler'), $sessionStatus['handler']);
|
||||
echo sprintf('<span style="color:%s;">%s</span>', $colour, __($sessionErrors[$sessionStatus['error_code']]));
|
||||
if($sessionStatus['handler'] === 'database'){
|
||||
echo sprintf('<br><span style="color:%s;">%s: %s</span>',$colour, __('Expired sessions'), $sessionStatus['expired_count']);
|
||||
if ($sessionStatus['error_code'] === 1){
|
||||
echo sprintf('<br><a href="<?php echo $baseurl;?>/servers/purgeSessions"><span class="btn btn-inverse" style="padding-top:1px;padding-bottom:1px;">%s</span></a>', __('Purge sessions'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if ($sessionStatus < 2):
|
||||
?>
|
||||
<a href="<?php echo $baseurl;?>/servers/purgeSessions"><span class="btn btn-inverse" style="padding-top:1px;padding-bottom:1px;"><?php echo __('Purge sessions');?></span></a>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<h3><?php echo __('Upgrade authkeys keys to the advanced keys format'); ?><a id="advanced_authkey_update"> </a></h3>
|
||||
<p>
|
||||
<?php
|
||||
|
|
Loading…
Reference in New Issue