@drumee/setup-infra 1.0.14 → 1.0.16

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.
Files changed (75) hide show
  1. package/bin/create-local-certs +38 -0
  2. package/bin/env +8 -5
  3. package/bin/init-acme +23 -4
  4. package/bin/init-named +1 -1
  5. package/bin/install +28 -4
  6. package/bin/prosody +21 -12
  7. package/index.js +314 -184
  8. package/package.json +2 -2
  9. package/templates/etc/bind/named.conf.local +39 -0
  10. package/templates/etc/bind/named.conf.options +13 -4
  11. package/templates/etc/dhcp/dhclient.conf +55 -0
  12. package/templates/etc/drumee/certs/jitsi.private.cnf +13 -0
  13. package/templates/etc/drumee/certs/private.cnf +13 -0
  14. package/templates/etc/drumee/conf.d/conference.private.json +9 -0
  15. package/templates/etc/drumee/conf.d/conference.public.json +9 -0
  16. package/templates/etc/drumee/conf.d/myDrumee.json.tpl +2 -1
  17. package/templates/etc/drumee/drumee.sh.tpl +32 -17
  18. package/templates/etc/drumee/infrastructure/internals/accel.private.conf.tpl +47 -0
  19. package/templates/etc/drumee/infrastructure/internals/{accel.conf.tpl → accel.public.conf.tpl} +1 -1
  20. package/templates/etc/drumee/infrastructure/{platform.json.tpl → mfs.private.conf.tpl} +5 -5
  21. package/templates/etc/drumee/infrastructure/{mfs.conf.tpl → mfs.public.conf.tpl} +1 -1
  22. package/templates/etc/drumee/infrastructure/routes/private.conf.tpl +143 -0
  23. package/templates/etc/drumee/infrastructure/routes/{main.conf.tpl → public.conf.tpl} +18 -28
  24. package/templates/etc/drumee/infrastructure/servers/tt.conf +9 -9
  25. package/templates/etc/drumee/ssl/private.conf.tpl +2 -1
  26. package/templates/etc/drumee/ssl/public.conf.tpl +1 -1
  27. package/templates/etc/jitsi/jicofo/jicofo.private.conf.tpl +46 -0
  28. package/templates/etc/jitsi/jicofo/{jicofo.conf.tpl → jicofo.public.conf.tpl} +7 -7
  29. package/templates/etc/jitsi/jicofo/sip-cmmunicator.private.properties +3 -0
  30. package/templates/etc/jitsi/jicofo/sip-cmmunicator.public.properties +3 -0
  31. package/templates/etc/jitsi/meet.private.conf.tpl +132 -0
  32. package/templates/etc/jitsi/{meet.conf.tpl → meet.public.conf.tpl} +5 -5
  33. package/templates/etc/jitsi/ssl.private.conf.tpl +25 -0
  34. package/templates/etc/jitsi/{ssl.conf.tpl → ssl.public.conf.tpl} +3 -3
  35. package/templates/etc/jitsi/videobridge/defaults/jvb.conf +1 -1
  36. package/templates/etc/jitsi/videobridge/jvb.private.conf +67 -0
  37. package/templates/etc/jitsi/videobridge/{jvb.conf → jvb.public.conf} +6 -6
  38. package/templates/etc/jitsi/web/config.private.js.tpl +208 -0
  39. package/templates/etc/jitsi/web/{config.js.tpl → config.public.js.tpl} +4 -4
  40. package/templates/etc/jitsi/web/defaults/default +2 -2
  41. package/templates/etc/jitsi/web/defaults/meet.conf +3 -3
  42. package/templates/etc/mysql/mariadb.conf.d/50-server.cnf +3 -3
  43. package/templates/etc/nginx/modules-enabled/{90-turn-relay.conf → 90-turn-relay.private.conf.tpl} +6 -6
  44. package/templates/etc/nginx/modules-enabled/{90-turn-relay.conf.tpl → 90-turn-relay.public.conf.tpl} +4 -4
  45. package/templates/etc/nginx/nginx.conf +2 -0
  46. package/templates/etc/nginx/sites-enabled/{public.conf.tpl → 01-public.conf.tpl} +7 -7
  47. package/templates/etc/nginx/sites-enabled/{private.conf.tpl → 02-private.conf.tpl} +6 -6
  48. package/templates/etc/nginx/sites-enabled/{jitsi.conf.tpl → 20-jitsi.private.conf.tpl} +9 -9
  49. package/templates/etc/nginx/sites-enabled/{pivate.jitsi.conf.tpl → 20-jitsi.public.conf.tpl} +9 -9
  50. package/templates/etc/nginx/sites-enabled/{localhost.conf → loopback.tpl} +10 -9
  51. package/templates/etc/nginx/sites-enabled/turnrelay.conf.tpl +4 -4
  52. package/templates/etc/prosody/conf.d/private.cfg.lua.tpl +51 -51
  53. package/templates/etc/prosody/conf.d/public.cfg.lua.tpl +47 -47
  54. package/templates/etc/prosody/defaults/conf.d/jitsi-meet.cfg.lua +3 -3
  55. package/templates/etc/turnserver.private.conf.tpl +46 -0
  56. package/templates/etc/{turnserver.conf.tpl → turnserver.public.conf.tpl} +3 -3
  57. package/templates/index.js +3 -2
  58. package/templates/utils.js +22 -99
  59. package/templates/var/lib/bind/domain.tpl +70 -0
  60. package/templates/var/lib/bind/private-reverse.tpl +1 -1
  61. package/templates/var/lib/bind/{prvate.tpl → private.tpl} +1 -10
  62. package/templates/var/lib/bind/public-reverse.tpl +7 -7
  63. package/templates/var/lib/bind/public.tpl +7 -7
  64. package/bin/init-private +0 -40
  65. package/bin/set-jitsi-conf +0 -14
  66. package/template.js +0 -453
  67. package/templates/etc/bind/named.conf.private +0 -21
  68. package/templates/etc/bind/named.conf.public +0 -21
  69. package/templates/etc/drumee/conf.d/conference.json.tpl +0 -9
  70. package/templates/etc/drumee/dnsapi.sh.tpl +0 -28
  71. package/templates/etc/drumee/env.json +0 -29
  72. package/templates/etc/jitsi/jicofo/sip-cmmunicator.properties +0 -3
  73. package/templates/etc/nginx/sites-enabled/public.jitsi.conf.tpl +0 -28
  74. package/templates/etc/prosody/conf.d/vhost.cfg.lua.tpl +0 -162
  75. package/thidima.sh +0 -44
