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 $cacheDir = __DIR__ . '/../www/cache/';
12 $host1 = 'http://radio567.vtuner.com/';
13 $host2 = 'http://radio5672.vtuner.com/';
14 if ($_SERVER['HTTP_HOST'] !== '') {
15 $host1 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
16 $host2 = 'http://' . $_SERVER['HTTP_HOST'] . '/';
18 $cacheDirUrl = $host1 . 'cache/';
19 $cfgFile = $dataDir . 'config.php';
20 if (file_exists($cfgFile)) {
24 if (strtolower($fullUri) == '/setupapp/radio567/asp/browsexpa/loginxml.asp?token=0'
25 || $fullUri == '/RadioNativeLogin.php'
27 //initial login for "internet radio", podcasts and "my noxon"
28 header('Content-type: text/html');
29 readfile($dataDir . 'login-camelcase.xml');
31 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/LoginXML.asp') {
33 $path = '/internetradio/';
34 } else if ($path == '/setupapp/radio567/asp/BrowseXPA/navXML.asp') {
37 } else if ($path == '/RadioNative.php') {
40 } else if ($path == '/setupapp/radio567/asp/BrowseXML/FavXML.asp') {
41 //Internet Radio Station favorites favorited on device
42 sendMessage('Unsupported');
43 } else if ($path == '/RadioNativeFavorites.php') {
44 //Favorites, defined via web interface
45 sendMessage('Unsupported');
46 } else if ($path == '/transcode') {
47 require_once 'mediatomb.php';
48 transcodeMediatombItem($_GET['mtParentId'], $_GET['mtItemTitle']);
52 handleRequest(ltrim($path, '/'));
54 function handleRequest($path)
57 if (strpos($path, '..') !== false) {
62 if (substr($path, 0, 14) == 'internetradio/') {
63 require_once 'mediatomb.php';
64 handleRequestMediatomb($path, 'internetradio/');
69 $fullPath = $varDir . $path;
70 if (!file_exists($fullPath)) {
71 sendMessage('Not found: ' . $path);
75 $ext = pathinfo($path, PATHINFO_EXTENSION);
76 if (is_dir($fullPath)) {
78 } else if ($ext == 'url') {
79 require_once 'podcasts.php';
81 } else if ($ext == 'txt') {
83 } else if ($ext == 'sh') {
86 sendMessage('Unknown file type');
90 function pathEncode($urlPath)
92 return str_replace('%2F', '/', rawurlencode($urlPath));
95 function sendDir($path)
100 addPreviousItem($listItems, $path);
102 $entries = glob(str_replace('//', '/', $varDir . rtrim($path, '/') . '/*'));
104 foreach ($entries as $entry) {
105 $urlPath = pathEncode(substr($entry, strlen($varDir)));
106 $ext = pathinfo($entry, PATHINFO_EXTENSION);
108 $titleBase = basename($entry);
109 $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase);
110 if (is_dir($entry)) {
112 $listItems[] = getDirItem($titleBase, $urlPath . '/');
113 } else if ($ext == 'url') {
116 $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath);
117 } else if (substr($entry, -8) == '.auto.sh') {
118 //automatically execute script while listing this directory
119 addScriptOutput($listItems, $entry);
120 } else if ($ext == 'txt' || $ext == 'sh') {
123 $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath);
127 $listItems[] = getMessageItem('No files or folders');
129 sendListItems($listItems);
132 function sendScript($path)
136 $listItems = array();
137 addPreviousItem($listItems, $path);
139 $fullPath = $varDir . $path;
140 addScriptOutput($listItems, $fullPath);
141 sendListItems($listItems);
144 function addScriptOutput(&$listItems, $fullPath)
146 exec($fullPath . ' 2>&1', $output, $retVal);
149 addTextLines($listItems, $output);
151 $listItems[] = getMessageItem('Error executing script');
152 addTextLines($listItems, $output);
156 function sendTextFile($path)
159 $listItems = array();
160 addPreviousItem($listItems, $path);
162 $lines = file($varDir . $path);
163 addTextLines($listItems, $lines);
164 sendListItems($listItems);
167 function addTextLines(&$listItems, $lines)
169 foreach ($lines as $line) {
172 $listItems[] = getDisplayItem($line);
177 function getDisplayItem($line)
179 $line = preg_replace('#\s+#', ' ', $line);
181 . '<ItemType>Display</ItemType>'
182 . '<Display>' . utf8_decode(htmlspecialchars($line)) . '</Display>'
186 function getDirItem($title, $urlPath)
188 global $host1, $host2;
190 . '<ItemType>Dir</ItemType>'
191 . '<Title>' . utf8_decode(htmlspecialchars($title)) . '</Title>'
192 . '<UrlDir>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDir>'
193 . '<UrlDirBackUp>' . $host2 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlDirBackUp>'
197 function getEpisodeItem($title, $fullUrl, $desc, $type)
200 . '<ItemType>ShowEpisode</ItemType>'
201 . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
202 . '<ShowEpisodeURL>' . htmlspecialchars($fullUrl) . '</ShowEpisodeURL>'
203 . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
204 . '<ShowMime>' . $type . '</ShowMime>'
208 function getPodcastItem($title, $urlPath)
212 . '<ItemType>ShowOnDemand</ItemType>'
213 . '<ShowOnDemandName>' . utf8_decode(htmlspecialchars($title)) . '</ShowOnDemandName>'
214 . '<ShowOnDemandURL>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</ShowOnDemandURL>'
218 function getMessageItem($msg)
221 . '<ItemType>Message</ItemType>'
222 . '<Message>' . utf8_decode(htmlspecialchars($msg)) . '</Message>'
226 function getPreviousItem($urlPath)
228 global $host1, $host2;
230 . '<ItemType>Previous</ItemType>'
231 . '<UrlPrevious>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPrevious>'
232 . '<UrlPreviousBackUp>' . $host1 . utf8_decode(htmlspecialchars($urlPath)) . '</UrlPreviousBackUp>'
236 function addPreviousItem(&$listItems, $urlPath)
238 $parentDir = dirname($urlPath) . '/';
239 if ($parentDir == '/') {
242 $listItems[] = getPreviousItem($parentDir);
245 function sendMessage($msg)
247 sendListItems(array(getMessageItem($msg)));
250 function sendListItems($listItems)
254 if (isset($_GET['startitems'])) {
255 $startitems = (int) $_GET['startitems'];
257 if (isset($_GET['enditems'])) {
258 $enditems = (int) $_GET['enditems'];
262 $xml = '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
263 $xml .= '<?xml-stylesheet type="text/xsl" href="/html.xsl"?>' . "\n";
264 $xml .= '<ListOfItems>' . "\n";
265 foreach ($listItems as $item) {
266 $xml .= $item . "\n";
268 $xml .= "</ListOfItems>\n";
270 header('Content-type: text/xml');