コード例 #1
0
ファイル: Job.php プロジェクト: humbertcostas/MISP
 public function cache($type, $isSiteAdmin, $org, $target, $jobOrg, $sid = null)
 {
     $extra = null;
     $extra2 = null;
     $shell = 'Event';
     $this->create();
     $data = array('worker' => 'cache', 'job_type' => 'cache_' . $type, 'job_input' => $target, 'status' => 0, 'retries' => 0, 'org' => $jobOrg, 'message' => 'Fetching events.');
     if ($type === 'md5' || $type === 'sha1') {
         $extra = $type;
         $type = 'hids';
     }
     if ($type === 'csv_all' || $type === 'csv_sig') {
         $extra = $type;
         $type = 'csv';
     }
     if ($type === 'suricata' || $type === 'snort') {
         $extra = $type;
         $type = 'nids';
         $extra2 = $sid;
     }
     if ($type === 'rpz') {
         $extra = $type;
     }
     $this->save($data);
     $id = $this->id;
     $process_id = CakeResque::enqueue('cache', $shell . 'Shell', array('cache' . $type, $org, $isSiteAdmin, $id, $extra, $extra2), true);
     $this->saveField('process_id', $process_id);
     return $id;
 }
コード例 #2
0
ファイル: Task.php プロジェクト: humbertcostas/MISP
 public function reQueue($task, $worker, $shell, $action, $userId, $taskId)
 {
     $time = time();
     // Keep adding the timer's time interval until we get a date that is in the future! We don't want to keep queuing tasks in the past since they will execute until it catches up.
     while ($task['Task']['next_execution_time'] < $time) {
         $task['Task']['next_execution_time'] = strtotime('+' . $task['Task']['timer'] . ' hours', $task['Task']['next_execution_time']);
     }
     $task['Task']['scheduled_time'] = $this->breakTime($task['Task']['scheduled_time'], $task['Task']['timer']);
     $task['Task']['scheduled_time'] = date('H:i', $task['Task']['next_execution_time']);
     // Now that we have figured out when the next execution should happen, it's time to enqueue it.
     $process_id = CakeResque::enqueueAt($task['Task']['next_execution_time'], $worker, $shell, array($action, $task['Task']['next_execution_time'], $userId, $taskId), true);
     $task['Task']['job_id'] = $process_id;
     $this->id = $task['Task']['id'];
     $this->save($task);
 }
コード例 #3
0
ファイル: Post.php プロジェクト: humbertcostas/MISP
 public function sendPostsEmailRouter($user_id, $post_id, $event_id, $title, $message, $JobId = false)
 {
     if (Configure::read('MISP.background_jobs')) {
         $user = $this->User->findById($user_id);
         $job = ClassRegistry::init('Job');
         $job->create();
         $data = array('worker' => 'email', 'job_type' => 'posts_alert', 'job_input' => 'Post: ' . $post_id, 'status' => 0, 'retries' => 0, 'org' => $user['User']['org'], 'message' => 'Sending..');
         $job->save($data);
         $jobId = $job->id;
         $process_id = CakeResque::enqueue('email', 'EventShell', array('postsemail', $user_id, $post_id, $event_id, $title, $message, $jobId));
         $job->saveField('process_id', $process_id);
         return true;
     } else {
         $result = $this->sendPostsEmail($user_id, $post_id, $event_id, $title, $message);
         return $result;
     }
 }
コード例 #4
0
ファイル: JobsController.php プロジェクト: humbertcostas/MISP
 public function index()
 {
     if (!$this->_isSiteAdmin()) {
         throw new MethodNotAllowedException();
     }
     if (!Configure::read('MISP.background_jobs')) {
         throw new NotFoundException('Background jobs are not enabled on this instance.');
     }
     $this->recursive = 0;
     $jobs = $this->paginate();
     foreach ($jobs as &$job) {
         if ($job['Job']['process_id']) {
             $job['Job']['status'] = $this->__jobStatusConverter(CakeResque::getJobStatus($job['Job']['process_id']));
         } else {
             $job['Job']['status'] = '???';
         }
     }
     $this->set('list', $jobs);
 }
