Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var seriesBufferChecker = null;
var seriesBufferCounter = 0;
var seriesBufferFlushPlanned = false;
var seriesBuffer = {};
var conflictingPoints = {};
var errorPoints = {};
var tasksStart = [];
var connected = null;
var finished = false;
var aliasMap = {};
function getAppName() {
const parts = __dirname.replace(/\\/g, '/').split('/');
return parts[parts.length - 1].split('.')[0];
}
utils.appName = getAppName();
var adapter = utils.Adapter('influxdb');
adapter.on('objectChange', function (id, obj) {
var formerAliasId = aliasMap[id] ? aliasMap[id] : id;
if (obj && obj.common &&
(
// todo remove history sometime (2016.08) - Do not forget object selector in io-package.json
(obj.common.history && obj.common.history[adapter.namespace] && obj.common.history[adapter.namespace].enabled) ||
(obj.common.custom && obj.common.custom[adapter.namespace] && obj.common.custom[adapter.namespace].enabled)
)
) {
var realId = id;
var checkForRemove = true;
if (obj.common.custom && obj.common.custom[adapter.namespace] && obj.common.custom[adapter.namespace].aliasId) {
if (obj.common.custom[adapter.namespace].aliasId !== id) {
let lang = 'en';
let extensions = {};
let bruteForce = {};
let socketIoFile = null;
let webPreSettings = {};
let webByVersion = {};
let loginPage = null;
const FORBIDDEN_CHARS = /[\]\[*,;'"`<>\\\s?]/g; // with space
let redirectLink = '';
function getAppName() {
const parts = __dirname.replace(/\\/g, '/').split('/');
return parts[parts.length - 1].split('.')[0];
}
utils.appName = getAppName();
// copied from here: https://github.com/component/escape-html/blob/master/index.js
const matchHtmlRegExp = /["'&<>]/;
function escapeHtml (string) {
const str = '' + string;
const match = matchHtmlRegExp.exec(str);
if (!match) {
return str;
}
let escape;
let html = '';
let index;
let lastIndex = 0;
extAPI = require(__dirname + '/' + parts.join('/'));
} else {
extAPI = require(utils.appName + '.' + extensions[e].path);
}
extensions[e].obj = new extAPI(server.server, {secure: settings.secure, port: settings.port}, adapter, extensions[e].config, server.app);
adapter.log.info('Connect extension "' + extensions[e].path + '"');
} catch (err) {
adapter.log.error('Cannot start extension "' + e + '": ' + err);
}
}
// Activate integrated simple API
if (settings.simpleapi) {
try {
let SimpleAPI = require(utils.appName + '.simple-api/lib/simpleapi.js');
server.api = new SimpleAPI(server.server, {secure: settings.secure, port: settings.port}, adapter);
} catch (e) {
adapter.log.error('Cannot find simple api module! ' + e);
}
}
if (server.app) {
// deliver web files from objectDB
server.app.use('/', (req, res) => {
let url = decodeURI(req.url);
// remove all ../
// important: Linux does not normalize "\" but fs.readFile accepts it as '/'
url = path.normalize(url.replace(/\\/g, '/')).replace(/\\/g, '/');
// remove '////' at start and let only one
(function _constructor(config) {
const clientId = config.clientId || ((tools.getHostname ? tools.getHostname() : utils.appName) + '.' + adapter.namespace);
const _url = ((!config.ssl) ? 'mqtt' : 'mqtts') + '://' + (config.user ? (config.user + ':' + config.pass + '@') : '') + config.url + (config.port ? (':' + config.port) : '') + '?clientId=' + clientId;
const __url = ((!config.ssl) ? 'mqtt' : 'mqtts') + '://' + (config.user ? (config.user + ':*******************@') : '') + config.url + (config.port ? (':' + config.port) : '') + '?clientId=' + clientId;
adapter.log.info('Try to connect to ' + __url);
client = mqtt.connect(_url, {
keepalive: config.keepalive || 10, /* in seconds */
protocolId: 'MQTT',
protocolVersion: 4,
reconnectPeriod: config.reconnectPeriod || 1000, /* in milliseconds */
connectTimeout: (config.connectTimeout || 30) * 1000, /* in milliseconds */
clean: !config.persistent
});
// By default subscribe on all topics
if (!config.patterns) config.patterns = '#';
if (typeof config.patterns === 'string') {
function connect() {
adapter.log.info('Connecting ' + adapter.config.protocol + '://' + adapter.config.host + ':' + adapter.config.port + ' ...');
adapter.config.dbname = adapter.config.dbname || utils.appName;
adapter.config.seriesBufferMax = parseInt(adapter.config.seriesBufferMax, 10) || 0;
client = influx({
host: adapter.config.host,
port: adapter.config.port, // optional, default 8086
protocol: adapter.config.protocol, // optional, default 'http'
username: adapter.config.user,
password: adapter.config.password,
database: adapter.config.dbname,
timePrecision: 'ms'
});
client.getDatabaseNames(function (err, dbNames) {
if (err) {
adapter.log.error(err);
'use strict';
const mqtt = require('mqtt');
const utils = require('@iobroker/adapter-core');
const tools = require(utils.controllerDir + '/lib/tools');
const state2string = require(__dirname + '/common').state2string;
const convertTopic2id = require(__dirname + '/common').convertTopic2id;
const convertID2topic = require(__dirname + '/common').convertID2topic;
const messageboxRegex = new RegExp('\\.messagebox$');
function getAppName() {
const parts = __dirname.replace(/\\/g, '/').split('/');
return parts[parts.length - 2].split('.')[0];
}
utils.appName = getAppName();
function MQTTClient(adapter, states) {
if (!(this instanceof MQTTClient)) return new MQTTClient(adapter, states);
let client = null;
let topic2id = {};
let id2topic = {};
const namespaceRegEx = new RegExp('^' + adapter.namespace.replace('.', '\\.') + '\\.');
let connected = false;
this.destroy = () => {
if (client) {
client.end();
client = null;
}
};