system_usermanager.php 43.3 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
    Copyright (C) 2014-2016 Deciso B.V.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    Copyright (C) 2008 Shrew Soft Inc.
    Copyright (C) 2005 Paul Taylor <paultaylor@winn-dixie.com>
    Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>
    All rights reserved.

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

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

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

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

require_once 'guiconfig.inc';
require_once 'base32/Base32.php';
Ad Schellevis's avatar
Ad Schellevis committed
34

35 36 37 38 39 40
function get_user_privdesc(& $user)
{
    global $priv_list;

    $privs = array();

41
    if (!isset($user['priv']) || !is_array($user['priv'])) {
42
        $user_privs = array();
43 44
    } else {
        $user_privs = $user['priv'];
45
    }
46

47
    $names = local_user_get_groups($user, true);
48

49 50
    foreach ($names as $name) {
        $group = getGroupEntry($name);
51 52 53 54 55 56 57 58 59 60 61 62 63
        if (isset($group['priv']) && is_array($group['priv'])) {
          foreach ($group['priv'] as $pname) {
              if (in_array($pname, $user_privs)) {
                  continue;
              }
              if (empty($priv_list[$pname])) {
                  continue;
              }
              $priv = $priv_list[$pname];
              $priv['group'] = $group['name'];
              $priv['id'] = $pname;
              $privs[] = $priv;
          }
64 65 66 67
        }
    }

    foreach ($user_privs as $pname) {
68 69
        if (!empty($priv_list[$pname])) {
            $priv_list[$pname]['id'] = $pname;
70 71 72 73
            $privs[] = $priv_list[$pname];
        }
    }

74
    legacy_html_escape_form_data($privs);
75
    return $privs;
76 77
}

78
// link user section
79 80
if (!isset($config['system']['user']) || !is_array($config['system']['user'])) {
    $config['system']['user'] = array();
Ad Schellevis's avatar
Ad Schellevis committed
81
}
82
$a_user = &$config['system']['user'];
Ad Schellevis's avatar
Ad Schellevis committed
83

84 85 86 87 88 89 90
// reset errors and action
$input_errors = array();
$act = null;
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // process get type actions
    if (isset($_GET['userid']) && isset($a_user[$_GET['userid']])) {
        $id = $_GET['userid'];
91
    }
92 93
    if (isset($_GET['act'])) {
        $act = $_GET['act'];
94
    }
95 96
    if (isset($_GET['savemsg'])) {
        $savemsg = htmlspecialchars($_GET['savemsg']);
97
    }
98 99 100 101 102 103 104 105 106 107 108 109
    if ($act == "expcert" && isset($id)) {
        // export certificate
        $cert =& lookup_cert($a_user[$id]['cert'][$_GET['certid']]);

        $exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.crt");
        $exp_data = base64_decode($cert['crt']);
        $exp_size = strlen($exp_data);

        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment; filename={$exp_name}");
        header("Content-Length: $exp_size");
        echo $exp_data;
110
        exit;
111 112 113 114 115 116 117 118 119 120 121
    } elseif ($act == "expckey" && isset($id)) {
        // export private key
        $cert =& lookup_cert($a_user[$id]['cert'][$_GET['certid']]);
        $exp_name = urlencode("{$a_user[$id]['name']}-{$cert['descr']}.key");
        $exp_data = base64_decode($cert['prv']);
        $exp_size = strlen($exp_data);

        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment; filename={$exp_name}");
        header("Content-Length: $exp_size");
        echo $exp_data;
122
        exit;
123 124
    } elseif ($act == 'new' || $act == 'edit') {
        // edit user, load or init data
125
        $fieldnames = array('user_dn', 'descr', 'expires', 'scope', 'uid', 'priv', 'ipsecpsk', 'lifetime', 'otp_seed');
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        if (isset($id)) {
            if (isset($a_user[$id]['authorizedkeys'])) {
                $pconfig['authorizedkeys'] = base64_decode($a_user[$id]['authorizedkeys']);
            }
            if (isset($a_user[$id]['name'])) {
                $pconfig['usernamefld'] = $a_user[$id]['name'];
            }
            $pconfig['groups'] = local_user_get_groups($a_user[$id]);
            $pconfig['disabled'] = isset($a_user[$id]['disabled']);
            foreach ($fieldnames as $fieldname) {
                if (isset($a_user[$id][$fieldname])) {
                    $pconfig[$fieldname] = $a_user[$id][$fieldname];
                } else {
                    $pconfig[$fieldname] = null;
                }
            }
142
        } else {
143 144 145 146 147 148 149
            // set defaults
            $pconfig['groups'] = null;
            $pconfig['disabled'] = false;
            $pconfig['scope'] = "user";
            $pconfig['lifetime'] = 365;
            $pconfig['usernamefld'] = null;
            foreach ($fieldnames as $fieldname) {
150
                if (!isset($pconfig[$fieldname])) {
151 152 153
                    $pconfig[$fieldname] = null;
                }
            }
154 155
        }
    }