package/index.js CHANGED
@@ -6,22 +6,51 @@ const { join, dirname } = require("path");
6
6
  const { isString } = require("lodash");
7
7
  const { exit } = process;
8
8
  const { loadSysEnv, sysEnv, uniqueId } = require("@drumee/server-essentials");
9
- const { totalmem, userInfo } = require('os');
9
+ const { totalmem } = require('os');
10
10
  const {
11
- existsSync, close, writeSync, openSync, readFileSync, mkdirSync
11
+ existsSync, close, writeSync, openSync, readFileSync
12
12
  } = require("fs");
13
13
  const { args, hasExistingSettings } = require('./templates/utils')
14
14
 
15
15
  const JSON_OPT = { spaces: 2, EOL: "\r\n" };
16
16
 
17
- const {
17
+ let {
18
18
  ACME_DIR,
19
19
  ACME_EMAIL_ACCOUNT,
20
+ ADMIN_EMAIL,
21
+ BACKUP_STORAGE,
20
22
  CERTS_DIR,
23
+ DRUMEE_DATA_DIR,
24
+ DRUMEE_DB_DIR,
25
+ DRUMEE_DESCRIPTION,
26
+ DRUMEE_DOMAIN_NAME,
27
+ DRUMEE_HTTP_PORT,
28
+ DRUMEE_LOCAL_PORT,
29
+ DRUMEE_HTTPS_PORT,
21
30
  MAIL_USER,
31
+ MAX_BODY_SIZE,
22
32
  NSUPDATE_KEY,
33
+ PRIVATE_DOMAIN,
34
+ PRIVATE_IP4,
35
+ PRIVATE_IP6,
36
+ PUBLIC_IP4,
37
+ PRIVATE_IF4,
38
+ PUBLIC_IP6,
39
+ STORAGE_BACKUP,
40
+ INSTANCE_TYPE
23
41
  } = process.env;
24
42
 
43
+ let PUBLIC_DOMAIN = DRUMEE_DOMAIN_NAME;
44
+
45
+ if (PUBLIC_DOMAIN) {
46
+ if (!PRIVATE_DOMAIN) PRIVATE_DOMAIN = PUBLIC_DOMAIN.replace(/\.([a-z_\-0-9]{2,})$/, '.local');
47
+ }
48
+
49
+ PRIVATE_DOMAIN = PRIVATE_DOMAIN || 'local.drumee';
50
+ DRUMEE_HTTPS_PORT = DRUMEE_HTTPS_PORT || 443;
51
+ DRUMEE_LOCAL_PORT = DRUMEE_LOCAL_PORT || 8443;
52
+ DRUMEE_HTTP_PORT = DRUMEE_HTTP_PORT || 80;
53
+
25
54
  /**
26
55
  *
27
56
  * @param {*} l
@@ -134,12 +163,19 @@ function writeTemplates(data, targets) {
134
163
  Template.write(data, out, tpl);
135
164
  }
136
165
  } catch (e) {
137
- console.error(e)
138
- console.error("Failed to write configs for", target)
166
+ console.error("Failed to write configs for", target, e)
139
167
  }
140
168
  }
141
169
  }
142
170
 
171
+ /**
172
+ *
173
+ * @returns
174
+ */
175
+ function isDevInstance() {
176
+ return /^dev/.test(INSTANCE_TYPE)
177
+ }
178
+
143
179
  /**
144
180
  *
145
181
  */
@@ -170,9 +206,10 @@ function writeEcoSystem(data) {
170
206
  script: "./service.js"
171
207
  }, instances, 'cluster_mode');
