function handleRequest($path)
{
global $varDir;
- if (strpos($path, '..') !== false) {
+ if (strpos($path, '/../') !== false) {
sendMessage('No');
return;
}
if (substr($path, 0, 14) == 'internetradio/') {
require_once 'mediatomb.php';
- handleRequestMediatomb($path, 'internetradio/');
+ handleMediatomb('browse', $path, 'internetradio/');
+ return;
+ } else if (substr($path, 0, 11) == '.mt-single/') {
+ require_once 'mediatomb.php';
+ handleMediatomb('single', $path, '.mt-single/');
return;
}
sendPodcast($path);
} else if ($ext == 'txt') {
sendTextFile($path);
- } else if ($ext == 'sh') {
+ } else if (is_executable($fullPath)) {
sendScript($path);
} else {
sendMessage('Unknown file type');
global $varDir;
$listItems = array();
- addPreviousItem($listItems, $path);
+ $enablePaging = true;
$entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
$count = 0;
+ $noCache = false;
foreach ($entries as $entry) {
$urlPath = pathEncode(substr($entry, strlen($varDir)));
$ext = pathinfo($entry, PATHINFO_EXTENSION);
//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') {
+ $enablePaging = false;
+ } else if ($ext == 'txt' || is_executable($entry)) {
//plain text file
++$count;
$listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
+ } else if (basename($entry) == 'nocache') {
+ $noCache = true;
}
}
if (!$count) {
$listItems[] = getMessageItem('No files or folders');
}
- sendListItems($listItems);
+ sendListItems(
+ $listItems, buildPreviousItem($path),
+ $enablePaging, $noCache
+ );
}
function sendScript($path)
global $varDir;
$listItems = array();
- addPreviousItem($listItems, $path);
$fullPath = $varDir . $path;
addScriptOutput($listItems, $fullPath);
- sendListItems($listItems);
+ sendListItems($listItems, buildPreviousItem($path), false);
}
function addScriptOutput(&$listItems, $fullPath)
{
global $varDir;
$listItems = array();
- addPreviousItem($listItems, $path);
$lines = file($varDir . $path);
addTextLines($listItems, $lines);
- sendListItems($listItems);
+ sendListItems($listItems, buildPreviousItem($path));
}
function addTextLines(&$listItems, $lines)
$line = preg_replace('#\s+#', ' ', $line);
return '<Item>'
. '<ItemType>Display</ItemType>'
- . '<Display>' . utf8_decode(htmlspecialchars($line)) . '</Display>'
+ . '<Display>' . nox_esc($line) . '</Display>'
. '</Item>';
}
global $host1, $host2;
return '<Item>'
. '<ItemType>Dir</ItemType>'
- . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
- . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
- . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
+ . '<Title>' . nox_esc($title) . '</Title>'
+ . '<UrlDir>' . $host1 . nox_esc($urlPath) . '</UrlDir>'
+ . '<UrlDirBackUp>' . $host2 . nox_esc($urlPath) . '</UrlDirBackUp>'
. '</Item>';
}
{
return '<Item>'
. '<ItemType>ShowEpisode</ItemType>'
- . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
+ . '<ShowEpisodeName>' . nox_esc($title) . '</ShowEpisodeName>'
. '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
- . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
+ . '<ShowDesc>' . nox_esc($desc) . '</ShowDesc>'
. '<ShowMime>' . $type . '</ShowMime>'
. '</Item>';
}
global $host1;
return '<Item>'
. '<ItemType>ShowOnDemand</ItemType>'
- . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
- . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
+ . '<ShowOnDemandName>' . nox_esc($title) . '</ShowOnDemandName>'
+ . '<ShowOnDemandURL>' . $host1 . nox_esc($urlPath) . '</ShowOnDemandURL>'
. '</Item>';
}
{
return '<Item>'
. '<ItemType>Message</ItemType>'
- . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
+ . '<Message>' . nox_esc($msg) . '</Message>'
. '</Item>';
}
global $host1, $host2;
return '<Item>'
. '<ItemType>Previous</ItemType>'
- . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
- . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
+ . '<UrlPrevious>' . $host1 . nox_esc($urlPath) . '</UrlPrevious>'
+ . '<UrlPreviousBackUp>' . $host1 . nox_esc($urlPath) . '</UrlPreviousBackUp>'
. '</Item>';
}
-function addPreviousItem(&$listItems, $urlPath)
+function buildPreviousItem($urlPath)
{
$parentDir = dirname($urlPath) . '/';
if ($parentDir == '/') {
- return;
+ return null;
}
- $listItems[] = getPreviousItem($parentDir);
+ return getPreviousItem($parentDir);
+}
+
+function nox_esc($string)
+{
+ return utf8_decode(htmlspecialchars($string));
}
function sendMessage($msg)
sendListItems(array(getMessageItem($msg)));
}
-function sendListItems($listItems)
-{
+function sendListItems(
+ $listItems, $previous = null, $enablePaging = true, $noCache = false
+) {
$startitems = 1;
- $enditems = 10;
+ $enditems = 100000;
if (isset($_GET['startitems'])) {
$startitems = (int) $_GET['startitems'];
}
if (isset($_GET['enditems'])) {
$enditems = (int) $_GET['enditems'];
}
- //TODO: limit list
+
+ if ($enablePaging) {
+ $itemCount = count($listItems);
+ } else {
+ $itemCount = -1;
+ }
+ if ($previous !== null) {
+ $previous .= "\n";
+ }
$xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
$xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
$xml .= '<ListOfItems>' . "\n";
+ if ($noCache) {
+ $xml .= "<NoCache>1</NoCache>\n";
+ }
+ $xml .= '<ItemCount>' . $itemCount . '</ItemCount>' . "\n";
+ $xml .= $previous;
+
+ $num = 0;
foreach ($listItems as $item) {
- $xml .= $item . "\n";
+ ++$num;
+ if (!$enablePaging || ($num >= $startitems && $num <= $enditems)) {
+ $xml .= $item . "\n";
+ }
}
$xml .= "</ListOfItems>\n";
- header('Content-type: text/xml');
+ header('Content-type: text/xml; charset=iso-8859-1');
echo $xml;
}
?>