X-Git-Url: https://git.cweiske.de/noxon-gateway.git/blobdiff_plain/affe79e23a8b656a343064d1f4f02bee870cfd54..4233101d0f4a9ce02d399e98ea97ceade9ce42a5:/www/index.php diff --git a/www/index.php b/www/index.php index 4db5f2e..8b803db 100644 --- a/www/index.php +++ b/www/index.php @@ -19,17 +19,12 @@ if (file_exists($cfgFile)) { include $cfgFile; } -if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0') { - //initial login for "internet radio" and podcasts - //lowercase tags +if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0' + || $fullUri == '/RadioNativeLogin.php' +) { + //initial login for "internet radio", podcasts and "my noxon" header('Content-type: text/html'); - readfile($dataDir . 'initial-login.xml'); - exit(); -} else if ($fullUri == '/RadioNativeLogin.php') { - //initial login for "My noxon" - //this one wants CamelCased tags - header('Content-type: text/html'); - readfile($dataDir . 'login-mynoxon.xml'); + readfile($dataDir . 'login-camelcase.xml'); exit(); } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') { //"Internet Radio" @@ -79,18 +74,26 @@ function handleRequest($path) return; } + $ext = pathinfo($path, PATHINFO_EXTENSION); if (is_dir($fullPath)) { sendDir($path); - } else if (substr($path, -4) == '.url') { + } else if ($ext == 'url') { require_once 'podcasts.php'; sendPodcast($path); - } else if (substr($path, -4) == '.txt') { + } else if ($ext == 'txt') { sendTextFile($path); + } else if ($ext == 'sh') { + sendScript($path); } else { sendMessage('Unknown file type'); } } +function pathEncode($urlPath) +{ + return str_replace('%2F', '/', rawurlencode($urlPath)); +} + function sendDir($path) { global $varDir; @@ -101,18 +104,25 @@ function sendDir($path) $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*')); $count = 0; foreach ($entries as $entry) { - $urlPath = substr($entry, strlen($varDir)); + $urlPath = pathEncode(substr($entry, strlen($varDir))); + $ext = pathinfo($entry, PATHINFO_EXTENSION); + + $titleBase = basename($entry); + $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase); if (is_dir($entry)) { ++$count; - $listItems[] = getDirItem(basename($entry), $urlPath . '/'); - } else if (substr($entry, -4) == '.url') { + $listItems[] = getDirItem($titleBase, $urlPath . '/'); + } else if ($ext == 'url') { //podcast ++$count; - $listItems[] = getPodcastItem(basename($entry, '.url'), $urlPath); - } else if (substr($entry, -4) == '.txt') { + $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath); + } 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; - $listItems[] = getDirItem(basename($entry, '.txt'), $urlPath); + $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath); } } if (!$count) { @@ -121,6 +131,30 @@ function sendDir($path) 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; @@ -128,17 +162,26 @@ function sendTextFile($path) addPreviousItem($listItems, $path); $lines = file($varDir . $path); + addTextLines($listItems, $lines); + sendListItems($listItems); +} + +function addTextLines(&$listItems, $lines) +{ foreach ($lines as $line) { - $listItems[] = getDisplayItem($line); + $line = trim($line); + if ($line != '') { + $listItems[] = getDisplayItem($line); + } } - sendListItems($listItems); } function getDisplayItem($line) { + $line = preg_replace('#\s+#', ' ', $line); return '' . 'Display' - . '' . utf8_decode(htmlspecialchars(trim($line))) . '' + . '' . utf8_decode(htmlspecialchars($line)) . '' . ''; }