.. Reference: http://agiletoolkit.org/doc/ref *ATK4***************************************************** This file is part of Agile Toolkit 4 http://agiletoolkit.org (c) 2008-2011 Agile Technologies Ireland Limited Distributed under Affero General Public License v3 If you are using this file in YOUR web software, you must make your make source code for YOUR web software public. See LICENSE.txt for more information You can obtain non-public copy of Agile Toolkit 4 at http://agiletoolkit.org/commercial ****************************************************ATK4*
Inheritance: extends AbstractController
Exemple #1
0
 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');
 }
 /**
  * Because I kept writing this a lot
  *
  * @param $file
  *
  * @return mixed|null
  */
 public static function PathRead($file)
 {
     $file = JsonReader::GetRawFile(PathFinder::Path($file));
     if ($file != null) {
         return json_decode($file, true);
     }
     return null;
 }
Exemple #3
0
 function calculate()
 {
     if ($this->calculed == false) {
         $this->calculing = true;
         $startFinder = new PathFinder($this, $this->fromTile, null);
         $startFinder->applyForBest();
         $i = 0;
         while (count($this->_buffer) && $i < $this->_maxIteration) {
             $pathFinder = $this->removeFromBufferAt(0);
             $pathFinder->calculate();
             $i++;
         }
         $this->success = $i < $this->_maxIteration;
         if (!$this->success) {
             debug('busted');
         }
         $this->calculed = true;
     }
 }
Exemple #4
0
 /**
  * Find paths from this node to the given node
  *
  * @param Node $to
  * @param string $type
  * @param string $dir
  * @return PathFinder
  */
 public function findPathsTo(Node $to, $type = null, $dir = null)
 {
     $finder = new PathFinder($this->client);
     $finder->setStartNode($this);
     $finder->setEndNode($to);
     if ($dir) {
         $finder->setDirection($dir);
     }
     if ($type) {
         $finder->setType($type);
     }
     return $finder;
 }
Exemple #5
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);
         }
     }
 }
 /**
  * Parses a path.
  *
  * @param $path
  *
  * @return null|string
  */
 private static function ParsePath($path)
 {
     /**
      * First, we explode the path.
      */
     $real_path = explode("\\", $path);
     /**
      * We then create a temporary string which will be added to.
      */
     $built_path = "";
     /**
      * We then loop
      */
     foreach ($real_path as $key => $value) {
         /**
          * Extend the path
          */
         $built_path = $built_path . $value . "/";
         /**
          * If we find our sources folder
          */
         if (FileMethods::DirectoryExists($built_path . PathFinder::$source_folder)) {
             /**
              * This is basically a safe check to find out if we found the right src
              */
             if (PathFinder::FindSecret($built_path)) {
                 /**
                  * Return the correct path!
                  */
                 return $built_path;
             }
             continue;
         } else {
             continue;
         }
     }
     return null;
 }
Exemple #7
0
 function exec_gpg($command)
 {
     $tempd = PathFinder::ensure(VIREX_TEMP_PATH . DIRECTORY_SEPARATOR . 'gpg');
     $gpghome = PathFinder::ensure(VIREX_TEMP_PATH . DIRECTORY_SEPARATOR . 'gnupg');
     $file = uniqid('file_');
     $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", "{$tempd}/{$file}.txt", "w"));
     //        $process = proc_open('gpg --always-trust --no-secmem-warning ' . $command, $descriptorspec, $pipes, $tempd);
     $process = proc_open('gpg --always-trust --no-secmem-warning --no-tty --homedir=' . $gpghome . ' ' . $command, $descriptorspec, $pipes, $tempd);
     if (is_resource($process)) {
         proc_close($process);
     }
     $response = file_get_contents("{$tempd}/{$file}.txt");
     unlink("{$tempd}/{$file}.txt");
     return $response;
 }
Exemple #8
0
 public function encrypt_buffer($buffer, $recp)
 {
     $gpghome = PathFinder::ensure(VIREX_TEMP_PATH . DIRECTORY_SEPARATOR . 'gnupg');
     $plaintext = tempnam(VIREX_TEMP_PATH, "Buffer");
     $encrypted = $plaintext . ".gpg";
     $fout = fopen($plaintext, "w");
     fwrite($fout, $buffer);
     fclose($fout);
     $command = 'gpg --batch --pgp2 --no-tty --homedir=' . $gpghome . ' --always-trust --no-secmem-warning -e -r "' . $recp . '" ' . $plaintext;
     $result = exec($command, $output, $errorcode);
     if (!file_exists($encrypted)) {
         die("ERROR! => Error encrypting buffer!");
     }
     $encrypted_buffer = file_get_contents($encrypted);
     @unlink($plaintext);
     @unlink($encrypted);
     return $encrypted_buffer;
 }
