Commit 62b4d129 authored by Ad Schellevis's avatar Ad Schellevis

whitespace firewall_aliases_import.php

parent 27f73e93
<?php <?php
/* /*
Copyright (C) 2014 Deciso B.V. Copyright (C) 2014 Deciso B.V.
Copyright (C) 2005 Scott Ullrich Copyright (C) 2005 Scott Ullrich
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("guiconfig.inc"); require_once("guiconfig.inc");
...@@ -33,112 +33,112 @@ if (!is_array($config['aliases'])) { ...@@ -33,112 +33,112 @@ if (!is_array($config['aliases'])) {
$config['aliases'] = array(); $config['aliases'] = array();
} }
if (!is_array($config['aliases']['alias'])) { if (!is_array($config['aliases']['alias'])) {
$config['aliases']['alias'] = array(); $config['aliases']['alias'] = array();
} }
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);
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
// save form data // save form data
$input_errors = array(); $input_errors = array();
$pconfig = $_POST; $pconfig = $_POST;
// input validation // input validation
$reqdfields = explode(" ", "name aliasimport"); $reqdfields = explode(" ", "name aliasimport");
$reqdfieldsn = array(gettext("Name"),gettext("Aliases")); $reqdfieldsn = array(gettext("Name"),gettext("Aliases"));
do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
if (is_validaliasname($pconfig['name']) == false) { if (is_validaliasname($pconfig['name']) == false) {
$input_errors[] = gettext("The alias name may only consist of the characters") . " a-z, A-Z, 0-9, _."; $input_errors[] = gettext("The alias name may only consist of the characters") . " a-z, A-Z, 0-9, _.";
} }
/* check for name duplicates */ /* check for name duplicates */
if (is_alias($pconfig['name'])) { if (is_alias($pconfig['name'])) {
$input_errors[] = gettext("An alias with this name already exists."); $input_errors[] = gettext("An alias with this name already exists.");
} }
// Add all Load balance names to reserved_keywords // Add all Load balance names to reserved_keywords
if (isset($config['load_balancer']['lbpool'])) { if (isset($config['load_balancer']['lbpool'])) {
foreach ($config['load_balancer']['lbpool'] as $lbpool) { foreach ($config['load_balancer']['lbpool'] as $lbpool) {
$reserved_keywords[] = $lbpool['name']; $reserved_keywords[] = $lbpool['name'];
} }
} }
// Keywords not allowed in names // Keywords not allowed in names
$reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec"); $reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
$reserved_ifs = get_configured_interface_list(false, true); $reserved_ifs = get_configured_interface_list(false, true);
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names); $reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
/* Check for reserved keyword names */ /* Check for reserved keyword names */
foreach($reserved_keywords as $rk) foreach($reserved_keywords as $rk)
if ($rk == $pconfig['name']) if ($rk == $pconfig['name'])
$input_errors[] = sprintf(gettext("Cannot use a reserved keyword as alias name %s"), $rk); $input_errors[] = sprintf(gettext("Cannot use a reserved keyword as alias name %s"), $rk);
/* check for name interface description conflicts */ /* check for name interface description conflicts */
foreach($config['interfaces'] as $interface) { foreach($config['interfaces'] as $interface) {
if($interface['descr'] == $pconfig['name']) { if($interface['descr'] == $pconfig['name']) {
$input_errors[] = gettext("An interface description with this name already exists."); $input_errors[] = gettext("An interface description with this name already exists.");
break; break;
} }
} }
$imported_ips = array(); $imported_ips = array();
$imported_descs = array(); $imported_descs = array();
foreach (explode("\n", $pconfig['aliasimport']) as $impline) { foreach (explode("\n", $pconfig['aliasimport']) as $impline) {
$implinea = explode(" ",trim($impline),2); $implinea = explode(" ",trim($impline),2);
$impip = trim($implinea[0]); $impip = trim($implinea[0]);
if (!empty($implinea[1])) { if (!empty($implinea[1])) {
// trim and truncate description to max 200 characters // trim and truncate description to max 200 characters
$impdesc = substr(trim($implinea[1]),0, 200); $impdesc = substr(trim($implinea[1]),0, 200);
} else { } else {
// 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 (strpos($impip,'-') !== false) { if (strpos($impip,'-') !== false) {
// ip range provided // ip range provided
$ipaddr1 = explode('-', $impip)[0]; $ipaddr1 = explode('-', $impip)[0];
$ipaddr2 = explode('-', $impip)[1]; $ipaddr2 = explode('-', $impip)[1];
if (!is_ipaddr($ipaddr1)) { if (!is_ipaddr($ipaddr1)) {
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr1); $input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr1);
} elseif (!is_ipaddr($ipaddr2)) { } elseif (!is_ipaddr($ipaddr2)) {
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr2); $input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $ipaddr2);
} else { } else {
foreach (ip_range_to_subnet_array($ipaddr1, $ipaddr2) as $network) { foreach (ip_range_to_subnet_array($ipaddr1, $ipaddr2) as $network) {
$imported_ips[] = $network; $imported_ips[] = $network;
$imported_descs[] = $impdesc; $imported_descs[] = $impdesc;
} }
} }
} 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) && !is_hostname($impip) && !empty($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;
} }
} }
} }
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'] = "network";
$alias['descr'] = $pconfig['descr']; $alias['descr'] = $pconfig['descr'];
$config['aliases']['alias'][] = $alias; $config['aliases']['alias'][] = $alias;
// Sort list // Sort list
$config['aliases']['alias'] = msort($config['aliases']['alias'], "name"); $config['aliases']['alias'] = msort($config['aliases']['alias'], "name");
if (write_config()) { if (write_config()) {
mark_subsystem_dirty('aliases'); mark_subsystem_dirty('aliases');
} }
redirectHeader("firewall_aliases.php"); redirectHeader("firewall_aliases.php");
exit; exit;
} }
} }
$pgtitle = array(gettext("Firewall"),gettext("Aliases"),gettext("Bulk import")); $pgtitle = array(gettext("Firewall"),gettext("Aliases"),gettext("Bulk import"));
...@@ -148,75 +148,75 @@ include("head.inc"); ...@@ -148,75 +148,75 @@ include("head.inc");
?> ?>
<body> <body>
<?php include("fbegin.inc"); ?> <?php include("fbegin.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"> <div class="content-box">
<header class="content-box-head container-fluid"> <header class="content-box-head container-fluid">
<h3><?=gettext("Alias Import");?></h3> <h3><?=gettext("Alias Import");?></h3>
</header> </header>
<div class="content-box-main"> <div class="content-box-main">
<form action="firewall_aliases_import.php" method="post" name="iform"> <form action="firewall_aliases_import.php" method="post" name="iform">
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<td colspan="2" align="right"> <td colspan="2" align="right">
<small><?=gettext("full help"); ?> </small> <small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_opnvpn_server" type="button"></i></a> <i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_opnvpn_server" type="button"></i></a>
</td> </td>
</tr> </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%">
<input name="name" type="text" class="form-control unknown" size="40" maxlength="31" value="<?=$pconfig['name'];?>" /> <input name="name" type="text" class="form-control unknown" size="40" maxlength="31" value="<?=$pconfig['name'];?>" />
<div class="hidden" for="help_for_name"> <div class="hidden" for="help_for_name">
<?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z and 0-9\"."); ?> <?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z and 0-9\"."); ?>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><a id="help_for_description" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description"); ?></td> <td><a id="help_for_description" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description"); ?></td>
<td> <td>
<input name="descr" type="text" value="<?=$pconfig['descr'];?>" /> <input name="descr" type="text" value="<?=$pconfig['descr'];?>" />
<div class="hidden" for="help_for_description"> <div class="hidden" for="help_for_description">
<?=gettext("You may enter a description here for your reference (not parsed)"); ?>. <?=gettext("You may enter a description here for your reference (not parsed)"); ?>.
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><a id="help_for_alias" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Aliases to import"); ?></td> <td><a id="help_for_alias" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Aliases to import"); ?></td>
<td> <td>
<textarea name="aliasimport" rows="15" cols="40"><?=$pconfig['aliasimport'];?></textarea> <textarea name="aliasimport" rows="15" cols="40"><?=$pconfig['aliasimport'];?></textarea>
<div class="hidden" for="help_for_alias"> <div class="hidden" for="help_for_alias">
<?=gettext("Paste in the aliases to import separated by a carriage return. Common examples are lists of IPs, networks, blacklists, etc."); ?> <?=gettext("Paste in the aliases to import separated by a carriage return. Common examples are lists of IPs, networks, blacklists, etc."); ?>
<br /> <br />
<?=gettext("The list may contain IP addresses, with or without CIDR prefix, IP ranges, blank lines (ignored) and an optional description after each IP. e.g.:"); ?> <?=gettext("The list may contain IP addresses, with or without CIDR prefix, IP ranges, blank lines (ignored) and an optional description after each IP. e.g.:"); ?>
<code> <code>
<br/>172.16.1.2 <br/>172.16.1.2
<br/>172.16.0.0/24 <br/>172.16.0.0/24
<br/>10.11.12.100-10.11.12.200 <br/>10.11.12.100-10.11.12.200
<br/>192.168.1.254 Home router <br/>192.168.1.254 Home router
<br/>10.20.0.0/16 Office network <br/>10.20.0.0/16 Office network
<br/>10.40.1.10-10.40.1.19 Managed switches <br/>10.40.1.10-10.40.1.19 Managed switches
</code> </code>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td> <td>
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" /> <input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>"
onclick="window.location.href='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_aliases.php');?>'" /> onclick="window.location.href='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_aliases.php');?>'" />
</td> </td>
</tr> </tr>
</table> </table>
</form> </form>
</div> </div>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</section> </section>
<?php include("foot.inc"); ?> <?php include("foot.inc"); ?>
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