Development > Coding and development discussion

Running system commands from bot

<< < (2/2)

Tomate:
I will improve the module in security aspects etc., but first I want core functionality.
According to the PHP manual the system(); command will only output the last line.
I need to use shell_exec(); instead. It works perfectly now.

Here's my result:


--- Code: ---<?php
   /*
Versuch: system();-Kommandos via Bot
   */
 
  $bash = new bash($bot);

  class bash Extends BaseActiveModule
  {
    var $bot;
    var $bash;
    var $returnstr;


    function __construct (&$bot)
    {
      parent::__construct(&$bot, get_class($this));

      $this -> register_command("all", "bash", "SUPERADMIN");

      $this -> help['description'] = 'linux bash list';
      $this -> help['command']['beer']="bash list";

     }



function command_handler($name, $msg, $source)
{
$this->error->reset();
$args = $this->parse_com($msg, array('com','args'));
$retstr = shell_exec($args["args"]);
return "Kommando ausgeführt. ".$this -> bot -> core("tools") -> make_blob("Ausgabe", $retstr);
}
}

?>
--- End code ---

Thanks for your help!

Navigation

[0] Message Index

[*] Previous page

Go to full version