@drumee/setup-infra 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/init-acme +13 -5
- package/bin/init-private +40 -0
- package/bin/prosody +1 -1
- package/index.js +295 -162
- package/package.json +3 -4
- package/templates/etc/bind/named.conf.options +1 -1
- package/templates/etc/bind/named.conf.private +21 -0
- package/templates/etc/bind/{named.conf.local → named.conf.public} +2 -2
- package/templates/etc/dkimkeys/dkim.key +1 -1
- package/templates/etc/drumee/conf.d/myDrumee.json.tpl +1 -1
- package/templates/etc/drumee/dnsapi.sh.tpl +1 -1
- package/templates/etc/drumee/drumee.sh.tpl +24 -17
- package/templates/etc/drumee/env.json +1 -1
- package/templates/etc/drumee/infrastructure/routes/main.conf.tpl +23 -13
- package/templates/etc/drumee/ssl/{main.conf.tpl → private.conf.tpl} +2 -4
- package/templates/etc/drumee/ssl/public.conf.tpl +10 -0
- package/templates/etc/mysql/mariadb.conf.d/50-client.cnf +21 -0
- package/templates/etc/mysql/mariadb.conf.d/50-server.cnf +2 -1
- package/templates/etc/nginx/nginx.conf +1 -1
- package/templates/etc/nginx/sites-enabled/jitsi.conf.tpl +4 -4
- package/templates/etc/nginx/sites-enabled/{loopback.tpl → localhost.conf} +9 -10
- package/templates/etc/nginx/sites-enabled/pivate.jitsi.conf.tpl +28 -0
- package/templates/etc/nginx/sites-enabled/private.conf.tpl +40 -0
- package/templates/etc/nginx/sites-enabled/{drumee.conf.tpl → public.conf.tpl} +8 -8
- package/templates/etc/nginx/sites-enabled/public.jitsi.conf.tpl +28 -0
- package/templates/etc/postfix/main.cf +1 -1
- package/templates/etc/prosody/conf.d/private.cfg.lua.tpl +162 -0
- package/templates/etc/prosody/conf.d/public.cfg.lua.tpl +162 -0
- package/templates/index.js +19 -13
- package/templates/utils.js +192 -0
- package/templates/var/lib/bind/private-reverse.tpl +17 -0
- package/templates/var/lib/bind/prvate.tpl +70 -0
- /package/templates/var/lib/bind/{revserse.tpl → public-reverse.tpl} +0 -0
- /package/templates/var/lib/bind/{domain.tpl → public.tpl} +0 -0
package/index.js
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// ======================================================
|
|
4
|
-
//
|
|
5
|
-
// ======================================================
|
|
6
3
|
const Template = require("./templates");
|
|
7
|
-
const { writeFileSync } = require(`jsonfile`);
|
|
4
|
+
const { writeFileSync, readFileSync: readJson } = require(`jsonfile`);
|
|
8
5
|
const { join, dirname } = require("path");
|
|
9
6
|
const { isString } = require("lodash");
|
|
10
7
|
const { exit } = process;
|
|
11
|
-
const { sysEnv, uniqueId } = require("@drumee/server-essentials");
|
|
12
|
-
const { totalmem } = require('os');
|
|
13
|
-
const ARGV = require('minimist')(process.argv.slice(2));
|
|
8
|
+
const { loadSysEnv, sysEnv, uniqueId } = require("@drumee/server-essentials");
|
|
9
|
+
const { totalmem, userInfo } = require('os');
|
|
14
10
|
const {
|
|
15
11
|
existsSync, close, writeSync, openSync, readFileSync, mkdirSync
|
|
16
12
|
} = require("fs");
|
|
13
|
+
const { args, hasExistingSettings } = require('./templates/utils')
|
|
17
14
|
|
|
18
15
|
const JSON_OPT = { spaces: 2, EOL: "\r\n" };
|
|
19
16
|
|
|
20
17
|
const {
|
|
21
18
|
ACME_DIR,
|
|
22
19
|
ACME_EMAIL_ACCOUNT,
|
|
23
|
-
|
|
24
|
-
DB_BACKUP,
|
|
25
|
-
DRUMEE_DB_DIR,
|
|
26
|
-
DRUMEE_DESCRIPTION,
|
|
27
|
-
DRUMEE_DOMAIN_NAME,
|
|
28
|
-
FORCE_INSTALL,
|
|
20
|
+
CERTS_DIR,
|
|
29
21
|
MAIL_USER,
|
|
30
|
-
MAX_BODY_SIZE,
|
|
31
22
|
NSUPDATE_KEY,
|
|
32
|
-
PUBLIC_IP4,
|
|
33
|
-
PUBLIC_IP6,
|
|
34
|
-
STORAGE_BACKUP,
|
|
35
23
|
} = process.env;
|
|
36
24
|
|
|
37
25
|
/**
|
|
@@ -69,8 +57,7 @@ function copyFields(data, keys) {
|
|
|
69
57
|
*/
|
|
70
58
|
function factory(data) {
|
|
71
59
|
let route = "main";
|
|
72
|
-
let
|
|
73
|
-
let base = `${data.server_dir}/${mode}/${route}/`;
|
|
60
|
+
let base = `${data.server_dir}/${route}/`;
|
|
74
61
|
return {
|
|
75
62
|
name: "factory",
|
|
76
63
|
script: `./index.js`,
|
|
@@ -109,10 +96,10 @@ function worker(data, instances = 1, exec_mode = 'fork_mode') {
|
|
|
109
96
|
name,
|
|
110
97
|
server_dir,
|
|
111
98
|
runtime_dir,
|
|
112
|
-
mode,
|
|
113
99
|
} = data;
|
|
100
|
+
|
|
114
101
|
if (!server_dir) server_dir = join(runtime_dir, 'server');
|
|
115
|
-
let base = `${server_dir}/${
|
|
102
|
+
let base = `${server_dir}/${route}`;
|
|
116
103
|
return {
|
|
117
104
|
name,
|
|
118
105
|
script,
|
|
@@ -134,16 +121,21 @@ function worker(data, instances = 1, exec_mode = 'fork_mode') {
|
|
|
134
121
|
*
|
|
135
122
|
*/
|
|
136
123
|
function writeTemplates(data, targets) {
|
|
137
|
-
if (
|
|
124
|
+
if (args.readonly || args.noCheck) {
|
|
138
125
|
console.log("Readonly", targets, data);
|
|
139
126
|
return
|
|
140
127
|
}
|
|
141
128
|
for (let target of targets) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
129
|
+
try {
|
|
130
|
+
if (isString(target)) {
|
|
131
|
+
Template.write(data, target, target);
|
|
132
|
+
} else {
|
|
133
|
+
let { out, tpl } = target;
|
|
134
|
+
Template.write(data, out, tpl);
|
|
135
|
+
}
|
|
136
|
+
} catch (e) {
|
|
137
|
+
console.error(e)
|
|
138
|
+
console.error("Failed to write configs for", target)
|
|
147
139
|
}
|
|
148
140
|
}
|
|
149
141
|
}
|
|
@@ -155,10 +147,8 @@ function writeEcoSystem(data) {
|
|
|
155
147
|
const ports = {
|
|
156
148
|
pushPort: 23000,
|
|
157
149
|
restPort: 24000,
|
|
158
|
-
mode: "dist",
|
|
159
150
|
route: "main",
|
|
160
151
|
};
|
|
161
|
-
|
|
162
152
|
let main = worker({
|
|
163
153
|
...data,
|
|
164
154
|
...ports,
|
|
@@ -182,11 +172,14 @@ function writeEcoSystem(data) {
|
|
|
182
172
|
|
|
183
173
|
let f = factory(data);
|
|
184
174
|
let routes = [main, main_service, f];
|
|
185
|
-
let ecosystem = "
|
|
186
|
-
|
|
175
|
+
//let ecosystem = "etc/drumee/infrastructure/ecosystem.json";
|
|
176
|
+
let ecosystem = Template.chroot("etc/drumee/infrastructure/ecosystem.json");
|
|
177
|
+
if (args.readonly) {
|
|
187
178
|
console.log("Readonly", ecosystem, routes);
|
|
188
179
|
return
|
|
189
180
|
}
|
|
181
|
+
console.log("Writing ecosystem into ", ecosystem);
|
|
182
|
+
Template.makedir(dirname(ecosystem));
|
|
190
183
|
writeFileSync(ecosystem, routes, JSON_OPT);
|
|
191
184
|
let targets = [
|
|
192
185
|
{
|
|
@@ -212,9 +205,17 @@ function getSocketPath() {
|
|
|
212
205
|
return socketPath;
|
|
213
206
|
}
|
|
214
207
|
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
*
|
|
211
|
+
* @param {*} opt
|
|
212
|
+
* @returns
|
|
213
|
+
*/
|
|
215
214
|
function makeData(opt) {
|
|
216
215
|
let data = sysEnv();
|
|
217
|
-
|
|
216
|
+
if (args.env_file && existsSync(args.env_file)) {
|
|
217
|
+
loadEnvFile(args.env_file, opt)
|
|
218
|
+
}
|
|
218
219
|
data.chroot = Template.chroot();
|
|
219
220
|
data.acme_store = join(data.certs_dir, `${data.domain_name}_ecc`);
|
|
220
221
|
data.ca_server = data.ca_server || data.acme_ssl;
|
|
@@ -223,75 +224,143 @@ function makeData(opt) {
|
|
|
223
224
|
}
|
|
224
225
|
for (let row of opt) {
|
|
225
226
|
let [key, value, fallback] = row;
|
|
226
|
-
if (!value) value = fallback;
|
|
227
|
-
if (
|
|
228
|
-
if (
|
|
227
|
+
if (!value) value = data[key] || fallback;
|
|
228
|
+
if (value == null) continue;
|
|
229
|
+
if (isString(value)) {
|
|
229
230
|
if (/.+\+$/.test(value)) {
|
|
230
231
|
value = value.replace(/\+$/, data[key]);
|
|
231
232
|
}
|
|
232
233
|
data[key] = value.trim() || fallback;
|
|
234
|
+
} else {
|
|
235
|
+
data[key] = value
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
|
|
239
|
+
/** Named extra settings */
|
|
240
|
+
data.allow_recursion = 'localhost;';
|
|
236
241
|
if (data.public_ip4) {
|
|
237
242
|
data.reverse_ip4 = data.public_ip4.split('.').reverse().join('.');
|
|
243
|
+
} else {
|
|
244
|
+
data.reverse_ip4 = ""
|
|
238
245
|
}
|
|
239
246
|
|
|
247
|
+
if (!data.public_ip6) {
|
|
248
|
+
data.public_ip6 = "";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!data.storage_backup) {
|
|
252
|
+
data.storage_backup = ""
|
|
253
|
+
}
|
|
240
254
|
return data;
|
|
241
255
|
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
*
|
|
259
|
+
* @param {*} env
|
|
260
|
+
* @param {*} opt
|
|
261
|
+
*/
|
|
262
|
+
function loadEnvFile(file, opt) {
|
|
263
|
+
let src = readJson(file);
|
|
264
|
+
opt.map((r) => {
|
|
265
|
+
let [key] = r;
|
|
266
|
+
if (src[key] != null) r[1] = src[key];
|
|
267
|
+
})
|
|
268
|
+
console.log(opt)
|
|
269
|
+
}
|
|
270
|
+
|
|
242
271
|
/**
|
|
243
272
|
*
|
|
244
273
|
*/
|
|
245
274
|
function getSysConfigs() {
|
|
246
|
-
|
|
247
|
-
if (existsSync('/etc/drumee/drumee.sh') && !FORCE_INSTALL) {
|
|
248
|
-
console.log(
|
|
249
|
-
`There is already a domain name configured on this server (${domain_name})\n`, `Use FORCE_INSTALL=yes to override`);
|
|
275
|
+
if (hasExistingSettings(Template.chroot('etc/drumee/drumee.json'))) {
|
|
250
276
|
exit(0)
|
|
251
277
|
}
|
|
252
|
-
|
|
278
|
+
|
|
279
|
+
let use_email = 0;
|
|
280
|
+
if (args.public_domain) use_email = 1;
|
|
281
|
+
let domain_name = args.public_domain || args.private_domain;
|
|
253
282
|
if (!domain_name) {
|
|
254
|
-
|
|
255
|
-
|
|
283
|
+
if (!args.localhost) {
|
|
284
|
+
console.log("There is no domain name defined for the installation", args);
|
|
285
|
+
exit(0)
|
|
286
|
+
}
|
|
256
287
|
}
|
|
288
|
+
|
|
289
|
+
const nsupdate_key = Template.chroot('etc/bind/keys/update.key')
|
|
257
290
|
const opt = [
|
|
258
|
-
["
|
|
259
|
-
["
|
|
260
|
-
["
|
|
261
|
-
["
|
|
262
|
-
["
|
|
263
|
-
["
|
|
264
|
-
["
|
|
265
|
-
["
|
|
266
|
-
["
|
|
267
|
-
["
|
|
268
|
-
["
|
|
269
|
-
["
|
|
270
|
-
["max_body_size", MAX_BODY_SIZE, '10G'],
|
|
291
|
+
["nsupdate_key", NSUPDATE_KEY, nsupdate_key],
|
|
292
|
+
["admin_email", args.admin_email],
|
|
293
|
+
["credential_dir", Template.chroot('etc/drumee/credential')],
|
|
294
|
+
["domain_desc", args.description, 'My Drumee Box'],
|
|
295
|
+
["max_body_size", args.max_body_size, '10G'],
|
|
296
|
+
["drumee_root", args.drumee_root, "/var/lib/drumee"],
|
|
297
|
+
["use_email", use_email, 0],
|
|
298
|
+
["db_dir", args.db_dir, '/var/lib/mysql'],
|
|
299
|
+
["backup_storage", args.backup_storage, ""],
|
|
300
|
+
["data_dir", args.data_dir, '/var/lib/drumee/data'],
|
|
301
|
+
["http_port", args.http_port, 80],
|
|
302
|
+
["https_port", args.https_port, 443],
|
|
271
303
|
]
|
|
272
|
-
|
|
304
|
+
|
|
305
|
+
if (!args.localhost) {
|
|
306
|
+
opt.push(
|
|
307
|
+
["private_ip4", args.private_ip4],
|
|
308
|
+
["public_domain", args.public_domain],
|
|
309
|
+
["public_ip4", args.public_ip4],
|
|
310
|
+
["public_ip6", args.public_ip6],
|
|
311
|
+
["storage_backup", args.backup_storage], /** Legacy */
|
|
312
|
+
["private_domain", args.private_domain],
|
|
313
|
+
["acme_dir", ACME_DIR],
|
|
314
|
+
["acme_email_account", ACME_EMAIL_ACCOUNT, args.admin_email],
|
|
315
|
+
["certs_dir", CERTS_DIR],
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
let data = makeData(opt);
|
|
321
|
+
|
|
322
|
+
if (!data) {
|
|
323
|
+
exit(1);
|
|
324
|
+
}
|
|
273
325
|
let d = new Date().toISOString();
|
|
274
326
|
let [day, hour] = d.split('T')
|
|
275
327
|
day = day.replace(/\-/g, '');
|
|
276
328
|
hour = hour.split(':')[0];
|
|
277
329
|
data.serial = `${day}${hour}`;
|
|
278
330
|
|
|
279
|
-
let
|
|
331
|
+
let configs = { ...data };
|
|
280
332
|
let keys = ["myConf", "chroot", "date"];
|
|
281
333
|
|
|
282
334
|
for (let key of keys) {
|
|
283
|
-
delete
|
|
335
|
+
delete configs[key];
|
|
284
336
|
}
|
|
285
337
|
|
|
286
|
-
if (
|
|
287
|
-
return
|
|
338
|
+
if (args.readonly) {
|
|
339
|
+
return configs;
|
|
288
340
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
341
|
+
|
|
342
|
+
configs.socketPath = getSocketPath();
|
|
343
|
+
configs.runtime_dir = join(configs.drumee_root, 'runtime');
|
|
344
|
+
configs.server_dir = join(configs.runtime_dir, 'server');
|
|
345
|
+
configs.server_base = configs.server_dir;
|
|
346
|
+
configs.server_home = join(configs.server_base, 'main');
|
|
347
|
+
configs.server_location = configs.server_home;
|
|
348
|
+
|
|
349
|
+
//console.log(configs)
|
|
350
|
+
configs.ui_dir = join(configs.runtime_dir, 'ui');
|
|
351
|
+
configs.ui_base = join(configs.ui_dir, 'main');
|
|
352
|
+
configs.ui_home = configs.ui_base;
|
|
353
|
+
configs.ui_location = configs.ui_base;
|
|
354
|
+
|
|
355
|
+
configs.tmp_dir = join(configs.runtime_dir, 'tmp');
|
|
356
|
+
configs.static_dir = join(configs.runtime_dir, 'static');
|
|
357
|
+
|
|
358
|
+
let filename = Template.chroot("etc/drumee/drumee.json");
|
|
359
|
+
console.log("Writing main conf into drumee.json", filename);
|
|
360
|
+
Template.makedir(dirname(filename));
|
|
361
|
+
writeFileSync(filename, configs, JSON_OPT);
|
|
362
|
+
console.log(configs)
|
|
363
|
+
return configs;
|
|
295
364
|
}
|
|
296
365
|
|
|
297
366
|
/**
|
|
@@ -301,6 +370,7 @@ function getSysConfigs() {
|
|
|
301
370
|
function writeCredentials(file, data) {
|
|
302
371
|
let target = Template.chroot(`etc/drumee/credential/${file}.json`);
|
|
303
372
|
console.log(`Writing credentials into ${target}`);
|
|
373
|
+
Template.makedir(dirname(target));
|
|
304
374
|
writeFileSync(target, data, JSON_OPT);
|
|
305
375
|
}
|
|
306
376
|
|
|
@@ -317,14 +387,13 @@ function errorHandler(err) {
|
|
|
317
387
|
*/
|
|
318
388
|
function copyConfigs(items) {
|
|
319
389
|
for (let item of items) {
|
|
320
|
-
let
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
let content = readFileSync(
|
|
390
|
+
let src = join(__dirname, 'configs', item);
|
|
391
|
+
let dest = Template.chroot(item);
|
|
392
|
+
console.log(`Copying ${src} to ${dest}`)
|
|
393
|
+
Template.makedir(dirname(dest))
|
|
394
|
+
let content = readFileSync(src);
|
|
325
395
|
let str = String(content).toString();
|
|
326
396
|
//Buffer.from(content, "utf8");
|
|
327
|
-
let dest = Template.chroot(item);
|
|
328
397
|
let fd = openSync(dest, "w+");
|
|
329
398
|
writeSync(fd, str);
|
|
330
399
|
close(fd, errorHandler);
|
|
@@ -361,92 +430,131 @@ function getDkim(file) {
|
|
|
361
430
|
*
|
|
362
431
|
*/
|
|
363
432
|
function writeInfraConf(data) {
|
|
364
|
-
|
|
433
|
+
|
|
365
434
|
const etc = 'etc';
|
|
366
435
|
const nginx = join(etc, 'nginx');
|
|
367
436
|
const drumee = join(etc, 'drumee');
|
|
368
|
-
const bind = join(etc, 'bind'
|
|
369
|
-
const
|
|
437
|
+
const bind = join(etc, 'bind');
|
|
438
|
+
const libbind = join('var', 'lib', 'bind');
|
|
439
|
+
const postfix = join(etc, 'postfix');
|
|
370
440
|
const mariadb = join(etc, 'mysql', 'mariadb.conf.d');
|
|
371
441
|
const infra = join(drumee, 'infrastructure');
|
|
372
|
-
const {
|
|
373
|
-
const dkim = join(etc, 'opendkim', 'keys', domain, 'dkim.txt');
|
|
442
|
+
const { public_domain, private_domain } = data;
|
|
374
443
|
let targets = [
|
|
375
|
-
|
|
376
|
-
// Nginx
|
|
377
|
-
`${nginx}/sites-enabled/drumee.conf`,
|
|
378
|
-
|
|
379
|
-
// Drumee
|
|
380
|
-
`${drumee}/ssl/main.conf`,
|
|
381
444
|
`${drumee}/drumee.sh`,
|
|
382
|
-
`${drumee}/conf.d/conference.json`,
|
|
383
445
|
`${drumee}/conf.d/drumee.json`,
|
|
384
446
|
`${drumee}/conf.d/exchange.json`,
|
|
385
447
|
`${drumee}/conf.d/myDrumee.json`,
|
|
386
|
-
`${drumee}/conf.d/conference.json`,
|
|
387
448
|
`${drumee}/conf.d/drumee.json`,
|
|
388
449
|
`${drumee}/conf.d/myDrumee.json`,
|
|
389
450
|
|
|
390
451
|
`${infra}/mfs.conf`,
|
|
391
452
|
`${infra}/routes/main.conf`,
|
|
392
453
|
`${infra}/internals/accel.conf`,
|
|
393
|
-
{
|
|
394
|
-
tpl: `var/lib/bind/domain.tpl`,
|
|
395
|
-
out: `var/lib/bind/${domain}`
|
|
396
|
-
},
|
|
397
|
-
`${bind}/named.conf.local`,
|
|
398
|
-
`${bind}/named.conf.log`,
|
|
399
|
-
`${bind}/named.conf.options`,
|
|
400
|
-
`${postfix}/main.cf`,
|
|
401
|
-
`${postfix}/mysql-virtual-alias-maps.cf`,
|
|
402
|
-
`${postfix}/mysql-virtual-mailbox-domains.cf`,
|
|
403
|
-
`${postfix}/mysql-virtual-mailbox-maps.cf`,
|
|
404
|
-
`${etc}/dkimkeys/dkim.key`,
|
|
405
|
-
`${etc}/mail/dkim.key`,
|
|
406
|
-
`${etc}/mailname`,
|
|
407
|
-
`${etc}/opendkim/KeyTable`,
|
|
408
|
-
`${mariadb}/50-server.cnf`,
|
|
409
454
|
];
|
|
410
455
|
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
456
|
+
if (args.localhost) {
|
|
457
|
+
let { username } = userInfo();
|
|
458
|
+
let system_group = username;
|
|
459
|
+
if (username = 'root') {
|
|
460
|
+
username = data.system_user || 'www-data';
|
|
461
|
+
system_group = data.system_group || 'www-data';
|
|
462
|
+
}
|
|
463
|
+
data.system_user = username;
|
|
464
|
+
data.system_group = system_group;
|
|
465
|
+
targets.push(`${nginx}/sites-enabled/localhost.conf`)
|
|
466
|
+
let dir = join(args.drumee_root, 'cache', 'localhost')
|
|
467
|
+
mkdirSync(dir, { recursive: true });
|
|
468
|
+
if (args.db_dir != '/var/lib/mysql') {
|
|
469
|
+
targets.push(
|
|
470
|
+
`${mariadb}/50-server.cnf`,
|
|
471
|
+
`${mariadb}/50-client.cnf`,
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
targets.push(
|
|
476
|
+
`${bind}/named.conf.log`,
|
|
477
|
+
`${bind}/named.conf.options`,
|
|
478
|
+
`${mariadb}/50-server.cnf`,
|
|
479
|
+
`${mariadb}/50-client.cnf`,
|
|
480
|
+
)
|
|
416
481
|
}
|
|
417
|
-
|
|
418
|
-
data
|
|
419
|
-
data.
|
|
420
|
-
|
|
421
|
-
|
|
482
|
+
|
|
483
|
+
writeEcoSystem(data);
|
|
484
|
+
if (data.public_ip4 && public_domain) {
|
|
485
|
+
let dir = join(args.drumee_root, 'cache', public_domain)
|
|
486
|
+
mkdirSync(dir, { recursive: true });
|
|
487
|
+
targets.push(
|
|
488
|
+
`${nginx}/sites-enabled/public.conf`,
|
|
489
|
+
`${drumee}/ssl/public.conf`,
|
|
490
|
+
`${bind}/named.conf.public`,
|
|
491
|
+
{ tpl: `${libbind}/public.tpl`, out: `${libbind}/${public_domain}` },
|
|
492
|
+
{ tpl: `${libbind}/public-reverse.tpl`, out: `${libbind}/${data.public_ip4}` }
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
const dkim = join(etc, 'opendkim', 'keys', public_domain, 'dkim.txt');
|
|
496
|
+
targets.push(
|
|
497
|
+
`${postfix}/main.cf`,
|
|
498
|
+
`${postfix}/mysql-virtual-alias-maps.cf`,
|
|
499
|
+
`${postfix}/mysql-virtual-mailbox-domains.cf`,
|
|
500
|
+
`${postfix}/mysql-virtual-mailbox-maps.cf`,
|
|
501
|
+
`${etc}/dkimkeys/dkim.key`,
|
|
502
|
+
`${etc}/mail/dkim.key`,
|
|
503
|
+
`${etc}/mailname`,
|
|
504
|
+
`${etc}/opendkim/KeyTable`,
|
|
505
|
+
)
|
|
506
|
+
data.dkim_key = getDkim(dkim);
|
|
507
|
+
data.mail_user = MAIL_USER || 'postfix';
|
|
508
|
+
data.mail_password = uniqueId();
|
|
509
|
+
data.smptd_cache_db = "btree:$";
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (data.private_ip4 && private_domain) {
|
|
513
|
+
let dir = join(args.drumee_root, 'cache', private_domain)
|
|
514
|
+
mkdirSync(dir, { recursive: true });
|
|
515
|
+
targets.push(
|
|
516
|
+
`${nginx}/sites-enabled/private.conf`,
|
|
517
|
+
`${drumee}/ssl/private.conf`,
|
|
518
|
+
`${bind}/named.conf.private`,
|
|
519
|
+
{ tpl: `${libbind}/private.tpl`, out: `${libbind}/${private_domain}` },
|
|
520
|
+
{ tpl: `${libbind}/private-reverse.tpl`, out: `${libbind}/${data.private_ip4}` },
|
|
521
|
+
)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
|
|
422
525
|
writeTemplates(data, targets);
|
|
423
526
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
527
|
+
if (!args.localhost) {
|
|
528
|
+
writeCredentials("postfix", {
|
|
529
|
+
host: 'localhost',
|
|
530
|
+
user: data.mail_user,
|
|
531
|
+
password: data.mail_password,
|
|
532
|
+
})
|
|
429
533
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
534
|
+
writeCredentials("db", {
|
|
535
|
+
password: uniqueId(),
|
|
536
|
+
user: "drumee-app",
|
|
537
|
+
host: "localhost",
|
|
538
|
+
})
|
|
435
539
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
540
|
+
writeCredentials("email", {
|
|
541
|
+
host: `localhost`,
|
|
542
|
+
port: 587,
|
|
543
|
+
secure: false,
|
|
544
|
+
auth: {
|
|
545
|
+
user: `butler@${public_domain}`,
|
|
546
|
+
pass: uniqueId()
|
|
547
|
+
},
|
|
548
|
+
tls: {
|
|
549
|
+
rejectUnauthorized: false
|
|
550
|
+
}
|
|
551
|
+
})
|
|
448
552
|
|
|
449
|
-
|
|
553
|
+
copyConfigs([
|
|
554
|
+
'etc/postfix/master.cf',
|
|
555
|
+
'etc/cron.d/drumee',
|
|
556
|
+
])
|
|
557
|
+
}
|
|
450
558
|
}
|
|
451
559
|
|
|
452
560
|
/**
|
|
@@ -479,7 +587,6 @@ function writeJitsiConf(data) {
|
|
|
479
587
|
// Nginx
|
|
480
588
|
`${nginx}/sites-enabled/jitsi.conf`,
|
|
481
589
|
`${nginx}/modules-enabled/90-turn-relay.conf`,
|
|
482
|
-
//`${nginx}/sites-enabled/turnrelay.conf`,
|
|
483
590
|
|
|
484
591
|
// Prosody
|
|
485
592
|
`${prosody}/prosody.cfg.lua`,
|
|
@@ -514,15 +621,15 @@ function makeConfData(data) {
|
|
|
514
621
|
jvb_password: randomString(),
|
|
515
622
|
app_id: randomString(),
|
|
516
623
|
app_password: randomString(),
|
|
517
|
-
ui_base: join(data.ui_base, '
|
|
624
|
+
ui_base: join(data.ui_base, 'main'),
|
|
518
625
|
location: '/-/',
|
|
519
626
|
pushPort: 23000,
|
|
520
627
|
restPort: 24000,
|
|
521
628
|
};
|
|
522
629
|
if (!data.export_dir) data.export_dir = null;
|
|
523
630
|
if (!data.import_dir) data.import_dir = null;
|
|
524
|
-
if (!data.
|
|
525
|
-
data.
|
|
631
|
+
if (!data.private_address) {
|
|
632
|
+
data.private_address = data.public_address || "127.0.0.1";
|
|
526
633
|
}
|
|
527
634
|
return data
|
|
528
635
|
}
|
|
@@ -536,38 +643,64 @@ function privateIp() {
|
|
|
536
643
|
})
|
|
537
644
|
}
|
|
538
645
|
|
|
646
|
+
/**
|
|
647
|
+
*
|
|
648
|
+
*/
|
|
649
|
+
async function getAddresses(data) {
|
|
650
|
+
const isPrivate = await privateIp();
|
|
651
|
+
let os = require("os");
|
|
652
|
+
let interfaces = os.networkInterfaces();
|
|
653
|
+
let private_ip4, public_ip4, private_ip6, public_ip6;
|
|
654
|
+
for (let name in interfaces) {
|
|
655
|
+
if (name == 'lo') continue;
|
|
656
|
+
for (let dev of interfaces[name]) {
|
|
657
|
+
switch (dev.family) {
|
|
658
|
+
case 'IPv4':
|
|
659
|
+
if (isPrivate(dev.address) && !private_ip4) {
|
|
660
|
+
private_ip4 = dev.address;
|
|
661
|
+
}
|
|
662
|
+
if (!isPrivate(dev.address) && !public_ip4) {
|
|
663
|
+
public_ip4 = dev.address;
|
|
664
|
+
}
|
|
665
|
+
break;
|
|
666
|
+
case 'IPv6':
|
|
667
|
+
if (isPrivate(dev.address) && !private_ip6) {
|
|
668
|
+
private_ip6 = dev.address;
|
|
669
|
+
}
|
|
670
|
+
if (!isPrivate(dev.address) && !public_ip6) {
|
|
671
|
+
public_ip6 = dev.address;
|
|
672
|
+
}
|
|
673
|
+
break;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
data.private_ip4 = data.private_ip4 || private_ip4;
|
|
678
|
+
data.private_ip6 = data.private_ip6 || private_ip6;
|
|
679
|
+
data.local_address = data.private_ip4;
|
|
680
|
+
|
|
681
|
+
data.public_ip4 = data.public_ip4 || public_ip4;
|
|
682
|
+
data.public_ip6 = data.public_ip6 || public_ip6;
|
|
683
|
+
|
|
684
|
+
return data;
|
|
685
|
+
}
|
|
686
|
+
|
|
539
687
|
/**
|
|
540
688
|
*
|
|
541
689
|
* @returns
|
|
542
690
|
*/
|
|
543
|
-
function
|
|
691
|
+
function main() {
|
|
692
|
+
const env_root = args.outdir || args.chroot;
|
|
693
|
+
if (env_root) loadSysEnv(env_root);
|
|
544
694
|
return new Promise(async (res, rej) => {
|
|
545
695
|
let data = getSysConfigs();
|
|
546
696
|
data.chroot = Template.chroot();
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
let interfaces = os.networkInterfaces();
|
|
550
|
-
for (let name in interfaces) {
|
|
551
|
-
for (let dev of interfaces[name]) {
|
|
552
|
-
if (dev.family == 'IPv4') {
|
|
553
|
-
if (isPrivate(dev.address)) {
|
|
554
|
-
data.local_address = dev.address;
|
|
555
|
-
break;
|
|
556
|
-
}
|
|
557
|
-
if (!dev.internal) {
|
|
558
|
-
public_address = dev.address;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
if (data.local_address) break;
|
|
563
|
-
}
|
|
564
|
-
data = makeConfData(data);
|
|
697
|
+
data = { ...data, ...makeConfData(data) };
|
|
698
|
+
data = await getAddresses(data);
|
|
565
699
|
let func = [];
|
|
566
|
-
if (
|
|
567
|
-
func
|
|
700
|
+
if (args.only_infra || args.no_jitsi || args.localhost || data.local_domain) {
|
|
701
|
+
func.push(writeInfraConf)
|
|
568
702
|
} else {
|
|
569
|
-
|
|
570
|
-
if (ARGV.jitsi) func.push(writeJitsiConf)
|
|
703
|
+
func = [writeInfraConf, writeJitsiConf];
|
|
571
704
|
}
|
|
572
705
|
func.map(function (f) {
|
|
573
706
|
f(data);
|
|
@@ -577,7 +710,7 @@ function configure() {
|
|
|
577
710
|
});
|
|
578
711
|
}
|
|
579
712
|
|
|
580
|
-
|
|
713
|
+
main()
|
|
581
714
|
.then(() => {
|
|
582
715
|
exit(0);
|
|
583
716
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drumee/setup-infra",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Drumee Infrastructure Setup Utilities",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,12 +17,11 @@
|
|
|
17
17
|
"author": "Somanos Sar <somanos@drumee.com>",
|
|
18
18
|
"license": "AGPL V3",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@drumee/
|
|
21
|
-
"
|
|
20
|
+
"@drumee/server-essentials": "^1.1.31",
|
|
21
|
+
"argparse": "^2.0.1",
|
|
22
22
|
"crypto": "^1.0.1",
|
|
23
23
|
"jsonfile": "^5.0.0",
|
|
24
24
|
"lodash": "^4.17.21",
|
|
25
|
-
"minimist": "^1.2.8",
|
|
26
25
|
"ovh": "^2.0.3",
|
|
27
26
|
"private-ip": "^3.0.1",
|
|
28
27
|
"shelljs": "^0.8.5",
|