2017-10-29 19:21:34 +01:00
|
|
|
<?php
|
2019-08-06 21:34:58 +02:00
|
|
|
|
2020-02-15 18:57:46 +01:00
|
|
|
require '../../includes/csrf.php';
|
2019-08-06 21:34:58 +02:00
|
|
|
|
2020-02-15 18:57:46 +01:00
|
|
|
require_once '../../includes/config.php';
|
|
|
|
require_once '../../includes/functions.php';
|
2017-10-29 19:21:34 +01:00
|
|
|
|
2019-08-12 12:02:40 +02:00
|
|
|
if (isset($_POST['generate'])) {
|
2020-05-12 08:50:28 +02:00
|
|
|
$cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1), array('..','.','dhcpcd.conf','defaults'));
|
2019-08-12 12:02:40 +02:00
|
|
|
$cnfNetworking = array_combine($cnfNetworking, $cnfNetworking);
|
2020-05-12 08:50:28 +02:00
|
|
|
$strConfFile = file_get_contents(RASPI_CONFIG_NETWORKING.'/defaults')."\n";
|
2019-08-12 12:02:40 +02:00
|
|
|
foreach ($cnfNetworking as $index => $file) {
|
|
|
|
if ($index != "defaults") {
|
2019-07-17 22:17:19 +02:00
|
|
|
$cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file, false, INI_SCANNER_RAW);
|
2019-08-12 12:02:40 +02:00
|
|
|
if ($cnfFile['static'] === 'true') {
|
2020-05-12 08:50:28 +02:00
|
|
|
$strConfFile .= "#Static IP configured for ".$cnfFile['interface']."\n";
|
2017-10-29 19:21:34 +01:00
|
|
|
$strConfFile .= "interface ".$cnfFile['interface']."\n";
|
2020-10-02 00:06:47 +02:00
|
|
|
if (isset($cnfFile['metric'])) {
|
|
|
|
$strConfFile .= "metric ".$cnfFile['metric']."\n";
|
|
|
|
}
|
2017-10-29 19:21:34 +01:00
|
|
|
$strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n";
|
|
|
|
$strConfFile .= "static routers=".$cnfFile['routers']."\n";
|
2020-05-12 08:50:28 +02:00
|
|
|
$strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n\n";
|
2019-08-12 12:02:40 +02:00
|
|
|
} elseif ($cnfFile['static'] === 'false' && $cnfFile['failover'] === 'true') {
|
2020-05-12 08:50:28 +02:00
|
|
|
$strConfFile .= "#Failover static IP configured for ".$cnfFile['interface']."\n";
|
2017-10-29 19:21:34 +01:00
|
|
|
$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";
|
2020-10-02 00:06:47 +02:00
|
|
|
if (isset($cnfFile['metric'])) {
|
|
|
|
$strConfFile .= "metric ".$cnfFile['metric']."\n";
|
|
|
|
}
|
2017-10-29 19:21:34 +01:00
|
|
|
$strConfFile .= "fallback static_".$cnfFile['interface']."\n\n";
|
|
|
|
} else {
|
2020-10-02 10:27:35 +02:00
|
|
|
$strConfFile .= "#DHCP configured for ".pathinfo($file, PATHINFO_FILENAME)."\n\n";
|
2017-10-29 19:21:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 12:02:40 +02:00
|
|
|
if (file_put_contents(RASPI_CONFIG_NETWORKING.'/dhcpcd.conf', $strConfFile)) {
|
2020-05-12 08:50:28 +02:00
|
|
|
exec('sudo /bin/cp '.RASPI_CONFIG_NETWORKING.'/dhcpcd.conf '.RASPI_DHCPCD_CONFIG);
|
2017-10-29 19:21:34 +01:00
|
|
|
$output = ['return'=>0,'output'=>'Settings successfully applied'];
|
|
|
|
} else {
|
|
|
|
$output = ['return'=>2,'output'=>'Unable to write to apply settings'];
|
|
|
|
}
|
|
|
|
echo json_encode($output);
|
|
|
|
}
|