예제 #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
파일: 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;
     }
 }
예제 #3
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']);
 }
예제 #4
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;
     }
 }
예제 #5
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'));
     }
 }
예제 #6
0
 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'));
     }
 }