Project

General

Profile

Download (19.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
    $Id$
4
        part of pfSense (http://www.pfSense.com)
5
    originally part of part of m0n0wall (http://m0n0.ch/wall)
6

    
7
    Copyright (C) 2007 Bill Marquette <bill.marquette@gmail.com>.
8
    All rights reserved.
9

    
10
    Copyright (C) 2006 Scott Ullrich <sullrich@gmail.com>.
11
    All rights reserved.
12

    
13
    Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>.
14
    All rights reserved.
15

    
16
    Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
17
    All rights reserved.
18

    
19
    Redistribution and use in source and binary forms, with or without
20
    modification, are permitted provided that the following conditions are met:
21

    
22
    1. Redistributions of source code must retain the above copyright notice,
23
       this list of conditions and the following disclaimer.
24

    
25
    2. Redistributions in binary form must reproduce the above copyright
26
       notice, this list of conditions and the following disclaimer in the
27
       documentation and/or other materials provided with the distribution.
28

    
29
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
30
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
31
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
33
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
    POSSIBILITY OF SUCH DAMAGE.
39
*/
40

    
41
require("guiconfig.inc");
42

    
43
//$_SESSION['NO_AJAX'] = true;
44

    
45
$pgtitle = "System: Group manager";
46
$treeItemID = 0;
47

    
48
function walkArea($title,
49
                  $t,
50
                  $area,
51
                  $id,
52
                  &$counter,
53
                  &$script_tag,
54
                  $tmpfname,
55
                  &$group) {
56
  global $treeItemID;
57

    
58
  foreach($area as $a => $aa) {
59
    if (is_array($aa) && count($aa) > 0) {
60
      $title .= "_{$a}";
61
      echo "<li class=\"closed\"><a id=\"treeitem_{$treeItemID}\" href=\"#\">$a</a><ul>";
62
      $treeItemID++;
63
      walkArea($title,
64
               $a,
65
               $aa,
66
               $id,
67
               $counter,
68
               $script_tag,
69
               $tmpfname,
70
               $group);
71
      echo "</ul>\n";
72
    } else {
73
      $tmp_string = "{$t}";
74
      $tmp_string .= ": ";
75
      $tmp_string .= $a;
76
      $trimmed_title = trim($title);
77
      $trimmed_a = trim($a);
78
      $this_id = "{$trimmed_title}_{$trimmed_a}_{$counter}";
79
      $this_id = str_replace(" ", "", $this_id);
80
      $this_id = str_replace("/", "", $this_id);
81
      $stripped_session = str_replace("/tmp/", "", $tmpfname);
82
      $allowed = false;
83
      if (is_array($group['pages'])) {
84
          foreach($group['pages'] as $page) {
85
              if (stristr($aa, $page))
86
                  $allowed = true;
87
              // echo "$page || $aa";
88
          }
89
      }
90
      $allowed ? $checked = " checked=\"checked\"" : $checked = "";
91
      echo "                        <li id=\"treeitem_{$treeItemID}\" class=\"closed\" title=\"{$aa}\"><a name=\"anchor_{$treeItemID}\" style=\"display: none;\">&nbsp;</a>";
92
      $idForOnClick = $treeItemID;
93
      $treeItemID++;
94
      echo "<input type=\"checkbox\" class=\"formfld\" id=\"treeitem_{$treeItemID}\" ";
95
      $treeItemID++;
96
      echo "name=\"treeitem_{$treeItemID}\" title=\"{$area}\" onClick=\"getURL('system_groupmanager.php?id={$id}&amp;toggle={$aa}&amp;item={$idForOnClick}&amp;session={$stripped_session}', after_request_callback); rotate();\" {$checked} />&nbsp;";
97
      $treeItemID++;
98
      echo "<a id=\"treeitem_{$treeItemID}\" href=\"#anchor_{$idForOnClick}\" onclick=\"getURL('system_groupmanager.php?id={$id}&amp;toggle={$aa}&amp;item={$idForOnClick}&amp;session={$stripped_session}', after_request_callback); rotate();\">{$a}</a></li>\n";
99
      $idForScript = $treeItemID;
100
      $treeItemID++;
101

    
102
//echo "$script_tag <hr />";
103
      $script_tag .= "var item = document.getElementById('treeitem_{$idForScript}');\n";
104
      if ($allowed) {
105
          $script_tag .= "item.style.backgroundImage = \"url('/tree/page-file_play.gif')\";\n";
106
      } else {
107
          $script_tag .= "item.style.backgroundImage = \"url('/tree/page-file_x.gif')\";\n";
108
      }
109
      $counter++;
110
    } // end if
111
  } // end foreach
112
}
113

    
114
function init_ajax_helper_file()
115
{
116
    global $config, $id, $global;
117
    $a_group = &$config['system']['group'];
118
    $id = $_GET['id'];
119
    if (isset($id) && $a_group[$id])
120
        $group = $a_group[$id];
121
    else
122
        $group = array();
123
    $_SESSION['group_pages'] = $group['pages'];
124
    return;
125
}
126

    
127
if ($_GET['toggle'] <> "") {
128
    /* AJAX is calling, lets take care of it */
129
    if (!file_exists("/tmp/" . $_GET['session'])) {
130
        init_ajax_helper_file($_GET['session']);
131
    }
132
    $fc = file_get_contents("/tmp/" . $_GET['session']);
133
    $file_split = split("\n", $fc);
134
    $found = -1;
135
    for($x = 0; $x < count($file_split); $x++) {
136
        if ($file_split[$x] == $_GET['toggle']) {
137
            $found = $x;
138
        }
139
    }
140
    if ($found == -1) {
141
        $file_split[] = $_GET['toggle'];
142
        $image = "/tree/page-file_play.gif";
143
    } else {
144
        unset($file_split[$found]);
145
        $image = "/tree/page-file_x.gif";
146
    }
147
    $fd = fopen("/tmp/{$_GET['session']}", "w");
148
    if ($file_split)
149
        foreach($file_split as $fs) {
150
        if ($fs)
151
            fwrite($fd, $fs . "\n");
152
    }
153
    fclose($fd);
154
    echo $_GET['item'] . "_a||" . "{$image}";
155
    exit;
156
}
157

    
158
function convert_array_to_pgtitle($orig)
159
{
160
    $newstring = "";
161
    foreach($orig as $o) {
162
        if ($newstring <> "")
163
            $newstring .= ": ";
164
        $newstring .= $o;
165
    }
166
    return $newstring;
167
}
168
// Returns an array of pages with their descriptions
169
function getAdminPageList()
170
{
171
    global $g;
172

    
173
    $tmp = Array();
174

    
175
    if ($dir = opendir($g['www_path'])) {
176
        while ($file = readdir($dir)) {
177
            // Make sure the file exists and is not a directory
178
            if ($file == "." or $file == ".." or $file[0] == '.')
179
                continue;
180
            // Is this a .inc.php file? pfSense!
181
            if (fnmatch('guiconfig.inc', $file))
182
                continue;
183
            if (fnmatch('*.inc', $file))
184
                continue;
185
            if (fnmatch('*.inc.php', $file))
186
                continue;
187
            if (fnmatch('*.php', $file)) {
188
                // Read the description out of the file
189
                $contents = file_get_contents($file);
190
                $contents_split = split("\n", $contents);
191
                $mlinestr = "";
192
                foreach($contents_split as $contents) {
193
                    $pgtitle = "";
194
                    // Looking for a line like:
195
                    // $pgtitle = array(gettext("System"), gettext("Group manager")); // - DO NOT REMOVE.
196
                    if ($mlinestr == "" && stristr($contents, "\$pgtitle") == false)
197
                        continue;
198
                    if ($mlinestr == "" && stristr($contents, "=") == false)
199
                        continue;
200
                    if (stristr($contents, "<"))
201
                        continue;
202
                    if (stristr($contents, ">"))
203
                        continue;
204
                    /* at this point its evalable */
205
                    $contents = trim ($contents);
206
                    $lastchar = substr($contents, strlen($contents) - 1, strlen($contents));
207
                    $firstchar = substr($contents, 0, 1);
208

    
209
                    /* check whether pgtitle is on one or multible lines */
210
                    if ($firstchar <> "/" && $firstchar <> "#" && $lastchar <> ";") {
211
                        /* remember the partitial pgtitle string for the next loop iteration */
212
                        $mlinestr .= $contents;
213
                        continue;
214
                    } else if ($mlinestr <> "" && $lastchar == ";") {
215
                        /* this is the final pgtitle part including the semicolon */
216
                        $mlinestr .= $contents;
217
                    } else if ($mlinestr == "" && $lastchar == ";") {
218
                        /* this is a single line pgtitle, hence just
219
                         * copy its contents into mlinestr
220
                         */
221
                        $mlinestr = $contents;
222
                    } else if ($firstchar == "/" || $firstchar == "#") {
223
                        /* same applies for comment lines */
224
                        $mlinestr = $contents;
225
                    }
226

    
227
                    eval($mlinestr);
228

    
229
                    /* after eval, if not an array, continue */
230
                    if (!is_array($pgtitle)) {
231
                        /* reset mlinestr for the next loop iteration */
232
                        $mlinestr = "";
233
                        continue;
234
                    }
235

    
236
                    $tmp[$file] = $pgtitle;
237

    
238
                    /* break out of the for loop, on to next file */
239
                    break;
240
                }
241
            }
242
        }
243

    
244
        /* loop through and read in wizard information */
245
        if ($dir = opendir("{$g['www_path']}/wizards")) {
246
            while ($file = readdir($dir)) {
247
                // Make sure the file exists and is not directory
248
                if ($file == "." or $file == ".." or $file[0] == '.')
249
                    continue;
250
                // Is this a .xml file? pfSense!
251
                if (fnmatch('*.xml', $file)) {
252
                    /* parse package and retrieve the package title */
253
                    $pkg = parse_xml_config_pkg("{$g['www_path']}/wizards/{$file}", "pfsensewizard");
254
                    $title = $pkg['title'];
255
                    if ($title)
256
                        $tmp[$file] = trim($title);
257
                }
258
            }
259
        }
260

    
261
        /* loop through and read in package information */
262
        if ($dir = opendir("{$g['pkg_path']}")) {
263
            while ($file = readdir($dir)) {
264
                // Make sure the file exists and is not directory
265
                if ($file == "." or $file == ".." or $file[0] == '.')
266
                    continue;
267
                // Is this a .xml file? pfSense!
268
                if (fnmatch('*.xml', $file)) {
269
                    /* parse package and retrieve the package title */
270
                    $pkg = @parse_xml_config_pkg("{$g['pkg_path']}/{$file}", "packagegui");
271
                    $title = $pkg['title'];
272
                    if ($title)
273
                        $tmp[$file] = trim($title);
274
                }
275
            }
276
            closedir($dir);
277
        }
278

    
279
        // Sets Interfaces:Optional page that didn't read in properly with the above method,
280
        // and pages that don't have descriptions.
281
        $tmp['interfaces_opt.php'] = ("Interfaces: Optional");
282
        $tmp['graph.php'] = ("Status: Traffic Graph");
283
        $tmp['graph_cpu.php'] = ("Diagnostics: CPU Utilization");
284
        $tmp['exec_raw.php'] = ("Hidden: Exec Raw");
285
        $tmp['uploadconfig.php'] = ("Hidden: Upload Configuration");
286
        $tmp['index.php'] = ("Status: System");
287
        $tmp['system_usermanager.php'] = ("System: User Password");
288
        $tmp['diag_logs_settings.php'] = ("Diagnostics: Logs: Settings");
289
        $tmp['diag_logs_vpn.php'] = ("Diagnostics: Logs: PPTP VPN");
290
        $tmp['diag_logs_filter.php'] = ("Diagnostics: Logs: Firewall");
291
        $tmp['diag_logs_portal.php'] = ("Diagnostics: Logs: Captive Portal");
292
        $tmp['diag_logs_dhcp.php'] = ("Diagnostics: Logs: DHCP");
293
        $tmp['diag_logs.php'] = ("Diagnostics: Logs: System");
294

    
295
        $tmp['ifstats.php'] = ("Hidden: *XMLRPC Interface Stats");
296
        $tmp['license.php'] = ("System: License");
297
        $tmp['progress.php'] = ("Hidden: *No longer included");
298
        $tmp['diag_logs_filter_dynamic.php'] = ("Hidden: *No longer included");
299
        $tmp['preload.php'] = ("Hidden: *XMLRPC Preloader");
300
        $tmp['xmlrpc.php'] = ("Hidden: *XMLRPC Library");
301
        $tmp['pkg.php'] = ("System: *Renderer for XML based package GUIs (Part I)");
302
        $tmp['pkg_edit.php'] = ("System: *Renderer for XML based package GUIs (Part II)");
303

    
304
        $tmp['functions.inc.php'] = ("Hidden: Ajax Helper 1");
305
        $tmp['javascript.inc.php'] = ("Hidden: Ajax Helper 2 ");
306
        $tmp['sajax.class.php'] = ("Hidden: Ajax Helper 3");
307

    
308
        asort($tmp);
309

    
310
        return $tmp;
311
    }
312
}
313
// Get a list of all admin pages & Descriptions
314
$pages = getAdminPageList();
315

    
316
if (!is_array($config['system']['group'])) {
317
    $config['system']['group'] = array();
318
}
319
admin_groups_sort();
320
$a_group = &$config['system']['group'];
321

    
322
$id = $_GET['id'];
323
if (isset($_POST['id']))
324
    $id = $_POST['id'];
325

    
326
if ($_GET['act'] == "del") {
327
    if ($a_group[$_GET['id']]) {
328
        $ok_to_delete = true;
329
        if (isset($config['system']['user'])) {
330
            foreach ($config['system']['user'] as $userent) {
331
                if ($userent['groupname'] == $a_group[$_GET['id']]['name']) {
332
                    $ok_to_delete = false;
333
                    $input_errors[] = gettext("users still exist who are members of this group!");
334
                    break;
335
                }
336
            }
337
        }
338
        if ($ok_to_delete) {
339
            unset($a_group[$_GET['id']]);
340
            write_config();
341
            pfSenseHeader("system_groupmanager.php");
342
            exit;
343
        }
344
    }
345
}
346

    
347
if ($_POST) {
348
    unset($input_errors);
349
    $pconfig = $_POST;
350
    /* input validation */
351
    $reqdfields = explode(" ", "groupname");
352
    $reqdfieldsn = explode(",", "Group Name");
353

    
354
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
355

    
356
    if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
357
        $input_errors[] = gettext("The group name contains invalid characters.");
358

    
359
    if (!$input_errors && !(isset($id) && $a_group[$id])) {
360
        /* make sure there are no dupes */
361
        foreach ($a_group as $group) {
362
            if ($group['name'] == $_POST['groupname']) {
363
                $input_errors[] = gettext("Another entry with the same group name already exists.");
364
                break;
365
            }
366
        }
367
    }
368

    
369
    if (!$input_errors) {
370
        if (isset($id) && $a_group[$id])
371
            $group = $a_group[$id];
372

    
373
        $group['name'] = $_POST['groupname'];
374
        isset($_POST['homepage']) ? $group['home'] = $_POST['homepage'] : $group['home'] = "index.php";
375
        isset($_POST['gtype']) ? $group['scope'] = $_POST['gtype'] : $group['scope'] = "system";
376
        $group['description'] = $_POST['description'];
377
        unset($group['pages'][0]['page']);
378

    
379
        $file_split = split("\n", file_get_contents("/tmp/" . $_POST['session']));
380
        for($x = 0; $x < count($file_split); $x++) {
381
            if ($file_split[$x])
382
                $group['pages'][0]['page'][] = $file_split[$x];
383
        }
384

    
385
        if (isset($id) && $a_group[$id])
386
            $a_group[$id] = $group;
387
        else
388
            $a_group[] = $group;
389

    
390
        write_config();
391

    
392
        pfSenseHeader("system_groupmanager.php");
393
        exit;
394
    }
395
}
396

    
397
include("head.inc");
398

    
399
?><script type="text/javascript">
400

    
401
  function checkallareas(enable) {
402
    var elem = document.iform.elements.length;
403
    var endis = (document.iform.checkall.checked || enable);
404

    
405
    for (i = 0; i < elem; i++) {
406
      if (document.iform.elements[i].name.indexOf("chk-") >= 0) {
407
        document.iform.elements[i].checked = true;
408
        document.iform.elements[i].click();
409
      }
410
    }
411
  }
412
  
413
</script>
414
<link href="/tree/tree.css" rel="stylesheet" type="text/css" />
415
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
416
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
417

    
418
<?
419

    
420
// XXX: billm TODO
421
//echo $pfSenseHead->getHTML();
422

    
423
?>
424

    
425
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
426
<?php include("fbegin.inc");?>
427
<p class="pgtitle"><?=$pgtitle;?></p>
428
<?php if ($input_errors) print_input_errors($input_errors);?>
429
<?php if ($savemsg) print_info_box($savemsg);?>
430
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
431
    <tr>
432
      <td class="tabnavtbl">
433
<?php
434
  $tab_array = array();
435
  $tab_array[] = array(gettext("Users"), false, "system_usermanager.php");
436
  $tab_array[] = array(gettext("Group"), true, "system_groupmanager.php");
437
  $tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
438
  display_top_tabs($tab_array);
439
?>
440
      </td>
441
    </tr>
442
    <tr>
443
      <td class="tabcont">
444

    
445
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
446
    <tr>
447
      <td width="35%" class="listhdrr"><?=gettext("Group name");?></td>
448
      <td width="20%" class="listhdrr"><?=gettext("Description");?></td>
449
      <td width="20%" class="listhdrr"><?=gettext("Pages Accessible");?></td>
450
      <td width="10%" class="list"></td>
451
    </tr>
452
<?php
453
    $i = 0;
454
    foreach($a_group as $group):
455
?>
456
    <tr>
457
      <td class="listlr" valign="middle" nowrap="nowrap">
458
        <table border="0" cellpadding="0" cellspacing="0">
459
          <tr>
460
            <td align="left" valign="middle">
461
              <?php if($group['scope'] == "user"): ?>
462
              <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-group.png" alt="Group" title="Group" border="0" height="20" width="20" />
463
              <?php else: ?>
464
              <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-group-grey.png" alt="Group" title="Group" border="0" height="20" width="20" />
465
              <?php endif; ?>
466
              &nbsp;
467
            </td>
468
            <td align="left" valign="middle">
469
		<?
470
		if($group['name'] != "")
471
			echo htmlspecialchars($group['name']);
472
		else
473
			echo "&nbsp";
474
		?>
475
            </td>
476
          </tr>
477
        </table>
478
      </td>
479
      <td class="listr">
480
                <?
481
		if($group['description'] != "")
482
			echo htmlspecialchars($group['description']);
483
		else
484
			echo "&nbsp;";
485
		?>
486
      </td>
487
      <td class="listbg">
488
        <?php if(is_array($group['pages'])): ?>
489
          <?php if ($group['pages'][0] == 'ANY'): ?>
490
        <font color="white">ANY</font>
491
          <? else: ?>
492
        <font color="white"><?=count($group['pages']);?> pages</font>
493
          <?php endif; ?>
494
        <?php endif; ?>
495
      </td>
496
      <?php if($group['scope'] == "user"): ?>
497
      <td valign="middle" nowrap class="list">
498
        <a href="system_groupmanager_edit.php?act=edit&amp;id=<?=$i;?>">
499
          <img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit group");?>" width="17" height="17" border="0" alt="" />
500
        </a>
501
        <a href="system_groupmanager.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this group?");?>')">
502
          <img src="./themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete group");?>" width="17" height="17" border="0" alt="" />
503
        </a>
504
      </td>
505
      <?php endif; ?>
506
    </tr>
507
<?php
508
    $i++;
509
    endforeach;
510
?>
511
    <tr>
512
      <td class="list" colspan="3"></td>
513
      <td class="list">
514
        <a href="system_groupmanager_edit.php?act=new">
515
          <img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add group");?>" width="17" height="17" border="0" alt="" />
516
        </a>
517
      </td>
518
    </tr>
519
    <tr>
520
      <td colspan="3">
521
        <p>
522
        <?=gettext("Additional webConfigurator admin groups can be added here.  Each group can be restricted to specific portions of the webConfigurator.  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.");?>
523
        </p>
524
        <p>
525
          <?=gettext("A group icon that appears grey indicates that it is a system group and thus can't be modified or deleted.");?>
526
        </p>
527
      </td>
528
    </tr>
529
  </table>
530
  </td></tr>
531
</table>
532

    
533
<script type="text/javascript">
534
  window.setTimeout('afterload()', '10');
535
  function afterload() {
536
    <?php echo $script_tag ?>
537
  }
538
</script>
539
<?php include("fend.inc");?>
540
</body>
541
</html>
542
        
(152-152/186)