From e68e53a80ddd286e5dd63499c9126d4344585677 Mon Sep 17 00:00:00 2001
From: Christopher Vagnetoft <cvagnetoft@gmail.com>
Date: Fri, 16 Dec 2016 01:14:43 +0100
Subject: [PATCH] Added command module, bugfixes

---
 lib/config.php      |  8 ++++----
 modules/command.php | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 modules/command.php

diff --git a/lib/config.php b/lib/config.php
index ee7a326..d6c1130 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -67,9 +67,9 @@ function config_write() {
 
     $items = $root->createChild("items");
     foreach ($_CONFIG['items'] as $item) {
-        $opts = array_map(function ($opt) { return $opt->name; }, $_MODULES[$item[0]]->opts);
-        $conf = $items->createChild($item[0]);
-        $conf->setValue($item[1]);
+        $opts = array_map(function ($opt) { return $opt->name; }, $_MODULES[$item[1]]->opts);
+        $conf = $items->createChild($item[1]);
+        $conf->setValue($item[0]);
         foreach ($item[2] as $k=>$v) {
             if (in_array($k,$opts)) {
                 $conf->setAttribute($k,$v);
@@ -99,7 +99,7 @@ function config_item_edit($name, array $attr) {
     global $_CONFIG;
     $filtered = [];
     foreach ($_CONFIG['items'] as $item) {
-        if ($item[1]==$name) {
+        if ($item[0]==$name) {
             $item[2] = array_merge($item[2],$attr);
         }
         $filtered[] = $item;
diff --git a/modules/command.php b/modules/command.php
new file mode 100644
index 0000000..0f1d104
--- /dev/null
+++ b/modules/command.php
@@ -0,0 +1,19 @@
+<?php
+
+define("COMMAND_CLASS", "class");
+define("COMMAND_EXEC", "exec");
+
+function _command(array $opts) {
+    $attr = [
+        'class' => $opts[COMMAND_CLASS]
+    ];
+    if (($exec = $opts[COMMAND_EXEC])) {
+        $output = trim(exec($exec));
+    } else {
+        $output = null;
+    }
+    return panel($output, $attr, 'command');
+}
+module("command", "Execute a command and display the output");
+option("exec",COMMAND_EXEC,OPT_TYPE_STRING,"Command to execute","");
+option("class",COMMAND_CLASS,OPT_TYPE_STRING,"The class to use","system");
\ No newline at end of file