From 77316709e1012ea9d3c5b3756fcd03ca2e13f06a Mon Sep 17 00:00:00 2001 From: Lawrence Date: Mon, 23 Oct 2017 00:26:49 +0800 Subject: [PATCH 01/11] Creating networking interface to change between Static / Dynamic IPs --- includes/networking.php | 118 ++++++++++++++++++++++++++++++++++++++++ index.php | 15 +++-- 2 files changed, 129 insertions(+), 4 deletions(-) create mode 100755 includes/networking.php diff --git a/includes/networking.php b/includes/networking.php new file mode 100755 index 00000000..57b46d58 --- /dev/null +++ b/includes/networking.php @@ -0,0 +1,118 @@ + + + +
+
+
+
+ Configure Networking +
+
+ +
+
+ Current Settings:
+ +
+
+
'.$interface.'
+
+ '; + foreach(${$interface} as $line) { + echo $line.'
'; + } + echo ' +
+
+
+
'; + } + ?> +
+ +
+
+
+
+

Adapter IP Address Settings:

+
+ + +
+

Enable Fallback to Static Option:

+
+ + +
+
+
+

Static IP Options

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
'; + } + ?> +
+
+
+ + + + + + diff --git a/index.php b/index.php index d5cb80bd..b7a400da 100755 --- a/index.php +++ b/index.php @@ -13,7 +13,7 @@ * @author Lawrence Yau * @author Bill Zimmerman * @license GNU General Public License, version 3 (GPL-3.0) - * @version 1.2.2 + * @version 1.2.3 * @link https://github.com/billz/raspap-webgui * @see http://sirlagz.net/2013/02/08/raspap-webgui/ */ @@ -50,6 +50,7 @@ include_once( 'includes/dhcp.php' ); include_once( 'includes/hostapd.php' ); include_once( 'includes/system.php' ); include_once( 'includes/configure_client.php' ); +include_once( 'includes/networking.php' ); $output = $return = 0; $page = $_GET['page']; @@ -117,7 +118,7 @@ $csrf_token = $_SESSION['csrf_token']; - RaspAP Wifi Portal v1.2.2 + RaspAP Wifi Portal v1.2.3 @@ -129,10 +130,13 @@ $csrf_token = $_SESSION['csrf_token']; Dashboard
  • - Configure client + Configure WiFi Client
  • - Configure hotspot + Configure Hotspot +
  • +
  • + Configure Networking
  • Configure DHCP Server @@ -181,6 +185,9 @@ $csrf_token = $_SESSION['csrf_token']; case "wpa_conf": DisplayWPAConfig(); break; + case "network_conf": + DisplayNetworkingConfig(); + break; case "hostapd_conf": DisplayHostAPDConfig(); break; From 7749b79e2faddfa46fbdc05b689c3bed55c1892f Mon Sep 17 00:00:00 2001 From: Lawrence Date: Sat, 28 Oct 2017 02:40:30 +0800 Subject: [PATCH 02/11] Implemented start of web interface to update Static IP addresses or use DHCP. Currently saves to files in /etc/raspap/networking, still need to build something to generate a working config for dhcpcd --- ajax/networking/get_all_interfaces.php | 4 + ajax/networking/get_int_config.php | 27 ++++++ ajax/networking/get_ip_summary.php | 15 ++++ ajax/networking/save_int_config.php | 75 +++++++++++++++++ includes/functions.php | 2 +- includes/networking.php | 31 +++---- index.php | 14 ++-- installers/common.sh | 8 ++ js/custom.js | 111 +++++++++++++++++++++++++ 9 files changed, 265 insertions(+), 22 deletions(-) create mode 100644 ajax/networking/get_all_interfaces.php create mode 100644 ajax/networking/get_int_config.php create mode 100644 ajax/networking/get_ip_summary.php create mode 100644 ajax/networking/save_int_config.php create mode 100644 js/custom.js diff --git a/ajax/networking/get_all_interfaces.php b/ajax/networking/get_all_interfaces.php new file mode 100644 index 00000000..432d0a5d --- /dev/null +++ b/ajax/networking/get_all_interfaces.php @@ -0,0 +1,4 @@ + diff --git a/ajax/networking/get_int_config.php b/ajax/networking/get_int_config.php new file mode 100644 index 00000000..f132f45a --- /dev/null +++ b/ajax/networking/get_int_config.php @@ -0,0 +1,27 @@ +1,'output'=>['DHCPConfig'=>$intDHCPConfig,'StaticConfig'=>$intStaticConfig]]; + echo json_encode($jsonData); + +} else { + $jsonData = ['return'=>2,'output'=>['Error getting data']]; + echo json_encode($jsonData); +} + +?> diff --git a/ajax/networking/get_ip_summary.php b/ajax/networking/get_ip_summary.php new file mode 100644 index 00000000..cd42f575 --- /dev/null +++ b/ajax/networking/get_ip_summary.php @@ -0,0 +1,15 @@ +$intResult,'output'=>$intOutput]; + echo json_encode($jsonData); +} else { + $jsonData = ['return'=>2,'output'=>['Error getting data']]; + echo json_encode($jsonData); +} + +?> diff --git a/ajax/networking/save_int_config.php b/ajax/networking/save_int_config.php new file mode 100644 index 00000000..1f698728 --- /dev/null +++ b/ajax/networking/save_int_config.php @@ -0,0 +1,75 @@ + $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'); + var_dump($_POST); + if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) { + $int = $_POST['interface']; + $cfg = []; + if($_POST[$int.'-static'] == 'true') { + $file = "STATIC-".$int.".ini"; + $ip = $_POST[$int.'-ipaddress']; + $netmask = mask2cidr($_POST[$int.'-netmask']); + $dns1 = $_POST[$int.'-dnssvr']; + $dns2 = $_POST[$int.'-dnssvralt']; + + $cfg['static'] = $_POST[$int.'-static']; + $cfg['interface'] = $int; + $cfg['routers'] = $_POST[$int.'-gateway']; + $cfg['ip_address'] = $ip."/".$netmask; + $cfg['domain_name_server'] = $dns1." ".$dns2; + + if(write_php_ini($cfg,RASPI_CONFIG_NETWORKING.'/'.$file)) { + $jsonData = ['return'=>0,'output'=>['Successfully Updated Network Configuration']]; + } else { + $jsonData = ['return'=>1,'output'=>['Error saving network configuration']]; + } + } + } else { + $jsonData = ['return'=>2,'output'=>['Error saving network configuration']]; + } + echo json_encode($jsonData); +?> diff --git a/includes/functions.php b/includes/functions.php index f391e461..dce7e66a 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -7,7 +7,7 @@ */ function CSRFToken() { ?> - + + CSRFToken(); +?>
    @@ -42,30 +43,26 @@ function DisplayNetworkingConfig(){
    '.$interface.'
    -
    - '; - foreach(${$interface} as $line) { - echo $line.'
    '; - } - echo ' +
    '; } ?> + Refresh
    -
    +

    Adapter IP Address Settings:

    -

    Enable Fallback to Static Option:

    -
    @@ -99,6 +96,12 @@ function DisplayNetworkingConfig(){
    +
    + + +
    + Save Settings + Apply Settings
    diff --git a/index.php b/index.php index 84d6b22f..bc745810 100755 --- a/index.php +++ b/index.php @@ -17,16 +17,11 @@ * @link https://github.com/billz/raspap-webgui * @see http://sirlagz.net/2013/02/08/raspap-webgui/ */ - +/* define('RASPI_CONFIG', '/etc/raspap'); +define('RASPI_CONFIG_NETWORKING',RASPI_CONFIG.'/networking'); define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); -//if(file_exists(RASPI_CONFIG.'/raspap.auth')) { -// define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); -//} else { -// define('RASPI_ADMIN_DETAILS',''); -//} - // Constants for configuration file paths. // These are typical for default RPi installs. Modify if needed. define('RASPI_DNSMASQ_CONFIG', '/etc/dnsmasq.conf'); @@ -42,7 +37,9 @@ define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc'); // Optional services, set to true to enable. define('RASPI_OPENVPN_ENABLED', false ); define('RASPI_TORPROXY_ENABLED', false ); +*/ +include_once( 'includes/config.php' ); include_once( RASPI_CONFIG.'/raspap.php' ); include_once( 'includes/functions.php' ); include_once( 'includes/dashboard.php' ); @@ -248,5 +245,8 @@ $theme_url = 'dist/css/' . $theme; + + + diff --git a/installers/common.sh b/installers/common.sh index f1eb7004..21dd0aeb 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -84,10 +84,18 @@ function create_raspap_directories() { sudo mv $raspap_dir "$raspap_dir.`date +%F-%R`" || install_error "Unable to move old '$raspap_dir' out of the way" fi sudo mkdir -p "$raspap_dir" || install_error "Unable to create directory '$raspap_dir'" + # Create a directory for existing file backups. sudo mkdir -p "$raspap_dir/backups" + # Create a directory to store networking configs + sudo mkdir -p "$raspap_dir/networking" + # Copy existing dhcpcd.conf to use as base config + cat /etc/dhcpcd.conf > "$raspap_dir/networking/defaults" + sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || install_error "Unable to change file ownership for '$raspap_dir'" + + } # Fetches latest files from github to webroot diff --git a/js/custom.js b/js/custom.js new file mode 100644 index 00000000..8f8b61a6 --- /dev/null +++ b/js/custom.js @@ -0,0 +1,111 @@ +function createNetmaskAddr(bitCount) { + var mask=[]; + for(i=0;i<4;i++) { + var n = Math.min(bitCount, 8); + mask.push(256 - Math.pow(2, 8-n)); + bitCount -= n; + } + return mask.join('.'); +} + +function loadSummary(strInterface) { + $.post('/ajax/networking/get_ip_summary.php',{interface:strInterface,csrf_token:csrf},function(data){ + jsonData = JSON.parse(data); + console.log(jsonData); + if(jsonData['return'] == 0) { + $('#'+strInterface+'-summary').html(jsonData['output'].join('
    ')); + } else if(jsonData['return'] == 2) { + $('#'+strInterface+'-summary').append(''); + } + }); +} + +function getAllInterfaces() { + $.get('/ajax/networking/get_all_interfaces.php',function(data){ + jsonData = JSON.parse(data); + $.each(jsonData,function(ind,value){loadSummary(value)}); + }); +} + +function setupTabs() { + $('a[data-toggle="tab"]').on('shown.bs.tab',function(e){ + var target = $(e.target).attr('href'); + if(!target.match('summary')) { + var int = target.replace("#",""); + loadCurrentSettings(int); + } + }); +} + +function loadCurrentSettings(strInterface) { + $.post('/ajax/networking/get_int_config.php',{interface:strInterface,csrf_token:csrf},function(data){ + jsonData = JSON.parse(data); + //console.log(data); + $.each(jsonData['output'],function(i,v) { + //console.log(i); + var int = v['interface']; + //console.log('interface : '+int); + $.each(v,function(i2,v2) { + //console.log(i2+":"+v2); + switch(i2) { + case "static": + if(v2 == 1) { + $('#'+int+'-static').click(); + } + break; + case "interface": + break; + case "ip_address": + var arrIPNetmask = v2.split('/'); + $('#'+int+'-ipaddress').val(arrIPNetmask[0]); + $('#'+int+'-netmask').val(createNetmaskAddr(arrIPNetmask[1])); + break; + case "routers": + $('#'+int+'-gateway').val(v2); + break; + case "domain_name_server": + svrsDNS = v2.split(" "); + $('#'+int+'-dnssvr').val(svrsDNS[0]); + $('#'+int+'-dnssvralt').val(svrsDNS[1]); + break; + } + }); + }); + }); +} + +function setupBtns() { + $('#btnSummaryRefresh').click(function(){getAllInterfaces();}); + $('.intsave').click(function(){ + var int = $(this).data('int'); + var frmInt = $('#frm-'+int).find(':input'); + var arrFormData = {}; + $.each(frmInt,function(i3,v3){ + if($(v3).attr('type') == 'radio') { + arrFormData[$(v3).attr('id')] = $(v3).prop('checked'); + } else { + arrFormData[$(v3).attr('id')] = $(v3).val(); + } + }); + arrFormData['interface'] = int; + arrFormData['csrf_token'] = csrf; + $.post('/ajax/networking/save_int_config.php',arrFormData,function(data){ + console.log(data); + }); + }); +} + +$().ready(function(){ + csrf = $('#csrf_token').val(); + pageCurrent = window.location.href.split("?")[1].split("=")[1]; + pageCurrent = pageCurrent.replace("#",""); + switch(pageCurrent) { + case "network_conf": + getAllInterfaces(); + setupTabs(); + setupBtns(); + break; + } +}); + + From fe609459492257a25a94b9e93119251142eb746d Mon Sep 17 00:00:00 2001 From: Lawrence Date: Sat, 28 Oct 2017 02:42:40 +0800 Subject: [PATCH 03/11] Removed commented out code from index.php. configuratin parameters have been moved to includes/config.php --- index.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/index.php b/index.php index bc745810..6b38325d 100755 --- a/index.php +++ b/index.php @@ -17,27 +17,6 @@ * @link https://github.com/billz/raspap-webgui * @see http://sirlagz.net/2013/02/08/raspap-webgui/ */ -/* -define('RASPI_CONFIG', '/etc/raspap'); -define('RASPI_CONFIG_NETWORKING',RASPI_CONFIG.'/networking'); -define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth'); - -// Constants for configuration file paths. -// These are typical for default RPi installs. Modify if needed. -define('RASPI_DNSMASQ_CONFIG', '/etc/dnsmasq.conf'); -define('RASPI_DNSMASQ_LEASES', '/var/lib/misc/dnsmasq.leases'); -define('RASPI_HOSTAPD_CONFIG', '/etc/hostapd/hostapd.conf'); -define('RASPI_WPA_SUPPLICANT_CONFIG', '/etc/wpa_supplicant/wpa_supplicant.conf'); -define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd'); -define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant'); -define('RASPI_OPENVPN_CLIENT_CONFIG', '/etc/openvpn/client.conf'); -define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server.conf'); -define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc'); - -// Optional services, set to true to enable. -define('RASPI_OPENVPN_ENABLED', false ); -define('RASPI_TORPROXY_ENABLED', false ); -*/ include_once( 'includes/config.php' ); include_once( RASPI_CONFIG.'/raspap.php' ); From d42e265365859a84acc422318fa1cc87a0bfcb16 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Sat, 28 Oct 2017 02:44:45 +0800 Subject: [PATCH 04/11] Updated version number to reflect big functionality update --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 6b38325d..4a2f3119 100755 --- a/index.php +++ b/index.php @@ -13,7 +13,7 @@ * @author Lawrence Yau * @author Bill Zimmerman * @license GNU General Public License, version 3 (GPL-3.0) - * @version 1.2.3 + * @version 1.3.0 * @link https://github.com/billz/raspap-webgui * @see http://sirlagz.net/2013/02/08/raspap-webgui/ */ @@ -104,7 +104,7 @@ $theme_url = 'dist/css/' . $theme; - RaspAP Wifi Portal v1.2.3 + RaspAP Wifi Portal v1.3.0 From 6e786e41c247276c6d30aa14774a6c8e3ea38b03 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Sun, 29 Oct 2017 12:31:51 +0800 Subject: [PATCH 05/11] Updating index to create new menu, custom.js with new code, moved config parameters from index.php to its own file --- includes/config.php | 23 +++++++++++++++++++++++ index.php | 9 +++++++-- js/custom.js | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 includes/config.php diff --git a/includes/config.php b/includes/config.php new file mode 100644 index 00000000..58033aa4 --- /dev/null +++ b/includes/config.php @@ -0,0 +1,23 @@ + diff --git a/index.php b/index.php index 4a2f3119..26aad6a0 100755 --- a/index.php +++ b/index.php @@ -121,8 +121,13 @@ $theme_url = 'dist/css/' . $theme;
  • Configure Hotspot
  • -
  • - Configure Networking +
  • Configure DHCP Server diff --git a/js/custom.js b/js/custom.js index 8f8b61a6..f4b8f9db 100644 --- a/js/custom.js +++ b/js/custom.js @@ -49,7 +49,7 @@ function loadCurrentSettings(strInterface) { //console.log(i2+":"+v2); switch(i2) { case "static": - if(v2 == 1) { + if(v2 == 'true') { $('#'+int+'-static').click(); } break; From 8d77295fd3d66ce1aeda87980fe2e714e00e0e14 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Mon, 30 Oct 2017 02:21:34 +0800 Subject: [PATCH 06/11] Updated sudoers to accomodate restarting dhcpcd to apply network settings. Updated installer to insert new lines Created files to generate / modify / save dhcpcd files and networking configuration --- ajax/networking/gen_int_config.php | 42 +++++++++++++++++++ ajax/networking/get_int_config.php | 15 +++---- ajax/networking/save_int_config.php | 35 ++++++++-------- includes/networking.php | 1 + index.php | 14 +++---- installers/common.sh | 1 + js/custom.js | 63 ++++++++++++++++++++++++----- 7 files changed, 126 insertions(+), 45 deletions(-) create mode 100644 ajax/networking/gen_int_config.php diff --git a/ajax/networking/gen_int_config.php b/ajax/networking/gen_int_config.php new file mode 100644 index 00000000..2cfdd4c5 --- /dev/null +++ b/ajax/networking/gen_int_config.php @@ -0,0 +1,42 @@ +$file) { + if($index != "defaults") { + $cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file); + if($cnfFile['static'] === 'true') { + $strConfFile .= "interface ".$cnfFile['interface']."\n"; + $strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n"; + $strConfFile .= "static routers=".$cnfFile['routers']."\n"; + $strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n"; + } elseif($cnfFile['static'] === 'false' && $cnfFile['failover'] === 'true') { + $strConfFile .= "profile static_".$cnfFile['interface']."\n"; + $strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n"; + $strConfFile .= "static routers=".$cnfFile['routers']."\n"; + $strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n\n"; + $strConfFile .= "interface ".$cnfFile['interface']."\n"; + $strConfFile .= "fallback static_".$cnfFile['interface']."\n\n"; + } else { + $strConfFile .= "#DHCP configured for ".$cnfFile['interface']."\n\n"; + } + } else { + $strConfFile .= file_get_contents(RASPI_CONFIG_NETWORKING.'/'.$index)."\n\n"; + } + } + + if(file_put_contents(RASPI_CONFIG_NETWORKING.'/dhcpcd.conf',$strConfFile)) { + exec('sudo /bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf'); + $output = ['return'=>0,'output'=>'Settings successfully applied']; + } else { + $output = ['return'=>2,'output'=>'Unable to write to apply settings']; + } + echo json_encode($output); +} + +?> diff --git a/ajax/networking/get_int_config.php b/ajax/networking/get_int_config.php index f132f45a..59b3a762 100644 --- a/ajax/networking/get_int_config.php +++ b/ajax/networking/get_int_config.php @@ -6,19 +6,16 @@ include_once('../../includes/functions.php'); if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) { $int = $_POST['interface']; - if(!file_exists(RASPI_CONFIG_NETWORKING.'/DHCP-'.$int)) { - touch(RASPI_CONFIG_NETWORKING.'/DHCP-'.$int.'.ini'); + if(!file_exists(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini')) { + touch(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini'); } - if(!file_exists(RASPI_CONFIG_NETWORKING.'/STATIC-'.$int)) { - touch(RASPI_CONFIG_NETWORKING.'/STATIC-'.$int.'.ini'); - } - - $intDHCPConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/DHCP-'.$int.'.ini'); - $intStaticConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/STATIC-'.$int.'.ini'); - $jsonData = ['return'=>1,'output'=>['DHCPConfig'=>$intDHCPConfig,'StaticConfig'=>$intStaticConfig]]; + $intConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini'); + $jsonData = ['return'=>1,'output'=>['intConfig'=>$intConfig]]; echo json_encode($jsonData); + // Todo - get dhcp lease information from `dhcpcd -U eth0` ? maybe ? + } else { $jsonData = ['return'=>2,'output'=>['Error getting data']]; echo json_encode($jsonData); diff --git a/ajax/networking/save_int_config.php b/ajax/networking/save_int_config.php index 1f698728..77593f32 100644 --- a/ajax/networking/save_int_config.php +++ b/ajax/networking/save_int_config.php @@ -45,31 +45,30 @@ function safefilerewrite($fileName, $dataToSave) { session_start(); include_once('../../includes/config.php'); include_once('../../includes/functions.php'); - var_dump($_POST); if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) { $int = $_POST['interface']; $cfg = []; - if($_POST[$int.'-static'] == 'true') { - $file = "STATIC-".$int.".ini"; - $ip = $_POST[$int.'-ipaddress']; - $netmask = mask2cidr($_POST[$int.'-netmask']); - $dns1 = $_POST[$int.'-dnssvr']; - $dns2 = $_POST[$int.'-dnssvralt']; + $file = $int.".ini"; + $ip = $_POST[$int.'-ipaddress']; + $netmask = mask2cidr($_POST[$int.'-netmask']); + $dns1 = $_POST[$int.'-dnssvr']; + $dns2 = $_POST[$int.'-dnssvralt']; - $cfg['static'] = $_POST[$int.'-static']; - $cfg['interface'] = $int; - $cfg['routers'] = $_POST[$int.'-gateway']; - $cfg['ip_address'] = $ip."/".$netmask; - $cfg['domain_name_server'] = $dns1." ".$dns2; - if(write_php_ini($cfg,RASPI_CONFIG_NETWORKING.'/'.$file)) { - $jsonData = ['return'=>0,'output'=>['Successfully Updated Network Configuration']]; - } else { - $jsonData = ['return'=>1,'output'=>['Error saving network configuration']]; - } + $cfg['interface'] = $int; + $cfg['routers'] = $_POST[$int.'-gateway']; + $cfg['ip_address'] = $ip."/".$netmask; + $cfg['domain_name_server'] = $dns1." ".$dns2; + $cfg['static'] = $_POST[$int.'-static']; + $cfg['failover'] = $_POST[$int.'-failover']; + + if(write_php_ini($cfg,RASPI_CONFIG_NETWORKING.'/'.$file)) { + $jsonData = ['return'=>0,'output'=>['Successfully Updated Network Configuration']]; + } else { + $jsonData = ['return'=>1,'output'=>['Error saving network configuration to file']]; } } else { - $jsonData = ['return'=>2,'output'=>['Error saving network configuration']]; + $jsonData = ['return'=>2,'output'=>'Unable to detect interface']; } echo json_encode($jsonData); ?> diff --git a/includes/networking.php b/includes/networking.php index c565412f..ad69c346 100755 --- a/includes/networking.php +++ b/includes/networking.php @@ -26,6 +26,7 @@ function DisplayNetworkingConfig(){ Configure Networking
    +
    @@ -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 08/11] 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 From 28513a91ee10a4c68a829aa0c8322a8ebf552609 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Sat, 4 Nov 2017 12:56:51 +0800 Subject: [PATCH 09/11] Removing conflict --- includes/hostapd.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 1b4eccaa..1465d333 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -461,11 +461,6 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status) // Check for Logging Checkbox $logEnable = 0; -<<<<<<< HEAD -======= - echo "SOMETHING ".$arrHostapdConf['LogEnable']; - echo 'logenable set:'.$_POST['logEnable']; ->>>>>>> 604b28130fd2e331a8c13b773239e0dcf0fa2fdf if($arrHostapdConf['LogEnable'] == 0) { if(isset($_POST['logEnable'])) { // Need code to enable logfile logging here From f6cfd65a5531984260b3ccee3c1ce81c7a1dede7 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 4 Nov 2017 20:23:55 +0000 Subject: [PATCH 10/11] Moved sublevel item to top level (for now) --- index.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 6c28e6a1..e6fc4e24 100755 --- a/index.php +++ b/index.php @@ -122,13 +122,8 @@ $theme_url = 'dist/css/' . $theme; Configure Hotspot
  • - - -
  • + Configure Networking +
  • Configure DHCP Server
  • From d38ae7f33498c97c14ece5944dac5a02b814de51 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 4 Nov 2017 20:24:23 +0000 Subject: [PATCH 11/11] Standardize UI elements --- includes/networking.php | 187 ++++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 92 deletions(-) mode change 100755 => 100644 includes/networking.php diff --git a/includes/networking.php b/includes/networking.php old mode 100755 new mode 100644 index ad69c346..c0b74816 --- a/includes/networking.php +++ b/includes/networking.php @@ -20,103 +20,106 @@ function DisplayNetworkingConfig(){ ?>
    -
    -
    -
    - Configure Networking -
    -
    -
    - +
    +
    +
    + Configure Networking +
    +
    +
    +
    -
    - Current Settings:
    - +

    Current Settings

    +
    + -
    -
    -
    '.$interface.'
    -
    -
    -
    -
    + echo '
    +
    +
    '.$interface.'
    +
    +
    '; } - ?> - Refresh -
    - -
    -
    -
    -
    -

    Adapter IP Address Settings:

    -
    - - -
    -

    Enable Fallback to Static Option:

    -
    - - -
    -
    -
    -

    Static IP Options

    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    - Save Settings - Apply Settings -
    -
    -
    -
    '; - } - ?> -
    -
    -
    + ?> +
    +
    + +
    +
    + +
    +
    +
    +
    +

    Adapter IP Address Settings

    +
    + + +
    +

    Enable Fallback to Static Option

    +
    + + +
    +
    +
    +

    Static IP Options

    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    + Save Settings + Apply Settings +
    +
    +
    +
    '; + } + ?> +
    +
    + + + - - - - +