2008-03-09 22:49:53 +00:00
<? php
2011-10-18 14:41:19 +00:00
2018-09-11 07:51:35 -05:00
use LibreNMS\Authentication\LegacyAuth ;
2017-05-18 16:08:10 -05:00
use LibreNMS\Authentication\TwoFactor ;
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
$pagetitle [] = 'Preferences' ;
2011-10-18 14:41:19 +00:00
2015-08-29 21:44:29 +05:30
echo '<h2>User Preferences</h2>' ;
echo '<hr>' ;
2008-03-09 22:49:53 +00:00
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: user () -> isDemoUser ()) {
2015-02-16 23:45:28 +00:00
demo_account ();
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
if ( $_POST [ 'action' ] == 'changepass' ) {
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: get () -> authenticate ( LegacyAuth :: user () -> username , $_POST [ 'old_pass' ])) {
2015-07-13 20:10:26 +02:00
if ( $_POST [ 'new_pass' ] == '' || $_POST [ 'new_pass2' ] == '' ) {
$changepass_message = 'Password must not be blank.' ;
2016-08-18 20:28:22 -05:00
} elseif ( $_POST [ 'new_pass' ] == $_POST [ 'new_pass2' ]) {
2018-09-11 07:51:35 -05:00
LegacyAuth :: get () -> changePassword ( LegacyAuth :: user () -> username , $_POST [ 'new_pass' ]);
2015-07-13 20:10:26 +02:00
$changepass_message = 'Password Changed.' ;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$changepass_message = "Passwords don't match." ;
}
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$changepass_message = 'Incorrect password' ;
}
}
2016-10-22 15:51:20 +00:00
if ( $vars [ 'action' ] === 'changedash' ) {
2016-10-19 15:37:26 -06:00
if ( ! empty ( $vars [ 'dashboard' ])) {
2017-04-01 16:18:00 -05:00
set_user_pref ( 'dashboard' , ( int ) $vars [ 'dashboard' ]);
2016-10-22 15:51:20 +00:00
$updatedashboard_message = "User default dashboard updated" ;
2016-10-19 15:37:26 -06:00
}
}
2018-11-08 23:01:46 +01:00
if ( $vars [ 'action' ] === 'changenote' ) {
set_user_pref ( 'add_schedule_note_to_device' , ( bool ) $vars [ 'notetodevice' ]);
if ( $vars [ 'notetodevice' ]) {
$updatenote_message = "Schedule notes will now be added to device notes" ;
} else {
$updatenote_message = "Schedule notes will no longer be added to device notes" ;
}
}
2010-06-21 15:39:43 +00:00
2015-07-13 20:10:26 +02:00
include 'includes/update-preferences-password.inc.php' ;
2008-03-09 22:49:53 +00:00
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: get () -> canUpdatePasswords ( LegacyAuth :: user () -> username )) {
2015-07-13 20:10:26 +02:00
echo '<h3>Change Password</h3>' ;
2015-08-29 21:44:29 +05:30
echo '<hr>' ;
echo "<div class='well'>" ;
2015-07-13 20:10:26 +02:00
echo $changepass_message ;
echo "<form method='post' action='preferences/' class='form-horizontal' role='form'>
2014-01-13 10:05:19 +00:00
<input type=hidden name='action' value='changepass'>
<div class='form-group'>
2015-09-22 18:31:14 +05:30
<label for='old_pass' class='col-sm-2 control-label'>Current Password</label>
2014-01-13 10:05:19 +00:00
<div class='col-sm-4'>
<input type=password name=old_pass autocomplete='off' class='form-control input-sm'>
</div>
<div class='col-sm-6'>
</div>
</div>
<div class='form-group'>
<label for='new_pass' class='col-sm-2 control-label'>New Password</label>
<div class='col-sm-4'>
<input type=password name=new_pass autocomplete='off' class='form-control input-sm'>
</div>
<div class='col-sm-6'>
</div>
</div>
<div class='form-group'>
2014-06-17 19:56:20 +01:00
<label for='new_pass2' class='col-sm-2 control-label'>New Password</label>
2014-01-13 10:05:19 +00:00
<div class='col-sm-4'>
<input type=password name=new_pass2 autocomplete='off' class='form-control input-sm'>
2015-09-22 18:31:14 +05:30
<br>
2015-08-29 21:44:29 +05:30
<center><button type='submit' class='btn btn-default'>Submit</button></center>
2014-01-13 10:05:19 +00:00
</div>
<div class='col-sm-6'>
</div>
</div>
2015-08-29 21:44:29 +05:30
2015-07-13 20:10:26 +02:00
</form>" ;
echo '</div>' ;
} //end if
if ( $config [ 'twofactor' ] === true ) {
2018-09-11 07:51:35 -05:00
$twofactor = get_user_pref ( 'twofactor' );
echo '<script src="js/jquery.qrcode.min.js"></script>' ;
echo '<h3>Two-Factor Authentication</h3>' ;
echo '<hr>' ;
echo '<div class="well">' ;
if ( ! empty ( $twofactor )) {
$twofactor [ 'text' ] = "<div class='form-group'>
2014-12-24 21:22:02 +00:00
<label for='twofactorkey' class='col-sm-2 control-label'>Secret Key</label>
<div class='col-sm-4'>
<input type='text' name='twofactorkey' autocomplete='off' disabled class='form-control input-sm' value='" . $twofactor [ 'key' ] . "' />
</div>
</div>" ;
2018-09-11 07:51:35 -05:00
if ( $twofactor [ 'counter' ] !== false ) {
$twofactor [ 'uri' ] = 'otpauth://hotp/' . LegacyAuth :: user () -> username . '?issuer=LibreNMS&counter=' . $twofactor [ 'counter' ] . '&secret=' . $twofactor [ 'key' ];
$twofactor [ 'text' ] .= "<div class='form-group'>
2014-12-24 21:22:02 +00:00
<label for='twofactorcounter' class='col-sm-2 control-label'>Counter</label>
<div class='col-sm-4'>
<input type='text' name='twofactorcounter' autocomplete='off' disabled class='form-control input-sm' value='" . $twofactor [ 'counter' ] . "' />
</div>
</div>" ;
2018-09-11 07:51:35 -05:00
} else {
$twofactor [ 'uri' ] = 'otpauth://totp/' . LegacyAuth :: user () -> username . '?issuer=LibreNMS&secret=' . $twofactor [ 'key' ];
}
2015-07-13 20:10:26 +02:00
2018-09-11 07:51:35 -05:00
echo '<div id="twofactorqrcontainer">
2014-12-24 21:22:02 +00:00
<div id="twofactorqr"></div>
<button class="btn btn-default" onclick="$(\'#twofactorkeycontainer\').show(); $(\'#twofactorqrcontainer\').hide();">Manual</button>
</div>' ;
2018-09-11 07:51:35 -05:00
echo '<div id="twofactorkeycontainer">
2014-12-24 21:22:02 +00:00
<form id="twofactorkey" class="form-horizontal" role="form">' . $twofactor [ 'text' ] . '</form>
<button class="btn btn-default" onclick="$(\'#twofactorkeycontainer\').hide(); $(\'#twofactorqrcontainer\').show();">QR</button>
</div>' ;
2018-09-11 07:51:35 -05:00
echo '<script>$("#twofactorqr").qrcode({"text": "' . $twofactor [ 'uri' ] . '"}); $("#twofactorkeycontainer").hide();</script>' ;
echo '<br/><form method="post" class="form-horizontal" role="form" action="2fa/remove">
2014-12-24 21:22:02 +00:00
<button class="btn btn-danger" type="submit">Disable TwoFactor</button>
</form>' ;
2018-09-11 07:51:35 -05:00
} else {
echo '<form method="post" class="form-horizontal" role="form" action="2fa/add">
2014-12-24 21:22:02 +00:00
<div class="form-group">
<label for="twofactortype" class="col-sm-2 control-label">TwoFactor Type</label>
<div class="col-sm-4">
2018-09-11 07:51:35 -05:00
<select name="twofactortype" class="select">
2014-12-24 21:22:02 +00:00
<option value="time">Time Based (TOTP)</option>
2018-09-11 07:51:35 -05:00
<option value="counter">Counter Based (HOTP)</option>
2014-12-24 21:22:02 +00:00
</select>
</div>
</div>
2018-09-11 07:51:35 -05:00
<div class="form-group">
<div class="col-sm-4 col-sm-offset-1">
<button class="btn btn-default" type="submit">Generate TwoFactor Secret Key</button>
</div>
</div>
2014-12-24 21:22:02 +00:00
</form>' ;
2015-07-13 20:10:26 +02:00
} //end if
2018-09-11 07:51:35 -05:00
echo '</div>' ;
2015-07-13 20:10:26 +02:00
} //end if
} //end if
2016-10-19 15:37:26 -06:00
echo "<h3>Default Dashboard</h3>
<hr>
<div class='well'>" ;
2016-10-22 15:51:20 +00:00
if ( ! empty ( $updatedashboard_message )) {
print_message ( $updatedashboard_message );
}
2016-10-19 15:37:26 -06:00
echo "
<form method='post' action='preferences/' class='form-horizontal' role='form'>
<div class='form-group'>
<input type=hidden name='action' value='changedash'>
<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 () as $dash ) {
2016-10-19 15:37:26 -06:00
echo "
2017-04-01 16:18:00 -05:00
<option value='" . $dash [ 'dashboard_id' ] . "'" . ( $dash [ 'default' ] ? ' selected' : '' ) . ">" . display ( $dash [ 'username' ]) . ':' . display ( $dash [ 'dashboard_name' ]) . "</option>" ;
2016-10-19 16:03:51 -06:00
}
echo "
2016-10-19 15:37:26 -06:00
</select>
<br>
<center><button type='submit' class='btn btn-default'>Update Dashboard</button></center>
</div>
<div class='col-sm-6'></div>
</div>
</div>
</form>
</div>" ;
2015-07-13 20:10:26 +02:00
2018-11-08 23:01:46 +01:00
echo "<h3>Add schedule notes to devices notes</h3>
<hr>
<div class='well'>" ;
if ( ! empty ( $updatenote_message )) {
print_message ( $updatenote_message );
}
echo "
<form method='post' action='preferences/' class='form-horizontal' role='form'>
<div class='form-group'>
<input type=hidden name='action' value='changenote'>
<div class='form-group'>
<label for='dashboard' class='col-sm-3 control-label'>Add schedule notes to devices notes</label>
<div class='col-sm-4'>
<input id='notetodevice' type='checkbox' name='notetodevice' data-size='small' " . (( get_user_pref ( 'add_schedule_note_to_device' , false )) ? 'checked' : '' ) . ">
</div>
</div>
<div class='form-group'>
<div class='col-sm-4 col-sm-offset-3'>
<button type='submit' class='btn btn-default'>Update preferences</button>
</div>
<div class='col-sm-6'></div>
</div>
</div>
</form>
</div>" ;
2015-08-29 21:44:29 +05:30
echo "<h3>Device Permissions</h3>" ;
echo "<hr>" ;
2018-09-11 07:51:35 -05:00
echo '<div class="well">' ;
if ( LegacyAuth :: user () -> hasGlobalAdmin ()) {
2015-07-13 20:10:26 +02:00
echo "<strong class='blue'>Global Administrative Access</strong>" ;
2018-09-11 07:51:35 -05:00
} elseif ( LegacyAuth :: user () -> hasGlobalRead ()) {
2015-07-13 20:10:26 +02:00
echo "<strong class='green'>Global Viewing Access</strong>" ;
2018-04-07 15:55:28 -05:00
} else {
2018-09-11 07:51:35 -05:00
foreach ( dbFetchRows ( 'SELECT * FROM `devices_perms` AS P, `devices` AS D WHERE `user_id` = ? AND P.device_id = D.device_id' , array ( LegacyAuth :: id ())) as $perm ) {
2015-07-13 20:10:26 +02:00
// FIXME generatedevicelink?
echo "<a href='device/device=" . $perm [ 'device_id' ] . "'>" . $perm [ 'hostname' ] . '</a><br />' ;
$dev_access = 1 ;
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
if ( ! $dev_access ) {
echo 'No access!' ;
}
2011-03-17 00:09:20 +00:00
}
2008-03-09 22:49:53 +00:00
2015-07-13 20:10:26 +02:00
echo '</div>' ;
2018-11-08 23:01:46 +01:00
echo "<script>$( \" [name='notetodevice'] \" ).bootstrapSwitch('offColor','danger');</script>" ;