1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_aliases_import.php
|
5
|
Copyright (C) 2005 Scott Ullrich
|
6
|
All rights reserved.
|
7
|
|
8
|
Redistribution and use in source and binary forms, with or without
|
9
|
modification, are permitted provided that the following conditions are met:
|
10
|
|
11
|
1. Redistributions of source code must retain the above copyright notice,
|
12
|
this list of conditions and the following disclaimer.
|
13
|
|
14
|
2. Redistributions in binary form must reproduce the above copyright
|
15
|
notice, this list of conditions and the following disclaimer in the
|
16
|
documentation and/or other materials provided with the distribution.
|
17
|
|
18
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
19
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
21
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
22
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27
|
POSSIBILITY OF SUCH DAMAGE.
|
28
|
*/
|
29
|
/*
|
30
|
pfSense_MODULE: filter
|
31
|
*/
|
32
|
|
33
|
##|+PRIV
|
34
|
##|*IDENT=page-firewall-alias-import
|
35
|
##|*NAME=Firewall: Alias: Import page
|
36
|
##|*DESCR=Allow access to the 'Firewall: Alias: Import' page.
|
37
|
##|*MATCH=firewall_aliases_import.php*
|
38
|
##|-PRIV
|
39
|
|
40
|
|
41
|
// Keywords not allowed in names
|
42
|
$reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
|
43
|
|
44
|
require("guiconfig.inc");
|
45
|
require_once("util.inc");
|
46
|
require_once("filter.inc");
|
47
|
require("shaper.inc");
|
48
|
|
49
|
$pgtitle = array(gettext("Firewall"),gettext("Aliases"),gettext("Bulk import"));
|
50
|
|
51
|
// Add all Load balance names to reserved_keywords
|
52
|
if (is_array($config['load_balancer']['lbpool']))
|
53
|
foreach ($config['load_balancer']['lbpool'] as $lbpool)
|
54
|
$reserved_keywords[] = $lbpool['name'];
|
55
|
|
56
|
$reserved_ifs = get_configured_interface_list(false, true);
|
57
|
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
|
58
|
|
59
|
if (!is_array($config['aliases']['alias']))
|
60
|
$config['aliases']['alias'] = array();
|
61
|
$a_aliases = &$config['aliases']['alias'];
|
62
|
|
63
|
if($_POST['aliasimport'] <> "") {
|
64
|
$reqdfields = explode(" ", "name aliasimport");
|
65
|
$reqdfieldsn = array(gettext("Name"),gettext("Aliases"));
|
66
|
|
67
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
68
|
|
69
|
if (is_validaliasname($_POST['name']) == false)
|
70
|
$input_errors[] = gettext("The alias name may only consist of the characters") . " a-z, A-Z, 0-9, _.";
|
71
|
|
72
|
/* check for name duplicates */
|
73
|
if (is_alias($_POST['name']))
|
74
|
$input_errors[] = gettext("An alias with this name already exists.");
|
75
|
|
76
|
|
77
|
/* Check for reserved keyword names */
|
78
|
foreach($reserved_keywords as $rk)
|
79
|
if ($rk == $_POST['name'])
|
80
|
$input_errors[] = sprintf(gettext("Cannot use a reserved keyword as alias name %s"), $rk);
|
81
|
|
82
|
/* check for name interface description conflicts */
|
83
|
foreach($config['interfaces'] as $interface) {
|
84
|
if($interface['descr'] == $_POST['name']) {
|
85
|
$input_errors[] = gettext("An interface description with this name already exists.");
|
86
|
break;
|
87
|
}
|
88
|
}
|
89
|
|
90
|
if ($_POST['aliasimport']) {
|
91
|
$tocheck = explode("\n", $_POST['aliasimport']);
|
92
|
$imported = array();
|
93
|
foreach ($tocheck as $impip) {
|
94
|
$impip = trim($impip);
|
95
|
if (is_iprange($impip)) {
|
96
|
list($startip, $endip) = explode('-', $impip);
|
97
|
$rangesubnets = ip_range_to_subnet_array($startip, $endip);
|
98
|
$imported = array_merge($imported, $rangesubnets);
|
99
|
} else if (!is_ipaddr($impip) && !is_subnet($impip) && !empty($impip)) {
|
100
|
$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $impip);
|
101
|
} elseif (!empty($impip)) {
|
102
|
$imported[] = $impip;
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
|
107
|
if (!$input_errors && is_array($imported)) {
|
108
|
$alias = array();
|
109
|
$alias['address'] = implode(" ", $imported);
|
110
|
$alias['name'] = $_POST['name'];
|
111
|
$alias['type'] = "network";
|
112
|
$alias['descr'] = $_POST['descr'];
|
113
|
$a_aliases[] = $alias;
|
114
|
|
115
|
// Sort list
|
116
|
$a_aliases = msort($a_aliases, "name");
|
117
|
|
118
|
if (write_config())
|
119
|
mark_subsystem_dirty('aliases');
|
120
|
pfSenseHeader("firewall_aliases.php");
|
121
|
|
122
|
exit;
|
123
|
}
|
124
|
}
|
125
|
|
126
|
include("head.inc");
|
127
|
|
128
|
?>
|
129
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
130
|
<?php include("fbegin.inc"); ?>
|
131
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
132
|
<div id="niftyOutter">
|
133
|
<form action="firewall_aliases_import.php" method="post" name="iform" id="iform">
|
134
|
<div id="inputerrors"></div>
|
135
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall alias import">
|
136
|
<tr>
|
137
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Alias Import"); ?></td>
|
138
|
</tr>
|
139
|
<tr>
|
140
|
<td valign="top" class="vncellreq"><?=gettext("Alias Name"); ?></td>
|
141
|
<td class="vtable"> <input name="name" type="text" class="formfld unknown" id="name" size="40" value="<?=htmlspecialchars($_POST['name']);?>" />
|
142
|
<br /> <span class="vexpl">
|
143
|
<?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z and 0-9\"."); ?></span></td>
|
144
|
</tr>
|
145
|
<tr>
|
146
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
|
147
|
<td width="78%" class="vtable"> <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($_POST['descr']);?>" />
|
148
|
<br /> <span class="vexpl"><?=gettext("You may enter a description here " .
|
149
|
"for your reference (not parsed)"); ?>.</span></td>
|
150
|
</tr>
|
151
|
<tr>
|
152
|
<td valign="top" class="vncellreq"><?=gettext("Aliases to import"); ?></td>
|
153
|
<td class="vtable"><textarea name="aliasimport" rows="15" cols="40"><?php echo $_POST['aliasimport']; ?></textarea>
|
154
|
<br /> <span class="vexpl"><?=gettext("Paste in the aliases to import separated by a carriage return. Common examples are lists of IPs, networks, blacklists, etc."); ?>
|
155
|
<br /> <?=gettext("The list may contain only IP addresses."); ?> </span></td>
|
156
|
</tr>
|
157
|
<tr>
|
158
|
<td width="22%" valign="top"> </td>
|
159
|
<td width="78%">
|
160
|
<input id="submit" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
|
161
|
<input class="formbtn" type="button" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
|
162
|
</td></tr>
|
163
|
</table>
|
164
|
|
165
|
|
166
|
</form>
|
167
|
</div>
|
168
|
|
169
|
<?php include("fend.inc"); ?>
|
170
|
|
171
|
<script type="text/javascript">
|
172
|
//<![CDATA[
|
173
|
NiftyCheck();
|
174
|
Rounded("div#nifty","top","#FFF","#EEEEEE","smooth");
|
175
|
//]]>
|
176
|
</script>
|
177
|
|
178
|
</body>
|
179
|
</html>
|