Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authentication #681

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ install: configs
install -d -m 0777 $(DESTDIR)/var/www/images
install -d -m 0777 $(DESTDIR)/var/www/uploads
install -d -m 0777 $(DESTDIR)/var/www/scripts/i18n
install -d -m 0777 $(DESTDIR)/var/www/fonts
KraPete marked this conversation as resolved.
Show resolved Hide resolved

cp -a dist/css/*.css $(DESTDIR)/var/www/css
cp -a dist/images/* $(DESTDIR)/var/www/images
Expand All @@ -52,13 +53,12 @@ install: configs
cp -a dist/*.js $(DESTDIR)/var/www/
cp -a dist/*.svg $(DESTDIR)/var/www/
cp -a dist/*.png $(DESTDIR)/var/www/
cp -a dist/*.ttf $(DESTDIR)/var/www/
cp -a dist/*.woff $(DESTDIR)/var/www/
cp -a dist/*.woff2 $(DESTDIR)/var/www/ || :
cp -a dist/fonts/* $(DESTDIR)/var/www/fonts

install -m 0644 dist/404.html $(DESTDIR)/var/www/
install -m 0644 dist/robots.txt $(DESTDIR)/var/www/
install -m 0644 dist/index.html $(DESTDIR)/var/www/
install -m 0644 login/login.html $(DESTDIR)/var/www/
KraPete marked this conversation as resolved.
Show resolved Hide resolved

install -Dm0644 dist/configs/*.json -t $(DESTDIR)/usr/share/wb-mqtt-homeui
install -Dm0755 convert_config_v1v2.py $(DESTDIR)/usr/lib/wb-mqtt-homeui/convert_config_v1v2
Expand Down
28 changes: 19 additions & 9 deletions app/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

<div id="wrapper" class="fade" ng-class="{ 'show-console': consoleVisible }">
<exp-check-widget></exp-check-widget>
<div class="alert alert-danger" role="alert" ng-cloak ng-if="roles.notConfiguredUsers.length">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span translate>{{roles.notConfiguredUsersMessage}}</span>
KraPete marked this conversation as resolved.
Show resolved Hide resolved
</div>
KraPete marked this conversation as resolved.
Show resolved Hide resolved

<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" ng-controller='NavigationCtrl'>
Expand All @@ -38,16 +42,22 @@
<a class="navbar-brand wb-navbar-brand" ui-sref="home">
<img src="images/logo.svg" alt="Wiren Board Web UI">
</a>
<p class="navbar-text navbar-right connection-status">
<span class="label label-custom access-level-label" ng-class="roles.current.roles.isAdmin ? 'label label-custom label-danger' : 'label label-custom label-warning'"
ng-show="roles.current.roles.shortName"
title="{{'navigation.access.title' | translate}} {{roles.current.roles.name | translate}}">
<span class="mobile-screen-access-level">{{roles.current.roles.shortName | translate}}</span>
<span class="big-screen-access-level">{{'navigation.access.title' | translate}} {{roles.current.roles.name | translate}}</span>
</span>
<div class="navbar-text navbar-right connection-status">
<span class="connected-status label label-success" ng-show="isConnected()" translate>{{'navigation.connection.active'}}</span>
<span class="connected-status label label-danger" ng-show="!isConnected()" translate>{{'navigation.connection.inactive'}}</span>
</p>
<div class="dropdown user-menu navbar-right">
<i class="glyphicon glyphicon-user" id="userMenu" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></i>
<ul class="dropdown-menu" aria-labelledby="userMenu">
<li>
<span class='user-name' translate>{{roles.current.roles.name}}</span>
</li>
<li role="separator" class="divider"></li>
<li>
<a href="#" ng-click="logout()" translate>{{'app.buttons.logout'}}</a>
</li>
</ul>
</div>
</div>
</div>

<div class="nav navbar-nav navbar-right ma-0"></div>
Expand Down Expand Up @@ -102,7 +112,7 @@
<li>
<a data-toggle="collapse" data-target=".navbar-ex1-collapse" ui-sref="MQTTChannels" ui-sref-active="active">{{'navigation.menu.channels' | translate}}</a>
</li>
<li>
<li ng-if="showAccessControl()">
<a data-toggle="collapse" data-target=".navbar-ex1-collapse" ui-sref="accessLevel" ui-sref-active="active">{{'navigation.menu.access' | translate}}</a>
</li>
<li user-role="mto" current-role="roles.current.role">
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import HomeCtrl from './controllers/homeController';
import NavigationCtrl from './controllers/navigationController';
import LoginCtrl from './controllers/loginController';
import MQTTCtrl from './controllers/MQTTChannelsController';
import AccessLevelCtrl from './controllers/accessLevelController';
import DateTimePickerModalCtrl from './controllers/dateTimePickerModalController';
import DiagnosticCtrl from './controllers/diagnosticController';
import BackupCtrl from './controllers/backupController';
Expand Down Expand Up @@ -95,6 +94,7 @@ import onResizeDirective from './directives/resize';
import confirmDirective from './directives/confirm';
import fullscreenToggleDirective from './directives/fullscreenToggle';
import expCheckMetaDirective from './react-directives/exp-check/exp-check';
import usersPageDirective from './react-directives/users/users';
KraPete marked this conversation as resolved.
Show resolved Hide resolved

// Angular routes
import routingModule from './app.routes';
Expand Down Expand Up @@ -178,7 +178,6 @@ module
.controller('HomeCtrl', HomeCtrl)
.controller('LoginCtrl', LoginCtrl)
.controller('MQTTCtrl', MQTTCtrl)
.controller('AccessLevelCtrl', AccessLevelCtrl)
.controller('DateTimePickerModalCtrl', DateTimePickerModalCtrl)
.controller('DiagnosticCtrl', DiagnosticCtrl)
.controller('BackupCtrl', BackupCtrl)
Expand Down Expand Up @@ -266,7 +265,8 @@ module
.directive('onResize', ['$parse', onResizeDirective])
.directive('ngConfirm', confirmDirective)
.directive('fullscreenToggle', fullscreenToggleDirective)
.directive('expCheckWidget', expCheckMetaDirective);
.directive('expCheckWidget', expCheckMetaDirective)
.directive('usersPage', usersPageDirective);

module
.config([
Expand All @@ -277,7 +277,6 @@ module
'app',
'console',
'help',
'access',
'mqtt',
'system',
'ui',
Expand Down
1 change: 0 additions & 1 deletion app/scripts/app.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function routing($stateProvider, $locationProvider, $urlRouterProvider) {
.state('accessLevel', {
url: '/access-level',
template: require('../views/access-level.html'),
controller: 'AccessLevelCtrl as $ctrl',
})
.state('scan', {
url: '/scan',
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/components/loginForm/loginForm.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class LoginFormCtrl {
constructor($window, $rootScope, $state, $location, rolesFactory) {
'ngInject';

var currentURL = new URL("/mqtt", $window.location.href);
var currentURL = new URL('/mqtt', $window.location.href);
KraPete marked this conversation as resolved.
Show resolved Hide resolved
currentURL.protocol = currentURL.protocol.replace('http', 'ws');

this.rootScope = $rootScope;
this.isDev = ($window.location.host === 'localhost:8080'); // FIXME: find more beautiful way to detect local dev
this.isDev = $window.location.host === 'localhost:8080'; // FIXME: find more beautiful way to detect local dev
KraPete marked this conversation as resolved.
Show resolved Hide resolved
this.localStorage = $window.localStorage;
this.state = $state;
this.rolesFactory = rolesFactory;
Expand Down Expand Up @@ -62,8 +62,9 @@ class LoginFormCtrl {
//...........................................................................
updateLoginSettings() {
// Update settings in Local Storage
if (this.isDev)
if (this.isDev) {
this.localStorage.setItem('url', this.url);
}

this.localStorage.setItem('prefix', this.prefix);

Expand All @@ -84,7 +85,6 @@ class LoginFormCtrl {
isDev: this.isDev,
};

this.rolesFactory.setRole(1);
this.rootScope.requestConfig(loginData);
location.reload();
}
Expand Down
42 changes: 0 additions & 42 deletions app/scripts/controllers/accessLevelController.js

This file was deleted.

16 changes: 15 additions & 1 deletion app/scripts/controllers/navigationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
whenMqttReady,
errors,
uiConfig,
rolesFactory
rolesFactory,
$rootScope
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Add trailing comma for consistency
Trailing commas can improve diffs and code clarity.

🧰 Tools
🪛 eslint

[error] 12-13: Missing trailing comma.

(comma-dangle)

) {
'ngInject';

$scope.roles = rolesFactory;
$rootScope.roles = rolesFactory;
KraPete marked this conversation as resolved.
Show resolved Hide resolved
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Avoid assigning to $rootScope parameter
Modifying injected Angular parameters can lead to unintentional side effects. If possible, consider referencing or wrapping the object instead.

🧰 Tools
🪛 eslint

[error] 17-17: Assignment to property of function parameter '$rootScope'.

(no-param-reassign)


$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
Expand Down Expand Up @@ -84,6 +86,18 @@
? pageWrapperClassList.remove(overlayClass)
: pageWrapperClassList.add(overlayClass);
};

$scope.showAccessControl = function () {
return rolesFactory.current.roles.isAdmin || rolesFactory.notConfiguredUsers.length;
};

$scope.logout = function () {
fetch('/logout', {
method: 'POST',
}).then(() => {
window.location.href = '/login';

Check warning on line 98 in app/scripts/controllers/navigationController.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/scripts/controllers/navigationController.js#L98

Dangerous location.href assignment can lead to XSS. Please use escape('/login') as a wrapper for escaping
});
Comment on lines +94 to +99
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Handle errors when logging out
The logout process uses a fetch call without a .catch(...). Consider adding error handling logic (e.g., network issues).

};
KraPete marked this conversation as resolved.
Show resolved Hide resolved
}

//-----------------------------------------------------------------------------
Expand Down
27 changes: 0 additions & 27 deletions app/scripts/i18n/access/en.json

This file was deleted.

27 changes: 0 additions & 27 deletions app/scripts/i18n/access/ru.json

This file was deleted.

14 changes: 13 additions & 1 deletion app/scripts/i18n/app/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@
"load": "Cannot load WebUI config.",
"save": "Config saving failed",
"overflow": "Config saving failed. Try to clear page's localStorage and restart the browser. If problem remains, try to reduce overall size of SVG images.",
"stop-scan": "The controller started searching for Modbus devices. This could lead to slow polling of already configured devices. The search process is forcibly stopped"
"stop-scan": "The controller started searching for Modbus devices. This could lead to slow polling of already configured devices. The search process is forcibly stopped",
"not-configured-admin": "The administrator password is not set. Please set it in the settings",
"not-configured-user": "The user password is not set. Please set it in the settings",
"not-configured-operator": "The operator password is not set. Please set it in the settings",
"not-configured-operator-user": "The user and operator passwords are not set. Please set them in the settings"
KraPete marked this conversation as resolved.
Show resolved Hide resolved
},
"prompt": {
"dirty": "The page has unsaved changes. Are you sure you want to leave?",
"serial-config-leave": "Scanning will be canceled. Do you really want to leave the page?"
},
"buttons": {
"logout": "Logout"
},
"roles": {
"user": "User",
"operator": "Operator",
"admin": "Administrator"
KraPete marked this conversation as resolved.
Show resolved Hide resolved
}
},
"home": {
Expand Down
14 changes: 13 additions & 1 deletion app/scripts/i18n/app/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@
"load": "Не удалось загрузить настройки WebUI.",
"save": "Не удалось сохранить настройки",
"overflow": "Не удалось сохранить настройки. Попробуйте очистить localStorage страницы и перезапустить браузер. Если не помогло — попробуйте уменьшить суммарный размер SVG-изображений.",
"stop-scan": "В контроллере был запущен процесс поиска Modbus устройств. Это могло приводить к медленному опросу уже настроенных устройств. Процесс поиска принудительно остановлен"
"stop-scan": "В контроллере был запущен процесс поиска Modbus устройств. Это могло приводить к медленному опросу уже настроенных устройств. Процесс поиска принудительно остановлен",
"not-configured-admin": "Пароль администратора не установлен. Пожалуйста, установите его в настройках",
"not-configured-user": "Пароль пользователя не установлен. Пожалуйста, установите его в настройках",
"not-configured-operator": "Пароль оператора не установлен. Пожалуйста, установите его в настройках",
"not-configured-operator-user": "Пароли пользователя и оператора не установлены. Пожалуйста, установите их в настройках"
},
"prompt": {
"dirty": "На странице остались несохранённые изменения. Вы действительно хотите покинуть страницу?",
"serial-config-leave": "Процесс поиска устройств будет остановлен. Вы действительно хотите перейти на другую страницу?"
},
"buttons": {
"logout": "Выйти"
},
"roles": {
"user": "Пользователь",
"operator": "Оператор",
"admin": "Администратор"
}
},
"home": {
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/i18n/configurations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"file": "File",
"title": "Title",
"description": "Description",
"notice": "You cannot view this page. You can change",
"access": "access level"
"access-notice": "You don't have enough permissions to view this page"
KraPete marked this conversation as resolved.
Show resolved Hide resolved
},
"buttons": {
"save": "Save"
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/i18n/configurations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"file": "Файл",
"title": "Название",
"description": "Описание",
"notice": "Для просмотра этой страницы необходимо получить соответствующие ",
"access": "права доступа"
"access-notice": "У вас недостаточно прав для просмотра этой страницы"
KraPete marked this conversation as resolved.
Show resolved Hide resolved
},
"buttons": {
"save": "Записать"
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/i18n/devices/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"labels": {
"nothing": "No devices available for this moment.",
"delete": "Delete device",
"notice": "You cannot view this page. You can change",
"access": "access level"
"access-notice": "You don't have enough permissions to view this page"
},
"prompt": {
"delete": "Remove {{name}}?"
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/i18n/devices/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"labels": {
"nothing": "Нет устройств, доступных для отображения.",
"delete": "Удалить устройство",
"notice": "Для просмотра этой страницы необходимо получить соответствующие ",
"access": "права доступа"
"access-notice": "У вас недостаточно прав для просмотра этой страницы"
},
"prompt": {
"delete": "Удалить {{name}}?"
Expand Down
Loading