From 199065e93f15651165d37a97b4d385df9c031267 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 24 Jun 2020 23:36:19 +0100 Subject: [PATCH 01/10] Update installer with upgrade option. Resolves #617 --- installers/common.sh | 200 +++++++++++++++++++++++------------------ installers/raspbian.sh | 7 ++ 2 files changed, 120 insertions(+), 87 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index b27b0684..d00384fe 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -30,12 +30,17 @@ git_source_url="https://github.com/$repo" # $repo from install.raspap.com # Prompts user to set installation options function _config_installation() { - _install_log "Configure installation" + if [ "$upgrade" == 1 ]; then + opt=(Upgrade Upgrading upgrade) + else + opt=(Install Installing installation) + fi + _install_log "Configure ${opt[2]}" _get_linux_distro echo "Detected OS: ${DESC}" echo "Using GitHub repository: ${repo} ${branch} branch" - echo "Install directory: ${raspap_dir}" - echo -n "Install to lighttpd root: ${webroot_dir}? [Y/n]: " + echo "Configuration directory: ${raspap_dir}" + echo -n "lighttpd root: ${webroot_dir}? [Y/n]: " if [ "$assume_yes" == 0 ]; then read answer < /dev/tty if [ "$answer" != "${answer#[Nn]}" ]; then @@ -44,8 +49,12 @@ function _config_installation() { else echo -e fi - echo "Installing to lighttpd directory: ${webroot_dir}" - echo -n "Complete installation with these values? [Y/n]: " + echo "${opt[1]} lighttpd directory: ${webroot_dir}" + if [ "$upgrade" == 1 ]; then + echo "This will upgrade your existing install to version ${RASPAP_LATEST}" + echo "Your configuration will NOT be changed" + fi + echo -n "Complete ${opt[2]} with these values? [Y/n]: " if [ "$assume_yes" == 0 ]; then read answer < /dev/tty if [ "$answer" != "${answer#[Nn]}" ]; then @@ -290,6 +299,12 @@ function _download_latest_files() { git clone --branch $branch --depth 1 $git_source_url /tmp/raspap-webgui || _install_status 1 "Unable to download files from github" sudo mv /tmp/raspap-webgui $webroot_dir || _install_status 1 "Unable to move raspap-webgui to web root" + if [ "$upgrade" == 1 ]; then + _install_log "Applying existing configuration to ${webroot_dir}/includes" + sudo mv /tmp/config.php $webroot_dir/includes || _install_status 1 "Unable to move config.php to ${webroot_dir}/includes" + sudo mv /tmp/defaults.php $webroot_dir/includes || _install_status 1 "Unable to move defaults.php to ${webroot_dir}/includes" + fi + _install_status 0 } @@ -305,33 +320,40 @@ function _change_file_ownership() { # Check for existing configuration files function _check_for_old_configs() { - if [ -f /etc/network/interfaces ]; then - sudo cp /etc/network/interfaces "$raspap_dir/backups/interfaces.`date +%F-%R`" - sudo ln -sf "$raspap_dir/backups/interfaces.`date +%F-%R`" "$raspap_dir/backups/interfaces" - fi - - if [ -f /etc/hostapd/hostapd.conf ]; then - sudo cp /etc/hostapd/hostapd.conf "$raspap_dir/backups/hostapd.conf.`date +%F-%R`" - sudo ln -sf "$raspap_dir/backups/hostapd.conf.`date +%F-%R`" "$raspap_dir/backups/hostapd.conf" - fi - - if [ -f $raspap_dnsmasq ]; then - sudo cp $raspap_dnsmasq "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`" - sudo ln -sf "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`" "$raspap_dir/backups/dnsmasq.conf" - fi - - if [ -f /etc/dhcpcd.conf ]; then - sudo cp /etc/dhcpcd.conf "$raspap_dir/backups/dhcpcd.conf.`date +%F-%R`" - sudo ln -sf "$raspap_dir/backups/dhcpcd.conf.`date +%F-%R`" "$raspap_dir/backups/dhcpcd.conf" - fi - - for file in /etc/systemd/network/raspap-*.net*; do - if [ -f "${file}" ]; then - filename=$(basename $file) - sudo cp "$file" "${raspap_dir}/backups/${filename}.`date +%F-%R`" - sudo ln -sf "${raspap_dir}/backups/${filename}.`date +%F-%R`" "${raspap_dir}/backups/${filename}" + if [ "$upgrade" == 1 ]; then + _install_log "Moving existing configuration to /tmp" + sudo mv $webroot_dir/includes/config.php /tmp || _install_status 1 "Unable to move config.php to /tmp" + sudo mv $webroot_dir/includes/defaults.php /tmp || _install_status 1 "Unable to move defaults.php to /tmp" + else + _install_log "Backing up existing configs to ${raspap_dir}/backups" + if [ -f /etc/network/interfaces ]; then + sudo cp /etc/network/interfaces "$raspap_dir/backups/interfaces.`date +%F-%R`" + sudo ln -sf "$raspap_dir/backups/interfaces.`date +%F-%R`" "$raspap_dir/backups/interfaces" fi - done + + if [ -f /etc/hostapd/hostapd.conf ]; then + sudo cp /etc/hostapd/hostapd.conf "$raspap_dir/backups/hostapd.conf.`date +%F-%R`" + sudo ln -sf "$raspap_dir/backups/hostapd.conf.`date +%F-%R`" "$raspap_dir/backups/hostapd.conf" + fi + + if [ -f $raspap_dnsmasq ]; then + sudo cp $raspap_dnsmasq "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`" + sudo ln -sf "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`" "$raspap_dir/backups/dnsmasq.conf" + fi + + if [ -f /etc/dhcpcd.conf ]; then + sudo cp /etc/dhcpcd.conf "$raspap_dir/backups/dhcpcd.conf.`date +%F-%R`" + sudo ln -sf "$raspap_dir/backups/dhcpcd.conf.`date +%F-%R`" "$raspap_dir/backups/dhcpcd.conf" + fi + + for file in /etc/systemd/network/raspap-*.net*; do + if [ -f "${file}" ]; then + filename=$(basename $file) + sudo cp "$file" "${raspap_dir}/backups/${filename}.`date +%F-%R`" + sudo ln -sf "${raspap_dir}/backups/${filename}.`date +%F-%R`" "${raspap_dir}/backups/${filename}" + fi + done + fi _install_status 0 } @@ -348,29 +370,31 @@ function _move_config_file() { # Set up default configuration function _default_configuration() { - _install_log "Applying default configuration to installed services" - if [ -f /etc/default/hostapd ]; then - sudo mv /etc/default/hostapd /tmp/default_hostapd.old || _install_status 1 "Unable to remove old /etc/default/hostapd file" + if [ "$upgrade" == 0 ]; then + _install_log "Applying default configuration to installed services" + if [ -f /etc/default/hostapd ]; then + sudo mv /etc/default/hostapd /tmp/default_hostapd.old || _install_status 1 "Unable to remove old /etc/default/hostapd file" + fi + sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || _install_status 1 "Unable to move hostapd defaults file" + sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file" + sudo cp $webroot_dir/config/dnsmasq.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file" + sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" + + echo "Checking for existence of /etc/dnsmasq.d" + [ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d + + echo "Copying bridged AP config to /etc/systemd/network" + sudo systemctl stop systemd-networkd + sudo systemctl disable systemd-networkd + sudo cp $webroot_dir/config/raspap-bridge-br0.netdev /etc/systemd/network/raspap-bridge-br0.netdev || _install_status 1 "Unable to move br0 netdev file" + sudo cp $webroot_dir/config/raspap-br0-member-eth0.network /etc/systemd/network/raspap-br0-member-eth0.network || _install_status 1 "Unable to move br0 member file" + + echo "Copying primary RaspAP config to includes/config.php" + if [ ! -f "$webroot_dir/includes/config.php" ]; then + sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php" + fi + _install_status 0 fi - sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || _install_status 1 "Unable to move hostapd defaults file" - sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file" - sudo cp $webroot_dir/config/dnsmasq.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file" - sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" - - echo "Checking for existence of /etc/dnsmasq.d" - [ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d - - echo "Copying bridged AP config to /etc/systemd/network" - sudo systemctl stop systemd-networkd - sudo systemctl disable systemd-networkd - sudo cp $webroot_dir/config/raspap-bridge-br0.netdev /etc/systemd/network/raspap-bridge-br0.netdev || _install_status 1 "Unable to move br0 netdev file" - sudo cp $webroot_dir/config/raspap-br0-member-eth0.network /etc/systemd/network/raspap-br0-member-eth0.network || _install_status 1 "Unable to move br0 member file" - - echo "Copying primary RaspAP config to includes/config.php" - if [ ! -f "$webroot_dir/includes/config.php" ]; then - sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php" - fi - _install_status 0 } # Install and enable RaspAP daemon @@ -453,51 +477,53 @@ function _patch_system_files() { # Optimize configuration of php-cgi. function _optimize_php() { - _install_log "Optimize PHP configuration" - if [ ! -f "$phpcgiconf" ]; then - _install_warning "PHP configuration could not be found." - return - fi - - # Backup php.ini and create symlink for restoring. - datetimephpconf=$(date +%F-%R) - sudo cp "$phpcgiconf" "$raspap_dir/backups/php.ini.$datetimephpconf" - sudo ln -sf "$raspap_dir/backups/php.ini.$datetimephpconf" "$raspap_dir/backups/php.ini" - - echo -n "Enable HttpOnly for session cookies (Recommended)? [Y/n]: " - if [ "$assume_yes" == 0 ]; then - read answer < /dev/tty - if [ "$answer" != "${answer#[Nn]}" ]; then - echo -e - else - php_session_cookie=1; + if [ "$upgrade" == 0 ]; then + _install_log "Optimize PHP configuration" + if [ ! -f "$phpcgiconf" ]; then + _install_warning "PHP configuration could not be found." + return fi - fi - if [ "$assume_yes" == 1 ] || [ "$php_session_cookie" == 1 ]; then - echo "Php-cgi enabling session.cookie_httponly." - sudo sed -i -E 's/^session\.cookie_httponly\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/session.cookie_httponly = 1/' "$phpcgiconf" - fi + # Backup php.ini and create symlink for restoring. + datetimephpconf=$(date +%F-%R) + sudo cp "$phpcgiconf" "$raspap_dir/backups/php.ini.$datetimephpconf" + sudo ln -sf "$raspap_dir/backups/php.ini.$datetimephpconf" "$raspap_dir/backups/php.ini" - if [ "$php_package" = "php7.1-cgi" ]; then - echo -n "Enable PHP OPCache (Recommended)? [Y/n]: " + echo -n "Enable HttpOnly for session cookies (Recommended)? [Y/n]: " if [ "$assume_yes" == 0 ]; then read answer < /dev/tty if [ "$answer" != "${answer#[Nn]}" ]; then echo -e else - php_opcache=1; + php_session_cookie=1; fi fi - if [ "$assume_yes" == 1 ] || [ "$phpopcache" == 1 ]; then - echo -e "Php-cgi enabling opcache.enable." - sudo sed -i -E 's/^;?opcache\.enable\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/opcache.enable = 1/' "$phpcgiconf" - # Make sure opcache extension is turned on. - if [ -f "/usr/sbin/phpenmod" ]; then - sudo phpenmod opcache - else - _install_status 2 "phpenmod not found." + if [ "$assume_yes" == 1 ] || [ "$php_session_cookie" == 1 ]; then + echo "Php-cgi enabling session.cookie_httponly." + sudo sed -i -E 's/^session\.cookie_httponly\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/session.cookie_httponly = 1/' "$phpcgiconf" + fi + + if [ "$php_package" = "php7.1-cgi" ]; then + echo -n "Enable PHP OPCache (Recommended)? [Y/n]: " + if [ "$assume_yes" == 0 ]; then + read answer < /dev/tty + if [ "$answer" != "${answer#[Nn]}" ]; then + echo -e + else + php_opcache=1; + fi + fi + + if [ "$assume_yes" == 1 ] || [ "$phpopcache" == 1 ]; then + echo -e "Php-cgi enabling opcache.enable." + sudo sed -i -E 's/^;?opcache\.enable\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/opcache.enable = 1/' "$phpcgiconf" + # Make sure opcache extension is turned on. + if [ -f "/usr/sbin/phpenmod" ]; then + sudo phpenmod opcache + else + _install_status 2 "phpenmod not found." + fi fi fi fi diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 1e30fa19..bc8c5aab 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -20,6 +20,8 @@ # Overrides the default git branch (master) # -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 # @@ -37,6 +39,7 @@ repo="billz/raspap-webgui" branch="master" assume_yes=0 +upgrade=0 ovpn_option=1 adblock_option=1 @@ -61,6 +64,7 @@ Usage: raspbian.sh [OPTION]\n -r, --repo, --repository \n\tOverrides the default GitHub repo (billz/raspap-webgui) -b, --branch \n\tOverrides the default git branch (master) -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 ) @@ -95,6 +99,9 @@ while :; do 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 From e5f2c218e1f2d05344dc9bae5f99701dae6e9a2d Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 16:58:42 +0100 Subject: [PATCH 02/10] Processed with phpcbf, removed tabs --- includes/internetRoute.php | 55 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index b91e15c2..715bc3c4 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -1,36 +1,39 @@ $route) { - $prop=explode(' ',$route); - $rInfo[$i]["interface"]=$prop[0]; - $rInfo[$i]["ip-address"]=$prop[1]; - $rInfo[$i]["gateway"]=$prop[2]; - // resolve the name of the gateway (if possible) - unset($host); - exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1',$host); - if (empty($host)) $host[0]="*"; - $rInfo[$i]["gw-name"] = $host[0]; - if (isset($checkAccess) && $checkAccess) { +exec('ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev (\w*).*src (([0-9]{1,3}\.){3}[0-9]{1,3}).*/\3 \4 \1/p"', $routes); +if (!empty($routes) ) { + foreach ($routes as $i => $route) { + $prop=explode(' ', $route); + $rInfo[$i]["interface"]=$prop[0]; + $rInfo[$i]["ip-address"]=$prop[1]; + $rInfo[$i]["gateway"]=$prop[2]; + // resolve the name of the gateway (if possible) + unset($host); + exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1', $host); + if (empty($host)) { + $host[0]="*"; + } + $rInfo[$i]["gw-name"] = $host[0]; + if (isset($checkAccess) && $checkAccess) { // check internet connectivity w/ and w/o DNS resolution unset($okip); - exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okip); - if (empty($okip)) $okip[0]="failed"; + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"', $okip); + if (empty($okip)) { + $okip[0]="failed"; + } $rInfo[$i]["access-ip"] = $okip[0]; unset($okdns); - exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"',$okdns); - if (empty($okdns)) $okdns[0]="failed"; + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"', $okdns); + if (empty($okdns)) { + $okdns[0]="failed"; + } $rInfo[$i]["access-dns"] = $okdns[0]; - } } - } else { - $rInfo = array("error"=>"No route to the internet found"); - } - $rInfo_json = json_encode($rInfo); + } +} else { + $rInfo = array("error"=>"No route to the internet found"); +} +$rInfo_json = json_encode($rInfo); ?> From c4e2faa25ab2f95e629b3c695f179578d454931c Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:01:32 +0100 Subject: [PATCH 03/10] Update networking msg --- locale/en_US/LC_MESSAGES/messages.po | 3 +++ 1 file changed, 3 insertions(+) diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po index 70a9b06e..1ce53d99 100644 --- a/locale/en_US/LC_MESSAGES/messages.po +++ b/locale/en_US/LC_MESSAGES/messages.po @@ -451,6 +451,9 @@ msgstr "Configures the max_num_sta option of hostapd. The default and maximum is msgid "Summary" msgstr "Summary" +msgid "Internet connection" +msgstr "Internet connection" + msgid "Current settings" msgstr "Current settings" From 8647673d9a46285be06f5ed16d515b3a147fca4c Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:02:07 +0100 Subject: [PATCH 04/10] Move + rename constants --- config/config.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/config.php b/config/config.php index 2c3c9e8a..4e73ec2b 100755 --- a/config/config.php +++ b/config/config.php @@ -23,6 +23,9 @@ define('RASPI_OPENVPN_CLIENT_LOGIN', '/etc/openvpn/client/login.conf'); define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server/server.conf'); define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc'); define('RASPI_LIGHTTPD_CONFIG', '/etc/lighttpd/lighttpd.conf'); +define('RASPI_ACCESS_CHECK_IP', '1.1.1.1'); +define('RASPI_ACCESS_CHECK_DNS', 'one.one.one.one'); + // Constant for the 5GHz wireless regulatory domain define('RASPI_5GHZ_ISO_ALPHA2', array('US')); From 9afb773ab3241deb89711f23b672ffd1b768d16a Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:07:38 +0100 Subject: [PATCH 05/10] Minor: remove newline --- config/config.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/config.php b/config/config.php index 4e73ec2b..bfe464f6 100755 --- a/config/config.php +++ b/config/config.php @@ -26,7 +26,6 @@ define('RASPI_LIGHTTPD_CONFIG', '/etc/lighttpd/lighttpd.conf'); define('RASPI_ACCESS_CHECK_IP', '1.1.1.1'); define('RASPI_ACCESS_CHECK_DNS', 'one.one.one.one'); - // Constant for the 5GHz wireless regulatory domain define('RASPI_5GHZ_ISO_ALPHA2', array('US')); From 36141d1e9cce46280e05d9fec61c6b57e3e279c5 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:08:29 +0100 Subject: [PATCH 06/10] Update defaults w/ new constants --- includes/defaults.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/defaults.php b/includes/defaults.php index 524960f5..e1346112 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -27,6 +27,8 @@ $defaults = [ 'RASPI_OPENVPN_SERVER_CONFIG' => '/etc/openvpn/server/server.conf', 'RASPI_TORPROXY_CONFIG' => '/etc/tor/torrc', 'RASPI_LIGHTTPD_CONFIG' => '/etc/lighttpd/lighttpd.conf', + 'RASPI_ACCESS_CHECK_IP' => '1.1.1.1', + 'RASPI_ACCESS_CHECK_DNS' => 'one.one.one.one', // Optional services, set to true to enable. 'RASPI_WIFICLIENT_ENABLED' => true, From d878cbf356ea9a4f19c5c10c57a503daa920de14 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 28 Jun 2020 17:12:42 +0100 Subject: [PATCH 07/10] Processed with phpcbf --- templates/networking.php | 49 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/templates/networking.php b/templates/networking.php index a08fa884..455544bd 100755 --- a/templates/networking.php +++ b/templates/networking.php @@ -17,16 +17,15 @@ $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); // defaults to false $bridgedEnabled = $arrHostapdConf['BridgedEnable']; - ?> - - - + ?> + + + - +
-

