Project

General

Profile

Download (15.5 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
        unset($tmp['progress.php']);
116
        unset($tmp['stats.php']);
117
        unset($tmp['phpinfo.php']);
118
        unset($tmp['preload.php']);
119
        
120
        // Add appropriate descriptions for extensions, if they exist
121
        if(file_exists("extensions.inc")){
122
	   	   include("extensions.inc");
123
		}
124
		
125
		/* firewall rule view and edit entries for lan, wan, optX */
126
		$iflist = array("lan" => "lan", "wan" => "wan");
127
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) 
128
			$iflist['opt' . $i] = "opt{$i}";
129

    
130
		// Firewall Rules
131
		foreach ($iflist as $ifent => $ifname) {
132
			$entryname = "firewall_rules.php?if={$ifname}";
133
	        $tmp[$entryname] = ("Firewall: Rules: " . strtoupper($ifname));
134
			$entryname = "firewall_rules_edit.php?if={$ifname}";
135
	        $tmp[$entryname] = ("Firewall: Rules: Edit: " . strtoupper($ifname));
136
		}
137

    
138
		/* additional firewal rules tab entries */
139
		$entryname = "firewall_rules_edit.php?if=enc0";
140
        $tmp[$entryname] = "Firewall: Rules: Edit: IPsec";
141

    
142
		$entryname = "firewall_rules_edit.php?if=pptp";
143
        $tmp[$entryname] = "Firewall: Rules: Edit: PPTP";
144

    
145
		$entryname = "firewall_rules_edit.php?if=pppoe";
146
        $tmp[$entryname] = "Firewall: Rules: Edit: PPPoE";
147

    
148
		// NAT Items
149
		foreach ($iflist as $ifent => $ifname) {
150
			$entryname = "firewall_nat.php?if={$ifname}";
151
	        $tmp[$entryname] = ("Firewall: NAT: Port Forward " . strtoupper($ifname));
152
			$entryname = "firewall_nat_edit.php?if={$ifname}";
153
	        $tmp[$entryname] = ("Firewall: NAT: Port Forward: Edit: " . strtoupper($ifname));
154
		}
155
		/* additional nat tab entries */
156
		$entryname = "firewall_nat_edit.php?if=enc0";
157
        $tmp[$entryname] = "Firewall: NAT: Port Forward: Edit: IPsec";
158
        
159
		$entryname = "firewall_nat_edit.php?if=pptp";
160
        $tmp[$entryname] = "Firewall: NAT: Port Forward: Edit: PPTP";
161

    
162
		$entryname = "firewall_nat_edit.php?if=pppoe";
163
        $tmp[$entryname] = "Firewall: NAT: Port Forward: Edit: PPPoE";
164

    
165
        asort($tmp);
166
        return $tmp;
167
    }
168
}
169

    
170
// Get a list of all admin pages & Descriptions
171
$pages = getAdminPageList();
172

    
173
if (!is_array($config['system']['group'])) {
174
	$config['system']['group'] = array();
175
}
176
admin_groups_sort();
177
$a_group = &$config['system']['group'];
178

    
179
$id = $_GET['id'];
180
if (isset($_POST['id']))
181
	$id = $_POST['id'];
182
	
183
if ($_GET['act'] == "del") {
184
	if ($a_group[$_GET['id']]) {
185
	    $ok_to_delete = true;
186
	    if (isset($config['system']['user'])) {
187
    	    foreach ($config['system']['user'] as $userent) {
188
    	    	if ($userent['groupname'] == $a_group[$_GET['id']]['name']) {
189
    				$ok_to_delete = false;
190
    				$input_errors[] = "users still exist who are members of this group!";
191
    				break;	    
192
    	    	}
193
    	    }
194
	    }
195
        if ($ok_to_delete) {
196
    		unset($a_group[$_GET['id']]);
197
	       	write_config();
198
		    header("Location: system_groupmanager.php");
199
		    exit;
200
	    }
201
	}
202
}	
203
	
204
if ($_POST) {
205

    
206
	unset($input_errors);
207
	$pconfig = $_POST;
208

    
209
	/* input validation */
210
	$reqdfields = explode(" ", "groupname");
211
	$reqdfieldsn = explode(",", "Group Name");
212
	
213
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
214
	
215
	if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
216
		$input_errors[] = "The group name contains invalid characters.";
217
		
218
	if (!$input_errors && !(isset($id) && $a_group[$id])) {
219
		/* make sure there are no dupes */
220
		foreach ($a_group as $group) {
221
			if ($group['name'] == $_POST['groupname']) {
222
				$input_errors[] = "Another entry with the same group name already exists.";
223
				break;
224
			}
225
		}
226
	}
227
	
228
	if (!$input_errors) {
229
	
230
		if (isset($id) && $a_group[$id])
231
			$group = $a_group[$id];
232
		
233
		$group['name'] = $_POST['groupname'];
234
		$group['description'] = $_POST['description'];
235
		unset($group['pages']);
236
		foreach ($pages as $fname => $title) {
237
			$identifier = str_replace('.php','',$fname);
238
			if ($_POST[$identifier] == 'yes') {
239
				$group['pages'][] = $fname;
240
			}			
241
		}		
242
		
243
		if (isset($id) && $a_group[$id])
244
			$a_group[$id] = $group;
245
		else
246
			$a_group[] = $group;
247
		
248
		write_config();
249
		
250
		header("Location: system_groupmanager.php");
251
		exit;
252
	}
253
}
254

    
255
include("head.inc");
256

    
257
?>
258
<?php include("fbegin.inc"); ?>
259
<?php if ($input_errors) print_input_errors($input_errors); ?>
260
<?php if ($savemsg) print_info_box($savemsg); ?>
261
<table width="100%" border="0" cellpadding="0" cellspacing="0">
262
  <tr><td class="tabnavtbl">
263
  <ul id="tabnav">
264
	<?php 
265
		$tab_array = array();
266
		$tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
267
		$tab_array[] = array(gettext("Group"), true, "system_groupmanager.php");
268
		$tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
269
		display_top_tabs($tab_array);
270
    ?>     
271
  </ul>
272
  </td></tr>    
273
<tr>
274
  <td class="tabcont">
275
<?php
276
if($_GET['act']=="new" || $_GET['act']=="edit"){
277
	if($_GET['act']=="edit"){
278
		if (isset($id) && $a_group[$id]) {
279
	       $pconfig['name'] = $a_group[$id]['name'];
280
	       $pconfig['description'] = $a_group[$id]['description'];
281
	       $pconfig['pages'] = $a_group[$id]['pages'];
282
        }
283
	}
284
?>
285
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
286

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