forked from ADumaine/secnodetracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
110 lines (80 loc) · 3.19 KB
/
Copy pathsetup.js
File metadata and controls
110 lines (80 loc) · 3.19 KB
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
103
104
105
106
107
108
const promptly = require('promptly');
const fs = require("fs");
const oshome = require('os').homedir();
const LocalStorage = require('node-localstorage').LocalStorage;
const localStorage = new LocalStorage('./config');
const validator = (value) => {
if (value.length !== 35) {
throw new Error('That does not appear to be a t_address.');
}
return value;
};
//get values if setup rerun
let addr = localStorage.getItem('stakeaddr') || null;
let email = localStorage.getItem('email') || null;
let fqdn = localStorage.getItem('fqdn') || null;
//let urlDefault = 'https://tracksys.zensystem.io';
let urlDefault = 'http://devtracksys.secnodes.com';
let msg1 = addr ? ' (Default: ' + addr + '):' : ':';
let msg2 = email ? '(Default: ' + email + '):' : ':';
let msg3 = fqdn ? '(Default: ' + fqdn + '):' : ':';
let msg4 = '(Default: ' + urlDefault + '):';
//Prompt user for values
promptly
.prompt('Staking transparent address' + msg1, { 'default': addr, 'validator': validator })
.then((value) => {
localStorage.setItem('stakeaddr', value);
promptly.prompt('Alert email address' + msg2, { 'default': email })
.then((value) => {
localStorage.setItem('email', value);
promptly.prompt('Domain name used in cert - FQDN' + msg3, { 'default': fqdn })
.then((value) => {
localStorage.setItem('fqdn', value);
promptly.prompt('Tracking Server url' + msg4, { 'default': urlDefault })
.then((value) => {
localStorage.setItem('serverurl', value);
getRPC();
})
})
})
})
.catch((err) => {
console.log('Error:', err.message);
});
//get zen rpc config
const getRPC = () => {
console.log("Retrieving zen rpc config....");
let lines;
try {
let path1 = oshome + "/.zen/zen.conf";
let path2 = oshome + "/zencash/.zen/zen.conf";
let path3 = oshome + "/AppData/Roaming/Zen/zen.conf";
if (fs.existsSync(path1)) {
lines = fs.readFileSync(path1, "utf8").split("\n");
} else if (fs.existsSync(path2)) {
lines = fs.readFileSync(path2, "utf8").split("\n");
} else if (fs.existsSync(path3)) {
lines = fs.readFileSync(path3, "utf8").split("\n");
}
//console.log(path);
}
catch (e) {
console.log("ERROR finding or reading zen.conf file. Make sure the zen secure node is set up properly.");
process.exit();
}
lines.pop();
let config = {};
let testnet = false;
lines.forEach(line => {
if (line.indexOf('#') == -1 && line.indexOf("rpc") == 0) {
let idx = line.indexOf("="); //don't use split since user or pw could have =
let key = line.substring(0, idx);
let val = line.substring(idx + 1);
localStorage.setItem(key, val);
}
if (line == 'testnet=1') testnet = true;
});
if (!testnet)
return console.log("This version should only be run on testnet. Please reconfigure");
console.log("Setup Complete");
}