コード例 #5
0
 private function _pullScheduler($timestamp, $id)
 {
     $process_id = CakeResque::enqueueAt($timestamp, 'default', 'ServerShell', array('enqueuePull', $timestamp, $this->Auth->user('id'), $id), true);
     $this->Task->id = $id;
     $this->Task->saveField('job_id', $process_id);
 }
コード例 #6
0
 public function testEnqueueAreLogged()
 {
     $Resque = $this->Resque;
     $Resque::staticExpects($this->any())->method('enqueue')->will($this->returnValue(''));
     extract($this->fixture);
     CakeResque::enqueue('one', $class, $args, $track);
     CakeResque::enqueue('one', $class, $args, $track);
     CakeResque::enqueue('two', $class, $args, $track);
     CakeResque::enqueue('three', $class, $args, $track);
     $this->assertCount(3, CakeResque::$logs);
     $this->assertCount(2, CakeResque::$logs['one']);
     $this->assertCount(1, CakeResque::$logs['two']);
     $this->assertCount(1, CakeResque::$logs['three']);
 }
コード例 #7
0
ファイル: Server.php プロジェクト: firebitsbr/MISP
 public function workerDiagnostics(&$workerIssueCount)
 {
     $this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
     $workers = $this->ResqueStatus->getWorkers();
     if (function_exists('posix_getpwuid')) {
         $currentUser = posix_getpwuid(posix_geteuid());
         $currentUser = $currentUser['name'];
     } else {
         $currentUser = trim(shell_exec('whoami'));
     }
     $worker_array = array('cache' => array('ok' => true), 'default' => array('ok' => true), 'email' => array('ok' => true), 'scheduler' => array('ok' => true));
     $procAccessible = file_exists('/proc');
     foreach ($workers as $pid => $worker) {
         $entry = $worker['type'] == 'regular' ? $worker['queue'] : $worker['type'];
         $correct_user = $currentUser === $worker['user'];
         if (!is_numeric($pid)) {
             throw new MethodNotAllowedException('Non numeric PID found.');
         }
         if ($procAccessible) {
             $alive = $correct_user ? file_exists('/proc/' . addslashes($pid)) : false;
         } else {
             $alive = 'N/A';
         }
         $ok = true;
         if (!$alive || !$correct_user) {
             $ok = false;
             $workerIssueCount++;
             $worker_array[$entry]['ok'] = false;
         }
         $worker_array[$entry]['workers'][] = array('pid' => $pid, 'user' => $worker['user'], 'alive' => $alive, 'correct_user' => $correct_user, 'ok' => $ok);
     }
     foreach ($worker_array as $k => &$queue) {
         if ($k != 'scheduler') {
             $worker_array[$k]['jobCount'] = CakeResque::getQueueSize($k);
         }
         if (!isset($queue['workers'])) {
             $workerIssueCount++;
             $queue['ok'] = false;
         }
     }
     $worker_array['proc_accessible'] = $procAccessible;
     return $worker_array;
 }
コード例 #8
0
ファイル: Event.php プロジェクト: x86Labs/MISP
 /**
  *
  * Sends out an email to all people within the same org
  * with the request to be contacted about a specific event.
  * @todo move __sendContactEmail($id, $message) to a better place. (components?)
  *
  * @param unknown_type $id The id of the event for wich you want to contact the org.
  * @param unknown_type $message The custom message that will be appended to the email.
  * @param unknown_type $all, true: send to org, false: send to person.
  *
  * @codingStandardsIgnoreStart
  * @throws \UnauthorizedException as well. // TODO Exception NotFoundException
  * @codingStandardsIgnoreEnd
  *
  * @return True if success, False if error
  */
 public function sendContactEmailRouter($id, $message, $all, $user, $isSiteAdmin, $JobId = false)
 {
     if (Configure::read('MISP.background_jobs')) {
         $job = ClassRegistry::init('Job');
         $job->create();
         $data = array('worker' => 'email', 'job_type' => 'contact_alert', 'job_input' => 'To entire org: ' . $all, 'status' => 0, 'retries' => 0, 'org' => $user['org'], 'message' => 'Contacting.');
         $job->save($data);
         $jobId = $job->id;
         $process_id = CakeResque::enqueue('email', 'EventShell', array('contactemail', $id, $message, $all, $user['id'], $isSiteAdmin, $jobId));
         $job->saveField('process_id', $process_id);
         return true;
     } else {
         $userMod['User'] = $user;
         $result = $this->sendContactEmail($id, $message, $all, $userMod, $isSiteAdmin);
         return $result;
     }
 }