156 157 158 159
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // process post type requests
    if (isset($_POST['userid']) && isset($a_user[$_POST['userid']])) {
        $id = $_POST['userid'];
160
    }
161 162
    if (isset($_POST['act'])) {
        $act = $_POST['act'];
163
    }
164
    $pconfig = $_POST;
165

166 167
    if ($act == "deluser" && isset($id)) {
        // drop user
168 169 170 171 172 173 174
        if ($_SESSION['Username'] === $a_user[$id]['name']) {
            $input_errors[] = gettext('You cannot delete yourself.');
        } else {
            local_user_del($a_user[$id]);
            $userdeleted = $a_user[$id]['name'];
            unset($a_user[$id]);
            write_config();
175
            $savemsg = sprintf(gettext('The user "%s" was successfully removed.'), $userdeleted);
176
            header(url_safe('Location: /system_usermanager.php?savemsg=%s', array($savemsg)));
177 178
            exit;
        }
179 180 181 182 183 184
    } elseif ($act == "delcert" && isset($id)) {
        // remove certificate association
        $certdeleted = lookup_cert($a_user[$id]['cert'][$pconfig['certid']]);
        $certdeleted = $certdeleted['descr'];
        unset($a_user[$id]['cert'][$pconfig['certid']]);
        write_config();
185
        $savemsg = sprintf(gettext('The certificate association "%s" was successfully removed.'), $certdeleted);
186
        header(url_safe('Location: /system_usermanager.php?savemsg=%s&act=edit&userid=%s', array($savemsg, $id)));
187
        exit;
188 189 190 191 192 193
    } elseif ($act == "newApiKey" && isset($id)) {
        // every action is using the sequence of the user, to keep it understandable, we will use
        // the same strategy here (although we need a username to work with)
        //
        // the client side is (jquery) generates the actual download file.
        $username = $a_user[$id]['name'];
194
        $authFactory = new \OPNsense\Auth\AuthenticationFactory();
195 196 197 198 199 200 201 202 203
        $authenticator = $authFactory->get("Local API");
        $keyData = $authenticator->createKey($username);
        if ($keyData != null) {
            echo json_encode($keyData);
        }
        exit;
    } elseif ($act =='delApiKey'  && isset($id)) {
        $username = $a_user[$id]['name'];
        if (!empty($pconfig['api_delete'])) {
204
            $authFactory = new \OPNsense\Auth\AuthenticationFactory();
205 206
            $authenticator = $authFactory->get("Local API");
            $authenticator->dropKey($username, $pconfig['api_delete']);
207
            $savemsg = sprintf(gettext('The API key "%s" was successfully removed.'), $pconfig['api_delete']);
208 209 210 211
        } else {
            $savemsg = gettext('No API key found');
        }
        // redirect
212
        header(url_safe('Location: /system_usermanager.php?savemsg=%s&act=edit&userid=%s', array($savemsg, $id)));
213
        exit;
214 215 216 217 218 219 220
    } elseif (isset($pconfig['save'])) {
        // save user
        /* input validation */
        if (isset($id)) {
            $reqdfields = explode(" ", "usernamefld");
            $reqdfieldsn = array(gettext("Username"));
        } else {
221
            $reqdfields = explode(" ", "usernamefld passwordfld1");
222
            $reqdfieldsn = array(gettext("Username"), gettext("Password"));
223 224
        }

225
        do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
226

227 228
        if (preg_match("/[^a-zA-Z0-9\.\-_]/", $pconfig['usernamefld'])) {
            $input_errors[] = gettext("The username contains invalid characters.");
229 230
        }

231 232 233
        if (strlen($_POST['usernamefld']) > 16) {
            $input_errors[] = gettext("The username is longer than 16 characters.");
        }
234

235 236 237
        if (($pconfig['passwordfld1']) && ($pconfig['passwordfld1'] != $pconfig['passwordfld2'])) {
            $input_errors[] = gettext("The passwords do not match.");
        }
238

239 240 241 242
        if (!empty($pconfig['disabled']) && $_SESSION['Username'] === $a_user[$id]['name']) {
            $input_errors[] = gettext('You cannot disable yourself.');
        }

243 244 245 246 247 248 249 250 251 252 253 254
        if (isset($id)) {
            $oldusername = $a_user[$id]['name'];
        } else {
            $oldusername = "";
        }
        /* make sure this user name is unique */
        if (count($input_errors) == 0) {
            foreach ($a_user as $userent) {
                if ($userent['name'] == $pconfig['usernamefld'] && $oldusername != $pconfig['usernamefld']) {
                    $input_errors[] = gettext("Another entry with the same username already exists.");
                    break;
                }
255 256
            }
        }
257 258 259 260 261 262 263 264 265 266
        /* also make sure it is not reserved */
        if (count($input_errors) == 0) {
            $system_users = explode("\n", file_get_contents("/etc/passwd"));
            foreach ($system_users as $s_user) {
                $ent = explode(":", $s_user);
                if ($ent[0] == $pconfig['usernamefld'] && $oldusername != $pconfig['usernamefld']) {
                    $input_errors[] = gettext("That username is reserved by the system.");
                    break;
                }
            }
267 268
        }

269
       /*
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
       * Check for a valid expirationdate if one is set at all (valid means,
       * DateTime puts out a time stamp so any DateTime compatible time
       * format may be used. to keep it simple for the enduser, we only
       * claim to accept MM/DD/YYYY as inputs. Advanced users may use inputs
       * like "+1 day", which will be converted to MM/DD/YYYY based on "now".
       * Otherwhise such an entry would lead to an invalid expiration data.
       */
        if (!empty($pconfig['expires'])) {
            try {
                $expdate = new DateTime($pconfig['expires']);
                //convert from any DateTime compatible date to MM/DD/YYYY
                $pconfig['expires'] = $expdate->format("m/d/Y");
            } catch (Exception $ex) {
                $input_errors[] = gettext("Invalid expiration date format; use MM/DD/YYYY instead.");
            }
        }
286

287 288 289 290 291
        if (!empty($pconfig['name'])) {
            $ca = lookup_ca($pconfig['caref']);
            if (!$ca) {
                $input_errors[] = gettext("Invalid internal Certificate Authority") . "\n";
            }
292 293
        }

294 295 296 297 298 299 300 301 302 303
        if (count($input_errors)==0) {
            $userent = array();

            if (isset($id)) {
                $userent = $a_user[$id];
                /* the user name was modified */
                if ($pconfig['usernamefld'] != $pconfig['oldusername']) {
                    local_user_del($userent);
                }
            }
304

305 306 307 308
            /* the user password was modified */
            if (!empty($pconfig['passwordfld1'])) {
                local_user_set_password($userent, $pconfig['passwordfld1']);
            }
309

310
            isset($pconfig['scope']) ? $userent['scope'] = $pconfig['scope'] : $userent['scope'] = "system";
311

312 313 314 315 316
            $userent['name'] = $pconfig['usernamefld'];
            $userent['descr'] = $pconfig['descr'];
            $userent['expires'] = $pconfig['expires'];
            $userent['authorizedkeys'] = base64_encode($pconfig['authorizedkeys']);
            $userent['ipsecpsk'] = $pconfig['ipsecpsk'];
317 318 319 320 321 322
            if (!empty($pconfig['gen_otp_seed'])) {
                // generate 160bit base32 encoded secret
                $userent['otp_seed'] = Base32\Base32::encode(openssl_random_pseudo_bytes(20));
            } else {
                $userent['otp_seed'] = trim($pconfig['otp_seed']);
            }
323

324 325 326 327 328
            if (!empty($pconfig['disabled'])) {
                $userent['disabled'] = true;
            } elseif (isset($userent['disabled'])) {
                unset($userent['disabled']);
            }
329

330 331 332 333 334 335 336 337 338 339 340 341
            if (isset($id)) {
                $a_user[$id] = $userent;
            } else {
                $userent['uid'] = $config['system']['nextuid']++;
                /* Add the user to All Users group. */
                foreach ($config['system']['group'] as $gidx => $group) {
                    if ($group['name'] == "all") {
                        if (!is_array($config['system']['group'][$gidx]['member'])) {
                            $config['system']['group'][$gidx]['member'] = array();
                        }
                        $config['system']['group'][$gidx]['member'][] = $userent['uid'];
                        break;
342 343
                    }
                }
344 345

                $a_user[] = $userent;
346 347
            }

348 349 350
            local_user_set($userent);
            local_user_set_groups($userent, $pconfig['groups']);
            write_config();
351

352 353
            if (!empty($pconfig['chkNewCert'])) {
                // redirect to cert manager when a new cert is requested for this user
354
                header(url_safe('Location: /system_certmanager.php?act=new&userid=%s', array(count($a_user) - 1)));
355
            } else {
356
                header(url_safe('Location: /system_usermanager.php'));
357 358
                exit;
            }
359 360
        }
    } elseif (isset($id)) {
361
        header(url_safe('Location: /system_usermanager.php?userid=%s', array($id)));
362 363
        exit;
    } else {
364
        header(url_safe('Location: /system_usermanager.php'));
365
        exit;
366
    }
