Skip to content

Commit

Permalink
### 3.6.8 (2019-10-09)
Browse files Browse the repository at this point in the history
* (bluefox) Log paths were sanitized
* (bluefox) NPM packages were updated
  • Loading branch information
GermanBluefox committed Oct 9, 2019
1 parent 9872f45 commit 16b2b32
Show file tree
Hide file tree
Showing 10 changed files with 662 additions and 569 deletions.
13 changes: 7 additions & 6 deletions README.md
@@ -1,6 +1,5 @@
![Logo](admin/admin.png)
# ioBroker.admin
===================

[![NPM version](http://img.shields.io/npm/v/iobroker.admin.svg)](https://www.npmjs.com/package/iobroker.admin)
[![Downloads](https://img.shields.io/npm/dm/iobroker.admin.svg)](https://www.npmjs.com/package/iobroker.admin)
Expand All @@ -9,11 +8,9 @@

[![NPM](https://nodei.co/npm/iobroker.admin.png?downloads=true)](https://nodei.co/npm/iobroker.admin/)


User interface for configuration and administration.
User interface for configuration and administration of ioBroker.

## Using common.localLink

- %ip% - ioBroker ip address (address of the admin)
- %secure% or %protocol% - read from native.secure the value and use http or https
- %web_protocol% - looking for the first instance of web (e.g. web.0) and get "native.secure" from "system.adapter.web.0"
Expand Down Expand Up @@ -82,6 +79,10 @@ This project uses some icons from [Flaticon](https://www.flaticon.com/):
- <img src="src/img/rooms/toilet.svg" height="48" /> - Icons made by [Freepik](http://www.freepik.com) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)

## Changelog
### 3.6.8 (2019-10-09)
* (bluefox) Log paths were sanitized
* (bluefox) NPM packages were updated

### 3.6.7 (2019-09-24)
* (ldittmar) Add Node.JS version check to popup messages

Expand Down Expand Up @@ -276,7 +277,7 @@ This project uses some icons from [Flaticon](https://www.flaticon.com/):

### 3.0.11 (2018-01-11)
* (DeepCoreSystem) French update
* (bluefox) fix error with empty ID
* (bluefox) fix error with empty ID
* (bluefox) add sort by "recently updated"
* (ldittmar) add readme and issues viewer

Expand All @@ -287,7 +288,7 @@ This project uses some icons from [Flaticon](https://www.flaticon.com/):

### 3.0.7 (2018-01-01)
* (soef) update instances, objects and other lists
* (bluefox) rewrite interface with materialize
* (bluefox) rewrite interface with materialize

### 2.0.11 (2017-10-23)
* (bluefox) Configurable event update disable threshold
Expand Down
10 changes: 5 additions & 5 deletions gulpfile.js
Expand Up @@ -493,13 +493,13 @@ gulp.task('materializeJS', () => {
.pipe(concat('materialize.js'))
.pipe(babel({
plugins: [
'transform-es2015-arrow-functions',
'transform-es2015-block-scoping',
'transform-es2015-classes',
'transform-es2015-template-literals'
'@babel/plugin-transform-arrow-functions',
'@babel/plugin-transform-block-scoping',
'@babel/plugin-transform-classes',
'@babel/plugin-transform-template-literals'
]
}))
.pipe(uglify())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./www/lib/js'));
});
Expand Down
19 changes: 15 additions & 4 deletions io-package.json
Expand Up @@ -2,7 +2,7 @@
"common": {
"name": "admin",
"title": "Admin",
"version": "3.6.7",
"version": "3.6.8",
"news": {
"3.6.7": {
"en": "Add Node.JS version check to popup messages",
Expand All @@ -16,7 +16,18 @@
"pl": "Dodaj sprawdzanie wersji Node.JS do wyskakujących wiadomości",
"zh-cn": "将Node.JS版本检查添加到弹出消息"
},
"3.6.6": {
"3.6.7": {
"en": "Add Node.JS version check to popup messages",
"de": "Node.JS-Versionsprüfung zu Popup-Nachrichten hinzufügen",
"ru": "Добавить проверку версии Node.JS во всплывающие сообщения",
"pt": "Adicione a verificação da versão do Node.JS às mensagens pop-up",
"nl": "Voeg Node.JS versiecontrole toe aan pop-upberichten",
"fr": "Ajouter la vérification de la version de Node.JS aux messages contextuels",
"it": "Aggiungi il controllo versione Node.JS ai messaggi popup",
"es": "Agregar verificación de versión de Node.JS a mensajes emergentes",
"pl": "Dodaj sprawdzanie wersji Node.JS do wyskakujących wiadomości",
"zh-cn": "将Node.JS版本检查添加到弹出消息"
},"3.6.6": {
"en": "update some words translation",
"de": "Aktualisieren Sie einige Wörter Übersetzung",
"ru": "обновить перевод некоторых слов",
Expand Down Expand Up @@ -87,7 +98,7 @@
"es": "Integración del adaptador de información",
"pl": "Integracja adaptera informacyjnego",
"zh-cn": "信息适配器集成"
},
},
"3.6.0": {
"en": "Added Chinese translations\nNew informative states added about updates",
"de": "Chinesische Übersetzungen hinzugefügt\nNeue Informationsstände zu Updates hinzugefügt",
Expand Down Expand Up @@ -162,7 +173,7 @@
"fr": "docs/fr/admin.md",
"it": "docs/it/admin.md",
"pl": "docs/pl/admin.md",
"zh-cn": "docs/zh-cn/admin.md"
"zh-cn": "docs/zh-cn/admin.md"
},
"materialize": true,
"mode": "daemon",
Expand Down
86 changes: 58 additions & 28 deletions lib/socket.js
Expand Up @@ -9,8 +9,10 @@ const request = require('request');
const path = require('path');
const fs = require('fs');

function IOSocket(server, settings, adapter, objects, states, store) {
if (!(this instanceof IOSocket)) return new IOSocket(server, settings, adapter, objects, states, store);
function IOSocket(server, settings, adapter, objects, store) {
if (!(this instanceof IOSocket)) {
return new IOSocket(server, settings, adapter, objects, store);
}

const userKey = 'connect.sid'; // const
const cmdSessions = {};
Expand All @@ -19,6 +21,7 @@ function IOSocket(server, settings, adapter, objects, states, store) {
this.subscribes = {};
let cookieParser;
let passport;
let states = {};

if (settings.auth) {
cookieParser = require('cookie-parser');
Expand Down Expand Up @@ -433,10 +436,13 @@ function IOSocket(server, settings, adapter, objects, states, store) {

this.unsubscribe = function (socket, type, pattern) {
//console.log((socket._name || socket.id) + ' unsubscribe ' + pattern);
if (!this.subscribes[type]) this.subscribes[type] = {};
this.subscribes[type] = this.subscribes[type] || {};

if (socket) {
if (!socket._subscribe || !socket._subscribe[type]) return;
if (!socket._subscribe || !socket._subscribe[type]) {
return;
}

for (let i = socket._subscribe[type].length - 1; i >= 0; i--) {
if (socket._subscribe[type][i].pattern === pattern) {

Expand Down Expand Up @@ -539,7 +545,7 @@ function IOSocket(server, settings, adapter, objects, states, store) {
adapter.subscribeForeignObjects && adapter.subscribeForeignObjects(pattern);
} else if (type === 'log') {
adapter.log.debug('Subscribe LOGS');
if (adapter.requireLog) adapter.requireLog(true);
adapter.requireLog && adapter.requireLog(true);
}
} else {
that.subscribes[type][pattern]++;
Expand Down Expand Up @@ -692,7 +698,7 @@ function IOSocket(server, settings, adapter, objects, states, store) {
socket.on('getStates', function (callback) {
if (updateSession(socket) && checkPermissions(socket, 'getStates', callback)) {
if (typeof callback === 'function') {
callback(null, states);
adapter.getForeignStates('*', callback);
} else {
adapter.log.warn('[getStates] Invalid callback')
}
Expand All @@ -702,7 +708,11 @@ function IOSocket(server, settings, adapter, objects, states, store) {
socket.on('getState', function (id, callback) {
if (updateSession(socket) && checkPermissions(socket, 'getState', callback, id)) {
if (typeof callback === 'function') {
callback(null, states[id]);
if (states[id]) {
callback(null, states[id]);
} else {
adapter.getForeignState(id, callback);
}
} else {
adapter.log.warn('[getState] Invalid callback')
}
Expand All @@ -711,13 +721,11 @@ function IOSocket(server, settings, adapter, objects, states, store) {

socket.on('getForeignStates', function (pattern, callback) {
if (updateSession(socket) && checkPermissions(socket, 'getStates', callback)) {
adapter.getForeignStates(pattern, function (err, objs) {
if (typeof callback === 'function') {
callback(err, objs);
} else {
adapter.log.warn('[getForeignStates] Invalid callback')
}
});
if (typeof callback === 'function') {
adapter.getForeignStates(pattern, callback);
} else {
adapter.log.warn('[getForeignStates] Invalid callback')
}
}
});

Expand All @@ -727,16 +735,22 @@ function IOSocket(server, settings, adapter, objects, states, store) {
state = {val: state};
}

adapter.setForeignState(id, state, {user: this._acl.user}, function (err, res) {
if (typeof callback === 'function') {
callback(err, res);
}
});
// clear cache
if (states[id]) {
delete states[id];
}

adapter.setForeignState(id, state, {user: this._acl.user}, (err, res) =>
typeof callback === 'function' && callback(err, res));
}
});

socket.on('delState', function (id, callback) {
if (updateSession(socket) && checkPermissions(socket, 'delState', callback, id)) {
// clear cache
if (states[id]) {
delete states[id];
}
adapter.delForeignState(id, {user: this._acl.user}, callback);
}
});
Expand Down Expand Up @@ -965,7 +979,6 @@ function IOSocket(server, settings, adapter, objects, states, store) {
}
});


socket.on('unsubscribe', function (pattern, callback) {
if (updateSession(socket) && checkPermissions(socket, 'unsubscribe', callback, pattern)) {
if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
Expand All @@ -975,10 +988,13 @@ function IOSocket(server, settings, adapter, objects, states, store) {
} else {
that.unsubscribe(this, 'stateChange', pattern);
}
if (adapter.log.level === 'debug') showSubscribes(socket, 'stateChange');
if (typeof callback === 'function') {
setImmediate(callback, null);
}

// reset states cache on unsubscribe
states = {};

adapter.log.level === 'debug' && showSubscribes(socket, 'stateChange');

typeof callback === 'function' && setImmediate(callback, null);
}
});

Expand Down Expand Up @@ -1168,7 +1184,7 @@ function IOSocket(server, settings, adapter, objects, states, store) {
adapter.log.info('Subscribe on all states again');

setTimeout(function () {
if (readAll) {
/*if (readAll) {
adapter.getForeignStates('*', function (err, res) {
adapter.log.info('received all states');
for (const id in res) {
Expand All @@ -1178,11 +1194,14 @@ function IOSocket(server, settings, adapter, objects, states, store) {
}
}
});
}
}*/

that.server.sockets.emit('eventsThreshold', false);
adapter.unsubscribeForeignStates('system.adapter.*');
adapter.subscribeForeignStates('*');

Object.keys(that.subscribes.stateChange).forEach(pattern =>
adapter.subscribeForeignStates(pattern));

}, 50);
}
}
Expand All @@ -1196,7 +1215,10 @@ function IOSocket(server, settings, adapter, objects, states, store) {
eventsThreshold.timeActivated = new Date().getTime();

that.server.sockets.emit('eventsThreshold', true);
adapter.unsubscribeForeignStates('*');

Object.keys(that.subscribes.stateChange).forEach(pattern =>
adapter.unsubscribeForeignStates(pattern));

adapter.subscribeForeignStates('system.adapter.*');
}, 100);
}
Expand Down Expand Up @@ -1240,6 +1262,13 @@ function IOSocket(server, settings, adapter, objects, states, store) {
};

this.stateChange = function (id, state) {
if (!state) {
if (states[id]) {
delete states[id];
}
} else {
states[id] = state;
}
const clients = that.server.sockets.connected;

if (!eventsThreshold.active) {
Expand Down Expand Up @@ -1309,4 +1338,5 @@ function IOSocket(server, settings, adapter, objects, states, store) {

return this;
}

module.exports = IOSocket;

0 comments on commit 16b2b32

Please sign in to comment.