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
            if (isset($id) && $a_user[$id])
129
                $userent = $a_user[$id];
130

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
426
            write_config();
427

    
428
            sync_webgui_passwords();
429

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

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

    
476
<?php include("fend.inc");?>
477
</body>
478
</html>
(151-151/181)