Project

General

Profile

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

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

    
10
    Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
11
    All rights reserved.
12

    
13
    Redistribution and use in source and binary forms, with or without
14
    modification, are permitted provided that the following conditions are met:
15

    
16
    1. Redistributions of source code must retain the above copyright notice,
17
       this list of conditions and the following disclaimer.
18

    
19
    2. Redistributions in binary form must reproduce the above copyright
20
       notice, this list of conditions and the following disclaimer in the
21
       documentation and/or other materials provided with the distribution.
22

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

    
35
require("guiconfig.inc");
36
// The page title for non-admins
37
$pgtitle = array("System","User Password");
38

    
39
/* Check for custom priv system_usermanager (no .php ending) */
40
$isAdminUser = false;
41
$allowed = $g['privs'];
42
if(is_array($allowed))
43
	if (in_array("system_usermanager", $allowed))
44
		$isAdminUser = true;
45

    
46
if (isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER']) or $isAdminUser == true) {
47
    // Page title for main admin
48
    $pgtitle = array("System","User Manager");
49

    
50
    $id = $_GET['id'];
51
    if (isset($_POST['id']))
52
        $id = $_POST['id'];
53

    
54
	if (!is_array($config['system']['user'])) 
55
		$config['system']['user'] = array();
56

    
57
    admin_users_sort();
58
    if (is_array($config['system']['user'])) 
59
		$a_user = &$config['system']['user'];
60
    $t_privs = $a_user[$id]['priv'];
61

    
62
    if ($_GET['act'] == "del" && $_GET['what'] == "user") {
63
        if ($a_user[$_GET['id']]) {
64
            $userdeleted = $a_user[$_GET['id']]['name'];
65
            unset($a_user[$_GET['id']]);
66
            write_config();
67
            $retval = system_password_configure();
68
            $savemsg = get_std_save_message($retval);
69
            $savemsg = gettext("User") . " " . $userdeleted . " " . gettext("successfully deleted") . "<br />";
70
        }
71
    } else if ($_GET['act'] == "del" && $_GET['what'] == "priv") {
72
        if ($t_privs[$_GET['privid']]) {
73
            $privdeleted = $t_privs[$_GET['privid']]['id'];
74
            unset($a_user[$id]['priv'][$_GET['privid']]);
75
            write_config();
76
            unset($t_privs[$_GET['privid']]);
77
            $_GET['act'] = "edit";
78
            $retval = 0;
79
            $savemsg = get_std_save_message($retval);
80
            $savemsg = gettext("Privilege") . " " . $privdeleted . " " . gettext("of user") . " " . $a_user[$_GET['id']]['name'] . " " . gettext("successfully deleted") . "<br />";
81
        }
82
    }
83

    
84
    if ($_POST) {
85
        unset($input_errors);
86
        $pconfig = $_POST;
87

    
88
		if(!$_POST['groupname']) 
89
			$input_errors[] = "You must specify at least one group!";
90

    
91
        /* input validation */
92
        if (isset($id) && ($a_user[$id])) {
93
            $reqdfields = explode(" ", "usernamefld");
94
            $reqdfieldsn = explode(",", "Username");
95
        } else {
96
            $reqdfields = explode(" ", "usernamefld passwordfld1");
97
            $reqdfieldsn = explode(",", "Username,Password");
98
        }
99

    
100
        do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
101

    
102
        if (hasShellAccess($_POST['usernamefld'])) {
103
          if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['usernamefld']))
104
              $input_errors[] = gettext("The username contains invalid characters.");
105
        } else {
106
          if (preg_match("/[^a-zA-Z0-9\@\.\-_]/", $_POST['usernamefld']))
107
              $input_errors[] = gettext("The username contains invalid characters.");
108
        }
109

    
110
        if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2']))
111
            $input_errors[] = gettext("The passwords do not match.");
112

    
113
        if (!$input_errors && !(isset($id) && $a_user[$id])) {
114
            /* make sure there are no dupes */
115
            foreach ($a_user as $userent) {
116
                if ($userent['name'] == $_POST['usernamefld']) {
117
                    $input_errors[] = gettext("Another entry with the same username already exists.");
118
                    break;
119
                }
120
            }
121
        }
