Use file executable bit for script detection.
authorChristian Weiske <cweiske@cweiske.de>
Tue, 1 Dec 2015 16:22:54 +0000 (17:22 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 1 Dec 2015 16:23:00 +0000 (17:23 +0100)
This allows scripts to be written in any language.

README.rst
www/index.php

index dbfe3b52f8912ce033cb3b63c9e70b2f1ded91ea..11bac20fe271c040f9fa9d571e91771a70c4964f 100644 (file)
@@ -132,26 +132,26 @@ File types
 ==========
 Directory
   A directory is browsable by your Noxon radio
 ==========
 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
 ``.txt`` file
-  Text files are rendered as un-actionable lists.
+  Text files are rendered as un-actionable lists, one list item per line.
 
   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.
 
   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.
+executable file
+  Script is shown as directory and 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*`` (executable)
+  Script 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.
 
 File extensions get removed for display purposes.
 
 
 File extensions get removed for display purposes.
 
index d9b53f1e5677acdc6d20e089f3c2ba775dc4dbe2..1670931256fb90df76956f3b46b181dae5b9503c 100644 (file)
@@ -60,7 +60,7 @@ function handleRequest($path)
         sendPodcast($path);
     } else if ($ext == 'txt') {
         sendTextFile($path);
         sendPodcast($path);
     } else if ($ext == 'txt') {
         sendTextFile($path);
-    } else if ($ext == 'sh') {
+    } else if (is_executable($fullPath)) {
         sendScript($path);
     } else {
         sendMessage('Unknown file type');
         sendScript($path);
     } else {
         sendMessage('Unknown file type');
@@ -94,10 +94,12 @@ function sendDir($path)
             //podcast
             ++$count;
             $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
             //podcast
             ++$count;
             $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
-        } else if (substr($entry, -8) == '.auto.sh') {
+        } else if (is_executable($entry)
+            && strpos(basename($entry), '.auto') !== false
+        ) {
             //automatically execute script while listing this directory
             addScriptOutput($listItems, $entry);
             //automatically execute script while listing this directory
             addScriptOutput($listItems, $entry);
-        } else if ($ext == 'txt' || $ext == 'sh') {
+        } else if ($ext == 'txt' || is_executable($entry)) {
             //plain text file
             ++$count;
             $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
             //plain text file
             ++$count;
             $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);