2009-09-07 11:07:59 +00:00
< ? php
2008-03-09 22:49:53 +00:00
2019-12-30 12:11:26 +01:00
use App\Models\DeviceGroup ;
2018-10-29 21:41:50 +01:00
use App\Models\User ;
2017-11-18 11:33:03 +01:00
2015-03-21 21:30:55 +00:00
$no_refresh = true ;
2019-04-11 23:26:42 -05:00
require 'includes/html/javascript-interfacepicker.inc.php' ;
2010-06-21 04:18:06 +00:00
2008-03-09 22:49:53 +00:00
echo " <div style='margin: 10px;'> " ;
2011-10-18 14:41:19 +00:00
$pagetitle [] = 'Edit user' ;
2018-10-29 21:41:50 +01:00
if ( ! Auth :: user () -> hasGlobalAdmin ()) {
2019-04-11 23:26:42 -05:00
include 'includes/html/error-no-perm.inc.php' ;
2016-08-18 20:28:22 -05:00
} else {
2014-03-10 23:50:16 +00: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
2019-04-22 19:01:39 -05:00
echo '<p><h2>' . $user_data [ 'realname' ] . '</h2></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' ) {
2018-10-29 21:41:50 +01:00
if ( dbFetchCell ( 'SELECT COUNT(*) FROM devices_perms WHERE `device_id` = ? AND `user_id` = ?' , [ $vars [ 'device_id' ], $user_data [ 'user_id' ]])) {
dbDelete ( 'devices_perms' , '`device_id` = ? AND `user_id` = ?' , [ $vars [ 'device_id' ], $user_data [ 'user_id' ]]);
2015-07-13 20:10:26 +02:00
}
}
2011-03-17 00:09:20 +00:00
2011-09-21 14:54:21 +00: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` = ?' , [ $vars [ 'device_id' ], $user_data [ 'user_id' ]])) {
dbInsert ([ 'device_id' => $vars [ 'device_id' ], 'user_id' => $user_data [ 'user_id' ]], 'devices_perms' );
2010-08-10 12:08:42 +00:00
}
}
2008-03-09 22:49:53 +00:00
2019-12-30 12:11:26 +01:00
if ( $vars [ 'action' ] == 'deldevgroupperm' ) {
$user -> deviceGroups () -> detach ( $vars [ 'device_group_id' ]);
}
if ( $vars [ 'action' ] == 'adddevgroupperm' ) {
$user -> deviceGroups () -> syncWithoutDetaching ( $vars [ 'device_group_id' ]);
}
2011-09-21 14:54:21 +00: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` = ?' , [ $vars [ 'port_id' ], $user_data [ 'user_id' ]])) {
dbDelete ( 'ports_perms' , '`port_id` = ? AND `user_id` = ?' , [ $vars [ 'port_id' ], $user_data [ 'user_id' ]]);
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2011-03-17 00:09:20 +00: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` = ?' , [ $vars [ 'port_id' ], $user_data [ 'user_id' ]])) {
dbInsert ([ '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
2011-09-21 14:54:21 +00: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` = ?' , [ $vars [ 'bill_id' ], $user_data [ 'user_id' ]])) {
dbDelete ( 'bill_perms' , '`bill_id` = ? AND `user_id` = ?' , [ $vars [ 'bill_id' ], $user_data [ 'user_id' ]]);
2015-07-13 20:10:26 +02:00
}
}
2008-03-09 22:49:53 +00:00
2011-09-21 14:54:21 +00: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` = ?' , [ $vars [ 'bill_id' ], $user_data [ 'user_id' ]])) {
dbInsert ([ 'bill_id' => $vars [ 'bill_id' ], 'user_id' => $user_data [ 'user_id' ]], 'bill_perms' );
2015-07-13 20:10:26 +02:00
}
}
2014-03-10 23:50:16 +00:00
echo ' < div class = " row " >
< div class = " col-md-4 " > ' ;
2015-07-13 20:10:26 +02:00
2011-03-17 00:09:20 +00:00
// Display devices this users has access to
echo '<h3>Device Access</h3>' ;
2015-07-13 20:10:26 +02: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 > " ;
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' , [ $user_data [ 'user_id' ]]);
2011-05-15 14:42:30 +00: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> " ;
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=''>
2019-07-17 07:20:26 -05:00
" . csrf_field() . "
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 >
< select name = 'device_id' id = 'device_id' class = 'form-control' > " ;
2015-07-13 20:10:26 +02: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 ;
}
}
2008-03-09 22:49:53 +00:00
2011-03-17 00:09:20 +00:00
if ( ! $done ) {
2021-11-18 15:46:22 -06:00
echo " <option value=' " . $device [ 'device_id' ] . " '> " . format_hostname ( $device ) . '</option>' ;
2011-03-17 00:09:20 +00:00
}
}
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
2019-12-30 12:11:26 +01:00
echo ' </ div >
< div class = " col-md-4 " > ' ;
// Display devices this users has access to
echo '<h3>Device access via Device Group (beta)</h3>' ;
echo " <div class='panel panel-default panel-condensed'>
< table class = 'table table-hover table-condensed table-striped' >
< tr >
< th > Device Group </ th >
< th > Action </ th >
</ tr > " ;
foreach ( $user -> deviceGroups as $device_group_perm ) {
echo '<tr><td><strong>' . $device_group_perm -> name . " </td><td> <a href='edituser/action=deldevgroupperm/user_id= " . $user -> user_id . '/device_group_id=' . $device_group_perm -> id . " '><i class='fa fa-trash fa-lg icon-theme' aria-hidden='true'></i></a></strong></td></tr> " ;
}
echo ' </ table >
</ div > ' ;
if ( $user -> deviceGroups -> isEmpty ()) {
echo 'None Configured' ;
}
// Display device groups this user doesn't have access to
echo '<h4>Grant access to new Device Group</h4>' ;
$allow_dynamic = \LibreNMS\Config :: get ( 'permission.device_group.allow_dynamic' );
if ( ! $allow_dynamic ) {
echo '<i>Dynamic groups are disabled, set permission.device_group.allow_dynamic to enable.</i>' ;
}
echo " <form class='form-inline' role='form' method='post' action=''>
" . csrf_field() . "
< input type = 'hidden' value = '" . $user_data[' user_id '] . "' name = 'user_id' >
< input type = 'hidden' value = 'edituser' name = 'page' >
< input type = 'hidden' value = 'adddevgroupperm' name = 'action' >
< div class = 'form-group' >
< label class = 'sr-only' for = 'device_group_id' > Device </ label >
< select name = 'device_group_id' id = 'device_group_id' class = 'form-control' > " ;
$device_groups = DeviceGroup :: query ()
-> whereNotIn ( 'id' , $user -> deviceGroups -> pluck ( 'id' ))
-> when ( ! $allow_dynamic , function ( $query ) {
return $query -> where ( 'type' , 'static' );
})
-> orderBy ( 'name' )
-> get ([ 'id' , 'name' ]);
foreach ( $device_groups as $group ) {
echo '<option value="' . $group -> id . '">' . $group -> name . '</option>' ;
}
echo " </select>
</ div >
< button type = 'submit' class = 'btn btn-default' name = 'Submit' > Add </ button ></ form > " ;
echo " </div></div>
< div class = 'row' >
2014-03-10 23:50:16 +00:00
< 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
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' , [ $user_data [ '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 ) {
2014-03-10 23:50:16 +00:00
echo ' < tr >
< td >
2021-03-28 17:25:30 -05:00
< strong > ' . $interface_perm[' hostname '] . ' - ' . $interface_perm[' ifDescr '] . ' </ strong > ' . ' ' . \LibreNMS\Util\Clean::html($interface_perm[' ifAlias ' ], []) . "
2014-03-10 23:50:16 +00:00
</ td >
< td >
2018-10-29 21:41:50 +01:00
& nbsp ; & nbsp ; < 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 >
</ tr > " ;
2011-03-17 00:09:20 +00:00
$ipermdone = 'yes' ;
}
2015-07-13 20:10:26 +02:00
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' ;
}
2019-12-30 12:11:26 +01:00
// Display interfaces this user doesn't have access to
2011-03-17 00:09:20 +00:00
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'>
2019-07-17 07:20:26 -05:00
" . csrf_field() . "
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)' >
2011-03-17 00:09:20 +00:00
< option value = '' > Select a device </ option > " ;
2015-07-13 20:10:26 +02:00
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 ;
2015-07-13 20:10:26 +02:00
}
}
2011-03-17 00:09:20 +00:00
if ( ! $done ) {
2021-11-18 15:46:22 -06:00
echo " <option value=' " . $device [ 'device_id' ] . " '> " . format_hostname ( $device ) . '</option>' ;
2011-03-17 00:09:20 +00:00
}
}
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
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' , [ $user_data [ '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 ) {
2014-03-10 23:50:16 +00:00
echo ' < tr >
< 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 >
</ 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'>
2019-07-17 07:20:26 -05:00
" . csrf_field() . "
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 >
< select name = 'bill_id' class = 'form-control' id = 'bill_id' > " ;
2015-07-13 20:10:26 +02: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 ;
}
}
2008-03-09 22:49:53 +00:00
2011-03-17 00:09:20 +00:00
if ( ! $done ) {
echo " <option value=' " . $bill [ 'bill_id' ] . " '> " . $bill [ 'bill_name' ] . '</option>' ;
2015-07-13 20:10:26 +02:00
}
}
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 > " ;
2016-08-18 20:28:22 -05:00
} else {
2019-04-22 19:01:39 -05:00
echo '<script>window.location.replace("' . url ( 'users' ) . '");</script>' ;
2008-03-09 22:49:53 +00:00
} //end if
2015-07-13 20:10:26 +02:00
} //end if
2008-03-09 22:49:53 +00:00
2014-12-24 21:22:02 +00:00
echo '</div>' ;