122

    
123
		if(is_array($_POST['groupname'])) {
124
			foreach($_POST['groupname'] as $groupname) {
125
        		if ($pconfig['utype'] <> "system" && !isset($groupindex[$groupname])) {
126
            		$input_errors[] = gettext("group {$groupname} does not exist, please define the group before assigning users.");
127
        		}
128
			}
129
		}
130

    
131
        if (isset($config['system']['ssh']['sshdkeyonly']) &&
132
            empty($_POST['authorizedkeys'])) {
133
          $input_errors[] = gettext("You must provide an authorized key otherwise you won't be able to login into this system.");
134
        }
135

    
136
        /* if this is an AJAX caller then handle via JSON */
137
        if (isAjax() && is_array($input_errors)) {
138
            input_errors2Ajax($input_errors);
139
            exit;
140
        }
141

    
142
        if (!$input_errors) {
143
			$userent = "";
144
            if (isset($id) && $a_user[$id])
145
                $userent = $a_user[$id];
146

    
147
            /* the user did change his username */
148
            if ($_POST['usernamefld'] <> $_POST['oldusername']) {
149
                $_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
150
            }
151

    
152
            $userent['name'] = $_POST['usernamefld'];
153
            $userent['fullname'] = $_POST['fullname'];
154

    
155
            if ($pconfig['utype'] <> "system") 
156
				$userent['groupname'] = implode(",", $_POST['groupname']);
157

    
158
            isset($_POST['utype']) ? $userent['scope'] = $_POST['utype'] : $userent['scope'] = "system";
159

    
160
            if ($_POST['passwordfld1'])
161
                $userent['password'] = crypt($_POST['passwordfld1']);
162

    
163
            if(isset($config['system']['ssh']['sshdkeyonly'])) {
164
                $userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
165
            }
166

    
167
            if (isset($id) && $a_user[$id])
168
                $a_user[$id] = $userent;
169
            else
170
                $a_user[] = $userent;
171

    
172
            write_config();
173
            $retval = system_password_configure();
174
            sync_webgui_passwords();
175

    
176
            pfSenseHeader("system_usermanager.php");
177
        }
178
    }
179

    
180
    include("head.inc");
181
?>
182

    
183
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
184
<?php include("fbegin.inc");?>
185
<?php if ($input_errors) print_input_errors($input_errors);?>
186
<?php if ($savemsg) print_info_box($savemsg);?>
187
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
188
    <tr>
189
      <td class="tabnavtbl">
190
<?php
191
    $tab_array = array();
192
    $tab_array[] = array(gettext("Users"), true, "system_usermanager.php");
193
    $tab_array[] = array(gettext("Group"), false, "system_groupmanager.php");
194
    $tab_array[] = array(gettext("Settings"), false, "system_usermanager_settings.php");
195
    display_top_tabs($tab_array);
196
?>
197
      </td>
198
    </tr>
199
    <tr>
200
      <td class="tabcont">
201
<?php
202
    if ($_GET['act'] == "new" || $_GET['act'] == "edit" || $input_errors) {
203
        if ($_GET['act'] == "edit") {
204
            if (isset($id) && $a_user[$id]) {
205
                $pconfig['usernamefld'] = $a_user[$id]['name'];
206
                $pconfig['fullname'] = $a_user[$id]['fullname'];
207
                $pconfig['groupname'] = split(",", $a_user[$id]['groupname']);
208
                $pconfig['utype'] = $a_user[$id]['scope'];
209
                $pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']);
210
            }
211
        } else if ($_GET['act'] == "new") {
212
          /* set this value cause the text field is read only
213
           * and the user should not be able to mess with this
214
           * setting.
215
           */
216
          $pconfig['utype'] = "user";
217
        }
218
?>
219
      <form action="system_usermanager.php" method="post" name="iform" id="iform">
220
        <div id="inputerrors"></div>
221
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
222
          <tr>
223
            <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
224
            <td width="78%" class="vtable">
225
              <input name="usernamefld" type="text" class="formfld user" id="usernamefld" size="20" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" <?php if ($pconfig['utype'] == "system") { echo "readonly=\"readonly\" "; }?>/>
226
              <input name="oldusername" type="hidden" id="oldusername" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" />