Ad Schellevis's avatar
Ad Schellevis committed
367 368
}

369 370
legacy_html_escape_form_data($pconfig);
legacy_html_escape_form_data($a_user);
371

Ad Schellevis's avatar
Ad Schellevis committed
372
include("head.inc");
373

Ad Schellevis's avatar
Ad Schellevis committed
374
?>
375 376
<script type="text/javascript" src="/ui/js/jquery.qrcode.js"></script>
<script type="text/javascript" src="/ui/js/qrcode.js"></script>
Ad Schellevis's avatar
Ad Schellevis committed
377

378
<body>
Ad Schellevis's avatar
Ad Schellevis committed
379 380 381

<?php include("fbegin.inc"); ?>

382 383 384 385 386 387 388
<script type="text/javascript">
$( document ).ready(function() {
    // remove certificate association
    $(".act-del-cert").click(function(event){
      var certid = $(this).data('certid');
      event.preventDefault();
      BootstrapDialog.show({
Fabian Franz's avatar
Fabian Franz committed
389
          type:BootstrapDialog.TYPE_DANGER,
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
          title: "<?= gettext("Certificate");?>",
          message: '<?=gettext("Do you really want to remove this certificate association?") .'\n'. gettext("(Certificate will not be deleted)");?>',
          buttons: [{
                  label: "<?= gettext("No");?>",
                  action: function(dialogRef) {
                    dialogRef.close();
                  }}, {
                    label: "<?= gettext("Yes");?>",
                    action: function(dialogRef) {
                      $("#certid").val(certid);
                      $("#act").val("delcert");
                      $("#iform").submit();
                  }
          }]
      });
    });

    // remove user
    $(".act-del-user").click(function(event){
      var userid = $(this).data('userid');
410
      var username = $(this).data('username');
411 412
      event.preventDefault();
      BootstrapDialog.show({
Fabian Franz's avatar
Fabian Franz committed
413
          type:BootstrapDialog.TYPE_DANGER,
414
          title: "<?= gettext("User");?>",
415
          message: '<?=html_safe(gettext("Do you really want to delete this user?"));?>' + '<br/>('+username+")",
416 417 418 419 420 421 422
          buttons: [{
                  label: "<?= gettext("No");?>",
                  action: function(dialogRef) {
                    dialogRef.close();
                  }}, {
                    label: "<?= gettext("Yes");?>",
                    action: function(dialogRef) {
423
                      $("#userid").val(userid);
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
                      $("#act2").val("deluser");
                      $("#iform2").submit();
                  }
          }]
      });
    });

    // expand ssh key section on click
    $("#authorizedkeys").click(function(){
        $(this).attr('rows', '7');
    });

    // import ldap users
    $("#import_ldap_users").click(function(){
      url="system_usermanager_import_ldap.php";
      var oWin = window.open(url,"OPNsense","width=620,height=400,top=150,left=150,scrollbars=yes");
      if (oWin==null || typeof(oWin)=="undefined") {
Fabian Franz's avatar
Fabian Franz committed
441
        alert("<?=gettext('Popup blocker detected. Action aborted.');?>");
442 443 444
      }
    });

445 446 447 448 449 450 451 452 453 454 455

    // generate a new API key for this user
    $("#newApiKey").click(function(event){
        event.preventDefault();
        $.post(window.location, {act: 'newApiKey', userid: $("#userid").val() }, function(data) {
            if (data['key'] != undefined) {
                // only generate a key file if there's data
                output_data = 'key='+data['key'] +'\n' + 'secret='+data['secret'] +'\n';
                // create link, click and send to client
                $('<a></a>')
                        .attr('id','downloadFile')
Fabian Franz's avatar
Fabian Franz committed
456 457
                        .attr('href','data:text/plain;charset=utf8,' + encodeURIComponent(output_data))
                        .attr('download','apikey.txt')
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
                        .appendTo('body');

                $('#downloadFile').ready(function() {
                    $('#downloadFile').get(0).click();
                });
                // reload form
                location.reload();
            }
        },'json');
    });

    // delete API key
    $(".act-del-api-key").click(function(event){
        event.preventDefault();
        var apiKey = $(this).data('key');
        BootstrapDialog.show({
Fabian Franz's avatar
Fabian Franz committed
474
            type:BootstrapDialog.TYPE_DANGER,
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
            title: "<?= gettext("User");?>",
            message: '<?=gettext("Do you really want to delete this API key?");?>' + '<br/><small>('+apiKey.substring(0,40)+"...)</small>",
            buttons: [{
                    label: "<?= gettext("No");?>",
                    action: function(dialogRef) {
                      dialogRef.close();
                    }}, {
                      label: "<?= gettext("Yes");?>",
                      action: function(dialogRef) {
                        $("#act").val("delApiKey");
                        $("#api_delete").val(apiKey);
                        $("#iform").submit();
                    }
            }]
        });
    });

492
    $('.datepicker').datepicker();
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507

    $("#add_groups").click(function(){
        $("#groups").append($("#notgroups option:selected"));
        $("#notgroups option:selected").remove();
        $("#groups option:selected").prop('selected', false);
    });
    $("#remove_groups").click(function(){
        $("#notgroups").append($("#groups option:selected"));
        $("#groups option:selected").remove();
        $("#notgroups option:selected").prop('selected', false);
    });
    $("#save").click(function(){
        $("#groups > option").prop('selected', true);
        $("#notgroups > option").prop('selected', false);
    });
508 509
});
</script>
Ad Schellevis's avatar
Ad Schellevis committed
510 511


