function wrk_sourcecfg($db, $queueargs) { $action = $queueargs['mount']['action']; unset($queueargs['mount']['action']); switch ($action) { case 'reset': $dbh = cfgdb_connect($db); $source = cfgdb_read('cfg_source', $dbh); foreach ($source as $mp) { sysCmd("umount -f \"/mnt/NAS/" . $mp['name'] . "\""); sysCmd("rmdir \"/mnt/NAS/" . $mp['name'] . "\""); } if (cfgdb_delete('cfg_source', $dbh)) { $return = 1; } else { $return = 0; } $dbh = null; break; case 'add': $dbh = cfgdb_connect($db); print_r($queueargs); unset($queueargs['mount']['id']); // format values string foreach ($queueargs['mount'] as $key => $value) { if ($key == 'error') { $values .= "'" . SQLite3::escapeString($value) . "'"; error_log(">>>>> values on line 1014 >>>>> " . $values, 0); } else { $values .= "'" . SQLite3::escapeString($value) . "',"; error_log(">>>>> values on line 1016 >>>>> " . $values, 0); } } error_log(">>>>> values on line 1019 >>>>> " . $values, 0); // write new entry cfgdb_write('cfg_source', $dbh, $values); $newmountID = $dbh->lastInsertId(); $dbh = null; if (wrk_sourcemount($db, 'mount', $newmountID)) { $return = 1; } else { $return = 0; } break; case 'edit': $dbh = cfgdb_connect($db); $mp = cfgdb_read('cfg_source', $dbh, '', $queueargs['mount']['id']); cfgdb_update('cfg_source', $dbh, '', $queueargs['mount']); sysCmd("umount -f \"/mnt/NAS/" . $mp[0]['name'] . "\""); if ($mp[0]['name'] != $queueargs['mount']['name']) { sysCmd("rmdir \"/mnt/NAS/" . $mp[0]['name'] . "\""); sysCmd("mkdir \"/mnt/NAS/" . $queueargs['mount']['name'] . "\""); } if (wrk_sourcemount($db, 'mount', $queueargs['mount']['id'])) { $return = 1; } else { $return = 0; } error_log(">>>>> wrk_sourcecfg(edit) exit status = >>>>> " . $return, 0); $dbh = null; break; case 'delete': $dbh = cfgdb_connect($db); $mp = cfgdb_read('cfg_source', $dbh, '', $queueargs['mount']['id']); sysCmd("umount -f \"/mnt/NAS/" . $mp[0]['name'] . "\""); sysCmd("rmdir \"/mnt/NAS/" . $mp[0]['name'] . "\""); if (cfgdb_delete('cfg_source', $dbh, $queueargs['mount']['id'])) { $return = 1; } else { $return = 0; } $dbh = null; break; } return $return; }
// set UI notify $_SESSION['notify']['title'] = 'Reset MPD Config'; $_SESSION['notify']['msg'] = 'Restarting MPD daemon...'; session_write_close(); } else { session_start(); $_SESSION['notify']['title'] = 'Job Failed'; $_SESSION['notify']['msg'] = 'Background worker is busy.'; session_write_close(); } unset($_POST); } // handle POST if (isset($_POST['conf']) && !empty($_POST['conf'])) { foreach ($_POST['conf'] as $key => $value) { cfgdb_update('cfg_mpd', $dbh, $key, $value); } // tell worker to write new MPD config if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') { session_start(); $_SESSION['w_queue'] = "mpdcfg"; $_SESSION['w_active'] = 1; // set UI notify $_SESSION['notify']['title'] = 'MPD Config modified'; $_SESSION['notify']['msg'] = 'Restarting MPD daemon...'; session_write_close(); } else { session_start(); $_SESSION['notify']['title'] = 'Job Failed'; $_SESSION['notify']['msg'] = 'Background worker is busy.'; session_write_close();
} else { if (wrk_checkStrSysfile('/proc/net/wireless', 'wlan0')) { $_SESSION['netconf']['wlan0']['ip'] = '--- NO IP ASSIGNED ---'; } else { $_SESSION['netconf']['wlan0']['ip'] = '--- NO INTERFACE PRESENT ---'; } } } sysCmd('service networking restart'); // reset sourcecfg to defaults wrk_sourcecfg($db, 'reset'); sendMpdCommand($mpd, 'update'); // reset mpdconf to defaults $mpdconfdefault = cfgdb_read('', $dbh, 'mpdconfdefault'); foreach ($mpdconfdefault as $element) { cfgdb_update('cfg_mpd', $dbh, $element['param'], $element['value_default']); } // tell worker to write new MPD config wrk_mpdconf('/etc', $db); // update hash $hash = md5_file('/etc/mpd.conf'); playerSession('write', $db, 'mpdconfhash', $hash); sysCmd('service mpd restart'); $dbh = null; // disable minidlna / samba / MPD startup sysCmd("update-rc.d -f minidlna remove"); sysCmd("update-rc.d -f ntp remove"); sysCmd("update-rc.d -f smbd remove"); sysCmd("update-rc.d -f nmbd remove"); sysCmd("update-rc.d -f mpd remove"); sysCmd("echo 'manual' > /etc/init/minidlna.override");
$eth0 .= "address " . $_POST['eth0']['ip'] . "\n"; $eth0 .= "netmask " . $_POST['eth0']['netmask'] . "\n"; $eth0 .= "gateway " . $_POST['eth0']['gw'] . "\n"; if (isset($_POST['eth0']['dns1']) && !empty($_POST['eth0']['dns1'])) { $eth0 .= "nameserver " . $_POST['eth0']['dns1'] . "\n"; } if (isset($_POST['eth0']['dns2']) && !empty($_POST['eth0']['dns2'])) { $eth0 .= "nameserver " . $_POST['eth0']['dns2'] . "\n"; } } $wlan0 = "\n"; } // wlan0 if (isset($_POST['wifisec']['ssid']) && !empty($_POST['wifisec']['ssid'])) { $value = array('ssid' => $_POST['wifisec']['ssid'], 'encryption' => $_POST['wifisec']['encryption'], 'password' => $_POST['wifisec']['password']); cfgdb_update('cfg_wifisec', $dbh, '', $value); $wifisec = cfgdb_read('cfg_wifisec', $dbh); // format new config string for wlan0 $wlan0 = "\n"; $wlan0 .= "auto wlan0\n"; $wlan0 .= "iface wlan0 inet dhcp\n"; $wlan0 .= "wireless-power off\n"; if ($_POST['wifisec']['encryption'] == 'wpa') { $wlan0 .= "wpa-ssid " . $_POST['wifisec']['ssid'] . "\n"; $wlan0 .= "wpa-psk " . $_POST['wifisec']['password'] . "\n"; } else { $wlan0 .= "wireless-essid " . $_POST['wifisec']['ssid'] . "\n"; if ($_POST['wifisec']['encryption'] == 'wep') { $wlan0 .= "wireless-key " . $_POST['wifisec']['password'] . "\n"; } else { if ($_POST['wifisec']['encryption'] == 'none') {