From 59a99ee3af551a8dfd3ead685cd7f21468c28628 Mon Sep 17 00:00:00 2001 From: njkeng Date: Tue, 27 Feb 2018 21:21:41 +1000 Subject: [PATCH 01/20] Mobile friendly page Original page extends a long way to the right on mobile devices. This re-format contains the same data and controls, but narrows the size of the display. The page now displays on mobile devices with no need for scrolling to the right. --- includes/configure_client.php | 125 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 59 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index 206e6dc22..291850f10 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -163,70 +163,77 @@ function DisplayWPAConfig(){

showMessages(); ?>

-

Client settings for interface

-
- Rescan -
-
- - - - - - - - - - - - - $network) { ?> - - - - - - - - - - - - - - - +
+ +
Channel
+ + + + X + +
+ + +
Security
+
+ +
Passphrase
+ + --- + + + +
+ +
+ + /> + + /> + + /> +
+ + + + + + + -
SSIDChannelSecurityPassphrase
- - - - - - - - - - X - - - - - --- - - -
+

Interface

+ +
+ Rescan +
+ + + + + + + $network) { ?> + +
+
+
+ + + +

+
+ +
Status
- /> - - /> + + + + - /> -
-
+
- + From f9259b8fc6bd832e96db46f832086b335544d67f Mon Sep 17 00:00:00 2001 From: njkeng Date: Sun, 11 Mar 2018 21:59:24 +1000 Subject: [PATCH 02/20] Added reset script The reset script restores the default RaspAP configuration files. Basically this is a "factory reset" for the device. This script is to be triggered using a physical push button. --- installers/common.sh | 17 ++++++++++++----- installers/reset.sh | 12 ++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 installers/reset.sh diff --git a/installers/common.sh b/installers/common.sh index abf488b38..c1cc62f6b 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -117,6 +117,11 @@ function create_logging_scripts() { sudo mv /var/www/html/installers/*log.sh /etc/raspap/hostapd } +# Generate configuration reset files for raspap +function create_reset_script() { + sudo mv /var/www/html/installers/reset.sh /etc/raspap/hostapd +} + # Fetches latest files from github to webroot function download_latest_files() { if [ -d "$webroot_dir" ]; then @@ -183,16 +188,17 @@ function default_configuration() { if [ -f /etc/default/hostapd ]; then sudo mv /etc/default/hostapd /tmp/default_hostapd.old || install_error "Unable to remove old /etc/default/hostapd file" fi - sudo mv $webroot_dir/config/default_hostapd /etc/default/hostapd || install_error "Unable to move hostapd defaults file" - sudo mv $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || install_error "Unable to move hostapd configuration file" - sudo mv $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || install_error "Unable to move dnsmasq configuration file" - sudo mv $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || install_error "Unable to move dhcpcd configuration file" + sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || install_error "Unable to move hostapd defaults file" + sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || install_error "Unable to move hostapd configuration file" + sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || install_error "Unable to move dnsmasq configuration file" + sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || install_error "Unable to move dhcpcd configuration file" # Generate required lines for Rasp AP to place into rc.local file. # #RASPAP is for removal script lines=( - 'echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP' + 'echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward #RASPAP' 'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP' + '~pi\/shutdown-press-simple.py \& #RASPAP' ) for line in "${lines[@]}"; do @@ -290,6 +296,7 @@ function install_raspap() { download_latest_files change_file_ownership create_logging_scripts + create_reset_script move_config_file default_configuration patch_system_files diff --git a/installers/reset.sh b/installers/reset.sh new file mode 100644 index 000000000..4c5dbfe6c --- /dev/null +++ b/installers/reset.sh @@ -0,0 +1,12 @@ + +function reset_default_configuration() { + if [ -f /etc/default/hostapd ]; then + sudo mv /etc/default/hostapd /tmp/default_hostapd.old || echo -e "Unable to remove old /etc/default/hostapd file" + fi + sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || echo -e "Unable to move hostapd defaults file" + sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || echo -e "Unable to move hostapd configuration file" + sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || echo -e "Unable to move dnsmasq configuration file" + sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || echo -e "Unable to move dhcpcd configuration file" +} + +reset_default_configuration From 5f1589a5bb00bcf45aef843f6f9fbdc40d71c1f2 Mon Sep 17 00:00:00 2001 From: njkeng Date: Mon, 12 Mar 2018 12:03:49 +1000 Subject: [PATCH 03/20] Properly substitute forward slashes in directory names --- installers/common.sh | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index c1cc62f6b..318dbf1fc 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -111,15 +111,10 @@ function create_logging_scripts() { sudo mv $webroot_dir/installers/*log.sh $raspap_dir/hostapd || install_error "Unable to move logging scripts" } -# Generate logging enable/disable files for hostapd -function create_logging_scripts() { - sudo mkdir /etc/raspap/hostapd - sudo mv /var/www/html/installers/*log.sh /etc/raspap/hostapd -} - # Generate configuration reset files for raspap -function create_reset_script() { +function create_reset_scripts() { sudo mv /var/www/html/installers/reset.sh /etc/raspap/hostapd + sudo mv /var/www/html/installers/button.py /etc/raspap/hostapd } # Fetches latest files from github to webroot @@ -196,16 +191,16 @@ function default_configuration() { # Generate required lines for Rasp AP to place into rc.local file. # #RASPAP is for removal script lines=( - 'echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward #RASPAP' - 'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP' - '~pi\/shutdown-press-simple.py \& #RASPAP' + "echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP" + "iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP" + "$raspaspap_dir/button.py & #RASPAP" ) for line in "${lines[@]}"; do if grep "$line" /etc/rc.local > /dev/null; then echo "$line: Line already added" else - sed -i "s/exit 0/$line\nexit0/" /etc/rc.local + sed -i "s?exit 0?$line\nexit 0?" /etc/rc.local echo "Adding line $line" fi done @@ -296,7 +291,7 @@ function install_raspap() { download_latest_files change_file_ownership create_logging_scripts - create_reset_script + create_reset_scripts move_config_file default_configuration patch_system_files From f7c9b4eeb6e3b25b80dc4493780f30bf10c7b50d Mon Sep 17 00:00:00 2001 From: njkeng Date: Mon, 12 Mar 2018 12:04:12 +1000 Subject: [PATCH 04/20] Add script to handle button pressses --- installers/button.py | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 installers/button.py diff --git a/installers/button.py b/installers/button.py new file mode 100644 index 000000000..1c191a4cb --- /dev/null +++ b/installers/button.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +from gpiozero import Button, LED +from signal import pause +import os, sys + +# Define the location of the script to restore default configuration +defaultsscriptlocation = int(sys.argv[1]) if len(sys.argv) >= 1 else "/etc/raspap/hostapd/reset.sh" + +buttonGPIO = 21 # Pushbutton is connected to GPIO 21 (pin 40) +LEDGPIO = 20 # LED is connected to GPIO 20 (pin 38) + +restarttime = 1 # restart if held for greater than restarttime seconds +offtime = 6 # shut down if held for greater than offtime seconds +defaultstime = 15 # reset RaspAP to default config if held for greater than defaultstime seconds + +resetready = False +shutdownready = False +defaultsready = False + +def when_held(): + # find how long the button has been held + ptime = b.pressed_time + + # blink rate will increase the longer we hold + # Set flags for the action needed when the button is released + if ptime > restarttime && ptime < offtime: + led.blink(on_time=0.5/p, off_time=0.5/p) + resetready = True + shutdownready = False + defaultsready = False + + + if ptime > offtime && ptime < defaultstime: + led.blink(on_time=0.25/p, off_time=0.25/p) + resetready = False + shutdownready = True + defaultsready = False + + + if ptime > defaultstime: + led.blink(on_time=0.1/p, off_time=0.1/p) + resetready = False + shutdownready = False + defaultsready = True + + +def when_released(): + # turn the LEDs off if we release early + led.off() + + if resetready == True: + os.system("sudo restart") + + if shutdownready == True: + os.system("sudo poweroff") + + if defaultsready == True: + os.system("sudo " + defaultsscriptlocation) + os.system("sudo restart") + + # clear flags if we release early + resetready = False + shutdownready = False + defaultsready = False + + +led = LED(LEDGPIO) + +btn = Button(buttonGPIO, hold_time=restarttime, hold_repeat=True) +btn.when_held = when_held +btn.when_released = when_released +pause() \ No newline at end of file From a6f3764dc66caafbfdc30079e117cff8df8437a9 Mon Sep 17 00:00:00 2001 From: njkeng Date: Tue, 13 Mar 2018 17:15:17 +1000 Subject: [PATCH 05/20] Resolve global variable issues --- installers/button.py | 93 ++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/installers/button.py b/installers/button.py index 1c191a4cb..64f02a9b3 100644 --- a/installers/button.py +++ b/installers/button.py @@ -5,69 +5,88 @@ import os, sys # Define the location of the script to restore default configuration -defaultsscriptlocation = int(sys.argv[1]) if len(sys.argv) >= 1 else "/etc/raspap/hostapd/reset.sh" +defaultsscriptlocation = "/etc/raspap/hostapd/reset.sh" +scriptlocation = sys.argv[1] if len(sys.argv) >= 2 else defaultsscriptlocation buttonGPIO = 21 # Pushbutton is connected to GPIO 21 (pin 40) -LEDGPIO = 20 # LED is connected to GPIO 20 (pin 38) +ledGPIO = 20 # LED is connected to GPIO 20 (pin 38) restarttime = 1 # restart if held for greater than restarttime seconds offtime = 6 # shut down if held for greater than offtime seconds defaultstime = 15 # reset RaspAP to default config if held for greater than defaultstime seconds -resetready = False -shutdownready = False -defaultsready = False +restartready = False # Flag for reset time exceeded +shutdownready = False # Flag for shutdown time exceeded +defaultsready = False # Flag for defaults reset flag exceeded def when_held(): + global restartready + global shutdownready + global defaultsready + # find how long the button has been held - ptime = b.pressed_time + held_time = button.held_time - restarttime # blink rate will increase the longer we hold # Set flags for the action needed when the button is released - if ptime > restarttime && ptime < offtime: - led.blink(on_time=0.5/p, off_time=0.5/p) - resetready = True - shutdownready = False - defaultsready = False + if held_time > restarttime and held_time < offtime and not restartready: + led.blink(on_time=0.5, off_time=0.5) + restartready = True + shutdownready = False + defaultsready = False + print "Restart time reached" - if ptime > offtime && ptime < defaultstime: - led.blink(on_time=0.25/p, off_time=0.25/p) - resetready = False - shutdownready = True - defaultsready = False + if held_time > offtime and held_time < defaultstime and not shutdownready: + led.blink(on_time=0.25, off_time=0.25) + restartready = False + shutdownready = True + defaultsready = False + print "Shutdown time reached" - if ptime > defaultstime: - led.blink(on_time=0.1/p, off_time=0.1/p) - resetready = False - shutdownready = False - defaultsready = True + if held_time > defaultstime and not defaultsready: + led.blink(on_time=0.1, off_time=0.1) + restartready = False + shutdownready = False + defaultsready = True + print "Restore defaults time reached" def when_released(): - # turn the LEDs off if we release early - led.off() + global restartready + global shutdownready + global defaultsready + + led.on() - if resetready == True: - os.system("sudo restart") + if restartready: + print "System restarting" + os.system("sudo reboot") - if shutdownready == True: + if shutdownready: + print "System powering down" os.system("sudo poweroff") - if defaultsready == True: - os.system("sudo " + defaultsscriptlocation) - os.system("sudo restart") + if defaultsready: + print "System restoring RaspAP defaults" + os.system("sudo bash " + scriptlocation) + os.system("sudo reboot") + + # Clear flags if the button was released early + print "Button released before any action was needed" + restartready = False + shutdownready = False + defaultsready = False + - # clear flags if we release early - resetready = False - shutdownready = False - defaultsready = False +led = LED(ledGPIO) +led.on() +button = Button(buttonGPIO, hold_time=restarttime, hold_repeat=True) +button.when_held = when_held +button.when_released = when_released -led = LED(LEDGPIO) +print "Waiting for a button press" -btn = Button(buttonGPIO, hold_time=restarttime, hold_repeat=True) -btn.when_held = when_held -btn.when_released = when_released pause() \ No newline at end of file From 034e8b84703369d9a9df28fc2e13789788794ecf Mon Sep 17 00:00:00 2001 From: njkeng Date: Tue, 20 Mar 2018 20:23:35 +1000 Subject: [PATCH 06/20] Allow use of User settings for factory reset Added functions to save current RaspAP settings as "User" defaults. Added a selection for RaspAP factory reset to use User defaults or RaspAP defaults. --- includes/system.php | 194 +++++++++++++++++++++++++++++++++++++++++-- installers/button.py | 2 +- installers/common.sh | 20 +++-- installers/reset.sh | 30 +++++-- 4 files changed, 228 insertions(+), 18 deletions(-) diff --git a/includes/system.php b/includes/system.php index 8f8c29e38..6cef9eeb0 100755 --- a/includes/system.php +++ b/includes/system.php @@ -46,7 +46,7 @@ function RPiVersion() { * */ function DisplaySystem(){ - + $status = new StatusMessages(); // hostname exec("hostname -f", $hostarray); $hostname = $hostarray[0]; @@ -80,6 +80,64 @@ function DisplaySystem(){ elseif ($cpuload > 75) { $cpuload_status = "warning"; } elseif ($cpuload > 0) { $cpuload_status = "success"; } + + # Check for RasAP defaults or user saved defaults upon system factory reset + if ( ! $arrDefaultsConf = parse_ini_file('/etc/raspap/hostapd/reset.ini')) { + $status->addMessage('Could not read the configuration file', 'warning'); + } + + # Write preference for RaspAP defaults to reset.ini + if( isset($_POST['select_raspap_defaults']) ) { + if (CSRFValidate()) { + $arrDefaultsConf["user_reset_files"] = "0"; + if ( write_php_ini($arrDefaultsConf,'/etc/raspap/hostapd/reset.ini')) { + $status->addMessage('Successfully saved preference for RaspAP defaults', 'success'); + } else { + $status->addMessage('Unable to save configuration preferences', 'danger'); + } + } else { + $status->addMessage('Unable to save configuration preferences', 'danger'); + error_log('CSRF violation'); + } + } + + # Write preference for user-saved defaults to reset.ini + if( isset($_POST['select_user_defaults']) ) { + if (CSRFValidate()) { + $arrDefaultsConf["user_reset_files"] = "1"; + if ( write_php_ini($arrDefaultsConf,'/etc/raspap/hostapd/reset.ini')) { + $status->addMessage('Successfully saved preference for user-daved defaults', 'success'); + } else { + $status->addMessage('Unable to save configuration preferences', 'danger'); + } + } else { + error_log('CSRF violation'); + } + } + + # Copy current RaspAP settings into user preference files + if( isset($_POST['save_user_settings']) ) { + if (CSRFValidate()) { + SaveUserSettings($status); + $arrDefaultsConf["user_files_saved"] = "1"; + write_php_ini($arrDefaultsConf,'/etc/raspap/hostapd/reset.ini'); + } else { + error_log('CSRF violation'); + } + } + + # Use values from reset.ini for correct display of buttons on "defaults" tab + if ( $arrDefaultsConf['user_reset_files'] == "0") { + $raspapDefaults = " active"; + $userDefaults = ""; + } else { + $raspapDefaults = ""; + $userDefaults = " active"; + } + if ( $arrDefaultsConf['user_files_saved'] == "0") { + $disableUserSettings = ' disabled="disabled"'; + } + ?>
@@ -97,13 +155,14 @@ function DisplaySystem(){ $result = shell_exec("sudo /sbin/shutdown -h now"); } ?> - +

showMessages(); ?>

@@ -140,12 +199,28 @@ function DisplaySystem(){
+
+
+
+

Source for reset data

+
Settings that will be written in if a factory reset is performed
+
+ + name="select_user_defaults" value="User settings" /> +
+
+

Save user settings

+
Save current settings as user defaults
+
+ +
+
+
+
- -
@@ -162,4 +237,113 @@ function DisplaySystem(){ addMessage('Successfully saved WiFI hotspot configuration', 'success'); + } else { + $status->addMessage('Unable to save WiFI hotspot configuration', 'danger'); + $success = False; + } + + # DHCP server + if (! shell_exec("sudo cp /etc/dnsmasq.conf config/user_dnsmasq.conf")) { + $status->addMessage('Successfully saved DHCP server configuration', 'success'); + } else { + $status->addMessage('Unable to save DHCP server configuration', 'danger'); + $success = False; + } + + # DHCP client + if (! shell_exec("sudo cp /etc/dhcpcd.conf config/user_dhcpcd.conf")) { + $status->addMessage('Successfully saved Networking configuration', 'success'); + } else { + $status->addMessage('Unable to save Networking configuration', 'danger'); + $success = False; + } + + # Update wifi client configuration + if (file_exists('/etc/wpa_supplicant/wpa_supplicant.conf')) { + if (! shell_exec("sudo cp /etc/wpa_supplicant/wpa_supplicant.conf config/user_wpa_supplicant.conf")) { + $status->addMessage('Successfully saved WiFi client configuration', 'success'); + } else { + $status->addMessage('Unable to save WiFi client configuration', 'warning'); + $success = False; + } + } else { + if (file_exists('config/user_wpa_supplicant.conf')) { + if (! shell_exec("sudo rm config/user_wpa_supplicant.conf")) { + $status->addMessage('Successfully removed old WiFi client configuration', 'success'); + } else { + $status->addMessage('Unable to remove old WiFi client configuration', 'warning'); + $success = False; + } + } + } + + # Update wlan0 wifi client configuration + if (file_exists('/etc/wpa_supplicant/wpa_supplicant-wlan0.conf')) { + if (! shell_exec("sudo cp /etc/wpa_supplicant/wpa_supplican-wlan0t.conf config/user_wpa_supplicant-wlan0.conf")) { + $status->addMessage('Successfully saved wlan0 WiFi client configuration', 'success'); + } else { + $status->addMessage('Unable to save wlan0 WiFi client configuration', 'warning'); + $success = False; + } + } else { + if (file_exists('config/user_wpa_supplicant-wlan0.conf')) { + if (! shell_exec("sudo rm config/user_wpa_supplicant-wlan0.conf")) { + $status->addMessage('Successfully removed old wlan0 WiFi client configuration', 'success'); + } else { + $status->addMessage('Unable to remove old wlan0 WiFi client configuration', 'warning'); + $success = False; + } + } + } + + # Update wlan1 wifi client configuration + if (file_exists('/etc/wpa_supplicant/wpa_supplicant-wlan1.conf')) { + if (! shell_exec("sudo cp /etc/wpa_supplicant/wpa_supplican-wlan1t.conf config/user_wpa_supplicant-wlan1.conf")) { + $status->addMessage('Successfully saved wlan1 WiFi client configuration', 'success'); + } else { + $status->addMessage('Unable to save wlan1 WiFi client configuration', 'warning'); + $success = False; + } + } else { + if (file_exists('config/user_wpa_supplicant-wlan1.conf')) { + if (! shell_exec("sudo rm config/user_wpa_supplicant-wlan1.conf")) { + $status->addMessage('Successfully removed old wlan1 WiFi client configuration', 'success'); + } else { + $status->addMessage('Unable to remove old wlan1 WiFi client configuration', 'warning'); + $success = False; + } + } + } + + # Update RaspAP authentication configuration + if (file_exists('/etc/raspap/raspap.auth')) { + if (! shell_exec("sudo cp /etc/raspap/raspap.auth config/user_raspap.auth")) { + $status->addMessage('Successfully saved RaspAP authentication configuration', 'success'); + } else { + $status->addMessage('Unable to save RaspAP authentication configuration', 'warning'); + $success = False; + } + } else { + if (file_exists('config/user_raspap.auth')) { + if (! shell_exec("sudo rm config/user_raspap.auth")) { + $status->addMessage('Successfully removed old RaspAP authentication configuration', 'success'); + } else { + $status->addMessage('Unable to remove old RaspAP authentication configuration', 'warning'); + $success = False; + } + } + } + + return $success; +} + ?> diff --git a/installers/button.py b/installers/button.py index 64f02a9b3..b9a1e5b83 100644 --- a/installers/button.py +++ b/installers/button.py @@ -25,7 +25,7 @@ def when_held(): global defaultsready # find how long the button has been held - held_time = button.held_time - restarttime + held_time = button.held_time + restarttime # blink rate will increase the longer we hold # Set flags for the action needed when the button is released diff --git a/installers/common.sh b/installers/common.sh index 318dbf1fc..86bf65adb 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -183,17 +183,17 @@ function default_configuration() { if [ -f /etc/default/hostapd ]; then sudo mv /etc/default/hostapd /tmp/default_hostapd.old || install_error "Unable to remove old /etc/default/hostapd file" fi - sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || install_error "Unable to move hostapd defaults file" - sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || install_error "Unable to move hostapd configuration file" - sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || install_error "Unable to move dnsmasq configuration file" - sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || install_error "Unable to move dhcpcd configuration file" + sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || install_error "Unable to copy hostapd defaults file" + sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || install_error "Unable to copy hostapd configuration file" + sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || install_error "Unable to copy dnsmasq configuration file" + sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || install_error "Unable to copy dhcpcd configuration file" # Generate required lines for Rasp AP to place into rc.local file. # #RASPAP is for removal script lines=( "echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP" "iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP" - "$raspaspap_dir/button.py & #RASPAP" + "$raspaspap_dir/button.py \& #RASPAP" ) for line in "${lines[@]}"; do @@ -206,6 +206,14 @@ function default_configuration() { done } +# Set up configuration for the reset function +function configuration_for_reset() { + install_log "Setting up configuration for the reset function" + sudo echo "webroot_dir = $webroot_dir" >> /etc/raspap/hostapd/reset.ini || install_error "Unable to write to reset configuration file" + sudo echo "user_reset_files = 0" >> /etc/raspap/hostapd/reset.ini || install_error "Unable to write to reset configuration file" + sudo echo "user_files_saved = 0" >> /etc/raspap/hostapd/reset.ini || install_error "Unable to write to reset configuration file" +} + # Add a single entry to the sudoers file function sudo_add() { @@ -294,6 +302,8 @@ function install_raspap() { create_reset_scripts move_config_file default_configuration + configuration_for_reset + sudo_add patch_system_files install_complete } diff --git a/installers/reset.sh b/installers/reset.sh index 4c5dbfe6c..d322f1714 100644 --- a/installers/reset.sh +++ b/installers/reset.sh @@ -1,12 +1,28 @@ function reset_default_configuration() { - if [ -f /etc/default/hostapd ]; then - sudo mv /etc/default/hostapd /tmp/default_hostapd.old || echo -e "Unable to remove old /etc/default/hostapd file" - fi - sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || echo -e "Unable to move hostapd defaults file" - sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || echo -e "Unable to move hostapd configuration file" - sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || echo -e "Unable to move dnsmasq configuration file" - sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || echo -e "Unable to move dhcpcd configuration file" + webroot_dir=cat /etc/raspap/hostapd/reset.ini | grep --only-matching --perl-regexp "(?<=webroot_dir = ).*" || echo -e "Unable to read from reset configuration file" + user_reset_files=cat /etc/raspap/hostapd/reset.ini | grep --only-matching --perl-regexp "(?<=user_reset_files = ).*" || echo -e "Unable to read from reset configuration file" + if ["$user_reset_files" == "0"]; + sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || echo -e "Unable to write hostapd configuration file" + sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || echo -e "Unable to write dnsmasq configuration file" + sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || echo -e "Unable to write dhcpcd configuration file" + sudo rm /etc/wpa_supplicant/wpa_supplicant.conf || echo -e "Unable to remove WPA supplicant configuration file" + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf || echo -e "Unable to remove wlan0 WPA supplicant configuration file" + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf || echo -e "Unable to remove wlan1 WPA supplicant configuration file" + sudo rm /etc/raspap/raspap.auth || echo -e "Unable to remove RaspAP authentication configuration file" + else + sudo cp $webroot_dir/config/user_hostapd.conf /etc/hostapd/hostapd.conf || echo -e "Unable to write user hostapd configuration file" + sudo cp $webroot_dir/config/user_dnsmasq.conf /etc/dnsmasq.conf || echo -e "Unable to write user dnsmasq configuration file" + sudo cp $webroot_dir/config/user_dhcpcd.conf /etc/dhcpcd.conf || echo -e "Unable to write user dhcpcd configuration file" + sudo rm /etc/wpa_supplicant/wpa_supplicant.conf || echo -e "Unable to remove WPA supplicant configuration file" + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf || echo -e "Unable to remove wlan0 WPA supplicant configuration file" + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf || echo -e "Unable to remove wlan1 WPA supplicant configuration file" + sudo cp $webroot_dir/config/user_wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf || echo -e "Unable to write WPA supplicant configuration file" + sudo cp $webroot_dir/config/user_wpa_supplicant-wlan0.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf || echo -e "Unable to write wlan0 WPA supplicant configuration file" + sudo cp $webroot_dir/config/user_wpa_supplicant-wlan1.conf /etc/wpa_supplicant/wpa_supplicant-wlan1.conf || echo -e "Unable to write wlan1 WPA supplicant configuration file" + sudo rm /etc/raspap/raspap.auth || echo -e "Unable to remove RaspAP authentication configuration file" + sudo cp $webroot_dir/config/user_raspap.auth /etc/raspap/raspap.auth || echo -e "Unable to remove RaspAP authentication configuration file" + fi } reset_default_configuration From 5e0dfbb784a69c60c9b6a79c8bb8a5efd0f32a51 Mon Sep 17 00:00:00 2001 From: njkeng Date: Tue, 20 Mar 2018 20:58:23 +1000 Subject: [PATCH 07/20] Avoid escaping directory structures in sed regex Changed the sed regex delimiting character from a / to a ? The script substitutes a string $raspap_dir. This string can be changed and it will not be escaped. It is not possible to escape the string without the use of additional regex. So, the sed regex delimiting character has been changed to eliminate the need for escaping. --- installers/common.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 30ca109cb..363b9a2d8 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -191,16 +191,16 @@ function default_configuration() { # Generate required lines for Rasp AP to place into rc.local file. # #RASPAP is for removal script lines=( - 'echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward #RASPAP' - 'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP' - + "echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP" + "iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP" + "$raspap_dir/button.py \& #RASPAP" ) for line in "${lines[@]}"; do if grep "$line" /etc/rc.local > /dev/null; then echo "$line: Line already added" else - sudo sed -i "s/^exit 0$/$line\nexit 0/" /etc/rc.local + sudo sed -i "s?^exit 0$?$line\nexit 0?" /etc/rc.local echo "Adding line $line" fi done From fe90c270425e21d625981e685ac78628ca1db09b Mon Sep 17 00:00:00 2001 From: njkeng Date: Tue, 20 Mar 2018 21:14:42 +1000 Subject: [PATCH 08/20] Fix quotation of strings --- installers/common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 363b9a2d8..663979aad 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -191,9 +191,9 @@ function default_configuration() { # Generate required lines for Rasp AP to place into rc.local file. # #RASPAP is for removal script lines=( - "echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP" - "iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP" - "$raspap_dir/button.py \& #RASPAP" + 'echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP' + 'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP' + '$raspap_dir/button.py \& #RASPAP' ) for line in "${lines[@]}"; do From a7a6477ac779d687dad3d43ce70c644acba97eb4 Mon Sep 17 00:00:00 2001 From: njkeng Date: Wed, 21 Mar 2018 10:09:10 +1000 Subject: [PATCH 09/20] Temporary changes to test quick installer These changes will be reversed once testing is complete --- README.md | 1 + installers/common.sh | 4 +++- installers/raspbian.sh | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2b10dbf4..d3cf8ffe1 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ After you complete the intial setup, you'll be able to administer these services Install RaspAP from your RaspberryPi's shell prompt: ```sh $ wget -q https://git.io/voEUQ -O /tmp/raspap && bash /tmp/raspap +$ wget -q https://raw.githubusercontent.com/njkeng/raspap-webgui/reset-button/installers/raspbian.sh -O /tmp/raspap && bash /tmp/raspap ``` The installer will complete the steps in the manual installation (below) for you. diff --git a/installers/common.sh b/installers/common.sh index 663979aad..9bd16022c 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -124,7 +124,9 @@ function download_latest_files() { fi install_log "Cloning latest files from github" - git clone https://github.com/billz/raspap-webgui /tmp/raspap-webgui || install_error "Unable to download files from github" +# git clone https://github.com/billz/raspap-webgui /tmp/raspap-webgui || install_error "Unable to download files from github" +# Clone from my branch to test quick installer + git clone -b reset-button --single-branch https://github.com/njkeng/raspap-webgui /tmp/raspap-webgui sudo mv /tmp/raspap-webgui $webroot_dir || install_error "Unable to move raspap-webgui to web root" } diff --git a/installers/raspbian.sh b/installers/raspbian.sh index ecf395c7b..5b5bd4543 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -1,4 +1,7 @@ -UPDATE_URL="https://raw.githubusercontent.com/billz/raspap-webgui/master/" +#UPDATE_URL="https://raw.githubusercontent.com/billz/raspap-webgui/master/" +# Temporary change to test quick installer +UPDATE_URL="https://raw.githubusercontent.com/njkeng/raspap-webgui/reset-button/" +git clone -b reset-button --single-branch https://github.com/njkeng/raspap-webgui /tmp/raspap-webgui wget -q ${UPDATE_URL}/installers/common.sh -O /tmp/raspapcommon.sh source /tmp/raspapcommon.sh && rm -f /tmp/raspapcommon.sh From 8369fe425fa8a36d7845c04589b50d0f8eb5c072 Mon Sep 17 00:00:00 2001 From: njkeng Date: Wed, 21 Mar 2018 11:55:38 +1000 Subject: [PATCH 10/20] Adjust file permissions for reset.ini Installation script was unable to write directly into /etc/raspap/hostapd. Writing to /tmp and moving the file in instead. --- installers/common.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 9bd16022c..1c078ca0a 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -176,9 +176,22 @@ function move_config_file() { install_log "Moving configuration file to '$raspap_dir'" sudo mv "$webroot_dir"/raspap.php "$raspap_dir" || install_error "Unable to move files to '$raspap_dir'" +} + +# Set up configuration for the reset function +function configuration_for_reset() { + install_log "Setting up configuration for the reset function" + sudo echo "webroot_dir = $webroot_dir" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" + sudo echo "user_reset_files = 0" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" + sudo echo "user_files_saved = 0" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" +} + +# Set permissions for all RaspAP directories and folders +function set_permissions() { sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || install_error "Unable to change file ownership for '$raspap_dir'" } + # Set up default configuration function default_configuration() { install_log "Setting up hostapd" @@ -202,21 +215,12 @@ function default_configuration() { if grep "$line" /etc/rc.local > /dev/null; then echo "$line: Line already added" else - sudo sed -i "s?^exit 0$?$line\nexit 0?" /etc/rc.local + sudo sed -i "s~^exit 0$~$line\nexit 0~" /etc/rc.local echo "Adding line $line" fi done } -# Set up configuration for the reset function -function configuration_for_reset() { - install_log "Setting up configuration for the reset function" - sudo echo "webroot_dir = $webroot_dir" >> /etc/raspap/hostapd/reset.ini || install_error "Unable to write to reset configuration file" - sudo echo "user_reset_files = 0" >> /etc/raspap/hostapd/reset.ini || install_error "Unable to write to reset configuration file" - sudo echo "user_files_saved = 0" >> /etc/raspap/hostapd/reset.ini || install_error "Unable to write to reset configuration file" -} - - # Add a single entry to the sudoers file function sudo_add() { sudo bash -c "echo \"www-data ALL=(ALL) NOPASSWD:$1\" | (EDITOR=\"tee -a\" visudo)" \ @@ -303,8 +307,9 @@ function install_raspap() { create_logging_scripts create_reset_scripts move_config_file - default_configuration configuration_for_reset + set_permissions + default_configuration sudo_add patch_system_files install_complete From 7108563ece90d673e7319d2f3e3570782163da6c Mon Sep 17 00:00:00 2001 From: njkeng Date: Wed, 21 Mar 2018 11:56:34 +1000 Subject: [PATCH 11/20] Move temporary file into /etc/raspap/hostapd --- installers/common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/installers/common.sh b/installers/common.sh index 1c078ca0a..56bcfea42 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -184,6 +184,7 @@ function configuration_for_reset() { sudo echo "webroot_dir = $webroot_dir" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" sudo echo "user_reset_files = 0" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" sudo echo "user_files_saved = 0" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" + sudo mv /tmp/reset.ini /etc/raspap/hostapd/ || install_error "Unable to move files to '$raspap_dir'" } # Set permissions for all RaspAP directories and folders From 2182973bac70c660ac63f33c10b136b6e3ffdbed Mon Sep 17 00:00:00 2001 From: njkeng Date: Wed, 21 Mar 2018 12:40:48 +1000 Subject: [PATCH 12/20] Modify scripts to work with python3 --- installers/button.py | 16 ++++++++-------- installers/common.sh | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/installers/button.py b/installers/button.py index b9a1e5b83..600d740e1 100644 --- a/installers/button.py +++ b/installers/button.py @@ -34,7 +34,7 @@ def when_held(): restartready = True shutdownready = False defaultsready = False - print "Restart time reached" + print ("Restart time reached") if held_time > offtime and held_time < defaultstime and not shutdownready: @@ -42,7 +42,7 @@ def when_held(): restartready = False shutdownready = True defaultsready = False - print "Shutdown time reached" + print ("Shutdown time reached") if held_time > defaultstime and not defaultsready: @@ -50,7 +50,7 @@ def when_held(): restartready = False shutdownready = False defaultsready = True - print "Restore defaults time reached" + print ("Restore defaults time reached") def when_released(): @@ -61,20 +61,20 @@ def when_released(): led.on() if restartready: - print "System restarting" + print ("System restarting") os.system("sudo reboot") if shutdownready: - print "System powering down" + print ("System powering down") os.system("sudo poweroff") if defaultsready: - print "System restoring RaspAP defaults" + print ("System restoring RaspAP defaults") os.system("sudo bash " + scriptlocation) os.system("sudo reboot") # Clear flags if the button was released early - print "Button released before any action was needed" + print ("Button released before any action was needed") restartready = False shutdownready = False defaultsready = False @@ -87,6 +87,6 @@ def when_released(): button.when_held = when_held button.when_released = when_released -print "Waiting for a button press" +print ("Waiting for a button press") pause() \ No newline at end of file diff --git a/installers/common.sh b/installers/common.sh index 56bcfea42..ed0835ac1 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -209,7 +209,7 @@ function default_configuration() { lines=( 'echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP' 'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP' - '$raspap_dir/button.py \& #RASPAP' + "python3 $raspap_dir/hostapd/button.py \& #RASPAP" ) for line in "${lines[@]}"; do From 7997895aa7c5d237d01797f2c7cec1ca6dcfcaab Mon Sep 17 00:00:00 2001 From: njkeng Date: Wed, 21 Mar 2018 19:10:44 +1000 Subject: [PATCH 13/20] Changing file permissions --- includes/system.php | 2 +- installers/reset.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 installers/reset.sh diff --git a/includes/system.php b/includes/system.php index 6cef9eeb0..524a975f1 100755 --- a/includes/system.php +++ b/includes/system.php @@ -106,7 +106,7 @@ function DisplaySystem(){ if (CSRFValidate()) { $arrDefaultsConf["user_reset_files"] = "1"; if ( write_php_ini($arrDefaultsConf,'/etc/raspap/hostapd/reset.ini')) { - $status->addMessage('Successfully saved preference for user-daved defaults', 'success'); + $status->addMessage('Successfully saved preference for user-saved defaults', 'success'); } else { $status->addMessage('Unable to save configuration preferences', 'danger'); } diff --git a/installers/reset.sh b/installers/reset.sh old mode 100644 new mode 100755 From 9c34169c4b4da256a6f797fc3113322a11ff273f Mon Sep 17 00:00:00 2001 From: njkeng Date: Wed, 21 Mar 2018 22:55:03 +1000 Subject: [PATCH 14/20] Fix regex issues --- installers/reset.sh | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/installers/reset.sh b/installers/reset.sh index d322f1714..e538b9031 100755 --- a/installers/reset.sh +++ b/installers/reset.sh @@ -1,27 +1,30 @@ +#!/bin/bash function reset_default_configuration() { - webroot_dir=cat /etc/raspap/hostapd/reset.ini | grep --only-matching --perl-regexp "(?<=webroot_dir = ).*" || echo -e "Unable to read from reset configuration file" - user_reset_files=cat /etc/raspap/hostapd/reset.ini | grep --only-matching --perl-regexp "(?<=user_reset_files = ).*" || echo -e "Unable to read from reset configuration file" - if ["$user_reset_files" == "0"]; - sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || echo -e "Unable to write hostapd configuration file" - sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || echo -e "Unable to write dnsmasq configuration file" - sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || echo -e "Unable to write dhcpcd configuration file" - sudo rm /etc/wpa_supplicant/wpa_supplicant.conf || echo -e "Unable to remove WPA supplicant configuration file" - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf || echo -e "Unable to remove wlan0 WPA supplicant configuration file" - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf || echo -e "Unable to remove wlan1 WPA supplicant configuration file" - sudo rm /etc/raspap/raspap.auth || echo -e "Unable to remove RaspAP authentication configuration file" + + webroot_dir=$(sudo cat /etc/raspap/hostapd/reset.ini | grep --only-matching --perl-regexp "(?<=webroot_dir = \")\S+(?=\")") + user_reset_files=$(sudo cat /etc/raspap/hostapd/reset.ini | grep --only-matching --perl-regexp "(?<=user_reset_files = ).") + + if [ "$user_reset_files" == "0" ]; then + sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf + sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf + sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf + sudo rm /etc/wpa_supplicant/wpa_supplicant.conf + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf + sudo rm /etc/raspap/raspap.auth else - sudo cp $webroot_dir/config/user_hostapd.conf /etc/hostapd/hostapd.conf || echo -e "Unable to write user hostapd configuration file" - sudo cp $webroot_dir/config/user_dnsmasq.conf /etc/dnsmasq.conf || echo -e "Unable to write user dnsmasq configuration file" - sudo cp $webroot_dir/config/user_dhcpcd.conf /etc/dhcpcd.conf || echo -e "Unable to write user dhcpcd configuration file" - sudo rm /etc/wpa_supplicant/wpa_supplicant.conf || echo -e "Unable to remove WPA supplicant configuration file" - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf || echo -e "Unable to remove wlan0 WPA supplicant configuration file" - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf || echo -e "Unable to remove wlan1 WPA supplicant configuration file" - sudo cp $webroot_dir/config/user_wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf || echo -e "Unable to write WPA supplicant configuration file" - sudo cp $webroot_dir/config/user_wpa_supplicant-wlan0.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf || echo -e "Unable to write wlan0 WPA supplicant configuration file" - sudo cp $webroot_dir/config/user_wpa_supplicant-wlan1.conf /etc/wpa_supplicant/wpa_supplicant-wlan1.conf || echo -e "Unable to write wlan1 WPA supplicant configuration file" - sudo rm /etc/raspap/raspap.auth || echo -e "Unable to remove RaspAP authentication configuration file" - sudo cp $webroot_dir/config/user_raspap.auth /etc/raspap/raspap.auth || echo -e "Unable to remove RaspAP authentication configuration file" + sudo cp $webroot_dir/config/user_hostapd.conf /etc/hostapd/hostapd.conf + sudo cp $webroot_dir/config/user_dnsmasq.conf /etc/dnsmasq.conf + sudo cp $webroot_dir/config/user_dhcpcd.conf /etc/dhcpcd.conf + sudo rm /etc/wpa_supplicant/wpa_supplicant.conf + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf + sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf + sudo cp $webroot_dir/config/user_wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf + sudo cp $webroot_dir/config/user_wpa_supplicant-wlan0.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf + sudo cp $webroot_dir/config/user_wpa_supplicant-wlan1.conf /etc/wpa_supplicant/wpa_supplicant-wlan1.conf + sudo rm /etc/raspap/raspap.auth + sudo cp $webroot_dir/config/user_raspap.auth /etc/raspap/raspap.auth fi } From 767f2b4ccbe1bf10aba47b2f7567a5a8bd07e12b Mon Sep 17 00:00:00 2001 From: njkeng Date: Fri, 30 Mar 2018 16:05:33 +1000 Subject: [PATCH 15/20] Fix handling of default wpa_supplicant files --- installers/common.sh | 9 +++++++++ installers/reset.sh | 15 ++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index ed0835ac1..83f845406 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -203,6 +203,15 @@ function default_configuration() { sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || install_error "Unable to copy hostapd configuration file" sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf || install_error "Unable to copy dnsmasq configuration file" sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || install_error "Unable to copy dhcpcd configuration file" + if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then + sudo cp /etc/wpa_supplicant/wpa_supplicant.conf $webroot_dir/config/wpa_supplicant.conf || install_error "Unable to copy original wpa_supplicant configuration" + fi + if [ -f /etc/wpa_supplicant/wpa_supplicant_wlan0.conf ]; then + sudo cp /etc/wpa_supplicant/wpa_supplicant_wlan0.conf $webroot_dir/config/wpa_supplicant_wlan0.conf || install_error "Unable to copy original wpa_supplicant_wlan0 configuration" + fi + if [ -f /etc/wpa_supplicant/wpa_supplicant_wlan1.conf ]; then + sudo cp /etc/wpa_supplicant/wpa_supplicant_wlan1.conf $webroot_dir/config/wpa_supplicant_wlan1.conf || install_error "Unable to copy original wpa_supplicant_wlan1 configuration" + fi # Generate required lines for Rasp AP to place into rc.local file. # #RASPAP is for removal script diff --git a/installers/reset.sh b/installers/reset.sh index e538b9031..06962b2cc 100755 --- a/installers/reset.sh +++ b/installers/reset.sh @@ -9,21 +9,18 @@ function reset_default_configuration() { sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf - sudo rm /etc/wpa_supplicant/wpa_supplicant.conf - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf + sudo cp $webroot_dir/config/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf + sudo cp $webroot_dir/config/wpa_supplicant_wlan0.conf /etc/wpa_supplicant/wpa_supplicant_wlan0.conf + sudo cp $webroot_dir/config/wpa_supplicant_wlan1.conf /etc/wpa_supplicant/wpa_supplicant_wlan1.conf sudo rm /etc/raspap/raspap.auth else sudo cp $webroot_dir/config/user_hostapd.conf /etc/hostapd/hostapd.conf sudo cp $webroot_dir/config/user_dnsmasq.conf /etc/dnsmasq.conf sudo cp $webroot_dir/config/user_dhcpcd.conf /etc/dhcpcd.conf - sudo rm /etc/wpa_supplicant/wpa_supplicant.conf - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan0.conf - sudo rm /etc/wpa_supplicant/wpa_supplicant-wlan1.conf sudo cp $webroot_dir/config/user_wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf - sudo cp $webroot_dir/config/user_wpa_supplicant-wlan0.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf - sudo cp $webroot_dir/config/user_wpa_supplicant-wlan1.conf /etc/wpa_supplicant/wpa_supplicant-wlan1.conf - sudo rm /etc/raspap/raspap.auth + sudo cp $webroot_dir/config/user_wpa_supplicant_wlan0.conf /etc/wpa_supplicant/wpa_supplicant_wlan0.conf + sudo cp $webroot_dir/config/user_wpa_supplicant_wlan1.conf /etc/wpa_supplicant/wpa_supplicant_wlan1.conf + sudo rm /etc/raspap/raspap.auth sudo cp $webroot_dir/config/user_raspap.auth /etc/raspap/raspap.auth fi } From f1aec9232787871e32f51a6789741554172efd4e Mon Sep 17 00:00:00 2001 From: njkeng Date: Sat, 31 Mar 2018 11:59:41 +1000 Subject: [PATCH 16/20] Fix saving of user settings --- includes/system.php | 105 ++++++++++++++++++++++++-------------------- installers/reset.sh | 2 + 2 files changed, 60 insertions(+), 47 deletions(-) diff --git a/includes/system.php b/includes/system.php index 524a975f1..faa462a6f 100755 --- a/includes/system.php +++ b/includes/system.php @@ -96,7 +96,7 @@ function DisplaySystem(){ $status->addMessage('Unable to save configuration preferences', 'danger'); } } else { - $status->addMessage('Unable to save configuration preferences', 'danger'); + $status->addMessage('Unable to save configuration preferences', 'danger'); error_log('CSRF violation'); } } @@ -241,109 +241,120 @@ function DisplaySystem(){ function SaveUserSettings($status) { - $success = True; + $fail = False; # WiFi hotspot - if (! shell_exec("sudo cp /etc/hostapd/hostapd.conf config/user_hostapd.conf")) { - $status->addMessage('Successfully saved WiFI hotspot configuration', 'success'); + exec( 'cp /etc/hostapd/hostapd.conf config/user_hostapd.conf', $output, $return ); + if ($return) { + $status->addMessage('Unable to save WiFi hotspot configuration', 'danger'); + $fail = True; } else { - $status->addMessage('Unable to save WiFI hotspot configuration', 'danger'); - $success = False; + $status->addMessage('Successfully saved WiFi hotspot configuration', 'success'); } # DHCP server - if (! shell_exec("sudo cp /etc/dnsmasq.conf config/user_dnsmasq.conf")) { - $status->addMessage('Successfully saved DHCP server configuration', 'success'); - } else { + exec( 'cp /etc/dnsmasq.conf config/user_dnsmasq.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to save DHCP server configuration', 'danger'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully saved DHCP server configuration', 'success'); } # DHCP client - if (! shell_exec("sudo cp /etc/dhcpcd.conf config/user_dhcpcd.conf")) { - $status->addMessage('Successfully saved Networking configuration', 'success'); - } else { + exec( 'cp /etc/dhcpcd.conf config/user_dhcpcd.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to save Networking configuration', 'danger'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully saved Networking configuration', 'success'); } # Update wifi client configuration if (file_exists('/etc/wpa_supplicant/wpa_supplicant.conf')) { - if (! shell_exec("sudo cp /etc/wpa_supplicant/wpa_supplicant.conf config/user_wpa_supplicant.conf")) { - $status->addMessage('Successfully saved WiFi client configuration', 'success'); - } else { + exec( 'sudo cat /etc/wpa_supplicant/wpa_supplicant.conf > config/user_wpa_supplicant.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to save WiFi client configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully saved WiFi client configuration', 'success'); } } else { if (file_exists('config/user_wpa_supplicant.conf')) { - if (! shell_exec("sudo rm config/user_wpa_supplicant.conf")) { - $status->addMessage('Successfully removed old WiFi client configuration', 'success'); - } else { + exec( 'rm config/user_wpa_supplicant.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to remove old WiFi client configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully removed old WiFi client configuration', 'success'); } } } # Update wlan0 wifi client configuration if (file_exists('/etc/wpa_supplicant/wpa_supplicant-wlan0.conf')) { - if (! shell_exec("sudo cp /etc/wpa_supplicant/wpa_supplican-wlan0t.conf config/user_wpa_supplicant-wlan0.conf")) { - $status->addMessage('Successfully saved wlan0 WiFi client configuration', 'success'); - } else { + exec( 'sudo cat /etc/wpa_supplicant/wpa_supplicant-wlan0.conf > config/user_wpa_supplicant-wlan0.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to save wlan0 WiFi client configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully saved wlan0 WiFi client configuration', 'success'); } } else { if (file_exists('config/user_wpa_supplicant-wlan0.conf')) { - if (! shell_exec("sudo rm config/user_wpa_supplicant-wlan0.conf")) { - $status->addMessage('Successfully removed old wlan0 WiFi client configuration', 'success'); - } else { + exec( 'rm config/user_wpa_supplicant-wlan0.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to remove old wlan0 WiFi client configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully removed old wlan0 WiFi client configuration', 'success'); } } } # Update wlan1 wifi client configuration if (file_exists('/etc/wpa_supplicant/wpa_supplicant-wlan1.conf')) { - if (! shell_exec("sudo cp /etc/wpa_supplicant/wpa_supplican-wlan1t.conf config/user_wpa_supplicant-wlan1.conf")) { - $status->addMessage('Successfully saved wlan1 WiFi client configuration', 'success'); - } else { + exec( 'sudo cat /etc/wpa_supplicant/wpa_supplicant-wlan1.conf > config/user_wpa_supplicant-wlan1.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to save wlan1 WiFi client configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully saved wlan1 WiFi client configuration', 'success'); } } else { if (file_exists('config/user_wpa_supplicant-wlan1.conf')) { - if (! shell_exec("sudo rm config/user_wpa_supplicant-wlan1.conf")) { - $status->addMessage('Successfully removed old wlan1 WiFi client configuration', 'success'); - } else { + exec( 'rm config/user_wpa_supplicant-wlan1.conf', $output, $return ); + if ($return) { $status->addMessage('Unable to remove old wlan1 WiFi client configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully removed old wlan1 WiFi client configuration', 'success'); } } } # Update RaspAP authentication configuration if (file_exists('/etc/raspap/raspap.auth')) { - if (! shell_exec("sudo cp /etc/raspap/raspap.auth config/user_raspap.auth")) { - $status->addMessage('Successfully saved RaspAP authentication configuration', 'success'); - } else { + exec( 'cp /etc/raspap/raspap.auth config/user_raspap.auth', $output, $return ); + if ($return) { $status->addMessage('Unable to save RaspAP authentication configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully saved RaspAP authentication configuration', 'success'); } } else { if (file_exists('config/user_raspap.auth')) { - if (! shell_exec("sudo rm config/user_raspap.auth")) { - $status->addMessage('Successfully removed old RaspAP authentication configuration', 'success'); - } else { + exec( 'rm config/user_raspap.auth', $output, $return ); + if ($return) { $status->addMessage('Unable to remove old RaspAP authentication configuration', 'warning'); - $success = False; + $fail = True; + } else { + $status->addMessage('Successfully removed old RaspAP authentication configuration', 'success'); } } } - return $success; + return $fail; } ?> diff --git a/installers/reset.sh b/installers/reset.sh index 06962b2cc..208cbd843 100755 --- a/installers/reset.sh +++ b/installers/reset.sh @@ -6,6 +6,7 @@ function reset_default_configuration() { user_reset_files=$(sudo cat /etc/raspap/hostapd/reset.ini | grep --only-matching --perl-regexp "(?<=user_reset_files = ).") if [ "$user_reset_files" == "0" ]; then + echo Restoring RaspAP defaults sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf sudo cp $webroot_dir/config/dnsmasq.conf /etc/dnsmasq.conf sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf @@ -14,6 +15,7 @@ function reset_default_configuration() { sudo cp $webroot_dir/config/wpa_supplicant_wlan1.conf /etc/wpa_supplicant/wpa_supplicant_wlan1.conf sudo rm /etc/raspap/raspap.auth else + echo Restoring user defaults sudo cp $webroot_dir/config/user_hostapd.conf /etc/hostapd/hostapd.conf sudo cp $webroot_dir/config/user_dnsmasq.conf /etc/dnsmasq.conf sudo cp $webroot_dir/config/user_dhcpcd.conf /etc/dhcpcd.conf From e726432c25ac82f77b34853cfa8719aa652a6773 Mon Sep 17 00:00:00 2001 From: njkeng Date: Sat, 31 Mar 2018 17:11:24 +1000 Subject: [PATCH 17/20] Fix dashboard control issues Commands to set interface up or down used ifconfig to check if interface was already up or down. The rest of the page uses "ip s a". The results of these two checks sometimes conflict. As ifconfig is now obsolete (refer https://linux.die.net/man/8/ifconfig), script has been edited so that everything uses the "ip s a" check. Warnings that the interface was already up/down were output in plain text. Edited to output these warnings as status->messages. Refresh button was using javascript to reload the identical page. This had the consequence of re-submitting the form as well, including Start and Stop commands. Replaced the javascript reload with a link back to the dashboard page. Used a button class id that has a nifty reload symbol. Page was attempting to both change the status of the interface and check the status of the interface on the same page load. This is not possible. Added a javascript timed page refresh after an interface state change so that the interface status can be correctly displayed. --- includes/dashboard.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/includes/dashboard.php b/includes/dashboard.php index fa5820dc4..ca8a52381 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -51,26 +51,37 @@ function DisplayDashboard(){ $strFrequency = $result[1]; if(strpos( $strWlan0, "UP" ) !== false) { - $status->addMessage('Interface is up', 'success'); $wlan0up = true; - } else { - $status->addMessage('Interface is down', 'warning'); } - if( isset($_POST['ifdown_wlan0']) ) { - exec( 'ifconfig ' . RASPI_WIFI_CLIENT_INTERFACE . ' | grep -i running | wc -l',$test ); - if($test[0] == 1) { + if( $wlan0up ) { + if( isset($_POST['ifdown_wlan0']) ) { exec( 'sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' down',$return ); + $status->addMessage('Stopping the interface. Wait for the page to refresh', 'warning'); + ?> + + addMessage('Interface is already up', 'warning'); } else { - echo 'Interface already down'; + $status->addMessage('Interface is up', 'success'); } - } elseif( isset($_POST['ifup_wlan0']) ) { - exec( 'ifconfig ' . RASPI_WIFI_CLIENT_INTERFACE . ' | grep -i running | wc -l',$test ); - if($test[0] == 0) { + } else { + if( isset($_POST['ifup_wlan0']) ) { exec( 'sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' up',$return ); exec( 'sudo ip -s a f label ' . RASPI_WIFI_CLIENT_INTERFACE,$return); + $status->addMessage('Starting the interface. Wait for the page to refresh', 'warning'); + ?> + + addMessage('Interface is already down', 'warning'); } else { - echo 'Interface already up'; + $status->addMessage('Interface is down', 'warning'); } } ?> @@ -131,7 +142,7 @@ function DisplayDashboard(){ echo ''; } ?> - + Refresh From c1b6a9bbe1a5534586d325281d13ea330f08b959 Mon Sep 17 00:00:00 2001 From: njkeng Date: Mon, 2 Apr 2018 22:57:43 +1000 Subject: [PATCH 18/20] Fix intitialisation of reset.ini Intitialisation was not putting quotes around string data. All subsequent writes were inserting quotes. Formatting is now consistent. --- installers/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installers/common.sh b/installers/common.sh index 75678ec95..677f3b3e0 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -181,7 +181,7 @@ function move_config_file() { # Set up configuration for the reset function function configuration_for_reset() { install_log "Setting up configuration for the reset function" - sudo echo "webroot_dir = $webroot_dir" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" + sudo echo "webroot_dir = \"$webroot_dir\"" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" sudo echo "user_reset_files = 0" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" sudo echo "user_files_saved = 0" >> /tmp/reset.ini || install_error "Unable to write to reset configuration file" sudo mv /tmp/reset.ini /etc/raspap/hostapd/ || install_error "Unable to move files to '$raspap_dir'" From dfa0b11eae33cfe27c77b36e635cb3609b8bfb87 Mon Sep 17 00:00:00 2001 From: njkeng Date: Sun, 8 Apr 2018 17:39:54 +1000 Subject: [PATCH 19/20] Update to include reset button Full write-up including images --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index 5ebff82f8..aee056fcd 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ We'd be curious to hear about how you use this with your own Pi-powered access p - [Prerequisites](#prerequisites) - [Quick installer](#quick-installer) - [Manual installation](#manual-installation) + - [Optional reset button](#optional-reset-button) - [Optional services](#optional-services) - [How to contribute](#how-to-contribute) - [License](#license) @@ -115,6 +116,61 @@ sudo reboot The default username is 'admin' and the default password is 'secret'. +## Optional reset button + +#### About +The RaspAP software monitors a GPIO pin which can be used to activate several reset functions. When held for different lengths of time, this one pin can activate reboot, power down and factory reset functions. You can connect a push button to this GPIO pin to make these functions available to the user. RaspAP also drives a GPIO output pin to indicate which function will be activated. You can wire an LED to this pin so that you can clearly see which function will be activated. The LED is not necessary to use the reset functions but it is nice to have. + +This functionality is included in RaspAP. All you need to do is add the button and the LED. + +#### Reset functions + +The following functions can all be accessed by using the reset button + +- Reboot. The Pi will power down and power back up again. +- Shutdown. The Pi will shut down. You need to cycle power to re-start the Pi. +- Factory reset. See [below](#factory-reset-function) for details about how this works. + +#### Function selection + +To activate the reset functions, hold the reset button down. Different hold times select the reset function that will be performed. +If you have connected an LED, the LED flash timing shows which of the reset functions will be activated when the button is released. + +The reset function hold times and the LED flash codes are: + +Reset function | Button held for | Recommended hold time | LED flash rate +-------------- | --------------- | --------------------- | --------------- +Device reboot | Between 1sec and 6 sec | 3 seconds | 1 per second (slow) +Device shutdown | Between 6 sec and 15 sec | 8 seconds | 2 per second (medium) +Factory reset | Longer than 15 seconds | 20 seconds | 5 per second (fast) + +If the button has not been pressed, the LED will simply be ON. This indicates that RaspAP is operating normally. + +Video showing how to use the button to activate the reset modes +https://youtu.be/7N_r_Cffa58 + +#### Factory reset function + +The factory reset function restores RaspAP settings to a pre-defined state. Without changing any settings, the factory reset restores the default RaspAP settings, as would be used for a new installation. + +You can configure the factory reset function to use settings that you have saved. The System -> Defaults menu has functions to set this up. There is a control that will save the current RaspAP configuration. You can also select whether the user saved settings or the RaspAP default settings will be used upon factory reset. + +#### Adding the button and the LED + +The button must be connected so that it shorts the pin GPIO 21 to ground. There is a ground pin directly adjacent to GPIO21 that will be convenient for most applications. Any normally open button will work. +The LED is connected from pin GPIO 20 to ground via a resistor. Using a resistor is **critical**. Leaving it out will definitely fry the GPIO pin and if you're unlucky it will take out the whole processor too. 330 ohms is a safe value to choose for the resistor. + +Fritzing diagram showing which Pi pins to use and which way around the LED needs to be. +![](https://i.imgur.com/m7pT25C.png) + +Photo of a button and LED installed on a Raspberry Pi Zero W. +![](https://i.imgur.com/X95yb6S.png) + +Reference GPIO pinouts +![](https://pinout.xyz/resources/raspberry-pi-pinout.png) +Image courtesy of [pinout.xyz](https://pinout.xyz/) + + ## Optional services OpenVPN and TOR are two additional services that run perfectly well on the RPi, and are a nice way to extend the usefulness of your WiFi router. I've started on interfaces to administer these services. Not everyone will need them, so for the moment they are disabled by default. You can enable them by changing these options in `index.php`: From d1bf003c2a44ff5d3d055002693a69d6585320f4 Mon Sep 17 00:00:00 2001 From: njkeng Date: Sun, 8 Apr 2018 17:45:53 +1000 Subject: [PATCH 20/20] Undo changes used for testing Changed all links back to billz repository --- README.md | 1 - installers/common.sh | 4 +--- installers/raspbian.sh | 5 +---- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index aee056fcd..c97228dd4 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ After you complete the intial setup, you'll be able to administer these services Install RaspAP from your RaspberryPi's shell prompt: ```sh $ wget -q https://git.io/voEUQ -O /tmp/raspap && bash /tmp/raspap -$ wget -q https://raw.githubusercontent.com/njkeng/raspap-webgui/reset-button/installers/raspbian.sh -O /tmp/raspap && bash /tmp/raspap ``` The installer will complete the steps in the manual installation (below) for you. diff --git a/installers/common.sh b/installers/common.sh index 677f3b3e0..5330f79f9 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -124,9 +124,7 @@ function download_latest_files() { fi install_log "Cloning latest files from github" -# git clone https://github.com/billz/raspap-webgui /tmp/raspap-webgui || install_error "Unable to download files from github" -# Clone from my branch to test quick installer - git clone -b reset-button --single-branch https://github.com/njkeng/raspap-webgui /tmp/raspap-webgui + git clone https://github.com/billz/raspap-webgui /tmp/raspap-webgui || install_error "Unable to download files from github" sudo mv /tmp/raspap-webgui $webroot_dir || install_error "Unable to move raspap-webgui to web root" } diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 5b5bd4543..ecf395c7b 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -1,7 +1,4 @@ -#UPDATE_URL="https://raw.githubusercontent.com/billz/raspap-webgui/master/" -# Temporary change to test quick installer -UPDATE_URL="https://raw.githubusercontent.com/njkeng/raspap-webgui/reset-button/" -git clone -b reset-button --single-branch https://github.com/njkeng/raspap-webgui /tmp/raspap-webgui +UPDATE_URL="https://raw.githubusercontent.com/billz/raspap-webgui/master/" wget -q ${UPDATE_URL}/installers/common.sh -O /tmp/raspapcommon.sh source /tmp/raspapcommon.sh && rm -f /tmp/raspapcommon.sh