512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
  <section class="page-content-main">
    <div class="container-fluid">
      <div class="row">
<?php
      if (isset($input_errors) && count($input_errors) > 0) {
          print_input_errors($input_errors);
      }
      if (isset($savemsg)) {
          print_info_box($savemsg);
      }
?>
        <section class="col-xs-12">
            <div class="tab-content content-box col-xs-12 table-responsive">
<?php
            if ($act == "new" || $act == "edit" ) :?>
527
              <form method="post" name="iform" id="iform">
528 529 530
                <input type="hidden" id="act" name="act" value="<?=$act;?>" />
                <input type="hidden" id="userid" name="userid" value="<?=(isset($id) ? $id : '');?>" />
                <input type="hidden" id="priv_delete" name="priv_delete" value="" /> <!-- delete priv action -->
531
                <input type="hidden" id="api_delete" name="api_delete" value="" /> <!-- delete api ke action -->
532
                <input type="hidden" id="certid" name="certid" value="" /> <!-- remove cert association action -->
533
                <table class="table table-striped opnsense_standard_table_form">
534 535 536 537
                  <tr>
                    <td width="22%"></td>
                    <td width="78%" align="right">
                      <small><?=gettext("full help"); ?> </small>
Ad Schellevis's avatar
Ad Schellevis committed
538
                      <i class="fa fa-toggle-off text-danger"  style="cursor: pointer;" id="show_all_help_page" type="button"></i>
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
                    </td>
                  </tr>
                  <tr>
                    <td><?=gettext("Defined by");?></td>
                    <td>
                      <strong><?=strtoupper($pconfig['scope']);?></strong>
                      <input name="scope" type="hidden" value="<?=$pconfig['scope']?>" />
                    </td>
                  </tr>
                  <tr>
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Disabled");?></td>
                    <td>
                      <input name="disabled" type="checkbox" id="disabled" <?= $pconfig['disabled'] ? "checked=\"checked\"" : "" ?> />
                    </td>
                  </tr>
                  <tr>
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Username");?></td>
                    <td>
                      <input name="usernamefld" type="text" class="formfld user" id="usernamefld" size="20" maxlength="16" value="<?=$pconfig['usernamefld'];?>" <?= $pconfig['scope'] == "system" || !empty($pconfig['user_dn']) ? "readonly=\"readonly\"" : "";?> />
                      <input name="oldusername" type="hidden" id="oldusername" value="<?=$pconfig['usernamefld'];?>" />
                    </td>
                  </tr>
