Project

General

Profile

Download (20.7 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 = "System: User Password";
38

    
39
if (isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER'])) {
40
    // Page title for main admin
41
    $pgtitle = "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

    
51
    admin_users_sort();
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($t_privs[$_GET['privid']]);
68
            write_config();
69
            $_GET['act'] = "edit";
70
            $retval = 0;
71
            $savemsg = get_std_save_message($retval);
72
            $savemsg = gettext("Privilege") . " " . $privdeleted . " " . gettext("of user") . " " . $a_user[$_GET['id']]['name'] . " " . gettext("successfully deleted") . "<br />";
73
        }
74
    }
75

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

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

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

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

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

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

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

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

    
121
        /* if this is an AJAX caller then handle via JSON */
122
        if (isAjax() && is_array($input_errors)) {
123
            input_errors2Ajax($input_errors);
124
            exit;
125
        }
126

    
127
        if (!$input_errors) {
128
			$userent = "";
129
            if (isset($id) && $a_user[$id])
130
                $userent = $a_user[$id];
131

    
132
            /* the user did change his username */
133
            if ($_POST['usernamefld'] <> $_POST['oldusername']) {
134
                $_SERVER['REMOTE_USER'] = $_POST['usernamefld'];
135
            }
136

    
137
            $userent['name'] = $_POST['usernamefld'];
138
            $userent['fullname'] = $_POST['fullname'];
139
            if ($pconfig['utype'] <> "system") {
140
              $userent['groupname'] = $_POST['groupname'];
141
            }
142
            isset($_POST['utype']) ? $userent['scope'] = $_POST['utype'] : $userent['scope'] = "system";
143

    
144
            if ($_POST['passwordfld1'])
145
                $userent['password'] = crypt($_POST['passwordfld1']);
146

    
147
            if(isset($config['system']['ssh']['sshdkeyonly'])) {
148
                $userent['authorizedkeys'] = base64_encode($_POST['authorizedkeys']);
149
            }
150

    
151
            if (isset($id) && $a_user[$id])
152
                $a_user[$id] = $userent;
153
            else
154
                $a_user[] = $userent;
155

    
156
            write_config();
157
            $retval = system_password_configure();
158
            sync_webgui_passwords();
159

    
160
            pfSenseHeader("system_usermanager.php");
161
        }
162
    }
163

    
164
    include("head.inc");
165
?>
166

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

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

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

    
414
        /* input validation */
415
        $reqdfields = explode(" ", "passwordfld1");
416
        $reqdfieldsn = explode(",", "Password");
417

    
418
        do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
419

    
420
        if ($_POST['passwordfld1'] != $_POST['passwordfld2'])
421
            $input_errors[] = "The passwords do not match.";
422

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

    
427
            write_config();
428

    
429
            sync_webgui_passwords();
430

    
431
            $retval = system_password_configure();
432
            $savemsg = get_std_save_message($retval);
433
            $savemsg = "Password successfully changed<br />";
434
        }
435
    }
436
?>
437

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

    
477
<?php include("fend.inc");?>
478
</body>
479
</html>
(155-155/186)