示例#1
0
function wrk_sourcemount($db, $action, $id)
{
    switch ($action) {
        case 'mount':
            $dbh = cfgdb_connect($db);
            $mp = cfgdb_read('cfg_source', $dbh, '', $id);
            sysCmd("mkdir \"/mnt/NAS/" . $mp[0]['name'] . "\"");
            if ($mp[0]['type'] == 'cifs') {
                // smb/cifs mount
                $mountstr = "mount -t cifs \"//" . $mp[0]['address'] . "/" . $mp[0]['remotedir'] . "\" -o username="******",password="******",rsize=" . $mp[0]['rsize'] . ",wsize=" . $mp[0]['wsize'] . ",iocharset=" . $mp[0]['charset'] . "," . $mp[0]['options'] . " \"/mnt/NAS/" . $mp[0]['name'] . "\"";
            } else {
                // nfs mount
                $mountstr = "mount -t nfs -o " . $mp[0]['options'] . " \"" . $mp[0]['address'] . ":/" . $mp[0]['remotedir'] . "\" \"/mnt/NAS/" . $mp[0]['name'] . "\"";
            }
            // debug
            error_log(">>>>> mount string >>>>> " . $mountstr, 0);
            $sysoutput = sysCmd($mountstr);
            error_log(var_dump($sysoutput), 0);
            if (empty($sysoutput)) {
                if (!empty($mp[0]['error'])) {
                    $mp[0]['error'] = '';
                    cfgdb_update('cfg_source', $dbh, '', $mp[0]);
                }
                $return = 1;
            } else {
                sysCmd("rmdir \"/mnt/NAS/" . $mp[0]['name'] . "\"");
                $mp[0]['error'] = implode("\n", $sysoutput);
                cfgdb_update('cfg_source', $dbh, '', $mp[0]);
                $return = 0;
            }
            break;
        case 'mountall':
            $dbh = cfgdb_connect($db);
            $mounts = cfgdb_read('cfg_source', $dbh);
            foreach ($mounts as $mp) {
                if (!wrk_checkStrSysfile('/proc/mounts', $mp['name'])) {
                    $return = wrk_sourcemount($db, 'mount', $mp['id']);
                }
            }
            $dbh = null;
            break;
    }
    return $return;
}
示例#2
0
        if ($_POST['action'] == 'edit') {
            $jobID = wrk_control($redis, 'newjob', $data = array('wrkcmd' => 'sourcecfg', 'action' => 'edit', 'args' => $_POST['mount']));
        }
        if ($_POST['action'] == 'delete') {
            $jobID = wrk_control($redis, 'newjob', $data = array('wrkcmd' => 'sourcecfg', 'action' => 'delete', 'args' => $_POST['mount']));
        }
        if ($_POST['action'] == 'reset') {
            $jobID = wrk_control($redis, 'newjob', $data = array('wrkcmd' => 'sourcecfgman', 'action' => 'reset'));
        }
    }
}
waitSyWrk($redis, $jobID);
$source = netMounts($redis, 'read');
if ($source !== true) {
    foreach ($source as $mp) {
        if (wrk_checkStrSysfile('/proc/mounts', '/mnt/MPD/NAS/' . $mp['name'])) {
            $mp['status'] = 1;
        } else {
            $mp['status'] = 0;
        }
        $mounts[] = $mp;
    }
}
$template->mounts = $mounts;
$usbmounts = $redis->hGetAll('usbmounts');
foreach ($usbmounts as $usbmount) {
    $template->usbmounts[] = json_decode($usbmount);
}
if (isset($template->action)) {
    if (isset($template->arg)) {
        foreach ($source as $mp) {
     //$netconf .= "\n";
     //$netconf .= "auto eth0\n";
     $netconf = $netconf . $_SESSION['w_queueargs'];
     fwrite($fp, $netconf);
     fclose($fp);
     // update hash
     $hash = md5_file('/etc/network/interfaces');
     playerSession('write', $db, 'netconfhash', $hash);
     // restart wlan0 interface
     if (strpos($netconf, 'wlan0') != false) {
         $cmd = "ip addr list wlan0 |grep \"inet \" |cut -d' ' -f6|cut -d/ -f1";
         $ip_wlan0 = sysCmd($cmd);
         if (!empty($ip_wlan0[0])) {
             $_SESSION['netconf']['wlan0']['ip'] = $ip_wlan0[0];
         } 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');
     break;
 case 'netcfgman':
     $file = '/etc/network/interfaces';
     $fp = fopen($file, 'w');
     fwrite($fp, $_SESSION['w_queueargs']);
     fclose($fp);
     break;
 case 'mpdcfg':
示例#4
0
     if ($_SESSION['dev'] == 1) {
         $_SESSION['w_queueargs'] = 'dev';
     }
     sysCmd("/var/www/command/orion_optimize.sh " . $args);
     break;
 case 'netcfg':
     $netconf = "auto lo\n";
     $netconf .= "iface lo inet loopback\n";
     file_put_contents('/etc/network/interfaces', $netconf . $args);
     // restart wlan0 interface
     if (strpos($netconf, 'wlan0') != false) {
         $ip_wlan0 = sysCmd("ip addr list wlan0 |grep \"inet \" |cut -d' ' -f6|cut -d/ -f1");
         if (!empty($ip_wlan0[0])) {
             $ip = $ip_wlan0[0];
         } else {
             $ip = wrk_checkStrSysfile('/proc/net/wireless', 'wlan0') ? '--- NO IP ASSIGNED ---' : '--- NO INTERFACE PRESENT ---';
         }
         // update session
         Session::wrap(function () use($ip) {
             $_SESSION['netconf']['wlan0']['ip'] = $ip;
         }, true);
     }
     sysCmd('service networking restart');
     break;
 case 'netcfgman':
     file_put_contents('/etc/network/interfaces', $args);
     break;
 case 'mpdcfg':
     wrk_mpdconf(getKernelVer($_SESSION['kernelver']), $_SESSION['i2s']);
     sysCmd('killall mpd');
     sysCmd('service mpd start');
示例#5
0
    $_mpd_select['audio_output_format'] .= "<option value=\"44100:32:2\" " . ($_mpd['audio_output_format'] == '44100:32:2' ? "selected" : "") . ">32 bit / 44.1 khz</option>\n";
    $_mpd_select['audio_output_format'] .= "<option value=\"96000:32:2\" " . ($_mpd['audio_output_format'] == '96000:32:2' ? "selected" : "") . ">32 bit / 96 khz</option>\n";
    $_mpd_select['audio_output_format'] .= "<option value=\"192000:32:2\" " . ($_mpd['audio_output_format'] == '192000:32:2' ? "selected" : "") . ">32 bit / 192 khz</option>\n";
    $_mpd_select['audio_output_format'] .= "<option value=\"384000:32:2\" " . ($_mpd['audio_output_format'] == '384000:32:2' ? "selected" : "") . ">32 bit / 384 khz</option>\n";
    // mixer_type
    $_mpd_select['mixer_type'] .= "<option value=\"disabled\" " . (($_mpd['mixer_type'] == 'none' or $_mpd['mixer_type'] == '') ? "selected" : "") . ">disabled</option>\n";
    $_mpd_select['mixer_type'] .= "<option value=\"hardware\" " . ($_mpd['mixer_type'] == 'hardware' ? "selected" : "") . ">Hardware</option>\n";
    $_mpd_select['mixer_type'] .= "<option value=\"software\" " . ($_mpd['mixer_type'] == 'software' ? "selected" : "") . ">Software</option>\n";
    // set normal config template
    $tpl = "mpd-config.html";
}
// close DB connection
$dbh = null;
// unlock session files
playerSession('unlock', $db, '', '');
if (wrk_checkStrSysfile('/proc/asound/card0/pcm0p/info', 'bcm2835')) {
    $_audioout = "<select id=\"audio-output-interface\" name=\"conf[audio-output-interface]\" class=\"input-large\">\n";
    //$_audioout .= "<option value=\"disabled\">disabled</option>";
    $_audioout .= "<option value=\"jack\">Analog Jack</option>\n";
    $_audioout .= "<option value=\"hdmi\">HDMI</option>\n";
    $_audioout .= "</select>\n";
    $_audioout .= "<span class=\"help-block\">Select MPD Audio output interface</span>\n";
} else {
    $_audioout .= "<input class=\"input-large\" class=\"input-large\" type=\"text\" id=\"port\" name=\"\" value=\"USB Audio\" data-trigger=\"change\" disabled>\n";
}
?>

<?php 
$sezione = basename(__FILE__, '.php');
include '_header.php';
?>
示例#6
0
文件: sources.php 项目: norrest/test
		$_SESSION['notify']['title'] = 'Job Failed';
		$_SESSION['notify']['msg'] = 'background worker is busy.';
		session_write_close();
		}
} */
// wait for worker output if $_SESSION['w_active'] = 1
waitWorker(5, 'sources');
$dbh = cfgdb_connect($db);
$source = cfgdb_read('cfg_source', $dbh);
$dbh = null;
// set normal config template
$tpl = "sources.html";
// unlock session files
playerSession('unlock', $db, '', '');
foreach ($source as $mp) {
    if (wrk_checkStrSysfile('/proc/mounts', $mp['name'])) {
        $icon = "<i class='fa fa-check green sx'></i>";
    } else {
        $icon = "<i class='fa fa-remove red sx'></i>";
    }
    $_mounts .= "<p><a href=\"sources.php?p=edit&id=" . $mp['id'] . "\" class='btn btn-large btn-block'> " . $icon . " NAS/" . $mp['name'] . "&nbsp;&nbsp;&nbsp;&nbsp;//" . $mp['address'] . "/" . $mp['remotedir'] . " </a></p>";
}
?>

<?php 
$sezione = basename(__FILE__, '.php');
include '_header.php';
?>

<!-- content --!>
<?php 
示例#7
0
function wrk_sourcemount($action, $id = null)
{
    $return = null;
    switch ($action) {
        case 'mount':
            $mp = ConfigDB::read('cfg_source', '', $id);
            sysCmd("mkdir '/mnt/NAS/" . $mp[0]['name'] . "'");
            $mountstr = 'mount -t ' . ($mp[0]['type'] == 'cifs') ? "cifs '//" . $mp[0]['address'] . "/" . $mp[0]['remotedir'] . "' -o username="******",password='******'password'] . "',rsize=" . $mp[0]['rsize'] . ",wsize=" . $mp[0]['wsize'] . ",iocharset=" . $mp[0]['charset'] . "," . $mp[0]['options'] . " '/mnt/NAS/" . $mp[0]['name'] . "'" : "nfs -o " . $mp[0]['options'] . " '" . $mp[0]['address'] . ":/" . $mp[0]['remotedir'] . "' '/mnt/NAS/" . $mp[0]['name'] . "'";
            // debug
            $sysoutput = sysCmd($mountstr);
            if (empty($sysoutput)) {
                if (!empty($mp[0]['error'])) {
                    $mp[0]['error'] = '';
                    ConfigDB::update('cfg_source', '', $mp[0]);
                }
                $return = 1;
            } else {
                sysCmd("rmdir '/mnt/NAS/" . $mp[0]['name'] . "'");
                $mp[0]['error'] = implode("\n", $sysoutput);
                ConfigDB::update('cfg_source', '', $mp[0]);
                $return = 0;
            }
            break;
        case 'mountall':
            $mounts = ConfigDB::read('cfg_source');
            foreach ($mounts as $mp) {
                if (!wrk_checkStrSysfile('/proc/mounts', $mp['name'])) {
                    $return = wrk_sourcemount('mount', $mp['id']);
                }
            }
            break;
    }
    return $return;
}
示例#8
0
            uiSetNotification('Job failed', 'Background worker is busy');
        }
    }
}
Session::close();
// wait for worker
waitWorker();
// update MPD db after worker finishes
if (false !== ($mpd = openMpdSocket(MPD_HOST, 6600))) {
    execMpdCommand($mpd, 'update');
    closeMpdSocket($mpd);
}
$source = ConfigDB::read('cfg_source');
$_mounts = '';
foreach ($source as $mp) {
    $icon = wrk_checkStrSysfile('/proc/mounts', $mp['name']) ? "<i class='icon-ok green sx'></i>" : "<i class='icon-remove red sx'></i>";
    $_mounts .= "<p><a href=\"sources.php?p=edit&id=" . $mp['id'] . "\" class='btn btn-large' style='width: 240px;'> " . $icon . " " . $mp['name'] . " (" . $mp['address'] . ") </a></p>";
}
$tpl = "sources";
if (isset($_GET['p']) && !empty($_GET['p'])) {
    if (isset($_GET['id']) && !empty($_GET['id'])) {
        $_id = $_GET['id'];
        foreach ($source as $mount) {
            if ($mount['id'] == $_id) {
                $_name = $mount['name'];
                $_address = $mount['address'];
                $_remotedir = $mount['remotedir'];
                $_username = $mount['username'];
                $_password = $mount['password'];
                $_rsize = $mount['rsize'];
                $_wsize = $mount['wsize'];