Project

General

Profile

Download (16.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/*
3
	$Id: system_groupmanager.php 
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>.
7
	All rights reserved. 
8

    
9
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11
	
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14
	
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17
	
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21
	
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
require("guiconfig.inc");
35

    
36
$pgtitle = array("System", "Group manager");
37

    
38
// Returns an array of pages with their descriptions
39
function getAdminPageList() {
40
	global $g;
41
	global $config;
42
	
43
    $tmp = Array();
44

    
45
    if ($dir = opendir($g['www_path'])) {
46
		while($file = readdir($dir)) {
47
	    	// Make sure the file exists
48
	    	if($file != "." && $file != ".." && $file[0] != '.') {
49
	    		// Is this a .php file?
50
	    		if (fnmatch('*.php',$file)) {
51
	    			// Read the description out of the file
52
		    		$contents = file_get_contents($file);
53
		    		// Looking for a line like:
54
		    		// $pgtitle = array("System", "Group manager");
55
		    		$offset = strpos($contents,'$pgtitle');
56
		    		$titlepos = strpos($contents,'(',$offset);
57
		    		$titleendpos = strpos($contents,')',$titlepos);
58
		    		if (($offset > 0) && ($titlepos > 0) && ($titleendpos > 0)) {
59
		    			// Title found, extract it
60
		    			$title = str_replace(',',': ',str_replace(array('"'),'',substr($contents,++$titlepos,($titleendpos - $titlepos))));
61
		    			$tmp[$file] = trim($title);
62
		    		}
63
		    		else {
64
		    			$tmp[$file] = '';
65
		    		}
66
	    		
67
	    		}
68
	        }
69
		}
70

    
71
        closedir($dir);
72
        
73
        // Sets Interfaces:Optional page that didn't read in properly with the above method,
74
        // and pages that don't have descriptions.
75
        $tmp['interfaces_opt.php'] = "Interfaces: Optional";
76
        $tmp['graph.php'] = "Diagnostics: Interface Traffic";
77
        $tmp['graph_cpu.php'] = "Diagnostics: CPU Utilization";
78
        $tmp['exec.php'] = "Command";
79
        $tmp['exec_raw.php'] = "Hidden: Exec Raw";
80
        $tmp['status.php'] = "Hidden: Detailed Status";
81
        $tmp['uploadconfig.php'] = "Hidden: Upload Configuration";
82
        $tmp['index.php'] = "*After Login/Dashboard";
83
        $tmp['system_usermanager.php'] = "*User Password change portal";
84
        $tmp['diag_logs_settings.php'] = "Diagnostics: Logs: Settings";
85
        $tmp['diag_logs_vpn.php'] = "Diagnostics: Logs: PPTP VPN";
86
        $tmp['diag_logs_filter.php'] = "Diagnostics: Logs: Firewall";
87
        $tmp['diag_logs_portal.php'] = "Diagnostics: Logs: Captive Portal";
88
        $tmp['diag_logs_dhcp.php'] = "Diagnostics: Logs: DHCP";
89
        $tmp['diag_logs.php'] = "Diagnostics: Logs: System";
90

    
91
		$tmp['cg2.php'] = "CoreGUI GUI Manager";
92
        
93
        unset($tmp['system_groupmanager_edit.php']);
94
        unset($tmp['firewall_rules_schedule_logic.php']);
95
        unset($tmp['status_rrd_graph_img.php']);
96
        unset($tmp['diag_new_states.php']);
97
        unset($tmp['system_usermanager_edit.php']);
98
        
99
        $tmp['pkg.php'] = "{$g['product_name']} Package manager";
100
        $tmp['pkg_edit.php'] = "{$g['product_name']} Package manager edit";
101
        $tmp['wizard.php'] = "{$g['product_name']} wizard subsystem";
102
        $tmp['graphs.php'] = "Graphing subsystem";
103
        $tmp['headjs.php'] = "*Required for javascript";
104

    
105
		$tmp['ifstats.php'] = ("*Hidden: XMLRPC Interface Stats");
106
		$tmp['license.php'] = ("*System: License");
107
		$tmp['progress.php'] = ("*Hidden: No longer included");
108
		$tmp['diag_logs_filter_dynamic.php'] = ("*Hidden: No longer included"); 
109
		$tmp['preload.php'] = ("*Hidden: XMLRPC Preloader");
110
		$tmp['xmlrpc.php'] = ("*Hidden: XMLRPC Library");        
111
		
112
		$tmp['functions.inc.php'] = ("Hidden: Ajax Helper 1");
113
		$tmp['javascript.inc.php'] = ("Hidden: Ajax Helper 2 ");
114
		$tmp['sajax.class.php'] = ("Hidden: Ajax Helper 3");
115

    
116
		/* custom pkg.php items */
117
		$tmp['pkg.php?xml=openvpn.xml'] = ("VPN: OpenVPN");
118
		$tmp['pkg_edit.php?xml=carp_settings.xml&id=0'] = ("Services: CARP Settings: Edit");
119
		$tmp['pkg_edit.php?xml=olsrd.xml&id=0'] = ("Services: OLSR");
120
		$tmp['pkg_edit.php?xml=openntpd.xml&id=0'] = ("Services: NTP Server");
121
		
122
		$tmp['system_usermanager_settings_test.php'] = ("System: User Manager: Settings: Test LDAP");
123
		
124
		/*  unset older openvpn scripts, we have a custom version
125
		 *  included in CoreGUI */
126
	 	unset($tmp['vpn_openvpn.php']);
127
		unset($tmp['vpn_openvpn_crl.php']);
128
		unset($tmp['vpn_openvpn_ccd.php']);
129
		unset($tmp['vpn_openvpn_srv.php']);
130
		unset($tmp['vpn_openvpn_cli.php']);
131
		unset($tmp['vpn_openvpn_ccd_edit.php']);
132
		unset($tmp['phpconfig.php']);
133
		unset($tmp['system_usermanager_settings_ldapacpicker.php']);
134
		
135
        unset($tmp['progress.php']);
136
        unset($tmp['stats.php']);
137
        unset($tmp['phpinfo.php']);
138
        unset($tmp['preload.php']);
139
        
140
        // Add appropriate descriptions for extensions, if they exist
141
        if(file_exists("extensions.inc")){
142
	   	   include("extensions.inc");
143
		}
144
		
145
		/* firewall rule view and edit entries for lan, wan, optX */
146
		$iflist = get_configured_interface_list(false, true);
147

    
148
		// Firewall Rules
149
		foreach ($iflist as $ifent => $ifname) {
150
			$entryname = "firewall_rules.php?if={$ifname}";
151
	        $tmp[$entryname] = ("Firewall: Rules: " . strtoupper($ifname));
152
			$entryname = "firewall_rules_edit.php?if={$ifname}";
153
	        $tmp[$entryname] = ("Firewall: Rules: Edit: " . strtoupper($ifname));
154
		}
155

    
156
		/* additional firewal rules tab entries */
157
		$entryname = "firewall_rules_edit.php?if=enc0";
158
        $tmp[$entryname] = "Firewall: Rules: Edit: IPsec";
159

    
160
		$entryname = "firewall_rules_edit.php?if=pptp";
161
        $tmp[$entryname] = "Firewall: Rules: Edit: PPTP";
162

    
163
		$entryname = "firewall_rules_edit.php?if=pppoe";
164
        $tmp[$entryname] = "Firewall: Rules: Edit: PPPoE";
165

    
166
		// User manager
167
		$entryname = "system_usermanager.php";
168
		$tmp[$entryname] = "System: Change Password";
169

    
170
		// User manager
171
		$entryname = "system_usermanager";
172
		$tmp[$entryname] = "System: User Manager";
173

    
174
		// NAT Items
175
		foreach ($iflist as $ifent => $ifname) {
176
			$entryname = "firewall_nat.php?if={$ifname}";
177
	        $tmp[$entryname] = ("Firewall: NAT: Port Forward " . strtoupper($ifname));
178
			$entryname = "firewall_nat_edit.php?if={$ifname}";
179
	        $tmp[$entryname] = ("Firewall: NAT: Port Forward: Edit: " . strtoupper($ifname));
180
		}
181
		/* additional nat tab entries */
182
		$entryname = "firewall_nat_edit.php?if=enc0";
183
        $tmp[$entryname] = "Firewall: NAT: Port Forward: Edit: IPsec";
184
        
185
		$entryname = "firewall_nat_edit.php?if=pptp";
186
        $tmp[$entryname] = "Firewall: NAT: Port Forward: Edit: PPTP";
187

    
188
		$entryname = "firewall_nat_edit.php?if=pppoe";
189
        $tmp[$entryname] = "Firewall: NAT: Port Forward: Edit: PPPoE";
190

    
191
        asort($tmp);
192
        return $tmp;
193
    }
