From cf149fd498a380b754ca368a9b070b31fb0440c9 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 25 Oct 2017 23:45:18 +0000 Subject: [PATCH 1/8] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c6ed044..653824e2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](http://i.imgur.com/xeKD93p.png) # `$ raspap-webgui` [![Release 1.2.1](https://img.shields.io/badge/Release-1.2.1-green.svg)](https://github.com/billz/raspap-webgui/releases) -A simple, responsive web interface t:o control wifi, hostapd and related services on the Raspberry Pi. +A simple, responsive web interface to control wifi, hostapd and related services on the Raspberry Pi. This project was inspired by a [**blog post**](http://sirlagz.net/2013/02/06/script-web-configuration-page-for-raspberry-pi/) by SirLagz about using a web page rather than ssh to configure wifi and hostapd settings on the Raspberry Pi. I mostly just prettified the UI by wrapping it in [**SB Admin 2**](https://github.com/BlackrockDigital/startbootstrap-sb-admin-2), a Bootstrap based admin theme. From f0f4f16438cd66b340f37fa7be0423ec51cc148c Mon Sep 17 00:00:00 2001 From: Joseph Haig Date: Sat, 28 Oct 2017 12:00:15 +0000 Subject: [PATCH 2/8] Fix fastcgi-php setup for fresh install --- installers/common.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/installers/common.sh b/installers/common.sh index f1eb7004..09661fda 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -73,7 +73,13 @@ function enable_php_lighttpd() { install_log "Enabling PHP for lighttpd" sudo lighty-enable-mod fastcgi-php - if [ $? -eq 2 ]; then echo already enabled; else install_error "Cannot enable fastcgi-php for lighttpd"; fi + if [ $? -eq 2 ] + then + echo ' [already enabled]' + elif [ $? -ne 0 ] + then + install_error "Cannot enable fastcgi-php for lighttpd" + fi sudo /etc/init.d/lighttpd restart || install_error "Unable to restart lighttpd" } From c8f863aeaf1cf1906293dace1274aaea16e57964 Mon Sep 17 00:00:00 2001 From: Joseph Haig Date: Sat, 28 Oct 2017 20:59:17 +0100 Subject: [PATCH 3/8] Fix properly --- installers/common.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 09661fda..9ac4046f 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -73,10 +73,11 @@ function enable_php_lighttpd() { install_log "Enabling PHP for lighttpd" sudo lighty-enable-mod fastcgi-php - if [ $? -eq 2 ] + ERR=$? + if [ $ERR -eq 2 ] then echo ' [already enabled]' - elif [ $? -ne 0 ] + elif [ $ERR -ne 0 ] then install_error "Cannot enable fastcgi-php for lighttpd" fi From f61cc31b20947197143adba22474a60f005f53bf Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 2 Nov 2017 22:43:41 +0800 Subject: [PATCH 4/8] Created new branch off master to help troubleshoot with #132 --- includes/functions.php | 48 ++++++++++++++++++++++++++++++++++++++++ includes/hostapd.php | 45 +++++++++++++++++++++++++++++++++++++ installers/common.sh | 6 +++++ installers/disablelog.sh | 3 +++ installers/enablelog.sh | 2 ++ 5 files changed, 104 insertions(+) create mode 100755 installers/disablelog.sh create mode 100755 installers/enablelog.sh diff --git a/includes/functions.php b/includes/functions.php index f391e461..ebcb8791 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,4 +1,52 @@ $val) { + if(is_array($val)) { + $res[] = "[$key]"; + foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"'); + } + else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"'); + } + if(safefilerewrite($file, implode("\r\n", $res))) { + return true; + } else { + return false; + } +} + +function safefilerewrite($fileName, $dataToSave) { + if ($fp = fopen($fileName, 'w')) { + $startTime = microtime(TRUE); + do { + $canWrite = flock($fp, LOCK_EX); + // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load + if(!$canWrite) usleep(round(rand(0, 100)*1000)); + } while ((!$canWrite)and((microtime(TRUE)-$startTime) < 5)); + + //file was locked so now we can store information + if ($canWrite) { + fwrite($fp, $dataToSave); + flock($fp, LOCK_UN); + } + fclose($fp); + return true; + } else { + return false; + } +} + + /** * diff --git a/includes/hostapd.php b/includes/hostapd.php index ece1a83d..b0f5e22f 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -10,6 +10,8 @@ function DisplayHostAPDConfig(){ $status = new StatusMessages(); + $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); + $arrConfig = array(); $arrChannel = array('a','b','g'); $arrSecurity = array( 1 => 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2'); @@ -74,6 +76,7 @@ function DisplayHostAPDConfig(){
  • Basic
  • Security
  • Advanced
  • +
  • Logfile Output
  • @@ -130,8 +133,28 @@ function DisplayHostAPDConfig(){ +
    + '; + } else { + echo "Logfile output not enabled"; + } + ?> +

    Advanced settings

    +
    +
    +
    + +
    +
    +
    @@ -431,6 +454,28 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $good_input = true; + // Check for Logging Checkbox + $logEnable = 0; + echo "SOMETHING ".$arrHostapdConf['LogEnable']; + echo 'logenable set:'.$_POST['logEnable']; + if($arrHostapdConf['LogEnable'] == 0) { + if(isset($_POST['logEnable'])) { + // Need code to enable logfile logging here + $logEnable = 1; + exec('sudo /etc/raspap/hostapd/enablelog.sh'); + } else { + exec('sudo /etc/raspap/hostapd/disablelog.sh'); + } + } else { + if(isset($_POST['logEnable'])) { + $logEnable = 1; + exec('sudo /etc/raspap/hostapd/enablelog.sh'); + } else { + exec('sudo /etc/raspap/hostapd/disablelog.sh'); + } + } + write_php_ini(["LogEnable" => $logEnable],'/etc/raspap/hostapd.ini'); + // Verify input if (strlen($_POST['ssid']) == 0 || strlen($_POST['ssid']) > 32) { // Not sure of all the restrictions of SSID diff --git a/installers/common.sh b/installers/common.sh index 9ac4046f..905f9f26 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -97,6 +97,12 @@ function create_raspap_directories() { sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || install_error "Unable to change file ownership for '$raspap_dir'" } +# 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/rasp/hostapd +} + # Fetches latest files from github to webroot function download_latest_files() { if [ -d "$webroot_dir" ]; then diff --git a/installers/disablelog.sh b/installers/disablelog.sh new file mode 100755 index 00000000..4272b88f --- /dev/null +++ b/installers/disablelog.sh @@ -0,0 +1,3 @@ +#!/bin/bash +/bin/sed -i 's|DAEMON_OPTS=" -f /tmp/hostapd.log"|#DAEMON_OPTS=""|' /etc/default/hostapd + diff --git a/installers/enablelog.sh b/installers/enablelog.sh new file mode 100755 index 00000000..79f75546 --- /dev/null +++ b/installers/enablelog.sh @@ -0,0 +1,2 @@ +#!/bin/bash +/bin/sed -i 's|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|' /etc/default/hostapd From 7b933264788cbeee59dd1efa1a808619c25179be Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 2 Nov 2017 22:48:15 +0800 Subject: [PATCH 5/8] updated stylesheet and installer with left out stuff --- dist/css/custom.css | 5 +++++ installers/common.sh | 3 +++ 2 files changed, 8 insertions(+) diff --git a/dist/css/custom.css b/dist/css/custom.css index c4994797..17126ae5 100644 --- a/dist/css/custom.css +++ b/dist/css/custom.css @@ -48,3 +48,8 @@ height:100%; min-height:500px; } + +.logoutput { + width:100%; + height:300px; +} diff --git a/installers/common.sh b/installers/common.sh index 905f9f26..45670e66 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -220,6 +220,8 @@ function patch_system_files() { '/sbin/ip link set wlan0 down' '/sbin/ip link set wlan0 up' '/sbin/ip -s a f label wlan0' + '/etc/raspap/hostapd/enablelog.sh' + '/etc/raspap/hostapd/disablelog.sh' ) # Check if sudoers needs patchin @@ -256,6 +258,7 @@ function install_raspap() { install_dependencies enable_php_lighttpd create_raspap_directories + create_logging_scripts check_for_old_configs download_latest_files change_file_ownership From c88d027ec69c85f70a1f1a9130abbc8a34b8034d Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 2 Nov 2017 18:43:52 +0000 Subject: [PATCH 6/8] Added standard div wrapper to new tab --- includes/hostapd.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index b0f5e22f..648b02d3 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -134,14 +134,19 @@ function DisplayHostAPDConfig(){
    - '; - } else { - echo "Logfile output not enabled"; - } - ?> +

    Logfile output

    +
    +
    + '; + } else { + echo "
    Logfile output not enabled"; + } + ?> +
    +

    Advanced settings

    From 8d1370e2fdcf53444e0c43554dd898be095ca88a Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 2 Nov 2017 20:46:46 +0000 Subject: [PATCH 7/8] Removed debug output --- includes/hostapd.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 648b02d3..1465d333 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -461,8 +461,6 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) // Check for Logging Checkbox $logEnable = 0; - echo "SOMETHING ".$arrHostapdConf['LogEnable']; - echo 'logenable set:'.$_POST['logEnable']; if($arrHostapdConf['LogEnable'] == 0) { if(isset($_POST['logEnable'])) { // Need code to enable logfile logging here From 19a32f53ba25cf1f8367fa958964d45e965be40a Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 2 Nov 2017 21:05:40 +0000 Subject: [PATCH 8/8] Applied theme styles to log output --- dist/css/hackernews.css | 5 +++++ dist/css/terminal.css | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dist/css/hackernews.css b/dist/css/hackernews.css index d6bb7b4d..19836947 100644 --- a/dist/css/hackernews.css +++ b/dist/css/hackernews.css @@ -76,3 +76,8 @@ h4 { width: 140px; float: left; } + +.logoutput { + width: 100%; + height: 300px; +} diff --git a/dist/css/terminal.css b/dist/css/terminal.css index d7896dd8..f3d04fbf 100644 --- a/dist/css/terminal.css +++ b/dist/css/terminal.css @@ -196,4 +196,9 @@ a:focus, a:hover { float: left; } - +.logoutput { + width: 100%; + height: 300px; + background-color: #000; + border-color: #33ff00; +}