public function __construct($detection = 'detected') { $this->unpacker = new AUnpacker(); $this->unpacker->max_files = 10; $this->unpacker->r_levels = 1; $this->unpacker->outputDir = PathFinder::ensure(VIREX_TEMP_PATH . DIRECTORY_SEPARATOR . 'urls'); $this->baseUrl = PathFinder::get(VIREX_INCOMING_PATH, $detection, 'urls'); }
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); } } }
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(); } }
public function actionDownload() { $type = $_GET['type']; $md5 = $_GET['md5']; if ($type == 'detected') { $file = Yii::app()->db->createCommand()->select('hex(md5_sde) "hex"')->from('samples_detected_sde')->where('md5_sde =:md5', array(':md5' => $md5))->queryRow(); if ($file) { $fName = $file['hex']; $file = PathFinder::get(VIREX_STORAGE_PATH, $type, '') . substr($fName, 0, 3) . '/' . substr($fName, 3, 3) . '/' . substr($fName, 6, 3) . '/' . $fName; header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $md5 . "\""); echo file_get_contents($file); die; } } elseif ($type == 'clean') { $file = Yii::app()->db->createCommand()->select('hex(md5_scl) "hex"')->from('samples_clean_scl')->where('md5_scl =:md5', array(':md5' => $md5))->queryRow(); if ($file) { $fName = $file['hex']; $file = PathFinder::get(VIREX_STORAGE_PATH, $type, '') . substr($fName, 0, 3) . '/' . substr($fName, 3, 3) . '/' . substr($fName, 6, 3) . '/' . $fName; header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $md5 . "\""); echo file_get_contents($file); die; } } }
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 } }
public function actionSearch_file() { $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $time1 = $time; if (isset($_POST['search_md5'])) { $min_date = Yii::app()->user->limitation_date; $rd = Yii::app()->user->rights_daily; $rm = Yii::app()->user->rights_monthly; $rightsCondition = ''; if (!$rd || !$rm) { if ($rd) { $rightsCondition = ' AND type_sde = "daily"'; } elseif ($rm) { $rightsCondition = ' AND type_sde = "monthly"'; } else { $rightsCondition = ' AND type_sde = "None"'; } } $file = Yii::app()->db->createCommand()->select('md5_sde, hex(md5_sde) "hex"')->from('samples_detected_sde')->where('md5_sde =:md5 AND added_when_sde>="' . $min_date . '" AND enabled_sde = 1 ' . $rightsCondition, array(':md5' => $_POST['search_md5']))->queryRow(); if ($file) { header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $file['md5_sde'] . "\""); $file = PathFinder::get(VIREX_STORAGE_PATH, 'detected', '') . substr($file['hex'], 0, 3) . '/' . substr($file['hex'], 3, 3) . '/' . substr($file['hex'], 6, 3) . '/' . $file['hex']; readfile($file); die; } else { Yii::app()->user->setFlash('_error', "No sample found!"); $this->render('search_file'); return; } } elseif (isset($_POST['search_detection'])) { $search = $_POST['search_detection']; $min_date = Yii::app()->user->limitation_date; $rd = Yii::app()->user->rights_daily; $rm = Yii::app()->user->rights_monthly; $rightsCondition = ''; if (!$rd || !$rm) { if ($rd) { $rightsCondition = ' AND type_sde = "daily"'; } elseif ($rm) { $rightsCondition = ' AND type_sde = "monthly"'; } } $files = Yii::app()->db->createCommand()->select('md5_sde, file_size_sde')->from('samples_detected_sde')->where('added_when_sde>="' . $min_date . '" ' . $rightsCondition . ' and enabled_sde=1 AND detection_sde LIKE :detection', array(':detection' => $search . '%'))->group('md5_sde')->limit(1000)->queryAll(); $cont = ''; $f_id = 0; $id = (int) Yii::app()->user->userId; if (count($files)) { Yii::app()->db->createCommand("INSERT INTO user_lists_usl (date_usl, idusr_usl, text_usl, number_of_files_usl, start_interval_usl, end_interval_usl, list_type_usl)\r\n\t\t\t\t\t\t\tVALUES (NOW(), {$id}, :text, :number, :min_date, NOW(), 'Detected')")->execute(array(':text' => $_POST['search_detection'], ':number' => count($files), ':min_date' => $min_date)); $f_id = Yii::app()->db->lastInsertID; Yii::app()->db->createCommand("INSERT INTO permanent_statistics_user_psu (date_psu, hour_psu, idusr_psu, files_number_psu, files_size_psu, files_in_list_count_psu) VALUES\r\n\t\t\t\t\t\t\t\t(CURDATE(), HOUR(NOW()), {$id}, 0, 0, " . count($files) . ") ON DUPLICATE KEY UPDATE files_in_list_count_psu=files_in_list_count_psu+" . count($files))->execute(); } else { Yii::app()->user->setFlash('_error', "No samples found!"); $this->render('search_file'); return; } $command = Yii::app()->db->createCommand("INSERT INTO user_files_usf (idusl_usf, md5_usf, date_usf, count_usf, idusr_usf, file_size_usf) VALUES (\r\n\t\t\t\t\t\t\t\t{$f_id}, :md5, NOW(), 0, {$id}, :size)"); foreach ($files as $file) { $cont .= trim($file['md5_sde']) . ':' . $file['file_size_sde'] . "\n"; $command->bindValue(':md5', $file['md5_sde']); $command->bindvalue(':size', $file['file_size_sde']); $command->execute(); } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . date('Y-m-d') . ".txt\""); echo $cont; die; } $this->render('search_file'); }
public function actionUrls() { $model = new BogusArchive('search'); if (isset($_GET['action'])) { $id = (int) $_GET['id']; switch ($_GET['action']) { case 'download': $file = $model->findByPk($id); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $file->name_bga . "\""); echo file_get_contents(PathFinder::get(VIREX_STORAGE_PATH, $file->detection_bga, 'bogus', true) . $file->id_bga); die; break; case 'unpack': Yii::app()->db->createCommand("UPDATE bogus_archives_bga SET pending_action_bga='Rescan' WHERE id_bga={$id}")->execute(); Yii::app()->user->setFlash('_success', "Urls file will be reprocessed soon!"); header("Location: " . $_SERVER['HTTP_REFERER']); break; case 'delete': Yii::app()->db->createCommand("UPDATE bogus_archives_bga SET pending_action_bga='Delete' WHERE id_bga={$id}")->execute(); Yii::app()->user->setFlash('_success', "Urls file will be deleted soon!"); header("Location: " . $_SERVER['HTTP_REFERER']); break; } } $model->unsetAttributes(); // clear any default values if (isset($_GET['BogusArchive'])) { $model->attributes = $_GET['BogusArchive']; } $this->render('urls', array('model' => $model)); }