@drumee/setup-infra 1.0.13 → 1.0.15
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 +330 -163
- 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 +2 -2
- 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 +2 -2
- 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 +240 -0
- package/templates/var/lib/bind/private-reverse.tpl +17 -0
- package/templates/var/lib/bind/prvate.tpl +70 -0
- package/thidima.sh +0 -44
- /package/templates/var/lib/bind/{reverse.tpl → public-reverse.tpl} +0 -0
- /package/templates/var/lib/bind/{domain.tpl → public.tpl} +0 -0
package/index.js
CHANGED
|
@@ -1,37 +1,26 @@
|
|
|
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')
|
|
14
|
+
|
|
17
15
|
|
|
18
16
|
const JSON_OPT = { spaces: 2, EOL: "\r\n" };
|
|
19
17
|
|
|
20
18
|
const {
|
|
21
19
|
ACME_DIR,
|
|
22
20
|
ACME_EMAIL_ACCOUNT,
|
|
23
|
-
|
|
24
|
-
DB_BACKUP,
|
|
25
|
-
DRUMEE_DB_DIR,
|
|
26
|
-
DRUMEE_DESCRIPTION,
|
|
27
|
-
DRUMEE_DOMAIN_NAME,
|
|
28
|
-
FORCE_INSTALL,
|
|
21
|
+
CERTS_DIR,
|
|
29
22
|
MAIL_USER,
|
|
30
|
-
MAX_BODY_SIZE,
|
|
31
23
|
NSUPDATE_KEY,
|
|
32
|
-
PUBLIC_IP4,
|
|
33
|
-
PUBLIC_IP6,
|
|
34
|
-
STORAGE_BACKUP,
|
|
35
24
|
} = process.env;
|
|
36
25
|
|
|
37
26
|
/**
|
|
@@ -69,8 +58,7 @@ function copyFields(data, keys) {
|
|
|
69
58
|
*/
|
|
70
59
|
function factory(data) {
|
|
71
60
|
let route = "main";
|
|
72
|
-
let
|
|
73
|
-
let base = `${data.server_dir}/${mode}/${route}/`;
|
|
61
|
+
let base = `${data.server_dir}/${route}/`;
|
|
74
62
|
return {
|
|
75
63
|
name: "factory",
|
|
76
64
|
script: `./index.js`,
|
|
@@ -109,11 +97,12 @@ function worker(data, instances = 1, exec_mode = 'fork_mode') {
|
|
|
109
97
|
name,
|
|
110
98
|
server_dir,
|
|
111
99
|
runtime_dir,
|
|
112
|
-
mode,
|
|
113
100
|
} = data;
|
|
101
|
+
|
|
114
102
|
if (!server_dir) server_dir = join(runtime_dir, 'server');
|
|
115
|
-
let base = `${server_dir}/${
|
|
116
|
-
|
|
103
|
+
let base = `${server_dir}/${route}`;
|
|
104
|
+
let iname = name.replace('/', '-');
|
|
105
|
+
let opt = {
|
|
117
106
|
name,
|
|
118
107
|
script,
|
|
119
108
|
cwd: base,
|
|
@@ -126,24 +115,61 @@ function worker(data, instances = 1, exec_mode = 'fork_mode') {
|
|
|
126
115
|
},
|
|
127
116
|
dependencies: [`pm2-logrotate`],
|
|
128
117
|
exec_mode,
|
|
129
|
-
instances
|
|
118
|
+
instances,
|
|
119
|
+
out_file: join(data.log_dir, `log-${iname}.log`),
|
|
120
|
+
error_file: join(data.log_dir, `error-${iname}.log`),
|
|
121
|
+
pm2_log_routes: {
|
|
122
|
+
rotateInterval: '0 0 * * *', // Rotate daily at midnight
|
|
123
|
+
rotateModule: true,
|
|
124
|
+
max_size: '10M', // Rotate when log reaches 10MB
|
|
125
|
+
retain: 30 // Keep 30 rotated logs
|
|
126
|
+
}
|
|
130
127
|
};
|
|
128
|
+
if (args.watch_dirs) {
|
|
129
|
+
let dirs = args.watch_dirs.split(/,+/);
|
|
130
|
+
if (dirs.length) {
|
|
131
|
+
opt.watch = dirs;
|
|
132
|
+
opt.watch_delay = args.watch_delay;
|
|
133
|
+
if (args.watch_symlinks) {
|
|
134
|
+
opt.watch_options = {
|
|
135
|
+
followSymlinks: true
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
opt.watch_options = {
|
|
139
|
+
followSymlinks: false
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (args.watch_ignore) {
|
|
143
|
+
let ignored = args.watch_ignore.split(/,+/);
|
|
144
|
+
if (ignored.length) {
|
|
145
|
+
opt.ignore_watch = ignored;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return opt;
|
|
151
|
+
|
|
131
152
|
}
|
|
132
153
|
|
|
133
154
|
/***
|
|
134
155
|
*
|
|
135
156
|
*/
|
|
136
157
|
function writeTemplates(data, targets) {
|
|
137
|
-
if (
|
|
158
|
+
if (args.readonly || args.noCheck) {
|
|
138
159
|
console.log("Readonly", targets, data);
|
|
139
160
|
return
|
|
140
161
|
}
|
|
141
162
|
for (let target of targets) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
163
|
+
try {
|
|
164
|
+
if (isString(target)) {
|
|
165
|
+
Template.write(data, target, target);
|
|
166
|
+
} else {
|
|
167
|
+
let { out, tpl } = target;
|
|
168
|
+
Template.write(data, out, tpl);
|
|
169
|
+
}
|
|
170
|
+
} catch (e) {
|
|
171
|
+
console.error(e)
|
|
172
|
+
console.error("Failed to write configs for", target)
|
|
147
173
|
}
|
|
148
174
|
}
|
|
149
175
|
}
|
|
@@ -155,10 +181,8 @@ function writeEcoSystem(data) {
|
|
|
155
181
|
const ports = {
|
|
156
182
|
pushPort: 23000,
|
|
157
183
|
restPort: 24000,
|
|
158
|
-
mode: "dist",
|
|
159
184
|
route: "main",
|
|
160
185
|
};
|
|
161
|
-
|
|
162
186
|
let main = worker({
|
|
163
187
|
...data,
|
|
164
188
|
...ports,
|
|
@@ -182,11 +206,14 @@ function writeEcoSystem(data) {
|
|
|
182
206
|
|
|
183
207
|
let f = factory(data);
|
|
184
208
|
let routes = [main, main_service, f];
|
|
185
|
-
let ecosystem = "
|
|
186
|
-
|
|
209
|
+
//let ecosystem = "etc/drumee/infrastructure/ecosystem.json";
|
|
210
|
+
let ecosystem = Template.chroot("etc/drumee/infrastructure/ecosystem.json");
|
|
211
|
+
if (args.readonly) {
|
|
187
212
|
console.log("Readonly", ecosystem, routes);
|
|
188
213
|
return
|
|
189
214
|
}
|
|
215
|
+
console.log("Writing ecosystem into ", ecosystem);
|
|
216
|
+
Template.makedir(dirname(ecosystem));
|
|
190
217
|
writeFileSync(ecosystem, routes, JSON_OPT);
|
|
191
218
|
let targets = [
|
|
192
219
|
{
|
|
@@ -212,9 +239,17 @@ function getSocketPath() {
|
|
|
212
239
|
return socketPath;
|
|
213
240
|
}
|
|
214
241
|
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
* @param {*} opt
|
|
246
|
+
* @returns
|
|
247
|
+
*/
|
|
215
248
|
function makeData(opt) {
|
|
216
249
|
let data = sysEnv();
|
|
217
|
-
|
|
250
|
+
if (args.env_file && existsSync(args.env_file)) {
|
|
251
|
+
loadEnvFile(args.env_file, opt)
|
|
252
|
+
}
|
|
218
253
|
data.chroot = Template.chroot();
|
|
219
254
|
data.acme_store = join(data.certs_dir, `${data.domain_name}_ecc`);
|
|
220
255
|
data.ca_server = data.ca_server || data.acme_ssl;
|
|
@@ -223,75 +258,147 @@ function makeData(opt) {
|
|
|
223
258
|
}
|
|
224
259
|
for (let row of opt) {
|
|
225
260
|
let [key, value, fallback] = row;
|
|
226
|
-
if (!value) value = fallback;
|
|
227
|
-
if (
|
|
228
|
-
if (
|
|
261
|
+
if (!value) value = data[key] || fallback;
|
|
262
|
+
if (value == null) continue;
|
|
263
|
+
if (isString(value)) {
|
|
229
264
|
if (/.+\+$/.test(value)) {
|
|
230
265
|
value = value.replace(/\+$/, data[key]);
|
|
231
266
|
}
|
|
232
267
|
data[key] = value.trim() || fallback;
|
|
268
|
+
} else {
|
|
269
|
+
data[key] = value
|
|
233
270
|
}
|
|
234
271
|
}
|
|
235
272
|
|
|
273
|
+
/** Named extra settings */
|
|
274
|
+
data.allow_recursion = 'localhost;';
|
|
236
275
|
if (data.public_ip4) {
|
|
237
276
|
data.reverse_ip4 = data.public_ip4.split('.').reverse().join('.');
|
|
277
|
+
} else {
|
|
278
|
+
data.reverse_ip4 = ""
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!data.public_ip6) {
|
|
282
|
+
data.public_ip6 = "";
|
|
238
283
|
}
|
|
239
284
|
|
|
285
|
+
if (!data.storage_backup) {
|
|
286
|
+
data.storage_backup = ""
|
|
287
|
+
}
|
|
240
288
|
return data;
|
|
241
289
|
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
*
|
|
293
|
+
* @param {*} env
|
|
294
|
+
* @param {*} opt
|
|
295
|
+
*/
|
|
296
|
+
function loadEnvFile(file, opt) {
|
|
297
|
+
let src = readJson(file);
|
|
298
|
+
opt.map((r) => {
|
|
299
|
+
let [key] = r;
|
|
300
|
+
if (src[key] != null) r[1] = src[key];
|
|
301
|
+
})
|
|
302
|
+
console.log(opt)
|
|
303
|
+
}
|
|
304
|
+
|
|
242
305
|
/**
|
|
243
306
|
*
|
|
244
307
|
*/
|
|
245
308
|
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`);
|
|
309
|
+
if (hasExistingSettings(Template.chroot('etc/drumee/drumee.json'))) {
|
|
250
310
|
exit(0)
|
|
251
311
|
}
|
|
252
|
-
|
|
312
|
+
|
|
313
|
+
let use_email = 0;
|
|
314
|
+
if (args.public_domain) use_email = 1;
|
|
315
|
+
let domain_name = args.public_domain || args.private_domain;
|
|
253
316
|
if (!domain_name) {
|
|
254
|
-
|
|
255
|
-
|
|
317
|
+
if (!args.localhost) {
|
|
318
|
+
console.log("There is no domain name defined for the installation", args);
|
|
319
|
+
exit(0)
|
|
320
|
+
}
|
|
256
321
|
}
|
|
322
|
+
|
|
323
|
+
const nsupdate_key = Template.chroot('etc/bind/keys/update.key')
|
|
257
324
|
const opt = [
|
|
258
|
-
["
|
|
259
|
-
["
|
|
260
|
-
["
|
|
261
|
-
["
|
|
262
|
-
["
|
|
263
|
-
["
|
|
264
|
-
["
|
|
265
|
-
["
|
|
266
|
-
["
|
|
267
|
-
["
|
|
268
|
-
["
|
|
269
|
-
["
|
|
270
|
-
["
|
|
325
|
+
["nsupdate_key", NSUPDATE_KEY, nsupdate_key],
|
|
326
|
+
["admin_email", args.admin_email],
|
|
327
|
+
["credential_dir", Template.chroot('etc/drumee/credential')],
|
|
328
|
+
["domain_desc", args.description, 'My Drumee Box'],
|
|
329
|
+
["max_body_size", args.max_body_size, '10G'],
|
|
330
|
+
["drumee_root", args.drumee_root, "/var/lib/drumee"],
|
|
331
|
+
["use_email", use_email, 0],
|
|
332
|
+
["db_dir", args.db_dir, '/var/lib/mysql'],
|
|
333
|
+
["log_dir", args.log_dir, '/var/log/drumee'],
|
|
334
|
+
["system_user", args.system_user, 'www-data'],
|
|
335
|
+
["system_group", args.system_group, 'www-data'],
|
|
336
|
+
["backup_storage", args.backup_storage, ""],
|
|
337
|
+
["data_dir", args.data_dir, '/var/lib/drumee/data'],
|
|
338
|
+
["http_port", args.http_port, 80],
|
|
339
|
+
["https_port", args.https_port, 443],
|
|
340
|
+
["verbosity", args.verbosity, 2],
|
|
271
341
|
]
|
|
272
|
-
|
|
342
|
+
|
|
343
|
+
if (!args.localhost) {
|
|
344
|
+
opt.push(
|
|
345
|
+
["private_ip4", args.private_ip4],
|
|
346
|
+
["public_domain", args.public_domain],
|
|
347
|
+
["public_ip4", args.public_ip4],
|
|
348
|
+
["public_ip6", args.public_ip6],
|
|
349
|
+
["storage_backup", args.backup_storage], /** Legacy */
|
|
350
|
+
["private_domain", args.private_domain],
|
|
351
|
+
["acme_dir", ACME_DIR],
|
|
352
|
+
["acme_email_account", ACME_EMAIL_ACCOUNT, args.admin_email],
|
|
353
|
+
["certs_dir", CERTS_DIR],
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
let data = makeData(opt);
|
|
359
|
+
|
|
360
|
+
if (!data) {
|
|
361
|
+
exit(1);
|
|
362
|
+
}
|
|
273
363
|
let d = new Date().toISOString();
|
|
274
364
|
let [day, hour] = d.split('T')
|
|
275
365
|
day = day.replace(/\-/g, '');
|
|
276
366
|
hour = hour.split(':')[0];
|
|
277
367
|
data.serial = `${day}${hour}`;
|
|
278
368
|
|
|
279
|
-
let
|
|
369
|
+
let configs = { ...data };
|
|
280
370
|
let keys = ["myConf", "chroot", "date"];
|
|
281
371
|
|
|
282
372
|
for (let key of keys) {
|
|
283
|
-
delete
|
|
373
|
+
delete configs[key];
|
|
284
374
|
}
|
|
285
375
|
|
|
286
|
-
if (
|
|
287
|
-
return
|
|
376
|
+
if (args.readonly) {
|
|
377
|
+
return configs;
|
|
288
378
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
379
|
+
|
|
380
|
+
configs.socketPath = getSocketPath();
|
|
381
|
+
configs.runtime_dir = join(configs.drumee_root, 'runtime');
|
|
382
|
+
configs.server_dir = join(configs.runtime_dir, 'server');
|
|
383
|
+
configs.server_base = configs.server_dir;
|
|
384
|
+
configs.server_home = join(configs.server_base, 'main');
|
|
385
|
+
configs.server_location = configs.server_home;
|
|
386
|
+
|
|
387
|
+
//console.log(configs)
|
|
388
|
+
configs.ui_dir = join(configs.runtime_dir, 'ui');
|
|
389
|
+
configs.ui_base = join(configs.ui_dir, 'main');
|
|
390
|
+
configs.ui_home = configs.ui_base;
|
|
391
|
+
configs.ui_location = configs.ui_base;
|
|
392
|
+
|
|
393
|
+
configs.tmp_dir = join(configs.runtime_dir, 'tmp');
|
|
394
|
+
configs.static_dir = join(configs.runtime_dir, 'static');
|
|
395
|
+
|
|
396
|
+
let filename = Template.chroot("etc/drumee/drumee.json");
|
|
397
|
+
console.log("Writing main conf into drumee.json", filename);
|
|
398
|
+
Template.makedir(dirname(filename));
|
|
399
|
+
writeFileSync(filename, configs, JSON_OPT);
|
|
400
|
+
console.log(configs)
|
|
401
|
+
return configs;
|
|
295
402
|
}
|
|
296
403
|
|
|
297
404
|
/**
|
|
@@ -301,6 +408,7 @@ function getSysConfigs() {
|
|
|
301
408
|
function writeCredentials(file, data) {
|
|
302
409
|
let target = Template.chroot(`etc/drumee/credential/${file}.json`);
|
|
303
410
|
console.log(`Writing credentials into ${target}`);
|
|
411
|
+
Template.makedir(dirname(target));
|
|
304
412
|
writeFileSync(target, data, JSON_OPT);
|
|
305
413
|
}
|
|
306
414
|
|
|
@@ -317,14 +425,13 @@ function errorHandler(err) {
|
|
|
317
425
|
*/
|
|
318
426
|
function copyConfigs(items) {
|
|
319
427
|
for (let item of items) {
|
|
320
|
-
let
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
let content = readFileSync(
|
|
428
|
+
let src = join(__dirname, 'configs', item);
|
|
429
|
+
let dest = Template.chroot(item);
|
|
430
|
+
console.log(`Copying ${src} to ${dest}`)
|
|
431
|
+
Template.makedir(dirname(dest))
|
|
432
|
+
let content = readFileSync(src);
|
|
325
433
|
let str = String(content).toString();
|
|
326
434
|
//Buffer.from(content, "utf8");
|
|
327
|
-
let dest = Template.chroot(item);
|
|
328
435
|
let fd = openSync(dest, "w+");
|
|
329
436
|
writeSync(fd, str);
|
|
330
437
|
close(fd, errorHandler);
|
|
@@ -361,92 +468,127 @@ function getDkim(file) {
|
|
|
361
468
|
*
|
|
362
469
|
*/
|
|
363
470
|
function writeInfraConf(data) {
|
|
364
|
-
|
|
471
|
+
|
|
365
472
|
const etc = 'etc';
|
|
366
473
|
const nginx = join(etc, 'nginx');
|
|
367
474
|
const drumee = join(etc, 'drumee');
|
|
368
|
-
const bind = join(etc, 'bind'
|
|
369
|
-
const
|
|
475
|
+
const bind = join(etc, 'bind');
|
|
476
|
+
const libbind = join('var', 'lib', 'bind');
|
|
477
|
+
const postfix = join(etc, 'postfix');
|
|
370
478
|
const mariadb = join(etc, 'mysql', 'mariadb.conf.d');
|
|
371
479
|
const infra = join(drumee, 'infrastructure');
|
|
372
|
-
const {
|
|
373
|
-
const dkim = join(etc, 'opendkim', 'keys', domain, 'dkim.txt');
|
|
480
|
+
const { public_domain, private_domain } = data;
|
|
374
481
|
let targets = [
|
|
375
|
-
|
|
376
|
-
// Nginx
|
|
377
|
-
`${nginx}/sites-enabled/drumee.conf`,
|
|
378
|
-
|
|
379
|
-
// Drumee
|
|
380
|
-
`${drumee}/ssl/main.conf`,
|
|
381
482
|
`${drumee}/drumee.sh`,
|
|
382
|
-
`${drumee}/conf.d/conference.json`,
|
|
383
483
|
`${drumee}/conf.d/drumee.json`,
|
|
384
484
|
`${drumee}/conf.d/exchange.json`,
|
|
385
485
|
`${drumee}/conf.d/myDrumee.json`,
|
|
386
|
-
`${drumee}/conf.d/conference.json`,
|
|
387
486
|
`${drumee}/conf.d/drumee.json`,
|
|
388
487
|
`${drumee}/conf.d/myDrumee.json`,
|
|
389
488
|
|
|
489
|
+
`${nginx}/nginx.conf`,
|
|
490
|
+
|
|
390
491
|
`${infra}/mfs.conf`,
|
|
391
492
|
`${infra}/routes/main.conf`,
|
|
392
493
|
`${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
494
|
`${mariadb}/50-server.cnf`,
|
|
495
|
+
`${mariadb}/50-client.cnf`,
|
|
409
496
|
];
|
|
410
497
|
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
498
|
+
if (args.localhost) {
|
|
499
|
+
let { username } = userInfo();
|
|
500
|
+
let system_group = username;
|
|
501
|
+
if (username = 'root') {
|
|
502
|
+
username = data.system_user || 'www-data';
|
|
503
|
+
system_group = data.system_group || 'www-data';
|
|
504
|
+
}
|
|
505
|
+
data.system_user = username;
|
|
506
|
+
data.system_group = system_group;
|
|
507
|
+
targets.push(`${nginx}/sites-enabled/localhost.conf`)
|
|
508
|
+
let dir = join(args.drumee_root, 'cache', 'localhost')
|
|
509
|
+
mkdirSync(dir, { recursive: true });
|
|
510
|
+
} else {
|
|
511
|
+
targets.push(
|
|
512
|
+
`${bind}/named.conf.log`,
|
|
513
|
+
`${bind}/named.conf.options`,
|
|
514
|
+
)
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
writeEcoSystem(data);
|
|
518
|
+
if (data.public_ip4 && public_domain) {
|
|
519
|
+
let dir = join(args.drumee_root, 'cache', public_domain)
|
|
520
|
+
mkdirSync(dir, { recursive: true });
|
|
521
|
+
targets.push(
|
|
522
|
+
`${nginx}/sites-enabled/public.conf`,
|
|
523
|
+
`${drumee}/ssl/public.conf`,
|
|
524
|
+
`${bind}/named.conf.public`,
|
|
525
|
+
{ tpl: `${libbind}/public.tpl`, out: `${libbind}/${public_domain}` },
|
|
526
|
+
{ tpl: `${libbind}/public-reverse.tpl`, out: `${libbind}/${data.public_ip4}` }
|
|
527
|
+
);
|
|
528
|
+
|
|
529
|
+
const dkim = join(etc, 'opendkim', 'keys', public_domain, 'dkim.txt');
|
|
530
|
+
targets.push(
|
|
531
|
+
`${postfix}/main.cf`,
|
|
532
|
+
`${postfix}/mysql-virtual-alias-maps.cf`,
|
|
533
|
+
`${postfix}/mysql-virtual-mailbox-domains.cf`,
|
|
534
|
+
`${postfix}/mysql-virtual-mailbox-maps.cf`,
|
|
535
|
+
`${etc}/dkimkeys/dkim.key`,
|
|
536
|
+
`${etc}/mail/dkim.key`,
|
|
537
|
+
`${etc}/mailname`,
|
|
538
|
+
`${etc}/opendkim/KeyTable`,
|
|
539
|
+
)
|
|
540
|
+
data.dkim_key = getDkim(dkim);
|
|
541
|
+
data.mail_user = MAIL_USER || 'postfix';
|
|
542
|
+
data.mail_password = uniqueId();
|
|
543
|
+
data.smptd_cache_db = "btree:$";
|
|
416
544
|
}
|
|
417
|
-
|
|
418
|
-
data.
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
545
|
+
|
|
546
|
+
if (data.private_ip4 && private_domain) {
|
|
547
|
+
let dir = join(args.drumee_root, 'cache', private_domain)
|
|
548
|
+
mkdirSync(dir, { recursive: true });
|
|
549
|
+
targets.push(
|
|
550
|
+
`${nginx}/sites-enabled/private.conf`,
|
|
551
|
+
`${drumee}/ssl/private.conf`,
|
|
552
|
+
`${bind}/named.conf.private`,
|
|
553
|
+
{ tpl: `${libbind}/private.tpl`, out: `${libbind}/${private_domain}` },
|
|
554
|
+
{ tpl: `${libbind}/private-reverse.tpl`, out: `${libbind}/${data.private_ip4}` },
|
|
555
|
+
)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
|
|
422
559
|
writeTemplates(data, targets);
|
|
423
560
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
561
|
+
if (!args.localhost) {
|
|
562
|
+
writeCredentials("postfix", {
|
|
563
|
+
host: 'localhost',
|
|
564
|
+
user: data.mail_user,
|
|
565
|
+
password: data.mail_password,
|
|
566
|
+
})
|
|
429
567
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
568
|
+
writeCredentials("db", {
|
|
569
|
+
password: uniqueId(),
|
|
570
|
+
user: "drumee-app",
|
|
571
|
+
host: "localhost",
|
|
572
|
+
})
|
|
435
573
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
574
|
+
writeCredentials("email", {
|
|
575
|
+
host: `localhost`,
|
|
576
|
+
port: 587,
|
|
577
|
+
secure: false,
|
|
578
|
+
auth: {
|
|
579
|
+
user: `butler@${public_domain}`,
|
|
580
|
+
pass: uniqueId()
|
|
581
|
+
},
|
|
582
|
+
tls: {
|
|
583
|
+
rejectUnauthorized: false
|
|
584
|
+
}
|
|
585
|
+
})
|
|
448
586
|
|
|
449
|
-
|
|
587
|
+
copyConfigs([
|
|
588
|
+
'etc/postfix/master.cf',
|
|
589
|
+
'etc/cron.d/drumee',
|
|
590
|
+
])
|
|
591
|
+
}
|
|
450
592
|
}
|
|
451
593
|
|
|
452
594
|
/**
|
|
@@ -479,7 +621,6 @@ function writeJitsiConf(data) {
|
|
|
479
621
|
// Nginx
|
|
480
622
|
`${nginx}/sites-enabled/jitsi.conf`,
|
|
481
623
|
`${nginx}/modules-enabled/90-turn-relay.conf`,
|
|
482
|
-
//`${nginx}/sites-enabled/turnrelay.conf`,
|
|
483
624
|
|
|
484
625
|
// Prosody
|
|
485
626
|
`${prosody}/prosody.cfg.lua`,
|
|
@@ -514,15 +655,15 @@ function makeConfData(data) {
|
|
|
514
655
|
jvb_password: randomString(),
|
|
515
656
|
app_id: randomString(),
|
|
516
657
|
app_password: randomString(),
|
|
517
|
-
ui_base: join(data.ui_base, '
|
|
658
|
+
ui_base: join(data.ui_base, 'main'),
|
|
518
659
|
location: '/-/',
|
|
519
660
|
pushPort: 23000,
|
|
520
661
|
restPort: 24000,
|
|
521
662
|
};
|
|
522
663
|
if (!data.export_dir) data.export_dir = null;
|
|
523
664
|
if (!data.import_dir) data.import_dir = null;
|
|
524
|
-
if (!data.
|
|
525
|
-
data.
|
|
665
|
+
if (!data.private_address) {
|
|
666
|
+
data.private_address = data.public_address || "127.0.0.1";
|
|
526
667
|
}
|
|
527
668
|
return data
|
|
528
669
|
}
|
|
@@ -536,38 +677,64 @@ function privateIp() {
|
|
|
536
677
|
})
|
|
537
678
|
}
|
|
538
679
|
|
|
680
|
+
/**
|
|
681
|
+
*
|
|
682
|
+
*/
|
|
683
|
+
async function getAddresses(data) {
|
|
684
|
+
const isPrivate = await privateIp();
|
|
685
|
+
let os = require("os");
|
|
686
|
+
let interfaces = os.networkInterfaces();
|
|
687
|
+
let private_ip4, public_ip4, private_ip6, public_ip6;
|
|
688
|
+
for (let name in interfaces) {
|
|
689
|
+
if (name == 'lo') continue;
|
|
690
|
+
for (let dev of interfaces[name]) {
|
|
691
|
+
switch (dev.family) {
|
|
692
|
+
case 'IPv4':
|
|
693
|
+
if (isPrivate(dev.address) && !private_ip4) {
|
|
694
|
+
private_ip4 = dev.address;
|
|
695
|
+
}
|
|
696
|
+
if (!isPrivate(dev.address) && !public_ip4) {
|
|
697
|
+
public_ip4 = dev.address;
|
|
698
|
+
}
|
|
699
|
+
break;
|
|
700
|
+
case 'IPv6':
|
|
701
|
+
if (isPrivate(dev.address) && !private_ip6) {
|
|
702
|
+
private_ip6 = dev.address;
|
|
703
|
+
}
|
|
704
|
+
if (!isPrivate(dev.address) && !public_ip6) {
|
|
705
|
+
public_ip6 = dev.address;
|
|
706
|
+
}
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
data.private_ip4 = data.private_ip4 || private_ip4;
|
|
712
|
+
data.private_ip6 = data.private_ip6 || private_ip6;
|
|
713
|
+
data.local_address = data.private_ip4;
|
|
714
|
+
|
|
715
|
+
data.public_ip4 = data.public_ip4 || public_ip4;
|
|
716
|
+
data.public_ip6 = data.public_ip6 || public_ip6;
|
|
717
|
+
|
|
718
|
+
return data;
|
|
719
|
+
}
|
|
720
|
+
|
|
539
721
|
/**
|
|
540
722
|
*
|
|
541
723
|
* @returns
|
|
542
724
|
*/
|
|
543
|
-
function
|
|
725
|
+
function main() {
|
|
726
|
+
const env_root = args.outdir || args.chroot;
|
|
727
|
+
if (env_root) loadSysEnv(env_root);
|
|
544
728
|
return new Promise(async (res, rej) => {
|
|
545
729
|
let data = getSysConfigs();
|
|
546
730
|
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);
|
|
731
|
+
data = { ...data, ...makeConfData(data) };
|
|
732
|
+
data = await getAddresses(data);
|
|
565
733
|
let func = [];
|
|
566
|
-
if (
|
|
567
|
-
func
|
|
734
|
+
if (args.only_infra || args.no_jitsi || args.localhost || data.local_domain) {
|
|
735
|
+
func.push(writeInfraConf)
|
|
568
736
|
} else {
|
|
569
|
-
|
|
570
|
-
if (ARGV.jitsi) func.push(writeJitsiConf)
|
|
737
|
+
func = [writeInfraConf, writeJitsiConf];
|
|
571
738
|
}
|
|
572
739
|
func.map(function (f) {
|
|
573
740
|
f(data);
|
|
@@ -577,7 +744,7 @@ function configure() {
|
|
|
577
744
|
});
|
|
578
745
|
}
|
|
579
746
|
|
|
580
|
-
|
|
747
|
+
main()
|
|
581
748
|
.then(() => {
|
|
582
749
|
exit(0);
|
|
583
750
|
})
|