Beispiel #1
0
 protected function beforeAction($action, $params)
 {
     if ($this->debug) {
         ALogger::$debug = true;
     }
     return true;
 }
Beispiel #2
0
 public function actionPending()
 {
     /// DETECTED SAMPLES ACTIONS
     ALogger::log('detected files...', 'cyan');
     $m_detected = new SampleDetected('search');
     $m_detected->deleteFiles("pending_action_sde = 'delete'");
     unset($m_detected);
     /// CLEAN SAMPLES ACTIONS
     ALogger::log('clean files...', 'cyan');
     $m_undetected = new SampleClean('search');
     $m_undetected->deleteFiles("pending_action_scl = 'delete'");
     unset($m_undetected);
 }
Beispiel #3
0
 public static function deleteWhereCondition($condition)
 {
     $files = Yii::app()->db->createCommand("SELECT * FROM bogus_archives_bga WHERE {$condition}")->queryAll();
     ALogger::log('Found ' . count($files) . ' archives to delete.');
     foreach ($files as $f) {
         $bogusPath = PathFinder::get(VIREX_INCOMING_PATH, $f['detection_bga'], 'bogus', true);
         try {
             unlink($bogusPath . $f['id_bga']);
         } catch (Exception $e) {
             ALogger::error($e->getMessage());
             $err = 1;
         }
         if (!isset($err)) {
             Yii::app()->db->createCommand("DELETE FROM bogus_archives_bga WHERE id_bga = " . $f['id_bga'])->execute();
         } else {
             unset($err);
         }
     }
 }
Beispiel #4
0
 public function deleteFiles($where, $values = array())
 {
     $nerrors = 0;
     $nok = 0;
     $stillExists = Yii::app()->db->createCommand("SELECT count(*) 'n' FROM samples_detected_sde WHERE md5_sde=:md5");
     $deleteId = Yii::app()->db->createCommand("DELETE FROM samples_detected_sde WHERE id_sde=:id");
     $start = 0;
     while ($files = Yii::app()->db->createCommand("SELECT hex(md5_sde) 'hex', md5_sde, id_sde FROM samples_detected_sde WHERE " . $where)->queryAll(true, $values)) {
         ALogger::log('Found ' . count($files) . ' samples to delete.');
         $start += 5000;
         foreach ($files as $f) {
             ALogger::start_action('deleting ' . $f['md5_sde'] . '..');
             $deleteId->execute(array('id' => $f['id_sde']));
             $exists = $stillExists->bindValue(':md5', $f['md5_sde'])->queryRow();
             if (!$exists['n']) {
                 // I delete it only if is not in db anymore( it can be deleted only from monthly and still be in daily for example..)
                 $fName = PathFinder::get(VIREX_STORAGE_PATH, 'detected', '') . substr($f['hex'], 0, 3) . '/' . substr($f['hex'], 3, 3) . '/' . substr($f['hex'], 6, 3) . '/' . $f['hex'];
                 if (file_exists($fName)) {
                     try {
                         if (unlink($fName)) {
                             $nok++;
                         }
                     } catch (Exception $e) {
                         ALogger::error($e->get_message());
                         $nerrors++;
                     }
                 } else {
                     //	ALogger::error('file not found');				$nerrors++;
                     $nok++;
                 }
             } else {
                 $nok++;
             }
             ALogger::end_action();
         }
     }
     if ($nerrors + $nok > 0) {
         ALogger::log('Deleted: ' . $nok . ' samples');
         ALogger::log('Errors : ' . $nerrors . ' samples');
         ALogger::empty_line();
     }
 }
Beispiel #5
0
 public function actionDelete_fake_emails()
 {
     $nr = Yii::app()->db->createCommand('DELETE FROM external_users_usr WHERE register_date_usr < SUBDATE(NOW(), INTERVAL 2 DAY) AND status_usr = 0')->execute();
     ALogger::log($nr . ' users deleted!');
     ALogger::empty_line();
 }
Beispiel #6
0
 private function handleFolderLock($folder, $clearlock = false)
 {
     if ($clearlock) {
         $this->clearLock($folder);
     }
     if ($this->checkLock($folder, false, true)) {
         ALogger::error("{$folder} locked!");
         return false;
     }
     $this->setLock($folder);
     return true;
 }
Beispiel #7
0
 public static function init_handle_errors()
 {
     self::$oldErrorHandler = set_error_handler('ALogger::handle_error');
 }
Beispiel #8
0
 /**
  *
  * @param <string> $file
  */
 public function read_archive($file)
 {
     $this->unpacker->archivePath = $file;
     $error = false;
     $this->unpacker->unpack();
     if ($this->unpacker->hadError()) {
         $e = $this->unpacker->getError();
         ALogger::error('Unpacker: ' . $e[0] . ':' . $e[1]);
         $this->last_error = 'Unpacker: ' . $e[0] . ':' . $e[1];
         SystemHelper::emptyDir($this->unpacker->outputDir);
         if ($errorCode) {
             ALogger::error('Error cleaning extract folder ' . implode('|', $output), true);
         }
         return false;
     }
     $ok = true;
     foreach ($this->unpacker->getFiles() as $f) {
         if (!$this->check_file($f['path'], $f['mime'])) {
             $ok = false;
             break;
         }
     }
     if (!$ok) {
         foreach ($this->unpacker->getFiles() as $f) {
             unlink($f['path']);
         }
         // clean folder
         SystemHelper::emptyDir($this->unpacker->outputDir);
         if ($errorCode) {
             ALogger::error('Error cleaning extract folder ' . implode('|', $output), true);
         }
     } else {
         foreach ($this->unpacker->getFiles() as $f) {
             $this->read_file($f['path'], $f['mime']);
         }
         SystemHelper::emptyDir($this->unpacker->outputDir);
         if ($errorCode) {
             ALogger::error('Error cleaning extract folder ' . implode('|', $output), true);
         }
     }
     //perform cleanup:
     SystemHelper::emptyDir($this->unpacker->outputDir);
     if (count(scandir($this->unpacker->outputDir)) > 2) {
         ALogger::error('Error cleaning extract folder' . implode('|', $output), true);
     }
     return $ok;
 }
Beispiel #9
0
 private function move_file_to_bogus($detection, $type, $file, $error, $bogusId = null)
 {
     if ($bogusId) {
         // if file is already in bogus just change error message
         // execute update
         $q = "UPDATE bogus_archives_bga SET error_message_bga=:error WHERE id_bga=:id";
         Yii::app()->db->createCommand($q)->execute(array(':error' => $error, ':id' => $bogusId));
         return;
     }
     $bogusFolder = PathFinder::get(VIREX_INCOMING_PATH, $detection, 'bogus');
     $q = "INSERT INTO bogus_archives_bga (name_bga, detection_bga, type_bga, date_add_bga, error_message_bga)\r\n            VALUES (:name, :detection, :type, CURDATE(), :error)";
     Yii::app()->db->createCommand($q)->execute(array(':name' => basename($file), ':detection' => $detection, ':type' => $type, ':error' => $error));
     $id = Yii::app()->db->lastInsertId;
     try {
         rename($file, $bogusFolder . DIRECTORY_SEPARATOR . $id);
     } catch (Exception $e) {
         ALogger::error($e->getMessage(), true);
         // critical error
     }
 }