2 require_once __DIR__ . '/../src/header.php';
4 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0'
5 || $fullUri == '/RadioNativeLogin.phpb'
7 //initial login for "internet radio", podcasts and "my noxon"
8 header('Content-type: text/html');
9 readfile($dataDir . 'login-camelcase.xml');
11 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
13 $path = '/internetradio/';
14 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
17 } else if ($path == '/RadioNative.php') {
20 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
21 //Internet Radio Station favorites favorited on device
22 sendMessage('Unsupported');
23 } else if ($path == '/RadioNativeFavorites.php') {
24 //Favorites, defined via web interface
25 sendMessage('Unsupported');
28 handleRequest(ltrim($path, '/'));
30 function handleRequest($path)
33 if (strpos($path, '..') !== false) {
38 if (substr($path, 0, 14) == 'internetradio/') {
39 require_once 'mediatomb.php';
40 handleMediatomb('browse', $path, 'internetradio/');
42 } else if (substr($path, 0, 11) == '.mt-single/') {
43 require_once 'mediatomb.php';
44 handleMediatomb('single', $path, '.mt-single/');
49 $fullPath = $varDir . $path;
50 if (!file_exists($fullPath)) {
51 sendMessage('Not found: ' . $path);
55 $ext = pathinfo($path, PATHINFO_EXTENSION);
56 if (is_dir($fullPath)) {
58 } else if ($ext == 'url') {
59 require_once 'podcasts.php';
61 } else if ($ext == 'txt') {
63 } else if (is_executable($fullPath)) {
66 sendMessage('Unknown file type');
70 function pathEncode($urlPath)
72 return str_replace('%2F', '/', rawurlencode($urlPath));
75 function sendDir($path)
82 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
84 foreach ($entries as $entry) {
85 $urlPath = pathEncode(substr($entry, strlen($varDir)));
86 $ext = pathinfo($entry, PATHINFO_EXTENSION);
88 $titleBase = basename($entry);
89 $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase);
92 $listItems[] = getDirItem($titleBase, $urlPath . '/');
93 } else if ($ext == 'url') {
96 $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
97 } else if (is_executable($entry)
98 && strpos(basename($entry), '.auto') !== false
100 //automatically execute script while listing this directory
101 addScriptOutput($listItems, $entry);
102 $enablePaging = false;
103 } else if ($ext == 'txt' || is_executable($entry)) {
106 $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
110 $listItems[] = getMessageItem('No files or folders');
112 sendListItems($listItems, buildPreviousItem($path), $enablePaging);
115 function sendScript($path)
119 $listItems = array();
121 $fullPath = $varDir . $path;
122 addScriptOutput($listItems, $fullPath);
123 sendListItems($listItems, buildPreviousItem($path), false);
126 function addScriptOutput(&$listItems, $fullPath)
128 exec($fullPath . ' 2>&1', $output, $retVal);
131 addTextLines($listItems, $output);
133 $listItems[] = getMessageItem('Error executing script');
134 addTextLines($listItems, $output);
138 function sendTextFile($path)
141 $listItems = array();
143 $lines = file($varDir . $path);
144 addTextLines($listItems, $lines);
145 sendListItems($listItems, buildPreviousItem($path));
148 function addTextLines(&$listItems, $lines)
150 foreach ($lines as $line) {
153 $listItems[] = getDisplayItem($line);
158 function getDisplayItem($line)
160 $line = preg_replace('#\s+#', ' ', $line);
162 . '<ItemType>Display</ItemType>'
163 . '<Display>' . nox_esc($line) . '</Display>'
167 function getDirItem($title, $urlPath)
169 global $host1, $host2;
171 . '<ItemType>Dir</ItemType>'
172 . '<Title>' . nox_esc($title) . '</Title>'
173 . '<UrlDir>' . $host1 . nox_esc($urlPath) . '</UrlDir>'
174 . '<UrlDirBackUp>' . $host2 . nox_esc($urlPath) . '</UrlDirBackUp>'
178 function getEpisodeItem($title, $fullUrl, $desc, $type)
181 . '<ItemType>ShowEpisode</ItemType>'
182 . '<ShowEpisodeName>' . nox_esc($title) . '</ShowEpisodeName>'
183 . '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
184 . '<ShowDesc>' . nox_esc($desc) . '</ShowDesc>'
185 . '<ShowMime>' . $type . '</ShowMime>'
189 function getPodcastItem($title, $urlPath)
193 . '<ItemType>ShowOnDemand</ItemType>'
194 . '<ShowOnDemandName>' . nox_esc($title) . '</ShowOnDemandName>'
195 . '<ShowOnDemandURL>' . $host1 . nox_esc($urlPath) . '</ShowOnDemandURL>'
199 function getMessageItem($msg)
202 . '<ItemType>Message</ItemType>'
203 . '<Message>' . nox_esc($msg) . '</Message>'
207 function getPreviousItem($urlPath)
209 global $host1, $host2;
211 . '<ItemType>Previous</ItemType>'
212 . '<UrlPrevious>' . $host1 . nox_esc($urlPath) . '</UrlPrevious>'
213 . '<UrlPreviousBackUp>' . $host1 . nox_esc($urlPath) . '</UrlPreviousBackUp>'
217 function buildPreviousItem($urlPath)
219 $parentDir = dirname($urlPath) . '/';
220 if ($parentDir == '/') {
223 return getPreviousItem($parentDir);
226 function nox_esc($string)
228 return utf8_decode(htmlspecialchars($string));
231 function sendMessage($msg)
233 sendListItems(array(getMessageItem($msg)));
236 function sendListItems($listItems, $previous = null, $enablePaging = true)
240 if (isset($_GET['startitems'])) {
241 $startitems = (int) $_GET['startitems'];
243 if (isset($_GET['enditems'])) {
244 $enditems = (int) $_GET['enditems'];
248 $itemCount = count($listItems);
252 if ($previous !== null) {
256 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
257 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
258 $xml .= '<ListOfItems>' . "\n";
259 $xml .= '<ItemCount>' . $itemCount . '</ItemCount>' . "\n";
263 foreach ($listItems as $item) {
265 if (!$enablePaging || ($num >= $startitems && $num <= $enditems)) {
266 $xml .= $item . "\n";
269 $xml .= "</ListOfItems>\n";
271 header('Content-type: text/xml; charset=iso-8859-1');