227
            </td>
228
          </tr>
229
          <tr>
230
            <td width="22%" valign="top" class="vncellreq" rowspan="2"><?=gettext("Password");?></td>
231
            <td width="78%" class="vtable">
232
              <input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" value="" />
233
            </td>
234
          </tr>
235
          <tr>
236
            <td width="78%" class="vtable">
237
              <input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" value="" />&nbsp;<?= gettext("(confirmation)"); ?>
238
            </td>
239
          </tr>
240
          <tr>
241
            <td width="22%" valign="top" class="vncell"><?=gettext("Full name");?></td>
242
            <td width="78%" class="vtable">
243
              <input name="fullname" type="text" class="formfld unknown" id="fullname" size="20" value="<?=htmlspecialchars($pconfig['fullname']);?>" <?php if ($pconfig['utype'] == "system") { echo "readonly=\"readonly\" "; }?>/>
244
              <br />
245
              <?=gettext("User's full name, for your own information only");?>
246
            </td>
247
          </tr>
248
          <tr>
249
            <td width="22%" valign="top" class="vncell"><?=gettext("User type");?></td>
250
            <td width="78%" class="vtable">
251
              <input name="utype" type="text" class="formfld unknown" id="utype" size="20" value="<?=htmlspecialchars($pconfig['utype']);?>" readonly="readonly" />
252
              <br />
253
              <?=gettext("Indicates whether this is a system (aka non-deletable) user or a user created by a particular user.");?>
254
            </td>
255
          </tr>
