From 2e2ba3bb01f19f4141fc691b24610939302d3559 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 7 Jun 2020 03:59:18 +0100 Subject: Clean things up a bit and get things working again! --- Blatech.php | 117 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 54 insertions(+), 63 deletions(-) (limited to 'Blatech.php') diff --git a/Blatech.php b/Blatech.php index 701f2c2..fc414c3 100644 --- a/Blatech.php +++ b/Blatech.php @@ -1,70 +1,61 @@ - */ class Blatech { - protected $blatech = null; - - /** - * Construct the object loading the config file and storing it - * as an array in the $blatech var - * - * @author Phil Burton - * @param $config String The file and path of the config file - */ - public function __construct($config) - { - $this->blatech = parse_ini_file($config,true); - } - - /** - * Run a shell command and return the result - * - * @author Phil Burton - * @param $message Array The message containing the required commands - * @param $args String The sting of space seperated arguments - * @return String The result of the shell command - * @todo Abstract IRC related information away from this class - */ - public function runCommand($message, $args) - { - // Sanitise arguments - $args = static::sanitiseArgs($args); - var_dump($args); - $nick = ltrim(explode('!', $message[0])[0],":"); - $channel = $message[2]; + protected $blatech = null; - $msg = explode(" ", ltrim(trim($message[3],"\r\n"), ":!")); - if (!isset($msg[0])) { - return null; - } else { - if (array_key_exists($msg[0], $this->blatech)) { - $command = $this->blatech[$msg[0]]['command']; - $stdin = $this->blatech[$msg[0]]['stdin']; - $cargs = $this->blatech[$msg[0]]['args']; - $path = $this->blatech[$msg[0]]["path"]; - if ($path == true) { - $cd = "cd " . $path . ' && '; - } else { - $cd = ""; - } - if ($stdin == true) { - return explode("\n", shell_exec($cd . 'echo "' . $args . '" | ' . $command))[0]; - } else if ($cargs == true) { - return 'Command Line Arguments Not Supported Yet.'; - } else { - return explode("\n", shell_exec($cd . $command))[0]; - } - } - } - } + public function __construct($config) + { + $this->blatech = parse_ini_file($config, true); + } - private static function sanitiseArgs($string) - { - return preg_replace('/[^a-z\d_+:@#~!?\\/"\'£$%^*(){}\-\][=,.< >]/iu', '', $string); - } + public function runCommand($message, $args) + { + $args = static::sanitiseArgs($args); + $nick = ltrim(explode('!', $message[0])[0], ":"); + $channel = $message[2]; + $msg = explode(" ", ltrim(trim($message[3], "\r\n"), ":!")); + + if (!isset($msg[0])) { + return null; + } else { + if (array_key_exists($msg[0], $this->blatech)) { + $command = $this->blatech[$msg[0]]['command']; + $stdin = $this->blatech[$msg[0]]['stdin']; + $cargs = $this->blatech[$msg[0]]['args']; + $path = $this->blatech[$msg[0]]["path"]; + $include_trigger_as_argument = $this->blatech[$msg[0]]['include_trigger_as_argument']; + + if ($include_trigger_as_argument) { + $args = $msg[0] . ' ' . $args; + } + + if ($path) { + $path_check = is_readable($path); + + if (!$path_check) { + return 'Cannot access directory at : ' . $path; + } + + $cd = "cd " . $path . ' && '; + } else { + $cd = ""; + } + if ($stdin == true) { + // var_dump($cd . 'echo "' . $args . '" | ' . $command); + return explode("\n", shell_exec($cd . 'echo "' . $args . '" | ' . $command))[0]; + } else if ($cargs == true) { + return 'Command Line Arguments Not Supported Yet.'; + } else { + // var_dump($cd . 'echo "' . $args . '" | ' . $command); + return explode("\n", shell_exec($cd . $command))[0]; + } + } + } + } + + private static function sanitiseArgs($string) + { + return preg_replace('/[^a-z\d_+:@#~!?\\/"\'£$%^*(){}\-\][=,.< >]/iu', '', $string); + } } -- cgit v1.2.3