@@ -45,21 +44,21 @@ No route to the internet found"; - } else { - foreach($rInfo as $route) { - echo ""; - echo "".$route["interface"].""; - echo "".$route["ip-address"].""; - echo "".$route["gateway"]."
".$route["gw-name"].""; - echo "".$route["access-ip"]."
".ACCESS_CHECK_IP.""; - echo "".$route["access-dns"]."
".ACCESS_CHECK_DNS.""; - echo ""; - } - } + } else { + foreach($rInfo as $route) { + echo ""; + echo "".$route["interface"].""; + echo "".$route["ip-address"].""; + echo "".$route["gateway"]."
".$route["gw-name"].""; + echo "".$route["access-ip"]."
".RASPI_ACCESS_CHECK_IP.""; + echo "".$route["access-dns"]."
".RASPI_ACCESS_CHECK_DNS.""; + echo ""; + } + } ?> @@ -71,7 +70,7 @@

- +
@@ -90,7 +89,7 @@
- +
@@ -140,10 +139,10 @@
-
- +
+ - + From 4623060f08b97af2300600d08058272b5274ce65 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Mon, 29 Jun 2020 13:12:29 +0200 Subject: [PATCH 08/10] Simplify and cleanup handling of return values of system calls Handling of return values done in a single line. Determine only, if access is possible not not (true, false). The actual displayed text has to be determined, when displaying the result of the access check. --- includes/internetRoute.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index 715bc3c4..db04d685 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -12,24 +12,15 @@ if (!empty($routes) ) { // resolve the name of the gateway (if possible) unset($host); exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1', $host); - if (empty($host)) { - $host[0]="*"; - } - $rInfo[$i]["gw-name"] = $host[0]; + $rInfo[$i]["gw-name"] = empty($host) ? "*" : $host[0]; if (isset($checkAccess) && $checkAccess) { // check internet connectivity w/ and w/o DNS resolution unset($okip); - exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"', $okip); - if (empty($okip)) { - $okip[0]="failed"; - } - $rInfo[$i]["access-ip"] = $okip[0]; + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okip); + $rInfo[$i]["access-ip"] = empty($okip) ? false : true; unset($okdns); - exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/\&check\;/p"', $okdns); - if (empty($okdns)) { - $okdns[0]="failed"; - } - $rInfo[$i]["access-dns"] = $okdns[0]; + exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okdns); + $rInfo[$i]["access-dns"] = empty($okdns) ? false : true; } } } else { From 33a099de61eef44c0a639d7b53f2dd2d493ad4a2 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Mon, 29 Jun 2020 13:16:55 +0200 Subject: [PATCH 09/10] Define displayed text for internet access --- templates/networking.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/networking.php b/templates/networking.php index 455544bd..b566a91d 100755 --- a/templates/networking.php +++ b/templates/networking.php @@ -54,8 +54,10 @@ echo "".$route["interface"].""; echo "".$route["ip-address"].""; echo "".$route["gateway"]."
".$route["gw-name"].""; - echo "".$route["access-ip"]."
".RASPI_ACCESS_CHECK_IP.""; - echo "".$route["access-dns"]."
".RASPI_ACCESS_CHECK_DNS.""; + $checkok = $route["access-ip"] ? "✓" : "failed"; + echo "".$checkok."
".RASPI_ACCESS_CHECK_IP.""; + $checkok = $route["access-dns"] ? "✓" : "failed"; + echo "".$checkok."
".RASPI_ACCESS_CHECK_DNS.""; echo ""; } } From 42032e0df0921a53f66326efe13877a172f075cd Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Mon, 29 Jun 2020 13:36:38 +0200 Subject: [PATCH 10/10] Typo corrected --- includes/internetRoute.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/internetRoute.php b/includes/internetRoute.php index db04d685..78207a61 100644 --- a/includes/internetRoute.php +++ b/includes/internetRoute.php @@ -16,10 +16,10 @@ if (!empty($routes) ) { if (isset($checkAccess) && $checkAccess) { // check internet connectivity w/ and w/o DNS resolution unset($okip); - exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okip); + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okip); $rInfo[$i]["access-ip"] = empty($okip) ? false : true; unset($okdns); - exec('ping -W1 -c 1 -I '.$prop[0].' '.ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okdns); + exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okdns); $rInfo[$i]["access-dns"] = empty($okdns) ? false : true; } }