-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
102 lines (81 loc) · 3.62 KB
/
config.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const fs = require('fs');
const { getPasswordFromOSKeyStore, decryptString, encryptString } = require('./authFactory');
const { app } = require('electron').remote;
const path = require('path');
const basePath = path.join(app.getPath("userData"), 'servicedeskqueuechangealert');
if (!fs.existsSync(basePath)){
fs.mkdirSync(basePath);
}
const configPath = path.join(basePath, 'config.json');
class Config {
// TODO Make this working
static fileName = "config.json";
constructor(baseurl, username, password, serviceDeskId, queueId, interval, crowdTokenKey, chromeExtensionPassword) {
this.baseurl = baseurl;
this.username = username;
this.password = password;
this.serviceDeskId = serviceDeskId;
this.queueId = queueId;
this.interval = interval;
this.crowdTokenKey = crowdTokenKey;
this.chromeExtensionPassword = chromeExtensionPassword;
}
getFormValues() {
this.baseurl = document.getElementById("baseurl").value;
this.username = document.getElementById("username").value;
this.password = document.getElementById("password").value;
//this.serviceDeskId = document.getElementById("serviceDeskId").innerText;
//this.queueId = document.getElementById("queueId").innerText;
this.serviceDeskId = document.getElementById("serviceDeskId").value;
this.queueId = document.getElementById("queueId").value;
this.interval = document.getElementById("interval").value;
this.crowdTokenKey = document.getElementById("crowdTokenKey").value;
}
setFormValues() {
document.getElementById("baseurl").value = this.baseurl;
document.getElementById("username").value = this.username;
document.getElementById("password").value = this.password;
//this.serviceDeskId = document.getElementById("serviceDeskId").innerText;
//this.queueId = document.getElementById("queueId").innerText;
document.getElementById("serviceDeskId").value = this.serviceDeskId;
document.getElementById("queueId").value = this.queueId;
document.getElementById("interval").value = this.interval;
document.getElementById("crowdTokenKey").value = this.crowdTokenKey;
}
loadConfigFromString(password, string) {
var c = JSON.parse(string);
this.baseurl = c.baseurl;
this.username = c.username;
this.password = decryptString(password, c.password);
this.serviceDeskId = c.serviceDeskId;
this.queueId = c.queueId;
this.interval = c.interval;
this.crowdTokenKey = decryptString(password, c.crowdTokenKey);
this.chromeExtensionPassword = decryptString(password, c.chromeExtensionPassword);
}
save(password, callback) {
var c = new Config();
c = JSON.parse(JSON.stringify(this));
c.password = encryptString(password, this.password);
c.crowdTokenKey = encryptString(password, this.crowdTokenKey);
c.chromeExtensionPassword = encryptString(password, this.chromeExtensionPassword);
fs.writeFile(configPath, JSON.stringify(c), 'utf8', (err) => {
if (err) {
alert("An error occured while writing JSON Object to File.");
return console.log(err);
}
callback && callback(this);
});
}
load(password, callback) {
fs.readFile(configPath, 'utf8', (err, contents) => {
if (err) {
alert("An error occured while reading JSON Object to File.");
return console.log(err);
}
this.loadConfigFromString(password, contents);
callback && callback(this);
});
}
}
module.exports = Config