1 |
<?php |
---|
2 |
|
---|
3 |
// Debugging helpers |
---|
4 |
/* ini_set("display_errors", "on"); |
---|
5 |
ini_set("display_startup_errors", "on"); |
---|
6 |
set_time_limit(0); |
---|
7 |
// error_reporting(E_ALL ^ E_NOTICE) ; |
---|
8 |
error_reporting(E_ALL); |
---|
9 |
*/ |
---|
10 |
|
---|
11 |
// Compatibility functions for php 5.1.2 which doesn't support AddChild etc. |
---|
12 |
function simplexml_addChild($parent, $name, $value=''){ |
---|
13 |
$new_child = new SimpleXMLElement("<$name>$value</$name>"); |
---|
14 |
$node1 = dom_import_simplexml($parent); |
---|
15 |
$dom_sxe = dom_import_simplexml($new_child); |
---|
16 |
$node2 = $node1->ownerDocument->importNode($dom_sxe, true); |
---|
17 |
$node1->appendChild($node2); |
---|
18 |
return simplexml_import_dom($node2); |
---|
19 |
} |
---|
20 |
|
---|
21 |
|
---|
22 |
function simplexml_addAttribute($parent, $name, $value=''){ |
---|
23 |
$node1 = dom_import_simplexml($parent); |
---|
24 |
$node1->setAttribute($name,$value); |
---|
25 |
return simplexml_import_dom($node1); |
---|
26 |
} |
---|
27 |
|
---|
28 |
function write_mt_config($xml) { |
---|
29 |
global $mt_config; |
---|
30 |
|
---|
31 |
// Import into DOM as this allows for PrettyPrinting |
---|
32 |
$dom = new DOMDocument(); |
---|
33 |
$dom->preserveWhiteSpace = false; |
---|
34 |
$dom->loadXML($xml->asXML()); |
---|
35 |
$dom->formatOutput = true; |
---|
36 |
$dom->save($mt_config); |
---|
37 |
// echo "<pre>".htmlentities($dom->saveXML())."</pre>"; |
---|
38 |
} |
---|
39 |
|
---|
40 |
function restart_mt_server() { |
---|
41 |
shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc stop"); |
---|
42 |
shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc start"); |
---|
43 |
} |
---|
44 |
|
---|
45 |
require_once('/img/www/inc/db.class.php'); |
---|
46 |
|
---|
47 |
// retrieve the configuration status of the shipped DLNA_server |
---|
48 |
$dbtool=new dbtool(); |
---|
49 |
$dbtool->connect(); |
---|
50 |
$DLNA_server=$dbtool->db_getvar("DLNA_server","0"); |
---|
51 |
$bonding=$dbtool->db_getvar("nic1_mode_8023ad","none"); |
---|
52 |
$dbtool->db_close(); |
---|
53 |
|
---|
54 |
// Load the MediaTomb XML config |
---|
55 |
$mt_config = '/raid/data/module/MEDIATOMB/system/etc/config.xml'; |
---|
56 |
$xml = simplexml_load_file($mt_config); |
---|
57 |
|
---|
58 |
// Get the interface from the MT config |
---|
59 |
$interface = (string)$xml->server->interface; |
---|
60 |
|
---|
61 |
// Fixup incorrect network settings, e.g. bonding enabled but MT listening somewhere else. |
---|
62 |
if ($bonding != 'none' && $interface != 'bond0') { |
---|
63 |
$interface = 'bond0'; |
---|
64 |
$xml->server->interface = $interface; |
---|
65 |
write_mt_config($xml); |
---|
66 |
restart_mt_server(); |
---|
67 |
} else if ($bonding == 'none' && $interface == 'bond0') { |
---|
68 |
$interface = 'eth0'; |
---|
69 |
$xml->server->interface = $interface; |
---|
70 |
write_mt_config($xml); |
---|
71 |
restart_mt_server(); |
---|
72 |
} |
---|
73 |
|
---|
74 |
// Get the list of available shares from the samba config |
---|
75 |
$fh = fopen("/etc/samba/smb.conf", "r"); |
---|
76 |
$contents = fread($fh, filesize("/etc/samba/smb.conf")); |
---|
77 |
fclose($fh); |
---|
78 |
preg_match_all("/\[([^\]]*)\]\s*comment = ([^\n]*)[^\[]*guest only = ([^\n]*)[^\[]*path = ([^\n]*)/",$contents,$shares); |
---|
79 |
|
---|
80 |
$share_blacklist = array("nsync", "usbhdd", "usbcopy"); |
---|
81 |
|
---|
82 |
$mt_share_list = array(); |
---|
83 |
// Get the list of exported shares from the mediatomb xml config |
---|
84 |
foreach ($xml->import->autoscan->directory as $elem) { |
---|
85 |
$mt_share_list[] = (string)$elem['location']; |
---|
86 |
} |
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 |
// We're seeing a request. Handle it. |
---|
91 |
if (array_key_exists('action', $_POST)) { |
---|
92 |
if (!array_key_exists('shared', $_POST)) { |
---|
93 |
$_POST['shared'] = array(); |
---|
94 |
} |
---|
95 |
|
---|
96 |
// Find the shares not currently shared but requested |
---|
97 |
$add = (array_diff($_POST['shared'], $mt_share_list)); |
---|
98 |
// Find the shares not currently shared but requested |
---|
99 |
$del = (array_diff($mt_share_list, $_POST['shared'])); |
---|
100 |
|
---|
101 |
foreach ($add as $dir) { |
---|
102 |
print '<p>Adding '.$dir.'</p>'; |
---|
103 |
$directory = simplexml_addChild($xml->import->autoscan, 'directory'); |
---|
104 |
simplexml_addAttribute($directory, 'location', $dir); |
---|
105 |
// inotify is not supported on the current thecus kernel |
---|
106 |
// simplexml_addAttribute($directory, 'mode', 'inotify'); |
---|
107 |
simplexml_addAttribute($directory, 'mode', 'timed'); |
---|
108 |
simplexml_addAttribute($directory, 'interval', '3600'); |
---|
109 |
simplexml_addAttribute($directory, 'level', 'basic'); |
---|
110 |
simplexml_addAttribute($directory, 'recursive', 'yes'); |
---|
111 |
simplexml_addAttribute($directory, 'hidden-files', 'no'); |
---|
112 |
} |
---|
113 |
|
---|
114 |
|
---|
115 |
// Outer loop is a workaround for an early break as content is changing. |
---|
116 |
for ($i=0; $i < count($del); $i++) { |
---|
117 |
foreach ($xml->import->autoscan->directory as $dir) { |
---|
118 |
if (in_array((string)$dir['location'], $del)) { |
---|
119 |
print '<p>Removing '.(string)$dir['location'].'</p>'; |
---|
120 |
$oNode = dom_import_simplexml($dir); |
---|
121 |
$oNode->parentNode->removeChild($oNode); |
---|
122 |
|
---|
123 |
// Remove the deleted stuff from the sqlite db. Have to shellexec this here as php has no |
---|
124 |
// support for sqlite3 |
---|
125 |
$cmd = 'LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/raid/data/module/MEDIATOMB/system/lib/"'; |
---|
126 |
$cmd .= ' /raid/data/module/MEDIATOMB/system/bin/sqlite3'; |
---|
127 |
$cmd .= ' /raid/data/module/MEDIATOMB/system/var/mediatomb/mediatomb.db'; |
---|
128 |
$cmd .= ' "DELETE FROM mt_cds_object |
---|
129 |
WHERE |
---|
130 |
location LIKE \'F'.(string)$dir['location'].'/%\' |
---|
131 |
OR |
---|
132 |
location LIKE \'D'.(string)$dir['location'].'/%\' |
---|
133 |
OR |
---|
134 |
location LIKE \'D'.(string)$dir['location'].'\' |
---|
135 |
;"'; |
---|
136 |
|
---|
137 |
shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc stop"); |
---|
138 |
shell_exec($cmd); |
---|
139 |
shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc start"); |
---|
140 |
} |
---|
141 |
} |
---|
142 |
} |
---|
143 |
|
---|
144 |
if (array_key_exists('interface', $_POST)) { |
---|
145 |
$interface = $_POST['interface']; |
---|
146 |
$xml->server->interface = $interface; |
---|
147 |
} |
---|
148 |
|
---|
149 |
write_mt_config($xml); |
---|
150 |
restart_mt_server(); |
---|
151 |
|
---|
152 |
// File was modified, reload |
---|
153 |
$xml = simplexml_load_file($mt_config); |
---|
154 |
$mt_share_list = array(); |
---|
155 |
// Get the list of exported shares from the mediatomb xml config |
---|
156 |
foreach ($xml->import->autoscan->directory as $elem) { |
---|
157 |
$mt_share_list[] = (string)$elem['location']; |
---|
158 |
} |
---|
159 |
} |
---|
160 |
|
---|
161 |
|
---|
162 |
print ' |
---|
163 |
<div class="block_03"> |
---|
164 |
<table border=0 cellspacing=0 cellpadding=0 width="98%"> |
---|
165 |
<tr> |
---|
166 |
<td> |
---|
167 |
<table width="98%" border="1" cellpadding="0" cellspacing="0"> |
---|
168 |
<tr> |
---|
169 |
<td colspan="3"> |
---|
170 |
<div class="step"> |
---|
171 |
<div class="step_ar"> |
---|
172 |
<table width="95%" border="0" cellpadding="0" cellspacing="0"> |
---|
173 |
<tr> |
---|
174 |
<td width="70%"> |
---|
175 |
<div class="step_title"><nobr>Mediatomb - Free UPnP MediaServer</nobr></div> |
---|
176 |
</td> |
---|
177 |
<td width="30%" align="right"><img src="/modules/MEDIATOMB/www/mediatomb.png" ></td> |
---|
178 |
</tr> |
---|
179 |
</table> |
---|
180 |
</div> |
---|
181 |
</div> |
---|
182 |
</td> |
---|
183 |
</tr> |
---|
184 |
</table> |
---|
185 |
</td> |
---|
186 |
</tr> |
---|
187 |
<tr> |
---|
188 |
<td></td> |
---|
189 |
</tr> |
---|
190 |
</table> |
---|
191 |
</div> |
---|
192 |
'; |
---|
193 |
|
---|
194 |
if ($DLNA_server == 1) { |
---|
195 |
print ' |
---|
196 |
<table width="98%" border="0" cellpadding="0" cellspacing="0"> |
---|
197 |
<tr> |
---|
198 |
<td height="72"> |
---|
199 |
<p>The internal Mediabolic DLNA server is currently enabled.</p> |
---|
200 |
<p>Please disable it first through the <a href="/adm/getform.html?name=DLNA">Network/Media Server menu</a>.</p> |
---|
201 |
</td> |
---|
202 |
</tr> |
---|
203 |
</table> |
---|
204 |
'; |
---|
205 |
|
---|
206 |
} else { |
---|
207 |
|
---|
208 |
print ' |
---|
209 |
<form name="mediatombform" method="post"> |
---|
210 |
<table width="98%" border="0" cellpadding="0" cellspacing="0"> |
---|
211 |
<tr> |
---|
212 |
<td height="72"> |
---|
213 |
<table width="98%" border="0"> |
---|
214 |
<tr> |
---|
215 |
<td colspan="3"> |
---|
216 |
<div class="step"> |
---|
217 |
<div class="step_ar"> |
---|
218 |
<table width="50%" border="0" cellpadding="0" cellspacing="0"> |
---|
219 |
<tr> |
---|
220 |
<td width="377" height="13"><div class="step_title">Shared Media Folders</div></td> |
---|
221 |
</tr> |
---|
222 |
</table> |
---|
223 |
</div> |
---|
224 |
</div> |
---|
225 |
</td> |
---|
226 |
</tr> |
---|
227 |
'; |
---|
228 |
|
---|
229 |
for ($i=0; $i < count($shares[0]); $i++) { |
---|
230 |
if (!in_array($shares[1][$i], $share_blacklist)) { |
---|
231 |
print '<tr>'."\n"; |
---|
232 |
print '<td width="5%" style="text-align: center;">'; |
---|
233 |
if (in_array($shares[4][$i], $mt_share_list)) { |
---|
234 |
print '<input type="checkbox" name="shared[]" value="'.$shares[4][$i].'" checked="checked" /></td>'."\n"; |
---|
235 |
} else { |
---|
236 |
print '<input type="checkbox" name="shared[]" value="'.$shares[4][$i].'" /></td>'."\n"; |
---|
237 |
} |
---|
238 |
|
---|
239 |
print '<td width="35%">'.$shares[1][$i].'</td>'."\n"; |
---|
240 |
print '<td width="6a0%">'.$shares[2][$i].'</td>'."\n"; |
---|
241 |
print '</tr>'."\n"; |
---|
242 |
} |
---|
243 |
} |
---|
244 |
|
---|
245 |
print ' </table> |
---|
246 |
</td> |
---|
247 |
</tr> |
---|
248 |
</table> |
---|
249 |
'; |
---|
250 |
|
---|
251 |
|
---|
252 |
print ' |
---|
253 |
<table width="98%" border="0" cellpadding="0" cellspacing="0"> |
---|
254 |
<tr> |
---|
255 |
<td height="72"> |
---|
256 |
<table width="98%" border="0"> |
---|
257 |
<tr> |
---|
258 |
<td colspan="3"> |
---|
259 |
<div class="step"> |
---|
260 |
<div class="step_ar"> |
---|
261 |
<table width="50%" border="0" cellpadding="0" cellspacing="0"> |
---|
262 |
<tr> |
---|
263 |
<td width="377" height="13"><div class="step_title">System settings</div></td> |
---|
264 |
</tr> |
---|
265 |
</table> |
---|
266 |
</div> |
---|
267 |
</div> |
---|
268 |
</td> |
---|
269 |
</tr>'; |
---|
270 |
|
---|
271 |
|
---|
272 |
|
---|
273 |
print ' <tr> |
---|
274 |
<td>Network Interface: </td> |
---|
275 |
<td> |
---|
276 |
<select name="interface" size="1"'; |
---|
277 |
if ($bonding != "none") { |
---|
278 |
print 'disabled="disabled"'; |
---|
279 |
} |
---|
280 |
|
---|
281 |
print '>'."\n"; |
---|
282 |
|
---|
283 |
if ($interface == "eth0") { |
---|
284 |
print ' <option value="eth0" selected="selected">WAN</option> |
---|
285 |
<option value="eth1">LAN</option> |
---|
286 |
'; |
---|
287 |
} else if ($interface == "eth1") { |
---|
288 |
print ' <option value="eth0">WAN</option> |
---|
289 |
<option value="eth1" selected="selected">LAN</option> |
---|
290 |
'; |
---|
291 |
|
---|
292 |
} |
---|
293 |
|
---|
294 |
if ($bonding != "none") { |
---|
295 |
print ' <option selected="selected" value="bond0">Link aggregated</option> |
---|
296 |
'; |
---|
297 |
} |
---|
298 |
|
---|
299 |
|
---|
300 |
print ' </select> |
---|
301 |
</td> |
---|
302 |
</tr> |
---|
303 |
'; |
---|
304 |
|
---|
305 |
/* |
---|
306 |
|
---|
307 |
if ((string)$xml->server->ui['enabled'] == "yes") { |
---|
308 |
$webui = true; |
---|
309 |
} else { |
---|
310 |
$webui = false; |
---|
311 |
} |
---|
312 |
|
---|
313 |
print ' <tr> |
---|
314 |
<td>Webinterface </td> |
---|
315 |
<td> |
---|
316 |
<select name="webui" size="1">'; |
---|
317 |
print ($webui) ? ' <option selected="selected">Enabled</option>' : ' <option>Enabled</option>'; |
---|
318 |
print ($webui) ? ' <option>Disabled</option>' : ' <option selected="selected">Disabled</option>'; |
---|
319 |
print ' </select> |
---|
320 |
</td> |
---|
321 |
</tr> |
---|
322 |
'; |
---|
323 |
|
---|
324 |
|
---|
325 |
print ' </table> |
---|
326 |
</td> |
---|
327 |
</tr> |
---|
328 |
</table> |
---|
329 |
'; |
---|
330 |
*/ |
---|
331 |
|
---|
332 |
print ' |
---|
333 |
<table width="98%" border="0" cellpadding="0" cellspacing="0"> |
---|
334 |
<tr> |
---|
335 |
<td height="72"> |
---|
336 |
<div style="text-align: right; margin-right: 20px;"> |
---|
337 |
<input type="submit" value=" Apply "> |
---|
338 |
</div> |
---|
339 |
</td> |
---|
340 |
</tr> |
---|
341 |
</table> |
---|
342 |
<input type="hidden" name="action" value="update"> |
---|
343 |
</form> |
---|
344 |
'; |
---|
345 |
|
---|
346 |
|
---|
347 |
|
---|
348 |
} |
---|
349 |
|
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|
353 |
?> |
---|