Project

General

Profile

Download (10.4 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

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

    
50
if (!empty($id) && !is_numeric($id)) {
51
	pfSenseHeader("services_unbound_acls.php");
52
	exit;
53
}
54

    
55
$act = $_GET['act'];
56

    
57
if (isset($_POST['act'])) {
58
	$act = $_POST['act'];
59
}
60

    
61
if ($act == "del") {
62
	if (!$a_acls[$id]) {
63
		pfSenseHeader("services_unbound_acls.php");
64
		exit;
65
	}
66

    
67
	unset($a_acls[$id]);
68
	write_config();
69
	mark_subsystem_dirty('unbound');
70
}
71

    
72
if ($act == "new") {
73
	$id = unbound_get_next_id();
74
}
75

    
76
if ($act == "edit") {
77
	if (isset($id) && $a_acls[$id]) {
78
		$pconfig = $a_acls[$id];
79
		$networkacl = $a_acls[$id]['row'];
80
	}
81
}
82

    
83
// Add a row to the networks table
84
if($_GET && $_GET['addrow'])
85
    array_push($networkacl, array('acl_network' => '', 'mask' => '32', 'description' => ''));
86
             
87
if ($_POST) {
88
	unset($input_errors);
89
	$pconfig = $_POST;
90
    $deleting = false;
91
    
92
    // Delete a row from the networks table
93
    for($idx = 0; $idx<50; $idx++) {
94
        if($pconfig['dlt' . $idx] == 'Delete') {
95
            unset($networkacl[$idx]);
96
            $deleting = true;
97
            break;
98
        }
99
    }
100
  
101
	if ($_POST['apply']) {
102
		$retval = services_unbound_configure();
103
		$savemsg = get_std_save_message($retval);
104
		if ($retval == 0)
105
			clear_subsystem_dirty('unbound');
106
	} else if(!$deleting) {
107

    
108
		// input validation - only allow 50 entries in a single ACL
109
		for($x=0; $x<50; $x++) {
110
			if (isset($pconfig["acl_network{$x}"])) {
111
				$networkacl[$x] = array();
112
				$networkacl[$x]['acl_network'] = $pconfig["acl_network{$x}"];
113
				$networkacl[$x]['mask'] = $pconfig["mask{$x}"];
114
				$networkacl[$x]['description'] = $pconfig["description{$x}"];
115
				if (!is_ipaddr($networkacl[$x]['acl_network'])) {
116
					$input_errors[] = gettext("You must enter a valid IP address for each row under Networks.");
117
				}
118

    
119
				if (is_ipaddr($networkacl[$x]['acl_network'])) {
120
					if (!is_subnet($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask'])) {
121
						$input_errors[] = gettext("You must enter a valid IPv4 netmask for each IPv4 row under Networks.");
122
					}
123
				} else if (function_exists("is_ipaddrv6")) {
124
					if (!is_ipaddrv6($networkacl[$x]['acl_network'])) {
125
						$input_errors[] = gettext("You must enter a valid IPv6 address for {$networkacl[$x]['acl_network']}.");
126
					} else if (!is_subnetv6($networkacl[$x]['acl_network']."/".$networkacl[$x]['mask'])) {
127
						$input_errors[] = gettext("You must enter a valid IPv6 netmask for each IPv6 row under Networks.");
128
					}
129
				} else {
130
					$input_errors[] = gettext("You must enter a valid IP address for each row under Networks.");
131
				}
132
			} else if (isset($networkacl[$x])) {
133
				unset($networkacl[$x]);
134
			}
135
		}
136

    
137
		if (!$input_errors) {
138
			if ($pconfig['Submit'] == gettext("Save")) {
139
				$acl_entry = array();
140
				$acl_entry['aclid'] = $pconfig['aclid'];
141
				$acl_entry['aclname'] = $pconfig['aclname'];
142
				$acl_entry['aclaction'] = $pconfig['aclaction'];
143
				$acl_entry['description'] = $pconfig['description'];
144
				$acl_entry['aclid'] = $pconfig['aclid'];
145
				$acl_entry['row'] = array();
146
				foreach ($networkacl as $acl) {
147
					$acl_entry['row'][] = $acl;
148
				}
149

    
150
				if (isset($id) && $a_acls[$id]) {
151
					$a_acls[$id] = $acl_entry;
152
				} else {
153
					$a_acls[] = $acl_entry;
154
				}
155

    
156
				mark_subsystem_dirty("unbound");
157
				write_config();
158

    
159
				pfSenseHeader("/services_unbound_acls.php");
160
				exit;
161
			}
162

    
163
		}
164
	}
165
}
166

    
167
//DEBUG
168

    
169
$closehead = false;
170
$pgtitle = "Services: DNS Resolver: Access Lists";
171
$shortcut_section = "resolver";
172
include("head.inc");
173

    
174
if ($input_errors)
175
    print_input_errors($input_errors);
176
    
177
if ($savemsg)
178
    print_info_box($savemsg, 'success');
179
    
180
if (is_subsystem_dirty('unbound'))
181
    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."));
182

    
183
$tab_array = array();
184
$tab_array[] = array(gettext("General Settings"), false, "/services_unbound.php");
185
$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
186
$tab_array[] = array(gettext("Access Lists"), true, "/services_unbound_acls.php");
187
display_top_tabs($tab_array, true);
188

    
189
require('classes/Form.class.php');
190

    
191
if($act=="new" || $act=="edit") {
192
	
193
    $form = new Form();
194
    
195
    $section = new Form_Section('New Access List');
196
						
197
    $section->addInput(new Form_Input(
198
    	'aclid',
199
    	null,
200
    	'hidden',
201
    	$id
202
    ));
203
    
204
    $section->addInput(new Form_Input(
205
    	'act',
206
    	null,
207
    	'hidden',
208
    	$act
209
    ));
210
        						
211
    $section->addInput(new Form_Input(
212
    	'aclname',
213
    	'Access LIst name',
214
    	'text',
215
    	$pconfig['aclname']
216
    ))->setHelp('Provide an Access List name.');
217
    
218
    $section->addInput(new Form_Select(
219
	'action',
220
	'Action',
221
	strtolower($pconfig['aclaction']),
222
	array('allow' => 'Allow','deny' => 'Deny','refuse' => 'Refuse','allow snoop' => 'Allow Snoop')
223
    ))->setHelp('Choose what to do with DNS requests that match the criteria specified below.' . '<br />' .
224
                'Deny: Stops queries from hosts within the netblock defined below.' . '<br />' . 
225
                'Refuse: Stops queries from hosts within the netblock defined below, but sends a DNS rcode REFUSED error message back to the client.' . '<br />' .
226
                'Allow: Allow queries from hosts within the netblock defined below.' . '<br />' .
227
                'Allow Snoop: Allow 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.');
228

    
229
    $counter = 0;
230
    $numrows = count($networkacl) - 1;
231
    
232
    foreach($networkacl as $item) {
233
    	$network = $item['acl_network'];
234
    	$cidr = $item['mask'];
235
    	$description = $item['description'];
236
    	
237
    	$group = new Form_Group($counter == 0 ? 'Networks':null);
238
    	
239
    	$group->add(new Form_IpAddress(
240
    	    'acl_network' . $counter,
241
    	    null,
242
    	    $network
243
    	))->setHelp(($counter == $numrows) ? 'Network':null);
244
    	
245
    	$group->add(new Form_Select(
246
	        'mask' . $counter,
247
	        null,
248
	        $cidr,
249
	        array_combine(range(32, 1, -1), range(32, 1, -1))
250
        ))->setWidth(2)->setHelp(($counter == $numrows) ? 'Mask':null);
251
        
252
        $group->add(new Form_Input(
253
    	    'description' . $counter,
254
    	    null,
255
    	    'text',
256
    	    $description
257
    	))->setWidth(3)->setHelp(($counter == $numrows) ? 'Description':null);
258
    	
259
    	$btndlt = new Form_Button(
260
    	    'dlt' . $counter,
261
    	    'Delete'
262
	    );
263
	   
264
	    $btndlt->removeClass('btn-primary')->addClass('btn-sm btn-danger');
265
	   
266
    	$group->add($btndlt);
267

    
268
    	$section->add($group);
269
    	
270
    	$counter++;
271
    }
272

    
273
	$btnadd = new Form_Button(
274
	    'btnadd',
275
	    'Add row',
276
	    'services_unbound_acls.php?act=' . $act . '&addrow=yes'
277
	);
278
	
279
	$btnadd->removeClass(btn-primary)->addClass('btn-sm btn-success');
280
	
281
	$section->addInput(new Form_StaticText(
282
	    'Add row',
283
	    $btnadd
284
	))->setHelp('Remember to save after each Add or Delete');
285
	
286
    $section->addInput(new Form_Input(
287
    	'descr',
288
    	'Description',
289
    	'text',
290
    	$pconfig['descr']
291
    ))->setHelp('You may enter a description here for your reference.');
292
    
293
    $form->addGlobal(new Form_Button(
294
		'cancel',
295
		'Cancel',
296
		$referer
297
	));
298
	
299
    $form->add($section);
300
    print($form);
301
}
302
else // NOT 'edit' or 'add'
303
{
304
?>
305
<div class="panel panel-default">
306
    <div class="panel-heading"><?=gettext('Access Lists to control access to the DNS Resolver')?></div>
307
    <div class="panel-body">
308
        <div class="table-responsive">
309
            <table class="table table-striped table-hover table-condensed">
310
                <thead>
311
                    <tr>
312
        				<th><?=gettext("Access List Name"); ?></th>
313
        				<th><?=gettext("Action"); ?></th>
314
        				<th><?=gettext("Description"); ?></th>
315
        				<th>&nbsp;</th>
316
                    </tr>                
317
                </thead>
318
                <tbody>
319
<?php                
320
    $i = 0;
321
    foreach($a_acls as $acl):
322
?>
323
				    <tr ondblclick="document.location='services_unbound_acls.php?act=edit&amp;id=<?=$i?>'">
324
						<td>
325
						    <?=htmlspecialchars($acl['aclname'])?>
326
						</td>
327
						<td>
328
							<?=htmlspecialchars($acl['aclaction'])?>
329
						</td>
330
						<td>
331
							<?=htmlspecialchars($acl['description'])?>
332
						</td>
333
						<td>
334
							<a href="services_unbound_acls.php?act=edit&amp;id=<?=$i?>" class="btn btn-xs btn-info" >Edit</a>
335
							<a href="services_unbound_acls.php?act=del&amp;id=<?=$i?>" class="btn btn-xs btn-danger">Delete</a>
336
						</td>
337
					</tr>
338
<?php
339
        $i++;
340
	endforeach;
341
?>						                
342
                </tbody>
343
            </table>
344
        </div>
345
        <nav class="action-buttons">
346
            <a href="services_unbound_acls.php?act=new" class="btn btn-sm btn-success">Add</a>
347
        </nav>        
348
    </div>									
349
</div>
350
<?php	
351
}
352

    
353
include("foot.inc");
(157-157/241)