Software /
code /
prosody
Comparison
prosodyctl @ 7923:81f3068fc30c
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 01 Mar 2017 02:38:05 +0100 |
parent | 7686:8d6f367bed8c |
parent | 7922:2fd20f372cb1 |
child | 8015:ecb110f45c92 |
comparison
equal
deleted
inserted
replaced
7910:91db637be237 | 7923:81f3068fc30c |
---|---|
1 #!/usr/bin/env lua | 1 #!/usr/bin/env lua |
2 -- Prosody IM | 2 -- Prosody IM |
3 -- Copyright (C) 2008-2010 Matthew Wild | 3 -- Copyright (C) 2008-2010 Matthew Wild |
4 -- Copyright (C) 2008-2010 Waqas Hussain | 4 -- Copyright (C) 2008-2010 Waqas Hussain |
5 -- | 5 -- |
6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
8 -- | 8 -- |
9 | 9 |
10 -- prosodyctl - command-line controller for Prosody XMPP server | 10 -- prosodyctl - command-line controller for Prosody XMPP server |
63 config = require "core.configmanager" | 63 config = require "core.configmanager" |
64 | 64 |
65 local ENV_CONFIG; | 65 local ENV_CONFIG; |
66 do | 66 do |
67 local filenames = {}; | 67 local filenames = {}; |
68 | 68 |
69 local filename; | 69 local filename; |
70 if arg[1] == "--config" and arg[2] then | 70 if arg[1] == "--config" and arg[2] then |
71 table.insert(filenames, arg[2]); | 71 table.insert(filenames, arg[2]); |
72 if CFG_CONFIGDIR then | 72 if CFG_CONFIGDIR then |
73 table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]); | 73 table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]); |
118 if custom_plugin_paths then | 118 if custom_plugin_paths then |
119 local path_sep = package.config:sub(3,3); | 119 local path_sep = package.config:sub(3,3); |
120 -- path1;path2;path3;defaultpath... | 120 -- path1;path2;path3;defaultpath... |
121 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins"); | 121 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins"); |
122 end | 122 end |
123 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR, | 123 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR, |
124 plugins = CFG_PLUGINDIR or "plugins", data = data_path }; | 124 plugins = CFG_PLUGINDIR or "plugins", data = data_path }; |
125 | 125 |
126 if prosody.installed then | 126 if prosody.installed then |
127 -- Change working directory to data path. | 127 -- Change working directory to data path. |
128 require "lfs".chdir(data_path); | 128 require "lfs".chdir(data_path); |
159 if not switched_user then | 159 if not switched_user then |
160 -- Boo! | 160 -- Boo! |
161 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err)); | 161 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err)); |
162 end | 162 end |
163 end | 163 end |
164 | 164 |
165 -- Set our umask to protect data files | 165 -- Set our umask to protect data files |
166 pposix.umask(config.get("*", "umask") or "027"); | 166 pposix.umask(config.get("*", "umask") or "027"); |
167 pposix.setenv("HOME", data_path); | 167 pposix.setenv("HOME", data_path); |
168 pposix.setenv("PROSODY_CONFIG", ENV_CONFIG); | 168 pposix.setenv("PROSODY_CONFIG", ENV_CONFIG); |
169 else | 169 else |
210 print(""); | 210 print(""); |
211 os.exit(1); | 211 os.exit(1); |
212 end | 212 end |
213 | 213 |
214 | 214 |
215 local error_messages = setmetatable({ | 215 local error_messages = setmetatable({ |
216 ["invalid-username"] = "The given username is invalid in a Jabber ID"; | 216 ["invalid-username"] = "The given username is invalid in a Jabber ID"; |
217 ["invalid-hostname"] = "The given hostname is invalid"; | 217 ["invalid-hostname"] = "The given hostname is invalid"; |
218 ["no-password"] = "No password was supplied"; | 218 ["no-password"] = "No password was supplied"; |
219 ["no-such-user"] = "The given user does not exist on the server"; | 219 ["no-such-user"] = "The given user does not exist on the server"; |
220 ["no-such-host"] = "The given hostname does not exist in the config"; | 220 ["no-such-host"] = "The given hostname does not exist in the config"; |
239 end | 239 end |
240 | 240 |
241 for hostname, config in pairs(config.getconfig()) do | 241 for hostname, config in pairs(config.getconfig()) do |
242 hosts[hostname] = make_host(hostname); | 242 hosts[hostname] = make_host(hostname); |
243 end | 243 end |
244 | 244 |
245 local modulemanager = require "core.modulemanager" | 245 local modulemanager = require "core.modulemanager" |
246 | 246 |
247 local prosodyctl = require "util.prosodyctl" | 247 local prosodyctl = require "util.prosodyctl" |
248 local socket = require "socket" | 248 local socket = require "socket" |
249 ----------------------- | 249 ----------------------- |
288 if not user and host then | 288 if not user and host then |
289 show_message [[Failed to understand JID, please supply the JID you want to create]] | 289 show_message [[Failed to understand JID, please supply the JID you want to create]] |
290 show_usage [[adduser user@host]] | 290 show_usage [[adduser user@host]] |
291 return 1; | 291 return 1; |
292 end | 292 end |
293 | 293 |
294 if not host then | 294 if not host then |
295 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; | 295 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
296 return 1; | 296 return 1; |
297 end | 297 end |
298 | 298 |
299 if not hosts[host] then | 299 if not hosts[host] then |
300 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) | 300 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
301 show_warning("The user will not be able to log in until this is changed."); | 301 show_warning("The user will not be able to log in until this is changed."); |
302 hosts[host] = make_host(host); | 302 hosts[host] = make_host(host); |
303 end | 303 end |
304 | 304 |
305 if prosodyctl.user_exists{ user = user, host = host } then | 305 if prosodyctl.user_exists{ user = user, host = host } then |
306 show_message [[That user already exists]]; | 306 show_message [[That user already exists]]; |
307 return 1; | 307 return 1; |
308 end | 308 end |
309 | 309 |
310 local password = read_password(); | 310 local password = read_password(); |
311 if not password then return 1; end | 311 if not password then return 1; end |
312 | 312 |
313 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; | 313 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
314 | 314 |
315 if ok then return 0; end | 315 if ok then return 0; end |
316 | 316 |
317 show_message(msg) | 317 show_message(msg) |
318 return 1; | 318 return 1; |
319 end | 319 end |
320 | 320 |
321 function commands.passwd(arg) | 321 function commands.passwd(arg) |
327 if not user and host then | 327 if not user and host then |
328 show_message [[Failed to understand JID, please supply the JID you want to set the password for]] | 328 show_message [[Failed to understand JID, please supply the JID you want to set the password for]] |
329 show_usage [[passwd user@host]] | 329 show_usage [[passwd user@host]] |
330 return 1; | 330 return 1; |
331 end | 331 end |
332 | 332 |
333 if not host then | 333 if not host then |
334 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; | 334 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
335 return 1; | 335 return 1; |
336 end | 336 end |
337 | 337 |
338 if not hosts[host] then | 338 if not hosts[host] then |
339 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) | 339 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
340 show_warning("The user will not be able to log in until this is changed."); | 340 show_warning("The user will not be able to log in until this is changed."); |
341 hosts[host] = make_host(host); | 341 hosts[host] = make_host(host); |
342 end | 342 end |
343 | 343 |
344 if not prosodyctl.user_exists { user = user, host = host } then | 344 if not prosodyctl.user_exists { user = user, host = host } then |
345 show_message [[That user does not exist, use prosodyctl adduser to create a new user]] | 345 show_message [[That user does not exist, use prosodyctl adduser to create a new user]] |
346 return 1; | 346 return 1; |
347 end | 347 end |
348 | 348 |
349 local password = read_password(); | 349 local password = read_password(); |
350 if not password then return 1; end | 350 if not password then return 1; end |
351 | 351 |
352 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; | 352 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; |
353 | 353 |
354 if ok then return 0; end | 354 if ok then return 0; end |
355 | 355 |
356 show_message(error_messages[msg]) | 356 show_message(error_messages[msg]) |
357 return 1; | 357 return 1; |
358 end | 358 end |
359 | 359 |
360 function commands.deluser(arg) | 360 function commands.deluser(arg) |
366 if not user and host then | 366 if not user and host then |
367 show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]] | 367 show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]] |
368 show_usage [[deluser user@host]] | 368 show_usage [[deluser user@host]] |
369 return 1; | 369 return 1; |
370 end | 370 end |
371 | 371 |
372 if not host then | 372 if not host then |
373 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; | 373 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
374 return 1; | 374 return 1; |
375 end | 375 end |
376 | 376 |
377 if not hosts[host] then | 377 if not hosts[host] then |
378 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) | 378 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
379 hosts[host] = make_host(host); | 379 hosts[host] = make_host(host); |
380 end | 380 end |
381 | 381 |
382 if not prosodyctl.user_exists { user = user, host = host } then | 382 if not prosodyctl.user_exists { user = user, host = host } then |
383 show_message [[That user does not exist on this server]] | 383 show_message [[That user does not exist on this server]] |
384 return 1; | 384 return 1; |
385 end | 385 end |
386 | 386 |
387 local ok, msg = prosodyctl.deluser { user = user, host = host }; | 387 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
388 | 388 |
389 if ok then return 0; end | 389 if ok then return 0; end |
390 | 390 |
391 show_message(error_messages[msg]) | 391 show_message(error_messages[msg]) |
392 return 1; | 392 return 1; |
393 end | 393 end |
394 | 394 |
395 function commands.start(arg) | 395 function commands.start(arg) |
400 local ok, ret = prosodyctl.isrunning(); | 400 local ok, ret = prosodyctl.isrunning(); |
401 if not ok then | 401 if not ok then |
402 show_message(error_messages[ret]); | 402 show_message(error_messages[ret]); |
403 return 1; | 403 return 1; |
404 end | 404 end |
405 | 405 |
406 if ret then | 406 if ret then |
407 local ok, ret = prosodyctl.getpid(); | 407 local ok, ret = prosodyctl.getpid(); |
408 if not ok then | 408 if not ok then |
409 show_message("Couldn't get running Prosody's PID"); | 409 show_message("Couldn't get running Prosody's PID"); |
410 show_message(error_messages[ret]); | 410 show_message(error_messages[ret]); |
411 return 1; | 411 return 1; |
412 end | 412 end |
413 show_message("Prosody is already running with PID %s", ret or "(unknown)"); | 413 show_message("Prosody is already running with PID %s", ret or "(unknown)"); |
414 return 1; | 414 return 1; |
415 end | 415 end |
416 | 416 |
417 local ok, ret = prosodyctl.start(); | 417 local ok, ret = prosodyctl.start(); |
418 if ok then | 418 if ok then |
419 local daemonize = config.get("*", "daemonize"); | 419 local daemonize = config.get("*", "daemonize"); |
420 if daemonize == nil then | 420 if daemonize == nil then |
421 daemonize = prosody.installed; | 421 daemonize = prosody.installed; |
439 end | 439 end |
440 return 0; | 440 return 0; |
441 end | 441 end |
442 | 442 |
443 show_message("Failed to start Prosody"); | 443 show_message("Failed to start Prosody"); |
444 show_message(error_messages[ret]) | 444 show_message(error_messages[ret]) |
445 return 1; | 445 return 1; |
446 end | 446 end |
447 | 447 |
448 function commands.status(arg) | 448 function commands.status(arg) |
449 if arg[1] == "--help" then | 449 if arg[1] == "--help" then |
450 show_usage([[status]], [[Reports the running status of Prosody]]); | 450 show_usage([[status]], [[Reports the running status of Prosody]]); |
454 local ok, ret = prosodyctl.isrunning(); | 454 local ok, ret = prosodyctl.isrunning(); |
455 if not ok then | 455 if not ok then |
456 show_message(error_messages[ret]); | 456 show_message(error_messages[ret]); |
457 return 1; | 457 return 1; |
458 end | 458 end |
459 | 459 |
460 if ret then | 460 if ret then |
461 local ok, ret = prosodyctl.getpid(); | 461 local ok, ret = prosodyctl.getpid(); |
462 if not ok then | 462 if not ok then |
463 show_message("Couldn't get running Prosody's PID"); | 463 show_message("Couldn't get running Prosody's PID"); |
464 show_message(error_messages[ret]); | 464 show_message(error_messages[ret]); |
487 | 487 |
488 if not prosodyctl.isrunning() then | 488 if not prosodyctl.isrunning() then |
489 show_message("Prosody is not running"); | 489 show_message("Prosody is not running"); |
490 return 1; | 490 return 1; |
491 end | 491 end |
492 | 492 |
493 local ok, ret = prosodyctl.stop(); | 493 local ok, ret = prosodyctl.stop(); |
494 if ok then | 494 if ok then |
495 local i=1; | 495 local i=1; |
496 while true do | 496 while true do |
497 local ok, running = prosodyctl.isrunning(); | 497 local ok, running = prosodyctl.isrunning(); |
517 function commands.restart(arg) | 517 function commands.restart(arg) |
518 if arg[1] == "--help" then | 518 if arg[1] == "--help" then |
519 show_usage([[restart]], [[Restart a running Prosody server]]); | 519 show_usage([[restart]], [[Restart a running Prosody server]]); |
520 return 1; | 520 return 1; |
521 end | 521 end |
522 | 522 |
523 commands.stop(arg); | 523 commands.stop(arg); |
524 return commands.start(arg); | 524 return commands.start(arg); |
525 end | 525 end |
526 | 526 |
527 function commands.about(arg) | 527 function commands.about(arg) |
528 read_version(); | 528 read_version(); |
529 if arg[1] == "--help" then | 529 if arg[1] == "--help" then |
530 show_usage([[about]], [[Show information about this Prosody installation]]); | 530 show_usage([[about]], [[Show information about this Prosody installation]]); |
531 return 1; | 531 return 1; |
532 end | 532 end |
533 | 533 |
534 local pwd = "."; | 534 local pwd = "."; |
535 local lfs = require "lfs"; | 535 local lfs = require "lfs"; |
536 local array = require "util.array"; | 536 local array = require "util.array"; |
537 local keys = require "util.iterators".keys; | 537 local keys = require "util.iterators".keys; |
538 local hg = require"util.mercurial"; | 538 local hg = require"util.mercurial"; |
539 local relpath = config.resolve_relative_path; | 539 local relpath = config.resolve_relative_path; |
540 | 540 |
541 print("Prosody "..(prosody.version or "(unknown version)")); | 541 print("Prosody "..(prosody.version or "(unknown version)")); |
542 print(""); | 542 print(""); |
543 print("# Prosody directories"); | 543 print("# Prosody directories"); |
544 print("Data directory: "..relpath(pwd, data_path)); | 544 print("Data directory: "..relpath(pwd, data_path)); |
545 print("Config directory: "..relpath(pwd, CFG_CONFIGDIR or ".")); | 545 print("Config directory: "..relpath(pwd, CFG_CONFIGDIR or ".")); |
606 | 606 |
607 if not prosodyctl.isrunning() then | 607 if not prosodyctl.isrunning() then |
608 show_message("Prosody is not running"); | 608 show_message("Prosody is not running"); |
609 return 1; | 609 return 1; |
610 end | 610 end |
611 | 611 |
612 local ok, ret = prosodyctl.reload(); | 612 local ok, ret = prosodyctl.reload(); |
613 if ok then | 613 if ok then |
614 | 614 |
615 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect."); | 615 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect."); |
616 return 0; | 616 return 0; |
617 end | 617 end |
618 | 618 |
619 show_message(error_messages[ret]); | 619 show_message(error_messages[ret]); |
620 return 1; | 620 return 1; |
621 end | 621 end |
622 -- ejabberdctl compatibility | 622 -- ejabberdctl compatibility |
623 | |
624 local unpack = table.unpack or unpack; -- luacheck: ignore 113 | |
623 | 625 |
624 function commands.register(arg) | 626 function commands.register(arg) |
625 local user, host, password = unpack(arg); | 627 local user, host, password = unpack(arg); |
626 if (not (user and host)) or arg[1] == "--help" then | 628 if (not (user and host)) or arg[1] == "--help" then |
627 if user ~= "--help" then | 629 if user ~= "--help" then |
639 if not password then | 641 if not password then |
640 show_message [[Unable to register user with no password]]; | 642 show_message [[Unable to register user with no password]]; |
641 return 1; | 643 return 1; |
642 end | 644 end |
643 end | 645 end |
644 | 646 |
645 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; | 647 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
646 | 648 |
647 if ok then return 0; end | 649 if ok then return 0; end |
648 | 650 |
649 show_message(error_messages[msg]) | 651 show_message(error_messages[msg]) |
650 return 1; | 652 return 1; |
651 end | 653 end |
652 | 654 |
653 function commands.unregister(arg) | 655 function commands.unregister(arg) |
663 show_usage("unregister USER HOST [PASSWORD]", "Permanently remove a user account from the server"); | 665 show_usage("unregister USER HOST [PASSWORD]", "Permanently remove a user account from the server"); |
664 return 1; | 666 return 1; |
665 end | 667 end |
666 | 668 |
667 local ok, msg = prosodyctl.deluser { user = user, host = host }; | 669 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
668 | 670 |
669 if ok then return 0; end | 671 if ok then return 0; end |
670 | 672 |
671 show_message(error_messages[msg]) | 673 show_message(error_messages[msg]) |
672 return 1; | 674 return 1; |
673 end | 675 end |
674 | 676 |
675 local openssl; | 677 local openssl; |
1008 print(""); | 1010 print(""); |
1009 print(" You require encryption but mod_tls is not enabled."); | 1011 print(" You require encryption but mod_tls is not enabled."); |
1010 print(" Connections will fail."); | 1012 print(" Connections will fail."); |
1011 ok = false; | 1013 ok = false; |
1012 end | 1014 end |
1013 | 1015 |
1014 print("Done.\n"); | 1016 print("Done.\n"); |
1015 end | 1017 end |
1016 if not what or what == "dns" then | 1018 if not what or what == "dns" then |
1017 local dns = require "net.dns"; | 1019 local dns = require "net.dns"; |
1018 local idna = require "util.encodings".idna; | 1020 local idna = require "util.encodings".idna; |
1019 local ip = require "util.ip"; | 1021 local ip = require "util.ip"; |
1020 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222}); | 1022 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222}); |
1021 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269}); | 1023 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269}); |
1022 | 1024 |
1023 local c2s_srv_required, s2s_srv_required; | 1025 local c2s_srv_required, s2s_srv_required; |
1024 if not c2s_ports:contains(5222) then | 1026 if not c2s_ports:contains(5222) then |
1025 c2s_srv_required = true; | 1027 c2s_srv_required = true; |
1026 end | 1028 end |
1027 if not s2s_ports:contains(5269) then | 1029 if not s2s_ports:contains(5269) then |
1028 s2s_srv_required = true; | 1030 s2s_srv_required = true; |
1029 end | 1031 end |
1030 | 1032 |
1031 local problem_hosts = set.new(); | 1033 local problem_hosts = set.new(); |
1032 | 1034 |
1033 local external_addresses, internal_addresses = set.new(), set.new(); | 1035 local external_addresses, internal_addresses = set.new(), set.new(); |
1034 | 1036 |
1035 local fqdn = socket.dns.tohostname(socket.dns.gethostname()); | 1037 local fqdn = socket.dns.tohostname(socket.dns.gethostname()); |
1036 if fqdn then | 1038 if fqdn then |
1037 local res = dns.lookup(idna.to_ascii(fqdn), "A"); | 1039 local res = dns.lookup(idna.to_ascii(fqdn), "A"); |
1038 if res then | 1040 if res then |
1039 for _, record in ipairs(res) do | 1041 for _, record in ipairs(res) do |
1045 for _, record in ipairs(res) do | 1047 for _, record in ipairs(res) do |
1046 external_addresses:add(record.aaaa); | 1048 external_addresses:add(record.aaaa); |
1047 end | 1049 end |
1048 end | 1050 end |
1049 end | 1051 end |
1050 | 1052 |
1051 local local_addresses = require"util.net".local_addresses() or {}; | 1053 local local_addresses = require"util.net".local_addresses() or {}; |
1052 | 1054 |
1053 for addr in it.values(local_addresses) do | 1055 for addr in it.values(local_addresses) do |
1054 if not ip.new_ip(addr).private then | 1056 if not ip.new_ip(addr).private then |
1055 external_addresses:add(addr); | 1057 external_addresses:add(addr); |
1056 else | 1058 else |
1057 internal_addresses:add(addr); | 1059 internal_addresses:add(addr); |
1058 end | 1060 end |
1059 end | 1061 end |
1060 | 1062 |
1061 if external_addresses:empty() then | 1063 if external_addresses:empty() then |
1062 print(""); | 1064 print(""); |
1063 print(" Failed to determine the external addresses of this server. Checks may be inaccurate."); | 1065 print(" Failed to determine the external addresses of this server. Checks may be inaccurate."); |
1064 c2s_srv_required, s2s_srv_required = true, true; | 1066 c2s_srv_required, s2s_srv_required = true, true; |
1065 end | 1067 end |
1066 | 1068 |
1067 local v6_supported = not not socket.tcp6; | 1069 local v6_supported = not not socket.tcp6; |
1068 | 1070 |
1069 for jid, host_options in enabled_hosts() do | 1071 for jid, host_options in enabled_hosts() do |
1070 local all_targets_ok, some_targets_ok = true, false; | 1072 local all_targets_ok, some_targets_ok = true, false; |
1071 local node, host = jid_split(jid); | 1073 local node, host = jid_split(jid); |
1072 | 1074 |
1073 local is_component = not not host_options.component_module; | 1075 local is_component = not not host_options.component_module; |
1074 print("Checking DNS for "..(is_component and "component" or "host").." "..jid.."..."); | 1076 print("Checking DNS for "..(is_component and "component" or "host").." "..jid.."..."); |
1075 if node then | 1077 if node then |
1076 print("Only the domain part ("..host..") is used in DNS.") | 1078 print("Only the domain part ("..host..") is used in DNS.") |
1077 end | 1079 end |
1111 end | 1113 end |
1112 end | 1114 end |
1113 if target_hosts:empty() then | 1115 if target_hosts:empty() then |
1114 target_hosts:add(host); | 1116 target_hosts:add(host); |
1115 end | 1117 end |
1116 | 1118 |
1117 if target_hosts:contains("localhost") then | 1119 if target_hosts:contains("localhost") then |
1118 print(" Target 'localhost' cannot be accessed from other servers"); | 1120 print(" Target 'localhost' cannot be accessed from other servers"); |
1119 target_hosts:remove("localhost"); | 1121 target_hosts:remove("localhost"); |
1120 end | 1122 end |
1121 | 1123 |
1122 local modules = set.new(it.to_array(it.values(host_options.modules_enabled or {}))) | 1124 local modules = set.new(it.to_array(it.values(host_options.modules_enabled or {}))) |
1123 + set.new(it.to_array(it.values(config.get("*", "modules_enabled") or {}))) | 1125 + set.new(it.to_array(it.values(config.get("*", "modules_enabled") or {}))) |
1124 + set.new({ config.get(host, "component_module") }); | 1126 + set.new({ config.get(host, "component_module") }); |
1125 | 1127 |
1126 if modules:contains("proxy65") then | 1128 if modules:contains("proxy65") then |
1135 end | 1137 end |
1136 if #prob > 0 then | 1138 if #prob > 0 then |
1137 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/").." record. Create one or set 'proxy65_address' to the correct host/IP."); | 1139 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/").." record. Create one or set 'proxy65_address' to the correct host/IP."); |
1138 end | 1140 end |
1139 end | 1141 end |
1140 | 1142 |
1141 for host in target_hosts do | 1143 for host in target_hosts do |
1142 local host_ok_v4, host_ok_v6; | 1144 local host_ok_v4, host_ok_v6; |
1143 local res = dns.lookup(idna.to_ascii(host), "A"); | 1145 local res = dns.lookup(idna.to_ascii(host), "A"); |
1144 if res then | 1146 if res then |
1145 for _, record in ipairs(res) do | 1147 for _, record in ipairs(res) do |
1170 print(" "..host.." AAAA record points to unknown address "..record.aaaa); | 1172 print(" "..host.." AAAA record points to unknown address "..record.aaaa); |
1171 all_targets_ok = false; | 1173 all_targets_ok = false; |
1172 end | 1174 end |
1173 end | 1175 end |
1174 end | 1176 end |
1175 | 1177 |
1176 local bad_protos = {} | 1178 local bad_protos = {} |
1177 if not host_ok_v4 then | 1179 if not host_ok_v4 then |
1178 table.insert(bad_protos, "IPv4"); | 1180 table.insert(bad_protos, "IPv4"); |
1179 end | 1181 end |
1180 if not host_ok_v6 then | 1182 if not host_ok_v6 then |
1299 local ret, err = modulemanager.load("*", module_name); | 1301 local ret, err = modulemanager.load("*", module_name); |
1300 if not ret then | 1302 if not ret then |
1301 show_message("Failed to load module '"..module_name.."': "..err); | 1303 show_message("Failed to load module '"..module_name.."': "..err); |
1302 os.exit(1); | 1304 os.exit(1); |
1303 end | 1305 end |
1304 | 1306 |
1305 table.remove(arg, 1); | 1307 table.remove(arg, 1); |
1306 | 1308 |
1307 local module = modulemanager.get_module("*", module_name); | 1309 local module = modulemanager.get_module("*", module_name); |
1308 if not module then | 1310 if not module then |
1309 show_message("Failed to load module '"..module_name.."': Unknown error"); | 1311 show_message("Failed to load module '"..module_name.."': Unknown error"); |
1310 os.exit(1); | 1312 os.exit(1); |
1311 end | 1313 end |
1312 | 1314 |
1313 if not modulemanager.module_has_method(module, "command") then | 1315 if not modulemanager.module_has_method(module, "command") then |
1314 show_message("Fail: mod_"..module_name.." does not support any commands"); | 1316 show_message("Fail: mod_"..module_name.." does not support any commands"); |
1315 os.exit(1); | 1317 os.exit(1); |
1316 end | 1318 end |
1317 | 1319 |
1318 local ok, ret = modulemanager.call_module_method(module, "command", arg); | 1320 local ok, ret = modulemanager.call_module_method(module, "command", arg); |
1319 if ok then | 1321 if ok then |
1320 if type(ret) == "number" then | 1322 if type(ret) == "number" then |
1321 os.exit(ret); | 1323 os.exit(ret); |
1322 elseif type(ret) == "string" then | 1324 elseif type(ret) == "string" then |
1360 command{ "--help" }; | 1362 command{ "--help" }; |
1361 print"" | 1363 print"" |
1362 done[command_name] = true; | 1364 done[command_name] = true; |
1363 end | 1365 end |
1364 end | 1366 end |
1365 | 1367 |
1366 | 1368 |
1367 os.exit(0); | 1369 os.exit(0); |
1368 end | 1370 end |
1369 | 1371 |
1370 os.exit(commands[command]({ select(2, unpack(arg)) })); | 1372 os.exit(commands[command]({ select(2, unpack(arg)) })); |