Skip to content

Commit

Permalink
Generate module status after start/stop
Browse files Browse the repository at this point in the history
Otherwise, the Info pages cannot show if the module has successfully
started or stooped.
Snort and snort inline now write to separate cache files, otherwise they
could write and/or report the other's status.
Stopping snort instances should not stop snort inline.
Also, refactor module status functions.
  • Loading branch information
sonertari committed Aug 12, 2021
1 parent 9ffa414 commit 04ef834
Show file tree
Hide file tree
Showing 27 changed files with 90 additions and 60 deletions.
15 changes: 8 additions & 7 deletions src/Model/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ function __construct()
),

'GetModuleStatus' => array(
'argv' => array(),
// Trailing comma to avoid syntax error
'argv' => array(BOOL,),
'desc' => _('Get module status'),
),

Expand Down Expand Up @@ -2770,7 +2771,7 @@ function GetServiceStatus($get_info= 0, $start= '10min', $interval_changed= 0)
$model= new $Models[$name]();

// Do not cache module status individually here, we accumulate and cache them all in status.json below
$module_status= $model->_getModuleStatus($DashboardIntervals2Seconds[$start], FALSE);
$module_status= $model->_getModuleStatus($DashboardIntervals2Seconds[$start], 1, 0);
if ($module_status !== FALSE) {
$status[$name]= $module_status;
}
Expand Down Expand Up @@ -2814,19 +2815,19 @@ function getCachedContents($filename, &$contents)
return FALSE;
}

function GetModuleStatus()
function GetModuleStatus($generate_status)
{
global $StatusCheckInterval;

return Output(json_encode($this->_getModuleStatus($StatusCheckInterval)));
return Output(json_encode($this->_getModuleStatus($StatusCheckInterval, $generate_status)));
}

