$value"); $node1 = dom_import_simplexml($parent); $dom_sxe = dom_import_simplexml($new_child); $node2 = $node1->ownerDocument->importNode($dom_sxe, true); $node1->appendChild($node2); return simplexml_import_dom($node2); } function simplexml_addAttribute($parent, $name, $value=''){ $node1 = dom_import_simplexml($parent); $node1->setAttribute($name,$value); return simplexml_import_dom($node1); } function write_mt_config($xml) { global $mt_config; // Import into DOM as this allows for PrettyPrinting $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->loadXML($xml->asXML()); $dom->formatOutput = true; $dom->save($mt_config); // echo "
".htmlentities($dom->saveXML())."
"; } require_once('/img/www/inc/db.class.php'); // retrieve the configuration status of the shipped DLNA_server $dbtool=new dbtool(); $dbtool->connect(); $DLNA_server=$dbtool->db_getvar("DLNA_server","0"); $bonding=$dbtool->db_getvar("nic1_mode_8023ad","none"); $dbtool->db_close(); // Load the MediaTomb XML config $mt_config = '/raid/data/module/MEDIATOMB/system/etc/config.xml'; $xml = simplexml_load_file($mt_config); // Get the interface from the MT config $interface = (string)$xml->server->interface; // Fixup incorrect network settings, e.g. bonding enabled but MT listening somewhere else. if ($bonding != 'none' && $interface != 'bond0') { $interface = bond0; $xml->server->interface = $interface; write_mt_config($xml); } else if ($bonding == 'none' && interface == 'bond0') { $interface = eth0; $xml->server->interface = $interface; write_mt_config($xml); } // Get the list of available shares from the samba config $fh = fopen("/etc/samba/smb.conf", "r"); $contents = fread($fh, filesize("/etc/samba/smb.conf")); fclose($fh); preg_match_all("/\[([^\]]*)\]\s*comment = ([^\n]*)[^\[]*guest only = ([^\n]*)[^\[]*path = ([^\n]*)/",$contents,$shares); $share_blacklist = array("nsync", "usbhdd", "usbcopy"); $mt_share_list = array(); // Get the list of exported shares from the mediatomb xml config foreach ($xml->import->autoscan->directory as $elem) { $mt_share_list[] = (string)$elem['location']; } // We're seeing a request. Handle it. if (array_key_exists('action', $_POST)) { if (!array_key_exists('shared', $_POST)) { $_POST['shared'] = array(); } // Find the shares not currently shared but requested $add = (array_diff($_POST['shared'], $mt_share_list)); // Find the shares not currently shared but requested $del = (array_diff($mt_share_list, $_POST['shared'])); foreach ($add as $dir) { print '

Adding '.$dir.'

'; $directory = simplexml_addChild($xml->import->autoscan, 'directory'); simplexml_addAttribute($directory, 'location', $dir); // inotify is not supported on the current thecus kernel // simplexml_addAttribute($directory, 'mode', 'inotify'); simplexml_addAttribute($directory, 'mode', 'timed'); simplexml_addAttribute($directory, 'interval', '3600'); simplexml_addAttribute($directory, 'level', 'basic'); simplexml_addAttribute($directory, 'recursive', 'yes'); simplexml_addAttribute($directory, 'hidden-files', 'no'); } // Outer loop is a workaround for an early break as content is changing. for ($i=0; $i < count($del); $i++) { foreach ($xml->import->autoscan->directory as $dir) { if (in_array((string)$dir['location'], $del)) { print '

Removing '.(string)$dir['location'].'

'; $oNode = dom_import_simplexml($dir); $oNode->parentNode->removeChild($oNode); } } } write_mt_config($xml); // File was modified, reload $xml = simplexml_load_file($mt_config); $mt_share_list = array(); // Get the list of exported shares from the mediatomb xml config foreach ($xml->import->autoscan->directory as $elem) { $mt_share_list[] = (string)$elem['location']; } } print '
Mediatomb - Free UPnP MediaServer
'; if ($DLNA_server == 1) { print '

The internal Mediabolic DLNA server is currently enabled.

Please disable it first through the Network/Media Server menu.

'; } else { print '
'; for ($i=0; $i < count($shares[0]); $i++) { if (!in_array($shares[1][$i], $share_blacklist)) { print ''."\n"; print ''."\n"; } else { print ''."\n"; } print ''."\n"; print ''."\n"; print ''."\n"; } } print '
Shared Media Folders
'; if (in_array($shares[4][$i], $mt_share_list)) { print ''.$shares[1][$i].''.$shares[2][$i].'
'; print '
'; print ' '; /* if ((string)$xml->server->ui['enabled'] == "yes") { $webui = true; } else { $webui = false; } print ' '; print '
System settings
Network Interface:
Webinterface
'; */ print '
'; } ?>