Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@iobroker/socket-classes
Advanced tools
This library is used at least for the following adapters:
const TTL_SEC = 3600;
const SocketAdmin = require('@iobroker/socket-classes').SocketAdmin;
const ws = require('@iobroker/ws-server');
const session = require('express-session');
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const AdapterStore = require(utils.controllerDir + '/lib/session.js')(session, TTL_SEC);
const store = new AdapterStore({adapter});
const io = new SocketAdmin(adapter.config, adapter, objects);
io.start(
server,
ws,
{
userKey: 'connect.sid',
store,
secret: adapter.config.secret
}
);
// subscribe on all object changes
io.subscribe('objectChange', '*');
// later
io.close();
const TTL_SEC = 3600;
const ws = require('@iobroker/ws-server');
const SocketWS = require('@iobroker/socket-classes').SocketCommon;
const session = require('express-session');
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const AdapterStore = require(utils.controllerDir + '/lib/session.js')(session, TTL_SEC);
const store = new AdapterStore({adapter});
const settings = adapter.config;
settings.crossDomain = true;
settings.ttl = settings.ttl || TTL_SEC;
const io = new SocketWS(settings, adapter);
io.start(server.server, ws, {userKey: 'connect.sid', checkUser, store, secret: adapter.config.secret});
// later
io.close();
GUI client can send to desired instance the subscribe
message
socket.emit('clientSubscribe', 'cameras.0', 'startCamera', {width: 640, height: 480}, result => console.log('Started: ' + result));
The instance 'cameras.0' will receive message clientSubscribe
with information who want to receive messages.
adapter.on('message', obj => {
if (obj?.command === 'clientSubscribe') {
if (obj?.message.type && obj.message.type.startsWith('startCamera/')) {
const [, camera] = obj.message.type.split('/');
// start camera with obj.message.data
// ...
// inform GUI that camera is started
adapter.sendTo(obj.from, obj.command, {result: true}, obj.callback);
this.subscribes = this.subscribes || [];
this.subscribes.push({sid: obj.message.sid, from: obj.from, type: obj.message.type, camera});
}
} else
if (obj?.command === 'clientUnsubscribe' || obj?.command === 'clientSubscribeError') {
if (obj?.message.type && obj.message.type.startsWith('startCamera/')) {
const [, camera] = obj.message.type.split('/');
if (this.subscribes) {
const pos = this.subscribes.findIndex(s => s.sid === obj.message.sid && s.from === obj.from && s.type === obj.message.type);
if (pos !== -1) {
this.subscribes.splice(pos, 1);
// stop camera
// ...
}
}
}
}
});
and after that client will receive messages from instance
function sendImage(camera, data) {
this.subscribes.forEach(it => {
if (it.camera !== camera) {
return;
}
// send image to GUI
adapter.sendTo(it.from, 'im', {m: it.type, s: it.sid, d: data});
});
}
Authenticate user by login and password
function (isUserAuthenticated, isAuthenticationUsed)
Write error into ioBroker log
Write log entry into ioBroker log
['silly', 'debug', 'info', 'warn', 'error']
. Default is 'debug'.Checks, if the same feature is supported by the current js-controller
CONTROLLER_LICENSE_MANAGER
function (error, isSupported)
Get history data from specific instance
function (error, result)
Read content of HTTP(S) page server-side (without CORS and stuff)
function (error, {status, statusText}, body)
Send the message to specific instance
history.0
function (result)
Send a message to the specific host.
Host can answer to the following commands: cmdExec, getRepository, getInstalled, getInstalledAdapter, getVersion, getDiagData, getLocationOnDisk, getDevList, getLogs, getHostInfo, delLogs, readDirAsZip, writeDirAsZip, readObjectsAsZip, writeObjectsAsZip, checkLogging, updateMultihost
.
history.0
function (result)
Ask server is authentication enabled, and if the user authenticated
function (isAuthenticationUsed, userName)
Logout user
List commands and permissions
function (permissions)
Get user permissions
function (error, permissions)
Get the adapter version. Not the socket-classes version!
function (error, adapterVersion, adapterName)
Get adapter name. Not the socket-classes version!
function (error, adapterVersion)
Get one object
function (error, obj)
Get all objects that are relevant for web: all states and enums with rooms
function (error, obj)
Subscribe to object changes by pattern. The events will come as 'objectChange' events to the socket.
function (error)
Unsubscribe from object changes by pattern.
function (error)
Make a query to the object database.
custom
, but it must exist object _design/custom
. Too 99,9% use system
.state
, instance
, adapter
, host
, ...{startkey: 'system.adapter.', endkey?: 'system.adapter.\u9999', depth?: number}
function (error)
Set object.
function (error)
Delete object. Only deletion of flot objects is allowed
function (error)
Client informs specific instance about subscription on its messages. After subscription the socket will receive "im" messages from desired instance
function (error, result)
, target instance MUST acknowledge the subscription and return some object as resultClient unsubscribes from specific instance's messages
function (error, wasSubscribed)
, target instance MUST NOT acknowledge the un-subscriptionRead states by pattern
system.adapter.*
or array of state IDsfunction (error, states)
, where states
is an object like {'system.adapter.history.0': {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}, 'system.adapter.history.1': {...}}}
Read all states (which might not belong to this adapter) which match the given pattern
system.adapter.*
or array of state IDsfunction (error)
Read one state.
function (error, state)
, where state
is an object like {val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}
Write one state.
{val: 123, ack: true}
function (error, state)
, where state
is an object like {val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}
Read one binary state.
function (error, base64)
Write one binary state.
function (error)
Subscribe to state changes by pattern. The events will come as 'stateChange' events to the socket.
function (error)
Subscribe to state changes by pattern. Same as subscribe
. The events will come as 'stateChange' events to the socket.
function (error)
Unsubscribe from state changes by pattern.
function (error)
Unsubscribe from state changes by pattern. Same as unsubscribe
.
function (error)
Read file from ioBroker DB
vis.0
main/vis-views.json
function (error, data, mimeType)
Read file from ioBroker DB as base64 string
vis.0
main/vis-views.json
function (error, base64, mimeType)
Write file into ioBroker DB as base64 string
vis.0
main/vis-views.json
{mode: 0x0644}
function (error)
Write file into ioBroker DB as text DEPRECATED
vis.0
main/vis-views.json
{mode: 0x644}
function (error)
Delete file in ioBroker DB
vis.0
main/vis-views.json
function (error)
Delete file in ioBroker DB (same as unlink, but only for files)
vis.0
main/vis-views.json
function (error)
Delete file in ioBroker DB (same as unlink, but only for folders)
vis.0
main
function (error)
Rename file in ioBroker DB
vis.0
main/vis-views.json
main/vis-views-new.json
function (error)
Rename file or folder in ioBroker DB
vis.0
main/vis-views.json
main/vis-views-new.json
function (error)
Create folder in ioBroker DB
vis.0
main
function (error)
Read content of folder in ioBroker DB
vis.0
main
{filter: '*'}
or {filter: '*.json'}
function (error, files)
where files
is an array of objects, like {file: 'vis-views.json', isDir: false, stats: {size: 123}, modifiedAt: 1661336290090, acl: {owner: 'system.user.admin', ownerGroup: 'system.group.administrator', permissions: 1632, read: true, write: true}
Change file mode in ioBroker DB
vis.0
main/vis-views.json
{mode: 0x644}
or 0x644. The first digit is user, second group, third others. Bit 1 is execute
, bit 2 is write
, bit 3 is read
function (error)
Change file owner in ioBroker DB
vis.0
main/vis-views.json
{owner: 'system.user.user', ownerGroup: ''system.group.administrator'}
or 'system.user.user'. If ownerGroup is not defined, it will be taken from owner.function (error)
Check if the file or folder exists in ioBroker DB
vis.0
main/vis-views.json
function (error, isExist)
Subscribe to file changes in ioBroker DB
vis.0
or any object ID of type meta
. id
could have wildcards *
too.main/*.json
function (error)
Unsubscribe from file changes in ioBroker DB
vis.0
or any object ID of type meta
. id
could have wildcards *
too.main/*.json
function (error)
Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
history
.function (error, instanceList)
, where instanceList is an array of instance objects, e.g. {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}}
Authenticate user by login and password
function (isUserAuthenticated, isAuthenticationUsed)
Write error into ioBroker log
Write log entry into ioBroker log
['silly', 'debug', 'info', 'warn', 'error']
. Default is 'debug'.Checks, if the same feature is supported by the current js-controller
CONTROLLER_LICENSE_MANAGER
function (error, isSupported)
Get history data from specific instance
function (error, result)
Read content of HTTP(S) page server-side (without CORS and stuff)
function (error, {status, statusText}, body)
Send the message to specific instance
history.0
function (result)
Send a message to the specific host.
Host can answer to the following commands: cmdExec, getRepository, getInstalled, getInstalledAdapter, getVersion, getDiagData, getLocationOnDisk, getDevList, getLogs, getHostInfo, delLogs, readDirAsZip, writeDirAsZip, readObjectsAsZip, writeObjectsAsZip, checkLogging, updateMultihost
.
history.0
function (result)
Ask server is authentication enabled, and if the user authenticated
function (isAuthenticationUsed, userName)
Logout user
List commands and permissions
function (permissions)
Get user permissions
function (error, permissions)
Get the adapter version. Not the socket-classes version!
function (error, adapterVersion, adapterName)
Get adapter name. Not the socket-classes version!
function (error, adapterVersion)
Read the host object by IP address
function (ip, obj)
. If host is not found, obj is nullActivate or deactivate logging events. Events will be sent to the socket as log
event. Adapter must have common.logTransporter = true
function (error)
Get logs file from given host
function (error, files)
, where files
is array of {fileName:
log/hostname/transport/file, size: 123}
Delete state. The corresponding object will be deleted too.
function (error)
Execute the shell command on host/controller. Following response commands are expected: ´cmdStdout, cmdStderr, cmdExit´
Date.now()´. This session ID will come in events
cmdStdout, cmdStderr, cmdExit`function (error)
Used only for admin to the limited number of events to front-end.
Read ratings of adapters
function (error, ratings)
, where ratings
is object like {accuweather: {rating: {r: 3.33, c: 3}, 1.2.1: {r: 3, c: 1}},…}
Return current instance name like admin.0
function (error, namespace)
Decrypts text with the system secret key
function (error, decryptedText)
Encrypts text with the system secret key
function (error, encryptedText)
Returns if admin has easy mode enabled
function (error, isEasyModeStrict)
Get easy mode configuration
function (error, easyModeConfig)
, where easyModeConfig
is object like {strict: true, configs: [{_id: 'system.adapter.javascript.0', common: {...}}, {...}]}
Read all adapters objects
function (error, results)
, where results
is array of objects like {_id: 'system.adapter.javascript', common: {...}}
Read software licenses (vis, knx, ...) from ioBroker.net cloud for given user
function (error, results)
, where results
is array of objects like [{"json":"xxx","id":"ab","email":"dogafox@gmail.com","product":"iobroker.knx.year","version":"2","invoice":"Pxx","uuid":"uuid","time":"2021-11-16T19:53:02.000Z","validTill":"2022-11-16T22:59:59.000Z","datapoints":1000}]
Read all instances in short form to save bandwidth
function (error, results)
, where results
is an object like {'system.adapter.javascript.0': {adminTab, name, icon, enabled}}
Read all adapters in short for to save bandwidth
function (error, results)
, where results
is an object like {'javascript': {icon, v: '1.0.1', iv: 'ignoredVersion}}
Read all installed adapters in short form to save bandwidth
function (error, results)
, where results
is an object like `{'javascript': {version: '1.0.1'}}``Read system config in short form to save bandwidth
function (error, systemConfig)
, where systemConfig
is an object like {common: {...}, native: {secret: 'aaa'}}
Read repositories from cache in short form to save bandwidth
function (error, repositories)
, where repositories
is an object like {_id: 'system.repositories', common: {...}, native: {repositories: {default: {json: {_repoInfo: {...}}}}}}
Read current repository in short form to save bandwidth
function (error, repository)
, where repository
is an object like {'javascript': {version: '1.0.1', icon}, 'admin': {version: '1.0.1', icon}}
Read all hosts in short form to save bandwidth
function (error, hosts)
, where hosts
is an array of objects like [{_id:'system.host.raspi',common:{name:'raspi',icon:'icon',color:'blue',installedVersion:'2.1.0'},native:{hardware:{networkInterfaces:[...]}}}]
Add new user
benjamin
function (error)
Delete existing user. Admin cannot be deleted.
function (error)
Add a new group.
{"object":{"list":true,"read":true,"write":false,"delete":false},"state":{"list":true,"read":true,"write":true,"create":true,"delete":false},"users":{"list":true,"read":true,"write":false,"create":false,"delete":false},"other":{"execute":false,"http":true,"sendto":false},"file":{"list":true,"read":true,"write":false,"create":false,"delete":false}}
function (error)
Delete the existing group. Administrator group cannot be deleted.
function (error)
Change user password
function (error)
Get one object
function (error, obj)
Read absolutely all objects. Same as getAllObjects
.
function (error, objects)
, where objects
is an object like {'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}
Subscribe to object changes by pattern. The events will come as 'objectChange' events to the socket.
function (error)
Unsubscribe from object changes by pattern.
function (error)
Make a query to the object database.
custom
, but it must exist object _design/custom
. Too 99,9% use system
.state
, instance
, adapter
, host
, ...{startkey: 'system.adapter.', endkey?: 'system.adapter.\u9999', depth?: number}
function (error)
Set object.
function (error)
Delete an object or objects recursively. Objects with dontDelete
cannot be deleted.
{recursive: true}
function (error)
Client informs specific instance about subscription on its messages. After subscription the socket will receive "im" messages from desired instance
function (error, result)
, target instance MUST acknowledge the subscription and return some object as resultClient unsubscribes from specific instance's messages
function (error, wasSubscribed)
, target instance MUST NOT acknowledge the un-subscriptionRead absolutely all objects
function (error, objects)
, where objects
is an object like {'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}
Extend the existing object
{common: {name: 'new name'}}
function (error)
Read objects by pattern
system.adapter.admin.0.*
state
, channel
, device
, host
, adapter
. Default - state
function (error, objects)
, where objects
is an object like {'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}
Delete objects recursively. Objects with dontDelete
cannot be deleted. Same as delObject
but with recursive: true
.
function (error)
Read states by pattern
system.adapter.*
or array of state IDsfunction (error, states)
, where states
is an object like {'system.adapter.history.0': {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}, 'system.adapter.history.1': {...}}}
Read all states (which might not belong to this adapter) which match the given pattern
system.adapter.*
or array of state IDsfunction (error)
Read one state.
function (error, state)
, where state
is an object like {val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}
Write one state.
{val: 123, ack: true}
function (error, state)
, where state
is an object like {val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}
Read one binary state.
function (error, base64)
Write one binary state.
function (error)
Subscribe to state changes by pattern. The events will come as 'stateChange' events to the socket.
function (error)
Subscribe to state changes by pattern. Same as subscribe
. The events will come as 'stateChange' events to the socket.
function (error)
Unsubscribe from state changes by pattern.
function (error)
Unsubscribe from state changes by pattern. Same as unsubscribe
.
function (error)
Read file from ioBroker DB
vis.0
main/vis-views.json
function (error, data, mimeType)
Read file from ioBroker DB as base64 string
vis.0
main/vis-views.json
function (error, base64, mimeType)
Write file into ioBroker DB as base64 string
vis.0
main/vis-views.json
{mode: 0x0644}
function (error)
Write file into ioBroker DB as base64 string
vis.0
main/vis-views.json
{mode: 0x0644}
function (error)
Delete file in ioBroker DB
vis.0
main/vis-views.json
function (error)
Delete file in ioBroker DB (same as unlink, but only for files)
vis.0
main/vis-views.json
function (error)
Delete file in ioBroker DB (same as unlink, but only for folders)
vis.0
main
function (error)
Rename file in ioBroker DB
vis.0
main/vis-views.json
main/vis-views-new.json
function (error)
Rename file or folder in ioBroker DB
vis.0
main/vis-views.json
main/vis-views-new.json
function (error)
Create folder in ioBroker DB
vis.0
main
function (error)
Read content of folder in ioBroker DB
vis.0
main
{filter: '*'}
or {filter: '*.json'}
function (error, files)
where files
is an array of objects, like {file: 'vis-views.json', isDir: false, stats: {size: 123}, modifiedAt: 1661336290090, acl: {owner: 'system.user.admin', ownerGroup: 'system.group.administrator', permissions: 1632, read: true, write: true}
Change file mode in ioBroker DB
vis.0
main/vis-views.json
{mode: 0x644}
or 0x644. The first digit is user, second group, third others. Bit 1 is execute
, bit 2 is write
, bit 3 is read
function (error)
Change file owner in ioBroker DB
vis.0
main/vis-views.json
{owner: 'system.user.user', ownerGroup: ''system.group.administrator'}
or 'system.user.user'. If ownerGroup is not defined, it will be taken from owner.function (error)
Check if the file or folder exists in ioBroker DB
vis.0
main/vis-views.json
function (error, isExist)
Subscribe to file changes in ioBroker DB
vis.0
or any object ID of type meta
. id
could have wildcards *
too.main/*.json
function (error)
Unsubscribe from file changes in ioBroker DB
vis.0
or any object ID of type meta
. id
could have wildcards *
too.main/*.json
function (error)
Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
history
.function (error, instanceList)
, where instanceList is an array of instance objects, e.g. {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}}
getCompactInstances
method with version informationadapter-core
versionpublishInstanceMessageAll
commandname
json5
as json
getObjects
for web was extended by devices, channels and enumsdelObjects
methodgetCompactSystemRepositories
passport
writeDirAsZip
writeDirAsZip
locallygetObjects
commanddelObjects
commanddelObject
commandThe MIT License (MIT)
Copyright (c) 2020-2024 @GermanBluefox dogafox@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
ioBroker server-side web sockets
We found that @iobroker/socket-classes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.