Projet

Général

Profil

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

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

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
	mark_subsystem_dirty('unbound');
57
}
58

    
59
if ($act == "new") {
60
	$id = unbound_get_next_id();
61
}
62

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

    
70
if ($_POST) {
71
	unset($input_errors);
72
	$pconfig = $_POST;
73

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

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

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

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

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

    
122

    
123
				mark_subsystem_dirty("unbound");
124
				write_config();
125

    
126
				pfSenseHeader("/services_unbound_acls.php");
127
				exit;
128
			}
129

    
130
		}
131
	}
132
}
133

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

    
138
?>
139

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

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

    
149
	rowname[1] = "mask";
150
	rowtype[1] = "select,ipv4v6";
151
	rowsize[1] = "1";
152

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

    
160
<body>
161

    
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
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="services unbound acls">
178
	<tbody>
179
		<tr>
180
			<td class="tabnavtbl">
181
				<?php
182
					$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
				?>
188
			</td>
189
		</tr>
190
		<tr>
191
			<td id="mainarea">
192
				<div class="tabcont">
193
					<?php if($act=="new" || $act=="edit"): ?>
194
						<input name="aclid" type="hidden" value="<?=$id;?>" />
195
						<input name="act" type="hidden" value="<?=$act;?>" />
196

    
197
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
198
						<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
								<input name="aclname" type="text" class="formfld" id="aclname" size="30" maxlength="30" value="<?=htmlspecialchars($pconfig['aclname']);?>" />
205
								<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
									<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['aclaction'])) echo "selected=\"selected\""; ?>>
215
									<?=htmlspecialchars($type);?>
216
									</option>
217
									<?php endforeach; ?>
218
								</select>
219
								<br />
220
								<span class="vexpl">
221
									<?=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
								</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
							<table id="maintable" summary="networks">
233
								<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
											<input name="acl_network<?=$counter;?>" type="text" class="formfld unknown ipv4v6" id="acl_network<?=$counter;?>" size="30" value="<?=htmlspecialchars($network);?>" />
252
										</td>
253
										<td>
254
											<select name="mask<?=$counter;?>" class="formselect ipv4v6" id="mask<?=$counter;?>">
255
											<?php
256
												for ($i = 128; $i > 0; $i--) {
257
													echo "<option value=\"$i\" ";
258
													if ($i == $cidr) echo "selected=\"selected\"";
259
													echo ">" . $i . "</option>";
260
												}
261
											?>
262
											</select>
263
										</td>
264
										<td>
265
											<input name="description<?=$counter;?>" type="text" class="formfld unknown" id="description<?=$counter;?>" size="40" value="<?=htmlspecialchars($description);?>" />
266
										</td>
267
										<td>
268
											<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" alt="delete" /></a>
269
										</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
							//<![CDATA[
280
								field_counter_js = 3;
281
								rows = 1;
282
								totalrows = <?php echo $counter; ?>;
283
								loaded = <?php echo $counter; ?>;
284
							//]]>
285
							</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
								<input name="description" type="text" class="formfld unknown" id="description" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['description']);?>" />
294
								<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
								&nbsp;<br />&nbsp;
305
								<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
306
							</td>
307
						</tr>
308
					</table>
309

    
310
				<?php else: ?>
311

    
312
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="results">
313
					<thead>
314
						<tr>
315
							<td width="25%" class="listhdrr"><?=gettext("Access List Name"); ?></td>
316
							<td width="25%" class="listhdrr"><?=gettext("Action"); ?></td>
317
							<td width="45%" class="listhdr"><?=gettext("Description"); ?></td>
318
							<td width="5%" class="list">&nbsp;</td>
319
						</tr>
320
					</thead>
321
					<tfoot>
322
						<tr>
323
							<td class="list" colspan="3">&nbsp;</td>
324
							<td class="list">
325
								<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
							</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
					<tbody>
344
					<?php
345
						$i = 0;
346
						foreach($a_acls as $acl):
347
					?>
348
						<tr ondblclick="document.location='services_unbound_acls.php?act=edit&amp;id=<?=$i;?>'">
349
							<td class="listlr">
350
								<?=htmlspecialchars($acl['aclname']);?>
351
							</td>
352
							<td class="listr">
353
								<?=htmlspecialchars($acl['aclaction']);?>
354
							</td>
355
							<td class="listbg">
356
								<?=htmlspecialchars($acl['description']);?>
357
							</td>
358
							<td valign="middle" class="list nowrap">
359
								<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
							</td>
370
						</tr>
371
					<?php
372
						$i++;
373
						endforeach;
374
					?>
375
					<tr style="display:none"><td></td></tr>
376
					</tbody>
377
				</table>
378
			<?php endif; ?>
379
			</div>
380
			</td>
381
		</tr>
382
	</tbody>
383
</table>
384
</form>
385

    
386
<?php include("fend.inc"); ?>
387
</body>
388
</html>
(170-170/255)