@iobroker/js-controller-cli 7.2.2 → 7.2.3-alpha.1-20260621-61726ea22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/lib/_Types.d.ts +7 -0
- package/build/cjs/lib/cli/cliCert.d.ts +5 -2
- package/build/cjs/lib/cli/cliCert.js +5 -2
- package/build/cjs/lib/cli/cliCert.js.map +2 -2
- package/build/cjs/lib/cli/cliCommand.d.ts +32 -1
- package/build/cjs/lib/cli/cliCommand.js +4 -1
- package/build/cjs/lib/cli/cliCommand.js.map +2 -2
- package/build/cjs/lib/cli/cliCompact.d.ts +4 -1
- package/build/cjs/lib/cli/cliCompact.js +4 -1
- package/build/cjs/lib/cli/cliCompact.js.map +2 -2
- package/build/cjs/lib/cli/cliDebug.d.ts +4 -1
- package/build/cjs/lib/cli/cliDebug.js +4 -1
- package/build/cjs/lib/cli/cliDebug.js.map +2 -2
- package/build/cjs/lib/cli/cliHost.d.ts +8 -5
- package/build/cjs/lib/cli/cliHost.js +8 -5
- package/build/cjs/lib/cli/cliHost.js.map +2 -2
- package/build/cjs/lib/cli/cliLogs.d.ts +4 -1
- package/build/cjs/lib/cli/cliLogs.js +4 -1
- package/build/cjs/lib/cli/cliLogs.js.map +2 -2
- package/build/cjs/lib/cli/cliMessage.d.ts +1 -0
- package/build/cjs/lib/cli/cliMessage.js.map +2 -2
- package/build/cjs/lib/cli/cliObjects.d.ts +12 -9
- package/build/cjs/lib/cli/cliObjects.js +12 -9
- package/build/cjs/lib/cli/cliObjects.js.map +2 -2
- package/build/cjs/lib/cli/cliPlugin.js.map +1 -1
- package/build/cjs/lib/cli/cliProcess.d.ts +4 -0
- package/build/cjs/lib/cli/cliProcess.js +3 -0
- package/build/cjs/lib/cli/cliProcess.js.map +2 -2
- package/build/cjs/lib/cli/cliStates.d.ts +3 -0
- package/build/cjs/lib/cli/cliStates.js +3 -0
- package/build/cjs/lib/cli/cliStates.js.map +2 -2
- package/build/cjs/lib/setup/customError.d.ts +4 -0
- package/build/cjs/lib/setup/customError.js +3 -0
- package/build/cjs/lib/setup/customError.js.map +2 -2
- package/build/cjs/lib/setup/formatters.d.ts +4 -4
- package/build/cjs/lib/setup/formatters.js.map +1 -1
- package/build/cjs/lib/setup/pluginInfos.d.ts +5 -0
- package/build/cjs/lib/setup/pluginInfos.js.map +2 -2
- package/build/cjs/lib/setup/setupBackup.d.ts +34 -0
- package/build/cjs/lib/setup/setupBackup.js +22 -0
- package/build/cjs/lib/setup/setupBackup.js.map +2 -2
- package/build/cjs/lib/setup/setupInstall.d.ts +37 -14
- package/build/cjs/lib/setup/setupInstall.js +28 -14
- package/build/cjs/lib/setup/setupInstall.js.map +2 -2
- package/build/cjs/lib/setup/setupLicense.d.ts +8 -0
- package/build/cjs/lib/setup/setupLicense.js +3 -0
- package/build/cjs/lib/setup/setupLicense.js.map +2 -2
- package/build/cjs/lib/setup/setupList.d.ts +54 -0
- package/build/cjs/lib/setup/setupList.js +51 -0
- package/build/cjs/lib/setup/setupList.js.map +2 -2
- package/build/cjs/lib/setup/setupPacketManager.d.ts +10 -0
- package/build/cjs/lib/setup/setupPacketManager.js +6 -0
- package/build/cjs/lib/setup/setupPacketManager.js.map +2 -2
- package/build/cjs/lib/setup/setupRepo.d.ts +6 -0
- package/build/cjs/lib/setup/setupRepo.js +3 -0
- package/build/cjs/lib/setup/setupRepo.js.map +2 -2
- package/build/cjs/lib/setup/setupSetup.d.ts +27 -0
- package/build/cjs/lib/setup/setupSetup.js +18 -0
- package/build/cjs/lib/setup/setupSetup.js.map +2 -2
- package/build/cjs/lib/setup/setupUpgrade.d.ts +6 -0
- package/build/cjs/lib/setup/setupUpgrade.js +3 -0
- package/build/cjs/lib/setup/setupUpgrade.js.map +2 -2
- package/build/cjs/lib/setup/setupUpload.d.ts +71 -0
- package/build/cjs/lib/setup/setupUpload.js +65 -1
- package/build/cjs/lib/setup/setupUpload.js.map +2 -2
- package/build/cjs/lib/setup/setupUsers.d.ts +23 -14
- package/build/cjs/lib/setup/setupUsers.js +17 -14
- package/build/cjs/lib/setup/setupUsers.js.map +2 -2
- package/build/cjs/lib/setup/setupVendor.d.ts +9 -1
- package/build/cjs/lib/setup/setupVendor.js +4 -1
- package/build/cjs/lib/setup/setupVendor.js.map +2 -2
- package/build/cjs/lib/setup/setupVisDebug.d.ts +9 -0
- package/build/cjs/lib/setup/setupVisDebug.js +3 -0
- package/build/cjs/lib/setup/setupVisDebug.js.map +2 -2
- package/build/esm/lib/_Types.d.ts +7 -0
- package/build/esm/lib/_Types.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCert.d.ts +5 -2
- package/build/esm/lib/cli/cliCert.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCert.js +5 -2
- package/build/esm/lib/cli/cliCert.js.map +1 -1
- package/build/esm/lib/cli/cliCommand.d.ts +32 -1
- package/build/esm/lib/cli/cliCommand.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCommand.js +4 -1
- package/build/esm/lib/cli/cliCommand.js.map +1 -1
- package/build/esm/lib/cli/cliCompact.d.ts +4 -1
- package/build/esm/lib/cli/cliCompact.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCompact.js +4 -1
- package/build/esm/lib/cli/cliCompact.js.map +1 -1
- package/build/esm/lib/cli/cliDebug.d.ts +4 -1
- package/build/esm/lib/cli/cliDebug.d.ts.map +1 -1
- package/build/esm/lib/cli/cliDebug.js +4 -1
- package/build/esm/lib/cli/cliDebug.js.map +1 -1
- package/build/esm/lib/cli/cliHost.d.ts +8 -5
- package/build/esm/lib/cli/cliHost.d.ts.map +1 -1
- package/build/esm/lib/cli/cliHost.js +8 -5
- package/build/esm/lib/cli/cliHost.js.map +1 -1
- package/build/esm/lib/cli/cliLogs.d.ts +4 -1
- package/build/esm/lib/cli/cliLogs.d.ts.map +1 -1
- package/build/esm/lib/cli/cliLogs.js +4 -1
- package/build/esm/lib/cli/cliLogs.js.map +1 -1
- package/build/esm/lib/cli/cliMessage.d.ts +1 -0
- package/build/esm/lib/cli/cliMessage.d.ts.map +1 -1
- package/build/esm/lib/cli/cliMessage.js +1 -0
- package/build/esm/lib/cli/cliMessage.js.map +1 -1
- package/build/esm/lib/cli/cliObjects.d.ts +12 -9
- package/build/esm/lib/cli/cliObjects.d.ts.map +1 -1
- package/build/esm/lib/cli/cliObjects.js +17 -14
- package/build/esm/lib/cli/cliObjects.js.map +1 -1
- package/build/esm/lib/cli/cliPlugin.js +1 -1
- package/build/esm/lib/cli/cliProcess.d.ts +4 -0
- package/build/esm/lib/cli/cliProcess.d.ts.map +1 -1
- package/build/esm/lib/cli/cliProcess.js +5 -1
- package/build/esm/lib/cli/cliProcess.js.map +1 -1
- package/build/esm/lib/cli/cliStates.d.ts +3 -0
- package/build/esm/lib/cli/cliStates.d.ts.map +1 -1
- package/build/esm/lib/cli/cliStates.js +3 -0
- package/build/esm/lib/cli/cliStates.js.map +1 -1
- package/build/esm/lib/setup/customError.d.ts +4 -0
- package/build/esm/lib/setup/customError.d.ts.map +1 -1
- package/build/esm/lib/setup/customError.js +3 -0
- package/build/esm/lib/setup/customError.js.map +1 -1
- package/build/esm/lib/setup/formatters.d.ts +4 -4
- package/build/esm/lib/setup/formatters.js +4 -4
- package/build/esm/lib/setup/pluginInfos.d.ts +5 -0
- package/build/esm/lib/setup/pluginInfos.d.ts.map +1 -1
- package/build/esm/lib/setup/pluginInfos.js +5 -0
- package/build/esm/lib/setup/pluginInfos.js.map +1 -1
- package/build/esm/lib/setup/setupBackup.d.ts +34 -0
- package/build/esm/lib/setup/setupBackup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupBackup.js +25 -0
- package/build/esm/lib/setup/setupBackup.js.map +1 -1
- package/build/esm/lib/setup/setupInstall.d.ts +37 -14
- package/build/esm/lib/setup/setupInstall.d.ts.map +1 -1
- package/build/esm/lib/setup/setupInstall.js +31 -14
- package/build/esm/lib/setup/setupInstall.js.map +1 -1
- package/build/esm/lib/setup/setupLicense.d.ts +8 -0
- package/build/esm/lib/setup/setupLicense.d.ts.map +1 -1
- package/build/esm/lib/setup/setupLicense.js +6 -0
- package/build/esm/lib/setup/setupLicense.js.map +1 -1
- package/build/esm/lib/setup/setupList.d.ts +54 -0
- package/build/esm/lib/setup/setupList.d.ts.map +1 -1
- package/build/esm/lib/setup/setupList.js +54 -0
- package/build/esm/lib/setup/setupList.js.map +1 -1
- package/build/esm/lib/setup/setupPacketManager.d.ts +10 -0
- package/build/esm/lib/setup/setupPacketManager.d.ts.map +1 -1
- package/build/esm/lib/setup/setupPacketManager.js +9 -0
- package/build/esm/lib/setup/setupPacketManager.js.map +1 -1
- package/build/esm/lib/setup/setupRepo.d.ts +6 -0
- package/build/esm/lib/setup/setupRepo.d.ts.map +1 -1
- package/build/esm/lib/setup/setupRepo.js +6 -0
- package/build/esm/lib/setup/setupRepo.js.map +1 -1
- package/build/esm/lib/setup/setupSetup.d.ts +27 -0
- package/build/esm/lib/setup/setupSetup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupSetup.js +21 -0
- package/build/esm/lib/setup/setupSetup.js.map +1 -1
- package/build/esm/lib/setup/setupUpgrade.d.ts +6 -0
- package/build/esm/lib/setup/setupUpgrade.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpgrade.js +6 -0
- package/build/esm/lib/setup/setupUpgrade.js.map +1 -1
- package/build/esm/lib/setup/setupUpload.d.ts +71 -0
- package/build/esm/lib/setup/setupUpload.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpload.js +68 -1
- package/build/esm/lib/setup/setupUpload.js.map +1 -1
- package/build/esm/lib/setup/setupUsers.d.ts +23 -14
- package/build/esm/lib/setup/setupUsers.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUsers.js +20 -14
- package/build/esm/lib/setup/setupUsers.js.map +1 -1
- package/build/esm/lib/setup/setupVendor.d.ts +9 -1
- package/build/esm/lib/setup/setupVendor.d.ts.map +1 -1
- package/build/esm/lib/setup/setupVendor.js +7 -1
- package/build/esm/lib/setup/setupVendor.js.map +1 -1
- package/build/esm/lib/setup/setupVisDebug.d.ts +9 -0
- package/build/esm/lib/setup/setupVisDebug.d.ts.map +1 -1
- package/build/esm/lib/setup/setupVisDebug.js +6 -0
- package/build/esm/lib/setup/setupVisDebug.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/setup/setupUsers.ts"],
|
|
4
|
-
"sourcesContent": ["import { password, tools, EXIT_CODES } from '@iobroker/js-controller-common';\nimport type { ProcessExitCallback } from '../_Types.js';\nimport type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport prompt from 'prompt';\n\nexport interface CLIUsersOptions {\n processExit: ProcessExitCallback;\n objects: ObjectsRedisClient;\n}\n\n/** Map a prompt.Schema to properties of type string */\ntype SchemaPropsToString<TSchema extends prompt.Schema> = { [Property in keyof TSchema['properties']]: string };\n\nexport class Users {\n private readonly objects: ObjectsRedisClient;\n private readonly processExit: ProcessExitCallback;\n\n constructor(options: CLIUsersOptions) {\n if (!options.objects) {\n throw new Error('Invalid arguments: objects is missing');\n }\n if (!options.processExit) {\n throw new Error('Invalid arguments: processExit is missing');\n }\n\n this.objects = options.objects;\n this.processExit = options.processExit;\n }\n\n /**\n * Adds new user to system\n *\n * @param username name of the user which will be added\n * @param pw password\n * @param callback\n */\n addUser(username: string, pw: string, callback: ioBroker.ErrorCallback): void {\n // user id's should be case insensitive\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (obj) {\n return tools.maybeCallbackWithError(callback, 'User yet exists');\n }\n this.objects.setObject(\n `system.user.${_user}`,\n {\n type: 'user',\n common: {\n name: username,\n enabled: true,\n password: '',\n },\n from: `system.host.${tools.getHostName()}.cli`,\n ts: Date.now(),\n native: {},\n },\n err => {\n if (!err) {\n this.setPassword(username, pw, callback);\n } else {\n return tools.maybeCallbackWithError(callback, err);\n }\n },\n );\n });\n }\n\n /**\n * Checks if user exists\n *\n * @param username name of the user to check existence of\n */\n async isUser(username: string): Promise<boolean> {\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n let isExisting = false;\n try {\n isExisting = await this.objects.objectExists(`system.user.${_user}`);\n } catch {\n // ignore\n }\n\n return isExisting;\n }\n\n /**\n * Set password for specific user\n *\n * @param username name of the user to set password for\n * @param pw password\n * @param callback\n */\n setPassword(username: string, pw: string, callback: ioBroker.ErrorCallback): void {\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n\n password(pw).hash(null, null, (err, res) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n obj.common.password = res ?? '';\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(`system.user.${_user}`, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n });\n }\n\n /**\n * Checks if password is correct for given user\n *\n * @param username name of the user to check password\n * @param pw password\n * @param callback\n */\n checkPassword(username: string, pw: string, callback: (err?: Error | null, isOk?: boolean) => void): void {\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n\n password(pw).check(obj.common.password, (err, res) => {\n return tools.maybeCallbackWithError(callback, err, res);\n });\n });\n }\n\n /**\n * Deletes user from system\n *\n * @param username name of the user to delete\n * @param callback\n */\n delUser(username: string, callback: ioBroker.ErrorCallback): void {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"userdel user\"');\n }\n\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n if (obj.common.dontDelete) {\n return tools.maybeCallbackWithError(callback, 'Cannot delete user, while is system user');\n }\n this.objects.delObject(`system.user.${_user}`, err => {\n // Remove this user from all groups\n if (!err) {\n this.objects.getObjectList(\n { startkey: 'system.group.', endkey: 'system.group.\\u9999' },\n (err, groups) => {\n if (!groups) {\n return tools.maybeCallback(callback);\n }\n\n let count = 0;\n for (let i = 0; i < groups.rows.length; i++) {\n if (groups.rows[i].value.type !== 'group') {\n continue;\n }\n // find all groups\n if (\n groups.rows[i].value.common.members &&\n groups.rows[i].value.common.members.indexOf(`system.user.${_user}`) !== -1\n ) {\n const pos = groups.rows[i].value.common.members.indexOf(`system.user.${_user}`);\n groups.rows[i].value.common.members.splice(pos, 1);\n count++;\n groups.rows[i].value.from = `system.host.${tools.getHostName()}.cli`;\n groups.rows[i].value.ts = Date.now();\n this.objects.setObject(groups.rows[i].value._id, groups.rows[i].value, err => {\n if (!--count) {\n return tools.maybeCallbackWithError(callback, err);\n }\n });\n }\n }\n if (!count) {\n return tools.maybeCallback(callback);\n }\n },\n );\n } else {\n return tools.maybeCallbackWithError(callback, err);\n }\n });\n });\n }\n\n /**\n * Adds user to given group\n *\n * @param username user which will be added to the group\n * @param groupName name of the group where the user will be added to\n * @param callback\n */\n addUserToGroup(username: string, groupName: string, callback: ioBroker.ErrorCallback): void {\n let _user = username.replace(/\\s/g, '_').toLowerCase();\n if (!groupName.startsWith('system.group.')) {\n groupName = `system.group.${groupName}`;\n }\n if (!_user.startsWith('system.user.')) {\n _user = `system.user.${_user}`;\n }\n\n this.objects.getObject(_user, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n this.objects.getObject(groupName, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'Group does not exist');\n }\n obj.common = obj.common || {};\n obj.common.members = obj.common.members || [];\n\n if (obj.common.members.indexOf(_user) === -1) {\n obj.common.members.push(_user);\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(groupName, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n } else {\n return tools.maybeCallback(callback);\n }\n });\n });\n }\n\n /**\n * Add user via CLI prompt\n *\n * @param username user which sohuld be created\n * @param groupName default group for the new user\n * @param password user password\n * @param callback\n */\n addUserPrompt(username: string, groupName: string, password: string, callback: ioBroker.ErrorCallback): void {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"adduser newUser\"');\n }\n\n // Check group\n if (groupName.substring(0, 13) !== 'system.group.') {\n groupName = `system.group.${groupName}`;\n }\n\n this.objects.getObject(groupName, (err, obj) => {\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `Unknown group: ${groupName}`);\n }\n if (!password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n password: {\n description: 'Enter your password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n repeatPassword: {\n description: 'Repeat your password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (err, result) => {\n if (result) {\n if (result.password !== result.repeatPassword) {\n console.log('Passwords are not identical!');\n return void this.processExit(EXIT_CODES.INVALID_PASSWORD);\n }\n\n this.addUser(username, result.password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n this.addUserToGroup(username, groupName, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n });\n } else {\n return tools.maybeCallbackWithError(callback, err);\n }\n });\n } else {\n this.addUser(username, password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n this.addUserToGroup(username, groupName, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n });\n }\n });\n }\n\n /**\n * Set password of user\n *\n * @param username name of the user to set password for\n * @param password password of user\n * @param callback\n */\n async setUserPassword(username: string, password: string, callback: ioBroker.ErrorCallback): Promise<void> {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"passwd username\"');\n }\n\n const isExisting = await this.isUser(username);\n if (!isExisting) {\n return tools.maybeCallbackWithError(callback, `User \"${username}\" does not exist.`);\n }\n // Check a group\n if (!password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n password: {\n description: 'Enter your password:',\n pattern: /^[^'\"]*$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n repeatPassword: {\n description: 'Repeat your password:',\n pattern: /^[^'\"]*$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (_err: Error | null, result): void => {\n if (result) {\n if (result.password !== result.repeatPassword) {\n return tools.maybeCallbackWithError(callback, 'Passwords are not identical!');\n }\n\n this.setPassword(username, result.password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n } else {\n return tools.maybeCallbackWithError(callback, 'No password entered!');\n }\n });\n } else {\n this.setPassword(username, password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n }\n }\n\n /**\n * Enable user\n *\n * @param username name of the user which will be activated\n * @param enable true if it should be enabled else false\n * @param callback\n */\n enableUser(username: string, enable: boolean, callback: ioBroker.ErrorCallback): void {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"enable username\"');\n }\n if (username.startsWith('system.user.')) {\n username = username.substring('system.user.'.length);\n }\n\n if (username === 'admin' && !enable) {\n return tools.maybeCallbackWithError(callback, 'User admin cannot be disabled');\n }\n\n this.objects.getObject(`system.user.${username}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read user: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `User \"${username}\" not found`);\n }\n obj.common.enabled = enable;\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(obj._id, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n\n /**\n * Check if user password is valid\n *\n * @param username name of the user to check password for\n * @param password password to check\n * @param callback\n */\n checkUserPassword(username: string, password: string, callback: ioBroker.ErrorCallback): void {\n if (!username && !password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n username: {\n description: 'Enter username to check password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: false,\n },\n password: {\n description: 'Enter current password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (err, result) => {\n this.checkPassword(result.username, result.password, (err, res) => {\n if (err || !res) {\n return tools.maybeCallbackWithError(\n callback,\n `Password for user \"${result.username}\" does not match${err ? `: ${err.message}` : ''}`,\n );\n }\n return tools.maybeCallbackWithError(callback, null);\n });\n });\n } else if (!password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n password: {\n description: 'Enter current password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (err, result) => {\n this.checkPassword(username, result.password, (err, res) => {\n if (err || !res) {\n return tools.maybeCallbackWithError(\n callback,\n `Password for user \"${username}\" does not match${err ? `: ${err.message}` : ''}`,\n );\n }\n return tools.maybeCallbackWithError(callback, null);\n });\n });\n } else {\n this.checkPassword(username, password, (err, res) => {\n if (err || !res) {\n return tools.maybeCallbackWithError(\n callback,\n `Password for user \"${username}\" does not match${err ? `: ${err.message}` : ''}`,\n );\n }\n return tools.maybeCallbackWithError(callback, null);\n });\n }\n }\n\n /**\n * Get user object\n *\n * @param username name of the user to get object of\n * @param callback\n */\n getUser(username: string, callback: (err?: Error | null, enabled?: boolean) => void): void {\n this.objects.getObject(`system.user.${username}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read user: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `User \"${username}\" not found`);\n }\n return tools.maybeCallbackWithError(callback, null, obj.common.enabled);\n });\n }\n\n /**\n * Get group object\n *\n * @param group groupname\n * @param callback\n */\n getGroup(group: string, callback: (err?: Error | null, enabled?: boolean, members?: string[]) => void): void {\n this.objects.getObject(`system.group.${group}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read group: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `Group \"${group}\" not found`);\n }\n return tools.maybeCallbackWithError(callback, null, obj.common.enabled, obj.common.members);\n });\n }\n\n /**\n * Enable or disable group by name\n *\n * @param group groupname\n * @param enable if enable or disable\n * @param callback\n */\n enableGroup(group: string, enable: boolean, callback: ioBroker.ErrorCallback): void {\n if (!group) {\n return tools.maybeCallbackWithError(callback, 'Please define group name, like: \"enable groupname\"');\n }\n if (group.startsWith('system.group.')) {\n group = group.substring('system.group.'.length);\n }\n\n if (group === 'administrator' && !enable) {\n return tools.maybeCallbackWithError(callback, 'Group \"administrator\" cannot be disabled');\n }\n\n this.objects.getObject(`system.group.${group}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read group: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `Group \"${group}\" not found`);\n }\n obj.common.enabled = enable;\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(obj._id, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n\n /**\n * Add new group\n *\n * @param group groupname\n */\n async addGroup(group: string): Promise<void> {\n const _group = group.replace(/\\s/g, '_');\n const obj = await this.objects.getObject(`system.group.${_group}`);\n if (obj) {\n throw new Error('Group yet exists');\n } else {\n // TODO: shoudln't it have some default acl? TS is worrying\n await this.objects.setObject(`system.group.${_group}`, {\n type: 'group',\n common: {\n name: group,\n enabled: true,\n members: [],\n },\n from: `system.host.${tools.getHostName()}.cli`,\n ts: Date.now(),\n native: {},\n } as any);\n }\n }\n\n /**\n * Remove group\n *\n * @param group groupname\n * @param callback\n */\n delGroup(group: string, callback: ioBroker.ErrorCallback): void {\n const _group = group.replace(/\\s/g, '_');\n\n if (group === 'administrator') {\n return tools.maybeCallbackWithError(callback, 'Group \"administrator\" cannot be deleted');\n }\n this.objects.getObject(`system.group.${_group}`, (err, obj) => {\n if (!obj) {\n return tools.maybeCallbackWithError(callback, 'Group does not exists');\n }\n this.objects.delObject(`system.group.${_group}`, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n\n /**\n * Remove user from given group\n *\n * @param username name of the user which will be removed from group\n * @param groupName name of the group user will be removed from\n * @param callback\n */\n removeUserFromGroup(username: string, groupName: string, callback: ioBroker.ErrorCallback): void {\n const _group = groupName.replace(/\\s/g, '_');\n this.objects.getObject(`system.group.${_group}`, (err, obj) => {\n if (!obj) {\n return tools.maybeCallbackWithError(callback, 'Group does not exists');\n }\n const pos = obj.common.members.indexOf(`system.user.${username}`);\n if (pos === -1) {\n return tools.maybeCallbackWithError(callback, 'User not in group');\n }\n obj.common.members.splice(pos, 1);\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(obj._id, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kCAA4C;AAG5C,oBAAmB;AAUb,MAAO,MAAK;EACG;EACA;EAEjB,YAAY,SAAwB;AAChC,QAAI,CAAC,QAAQ,SAAS;AAClB,YAAM,IAAI,MAAM,uCAAuC;IAC3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AAK,QAAO;AAC1D,UAAI,CAAC,KAAK;AACN,eAAO,kCAAM,uBAAuB,UAAU,uBAAuB;MACzE;AACA,WAAK,QAAQ,UAAU,gBAAgB,MAAM,IAAI,CAAAA,SAAM;AACnD,eAAO,kCAAM,uBAAuB,UAAUA,IAAG;MACrD,CAAC;IACL,CAAC;EACL;;;;;;;;EASA,oBAAoB,UAAkB,WAAmB,UAAgC;AACrF,UAAM,SAAS,UAAU,QAAQ,OAAO,GAAG;AAC3C,SAAK,QAAQ,UAAU,gBAAgB,MAAM,IAAI,CAAC,KAAK,QAAO;AAC1D,UAAI,CAAC,KAAK;AACN,eAAO,kCAAM,uBAAuB,UAAU,uBAAuB;MACzE;AACA,YAAM,MAAM,IAAI,OAAO,QAAQ,QAAQ,eAAe,QAAQ,EAAE;AAChE,UAAI,QAAQ,IAAI;AACZ,eAAO,kCAAM,uBAAuB,UAAU,mBAAmB;MACrE;AACA,UAAI,OAAO,QAAQ,OAAO,KAAK,CAAC;AAChC,UAAI,OAAO,eAAe,kCAAM,YAAW,CAAE;AAC7C,UAAI,KAAK,KAAK,IAAG;AACjB,WAAK,QAAQ,UAAU,IAAI,KAAK,KAAK,CAAAA,SAAM;AACvC,eAAO,kCAAM,uBAAuB,UAAUA,IAAG;MACrD,CAAC;IACL,CAAC;EACL;;",
|
|
4
|
+
"sourcesContent": ["import { password, tools, EXIT_CODES } from '@iobroker/js-controller-common';\nimport type { ProcessExitCallback } from '../_Types.js';\nimport type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport prompt from 'prompt';\n\n/** Options for the users command */\nexport interface CLIUsersOptions {\n /** Callback to exit the process with an exit code */\n processExit: ProcessExitCallback;\n /** The objects database client */\n objects: ObjectsRedisClient;\n}\n\n/** Map a prompt.Schema to properties of type string */\ntype SchemaPropsToString<TSchema extends prompt.Schema> = { [Property in keyof TSchema['properties']]: string };\n\n/**\n * CLI command to manage ioBroker users and groups\n */\nexport class Users {\n private readonly objects: ObjectsRedisClient;\n private readonly processExit: ProcessExitCallback;\n\n /**\n * @param options The objects database client and the process-exit callback\n */\n constructor(options: CLIUsersOptions) {\n if (!options.objects) {\n throw new Error('Invalid arguments: objects is missing');\n }\n if (!options.processExit) {\n throw new Error('Invalid arguments: processExit is missing');\n }\n\n this.objects = options.objects;\n this.processExit = options.processExit;\n }\n\n /**\n * Adds new user to system\n *\n * @param username name of the user which will be added\n * @param pw password\n * @param callback Called once the user has been added\n */\n addUser(username: string, pw: string, callback: ioBroker.ErrorCallback): void {\n // user id's should be case insensitive\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (obj) {\n return tools.maybeCallbackWithError(callback, 'User yet exists');\n }\n this.objects.setObject(\n `system.user.${_user}`,\n {\n type: 'user',\n common: {\n name: username,\n enabled: true,\n password: '',\n },\n from: `system.host.${tools.getHostName()}.cli`,\n ts: Date.now(),\n native: {},\n },\n err => {\n if (!err) {\n this.setPassword(username, pw, callback);\n } else {\n return tools.maybeCallbackWithError(callback, err);\n }\n },\n );\n });\n }\n\n /**\n * Checks if user exists\n *\n * @param username name of the user to check existence of\n */\n async isUser(username: string): Promise<boolean> {\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n let isExisting = false;\n try {\n isExisting = await this.objects.objectExists(`system.user.${_user}`);\n } catch {\n // ignore\n }\n\n return isExisting;\n }\n\n /**\n * Set password for specific user\n *\n * @param username name of the user to set password for\n * @param pw password\n * @param callback Called once the password has been set\n */\n setPassword(username: string, pw: string, callback: ioBroker.ErrorCallback): void {\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n\n password(pw).hash(null, null, (err, res) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n obj.common.password = res ?? '';\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(`system.user.${_user}`, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n });\n }\n\n /**\n * Checks if password is correct for given user\n *\n * @param username name of the user to check password\n * @param pw password\n * @param callback Called with whether the password is correct\n */\n checkPassword(username: string, pw: string, callback: (err?: Error | null, isOk?: boolean) => void): void {\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n\n password(pw).check(obj.common.password, (err, res) => {\n return tools.maybeCallbackWithError(callback, err, res);\n });\n });\n }\n\n /**\n * Deletes user from system\n *\n * @param username name of the user to delete\n * @param callback Called once the user has been deleted\n */\n delUser(username: string, callback: ioBroker.ErrorCallback): void {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"userdel user\"');\n }\n\n const _user = username.replace(/\\s/g, '_').toLowerCase();\n\n this.objects.getObject(`system.user.${_user}`, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n if (obj.common.dontDelete) {\n return tools.maybeCallbackWithError(callback, 'Cannot delete user, while is system user');\n }\n this.objects.delObject(`system.user.${_user}`, err => {\n // Remove this user from all groups\n if (!err) {\n this.objects.getObjectList(\n { startkey: 'system.group.', endkey: 'system.group.\\u9999' },\n (err, groups) => {\n if (!groups) {\n return tools.maybeCallback(callback);\n }\n\n let count = 0;\n for (let i = 0; i < groups.rows.length; i++) {\n if (groups.rows[i].value.type !== 'group') {\n continue;\n }\n // find all groups\n if (\n groups.rows[i].value.common.members &&\n groups.rows[i].value.common.members.indexOf(`system.user.${_user}`) !== -1\n ) {\n const pos = groups.rows[i].value.common.members.indexOf(`system.user.${_user}`);\n groups.rows[i].value.common.members.splice(pos, 1);\n count++;\n groups.rows[i].value.from = `system.host.${tools.getHostName()}.cli`;\n groups.rows[i].value.ts = Date.now();\n this.objects.setObject(groups.rows[i].value._id, groups.rows[i].value, err => {\n if (!--count) {\n return tools.maybeCallbackWithError(callback, err);\n }\n });\n }\n }\n if (!count) {\n return tools.maybeCallback(callback);\n }\n },\n );\n } else {\n return tools.maybeCallbackWithError(callback, err);\n }\n });\n });\n }\n\n /**\n * Adds user to given group\n *\n * @param username user which will be added to the group\n * @param groupName name of the group where the user will be added to\n * @param callback Called once the user has been added to the group\n */\n addUserToGroup(username: string, groupName: string, callback: ioBroker.ErrorCallback): void {\n let _user = username.replace(/\\s/g, '_').toLowerCase();\n if (!groupName.startsWith('system.group.')) {\n groupName = `system.group.${groupName}`;\n }\n if (!_user.startsWith('system.user.')) {\n _user = `system.user.${_user}`;\n }\n\n this.objects.getObject(_user, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'User does not exist');\n }\n this.objects.getObject(groupName, (err, obj) => {\n if (err || !obj) {\n return tools.maybeCallbackWithError(callback, 'Group does not exist');\n }\n obj.common = obj.common || {};\n obj.common.members = obj.common.members || [];\n\n if (obj.common.members.indexOf(_user) === -1) {\n obj.common.members.push(_user);\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(groupName, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n } else {\n return tools.maybeCallback(callback);\n }\n });\n });\n }\n\n /**\n * Add user via CLI prompt\n *\n * @param username user which sohuld be created\n * @param groupName default group for the new user\n * @param password user password\n * @param callback Called once the user has been created\n */\n addUserPrompt(username: string, groupName: string, password: string, callback: ioBroker.ErrorCallback): void {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"adduser newUser\"');\n }\n\n // Check group\n if (groupName.substring(0, 13) !== 'system.group.') {\n groupName = `system.group.${groupName}`;\n }\n\n this.objects.getObject(groupName, (err, obj) => {\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `Unknown group: ${groupName}`);\n }\n if (!password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n password: {\n description: 'Enter your password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n repeatPassword: {\n description: 'Repeat your password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (err, result) => {\n if (result) {\n if (result.password !== result.repeatPassword) {\n console.log('Passwords are not identical!');\n return void this.processExit(EXIT_CODES.INVALID_PASSWORD);\n }\n\n this.addUser(username, result.password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n this.addUserToGroup(username, groupName, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n });\n } else {\n return tools.maybeCallbackWithError(callback, err);\n }\n });\n } else {\n this.addUser(username, password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n this.addUserToGroup(username, groupName, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n });\n }\n });\n }\n\n /**\n * Set password of user\n *\n * @param username name of the user to set password for\n * @param password password of user\n * @param callback Called once the password has been set\n */\n async setUserPassword(username: string, password: string, callback: ioBroker.ErrorCallback): Promise<void> {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"passwd username\"');\n }\n\n const isExisting = await this.isUser(username);\n if (!isExisting) {\n return tools.maybeCallbackWithError(callback, `User \"${username}\" does not exist.`);\n }\n // Check a group\n if (!password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n password: {\n description: 'Enter your password:',\n pattern: /^[^'\"]*$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n repeatPassword: {\n description: 'Repeat your password:',\n pattern: /^[^'\"]*$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (_err: Error | null, result): void => {\n if (result) {\n if (result.password !== result.repeatPassword) {\n return tools.maybeCallbackWithError(callback, 'Passwords are not identical!');\n }\n\n this.setPassword(username, result.password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n } else {\n return tools.maybeCallbackWithError(callback, 'No password entered!');\n }\n });\n } else {\n this.setPassword(username, password, err => {\n if (err) {\n return tools.maybeCallbackWithError(callback, err);\n }\n return tools.maybeCallback(callback);\n });\n }\n }\n\n /**\n * Enable user\n *\n * @param username name of the user which will be activated\n * @param enable true if it should be enabled else false\n * @param callback Called once the user has been enabled or disabled\n */\n enableUser(username: string, enable: boolean, callback: ioBroker.ErrorCallback): void {\n if (!username) {\n return tools.maybeCallbackWithError(callback, 'Please define user name, like: \"enable username\"');\n }\n if (username.startsWith('system.user.')) {\n username = username.substring('system.user.'.length);\n }\n\n if (username === 'admin' && !enable) {\n return tools.maybeCallbackWithError(callback, 'User admin cannot be disabled');\n }\n\n this.objects.getObject(`system.user.${username}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read user: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `User \"${username}\" not found`);\n }\n obj.common.enabled = enable;\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(obj._id, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n\n /**\n * Check if user password is valid\n *\n * @param username name of the user to check password for\n * @param password password to check\n * @param callback Called with whether the password is valid\n */\n checkUserPassword(username: string, password: string, callback: ioBroker.ErrorCallback): void {\n if (!username && !password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n username: {\n description: 'Enter username to check password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: false,\n },\n password: {\n description: 'Enter current password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (err, result) => {\n this.checkPassword(result.username, result.password, (err, res) => {\n if (err || !res) {\n return tools.maybeCallbackWithError(\n callback,\n `Password for user \"${result.username}\" does not match${err ? `: ${err.message}` : ''}`,\n );\n }\n return tools.maybeCallbackWithError(callback, null);\n });\n });\n } else if (!password) {\n prompt.message = '';\n prompt.delimiter = '';\n const schema = {\n properties: {\n password: {\n description: 'Enter current password:',\n pattern: /^[^'\"]+$/,\n message: 'No \" are allowed',\n hidden: true,\n },\n },\n } as const satisfies prompt.Schema;\n prompt.start();\n\n prompt.get<SchemaPropsToString<typeof schema>>(schema, (err, result) => {\n this.checkPassword(username, result.password, (err, res) => {\n if (err || !res) {\n return tools.maybeCallbackWithError(\n callback,\n `Password for user \"${username}\" does not match${err ? `: ${err.message}` : ''}`,\n );\n }\n return tools.maybeCallbackWithError(callback, null);\n });\n });\n } else {\n this.checkPassword(username, password, (err, res) => {\n if (err || !res) {\n return tools.maybeCallbackWithError(\n callback,\n `Password for user \"${username}\" does not match${err ? `: ${err.message}` : ''}`,\n );\n }\n return tools.maybeCallbackWithError(callback, null);\n });\n }\n }\n\n /**\n * Get user object\n *\n * @param username name of the user to get object of\n * @param callback Called with the user object\n */\n getUser(username: string, callback: (err?: Error | null, enabled?: boolean) => void): void {\n this.objects.getObject(`system.user.${username}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read user: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `User \"${username}\" not found`);\n }\n return tools.maybeCallbackWithError(callback, null, obj.common.enabled);\n });\n }\n\n /**\n * Get group object\n *\n * @param group groupname\n * @param callback Called with the group object\n */\n getGroup(group: string, callback: (err?: Error | null, enabled?: boolean, members?: string[]) => void): void {\n this.objects.getObject(`system.group.${group}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read group: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `Group \"${group}\" not found`);\n }\n return tools.maybeCallbackWithError(callback, null, obj.common.enabled, obj.common.members);\n });\n }\n\n /**\n * Enable or disable group by name\n *\n * @param group groupname\n * @param enable if enable or disable\n * @param callback Called once the group has been enabled or disabled\n */\n enableGroup(group: string, enable: boolean, callback: ioBroker.ErrorCallback): void {\n if (!group) {\n return tools.maybeCallbackWithError(callback, 'Please define group name, like: \"enable groupname\"');\n }\n if (group.startsWith('system.group.')) {\n group = group.substring('system.group.'.length);\n }\n\n if (group === 'administrator' && !enable) {\n return tools.maybeCallbackWithError(callback, 'Group \"administrator\" cannot be disabled');\n }\n\n this.objects.getObject(`system.group.${group}`, (err, obj) => {\n if (err) {\n return tools.maybeCallbackWithError(callback, `Cannot read group: ${err.message}`);\n }\n if (!obj) {\n return tools.maybeCallbackWithError(callback, `Group \"${group}\" not found`);\n }\n obj.common.enabled = enable;\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(obj._id, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n\n /**\n * Add new group\n *\n * @param group groupname\n */\n async addGroup(group: string): Promise<void> {\n const _group = group.replace(/\\s/g, '_');\n const obj = await this.objects.getObject(`system.group.${_group}`);\n if (obj) {\n throw new Error('Group yet exists');\n } else {\n // TODO: shoudln't it have some default acl? TS is worrying\n await this.objects.setObject(`system.group.${_group}`, {\n type: 'group',\n common: {\n name: group,\n enabled: true,\n members: [],\n },\n from: `system.host.${tools.getHostName()}.cli`,\n ts: Date.now(),\n native: {},\n } as any);\n }\n }\n\n /**\n * Remove group\n *\n * @param group groupname\n * @param callback Called once the group has been removed\n */\n delGroup(group: string, callback: ioBroker.ErrorCallback): void {\n const _group = group.replace(/\\s/g, '_');\n\n if (group === 'administrator') {\n return tools.maybeCallbackWithError(callback, 'Group \"administrator\" cannot be deleted');\n }\n this.objects.getObject(`system.group.${_group}`, (err, obj) => {\n if (!obj) {\n return tools.maybeCallbackWithError(callback, 'Group does not exists');\n }\n this.objects.delObject(`system.group.${_group}`, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n\n /**\n * Remove user from given group\n *\n * @param username name of the user which will be removed from group\n * @param groupName name of the group user will be removed from\n * @param callback Called once the user has been removed from the group\n */\n removeUserFromGroup(username: string, groupName: string, callback: ioBroker.ErrorCallback): void {\n const _group = groupName.replace(/\\s/g, '_');\n this.objects.getObject(`system.group.${_group}`, (err, obj) => {\n if (!obj) {\n return tools.maybeCallbackWithError(callback, 'Group does not exists');\n }\n const pos = obj.common.members.indexOf(`system.user.${username}`);\n if (pos === -1) {\n return tools.maybeCallbackWithError(callback, 'User not in group');\n }\n obj.common.members.splice(pos, 1);\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n this.objects.setObject(obj._id, obj, err => {\n return tools.maybeCallbackWithError(callback, err);\n });\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kCAA4C;AAG5C,oBAAmB;AAgBb,MAAO,MAAK;EACG;EACA;;;;EAKjB,YAAY,SAAwB;AAChC,QAAI,CAAC,QAAQ,SAAS;AAClB,YAAM,IAAI,MAAM,uCAAuC;IAC3D;AACA,QAAI,CAAC,QAAQ,aAAa;AACtB,YAAM,IAAI,MAAM,2CAA2C;IAC/D;AAEA,SAAK,UAAU,QAAQ;AACvB,SAAK,cAAc,QAAQ;EAC/B;;;;;;;;EASA,QAAQ,UAAkB,IAAY,UAAgC;AAElE,UAAM,QAAQ,SAAS,QAAQ,OAAO,GAAG,EAAE,YAAW;AACtD,SAAK,QAAQ,UAAU,eAAe,KAAK,IAAI,CAAC,KAAK,QAAO;AACxD,UAAI,KAAK;AACL,eAAO,kCAAM,uBAAuB,UAAU,iBAAiB;MACnE;AACA,WAAK,QAAQ,UACT,eAAe,KAAK,IACpB;QACI,MAAM;QACN,QAAQ;UACJ,MAAM;UACN,SAAS;UACT,UAAU;;QAEd,MAAM,eAA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,QAAQ,eAAe,QAAQ,EAAE;AAChE,UAAI,QAAQ,IAAI;AACZ,eAAO,kCAAM,uBAAuB,UAAU,mBAAmB;MACrE;AACA,UAAI,OAAO,QAAQ,OAAO,KAAK,CAAC;AAChC,UAAI,OAAO,eAAe,kCAAM,YAAW,CAAE;AAC7C,UAAI,KAAK,KAAK,IAAG;AACjB,WAAK,QAAQ,UAAU,IAAI,KAAK,KAAK,CAAAA,SAAM;AACvC,eAAO,kCAAM,uBAAuB,UAAUA,IAAG;MACrD,CAAC;IACL,CAAC;EACL;;",
|
|
6
6
|
"names": ["err", "obj", "password", "prompt"]
|
|
7
7
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';
|
|
2
2
|
import type { InternalLogger } from '@iobroker/js-controller-common-db/tools';
|
|
3
|
+
/** Options for the vendor command */
|
|
3
4
|
export interface CLIVendorOptions {
|
|
5
|
+
/** The objects database client */
|
|
4
6
|
objects: ObjectsRedisClient;
|
|
5
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* CLI command to apply vendor-specific customizations from the vendor file
|
|
10
|
+
*/
|
|
6
11
|
export declare class Vendor {
|
|
7
12
|
private readonly objects;
|
|
13
|
+
/**
|
|
14
|
+
* @param options The objects database client
|
|
15
|
+
*/
|
|
8
16
|
constructor(options: CLIVendorOptions);
|
|
9
17
|
/**
|
|
10
18
|
* Deep merge of source into target object
|
|
@@ -19,7 +27,7 @@ export declare class Vendor {
|
|
|
19
27
|
* @param file file path if not given, default path is used
|
|
20
28
|
* @param password vendor password
|
|
21
29
|
* @param javascriptPassword vendor JavaScript password
|
|
22
|
-
* @param logger
|
|
30
|
+
* @param logger Logger used to report progress and errors
|
|
23
31
|
*/
|
|
24
32
|
checkVendor(file: string | undefined, password: string, javascriptPassword: string | undefined, logger?: InternalLogger): Promise<boolean>;
|
|
25
33
|
}
|
|
@@ -39,6 +39,9 @@ var import_node_crypto = require("node:crypto");
|
|
|
39
39
|
const VENDOR_FILE = "/etc/iob-vendor.json";
|
|
40
40
|
class Vendor {
|
|
41
41
|
objects;
|
|
42
|
+
/**
|
|
43
|
+
* @param options The objects database client
|
|
44
|
+
*/
|
|
42
45
|
constructor(options) {
|
|
43
46
|
this.objects = options.objects;
|
|
44
47
|
}
|
|
@@ -67,7 +70,7 @@ class Vendor {
|
|
|
67
70
|
* @param file file path if not given, default path is used
|
|
68
71
|
* @param password vendor password
|
|
69
72
|
* @param javascriptPassword vendor JavaScript password
|
|
70
|
-
* @param logger
|
|
73
|
+
* @param logger Logger used to report progress and errors
|
|
71
74
|
*/
|
|
72
75
|
async checkVendor(file, password, javascriptPassword, logger) {
|
|
73
76
|
logger ||= {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/setup/setupVendor.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport { tools } from '@iobroker/js-controller-common';\nimport fs from 'fs-extra';\nimport deepClone from 'deep-clone';\nimport { isDeepStrictEqual } from 'node:util';\nimport type { InternalLogger } from '@iobroker/js-controller-common-db/tools';\nimport { randomBytes } from 'node:crypto';\n\nexport interface CLIVendorOptions {\n objects: ObjectsRedisClient;\n}\n\ninterface iobVendorFile {\n vendor?: {\n id?: string;\n name?: string;\n /** Logo for login in admin */\n icon?: string;\n /** Logo in the top left corner of admin */\n logo?: string;\n admin?: {\n menu?: {\n // Settings for left menu\n editable?: false; // Hide edit button in menu\n 'tab-hosts'?: false; // Hide hosts item (See all https://github.com/ioBroker/ioBroker.admin/blob/master/src-rx/src/components/Drawer.js#L142)\n 'tab-files'?: false; // Hide files item\n 'tab-users'?: false; // Hide users item\n 'tab-intro'?: false; // Hide intro item\n 'tab-info'?: false; // Hide info item\n 'tab-adapters'?: false; // Hide adapters item\n 'tab-instances'?: false; // Hide instances item\n 'tab-objects'?: false; // Hide objects item\n 'tab-enums'?: false; // Hide enums item\n 'tab-devices'?: false; // Hide devices item\n 'tab-logs'?: false; // Hide logs item\n 'tab-scenes'?: false; // Hide scenes item\n 'tab-events'?: false; // Hide events item\n 'tab-javascript'?: false; // Hide javascript item\n 'tab-text2command-0'?: false; // Hide text2command-0 item\n 'tab-echarts'?: false; // Hide echarts item\n [tabName: string]: false | undefined;\n };\n appBar?: {\n discovery?: false;\n systemSettings?: false;\n toggleTheme?: false;\n expertMode?: false;\n hostSelector?: false;\n };\n settings?: {\n tabConfig?: false; // Main config tab\n tabRepositories?: false; // Repositories tab\n tabCertificates?: false; // Certificates tab\n tabLetsEncrypt?: false; // Let's Encrypt tab\n tabDefaultACL?: false; // Default ACL tab\n tabStatistics?: false; // Statistics tab\n\n language?: false;\n tempUnit?: false;\n currency?: false;\n dateFormat?: false;\n isFloatComma?: false;\n defaultHistory?: false;\n activeRepo?: false;\n expertMode?: false;\n defaultLogLevel?: false;\n };\n adapters?: {\n gitHubInstall?: false; // hide button install from GitHub/npm\n statistics?: false; // hide statistics on the right top\n filterUpdates?: false; // hide button filter updates in adapter tab\n allowAdapterRating?: false; // do not show and do not load adapter ratings\n };\n login?: {\n title?: string;\n motto?: string;\n link?: string;\n };\n };\n /** Favicon for admin */\n ico?: string;\n uuidPrefix?: string;\n };\n model?: {\n /** name for host */\n name?: string;\n /** Icon for host */\n icon?: string;\n /** Color for host */\n color?: string;\n };\n uuid?: string;\n iobroker?: Partial<ioBroker.IoBrokerJson>;\n objects?: {\n [id: string]: ioBroker.Object;\n };\n}\n\nconst VENDOR_FILE = '/etc/iob-vendor.json';\n\nexport class Vendor {\n private readonly objects: ObjectsRedisClient;\n\n constructor(options: CLIVendorOptions) {\n this.objects = options.objects;\n }\n\n /**\n * Deep merge of source into target object\n *\n * @param target target obj\n * @param source source obj\n */\n private deepMerge(target: Record<string, any>, source: Record<string, any>): void {\n Object.keys(source).forEach(attr => {\n if (typeof source[attr] === 'object' && !(source[attr] instanceof Array)) {\n if (target[attr] && typeof target[attr] !== 'object') {\n target[attr] = {};\n }\n target[attr] = target[attr] || {};\n this.deepMerge(target[attr], source[attr]);\n } else {\n target[attr] = source[attr];\n }\n });\n }\n\n /**\n * Read info from '/etc/iob_vendor.json' and executes instructions stored there\n *\n * @param file file path if not given, default path is used\n * @param password vendor password\n * @param javascriptPassword vendor JavaScript password\n * @param logger\n */\n async checkVendor(\n file: string | undefined,\n password: string,\n javascriptPassword: string | undefined,\n logger?: InternalLogger,\n ): Promise<boolean> {\n logger ||= {\n debug: (text: string) => console.log(text),\n info: (text: string) => console.log(text),\n error: (text: string) => console.error(text),\n warn: (text: string) => console.warn(text),\n silly: (text: string) => console.log(text),\n };\n\n file ||= VENDOR_FILE;\n\n let data: iobVendorFile;\n if (fs.existsSync(file)) {\n try {\n data = fs.readJSONSync(file);\n } catch (err) {\n logger.error(`cannot read or parse \"${file}\": ${err.message}`);\n throw new Error(`cannot read or parse \"${file}\": ${err.message}`);\n }\n } else {\n logger.error(`\"${file}\" does not exist`);\n throw new Error(`\"${file}\" does not exist`);\n }\n\n if (data?.uuid) {\n const uuid = data.uuid;\n\n // check UUID\n const obj = await this.objects.getObject('system.meta.uuid');\n if (obj?.native) {\n if (obj.native.uuid !== uuid) {\n obj.native.uuid = uuid;\n\n logger.info(`Update \"system.meta.uuid:native.uuid\" = \"${obj.native.uuid}\"`);\n\n obj.nonEdit ||= {};\n obj.nonEdit.password = password;\n try {\n await this.objects.setObjectAsync('system.meta.uuid', obj);\n logger.info(`object system.meta.uuid updated: ${uuid}`);\n } catch (e) {\n logger.error(`Cannot update system.meta.uuid: ${e.message}`);\n }\n }\n } else {\n try {\n // @ts-expect-error type uuid is not allowed TODO: allow it for meta?\n await this.objects.setObjectAsync('system.meta.uuid', {\n type: 'meta',\n common: {\n name: 'uuid',\n type: 'uuid',\n },\n ts: new Date().getTime(),\n from: `system.host.${tools.getHostName()}.tools`,\n native: {\n uuid,\n },\n });\n logger.info(`object system.meta.uuid created: ${uuid}`);\n } catch (e) {\n logger.error(`Cannot create system.meta.uuid: ${e.message}`);\n }\n }\n }\n\n // patch iobroker.json file\n if (data?.iobroker) {\n const settings = fs.readJSONSync(tools.getConfigFileName());\n logger.info('Update iobroker.json file');\n this.deepMerge(settings, data.iobroker);\n fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(settings, null, 2));\n }\n\n if (data?.vendor) {\n const vendor = deepClone(data.vendor);\n\n // store vendor\n try {\n const configObj = await this.objects.getObject('system.config');\n if (configObj?.native) {\n let javascriptPasswordEncrypted: string | undefined;\n if (javascriptPassword) {\n if (!configObj.native?.secret) {\n const buf = randomBytes(24);\n configObj.native.secret = buf.toString('hex');\n }\n javascriptPasswordEncrypted = tools.encrypt(configObj.native.secret, javascriptPassword);\n }\n\n if (\n !isDeepStrictEqual(configObj.native.vendor, vendor) ||\n configObj.native.javascriptPassword !== javascriptPasswordEncrypted\n ) {\n configObj.native.vendor = vendor;\n configObj.nonEdit ||= {};\n if (javascriptPassword) {\n configObj.native.javascriptPassword = javascriptPasswordEncrypted;\n configObj.nonEdit.native ||= {};\n configObj.nonEdit.native.javascriptPassword = javascriptPasswordEncrypted;\n }\n configObj.nonEdit.password = password;\n await this.objects.setObjectAsync(configObj._id, configObj);\n logger.info('object system.config updated');\n }\n }\n } catch (e) {\n logger.error(`Cannot update system.config: ${e.message}`);\n }\n } else if (javascriptPassword) {\n const configObj = await this.objects.getObject('system.config');\n\n if (configObj?.native) {\n if (!configObj.native?.secret) {\n const buf = randomBytes(24);\n configObj.native.secret = buf.toString('hex');\n }\n const javascriptPasswordEncrypted = tools.encrypt(configObj.native.secret, javascriptPassword);\n if (configObj.native.javascriptPassword !== javascriptPasswordEncrypted) {\n configObj.native.javascriptPassword = javascriptPasswordEncrypted;\n configObj.nonEdit ||= {};\n configObj.nonEdit.password = password;\n configObj.nonEdit.native ||= {};\n configObj.nonEdit.native.javascriptPassword = javascriptPasswordEncrypted;\n try {\n await this.objects.setObjectAsync(configObj._id, configObj);\n logger.info('object system.config updated');\n } catch (e) {\n logger.error(`Cannot update system.config: ${e.message}`);\n }\n }\n }\n }\n\n // update all existing objects according to vendor\n if (data?.objects) {\n for (let id of Object.keys(data.objects)) {\n if (!id.includes('*')) {\n const _newObj = data.objects[id];\n const obj = await this.objects.getObject(id);\n if (obj) {\n obj.nonEdit ||= {} as ioBroker.NonEditable;\n const originalObj = deepClone(obj);\n _newObj.nonEdit ||= {} as ioBroker.NonEditable;\n _newObj.nonEdit.passHash = obj.nonEdit.passHash;\n // merge objects\n tools.copyAttributes(_newObj, obj);\n\n if (!isDeepStrictEqual(originalObj, obj)) {\n delete obj.nonEdit.passHash;\n obj.nonEdit.password = password;\n logger.info(`Update \"${obj._id}\"`);\n try {\n await this.objects.setObjectAsync(obj._id, obj);\n logger.info(`object \"${obj._id}\" updated`);\n } catch (e) {\n logger.error(`Cannot update \"${obj._id}\": ${e.message}`);\n }\n }\n } else {\n try {\n await this.objects.setObjectAsync(id, _newObj);\n logger.info(`object \"${_newObj._id}\" updated`);\n } catch (e) {\n logger.error(`Cannot update ${id} \"${JSON.stringify(_newObj)}\": ${e.message}`);\n }\n }\n } else {\n id = id.replace(/\\*/g, '');\n const _obj = data.objects[id];\n const arr = await this.objects.getObjectListAsync(\n {\n startkey: id,\n endkey: `${id}\\u9999`,\n },\n { checked: true },\n );\n\n if (arr?.rows?.length) {\n for (const row of arr.rows) {\n const obj = row.value;\n if (obj) {\n obj.nonEdit ||= {};\n const originalObj = deepClone(obj);\n _obj.nonEdit ||= {};\n _obj.nonEdit.passHash = obj.nonEdit.passHash;\n // merge objects\n tools.copyAttributes(_obj, obj);\n\n if (!isDeepStrictEqual(originalObj, obj)) {\n delete obj.nonEdit.passHash;\n obj.nonEdit.password = password;\n logger.info(`Update \"${obj._id}\"`);\n try {\n await this.objects.setObjectAsync(obj._id, obj);\n logger.info(`object \"${obj._id}\" updated`);\n } catch (e) {\n logger.error(`Cannot update \"${obj._id}\": ${e.message}`);\n }\n }\n }\n }\n }\n }\n }\n }\n\n // update host as last\n if (data?.model) {\n const model = data.model;\n const hostname = tools.getHostName();\n const obj = await this.objects.getObject(`system.host.${hostname}`);\n if (obj?.common) {\n if (\n (model.name && model.name !== 'JS controller' && obj.common.title === 'JS controller') ||\n (model.icon && !obj.common.icon) ||\n (model.color && !obj.common.color)\n ) {\n if (model.name) {\n obj.common.title = model.name;\n }\n if (model.icon) {\n obj.common.icon = model.icon;\n }\n if (model.color) {\n obj.common.color = model.color;\n }\n\n obj.nonEdit ||= {};\n obj.nonEdit.password = password;\n\n if (obj.common.title) {\n logger.info(`Update \"system.host.${hostname}:common.title\" = \"${obj.common.title}\"`);\n }\n if (obj.common.icon) {\n logger.info(`Update \"system.host.${hostname}:common.icon\" = \"${!!obj.common.icon}\"`);\n }\n if (obj.common.color) {\n logger.info(`Update \"system.host.${hostname}:common.color\" = \"${obj.common.color}\"`);\n }\n\n try {\n await this.objects.setObjectAsync(obj._id, obj);\n logger.info(`object \"system.host.${hostname}\" updated`);\n } catch (e) {\n logger.error(`Cannot update \"system.host.${hostname}\": ${e.message}`);\n }\n }\n }\n }\n\n // restart ioBroker\n return true;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;AAAA,kCAAsB;AACtB,sBAAe;AACf,wBAAsB;AACtB,uBAAkC;AAElC,yBAA4B;
|
|
4
|
+
"sourcesContent": ["import type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport { tools } from '@iobroker/js-controller-common';\nimport fs from 'fs-extra';\nimport deepClone from 'deep-clone';\nimport { isDeepStrictEqual } from 'node:util';\nimport type { InternalLogger } from '@iobroker/js-controller-common-db/tools';\nimport { randomBytes } from 'node:crypto';\n\n/** Options for the vendor command */\nexport interface CLIVendorOptions {\n /** The objects database client */\n objects: ObjectsRedisClient;\n}\n\ninterface iobVendorFile {\n vendor?: {\n id?: string;\n name?: string;\n /** Logo for login in admin */\n icon?: string;\n /** Logo in the top left corner of admin */\n logo?: string;\n admin?: {\n menu?: {\n // Settings for left menu\n editable?: false; // Hide edit button in menu\n 'tab-hosts'?: false; // Hide hosts item (See all https://github.com/ioBroker/ioBroker.admin/blob/master/src-rx/src/components/Drawer.js#L142)\n 'tab-files'?: false; // Hide files item\n 'tab-users'?: false; // Hide users item\n 'tab-intro'?: false; // Hide intro item\n 'tab-info'?: false; // Hide info item\n 'tab-adapters'?: false; // Hide adapters item\n 'tab-instances'?: false; // Hide instances item\n 'tab-objects'?: false; // Hide objects item\n 'tab-enums'?: false; // Hide enums item\n 'tab-devices'?: false; // Hide devices item\n 'tab-logs'?: false; // Hide logs item\n 'tab-scenes'?: false; // Hide scenes item\n 'tab-events'?: false; // Hide events item\n 'tab-javascript'?: false; // Hide javascript item\n 'tab-text2command-0'?: false; // Hide text2command-0 item\n 'tab-echarts'?: false; // Hide echarts item\n [tabName: string]: false | undefined;\n };\n appBar?: {\n discovery?: false;\n systemSettings?: false;\n toggleTheme?: false;\n expertMode?: false;\n hostSelector?: false;\n };\n settings?: {\n tabConfig?: false; // Main config tab\n tabRepositories?: false; // Repositories tab\n tabCertificates?: false; // Certificates tab\n tabLetsEncrypt?: false; // Let's Encrypt tab\n tabDefaultACL?: false; // Default ACL tab\n tabStatistics?: false; // Statistics tab\n\n language?: false;\n tempUnit?: false;\n currency?: false;\n dateFormat?: false;\n isFloatComma?: false;\n defaultHistory?: false;\n activeRepo?: false;\n expertMode?: false;\n defaultLogLevel?: false;\n };\n adapters?: {\n gitHubInstall?: false; // hide button install from GitHub/npm\n statistics?: false; // hide statistics on the right top\n filterUpdates?: false; // hide button filter updates in adapter tab\n allowAdapterRating?: false; // do not show and do not load adapter ratings\n };\n login?: {\n title?: string;\n motto?: string;\n link?: string;\n };\n };\n /** Favicon for admin */\n ico?: string;\n uuidPrefix?: string;\n };\n model?: {\n /** name for host */\n name?: string;\n /** Icon for host */\n icon?: string;\n /** Color for host */\n color?: string;\n };\n uuid?: string;\n iobroker?: Partial<ioBroker.IoBrokerJson>;\n objects?: {\n [id: string]: ioBroker.Object;\n };\n}\n\nconst VENDOR_FILE = '/etc/iob-vendor.json';\n\n/**\n * CLI command to apply vendor-specific customizations from the vendor file\n */\nexport class Vendor {\n private readonly objects: ObjectsRedisClient;\n\n /**\n * @param options The objects database client\n */\n constructor(options: CLIVendorOptions) {\n this.objects = options.objects;\n }\n\n /**\n * Deep merge of source into target object\n *\n * @param target target obj\n * @param source source obj\n */\n private deepMerge(target: Record<string, any>, source: Record<string, any>): void {\n Object.keys(source).forEach(attr => {\n if (typeof source[attr] === 'object' && !(source[attr] instanceof Array)) {\n if (target[attr] && typeof target[attr] !== 'object') {\n target[attr] = {};\n }\n target[attr] = target[attr] || {};\n this.deepMerge(target[attr], source[attr]);\n } else {\n target[attr] = source[attr];\n }\n });\n }\n\n /**\n * Read info from '/etc/iob_vendor.json' and executes instructions stored there\n *\n * @param file file path if not given, default path is used\n * @param password vendor password\n * @param javascriptPassword vendor JavaScript password\n * @param logger Logger used to report progress and errors\n */\n async checkVendor(\n file: string | undefined,\n password: string,\n javascriptPassword: string | undefined,\n logger?: InternalLogger,\n ): Promise<boolean> {\n logger ||= {\n debug: (text: string) => console.log(text),\n info: (text: string) => console.log(text),\n error: (text: string) => console.error(text),\n warn: (text: string) => console.warn(text),\n silly: (text: string) => console.log(text),\n };\n\n file ||= VENDOR_FILE;\n\n let data: iobVendorFile;\n if (fs.existsSync(file)) {\n try {\n data = fs.readJSONSync(file);\n } catch (err) {\n logger.error(`cannot read or parse \"${file}\": ${err.message}`);\n throw new Error(`cannot read or parse \"${file}\": ${err.message}`);\n }\n } else {\n logger.error(`\"${file}\" does not exist`);\n throw new Error(`\"${file}\" does not exist`);\n }\n\n if (data?.uuid) {\n const uuid = data.uuid;\n\n // check UUID\n const obj = await this.objects.getObject('system.meta.uuid');\n if (obj?.native) {\n if (obj.native.uuid !== uuid) {\n obj.native.uuid = uuid;\n\n logger.info(`Update \"system.meta.uuid:native.uuid\" = \"${obj.native.uuid}\"`);\n\n obj.nonEdit ||= {};\n obj.nonEdit.password = password;\n try {\n await this.objects.setObjectAsync('system.meta.uuid', obj);\n logger.info(`object system.meta.uuid updated: ${uuid}`);\n } catch (e) {\n logger.error(`Cannot update system.meta.uuid: ${e.message}`);\n }\n }\n } else {\n try {\n // @ts-expect-error type uuid is not allowed TODO: allow it for meta?\n await this.objects.setObjectAsync('system.meta.uuid', {\n type: 'meta',\n common: {\n name: 'uuid',\n type: 'uuid',\n },\n ts: new Date().getTime(),\n from: `system.host.${tools.getHostName()}.tools`,\n native: {\n uuid,\n },\n });\n logger.info(`object system.meta.uuid created: ${uuid}`);\n } catch (e) {\n logger.error(`Cannot create system.meta.uuid: ${e.message}`);\n }\n }\n }\n\n // patch iobroker.json file\n if (data?.iobroker) {\n const settings = fs.readJSONSync(tools.getConfigFileName());\n logger.info('Update iobroker.json file');\n this.deepMerge(settings, data.iobroker);\n fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(settings, null, 2));\n }\n\n if (data?.vendor) {\n const vendor = deepClone(data.vendor);\n\n // store vendor\n try {\n const configObj = await this.objects.getObject('system.config');\n if (configObj?.native) {\n let javascriptPasswordEncrypted: string | undefined;\n if (javascriptPassword) {\n if (!configObj.native?.secret) {\n const buf = randomBytes(24);\n configObj.native.secret = buf.toString('hex');\n }\n javascriptPasswordEncrypted = tools.encrypt(configObj.native.secret, javascriptPassword);\n }\n\n if (\n !isDeepStrictEqual(configObj.native.vendor, vendor) ||\n configObj.native.javascriptPassword !== javascriptPasswordEncrypted\n ) {\n configObj.native.vendor = vendor;\n configObj.nonEdit ||= {};\n if (javascriptPassword) {\n configObj.native.javascriptPassword = javascriptPasswordEncrypted;\n configObj.nonEdit.native ||= {};\n configObj.nonEdit.native.javascriptPassword = javascriptPasswordEncrypted;\n }\n configObj.nonEdit.password = password;\n await this.objects.setObjectAsync(configObj._id, configObj);\n logger.info('object system.config updated');\n }\n }\n } catch (e) {\n logger.error(`Cannot update system.config: ${e.message}`);\n }\n } else if (javascriptPassword) {\n const configObj = await this.objects.getObject('system.config');\n\n if (configObj?.native) {\n if (!configObj.native?.secret) {\n const buf = randomBytes(24);\n configObj.native.secret = buf.toString('hex');\n }\n const javascriptPasswordEncrypted = tools.encrypt(configObj.native.secret, javascriptPassword);\n if (configObj.native.javascriptPassword !== javascriptPasswordEncrypted) {\n configObj.native.javascriptPassword = javascriptPasswordEncrypted;\n configObj.nonEdit ||= {};\n configObj.nonEdit.password = password;\n configObj.nonEdit.native ||= {};\n configObj.nonEdit.native.javascriptPassword = javascriptPasswordEncrypted;\n try {\n await this.objects.setObjectAsync(configObj._id, configObj);\n logger.info('object system.config updated');\n } catch (e) {\n logger.error(`Cannot update system.config: ${e.message}`);\n }\n }\n }\n }\n\n // update all existing objects according to vendor\n if (data?.objects) {\n for (let id of Object.keys(data.objects)) {\n if (!id.includes('*')) {\n const _newObj = data.objects[id];\n const obj = await this.objects.getObject(id);\n if (obj) {\n obj.nonEdit ||= {} as ioBroker.NonEditable;\n const originalObj = deepClone(obj);\n _newObj.nonEdit ||= {} as ioBroker.NonEditable;\n _newObj.nonEdit.passHash = obj.nonEdit.passHash;\n // merge objects\n tools.copyAttributes(_newObj, obj);\n\n if (!isDeepStrictEqual(originalObj, obj)) {\n delete obj.nonEdit.passHash;\n obj.nonEdit.password = password;\n logger.info(`Update \"${obj._id}\"`);\n try {\n await this.objects.setObjectAsync(obj._id, obj);\n logger.info(`object \"${obj._id}\" updated`);\n } catch (e) {\n logger.error(`Cannot update \"${obj._id}\": ${e.message}`);\n }\n }\n } else {\n try {\n await this.objects.setObjectAsync(id, _newObj);\n logger.info(`object \"${_newObj._id}\" updated`);\n } catch (e) {\n logger.error(`Cannot update ${id} \"${JSON.stringify(_newObj)}\": ${e.message}`);\n }\n }\n } else {\n id = id.replace(/\\*/g, '');\n const _obj = data.objects[id];\n const arr = await this.objects.getObjectListAsync(\n {\n startkey: id,\n endkey: `${id}\\u9999`,\n },\n { checked: true },\n );\n\n if (arr?.rows?.length) {\n for (const row of arr.rows) {\n const obj = row.value;\n if (obj) {\n obj.nonEdit ||= {};\n const originalObj = deepClone(obj);\n _obj.nonEdit ||= {};\n _obj.nonEdit.passHash = obj.nonEdit.passHash;\n // merge objects\n tools.copyAttributes(_obj, obj);\n\n if (!isDeepStrictEqual(originalObj, obj)) {\n delete obj.nonEdit.passHash;\n obj.nonEdit.password = password;\n logger.info(`Update \"${obj._id}\"`);\n try {\n await this.objects.setObjectAsync(obj._id, obj);\n logger.info(`object \"${obj._id}\" updated`);\n } catch (e) {\n logger.error(`Cannot update \"${obj._id}\": ${e.message}`);\n }\n }\n }\n }\n }\n }\n }\n }\n\n // update host as last\n if (data?.model) {\n const model = data.model;\n const hostname = tools.getHostName();\n const obj = await this.objects.getObject(`system.host.${hostname}`);\n if (obj?.common) {\n if (\n (model.name && model.name !== 'JS controller' && obj.common.title === 'JS controller') ||\n (model.icon && !obj.common.icon) ||\n (model.color && !obj.common.color)\n ) {\n if (model.name) {\n obj.common.title = model.name;\n }\n if (model.icon) {\n obj.common.icon = model.icon;\n }\n if (model.color) {\n obj.common.color = model.color;\n }\n\n obj.nonEdit ||= {};\n obj.nonEdit.password = password;\n\n if (obj.common.title) {\n logger.info(`Update \"system.host.${hostname}:common.title\" = \"${obj.common.title}\"`);\n }\n if (obj.common.icon) {\n logger.info(`Update \"system.host.${hostname}:common.icon\" = \"${!!obj.common.icon}\"`);\n }\n if (obj.common.color) {\n logger.info(`Update \"system.host.${hostname}:common.color\" = \"${obj.common.color}\"`);\n }\n\n try {\n await this.objects.setObjectAsync(obj._id, obj);\n logger.info(`object \"system.host.${hostname}\" updated`);\n } catch (e) {\n logger.error(`Cannot update \"system.host.${hostname}\": ${e.message}`);\n }\n }\n }\n }\n\n // restart ioBroker\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;AAAA,kCAAsB;AACtB,sBAAe;AACf,wBAAsB;AACtB,uBAAkC;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,GAAG;UACvF;AACA,cAAI,IAAI,OAAO,MAAM;AACjB,mBAAO,KAAK,uBAAuB,QAAQ,qBAAqB,CAAC,CAAC,IAAI,OAAO,IAAI,GAAG;UACxF;AACA,cAAI,IAAI,OAAO,OAAO;AAClB,mBAAO,KAAK,uBAAuB,QAAQ,qBAAqB,IAAI,OAAO,KAAK,GAAG;UACvF;AAEA,cAAI;AACA,kBAAM,KAAK,QAAQ,eAAe,IAAI,KAAK,GAAG;AAC9C,mBAAO,KAAK,uBAAuB,QAAQ,WAAW;UAC1D,SAAS,GAAG;AACR,mBAAO,MAAM,8BAA8B,QAAQ,MAAM,EAAE,OAAO,EAAE;UACxE;QACJ;MACJ;IACJ;AAGA,WAAO;EACX;;",
|
|
6
6
|
"names": ["fs", "deepClone"]
|
|
7
7
|
}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';
|
|
2
2
|
import type { ProcessExitCallback } from '../_Types.js';
|
|
3
|
+
/** Options for the vis debug helper */
|
|
3
4
|
export interface CLIVisDebugOptions {
|
|
5
|
+
/** The objects database client */
|
|
4
6
|
objects: ObjectsRedisClient;
|
|
7
|
+
/** Callback to exit the process with an exit code */
|
|
5
8
|
processExit: ProcessExitCallback;
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Helper to upload a vis widget directory for debugging
|
|
12
|
+
*/
|
|
7
13
|
export declare class VisDebug {
|
|
8
14
|
private readonly objects;
|
|
9
15
|
private readonly processExit;
|
|
16
|
+
/**
|
|
17
|
+
* @param options The objects client and the process-exit callback
|
|
18
|
+
*/
|
|
10
19
|
constructor(options: CLIVisDebugOptions);
|
|
11
20
|
/**
|
|
12
21
|
* Upload widget directory to vis directory
|
|
@@ -38,6 +38,9 @@ var import_js_controller_common2 = require("@iobroker/js-controller-common");
|
|
|
38
38
|
class VisDebug {
|
|
39
39
|
objects;
|
|
40
40
|
processExit;
|
|
41
|
+
/**
|
|
42
|
+
* @param options The objects client and the process-exit callback
|
|
43
|
+
*/
|
|
41
44
|
constructor(options) {
|
|
42
45
|
this.objects = options.objects;
|
|
43
46
|
this.processExit = options.processExit;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/setup/setupVisDebug.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'fs-extra';\nimport { tools } from '@iobroker/js-controller-common';\nimport path from 'node:path';\nimport { EXIT_CODES } from '@iobroker/js-controller-common';\n\nimport type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport type { ProcessExitCallback } from '../_Types.js';\n\nexport interface CLIVisDebugOptions {\n objects: ObjectsRedisClient;\n processExit: ProcessExitCallback;\n}\n\nexport class VisDebug {\n private readonly objects: ObjectsRedisClient;\n private readonly processExit: ProcessExitCallback;\n\n constructor(options: CLIVisDebugOptions) {\n this.objects = options.objects;\n this.processExit = options.processExit;\n }\n\n /**\n * Upload widget directory to vis directory\n *\n * @param widgetDir directory of widgets\n * @param adapter name of the adapter\n * @param pathW widgets path\n */\n private async uploadWidgets(widgetDir: string, adapter: string, pathW: string): Promise<void> {\n if (!fs.existsSync(widgetDir)) {\n console.error(`Cannot upload widgets, because folder \"${widgetDir}\" does not exist`);\n return;\n }\n const dirs = fs.readdirSync(widgetDir);\n\n for (const dir of dirs) {\n const stat = fs.statSync(`${widgetDir}/${dir}`);\n if (stat.isDirectory()) {\n await this.uploadWidgets(`${widgetDir}/${dir}`, adapter, `${pathW}/${dir}`);\n } else {\n console.log(`Upload \"${widgetDir}/${dir}\"`);\n await this.objects.writeFile(adapter, `${pathW}/${dir}`, fs.readFileSync(`${widgetDir}/${dir}`));\n }\n }\n }\n\n /**\n * Activates vis debug for given widget\n *\n * @param widgetset widget to activate vis debug for\n */\n async enableDebug(widgetset: string): Promise<void> {\n let adapterDir: string | undefined;\n\n if (widgetset) {\n // Try to find out the adapter directory out of a list of options\n const adapterNames2Try = [`vis-${widgetset}`, widgetset];\n if (adapterNames2Try[0] === adapterNames2Try[1]) {\n adapterNames2Try.splice(1, 1);\n }\n for (const adapterName of adapterNames2Try) {\n try {\n const adapterDir2Try = tools.getAdapterDir(adapterName)!;\n // Query the entry\n const stats = fs.statSync(adapterDir2Try);\n\n // Is it a directory?\n if (stats.isDirectory()) {\n //found it!\n adapterDir = adapterDir2Try;\n break;\n }\n } catch {\n // OK\n }\n }\n\n if (!adapterDir) {\n console.error(`Adapter not found. Tried: ${adapterNames2Try.join(', ')}`);\n return void this.processExit(EXIT_CODES.MISSING_ADAPTER_FILES);\n }\n }\n\n // copy index.html.original to index.html\n // copy edit.html.original to edit.html\n // correct appName.json\n // correct config.js\n const controllerDir = tools.getControllerDir();\n let visDir = `${controllerDir}/node_modules/${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n visDir = `${controllerDir}/node_modules/${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n visDir = `${controllerDir}/../${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n visDir = `${controllerDir}/../${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n console.error(`Cannot find ${tools.appName.toLowerCase()}.vis`);\n return void this.processExit(EXIT_CODES.MISSING_ADAPTER_FILES);\n }\n }\n }\n }\n\n if (fs.existsSync(`${visDir}/www/index.html.original`)) {\n console.log(`Upload \"${path.normalize(`${visDir}/www/index.html.original`)}\"`);\n const file = fs.readFileSync(`${visDir}/www/index.html.original`, 'utf8');\n try {\n await this.objects.writeFile('vis', 'index.html', file);\n } catch (e) {\n console.error(`Cannot save ${visDir}/vis/index.html: ${e.message}`);\n }\n }\n\n if (fs.existsSync(`${visDir}/www/edit.html.original`)) {\n console.log(`Upload \"${path.normalize(`${visDir}/www/edit.html.original`)}\"`);\n const file = fs.readFileSync(`${visDir}/www/edit.html.original`, 'utf8');\n try {\n await this.objects.writeFile('vis', 'edit.html', file);\n } catch (e) {\n console.error(`Cannot save ${visDir}/vis/index.html: ${e.message}`);\n }\n }\n\n if (fs.existsSync(`${visDir}/www/cache.manifest`)) {\n console.log(`Modify \"${path.normalize(`${visDir}/www/cache.manifest`)}\"`);\n let file = fs.readFileSync(`${visDir}/www/cache.manifest`, 'utf-8');\n // if file does not exists\n if (!file.toString().trim()) {\n const version = fs.readJSONSync(`${visDir}/package.json`).version;\n file = `CACHE MANIFEST\n#\n# vis Version ${version}\n# dev build 2\n\n\n\nNETWORK:\n *\n\n\nCACHE:\n ./img/disconnect.png\n\nFALLBACK:\n ./index.html ./offline.html\n ./edit.html ./offline.html\n`;\n }\n const n = file.match(/# dev build (\\d+)/)![1];\n file = file.replace(`# dev build ${n}`, `# dev build ${parseInt(n, 10) + 1}`);\n // also update it in the vis npm dir like vis does it by itself\n fs.writeFileSync(`${visDir}/www/cache.manifest`, file);\n try {\n await this.objects.writeFile('vis', 'cache.manifest', file);\n } catch (e) {\n console.error(`Cannot save ${visDir}/www/cache.manifest: ${e.message}`);\n }\n }\n\n const file = fs.readJSONSync(tools.getConfigFileName(), 'utf8');\n\n if (!file.objects.noFileCache) {\n file.objects.noFileCache = true;\n fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(file, null, 2));\n await this.objects.enableFileCacheAsync(false);\n console.log('Disable cache. ioBroker restart required! Execute \"iobroker restart\"');\n }\n\n if (widgetset) {\n const { file } = await this.objects.readFile('vis', 'js/config.js', null);\n let content = typeof file === 'string' ? file : file.toString();\n\n content = content.replace(/[\\r\\n]/g, '');\n const json: Record<string, any> = JSON.parse(content.match(/\"widgetSets\":\\s(.*)};/)![1]);\n let found = false;\n for (const widget of Object.values(json)) {\n if (widget === widgetset || widget.name === widgetset) {\n found = true;\n break;\n }\n }\n // if widget-set not found in config.js\n if (!found) {\n console.log('Modify config.js');\n const pckg = fs.readJSONSync(`${adapterDir}/io-package.json`);\n if (pckg.native && pckg.native.dependencies && pckg.native.dependencies.length) {\n json.push({\n name: widgetset,\n depends: pckg.native.dependencies,\n });\n } else {\n json.push(widgetset);\n }\n\n content = content.replace(/\"widgetSets\":\\s+.*};/, `\"widgetSets\": ${JSON.stringify(json, null, 2)}};`);\n\n await this.objects.writeFile('vis', 'js/config.js', content);\n // upload all files into vis\n console.log(`Upload ${adapterDir}/widgets`);\n await this.uploadWidgets(`${adapterDir}/widgets`, 'vis', 'widgets');\n } else {\n // upload all files into vis\n console.log(`Upload \"${adapterDir}/widgets\"`);\n await this.uploadWidgets(`${adapterDir}/widgets`, 'vis', 'widgets');\n }\n }\n\n this.processExit(EXIT_CODES.NO_ERROR);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,sBAAe;AACf,kCAAsB;AACtB,uBAAiB;AACjB,IAAAA,+BAA2B;
|
|
4
|
+
"sourcesContent": ["import fs from 'fs-extra';\nimport { tools } from '@iobroker/js-controller-common';\nimport path from 'node:path';\nimport { EXIT_CODES } from '@iobroker/js-controller-common';\n\nimport type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport type { ProcessExitCallback } from '../_Types.js';\n\n/** Options for the vis debug helper */\nexport interface CLIVisDebugOptions {\n /** The objects database client */\n objects: ObjectsRedisClient;\n /** Callback to exit the process with an exit code */\n processExit: ProcessExitCallback;\n}\n\n/**\n * Helper to upload a vis widget directory for debugging\n */\nexport class VisDebug {\n private readonly objects: ObjectsRedisClient;\n private readonly processExit: ProcessExitCallback;\n\n /**\n * @param options The objects client and the process-exit callback\n */\n constructor(options: CLIVisDebugOptions) {\n this.objects = options.objects;\n this.processExit = options.processExit;\n }\n\n /**\n * Upload widget directory to vis directory\n *\n * @param widgetDir directory of widgets\n * @param adapter name of the adapter\n * @param pathW widgets path\n */\n private async uploadWidgets(widgetDir: string, adapter: string, pathW: string): Promise<void> {\n if (!fs.existsSync(widgetDir)) {\n console.error(`Cannot upload widgets, because folder \"${widgetDir}\" does not exist`);\n return;\n }\n const dirs = fs.readdirSync(widgetDir);\n\n for (const dir of dirs) {\n const stat = fs.statSync(`${widgetDir}/${dir}`);\n if (stat.isDirectory()) {\n await this.uploadWidgets(`${widgetDir}/${dir}`, adapter, `${pathW}/${dir}`);\n } else {\n console.log(`Upload \"${widgetDir}/${dir}\"`);\n await this.objects.writeFile(adapter, `${pathW}/${dir}`, fs.readFileSync(`${widgetDir}/${dir}`));\n }\n }\n }\n\n /**\n * Activates vis debug for given widget\n *\n * @param widgetset widget to activate vis debug for\n */\n async enableDebug(widgetset: string): Promise<void> {\n let adapterDir: string | undefined;\n\n if (widgetset) {\n // Try to find out the adapter directory out of a list of options\n const adapterNames2Try = [`vis-${widgetset}`, widgetset];\n if (adapterNames2Try[0] === adapterNames2Try[1]) {\n adapterNames2Try.splice(1, 1);\n }\n for (const adapterName of adapterNames2Try) {\n try {\n const adapterDir2Try = tools.getAdapterDir(adapterName)!;\n // Query the entry\n const stats = fs.statSync(adapterDir2Try);\n\n // Is it a directory?\n if (stats.isDirectory()) {\n //found it!\n adapterDir = adapterDir2Try;\n break;\n }\n } catch {\n // OK\n }\n }\n\n if (!adapterDir) {\n console.error(`Adapter not found. Tried: ${adapterNames2Try.join(', ')}`);\n return void this.processExit(EXIT_CODES.MISSING_ADAPTER_FILES);\n }\n }\n\n // copy index.html.original to index.html\n // copy edit.html.original to edit.html\n // correct appName.json\n // correct config.js\n const controllerDir = tools.getControllerDir();\n let visDir = `${controllerDir}/node_modules/${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n visDir = `${controllerDir}/node_modules/${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n visDir = `${controllerDir}/../${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n visDir = `${controllerDir}/../${tools.appName.toLowerCase()}.vis`;\n if (!fs.existsSync(visDir)) {\n console.error(`Cannot find ${tools.appName.toLowerCase()}.vis`);\n return void this.processExit(EXIT_CODES.MISSING_ADAPTER_FILES);\n }\n }\n }\n }\n\n if (fs.existsSync(`${visDir}/www/index.html.original`)) {\n console.log(`Upload \"${path.normalize(`${visDir}/www/index.html.original`)}\"`);\n const file = fs.readFileSync(`${visDir}/www/index.html.original`, 'utf8');\n try {\n await this.objects.writeFile('vis', 'index.html', file);\n } catch (e) {\n console.error(`Cannot save ${visDir}/vis/index.html: ${e.message}`);\n }\n }\n\n if (fs.existsSync(`${visDir}/www/edit.html.original`)) {\n console.log(`Upload \"${path.normalize(`${visDir}/www/edit.html.original`)}\"`);\n const file = fs.readFileSync(`${visDir}/www/edit.html.original`, 'utf8');\n try {\n await this.objects.writeFile('vis', 'edit.html', file);\n } catch (e) {\n console.error(`Cannot save ${visDir}/vis/index.html: ${e.message}`);\n }\n }\n\n if (fs.existsSync(`${visDir}/www/cache.manifest`)) {\n console.log(`Modify \"${path.normalize(`${visDir}/www/cache.manifest`)}\"`);\n let file = fs.readFileSync(`${visDir}/www/cache.manifest`, 'utf-8');\n // if file does not exists\n if (!file.toString().trim()) {\n const version = fs.readJSONSync(`${visDir}/package.json`).version;\n file = `CACHE MANIFEST\n#\n# vis Version ${version}\n# dev build 2\n\n\n\nNETWORK:\n *\n\n\nCACHE:\n ./img/disconnect.png\n\nFALLBACK:\n ./index.html ./offline.html\n ./edit.html ./offline.html\n`;\n }\n const n = file.match(/# dev build (\\d+)/)![1];\n file = file.replace(`# dev build ${n}`, `# dev build ${parseInt(n, 10) + 1}`);\n // also update it in the vis npm dir like vis does it by itself\n fs.writeFileSync(`${visDir}/www/cache.manifest`, file);\n try {\n await this.objects.writeFile('vis', 'cache.manifest', file);\n } catch (e) {\n console.error(`Cannot save ${visDir}/www/cache.manifest: ${e.message}`);\n }\n }\n\n const file = fs.readJSONSync(tools.getConfigFileName(), 'utf8');\n\n if (!file.objects.noFileCache) {\n file.objects.noFileCache = true;\n fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(file, null, 2));\n await this.objects.enableFileCacheAsync(false);\n console.log('Disable cache. ioBroker restart required! Execute \"iobroker restart\"');\n }\n\n if (widgetset) {\n const { file } = await this.objects.readFile('vis', 'js/config.js', null);\n let content = typeof file === 'string' ? file : file.toString();\n\n content = content.replace(/[\\r\\n]/g, '');\n const json: Record<string, any> = JSON.parse(content.match(/\"widgetSets\":\\s(.*)};/)![1]);\n let found = false;\n for (const widget of Object.values(json)) {\n if (widget === widgetset || widget.name === widgetset) {\n found = true;\n break;\n }\n }\n // if widget-set not found in config.js\n if (!found) {\n console.log('Modify config.js');\n const pckg = fs.readJSONSync(`${adapterDir}/io-package.json`);\n if (pckg.native && pckg.native.dependencies && pckg.native.dependencies.length) {\n json.push({\n name: widgetset,\n depends: pckg.native.dependencies,\n });\n } else {\n json.push(widgetset);\n }\n\n content = content.replace(/\"widgetSets\":\\s+.*};/, `\"widgetSets\": ${JSON.stringify(json, null, 2)}};`);\n\n await this.objects.writeFile('vis', 'js/config.js', content);\n // upload all files into vis\n console.log(`Upload ${adapterDir}/widgets`);\n await this.uploadWidgets(`${adapterDir}/widgets`, 'vis', 'widgets');\n } else {\n // upload all files into vis\n console.log(`Upload \"${adapterDir}/widgets\"`);\n await this.uploadWidgets(`${adapterDir}/widgets`, 'vis', 'widgets');\n }\n }\n\n this.processExit(EXIT_CODES.NO_ERROR);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,sBAAe;AACf,kCAAsB;AACtB,uBAAiB;AACjB,IAAAA,+BAA2B;AAgBrB,MAAO,SAAQ;EACA;EACA;;;;EAKjB,YAAY,SAA2B;AACnC,SAAK,UAAU,QAAQ;AACvB,SAAK,cAAc,QAAQ;EAC/B;;;;;;;;EASQ,MAAM,cAAc,WAAmB,SAAiB,OAAa;AACzE,QAAI,CAAC,gBAAAC,QAAG,WAAW,SAAS,GAAG;AAC3B,cAAQ,MAAM,0CAA0C,SAAS,kBAAkB;AACnF;IACJ;AACA,UAAM,OAAO,gBAAAA,QAAG,YAAY,SAAS;AA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,kBAAQ;AACR;QACJ;MACJ;AAEA,UAAI,CAAC,OAAO;AACR,gBAAQ,IAAI,kBAAkB;AAC9B,cAAM,OAAO,gBAAAF,QAAG,aAAa,GAAG,UAAU,kBAAkB;AAC5D,YAAI,KAAK,UAAU,KAAK,OAAO,gBAAgB,KAAK,OAAO,aAAa,QAAQ;AAC5E,eAAK,KAAK;YACN,MAAM;YACN,SAAS,KAAK,OAAO;WACxB;QACL,OAAO;AACH,eAAK,KAAK,SAAS;QACvB;AAEA,kBAAU,QAAQ,QAAQ,wBAAwB,iBAAiB,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC,IAAI;AAEpG,cAAM,KAAK,QAAQ,UAAU,OAAO,gBAAgB,OAAO;AAE3D,gBAAQ,IAAI,UAAU,UAAU,UAAU;AAC1C,cAAM,KAAK,cAAc,GAAG,UAAU,YAAY,OAAO,SAAS;MACtE,OAAO;AAEH,gBAAQ,IAAI,WAAW,UAAU,WAAW;AAC5C,cAAM,KAAK,cAAc,GAAG,UAAU,YAAY,OAAO,SAAS;MACtE;IACJ;AAEA,SAAK,YAAY,wCAAW,QAAQ;EACxC;;",
|
|
6
6
|
"names": ["import_js_controller_common", "fs", "path", "file"]
|
|
7
7
|
}
|
|
@@ -4,10 +4,15 @@ export type ProcessExitCallback = (exitCode: number) => void;
|
|
|
4
4
|
export type CleanDatabaseHandler = (isDeleteDb: boolean) => any;
|
|
5
5
|
export type DbConnectCallback = (params: DbConnectAsyncReturn) => void;
|
|
6
6
|
export type DbConnect = (onlyCheckOrParams?: boolean | Record<string, any>, paramsOrCb?: Record<string, any> | DbConnectCallback, callback?: DbConnectCallback) => void;
|
|
7
|
+
/** Result returned once the database connection has been established */
|
|
7
8
|
export interface DbConnectAsyncReturn {
|
|
9
|
+
/** The connected objects database client */
|
|
8
10
|
objects: ObjectsRedisClient;
|
|
11
|
+
/** The connected states database client */
|
|
9
12
|
states: StatesRedisClient;
|
|
13
|
+
/** Whether the controller is offline (no running host) */
|
|
10
14
|
isOffline?: boolean;
|
|
15
|
+
/** Type of the objects database backend */
|
|
11
16
|
objectsDBType: string;
|
|
12
17
|
/** The iobroker.json config file */
|
|
13
18
|
config: ioBroker.IoBrokerJson;
|
|
@@ -22,7 +27,9 @@ interface IoPackageCommon extends ioBroker.AdapterCommon {
|
|
|
22
27
|
};
|
|
23
28
|
};
|
|
24
29
|
}
|
|
30
|
+
/** An adapter object as stored in io-package.json */
|
|
25
31
|
export interface IoPackage extends ioBroker.AdapterObject {
|
|
32
|
+
/** The common section including the plugins configuration */
|
|
26
33
|
common: IoPackageCommon;
|
|
27
34
|
}
|
|
28
35
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_Types.d.ts","sourceRoot":"","sources":["../../../src/lib/_Types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,IAAI,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAE/E,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAC7D,MAAM,MAAM,oBAAoB,GAAG,CAAC,UAAU,EAAE,OAAO,KAAK,GAAG,CAAC;AAChE,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAEvE,MAAM,MAAM,SAAS,GAAG,CACpB,iBAAiB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,iBAAiB,EACpD,QAAQ,CAAC,EAAE,iBAAiB,KAC3B,IAAI,CAAC;AAEV,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC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M,EAAE,GAAG,CAAC,GAAG,iBAAiB,EACpD,QAAQ,CAAC,EAAE,iBAAiB,KAC3B,IAAI,CAAC;AAEV,wEAAwE;AACxE,MAAM,WAAW,oBAAoB;IACjC,4CAA4C;IAC5C,OAAO,EAAE,kBAAkB,CAAC;IAC5B,2CAA2C;IAC3C,MAAM,EAAE,iBAAiB,CAAC;IAC1B,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC;CACjC;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACjH,MAAM,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC;AAC3C,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAEjD,UAAU,eAAgB,SAAQ,QAAQ,CAAC,aAAa;IACpD,OAAO,EAAE;QACL,CAAC,UAAU,EAAE,MAAM,GAAG;YAClB,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC;SAC5B,CAAC;KACL,CAAC;CACL;AACD,qDAAqD;AACrD,MAAM,WAAW,SAAU,SAAQ,QAAQ,CAAC,aAAa;IACrD,6DAA6D;IAC7D,MAAM,EAAE,eAAe,CAAC;CAC3B"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { CLICommand, type CLICommandOptions } from './cliCommand.js';
|
|
2
2
|
/** Command ioBroker cert ... */
|
|
3
3
|
export declare class CLICert extends CLICommand {
|
|
4
|
+
/**
|
|
5
|
+
* @param options The command options including context and parameters
|
|
6
|
+
*/
|
|
4
7
|
constructor(options: CLICommandOptions);
|
|
5
8
|
/**
|
|
6
9
|
* Executes a command
|
|
7
10
|
*
|
|
8
|
-
* @param args
|
|
11
|
+
* @param args The command arguments (the first is the sub-command)
|
|
9
12
|
*/
|
|
10
13
|
execute(args: any[]): void | Promise<void>;
|
|
11
14
|
/**
|
|
@@ -15,7 +18,7 @@ export declare class CLICert extends CLICommand {
|
|
|
15
18
|
/**
|
|
16
19
|
* View the certificates on CLI
|
|
17
20
|
*
|
|
18
|
-
* @param _args
|
|
21
|
+
* @param _args The command arguments (the second is the certificate name)
|
|
19
22
|
*/
|
|
20
23
|
view(_args: any[]): void;
|
|
21
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliCert.d.ts","sourceRoot":"","sources":["../../../../src/lib/cli/cliCert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKrE,gCAAgC;AAChC,qBAAa,OAAQ,SAAQ,UAAU;
|
|
1
|
+
{"version":3,"file":"cliCert.d.ts","sourceRoot":"","sources":["../../../../src/lib/cli/cliCert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKrE,gCAAgC;AAChC,qBAAa,OAAQ,SAAQ,UAAU;IACnC;;OAEG;gBACS,OAAO,EAAE,iBAAiB;IAItC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB1C;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB7B;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI;CAwB3B"}
|
|
@@ -4,13 +4,16 @@ import * as messages from './messages.js';
|
|
|
4
4
|
import { tools, EXIT_CODES } from '@iobroker/js-controller-common';
|
|
5
5
|
/** Command ioBroker cert ... */
|
|
6
6
|
export class CLICert extends CLICommand {
|
|
7
|
+
/**
|
|
8
|
+
* @param options The command options including context and parameters
|
|
9
|
+
*/
|
|
7
10
|
constructor(options) {
|
|
8
11
|
super(options);
|
|
9
12
|
}
|
|
10
13
|
/**
|
|
11
14
|
* Executes a command
|
|
12
15
|
*
|
|
13
|
-
* @param args
|
|
16
|
+
* @param args The command arguments (the first is the sub-command)
|
|
14
17
|
*/
|
|
15
18
|
execute(args) {
|
|
16
19
|
const { callback, showHelp } = this.options;
|
|
@@ -51,7 +54,7 @@ export class CLICert extends CLICommand {
|
|
|
51
54
|
/**
|
|
52
55
|
* View the certificates on CLI
|
|
53
56
|
*
|
|
54
|
-
* @param _args
|
|
57
|
+
* @param _args The command arguments (the second is the certificate name)
|
|
55
58
|
*/
|
|
56
59
|
view(_args) {
|
|
57
60
|
let certName = _args[1];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliCert.js","sourceRoot":"","sources":["../../../../src/lib/cli/cliCert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEnE,gCAAgC;AAChC,MAAM,OAAO,OAAQ,SAAQ,UAAU;IACnC,YAAY,OAA0B;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,IAAW;QACf,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAExB,QAAQ,OAAO,EAAE,CAAC;YACd,KAAK,OAAO,CAAC;YACb,KAAK,QAAQ;gBACT,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;YACzB,KAAK,MAAM;gBACP,OAAO,IAA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