コード例 #9
0
 public function generateCorrelation()
 {
     if (!self::_isSiteAdmin()) {
         throw new NotFoundException();
     }
     if (!Configure::read('MISP.background_jobs')) {
         $k = $this->Attribute->generateCorrelation();
         $this->Session->setFlash(__('All done. ' . $k . ' attributes processed.'));
         $this->redirect(array('controller' => 'pages', 'action' => 'display', 'administration'));
     } else {
         $job = ClassRegistry::init('Job');
         $job->create();
         $data = array('worker' => 'default', 'job_type' => 'generate correlation', 'job_input' => 'All attributes', 'status' => 0, 'retries' => 0, 'org' => 'ADMIN', 'message' => 'Job created.');
         $job->save($data);
         $jobId = $job->id;
         $process_id = CakeResque::enqueue('default', 'AdminShell', array('jobGenerateCorrelation', $jobId));
         $job->saveField('process_id', $process_id);
         $this->Session->setFlash(__('Job queued. You can view the progress if you navigate to the active jobs view (administration -> jobs).'));
         $this->redirect(array('controller' => 'pages', 'action' => 'display', 'administration'));
     }
 }
コード例 #10
0
ファイル: Server.php プロジェクト: vman747/MISP
 public function workerDiagnostics(&$workerIssueCount)
 {
     $this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
     $workers = $this->ResqueStatus->getWorkers();
     $currentUser = get_current_user();
     $worker_array = array('cache' => array('ok' => true), 'default' => array('ok' => true), 'email' => array('ok' => true), 'scheduler' => array('ok' => true));
     foreach ($workers as $pid => $worker) {
         $entry = $worker['type'] == 'regular' ? $worker['queue'] : $worker['type'];
         $correct_user = $currentUser === $worker['user'];
         if (!is_numeric($pid)) {
             throw new MethodNotAllowedException('Non numeric PID found.');
         }
         $alive = $correct_user ? substr_count(trim(shell_exec('ps -p ' . $pid)), PHP_EOL) > 0 : false;
         $ok = true;
         if (!$alive || !$correct_user) {
             $ok = false;
             $workerIssueCount++;
             $worker_array[$entry]['ok'] = false;
         }
         $worker_array[$entry]['workers'][] = array('pid' => $pid, 'user' => $worker['user'], 'alive' => $alive, 'correct_user' => $correct_user, 'ok' => $ok);
     }
     foreach ($worker_array as $k => &$queue) {
         if ($k != 'scheduler') {
             $worker_array[$k]['jobCount'] = CakeResque::getQueueSize($k);
         }
         if (!isset($queue['workers'])) {
             $workerIssueCount++;
             $queue['ok'] = false;
         }
     }
     return $worker_array;
 }
コード例 #11
0
ファイル: bootstrap.php プロジェクト: rchavik/Cake-Resque
<?php

