Skip to content

Commit aa69ebd

Browse files
committed
Adding salt encryption in .env
Changing values: PANEL_URL, ADMIN_URL
1 parent 1a96f34 commit aa69ebd

File tree

17 files changed

+89
-77
lines changed

17 files changed

+89
-77
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ sudo nano .env
333333

334334
```
335335
# Set this with your node URL (e.g., 'zksensor.com')
336-
NODE_ID='YOUR_NODE_DOMAIN'
336+
PANEL_URL='YOUR_NODE_DOMAIN'
337+
338+
# Set this with your node admin URL (e.g., 'admin.zksensor.com')
339+
ADMIN_URL='YOUR_NODE_ADMIN_DOMAIN'
337340
338341
# Set this with your node name (e.g., 'zkSensor')
339342
NODE_NAME='YOUR_NODE_NAME'
@@ -349,9 +352,11 @@ FAUCET_WALLET_PRIVATE_KEY='YOUR_FAUCET_WALLET_PRIVATE_KEY'
349352
# Admin Wallet Private Key
350353
ADMIN_WALLET_PRIVATE_KEY='YOUR_ADMIN_WALLET_PRIVATE_KEY'
351354
355+
# Sets how many times passwords are hashed. Higher values mean stronger security but slower processing
356+
CRYPTION_SALT=10
357+
352358
# Server Configuration
353359
HOST_PROTOCOL='https://'
354-
HOST_NAME_OR_IP=PANEL_URL
355360
HOST_PORT='6000'
356361
HOST_SUB_DIRECTORY='app'
357362
@@ -424,7 +429,10 @@ Never share your account’s private key with anyone.
424429
- Update these parameters in the file:
425430
```
426431
# Set this with your node URL (e.g., 'zksensor.com')
427-
NODE_ID='YOUR_NODE_DOMAIN'
432+
PANEL_URL='YOUR_NODE_DOMAIN'
433+
434+
# Set this with your node admin URL (e.g., 'admin.zksensor.com')
435+
ADMIN_URL='YOUR_NODE_ADMIN_DOMAIN'
428436
429437
# Set this with your node name (e.g., 'zkSensor')
430438
NODE_NAME='YOUR_NODE_NAME'
@@ -435,8 +443,6 @@ MONGO_PASSWORD='FIDESINNOVA_DB_PASSWORD'
435443
FAUCET_WALLET_PRIVATE_KEY='YOUR_FAUCET_WALLET_PRIVATE_KEY'
436444
ADMIN_WALLET_PRIVATE_KEY='YOUR_ADMIN_WALLET_PRIVATE_KEY'
437445
438-
HOST_NAME_OR_IP='panel.YOUR-DOMAIN'
439-
440446
# Email Server Configuration
441447
MAIL_HOST='YOUR_HOST_MAIL_SERVER_PROVIDER'
442448
# Please check your email server’s mail port number by configuring an email client on your mobile or computer to confirm. On some servers, it may be 587 or a different port.

backend/src/app.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class AppController {
7272
background: process.env.THEME_BACKGROUND,
7373
box: process.env.THEME_BOX,
7474
button: process.env.THEME_BUTTON,
75-
nodeId: process.env.NODE_ID,
75+
nodeId: process.env.PANEL_URL,
7676
};
7777
}
7878

