예제 #1
0
파일: Session.php 프로젝트: dermidgen/moode
 /**
  * Open session, adjust UID if required
  */
 public static function open($admin = false)
 {
     if (PHP_SESSION_ACTIVE == session_status()) {
         throw new \LogicException('Session already open');
     }
     // automatic admin mode for command line testing if root
     $session_file = session_save_path() . DIRECTORY_SEPARATOR . 'sess_' . static::SESSION_ID;
     if (file_exists($session_file) && is_readable($session_file)) {
         $session_owner = fileowner($session_file);
         if ($session_owner !== posix_getuid() && 0 === posix_getuid()) {
             // echo("o: $session_owner\n");
             $admin = true;
         }
         $_SESSION['_dirty'] = microtime();
     }
     // set effective uid of session owner
     if ($admin) {
         static::$pre_session_uid = posix_getuid();
         posix_seteuid(posix_getpwnam(static::SESSION_ADMIN_USER)['uid']);
     }
     // tie all users to single session
     session_id(static::SESSION_ID);
     if (false === session_start()) {
         throw new \RuntimeException('Could not start session');
     }
     // update sesson with current configuration
     // TODO check if necessary
     foreach (ConfigDB::read('cfg_engine') as $row) {
         $_SESSION[$row['param']] = $row['value'];
     }
 }