function _getModuleStatus($start, $do_cache= TRUE)
function _getModuleStatus($start, $generate_status, $do_cache= 1)
{
$status= array();
$cache= "{$this->UTMFWDIR}/cache/{$this->CollectdName}_status.json";
$cache= "{$this->UTMFWDIR}/cache/{$this->Name}_status.json";

if (!$this->getCachedContents($cache, $status)) {
if ($generate_status || !$this->getCachedContents($cache, $status)) {
$runStatus= $this->IsRunning() ? 'R' : 'S';

$status= array(
Expand Down
4 changes: 2 additions & 2 deletions src/Model/snortinline.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ function FindPid()
*/
function IsRunning($proc= '')
{
$re= "\/usr\/local\/bin\/snort\s+[^\n]*-Q\s+[^\n]*";
$re= "/usr/local/bin/snort\s+[^\n]*-Q\s+[^\n]*";

$output= $this->RunShellCommand('/bin/ps arwwx -U_snort');
if (preg_match("/$re/m", $output)) {
if (preg_match("|$re|m", $output)) {
return TRUE;
}
return FALSE;
Expand Down
8 changes: 4 additions & 4 deletions src/View/clamav/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@

require_once('clamd.php');
$Clamd= $View;
$Clamd->ProcessStartStopRequests();
$generate_clamd_status= $Clamd->ProcessStartStopRequests();

require_once('freshclam.php');
$Freshclam= $View;
$Freshclam->ProcessStartStopRequests();
$generate_freshclam_status= $Freshclam->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$Clamd->PrintStatusForm();
$Freshclam->PrintStatusForm();
$Clamd->PrintStatusForm($generate_clamd_status);
$Freshclam->PrintStatusForm($generate_freshclam_status);

PrintHelpWindow(_HELPWINDOW('UTMFW uses ClamAV for all virus scanning purposes. Freshclam checks and updates ClamAV virus database periodically. By default, the database is updated every hour. You may not be able to stop or restart freshclam instance once it starts the update process; wait for a minute and try again.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
4 changes: 2 additions & 2 deletions src/View/dante/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('include.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm(PRINT_COUNT);
$View->PrintStatusForm($generate_status, PRINT_COUNT);

PrintHelpWindow(_HELPWINDOW('SOCKS proxy is used by clients which support SOCKS protocol, such as file sharing applications. If you do not plan on providing support for SOCKS-enabled applications, you can stop this proxy. Some client applications fail to use the SOCKS proxy fully, even if they are configured correctly. Check the packet filter logs for blocked packets.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
4 changes: 2 additions & 2 deletions src/View/dhcpd/dhcpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
* Info, arp output, and list of leases.
*/

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm();
$View->PrintStatusForm($generate_status);
?>
<strong><?php echo _TITLE2('Leases').':' ?></strong>
<?php
Expand Down
4 changes: 2 additions & 2 deletions src/View/dnsmasq/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('include.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm();
$View->PrintStatusForm($generate_status, PRINT_COUNT);

PrintHelpWindow(_HELPWINDOW('The DNS forwarder sends all queries to the name servers in /etc/resolv.conf.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
4 changes: 2 additions & 2 deletions src/View/e2guardian/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('e2guardian.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm();
$View->PrintStatusForm($generate_status);

PrintHelpWindow(_HELPWINDOW('The web filter runs multithreaded. The maximum number of web filter threads can be adjusted on the configuration pages.
Expand Down
4 changes: 2 additions & 2 deletions src/View/ftp-proxy/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('include.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm();
$View->PrintStatusForm($generate_status);

PrintHelpWindow(_HELPWINDOW('Internal clients connect to FTP servers on the external network via this FTP proxy. Since FTP protocol makes use of ports other than the ftp ports, allowing requests to ftp ports only is not enough. You need to run an FTP proxy.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
4 changes: 2 additions & 2 deletions src/View/httpd/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('httpd.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm(PRINT_COUNT);
$View->PrintStatusForm($generate_status, PRINT_COUNT);
PrintHelpWindow(_HELPWINDOW('This web administration interface is served by OpenBSD/httpd. If you stop the web server, you will lose your connection to this web interface. You can restart it on the command line.'));
require_once($VIEW_PATH.'/footer.php');
?>
4 changes: 2 additions & 2 deletions src/View/imspector/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('imspector.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm();
$View->PrintStatusForm($generate_status);

PrintHelpWindow(_HELPWINDOW('IMSpector supports MSN, ICQ/AIM, Yahoo, and IRC protocols. IM Proxy can log all messages exchanged in text conversations.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
13 changes: 11 additions & 2 deletions src/View/lib/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,30 +271,39 @@ function Start()
*/
function ProcessStartStopRequests()
{
$generate_status= 0;

if (filter_has_var(INPUT_POST, 'Model')) {
if (filter_input(INPUT_POST, 'Model') == $this->Model) {
if (filter_has_var(INPUT_POST, 'Start')) {
$this->Restart();
$generate_status= 1;
}
else if (filter_has_var(INPUT_POST, 'Stop')) {
$this->Stop();
$generate_status= 1;
}
}
}
$this->Controller($Output, 'GetStatus');

return $generate_status;
}

/**
* Displays module status, software version, Restart/Stop buttons, and process table.
*
* @param boolean $generate_status Force generate module status, do not use cached status, necessary after process start/stop
* @param boolean $printcount Whether to print number of running processes too
* @param boolean $showbuttons Show Start/Stop buttons
* @param boolean $printprocs Whether to print the process table
* @param boolean $showrestartbutton Show Restart button, for System Info page
*/
function PrintStatusForm($printcount= FALSE, $showbuttons= TRUE, $printprocs= TRUE, $showrestartbutton= FALSE)
function PrintStatusForm($generate_status= 0, $printcount= FALSE, $showbuttons= TRUE, $printprocs= TRUE, $showrestartbutton= FALSE)
{
global $IMG_PATH, $ADMIN, $Status2Images, $StatusTitles;

$this->Controller($output, 'GetModuleStatus');
$this->Controller($output, 'GetModuleStatus', $generate_status);

$status= json_decode($output[0], TRUE);

Expand Down
3 changes: 3 additions & 0 deletions src/View/locale/en_EN/LC_MESSAGES/utmfw.po
Original file line number Diff line number Diff line change
Expand Up @@ -7228,6 +7228,9 @@ msgstr ""
msgid "You should select at least one interface to start IDS for"
msgstr ""

msgid "You should select at least one interface to stop IDS for"
msgstr ""

msgid ""
"You should take into account that there may be computers with static IP "
"addresses or using BOOTP protocol, and choose a range accordingly."
Expand Down
3 changes: 3 additions & 0 deletions src/View/locale/en_EN/LC_MESSAGES/utmfw_NOTICE.po
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ msgstr ""
msgid "You should select at least one interface to start IDS for"
msgstr ""

msgid "You should select at least one interface to stop IDS for"
msgstr ""

msgid "delete"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions src/View/locale/tr_TR/LC_MESSAGES/utmfw.po
Original file line number Diff line number Diff line change
Expand Up @@ -8524,6 +8524,9 @@ msgstr "Süreci başlatmak için en az bir conf dosyası seçmelisiniz"
msgid "You should select at least one interface to start IDS for"
msgstr "STS'yi başlatmak için en az bir ağ arayüzü seçmelisiniz"

msgid "You should select at least one interface to stop IDS for"
msgstr "STS'yi durdurmak için en az bir ağ arayüzü seçmelisiniz"

msgid ""
"You should take into account that there may be computers with static IP "
"addresses or using BOOTP protocol, and choose a range accordingly."
Expand Down
5 changes: 4 additions & 1 deletion src/View/locale/tr_TR/LC_MESSAGES/utmfw_NOTICE.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: UTMFW 6.9\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2009-11-11 16:21+0200\n"
"PO-Revision-Date: 2021-08-07 18:04+0300\n"
"PO-Revision-Date: 2021-08-12 17:05+0300\n"
"Last-Translator: Soner Tari <[email protected]>\n"
"Language: tr\n"
"Language-Team: Turkish <>\n"
Expand Down Expand Up @@ -231,6 +231,9 @@ msgstr "Süreci başlatmak için en az bir conf dosyası seçmelisiniz"
msgid "You should select at least one interface to start IDS for"
msgstr "STS'yi başlatmak için en az bir ağ arayüzü seçmelisiniz"

msgid "You should select at least one interface to stop IDS for"
msgstr "STS'yi durdurmak için en az bir ağ arayüzü seçmelisiniz"

msgid "delete"
msgstr "silmek"

Expand Down
16 changes: 8 additions & 8 deletions src/View/monitoring/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
require_once('include.php');

$View->Model= 'symon';
$View->ProcessStartStopRequests();
$generate_symon_status= $View->ProcessStartStopRequests();
$View->Model= 'symux';
$View->ProcessStartStopRequests();
$generate_symux_status= $View->ProcessStartStopRequests();
$View->Model= 'pmacct';
$View->ProcessStartStopRequests();
$generate_pmacct_status= $View->ProcessStartStopRequests();
$View->Model= 'collectd';
$View->ProcessStartStopRequests();
$generate_collectd_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->Model= 'symon';
$View->PrintStatusForm();
$View->PrintStatusForm($generate_symon_status);
$View->Model= 'symux';
$View->Caption= 'Symux';
$View->PrintStatusForm();
$View->PrintStatusForm($generate_symux_status);
$View->Model= 'pmacct';
$View->Caption= 'Pmacct';
$View->PrintStatusForm();
$View->PrintStatusForm($generate_pmacct_status);
$View->Model= 'collectd';
$View->Caption= 'Collectd';
$View->PrintStatusForm();
$View->PrintStatusForm($generate_collectd_status);

PrintHelpWindow(_HELPWINDOW('Graphs on this web user interface are generated by these monitoring processes. Settings of these software are handled by automatic configuration.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
4 changes: 2 additions & 2 deletions src/View/openssh/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('include.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm();
$View->PrintStatusForm($generate_status);

PrintHelpWindow(_HELPWINDOW('OpenSSH is the de-facto standard secure shell. If you stop OpenSSH, you cannot establish shell connections to the system remotely.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
6 changes: 5 additions & 1 deletion src/View/openvpn/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ function PrintConfStartStopForm()
}
}

$generate_status= 0;

if (filter_has_var(INPUT_POST, 'Start')) {
if (filter_has_var(INPUT_POST, 'ConfFiles')) {
foreach ($_POST['ConfFiles'] as $file) {
$View->Controller($Output, 'RestartInstance', $file);
}
$generate_status= 1;
}
else {
PrintHelpWindow(_NOTICE('FAILED').': '._NOTICE('You should select at least one conf file to start the process'), 'auto', 'ERROR');
Expand All @@ -69,14 +72,15 @@ function PrintConfStartStopForm()
// Snort inline IPS
$View->Stop();
}
$generate_status= 1;
}

$View->Controller($Output, 'GetStatus');

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm(FALSE, FALSE);
$View->PrintStatusForm($generate_status, FALSE, FALSE);
PrintConfStartStopForm();

PrintHelpWindow(_HELPWINDOW('OpenVPN is a virtual private networking solution based on OpenSSL. You should create different configuration for servers and clients, and start OpenVPN accordingly.'));
Expand Down
4 changes: 2 additions & 2 deletions src/View/p3scan/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_once('include.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$Reload= TRUE;
require_once($VIEW_PATH.'/header.php');

$View->PrintStatusForm();
$View->PrintStatusForm($generate_status);

PrintHelpWindow(_HELPWINDOW('POP3 proxy is used to scan incoming e-mails for viruses and spam. Make sure virus and spam scanners are running before starting this proxy.'));
require_once($VIEW_PATH.'/footer.php');
Expand Down
4 changes: 2 additions & 2 deletions src/View/pf/info.pf.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

require_once('pf.php');

$View->ProcessStartStopRequests();
$generate_status= $View->ProcessStartStopRequests();

$View->Controller($Output, 'GetPfInfo');
$PfInfo= implode("\n", $Output);
Expand All @@ -34,7 +34,7 @@
$Reload= TRUE;
require_once($VIEW_PATH . '/header.php');

$View->PrintStatusForm(FALSE, TRUE, FALSE);
$View->PrintStatusForm($generate_status, FALSE, TRUE, FALSE);
?>
<table class="shadowbox" style="padding-right: 12px;">
<tr>
Expand Down
Loading

0 comments on commit 04ef834

Please sign in to comment.