From c5f692263d7733edcbe773cf3cb071817b0e6ce6 Mon Sep 17 00:00:00 2001 From: Mark Pointing Date: Tue, 15 Dec 2020 18:05:07 +1000 Subject: [PATCH 1/4] Fixed function getWifiInterface for rpi0W. The old version would get 'wifi_client_interface' and 'ap_interface' reversed when rpi0W is used in AP-STA mode. This commit fixes the issue. --- includes/wifi_functions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index c4ec7c60..c2c432d2 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -53,7 +53,7 @@ function nearbyWifiStations(&$networks, $cached = true) $scan_results = cache( $cacheKey, function () { - exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan'); + exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan', $output, $returnval); sleep(3); exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results', $stdout); @@ -146,6 +146,14 @@ function getWifiInterface() $iface = $_SESSION['ap_interface'] = isset($arrHostapdConf['WifiInterface']) ? $arrHostapdConf['WifiInterface'] : RASPI_WIFI_AP_INTERFACE; // check for 2nd wifi interface -> wifi client on different interface exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); + $client_iface = $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); + + // specifically for rpi0W in AP-STA mode, the above check ends up with the interfaces + // crossed over (wifi_client_interface vs 'ap_interface'), because the second interface (uap0) is + // created by raspap and used as the access point. + if ($iface == "wlan0" && $client_iface = "uap0" && ($arrHostapdConf['WifiAPEnable'] ?? 0)){ + $_SESSION['wifi_client_interface'] = $iface; + $_SESSION['ap_interface'] = $client_iface; + } } From ed09f9b9da9f427ca20005bcdcf4dfd2b433b70f Mon Sep 17 00:00:00 2001 From: Mark Pointing Date: Tue, 15 Dec 2020 19:02:33 +1000 Subject: [PATCH 2/4] Cleaned up some debugging code identified when comparing PR. --- includes/wifi_functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index c2c432d2..040de215 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -53,7 +53,7 @@ function nearbyWifiStations(&$networks, $cached = true) $scan_results = cache( $cacheKey, function () { - exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan', $output, $returnval); + exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan'); sleep(3); exec('sudo wpa_cli -i ' .$_SESSION['wifi_client_interface']. ' scan_results', $stdout); From 12b69590daf274c8bb72a5fd8f12b4c3325ff510 Mon Sep 17 00:00:00 2001 From: Mark Pointing Date: Tue, 15 Dec 2020 10:45:27 +0000 Subject: [PATCH 3/4] Removed some band-aid fixes of incorrect client/ap interface identification function. --- includes/hostapd.php | 2 ++ includes/wifi_functions.php | 4 ++-- templates/configure_client.php | 9 +++------ templates/dashboard.php | 8 +++----- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 79b3ad02..9b698480 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -130,6 +130,8 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $status->addMessage('Attempting to set channel outside of permitted range', 'danger'); $good_input = false; } + + $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); // Check for Bridged AP mode checkbox $bridgedEnable = 0; diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 040de215..5b994dae 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -146,12 +146,12 @@ function getWifiInterface() $iface = $_SESSION['ap_interface'] = isset($arrHostapdConf['WifiInterface']) ? $arrHostapdConf['WifiInterface'] : RASPI_WIFI_AP_INTERFACE; // check for 2nd wifi interface -> wifi client on different interface exec("iw dev | awk '$1==\"Interface\" && $2!=\"$iface\" {print $2}'",$iface2); - $client_iface = $_SESSION['wifi_client_interface'] = empty($iface2) ? $iface : trim($iface2[0]); + $client_iface = $_SESSION['wifi_client_interface'] = (empty($iface2) ? $iface : trim($iface2[0])); // specifically for rpi0W in AP-STA mode, the above check ends up with the interfaces // crossed over (wifi_client_interface vs 'ap_interface'), because the second interface (uap0) is // created by raspap and used as the access point. - if ($iface == "wlan0" && $client_iface = "uap0" && ($arrHostapdConf['WifiAPEnable'] ?? 0)){ + if ($client_iface == "uap0" && ($arrHostapdConf['WifiAPEnable'] ?? 0)){ $_SESSION['wifi_client_interface'] = $iface; $_SESSION['ap_interface'] = $client_iface; } diff --git a/templates/configure_client.php b/templates/configure_client.php index afb3aeb3..567d858a 100755 --- a/templates/configure_client.php +++ b/templates/configure_client.php @@ -1,10 +1,7 @@ Date: Tue, 15 Dec 2020 15:04:55 +0000 Subject: [PATCH 4/4] Utility functions + param handling --- installers/raspbian.sh | 194 +++++++++++++++++++++++------------------ 1 file changed, 110 insertions(+), 84 deletions(-) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 35409dcf..9118b022 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -4,11 +4,12 @@ # Author: @billz # License: GNU General Public License v3.0 # -# Usage: +# Installs an instance of RaspAP. # +# Available options: # -y, --yes, --assume-yes # Assume "yes" as answer to all prompts and run non-interactively -# c, --cert, --certficate +# -c, --cert, --certficate # Installs mkcert and generates an SSL certificate for lighttpd # -o, --openvpn # Used with -y, --yes, sets OpenVPN install option (0=no install) @@ -35,93 +36,118 @@ # You are not obligated to bundle the LICENSE file with your RaspAP projects as long # as you leave these references intact in the header comments of your source files. -# Set defaults -repo="billz/raspap-webgui" -assume_yes=0 -upgrade=0 -ovpn_option=1 -adblock_option=1 - -# Define colors -readonly ANSI_RED="\033[0;31m" -readonly ANSI_GREEN="\033[0;32m" -readonly ANSI_YELLOW="\033[0;33m" -readonly ANSI_RASPBERRY="\033[0;35m" -readonly ANSI_ERROR="\033[1;37;41m" -readonly ANSI_RESET="\033[m" - -# Log output -readonly LOGFILE_PATH="/tmp" -exec > >(tee -i $LOGFILE_PATH/raspap_install.log) -exec 2>&1 - # Fetch latest release from GitHub API +repo="billz/raspap-webgui" #override with -r, --repo option readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' ) -branch="$RASPAP_LATEST" #override with the -b, --branch option +branch="$RASPAP_LATEST" #override with -b, --branch option + +function _setup_colors() { + ANSI_RED="\033[0;31m" + ANSI_GREEN="\033[0;32m" + ANSI_YELLOW="\033[0;33m" + ANSI_RASPBERRY="\033[0;35m" + ANSI_ERROR="\033[1;37;41m" + ANSI_RESET="\033[m" +} + +function _log_output() { + readonly LOGFILE_PATH="/tmp" + exec > >(tee -i $LOGFILE_PATH/raspap_install.log) + exec 2>&1 +} + +function _usage() { + cat << EOF +Usage: $(basename "$0") [OPTION] + +Installs an instance of RaspAP. + +Available options: +-y, --yes, --assume-yes + Assumes "yes" as an answer to all prompts +-c, --cert, --certificate + Installs an SSL certificate for lighttpd +-o, --openvpn + Used with -y, --yes, sets OpenVPN install option (0=no install) +-a, --adblock + Used with -y, --yes, sets Adblock install option (0=no install) +-r, --repo, --repository + Overrides the default GitHub repo (billz/raspap-webgui) +-b, --branch + Overrides the default git branch (latest release) +-h, --help + Outputs usage notes and exits +-u, --upgrade + Upgrades an existing installation to the latest release version +-v, --version + Outputs release info and exits -# Define usage notes -usage=$(cat << EOF -Usage: raspbian.sh [OPTION]\n --y, --yes, --assume-yes\n\tAssumes "yes" as an answer to all prompts --c, --cert, --certificate\n\tInstalls an SSL certificate for lighttpd --o, --openvpn \n\tUsed with -y, --yes, sets OpenVPN install option (0=no install) --a, --adblock \n\tUsed with -y, --yes, sets Adblock install option (0=no install) --r, --repo, --repository \n\tOverrides the default GitHub repo (billz/raspap-webgui) --b, --branch \n\tOverrides the default git branch (latest release) --h, --help\n\tOutputs usage notes and exits --u, --upgrade\n\tUpgrades an existing installation to the latest release version --v, --version\n\tOutputs release info and exits\n EOF -) + exit +} -# Parse command-line options -while :; do - case $1 in - -y|--yes|--assume-yes) - assume_yes=1 - apt_option="-y" - ;; - -o|--openvpn) - ovpn_option="$2" +function _parse_params() { + # default flag values + assume_yes=0 + upgrade=0 + ovpn_option=1 + adblock_option=1 + + while :; do + case ${1} in + -y|--yes|--assume-yes) + assume_yes=1 + apt_option="-y" + ;; + -o|--openvpn) + ovpn_option="$2" + shift + ;; + -a|--adblock) + adblock_option="$2" + shift + ;; + -c|--cert|--certificate) + install_cert=1 + ;; + -r|--repo|--repository) + repo="$2" + shift + ;; + -b|--branch) + branch="$2" + shift + ;; + -h|--help) + _usage + ;; + -u|--upgrade) + upgrade=1 + ;; + -v|--version) + _version + ;; + -*|--*) + echo "Unknown option: $1" + _usage + exit 1 + ;; + *) + break + ;; + esac shift - ;; - -a|--adblock) - adblock_option="$2" - shift - ;; - -c|--cert|--certificate) - install_cert=1 - ;; - -r|--repo|--repository) - repo="$2" - shift - ;; - -b|--branch) - branch="$2" - shift - ;; - -h|--help) - printf "$usage" - exit 1 - ;; - -u|--upgrade) - upgrade=1 - ;; - -v|--version) - printf "RaspAP v${RASPAP_LATEST} - Simple AP setup & WiFi management for Debian-based devices\n" - exit 1 - ;; - -*|--*) - echo "Unknown option: $1" - printf "$usage" - exit 1 - ;; - *) - break - ;; - esac - shift -done + done +} + +function _version() { + echo -e "RaspAP v${RASPAP_LATEST} - Simple AP setup & WiFi management for Debian-based devices" + exit +} + +_parse_params "$@" +_setup_colors +_log_output UPDATE_URL="https://raw.githubusercontent.com/$repo/$branch/" @@ -167,7 +193,7 @@ function _install_status() { function _update_system_packages() { _install_log "Updating sources" - sudo apt-get update || _install_error "Unable to update package list" + sudo apt-get update || _install_status 1 "Unable to update package list" } # Fetch required installer functions