Projet

Général

Profil

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

univnautes / usr / local / www / services_unbound_acls.php @ c1229525

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
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
	services_unbound_configure();
57
	$savemsg = gettext("Access List successfully deleted")."<br />";
58
}
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
	// input validation - only allow 50 entries in a single ACL
77
	for($x=0; $x<50; $x++) {
78
		if (isset($pconfig["acl_network{$x}"])) {
79
			$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
		}
97
	}
98
	
99
	if (!$input_errors) {
100
		if ($pconfig['Submit'] == gettext("Save")) {
101
			$acl_entry = array();
102
			$acl_entry['aclid'] = $pconfig['aclid'];
103
			$acl_entry['aclname'] = $pconfig['aclname'];
104
			$acl_entry['aclaction'] = $pconfig['aclaction'];
105
			$acl_entry['description'] = $pconfig['description'];
106
			$acl_entry['aclid'] = $pconfig['aclid'];
107
			$acl_entry['row'] = array();
108
			foreach ($networkacl as $acl)
109
				$acl_entry['row'][] = $acl;
110

    
111
			if (isset($id) && $a_acls[$id])
112
				$a_acls[$id] = $acl_entry;
113
			else
114
				$a_acls[] = $acl_entry;
115

    
116

    
117
			mark_subsystem_dirty("unbound");
118
			write_config();
119

    
120
			pfSenseHeader("/services_unbound_acls.php");
121
			exit;
122
		}
123

    
124
		if ($pconfig['apply']) {
125
			clear_subsystem_dirty("unbound");
126
			$retval = 0;
127
			$retval = services_unbound_configure();
128
			$savemsg = get_std_save_message($retval);
129
		}
130
	}
131
}
132

    
133
$closehead = false;
134
$pgtitle = "Services: DNS Resolver: Access Lists";
135
include("head.inc");
136

    
137
?>
138

    
139
<script type="text/javascript" src="/javascript/row_helper.js">
140
</script>
141

    
142
<script type="text/javascript">
143
//<![CDATA[
144
	function mask_field(fieldname, fieldsize, n) {
145
		return '<select name="' + fieldname + n + '" class="formselect" id="' + fieldname + n + '"><?php
146
			for ($i = 128; $i >= 0; $i--) {
147
					echo "<option value=\"$i\">$i<\/option>";
148
			}
149
		?><\/select>';
150
	}
151

    
152
	rowtype[0] = "textbox";
153
	rowname[0] = "acl_network";
154
	rowsize[0] = "30";
155
	rowname[1] = "mask";
156
	rowtype[1] = mask_field;
157
	rowtype[2] = "textbox";
158
	rowname[2] = "description";
159
	rowsize[2] = "40";
160
//]]>
161
</script>
162
</head>
163

    
164
<body>
165

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

    
172
if ($input_errors)
173
	print_input_errors($input_errors);
174

    
175
if ($savemsg)
176
	print_info_box($savemsg);
177

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

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

    
291
							</td>
292
						</tr>
293

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

    
314
				<?php else: ?>
315

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

    
382
<?php include("fend.inc"); ?>
383
</body>
384
</html>
(169-169/254)