<?php
                  if (!empty($pconfig['user_dn'])):?>
                  <tr>
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("User distinguished name");?></td>
                    <td>
                      <input name="user_dn" type="text" class="formfld user" id="user_dn" size="20" maxlength="16" value="<?=$pconfig['user_dn'];?>"/ readonly>
                    </td>
                  </tr>
<?php
                  else:?>
                  <tr>
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Password");?></td>
                    <td>
                      <input name="passwordfld1" type="password" class="formfld pwd" id="passwordfld1" size="20" value="" /><br/>
                      <input name="passwordfld2" type="password" class="formfld pwd" id="passwordfld2" size="20" value="" />&nbsp;
                      <small><?= gettext("(confirmation)"); ?></small>
                    </td>
                  </tr>
<?php
                  endif;?>
                  <tr>
                    <td><a id="help_for_fullname" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Full name");?></td>
                    <td>
                      <input name="descr" type="text" value="<?=$pconfig['descr'];?>" <?= $pconfig['scope'] == "system" || !empty($pconfig['user_dn']) ? "readonly=\"readonly\"" : "";?> />
                      <div class="hidden" for="help_for_fullname">
                        <?=gettext("User's full name, for your own information only");?>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td><a id="help_for_expires" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Expiration date"); ?></td>
                    <td>
593
                      <input name="expires" type="text" id="expires" class="datepicker" data-date-format="mm/dd/yyyy" value="<?=$pconfig['expires'];?>" />
594 595 596
                      <div class="hidden" for="help_for_expires">
                          <?=gettext("Leave blank if the account shouldn't expire, otherwise enter the expiration date in the following format: mm/dd/yyyy"); ?>
                      </div>
597
                    </td>
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
                  </tr>
                  <tr>
                    <td><a id="help_for_groups" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Group Memberships");?></td>
                    <td>
                      <table class="table" width="100%" border="0" cellpadding="0" cellspacing="0">
                        <thead>
                          <tr>
                            <th><?=gettext("Not Member Of"); ?></th>
                            <th>&nbsp;</th>
                            <th><?=gettext("Member Of"); ?></th>
                          </tr>
                        </thead>
                        <tbody>
                          <tr>
                            <td>
                              <select size="10" name="notgroups[]" id="notgroups" onchange="clear_selected('groups')" multiple="multiple">
<?php
                              foreach ($config['system']['group'] as $group) :
                                if (!empty($pconfig['groups']) && in_array($group['name'], $pconfig['groups'])) {
                                  continue;
                                }
