diff options
Diffstat (limited to 'Blatech.php')
-rw-r--r-- | Blatech.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Blatech.php b/Blatech.php new file mode 100644 index 0000000..c1b477e --- /dev/null +++ b/Blatech.php @@ -0,0 +1,62 @@ +<?php + +/** + * Run shell commands loaded from a config file + * + * @author Phil Burton <phlbeansburton@gmail.com> + */ +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 <philbeansburton@gmail.com> + * @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 <philbeansburton@gmail.com> + * @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) + { + $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"]; + 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]; + } + } + } + } +} |