+ public static function getnetworkAction()
+ {
+ $name = NULL;
+ $conf = '/etc/network/interfaces.d/uplink.conf';
+ if (file_exists($conf)) {
+ $dest = readlink($conf);
+ $name = substr($dest, 9, -5);
+ }
+
+ $upstream = [];
+ foreach (new DirectoryIterator(dirname($conf)) as $fileInfo) {
+ if (substr($fileInfo->getBasename(), 0, 9) != 'upstream_') continue;
+ $upstream[] = substr($fileInfo->getBasename('.conf'), 9);
+ }
+ sort($upstream);
+
+ $ip = NULL;
+ $lines = [];
+ $f = popen("ip -f inet addr show wlan0", 'r');
+ while (($line = fgets($f)) !== false)
+ $lines[] = rtrim($line);
+ pclose($f);
+ if (count($lines)) {
+ if (preg_match('/inet (\d+\.\d+\.\d+\.\d+)\/.*/', $lines[1], $matches))
+ $ip = $matches[1];
+ }
+
+ $networks = [];
+ $f = popen("iwlist wlan0 scan", 'r');
+ while (($line = fgets($f)) !== false) {
+ if (preg_match('/ESSID:"(.*?)"/', $line, $matches))
+ if (strlen($matches[1]))
+ $networks[] = $matches[1];
+ }
+ pclose($f);
+ sort($networks);
+
+ return ['name' => $name,
+ 'ip' => $ip,
+ 'networks' => $networks,
+ 'upstream' => $upstream];
+ }
+
+ public static function networkAction()
+ {
+ $ok = self::callCommand("super musiikki-wlan", array($_POST['wlan']));
+
+ return $ok;
+ }
+
+ public static function essidAction()
+ {
+ if (!preg_match('/^[A-Za-z0-9_-]+$/', $_POST['name']))
+ return;
+
+ $ok = self::callCommand("super musiikki-essid", array($_POST['name'], $_POST['essid'], $_POST['psk']));
+
+ return $ok;
+ }
+