From 7845c8908bbee85ed03d10e27684202fdcf7dc7d Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 2 Nov 2017 22:13:36 +0800 Subject: [PATCH 1/2] Initial commit to enable logging for hostapd --- ajax/networking/save_int_config.php | 43 -------------------------- dist/css/custom.css | 5 +++ includes/functions.php | 48 +++++++++++++++++++++++++++++ includes/hostapd.php | 41 ++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 43 deletions(-) diff --git a/ajax/networking/save_int_config.php b/ajax/networking/save_int_config.php index 77593f32..77fcd865 100644 --- a/ajax/networking/save_int_config.php +++ b/ajax/networking/save_int_config.php @@ -1,47 +1,4 @@ $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; - } -} - session_start(); include_once('../../includes/config.php'); include_once('../../includes/functions.php'); 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/includes/functions.php b/includes/functions.php index dce7e66a..417190fc 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..7ce31da5 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,24 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) $good_input = true; + // Check for Logging Checkbox + $logEnable = 0; + if($arrHostapdConf['LogEnable'] == 0) { + if(isset($_POST['logEnable'])) { + // Need code to enable logfile logging here + $logEnable = 1; + exec('sudo /bin/sed -i "\'"\'s|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|\'"\'" /etc/default/hostapd'); + } + } else { + if(isset($_POST['logEnable'])) { + $logEnable = 1; + exec('sudo /bin/sed -i "\'"\'s|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|\'"\'" /etc/default/hostapd'); + } else { + exec('sudo /bin/sed -i "\'"\'s|DAEMON_OPTS=" -f /tmp/hostapd.log"|#DAEMON_OPTS=""|\'"\'" /etc/default/hostapd'); + } + } + 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 From 604b28130fd2e331a8c13b773239e0dcf0fa2fdf Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 2 Nov 2017 22:33:11 +0800 Subject: [PATCH 2/2] Updating to help troubleshoot #132 Added the scripts to disable and enable logging for hostapd Updated sudoers to allow running scripts --- includes/hostapd.php | 10 +++++++--- installers/common.sh | 11 +++++++++++ installers/disablelog.sh | 3 +++ installers/enablelog.sh | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100755 installers/disablelog.sh create mode 100755 installers/enablelog.sh diff --git a/includes/hostapd.php b/includes/hostapd.php index 7ce31da5..b0f5e22f 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -456,18 +456,22 @@ 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 $logEnable = 1; - exec('sudo /bin/sed -i "\'"\'s|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|\'"\'" /etc/default/hostapd'); + exec('sudo /etc/raspap/hostapd/enablelog.sh'); + } else { + exec('sudo /etc/raspap/hostapd/disablelog.sh'); } } else { if(isset($_POST['logEnable'])) { $logEnable = 1; - exec('sudo /bin/sed -i "\'"\'s|#DAEMON_OPTS=""|DAEMON_OPTS=" -f /tmp/hostapd.log"|\'"\'" /etc/default/hostapd'); + exec('sudo /etc/raspap/hostapd/enablelog.sh'); } else { - exec('sudo /bin/sed -i "\'"\'s|DAEMON_OPTS=" -f /tmp/hostapd.log"|#DAEMON_OPTS=""|\'"\'" /etc/default/hostapd'); + exec('sudo /etc/raspap/hostapd/disablelog.sh'); } } write_php_ini(["LogEnable" => $logEnable],'/etc/raspap/hostapd.ini'); diff --git a/installers/common.sh b/installers/common.sh index 0e6e358c..60998e22 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -105,6 +105,13 @@ function create_raspap_directories() { } +# 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 @@ -194,6 +201,7 @@ function default_configuration() { done } + # 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)" \ @@ -223,6 +231,8 @@ function patch_system_files() { '/sbin/ip link set wlan0 up' '/sbin/ip -s a f label wlan0' '/bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf' + '/etc/raspap/hostapd/enablelog.sh' + '/etc/raspap/hostapd/disablelog.sh' ) # Check if sudoers needs patchin @@ -259,6 +269,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 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