From fce747789cee5d914545ddaa7aa8d0653955a2fe Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 1 Dec 2015 17:22:54 +0100 Subject: [PATCH] Use file executable bit for script detection. This allows scripts to be written in any language. --- README.rst | 26 +++++++++++++------------- www/index.php | 8 +++++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index dbfe3b5..11bac20 100644 --- a/README.rst +++ b/README.rst @@ -132,26 +132,26 @@ 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. + 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. +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. diff --git a/www/index.php b/www/index.php index d9b53f1..1670931 100644 --- a/www/index.php +++ b/www/index.php @@ -60,7 +60,7 @@ function handleRequest($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'); @@ -94,10 +94,12 @@ function sendDir($path) //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); - } else if ($ext == 'txt' || $ext == 'sh') { + } else if ($ext == 'txt' || is_executable($entry)) { //plain text file ++$count; $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath); -- 2.30.2