194
}
195

    
196
// Get a list of all admin pages & Descriptions
197
$pages = getAdminPageList();
198

    
199
if (!is_array($config['system']['group'])) {
200
	$config['system']['group'] = array();
201
}
202
admin_groups_sort();
203
$a_group = &$config['system']['group'];
204

    
205
$id = $_GET['id'];
206
if (isset($_POST['id']))
207
	$id = $_POST['id'];
208
	
209
if ($_GET['act'] == "del") {
210
	if ($a_group[$_GET['id']]) {
211
	    $ok_to_delete = true;
212
	    if (isset($config['system']['user'])) {
213
    	    foreach ($config['system']['user'] as $userent) {
214
    	    	if ($userent['groupname'] == $a_group[$_GET['id']]['name']) {
215
    				$ok_to_delete = false;
216
    				$input_errors[] = "users still exist who are members of this group!";
217
    				break;	    
218
    	    	}
219
    	    }
220
	    }
221
        if ($ok_to_delete) {
222
    		unset($a_group[$_GET['id']]);
223
	       	write_config();
224
		    header("Location: system_groupmanager.php");
225
		    exit;
226
	    }
227
	}
228
}	
229
	
230
if ($_POST) {
231

    
232
	unset($input_errors);
233
	$pconfig = $_POST;
234

    
235
	/* input validation */
236
	$reqdfields = explode(" ", "groupname");
237
	$reqdfieldsn = explode(",", "Group Name");
238
	
239
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
240
	
241
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
242
		$input_errors[] = "The group name contains invalid characters.";
243
		
244
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
245
		/* make sure there are no dupes */
246
		foreach ($a_group as $group) {
247
			if ($group['name'] == $_POST['groupname']) {
248
				$input_errors[] = "Another entry with the same group name already exists.";
249
				break;
250
			}
251
		}
252
	}
