Adds initialization of reservations in case is empty
parent
1f185fbaa1
commit
d7c02f43eb
|
@ -258,6 +258,17 @@ function backupConfig() {
|
|||
}
|
||||
}
|
||||
|
||||
function initializeReservations($config) {
|
||||
if (!isset($config[0]['arguments']['Dhcp4']['reservations'])) {
|
||||
$config[0]['arguments']['Dhcp4']['reservations'] = [];
|
||||
$set_output = executeCurlCommand('config-set', $config);
|
||||
if ($set_output == false && $set_output[0]["result"] != 0) {
|
||||
throw new Exception('Error al establecer la configuración de Kea DHCP');
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
function executeCurlCommand($command, $arguments = null, $create_backup = true) {
|
||||
$apiUrl = 'http://localhost:8000/';
|
||||
if ($command == 'config-get' || $command == 'config-write') {
|
||||
|
@ -296,7 +307,13 @@ function executeCurlCommand($command, $arguments = null, $create_backup = true)
|
|||
$output = json_decode($response, true);
|
||||
|
||||
if ($httpCode >= 200 && $httpCode < 300) {
|
||||
|
||||
if($command == 'config-get'){
|
||||
$output = initializeReservations($output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -389,7 +406,6 @@ $app->post('/dhcp/save', function() use ($app) {
|
|||
}else{
|
||||
try{
|
||||
$responseTest = executeCurlCommand('config-test', $configuration);
|
||||
|
||||
if ($responseTest[0]["result"] == 0){
|
||||
$responseSet = executeCurlCommand('config-set',$configuration);
|
||||
if ($responseSet == false && $responseSet[0]["result"] != 0) {
|
||||
|
|
Loading…
Reference in New Issue