256
          <?php if (isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER'])): ?>
257
          <tr>
258
            <td width="22%" valign="top" class="vncell"><?=gettext("User Privileges");?></td>
259
            <td width="78%" class="vtable">
260
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
261
                <tr>
262
                  <td width="5%" class="listhdrr"><?=gettext("ID");?></td>
263
                  <td width="30%" class="listhdrr"><?=gettext("Name");?></td>
264
                  <td width="40%" class="listhdrr"><?=gettext("Description");?></td>
265
                  <td width="5%" class="list"></td>
266
                </tr>
267

    
268
                <?php if(is_array($t_privs)): ?>
269
                <?php $i = 0; foreach ($t_privs as $priv): ?>
270
                <?php if($priv['id'] <> ""): ?>
271
                <tr>
272
                  <td class="listlr" <?php if($a_user[$id]['scope'] == "user") echo "ondblclick=\"document.location='system_usermanager_edit.php?id={$i}&userid={$id}&useract={$_GET['act']}';\""; ?>>
273
                    <?=htmlspecialchars($priv['id']);?>
274
                  </td>
275
                  <td class="listlr" <?php if($a_user[$id]['scope'] == "user") echo "ondblclick=\"document.location='system_usermanager_edit.php?id={$i}&userid={$id}&useract={$_GET['act']}';\""; ?>>
276
                    <?=htmlspecialchars($priv['name']);?>
277
                  </td>
278
                  <td class="listbg" <?php if($a_user[$id]['scope'] == "user") echo "ondblclick=\"document.location='system_usermanager_edit?id={$i}&userid={$id}&useract={$_GET['act']}';\""; ?>>
279
                    <font color="#FFFFFF"><?=htmlspecialchars($priv['descr']);?>&nbsp;</font>
280
                  </td>
281
                  <td valign="middle" nowrap class="list">
282
                    <?php if($a_user[$id]['scope'] == "user"): ?>
283
                    <table border="0" cellspacing="0" cellpadding="1">
284
                      <tr>
285
                        <td valign="middle"><a href="system_usermanager_edit.php?id=<?=$i;?>&userid=<?= $id ?>&useract=<?= $_GET['act'] ?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="" /></a></td>
286
                        <td valign="middle"><a href="system_usermanager.php?act=del&privid=<?=$i;?>&what=priv&id=<?= $id ?>" onclick="return confirm('<?=gettext("Do you really want to delete this mapping?");?>')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="" /></a></td>
287
                      </tr>
288
                    </table>
289
                    <?php endif; ?>
290
                  </td>
291
                </tr>
292
                <?php endif; ?>
293
                <?php $i++; endforeach; ?>
294
                <?php endif; ?>
295

    
296
                <?php if($a_user[$id]['scope'] == "user"): ?>
297
                <tr>
298
                  <td class="list" colspan="3"></td>
299
                  <td class="list">
300
                    <table border="0" cellspacing="0" cellpadding="1">
301
                      <tr>
302
                        <td valign="middle"><a href="system_usermanager_edit.php?userid=<?= $id ?>&useract=<?= $_GET['act'] ?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" /></a></td>
303
                      </tr>
304
                    </table>
305
                  </td>
306
                </tr>
307
                <?php endif; ?>
308
              </table>
309
            </td>
310
          </tr>
311
          <?php endif; ?>
312
          <?php if (isset($config['system']['ssh']['sshdkeyonly'])): ?>
313
          <tr>
314
            <td width="22%" valign="top" class="vncell"><?=gettext("Authorized keys");?></td>
315
            <td width="78%" class="vtable">
316
              <textarea name="authorizedkeys" cols="65" rows="7" id="authorizedkeys" class="formfld_cert" wrap="off"><?=htmlspecialchars($pconfig['authorizedkeys']);?></textarea>
317
              <br />
318
              <?=gettext("Paste an authorized keys file here.");?>
319
            </td>
320
          </tr>
321
          <?php endif; ?>
322
          <tr>
323
            <td width="22%" valign="top" class="vncell"><?=gettext("Group Name");?></td>
324
            <td width="78%" class="vtable">
325
              <select size="10" name="groupname[]" class="formselect" id="groupname" <?php if ($pconfig['utype'] == "system") { echo "disabled=\"disabled\" "; } ?> MULTIPLE>
326
              <?php foreach ($config['system']['group'] as $group): ?>
327
                <option value="<?=$group['name'];?>" <?php if (in_array($group['name'],$pconfig['groupname'])) { echo "selected"; } ?>>
328
                      <?=htmlspecialchars($group['name']);?>
329
                </option>
330
              <?php endforeach;?>
331
              </select>
332
              <br />
333
              <?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
334
            </td>
335
          </tr>
336
          <tr>
337
            <td width="22%" valign="top">&nbsp;</td>
338
            <td width="78%">
339
              <input id="submit" name="save" type="submit" class="formbtn" value="Save" />
340
              <?php if (isset($id) && $a_user[$id]): ?>
341
              <input name="id" type="hidden" value="<?=$id;?>" />
342
              <?php endif;?>
343
            </td>
344
          </tr>
345
        </table>
346
      </form>
347
<?php
348
    } else {
349
?>
350
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
351
        <tr>
352
          <td width="35%" class="listhdrr">Username</td>
353
          <td width="20%" class="listhdrr">Full name</td>
354
          <td width="20%" class="listhdrr">Group</td>
355
          <td width="10%" class="list"></td>
356
        </tr>
357
<?php
358
        $i = 0;
359
        foreach($a_user as $userent):
360
?>
361
        <tr ondblclick="document.location='system_usermanager.php?act=edit&id=<?=$i;?>'">
362
          <td class="listlr">
363
            <table border="0" cellpadding="0" cellspacing="0">
364
              <tr>
365
                <td align="left" valign="middle">
366
                  <?php if($userent['scope'] == "user"): ?>
367
                  <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-user.png" alt="User" title="User" border="0" height="20" width="20" />
368
                  <?php else: ?>
369
                  <img src="/themes/<?=$g['theme'];?>/images/icons/icon_system-user-grey.png" alt="User" title="User" border="0" height="20" width="20" />
370
                  <?php endif; ?>
371
                  &nbsp;
372
                </td>
373
                <td align="left" valign="middle">
374
                  <?=htmlspecialchars($userent['name']);?>
375
                </td>
376
              </tr>
377
            </table>
378
          </td>
379
          <td class="listr"><?=htmlspecialchars($userent['fullname']);?>&nbsp;</td>
380
          <td class="listbg">
381
			<?php
382
				$groupname = split(",", $userent['groupname']);
383
			?>
384
            <font color="white"><?=htmlspecialchars(implode(",",$groupname));?></font>&nbsp;
385
          </td>
386
          <td valign="middle" nowrap class="list">
387
            <a href="system_usermanager.php?act=edit&id=<?=$i;?>">
388
              <img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="edit user" alt="edit user" width="17" height="17" border="0" />
389
            </a>
390
            <?php if($userent['scope'] == "user"): ?>
391
            &nbsp;
392
            <a href="system_usermanager.php?act=del&what=user&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this User?");?>')">
393
              <img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="delete user" alt="delete user" width="17" height="17" border="0" />
394
            </a>
395
            <?php endif; ?>
396
          </td>
397
        </tr>
398
<?php
399
        $i++;
400
        endforeach;
401
?>
402
        <tr>
403
          <td class="list" colspan="3"></td>
404
          <td class="list">
405
            <a href="system_usermanager.php?act=new">
406
              <img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="add user" alt="add user" width="17" height="17" border="0" />
407
            </a>
408
          </td>
409
        </tr>
410
        <tr>
411
          <td colspan="3">
412
            <p>
413
              <?=gettext("Additional webConfigurator users can be added here.  User permissions are determined by the admin group they are a member of.");?>
414
            </p>
415
            <p>
416
              <?=gettext("An user icon that appears grey indicates that it is a system user and thus it's only possible to modified a subset of the regular user data. Additionally such an user can't be deleted.");?>
417
            </p>
418
          </td>
419
        </tr>
420
      </table>
421
<?php
422
    }
423
?>
424
    </td>
425
  </tr>
426
</table>
427
<?php
428
} else { // end of admin user code, start of normal user code
429
    if (isset($_POST['save'])) {
430
        unset($input_errors);
431

    
432
        /* input validation */
433
        $reqdfields = explode(" ", "passwordfld1");
434
        $reqdfieldsn = explode(",", "Password");
435

    
436
        do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
437

    
438
        if ($_POST['passwordfld1'] != $_POST['passwordfld2'])
439
            $input_errors[] = "The passwords do not match.";
440

    
441
        if (!$input_errors) {
442
            // all values are okay --> saving changes
443
            $config['system']['user'][$userindex[$HTTP_SERVER_VARS['AUTH_USER']]]['password'] = crypt(trim($_POST['passwordfld1']));
444

    
445
            write_config();
446

    
447
            sync_webgui_passwords();
448

    
449
            $retval = system_password_configure();
450
            $savemsg = get_std_save_message($retval);
451
            $savemsg = "Password successfully changed<br />";
452
        }
453
    }
454
?>
455

    
456
<?php
457
    include("head.inc");
458
?>
459
<?php include("fbegin.inc");?>
460
<?php if ($input_errors) print_input_errors($input_errors);?>
461
<?php if ($savemsg) print_info_box($savemsg);?>
462
<?php
463

    
464
/* deterimine if user is not local to system */
465
$islocal = false;
466
foreach($config['system']['user'] as $user) 
467
	if($user['name'] == $_SESSION['Username'])
468
		$islocal = true;
469
if($islocal == false) {
470
	echo "Sorry, you cannot change the password for a LDAP user.";
471
	include("fend.inc");
472
	exit;
473
}
474

    
475
?>
476
  <body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
477
    <form action="system_usermanager.php" method="post" name="iform" id="iform">
478
      <table width="100%" border="0" cellpadding="6" cellspacing="0">
479
        <tr>
480
          <td colspan="2" valign="top" class="listtopic"><?=$HTTP_SERVER_VARS['AUTH_USER']?>'s Password</td>
481
        </tr>
482
        <tr>
483
          <td width="22%" valign="top" class="vncell" rowspan="2">Password</td>
484
          <td width="78%" class="vtable">
485
            <input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" />
486
          </td>
487
        </tr>
488
        <tr>
489
          <td width="78%" class="vtable">
490
            <input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" />
491
            &nbsp;<?=gettext("(confirmation)");?>
492
            <br />
493
            <span class="vexpl"><?=gettext("Select a new password");?></span>
494
          </td>
495
        </tr>
496
        <tr>
497
          <td width="22%" valign="top">&nbsp;</td>
498
          <td width="78%">
499
            <input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
500
          </td>
501
        </tr>
502
      </table>
503
    </form>
504
<?php
505
} // end of normal user code
506
?>
507

    
508
<?php include("fend.inc");?>
509
</body>
510
</html>
511

    
(156-156/189)