2 set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/../src/');
3 $fullUri = $_SERVER['REQUEST_URI'];
4 if (isset($_SERVER['REDIRECT_URL'])) {
5 $path = $_SERVER['REDIRECT_URL'];
9 $dataDir = __DIR__ . '/../data/';
10 $varDir = realpath(__DIR__ . '/../var') . '/';
11 $host1 = 'http://radio567.vtuner.com/';
12 $host2 = 'http://radio5672.vtuner.com/';
13 if ($_SERVER['HTTP_HOST'] !== '') {
14 $host1 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
15 $host2 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
17 $cfgFile = $dataDir . 'config.php';
18 if (file_exists($cfgFile)) {
22 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0'
23 || $fullUri == '/RadioNativeLogin.php'
25 //initial login for "internet radio", podcasts and "my noxon"
26 header('Content-type: text/html');
27 readfile($dataDir . 'login-camelcase.xml');
29 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
31 $path = '/internetradio/';
32 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
35 } else if ($path == '/RadioNative.php') {
38 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
39 //Internet Radio Station favorites favorited on device
40 sendMessage('Unsupported');
41 } else if ($path == '/RadioNativeFavorites.php') {
42 //Favorites, defined via web interface
43 sendMessage('Unsupported');
46 handleRequest(ltrim($path, '/'));
48 function handleRequest($path)
51 if (strpos($path, '..') !== false) {
56 if (substr($path, 0, 14) == 'internetradio/') {
57 require_once 'mediatomb.php';
58 handleRequestMediatomb($path, 'internetradio/');
63 $fullPath = $varDir . $path;
64 if (!file_exists($fullPath)) {
65 sendMessage('Not found: ' . $path);
69 $ext = pathinfo($path, PATHINFO_EXTENSION);
70 if (is_dir($fullPath)) {
72 } else if ($ext == 'url') {
73 require_once 'podcasts.php';
75 } else if ($ext == 'txt') {
77 } else if ($ext == 'sh') {
80 sendMessage('Unknown file type');
84 function pathEncode($urlPath)
86 return str_replace('%2F', '/', rawurlencode($urlPath));
89 function sendDir($path)
94 addPreviousItem($listItems, $path);
96 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
98 foreach ($entries as $entry) {
99 $urlPath = pathEncode(substr($entry, strlen($varDir)));
100 $ext = pathinfo($entry, PATHINFO_EXTENSION);
102 $titleBase = basename($entry);
103 $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase);
104 if (is_dir($entry)) {
106 $listItems[] = getDirItem($titleBase, $urlPath . '/');
107 } else if ($ext == 'url') {
110 $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
111 } else if (substr($entry, -8) == '.auto.sh') {
112 //automatically execute script while listing this directory
113 addScriptOutput($listItems, $entry);
114 } else if ($ext == 'txt' || $ext == 'sh') {
117 $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
121 $listItems[] = getMessageItem('No files or folders');
123 sendListItems($listItems);
126 function sendScript($path)
130 $listItems = array();
131 addPreviousItem($listItems, $path);
133 $fullPath = $varDir . $path;
134 addScriptOutput($listItems, $fullPath);
135 sendListItems($listItems);
138 function addScriptOutput(&$listItems, $fullPath)
140 exec($fullPath . ' 2>&1', $output, $retVal);
143 addTextLines($listItems, $output);
145 $listItems[] = getMessageItem('Error executing script');
146 addTextLines($listItems, $output);
150 function sendTextFile($path)
153 $listItems = array();
154 addPreviousItem($listItems, $path);
156 $lines = file($varDir . $path);
157 addTextLines($listItems, $lines);
158 sendListItems($listItems);
161 function addTextLines(&$listItems, $lines)
163 foreach ($lines as $line) {
166 $listItems[] = getDisplayItem($line);
171 function getDisplayItem($line)
173 $line = preg_replace('#\s+#', ' ', $line);
175 . '<ItemType>Display</ItemType>'
176 . '<Display>' . utf8_decode(htmlspecialchars($line)) . '</Display>'
180 function getDirItem($title, $urlPath)
182 global $host1, $host2;
184 . '<ItemType>Dir</ItemType>'
185 . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
186 . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
187 . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
191 function getEpisodeItem($title, $fullUrl, $desc, $type)
194 . '<ItemType>ShowEpisode</ItemType>'
195 . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
196 . '<ShowEpisodeURL>' . $fullUrl . '</ShowEpisodeURL>'
197 . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
198 . '<ShowMime>' . $type . '</ShowMime>'
202 function getPodcastItem($title, $urlPath)
206 . '<ItemType>ShowOnDemand</ItemType>'
207 . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
208 . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
212 function getMessageItem($msg)
215 . '<ItemType>Message</ItemType>'
216 . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
220 function getPreviousItem($urlPath)
222 global $host1, $host2;
224 . '<ItemType>Previous</ItemType>'
225 . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
226 . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
230 function addPreviousItem(&$listItems, $urlPath)
232 $parentDir = dirname($urlPath) . '/';
233 if ($parentDir == '/') {
236 $listItems[] = getPreviousItem($parentDir);
239 function sendMessage($msg)
241 sendListItems(array(getMessageItem($msg)));
244 function sendListItems($listItems)
248 if (isset($_GET['startitems'])) {
249 $startitems = (int) $_GET['startitems'];
251 if (isset($_GET['enditems'])) {
252 $enditems = (int) $_GET['enditems'];
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 foreach ($listItems as $item) {
260 $xml .= $item . "\n";
262 $xml .= "</ListOfItems>\n";
264 header('Content-type: text/xml');