Projet

Général

Profil

Télécharger (8,03 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_aliases_import.php @ 81ca5f88

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_ips = array();
93
		$imported_descs = array();
94
		$desc_len_err_found = false;
95
		$desc_fmt_err_found = false;
96
		foreach ($tocheck as $impline) {
97
			$implinea = explode(" ",trim($impline),2);
98
			$impip = $implinea[0];
99
			$impdesc = trim($implinea[1]);
100
			if (strlen($impdesc) < 200) {
101
				if ((strpos($impdesc, "||") === false) && (substr($impdesc, 0, 1) != "|") && (substr($impdesc, -1, 1) != "|")) {
102
					if (is_iprange($impip)) {
103
						list($startip, $endip) = explode('-', $impip);
104
						$rangesubnets = ip_range_to_subnet_array($startip, $endip);
105
						$imported_ips = array_merge($imported_ips, $rangesubnets);
106
						$rangedescs = array_fill(0, count($rangesubnets), $impdesc);
107
						$imported_descs = array_merge($imported_descs, $rangedescs);
108
					} else if (!is_ipaddr($impip) && !is_subnet($impip) && !is_hostname($impip) && !empty($impip)) {
109
						$input_errors[] = sprintf(gettext("%s is not an IP address. Please correct the error to continue"), $impip);
110
					} elseif (!empty($impip)) {
111
						$imported_ips[] = $impip;
112
						$imported_descs[] = $impdesc;
113
					}
114
				}
115
				else {
116
					if (!$desc_fmt_err_found) {
117
						$input_errors[] = gettext("Descriptions may not start or end with vertical bar (|) or contain double vertical bar ||.");
118
						$desc_fmt_err_found = true;
119
					}
120
				}
121
			}
122
			else {
123
				if (!$desc_len_err_found) {
124
					/* Note: The 200 character limit is just a practical check to avoid accidents */
125
					/* if the user pastes a large number of IP addresses without line breaks.     */
126
					$input_errors[] = gettext("Descriptions must be less than 200 characters long.");
127
					$desc_len_err_found = true;
128
				}
129
			}
130
		}
131
		unset($desc_len_err_found, $desc_fmt_err_found);
132
	}
133

    
134
	if (!$input_errors && is_array($imported_ips)) {
135
		$alias = array();
136
		$alias['address'] = implode(" ", $imported_ips);
137
		$alias['detail'] = implode("||", $imported_descs);
138
		$alias['name'] = $_POST['name'];
139
		$alias['type'] = "network";
140
		$alias['descr'] = $_POST['descr'];
141
		unset($imported_ips, $imported_descs);
142
		$a_aliases[] = $alias;
143

    
144
		// Sort list
145
		$a_aliases = msort($a_aliases, "name");
146

    
147
		if (write_config())
148
			mark_subsystem_dirty('aliases');
149
		pfSenseHeader("firewall_aliases.php");
150

    
151
		exit;
152
	}
153
}
154

    
155
include("head.inc");
156

    
157
?>
158
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
159
<?php include("fbegin.inc"); ?>
160
<?php if ($input_errors) print_input_errors($input_errors); ?>
161
<div id="niftyOutter">
162
<form action="firewall_aliases_import.php" method="post" name="iform" id="iform">
163
<div id="inputerrors"></div>
164
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall alias import">
165
	<tr>
166
		<td colspan="2" valign="top" class="listtopic"><?=gettext("Alias Import"); ?></td>
167
	</tr>
168
	<tr>
169
		<td valign="top" class="vncellreq"><?=gettext("Alias Name"); ?></td>
170
		<td class="vtable">
171
			<input name="name" type="text" class="formfld unknown" id="name" size="40" maxlength="31" value="<?=htmlspecialchars($_POST['name']);?>" />
172
			<br />
173
			<span class="vexpl">
174
				<?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z and 0-9\"."); ?>
175
			</span>
176
		</td>
177
	</tr>
178
	<tr>
179
		<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
180
		<td width="78%" class="vtable">
181
			<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($_POST['descr']);?>" />
182
			<br />
183
			<span class="vexpl">
184
				<?=gettext("You may enter a description here for your reference (not parsed)"); ?>.
185
			</span>
186
		</td>
187
	</tr>
188
	<tr>
189
		<td valign="top" class="vncellreq"><?=gettext("Aliases to import"); ?></td>
190
		<td class="vtable">
191
			<textarea name="aliasimport" rows="15" cols="40"><?php echo $_POST['aliasimport']; ?></textarea>
192
			<br />
193
			<span class="vexpl">
194
				<?=gettext("Paste in the aliases to import separated by a carriage return.  Common examples are lists of IPs, networks, blacklists, etc."); ?>
195
				<br />
196
				<?=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.:"); ?>
197
				<br />172.16.1.2
198
				<br />172.16.0.0/24
199
				<br />10.11.12.100-10.11.12.200
200
				<br />192.168.1.254 Home router
201
				<br />10.20.0.0/16 Office network
202
				<br />10.40.1.10-10.40.1.19 Managed switches
203
			</span>
204
		</td>
205
	</tr>
206
	<tr>
207
		<td width="22%" valign="top">&nbsp;</td>
208
		<td width="78%">
209
			<input id="submit" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
210
			<input class="formbtn" type="button" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
211
		</td>
212
	</tr>
213
</table>
214

    
215

    
216
</form>
217
</div>
218

    
219
<?php include("fend.inc"); ?>
220

    
221
<script type="text/javascript">
222
//<![CDATA[
223
	NiftyCheck();
224
	Rounded("div#nifty","top","#FFF","#EEEEEE","smooth");
225
//]]>
226
</script>
227

    
228
</body>
229
</html>
(61-61/255)