mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
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
This commit is contained in:
42
ajax/networking/gen_int_config.php
Normal file
42
ajax/networking/gen_int_config.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once('../../includes/config.php');
|
||||
include_once('../../includes/functions.php');
|
||||
|
||||
if(isset($_POST['generate']) && isset($_POST['csrf_token']) && CSRFValidate()) {
|
||||
$cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1),array('..','.'));
|
||||
$cnfNetworking = array_combine($cnfNetworking,$cnfNetworking);
|
||||
$strConfFile = "";
|
||||
foreach($cnfNetworking as $index=>$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);
|
||||
}
|
||||
|
||||
?>
|
@@ -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);
|
||||
|
@@ -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);
|
||||
?>
|
||||
|
Reference in New Issue
Block a user