172
208
 
209
+
173
210
  let f = factory(data);
174
211
  let routes = [main, main_service, f];
175
- //let ecosystem = "etc/drumee/infrastructure/ecosystem.json";
212
+
176
213
  let ecosystem = Template.chroot("etc/drumee/infrastructure/ecosystem.json");
177
214
  if (args.readonly) {
178
215
  console.log("Readonly", ecosystem, routes);
@@ -217,7 +254,6 @@ function makeData(opt) {
217
254
  loadEnvFile(args.env_file, opt)
218
255
  }
219
256
  data.chroot = Template.chroot();
220
- data.acme_store = join(data.certs_dir, `${data.domain_name}_ecc`);
221
257
  data.ca_server = data.ca_server || data.acme_ssl;
222
258
  if (data.own_ssl && data.certs_dir) {
223
259
  data.own_certs_dir = data.certs_dir;
@@ -226,30 +262,43 @@ function makeData(opt) {
226
262
  let [key, value, fallback] = row;
227
263
  if (!value) value = data[key] || fallback;
228
264
  if (value == null) continue;
229
- if (isString(value)) {
265
+ if (!data[key]) {
230
266
  if (/.+\+$/.test(value)) {
231
267
  value = value.replace(/\+$/, data[key]);
232
268
  }
233
- data[key] = value.trim() || fallback;
234
- } else {
235
- data[key] = value
269
+ if (isString(value)) {
270
+ data[key] = value.trim() || fallback;
271
+ } else {
272
+ data[key] = value;
273
+ }
236
274
  }
237
275
  }
238
276
 
239
- /** Named extra settings */
240
- data.allow_recursion = 'localhost;';
241
- if (data.public_ip4) {
242
- data.reverse_ip4 = data.public_ip4.split('.').reverse().join('.');
277
+
278
+ if (!data.storage_backup) {
279
+ data.storage_backup = ""
280
+ }
281
+
282
+ if (data.private_domain) {
283
+ data.jitsi_private_domain = `jit.${data.private_domain}`;
243
284
  } else {
244
- data.reverse_ip4 = ""
285
+ data.jitsi_private_domain = "";
245
286
  }
246
287
 
247
- if (!data.public_ip6) {
248
- data.public_ip6 = "";
288
+ if (data.public_domain) {
289
+ data.use_email = 1;
290
+ data.jitsi_public_domain = `jit.${data.public_domain}`;
291
+ } else {
292
+ data.use_email = 0;
293
+ data.jitsi_public_domain = "";
249
294
  }
250
295
 
251
- if (!data.storage_backup) {
252
- data.storage_backup = ""
296
+ if (isDevInstance()) {
297
+ data.disable_symlinks = 'off';
298
+ data.logLevel = 3;
299
+ } else {
300
+ data.disable_symlinks = 'on';
301
+ data.logLevel = 2;
253
302
  }
254
303
  return data;
255
304
  }
@@ -260,6 +309,7 @@ function makeData(opt) {
260
309
  * @param {*} opt
261
310
  */
262
311
  function loadEnvFile(file, opt) {
312
+ console.log({ file })
263
313
  let src = readJson(file);
264
314
  opt.map((r) => {
265
315
  let [key] = r;
@@ -272,53 +322,46 @@ function loadEnvFile(file, opt) {
272
322
  *
273
323
  */
274
324
  function getSysConfigs() {
325
+ let {
326
+ public_domain, private_domain, private_ip4, public_ip4, public_ip6, backup_storage
327
+ } = sysEnv();
275
328
  if (hasExistingSettings(Template.chroot('etc/drumee/drumee.json'))) {
276
329
  exit(0)
277
330
  }
278
331
 
279
- let use_email = 0;
280
- if (args.public_domain) use_email = 1;
281
- let domain_name = args.public_domain || args.private_domain;
282
- if (!domain_name) {
283
- if (!args.localhost) {
284
- console.log("There is no domain name defined for the installation", args);
285
- exit(0)
286
- }
287
- }
332
+ public_domain = args.public_domain || PUBLIC_DOMAIN || public_domain;
333
+ private_domain = args.private_domain || PRIVATE_DOMAIN || private_domain;
288
334
 
335
+ backup_storage = args.backup_storage || BACKUP_STORAGE || STORAGE_BACKUP || backup_storage;
336
+
337
+ if (!public_domain && !private_domain) {
338
+ console.log("There is no domain name defined for the installation", args);
339
+ exit(0)
340
+ }
289
341
  const nsupdate_key = Template.chroot('etc/bind/keys/update.key')
290
342
  const opt = [
343
+ ["acme_dir", ACME_DIR],
344
+ ["acme_email_account", ACME_EMAIL_ACCOUNT, ADMIN_EMAIL],
345
+ ["admin_email", ADMIN_EMAIL],
346
+ ["backup_storage", backup_storage, ""],
347
+ ["certs_dir", CERTS_DIR],
348
+ ["data_dir", DRUMEE_DATA_DIR, '/data'],
349
+ ["db_dir", DRUMEE_DB_DIR, '/srv/db'],
350
+ ["domain_desc", DRUMEE_DESCRIPTION, 'My Drumee Box'],
351
+ ["jitsi_root_dir", '/usr/share/jitsi-meet'],
352
+ ["max_body_size", MAX_BODY_SIZE, '10G'],
291
353
  ["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],
354
+ ["private_domain", PRIVATE_DOMAIN],
355
+ ["private_ip4", private_ip4],
356
+ ["private_port", DRUMEE_LOCAL_PORT],
357
+ ["public_domain", public_domain],
358
+ ["public_http_port", DRUMEE_HTTP_PORT],
359
+ ["public_https_port", DRUMEE_HTTPS_PORT],
360
+ ["public_ip4", public_ip4],
361
+ ["public_ip6", public_ip6],
362
+ ["storage_backup", backup_storage], /** Legacy */
303
363
  ]
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
364
  let data = makeData(opt);
321
-
322
365
  if (!data) {
323
366
  exit(1);
324
367
  }
@@ -339,27 +382,18 @@ function getSysConfigs() {
339
382
  return configs;
340
383
  }
341
384
 
385
+ /** Settings designed to be used by the backend server */
386
+ configs.domain = public_domain || private_domain;
387
+ configs.public_domain = public_domain;
388
+ configs.private_domain = private_domain;
389
+ configs.main_domain = data.domain;
390
+ configs.domain_name = data.domain;
391
+ configs.log_dir = data.log_dir;
392
+
342
393
  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
394
  let filename = Template.chroot("etc/drumee/drumee.json");
359
- console.log("Writing main conf into drumee.json", filename);
360
395
  Template.makedir(dirname(filename));
361
396
  writeFileSync(filename, configs, JSON_OPT);
362
- console.log(configs)
363
397
  return configs;
364
398
  }
365
399
 
@@ -430,17 +464,21 @@ function getDkim(file) {
430
464
  *
431
465
  */
432
466
  function writeInfraConf(data) {
433
-
467
+ writeEcoSystem(data);
434
468
  const etc = 'etc';
435
469
  const nginx = join(etc, 'nginx');
436
470
  const drumee = join(etc, 'drumee');
437
471
  const bind = join(etc, 'bind');
438
472
  const libbind = join('var', 'lib', 'bind');
439
- const postfix = join(etc, 'postfix');
473
+ const postfix = join(etc, 'postfix',);
440
474
  const mariadb = join(etc, 'mysql', 'mariadb.conf.d');
441
475
  const infra = join(drumee, 'infrastructure');
442
- const { public_domain, private_domain } = data;
476
+ let { certs_dir, public_domain, private_domain, jitsi_private_domain, jits_public_domain } = data;
443
477
  let targets = [
478
+
479
+ // Nginx
480
+
481
+ // Drumee
444
482
  `${drumee}/drumee.sh`,
445
483
  `${drumee}/conf.d/drumee.json`,
446
484
  `${drumee}/conf.d/exchange.json`,
@@ -448,46 +486,20 @@ function writeInfraConf(data) {
448
486
  `${drumee}/conf.d/drumee.json`,
449
487
  `${drumee}/conf.d/myDrumee.json`,
450
488
 
451
- `${infra}/mfs.conf`,
452
- `${infra}/routes/main.conf`,
453
- `${infra}/internals/accel.conf`,
489
+ `${bind}/named.conf.log`,
490
+ `${bind}/named.conf.options`,
491
+ `${mariadb}/50-server.cnf`,
492
+ `${mariadb}/50-client.cnf`,
493
+ `${bind}/named.conf.local`,
454
494
  ];
455
495
 
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
- )
481
- }
482
-
483
- writeEcoSystem(data);
484
496
  if (data.public_ip4 && public_domain) {
485
- let dir = join(args.drumee_root, 'cache', public_domain)
486
- mkdirSync(dir, { recursive: true });
487
497
  targets.push(
488
- `${nginx}/sites-enabled/public.conf`,
498
+ `${infra}/internals/accel.public.conf`,
499
+ `${infra}/mfs.public.conf`,
500
+ `${infra}/routes/public.conf`,
501
+ `${nginx}/sites-enabled/01-public.conf`,
489
502
  `${drumee}/ssl/public.conf`,
490
- `${bind}/named.conf.public`,
491
503
  { tpl: `${libbind}/public.tpl`, out: `${libbind}/${public_domain}` },
492
504
  { tpl: `${libbind}/public-reverse.tpl`, out: `${libbind}/${data.public_ip4}` }
493
505
  );
@@ -510,51 +522,141 @@ function writeInfraConf(data) {
510
522
  }
511
523
 
512
524
  if (data.private_ip4 && private_domain) {
513
- let dir = join(args.drumee_root, 'cache', private_domain)
514
- mkdirSync(dir, { recursive: true });
515
525
  targets.push(
516
- `${nginx}/sites-enabled/private.conf`,
526
+ `${infra}/internals/accel.private.conf`,
527
+ `${infra}/mfs.private.conf`,
528
+ `${infra}/routes/private.conf`,
529
+ `${nginx}/sites-enabled/02-private.conf`,
517
530
  `${drumee}/ssl/private.conf`,
518
- `${bind}/named.conf.private`,
531
+ {
532
+ tpl: `${drumee}/certs/private.cnf`,
533
+ out: `${certs_dir}/${private_domain}_ecc/${private_domain}.cnf`
534
+ },
519
535
  { tpl: `${libbind}/private.tpl`, out: `${libbind}/${private_domain}` },
520
- { tpl: `${libbind}/private-reverse.tpl`, out: `${libbind}/${data.private_ip4}` },
536
+ { tpl: `${libbind}/private-reverse.tpl`, out: `${libbind}/${data.private_ip4}` }
521
537
  )
522
538
  }
523
539
 
540
+ if (jitsi_private_domain) {
541
+ targets.push(
542
+ {
543
+ tpl: `${drumee}/certs/jitsi.private.cnf`,
544
+ out: `${certs_dir}/${jitsi_private_domain}_ecc/${jitsi_private_domain}.cnf`
545
+ },
546
+ )
547
+ }
524
548
 
525
549
  writeTemplates(data, targets);
526
550
 
527
- if (!args.localhost) {
528
- writeCredentials("postfix", {
529
- host: 'localhost',
530
- user: data.mail_user,
531
- password: data.mail_password,
532
- })
551
+ writeCredentials("postfix", {
552
+ host: 'localhost',
553
+ user: data.mail_user,
554
+ password: data.mail_password,
555
+ })
533
556
 
534
- writeCredentials("db", {
535
- password: uniqueId(),
536
- user: "drumee-app",
537
- host: "localhost",
538
- })
557
+ writeCredentials("db", {
558
+ password: uniqueId(),
559
+ user: "drumee-app",
560
+ host: "localhost",
561
+ })
539
562
 
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
- })
563
+ writeCredentials("email", {
564
+ host: `localhost`,
565
+ port: 587,
566
+ secure: false,
567
+ auth: {
568
+ user: `butler@${public_domain}`,
569
+ pass: uniqueId()
570
+ },
571
+ tls: {
572
+ rejectUnauthorized: false
573
+ }
574
+ })
552
575
 
553
- copyConfigs([
554
- 'etc/postfix/master.cf',
555
- 'etc/cron.d/drumee',
556
- ])
557
- }
576
+ copyConfigs([
577
+ 'etc/postfix/master.cf',
578
+ 'etc/cron.d/drumee',
579
+ ])
580
+ }
581
+
582
+ /**
583
+ *
584
+ * @param {*} targets
585
+ * @param {*} type
586
+ */
587
+ function addJitsiConfigsFiles(targets, data, type = 'private') {
588
+ const etc = 'etc';
589
+ const jitsi = join(etc, 'jitsi');
590
+ const nginx = join(etc, 'nginx');
591
+ const prosody = join(etc, 'prosody');
592
+ const drumee = join(etc, 'drumee');
593
+
594
+ const domain = data[`jitsi_${type}_domain`];
595
+ targets.push(
596
+ {
597
+ tpl: `${jitsi}/jicofo/jicofo.${type}.conf`,
598
+ out: `${jitsi}/jicofo/jicofo.conf`,
599
+ },
600
+ {
601
+ tpl: `${jitsi}/jicofo/sip-cmmunicator.${type}.properties`,
602
+ out: `${jitsi}/jicofo/sip-cmmunicator.properties`
603
+ },
604
+ `${jitsi}/videobridge/jvb.${type}.conf`,
605
+ `${jitsi}/ssl.${type}.conf`,
606
+ `${jitsi}/meet.${type}.conf`,
607
+ `${jitsi}/web/config.${type}.js`,
608
+ `${nginx}/sites-enabled/20-jitsi.${type}.conf`,
609
+ `${nginx}/modules-enabled/90-turn-relay.${type}.conf`,
610
+ {
611
+ tpl: `${prosody}/conf.d/${type}.cfg.lua`,
612
+ out: `${prosody}/conf.d/${domain}.cfg.lua`,
613
+ },
614
+ `${etc}/turnserver.${type}.conf`,
615
+ {
616
+ tpl: `${drumee}/conf.d/conference.${type}.json`,
617
+ out: `${drumee}/conf.d/${domain}.json`,
618
+ },
619
+ )
620
+ }
621
+
622
+ /**
623
+ *
624
+ * @param {*} targets
625
+ * @param {*} type
626
+ */
627
+ function _addDrumeeConfigsFiles(targets, data, type = 'private') {
628
+ const etc = 'etc';
629
+ const jitsi = join(etc, 'jitsi');
630
+ const nginx = join(etc, 'nginx');
631
+ const prosody = join(etc, 'prosody');
632
+ const drumee = join(etc, 'drumee');
633
+
634
+ const domain = data[`jitsi_${type}_domain`];
635
+ targets.push(
636
+ {
637
+ tpl: `${jitsi}/jicofo/jicofo.${type}.conf`,
638
+ out: `${jitsi}/jicofo/jicofo.conf`,
639
+ },
640
+ {
641
+ tpl: `${jitsi}/jicofo/sip-cmmunicator.${type}.properties`,
642
+ out: `${jitsi}/jicofo/sip-cmmunicator.properties`
643
+ },
644
+ `${jitsi}/videobridge/jvb.${type}.conf`,
645
+ `${jitsi}/ssl.${type}.conf`,
646
+ `${jitsi}/meet.${type}.conf`,
647
+ `${jitsi}/web/config.${type}.js`,
648
+ `${nginx}/sites-enabled/20-jitsi.${type}.conf`,
649
+ `${nginx}/modules-enabled/90-turn-relay.${type}.conf`,
650
+ {
651
+ tpl: `${prosody}/conf.d/${type}.cfg.lua`,
652
+ out: `${prosody}/conf.d/${domain}.cfg.lua`,
653
+ },
654
+ `${etc}/turnserver.${type}.conf`,
655
+ {
656
+ tpl: `${drumee}/conf.d/conference.${type}.json`,
657
+ out: `${drumee}/conf.d/${domain}.json`,
658
+ },
659
+ )
558
660
  }
559
661
 
560
662
  /**
@@ -563,45 +665,27 @@ function writeInfraConf(data) {
563
665
  function writeJitsiConf(data) {
564
666
  const etc = 'etc';
565
667
  const jitsi = join(etc, 'jitsi');
566
- const nginx = join(etc, 'nginx');
567
668
  const prosody = join(etc, 'prosody');
568
669
  const drumee = join(etc, 'drumee');
569
670
  let targets = [
570
- // Jicofo
571
671
  `${jitsi}/jicofo/config`,
572
- `${jitsi}/jicofo/jicofo.conf`,
573
672
  `${jitsi}/jicofo/logging.properties`,
574
-
575
- // Jitsi Video Bridge
576
673
  `${jitsi}/videobridge/config`,
577
- `${jitsi}/videobridge/jvb.conf`,
578
674
  `${jitsi}/videobridge/logging.properties`,
579
-
580
- // Jitsi meet
581
- `${jitsi}/ssl.conf`,
582
- `${jitsi}/meet.conf`,
583
- `${jitsi}/web/config.js`,
584
675
  `${jitsi}/web/interface_config.js`,
585
676
  `${jitsi}/web/defaults/ffdhe2048.txt`,
586
-
587
- // Nginx
588
- `${nginx}/sites-enabled/jitsi.conf`,
589
- `${nginx}/modules-enabled/90-turn-relay.conf`,
590
-
591
- // Prosody
592
- `${prosody}/prosody.cfg.lua`,
593
677
  `${prosody}/defaults/credentials.sh`,
594
- {
595
- out: `${prosody}/conf.d/${data.jitsi_domain}.cfg.lua`,
596
- tpl: `${prosody}/conf.d/vhost.cfg.lua`
597
- },
598
- // `${prosody}/migrator.cfg.lua`,
599
-
600
- // Turnserver
601
- `${etc}/turnserver.conf`,
602
-
603
- `${drumee}/conf.d/conference.json`,
678
+ `${prosody}/prosody.cfg.lua`,
604
679
  ];
680
+ if (data.public_domain) {
681
+ addJitsiConfigsFiles(targets, data, `public`)
682
+ } else if (data.private_domain) {
683
+ addJitsiConfigsFiles(targets, data, `private`)
684
+ } else {
685
+ console.error(" No domain name available!")
686
+ return
687
+ }
688
+
605
689
  writeTemplates(data, targets);
606
690
 
607
691
  }
@@ -610,8 +694,10 @@ function writeJitsiConf(data) {
610
694
  *
611
695
  */
612
696
  function makeConfData(data) {
697
+ const endpoint_name = "main";
613
698
  data = {
614
699
  ...data,
700
+ endpoint_name,
615
701
  turn_sercret: randomString(),
616
702
  prosody_plugins: "/usr/share/jitsi-meet/prosody-plugins/",
617
703
  xmpp_password: randomString(),
@@ -621,16 +707,13 @@ function makeConfData(data) {
621
707
  jvb_password: randomString(),
622
708
  app_id: randomString(),
623
709
  app_password: randomString(),
624
- ui_base: join(data.ui_base, 'main'),
710
+ ui_base: join(data.ui_base, endpoint_name),
625
711
  location: '/-/',
626
712
  pushPort: 23000,
627
713
  restPort: 24000,
628
714
  };
629
715
  if (!data.export_dir) data.export_dir = null;
630
716
  if (!data.import_dir) data.import_dir = null;
631
- if (!data.private_address) {
632
- data.private_address = data.public_address || "127.0.0.1";
633
- }
634
717
  return data
635
718
  }
636
719
 
@@ -651,6 +734,7 @@ async function getAddresses(data) {
651
734
  let os = require("os");
652
735
  let interfaces = os.networkInterfaces();
653
736
  let private_ip4, public_ip4, private_ip6, public_ip6;
737
+ let private_if4, private_subnet_mask, private_broadcast_address;
654
738
  for (let name in interfaces) {
655
739
  if (name == 'lo') continue;
656
740
  for (let dev of interfaces[name]) {
@@ -658,6 +742,21 @@ async function getAddresses(data) {
658
742
  case 'IPv4':
659
743
  if (isPrivate(dev.address) && !private_ip4) {
660
744
  private_ip4 = dev.address;
745
+ private_if4 = name;
746
+ private_subnet_mask = dev.netmask;
747
+ let a = private_ip4.split('.');
748
+ let b = private_subnet_mask.split('.');
749
+ let i = 0;
750
+ let br = [];
751
+ for (let c of b) {
752
+ if (c == '255') {
753
+ br.push(a[i])
754
+ }else{
755
+ br.push('255')
756
+ }
757
+ i++;
758
+ }
759
+ private_broadcast_address = br.join('.')
661
760
  }
662
761
  if (!isPrivate(dev.address) && !public_ip4) {
663
762
  public_ip4 = dev.address;
@@ -674,16 +773,47 @@ async function getAddresses(data) {
674
773
  }
675
774
  }
676
775
  }
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
776
 
681
- data.public_ip4 = data.public_ip4 || public_ip4;
682
- data.public_ip6 = data.public_ip6 || public_ip6;
777
+ data.private_ip6 = args.private_ip6 || PRIVATE_IP6 || private_ip6;
778
+ data.private_ip4 = args.private_ip4 || PRIVATE_IP4 || private_ip4;
779
+ data.private_if4 = args.private_ip4 || PRIVATE_IF4 || private_if4;
780
+ data.private_if4 = args.private_ip4 || PRIVATE_IF4 || private_if4;
781
+ data.private_broadcast_address = private_broadcast_address || '255.255.255.255';
782
+ data.private_subnet_mask = private_subnet_mask || '255.255.255.0';
783
+
784
+ data.public_ip4 = args.public_ip4 || PUBLIC_IP4 || public_ip4;
785
+ data.public_ip6 = args.public_ip6 || PUBLIC_IP6 || public_ip6;
786
+
787
+ /** Named extra settings */
788
+ data.allow_recursion = 'localhost;';
789
+
790
+ if (data.public_ip4) {
791
+ data.allow_recursion = `${data.allow_recursion} ${data.public_ip4};`
792
+ let a = data.public_ip4.split('.');
793
+ a.pop();
794
+ data.reverse_public_ip4 = a.reverse().join('.');
795
+ } else {
796
+ data.reverse_public_ip4 = ""
797
+ }
798
+
799
+ if (!data.public_ip6) {
800
+ data.public_ip6 = "";
801
+ }
802
+ if (data.private_ip4) {
803
+ data.allow_recursion = `${data.allow_recursion} ${data.private_ip4};`
804
+ let a = data.private_ip4.split('.');
805
+ a.pop();
806
+ data.reverse_private_ip4 = a.reverse().join('.');
807
+ } else {
808
+ data.reverse_private_ip4 = ""
809
+ }
810
+
811
+ if (!data.public_ip6) {
812
+ data.public_ip6 = "";
813
+ }
683
814
 
684
815
  return data;
685
816
  }
686
-
687
817
  /**
688
818
  *
689
819
  * @returns
@@ -697,7 +827,7 @@ function main() {
697
827
  data = { ...data, ...makeConfData(data) };
698
828
  data = await getAddresses(data);
699
829
  let func = [];
700
- if (args.only_infra || args.no_jitsi || args.localhost || data.local_domain) {
830
+ if (args.only_infra || args.no_jitsi) {
701
831
  func.push(writeInfraConf)
702
832
  } else {
703
833
  func = [writeInfraConf, writeJitsiConf];