?>
                                <option value="<?=$group['name'];?>">
                                    <?=htmlspecialchars($group['name']);?>
                                </option>
<?php
                              endforeach;?>
                              </select>
626
                            </td>
627 628
                            <td class="text-center">
                              <br />
629
                              <a id="add_groups" class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("Add groups"); ?>">
630 631 632
                                  <span class="glyphicon glyphicon-arrow-right"></span>
                              </a>
                              <br /><br />
633
                              <a id="remove_groups" class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("Remove groups"); ?>">
634 635
                                  <span class="glyphicon glyphicon-arrow-left"></span>
                              </a>
636
                            </td>
637 638 639 640 641 642 643 644
                            <td>
                              <select size="10" name="groups[]" id="groups" onchange="clear_selected('notgroups')" multiple="multiple">
<?php
                              if (!empty($pconfig['groups'])) :
                                foreach ($config['system']['group'] as $group) :
                                  if (!in_array($group['name'], $pconfig['groups'])) {
                                    continue;
                                  }
645
?>
646 647 648 649 650 651
                                <option value="<?=$group['name'];?>">
                                    <?=htmlspecialchars($group['name']);?>
                                </option>
<?php
                                endforeach;
                            endif;
652
?>
653 654
                            </select>
                          </td>
655
                        </tr>
656 657 658 659 660 661 662
                      </table>
                      <div class="hidden" for="help_for_groups">
                          <?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?>
                      </div>
                    </td>
                  </tr>
<?php
663
                  if ($pconfig['uid'] != "") :?>
664
                  <tr>
665 666 667
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Effective Privileges");?></td>
                    <td>
                      <table class="table table-hover table-condensed">
668
                        <tr>
669 670 671
                          <td><b><?=gettext("Inherited From");?></b></td>
                          <td><b><?=gettext("Name");?></b></td>
                          <td><b><?=gettext("Description");?></b></td>
672
                        </tr>
673 674
<?php
                        foreach (get_user_privdesc($a_user[$id]) as $priv) :?>
675
                        <tr>
676 677 678
                            <td><?=!empty($priv['group']) ? $priv['group'] : ""?></td>
                            <td><?=$priv['name']?></td>
                            <td><?=!empty($priv['descr']) ? $priv['descr'] : ""?></td>
679
                        </tr>
680 681
<?php
                        endforeach;?>
682
                        <tr>
683 684 685 686 687
                          <td colspan="3">
                              <a href="system_usermanager_addprivs.php?userid=<?=$id?>" class="btn btn-xs btn-default"
                                  title="<?=gettext("edit privileges");?>" data-toggle="tooltip">
                                <span class="fa fa-pencil"></span>
                              </a>
688
                          </td>
689
                        </tr>
690 691 692 693 694 695 696
                      </table>
                    </td>
                  </tr>
                  <tr>
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("User Certificates");?></td>
                    <td>
                      <table class="table table-condensed">
697
                        <tr>
698 699 700
                          <td><?=gettext("Name");?></td>
                          <td><?=gettext("CA");?></td>
                          <td></td>
701
                        </tr>
702 703 704 705 706 707 708
<?php
                        if (isset($a_user[$id]['cert']) && is_array($a_user[$id]['cert'])) :
                          $i = 0;
                          foreach ($a_user[$id]['cert'] as $certref) :
                            $cert = lookup_cert($certref);
                            $ca = lookup_ca($cert['caref']);
?>
709
                        <tr>
710 711 712 713 714 715 716
                          <td><?=htmlspecialchars($cert['descr']);?>
                              <?=is_cert_revoked($cert) ? "(<b>".gettext('Revoked')."</b>)" : "";?>
                          </td>
                          <td>
                            <?=htmlspecialchars($ca['descr']);?>
                          </td>
                          <td>
717
                            <a href="system_usermanager.php?act=expckey&amp;certid=<?=$i?>&amp;userid=<?=$id?>"
718 719
                                class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("export private key");?>">
                              <span class="glyphicon glyphicon-arrow-down"></span>
720
                            </a>
721
                            <a href="system_usermanager.php?act=expcert&amp;certid=<?=$i?>&amp;userid=<?=$id?>"
722 723
                                class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("export certificate");?>">
                              <span class="glyphicon glyphicon-arrow-down"></span>
724 725
                            </a>
                            <button type="submit" data-certid="<?=$i;?>" class="btn btn-default btn-xs act-del-cert"
726 727
                                title="<?=gettext("unlink certificate");?>" data-toggle="tooltip">
                              <span class="fa fa-trash text-muted"></span>
728 729
                            </button>
                          </td>
730
                        </tr>
731 732 733 734
<?php
                        $i++;
                            endforeach;
                        endif;?>
735
                        <tr>
736
                          <td colspan="3">
737
                            <a href="system_certmanager.php?act=new&amp;userid=<?=$id?>" class="btn btn-default btn-xs"
