-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
84 lines (68 loc) · 2.05 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
const Homey = require('homey');
const globalVarMQTT = require("./global.js");
const brokerMQTT = require("./broker.js");
const logMQTT = require("./logmodule.js");
class MQTTBrokerApp extends Homey.App {
onInit() {
this.Homey = Homey;
this.logmodule = new logMQTT(this);
this.globalVar = new globalVarMQTT(this);
this.broker = new brokerMQTT(this);
}
changedSettings(body) {
this.logmodule.writelog('info',"changedSettings called");
this.logmodule.writelog('debug', body);
this.logmodule.setDebugState();
this.broker.stopBroker();
if (this.broker.getConnectOptions()) {
this.logmodule.writelog('info',"Settings checked OK");
// restart broker to listen on different port number
this.broker.startBroker();
return true;
}
return false;
}
getLogLines() {
return this.logmodule.getLogLines();
}
addNewUser(args) {
return this.globalVar.addNewUser(args);
}
deleteUser(args) {
return this.globalVar.deleteUser(args);
}
purgeUserData(args) {
return this.globalVar.purgeUserData(args);
}
/*
getUserArray: Getter for returning the user array to settings.
*/
getUserArray() {
return this.globalVar.getUserArray();
}
startBroker(args) {
return this.broker.startBroker();
}
stopBroker(args) {
return this.broker.stopBroker();
}
isBrokerRunning() {
return this.broker.isBrokerRunning();
}
generateSelfSignedCerts(body) {
this.logmodule.writelog('debug', "generateSelfSignedCerts called in app.js");
this.logmodule.writelog('debug', JSON.stringify(body));
const selfsigned = require("selfsigned");
var attrs = [{ name: 'commonName', value: body.commonname }];
var pems = selfsigned.generate(attrs, { days: body.daysvalid });
return pems;
}
saveX509Certs(args) {
this.broker.writeX509Data(args);
}
readX509Certs() {
return this.broker.readX509Data();
}
}
module.exports = MQTTBrokerApp;