2009-09-07 11:07:59 +00:00
< ? php
2008-03-09 22:49:53 +00:00
2018-10-29 21:41:50 +01:00
use App\Models\User ;
2018-09-11 07:51:35 -05:00
use LibreNMS\Authentication\LegacyAuth ;
2017-11-18 11:33:03 +01:00
2015-07-13 20:10:26 +02:00
$no_refresh = true ;
2015-03-21 21:30:55 +00:00
2015-07-13 20:10:26 +02:00
require 'includes/javascript-interfacepicker.inc.php' ;
2010-06-21 04:18:06 +00:00
2015-07-13 20:10:26 +02:00
echo " <div style='margin: 10px;'> " ;
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
$pagetitle [] = 'Edit user' ;
2011-10-18 14:41:19 +00:00
2018-10-29 21:41:50 +01:00
if ( ! Auth :: user () -> hasGlobalAdmin ()) {
2015-07-13 20:10:26 +02:00
include 'includes/error-no-perm.inc.php' ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
if ( $vars [ 'user_id' ] && ! $vars [ 'edit' ]) {
2018-10-29 21:41:50 +01:00
/** @var User $user */
$user = User :: find ( $vars [ 'user_id' ]);
$user_data = $user -> toArray (); // for compatibility with current code
2015-07-13 20:10:26 +02:00
echo '<p><h2>' . $user_data [ 'realname' ] . " </h2><a href='edituser/'>Change...</a></p> " ;
// Perform actions if requested
if ( $vars [ 'action' ] == 'deldevperm' ) {
2018-10-29 21:41:50 +01:00
if ( dbFetchCell ( 'SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?' , array ( $vars [ 'device_id' ], $user_data [ 'user_id' ]))) {
dbDelete ( 'devices_perms' , '`device_id` = ? AND `user_id` = ?' , array ( $vars [ 'device_id' ], $user_data [ 'user_id' ]));
2015-07-13 20:10:26 +02:00
}
}
2011-03-17 00:09:20 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'action' ] == 'adddevperm' ) {
2018-10-29 21:41:50 +01:00
if ( ! dbFetchCell ( 'SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?' , array ( $vars [ 'device_id' ], $user_data [ 'user_id' ]))) {
dbInsert ( array ( 'device_id' => $vars [ 'device_id' ], 'user_id' => $user_data [ 'user_id' ]), 'devices_perms' );
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'action' ] == 'delifperm' ) {
2018-10-29 21:41:50 +01:00
if ( dbFetchCell ( 'SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?' , array ( $vars [ 'port_id' ], $user_data [ 'user_id' ]))) {
dbDelete ( 'ports_perms' , '`port_id` = ? AND `user_id` = ?' , array ( $vars [ 'port_id' ], $user_data [ 'user_id' ]));
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'action' ] == 'addifperm' ) {
2018-10-29 21:41:50 +01:00
if ( ! dbFetchCell ( 'SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?' , array ( $vars [ 'port_id' ], $user_data [ 'user_id' ]))) {
dbInsert ( array ( 'port_id' => $vars [ 'port_id' ], 'user_id' => $user_data [ 'user_id' ]), 'ports_perms' );
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'action' ] == 'delbillperm' ) {
2018-10-29 21:41:50 +01:00
if ( dbFetchCell ( 'SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?' , array ( $vars [ 'bill_id' ], $user_data [ 'user_id' ]))) {
dbDelete ( 'bill_perms' , '`bill_id` = ? AND `user_id` = ?' , array ( $vars [ 'bill_id' ], $user_data [ 'user_id' ]));
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( $vars [ 'action' ] == 'addbillperm' ) {
2018-10-29 21:41:50 +01:00
if ( ! dbFetchCell ( 'SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?' , array ( $vars [ 'bill_id' ], $user_data [ 'user_id' ]))) {
dbInsert ( array ( 'bill_id' => $vars [ 'bill_id' ], 'user_id' => $user_data [ 'user_id' ]), 'bill_perms' );
2015-07-13 20:10:26 +02:00
}
}
echo '<div class="row">
<div class="col-md-4">' ;
// Display devices this users has access to
echo '<h3>Device Access</h3>' ;
echo " <div class='panel panel-default panel-condensed'>
2014-03-10 23:50:16 +00:00
<table class='table table-hover table-condensed table-striped'>
<tr>
<th>Device</th>
<th>Action</th>
2015-07-13 20:10:26 +02:00
</tr> " ;
2008-03-09 22:49:53 +00:00
2018-10-29 21:41:50 +01:00
$device_perms = dbFetchRows ( 'SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id' , array ( $user_data [ 'user_id' ]));
2015-07-13 20:10:26 +02:00
foreach ( $device_perms as $device_perm ) {
2018-08-06 16:37:36 +02:00
echo '<tr><td><strong>' . format_hostname ( $device_perm ) . " </td><td> <a href='edituser/action=deldevperm/user_id= " . $vars [ 'user_id' ] . '/device_id=' . $device_perm [ 'device_id' ] . " '><i class='fa fa-trash fa-lg icon-theme' aria-hidden='true'></i></a></strong></td></tr> " ;
2015-07-13 20:10:26 +02:00
$access_list [] = $device_perm [ 'device_id' ];
$permdone = 'yes' ;
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo '</table>
</div>' ;
2014-03-10 23:50:16 +00:00
2015-07-13 20:10:26 +02:00
if ( ! $permdone ) {
echo 'None Configured' ;
}
2011-03-17 00:09:20 +00:00
2015-07-13 20:10:26 +02:00
// Display devices this user doesn't have access to
echo '<h4>Grant access to new device</h4>' ;
echo " <form class='form-inline' role='form' method='post' action=''>
2018-10-29 21:41:50 +01:00
<input type='hidden' value=' " . $user_data [ 'user_id' ] . " ' name='user_id'>
2011-03-17 00:09:20 +00:00
<input type='hidden' value='edituser' name='page'>
<input type='hidden' value='adddevperm' name='action'>
2014-03-10 23:50:16 +00:00
<div class='form-group'>
<label class='sr-only' for='device_id'>Device</label>
2015-07-13 20:10:26 +02:00
<select name='device_id' id='device_id' class='form-control'> " ;
$devices = dbFetchRows ( 'SELECT * FROM `devices` ORDER BY hostname' );
foreach ( $devices as $device ) {
unset ( $done );
foreach ( $access_list as $ac ) {
if ( $ac == $device [ 'device_id' ]) {
$done = 1 ;
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( ! $done ) {
2017-05-05 12:25:58 +01:00
echo " <option value=' " . $device [ 'device_id' ] . " '> " . format_hostname ( $device , $device [ 'hostname' ]) . '</option>' ;
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo " </select>
2014-03-10 23:50:16 +00:00
</div>
2015-07-13 20:10:26 +02:00
<button type='submit' class='btn btn-default' name='Submit'>Add</button></form> " ;
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo " </div>
<div class='col-md-4'> " ;
echo '<h3>Interface Access</h3>' ;
2008-03-09 22:49:53 +00:00
2018-10-29 21:41:50 +01:00
$interface_perms = dbFetchRows ( 'SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id' , array ( $user_data [ 'user_id' ]));
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo " <div class='panel panel-default panel-condensed'>
2014-03-10 23:50:16 +00:00
<table class='table table-hover table-condensed table-striped'>
<tr>
<th>Interface name</th>
<th>Action</th>
2015-07-13 20:10:26 +02:00
</tr> " ;
foreach ( $interface_perms as $interface_perm ) {
echo '<tr>
2014-03-10 23:50:16 +00:00
<td>
2016-12-12 14:25:48 +00:00
<strong>' . $interface_perm [ 'hostname' ] . ' - ' . $interface_perm [ 'ifDescr' ] . '</strong>' . '' . display ( $interface_perm [ 'ifAlias' ]) . "
2014-03-10 23:50:16 +00:00
</td>
<td>
2018-10-29 21:41:50 +01:00
<a href='edituser/action=delifperm/user_id= " . $user_data [ 'user_id' ] . '/port_id=' . $interface_perm [ 'port_id' ] . " '><i class='fa fa-trash fa-lg icon-theme' aria-hidden='true'></i></a>
2014-03-10 23:50:16 +00:00
</td>
2015-07-13 20:10:26 +02:00
</tr> " ;
$ipermdone = 'yes' ;
}
echo '</table>
</div>' ;
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( ! $ipermdone ) {
echo 'None Configured' ;
}
2011-03-17 00:09:20 +00:00
2015-07-13 20:10:26 +02:00
// Display devices this user doesn't have access to
echo '<h4>Grant access to new interface</h4>' ;
2011-03-17 00:09:20 +00:00
2015-07-13 20:10:26 +02:00
echo " <form action='' method='post' class='form-horizontal' role='form'>
2018-10-29 21:41:50 +01:00
<input type='hidden' value=' " . $user_data [ 'user_id' ] . " ' name='user_id'>
2011-03-17 00:09:20 +00:00
<input type='hidden' value='edituser' name='page'>
<input type='hidden' value='addifperm' name='action'>
2014-03-10 23:50:16 +00:00
<div class='form-group'>
<label for='device' class='col-sm-2 control-label'>Device: </label>
<div class='col-sm-10'>
<select id='device' class='form-control' name='device' onchange='getInterfaceList(this)'>
2015-07-13 20:10:26 +02:00
<option value=''>Select a device</option> " ;
foreach ( $devices as $device ) {
unset ( $done );
foreach ( $access_list as $ac ) {
if ( $ac == $device [ 'device_id' ]) {
$done = 1 ;
}
}
2011-03-17 00:09:20 +00:00
2015-07-13 20:10:26 +02:00
if ( ! $done ) {
2017-05-05 12:25:58 +01:00
echo " <option value=' " . $device [ 'device_id' ] . " '> " . format_hostname ( $device , $device [ 'hostname' ]) . '</option>' ;
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo " </select>
2014-03-10 23:50:16 +00:00
</div>
</div>
<div class='form-group'>
<label for='port_id' class='col-sm-2 control-label'>Interface: </label>
<div class='col-sm-10'>
<select class='form-control' id='port_id' name='port_id'>
</select>
</div>
</div>
<div class='form-group'>
<div class='col-sm-12'>
2014-08-27 20:09:29 +10:00
<button type='submit' class='btn btn-default' name='Submit' value='Add'>Add</button>
2014-03-10 23:50:16 +00:00
</div>
</div>
2015-07-13 20:10:26 +02:00
</form> " ;
2014-03-10 23:50:16 +00:00
2015-07-13 20:10:26 +02:00
echo " </div>
<div class='col-md-4'> " ;
echo '<h3>Bill Access</h3>' ;
2008-03-09 22:49:53 +00:00
2018-10-29 21:41:50 +01:00
$bill_perms = dbFetchRows ( 'SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id' , array ( $user_data [ 'user_id' ]));
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo " <div class='panel panel-default panel-condensed'>
2014-03-10 23:50:16 +00:00
<table class='table table-hover table-condensed table-striped'>
<tr>
<th>Bill name</th>
<th>Action</th>
2015-07-13 20:10:26 +02:00
</tr> " ;
2014-03-10 23:50:16 +00:00
2015-07-13 20:10:26 +02:00
foreach ( $bill_perms as $bill_perm ) {
echo '<tr>
2014-03-10 23:50:16 +00:00
<td>
2017-01-25 19:42:26 +02:00
<strong>' . $bill_perm [ 'bill_name' ] . " </strong></td><td width=50> <a href='edituser/action=delbillperm/user_id= " . $vars [ 'user_id' ] . '/bill_id=' . $bill_perm [ 'bill_id' ] . " '><i class='fa fa-trash fa-lg icon-theme' aria-hidden='true'></i></a>
2014-03-10 23:50:16 +00:00
</td>
2015-07-13 20:10:26 +02:00
</tr> " ;
$bill_access_list [] = $bill_perm [ 'bill_id' ];
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
$bpermdone = 'yes' ;
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo '</table>
</div>' ;
2014-03-10 23:50:16 +00:00
2015-07-13 20:10:26 +02:00
if ( ! $bpermdone ) {
echo 'None Configured' ;
}
2011-03-17 00:09:20 +00:00
2015-07-13 20:10:26 +02:00
// Display devices this user doesn't have access to
echo '<h4>Grant access to new bill</h4>' ;
echo " <form method='post' action='' class='form-inline' role='form'>
2018-10-29 21:41:50 +01:00
<input type='hidden' value=' " . $user_data [ 'user_id' ] . " ' name='user_id'>
2011-03-17 00:09:20 +00:00
<input type='hidden' value='edituser' name='page'>
<input type='hidden' value='addbillperm' name='action'>
2014-03-10 23:50:16 +00:00
<div class='form-group'>
<label class='sr-only' for='bill_id'>Bill</label>
2015-07-13 20:10:26 +02:00
<select name='bill_id' class='form-control' id='bill_id'> " ;
$bills = dbFetchRows ( 'SELECT * FROM `bills` ORDER BY `bill_name`' );
foreach ( $bills as $bill ) {
unset ( $done );
foreach ( $bill_access_list as $ac ) {
if ( $ac == $bill [ 'bill_id' ]) {
$done = 1 ;
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( ! $done ) {
echo " <option value=' " . $bill [ 'bill_id' ] . " '> " . $bill [ 'bill_name' ] . '</option>' ;
}
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo " </select>
2014-03-10 23:50:16 +00:00
</div>
2014-08-27 20:09:29 +10:00
<button type='submit' class='btn btn-default' name='Submit' value='Add'>Add</button>
2014-03-10 23:50:16 +00:00
</form>
2015-07-13 20:10:26 +02:00
</div> " ;
2016-08-18 20:28:22 -05:00
} elseif ( $vars [ 'user_id' ] && $vars [ 'edit' ]) {
2018-10-29 21:41:50 +01:00
if ( Auth :: user () -> isDemo ()) {
2015-07-13 20:10:26 +02:00
demo_account ();
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
if ( ! empty ( $vars [ 'new_level' ])) {
if ( $vars [ 'can_modify_passwd' ] == 'on' ) {
$vars [ 'can_modify_passwd' ] = '1' ;
}
2018-09-11 07:51:35 -05:00
LegacyAuth :: get () -> updateUser ( $vars [ 'user_id' ], $vars [ 'new_realname' ], $vars [ 'new_level' ], $vars [ 'can_modify_passwd' ], $vars [ 'new_email' ]);
2015-07-13 20:10:26 +02:00
print_message ( 'User has been updated' );
2018-09-11 07:51:35 -05:00
if ( ! empty ( $vars [ 'new_pass1' ]) && $vars [ 'new_pass1' ] == $vars [ 'new_pass2' ] && LegacyAuth :: get () -> canUpdatePasswords ( $vars [ 'cur_username' ])) {
if ( LegacyAuth :: get () -> changePassword ( $vars [ 'cur_username' ], $vars [ 'new_pass1' ]) == 1 ) {
2015-07-15 20:52:43 +01:00
print_message ( " User password has been updated " );
2016-08-18 20:28:22 -05:00
} else {
print_error ( " Password couldn't be updated " );
}
} elseif ( ! empty ( $vars [ 'new_pass1' ]) && $vars [ 'new_pass1' ] != $vars [ 'new_pass2' ]) {
print_error ( " The supplied passwords didn't match so weren't updated " );
2015-07-15 20:52:43 +01:00
}
2014-12-24 21:22:02 +00:00
}
2018-10-29 21:41:50 +01:00
$users_details = User :: find ( $vars [ 'user_id' ]) -> toArray ();
2016-10-11 00:27:20 -06:00
if ( ! empty ( $users_details )) {
if ( ! empty ( $vars [ 'dashboard' ]) && $vars [ 'dashboard' ] != $users_details [ 'dashboard' ]) {
2017-04-01 16:18:00 -05:00
set_user_pref ( 'dashboard' , $vars [ 'dashboard' ]);
2016-10-11 00:27:20 -06:00
print_message ( " User default dashboard updated " );
}
echo " <form class='form-horizontal' role='form' method='post' action=''>
<input type='hidden' name='user_id' value=' " . $vars [ 'user_id' ] . " '>
<input type='hidden' name='cur_username' value=' " . $users_details [ 'username' ] . " '>
<input type='hidden' name='edit' value='yes'>
" ;
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: get () -> canUpdateUsers () == '1' ) {
2015-07-13 20:10:26 +02:00
if ( empty ( $vars [ 'new_realname' ])) {
$vars [ 'new_realname' ] = $users_details [ 'realname' ];
}
if ( empty ( $vars [ 'new_level' ])) {
$vars [ 'new_level' ] = $users_details [ 'level' ];
}
if ( empty ( $vars [ 'can_modify_passwd' ])) {
$vars [ 'can_modify_passwd' ] = $users_details [ 'can_modify_passwd' ];
2016-08-18 20:28:22 -05:00
} elseif ( $vars [ 'can_modify_passwd' ] == 'on' ) {
2015-07-13 20:10:26 +02:00
$vars [ 'can_modify_passwd' ] = '1' ;
}
if ( empty ( $vars [ 'new_email' ])) {
$vars [ 'new_email' ] = $users_details [ 'email' ];
}
2016-10-11 00:27:20 -06:00
echo "
2014-03-10 23:50:16 +00:00
<div class='form-group'>
<label for='new_realname' class='col-sm-2 control-label'>Realname</label>
<div class='col-sm-4'>
2015-07-13 20:10:26 +02:00
<input name='new_realname' class='form-control input-sm' value=' " . $vars [ 'new_realname' ] . " '>
2014-03-10 23:50:16 +00:00
</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'>
2015-07-13 20:10:26 +02:00
<input name='new_email' class='form-control input-sm' value=' " . $vars [ 'new_email' ] . " '>
2014-03-10 23:50:16 +00:00
</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'>
2015-07-13 20:10:26 +02:00
<option value='1' " ;
if ( $vars [ 'new_level' ] == '1' ) {
echo 'selected' ;
} echo " >Normal User</option>
<option value='5' " ;
if ( $vars [ 'new_level' ] == '5' ) {
echo 'selected' ;
} echo " >Global Read</option>
<option value='10' " ;
if ( $vars [ 'new_level' ] == '10' ) {
echo 'selected' ;
} echo " >Administrator</option>
<option value='11' " ;
if ( $vars [ 'new_level' ] == '11' ) {
echo 'selected' ;
} echo " >Demo account</option>
2014-03-10 23:50:16 +00:00
</select>
</div>
<div class='col-sm-6'>
</div>
2015-07-15 20:52:43 +01:00
</div> " ;
2015-07-13 17:21:07 +01:00
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: get () -> canUpdatePasswords ( $users_details [ 'username' ])) {
2016-08-18 20:28:22 -05:00
echo "
2015-07-15 20:52:43 +01:00
<div class='form-group'>
<label for='new_pass1' class='col-sm-2 control-label'>Password</label>
<div class='col-sm-4'>
<input type='password' name='new_pass1' class='form-control input-sm' value=' " . $vars [ 'new_pass1' ] . " '>
</div>
</div>
<div class='form-group'>
<label for='new_pass2' class='col-sm-2 control-label'>Confirm Password</label>
<div class='col-sm-4'>
<input type='password' name='new_pass2' class='form-control input-sm' value=' " . $vars [ 'new_pass2' ] . " '>
</div>
</div>
" ;
2016-08-18 20:28:22 -05:00
}
2015-07-13 17:21:07 +01:00
2016-08-18 20:28:22 -05:00
echo " <div class='form-group'>
2014-03-10 23:50:16 +00:00
<div class='col-sm-6'>
<div class='checkbox'>
<label>
2015-07-13 20:10:26 +02:00
<input type='checkbox' " ;
if ( $vars [ 'can_modify_passwd' ] == '1' ) {
echo " checked='checked' " ;
2017-01-16 11:11:37 +00:00
} echo " name='can_modify_passwd'> Allow the user to change their password.
2014-03-10 23:50:16 +00:00
</label>
</div>
</div>
<div class='col-sm-6'>
</div>
</div>
2016-10-11 00:27:20 -06:00
" ;
}
echo "
<div class='form-group'>
<label for='dashboard' class='col-sm-2 control-label'>Dashboard</label>
<div class='col-sm-4'><select class='form-control' name='dashboard'> " ;
2017-04-01 16:18:00 -05:00
foreach ( get_dashboards ( $vars [ 'user_id' ]) as $dash ) {
echo " <option value=' " . $dash [ 'dashboard_id' ] . " ' " . ( $dash [ 'default' ] ? ' selected' : '' ) . " > " . $dash [ 'username' ] . ':' . $dash [ 'dashboard_name' ] . " </option> " ;
2016-10-11 00:27:20 -06:00
}
echo " </select>
</div>
</div>
2014-03-10 23:50:16 +00:00
<button type='submit' class='btn btn-default'>Update User</button>
2015-07-13 20:10:26 +02:00
</form> " ;
2016-10-11 00:27:20 -06:00
if ( $config [ 'twofactor' ]) {
if ( $vars [ 'twofactorremove' ]) {
2017-04-01 16:18:00 -05:00
if ( set_user_pref ( 'twofactor' , array (), $vars [ 'user_id' ])) {
2016-10-11 00:27:20 -06:00
echo " <div class='alert alert-success'>TwoFactor credentials removed.</div> " ;
} else {
echo " <div class='alert alert-danger'>Couldnt remove user's TwoFactor credentials.</div> " ;
}
}
if ( $vars [ 'twofactorunlock' ]) {
2017-04-01 16:18:00 -05:00
$twofactor = get_user_pref ( 'twofactor' , array (), $vars [ 'user_id' ]);
2016-10-11 00:27:20 -06:00
$twofactor [ 'fails' ] = 0 ;
2017-04-01 16:18:00 -05:00
if ( set_user_pref ( 'twofactor' , $twofactor , $vars [ 'user_id' ])) {
2016-10-11 00:27:20 -06:00
echo " <div class='alert alert-success'>User unlocked.</div> " ;
} else {
echo " <div class='alert alert-danger'>Couldnt reset user's TwoFactor failures.</div> " ;
}
}
echo " <br/><div class='well'><h3>Two-Factor Authentication</h3> " ;
2017-04-01 16:18:00 -05:00
$twofactor = get_user_pref ( 'twofactor' , array (), $vars [ 'user_id' ]);
2016-10-11 00:27:20 -06:00
if ( $twofactor [ 'fails' ] >= 3 && ( ! $config [ 'twofactor_lock' ] || ( time () - $twofactor [ 'last' ]) < $config [ 'twofactor_lock' ])) {
echo " <form class='form-horizontal' role='form' method='post' action=''>
2015-07-13 20:10:26 +02:00
<input type='hidden' name='user_id' value=' " . $vars [ 'user_id' ] . " '>
2014-12-24 21:22:02 +00:00
<input type='hidden' name='edit' value='yes'>
<div class='form-group'>
<label for='twofactorunlock' class='col-sm-2 control-label'>User exceeded failures</label>
<input type='hidden' name='twofactorunlock' value='1'>
<button type='submit' class='btn btn-default'>Unlock</button>
</div>
</form> " ;
2016-10-11 00:27:20 -06:00
}
2015-07-13 20:10:26 +02:00
2016-10-11 00:27:20 -06:00
if ( $twofactor [ 'key' ]) {
echo " <form class='form-horizontal' role='form' method='post' action=''>
2015-07-13 20:10:26 +02:00
<input type='hidden' name='user_id' value=' " . $vars [ 'user_id' ] . " '>
2014-12-24 21:22:02 +00:00
<input type='hidden' name='edit' value='yes'>
<input type='hidden' name='twofactorremove' value='1'>
<button type='submit' class='btn btn-danger'>Disable TwoFactor</button>
</form>
</div> " ;
2016-10-11 00:27:20 -06:00
} else {
echo '<p>No TwoFactor key generated for this user, Nothing to do.</p>' ;
}
2015-07-13 20:10:26 +02:00
} //end if
2016-08-18 20:28:22 -05:00
} else {
2016-10-11 00:27:20 -06:00
print_error ( 'Error getting user details' );
} //end if !empty($users_details)
2015-07-13 20:10:26 +02:00
} //end if
2016-08-18 20:28:22 -05:00
} else {
2018-10-30 23:30:39 +00:00
$userlist = User :: thisAuth () -> get ();
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo '<h3>Select a user to edit</h3>' ;
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo " <form method='post' action='' class='form-horizontal' role='form'>
2011-03-17 00:09:20 +00:00
<input type='hidden' value='edituser' name='page'>
2014-03-10 23:50:16 +00:00
<div class='form-group'>
<label for='user_id' class='col-sm-2 control-label'>User</label>
<div class='col-sm-4'>
2015-07-13 20:10:26 +02:00
<select name='user_id' class='form-control input-sm'> " ;
2018-10-29 21:41:50 +01:00
foreach ( $userlist as $userentry ) {
switch ( $userentry -> level ) {
2017-02-01 21:05:50 +01:00
case " 10 " :
2018-10-29 21:41:50 +01:00
$userlevel = 'admin' ;
2017-02-01 21:05:50 +01:00
break ;
case " 11 " :
2018-10-29 21:41:50 +01:00
$userlevel = 'demo' ;
2017-02-01 21:05:50 +01:00
break ;
default :
2018-10-29 21:41:50 +01:00
$userlevel = '' ;
}
if ( empty ( $userlevel )) {
$userlevel = $userentry -> auth_type ;
} elseif ( ! empty ( $userentry -> auth_type )) {
$userlevel .= " , " . $userentry -> auth_type ;
2017-02-01 21:05:50 +01:00
}
2018-10-29 21:41:50 +01:00
if ( ! empty ( $userlevel )) {
$userlevel = " ( $userlevel ) " ;
}
echo " <option value=' " . $userentry -> user_id . " '> " . $userentry -> username . $userlevel . '</option>' ;
2015-07-13 20:10:26 +02:00
}
echo " </select>
2014-01-13 10:05:19 +00:00
</div>
</div>
2014-03-10 23:50:16 +00:00
<div class='form-group'>
<div class='col-sm-offset-2 col-sm-3'>
<button type='submit' name='Submit' class='btn btn-default'>Edit Permissions</button> / <button type='submit' name='edit' value='user' class='btn btn-default'>Edit User</button>
</div>
2014-01-13 10:05:19 +00:00
</div>
2015-07-13 20:10:26 +02:00
</form> " ;
} //end if
} //end if
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo '</div>' ;