Project

General

Profile

Download (16.3 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'] = "Hidden: Exec";
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";
83
        $tmp['index.php'] = "*After Login/Dashboard";
84
        $tmp['system_usermanager.php'] = "*User Password change portal";
85
        $tmp['diag_logs_settings.php'] = "Diagnostics: Logs: Settings";
86
        $tmp['diag_logs_vpn.php'] = "Diagnostics: Logs: PPTP VPN";
87
        $tmp['diag_logs_filter.php'] = "Diagnostics: Logs: Firewall";
88
        $tmp['diag_logs_portal.php'] = "Diagnostics: Logs: Captive Portal";
89
        $tmp['diag_logs_dhcp.php'] = "Diagnostics: Logs: DHCP";
90
        $tmp['diag_logs.php'] = "Diagnostics: Logs: System";
91
        
92
        unset($tmp['system_groupmanager_edit.php']);
93
        unset($tmp['firewall_rules_schedule_logic.php']);
94
        unset($tmp['status_rrd_graph_img.php']);
95
        unset($tmp['diag_new_states.php']);
96
        unset($tmp['system_usermanager_edit.php']);
97
        
98
        $tmp['pkg.php'] = "{$g['prouct_name']} package manager";
99
        $tmp['pkg_edit.php'] = "{$g['product_name']} package manager edit";
100
        $tmp['wizard.php'] = "{$g['product_name']} wizard subsystem";
101
        $tmp['graphs.php'] = "Graphing subsystem";
102
        $tmp['headjs.php'] = "*Required for javascript";
103

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

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

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

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

    
157
		$entryname = "firewall_rules_edit.php?if=pptp";
158
        $tmp[$entryname] = "Firewall: Rules: Edit: PPTP";
159

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

    
163
		// User manager
164
		$entryname = "system_usermanager.php";
165
		$tmp[$entryname] = "System: Change Password";
166

    
167
		// User manager
168
		$entryname = "system_usermanager";
169
		$tmp[$entryname] = "System: User Manager";
170

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

    
185
		$entryname = "firewall_nat_edit.php?if=pppoe";
186
        $tmp[$entryname] = "Firewall: NAT: Port Forward: Edit: PPPoE";
187

    
188
        asort($tmp);
189
        return $tmp;
190
    }
191
}
192

    
193
// Get a list of all admin pages & Descriptions
194
$pages = getAdminPageList();
195

    
196
if (!is_array($config['system']['group'])) {
197
	$config['system']['group'] = array();
198
}
199
admin_groups_sort();
200
$a_group = &$config['system']['group'];
201

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

    
229
	unset($input_errors);
230
	$pconfig = $_POST;
231

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

    
276
include("head.inc");
277

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

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