This commit is contained in:
Ad Schellevis 2018-12-16 20:13:19 +01:00
parent 1e3fc6dcc7
commit 8aa6da2fb0
4 changed files with 60 additions and 167 deletions

View File

@ -458,12 +458,12 @@ function filter_configure_sync($verbose = false, $flush_states = false, $load_al
/* Brutal ugly hack but required -- PF is stuck, unwedge */
if (strstr("$rules_error[0]", "busy")) {
exec('/sbin/pfctl -d; /sbin/pfctl -e; /sbin/pfctl -f /tmp/rules.debug');
file_notice('pf_busy', gettext('PF was wedged/busy and has been reset.'), 'pf_busy', '');
file_notice(gettext('PF was wedged/busy and has been reset.'));
} else {
exec('/sbin/pfctl -o basic -f /tmp/rules.debug.old 2>&1');
}
file_notice('filter_load', sprintf(gettext('There were error(s) loading the rules: %s%s'), $rules_error[0], $config_line), 'Filter Reload', '');
file_notice(sprintf(gettext('There were error(s) loading the rules: %s%s'), $rules_error[0], $config_line));
unlock($filterlck);
if ($verbose) {
@ -622,7 +622,7 @@ function filter_generate_aliases()
# a bit of a hack, but prevents the ruleset from not being able to load if these types are in
# the configuration.
$aliases .= "{$aliased['name']} = \"{ 0 <> 65535 }\"\n";
file_notice('filter_load', sprintf(gettext('URL port aliases types not supported [%s]'), $aliased['name']), 'Filter Reload', '');
file_notice(sprintf(gettext('URL port aliases types not supported [%s]'), $aliased['name']));
break;
case "port":
$tmp_ports = implode(" ", filter_core_get_port_alias($aliased['name']));

View File

@ -1670,7 +1670,7 @@ function interface_carp_configure(&$vip)
/* NOTE: Maybe its useless nowdays */
$realif = get_real_interface($vip['interface']);
if (!does_interface_exist($realif)) {
file_notice("CARP", sprintf(gettext("Interface specified for the virtual IP address %s does not exist. Skipping this VIP."), $vip['subnet']), "Firewall: Virtual IP", "");
file_notice(sprintf(gettext("Interface specified for the virtual IP address %s does not exist. Skipping this VIP."), $vip['subnet']));
return;
}

View File

@ -1,6 +1,7 @@
<?php
/*
* Copyright (C) 2018 Deciso B.V.
* Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
* Copyright (C) 2005 Colin Smith <ethethlay@gmail.com>
* All rights reserved.
@ -29,172 +30,64 @@
*/
/****f* notices/file_notice
* NAME
* file_notice
* INPUTS
* $id, $notice, $category, $url, $priority
* RESULT
* Files a notice and kicks off the various alerts, smtp, system log, etc.
******/
function file_notice($id, $notice, $category = 'General', $url = '', $priority = 1) {
/*
* $category - Category that this notice should be displayed under. This can be arbitrary,
* but a page must be set to receive this messages for it to be displayed.
*
* $priority - A notice's priority. Higher numbers indicate greater severity.
* 0 = informational, 1 = warning, 2 = error, etc. This may also be arbitrary,
*/
if(!$queue = get_notices()) $queue = array();
$queuekey = time();
$toqueue = array(
'id' => $id,
'notice' => $notice,
'url' => $url,
'category' => $category,
'priority' => $priority,
);
$queue[$queuekey] = $toqueue;
$queueout = fopen('/tmp/notices', 'w');
if(!$queueout) {
log_error(sprintf('Could not open %s for writing', '/tmp/notices'));
return;
}
fwrite($queueout, serialize($queue));
fclose($queueout);
log_error("New alert found: $notice");
return $queuekey;
}
/****f* notices/get_notices
* NAME
* get_notices
* INPUTS
* $category
* RESULT
* Returns a specific notices text
******/
function get_notices($category = 'all')
function file_notice($notice)
{
if (file_exists('/tmp/notices')) {
$queue = unserialize(file_get_contents('/tmp/notices'));
if (!$queue) {
return false;
}
if ($category != 'all') {
foreach($queue as $time => $notice) {
if (strtolower($notice['category']) == strtolower($category)) {
$toreturn[$time] = $notice;
}
}
return $toreturn;
}
return $queue;
}
return false;
$queue = get_notices();
$queue[time()] = array('notice' => $notice);
file_put_contents('/tmp/notices', serialize($queue));
}
function get_notices()
{
$toreturn = array();
if (file_exists('/tmp/notices')) {
$queue = unserialize(file_get_contents('/tmp/notices'));
if ($queue) {
foreach($queue as $time => $notice) {
if (strtolower($notice['category']) == strtolower($category)) {
$toreturn[$time] = $notice;
}
}
}
}
return $toreturn;
}
/****f* notices/close_notice
* NAME
* close_notice
* INPUTS
* $id
* RESULT
* Removes a notice from the list
******/
function close_notice($id)
{
$ids = array();
if(!$notices = get_notices()) return;
if($id == "all") {
@unlink('/tmp/notices');
return;
}
foreach(array_keys($notices) as $time) {
if($id == $time) {
unset($notices[$id]);
break;
}
}
foreach($notices as $key => $notice) {
$ids[$key] = $notice['id'];
}
foreach($ids as $time => $tocheck) {
if($id == $tocheck) {
unset($notices[$time]);
break;
}
}
if(count($notices) != 0) {
$queueout = fopen('/tmp/notices', 'w');
fwrite($queueout, serialize($notices));
fclose($queueout);
} else {
@unlink('/tmp/notices');
}
$ids = array();
if (file_exists('/tmp/notices')) {
if ($id == "all") {
@unlink('/tmp/notices');
} else {
$notices = get_notices();
foreach (array_keys($notices) as $time) {
if ($id == $time) {
unset($notices[$id]);
break;
}
}
if (count($notices) > 0) {
file_put_contents('/tmp/notices', serialize($notices));
} else {
@unlink('/tmp/notices');
}
}
}
}
/****f* notices/print_notices
* NAME
* print_notices
* INPUTS
* $notices, $category
* RESULT
* prints notices to the GUI
******/
function print_notices($notices, $category = "all")
function print_notices($notices)
{
if (!is_array($notices) || count($notices) == 0) {
/* nothing to do */
return;
}
foreach ($notices as $notice) {
if($category != "all") {
if(in_array($notice['category'], $category)) $categories[] = $notice['category'];
} else {
$categories[] = $notice['category'];
}
}
$categories = array_unique($categories);
sort($categories);
$toreturn = '';
foreach($categories as $category) {
$toreturn .= "<ul><li>{$category}<ul>";
foreach($notices as $notice) {
if(strtolower($notice['category']) == strtolower($category)) {
if($notice['id'] != '') {
if($notice['url'] != '') {
$toreturn .= "<li><a href={$notice['url']}>{$notice['id']}</a> - {$notice['notice']}</li>";
} else {
$toreturn .= "<li>{$notice['id']} - {$notice['notice']}</li>";
}
}
}
}
$toreturn .= "</ul></li></ul>";
}
return $toreturn;
$toreturn = '';
if (is_array($notices) && count($notices) > 0) {
foreach ($notices as $notice) {
$toreturn .= "<li>{$notice['id']} - {$notice['notice']}</li>";
}
}
return $toreturn;
}
/****f* notices/are_notices_pending
* NAME
* are_notices_pending
* INPUTS
* $category to check
* RESULT
* returns true if notices are pending, false if they are not
******/
function are_notices_pending($category = 'all')
function are_notices_pending()
{
if (file_exists('/tmp/notices')) {
return true;
}
return false;
return file_exists('/tmp/notices');
}

View File

@ -85,7 +85,7 @@ function carp_check_version($url, $username, $password, $method = 'opnsense.firm
// propagate error to log
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ;
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
file_notice($error);
// print communication details on failure
echo $client->getDetails();
return false ;
@ -94,7 +94,7 @@ function carp_check_version($url, $username, $password, $method = 'opnsense.firm
if (!is_array($remote_version) && trim($remote_version) == "Authentication failed") {
$error = "An authentication failure occurred while trying to access {$url} ({$method}).";
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
file_notice($error);
return false;
}
@ -214,7 +214,7 @@ function carp_sync_xml($url, $username, $password, $sections, $method = 'opnsens
// propagate error to log
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ;
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
file_notice($error);
// print communication details on failure
echo $client->getDetails();
return false ;
@ -223,7 +223,7 @@ function carp_sync_xml($url, $username, $password, $sections, $method = 'opnsens
if (!is_array($response) && trim($response) == "Authentication failed") {
$error = "An authentication failure occurred while trying to access {$url} ({$method}).";
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
file_notice($error);
exit;
}
@ -315,7 +315,7 @@ if (isset($config['hasync']) && is_array($config['hasync'])) {
// propagate error to log
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ;
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
file_notice($error);
// print communication details on failure
echo $client->getDetails();
return false ;
@ -324,7 +324,7 @@ if (isset($config['hasync']) && is_array($config['hasync'])) {
if (!is_array($response) && trim($response) == "Authentication failed") {
$error = "An authentication failure occurred while trying to access {$url} ({$method}).";
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
file_notice($error);
exit;
}