diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..a49d3714 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +## How to contribute + +1. File an issue in the repository, using the bug tracker, describing the + contribution you'd like to make. This will help us to get you started on the + right foot. +2. Fork the project in your account and create a new branch: + `your-great-feature`. +3. Commit your changes in that branch. +4. Open a pull request, and reference the initial issue in the pull request + message. diff --git a/README.md b/README.md index 0c6ed044..56ef18ef 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ ![](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. +# `$ raspap-webgui` [![Release 1.3.0](https://img.shields.io/badge/Release-1.3.0-green.svg)](https://github.com/billz/raspap-webgui/releases) +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. +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. Since then, the project has evolved to include greater control over many aspects of a networked RPi, better security, authentication, support for themes and more. We'd be curious to hear about how you use this with your own Pi-powered access points. Ping us on Twitter ([**@billzimmerman**](https://twitter.com/billzimmerman), [**@jrmhaig**](https://twitter.com/jrmhaig) and [**@SirLagz**](https://twitter.com/SirLagz)). Until then, here are some screenshots: -![](https://i.imgur.com/l4Vgd5G.png) -![](https://i.imgur.com/mRPtEnC.png) -![](https://i.imgur.com/FFdKoML.png) +![](https://i.imgur.com/0f27nen.png) +![](https://i.imgur.com/jFDMEy6.png) +![](https://i.imgur.com/ck0XS8P.png) +![](https://i.imgur.com/Vaej8Xv.png) +![](https://i.imgur.com/iNuMMip.png) ## Contents - [Prerequisites](#prerequisites) @@ -78,7 +80,7 @@ www-data ALL=(ALL) NOPASSWD:/sbin/reboot ``` Once those modifications are done, git clone the files to `/var/www/html`. -**Note,** for older versions of Raspbian (before Jessie, May 2016) use +**Note:** for older versions of Raspbian (before Jessie, May 2016) use `/var/www` instead. ```sh sudo rm -rf /var/www/html @@ -124,3 +126,4 @@ Please note that these are only UI's for now. If there's enough interest I'll co ## License See the [LICENSE](./LICENSE) file. + 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/config/rc.local b/config/rc.local deleted file mode 100755 index 9abe1ac9..00000000 --- a/config/rc.local +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -e -# -# rc.local -# -# This script is executed at the end of each multiuser runlevel. -# Make sure that the script will "exit 0" on success or any other -# value on error. -# -# In order to enable or disable this script just change the execution -# bits. -# -# By default this script does nothing. - -# Print the IP address -_IP=$(hostname -I) || true -if [ "$_IP" ]; then - printf "My IP address is %s\n" "$_IP" -fi - -# Set up IP forwarding and NAT routing -echo 1 > /proc/sys/net/ipv4/ip_forward -iptables -t nat -A POSTROUTING -j MASQUERADE - -exit 0 diff --git a/dist/css/custom.css b/dist/css/custom.css index 4b020f29..17126ae5 100644 --- a/dist/css/custom.css +++ b/dist/css/custom.css @@ -37,6 +37,7 @@ .webconsole { width:100%; height:100%; + border:1px solid; } #console { @@ -47,3 +48,8 @@ height:100%; min-height:500px; } + +.logoutput { + width:100%; + height:300px; +} 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..ace1fc60 100644 --- a/dist/css/terminal.css +++ b/dist/css/terminal.css @@ -66,7 +66,7 @@ a:focus, a:hover { border-color: #33ff00; } -.panel-primary>.panel-heading { +.panel-primary>.panel-heading, .panel-default>.panel-heading { border-color: #33ff00; background-color: #33ff00; color: #000; @@ -81,6 +81,11 @@ a:focus, a:hover { margin-bottom: 20px; border: 1px solid #33ff00; border-radius: 0px; + background-color: #000; +} + +hr { + border-top: 1px solid #33ff00; } .page-header { @@ -135,6 +140,28 @@ a:focus, a:hover { color: #33ff00; } +label.btn.btn-primary { + color: #33ff00; +} + +label.btn.btn-primary.active, label.btn.btn-warning.active { + background-color: #33ff00; + border-color: #33ff00; + color: #000; +} + +.label-warning { + background-color: #33ff00; +} + +span.label.label-warning { + color: #000; +} + +.btn.btn-primary { + border-color: #33ff00; +} + .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th { background-color: #000; border-top: 1px solid #000; @@ -160,7 +187,7 @@ a:focus, a:hover { border-radius: 0px; } -.alert-success,.alert-warning,.alert-ifo,.alert-dismissable { +.alert-success,.alert-warning,.alert-ifo,.alert-dismissable,.alert-danger { color: #33ff00; background-color: #000; border-color: #33ff00; @@ -182,6 +209,16 @@ a:focus, a:hover { transition: unset; } +input[type="text"]{ + color: #33ff00 !important +} + +.form-control::-webkit-input-placeholder { color: #33ff00; } +.form-control:-moz-placeholder { color: #33ff00; } +.form-control::-moz-placeholder { color: #33ff00; } +.form-control:-ms-input-placeholder { color: #33ff00; } +.form-control::-ms-input-placeholder { color: #33ff00; } + .progress { background-color: #000; border-radius: 0px; @@ -196,4 +233,28 @@ a:focus, a:hover { float: left; } +.logoutput { + width: 100%; + height: 300px; + background-color: #000; + border-color: #33ff00; +} +.webconsole { + width: 100%; + height: 100%; + border-color: #33ff00; + border-bottom: 1px solid; + border-left: 1px solid; + border-top: 0px; + border-right: 1px solid; +} + +#console { + height: 500px; +} + +.systemtabcontent { + height: 100%; + min-height: 500px; +} 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/dhcp.php b/includes/dhcp.php index 465d56e4..8e9b17fb 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -149,11 +149,11 @@ function DisplayDHCPConfig() {
-
+
-
+
diff --git a/includes/functions.php b/includes/functions.php index f391e461..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; + } +} + + /** * @@ -7,7 +55,7 @@ */ function CSRFToken() { ?> - + 'WPA', 2 => 'WPA2',3=> 'WPA+WPA2'); @@ -74,6 +76,7 @@ function DisplayHostAPDConfig(){
  • Basic
  • Security
  • Advanced
  • +
  • Logfile Output
  • @@ -130,8 +133,33 @@ function DisplayHostAPDConfig(){
    +
    +

    Logfile output

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

    Advanced settings

    +
    +
    +
    + +
    +
    +
    @@ -431,6 +459,26 @@ 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 /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/includes/networking.php b/includes/networking.php new file mode 100644 index 00000000..c0b74816 --- /dev/null +++ b/includes/networking.php @@ -0,0 +1,125 @@ + + +
    +
    +
    +
    + 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 13065e11..d658db54 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -78,8 +78,7 @@ function install_dependencies() { function enable_php_lighttpd() { install_log "Enabling PHP for lighttpd" - sudo lighttpd-enable-mod fastcgi-php - + sudo lighttpd-enable-mod fastcgi-php sudo service lighttpd force-reload sudo /etc/init.d/lighttpd restart || install_error "Unable to restart lighttpd" } @@ -101,6 +100,14 @@ function create_raspap_directories() { cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/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 +function create_logging_scripts() { + sudo mkdir /etc/raspap/hostapd + sudo mv /var/www/html/installers/*log.sh /etc/raspap/hostapd } # Generate logging enable/disable files for hostapd @@ -186,7 +193,7 @@ function default_configuration() { 'echo 1 > /proc/sys/net/ipv4/ip_forward #RASPAP' 'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP' ) - + for line in "${lines[@]}"; do if grep "$line" /etc/rc.local > /dev/null; then echo "$line: Line already added" 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 diff --git a/installers/uninstall.sh b/installers/uninstall.sh index b63ab2f0..3854fa04 100755 --- a/installers/uninstall.sh +++ b/installers/uninstall.sh @@ -63,10 +63,23 @@ function check_for_backups() { fi if [ -f "$raspap_dir/backups/dhcpcd.conf" ]; then echo -n "Restore the last dhcpcd.conf file? [y/N]: " + read answer if [[ $answer -eq 'y' ]]; then sudo cp "$raspap_dir/backups/dhcpcd.conf" /etc/dhcpcd.conf fi fi + if [ -f "$raspap_dir/backups/rc.local" ]; then + echo -n "Restore the last rc.local file? [y/N]: " + read answer + if [[ $answer -eq 'y' ]]; then + sudo cp "$raspap_dir/backups/rc.local" /etc/rc.local + else + echo -n "Remove RaspAP Lines from /etc/rc.local? [Y/n]: " + if $answer -ne 'n' ]]; then + sed -i '/#RASPAP/d' /etc/rc.local + fi + fi + fi fi } 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; + } +}); + +