Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 12229:30ea791ce817
mod_admin_shell: Add descriptions of each column to 'help columns'
Since some of the titles are quite dense
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 30 Jan 2022 12:49:43 +0100 |
| parent | 12228:f60f9cd9d26c |
| child | 12258:99560987ea19 |
comparison
equal
deleted
inserted
replaced
| 12228:f60f9cd9d26c | 12229:30ea791ce817 |
|---|---|
| 319 print [[The columns shown by c2s:show() and s2s:show() can be customizied via the]] | 319 print [[The columns shown by c2s:show() and s2s:show() can be customizied via the]] |
| 320 print [['columns' argument as described here.]] | 320 print [['columns' argument as described here.]] |
| 321 print [[]] | 321 print [[]] |
| 322 print [[Columns can be specified either as "id jid ipv" or as {"id", "jid", "ipv"}.]] | 322 print [[Columns can be specified either as "id jid ipv" or as {"id", "jid", "ipv"}.]] |
| 323 print [[Available columns are:]] | 323 print [[Available columns are:]] |
| 324 local meta_columns = { | |
| 325 { title = "ID"; width = 5 }; | |
| 326 { title = "Column Title"; width = 12 }; | |
| 327 { title = "Description"; width = 12 }; | |
| 328 }; | |
| 329 -- auto-adjust widths | |
| 330 for column, spec in pairs(available_columns) do | |
| 331 meta_columns[1].width = math.max(meta_columns[1].width or 0, #column); | |
| 332 meta_columns[2].width = math.max(meta_columns[2].width or 0, #(spec.title or "")); | |
| 333 meta_columns[3].width = math.max(meta_columns[3].width or 0, #(spec.description or "")); | |
| 334 end | |
| 335 local row = format_table(meta_columns, 120) | |
| 336 print(row()); | |
| 324 for column, spec in iterators.sorted_pairs(available_columns) do | 337 for column, spec in iterators.sorted_pairs(available_columns) do |
| 325 print("- "..column..": "..(spec.title or capitalize(column))); | 338 print(row({ column, spec.title, spec.description })); |
| 326 -- TODO descriptions | |
| 327 end | 339 end |
| 328 print [[]] | 340 print [[]] |
| 329 print [[Most fields on the internal session structures can also be used as columns]] | 341 print [[Most fields on the internal session structures can also be used as columns]] |
| 330 -- Also, you can pass a table column specification directly, with mapper callabck and all | 342 -- Also, you can pass a table column specification directly, with mapper callabck and all |
| 331 end | 343 end |
| 701 end | 713 end |
| 702 | 714 |
| 703 available_columns = { | 715 available_columns = { |
| 704 jid = { | 716 jid = { |
| 705 title = "JID"; | 717 title = "JID"; |
| 718 description = "Full JID of user session"; | |
| 706 width = 32; | 719 width = 32; |
| 707 key = "full_jid"; | 720 key = "full_jid"; |
| 708 mapper = function(full_jid, session) return full_jid or get_jid(session) end; | 721 mapper = function(full_jid, session) return full_jid or get_jid(session) end; |
| 709 }; | 722 }; |
| 710 host = { | 723 host = { |
| 711 title = "Host"; | 724 title = "Host"; |
| 725 description = "Local hostname"; | |
| 712 key = "host"; | 726 key = "host"; |
| 713 width = 22; | 727 width = 22; |
| 714 mapper = function(host, session) | 728 mapper = function(host, session) |
| 715 return host or get_s2s_hosts(session) or "?"; | 729 return host or get_s2s_hosts(session) or "?"; |
| 716 end; | 730 end; |
| 717 }; | 731 }; |
| 718 remote = { | 732 remote = { |
| 719 title = "Remote"; | 733 title = "Remote"; |
| 734 description = "Remote hostname"; | |
| 720 width = 22; | 735 width = 22; |
| 721 mapper = function(_, session) | 736 mapper = function(_, session) |
| 722 return select(2, get_s2s_hosts(session)); | 737 return select(2, get_s2s_hosts(session)); |
| 723 end; | 738 end; |
| 724 }; | 739 }; |
| 725 port = { | 740 port = { |
| 726 title = "Port"; | 741 title = "Port"; |
| 742 description = "Server port used"; | |
| 727 width = 5; | 743 width = 5; |
| 728 align = "right"; | 744 align = "right"; |
| 729 key = "conn"; | 745 key = "conn"; |
| 730 mapper = function(conn) return conn:serverport(); end; | 746 mapper = function(conn) return conn:serverport(); end; |
| 731 }; | 747 }; |
| 732 dir = { | 748 dir = { |
| 733 title = "Dir"; | 749 title = "Dir"; |
| 750 description = "Direction of server-to-server connection"; | |
| 734 width = 3; | 751 width = 3; |
| 735 key = "direction"; | 752 key = "direction"; |
| 736 mapper = function(dir, session) | 753 mapper = function(dir, session) |
| 737 if session.incoming and session.outgoing then return "<->"; end | 754 if session.incoming and session.outgoing then return "<->"; end |
| 738 if dir == "outgoing" then return "-->"; end | 755 if dir == "outgoing" then return "-->"; end |
| 739 if dir == "incoming" then return "<--"; end | 756 if dir == "incoming" then return "<--"; end |
| 740 end; | 757 end; |
| 741 }; | 758 }; |
| 742 id = { title = "Session ID"; width = 20; key = "id" }; | 759 id = { title = "Session ID"; description = "Internal session ID used in logging"; width = 20; key = "id" }; |
| 743 type = { title = "Type"; width = #"c2s_unauthed"; key = "type" }; | 760 type = { title = "Type"; description = "Session type"; width = #"c2s_unauthed"; key = "type" }; |
| 744 method = { | 761 method = { |
| 745 title = "Method"; | 762 title = "Method"; |
| 763 description = "Connection method"; | |
| 746 width = 10; | 764 width = 10; |
| 747 mapper = function(_, session) | 765 mapper = function(_, session) |
| 748 if session.bosh_version then | 766 if session.bosh_version then |
| 749 return "BOSH"; | 767 return "BOSH"; |
| 750 elseif session.websocket_request then | 768 elseif session.websocket_request then |
| 754 end | 772 end |
| 755 end; | 773 end; |
| 756 }; | 774 }; |
| 757 ipv = { | 775 ipv = { |
| 758 title = "IPv"; | 776 title = "IPv"; |
| 777 description = "Internet Protocol version (4 or 6)"; | |
| 759 width = 4; | 778 width = 4; |
| 760 key = "ip"; | 779 key = "ip"; |
| 761 mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; | 780 mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; |
| 762 }; | 781 }; |
| 763 ip = { title = "IP address"; width = 40; key = "ip" }; | 782 ip = { title = "IP address"; description = "IP address the session connected from"; width = 40; key = "ip" }; |
| 764 status = { | 783 status = { |
| 765 title = "Status"; | 784 title = "Status"; |
| 785 description = "Presence status"; | |
| 766 width = 6; | 786 width = 6; |
| 767 key = "presence"; | 787 key = "presence"; |
| 768 mapper = function(p) | 788 mapper = function(p) |
| 769 if not p then return ""; end | 789 if not p then return ""; end |
| 770 return p:get_child_text("show") or "online"; | 790 return p:get_child_text("show") or "online"; |
| 771 end; | 791 end; |
| 772 }; | 792 }; |
| 773 secure = { | 793 secure = { |
| 774 title = "Security"; | 794 title = "Security"; |
| 795 description = "TLS version or security status"; | |
| 775 key = "conn"; | 796 key = "conn"; |
| 776 width = 8; | 797 width = 8; |
| 777 mapper = function(conn, session) | 798 mapper = function(conn, session) |
| 778 if not session.secure then return "insecure"; end | 799 if not session.secure then return "insecure"; end |
| 779 if not conn or not conn:ssl() then return "secure" end | 800 if not conn or not conn:ssl() then return "secure" end |
| 783 return tls_info and tls_info.protocol or "secure"; | 804 return tls_info and tls_info.protocol or "secure"; |
| 784 end; | 805 end; |
| 785 }; | 806 }; |
| 786 encryption = { | 807 encryption = { |
| 787 title = "Encryption"; | 808 title = "Encryption"; |
| 809 description = "Encryption algorithm used (TLS cipher suite)"; | |
| 788 width = 30; | 810 width = 30; |
| 789 key = "conn"; | 811 key = "conn"; |
| 790 mapper = function(conn) | 812 mapper = function(conn) |
| 791 local sock = conn:socket(); | 813 local sock = conn:socket(); |
| 792 local info = sock and sock.info and sock:info(); | 814 local info = sock and sock.info and sock:info(); |
| 793 if info then return info.cipher end | 815 if info then return info.cipher end |
| 794 end; | 816 end; |
| 795 }; | 817 }; |
| 796 cert = { | 818 cert = { |
| 797 title = "Certificate"; | 819 title = "Certificate"; |
| 820 description = "Validation status of certificate"; | |
| 798 key = "cert_identity_status"; | 821 key = "cert_identity_status"; |
| 799 width = 13; | 822 width = 13; |
| 800 mapper = function(cert_status, session) | 823 mapper = function(cert_status, session) |
| 801 if cert_status then return capitalize(cert_status); end | 824 if cert_status then return capitalize(cert_status); end |
| 802 if session.cert_chain_status == "Invalid" then | 825 if session.cert_chain_status == "Invalid" then |
| 813 return "Not validated"; | 836 return "Not validated"; |
| 814 end; | 837 end; |
| 815 }; | 838 }; |
| 816 sni = { | 839 sni = { |
| 817 title = "SNI"; | 840 title = "SNI"; |
| 841 description = "Hostname requested in TLS"; | |
| 818 width = 22; | 842 width = 22; |
| 819 mapper = function(_, session) | 843 mapper = function(_, session) |
| 820 if not session.conn then return end | 844 if not session.conn then return end |
| 821 local sock = session.conn:socket(); | 845 local sock = session.conn:socket(); |
| 822 return sock and sock.getsniname and sock:getsniname() or ""; | 846 return sock and sock.getsniname and sock:getsniname() or ""; |
| 823 end; | 847 end; |
| 824 }; | 848 }; |
| 825 alpn = { | 849 alpn = { |
| 826 title = "ALPN"; | 850 title = "ALPN"; |
| 851 description = "Protocol requested in TLS"; | |
| 827 width = 11; | 852 width = 11; |
| 828 mapper = function(_, session) | 853 mapper = function(_, session) |
| 829 if not session.conn then return end | 854 if not session.conn then return end |
| 830 local sock = session.conn:socket(); | 855 local sock = session.conn:socket(); |
| 831 return sock and sock.getalpn and sock:getalpn() or ""; | 856 return sock and sock.getalpn and sock:getalpn() or ""; |
| 832 end; | 857 end; |
| 833 }; | 858 }; |
| 834 smacks = { | 859 smacks = { |
| 835 title = "SM"; | 860 title = "SM"; |
| 861 description = "Stream Management (XEP-0198) status"; | |
| 836 key = "smacks"; | 862 key = "smacks"; |
| 837 width = 11; | 863 width = 11; |
| 838 mapper = function(smacks_xmlns, session) | 864 mapper = function(smacks_xmlns, session) |
| 839 if not smacks_xmlns then return "no"; end | 865 if not smacks_xmlns then return "no"; end |
| 840 if session.hibernating then return "hibernating"; end | 866 if session.hibernating then return "hibernating"; end |
| 841 return "yes"; | 867 return "yes"; |
| 842 end; | 868 end; |
| 843 }; | 869 }; |
| 844 smacks_queue = { | 870 smacks_queue = { |
| 845 title = "SM Queue"; | 871 title = "SM Queue"; |
| 872 description = "Length of Stream Management stanza queue"; | |
| 846 key = "outgoing_stanza_queue"; | 873 key = "outgoing_stanza_queue"; |
| 847 width = 8; | 874 width = 8; |
| 848 align = "right"; | 875 align = "right"; |
| 849 mapper = function (queue) | 876 mapper = function (queue) |
| 850 return queue and tostring(queue:count_unacked()); | 877 return queue and tostring(queue:count_unacked()); |
| 851 end | 878 end |
| 852 }; | 879 }; |
| 853 csi = { | 880 csi = { |
| 854 title = "CSI State"; | 881 title = "CSI State"; |
| 882 description = "Client State Indication (XEP-0352)"; | |
| 855 key = "state"; | 883 key = "state"; |
| 856 -- TODO include counter | 884 -- TODO include counter |
| 857 }; | 885 }; |
| 858 s2s_sasl = { | 886 s2s_sasl = { |
| 859 title = "SASL"; | 887 title = "SASL"; |
| 888 description = "Server authentication status"; | |
| 860 key = "external_auth"; | 889 key = "external_auth"; |
| 861 width = 10; | 890 width = 10; |
| 862 mapper = capitalize | 891 mapper = capitalize |
| 863 }; | 892 }; |
| 864 dialback = { | 893 dialback = { |
| 865 title = "Dialback"; | 894 title = "Dialback"; |
| 895 description = "Legacy server verification"; | |
| 866 key = "dialback_key"; | 896 key = "dialback_key"; |
| 867 width = 13; | 897 width = 13; |
| 868 mapper = function (dialback_key, session) | 898 mapper = function (dialback_key, session) |
| 869 if not dialback_key then | 899 if not dialback_key then |
| 870 if session.type == "s2sin" or session.type == "s2sout" then | 900 if session.type == "s2sin" or session.type == "s2sout" then |