1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_aliases_edit.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
|
$pgtitle = array("Firewall","Aliases","Import");
|
41
|
|
42
|
$reserved_keywords = array("pass", "out", "queue", "max", "min", "pptp");
|
43
|
|
44
|
require("guiconfig.inc");
|
45
|
require("filter.inc");
|
46
|
require("shaper.inc");
|
47
|
|
48
|
$reserved_ifs = get_configured_interface_list(false, true);
|
49
|
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs);
|
50
|
|
51
|
if (!is_array($config['aliases']['alias']))
|
52
|
$config['aliases']['alias'] = array();
|
53
|
|
54
|
aliases_sort();
|
55
|
$a_aliases = &$config['aliases']['alias'];
|
56
|
|
57
|
if($_POST['aliasimport'] <> "") {
|
58
|
$reqdfields = explode(" ", "name aliasimport");
|
59
|
$reqdfieldsn = explode(",", "Name,Aliases");
|
60
|
|
61
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
62
|
|
63
|
if (is_validaliasname($_POST['name']) == false)
|
64
|
$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
|
65
|
|
66
|
/* check for name conflicts */
|
67
|
foreach ($a_aliases as $alias) {
|
68
|
if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
|
69
|
continue;
|
70
|
|
71
|
if ($alias['name'] == $_POST['name']) {
|
72
|
$input_errors[] = "An alias with this name already exists.";
|
73
|
break;
|
74
|
}
|
75
|
}
|
76
|
|
77
|
/* Check for reserved keyword names */
|
78
|
foreach($reserved_keywords as $rk)
|
79
|
if ($rk == $_POST['name'])
|
80
|
$input_errors[] = "Cannot use a reserved keyword as alias name $rk";
|
81
|
|
82
|
/* check for name interface description conflicts */
|
83
|
foreach($config['interfaces'] as $interface) {
|
84
|
if($interface['descr'] == $_POST['name']) {
|
85
|
$input_errors[] = "An interface description with this name already exists.";
|
86
|
break;
|
87
|
}
|
88
|
}
|
89
|
|
90
|
/* Validate imported hosts or networks */
|
91
|
switch ($_POST['type']) {
|
92
|
|
93
|
case "host" :
|
94
|
if ($_POST['aliasimport']) {
|
95
|
$toimport = split("\n", $_POST['aliasimport']);
|
96
|
foreach ($toimport as $impip) {
|
97
|
if (!is_ipaddr(trim($impip)))
|
98
|
$input_errors[] = "$impip is not an ip address. Please correct the error to continue";
|
99
|
}
|
100
|
}
|
101
|
break;
|
102
|
|
103
|
case "network" :
|
104
|
if ($_POST['aliasimport']) {
|
105
|
$toimport = split("\n", $_POST['aliasimport']);
|
106
|
foreach ($toimport as $impip) {
|
107
|
list($impip, $mask) = split('/',$impip);
|
108
|
if (!is_ipaddr(trim($impip)))
|
109
|
$input_errors[] = "$impip is not an ip address. Please correct the error to continue";
|
110
|
if (!is_numeric(trim($mask)) or ($mask > 32) or ($mask < 0))
|
111
|
$input_errors[] = "The field '$mask' must contain a valid CIDR range.";
|
112
|
}
|
113
|
}
|
114
|
break;
|
115
|
}
|
116
|
|
117
|
/* create details for each ip. IPs also gets arranged better in config.xml */
|
118
|
$final_address_details .= "Entry added" . " ";
|
119
|
$final_address_details .= date('r');
|
120
|
$final_address_details .= "||";
|
121
|
|
122
|
|
123
|
if ($_POST['aliasimport']) {
|
124
|
$detail = "";
|
125
|
$myips = "";
|
126
|
$toimport2 = split("\n", $_POST['aliasimport']);
|
127
|
foreach($toimport2 as $impip2){
|
128
|
if ($impip2 !== ""){
|
129
|
$myips .= trim($impip2) . " ";
|
130
|
$detail .= $final_address_details;
|
131
|
}
|
132
|
}
|
133
|
}
|
134
|
$myips = substr($myips,0,-1);
|
135
|
|
136
|
if (!$input_errors) {
|
137
|
$alias = array();
|
138
|
$alias['name'] = $_POST['name'];
|
139
|
$alias['address'] = $myips; /* str_replace("\n", " ", $_POST['aliasimport']); */
|
140
|
$alias['type'] = $_POST['type'];
|
141
|
$alias['descr'] = $_POST['descr'];
|
142
|
$alias['detail'] = $detail;
|
143
|
$a_aliases[] = $alias;
|
144
|
write_config();
|
145
|
pfSenseHeader("firewall_aliases.php");
|
146
|
exit;
|
147
|
}
|
148
|
}
|
149
|
|
150
|
include("head.inc");
|
151
|
|
152
|
?>
|
153
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
154
|
<?php include("fbegin.inc"); ?>
|
155
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
156
|
<div id="niftyOutter">
|
157
|
<form action="firewall_aliases_import.php" method="post" name="iform" id="iform">
|
158
|
<div id="inputerrors"></div>
|
159
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
160
|
<tr>
|
161
|
<td colspan="2" valign="top" class="listtopic">Alias Import</td>
|
162
|
</tr>
|
163
|
<tr>
|
164
|
<td valign="top" class="vncellreq">Alias Name</td>
|
165
|
<td class="vtable"> <input name="name" type="text" class="formfld unknown" id="name" size="40" value="<?=htmlspecialchars($_POST['name']);?>" />
|
166
|
<br /> <span class="vexpl">
|
167
|
The name of the alias may only consist of the characters a-z, A-Z and 0-9.</span></td>
|
168
|
</tr>
|
169
|
<tr>
|
170
|
<td width="22%" valign="top" class="vncell">Description</td>
|
171
|
<td width="78%" class="vtable"> <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($_POST['descr']);?>" />
|
172
|
<br /> <span class="vexpl">You may enter a description here
|
173
|
for your reference (not parsed).</span></td>
|
174
|
</tr>
|
175
|
<tr>
|
176
|
<td width="22%" valign="top" class="vncellreq">Type</td>
|
177
|
<td width="78%" class="vtable">
|
178
|
<select name="type" class="formselect" id="type">
|
179
|
<?php
|
180
|
$types = explode(",", "Host(s), Network(s)");
|
181
|
$vals = explode(" ", "host network");
|
182
|
$j = 0; for ($j = 0; $j < count($vals); $j++): ?>
|
183
|
<option value="<?=$vals[$j];?>" <?php if ($vals[$j] == $pconfig['type']) echo "selected";?>>
|
184
|
<?=htmlspecialchars($types[$j]);?>
|
185
|
</option>
|
186
|
<?php endfor; ?>
|
187
|
</select>
|
188
|
<br /> <span class="vexpl">
|
189
|
Select which type you will import</span></td>
|
190
|
</td>
|
191
|
</tr>
|
192
|
|
193
|
<tr>
|
194
|
<td valign="top" class="vncellreq">Aliases to import</td>
|
195
|
<td class="vtable"><textarea name="aliasimport" ROWS="15" COLS="40"><?php echo $_POST['aliasimport']; ?></textarea>
|
196
|
<br /> <span class="vexpl">Paste in the aliases to import separated by a carriage return. Common examples are lists of IPs, networks, blacklists, etc.
|
197
|
<br /> The Host list may contain only IP addresses. Network IP/CIDR only</span></td>
|
198
|
</tr>
|
199
|
<tr>
|
200
|
<td width="22%" valign="top"> </td>
|
201
|
<td width="78%">
|
202
|
<input id="submit" name="Submit" type="submit" class="formbtn" value="Save" />
|
203
|
<input class="formbtn" type="button" value="Cancel" onclick="history.back()" />
|
204
|
</tr>
|
205
|
</table>
|
206
|
|
207
|
|
208
|
</form>
|
209
|
</div>
|
210
|
|
211
|
<?php include("fend.inc"); ?>
|
212
|
|
213
|
<script type="text/javascript">
|
214
|
NiftyCheck();
|
215
|
Rounded("div#nifty","top","#FFF","#EEEEEE","smooth");
|
216
|
</script>
|
217
|
|
218
|
|
219
|
</body>
|
220
|
</html>
|