Exemplo n.º 1
0
 public function testInputArguments()
 {
     $tests = array(array("data" => array("conntrack-monitor.php", "--verbose", "--filter", "194.8.253.11"), "result" => array("verbose" => true, "filter" => "194.8.253.11")), array("data" => array("conntrack-monitor.php", "--verbose"), "result" => array("verbose" => true)), array("data" => array("conntrack-monitor.php", "--help"), "result" => array("action" => "help")), array("data" => array("conntrack-monitor.php", "--show", "alias"), "result" => array("action" => "show", "value" => "alias")), array("data" => array("conntrack-monitor.php", "-v"), "result" => array("verbose" => true)), array("data" => array("conntrack-monitor.php", "--alias", "194.8.253.77", "vps0008.best-hosting.cz"), "result" => array("action" => "alias", "ip" => "194.8.253.77", "value" => "vps0008.best-hosting.cz")), array("data" => array("conntrack-monitor.php", "-a", "194.8.253.77", "vps0008.best-hosting.cz"), "result" => array("action" => "alias", "ip" => "194.8.253.77", "value" => "vps0008.best-hosting.cz")), array("data" => array("conntrack-monitor.php", "-m", 500), "result" => array("minimum" => 500)));
     foreach ($tests as $t) {
         // 			var_dump($t["data"]);die;
         $args = new Arguments($t["data"]);
         $this->assertTrue($t["result"] == $args->getArguments());
     }
 }
 public function run($argv)
 {
     // CLI arguments
     $args = new Arguments($argv);
     $this->config = $this->getconfig();
     $this->config = $args->fill($args->getArguments(), $this->config);
     // subnets and connections config
     $fc = new FileCache(__DIR__ . self::CACHE_CONNECTIONS);
     $this->config["connections"] = $fc->getData();
     $fc = new FileCache(__DIR__ . self::CACHE_SUBNETS);
     $this->config["subnets"] = $fc->getData();
     // 	var_dump($this->config['action']);die;
     switch ($this->config['action']) {
         case "alias":
             $out = $this->setCacheValue(__DIR__ . self::CACHE_ALIAS, $this->config['ip'], $this->config['value']);
             break;
         case "connection":
             $out = $this->setCacheValue(__DIR__ . self::CACHE_CONNECTIONS, $this->config['ip'], $this->config['value']);
             break;
         case "subnet":
             $out = $this->setCacheValue(__DIR__ . self::CACHE_SUBNETS, $this->config['ip'], $this->config['value']);
             break;
         case "limit":
             $out = $this->setLimit($this->config['ip'], $this->config['limit']);
             break;
         case "show":
             $out = $this->show($this->config['value']);
             break;
         case "help":
             $out = $this->help();
             break;
         case "conntrack":
         default:
             $out = $this->conntrackAction($args->getStream());
             break;
     }
     return $out;
 }