Projet

Général

Profil

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

univnautes / usr / local / www / services_unbound_acls.php @ 62424bdb

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
	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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound_acls.php');
36

    
37
if (!is_array($config['unbound']['acls']))
38
	$config['unbound']['acls'] = array();
39

    
40
$a_acls = &$config['unbound']['acls'];
41

    
42
$id = $_GET['id'];
43
if (isset($_POST['aclid']))
44
	$id = $_POST['aclid'];
45

    
46
$act = $_GET['act'];
47
if (isset($_POST['act']))
48
	$act = $_POST['act'];
49

    
50
if ($act == "del") {
51
	if (!$a_acls[$id]) {
52
		pfSenseHeader("services_unbound_acls.php");
53
		exit;
54
	}
55

    
56
	unset($a_acls[$id]);
57
	write_config();
58
	mark_subsystem_dirty('unbound');
59
}
60

    
61
if ($act == "new") {
62
	$id = unbound_get_next_id();
63
}
64

    
65
if ($act == "edit") {
66
	if (isset($id) && $a_acls[$id]) {
67
		$pconfig = $a_acls[$id];
68
		$networkacl = $a_acls[$id]['row'];
69
	}
70
}
71

    
72
if ($_POST) {
73
	unset($input_errors);
74
	$pconfig = $_POST;
75

    
76
	if ($_POST['apply']) {
77
		$retval = services_unbound_configure();
78
		$savemsg = get_std_save_message($retval);
79
		if ($retval == 0)
80
			clear_subsystem_dirty('unbound');
81
	} else {
82

    
83
		// input validation - only allow 50 entries in a single ACL
84
		for($x=0; $x<50; $x++) {
85
			if (isset($pconfig["acl_network{$x}"])) {
86
				$networkacl[$x] = array();
87
				$networkacl[$x]['acl_network'] = $pconfig["acl_network{$x}"];
88
				$networkacl[$x]['mask'] = $pconfig["mask{$x}"];
89
				$networkacl[$x]['description'] = $pconfig["description{$x}"];
90
				if (!is_ipaddr($networkacl[$x]['acl_network']))
91
					$input_errors[] = gettext("You must enter a valid network IP address for {$networkacl[$x]['acl_network']}.");
92

    
93
				if (is_ipaddr($networkacl[$x]['acl_network'])) {
94
					if (!is_subnet($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask']))
95
						$input_errors[] = gettext("You must enter a valid IPv4 netmask for {$networkacl[$x]['acl_network']}/{$networkacl[$x]['mask']}.");
96
				} else if (function_exists("is_ipaddrv6")) {
97
					if (!is_ipaddrv6($networkacl[$x]['acl_network']))
98
						$input_errors[] = gettext("You must enter a valid IPv6 address for {$networkacl[$x]['acl_network']}.");
99
					else if (!is_subnetv6($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask']))
100
						$input_errors[] = gettext("You must enter a valid IPv6 netmask for {$networkacl[$x]['acl_network']}/{$networkacl[$x]['mask']}.");
101
				} else
102
					$input_errors[] = gettext("You must enter a valid IPv4 address for {$networkacl[$x]['acl_network']}.");
103
			} else if (isset($networkacl[$x]))
104
				unset($networkacl[$x]);
105
		}
106

    
107
		if (!$input_errors) {
108
			if ($pconfig['Submit'] == gettext("Save")) {
109
				$acl_entry = array();
110
				$acl_entry['aclid'] = $pconfig['aclid'];
111
				$acl_entry['aclname'] = $pconfig['aclname'];
112
				$acl_entry['aclaction'] = $pconfig['aclaction'];
113
				$acl_entry['description'] = $pconfig['description'];
114
				$acl_entry['aclid'] = $pconfig['aclid'];
115
				$acl_entry['row'] = array();
116
				foreach ($networkacl as $acl)
117
					$acl_entry['row'][] = $acl;
118

    
119
				if (isset($id) && $a_acls[$id])
120
					$a_acls[$id] = $acl_entry;
121
				else
122
					$a_acls[] = $acl_entry;
123

    
124

    
125
				mark_subsystem_dirty("unbound");
126
				write_config();
127

    
128
				pfSenseHeader("/services_unbound_acls.php");
129
				exit;
130
			}
131

    
132
		}
133
	}
134
}
135

    
136
$closehead = false;
137
$pgtitle = "Services: DNS Resolver: Access Lists";
138
include("head.inc");
139

    
140
?>
141

    
142
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
143
<script type="text/javascript" src="/javascript/row_helper.js"></script>
144

    
145
<script type="text/javascript">
146
//<![CDATA[
147
	rowname[0] = "acl_network";
148
	rowtype[0] = "textbox,ipv4v6";
149
	rowsize[0] = "30";
150

    
151
	rowname[1] = "mask";
152
	rowtype[1] = "select,ipv4v6";
153
	rowsize[1] = "1";
154

    
155
	rowname[2] = "description";
156
	rowtype[2] = "textbox";
157
	rowsize[2] = "40";
158
//]]>
159
</script>
160
</head>
161

    
162
<body>
163

    
164
<?php include("fbegin.inc"); ?>
165
<form action="services_unbound_acls.php" method="post" name="iform" id="iform">
166
<?php
167
if (!$savemsg)
168
	$savemsg = "";
169

    
170
if ($input_errors)
171
	print_input_errors($input_errors);
172

    
173
if ($savemsg)
174
	print_info_box($savemsg);
175

    
176
if (is_subsystem_dirty("unbound"))
177
		print_info_box_np(gettext("The settings for the DNS Resolver have changed. You must apply the configuration to take affect."));
178
?>
179
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="services unbound acls">
180
	<tbody>
181
		<tr>
182
			<td class="tabnavtbl">
183
				<?php
184
					$tab_array = array();
185
					$tab_array[] = array(gettext("General Settings"), false, "/services_unbound.php");
186
					$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
187
					$tab_array[] = array(gettext("Access Lists"), true, "/services_unbound_acls.php");
188
					display_top_tabs($tab_array, true);
189
				?>
190
			</td>
191
		</tr>
192
		<tr>
193
			<td id="mainarea">
194
				<div class="tabcont">
195
					<?php if($act=="new" || $act=="edit"): ?>
196
						<input name="aclid" type="hidden" value="<?=$id;?>" />
197
						<input name="act" type="hidden" value="<?=$act;?>" />
198

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

    
289
							</td>
290
						</tr>
291

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

    
313
				<?php else: ?>
314

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

    
389
<?php include("fend.inc"); ?>
390
</body>
391
</html>
(171-171/256)