32) {
$input_errors[] = gettext("A IPv4 subnet can not be over 32 bits.");
} else {
$osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
$new_targets[] = $osn;
}
} elseif (is_alias($_POST['network'])) {
$osn = $_POST['network'];
foreach (preg_split('/\s+/', $aliastable[$osn]) as $tgt) {
if (is_ipaddrv4($tgt)) {
$tgt .= "/32";
}
if (is_ipaddrv6($tgt)) {
$tgt .= "/128";
}
if (!is_subnet($tgt)) {
continue;
}
if (!is_subnetv6($tgt)) {
continue;
}
$new_targets[] = $tgt;
}
}
if (!isset($id)) {
$id = count($a_routes);
}
$oroute = $a_routes[$id];
$old_targets = array();
if (!empty($oroute)) {
if (is_alias($oroute['network'])) {
foreach (filter_expand_alias_array($oroute['network']) as $tgt) {
if (is_ipaddrv4($tgt)) {
$tgt .= "/32";
} else if (is_ipaddrv6($tgt)) {
$tgt .= "/128";
}
if (!is_subnet($tgt)) {
continue;
}
$old_targets[] = $tgt;
}
} else {
$old_targets[] = $oroute['network'];
}
}
$overlaps = array_intersect($current_targets, $new_targets);
$overlaps = array_diff($overlaps, $old_targets);
if (count($overlaps)) {
$input_errors[] = gettext("A route to these destination networks already exists") . ": " . implode(", ", $overlaps);
}
if (is_array($config['interfaces'])) {
foreach ($config['interfaces'] as $if) {
if (is_ipaddrv4($_POST['network']) &&
isset($if['ipaddr']) && isset($if['subnet']) &&
is_ipaddrv4($if['ipaddr']) && is_numeric($if['subnet']) &&
($_POST['network_subnet'] == $if['subnet']) &&
(gen_subnet($_POST['network'], $_POST['network_subnet']) == gen_subnet($if['ipaddr'], $if['subnet']))) {
$input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']);
} else if (is_ipaddrv6($_POST['network']) &&
isset($if['ipaddrv6']) && isset($if['subnetv6']) &&
is_ipaddrv6($if['ipaddrv6']) && is_numeric($if['subnetv6']) &&
($_POST['network_subnet'] == $if['subnetv6']) &&
(gen_subnetv6($_POST['network'], $_POST['network_subnet']) == gen_subnetv6($if['ipaddrv6'], $if['subnetv6']))) {
$input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']);
}
}
}
if (!$input_errors) {
$route = array();
$route['network'] = $osn;
$route['gateway'] = $_POST['gateway'];
$route['descr'] = $_POST['descr'];
if ($_POST['disabled']) {
$route['disabled'] = true;
} else {
unset($route['disabled']);
}
if (file_exists("{$g['tmp_path']}/.system_routes.apply")) {
$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply"));
} else {
$toapplylist = array();
}
$a_routes[$id] = $route;
if (!empty($oroute)) {
$delete_targets = array_diff($old_targets, $new_targets);
if (count($delete_targets)) {
foreach ($delete_targets as $dts) {
if (is_ipaddrv6($dts)) {
$family = "-inet6";
}
$toapplylist[] = "/sbin/route delete {$family} {$dts}";
}
}
}
file_put_contents("{$g['tmp_path']}/.system_routes.apply", serialize($toapplylist));
mark_subsystem_dirty('staticroutes');
write_config();
header("Location: system_routes.php");
exit;
}
}
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Static Routes"), gettext("Edit"));
$shortcut_section = "routing";
include("head.inc");
if ($input_errors) {
print_input_errors($input_errors);
}
$form = new Form;
if (isset($id) && $a_routes[$id]) {
$form->addGlobal(new Form_Input(
'id',
null,
'hidden',
$id
));
}
$section = new Form_Section('Edit Route Entry');
$section->addInput(new Form_IpAddress(
'network',
'Destination network',
$pconfig['network']
))->addMask('network_subnet', $pconfig['network_subnet'])->setPattern('[.a-zA-Z0-9_]+')->setHelp('Destination network for this static route');
$allGateways = array_combine(
array_map(function($g){ return $g['name']; }, $a_gateways),
array_map(function($g){ return $g['name'] .' - '. $g['gateway']; }, $a_gateways)
);
$section->addInput(new Form_Select(
'gateway',
'Gateway',
$pconfig['gateway'],
$allGateways
))->setHelp('Choose which gateway this route applies to or add a new one first');
$section->addInput(new Form_Checkbox(
'disabled',
'Disabled',
'Disable this static route',
$pconfig['disabled']
))->setHelp('Set this option to disable this static route without removing it from '.
'the list.');
$section->addInput(new Form_Input(
'descr',
'Description',
'text',
htmlspecialchars($pconfig['descr'])
))->setHelp('You may enter a description here for your reference (not parsed).');
$form->add($section);
print $form;
?>