Fix bug notifications not being sent.

The code to handle sending of notification was missing. This change
makes two different options available on how notifications will be
handled which will be controlled by CRON_SERVER_IP config option.

 - If CRON_SERVER_IP is set, the server with the given IP should
   call URL ../admin/?task=cron every x minutes. If the config
   is left empty, the notification will be called once the
   incident has  been saved. (The latter meothod might cause
   server timeout if there are large numbers of subscribers!)

Other minor changes:

 - Removed old commented code

 - Removed call to syslog used for debugging
This commit is contained in:
thnilsen
2020-08-15 21:09:57 +02:00
parent 8d31ec7f7c
commit ea582aeed6
6 changed files with 100 additions and 144 deletions
+28 -4
View File
@@ -7,10 +7,34 @@ if (!file_exists("../config.php"))
else{
require_once("../config.php");
require_once("../classes/constellation.php");
require_once("../classes/mailer.php");
require_once("../classes/mailer.php");
require_once("../classes/notification.php");
require_once("../template.php");
require_once("../libs/parsedown/Parsedown.php");
require_once("../classes/queue.php");
// Process the subscriber notification queue
// If CRON_SERVER_IP is not set, call notification once incident has been saved
if ( empty(CRON_SERVER_IP) )
{
if ( isset($_GET['sent']) && $_GET['sent'] == true )
{
Queue::process_queue();
}
}
else if ( isset($_GET['task']) && $_GET['task'] == 'cron' )
{
// Else, base it on call to /admin?task=cron being called from IP defined by CRON_SERVER_IP
if (! empty(CRON_SERVER_IP) && $_SERVER['REMOTE_ADDR'] == CRON_SERVER_IP )
{
Queue::process_queue();
syslog(1, "CRON server processed");
}
else {
syslog(1, "CRON called from unauthorised server");
}
}
if(isset($_COOKIE['user'])&&!isset($_SESSION['user']))
{
@@ -32,7 +56,7 @@ else{
require_once("login-form.php");
}
}
else
else
{
$user = new User($_SESSION['user']);
if (!$user->is_active())
@@ -53,7 +77,7 @@ else{
case 'user':
require_once("user.php");
break;
case 'settings':
require_once("settings.php");
break;
@@ -73,4 +97,4 @@ else{
Template::render_footer(true);
}
}
}