Commit ecd355bc authored by Franco Fichtner's avatar Franco Fichtner

interfaces: fix clearing the dhcp config file when override file is gone #1052

(cherry picked from commit e86885cb)
(cherry picked from commit 57bb583c)
(cherry picked from commit b2362628)
parent 6ae5ea13
......@@ -3410,7 +3410,13 @@ function interface_dhcpv6_configure($interface = 'wan', $wancfg)
// DHCP6 Config File Override
if (!empty($wancfg['adv_dhcp6_config_file_override'])) {
$dhcp6cconf = DHCP6_Config_File_Override($wancfg, $wanif);
$dhcp6cfile = $wancfg['adv_dhcp6_config_file_override_path'];
if (file_exists($dhcp6cfile)) {
$dhcp6cconf = file_get_contents($dhcp6cfile);
$dhcp6cconf = DHCP6_Config_File_Substitutions($wancfg, $wanif, $dhcp6cconf);
} else {
log_error(sprintf('DHCP6 config file override does not exist: "%s"', $dhcp6cfile));
}
}
/* wide-dhcp6c works for now. */
......@@ -3647,23 +3653,6 @@ function DHCP6_Config_File_Advanced($interface, $wancfg, $wanif)
return $dhcp6cconf;
}
function DHCP6_Config_File_Override($wancfg, $wanif)
{
$dhcp6cfile = $wancfg['adv_dhcp6_config_file_override_path'];
$dhcp6cconf = '';
if (file_exists($dhcp6cfile)) {
$dhcp6cconf = file_get_contents($dhcp6cfile);
$dhcp6cconf = DHCP6_Config_File_Substitutions($wancfg, $wanif, $dhcp6cconf);
} else {
log_error(sprintf('DHCP6 config file override does not exist: %s', $dhcp6cfile));
}
return $dhcp6cconf;
}
function DHCP6_Config_File_Substitutions($wancfg, $wanif, $dhcp6cconf)
{
$dhcp6cconf = DHCP_Config_File_Substitutions($wancfg, $wanif, $dhcp6cconf);
......@@ -3744,7 +3733,13 @@ EOD;
// DHCP Config File Override
if (!empty($wancfg['adv_dhcp_config_file_override'])) {
$dhclientconf = DHCP_Config_File_Override($wancfg, $wanif);
$dhclientfile = $wancfg['adv_dhcp_config_file_override_path'];
if (file_exists($dhclientfile)) {
$dhclientconf = file_get_contents($dhclientfile);
$dhclientconf = DHCP_Config_File_Substitutions($wancfg, $wanif, $dhclientconf);
} else {
log_error(sprintf('DHCP config file override does not exist: "%s"', $dhclientfile));
}
}
fwrite($fd, $dhclientconf);
......@@ -3834,23 +3829,6 @@ function DHCP_Config_File_Advanced($interface, $wancfg, $wanif)
return $dhclientconf;
}
function DHCP_Config_File_Override($wancfg, $wanif)
{
$dhclientfile = $wancfg['adv_dhcp_config_file_override_path'];
$dhclientconf = '';
if (file_exists($dhclientfile)) {
$dhclientconf = file_get_contents($dhclientfile);
$dhclientconf = DHCP_Config_File_Substitutions($wancfg, $wanif, $dhclientconf);
} else {
log_error(sprintf('DHCP config file override does not exist: %s', $dhclientfile));
}
return $dhclientconf;
}
function DHCP_Config_File_Substitutions($wancfg, $wanif, $dhclientconf)
{
......
......@@ -611,6 +611,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (in_array($a_interfaces[$if]['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
$input_errors[] = sprintf(gettext("You have to reassign the interface to be able to configure as %s."),$pconfig['type']);
}
if (!empty($pconfig['adv_dhcp_config_file_override'] && !file_exists($pconfig['adv_dhcp_config_file_override_path']))) {
$input_errors[] = sprintf(gettext('The DHCP override file "%s" does not exist.'), $pconfig['adv_dhcp_config_file_override_path']);
}
break;
case "ppp":
$reqdfields = explode(" ", "ports phone");
......@@ -654,6 +657,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$reqdfieldsn = array(gettext("IPv6 address"),gettext("Subnet bit count"),gettext("Gateway"));
do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
break;
case "dhcp6":
if (!empty($pconfig['adv_dhcp6_config_file_override'] && !file_exists($pconfig['adv_dhcp6_config_file_override_path']))) {
$input_errors[] = sprintf(gettext('The DHCPv6 override file "%s" does not exist.'), $pconfig['adv_dhcp6_config_file_override_path']);
}
break;
case "none":
if (isset($config['virtualip']['vip'])) {
foreach ($config['virtualip']['vip'] as $vip) {
......@@ -1908,7 +1916,7 @@ include("head.inc");
</thead>
<tbody>
<tr>
<td width="22%"></td>
<td width="22%"><a id="help_for_dhcp_mode" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Configuration Mode"); ?></td>
<td width="78%">
<div id="dhcp_mode" class="btn-group" data-toggle="buttons">
<label class="btn btn-default <?=empty($pconfig['adv_dhcp_config_advanced']) && empty($pconfig['adv_dhcp_config_file_override']) ? "active" : "";?>">
......@@ -1924,6 +1932,11 @@ include("head.inc");
<?=gettext("Config File Override");?>
</label>
</div>
<div class="hidden" for="help_for_dhcp_mode">
<?= gettext('The basic mode auto-configures DHCP using default values and optional user input.') ?><br/>
<?= gettext('The advanced mode does not provide any default values, you will need to fill out any values you would like to use.') ?></br>
<?= gettext('The configuration file override mode may point to a fully customised file on the system instead.') ?>
</div>
</td>
</tr>
<tr class="dhcp_basic">
......@@ -2046,7 +2059,7 @@ include("head.inc");
</td>
</tr>
<tr class="dhcp_file_override">
<td><a id="help_for_dhcp_config_file_override_path" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Config File Override");?>
<td><a id="help_for_dhcp_config_file_override_path" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Configuration File Override");?>
<td>
<input name="adv_dhcp_config_file_override_path" type="text" id="adv_dhcp_config_file_override_path" value="<?=$pconfig['adv_dhcp_config_file_override_path'];?>" />
<div class="hidden" for="help_for_dhcp_config_file_override_path">
......@@ -2418,7 +2431,7 @@ include("head.inc");
</thead>
<tbody>
<tr>
<td width="22%"></td>
<td width="22%"><a id="help_for_dhcpv6_mode" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Configuration Mode"); ?></td>
<td width="78%">
<div id="dhcpv6_mode" class="btn-group" data-toggle="buttons">
<label class="btn btn-default <?=empty($pconfig['adv_dhcp6_config_advanced']) && empty($pconfig['adv_dhcp6_config_file_override']) ? "active" : "";?>">
......@@ -2434,6 +2447,11 @@ include("head.inc");
<?=gettext("Config File Override");?>
</label>
</div>
<div class="hidden" for="help_for_dhcpv6_mode">
<?= gettext('The basic mode auto-configures DHCP using default values and optional user input.') ?><br/>
<?= gettext('The advanced mode does not provide any default values, you will need to fill out any values you would like to use.') ?></br>
<?= gettext('The configuration file override mode may point to a fully customised file on the system instead.') ?>
</div>
</td>
</tr>
<tr class="dhcpv6_advanced dhcpv6_file_override">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment