Project

General

Profile

Download (20.9 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
if (isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER'])) {
40
    // Page title for main admin
41
    $pgtitle = array("System","User Manager");
42

    
43
    $id = $_GET['id'];
44
    if (isset($_POST['id']))
45
        $id = $_POST['id'];
46

    
47
	if (!is_array($config['system']['user'])) 
48
		$config['system']['user'] = array();
49

    
50
    admin_users_sort();
51
    if (is_array($config['system']['user'])) 
52
		$a_user = &$config['system']['user'];
53
    $t_privs = $a_user[$id]['priv'];
54

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

    
77
    if ($_POST) {
78
        unset($input_errors);
79
        $pconfig = $_POST;
80

    
81
        /* input validation */
82
        if (isset($id) && ($a_user[$id])) {
83
            $reqdfields = explode(" ", "usernamefld");
84
            $reqdfieldsn = explode(",", "Username");
85
        } else {
86
            $reqdfields = explode(" ", "usernamefld passwordfld1");
87
            $reqdfieldsn = explode(",", "Username,Password");
88
        }
89

    
90
        do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
91

    
92
        if (hasShellAccess($_POST['usernamefld'])) {
93
          if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['usernamefld']))
94
              $input_errors[] = gettext("The username contains invalid characters.");
95
        } else {
96
          if (preg_match("/[^a-zA-Z0-9\@\.\-_]/", $_POST['usernamefld']))
97
              $input_errors[] = gettext("The username contains invalid characters.");
98
        }
99

    
100
        if (($_POST['passwordfld1']) && ($_POST['passwordfld1'] != $_POST['passwordfld2']))
101
            $input_errors[] = gettext("The passwords do not match.");
102

    
103
        if (!$input_errors && !(isset($id) && $a_user[$id])) {
104
            /* make sure there are no dupes */
105
            foreach ($a_user as $userent) {
106
                if ($userent['name'] == $_POST['usernamefld']) {
107
                    $input_errors[] = gettext("Another entry with the same username already exists.");
108
                    break;
109
                }
110
            }
111
        }
112

    
113
		if(is_array($_POST['groupname'])) {
114
			foreach($_POST['groupname'] as $groupname) {
115
        		if ($pconfig['utype'] <> "system" && !isset($groupindex[$groupname])) {
116
            		$input_errors[] = gettext("group {$groupname} does not exist, please define the group before assigning users.");
117
        		}
118
			}
119
		}
120

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

    
126
        /* if this is an AJAX caller then handle via JSON */
127
        if (isAjax() && is_array($input_errors)) {
128
            input_errors2Ajax($input_errors);
129
            exit;
130
        }
131

    
132
        if (!$input_errors) {
133
			$userent = "";
134
            if (isset($id) && $a_user[$id])
135
                $userent = $a_user[$id];
136

    
137

    
138

    
139
            /* the user did change his username */
140
            if ($_POST['usernamefld'] <> $_POST['oldusername']) {
141
                $_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
142
            }
143

    
144
            $userent['name'] = $_POST['usernamefld'];
145
            $userent['fullname'] = $_POST['fullname'];
146

    
147
            if ($pconfig['utype'] <> "system") 
148
				$userent['groupname'] = implode(",", $_POST['groupname']);
149

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

    
152
            if ($_POST['passwordfld1'])
153
                $userent['password'] = crypt($_POST['passwordfld1']);
154

    
155
            if(isset($config['system']['ssh']['sshdkeyonly'])) {
156
                $userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
157
            }
158

    
159
            if (isset($id) && $a_user[$id])
160
                $a_user[$id] = $userent;
161
            else
162
                $a_user[] = $userent;
163

    
164
            write_config();
165
            $retval = system_password_configure();
166
            sync_webgui_passwords();
167

    
168
            pfSenseHeader("system_usermanager.php");
169
        }
170
    }
171

    
172
    include("head.inc");
173
?>
174

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

    
260
                <?php if(is_array($t_privs)): ?>
261
                <?php $i = 0; foreach ($t_privs as $priv): ?>
262
                <?php if($priv['id'] <> ""): ?>
263
                <tr>
264
                  <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']}';\""; ?>>
265
                    <?=htmlspecialchars($priv['id']);?>
266
                  </td>
267
                  <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']}';\""; ?>>
268
                    <?=htmlspecialchars($priv['name']);?>
269
                  </td>
270
                  <td class="listbg" <?php if($a_user[$id]['scope'] == "user") echo "ondblclick=\"document.location='system_usermanager_edit?id={$i}&userid={$id}&useract={$_GET['act']}';\""; ?>>
271
                    <font color="#FFFFFF"><?=htmlspecialchars($priv['descr']);?>&nbsp;</font>
272
                  </td>
273
                  <td valign="middle" nowrap class="list">
274
                    <?php if($a_user[$id]['scope'] == "user"): ?>
275
                    <table border="0" cellspacing="0" cellpadding="1">
276
                      <tr>
277
                        <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>
278
                        <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>
279
                      </tr>
280
                    </table>
281
                    <?php endif; ?>
282
                  </td>
283
                </tr>
284
                <?php endif; ?>
285
                <?php $i++; endforeach; ?>
286
                <?php endif; ?>
287

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

    
424
        /* input validation */
425
        $reqdfields = explode(" ", "passwordfld1");
426
        $reqdfieldsn = explode(",", "Password");
427

    
428
        do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
429

    
430
        if ($_POST['passwordfld1'] != $_POST['passwordfld2'])
431
            $input_errors[] = "The passwords do not match.";
432

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

    
437
            write_config();
438

    
439
            sync_webgui_passwords();
440

    
441
            $retval = system_password_configure();
442
            $savemsg = get_std_save_message($retval);
443
            $savemsg = "Password successfully changed<br />";
444
        }
445
    }
446
?>
447

    
448
<?php
449
    include("head.inc");
450
?>
451
<?php include("fbegin.inc");?>
452
<?php if ($input_errors) print_input_errors($input_errors);?>
453
<?php if ($savemsg) print_info_box($savemsg);?>
454
  <body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
455
    <form action="system_usermanager.php" method="post" name="iform" id="iform">
456
      <table width="100%" border="0" cellpadding="6" cellspacing="0">
457
        <tr>
458
          <td colspan="2" valign="top" class="listtopic"><?=$HTTP_SERVER_VARS['AUTH_USER']?>'s Password</td>
459
        </tr>
460
        <tr>
461
          <td width="22%" valign="top" class="vncell" rowspan="2">Password</td>
462
          <td width="78%" class="vtable">
463
            <input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" />
464
          </td>
465
        </tr>
466
        <tr>
467
          <td width="78%" class="vtable">
468
            <input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" />
469
            &nbsp;<?=gettext("(confirmation)");?>
470
            <br />
471
            <span class="vexpl"><?=gettext("Select a new password");?></span>
472
          </td>
473
        </tr>
474
        <tr>
475
          <td width="22%" valign="top">&nbsp;</td>
476
          <td width="78%">
477
            <input name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
478
          </td>
479
        </tr>
480
      </table>
481
    </form>
482
<?php
483
} // end of normal user code
484
?>
485

    
486
<?php include("fend.inc");?>
487
</body>
488
</html>
(154-154/187)