Exemple #9
0
 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;
         }
     }
 }
 public function testGetPaths_TransportFails_ThrowsException()
 {
     $startNode = new Node($this->client);
     $startNode->setId(123);
     $endNode = new Node($this->client);
     $endNode->setId(456);
     $finder = new PathFinder($this->client);
     $finder->setType('FOOTYPE')->setDirection(Relationship::DirectionOut)->setMaxDepth(3)->setStartNode($startNode)->setEndNode($endNode);
     $this->transport->expects($this->any())->method('post')->will($this->returnValue(array('code' => 400)));
     $this->setExpectedException('\\Everyman\\Neo4j\\Exception');
     $this->client->getPaths($finder);
 }
Exemple #11
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();
     }
 }
 /**
  * Reads the default parser needles
  *
  * @return mixed|null
  */
 public static function ReadDefaults()
 {
     return JsonReader::ReadFile(PathFinder::RealPath("Json/misc/default_parser_needles.json"));
 }
Exemple #13
0
 function calculate()
 {
     $adjacentTiles = array($this->getTopTile(), $this->getRightTile(), $this->getBottomTile(), $this->getLeftTile());
     foreach ($adjacentTiles as $t) {
         //if(empty($this->lastTile['tile'])){
         //	debug($this->lastTile);
         //}
         if ($t && (empty($this->lastTile) || $t['Tile']['id'] != $this->lastTile['Tile']['id']) && $this->_calculator->testTileForPathing($t)) {
             $pathFinder = new PathFinder($this->_calculator, $t, $this->curTile);
             $pathFinder->applyForBest();
         }
     }
 }
Exemple #14
0
 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');
 }
 /**
  * Again, because I was writing this quite a bit haha!
  *
  * @param $file
  *
  * @param $contents
  *
  * @return null
  */
 public static function PathWrite($file, $contents)
 {
     return JsonWriter::Write(PathFinder::Path($file), $contents);
 }
Exemple #16
0
{
    $map = array();
    for ($x = 1; $x <= 20; $x++) {
        for ($y = 1; $y <= 20; $y++) {
            $rand = rand(1, 4);
            if ($rand == 1) {
                $map[$x . 'x' . $y] = array('weight' => '3.0');
            } else {
                $map[$x . 'x' . $y] = array('weight' => '1.0');
            }
        }
    }
    return $map;
}
//Currently getMap is dynamic and changes with each try, but you can send a pre-generated maps here just as easily
//as long as the weight is set for each map tile element and the array key is in XxY format
$map = getMap();
require 'class.pathfinder.php';
$path = new PathFinder();
//Create new pathfinder object
$path->setOrigin(1, 1);
//Set the start location
$path->setDestination(20, 20);
//Set the destination
$path->setMap($map);
//Assign the map to use for calculations
$result = $path->returnPath();
//Returns an array of all the walked steps
echo '<pre>';
print_r($result);
echo '</pre>';
Exemple #17
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
     }
 }
Exemple #18
0
            //echo "$now => $next = $len\n";
            $now = $next;
        }
        return $len;
    }
}
$max = [];
$max_num = 0;
$start = time();
//可怜的我发现自己不会写排列组合的代码 >_< ,下一版本改进
for ($path_num = 123456789; $path_num <= 598764321; $path_num++) {
    $str = strval($path_num);
    if ($str[0] == 3) {
        $path_num = 512346789;
        //3,4和1,2等效
    }
    if (strpos($str, '0')) {
        continue;
    }
    $path = array_filter(preg_split("//", $str));
    if (count(array_unique($path)) != count($path)) {
        continue;
    }
    $o = new PathFinder();
    $total = $o->calculate($path);
    if ($total > $max_num) {
        $max_num = $total;
        $max = $path;
    }
}
var_dump($max, $max_num, time() - $start);
Exemple #19
0
 /**
  * Read tor exit points.
  *
  * @return mixed|null
  */
 public static function ReadTorExitPoints()
 {
     if (FileMethods::FileExists(PathFinder::Path('Json/resources/tor_exit_points.json'))) {
         return JsonReader::PathRead('Json/resources/tor_exit_points.json');
     }
     return null;
 }
Exemple #20
0
 /**
  * Add new location with additional resources.
  *
  * @param array $contents
  * @param mixed $obsolete
  *
  * @return PathFinder_Location
  */
 public function addLocation($contents, $obsolete = UNDEFINED)
 {
     if ($obsolete !== UNDEFINED) {
         throw $this->exception('Use a single argument for addLocation');
     }
     return $this->pathfinder->addLocation($contents);
 }
Exemple #21
0
 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));
 }