Commit 7a4fe2a1 authored by Ad Schellevis's avatar Ad Schellevis

(alias) add type to import, for hostnames. closes https://github.com/opnsense/core/issues/875

parent 796986fa
...@@ -38,7 +38,7 @@ if (!isset($config['aliases']['alias'])) { ...@@ -38,7 +38,7 @@ if (!isset($config['aliases']['alias'])) {
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// initialize form vars // 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') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
// save form data // save form data
$input_errors = array(); $input_errors = array();
...@@ -94,7 +94,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -94,7 +94,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// no description given, use alias description // no description given, use alias description
$impdesc = trim(str_replace('|',' ' , $pconfig['descr'])); $impdesc = trim(str_replace('|',' ' , $pconfig['descr']));
} }
if (empty($impip)) {
// skip empty lines
continue;
} elseif ($pconfig['type'] == "network") {
// import networks
if (strpos($impip,'-') !== false) { if (strpos($impip,'-') !== false) {
// ip range provided // ip range provided
$ipaddr1 = explode('-', $impip)[0]; $ipaddr1 = explode('-', $impip)[0];
...@@ -111,22 +115,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -111,22 +115,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
} else { } else {
// single ip or network // single ip or network
if (!is_ipaddr($impip) && !is_subnet($impip) && !is_hostname($impip) && !empty($impip)) { if (!is_ipaddr($impip) && !is_subnet($impip)) {
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $impip); $input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $impip);
} else { } else {
$imported_ips[] = $impip; $imported_ips[] = $impip;
$imported_descs[] = $impdesc; $imported_descs[] = $impdesc;
} }
} }
} else {
// 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) { if (count($input_errors) == 0) {
// create output structure and serialize to config // create output structure and serialize to config
$alias = array(); $alias = array();
$alias['address'] = implode(" ", $imported_ips); $alias['address'] = implode(" ", $imported_ips);
$alias['detail'] = implode("||", $imported_descs); $alias['detail'] = implode("||", $imported_descs);
$alias['name'] = $pconfig['name']; $alias['name'] = $pconfig['name'];
$alias['type'] = "network"; $alias['type'] = $pconfig['type'];
$alias['descr'] = $pconfig['descr']; $alias['descr'] = $pconfig['descr'];
$config['aliases']['alias'][] = $alias; $config['aliases']['alias'][] = $alias;
...@@ -151,7 +163,7 @@ include("head.inc"); ...@@ -151,7 +163,7 @@ include("head.inc");
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <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"> <section class="col-xs-12">
<div class="content-box tab-content"> <div class="content-box tab-content">
<form action="firewall_aliases_import.php" method="post" name="iform"> <form action="firewall_aliases_import.php" method="post" name="iform">
...@@ -163,6 +175,31 @@ include("head.inc"); ...@@ -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> <i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
</td> </td>
</tr> </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> <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="22%"><a id="help_for_name" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Alias Name"); ?></td>
<td width="78%"> <td width="78%">
......
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