2 require_once __DIR__ . '/../src/header.php';
4 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0'
5 || $fullUri == '/RadioNativeLogin.php'
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 ($ext == 'sh') {
66 sendMessage('Unknown file type');
70 function pathEncode($urlPath)
72 return str_replace('%2F', '/', rawurlencode($urlPath));
75 function sendDir($path)
80 addPreviousItem($listItems, $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 (substr($entry, -8) == '.auto.sh') {
98 //automatically execute script while listing this directory
99 addScriptOutput($listItems, $entry);
100 } else if ($ext == 'txt' || $ext == 'sh') {
103 $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
107 $listItems[] = getMessageItem('No files or folders');
109 sendListItems($listItems);
112 function sendScript($path)
116 $listItems = array();
117 addPreviousItem($listItems, $path);
119 $fullPath = $varDir . $path;
120 addScriptOutput($listItems, $fullPath);
121 sendListItems($listItems);
124 function addScriptOutput(&$listItems, $fullPath)
126 exec($fullPath . ' 2>&1', $output, $retVal);
129 addTextLines($listItems, $output);
131 $listItems[] = getMessageItem('Error executing script');
132 addTextLines($listItems, $output);
136 function sendTextFile($path)
139 $listItems = array();
140 addPreviousItem($listItems, $path);
142 $lines = file($varDir . $path);
143 addTextLines($listItems, $lines);
144 sendListItems($listItems);
147 function addTextLines(&$listItems, $lines)
149 foreach ($lines as $line) {
152 $listItems[] = getDisplayItem($line);
157 function getDisplayItem($line)
159 $line = preg_replace('#\s+#', ' ', $line);
161 . '<ItemType>Display</ItemType>'
162 . '<Display>' . utf8_decode(htmlspecialchars($line)) . '</Display>'
166 function getDirItem($title, $urlPath)
168 global $host1, $host2;
170 . '<ItemType>Dir</ItemType>'
171 . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
172 . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
173 . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
177 function getEpisodeItem($title, $fullUrl, $desc, $type)
180 . '<ItemType>ShowEpisode</ItemType>'
181 . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
182 . '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
183 . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
184 . '<ShowMime>' . $type . '</ShowMime>'
188 function getPodcastItem($title, $urlPath)
192 . '<ItemType>ShowOnDemand</ItemType>'
193 . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
194 . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
198 function getMessageItem($msg)
201 . '<ItemType>Message</ItemType>'
202 . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
206 function getPreviousItem($urlPath)
208 global $host1, $host2;
210 . '<ItemType>Previous</ItemType>'
211 . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
212 . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
216 function addPreviousItem(&$listItems, $urlPath)
218 $parentDir = dirname($urlPath) . '/';
219 if ($parentDir == '/') {
222 $listItems[] = getPreviousItem($parentDir);
225 function sendMessage($msg)
227 sendListItems(array(getMessageItem($msg)));
230 function sendListItems($listItems)
234 if (isset($_GET['startitems'])) {
235 $startitems = (int) $_GET['startitems'];
237 if (isset($_GET['enditems'])) {
238 $enditems = (int) $_GET['enditems'];
242 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
243 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
244 $xml .= '<ListOfItems>' . "\n";
245 foreach ($listItems as $item) {
246 $xml .= $item . "\n";
248 $xml .= "</ListOfItems>\n";
250 header('Content-type: text/xml; charset=iso-8859-1');