Esempio n. 1
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     $collector = collectorFactory::create($this->argument('name'));
     if (!$collector) {
         $this->error("The requested collector {$this->argument('name')} could not be started check logs for PID:" . getmypid());
         return false;
     }
     $results = $collector->parse();
     print_r($results);
     return true;
 }
Esempio n. 2
0
 /**
  * Execute the command.
  *
  * @return bool
  */
 public function handle()
 {
     Log::info(get_class($this) . ': ' . 'Queued worker is starting the collector: ' . $this->collector);
     $collector = collectorFactory::create($this->collector);
     if (!$collector) {
         Log::error("The requested collector {$this->collector} could not be started check logs for PID:" . getmypid());
         $this->exception();
         return;
     }
     $collectorResult = $collector->parse();
     if ($collectorResult['errorStatus'] == true) {
         Log::error("The requested collector {$this->collector} returned an error. check logs for PID:" . getmypid());
         $this->exception();
         return;
     }
     /*
      * save evidence onto disk
      */
     $evidence = new EvidenceSave();
     $evidenceData = json_encode(['collectorName' => $this->collector, 'collectorData' => $collectorResult]);
     $evidenceFile = $evidence->save($evidenceData);
     if (!$evidenceFile) {
         Log::error(get_class($this) . ': ' . 'Error returned while asking to write evidence file, cannot continue');
         $this->exception();
         return;
     }
     /*
      * build evidence model, but wait with saving it
      **/
     $evidence = new Evidence();
     $evidence->filename = $evidenceFile;
     $evidence->sender = 'abuse@localhost';
     $evidence->subject = "CLI Collector {$this->collector}";
     /*
      * Call IncidentsProcess to validate, store evidence and save incidents
      */
     $incidentsProcess = new IncidentsProcess($collectorResult['data'], $evidence);
     // Only continue if not empty, empty set is acceptable (exit OK)
     if (!$incidentsProcess->notEmpty()) {
         return;
     }
     // Validate the data set
     if (!$incidentsProcess->validate()) {
         $this->exception();
         return;
     }
     // Write the data set to database
     if (!$incidentsProcess->save()) {
         $this->exception();
         return;
     }
     Log::info(get_class($this) . ': ' . 'Queued worker has ended the processing of collector: ' . $this->collector);
 }
Esempio n. 3
0
 /**
  * Execute the console command.
  *
  * @return bool
  */
 public function handle()
 {
     Log::info(get_class($this) . ': ' . 'Starting a collection run for all enabled collectors');
     $collectors = collectorFactory::getCollectors();
     foreach ($collectors as $collectorName) {
         if (config("collectors.{$collectorName}.collector.enabled") === true) {
             if ($this->option('noqueue') == true) {
                 // In debug mode we don't queue the job
                 Log::debug(get_class($this) . ': ' . 'Queuing disabled. Directly handling message file: ' . $collectorName);
                 $processer = new CollectorProcess($collectorName);
                 $processer->handle();
             } else {
                 Log::info(get_class($this) . ': ' . 'Pushing collector into queue: ' . $collectorName);
                 $this->dispatch(new CollectorProcess($collectorName));
             }
         }
     }
     Log::info('Completed collections startup for all enabled collectors');
     return true;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc }
  */
 protected function findAll()
 {
     $collectors = collectorFactory::getCollectors();
     return $this->hydrateCollectorsWithDescription($collectors);
 }
Esempio n. 5
0
 /**
  * Execute the command
  *
  * @return boolean
  */
 public function handle()
 {
     Log::info(get_class($this) . ': ' . 'Queued worker is starting the collector: ' . $this->collector);
     $collector = collectorFactory::create($this->collector);
     if (!$collector) {
         Log::error("The requested collector {$this->collector} could not be started check logs for PID:" . getmypid());
         $this->exception();
     }
     $collectorResult = $collector->parse();
     if ($collectorResult['errorStatus'] == true) {
         Log::error("The requested collector {$this->collector} returned an error. check logs for PID:" . getmypid());
         $this->exception();
     }
     if (count($collectorResult['data']) !== 0) {
         // Call validator
         $validator = new EventsValidate();
         $validatorResult = $validator->check($collectorResult['data']);
         if ($validatorResult['errorStatus'] === true) {
             Log::error(get_class($validator) . ': ' . 'Validator has ended with errors ! : ' . $validatorResult['errorMessage']);
             $this->exception();
             return;
         } else {
             Log::info(get_class($validator) . ': ' . 'Validator has ended without errors');
         }
         /**
          * save evidence onto disk
          */
         $filesystem = new Filesystem();
         $datefolder = Carbon::now()->format('Ymd');
         $path = storage_path() . '/mailarchive/' . $datefolder . '/';
         $file = Uuid::generate(4) . '.eml';
         $filename = $path . $file;
         if (!$filesystem->isDirectory($path)) {
             // If a datefolder does not exist, then create it or die trying
             if (!$filesystem->makeDirectory($path)) {
                 Log::error(get_class($this) . ': ' . 'Unable to create directory: ' . $path);
                 $this->exception();
             }
             chown($path, 'abuseio');
             chgrp($path, 'abuseio');
         }
         if ($filesystem->isFile($filename)) {
             Log::error(get_class($this) . ': ' . 'File aready exists: ' . $filename);
             $this->exception();
         }
         if ($filesystem->put($filename, json_encode(['collectorName' => $this->collector, 'collectorData' => $collectorResult])) === false) {
             Log::error(get_class($this) . ': ' . 'Unable to write file: ' . $filename);
             $this->exception();
         }
         chown($path . $filename, 'abuseio');
         chgrp($path . $filename, 'abuseio');
         /**
          * save evidence into table
          **/
         $evidence = new Evidence();
         $evidence->filename = $filename;
         $evidence->sender = 'abuse@localhost';
         $evidence->subject = "CLI Collector {$this->collector}";
         $evidence->save();
         /**
          * call saver
          **/
         $saver = new EventsSave();
         $saverResult = $saver->save($collectorResult['data'], $evidence->id);
         /**
          * We've hit a snag, so we are gracefully killing ourselves
          * after we contact the admin about it. EventsSave should never
          * end with problems unless the mysql died while doing transactions
          **/
         if ($saverResult['errorStatus'] === true) {
             Log::error(get_class($saver) . ': ' . 'Saver has ended with errors ! : ' . $saverResult['errorMessage']);
             $this->exception();
             return;
         } else {
             Log::info(get_class($saver) . ': ' . 'Saver has ended without errors');
         }
     } else {
         Log::warning(get_class($this) . ': ' . 'Collector did not return any events therefore skipping validation and saving a empty event set');
     }
     Log::info(get_class($this) . ': ' . 'Queued worker has ended the processing of collector: ' . $this->collector);
 }