4 protected static function callCommand($cmd, array $data=array())
6 if (($pipe = popen($cmd, 'w')) === false)
9 foreach ($data as $value)
10 fwrite($pipe, $value . "\n");
16 public static function getdatetimeAction()
18 return array('year' => date('Y'),
22 'minute' => date('i'),
23 'second' => date('s'));
26 public static function datetimeAction()
28 $date = sprintf("%04d-%02d-%02d", $_POST['year'], $_POST['month'], $_POST['day']);
29 $time = sprintf("%02d:%02d:%02d", $_POST['hour'], $_POST['minute'], $_POST['second']);
31 $ok = self::callCommand("super musiikki-datetime", array($date, $time));
36 public static function getwifiAction()
38 if (!file_exists('/etc/hostapd/hostapd.conf'))
41 if (($f = fopen('/etc/hostapd/hostapd.conf', 'r')) === false)
47 while (($line = fgets($f)) !== false) {
49 if (substr($line,0,1) == '#') continue;
50 if (!strlen($line)) continue;
52 $parts = explode('=', $line, 2);
53 if ($parts[0] == 'ssid')
55 elseif ($parts[0] == 'wpa_passphrase')
56 $password = $parts[1];
61 return array('essid' => $essid,
62 'password' => $password);
65 public static function wifiAction()
67 $ok = self::callCommand("super musiikki-wifi", array($_POST['essid'], $_POST['password']));
72 public static function getnetworkAction()
75 $conf = '/etc/network/interfaces.d/uplink.conf';
76 if (file_exists($conf)) {
77 $dest = readlink($conf);
78 $name = substr($dest, 9, -5);
82 foreach (new DirectoryIterator(dirname($conf)) as $fileInfo) {
83 if (substr($fileInfo->getBasename(), 0, 9) != 'upstream_') continue;
84 $upstream[] = substr($fileInfo->getBasename('.conf'), 9);
90 $f = popen("ip -f inet addr show wlan0", 'r');
91 while (($line = fgets($f)) !== false)
92 $lines[] = rtrim($line);
95 if (preg_match('/inet (\d+\.\d+\.\d+\.\d+)\/.*/', $lines[1], $matches))
100 $f = popen("iwlist wlan0 scan", 'r');
101 while (($line = fgets($f)) !== false) {
102 if (preg_match('/ESSID:"(.*?)"/', $line, $matches))
103 if (strlen($matches[1]))
104 $networks[] = $matches[1];
109 return ['name' => $name,
111 'networks' => $networks,
112 'upstream' => $upstream];
115 public static function networkAction()
117 $ok = self::callCommand("super musiikki-wlan", array($_POST['wlan']));
122 public static function essidAction()
124 if (!preg_match('/^[A-Za-z0-9_-]+$/', $_POST['name']))
127 $ok = self::callCommand("super musiikki-essid", array($_POST['name'], $_POST['essid'], $_POST['psk']));
132 public static function getsharesAction()
134 return array('ro_name' => '\\\\' . $_SERVER['SERVER_ADDR'] .'\\'. Config::SHARE_READ,
135 'ro_user' => Config::SHARE_READ,
137 'rw_name' => '\\\\' . $_SERVER['SERVER_ADDR'] .'\\'. Config::SHARE_WRITE,
138 'rw_user' => Config::SHARE_WRITE,
139 'rw_password' => '');
142 public static function sharesAction()
144 $ok = self::callCommand("super musiikki-shares", array($_POST['ro_password'], $_POST['rw_password']));
149 public static function getpasswdAction()
154 public static function passwdAction()
156 if (!strlen($_POST['password'])) return false;
158 if (($f = fopen(Config::main()->get('password'), 'w')) === false) return false;
160 fwrite($f, sprintf("admin:%s\n", $_POST['password']));
166 public static function gethaltAction()
171 public static function haltAction()
173 $ok = self::callCommand("super musiikki-wlan", array(''));
174 $ok = self::callCommand("super musiikki-halt");
179 public static function getrescanAction()
181 $mtime = filemtime(Config::main()->get('cache'));
183 return array('modified' => date ("d. F Y H:i:s", $mtime));
186 public static function rescanAction()
188 $mtime = filemtime(Config::main()->get('cache'));
189 if ($mtime > time()-10)
190 return array('info' => 'Rescan läuft gerade und kann nicht erneut getriggert werden.');
192 if (($f = fopen(Config::main()->get('rescan_file'), 'w')) !== false) {
201 public static function getsearchAction()
206 public static function searchAction()
208 $cache = new Cache();
210 $list = $cache->findTitles($_POST['keyword']);
212 return ['results' => $list,
213 'playlist' => $_SESSION['playlist']];
216 public static function getresultsAction()
221 public static function playlistSelectAction()
223 $_SESSION['playlist'] = $_POST['name'];
226 public static function getplaylistsAction()
228 $playlists = new Playlists();
230 if (array_key_exists('playlist', $_SESSION))
231 $selected = $_SESSION['playlist'];
233 return ['list' => $playlists->getList(),
234 'selected' => $selected];
237 public static function playlistAction()
239 $playlists = new Playlists();
241 return ['title' => $_POST['name'],
242 'list' => $playlists->getContents($_POST['name'])];
245 public function playlistNewAction()
247 $playlists = new Playlists();
248 $playlists->create($_POST['name']);
251 public function playlistAddAction()
253 $cache = new Cache();
254 $playlists = new Playlists();
256 if (!array_key_exists('playlist', $_SESSION))
259 $playlists->add($_SESSION['playlist'], $cache->getRelativePath($_POST['id']));