WebUi PW Support (#9)

* Initial WebUi Password Support

* Small changes

* Initial WebUi Password Support

* Small changes

* Basic WebUi Token support

* added "removeStorage", added uiLock, updated login page

* Small improvments

* Small change
This commit is contained in:
b1rdhous3 2019-08-30 20:04:02 +02:00 committed by brindosch
parent 4595ae8e2d
commit f764202561
8 changed files with 175 additions and 7 deletions

View File

@ -0,0 +1,33 @@
<div class="container" style="margin:20px auto;max-width:500px;">
<center>
<div>
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Login</h3>
</div>
<div class="panel-body">
<div class="form-group">
<input name="password" class="form-control" type="password" id="password" placeholder="Password" autocomplete="off"/>
<input name="show_pw" type="checkbox" id="show_pw"/><label for="show_pw">Show/Hide Password</label>
</div>
<div class="form-group">
<button class="btn btn-sm btn-success" id="btn_password" onclick="requestAuthorization(document.getElementById('password').value)" disabled><i class="fa fa-fw fa-unlock"></i>Login</button>
</div>
</div>
</div>
</div>
</center>
</div>
<script>
removeOverlay();
$('#password').off().on('input',function(e) {
if(e.currentTarget.value.length >= 8)
$('#btn_password').removeAttr('disabled');
});
$('#show_pw').off().on('change',function(e) {
(e.currentTarget.checked ? $('#password').attr('type', 'text') : $('#password').attr('type', 'password'))
});
</script>

View File

@ -76,6 +76,8 @@
"dashboard_alert_message_confsave_success" : "Deine Hyperion Konfiguration wurde erfolgreich gespeichert. Deine Änderungen sind somit übernommen.",
"dashboard_message_global_setting_t": "Instanzunabhängige Einstellung",
"dashboard_message_global_setting": "Die Einstellungen auf dieser Seite sind instanzunabhängig. Änderungen werden global übernommen.",
"dashboard_message_default_password_t": "WebUi Standardpasswort gesetzt",
"dashboard_message_default_password": "Das Standardpasswort der WebUi ist gesetzt. Wir empfehlen dringend, dieses zu ändern.",
"dashboard_active_instance": "Ausgewählte Instanz",
"main_menu_dashboard_token": "Dashboard",
"main_menu_configuration_token": "Konfiguration",
@ -313,6 +315,8 @@
"infoDialog_effconf_created_text": "Der Effekt \"$1\" wurde erfolgreich erstellt!",
"InfoDialog_lang_title": "Spracheinstellung",
"InfoDialog_lang_text": "Sollte dir die Vorauswahl der automatischen Spracherkennung nicht gefallen, kannst du die Sprache hier manuell festlegen.",
"InfoDialog_changePassword_title" : "Change Password",
"InfoDialog_changePassword_success" : "Passwort erfolgreich gespeichert!",
"InfoDialog_access_title": "Einstellungsstufe",
"InfoDialog_access_text": "Je höher die Stufe je mehr Einstellungen und Funktionen stehen zur Verfügung. Empfohlen ist \"Standard\".",
"InfoDialog_nowrite_title": "Fehler beim Schreibzugriff!",

View File

@ -75,6 +75,8 @@
"dashboard_alert_message_confsave_success" : "Your Hyperion configuration has been saved successfully. Your changes are now active.",
"dashboard_message_global_setting_t": "Instance independent setting",
"dashboard_message_global_setting": "The settings on this page are not depending on a specific instance. Changes will be stored globally for all instances.",
"dashboard_message_default_password_t": "WebUi default password is set",
"dashboard_message_default_password": "The default password for the WebUi is set. We strongly recommend to change this.",
"dashboard_active_instance": "Selected instance",
"main_menu_dashboard_token" : "Dashboard",
"main_menu_configuration_token" : "Configuration",
@ -313,6 +315,8 @@
"InfoDialog_lang_title" : "Language setting",
"InfoDialog_lang_text" : "If you don't like the result of the automatic language detection you could overwrite it here.",
"InfoDialog_access_title" : "Settings level",
"InfoDialog_changePassword_title" : "Change Password",
"InfoDialog_changePassword_success" : "Password successfully saved!",
"InfoDialog_access_text" : "Depending on settings level you could adjust more options or get access to more features. Recommended is the \"Default\" level.",
"InfoDialog_nowrite_title" : "write permission error!",
"InfoDialog_nowrite_text" : "Hyperion can't write to your current loaded configuration file. Please repair the file permissions to proceed.",

View File

@ -92,7 +92,7 @@
</div>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
<ul class="nav navbar-top-links navbar-right" id="top-navbar">
<!-- Browser built in capture stream - streamer.js -->
<li class="dropdown" id="btn_streamer" style="display:none">
<!-- Hidden helpers -->
@ -170,8 +170,23 @@
</div>
</a>
</li>
<li class="divider"></li>
<li id="btn_changePassword">
<a>
<div>
<i class="fa fa-key fa-fw"></i>
<span data-i18n="InfoDialog_changePassword_title"></span>
</div>
</a>
</li>
</ul>
</li>
<!-- /.lock-ui -->
<li class="dropdown" id="btn_lock_ui" style="display:none">
<a>
<i class="fa fa-lock fa-fw"></i>
</a>
</li>
</ul>
<!-- /.navbar-top-left -->
@ -228,6 +243,12 @@
<span data-i18n="dashboard_message_global_setting"></span>
</div>
</div>
<div id="hyperion_default_password_notify" style="display:none;padding:0 10px;margin:0">
<div class="bs-callout bs-callout-warning">
<h4 data-i18n="dashboard_message_default_password_t"></h4>
<span data-i18n="dashboard_message_default_password"></span>
</div>
</div>
<div id="hyperion_disabled_notify" style="display:none;padding:0 10px;margin:0">
<div class="bs-callout bs-callout-danger">
<h4 data-i18n="dashboard_alert_message_disabled_t"></h4>

View File

@ -80,15 +80,77 @@ $(document).ready( function() {
});
$(window.hyperion).one("cmd-authorize-login", function(event) {
$("#main-nav").removeAttr('style')
$("#top-navbar").removeAttr('style')
if(window.defaultPasswordIsSet === true)
$('#hyperion_default_password_notify').fadeIn().delay(10000).fadeOut();
else
//if logged on and pw != default show option to lock ui
$("#btn_lock_ui").removeAttr('style')
if (event.response.hasOwnProperty('info'))
setStorage("loginToken", event.response.info.token, true);
requestServerConfigSchema();
});
$(window.hyperion).on("cmd-authorize-newPassword", function(event) {
if (event.response.success === true)
showInfoDialog("success",$.i18n('InfoDialog_changePassword_success'));
});
$(window.hyperion).one("cmd-authorize-newPasswordRequired", function(event) {
var loginToken = getStorage("loginToken", true)
if (event.response.info.newPasswordRequired == true)
{
window.defaultPasswordIsSet = true;
if(loginToken)
requestTokenAuthorization(loginToken)
else
requestAuthorization('hyperion');
}
else
{
$("#main-nav").attr('style', 'display:none')
$("#top-navbar").attr('style', 'display:none')
if(loginToken)
requestTokenAuthorization(loginToken)
else
loadContentTo("#page-content", "login")
}
});
$(window.hyperion).one("cmd-authorize-adminRequired", function(event) {
//Check if a admin login is required.
//If yes: check if default pw is set. If no: go ahead to get server config and render page
if (event.response.info.adminRequired === true)
requestRequiresDefaultPasswortChange();
else
requestServerConfigSchema();
});
$(window.hyperion).on("error",function(event){
showInfoDialog("error","Error", event.reason);
//If we are getting an error "No Authorization" back with a set loginToken we will forward to new Login (Token is expired.
//e.g.: hyperiond was started new in the meantime)
if (event.reason == "No Authorization" && getStorage("loginToken", true))
{
removeStorage("loginToken", true);
requestRequiresAdminAuth();
}
else
{
showInfoDialog("error","Error", event.reason);
}
});
$(window.hyperion).on("open",function(event){
requestAuthorization();
requestRequiresAdminAuth();
});
$(window.hyperion).one("ready", function(event) {

View File

@ -28,6 +28,7 @@ window.wSess = [];
window.currentHyperionInstance = 0;
window.currentHyperionInstanceName = "?";
window.comps = [];
window.defaultPasswordIsSet = null;
tokenList = {};
function initRestart()
@ -176,14 +177,19 @@ function requestRequiresDefaultPasswortChange()
sendToHyperion("authorize","newPasswordRequired");
}
// Change password
function requestChangePassword(oldPw, newPW)
function requestChangePassword(oldPw, newPw)
{
sendToHyperion("authorize","newPassword",'"password": "'+oldPw+'", "newPassword":"'+newPw+'"');
}
function requestAuthorization()
function requestAuthorization(password)
{
sendToHyperion("authorize","login",'"password": "hyperion"');
sendToHyperion("authorize","login",'"password": "' + password + '"');
}
function requestTokenAuthorization(token)
{
sendToHyperion("authorize","login",'"token": "' + token + '"');
}
function requestToken(comment)

View File

@ -112,6 +112,24 @@ $(document).ready( function() {
$('#id_select').trigger('change');
});
//Change Password
$('#btn_changePassword').off().on('click',function() {
showInfoDialog('changePassword', $.i18n('InfoDialog_changePassword_title'));
$('#id_btn_ok').off().on('click',function() {
var oldPw = $('#oldPw').val();
var newPw = $('#newPw').val();
requestChangePassword(oldPw, newPw)
});
});
//Lock Ui
$('#btn_lock_ui').off().on('click',function() {
removeStorage('loginToken', true);
location.replace('/');
});
//hide menu elements
if (storedAccess != 'expert')
$('#load_webconfig').toggle(false);

View File

@ -40,6 +40,17 @@ function setStorage(item, value, session)
}
}
function removeStorage(item, session)
{
if(storageComp())
{
if(session === true)
sessionStorage.removeItem(item);
else
localStorage.removeItem(item);
}
}
function debugMessage(msg)
{
if (window.debugMessagesActive)
@ -286,6 +297,15 @@ function showInfoDialog(type,header,message)
$('#id_footer_rename').html('<button type="button" id="id_btn_ok" class="btn btn-success" data-dismiss-modal="#modal_dialog_rename" disabled><i class="fa fa-fw fa-save"></i>'+$.i18n('general_btn_ok')+'</button>');
$('#id_footer_rename').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'+$.i18n('general_btn_cancel')+'</button>');
}
else if (type == "changePassword")
{
$('#id_body_rename').html('<i style="margin-bottom:20px" class="fa fa-key modal-icon-edit"><br>');
$('#id_body_rename').append('<h4>'+header+'</h4>');
$('#id_body_rename').append('<input class="form-control" id="oldPw" placeholder="Old" type="text"> <br />');
$('#id_body_rename').append('<input class="form-control" id="newPw" placeholder="New" type="text">');
$('#id_footer_rename').html('<button type="button" id="id_btn_ok" class="btn btn-success" data-dismiss-modal="#modal_dialog_rename"><i class="fa fa-fw fa-save"></i>'+$.i18n('general_btn_ok')+'</button>');
$('#id_footer_rename').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'+$.i18n('general_btn_cancel')+'</button>');
}
else if (type == "checklist")
{
$('#id_body').html('<img style="margin-bottom:20px" src="img/hyperion/hyperionlogo.png" alt="Redefine ambient light!">');
@ -315,7 +335,7 @@ function showInfoDialog(type,header,message)
$('#id_body').append('<select id="id_select" class="form-control" style="margin-top:10px;width:auto;"></select>');
$(type == "renInst" ? "#modal_dialog_rename" : "#modal_dialog").modal({
$(type == "renInst" || type == "changePassword" ? "#modal_dialog_rename" : "#modal_dialog").modal({
backdrop : "static",
keyboard: false,
show: true