예제 #2
0
파일: daemon.php 프로젝트: dermidgen/moode
 closeMpdSocket($mpd);
 $currentsong = _parseMpdCurrentSong($resp);
 // TC (Tim Curtis) 2015-07-31: updated logic
 // Logic modeled after player_lib.js getPlaylist();
 // RADIO STATION
 if (isset($currentsong['Name']) || substr($currentsong['file'], 0, 4) == "http" && !isset($currentsong['Artist'])) {
     if (!isset($currentsong['Title'])) {
         $title = "Streaming source";
     } else {
         $title = $currentsong['Title'];
         $searchStr = str_replace('-', ' ', $title);
         $searchStr = str_replace('&', ' ', $searchStr);
         $searchStr = preg_replace('!\\s+!', '+', $searchStr);
     }
     $artist = "<i class=\"icon-microphone\"></i>";
     $result = ConfigDB::read('cfg_radio', $currentsong['file']);
     if (0 == count($result)) {
         // station not in db
         $album = isset($currentsong['Name']) ? $currentsong['Name'] : "Unknown station";
     } else {
         $album = $result[0]['name'];
     }
     // SONG FILE OR UPNP SONG URL
 } else {
     $title = isset($currentsong['Title']) ? $currentsong['Title'] : pathinfo($currentsong['file'], PATHINFO_FILENAME);
     $artist = isset($currentsong['Artist']) ? $currentsong['Artist'] : "Unknown artist";
     $album = isset($currentsong['Album']) ? $currentsong['Album'] : "Unknown album";
     // search string
     if ($artist == "Unknown artist" && $album == "Unknown album") {
         $searchStr = $title;
     } else {
예제 #3
0
}
// Handle manual config
if (isset($_POST['mpdconf']) && !empty($_POST['mpdconf'])) {
    // tell worker to write new MPD config
    if ($workerSuccess = workerPushTask('mpdcfgman', $_POST['mpdconf'])) {
        uiSetNotification('MPD config modified', 'Restarting MPD server...');
    }
}
// could not start worker job
if (false === $workerSuccess) {
    uiSetNotification('Job failed', 'Background worker is busy');
}
Session::close();
// Wait for worker
waitWorker();
$mpdconf = ConfigDB::read('', 'mpdconf');
// Prepare array
$_mpd = array('port' => '', 'gapless_mp3_playback' => '', 'auto_update' => '', 'samplerate_converter' => '', 'auto_update_depth' => '', 'zeroconf_enabled' => '', 'zeroconf_name' => '', 'audio_output_format' => '', 'mixer_type' => '', 'audio_buffer_size' => '', 'buffer_before_play' => '', 'dsd_usb' => '', 'device' => '', 'volume_normalization' => '');
// Parse output for template $_mpdconf
foreach ($mpdconf as $key => $value) {
    foreach ($_mpd as $key2 => $value2) {
        if ($value['param'] == $key2) {
            $_mpd[$key2] = $value['value_player'];
        }
    }
}
function getDeviceName($file)
{
    $dev = rtrim(@file_get_contents($file));
    switch ($dev) {
        case "":
예제 #4
0
파일: worker.php 프로젝트: dermidgen/moode
function wrk_sourcecfg($queueargs)
{
    $action = $queueargs['mount']['action'];
    unset($queueargs['mount']['action']);
    switch ($action) {
        case 'reset':
            $source = ConfigDB::read('cfg_source');
            foreach ($source as $mp) {
                sysCmd("umount -f '/mnt/NAS/" . $mp['name'] . "'");
                sysCmd("rmdir '/mnt/NAS/" . $mp['name'] . "'");
            }
            $return = ConfigDB::delete('cfg_source') ? 1 : 0;
            break;
        case 'add':
            print_r($queueargs);
            unset($queueargs['mount']['id']);
            // write new entry
            $newmountID = ConfigDB::write('cfg_source', array_values($queueargs['mount']));
            $return = wrk_sourcemount('mount', $newmountID) ? 1 : 0;
            break;
        case 'edit':
            $mp = ConfigDB::read('cfg_source', '', $queueargs['mount']['id']);
            ConfigDB::update('cfg_source', '', $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'] . "'");
            }
            $return = wrk_sourcemount('mount', $queueargs['mount']['id']) ? 1 : 0;
            break;
        case 'delete':
            $mp = ConfigDB::read('cfg_source', '', $queueargs['mount']['id']);
            sysCmd("umount -f '/mnt/NAS/" . $mp[0]['name'] . "'");
            sysCmd("rmdir '/mnt/NAS/" . $mp[0]['name'] . "'");
            $return = ConfigDB::delete('cfg_source', $queueargs['mount']['id']) ? 1 : 0;
            break;
    }
    return $return;
}
예제 #5
0
파일: player.php 프로젝트: dermidgen/moode
function _parseMpdConf()
{
    // prepare array
    $_mpd = array('port' => '', 'gapless_mp3_playback' => '', 'auto_update' => '', 'samplerate_converter' => '', 'auto_update_depth' => '', 'zeroconf_enabled' => '', 'zeroconf_name' => '', 'audio_output_format' => '', 'mixer_type' => '', 'audio_buffer_size' => '', 'buffer_before_play' => '', 'dsd_usb' => '', 'device' => '', 'volume_normalization' => '');
    // read in mpd conf settings
    $mpdconf = ConfigDB::read('', 'mpdconf');
    // parse output for template
    foreach ($mpdconf as $key => $value) {
        if (in_array($value['param'], array_keys($_mpd))) {
            $_mpd[$value['param']] = $value['value_player'];
        }
    }
    // parse audio output format, ex "44100:16:2"
    $_mpd += parseAudioFormat($_mpd['audio_output_format']);
    return $_mpd;
}
예제 #6
0
파일: tcmods.php 프로젝트: dermidgen/moode
        echo "Background worker is busy";
    }
    // Display template if not clock radio reload or tcmods conf reload
    if (isset($tpl)) {
        render($tpl);
    }
    exit;
}
/*
 * Json commands
 */
if (isset($_GET['cmd']) && $_GET['cmd'] != '') {
    header('Content-type: application/json');
    switch ($cmd = $_GET['cmd']) {
        case 'getaudiodevdesc':
            $result = ConfigDB::read('cfg_audiodev', $_POST['audiodev']);
            $res = $result[0];
            break;
        case 'getupnpcoverurl':
            $rtn = sysCmd('upexplorer --album-art "' . $_SESSION['upnp_name'] . '"');
            $res = array('coverurl' => $rtn[0]);
            break;
        case 'readtcmconf':
            $res = getTcmodsConf();
            break;
        case 'updatetcmconf':
            $res = _updTcmodsConf($_POST);
            break;
        case 'getmpdstatus':
            $res = _parseStatusResponse(mpdStatus($mpd));
            break;
예제 #7
0
파일: sources.php 프로젝트: dermidgen/moode
        if (workerPushTask('sourcecfg', $_POST)) {
            uiSetNotification('Mount point modified', 'MPD database update initiated...');
        } else {
            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'];
예제 #8
0
            uiSetNotification('Job failed', 'Background worker is busy');
        }
    }
    // create job for background worker
    if (workerPushTask('netcfg', $wlan0 . $eth0)) {
        uiSetNotification('Network config', isset($_GET['reset']) && $_GET['reset'] == 1 ? 'Network config reset' : 'Network config modified');
    } else {
        uiSetNotification('Job failed', 'Background worker is busy');
    }
    // unlock session file
    Session::close();
}
// wait for worker
waitWorker();
$net = ConfigDB::read('cfg_lan');
$wifisec = ConfigDB::read('cfg_wifisec');
// eth0
$_eth0 = isset($_SESSION['netconf']['eth0']) && !empty($_SESSION['netconf']['eth0']) ? $_SESSION['netconf']['eth0']['ip'] : "Not used";
$_int0dhcp = "<option value=\"true\" " . (isset($net[0]['dhcp']) && $net[0]['dhcp'] == "true" ? "selected" : "") . " >enabled (Auto)</option>\n";
$_int0dhcp .= "<option value=\"false\" " . (isset($net[0]['dhcp']) && $net[0]['dhcp'] == "false" ? "selected" : "") . " >disabled (Static)</option>\n";
$_int0 = $net[0];
// wlan0
$_wlan0 = isset($_SESSION['netconf']['wlan0']) && !empty($_SESSION['netconf']['wlan0']) ? $_SESSION['netconf']['wlan0']['ip'] : "Not used";
$_wlan0ssid = $wifisec[0]['ssid'];
// TC (Tim Curtis) 2015-04-29: reorder so WPA/WPA2 is first
$_wlan0security = "<option value=\"wpa\"" . ($wifisec[0]['security'] == 'wpa' ? "selected" : "") . ">WPA/WPA2 Personal</option>\n";
$_wlan0security .= "<option value=\"wep\"" . ($wifisec[0]['security'] == 'wep' ? "selected" : "") . ">WEP</option>\n";
$_wlan0security .= "<option value=\"none\"" . ($wifisec[0]['security'] == 'none' ? "selected" : "") . ">No security</option>\n";
// unlock session files
Session::close();
render("net-config");