$value$name>"); $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()).""; } function restart_mt_server() { shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc stop"); shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc start"); } 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); restart_mt_server(); } else if ($bonding == 'none' && $interface == 'bond0') { $interface = 'eth0'; $xml->server->interface = $interface; write_mt_config($xml); restart_mt_server(); } // 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); // Remove the deleted stuff from the sqlite db. Have to shellexec this here as php has no // support for sqlite3 $cmd = 'LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/raid/data/module/MEDIATOMB/system/lib/"'; $cmd .= ' /raid/data/module/MEDIATOMB/system/bin/sqlite3'; $cmd .= ' /raid/data/module/MEDIATOMB/system/var/mediatomb/mediatomb.db'; $cmd .= ' "DELETE FROM mt_cds_object WHERE location LIKE \'F'.(string)$dir['location'].'/%\' OR location LIKE \'D'.(string)$dir['location'].'/%\' OR location LIKE \'D'.(string)$dir['location'].'\' ;"'; shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc stop"); shell_exec($cmd); shell_exec("/raid/data/module/MEDIATOMB/Shell/module.rc start"); } } } if (array_key_exists('interface', $_POST)) { $interface = $_POST['interface']; $xml->server->interface = $interface; } write_mt_config($xml); restart_mt_server(); // 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 '
|
|||||
The internal Mediabolic DLNA server is currently enabled. Please disable it first through the Network/Media Server menu. |