Add support for shell scripts and auto-executed scripts.
authorChristian Weiske <cweiske@cweiske.de>
Wed, 25 Nov 2015 16:14:19 +0000 (17:14 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 25 Nov 2015 16:14:19 +0000 (17:14 +0100)
Now I'm finally able to control my house's heating system
from the kitchen radio.

README.rst
www/index.php

index c84f3e4d1ef41265f9f4ff98298bb55726567d6d..9d86b21832d7d8ef9a347cde026972d6352c3a9b 100644 (file)
@@ -1,7 +1,8 @@
 ********************
 Noxon iRadio gateway
 ********************
 ********************
 Noxon iRadio gateway
 ********************
-Push your own content onto Noxon iRadio devices.
+Push your own content onto Noxon iRadio devices:
+RSS feeds, text files and MediaTomb server structures.
 
 This tool makes it possible to push own data into the menu
 entries
 
 This tool makes it possible to push own data into the menu
 entries
@@ -11,11 +12,54 @@ entries
 - My Noxon
 
 
 - My Noxon
 
 
-================
-Adding a podcast
-================
-Create a file "Title.url" in ``var/podcasts/`` and write
-the URL of the podcast MP3 RSS feed into it.
+===================================
+Customizung the directory structure
+===================================
+The ``var/`` directory contains three directories you can fill with
+your own content.
+
+================ ==================
+Menu item        ``var/`` Directory
+================ ==================
+Internet Radio   ``internetradio``
+Podcasts         ``podcasts``
+My Noxon         ``mynoxon``
+================ ==================
+
+You can put folders and files into this directories.
+
+The ``internetradio`` directory is hard-coded to display the contents
+of a MediaTomb UPnP server.
+You can remove the check in ``index.php#handleRequest()`` if you do not
+want this.
+
+
+File types
+==========
+Directory
+  A directory is browsable by your Noxon radio
+``.sh`` file
+  Shell script which is shown as directory and which gets executed
+  when navigating into it.
+  Output is shown as it is for ``.txt`` files.
+
+  I use it to control my house's heating system from the radio.
+``.auto.sh``
+  Shell script which gets executed when browsing the folder.
+  The output is integrated into the directory listing with the same
+  rules as for ``.txt`` files.
+
+  You can use this to show the current time within the directory listing.
+``.txt`` file
+  Text files are rendered as un-actionable lists.
+
+  Empty lines get removed, consecutive spaces get collapsed.
+``.url`` file
+  Podcast feed URL file.
+
+  Simply contains the URL to the podcast's MP3 RSS feed.
+
+File extensions get removed for display purposes.
 
 
 =====
 
 
 =====
@@ -32,6 +76,12 @@ by this tool::
     gatekeeper.my-noxon.net
 
 
     gatekeeper.my-noxon.net
 
 
+MediaTomb
+=========
+To be able to browse a MediaTomb server, copy ``data/config.php.dist`` to
+``data/config.php`` and fill it with mediatomb web interface credentials.
+
+
 =======
 License
 =======
 =======
 License
 =======
index b7426326e1d46e8925c199bd822b0c39024e0bd3..2a380377f89e175fcdfccfd73cfea60e9b4d909d 100644 (file)
@@ -80,13 +80,16 @@ function handleRequest($path)
         return;
     }
 
         return;
     }
 
+    $ext = pathinfo($path, PATHINFO_EXTENSION);
     if (is_dir($fullPath)) {
         sendDir($path);
     if (is_dir($fullPath)) {
         sendDir($path);
-    } else if (substr($path, -4) == '.url') {
+    } else if ($ext == 'url') {
         require_once 'podcasts.php';
         sendPodcast($path);
         require_once 'podcasts.php';
         sendPodcast($path);
-    } else if (substr($path, -4) == '.txt') {
+    } else if ($ext == 'txt') {
         sendTextFile($path);
         sendTextFile($path);
+    } else if ($ext == 'sh') {
+        sendScript($path);
     } else {
         sendMessage('Unknown file type');
     }
     } else {
         sendMessage('Unknown file type');
     }
@@ -108,17 +111,21 @@ function sendDir($path)
     $count = 0;
     foreach ($entries as $entry) {
         $urlPath = pathEncode(substr($entry, strlen($varDir)));
     $count = 0;
     foreach ($entries as $entry) {
         $urlPath = pathEncode(substr($entry, strlen($varDir)));
+        $ext = pathinfo($entry, PATHINFO_EXTENSION);
         if (is_dir($entry)) {
             ++$count;
             $listItems[] = getDirItem(basename($entry), $urlPath . '/');
         if (is_dir($entry)) {
             ++$count;
             $listItems[] = getDirItem(basename($entry), $urlPath . '/');
-        } else if (substr($entry, -4) == '.url') {
+        } else if ($ext == 'url') {
             //podcast
             ++$count;
             $listItems[] = getPodcastItem(basename($entry, '.url'), $urlPath);
             //podcast
             ++$count;
             $listItems[] = getPodcastItem(basename($entry, '.url'), $urlPath);
-        } else if (substr($entry, -4) == '.txt') {
+        } else if (substr($entry, -8) == '.auto.sh') {
+            //automatically execute script while listing this directory
+            addScriptOutput($listItems, $entry);
+        } else if ($ext == 'txt' || $ext == 'sh') {
             //plain text file
             ++$count;
             //plain text file
             ++$count;
-            $listItems[] = getDirItem(basename($entry, '.txt'), $urlPath);
+            $listItems[] = getDirItem(basename($entry, '.' . $ext), $urlPath);
         }
     }
     if (!$count) {
         }
     }
     if (!$count) {
@@ -127,6 +134,30 @@ function sendDir($path)
     sendListItems($listItems);
 }
 
     sendListItems($listItems);
 }
 
+function sendScript($path)
+{
+    global $varDir;
+
+    $listItems = array();
+    addPreviousItem($listItems, $path);
+
+    $fullPath = $varDir . $path;
+    addScriptOutput($listItems, $fullPath);
+    sendListItems($listItems);
+}
+
+function addScriptOutput(&$listItems, $fullPath)
+{
+    exec($fullPath . ' 2>&1', $output, $retVal);
+
+    if ($retVal == 0) {
+        addTextLines($listItems, $output);
+    } else {
+        $listItems[] = getMessageItem('Error executing script');
+        addTextLines($listItems, $output);
+    }
+}
+
 function sendTextFile($path)
 {
     global $varDir;
 function sendTextFile($path)
 {
     global $varDir;
@@ -134,13 +165,18 @@ function sendTextFile($path)
     addPreviousItem($listItems, $path);
 
     $lines = file($varDir . $path);
     addPreviousItem($listItems, $path);
 
     $lines = file($varDir . $path);
+    addTextLines($listItems, $lines);
+    sendListItems($listItems);
+}
+
+function addTextLines(&$listItems, $lines)
+{
     foreach ($lines as $line) {
         $line = trim($line);
         if ($line != '') {
             $listItems[] = getDisplayItem($line);
         }
     }
     foreach ($lines as $line) {
         $line = trim($line);
         if ($line != '') {
             $listItems[] = getDisplayItem($line);
         }
     }
-    sendListItems($listItems);
 }
 
 function getDisplayItem($line)
 }
 
 function getDisplayItem($line)