2009-09-07 11:07:59 +00:00
< ? php
2008-03-09 22:49:53 +00:00
2015-03-21 21:30:55 +00:00
$no_refresh = TRUE ;
2010-06-21 04:18:06 +00:00
include ( " includes/javascript-interfacepicker.inc.php " );
2008-03-09 22:49:53 +00:00
echo ( " <div style='margin: 10px;'> " );
2011-10-18 14:41:19 +00:00
$pagetitle [] = " Edit user " ;
2011-03-17 00:09:20 +00:00
if ( $_SESSION [ 'userlevel' ] != '10' ) { include ( " includes/error-no-perm.inc.php " ); } else
{
2014-03-10 23:50:16 +00:00
if ( $vars [ 'user_id' ] && ! $vars [ 'edit' ])
2011-03-17 00:09:20 +00:00
{
2011-09-21 14:54:21 +00:00
$user_data = dbFetchRow ( " SELECT * FROM users WHERE user_id = ? " , array ( $vars [ 'user_id' ]));
echo ( " <p><h2> " . $user_data [ 'realname' ] . " </h2><a href='edituser/'>Change...</a></p> " );
2011-03-17 00:09:20 +00:00
// Perform actions if requested
2011-09-21 14:54:21 +00:00
if ( $vars [ 'action' ] == " deldevperm " )
2011-03-17 00:09:20 +00:00
{
2011-09-21 14:54:21 +00:00
if ( dbFetchCell ( " SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ? " , array ( $vars [ 'device_id' ] , $vars [ 'user_id' ])))
2011-03-26 19:12:24 +00:00
{
2011-09-21 14:54:21 +00:00
dbDelete ( 'devices_perms' , " `device_id` = ? AND `user_id` = ? " , array ( $vars [ 'device_id' ], $vars [ 'user_id' ]));
2011-03-17 00:09:20 +00:00
}
2010-08-10 12:08:42 +00:00
}
2011-09-21 14:54:21 +00:00
if ( $vars [ 'action' ] == " adddevperm " )
2011-03-17 00:09:20 +00:00
{
2011-09-21 14:54:21 +00:00
if ( ! dbFetchCell ( " SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ? " , array ( $vars [ 'device_id' ] , $vars [ 'user_id' ])))
2011-03-26 19:12:24 +00:00
{
2011-09-21 14:54:21 +00:00
dbInsert ( array ( 'device_id' => $vars [ 'device_id' ], 'user_id' => $vars [ 'user_id' ]), 'devices_perms' );
2011-03-17 00:09:20 +00:00
}
2010-08-10 12:08:42 +00:00
}
2011-09-21 14:54:21 +00:00
if ( $vars [ 'action' ] == " delifperm " )
2011-03-17 00:09:20 +00:00
{
2012-05-16 13:25:50 +00:00
if ( dbFetchCell ( " SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ? " , array ( $vars [ 'port_id' ], $vars [ 'user_id' ])))
2011-03-26 19:12:24 +00:00
{
2012-05-16 13:25:50 +00:00
dbDelete ( 'ports_perms' , " `port_id` = ? AND `user_id` = ? " , array ( $vars [ 'port_id' ], $vars [ 'user_id' ]));
2011-03-17 00:09:20 +00:00
}
2010-08-10 12:08:42 +00:00
}
2011-09-21 14:54:21 +00:00
if ( $vars [ 'action' ] == " addifperm " )
2011-03-17 00:09:20 +00:00
{
2012-05-16 13:25:50 +00:00
if ( ! dbFetchCell ( " SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ? " , array ( $vars [ 'port_id' ], $vars [ 'user_id' ])))
2011-03-26 19:12:24 +00:00
{
2012-05-16 13:25:50 +00:00
dbInsert ( array ( 'port_id' => $vars [ 'port_id' ], 'user_id' => $vars [ 'user_id' ]), 'ports_perms' );
2011-03-17 00:09:20 +00:00
}
2010-08-10 12:08:42 +00:00
}
2011-09-21 14:54:21 +00:00
if ( $vars [ 'action' ] == " delbillperm " )
2011-03-17 00:09:20 +00:00
{
2011-09-21 14:54:21 +00:00
if ( dbFetchCell ( " SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ? " , array ( $vars [ 'bill_id' ], $vars [ 'user_id' ])))
2011-03-26 19:12:24 +00:00
{
2011-09-21 14:54:21 +00:00
dbDelete ( 'bill_perms' , " `bill_id` = ? AND `user_id` = ? " , array ( $vars [ 'bill_id' ], $vars [ 'user_id' ]));
2011-03-17 00:09:20 +00:00
}
2010-08-10 12:08:42 +00:00
}
2011-09-21 14:54:21 +00:00
if ( $vars [ 'action' ] == " addbillperm " )
2011-03-17 00:09:20 +00:00
{
2011-09-21 14:54:21 +00:00
if ( ! dbFetchCell ( " SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ? " , array ( $vars [ 'bill_id' ], $vars [ 'user_id' ])))
2011-03-26 19:12:24 +00:00
{
2011-09-21 14:54:21 +00:00
dbInsert ( array ( 'bill_id' => $vars [ 'bill_id' ], 'user_id' => $vars [ 'user_id' ]), 'bill_perms' );
2011-03-17 00:09:20 +00:00
}
2010-08-10 12:08:42 +00:00
}
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( '<div class="row">
<div class="col-md-4">' );
2008-03-09 22:49:53 +00:00
2011-03-17 00:09:20 +00:00
// Display devices this users has access to
echo ( " <h3>Device Access</h3> " );
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( " <div class='panel panel-default panel-condensed'>
<table class='table table-hover table-condensed table-striped'>
<tr>
<th>Device</th>
<th>Action</th>
</tr> " );
2011-09-21 14:54:21 +00:00
$device_perms = dbFetchRows ( " SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id " , array ( $vars [ 'user_id' ]));
2011-05-15 14:42:30 +00:00
foreach ( $device_perms as $device_perm )
2011-03-17 00:09:20 +00:00
{
2014-03-10 23:50:16 +00:00
echo ( " <tr><td><strong> " . $device_perm [ 'hostname' ] . " </td><td> <a href='edituser/action=deldevperm/user_id= " . $vars [ 'user_id' ] . " /device_id= " . $device_perm [ 'device_id' ] . " '><img src='images/16/cross.png' align=absmiddle border=0></a></strong></td></tr> " );
2011-03-17 00:09:20 +00:00
$access_list [] = $device_perm [ 'device_id' ];
$permdone = " yes " ;
2008-03-09 22:49:53 +00:00
}
2014-03-10 23:50:16 +00:00
echo ( " </table>
</div> " );
2011-03-17 00:09:20 +00:00
if ( ! $permdone ) { echo ( " None Configured " ); }
// Display devices this user doesn't have access to
echo ( " <h4>Grant access to new device</h4> " );
2014-03-10 23:50:16 +00:00
echo ( " <form class='form-inline' role='form' method='post' action=''>
2011-09-21 14:54:21 +00:00
<input type='hidden' value=' " . $vars [ '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>
<select name='device_id' id='device_id' class='form-control'> " );
2011-03-17 00:09:20 +00:00
2011-05-15 14:42:30 +00:00
$devices = dbFetchRows ( " SELECT * FROM `devices` ORDER BY hostname " );
foreach ( $devices as $device )
2011-03-17 00:09:20 +00:00
{
unset ( $done );
foreach ( $access_list as $ac ) { if ( $ac == $device [ 'device_id' ]) { $done = 1 ; } }
if ( ! $done )
{
echo ( " <option value=' " . $device [ 'device_id' ] . " '> " . $device [ 'hostname' ] . " </option> " );
}
}
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( " </select>
</div>
<button type='submit' class='btn btn-default' name='Submit'>Add</button></form> " );
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( " </div>
<div class='col-md-4'> " );
2011-03-17 00:09:20 +00:00
echo ( " <h3>Interface Access</h3> " );
2008-03-09 22:49:53 +00:00
2012-05-16 13:25:50 +00: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 ( $vars [ 'user_id' ]));
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( " <div class='panel panel-default panel-condensed'>
<table class='table table-hover table-condensed table-striped'>
<tr>
<th>Interface name</th>
<th>Action</th>
</tr> " );
2011-05-15 14:42:30 +00:00
foreach ( $interface_perms as $interface_perm )
2011-03-17 00:09:20 +00:00
{
2014-03-10 23:50:16 +00:00
echo ( " <tr>
<td>
<strong> " . $interface_perm [ 'hostname' ] . " - " . $interface_perm [ 'ifDescr' ] . " </strong> " .
" " . $interface_perm [ 'ifAlias' ] . "
</td>
<td>
<a href='edituser/action=delifperm/user_id= " . $vars [ 'user_id' ] .
" /port_id= " . $interface_perm [ 'port_id' ] . " '><img src='images/16/cross.png' align=absmiddle border=0></a>
</td>
</tr> " );
2011-03-17 00:09:20 +00:00
$ipermdone = " yes " ;
}
2014-03-10 23:50:16 +00:00
echo ( " </table>
</div> " );
2008-03-09 22:49:53 +00:00
2011-03-17 00:09:20 +00:00
if ( ! $ipermdone ) { echo ( " None Configured " ); }
// Display devices this user doesn't have access to
echo ( " <h4>Grant access to new interface</h4> " );
2014-03-10 23:50:16 +00:00
echo ( " <form action='' method='post' class='form-horizontal' role='form'>
2011-09-21 14:54:21 +00:00
<input type='hidden' value=' " . $vars [ '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)'>
2011-03-17 00:09:20 +00:00
<option value=''>Select a device</option> " );
2011-05-15 14:42:30 +00:00
foreach ( $devices as $device )
2011-03-17 00:09:20 +00:00
{
unset ( $done );
foreach ( $access_list as $ac ) { if ( $ac == $device [ 'device_id' ]) { $done = 1 ; } }
if ( ! $done ) { echo ( " <option value=' " . $device [ 'device_id' ] . " '> " . $device [ 'hostname' ] . " </option> " ); }
}
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( " </select>
</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>
</form> " );
echo ( " </div>
<div class='col-md-4'> " );
2011-03-17 00:09:20 +00:00
echo ( " <h3>Bill Access</h3> " );
2008-03-09 22:49:53 +00:00
2011-09-21 14:54:21 +00: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 ( $vars [ 'user_id' ]));
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( " <div class='panel panel-default panel-condensed'>
<table class='table table-hover table-condensed table-striped'>
<tr>
<th>Bill name</th>
<th>Action</th>
</tr> " );
2011-05-15 14:42:30 +00:00
foreach ( $bill_perms as $bill_perm )
2011-03-17 00:09:20 +00:00
{
2014-03-10 23:50:16 +00:00
echo ( " <tr>
<td>
<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' ] . " '><img src='images/16/cross.png' align=absmiddle border=0></a>
</td>
</tr> " );
2011-03-17 00:09:20 +00:00
$bill_access_list [] = $bill_perm [ 'bill_id' ];
2008-03-09 22:49:53 +00:00
2011-03-17 00:09:20 +00:00
$bpermdone = " yes " ;
2008-03-09 22:49:53 +00:00
}
2014-03-10 23:50:16 +00:00
echo ( " </table>
</div> " );
2011-03-17 00:09:20 +00:00
if ( ! $bpermdone ) { echo ( " None Configured " ); }
// Display devices this user doesn't have access to
echo ( " <h4>Grant access to new bill</h4> " );
2014-03-10 23:50:16 +00:00
echo ( " <form method='post' action='' class='form-inline' role='form'>
2011-09-21 14:54:21 +00:00
<input type='hidden' value=' " . $vars [ '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>
<select name='bill_id' class='form-control' id='bill_id'> " );
2011-03-17 00:09:20 +00:00
2011-05-25 16:40:03 +00:00
$bills = dbFetchRows ( " SELECT * FROM `bills` ORDER BY `bill_name` " );
2011-05-15 14:42:30 +00:00
foreach ( $bills as $bill )
2011-03-17 00:09:20 +00:00
{
unset ( $done );
foreach ( $bill_access_list as $ac ) { if ( $ac == $bill [ 'bill_id' ]) { $done = 1 ; } }
if ( ! $done )
{
echo ( " <option value=' " . $bill [ 'bill_id' ] . " '> " . $bill [ 'bill_name' ] . " </option> " );
}
}
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00:00
echo ( " </select>
</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>
</div> " );
} elseif ( $vars [ 'user_id' ] && $vars [ 'edit' ]) {
2015-02-17 13:12:29 +00:00
if ( $_SESSION [ 'userlevel' ] == 11 ) {
2015-02-16 23:55:36 +00:00
demo_account ();
} else {
2014-03-10 23:50:16 +00:00
if ( ! empty ( $vars [ 'new_level' ]))
{
if ( $vars [ 'can_modify_passwd' ] == 'on' ) {
$vars [ 'can_modify_passwd' ] = '1' ;
}
update_user ( $vars [ 'user_id' ], $vars [ 'new_realname' ], $vars [ 'new_level' ], $vars [ 'can_modify_passwd' ], $vars [ 'new_email' ]);
print_message ( " User has been updated " );
}
if ( can_update_users () == '1' ) {
$users_details = get_user ( $vars [ 'user_id' ]);
if ( ! empty ( $users_details ))
{
2008-03-09 22:49:53 +00:00
2014-03-10 23:50:16 +00: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' ];
} elseif ( $vars [ 'can_modify_passwd' ] == 'on' ) {
$vars [ 'can_modify_passwd' ] = '1' ;
}
if ( empty ( $vars [ 'new_email' ]))
{
$vars [ 'new_email' ] = $users_details [ 'email' ];
}
2014-12-24 21:22:02 +00:00
if ( $config [ 'twofactor' ] ) {
if ( $vars [ 'twofactorremove' ] ) {
if ( dbUpdate ( array ( 'twofactor' => '' ), users , 'user_id = ?' , array ( $vars [ 'user_id' ])) ) {
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' ] ) {
$twofactor = dbFetchRow ( " SELECT twofactor FROM users WHERE user_id = ? " , array ( $vars [ 'user_id' ]));
$twofactor = json_decode ( $twofactor [ 'twofactor' ], true );
$twofactor [ 'fails' ] = 0 ;
if ( dbUpdate ( array ( 'twofactor' => json_encode ( $twofactor )), users , 'user_id = ?' , array ( $vars [ 'user_id' ])) ) {
echo " <div class='alert alert-success'>User unlocked.</div> " ;
} else {
echo " <div class='alert alert-danger'>Couldnt reset user's TwoFactor failures.</div> " ;
}
}
}
2014-03-10 23:50:16 +00:00
echo ( " <form class='form-horizontal' role='form' method='post' action=''>
<input type='hidden' name='user_id' value=' " . $vars [ 'user_id' ] . " '>
<input type='hidden' name='edit' value='yes'>
<div class='form-group'>
<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' value=' " . $vars [ 'new_realname' ] . " '>
</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' value=' " . $vars [ 'new_email' ] . " '>
</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' " ); 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>
2015-02-16 23:45:28 +00:00
<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>
</div>
<div class='form-group'>
<div class='col-sm-6'>
<div class='checkbox'>
<label>
<input type='checkbox' " ); if ( $vars [ 'can_modify_passwd' ] == '1' ) { echo " checked='checked' " ; } echo ( " name='can_modify_passwd'> Allow the user to change his password.
</label>
</div>
</div>
<div class='col-sm-6'>
</div>
</div>
<button type='submit' class='btn btn-default'>Update User</button>
2014-12-24 21:22:02 +00:00
</form> " );
if ( $config [ 'twofactor' ] ) {
echo " <br/><div class='well'><h3>Two-Factor Authentication</h3> " ;
$twofactor = dbFetchRow ( " SELECT twofactor FROM users WHERE user_id = ? " , array ( $vars [ 'user_id' ]));
$twofactor = json_decode ( $twofactor [ 'twofactor' ], true );
if ( $twofactor [ 'fails' ] >= 3 && ( ! $config [ 'twofactor_lock' ] || ( time () - $twofactor [ 'last' ]) < $config [ 'twofactor_lock' ]) ) {
echo " <form class='form-horizontal' role='form' method='post' action=''>
<input type='hidden' name='user_id' value=' " . $vars [ 'user_id' ] . " '>
<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> " ;
}
if ( $twofactor [ 'key' ] ) {
echo " <form class='form-horizontal' role='form' method='post' action=''>
<input type='hidden' name='user_id' value=' " . $vars [ 'user_id' ] . " '>
<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> " ;
} else {
echo " <p>No TwoFactor key generated for this user, Nothing to do.</p> " ;
}
}
2014-03-10 23:50:16 +00:00
} else {
echo print_error ( " Error getting user details " );
}
} else {
echo print_error ( " Authentication method doesn't support updating users " );
}
2015-02-16 23:55:36 +00:00
}
2011-03-17 00:09:20 +00:00
} else {
2008-03-09 22:49:53 +00:00
2011-09-22 16:46:30 +00:00
$user_list = get_userlist ();
2008-03-09 22:49:53 +00:00
2011-03-17 00:09:20 +00:00
echo ( " <h3>Select a user to edit</h3> " );
2008-03-09 22:49:53 +00:00
2014-01-13 10:05:19 +00: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'>
<select name='user_id' class='form-control input-sm'> " );
2011-10-04 09:10:21 +00:00
foreach ( $user_list as $user_entry )
2011-03-17 00:09:20 +00:00
{
echo ( " <option value=' " . $user_entry [ 'user_id' ] . " '> " . $user_entry [ 'username' ] . " </option> " );
}
2014-01-13 10:05:19 +00:00
echo ( " </select>
</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>
</form> " );
2008-03-09 22:49:53 +00:00
}
}
echo ( " </div> " );
2011-05-12 23:17:44 +00:00
?>