Example #1
0
 public function execute($message)
 {
     global $pluginManager;
     global $t;
     $t->setPlugin("netutils");
     $reply = "";
     $data = $message->getData();
     $shell = new Shell();
     $execute = true;
     $call = $message->getCommand();
     array_shift($data);
     switch ($call) {
         case "nslookup":
             $shell->setFilter(array("main" => "nslookup", "subarg" => array()));
             $cmd = "nslookup " . implode(" ", $data);
             break;
         case "dig":
             $shell->setFilter(array("main" => "dig", "subarg" => array()));
             $cmd = "dig " . implode(" ", $data);
             break;
         case "nmap":
             $shell->setFilter(array("main" => "nmap", "subarg" => array()));
             $cmd = "nmap " . implode(" ", $data);
             break;
         case "whois":
             $shell->setFilter(array("main" => "whois", "subarg" => array()));
             $cmd = "whois " . implode(" ", $data);
             break;
         default:
             $reply = $t->g("default");
             $execute = false;
             break;
     }
     if ($execute) {
         $shell->setCmd($cmd);
         if ($shell->execute()) {
             $reply = "`\$ " . api::encodePlain($cmd) . "\n" . api::encodePlain(implode("\n", $shell->getOutput())) . "`";
         } else {
             $reply = sprintf($t->g("command_error"), api::encodePlain($cmd));
         }
     }
     // Api::reply($message, $reply, true);
     global $api;
     $api->sendMessage($message->chat->id, $reply, "Markdown", true);
 }
Example #2
0
 /**
  * Applies changes from remote repository.
  * @param string $projectRoot VCS project root directory path.
  * @param string $log if parameter passed it will be filled with related log string.
  * @return boolean whether the changes have been applied successfully.
  */
 public function applyRemoteChanges($projectRoot, &$log = null)
 {
     $result = Shell::execute('(cd {projectRoot}; {binPath} pull -b {branch} -u)', ['{binPath}' => $this->binPath, '{projectRoot}' => $projectRoot, '{branch}' => $this->getCurrentBranch($projectRoot)]);
     $log = $result->toString();
     return $result->isOk();
 }
Example #3
0
 public function test_failure()
 {
     $s = new Shell();
     $result = $s->execute('exit 4', $output);
     $this->assertEquals(4, $result);
 }