Software / code / prosody
Comparison
prosodyctl @ 5585:3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 17 May 2013 13:35:12 +0100 |
| parent | 5584:1d841117117c |
| child | 5589:8745193e651e |
comparison
equal
deleted
inserted
replaced
| 5584:1d841117117c | 5585:3e097acf82de |
|---|---|
| 816 print(" see http://prosody.im/doc/configure#overview for more information.") | 816 print(" see http://prosody.im/doc/configure#overview for more information.") |
| 817 print(""); | 817 print(""); |
| 818 print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", ")); | 818 print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", ")); |
| 819 end | 819 end |
| 820 end | 820 end |
| 821 print("Done."); | 821 print("Done.\n"); |
| 822 end | |
| 823 if not what or what == "dns" then | |
| 824 local dns = require "net.dns"; | |
| 825 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222}); | |
| 826 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269}); | |
| 827 | |
| 828 local c2s_srv_required, s2s_srv_required; | |
| 829 if not c2s_ports:contains(5222) then | |
| 830 c2s_srv_required = true; | |
| 831 end | |
| 832 if not s2s_ports:contains(5269) then | |
| 833 s2s_srv_required = true; | |
| 834 end | |
| 835 | |
| 836 local problem_hosts = set.new(); | |
| 837 | |
| 838 local external_addresses = set.new(); | |
| 839 | |
| 840 local fqdn = socket.dns.tohostname(socket.dns.gethostname()); | |
| 841 if fqdn then | |
| 842 local res = dns.lookup(fqdn, "A"); | |
| 843 if res then | |
| 844 for _, record in ipairs(res) do | |
| 845 external_addresses:add(record.a); | |
| 846 end | |
| 847 end | |
| 848 local res = dns.lookup(fqdn, "AAAA"); | |
| 849 if res then | |
| 850 for _, record in ipairs(res) do | |
| 851 external_addresses:add(record.aaaa); | |
| 852 end | |
| 853 end | |
| 854 end | |
| 855 | |
| 856 if external_addresses:empty() then | |
| 857 print(""); | |
| 858 print(" Failed to determine the external addresses of this server. Checks may be inaccurate."); | |
| 859 c2s_srv_required, s2s_srv_required = true, true; | |
| 860 end | |
| 861 | |
| 862 local v6_supported = not not socket.tcp6; | |
| 863 | |
| 864 for host, host_options in it.filter("*", pairs(config.getconfig())) do | |
| 865 local all_targets_ok, some_targets_ok = true, false; | |
| 866 | |
| 867 local is_component = not not host_options.component_module; | |
| 868 print("Checking DNS for "..(is_component and "component" or "host").." "..host.."..."); | |
| 869 local target_hosts = set.new(); | |
| 870 if not is_component then | |
| 871 local res = dns.lookup("_xmpp-client._tcp."..host..".", "SRV"); | |
| 872 if res then | |
| 873 for _, record in ipairs(res) do | |
| 874 target_hosts:add(record.srv.target); | |
| 875 if not c2s_ports:contains(record.srv.port) then | |
| 876 print(" SRV target "..record.srv.target.." contains unknown client port: "..record.srv.port); | |
| 877 end | |
| 878 end | |
| 879 else | |
| 880 if c2s_srv_required then | |
| 881 print(" No _xmpp-client SRV record found for "..host..", but it looks like you need one."); | |
| 882 else | |
| 883 target_hosts:add(host); | |
| 884 end | |
| 885 end | |
| 886 end | |
| 887 local res = dns.lookup("_xmpp-server._tcp."..host..".", "SRV"); | |
| 888 if res then | |
| 889 for _, record in ipairs(res) do | |
| 890 target_hosts:add(record.srv.target); | |
| 891 if not s2s_ports:contains(record.srv.port) then | |
| 892 print(" SRV target "..record.srv.target.." contains unknown server port: "..record.srv.port); | |
| 893 end | |
| 894 end | |
| 895 else | |
| 896 if s2s_srv_required then | |
| 897 print(" No _xmpp-server SRV record found for "..host..", but it looks like you need one."); | |
| 898 else | |
| 899 target_hosts:add(host); | |
| 900 end | |
| 901 end | |
| 902 if target_hosts:empty() then | |
| 903 target_hosts:add(host); | |
| 904 end | |
| 905 | |
| 906 if target_hosts:contains("localhost") then | |
| 907 print(" Target 'localhost' cannot be accessed from other servers"); | |
| 908 target_hosts:remove("localhost"); | |
| 909 end | |
| 910 | |
| 911 for host in target_hosts do | |
| 912 local host_ok_v4, host_ok_v6; | |
| 913 local res = dns.lookup(host, "A"); | |
| 914 if res then | |
| 915 for _, record in ipairs(res) do | |
| 916 if external_addresses:contains(record.a) then | |
| 917 some_targets_ok = true; | |
| 918 host_ok_v4 = true; | |
| 919 else | |
| 920 print(" "..host.." A record points to unknown address "..record.a); | |
| 921 all_targets_ok = false; | |
| 922 end | |
| 923 end | |
| 924 end | |
| 925 local res = dns.lookup(host, "AAAA"); | |
| 926 if res then | |
| 927 for _, record in ipairs(res) do | |
| 928 if external_addresses:contains(record.aaaa) then | |
| 929 some_targets_ok = true; | |
| 930 host_ok_v6 = true; | |
| 931 else | |
| 932 print(" "..host.." AAAA record points to unknown address "..record.aaaa); | |
| 933 all_targets_ok = false; | |
| 934 end | |
| 935 end | |
| 936 end | |
| 937 | |
| 938 if not host_ok_v4 then | |
| 939 print(" Host "..host.." does not seem to resolve to this server for IPv4"); | |
| 940 end | |
| 941 if not host_ok_v6 and v6_supported then | |
| 942 print(" Host "..host.." does not seem to resolve to this server for IPv6"); | |
| 943 elseif host_ok_v6 and not v6_supported then | |
| 944 print(" Host "..host.." has AAAA records, but your version of LuaSocket does not support IPv6."); | |
| 945 print(" Please see http://prosody.im/doc/ipv6 for more information."); | |
| 946 end | |
| 947 end | |
| 948 if not all_targets_ok then | |
| 949 print(" "..(some_targets_ok and "Only some" or "No").." targets for "..host.." appear to resolve to this server."); | |
| 950 if is_component then | |
| 951 print(" DNS records are necessary if you want users on other servers to access this component."); | |
| 952 end | |
| 953 print(""); | |
| 954 problem_hosts:add(host); | |
| 955 end | |
| 956 end | |
| 957 if not problem_hosts:empty() then | |
| 958 print(""); | |
| 959 print("For more information about DNS configuration please see http://prosody.im/doc/dns"); | |
| 960 print(""); | |
| 961 ok = false; | |
| 962 end | |
| 822 end | 963 end |
| 823 if not ok then | 964 if not ok then |
| 824 print("Problems found, see above."); | 965 print("Problems found, see above."); |
| 825 else | 966 else |
| 826 print("All checks passed, congratulations!"); | 967 print("All checks passed, congratulations!"); |