/**
 * CakeResque bootstrap file.
 *
 * Used to load CakeResque class and initialize it.
 *
 * PHP version 5
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author        Wan Qi Chen <*****@*****.**>
 * @copyright     Copyright 2012, Wan Qi Chen <*****@*****.**>
 * @link          http://cakeresque.kamisama.me
 * @package       CakeResque
 * @subpackage	  CakeResque.Config
 * @since         0.5
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
require_once dirname(__DIR__) . DS . 'Lib' . DS . 'CakeResque.php';
CakeResque::init();
コード例 #12
0
ファイル: ServersController.php プロジェクト: x86Labs/MISP
 public function push($id = null, $technique = false)
 {
     $this->Server->id = $id;
     if (!$this->Server->exists()) {
         throw new NotFoundException(__('Invalid server'));
     }
     $s = $this->Server->read(null, $id);
     if (!$this->_isSiteAdmin() && !($s['Server']['org'] == $this->Auth->user('org') && $this->_isAdmin())) {
         $this->redirect(array('controller' => 'servers', 'action' => 'index'));
     }
     if (!Configure::read('MISP.background_jobs')) {
         $server = $this->Server->read(null, $id);
         App::uses('SyncTool', 'Tools');
         $syncTool = new SyncTool();
         $HttpSocket = $syncTool->setupHttpSocket($server);
         $result = $this->Server->push($id, $technique, false, $HttpSocket, $this->Auth->user('email'));
         $this->set('successes', $result[0]);
         $this->set('fails', $result[1]);
     } else {
         $this->loadModel('Job');
         $this->Job->create();
         $data = array('worker' => 'default', 'job_type' => 'push', 'job_input' => 'Server: ' . $id, 'status' => 0, 'retries' => 0, 'org' => $this->Auth->user('org'), 'message' => 'Pushing.');
         $this->Job->save($data);
         $jobId = $this->Job->id;
         $process_id = CakeResque::enqueue('default', 'ServerShell', array('push', $id, $technique, $jobId, $this->Auth->user('id')));
         $this->Job->saveField('process_id', $process_id);
         $this->Session->setFlash('Push queued for background execution.');
         $this->redirect(array('action' => 'index'));
     }
 }
コード例 #13
0
ファイル: ServersController.php プロジェクト: jmc578/MISP
 public function serverSettings($tab = false)
 {
     if (!$this->_isSiteAdmin()) {
         throw new MethodNotAllowedException();
     }
     if ($this->request->is('Get')) {
         $tabs = array('MISP' => array('count' => 0, 'errors' => 0, 'severity' => 5), 'GnuPG' => array('count' => 0, 'errors' => 0, 'severity' => 5), 'Proxy' => array('count' => 0, 'errors' => 0, 'severity' => 5), 'Security' => array('count' => 0, 'errors' => 0, 'severity' => 5), 'misc' => array('count' => 0, 'errors' => 0, 'severity' => 5), 'Plugin' => array('count' => 0, 'errors' => 0, 'severity' => 5));
         $writeableErrors = array(0 => 'OK', 1 => 'Directory doesn\'t exist', 2 => 'Directory is not writeable');
         $gpgErrors = array(0 => 'OK', 1 => 'FAIL: settings not set', 2 => 'FAIL: bad GnuPG.*', 3 => 'FAIL: encrypt 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.');
         $stixOperational = array(0 => 'STIX or CyBox library not installed correctly', 1 => 'OK');
         $stixVersion = array(0 => 'Incorrect STIX version installed, found $current, expecting $expected', 1 => 'OK');
         $cyboxVersion = array(0 => 'Incorrect CyBox version installed, found $current, expecting $expected', 1 => 'OK');
         $finalSettings = $this->Server->serverSettingsRead();
         $issues = array('errors' => array(0 => array('value' => 0, 'description' => 'MISP will not operate correctly or will be unsecure until these issues are resolved.'), 1 => array('value' => 0, 'description' => 'Some of the features of MISP cannot be utilised until these issues are resolved.'), 2 => array('value' => 0, 'description' => 'There are some optional tweaks that could be done to improve the looks of your MISP instance.')), 'deprecated' => array(), 'overallHealth' => 3);
         $dumpResults = array();
         foreach ($finalSettings as $k => $result) {
             if ($result['level'] == 3) {
                 $issues['deprecated']++;
             }
             $tabs[$result['tab']]['count']++;
             if (isset($result['error']) && $result['level'] < 3) {
                 $issues['errors'][$result['level']]['value']++;
                 if ($result['level'] < $issues['overallHealth']) {
                     $issues['overallHealth'] = $result['level'];
                 }
                 $tabs[$result['tab']]['errors']++;
                 if ($result['level'] < $tabs[$result['tab']]['severity']) {
                     $tabs[$result['tab']]['severity'] = $result['level'];
                 }
             }
             $dumpResults[] = $result;
             if ($result['tab'] != $tab) {
                 unset($finalSettings[$k]);
             }
         }
         // Diagnostics portion
         $diagnostic_errors = 0;
         App::uses('File', 'Utility');
         App::uses('Folder', 'Utility');
         $additionalViewVars = array();
         if ($tab == 'files') {
             $files = $this->__manageFiles();
             $this->set('files', $files);
         }
         // Only run this check on the diagnostics tab
         if ($tab == 'diagnostics' || $tab == 'download') {
             // check if the current version of MISP is outdated or not
             $version = $this->__checkVersion();
             $this->set('version', $version);
             if ($version && (!$version['upToDate'] || $version['upToDate'] == 'older')) {
                 $diagnostic_errors++;
             }
             // check if the STIX and Cybox libraries are working and the correct version using the test script stixtest.py
             $stix = $this->Server->stixDiagnostics($diagnostic_errors, $stixVersion, $cyboxVersion);
             // if GPG is set up in the settings, try to encrypt a test message
             $gpgStatus = $this->Server->gpgDiagnostics($diagnostic_errors);
             // if the message queue pub/sub is enabled, check whether the extension works
             $zmqStatus = $this->Server->zmqDiagnostics($diagnostic_errors);
             // if Proxy is set up in the settings, try to connect to a test URL
             $proxyStatus = $this->Server->proxyDiagnostics($diagnostic_errors);
             $additionalViewVars = array('gpgStatus', 'proxyStatus', 'zmqStatus', 'stixVersion', 'cyboxVersion', 'gpgErrors', 'proxyErrors', 'zmqErrors', 'stixOperational', 'stix');
         }
         // check whether the files are writeable
         $writeableDirs = $this->Server->writeableDirsDiagnostics($diagnostic_errors);
         $viewVars = array('diagnostic_errors', 'tabs', 'tab', 'issues', 'finalSettings', 'writeableErrors', 'writeableDirs');
         $viewVars = array_merge($viewVars, $additionalViewVars);
         foreach ($viewVars as $viewVar) {
             $this->set($viewVar, ${$viewVar});
         }
         if (Configure::read('MISP.background_jobs')) {
             $worker_array = array('cache' => array(), 'default' => array(), 'email' => array(), '_schdlr_' => array());
             // disable notice errors, getWorkers() is meant to be run from the command line and throws a notice
             // because STDIN is not defined - since we don't actually log anything this is safe to ignore.
             $error_reporting = error_reporting();
             error_reporting(0);
             $results = CakeResque::getWorkers();
             error_reporting($error_reporting);
             foreach ($results as $result) {
                 $result = (array) $result;
                 if (in_array($result["*queues"][0], array_keys($worker_array))) {
                     $worker_array[$result["*queues"][0]][] = $result["*id"];
                 }
             }
             $workerIssueCount = 0;
             foreach ($worker_array as $k => $queue) {
                 if (empty($queue)) {
                     $workerIssueCount++;
                 }
             }
             $this->set('worker_array', $worker_array);
         } else {
             $workerIssueCount = 4;
             $this->set('worker_array', array());
         }
         if ($tab == 'download') {
             foreach ($dumpResults as &$dr) {
                 unset($dr['description']);
             }
             $dump = array('gpgStatus' => $gpgErrors[$gpgStatus], 'proxyStatus' => $proxyErrors[$proxyStatus], 'zmqStatus' => $zmqStatus, 'stix' => $stix, 'writeableDirs' => $writeableDirs, 'finalSettings' => $dumpResults);
             $this->response->body(json_encode($dump, JSON_PRETTY_PRINT));
             $this->response->type('json');
             $this->response->download('MISP.report.json');
             return $this->response;
         }
         $priorities = array(0 => 'Critical', 1 => 'Recommended', 2 => 'Optional', 3 => 'Deprecated');
         $this->set('priorities', $priorities);
         $this->set('workerIssueCount', $workerIssueCount);
         $priorityErrorColours = array(0 => 'red', 1 => 'yellow', 2 => 'green');
         $this->set('priorityErrorColours', $priorityErrorColours);
     }
 }