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 handleRequestMediatomb($path, 'internetradio/');
45 $fullPath = $varDir . $path;
46 if (!file_exists($fullPath)) {
47 sendMessage('Not found: ' . $path);
51 $ext = pathinfo($path, PATHINFO_EXTENSION);
52 if (is_dir($fullPath)) {
54 } else if ($ext == 'url') {
55 require_once 'podcasts.php';
57 } else if ($ext == 'txt') {
59 } else if ($ext == 'sh') {
62 sendMessage('Unknown file type');
66 function pathEncode($urlPath)
68 return str_replace('%2F', '/', rawurlencode($urlPath));
71 function sendDir($path)
76 addPreviousItem($listItems, $path);
78 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
80 foreach ($entries as $entry) {
81 $urlPath = pathEncode(substr($entry, strlen($varDir)));
82 $ext = pathinfo($entry, PATHINFO_EXTENSION);
84 $titleBase = basename($entry);
85 $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase);
88 $listItems[] = getDirItem($titleBase, $urlPath . '/');
89 } else if ($ext == 'url') {
92 $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
93 } else if (substr($entry, -8) == '.auto.sh') {
94 //automatically execute script while listing this directory
95 addScriptOutput($listItems, $entry);
96 } else if ($ext == 'txt' || $ext == 'sh') {
99 $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
103 $listItems[] = getMessageItem('No files or folders');
105 sendListItems($listItems);
108 function sendScript($path)
112 $listItems = array();
113 addPreviousItem($listItems, $path);
115 $fullPath = $varDir . $path;
116 addScriptOutput($listItems, $fullPath);
117 sendListItems($listItems);
120 function addScriptOutput(&$listItems, $fullPath)
122 exec($fullPath . ' 2>&1', $output, $retVal);
125 addTextLines($listItems, $output);
127 $listItems[] = getMessageItem('Error executing script');
128 addTextLines($listItems, $output);
132 function sendTextFile($path)
135 $listItems = array();
136 addPreviousItem($listItems, $path);
138 $lines = file($varDir . $path);
139 addTextLines($listItems, $lines);
140 sendListItems($listItems);
143 function addTextLines(&$listItems, $lines)
145 foreach ($lines as $line) {
148 $listItems[] = getDisplayItem($line);
153 function getDisplayItem($line)
155 $line = preg_replace('#\s+#', ' ', $line);
157 . '<ItemType>Display</ItemType>'
158 . '<Display>' . utf8_decode(htmlspecialchars($line)) . '</Display>'
162 function getDirItem($title, $urlPath)
164 global $host1, $host2;
166 . '<ItemType>Dir</ItemType>'
167 . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
168 . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
169 . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
173 function getEpisodeItem($title, $fullUrl, $desc, $type)
176 . '<ItemType>ShowEpisode</ItemType>'
177 . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
178 . '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
179 . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
180 . '<ShowMime>' . $type . '</ShowMime>'
184 function getPodcastItem($title, $urlPath)
188 . '<ItemType>ShowOnDemand</ItemType>'
189 . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
190 . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
194 function getMessageItem($msg)
197 . '<ItemType>Message</ItemType>'
198 . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
202 function getPreviousItem($urlPath)
204 global $host1, $host2;
206 . '<ItemType>Previous</ItemType>'
207 . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
208 . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
212 function addPreviousItem(&$listItems, $urlPath)
214 $parentDir = dirname($urlPath) . '/';
215 if ($parentDir == '/') {
218 $listItems[] = getPreviousItem($parentDir);
221 function sendMessage($msg)
223 sendListItems(array(getMessageItem($msg)));
226 function sendListItems($listItems)
230 if (isset($_GET['startitems'])) {
231 $startitems = (int) $_GET['startitems'];
233 if (isset($_GET['enditems'])) {
234 $enditems = (int) $_GET['enditems'];
238 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
239 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
240 $xml .= '<ListOfItems>' . "\n";
241 foreach ($listItems as $item) {
242 $xml .= $item . "\n";
244 $xml .= "</ListOfItems>\n";
246 header('Content-type: text/xml');