@iobroker/js-controller-common
Advanced tools
Comparing version 4.0.0-alpha.6-20210908-7ef2f01b to 4.0.0-alpha.60-20220129-2fc569f3
@@ -6,2 +6,2 @@ module.exports = { | ||
logger: require('./lib/common/logger') | ||
}; | ||
}; |
@@ -48,4 +48,6 @@ 'use strict'; | ||
CANNOT_UPDATE_LICENSE: 46, | ||
CANNOT_DELETE_DEPENDENCY: 47, | ||
CANNOT_GET_STATES: 50, | ||
ADAPTER_ALREADY_INSTALLED: 51, | ||
CANNOT_RESTORE_BACKUP: 52, | ||
CONTROLLER_RUNNING: 99, | ||
@@ -55,3 +57,4 @@ CONTROLLER_NOT_RUNNING: 100, | ||
CANNOT_GET_REPO_LIST: 102, | ||
START_IMMEDIATELY_AFTER_STOP: 156 | ||
START_IMMEDIATELY_AFTER_STOP: 156, | ||
FILE_NOT_FOUND: 404 | ||
}; | ||
@@ -58,0 +61,0 @@ // Allow reverse lookup (exit code -> error name) |
@@ -7,12 +7,12 @@ /* jshint -W097 */ | ||
const winston = require('winston'); | ||
const DailyRotateFile = require('winston-daily-rotate-file'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
const tools = require('./tools'); | ||
const hostname = tools.getHostName(); | ||
const Transport = require('winston-transport'); | ||
const {LEVEL} = require('triple-beam'); | ||
const deepClone = require('deep-clone'); | ||
const winston = require('winston'); | ||
const DailyRotateFile = require('winston-daily-rotate-file'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
const tools = require('./tools'); | ||
const hostname = tools.getHostName(); | ||
const Transport = require('winston-transport'); | ||
const { LEVEL } = require('triple-beam'); | ||
const deepClone = require('deep-clone'); | ||
@@ -28,3 +28,3 @@ let SysLog; | ||
try { | ||
Seq = require('winston-seq-updated').default; | ||
Seq = require('@datalust/winston-seq').SeqTransport; | ||
} catch { | ||
@@ -35,67 +35,66 @@ //console.log('No seq support'); | ||
// We must check if SysLog is defined before extending it | ||
const IoSysLog = SysLog && class extends SysLog { | ||
constructor(options) { | ||
super(options); | ||
} | ||
log(info, callback) { | ||
// we need to map the ioBroker loglevels to the Syslog ones | ||
const ioInfo = info; | ||
if (ioInfo[LEVEL] === 'warn') { | ||
ioInfo[LEVEL] = 'warning'; | ||
const IoSysLog = | ||
SysLog && | ||
class extends SysLog { | ||
constructor(options) { | ||
super(options); | ||
} | ||
if (ioInfo[LEVEL] === 'info') { | ||
ioInfo[LEVEL] = 'notice'; | ||
} | ||
if (ioInfo[LEVEL] === 'debug') { | ||
ioInfo[LEVEL] = 'info'; | ||
} | ||
if (ioInfo[LEVEL] === 'silly') { | ||
ioInfo[LEVEL] = 'debug'; | ||
} | ||
super.log(ioInfo, callback); | ||
} | ||
}; | ||
// We want to enhance some data for Seq | ||
const IoSeq = Seq && class extends Seq { | ||
constructor(options) { | ||
options.levelMapper = options.levelMapper || function (level) { | ||
level = (level || '').toLowerCase(); | ||
if (level.includes('error')) { | ||
return 'Error'; | ||
log(info, callback) { | ||
// we need to map the ioBroker loglevels to the Syslog ones | ||
const ioInfo = info; | ||
if (ioInfo[LEVEL] === 'warn') { | ||
ioInfo[LEVEL] = 'warning'; | ||
} | ||
if (level.includes('warn')) { | ||
return 'Warning'; | ||
if (ioInfo[LEVEL] === 'info') { | ||
ioInfo[LEVEL] = 'notice'; | ||
} | ||
if (level.includes('info')) { | ||
return 'Information'; | ||
if (ioInfo[LEVEL] === 'debug') { | ||
ioInfo[LEVEL] = 'info'; | ||
} | ||
if (level.includes('debug')) { | ||
return 'Debug'; | ||
if (ioInfo[LEVEL] === 'silly') { | ||
ioInfo[LEVEL] = 'debug'; | ||
} | ||
if (level.includes('silly')) { | ||
return 'Verbose'; | ||
super.log(ioInfo, callback); | ||
} | ||
}; | ||
// We want to enhance some data for Seq | ||
const IoSeq = | ||
Seq && | ||
class extends Seq { | ||
log(info, callback) { | ||
const ioInfo = info; | ||
ioInfo.props = ioInfo.props || {}; | ||
// map our log levels to Seq levels | ||
const level = (info.level || '').toLowerCase(); | ||
if (level.includes('error')) { | ||
info.level = 'Error'; | ||
} else if (level.includes('warn')) { | ||
info.level = 'Warning'; | ||
} else if (level.includes('info')) { | ||
info.level = 'Information'; | ||
} else if (level.includes('debug')) { | ||
info.level = 'Debug'; | ||
} else if (level.includes('silly')) { | ||
info.level = 'Verbose'; | ||
} else { | ||
info.level = 'Information'; | ||
} | ||
return 'Information'; | ||
}; | ||
super(options); | ||
} | ||
log(info, callback) { | ||
const ioInfo = info; | ||
ioInfo.meta = ioInfo.meta || {}; | ||
// we add own properties | ||
ioInfo.meta.Hostname = tools.getHostName(); | ||
const msgParts = ioInfo.message.match(/^([^.]+\.[0-9]+) \(([^)]+)\) (.*)$/); | ||
if (msgParts) { | ||
ioInfo.meta.Source = msgParts[1]; | ||
ioInfo.meta.Pid = msgParts[2]; | ||
} else { | ||
ioInfo.meta.Source = 'js-controller'; | ||
// we add own properties | ||
ioInfo.props.Hostname = tools.getHostName(); | ||
if (ioInfo.message) { | ||
const msgParts = ioInfo.message.match(/^([^.]+\.[0-9]+) \(([^)]+)\) (.*)$/); | ||
if (msgParts) { | ||
ioInfo.props.Source = msgParts[1]; | ||
ioInfo.props.Pid = msgParts[2]; | ||
} else { | ||
ioInfo.props.Source = 'js-controller'; | ||
} | ||
} | ||
super.log(ioInfo, callback); | ||
} | ||
super.log(ioInfo, callback); | ||
} | ||
}; | ||
}; | ||
@@ -132,4 +131,3 @@ // Class used to inform adapter about new log entry | ||
const formatter = info => | ||
`${timestamp(info.timestamp)} - ${info.level}: ${info.message}`; | ||
const formatter = info => `${timestamp(info.timestamp)} - ${info.level}: ${info.message}`; | ||
@@ -139,3 +137,6 @@ files = files || []; | ||
// indicator which is used to determine the log dir for developing, where it should be inside the repository | ||
const isNpm = !__dirname.replace(/\\/g, '/').toLowerCase().includes(tools.appName.toLowerCase() + `.js-controller/packages/`); | ||
const isNpm = !__dirname | ||
.replace(/\\/g, '/') | ||
.toLowerCase() | ||
.includes(tools.appName.toLowerCase() + `.js-controller/packages/`); | ||
@@ -145,8 +146,8 @@ if (typeof level === 'object') { | ||
level = userOptions.level; | ||
prefix = userOptions.prefix; | ||
level = userOptions.level; | ||
prefix = userOptions.prefix; | ||
noStdout = userOptions.noStdout; | ||
const winstonFormats = []; | ||
winstonFormats.push(winston.format.timestamp({format: timestamp})); | ||
winstonFormats.push(winston.format.timestamp({ format: timestamp })); | ||
if (userOptions.json === undefined || userOptions.json) { | ||
@@ -169,9 +170,12 @@ winstonFormats.push(winston.format.json()); | ||
let fName = 0; | ||
const isWindows = os.platform().match(/^win/); | ||
const isWindows = os.platform().startsWith('win'); | ||
Object.keys(userOptions.transport).forEach(f => { | ||
const transport = userOptions.transport[f]; | ||
transport._defaultConfigLoglevel = transport.level; // remember Loglevel if set | ||
transport.level = transport.level || level; | ||
if (transport.type === 'file' && transport.enabled !== false) { | ||
transport.filename = transport.filename || 'log/' + tools.appName; | ||
transport.filename = transport.filename || ('log/' + tools.appName); | ||
if (!transport.fileext && transport.filename.indexOf('.log') === -1) { | ||
@@ -186,35 +190,42 @@ transport.fileext = '.log'; | ||
transport.handleExceptions = false; | ||
transport.name = !fName ? tools.appName : 'dailyRotateFile' + fName; | ||
transport.name = !fName ? tools.appName : 'dailyRotateFile' + fName; | ||
fName++; | ||
transport.filename = transport.filename.replace(/\\/g, '/'); | ||
transport.filename = transport.filename.replace(/\\/g, '/'); | ||
if (transport.filename.match(/^\w:\/|^\//)) { | ||
transport.filename = path.normalize(transport.filename); | ||
} else { | ||
const _path = path.normalize(`${tools.getControllerDir()}${isNpm ? '/../../' : '/'}${transport.filename}`); | ||
/* | ||
if (_path.indexOf('js-controller') !== -1 && isNpm) { | ||
_path = path.normalize(`${__dirname}/../../${transport.filename}`); | ||
} | ||
*/ | ||
transport.filename = _path; | ||
transport.filename = path.normalize( | ||
`${tools.getControllerDir()}${isNpm ? '/../../' : '/'}${transport.filename}` | ||
); | ||
} | ||
transport.auditFile = transport.filename + '-audit.json'; | ||
transport.auditFile = transport.filename + '-audit.json'; | ||
transport.createSymlink = (transport.createSymlink !== undefined) ? transport.createSymlink : !isWindows; | ||
transport.symlinkName = (transport.symlinkName !== undefined) ? transport.symlinkName : (path.basename(transport.filename + '.current.log')); | ||
transport.createSymlink = | ||
transport.createSymlink !== undefined ? transport.createSymlink : !isWindows; | ||
transport.symlinkName = | ||
transport.symlinkName !== undefined | ||
? transport.symlinkName | ||
: path.basename(transport.filename + '.current.log'); | ||
transport.filename += '.%DATE%' + (transport.fileext || ''); | ||
transport.filename += '.%DATE%' + (transport.fileext || ''); | ||
//transport.label = prefix || ''; //TODO format.label() | ||
transport.level = transport.level || level; | ||
// transport.json = (transport.json !== undefined) ? transport.json : false; // TODO format.json(), new Default!! | ||
transport.silent = (transport.silent !== undefined) ? transport.silent : false; | ||
transport.silent = transport.silent !== undefined ? transport.silent : false; | ||
// transport.colorize = (transport.colorize !== undefined) ? transport.colorize : ((userOptions.colorize === undefined) ? true : userOptions.colorize); //TODO format.colorize() | ||
transport.localTime = (transport.localTime !== undefined) ? transport.localTime : ((userOptions.localTime === undefined) ? true : userOptions.localTime); | ||
transport.datePattern = 'YYYY-MM-DD'; | ||
transport.format = winston.format.combine(winston.format.printf(formatter)); | ||
transport.localTime = | ||
transport.localTime !== undefined | ||
? transport.localTime | ||
: userOptions.localTime === undefined | ||
? true | ||
: userOptions.localTime; | ||
transport.datePattern = 'YYYY-MM-DD'; | ||
transport.format = winston.format.combine(winston.format.printf(formatter)); | ||
/*transport.logException = function (message, info, next, err) { | ||
console.error(message); | ||
};*/ | ||
transport.zippedArchive = isWindows ? false: (transport.zippedArchive !== undefined ? transport.zippedArchive : true); | ||
transport.zippedArchive = isWindows | ||
? false | ||
: transport.zippedArchive !== undefined | ||
? transport.zippedArchive | ||
: true; | ||
@@ -264,3 +275,3 @@ if (transport.maxFiles === null && userOptions.maxDays) { | ||
} catch (err) { | ||
console.log(`Cannot activate Syslog: ${err}`); | ||
console.log(`Cannot activate Syslog: ${err.message}`); | ||
} | ||
@@ -280,3 +291,3 @@ } else if (transport.type === 'http' && transport.enabled !== false) { | ||
} catch (err) { | ||
console.log('Cannot activate HTTP: ' + err); | ||
console.log(`Cannot activate HTTP: ${err.message}`); | ||
} | ||
@@ -296,3 +307,3 @@ } else if (transport.type === 'stream' && transport.enabled !== false) { | ||
transport.stream.on('error', err => { | ||
console.log('Error in Stream: ' + err); | ||
console.log(`Error in Stream: ${err}`); | ||
}); | ||
@@ -315,9 +326,9 @@ } | ||
try { | ||
transport.onError = e => { | ||
console.log(`SEQ error: ${e}`); | ||
}; | ||
const seqLogger = new IoSeq(transport); | ||
seqLogger.on('error', error => { | ||
console.log(`SEQ error: ${error}`); | ||
}); | ||
options.transports.push(seqLogger); | ||
} catch (err) { | ||
console.log(`Cannot activate SEQ: ${err}`); | ||
console.log(`Cannot activate SEQ: ${err.message}`); | ||
} | ||
@@ -333,10 +344,12 @@ } else { | ||
const opt = { | ||
name: i ? 'dailyRotateFile' + i : tools.appName, | ||
filename: path.normalize(isNpm ? `${__dirname}/../../../log/${files[i]}` : `${__dirname}/../log/${files[i]}`), | ||
extension: '.log', | ||
datePattern: 'YYYY-MM-DD', | ||
name: i ? 'dailyRotateFile' + i : tools.appName, | ||
filename: path.normalize( | ||
isNpm ? `${__dirname}/../../../log/${files[i]}` : `${__dirname}/../log/${files[i]}` | ||
), | ||
extension: '.log', | ||
datePattern: 'YYYY-MM-DD', | ||
//json: false, // If true, messages will be logged as JSON (default true). TODO format.json() | ||
level, | ||
silent: false, | ||
localTime: true, | ||
silent: false, | ||
localTime: true, | ||
//colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize() | ||
@@ -354,17 +367,21 @@ //timestamp: timestamp, // TODO: format.timestamp() | ||
if (!noStdout) { | ||
options.transports.push(new winston.transports.Console({ | ||
level, | ||
silent: false, | ||
format: winston.format.combine(winston.format.printf(formatter)) | ||
//colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize() | ||
//timestamp: timestamp, // TODO: format.timestamp() | ||
//label: prefix || '' // TODO format.label() | ||
})); | ||
options.transports.push( | ||
new winston.transports.Console({ | ||
level, | ||
silent: false, | ||
format: winston.format.combine(winston.format.printf(formatter)) | ||
//colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize() | ||
//timestamp: timestamp, // TODO: format.timestamp() | ||
//label: prefix || '' // TODO format.label() | ||
}) | ||
); | ||
} | ||
// Must be registered, for adapter.js notification about new logs | ||
options.transports.push(new NotifierTransport({ | ||
level, | ||
silent: false | ||
})); | ||
options.transports.push( | ||
new NotifierTransport({ | ||
level, | ||
silent: false | ||
}) | ||
); | ||
@@ -400,3 +417,7 @@ const log = winston.createLogger(options); | ||
this.transports.forEach(transport => { | ||
if (transport.name !=='dailyRotateFile' || !transport.options || transport.options.name !== tools.appName) { | ||
if ( | ||
transport.name !== 'dailyRotateFile' || | ||
!transport.options || | ||
transport.options.name !== tools.appName | ||
) { | ||
return; | ||
@@ -432,6 +453,12 @@ } | ||
this.log({ | ||
level: os.platform().match(/^win/) ? 'info' : 'error', | ||
message: `host.${hostname} Cannot delete file "${path.normalize(transport.dirname + '/' + files[i])}": ${e}` | ||
level: os.platform().startsWith('win') ? 'info' : 'error', | ||
message: `host.${hostname} Cannot delete file "${path.normalize( | ||
transport.dirname + '/' + files[i] | ||
)}": ${e}` | ||
}); | ||
console.log(`host.${hostname} Cannot delete file "${path.normalize(transport.dirname + '/' + files[i])}": ${e}`); | ||
console.log( | ||
`host.${hostname} Cannot delete file "${path.normalize( | ||
transport.dirname + '/' + files[i] | ||
)}": ${e}` | ||
); | ||
} | ||
@@ -509,4 +536,3 @@ } | ||
value = '00' + value; | ||
} else | ||
if (value < 100) { | ||
} else if (value < 100) { | ||
value = '0' + value; | ||
@@ -513,0 +539,0 @@ } |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* 7'2014-2016 Bluefox <dogafox@gmail.com> | ||
* 7'2014-2021 Bluefox <dogafox@gmail.com> | ||
* 2014 hobbyquaker <hq@ccu.io> | ||
@@ -38,4 +38,4 @@ * | ||
const crypto = require('crypto'); | ||
let version = null; | ||
const crypto = require('crypto'); | ||
let version = null; | ||
@@ -45,3 +45,2 @@ const password = pw => { | ||
hash: (salt, iterations, callback) => { | ||
salt = salt || crypto.randomBytes(16).toString('hex'); | ||
@@ -53,3 +52,3 @@ iterations = iterations || 10000; | ||
version = process.version.replace('v', ''); | ||
version = !version.match(/^0\.10\./); | ||
version = !version.startsWith('0.10.'); | ||
} | ||
@@ -73,3 +72,2 @@ | ||
}); | ||
} | ||
@@ -89,13 +87,21 @@ }, | ||
this.hash(key[3], parseInt(key[1], 10), function (error, newHash) { | ||
this.hash(key[3], parseInt(key[1], 10), (error, newHash) => { | ||
if (error) { | ||
return callback(error); | ||
callback(error); | ||
} else { | ||
callback(null, newHash === hashedPassword); | ||
} | ||
callback(null, newHash === hashedPassword); | ||
}); | ||
}, | ||
complexity: _callback => { | ||
// Todo: Check for password complexity | ||
return true; | ||
complexity: (password, callback) => { | ||
let result = false; | ||
if (typeof password === 'string') { | ||
result = | ||
password.length >= 8 && // minimum length is 8 | ||
password.match(/\d/) && // contains at least one digit | ||
password.match(/[a-z]/) && // contains at least one lower case letter | ||
password.match(/[A-Z]/); // contains at least one upper case letter | ||
} | ||
typeof callback === 'function' && callback(result); | ||
return result; // true if the complexity OK | ||
} | ||
@@ -105,2 +111,2 @@ }; | ||
module.exports = password; | ||
module.exports = password; |
{ | ||
"name": "@iobroker/js-controller-common", | ||
"version": "4.0.0-alpha.6-20210908-7ef2f01b", | ||
"version": "4.0.0-alpha.60-20220129-2fc569f3", | ||
"engines": { | ||
@@ -8,11 +8,13 @@ "node": ">=12.0.0" | ||
"optionalDependencies": { | ||
"winston-seq-updated": "^1.0.4", | ||
"@datalust/winston-seq": "^1.0.0", | ||
"winston-syslog": "^2.4.4" | ||
}, | ||
"dependencies": { | ||
"@alcalzone/pak": "^0.6.0", | ||
"@alcalzone/pak": "^0.7.0", | ||
"ci-info": "^3.3.0", | ||
"deep-clone": "^3.0.3", | ||
"event-stream": "^4.0.1", | ||
"fs-extra": "^10.0.0", | ||
"node-forge": "^0.10.0", | ||
"jsonwebtoken": "^8.5.1", | ||
"node-forge": "^1.0.0", | ||
"node.extend": "^2.0.2", | ||
@@ -24,3 +26,3 @@ "promisify-child-process": "^4.1.1", | ||
"winston": "^3.3.3", | ||
"winston-daily-rotate-file": "^4.5.5" | ||
"winston-daily-rotate-file": "^4.6.0" | ||
}, | ||
@@ -50,3 +52,3 @@ "keywords": [ | ||
], | ||
"gitHead": "9d77288dced25b34016640e44d7283efff371126" | ||
"gitHead": "4244d139806c6d96d6d1454a00479b693a22b4e3" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
160466
4040
16
+ Addedci-info@^3.3.0
+ Addedjsonwebtoken@^8.5.1
+ Added@alcalzone/pak@0.7.0(transitive)
+ Added@datalust/winston-seq@1.0.2(transitive)
+ Addedbuffer-equal-constant-time@1.0.1(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedecdsa-sig-formatter@1.0.11(transitive)
+ Addedjsonwebtoken@8.5.1(transitive)
+ Addedjwa@1.4.1(transitive)
+ Addedjws@3.2.2(transitive)
+ Addedlodash.includes@4.3.0(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isinteger@4.0.4(transitive)
+ Addedlodash.isnumber@3.0.3(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.isstring@4.0.1(transitive)
+ Addedlodash.once@4.1.1(transitive)
+ Addednode-forge@1.3.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedseq-logging@1.1.2(transitive)
- Removed@alcalzone/pak@0.6.0(transitive)
- Removednode-forge@0.10.0(transitive)
- Removedseq-logging@0.4.6(transitive)
- Removedwinston-seq-updated@1.0.4(transitive)
Updated@alcalzone/pak@^0.7.0
Updatednode-forge@^1.0.0