253
	
254
	if (!$input_errors) {
255
	
256
		if (isset($id) && $a_group[$id])
257
			$group = $a_group[$id];
258
		
259
		if($id)
260
			unset($a_group[$id]);
261
		
262
		$group['name'] = $_POST['groupname'];
263
		$group['description'] = $_POST['description'];
264
		unset($group['pages']);
265
		
266
		foreach ($pages as $fname => $title) {
267
			$identifier = str_replace('.php','XXXUMXXX',$fname);
268
			$identifier = str_replace('.','XXXDOTXXX',$identifier);
269
			if ($_POST[$identifier] == 'yes') {
270
				$group['pages'][] = $fname;
271
			}
272
		}		
273
		
274
		if (isset($id) && $a_group[$id])
275
			$a_group[$id] = $group;
276
		else
277
			$a_group[] = $group;
278
		
279
		write_config();
280
		
281
		header("Location: system_groupmanager.php");
282
		exit;
283
	}
284
}
285

    
286
include("head.inc");
287

    
288
?>
289
<?php include("fbegin.inc"); ?>
290
<?php if ($input_errors) print_input_errors($input_errors); ?>
291
<?php if ($savemsg) print_info_box($savemsg); ?>
292
<table width="100%" border="0" cellpadding="0" cellspacing="0">
293
  <tr><td class="tabnavtbl">
294
  <ul id="tabnav">
295
	<?php 
296
		$tab_array = array();
297
		$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
298
		$tab_array[] = array(gettext("Group"), true, "system_groupmanager.php");
299
		$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
300
		display_top_tabs($tab_array);
301
    ?>     
302
  </ul>
303
  </td></tr>    
304
<tr>
305
  <td class="tabcont">
