Beispiel #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);
 }
Beispiel #2
0
 public function execute($message)
 {
     $cmd = strtolower($message->getCommand());
     $data = $message->getData();
     $params = array("format" => "plaintext");
     $wa = new WolframAlphaEngine(WOLFRAM_API_KEY);
     $res = $wa->getResults(implode(" ", $data), $params);
     file_put_contents("log/wolfram.log", json_encode($res));
     $sol = array();
     if ($res->isError()) {
         Api::reply($message, "Da kann ich leider nichts mit anfangen...", false);
         return;
     }
     if (count($res->getPods()) > 0) {
         foreach ($res->getPods() as $pod) {
             if ($pod->attributes["id"] == "Solution") {
                 $sol[] = "*Ergebnisse für " . implode(" ", $data) . "*:";
                 foreach ($pod->getSubpods() as $solution) {
                     $sol[] = api::encodePlain($solution->plaintext);
                 }
             } elseif ($pod->attributes["id"] == "ComplexSolution") {
                 $sol[] = "*Komplexe Ergebnisse für " . implode(" ", $data) . "*:";
                 foreach ($pod->getSubpods() as $solution) {
                     $sol[] = api::encodePlain($solution->plaintext);
                 }
             } elseif ($pod->attributes["id"] == "Result") {
                 $sol[] = "*Ergebnis für " . implode(" ", $data) . "*:";
                 foreach ($pod->getSubpods() as $solution) {
                     $sol[] = api::encodePlain($solution->plaintext);
                 }
             }
         }
     }
     if (sizeof($sol) == 0) {
         $sol[] = "Leider keine Ergebnisse :(";
     }
     Api::reply($message->chat, implode("\n", $sol), true);
 }