From 9cb564a15fc1bff0aae2f15edaaf5632b1b75e70 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 12 Aug 2019 11:02:40 +0100 Subject: [PATCH] Processed with phpcs for PSR-2 coding standard --- ajax/networking/gen_int_config.php | 18 ++++----- ajax/networking/get_all_interfaces.php | 7 ++-- ajax/networking/get_int_config.php | 6 +-- ajax/networking/get_ip_summary.php | 8 ++-- ajax/networking/save_int_config.php | 51 +++++++++++++------------- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/ajax/networking/gen_int_config.php b/ajax/networking/gen_int_config.php index c892bb0a..c166c529 100644 --- a/ajax/networking/gen_int_config.php +++ b/ajax/networking/gen_int_config.php @@ -5,19 +5,19 @@ require('../../includes/csrf.php'); include_once('../../includes/config.php'); include_once('../../includes/functions.php'); -if(isset($_POST['generate'])) { - $cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1),array('..','.','dhcpcd.conf')); - $cnfNetworking = array_combine($cnfNetworking,$cnfNetworking); +if (isset($_POST['generate'])) { + $cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1), array('..','.','dhcpcd.conf')); + $cnfNetworking = array_combine($cnfNetworking, $cnfNetworking); $strConfFile = ""; - foreach($cnfNetworking as $index=>$file) { - if($index != "defaults") { + foreach ($cnfNetworking as $index => $file) { + if ($index != "defaults") { $cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file, false, INI_SCANNER_RAW); - if($cnfFile['static'] === 'true') { + 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') { + } 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"; @@ -32,7 +32,7 @@ if(isset($_POST['generate'])) { } } - if(file_put_contents(RASPI_CONFIG_NETWORKING.'/dhcpcd.conf',$strConfFile)) { + 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 { @@ -40,5 +40,3 @@ if(isset($_POST['generate'])) { } echo json_encode($output); } - -?> diff --git a/ajax/networking/get_all_interfaces.php b/ajax/networking/get_all_interfaces.php index 2c6b5a3d..6924d4d9 100644 --- a/ajax/networking/get_all_interfaces.php +++ b/ajax/networking/get_all_interfaces.php @@ -1,7 +1,6 @@ +exec("ls /sys/class/net | grep -v lo", $interfaces); +echo json_encode($interfaces); diff --git a/ajax/networking/get_int_config.php b/ajax/networking/get_int_config.php index 62f1aae0..ddcef701 100644 --- a/ajax/networking/get_int_config.php +++ b/ajax/networking/get_int_config.php @@ -6,9 +6,9 @@ include_once('../../includes/config.php'); include_once('../../includes/functions.php'); -if(isset($_POST['interface'])) { +if (isset($_POST['interface'])) { $int = preg_replace('/[^a-z0-9]/', '', $_POST['interface']); - if(!file_exists(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini')) { + if (!file_exists(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini')) { touch(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini'); } @@ -17,9 +17,7 @@ if(isset($_POST['interface'])) { 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 index 0342e116..b3b16030 100644 --- a/ajax/networking/get_ip_summary.php +++ b/ajax/networking/get_ip_summary.php @@ -4,9 +4,9 @@ require('../../includes/csrf.php'); include_once('../../includes/functions.php'); -if(isset($_POST['interface'])) { - $int = preg_replace('/[^a-z0-9]/','',$_POST['interface']); - exec('ip a s '.$int,$intOutput,$intResult); +if (isset($_POST['interface'])) { + $int = preg_replace('/[^a-z0-9]/', '', $_POST['interface']); + exec('ip a s '.$int, $intOutput, $intResult); $intOutput = array_map('htmlentities', $intOutput); $jsonData = ['return'=>$intResult,'output'=>$intOutput]; echo json_encode($jsonData); @@ -14,5 +14,3 @@ if(isset($_POST['interface'])) { $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 b3d707ae..74716a23 100644 --- a/ajax/networking/save_int_config.php +++ b/ajax/networking/save_int_config.php @@ -1,33 +1,34 @@ 0,'output'=>['Successfully Updated Network Configuration']]; - } else { - $jsonData = ['return'=>1,'output'=>['Error saving network configuration to file']]; - } + if (write_php_ini($cfg, RASPI_CONFIG_NETWORKING.'/'.$file)) { + $jsonData = ['return'=>0,'output'=>['Successfully Updated Network Configuration']]; } else { - $jsonData = ['return'=>2,'output'=>'Unable to detect interface']; + $jsonData = ['return'=>1,'output'=>['Error saving network configuration to file']]; } - echo json_encode($jsonData); -?> +} else { + $jsonData = ['return'=>2,'output'=>'Unable to detect interface']; +} + +echo json_encode($jsonData);