738
                                title="<?=gettext("create or link user certificate");?>" data-toggle="tooltip">
739 740 741
                              <span class="glyphicon glyphicon-plus"></span>
                            </a>
                          </td>
742
                        </tr>
743 744 745
                      </table>
                    </td>
                  </tr>
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
                  <tr>
                      <td><a id="help_for_apikeys" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("API keys");?> </td>
                      <td>
                          <!-- -->
                          <table class="table table-condensed">
                              <thead>
                                  <tr>
                                    <th>
                                        <?=gettext('key');?>
                                    </th>
                                    <th>
                                    </th>
                                  </tr>
                              </thead>
                              <tbody>
<?php
                                  if (isset($a_user[$id]['apikeys']['item'])):
                                    foreach ($a_user[$id]['apikeys']['item'] as $userApiKey):?>
                                  <tr>
                                      <td>
                                        <small>
                                          <?php // listtags always changes our key item to an array.. ?>
                                          <?php // don't want to change "key" to something less sane. ?>
                                          <?=$userApiKey['key'][0];?>
770
                                        </small>
771 772 773
                                      </td>
                                      <td>
                                        <button data-key="<?=$userApiKey['key'][0];?>" type="button" class="btn btn-default btn-xs act-del-api-key"
774 775
                                            title="<?=gettext("delete API key");?>" data-toggle="tooltip">
                                          <span class="glyphicon glyphicon-trash"></span>
776 777 778 779 780 781 782 783 784
                                        </button>
                                      </td>
                                  </tr>
<?php
                                    endforeach;
                                  endif;?>
                              </tbody>
                              <tfoot>
                                  <tr>
785
                                    <td colspan="2">
786
                                      <button type="button" class="btn btn-default btn-xs" id="newApiKey"
787
                                          title="<?=gettext('Create API key');?>" data-toggle="tooltip">
788
                                        <span class="glyphicon glyphicon-plus"></span>
789 790 791 792 793 794
                                      </button>
                                    </td>
                                  </tr>
                              </tfoot>
                          </table>
                          <div class="hidden" for="help_for_apikeys">
795
                              <hr/>
796
                              <?=gettext('Manage API keys here for machine to machine interaction using this user\'s credentials.');?>
797 798 799
                          </div>
                      </td>
                  </tr>
800
<?php
801
                else :?>
802 803 804
                  <tr id="usercertchck">
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Certificate");?></td>
                    <td>
805
                      <input type="checkbox" id="chkNewCert" name="chkNewCert" /> <?=gettext("Click to create a user certificate."); ?> (<?=gettext("Redirects on save"); ?>)
806 807
                    </td>
                  </tr>
Ad Schellevis's avatar
Ad Schellevis committed
808
<?php
809
                endif;?>
810 811 812 813 814 815 816 817 818 819
                  <tr>
                    <td><a id="help_for_otp_seed" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a>  <?=gettext("OTP seed");?></td>
                    <td>
                      <input name="otp_seed" type="text" value="<?=$pconfig['otp_seed'];?>"/>
                      <input type="checkbox" name="gen_otp_seed"/>&nbsp;<small><?=gettext("generate new (160bit) secret");?></small>
                      <div class="hidden" for="help_for_otp_seed">
                        <?=gettext("OTP (base32) seed to use when a one time password authenticator is used");?><br/>
<?php
                        if (!empty($pconfig['otp_seed'])):
                            // construct google url, using token, username and this machines hostname
820 821 822
                            $otp_url = "otpauth://totp/";
                            $otp_url .= $pconfig['usernamefld']."@".htmlspecialchars($config['system']['hostname'])."?secret=";
                            $otp_url .= $pconfig['otp_seed'];
823 824
                        ?>
                            <br/>
825 826 827 828 829
                            <?=gettext("When using google authenticator, scan the following qrcode for easy setup:");?><br/>
                            <div id="otp_qrcode"></div>
                            <script type="text/javascript">
                                $('#otp_qrcode').qrcode('<?= $otp_url ?>');
                            </script>
830 831 832 833 834
<?php
                        endif;?>
                      </div>
                    </td>
                  </tr>
835 836 837 838 839 840 841
                  <tr>
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Authorized keys");?></td>
                    <td>
                      <textarea name="authorizedkeys" id="authorizedkeys" class="form-control" cols="65" rows="1" placeholder="<?=gettext("Paste an authorized keys file here.");?>" wrap='off'><?=$pconfig['authorizedkeys'];?></textarea>
                    </td>
                  </tr>
                  <tr id="ipsecpskrow">
842
                    <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("IPsec Pre-Shared Key");?></td>
843 844 845 846 847 848 849
                    <td>
                      <input name="ipsecpsk" type="text" size="65" value="<?=$pconfig['ipsecpsk'];?>" />
                    </td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>
850
                      <input name="save" id="save" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
