Project

General

Profile

Download (13.7 KB) Statistics
| Branch: | Tag: | Revision:
1 7ed0e844 Warren Baker
<?php
2
/* $Id$ */
3
/*
4
	services_unbound_acls.php
5 c7281770 Chris Buechler
	part of pfSense (https://www.pfsense.org/)
6 7ed0e844 Warren Baker
7
	Copyright (C) 2011 Warren Baker <warren@decoy.co.za>
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
require("guiconfig.inc");
33
require("unbound.inc");
34
35
if (!is_array($config['unbound']['acls']))
36
	$config['unbound']['acls'] = array();
37
38
$a_acls = &$config['unbound']['acls'];
39
40
$id = $_GET['id'];
41
if (isset($_POST['aclid']))
42
	$id = $_POST['aclid'];
43
44
$act = $_GET['act'];
45
if (isset($_POST['act']))
46
	$act = $_POST['act'];
47
48
if ($act == "del") {
49
	if (!$a_acls[$id]) {
50
		pfSenseHeader("services_unbound_acls.php");
51
		exit;
52
	}
53
54
	unset($a_acls[$id]);
55
	write_config();
56 519597bc Warren Baker
	services_unbound_configure();
57 8cd558b6 ayvis
	$savemsg = gettext("Access List successfully deleted")."<br />";
58 7ed0e844 Warren Baker
}
59
60
if ($act == "new") {
61
	$id = unbound_get_next_id();
62
}
63
64
if ($act == "edit") {
65
	if (isset($id) && $a_acls[$id]) {
66
		$pconfig = $a_acls[$id];
67
		$networkacl = $a_acls[$id]['row'];
68
	}
69
}
70
71
if ($_POST) {
72
73
	unset($input_errors);
74
	$pconfig = $_POST;
75
76 519597bc Warren Baker
	// input validation - only allow 50 entries in a single ACL
77 7ed0e844 Warren Baker
	for($x=0; $x<50; $x++) {
78 519597bc Warren Baker
		if (isset($pconfig["acl_network{$x}"])) {
79 7ed0e844 Warren Baker
			$networkacl[$x] = array();
80
			$networkacl[$x]['acl_network'] = $pconfig["acl_network{$x}"];
81
			$networkacl[$x]['mask'] = $pconfig["mask{$x}"];
82
			$networkacl[$x]['description'] = $pconfig["description{$x}"];
83
			if (!is_ipaddr($networkacl[$x]['acl_network']))
84
				$input_errors[] = gettext("You must enter a valid network IP address for {$networkacl[$x]['acl_network']}.");
85
86
			if (is_ipaddr($networkacl[$x]['acl_network'])) {
87
				if (!is_subnet($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask']))
88
					$input_errors[] = gettext("You must enter a valid IPv4 netmask for {$networkacl[$x]['acl_network']}/{$networkacl[$x]['mask']}.");
89
			} else if (function_exists("is_ipaddrv6")) {
90
				if (!is_ipaddrv6($networkacl[$x]['acl_network']))
91
					$input_errors[] = gettext("You must enter a valid IPv6 address for {$networkacl[$x]['acl_network']}.");
92
				else if (!is_subnetv6($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask']))
93
					$input_errors[] = gettext("You must enter a valid IPv6 netmask for {$networkacl[$x]['acl_network']}/{$networkacl[$x]['mask']}.");
94
			} else
95
				$input_errors[] = gettext("You must enter a valid IPv4 address for {$networkacl[$x]['acl_network']}.");
96 cb79dc0d Renato Botelho
		} else if (isset($networkacl[$x]))
97
			unset($networkacl[$x]);
98 7ed0e844 Warren Baker
	}
99
	
100
	if (!$input_errors) {
101
		if ($pconfig['Submit'] == gettext("Save")) {
102 8fccab67 Warren Baker
			$acl_entry = array();
103
			$acl_entry['aclid'] = $pconfig['aclid'];
104
			$acl_entry['aclname'] = $pconfig['aclname'];
105
			$acl_entry['aclaction'] = $pconfig['aclaction'];
106
			$acl_entry['description'] = $pconfig['description'];
107
			$acl_entry['aclid'] = $pconfig['aclid'];
108
			$acl_entry['row'] = array();
109
			foreach ($networkacl as $acl)
110
				$acl_entry['row'][] = $acl;
111
112
			if (isset($id) && $a_acls[$id])
113
				$a_acls[$id] = $acl_entry;
114
			else
115
				$a_acls[] = $acl_entry;
116
117
118
			mark_subsystem_dirty("unbound");
119
			write_config();
120
121 7ed0e844 Warren Baker
			pfSenseHeader("/services_unbound_acls.php");
122
			exit;
123
		}
124
125
		if ($pconfig['apply']) {
126 8fccab67 Warren Baker
			clear_subsystem_dirty("unbound");
127
			$retval = 0;
128
			$retval = services_unbound_configure();
129
			$savemsg = get_std_save_message($retval);
130 7ed0e844 Warren Baker
		}
131
	}
132
}
133
134 f6543a41 Colin Fleming
$closehead = false;
135 7ed0e844 Warren Baker
$pgtitle = "Services: DNS Resolver: Access Lists";
136
include("head.inc");
137
138
?>
139
140 dbf81496 Renato Botelho
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
141
<script type="text/javascript" src="/javascript/row_helper.js"></script>
142 7ed0e844 Warren Baker
143
<script type="text/javascript">
144 f6543a41 Colin Fleming
//<![CDATA[
145 7ed0e844 Warren Baker
	rowname[0] = "acl_network";
146 dbf81496 Renato Botelho
	rowtype[0] = "textbox,ipv4v6";
147 7ed0e844 Warren Baker
	rowsize[0] = "30";
148 dbf81496 Renato Botelho
149 7ed0e844 Warren Baker
	rowname[1] = "mask";
150 dbf81496 Renato Botelho
	rowtype[1] = "select,ipv4v6";
151
	rowsize[1] = "1";
152
153 7ed0e844 Warren Baker
	rowname[2] = "description";
154 dbf81496 Renato Botelho
	rowtype[2] = "textbox";
155 7ed0e844 Warren Baker
	rowsize[2] = "40";
156 f6543a41 Colin Fleming
//]]>
157 7ed0e844 Warren Baker
</script>
158 f6543a41 Colin Fleming
</head>
159 7ed0e844 Warren Baker
160 9961044a Warren Baker
<body>
161 7ed0e844 Warren Baker
162
<?php include("fbegin.inc"); ?>
163
<form action="services_unbound_acls.php" method="post" name="iform" id="iform">
164
<?php
165
if (!$savemsg)
166
	$savemsg = "";
167
168
if ($input_errors)
169
	print_input_errors($input_errors);
170
171
if ($savemsg)
172
	print_info_box($savemsg);
173
174
if (is_subsystem_dirty("unbound"))
175
		print_info_box_np(gettext("The settings for the DNS Resolver have changed. You must apply the configuration to take affect."));
176
?>
177 9961044a Warren Baker
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="services unbound acls">
178
	<tbody>
179
		<tr>
180
			<td class="tabnavtbl">
181 7ed0e844 Warren Baker
				<?php
182 9961044a Warren Baker
					$tab_array = array();
183
					$tab_array[] = array(gettext("General Settings"), false, "/services_unbound.php");
184
					$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
185
					$tab_array[] = array(gettext("Access Lists"), true, "/services_unbound_acls.php");
186
					display_top_tabs($tab_array, true);
187 7ed0e844 Warren Baker
				?>
188 9961044a Warren Baker
			</td>
189
		</tr>
190
		<tr>
191
			<td id="mainarea">
192
				<div class="tabcont">
193
					<?php if($act=="new" || $act=="edit"): ?>
194 f6543a41 Colin Fleming
						<input name="aclid" type="hidden" value="<?=$id;?>" />
195
						<input name="act" type="hidden" value="<?=$act;?>" />
196 9961044a Warren Baker
197 f6543a41 Colin Fleming
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
198 9961044a Warren Baker
						<tr>
199
							<td colspan="2" valign="top" class="listtopic"><?=ucwords(sprintf(gettext("%s Access List"),$act));?></td>
200
						</tr>
201
						<tr>
202
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Access List name");?></td>
203
							<td width="78%" class="vtable">
204 f6543a41 Colin Fleming
								<input name="aclname" type="text" class="formfld" id="aclname" size="30" maxlength="30" value="<?=htmlspecialchars($pconfig['aclname']);?>" />
205 9961044a Warren Baker
								<br />
206
								<span class="vexpl"><?=gettext("Provide an Access List name.");?></span>
207
							</td>
208
						</tr>
209
						<tr>
210
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Action");?></td>
211
							<td width="78%" class="vtable">
212
								<select name="aclaction" class="formselect">
213
									<?php $types = explode(",", "Allow,Deny,Refuse,Allow Snoop"); foreach ($types as $type): ?>
214 f6543a41 Colin Fleming
									<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['aclaction'])) echo "selected=\"selected\""; ?>>
215 9961044a Warren Baker
									<?=htmlspecialchars($type);?>
216
									</option>
217
									<?php endforeach; ?>
218
								</select>
219 8cd558b6 ayvis
								<br />
220 9961044a Warren Baker
								<span class="vexpl">
221 8cd558b6 ayvis
									<?=gettext("Choose what to do with DNS requests that match the criteria specified below.");?> <br />
222
									<?=gettext("<b>Deny:</b> This action stops queries from hosts within the netblock defined below.");?> <br />
223
									<?=gettext("<b>Refuse:</b> This action also stops queries from hosts within the netblock defined below, but sends a DNS rcode REFUSED error message back to the client.");?> <br />
224
									<?=gettext("<b>Allow:</b> This action allows queries from hosts within the netblock defined below.");?> <br />
225
									<?=gettext("<b>Allow Snoop:</b> This action allows recursive and nonrecursive access from hosts within the netblock defined below. Used for cache snooping and ideally should only be configured for your administrative host.");?> <br />
226 9961044a Warren Baker
								</span>
227
							</td>
228
						</tr>
229
						<tr>
230
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Networks");?></td>
231
						<td width="78%" class="vtable">
232 f6543a41 Colin Fleming
							<table id="maintable" summary="networks">
233 9961044a Warren Baker
								<tbody>
234
									<tr>
235
										<td><div id="onecolumn"><?=gettext("Network");?></div></td>
236
										<td><div id="twocolumn"><?=gettext("CIDR");?></div></td>
237
										<td><div id="threecolumn"><?=gettext("Description");?></div></td>
238
									</tr>
239
									<?php $counter = 0; ?>
240
									<?php
241
										if($networkacl)
242
											foreach($networkacl as $item):
243
									?>
244
											<?php
245
												$network = $item['acl_network'];
246
												$cidr = $item['mask'];
247
												$description = $item['description'];
248
											?>
249
									<tr>
250
										<td>
251 dbf81496 Renato Botelho
											<input name="acl_network<?=$counter;?>" type="text" class="formfld unknown ipv4v6" id="acl_network<?=$counter;?>" size="30" value="<?=htmlspecialchars($network);?>" />
252 9961044a Warren Baker
										</td>
253
										<td>
254 dbf81496 Renato Botelho
											<select name="mask<?=$counter;?>" class="formselect ipv4v6" id="mask<?=$counter;?>">
255 9961044a Warren Baker
											<?php
256
												for ($i = 128; $i > 0; $i--) {
257
													echo "<option value=\"$i\" ";
258 f6543a41 Colin Fleming
													if ($i == $cidr) echo "selected=\"selected\"";
259 9961044a Warren Baker
													echo ">" . $i . "</option>";
260
												}
261
											?>
262
											</select>
263
										</td>
264
										<td>
265 dbf81496 Renato Botelho
											<input name="description<?=$counter;?>" type="text" class="formfld unknown" id="description<?=$counter;?>" size="40" value="<?=htmlspecialchars($description);?>" />
266 9961044a Warren Baker
										</td>
267
										<td>
268 f6543a41 Colin Fleming
											<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" alt="delete" /></a>
269 9961044a Warren Baker
										</td>
270
									</tr>
271
									<?php $counter++; ?>
272
									<?php endforeach; ?>
273
								</tbody>
274
							</table>
275
							<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
276
								<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
277
							</a>
278
							<script type="text/javascript">
279 f6543a41 Colin Fleming
							//<![CDATA[
280 9961044a Warren Baker
								field_counter_js = 3;
281
								rows = 1;
282
								totalrows = <?php echo $counter; ?>;
283
								loaded = <?php echo $counter; ?>;
284 f6543a41 Colin Fleming
							//]]>
285 9961044a Warren Baker
							</script>
286
287
							</td>
288
						</tr>
289
290
						<tr>
291
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
292
							<td width="78%" class="vtable">
293 f6543a41 Colin Fleming
								<input name="description" type="text" class="formfld unknown" id="description" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['description']);?>" />
294 9961044a Warren Baker
								<br />
295
								<span class="vexpl"><?=gettext("You may enter a description here for your reference.");?></span>
296
							</td>
297
						</tr>
298
						<tr>
299
							<td>&nbsp;</td>
300
						</tr>
301
						<tr>
302
							<td width="22%" valign="top">&nbsp;</td>
303
							<td width="78%">
304 8cd558b6 ayvis
								&nbsp;<br />&nbsp;
305 f6543a41 Colin Fleming
								<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
306 9961044a Warren Baker
							</td>
307
						</tr>
308
					</table>
309
310
				<?php else: ?>
311
312 f6543a41 Colin Fleming
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="results">
313 9961044a Warren Baker
					<thead>
314
						<tr>
315
							<td width="25%" class="listhdrr"><?=gettext("Access List Name"); ?></td>
316
							<td width="25%" class="listhdrr"><?=gettext("Action"); ?></td>
317 026f3639 Renato Botelho
							<td width="45%" class="listhdr"><?=gettext("Description"); ?></td>
318
							<td width="5%" class="list">&nbsp;</td>
319 9961044a Warren Baker
						</tr>
320
					</thead>
321 f6543a41 Colin Fleming
					<tfoot>
322
						<tr>
323 026f3639 Renato Botelho
							<td class="list" colspan="3">&nbsp;</td>
324 f6543a41 Colin Fleming
							<td class="list">
325 026f3639 Renato Botelho
								<table border="0" cellspacing="0" cellpadding="1" summary="icons">
326
									<tr>
327
										<td width="17">&nbsp;</td>
328
										<td valign="middle"><a href="services_unbound_acls.php?act=new">
329
											<img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("Add new Access List"); ?>" border="0" alt="add" />
330
										</a></td>
331
									</tr>
332
								</table>
333 f6543a41 Colin Fleming
							</td>
334
						</tr>
335
						<tr>
336
							<td colspan="4">
337
								<p>
338
									<?=gettext("Access Lists to control access to the DNS Resolver can be defined here.");?>
339
								</p>
340
							</td>
341
						</tr>
342
					</tfoot>
343 9961044a Warren Baker
					<tbody>
344
					<?php
345
						$i = 0;
346
						foreach($a_acls as $acl):
347
					?>
348 f6543a41 Colin Fleming
						<tr ondblclick="document.location='services_unbound_acls.php?act=edit&amp;id=<?=$i;?>'">
349 9961044a Warren Baker
							<td class="listlr">
350 026f3639 Renato Botelho
								<?=htmlspecialchars($acl['aclname']);?>
351 9961044a Warren Baker
							</td>
352
							<td class="listr">
353
								<?=htmlspecialchars($acl['aclaction']);?>
354
							</td>
355
							<td class="listbg">
356
								<?=htmlspecialchars($acl['description']);?>
357
							</td>
358 c1229525 Colin Fleming
							<td valign="middle" class="list nowrap">
359 026f3639 Renato Botelho
								<table border="0" cellspacing="0" cellpadding="1" summary="icons">
360
									<tr>
361
										<td valign="middle"><a href="services_unbound_acls.php?act=edit&amp;id=<?=$i;?>">
362
											<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit access list"); ?>" width="17" height="17" border="0" alt="edit" />
363
										</a></td>
364
										<td valign="middle"><a href="services_unbound_acls.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this access list?"); ?>')">
365
											<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete access list"); ?>" width="17" height="17" border="0" alt="delete" />
366
										</a></td>
367
									</tr>
368
								</table>
369 9961044a Warren Baker
							</td>
370
						</tr>
371
					<?php
372
						$i++;
373
						endforeach;
374
					?>
375 f6543a41 Colin Fleming
					<tr style="display:none"><td></td></tr>
376 9961044a Warren Baker
					</tbody>
377
				</table>
378 7ed0e844 Warren Baker
			<?php endif; ?>
379 f6543a41 Colin Fleming
			</div>
380 9961044a Warren Baker
			</td>
381
		</tr>
382
	</tbody>
383 7ed0e844 Warren Baker
</table>
384 f6543a41 Colin Fleming
</form>
385 9961044a Warren Baker
386 7ed0e844 Warren Baker
<?php include("fend.inc"); ?>
387 9961044a Warren Baker
</body>
388 f6543a41 Colin Fleming
</html>