From 2ca5f25dff321d0f47008ef57a9d42becfd3241d Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 25 Nov 2021 09:02:59 +0000 Subject: [PATCH] Merge First Edition of RaspAP/raspap-insiders --- app/css/lightsout.css | 2 +- app/img/wifi-qr-code.php | 13 +++ app/js/custom.js | 24 +----- config/config.php | 6 -- includes/adblock.php | 2 +- includes/dashboard.php | 170 +++++++++++++++++++++----------------- includes/defaults.php | 2 +- includes/dhcp.php | 4 +- includes/functions.php | 8 +- includes/networking.php | 12 +-- index.php | 14 +--- installers/common.sh | 6 +- installers/raspap.sudoers | 7 +- templates/dashboard.php | 166 +++++++++++-------------------------- templates/networking.php | 120 +-------------------------- 15 files changed, 177 insertions(+), 379 deletions(-) diff --git a/app/css/lightsout.css b/app/css/lightsout.css index 19ca7c5a..aa42b720 100644 --- a/app/css/lightsout.css +++ b/app/css/lightsout.css @@ -378,7 +378,7 @@ tspan, rect { fill: #d2d2d2; } -text-muted { +.text-muted { font-size: 0.8rem; } diff --git a/app/img/wifi-qr-code.php b/app/img/wifi-qr-code.php index e2baf69b..a36966c3 100644 --- a/app/img/wifi-qr-code.php +++ b/app/img/wifi-qr-code.php @@ -10,12 +10,25 @@ if (!isset($_SERVER['HTTP_REFERER'])) { exit; } +function qr_encode($str) +{ + return preg_replace('/(?showMessages(); return; } - - // ------------------------- Button pressed to switch client on/off --------------------------------------------------------- - $switchedOn = false; - if (!RASPI_MONITOR_ENABLED) { - if (isset($_POST['ifdown_wlan0'])) { - // Pressed stop button - $status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); - setClientState("down"); - $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); - } elseif (isset($_POST['ifup_wlan0'])) { - // Pressed start button - $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); - setClientState("up"); - $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); - $switchedOn = true; - } - } - - - // ----------------------------- INFOS ABOUT THE ACCESS POINT ------------------------------------------------------------- - exec('ip a show '.$_SESSION['ap_interface'], $stdoutIp); $stdoutIpAllLinesGlued = implode(" ", $stdoutIp); $stdoutIpWRepeatedSpaces = preg_replace('/\s\s+/', ' ', $stdoutIpAllLinesGlued); @@ -110,40 +88,103 @@ function DisplayDashboard(&$extraFooterScripts) $strTxBytes .= getHumanReadableDatasize($strTxBytes); } - // ------------------------ INFOS ABOUT THE CLIENT--------------------------------------------------------------- - $clientinfo=array("name"=>"none","type"=>-1,"connected"=>"n"); - $raspi_client=$_SESSION['wifi_client_interface']; - loadClientConfig(); - $all_clients = getClients(false); - $clientinfo = array("name" => "none", "connected" => "n"); - if ( ($idx = findCurrentClientIndex($all_clients)) >= 0) $clientinfo = $all_clients["device"][$idx]; - if ($clientinfo["name"] != "none") $raspi_client = $clientinfo["name"]; - $interfaceState = $clientinfo["connected"] == "y" ? 'UP' : 'DOWN'; - $txPower=""; - if ($clientinfo["type"] == "wlan") { - // txpower is now displayed on iw dev(..) info command, not on link command. - exec('iw dev '.$clientinfo["name"].' info | sed -rn "s/.*txpower ([0-9]*)[0-9\.]*( dBm).*/\1\2/p"', $stdoutIwInfo); - if (!empty($stdoutIwInfo)) $txPower=$stdoutIwInfo[0]; + define('SSIDMAXLEN', 32); + // Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable." + exec('iw dev ' .$_SESSION['wifi_client_interface']. ' link ', $stdoutIw); + $stdoutIwAllLinesGlued = implode('+', $stdoutIw); // Break lines with character illegal in SSID and MAC addr + $stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued); + + preg_match('/Connected to (([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}))/', $stdoutIwWRepSpaces, $matchesBSSID) || $matchesBSSID[1] = ''; + $connectedBSSID = $matchesBSSID[1]; + $connectedBSSID = empty($connectedBSSID) ? "-" : $connectedBSSID; + + $wlanHasLink = false; + if ($interfaceState === 'UP') { + $wlanHasLink = true; } - + + if (!preg_match('/SSID: ([^+]{1,'.SSIDMAXLEN.'})/', $stdoutIwWRepSpaces, $matchesSSID)) { + $wlanHasLink = false; + $matchesSSID[1] = 'None'; + } + + $connectedSSID = $matchesSSID[1]; + + preg_match('/freq: (\d+)/i', $stdoutIwWRepSpaces, $matchesFrequency) || $matchesFrequency[1] = ''; + $frequency = $matchesFrequency[1].' MHz'; + + preg_match('/signal: (-?[0-9]+ dBm)/i', $stdoutIwWRepSpaces, $matchesSignal) || $matchesSignal[1] = ''; + $signalLevel = $matchesSignal[1]; + $signalLevel = empty($signalLevel) ? "-" : $signalLevel; + + preg_match('/tx bitrate: ([0-9\.]+ [KMGT]?Bit\/s)/', $stdoutIwWRepSpaces, $matchesBitrate) || $matchesBitrate[1] = ''; + $bitrate = $matchesBitrate[1]; + $bitrate = empty($bitrate) ? "-" : $bitrate; + + // txpower is now displayed on iw dev(..) info command, not on link command. + exec('iw dev '.$_SESSION['wifi_client_interface'].' info ', $stdoutIwInfo); + $stdoutIwInfoAllLinesGlued = implode(' ', $stdoutIwInfo); + $stdoutIpInfoWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwInfoAllLinesGlued); + + preg_match('/txpower ([0-9\.]+ dBm)/i', $stdoutIpInfoWRepSpaces, $matchesTxPower) || $matchesTxPower[1] = ''; + $txPower = $matchesTxPower[1]; + + // iw does not have the "Link Quality". This is a is an aggregate value, + // and depends on the driver and hardware. + // Display link quality as signal quality for now. + $strLinkQuality = 0; + if ($signalLevel > -100 && $wlanHasLink) { + if ($signalLevel >= 0) { + $strLinkQuality = 100; + } else { + $strLinkQuality = 100 + intval($signalLevel); + } + } + + $wlan0up = false; $classMsgDevicestatus = 'warning'; if ($interfaceState === 'UP') { + $wlan0up = true; $classMsgDevicestatus = 'success'; } - if ($switchedOn) exec('sudo ip -s a f label ' . $raspi_client); - + if (!RASPI_MONITOR_ENABLED) { + if (isset($_POST['ifdown_wlan0'])) { + // Pressed stop button + if ($interfaceState === 'UP') { + $status->addMessage(sprintf(_('Interface is going %s.'), _('down')), 'warning'); + exec('sudo ip link set '.$_SESSION['wifi_client_interface'].' down'); + $wlan0up = false; + $status->addMessage(sprintf(_('Interface is now %s.'), _('down')), 'success'); + } elseif ($interfaceState === 'unknown') { + $status->addMessage(_('Interface state unknown.'), 'danger'); + } else { + $status->addMessage(sprintf(_('Interface already %s.'), _('down')), 'warning'); + } + } elseif (isset($_POST['ifup_wlan0'])) { + // Pressed start button + if ($interfaceState === 'DOWN') { + $status->addMessage(sprintf(_('Interface is going %s.'), _('up')), 'warning'); + exec('sudo ip link set ' .$_SESSION['wifi_client_interface']. ' up'); + exec('sudo ip -s a f label ' . $_SESSION['wifi_client_interface']); + $wlan0up = true; + $status->addMessage(sprintf(_('Interface is now %s.'), _('up')), 'success'); + } elseif ($interfaceState === 'unknown') { + $status->addMessage(_('Interface state unknown.'), 'danger'); + } else { + $status->addMessage(sprintf(_('Interface already %s.'), _('up')), 'warning'); + } + } else { + $status->addMessage(sprintf(_('Interface is %s.'), strtolower($interfaceState)), $classMsgDevicestatus); + } + } // brought in from template $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); $bridgedEnable = $arrHostapdConf['BridgedEnable']; - if ($arrHostapdConf['WifiAPEnable'] == 1) { - $client_interface = 'uap0'; - } else { - $client_interface = $clientinfo["name"]; - } + $clientInterface = $_SESSION['wifi_client_interface']; $apInterface = $_SESSION['ap_interface']; - $clientInterface = $raspi_client; $MACPattern = '"([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}"'; + if (getBridgedState()) { $moreLink = "hostapd_conf"; exec('iw dev ' . $apInterface . ' station dump | grep -oE ' . $MACPattern, $clients); @@ -151,39 +192,11 @@ function DisplayDashboard(&$extraFooterScripts) $moreLink = "dhcpd_conf"; exec('cat ' . RASPI_DNSMASQ_LEASES . '| grep -E $(iw dev ' . $apInterface . ' station dump | grep -oE ' . $MACPattern . ' | paste -sd "|")', $clients); } - $ifaceStatus = $clientinfo["connected"]=="y" ? "up" : "down"; - $isClientConfigured = true; - switch($clientinfo["type"]) { - case "eth": - case "usb": - $client_title = "Client: Ethernet cable"; - $type_name = "Ethernet"; - break; - case "phone": - $client_title = "Client: Smartphone (USB tethering)"; - $type_name = "Smartphone"; - break; - case "wlan": - $client_title = "Wireless Client"; - $type_name = "Wifi"; - break; - case "ppp": - case "hilink": - $client_title = "Mobile Data Client"; - $type_name = "Mobile Data"; - break; - default: - $client_title = "No information available"; - $type_name = "Not configured"; - $ifaceStatus = "warn"; - $isClientConfigured = false; - } + $ifaceStatus = $wlan0up ? "up" : "down"; echo renderTemplate( "dashboard", compact( "clients", - "client_title", - "type_name", "moreLink", "apInterface", "clientInterface", @@ -198,9 +211,14 @@ function DisplayDashboard(&$extraFooterScripts) "strRxBytes", "strTxPackets", "strTxBytes", + "connectedSSID", + "connectedBSSID", + "bitrate", + "signalLevel", "txPower", - "clientinfo", - "isClientConfigured" + "frequency", + "strLinkQuality", + "wlan0up" ) ); $extraFooterScripts[] = array('src'=>'app/js/dashboardchart.js', 'defer'=>false); diff --git a/includes/defaults.php b/includes/defaults.php index 3ba8d848..52b27276 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -6,7 +6,7 @@ if (!defined('RASPI_CONFIG')) { $defaults = [ 'RASPI_BRAND_TEXT' => 'RaspAP', - 'RASPI_VERSION' => '2.8.0', + 'RASPI_VERSION' => '2.7.1', 'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json', 'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', 'RASPI_WIFI_AP_INTERFACE' => 'wlan0', diff --git a/includes/dhcp.php b/includes/dhcp.php index 3e53017a..850d5847 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -180,9 +180,7 @@ function compareIPs($ip1, $ip2) function updateDnsmasqConfig($iface,$status) { $config = '# RaspAP '.$iface.' configuration'.PHP_EOL; - $config .= 'interface='.$iface.PHP_EOL. - 'dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd']. - ',255.255.255.0,'; + $config .= 'interface='.$iface.PHP_EOL.'dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd'].','.$_POST['SubnetMask'].','; if ($_POST['RangeLeaseTimeUnits'] !== 'infinite') { $config .= $_POST['RangeLeaseTime']; } diff --git a/includes/functions.php b/includes/functions.php index b3574023..81e642ed 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -757,8 +757,12 @@ function qr_encode($str) return preg_replace('/(? \ No newline at end of file diff --git a/index.php b/index.php index 00454c54..994aba5b 100755 --- a/index.php +++ b/index.php @@ -14,8 +14,8 @@ * @author Lawrence Yau * @author Bill Zimmerman * @license GNU General Public License, version 3 (GPL-3.0) - * @version 2.8.0 - * @link https://github.com/raspap/raspap-insiders/ + * @version 2.7.1 + * @link https://github.com/raspap/raspap-webgui/ * @link https://raspap.com/ * @see http://sirlagz.net/2013/02/08/raspap-webgui/ * @@ -41,7 +41,6 @@ require_once 'includes/system.php'; require_once 'includes/sysstats.php'; require_once 'includes/configure_client.php'; require_once 'includes/networking.php'; -require_once 'includes/firewall.php'; require_once 'includes/themes.php'; require_once 'includes/data_usage.php'; require_once 'includes/about.php'; @@ -176,11 +175,6 @@ $bridgedEnabled = getBridgedState(); - - - @@ -280,8 +274,8 @@ $bridgedEnabled = getBridgedState(); case "/torproxy_conf": DisplayTorProxyConfig(); break; - case "/firewall_conf": - DisplayFirewallConfig(); + case "/torproxy_conf": + DisplayTorProxyConfig(); break; case "/auth_conf": DisplayAuthConfig($config['admin_user'], $config['admin_pass']); diff --git a/installers/common.sh b/installers/common.sh index 00d6f513..2f10867c 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -139,10 +139,10 @@ function _get_linux_distro() { # Sets php package option based on Linux version, abort if unsupported distro function _set_php_package() { case $RELEASE in - 18.04|19.10|11*) # Ubuntu Server & Debian 11 + 18.04|19.10|11*) # Ubuntu Server & Debian 11 php_package="php7.4-cgi" phpcgiconf="/etc/php/7.4/cgi/php.ini" ;; - 10*) + 10*|11*) php_package="php7.3-cgi" phpcgiconf="/etc/php/7.3/cgi/php.ini" ;; 9*) @@ -159,7 +159,7 @@ function _set_php_package() { function _install_dependencies() { _install_log "Installing required packages" _set_php_package - if [ "$php_package" = "php7.4-cgi" ] && [ ${OS,,} = "ubuntu" ]; then + if [ "$php_package" = "php7.4-cgi" ] && [ ${OS,,} = "ubuntu" ]; then echo "Adding apt-repository ppa:ondrej/php" sudo apt-get install $apt_option software-properties-common || _install_status 1 "Unable to install dependency" sudo add-apt-repository $apt_option ppa:ondrej/php || _install_status 1 "Unable to add-apt-repository ppa:ondrej/php" diff --git a/installers/raspap.sudoers b/installers/raspap.sudoers index c7bbac5c..db5154e5 100644 --- a/installers/raspap.sudoers +++ b/installers/raspap.sudoers @@ -62,9 +62,4 @@ www-data ALL=(ALL) NOPASSWD:/bin/cat /etc/wireguard/*.conf www-data ALL=(ALL) NOPASSWD:/bin/cat /etc/wireguard/wg-*.key www-data ALL=(ALL) NOPASSWD:/bin/rm /etc/wireguard/*.conf www-data ALL=(ALL) NOPASSWD:/bin/rm /etc/wireguard/wg-*.key -www-data ALL=(ALL) NOPASSWD:/tmp/iptables_raspap.sh -www-data ALL=(ALL) NOPASSWD:/tmp/ip6tables_raspap.sh -www-data ALL=(ALL) NOPASSWD:/usr/sbin/iptables-save -www-data ALL=(ALL) NOPASSWD:/usr/sbin/ip6tables-save -www-data ALL=(ALL) NOPASSWD:/usr/bin/tee /etc/iptables/rules.v4 -www-data ALL=(ALL) NOPASSWD:/usr/bin/tee /etc/iptables/rules.v6 + diff --git a/templates/dashboard.php b/templates/dashboard.php index 113d004d..597dc6b5 100755 --- a/templates/dashboard.php +++ b/templates/dashboard.php @@ -3,17 +3,18 @@
-
- -
-
- -
+
+ +
+
+ +
+
@@ -32,97 +33,37 @@
-

+

- - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
- - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
'.$gw.""; ?>
-
- -
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
- +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ +
- -
- - -
- -
-
-
@@ -152,7 +93,7 @@ - + @@ -176,41 +117,28 @@
+
- + - - " name="ifup_wlan0" data-toggle="modal" data-target="#switchClientModal"/> - - " name="ifdown_wlan0" data-toggle="modal" data-target="#switchClientModal"/> + + " name="ifup_wlan0" /> + + " name="ifdown_wlan0" /> - +
+
- - -