Project

General

Profile

Download (13.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_unbound_acls.php
5
	part of pfSense (https://www.pfsense.org/)
6

    
7
	Copyright (C) 2011 Warren Baker <warren@decoy.co.za>
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
require("guiconfig.inc");
34
require("unbound.inc");
35

    
36
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound_acls.php');
37

    
38
if (!is_array($config['unbound']['acls'])) {
39
	$config['unbound']['acls'] = array();
40
}
41

    
42
$a_acls = &$config['unbound']['acls'];
43

    
44
$id = $_GET['id'];
45
if (isset($_POST['aclid'])) {
46
	$id = $_POST['aclid'];
47
}
48

    
49
$act = $_GET['act'];
50
if (isset($_POST['act'])) {
51
	$act = $_POST['act'];
52
}
53

    
54
if ($act == "del") {
55
	if (!$a_acls[$id]) {
56
		pfSenseHeader("services_unbound_acls.php");
57
		exit;
58
	}
59

    
60
	unset($a_acls[$id]);
61
	write_config();
62
	mark_subsystem_dirty('unbound');
63
}
64

    
65
if ($act == "new") {
66
	$id = unbound_get_next_id();
67
}
68

    
69
if ($act == "edit") {
70
	if (isset($id) && $a_acls[$id]) {
71
		$pconfig = $a_acls[$id];
72
		$networkacl = $a_acls[$id]['row'];
73
	}
74
}
75

    
76
if ($_POST) {
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	if ($_POST['apply']) {
81
		$retval = services_unbound_configure();
82
		$savemsg = get_std_save_message($retval);
83
		if ($retval == 0)
84
			clear_subsystem_dirty('unbound');
85
	} else {
86

    
87
		// input validation - only allow 50 entries in a single ACL
88
		for($x=0; $x<50; $x++) {
89
			if (isset($pconfig["acl_network{$x}"])) {
90
				$networkacl[$x] = array();
91
				$networkacl[$x]['acl_network'] = $pconfig["acl_network{$x}"];
92
				$networkacl[$x]['mask'] = $pconfig["mask{$x}"];
93
				$networkacl[$x]['description'] = $pconfig["description{$x}"];
94
				if (!is_ipaddr($networkacl[$x]['acl_network'])) {
95
					$input_errors[] = gettext("You must enter a valid IP address for each row under Networks.");
96
				}
97

    
98
				if (is_ipaddr($networkacl[$x]['acl_network'])) {
99
					if (!is_subnet($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask'])) {
100
						$input_errors[] = gettext("You must enter a valid IPv4 netmask for each IPv4 row under Networks.");
101
					}
102
				} else if (function_exists("is_ipaddrv6")) {
103
					if (!is_ipaddrv6($networkacl[$x]['acl_network'])) {
104
						$input_errors[] = gettext("You must enter a valid IPv6 address for {$networkacl[$x]['acl_network']}.");
105
					} else if (!is_subnetv6($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask'])) {
106
						$input_errors[] = gettext("You must enter a valid IPv6 netmask for each IPv6 row under Networks.");
107
					}
108
				} else {
109
					$input_errors[] = gettext("You must enter a valid IP address for each row under Networks.");
110
				}
111
			} else if (isset($networkacl[$x])) {
112
				unset($networkacl[$x]);
113
			}
114
		}
115

    
116
		if (!$input_errors) {
117
			if ($pconfig['Submit'] == gettext("Save")) {
118
				$acl_entry = array();
119
				$acl_entry['aclid'] = $pconfig['aclid'];
120
				$acl_entry['aclname'] = $pconfig['aclname'];
121
				$acl_entry['aclaction'] = $pconfig['aclaction'];
122
				$acl_entry['description'] = $pconfig['description'];
123
				$acl_entry['aclid'] = $pconfig['aclid'];
124
				$acl_entry['row'] = array();
125
				foreach ($networkacl as $acl) {
126
					$acl_entry['row'][] = $acl;
127
				}
128

    
129
				if (isset($id) && $a_acls[$id]) {
130
					$a_acls[$id] = $acl_entry;
131
				} else {
132
					$a_acls[] = $acl_entry;
133
				}
134

    
135
				mark_subsystem_dirty("unbound");
136
				write_config();
137

    
138
				pfSenseHeader("/services_unbound_acls.php");
139
				exit;
140
			}
141

    
142
		}
143
	}
144
}
145

    
146
$closehead = false;
147
$pgtitle = "Services: DNS Resolver: Access Lists";
148
$shortcut_section = "resolver";
149
include("head.inc");
150

    
151
?>
152

    
153
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
154
<script type="text/javascript" src="/javascript/row_helper.js"></script>
155

    
156
<script type="text/javascript">
157
//<![CDATA[
158
	rowname[0] = "acl_network";
159
	rowtype[0] = "textbox,ipv4v6";
160
	rowsize[0] = "30";
161

    
162
	rowname[1] = "mask";
163
	rowtype[1] = "select,ipv4v6";
164
	rowsize[1] = "1";
165

    
166
	rowname[2] = "description";
167
	rowtype[2] = "textbox";
168
	rowsize[2] = "40";
169
//]]>
170
</script>
171
</head>
172

    
173
<body>
174

    
175
<?php include("fbegin.inc"); ?>
176
<form action="services_unbound_acls.php" method="post" name="iform" id="iform">
177
<?php if ($input_errors) print_input_errors($input_errors); ?>
178
<?php if ($savemsg) print_info_box($savemsg); ?>
179
<?php if (is_subsystem_dirty('unbound')): ?><br/>
180
<?php print_info_box_np(gettext("The configuration of the DNS Resolver, has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));?><br />
181
<?php endif; ?>
182

    
183
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="services unbound acls">
184
	<tbody>
185
		<tr>
186
			<td class="tabnavtbl">
187
				<?php
188
					$tab_array = array();
189
					$tab_array[] = array(gettext("General Settings"), false, "/services_unbound.php");
190
					$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
191
					$tab_array[] = array(gettext("Access Lists"), true, "/services_unbound_acls.php");
192
					display_top_tabs($tab_array, true);
193
				?>
194
			</td>
195
		</tr>
196
		<tr>
197
			<td id="mainarea">
198
				<div class="tabcont">
199
					<?php if($act=="new" || $act=="edit"): ?>
200
						<input name="aclid" type="hidden" value="<?=$id;?>" />
201
						<input name="act" type="hidden" value="<?=$act;?>" />
202

    
203
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
204
						<tr>
205
							<td colspan="2" valign="top" class="listtopic"><?=ucwords(sprintf(gettext("%s Access List"),$act));?></td>
206
						</tr>
207
						<tr>
208
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Access List name");?></td>
209
							<td width="78%" class="vtable">
210
								<input name="aclname" type="text" class="formfld" id="aclname" size="30" maxlength="30" value="<?=htmlspecialchars($pconfig['aclname']);?>" />
211
								<br />
212
								<span class="vexpl"><?=gettext("Provide an Access List name.");?></span>
213
							</td>
214
						</tr>
215
						<tr>
216
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Action");?></td>
217
							<td width="78%" class="vtable">
218
								<select name="aclaction" class="formselect">
219
									<?php $types = explode(",", "Allow,Deny,Refuse,Allow Snoop"); foreach ($types as $type): ?>
220
									<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['aclaction'])) echo "selected=\"selected\""; ?>>
221
									<?=htmlspecialchars($type);?>
222
									</option>
223
									<?php endforeach; ?>
224
								</select>
225
								<br />
226
								<span class="vexpl">
227
									<?=gettext("Choose what to do with DNS requests that match the criteria specified below.");?> <br />
228
									<?=gettext("<b>Deny:</b> This action stops queries from hosts within the netblock defined below.");?> <br />
229
									<?=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 />
230
									<?=gettext("<b>Allow:</b> This action allows queries from hosts within the netblock defined below.");?> <br />
231
									<?=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 />
232
								</span>
233
							</td>
234
						</tr>
235
						<tr>
236
						<td width="22%" valign="top" class="vncellreq"><?=gettext("Networks");?></td>
237
						<td width="78%" class="vtable">
238
							<table id="maintable" summary="networks">
239
								<tbody>
240
									<tr>
241
										<td><div id="onecolumn"><?=gettext("Network");?></div></td>
242
										<td><div id="twocolumn"><?=gettext("CIDR");?></div></td>
243
										<td><div id="threecolumn"><?=gettext("Description");?></div></td>
244
									</tr>
245
									<?php $counter = 0; ?>
246
									<?php
247
										if($networkacl)
248
											foreach($networkacl as $item):
249
									?>
250
											<?php
251
												$network = $item['acl_network'];
252
												$cidr = $item['mask'];
253
												$description = $item['description'];
254
											?>
255
									<tr>
256
										<td>
257
											<input name="acl_network<?=$counter;?>" type="text" class="formfld unknown ipv4v6" id="acl_network<?=$counter;?>" size="30" value="<?=htmlspecialchars($network);?>" />
258
										</td>
259
										<td>
260
											<select name="mask<?=$counter;?>" class="formselect ipv4v6" id="mask<?=$counter;?>">
261
											<?php
262
												for ($i = 128; $i > 0; $i--) {
263
													echo "<option value=\"$i\" ";
264
													if ($i == $cidr) echo "selected=\"selected\"";
265
													echo ">" . $i . "</option>";
266
												}
267
											?>
268
											</select>
269
										</td>
270
										<td>
271
											<input name="description<?=$counter;?>" type="text" class="formfld unknown" id="description<?=$counter;?>" size="40" value="<?=htmlspecialchars($description);?>" />
272
										</td>
273
										<td>
274
											<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" alt="delete" /></a>
275
										</td>
276
									</tr>
277
									<?php $counter++; ?>
278
									<?php endforeach; ?>
279
								</tbody>
280
							</table>
281
							<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
282
								<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
283
							</a>
284
							<script type="text/javascript">
285
							//<![CDATA[
286
								field_counter_js = 3;
287
								rows = 1;
288
								totalrows = <?php echo $counter; ?>;
289
								loaded = <?php echo $counter; ?>;
290
							//]]>
291
							</script>
292

    
293
							</td>
294
						</tr>
295

    
296
						<tr>
297
							<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
298
							<td width="78%" class="vtable">
299
								<input name="description" type="text" class="formfld unknown" id="description" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['description']);?>" />
300
								<br />
301
								<span class="vexpl"><?=gettext("You may enter a description here for your reference.");?></span>
302
							</td>
303
						</tr>
304
						<tr>
305
							<td>&nbsp;</td>
306
						</tr>
307
						<tr>
308
							<td width="22%" valign="top">&nbsp;</td>
309
							<td width="78%">
310
								&nbsp;<br />&nbsp;
311
								<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
312
								<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
313
							</td>
314
						</tr>
315
					</table>
316

    
317
				<?php else: ?>
318

    
319
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="results">
320
					<thead>
321
						<tr>
322
							<td width="25%" class="listhdrr"><?=gettext("Access List Name"); ?></td>
323
							<td width="25%" class="listhdrr"><?=gettext("Action"); ?></td>
324
							<td width="45%" class="listhdr"><?=gettext("Description"); ?></td>
325
							<td width="5%" class="list">&nbsp;</td>
326
						</tr>
327
					</thead>
328
					<tfoot>
329
						<tr>
330
							<td class="list" colspan="3">&nbsp;</td>
331
							<td class="list">
332
								<table border="0" cellspacing="0" cellpadding="1" summary="icons">
333
									<tr>
334
										<td width="17">&nbsp;</td>
335
										<td valign="middle"><a href="services_unbound_acls.php?act=new">
336
											<img src="./themes/<?=$g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("Add new Access List"); ?>" border="0" alt="add" />
337
										</a></td>
338
									</tr>
339
								</table>
340
							</td>
341
						</tr>
342
						<tr>
343
							<td colspan="4">
344
								<p>
345
									<?=gettext("Access Lists to control access to the DNS Resolver can be defined here.");?>
346
								</p>
347
							</td>
348
						</tr>
349
					</tfoot>
350
					<tbody>
351
					<?php
352
						$i = 0;
353
						foreach($a_acls as $acl):
354
					?>
355
						<tr ondblclick="document.location='services_unbound_acls.php?act=edit&amp;id=<?=$i;?>'">
356
							<td class="listlr">
357
								<?=htmlspecialchars($acl['aclname']);?>
358
							</td>
359
							<td class="listr">
360
								<?=htmlspecialchars($acl['aclaction']);?>
361
							</td>
362
							<td class="listbg">
363
								<?=htmlspecialchars($acl['description']);?>
364
							</td>
365
							<td valign="middle" class="list nowrap">
366
								<table border="0" cellspacing="0" cellpadding="1" summary="icons">
367
									<tr>
368
										<td valign="middle"><a href="services_unbound_acls.php?act=edit&amp;id=<?=$i;?>">
369
											<img src="./themes/<?=$g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit access list"); ?>" width="17" height="17" border="0" alt="edit" />
370
										</a></td>
371
										<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?"); ?>')">
372
											<img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete access list"); ?>" width="17" height="17" border="0" alt="delete" />
373
										</a></td>
374
									</tr>
375
								</table>
376
							</td>
377
						</tr>
378
					<?php
379
						$i++;
380
						endforeach;
381
					?>
382
					<tr style="display:none"><td></td></tr>
383
					</tbody>
384
				</table>
385
			<?php endif; ?>
386
			</div>
387
			</td>
388
		</tr>
389
	</tbody>
390
</table>
391
</form>
392

    
393
<?php include("fend.inc"); ?>
394
</body>
395
</html>
(171-171/256)