From 72d4db300724b56c2f2c0007955aa359e20494ed Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 27 Jun 2014 21:36:14 +0200 Subject: [PATCH] 2 Background worker issues fixed - Start-up script could only be started from the script's location - Division by zero in e-mail alerts when calculating the progress of the background job --- app/Console/worker/start.sh | 1 + app/Model/Event.php | 71 +++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/app/Console/worker/start.sh b/app/Console/worker/start.sh index c0a3eeb89..1d5c2ad68 100644 --- a/app/Console/worker/start.sh +++ b/app/Console/worker/start.sh @@ -1,4 +1,5 @@ #!/bin/bash +cd "${0%/*}" ../cake CakeResque.CakeResque stop --all ../cake CakeResque.CakeResque start --interval 5 --queue default ../cake CakeResque.CakeResque start --interval 5 --queue cache diff --git a/app/Model/Event.php b/app/Model/Event.php index 17ffd4c16..d88278ce9 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -1150,45 +1150,46 @@ class Event extends AppModel { // But only do this if it is allowed in the bootstrap.php file. // if ($eventIsPrivate) { - $conditions = array('User.autoalert' => 1, 'User.gpgkey =' => "", 'User.org =' => $event['Event']['org']); + $conditions = array('User.autoalert' => 1, 'User.gpgkey =' => "", 'User.org =' => $event['Event']['org']); } else { - $conditions = array('User.autoalert' => 1, 'User.gpgkey =' => ""); + $conditions = array('User.autoalert' => 1, 'User.gpgkey =' => ""); } - if ('false' == Configure::read('GnuPG.onlyencrypted')) { - $alertUsers = $this->User->find('all', array( - 'conditions' => $conditions, - 'recursive' => 0, - )); - $max = count($alertUsers); - foreach ($alertUsers as $k => &$user) { - // prepare the the unencrypted email - $Email = new CakeEmail(); - $Email->from(Configure::read('MISP.email')); - $Email->to($user['User']['email']); - $Email->subject("[" . Configure::read('MISP.org') . " " . Configure::read('MISP.name') . "] Event " . $id . " - " . $subject . $event['ThreatLevel']['name'] . " - TLP Amber"); - $Email->emailFormat('text'); // both text or html - // send it - $Email->send($bodySigned); - $Email->reset(); - if ($processId) { - $this->Job->id = $processId; - $this->Job->saveField('progress', $k / $max * 50); - } + if ('false' == Configure::read('GnuPG.onlyencrypted')) { + $alertUsers = $this->User->find('all', array( + 'conditions' => $conditions, + 'recursive' => 0, + )); + $max = count($alertUsers); + foreach ($alertUsers as $k => &$user) { + // prepare the the unencrypted email + $Email = new CakeEmail(); + $Email->from(Configure::read('MISP.email')); + $Email->to($user['User']['email']); + $Email->subject("[" . Configure::read('MISP.org') . " " . Configure::read('MISP.name') . "] Event " . $id . " - " . $subject . $event['ThreatLevel']['name'] . " - TLP Amber"); + $Email->emailFormat('text'); // both text or html + // send it + $Email->send($bodySigned); + $Email->reset(); + if ($processId) { + $this->Job->id = $processId; + $this->Job->saveField('progress', $k / $max * 50); } } - // - // Build a list of the recipients that wish to receive encrypted mails. - // - if ($eventIsPrivate) { - $conditions = array('User.autoalert' => 1, 'User.gpgkey !=' => "", 'User.org =' => $event['Event']['org']); - } else { - $conditions = array('User.autoalert' => 1, 'User.gpgkey !=' => ""); - } - $alertUsers = $this->User->find('all', array( - 'conditions' => $conditions, - 'recursive' => 0, - ) - ); + } + // + // Build a list of the recipients that wish to receive encrypted mails. + // + if ($eventIsPrivate) { + $conditions = array('User.autoalert' => 1, 'User.gpgkey !=' => "", 'User.org =' => $event['Event']['org']); + } else { + $conditions = array('User.autoalert' => 1, 'User.gpgkey !=' => ""); + } + $alertUsers = $this->User->find('all', array( + 'conditions' => $conditions, + 'recursive' => 0, + ) + ); + $max = count($alertUsers); // encrypt the mail for each user and send it separately foreach ($alertUsers as $k => &$user) { // send the email