Project

General

Profile

Download (16.7 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 = array("lan" => "lan", "wan" => "wan");
147
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) 
148
			$iflist['opt' . $i] = "opt{$i}";
149

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

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

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

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

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

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

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

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

    
193
        asort($tmp);
194
        return $tmp;
195
    }
196
}
197

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

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

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

    
234
	unset($input_errors);
235
	$pconfig = $_POST;
236

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

    
288
include("head.inc");
289

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

    
320
<script type="text/javascript">
321
	function checkall() {
322
        var el = document.getElementById('iform');
323
        for (var i = 0; i < el.elements.length; i++) {
324
          el.elements[i].checked = true;
325
        }
326
   	}
327
   	function checknone() {
328
        var el = document.getElementById('iform');
329
        for (var i = 0; i < el.elements.length; i++) {
330
          el.elements[i].checked = false;
331
        }
332
   	}
333
</script>
334
<form action="system_groupmanager.php" method="post" name="iform" id="iform">
335
          <table width="100%" border="0" cellpadding="6" cellspacing="0">
336
            <tr> 
337
              <td width="22%" valign="top" class="vncellreq">Group name</td>
338
              <td width="78%" class="vtable"> 
339
              <?php 
340
              	$inuse = false;
341
              	foreach($config['system']['user'] as $su) {
342
					if($su['groupname'] == $pconfig['name']) 
343
						$inuse = true;
344
				}
345
              ?>
346
              <?php if($inuse == false): ?>
347
                <input name="groupname" type="text" class="formfld" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
348
              <?php else: ?>
349
              	<?php echo $pconfig['name']; ?>
350
              	<input name="groupname" type="hidden" class="formfld" id="groupname" value="<?=htmlspecialchars($pconfig['name']);?>"> 
351
              <?php endif; ?>
352
                </td>
353
            </tr>
354
            <tr> 
355
              <td width="22%" valign="top" class="vncell">Description</td>
356
              <td width="78%" class="vtable"> 
357
                <input name="description" type="text" class="formfld" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
358
                <br>
359
                Group description, for your own information only</td>
360
            </tr>
361
            <tr>
362
			  	<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>
363
			  	<span class="vexpl"><span class="red"><strong>&nbsp;Note: </strong></span>Pages 
364
          marked with an * are strongly recommended for every group.</span>
365
			  	</td>
366
				</tr>
367
				<tr><td colspan="4">
368
		           <input type="button" name="types[]" value="Check All" onClick="checkall(); return false;"> 
369
        		   <input type="button" name="types[]" value="Check None" onClick="checknone(); return false;">
370
				</td></tr>
371
            <tr>
372
              <td colspan="2">
373
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
374
              <tr>
375
                <td class="listhdrr">&nbsp;</td>
376
                <td class="listhdrr">Page Description</td>
377
                <td class="listhdr">Filename</td>
378
              </tr>
379
              <?php 
380
              foreach ($pages as $fname => $title) {
381
              	$identifier = str_replace('.php','XXXUMXXX',$fname);
382
				$identifier = str_replace('.','XXXDOTXXX',$identifier);
383
              	?>
384
              	<tr><td class="listlr">
385
              	<input class="check" name="<?=$identifier?>" type="checkbox" id="<?=$identifier?>" value="yes" <?php if (in_array($fname,$pconfig['pages'])) echo "checked"; ?>></td>
386
              	<td class="listr"><?=$title?></td>
387
              	<td class="listr"><?=$fname?></td>
388
              	</tr>
389
              	<?
390
              } ?>
391
              </table>
392
              </td>
393
            </tr>
394
            <tr> 
395
              <td width="22%" valign="top">&nbsp;</td>
396
              <td width="78%"> 
397
                <input name="save" type="submit" class="formbtn" value="Save"> 
398
		        <?php if (isset($id) && $a_group[$id]): ?>
399
		        <input name="id" type="hidden" value="<?=$id;?>">
400
		        <?php endif; ?>                
401
              </td>
402
            </tr>
403
          </table>
404
 </form>
405
<?php
406
} else {
407
?>
408
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
409
    <tr>
410
       <td width="35%" class="listhdrr">Group name</td>
411
       <td width="20%" class="listhdrr">Description</td>
412
       <td width="20%" class="listhdrr">Pages Accessible</td>                  
413
       <td width="10%" class="list"></td>
414
	</tr>
415
	<?php $i = 0; foreach($a_group as $group): ?>
416
		<tr>
417
                  <td class="listlr">
418
                    <?=htmlspecialchars($group['name']); ?>&nbsp;
419
                  </td>
420
                  <td class="listr">
421
                    <?=htmlspecialchars($group['description']);?>&nbsp;
422
                  </td>
423
                  <td class="listbg">
424
					<font color="white">
425
                    <?=count($group['pages']);?>&nbsp;
426
                  </td>
427
                  <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>
428
                     &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>
429
		</tr>
430
	<?php $i++; endforeach; ?>
431
	    <tr> 
432
			<td class="list" colspan="3"></td>
433
			<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>
434
		</tr>
435
		<tr>
436
			<td colspan="3">
437
		      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.
438
			</td>
439
		</tr>
440
 </table>
441
<?php } ?>
442
     
443
  </td>
444
  </tr>
445
  </table>
446
  
447
  
448
<?php include("fend.inc"); ?>
(153-153/189)