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_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..59b3a762 --- /dev/null +++ b/ajax/networking/get_int_config.php @@ -0,0 +1,24 @@ +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/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..77fcd865 --- /dev/null +++ b/ajax/networking/save_int_config.php @@ -0,0 +1,31 @@ +0,'output'=>['Successfully Updated Network Configuration']]; + } else { + $jsonData = ['return'=>1,'output'=>['Error saving network configuration to file']]; + } + } else { + $jsonData = ['return'=>2,'output'=>'Unable to detect interface']; + } + echo json_encode($jsonData); +?> 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/includes/functions.php b/includes/functions.php index ebcb8791..417190fc 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -55,7 +55,7 @@ function safefilerewrite($fileName, $dataToSave) { */ function CSRFToken() { ?> - + + +
+
+
+
+ Configure Networking +
+
+
+ +
+
+

Current Settings

+
+ +
+
'.$interface.'
+
+
+
'; + } + ?> +
+
+ +
+
+ +
+
+
+
+

Adapter IP Address Settings

+
+ + +
+

Enable Fallback to Static Option

+
+ + +
+
+
+

Static IP Options

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ Save Settings + Apply Settings +
+
+
+
'; + } + ?> +
+
+ +
+ + + + diff --git a/index.php b/index.php index 1c1eb921..e6fc4e24 100755 --- a/index.php +++ b/index.php @@ -13,36 +13,12 @@ * @author Lawrence Yau * @author Bill Zimmerman * @license GNU General Public License, version 3 (GPL-3.0) - * @version 1.2.2 + * @version 1.3.0 * @link https://github.com/billz/raspap-webgui * @see http://sirlagz.net/2013/02/08/raspap-webgui/ */ -define('RASPI_CONFIG', '/etc/raspap'); -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'); -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' ); include_once( 'includes/functions.php' ); include_once( 'includes/dashboard.php' ); @@ -52,6 +28,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' ); include_once( 'includes/themes.php' ); $output = $return = 0; @@ -127,7 +104,7 @@ $theme_url = 'dist/css/' . $theme; - RaspAP Wifi Portal v1.2.2 + RaspAP Wifi Portal v1.3.0 @@ -139,11 +116,14 @@ $theme_url = 'dist/css/' . $theme; Dashboard
  • - Configure client + Configure WiFi Client
  • - Configure hotspot + Configure Hotspot
  • +
  • + Configure Networking +
  • Configure DHCP Server
  • @@ -194,6 +174,9 @@ $theme_url = 'dist/css/' . $theme; case "wpa_conf": DisplayWPAConfig(); break; + case "network_conf": + DisplayNetworkingConfig(); + break; case "hostapd_conf": DisplayHostAPDConfig(); break; @@ -241,5 +224,8 @@ $theme_url = 'dist/css/' . $theme; + + + diff --git a/installers/common.sh b/installers/common.sh index 45670e66..9fbb95da 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -91,10 +91,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'" + + } # Generate logging enable/disable files for hostapd @@ -192,6 +200,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)" \ @@ -220,6 +229,7 @@ function patch_system_files() { '/sbin/ip link set wlan0 down' '/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' ) diff --git a/js/custom.js b/js/custom.js new file mode 100644 index 00000000..d660f45e --- /dev/null +++ b/js/custom.js @@ -0,0 +1,152 @@ +function msgShow(retcode,msg) { + if(retcode == 0) { + var alertType = 'success'; + } else if(retcode == 2 || retcode == 1) { + var alertType = 'danger'; + } + var htmlMsg = ''; + return htmlMsg; +} + +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); + $.each(jsonData['output'],function(i,v) { + var int = v['interface']; + $.each(v,function(i2,v2) { + switch(i2) { + case "static": + if(v2 == 'true') { + $('#'+int+'-static').click(); + $('#'+int+'-nofailover').click(); + } else { + $('#'+int+'-dhcp').click(); + } + break; + case "failover": + if(v2 === 'true') { + $('#'+int+'-failover').click(); + } else { + $('#'+int+'-nofailover').click(); + } + 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 saveNetworkSettings(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); + var jsonData = JSON.parse(data); + $('#msgNetworking').html(msgShow(jsonData['return'],jsonData['output'])); + }); +} + +function applyNetworkSettings() { + var int = $(this).data('int'); + arrFormData = {}; + arrFormData['csrf_token'] = csrf; + arrFormData['generate'] = ''; + $.post('/ajax/networking/gen_int_config.php',arrFormData,function(data){ + console.log(data); + var jsonData = JSON.parse(data); + $('#msgNetworking').html(msgShow(jsonData['return'],jsonData['output'])); + }); +} + +function setupBtns() { + $('#btnSummaryRefresh').click(function(){getAllInterfaces();}); + + $('.intsave').click(function(){ + var int = $(this).data('int'); + saveNetworkSettings(int); + }); + + $('.intapply').click(function(){ + applyNetworkSettings(); + }); +} + +$().ready(function(){ + csrf = $('#csrf_token').val(); + pageCurrent = window.location.href.split("?")[1].split("=")[1]; + pageCurrent = pageCurrent.replace("#",""); + $('#side-menu').metisMenu(); + switch(pageCurrent) { + case "network_conf": + getAllInterfaces(); + setupTabs(); + setupBtns(); + break; + } +}); + +