Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 13035:93c1590b5951
mod_admin_shell: Calculate widths of columns from example values
Harder to accidentally count wrong if Lua is doing the counting on a
plausible input.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 06 Apr 2023 17:07:09 +0200 |
| parent | 13034:1387888a5596 |
| child | 13036:1612c7f7dd55 |
comparison
equal
deleted
inserted
replaced
| 13034:1387888a5596 | 13035:93c1590b5951 |
|---|---|
| 793 end; | 793 end; |
| 794 }; | 794 }; |
| 795 port = { | 795 port = { |
| 796 title = "Port"; | 796 title = "Port"; |
| 797 description = "Server port used"; | 797 description = "Server port used"; |
| 798 width = 5; | 798 width = #string.format("%d", 0xffff); -- max 16 bit unsigned integer |
| 799 align = "right"; | 799 align = "right"; |
| 800 key = "conn"; | 800 key = "conn"; |
| 801 mapper = function(conn) | 801 mapper = function(conn) |
| 802 if conn then | 802 if conn then |
| 803 return conn:serverport(); | 803 return conn:serverport(); |
| 805 end; | 805 end; |
| 806 }; | 806 }; |
| 807 dir = { | 807 dir = { |
| 808 title = "Dir"; | 808 title = "Dir"; |
| 809 description = "Direction of server-to-server connection"; | 809 description = "Direction of server-to-server connection"; |
| 810 width = 3; | 810 width = #"<->"; |
| 811 key = "direction"; | 811 key = "direction"; |
| 812 mapper = function(dir, session) | 812 mapper = function(dir, session) |
| 813 if session.incoming and session.outgoing then return "<->"; end | 813 if session.incoming and session.outgoing then return "<->"; end |
| 814 if dir == "outgoing" then return "-->"; end | 814 if dir == "outgoing" then return "-->"; end |
| 815 if dir == "incoming" then return "<--"; end | 815 if dir == "incoming" then return "<--"; end |
| 818 id = { title = "Session ID"; description = "Internal session ID used in logging"; width = 20; key = "id" }; | 818 id = { title = "Session ID"; description = "Internal session ID used in logging"; width = 20; key = "id" }; |
| 819 type = { title = "Type"; description = "Session type"; width = #"c2s_unauthed"; key = "type" }; | 819 type = { title = "Type"; description = "Session type"; width = #"c2s_unauthed"; key = "type" }; |
| 820 method = { | 820 method = { |
| 821 title = "Method"; | 821 title = "Method"; |
| 822 description = "Connection method"; | 822 description = "Connection method"; |
| 823 width = 10; | 823 width = math.max(#"BOSH", #"WebSocket", #"TCP"); |
| 824 mapper = function(_, session) | 824 mapper = function(_, session) |
| 825 if session.bosh_version then | 825 if session.bosh_version then |
| 826 return "BOSH"; | 826 return "BOSH"; |
| 827 elseif session.websocket_request then | 827 elseif session.websocket_request then |
| 828 return "WebSocket"; | 828 return "WebSocket"; |
| 832 end; | 832 end; |
| 833 }; | 833 }; |
| 834 ipv = { | 834 ipv = { |
| 835 title = "IPv"; | 835 title = "IPv"; |
| 836 description = "Internet Protocol version (4 or 6)"; | 836 description = "Internet Protocol version (4 or 6)"; |
| 837 width = 4; | 837 width = #"IPvX"; |
| 838 key = "ip"; | 838 key = "ip"; |
| 839 mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; | 839 mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; |
| 840 }; | 840 }; |
| 841 ip = { title = "IP address"; description = "IP address the session connected from"; width = 40; key = "ip" }; | 841 ip = { |
| 842 title = "IP address"; | |
| 843 description = "IP address the session connected from"; | |
| 844 width = #"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"; | |
| 845 key = "ip"; | |
| 846 }; | |
| 842 status = { | 847 status = { |
| 843 title = "Status"; | 848 title = "Status"; |
| 844 description = "Presence status"; | 849 description = "Presence status"; |
| 845 width = 6; | 850 width = math.max(#"online", #"chat"); |
| 846 key = "presence"; | 851 key = "presence"; |
| 847 mapper = function(p) | 852 mapper = function(p) |
| 848 if not p then return ""; end | 853 if not p then return ""; end |
| 849 return p:get_child_text("show") or "online"; | 854 return p:get_child_text("show") or "online"; |
| 850 end; | 855 end; |
| 851 }; | 856 }; |
| 852 secure = { | 857 secure = { |
| 853 title = "Security"; | 858 title = "Security"; |
| 854 description = "TLS version or security status"; | 859 description = "TLS version or security status"; |
| 855 key = "conn"; | 860 key = "conn"; |
| 856 width = 8; | 861 width = math.max(#"secure", "TLSvX.Y"); |
| 857 mapper = function(conn, session) | 862 mapper = function(conn, session) |
| 858 if not session.secure then return "insecure"; end | 863 if not session.secure then return "insecure"; end |
| 859 if not conn or not conn:ssl() then return "secure" end | 864 if not conn or not conn:ssl() then return "secure" end |
| 860 local tls_info = conn.ssl_info and conn:ssl_info(); | 865 local tls_info = conn.ssl_info and conn:ssl_info(); |
| 861 return tls_info and tls_info.protocol or "secure"; | 866 return tls_info and tls_info.protocol or "secure"; |
| 862 end; | 867 end; |
| 863 }; | 868 }; |
| 864 encryption = { | 869 encryption = { |
| 865 title = "Encryption"; | 870 title = "Encryption"; |
| 866 description = "Encryption algorithm used (TLS cipher suite)"; | 871 description = "Encryption algorithm used (TLS cipher suite)"; |
| 872 -- openssl ciphers 'ALL:COMPLEMENTOFALL' | tr : \\n | awk 'BEGIN {n=1} length() > n {n=length()} END {print(n)}' | |
| 867 width = 30; | 873 width = 30; |
| 868 key = "conn"; | 874 key = "conn"; |
| 869 mapper = function(conn) | 875 mapper = function(conn) |
| 870 local info = conn and conn.ssl_info and conn:ssl_info(); | 876 local info = conn and conn.ssl_info and conn:ssl_info(); |
| 871 if info then return info.cipher end | 877 if info then return info.cipher end |
| 873 }; | 879 }; |
| 874 cert = { | 880 cert = { |
| 875 title = "Certificate"; | 881 title = "Certificate"; |
| 876 description = "Validation status of certificate"; | 882 description = "Validation status of certificate"; |
| 877 key = "cert_identity_status"; | 883 key = "cert_identity_status"; |
| 878 width = 11; | 884 width = math.max(#"Expired", #"Self-signed", #"Untrusted", #"Mismatched", #"Unknown"); |
| 879 mapper = function(cert_status, session) | 885 mapper = function(cert_status, session) |
| 880 if cert_status then return capitalize(cert_status); end | 886 if cert_status then return capitalize(cert_status); end |
| 881 if session.cert_chain_status == "Invalid" then | 887 if session.cert_chain_status == "Invalid" then |
| 882 local cert_errors = set.new(session.cert_chain_errors[1]); | 888 local cert_errors = set.new(session.cert_chain_errors[1]); |
| 883 if cert_errors:contains("certificate has expired") then | 889 if cert_errors:contains("certificate has expired") then |
| 893 end; | 899 end; |
| 894 }; | 900 }; |
| 895 sni = { | 901 sni = { |
| 896 title = "SNI"; | 902 title = "SNI"; |
| 897 description = "Hostname requested in TLS"; | 903 description = "Hostname requested in TLS"; |
| 898 width = 22; | 904 width = 22; -- same as host, remote etc |
| 899 mapper = function(_, session) | 905 mapper = function(_, session) |
| 900 if not session.conn then return end | 906 if not session.conn then return end |
| 901 local sock = session.conn:socket(); | 907 local sock = session.conn:socket(); |
| 902 return sock and sock.getsniname and sock:getsniname() or ""; | 908 return sock and sock.getsniname and sock:getsniname() or ""; |
| 903 end; | 909 end; |
| 904 }; | 910 }; |
| 905 alpn = { | 911 alpn = { |
| 906 title = "ALPN"; | 912 title = "ALPN"; |
| 907 description = "Protocol requested in TLS"; | 913 description = "Protocol requested in TLS"; |
| 908 width = 11; | 914 width = math.max(#"http/1.1", #"xmpp-client", #"xmpp-server"); |
| 909 mapper = function(_, session) | 915 mapper = function(_, session) |
| 910 if not session.conn then return end | 916 if not session.conn then return end |
| 911 local sock = session.conn:socket(); | 917 local sock = session.conn:socket(); |
| 912 return sock and sock.getalpn and sock:getalpn() or ""; | 918 return sock and sock.getalpn and sock:getalpn() or ""; |
| 913 end; | 919 end; |
| 914 }; | 920 }; |
| 915 smacks = { | 921 smacks = { |
| 916 title = "SM"; | 922 title = "SM"; |
| 917 description = "Stream Management (XEP-0198) status"; | 923 description = "Stream Management (XEP-0198) status"; |
| 918 key = "smacks"; | 924 key = "smacks"; |
| 919 width = 11; | 925 -- FIXME shorter synonym for hibernating |
| 926 width = math.max(#"yes", #"no", #"hibernating"); | |
| 920 mapper = function(smacks_xmlns, session) | 927 mapper = function(smacks_xmlns, session) |
| 921 if not smacks_xmlns then return "no"; end | 928 if not smacks_xmlns then return "no"; end |
| 922 if session.hibernating then return "hibernating"; end | 929 if session.hibernating then return "hibernating"; end |
| 923 return "yes"; | 930 return "yes"; |
| 924 end; | 931 end; |
| 948 }; | 955 }; |
| 949 dialback = { | 956 dialback = { |
| 950 title = "Dialback"; | 957 title = "Dialback"; |
| 951 description = "Legacy server verification"; | 958 description = "Legacy server verification"; |
| 952 key = "dialback_key"; | 959 key = "dialback_key"; |
| 953 width = 13; | 960 width = math.max(#"Not used", #"Not initiated", #"Initiated", #"Completed"); |
| 954 mapper = function (dialback_key, session) | 961 mapper = function (dialback_key, session) |
| 955 if not dialback_key then | 962 if not dialback_key then |
| 956 if session.type == "s2sin" or session.type == "s2sout" then | 963 if session.type == "s2sin" or session.type == "s2sout" then |
| 957 return "Not used"; | 964 return "Not used"; |
| 958 end | 965 end |