backend/src/app.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class AppService {
3131
const fileContent = await fs.promises.readFile(filePath, 'utf-8');
3232
this.deviceList = JSON.parse(fileContent).map((device) => ({
3333
...device,
34-
url: `${process.env.HOST_PROTOCOL}${process.env.HOST_NAME_OR_IP}/${process.env.HOST_SUB_DIRECTORY}/uploads/devices/${device.fileName}`,
34+
url: `${process.env.HOST_PROTOCOL}${process.env.PANEL_URL}/${process.env.HOST_SUB_DIRECTORY}/uploads/devices/${device.fileName}`,
3535
}));
3636
} catch (error) {
3737
console.error('Error reading devices.json:');
@@ -82,7 +82,7 @@ export class AppService {
8282
const device = this.deviceList.find((d) => d.type === deviceType);
8383

8484
if (device) {
85-
return `${process.env.HOST_PROTOCOL}${process.env.HOST_NAME_OR_IP}/${process.env.HOST_SUB_DIRECTORY}/uploads/devices/${device.fileName}`;
85+
return `${process.env.HOST_PROTOCOL}${process.env.PANEL_URL}/${process.env.HOST_SUB_DIRECTORY}/uploads/devices/${device.fileName}`;
8686
} else {
8787
console.log(`Device type "${deviceType}" not found.`);
8888
return null;

backend/src/main.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,8 @@ async function bootstrap() {
2525

2626
app.useStaticAssets(join(__dirname, '../uploads'));
2727

28-
const hostName = process.env.HOST_NAME_OR_IP;
29-
let adminHostName = '';
30-
31-
if (hostName == 'developer.fidesinnova.io') {
32-
adminHostName = 'admindeveloper.fidesinnova.io';
33-
} else {
34-
// const host = String(hostName).split('.').slice(-2).join('.');
35-
const parts = String(hostName).split('.');
36-
const host = parts.slice(1).join('.');
37-
adminHostName = 'admin.' + host;
38-
}
39-
40-
console.log('adminHostName:', adminHostName);
41-
console.log('hostName:', hostName);
28+
const hostName = process.env.PANEL_URL || '';
29+
const adminHostName = process.env.ADMIN_URL || '';
4230

4331
app.enableCors({
4432
origin: (origin, callback) => {

backend/src/modules/broker/services/mqtt.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class MqttService implements OnModuleInit {
116116
);
117117
});
118118

119-
const host = 'https://' + process.env.HOST_NAME_OR_IP;
119+
const host = 'https://' + process.env.PANEL_URL;
120120

121121
// fired when a client connects
122122
aedes.on('client', async function (client) {
@@ -248,7 +248,7 @@ export class MqttService implements OnModuleInit {
248248
const { proof, ...dataWithoutProof } = parsedPayload.data;
249249
const deviceData = await this.getDeviceType(parsedPayload.from)
250250
await this.contractService.storeZKP(
251-
String(process.env.NODE_ID),
251+
String(process.env.PANEL_URL),
252252
String(client.id),
253253
JSON.stringify(proof),
254254
JSON.stringify(dataWithoutProof),
@@ -263,7 +263,8 @@ export class MqttService implements OnModuleInit {
263263
true,
264264
);
265265

266-
await this.deviceService.editDevice(
266+
try {
267+
await this.deviceService.editDevice(
267268
{
268269
deviceId: String(deviceData?._id),
269270
hardwareVersion: Number(String(parsedPayload.data.HV)),
@@ -272,9 +273,13 @@ export class MqttService implements OnModuleInit {
272273
'root',
273274
true,
274275
);
275-
console.log(
276+
console.log(
276277
`HV and FV of device with id: ${deviceData._id} updated successfully.`,
277278
);
279+
} catch (error) {
280+
console.log('Error updating device HV and FV:', error);
281+
}
282+
278283
}
279284

280285
axios

backend/src/modules/device/controllers/device-type.controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class DeviceTypeController {
3535

3636
constructor(private readonly deviceTypeService: DeviceTypeService) {}
3737

38-
@Get('v1/device-type/get-all-device-types')
38+
/* @Get('v1/device-type/get-all-device-types')
3939
@HttpCode(200)
4040
@UseGuards(JwtAuthGuard)
4141
@ApiBearerAuth()
@@ -44,7 +44,7 @@ export class DeviceTypeController {
4444
description: 'Gets all device types.',
4545
})
4646
async getAllDeviceTypes() {
47-
/* await this.deviceTypeService.getAllDeviceTypes()
47+
await this.deviceTypeService.getAllDeviceTypes()
4848
.then((data)=>{
4949
this.result = data
5050
})
@@ -54,6 +54,6 @@ export class DeviceTypeController {
5454
throw new GeneralException(ErrorTypeEnum.UNPROCESSABLE_ENTITY, errorMessage)
5555
})
5656
57-
return this.result; */
58-
}
57+
return this.result;
58+
} */
5959
}

backend/src/modules/device/controllers/device.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class DeviceController {
9292
const newBody = {
9393
...body,
9494
userId: request.user.userId,
95-
nodeId: process.env.NODE_ID,
95+
nodeId: process.env.PANEL_URL,
9696
};
9797
return await this.deviceService.insertDevice(newBody);
9898
}

backend/src/modules/device/services/device.service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,10 @@ export class DeviceService {
491491
console.log('Founded Device is:', foundDevice);
492492

493493
console.log(
494-
`Device Node: ${foundDevice.nodeId} ||| BackEnd Node: ${process.env.NODE_ID}`,
494+
`Device Node: ${foundDevice.nodeId} ||| BackEnd Node: ${process.env.PANEL_URL}`,
495495
);
496496

497-
if (String(foundDevice.nodeId) !== String(process.env.NODE_ID)) {
497+
if (String(foundDevice.nodeId) !== String(process.env.PANEL_URL)) {
498498
let errorMessage = `You can't edit other nodes devices !`;
499499
throw new GeneralException(ErrorTypeEnum.FORBIDDEN, errorMessage);
500500
}
@@ -513,7 +513,7 @@ export class DeviceService {
513513
};
514514
return this.result;
515515
}
516-
foundDevice.nodeId = String(process.env.NODE_ID);
516+
foundDevice.nodeId = String(process.env.PANEL_URL);
517517
foundDevice.updatedBy =
518518
String(userId) == 'root' ? foundDevice.updatedBy : userId;
519519
foundDevice.updateDate = new Date();
@@ -528,7 +528,7 @@ export class DeviceService {
528528
this.result = data;
529529
if (body.isShared == true && foundDevice.isShared == false) {
530530
this.contractService.shareDevice(
531-
String(process.env.NODE_ID),
531+
String(process.env.PANEL_URL),
532532
String(newData._id),
533533
String(newData.userId),
534534
String(newData.deviceName),
@@ -549,7 +549,7 @@ export class DeviceService {
549549
newData.deviceEncryptedId,
550550
);
551551
this.contractService.removeSharedDevice(
552-
process.env.NODE_ID,
552+
process.env.PANEL_URL,
553553
String(newData._id),
554554
);
555555
}
@@ -563,7 +563,7 @@ export class DeviceService {
563563
}
564564

565565
async updateAllDevices() {
566-
await this.deviceRepository.updateAllNodeIds(process.env.NODE_ID);
566+
await this.deviceRepository.updateAllNodeIds(process.env.PANEL_URL);
567567
}
568568

569569
async renameDevice(body, userId, isAdmin = false): Promise<any> {
@@ -850,7 +850,7 @@ export class DeviceService {
850850
console.log('Updated found device for deletion is: ', foundDevice);
851851

852852
this.contractService.removeSharedDevice(
853-
process.env.NODE_ID,
853+
process.env.PANEL_URL,
854854
String(foundDevice._id),
855855
);
856856

@@ -899,7 +899,7 @@ export class DeviceService {
899899

900900
for (const element of devices) {
901901
this.contractService.removeSharedDevice(
902-
process.env.NODE_ID,
902+
process.env.PANEL_URL,
903903
String(element._id),
904904
);
905905

backend/src/modules/media/services/media.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class MediaService {
5959
_id: uploadedFile._id,
6060
fileName: uploadedFile.fileName,
6161
path: uploadedFile.path,
62-
url: `${process.env.HOST_PROTOCOL + process.env.HOST_NAME_OR_IP}/${
62+
url: `${process.env.HOST_PROTOCOL + process.env.PANEL_URL}/${
6363
process.env.HOST_SUB_DIRECTORY
6464
}/${String(basePath).replace('./', '')}/${uploadedFile.path}`,
6565
size: uploadedFile.size,
@@ -93,7 +93,7 @@ export class MediaService {
9393

9494
return {
9595
...media._doc,
96-
url: `${process.env.HOST_PROTOCOL + process.env.HOST_NAME_OR_IP}/${
96+
url: `${process.env.HOST_PROTOCOL + process.env.PANEL_URL}/${
9797
process.env.HOST_SUB_DIRECTORY
9898
}/${media.path}`,
9999
};

backend/src/modules/service/controllers/service.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class ServiceController {
7171
const data = {
7272
...body,
7373
userId: request.user.userId,
74-
nodeId: process.env.NODE_ID
74+
nodeId: process.env.PANEL_URL
7575
};
7676
return await this.serviceService.insertService(data);
7777
}

0 commit comments

Comments
 (0)