306
<?php
307
if($_GET['act']=="new" || $_GET['act']=="edit"){
308
	if($_GET['act']=="edit"){
309
		if (isset($id) && $a_group[$id]) {
310
	       $pconfig['name'] = $a_group[$id]['name'];
311
	       $pconfig['description'] = $a_group[$id]['description'];
312
	       $pconfig['pages'] = $a_group[$id]['pages'];
313
        }
314
	}
315
?>
316
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
317

    
318
<script type="text/javascript">
319
	function checkall() {
320
        var el = document.getElementById('iform');
321
        for (var i = 0; i < el.elements.length; i++) {
322
          el.elements[i].checked = true;
323
        }
324
   	}
325
   	function checknone() {
326
        var el = document.getElementById('iform');
327
        for (var i = 0; i < el.elements.length; i++) {
328
          el.elements[i].checked = false;
329
        }
330
   	}
331
</script>
332
<form action="system_groupmanager.php" method="post" name="iform" id="iform">
333
          <table width="100%" border="0" cellpadding="6" cellspacing="0">
334
            <tr> 
335
              <td width="22%" valign="top" class="vncellreq">Group name</td>
336
              <td width="78%" class="vtable"> 
337
              <?php 
338
              	$inuse = false;
339
              	foreach($config['system']['user'] as $su) {
340
					if($su['groupname'] == $pconfig['name']) 
341
						$inuse = true;
342
				}
343
              ?>
344
              <?php if($inuse == false): ?>
345
                <input name="groupname" type="text" class="formfld" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
346
              <?php else: ?>
347
              	<?php echo $pconfig['name']; ?>
348
              	<input name="groupname" type="hidden" class="formfld" id="groupname" value="<?=htmlspecialchars($pconfig['name']);?>"> 
349
              <?php endif; ?>
350
                </td>
351
            </tr>
352
            <tr> 
353
              <td width="22%" valign="top" class="vncell">Description</td>
354
              <td width="78%" class="vtable"> 
355
                <input name="description" type="text" class="formfld" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
356
                <br>
357
                Group description, for your own information only</td>
358
            </tr>
359
            <tr>
360
			  	<td colspan="4"><br>&nbsp;Select that pages that this group may access.  Members of this group will be able to perform all actions that<br>&nbsp; are possible from each individual web page.  Ensure you set access levels appropriately.<br><br>
361
			  	<span class="vexpl"><span class="red"><strong>&nbsp;Note: </strong></span>Pages 
362
          marked with an * are strongly recommended for every group.</span>
363
			  	</td>
364
				</tr>
365
				<tr><td colspan="4">
366
		           <input type="button" name="types[]" value="Check All" onClick="checkall(); return false;"> 
367
        		   <input type="button" name="types[]" value="Check None" onClick="checknone(); return false;">
368
				</td></tr>
369
            <tr>
370
              <td colspan="2">
371
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
372
              <tr>
373
                <td class="listhdrr">&nbsp;</td>
374
                <td class="listhdrr">Page Description</td>
375
                <td class="listhdr">Filename</td>
376
              </tr>
377
              <?php 
378
              foreach ($pages as $fname => $title) {
379
              	$identifier = str_replace('.php','XXXUMXXX',$fname);
380
				$identifier = str_replace('.','XXXDOTXXX',$identifier);
381
              	?>
382
              	<tr><td class="listlr">
383
              	<input class="check" name="<?=$identifier?>" type="checkbox" id="<?=$identifier?>" value="yes" <?php if (in_array($fname,$pconfig['pages'])) echo "checked"; ?>></td>
384
              	<td class="listr"><?=$title?></td>
385
              	<td class="listr"><?=$fname?></td>
386
              	</tr>
387
              	<?
388
              } ?>
389
              </table>
390
              </td>
391
            </tr>
392
            <tr> 
393
              <td width="22%" valign="top">&nbsp;</td>
394
              <td width="78%"> 
395
                <input name="save" type="submit" class="formbtn" value="Save"> 
396
		        <?php if (isset($id) && $a_group[$id]): ?>
397
		        <input name="id" type="hidden" value="<?=$id;?>">
398
		        <?php endif; ?>                
399
              </td>
400
            </tr>
401
          </table>
402
 </form>
403
<?php
404
} else {
405
?>
406
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
407
    <tr>
408
       <td width="35%" class="listhdrr">Group name</td>
409
       <td width="20%" class="listhdrr">Description</td>
410
       <td width="20%" class="listhdrr">Pages Accessible</td>                  
411
       <td width="10%" class="list"></td>
412
	</tr>
413
	<?php $i = 0; foreach($a_group as $group): ?>
414
		<tr>
415
                  <td class="listlr">
416
                    <?=htmlspecialchars($group['name']); ?>&nbsp;
417
                  </td>
418
                  <td class="listr">
419
                    <?=htmlspecialchars($group['description']);?>&nbsp;
420
                  </td>
421
                  <td class="listbg">
422
					<font color="white">
423
                    <?=count($group['pages']);?>&nbsp;
424
                  </td>
425
                  <td valign="middle" nowrap class="list"> <a href="system_groupmanager.php?act=edit&id=<?=$i; ?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit group" width="17" height="17" border="0"></a>
426
                     &nbsp;<a href="system_groupmanager.php?act=del&id=<?=$i; ?>" onclick="return confirm('Do you really want to delete this group?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete group" width="17" height="17" border="0"></a></td>
427
		</tr>
428
	<?php $i++; endforeach; ?>
429
	    <tr> 
430
			<td class="list" colspan="3"></td>
431
			<td class="list"> <a href="system_groupmanager.php?act=new"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add group" width="17" height="17" border="0"></a></td>
432
		</tr>
433
		<tr>
434
			<td colspan="3">
435
		      Additional webGui admin groups can be added here.  Each group can be restricted to specific portions of the webGUI.  Individually select the desired web pages each group may access.  For example, a troubleshooting group could be created which has access only to selected Status and Diagnostics pages.
436
			</td>
437
		</tr>
438
 </table>
439
<?php } ?>
440
     
441
  </td>
442
  </tr>
443
  </table>
444
  
445
  
446
<?php include("fend.inc"); ?>
(162-162/200)