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