Skip to content

Commit f7a45d6

Browse files
committed
Modified process with javascript Password
1 parent ba77e82 commit f7a45d6

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

packages/cli/src/lib/setup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,7 @@ async function processCommand(
27232723
case 'vendor': {
27242724
const password = args[0];
27252725
const file = args[1];
2726+
const javascriptPassword = args[2];
27262727
if (!password) {
27272728
console.warn(
27282729
`Please specify the password to update the vendor information!\n${tools.appName.toLowerCase()} vendor <PASS_PHRASE> <vendor.json>`,
@@ -2735,7 +2736,7 @@ async function processCommand(
27352736
const vendor = new Vendor({ objects });
27362737

27372738
try {
2738-
await vendor.checkVendor(file, password);
2739+
await vendor.checkVendor(file, password, javascriptPassword);
27392740
console.log(`Synchronised vendor information.`);
27402741
return void callback();
27412742
} catch (err) {

packages/cli/src/lib/setup/setupVendor.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ interface iobVendorFile {
1313
vendor?: {
1414
id?: string;
1515
name?: string;
16+
/** Logo for login in admin */
1617
icon?: string;
18+
/** Logo in the top left corner of admin */
19+
logo?: string;
1720
admin?: {
1821
menu?: {
1922
// Settings for left menu
@@ -73,23 +76,23 @@ interface iobVendorFile {
7376
link?: string;
7477
};
7578
};
79+
/** Favicon for admin */
7680
ico?: string;
7781
uuidPrefix?: string;
7882
};
7983
model?: {
80-
// name for host
84+
/** name for host */
8185
name?: string;
82-
// Icon for host
86+
/** Icon for host */
8387
icon?: string;
84-
// Color for host
88+
/** Color for host */
8589
color?: string;
8690
};
8791
uuid?: string;
8892
iobroker?: Partial<ioBroker.IoBrokerJson>;
8993
objects?: {
9094
[id: string]: ioBroker.Object;
9195
};
92-
javascriptPassword?: string;
9396
}
9497

9598
const VENDOR_FILE = '/etc/iob-vendor.json';
@@ -126,9 +129,15 @@ export class Vendor {
126129
*
127130
* @param file file path if not given, default path is used
128131
* @param password vendor password
132+
* @param javascriptPassword vendor JavaScript password
129133
* @param logger
130134
*/
131-
async checkVendor(file: string | undefined, password: string, logger?: InternalLogger): Promise<void> {
135+
async checkVendor(
136+
file: string | undefined,
137+
password: string,
138+
javascriptPassword: string | undefined,
139+
logger?: InternalLogger,
140+
): Promise<void> {
132141
logger ||= {
133142
debug: (text: string) => console.log(text),
134143
info: (text: string) => console.log(text),
@@ -208,22 +217,21 @@ export class Vendor {
208217
try {
209218
const obj = await this.objects.getObject('system.config');
210219
if (obj?.native) {
211-
let javascriptPassword: string | undefined;
212-
213-
if (data.javascriptPassword) {
214-
javascriptPassword = tools.encrypt(obj.native.secret, data.javascriptPassword);
220+
let javascriptPasswordEncrypted: string | undefined;
221+
if (javascriptPassword) {
222+
javascriptPasswordEncrypted = tools.encrypt(obj.native.secret, javascriptPassword);
215223
}
216224

217225
if (
218226
!isDeepStrictEqual(obj.native.vendor, vendor) ||
219-
obj.native.javascriptPassword !== javascriptPassword
227+
obj.native.javascriptPassword !== javascriptPasswordEncrypted
220228
) {
221229
obj.native.vendor = vendor;
222230
obj.nonEdit ||= {};
223231
if (javascriptPassword) {
224-
obj.native.javascriptPassword = javascriptPassword;
232+
obj.native.javascriptPassword = javascriptPasswordEncrypted;
225233
obj.nonEdit.native ||= {};
226-
obj.nonEdit.native.javascriptPassword = javascriptPassword;
234+
obj.nonEdit.native.javascriptPassword = javascriptPasswordEncrypted;
227235
}
228236
obj.nonEdit.password = password;
229237
await this.objects.setObjectAsync(obj._id, obj);
@@ -233,18 +241,18 @@ export class Vendor {
233241
} catch (e) {
234242
logger.error(`Cannot update system.config: ${e.message}`);
235243
}
236-
} else if (data?.javascriptPassword) {
244+
} else if (javascriptPassword) {
237245
const obj = await this.objects.getObject('system.config');
238246

239247
if (obj?.native) {
240-
const javascriptPassword = tools.encrypt(obj.native.secret, data.javascriptPassword);
241-
if (obj.native?.javascriptPassword !== javascriptPassword) {
248+
const javascriptPasswordEncrypted = tools.encrypt(obj.native.secret, javascriptPassword);
249+
if (obj.native?.javascriptPassword !== javascriptPasswordEncrypted) {
242250
obj.native ||= {};
243-
obj.native.javascriptPassword = javascriptPassword;
251+
obj.native.javascriptPassword = javascriptPasswordEncrypted;
244252
obj.nonEdit ||= {};
245253
obj.nonEdit.password = password;
246254
obj.nonEdit.native ||= {};
247-
obj.nonEdit.native.javascriptPassword = javascriptPassword;
255+
obj.nonEdit.native.javascriptPassword = javascriptPasswordEncrypted;
248256
try {
249257
await this.objects.setObjectAsync(obj._id, obj);
250258
logger.info('object system.config updated');

packages/controller/src/main.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,15 +1767,23 @@ async function setMeta(): Promise<void> {
17671767
logger?.info(`${hostLogPrefix} Detected vendor file: ${fs.existsSync(VENDOR_BOOTSTRAP_FILE)}`);
17681768

17691769
try {
1770-
const startScript = fs.readJSONSync(VENDOR_BOOTSTRAP_FILE);
1770+
const startScript: {
1771+
password?: string;
1772+
javascriptPassword?: string;
1773+
} = fs.readJSONSync(VENDOR_BOOTSTRAP_FILE);
17711774

17721775
if (startScript.password) {
17731776
const { Vendor } = await import('@iobroker/js-controller-cli');
17741777
const vendor = new Vendor({ objects: objects! });
17751778

17761779
logger?.info(`${hostLogPrefix} Apply vendor file: ${VENDOR_FILE}`);
17771780
try {
1778-
await vendor.checkVendor(VENDOR_FILE, startScript.password, logger);
1781+
await vendor.checkVendor(
1782+
VENDOR_FILE,
1783+
startScript.password,
1784+
startScript.javascriptPassword,
1785+
logger,
1786+
);
17791787
logger?.info(`${hostLogPrefix} Vendor information synchronised.`);
17801788
try {
17811789
if (fs.existsSync(VENDOR_BOOTSTRAP_FILE)) {

0 commit comments

Comments
 (0)