Files
librenms-librenms/html/pages/adduser.inc.php
mcq8 c9728a1f71 refactor: Refactored authorizers to classes (#7497)
* Refactored authorizers to classes

* Merge changes for #7335

* ! fix php 5.3 incompatibility

* Update ADAuthorizationAuthorizer.php

* Fix get_user -> getUser

* Rename AuthorizerFactory to Auth, fix interface missing functions

* Add phpdocs to all interface methods and normalize the names a bit.

* Re-work auth_test.php AD bind tests to work properly with the new class.
Reflection is not the nicest tool, but I think it is appropriate here.
Handle exceptions more nicely in auth_test.php

* Restore AD getUseList fix

Not sure how it got removed

* fix auth_test.php style
2017-11-18 10:33:03 +00:00

113 lines
3.7 KiB
PHP

<?php
use LibreNMS\Authentication\Auth;
$no_refresh = true;
if ($_SESSION['userlevel'] < '10') {
include 'includes/error-no-perm.inc.php';
} elseif ($_SESSION['userlevel'] == 11) {
demo_account();
} else {
echo '<h3>Add User</h3>';
echo '<hr>';
$pagetitle[] = 'Add user';
if (Auth::get()->canManageUsers()) {
if ($_POST['action'] == 'add') {
if ($_POST['new_username']) {
if (!Auth::get()->userExists($_POST['new_username'])) {
if (isset($_POST['can_modify_passwd'])) {
$_POST['can_modify_passwd'] = 1;
} else {
$_POST['can_modify_passwd'] = 0;
}
// FIXME: missing email field here on the form
if (Auth::get()->addUser($_POST['new_username'], $_POST['new_password'], $_POST['new_level'], $_POST['new_email'], $_POST['new_realname'], $_POST['can_modify_passwd'])) {
echo '<span class=info>User '.$_POST['username'].' added!</span>';
}
} else {
echo '<div class="red">User with this name already exists!</div>';
}
} else {
echo '<div class="red">Please enter a username!</div>';
}//end if
}//end if
echo "<form method='post' action='adduser/' class='form-horizontal' role='form'> <input type='hidden' value='add' name='action'>";
echo "
<div class='form-group'>
<label for='new_username' class='col-sm-2 control-label'>Username</label>
<div class='col-sm-4'>
<input name='new_username' class='form-control input-sm'>
</div>
<div class='col-sm-6'>
</div>
</div>";
?>
<div class='form-group'>
<label for='new_password' class='col-sm-2 control-label'>Password</label>
<div class='col-sm-4'>
<input name='new_password' id='new_password' type=password class='form-control input-sm'>
</div>
<div class='col-sm-6'>
</div>
</div>
<?php
if ($_POST['action'] == 'add' && !$_POST['new_password']) {
echo '<span class=red>Please enter a password!</span><br />';
}
echo "
<div class='form-group'>";
echo "<label for='new_realname' class='col-sm-2 control-label'>Realname</label>
<div class='col-sm-4'>
<input name='new_realname' class='form-control input-sm'>
</div>
<div class='col-sm-6'>
</div>
</div>
<div class='form-group'>
<label for='new_email' class='col-sm-2 control-label'>Email</label>
<div class='col-sm-4'>
<input name='new_email' class='form-control input-sm'>
</div>
<div class='col-sm-6'>
</div>
</div>
<div class='form-group'>
<label for='new_level' class='col-sm-2 control-label'>Level</label>
<div class='col-sm-4'>
<select name='new_level' class='form-control input-sm'>
<option value='1'>Normal User</option>
<option value='5'>Global Read</option>
<option value='10'>Administrator</option>
<option value='11'>Demo account</option>
</select>
<div class='checkbox'>
<label>
<input type='checkbox' checked='checked' name='can_modify_passwd'> Allow the user to change their password.
</label>
</div>
<hr>
<center><button type='submit' class='btn btn-default'>Add User</button></center>
</div>
<div class='col-sm-6'>
</div>
</div>";
echo "<div class='form-group'>
<div class='col-sm-6'>
</div>
<div class='col-sm-6'>
</div>
</div>";
echo '</form>';
} else {
echo '<span class="red">Auth module does not allow user management!</span><br />';
}//end if
}//end if