mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-19 19:15:22 +00:00
(alias) add type to import, for hostnames. closes https://github.com/opnsense/core/issues/875
This commit is contained in:
parent
796986fa76
commit
7a4fe2a1f4
@ -38,7 +38,7 @@ if (!isset($config['aliases']['alias'])) {
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
// initialize form vars
|
||||
$pconfig = array("name" => null, "descr" => null, "aliasimport" => null);
|
||||
$pconfig = array("name" => null, "descr" => null, "aliasimport" => null, "type" => "network");
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// save form data
|
||||
$input_errors = array();
|
||||
@ -94,39 +94,51 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
// no description given, use alias description
|
||||
$impdesc = trim(str_replace('|',' ' , $pconfig['descr']));
|
||||
}
|
||||
|
||||
if (strpos($impip,'-') !== false) {
|
||||
// ip range provided
|
||||
$ipaddr1 = explode('-', $impip)[0];
|
||||
$ipaddr2 = explode('-', $impip)[1];
|
||||
if (!is_ipaddr($ipaddr1)) {
|
||||
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr1);
|
||||
} elseif (!is_ipaddr($ipaddr2)) {
|
||||
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr2);
|
||||
if (empty($impip)) {
|
||||
// skip empty lines
|
||||
continue;
|
||||
} elseif ($pconfig['type'] == "network") {
|
||||
// import networks
|
||||
if (strpos($impip,'-') !== false) {
|
||||
// ip range provided
|
||||
$ipaddr1 = explode('-', $impip)[0];
|
||||
$ipaddr2 = explode('-', $impip)[1];
|
||||
if (!is_ipaddr($ipaddr1)) {
|
||||
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr1);
|
||||
} elseif (!is_ipaddr($ipaddr2)) {
|
||||
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr2);
|
||||
} else {
|
||||
foreach (ip_range_to_subnet_array($ipaddr1, $ipaddr2) as $network) {
|
||||
$imported_ips[] = $network;
|
||||
$imported_descs[] = $impdesc;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (ip_range_to_subnet_array($ipaddr1, $ipaddr2) as $network) {
|
||||
$imported_ips[] = $network;
|
||||
// single ip or network
|
||||
if (!is_ipaddr($impip) && !is_subnet($impip)) {
|
||||
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $impip);
|
||||
} else {
|
||||
$imported_ips[] = $impip;
|
||||
$imported_descs[] = $impdesc;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// single ip or network
|
||||
if (!is_ipaddr($impip) && !is_subnet($impip) && !is_hostname($impip) && !empty($impip)) {
|
||||
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $impip);
|
||||
// import hosts
|
||||
if (!is_hostname($impip)) {
|
||||
$input_errors[] = sprintf(gettext("%s is not an IP address or hostname. Please correct the error to continue"), $impip);
|
||||
} else {
|
||||
$imported_ips[] = $impip;
|
||||
$imported_descs[] = $impdesc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($input_errors) == 0) {
|
||||
// create output structure and serialize to config
|
||||
$alias = array();
|
||||
$alias['address'] = implode(" ", $imported_ips);
|
||||
$alias['detail'] = implode("||", $imported_descs);
|
||||
$alias['name'] = $pconfig['name'];
|
||||
$alias['type'] = "network";
|
||||
$alias['type'] = $pconfig['type'];
|
||||
$alias['descr'] = $pconfig['descr'];
|
||||
$config['aliases']['alias'][] = $alias;
|
||||
|
||||
@ -151,7 +163,7 @@ include("head.inc");
|
||||
<section class="page-content-main">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
|
||||
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
|
||||
<section class="col-xs-12">
|
||||
<div class="content-box tab-content">
|
||||
<form action="firewall_aliases_import.php" method="post" name="iform">
|
||||
@ -163,6 +175,31 @@ include("head.inc");
|
||||
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a id="help_for_type" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Type"); ?></td>
|
||||
<td>
|
||||
<select name="type" class="form-control">
|
||||
<option value="host" <?=$pconfig['type'] == "host" ? "selected=\"selected\"" : ""; ?>><?=gettext("Host(s)"); ?></option>
|
||||
<option value="network" <?=$pconfig['type'] == "network" ? "selected=\"selected\"" : ""; ?>><?=gettext("Network(s)"); ?></option>
|
||||
</select>
|
||||
<div class="hidden" for="help_for_type">
|
||||
<span class="text-info">
|
||||
<?=gettext("Networks")?><br/>
|
||||
</span>
|
||||
<small>
|
||||
<?=gettext("Networks are specified in CIDR format. Select the CIDR mask that pertains to each entry. /32 specifies a single IPv4 host, /128 specifies a single IPv6 host, /24 specifies 255.255.255.0, /64 specifies a normal IPv6 network, etc. Hostnames (FQDNs) may also be specified, using a /32 mask for IPv4 or /128 for IPv6.");?>
|
||||
<br/>
|
||||
</small>
|
||||
<span class="text-info">
|
||||
<?=gettext("Hosts")?><br/>
|
||||
</span>
|
||||
<small>
|
||||
<?=gettext("Enter as many hosts as you would like. Hosts must be specified by their IP address or fully qualified domain name (FQDN). FQDN hostnames are periodically re-resolved and updated. If multiple IPs are returned by a DNS query, all are used.");?>
|
||||
<br/>
|
||||
</small>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%"><a id="help_for_name" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Alias Name"); ?></td>
|
||||
<td width="78%">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user