851 852
                      <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>"
                             onclick="window.location.href='<?=isset($_SERVER['HTTP_REFERER']) ?  $_SERVER['HTTP_REFERER'] : '/system_usermanager.php';?>'" />
Ad Schellevis's avatar
Ad Schellevis committed
853
<?php
854 855
                      if (isset($id) && !empty($a_user[$id])) :?>
                      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
Ad Schellevis's avatar
Ad Schellevis committed
856
<?php
857
                      endif;?>
858
                    </td>
859 860 861
                  </tr>
                </table>
              </form>
Ad Schellevis's avatar
Ad Schellevis committed
862
<?php
863
              else :?>
864
              <form method="post" name="iform2" id="iform2">
865 866 867 868 869 870 871 872 873 874 875 876 877
                <input type="hidden" id="act2" name="act" value="" />
                <input type="hidden" id="userid" name="userid" value="<?=(isset($id) ? $id : '');?>" />
                <input type="hidden" id="username" name="username" value="" />
                <table class="table table-striped">
                  <thead>
                    <tr>
                      <th><?=gettext("Username"); ?></th>
                      <th><?=gettext("Full name"); ?></th>
                      <th><?=gettext("Groups"); ?></th>
                      <th></th>
                    </tr>
                  </thead>
                  <tbody>
Ad Schellevis's avatar
Ad Schellevis committed
878
<?php
879 880 881 882
                  $i = 0;
                  foreach ($a_user as $userent) :?>
                    <tr>
                      <td>
Ad Schellevis's avatar
Ad Schellevis committed
883
<?php
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
                        if ($userent['scope'] != "user") {
                            $usrimg = "glyphicon glyphicon-user text-danger";
                        } elseif (isset($userent['disabled'])) {
                                $usrimg = "glyphicon glyphicon-user text-muted";
                        } else {
                                $usrimg = "glyphicon glyphicon-user text-info";
                        }?>
                        <span class="<?=$usrimg;?>"></span> <?=$userent['name'];?>
                      </td>
                      <td><?=$userent['descr'];?></td>
                      <td>
                        <?=implode(",", local_user_get_groups($userent));?>
                      </td>
                      <td>
                        <a href="system_usermanager.php?act=edit&userid=<?=$i?>"
899 900
                            class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("edit user");?>">
                          <span class="glyphicon glyphicon-pencil"></span>
901
                        </a>
Ad Schellevis's avatar
Ad Schellevis committed
902
<?php
903 904
                        if ($userent['scope'] != "system") :?>
                        <button type="button" class="btn btn-default btn-xs act-del-user"
905
                            data-username="<?=$userent['name'];?>"
906 907
                            data-userid="<?=$i?>" title="<?=gettext("delete user");?>" data-toggle="tooltip">
                          <span class="fa fa-trash text-muted"></span>
908 909 910 911 912 913 914 915
                        </button>
<?php
                        endif;?>
                      </td>
                    </tr>
<?php
                  $i++;
                  endforeach;
Ad Schellevis's avatar
Ad Schellevis committed
916
?>
917
                    <tr>
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
                      <td colspan="3">
                        <table>
                          <tr>
                            <td></td>
                            <td width="20px"></td>
                            <td width="20px"><span class="glyphicon glyphicon-user text-danger"></span></td>
                            <td width="200px"><?= gettext('System Administrator') ?></td>
                            <td width="20px"><span class="glyphicon glyphicon-user text-muted"></span></td>
                            <td width="200px"><?= gettext('Disabled User') ?></td>
                            <td width="20px"><span class="glyphicon glyphicon-user text-info"></span></td>
                            <td width="200px"><?= gettext('Normal User') ?></td>
                            <td></td>
                          </tr>
                        </table>
                      </td>
933 934
                      <td>
                        <a href="system_usermanager.php?act=new" class="btn btn-default btn-xs"
935
                           title="<?=gettext("add user");?>" data-toggle="tooltip">
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
                          <span class="glyphicon glyphicon-plus"></span>
                        </a>
<?php
                        $authcfg_type = auth_get_authserver($config['system']['webgui']['authmode'])['type'];
                        if ($authcfg_type == 'ldap') :?>
                          <button type="submit" name="import"
                                  id="import_ldap_users"
                                  class="btn btn-default btn-xs"
                                  title="<?=gettext("import users")?>">
                              <i class="fa fa-cloud-download"></i>
                          </button>
<?php
                      endif;?>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="4">
                          <?=gettext("Additional users can be added here. User permissions for accessing " .
                                        "the webConfigurator can be assigned directly or inherited from group memberships. " .
                                        "An icon that appears grey indicates that it is a system defined object. " .
                                        "Some system object properties can be modified but they cannot be deleted."); ?>
                      </td>
                    </tr>
959
                  </tbody>
960 961 962 963 964 965 966 967 968
                </table>
              </form>
<?php
              endif;?>
            </div>
          </section>
        </div>
      </div>
    </section>
Ad Schellevis's avatar
Ad Schellevis committed
969

970
<?php include("foot.inc");