Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 11892:e712133b4de1
util.human.io: Pass nil to cell mapper to signal missing value
Seems more like conventional Lua than passing an empty string to signal
lack of value.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 12 Nov 2021 11:43:24 +0100 |
| parent | 11891:6a241e66eec5 |
| child | 11905:bbfa707a4756 |
comparison
equal
deleted
inserted
replaced
| 11891:6a241e66eec5 | 11892:e712133b4de1 |
|---|---|
| 41 | 41 |
| 42 local format_number = require "util.human.units".format; | 42 local format_number = require "util.human.units".format; |
| 43 local format_table = require "util.human.io".table; | 43 local format_table = require "util.human.io".table; |
| 44 | 44 |
| 45 local function capitalize(s) | 45 local function capitalize(s) |
| 46 if not s then return end | |
| 46 return (s:gsub("^%a", string.upper):gsub("_", " ")); | 47 return (s:gsub("^%a", string.upper):gsub("_", " ")); |
| 47 end | 48 end |
| 48 | 49 |
| 49 local commands = module:shared("commands") | 50 local commands = module:shared("commands") |
| 50 local def_env = module:shared("env"); | 51 local def_env = module:shared("env"); |
| 650 host = { | 651 host = { |
| 651 title = "Host"; | 652 title = "Host"; |
| 652 key = "host"; | 653 key = "host"; |
| 653 width = 22; | 654 width = 22; |
| 654 mapper = function(host, session) | 655 mapper = function(host, session) |
| 655 if host ~= "" then return host; end | 656 return host or get_s2s_hosts(session) or "?"; |
| 656 return get_s2s_hosts(session) or "?"; | |
| 657 end; | 657 end; |
| 658 }; | 658 }; |
| 659 remote = { | 659 remote = { |
| 660 title = "Remote"; | 660 title = "Remote"; |
| 661 width = 22; | 661 width = 22; |
| 669 key = "direction"; | 669 key = "direction"; |
| 670 mapper = function(dir, session) | 670 mapper = function(dir, session) |
| 671 if session.incoming and session.outgoing then return "<->"; end | 671 if session.incoming and session.outgoing then return "<->"; end |
| 672 if dir == "outgoing" then return "-->"; end | 672 if dir == "outgoing" then return "-->"; end |
| 673 if dir == "incoming" then return "<--"; end | 673 if dir == "incoming" then return "<--"; end |
| 674 return "" | |
| 675 end; | 674 end; |
| 676 }; | 675 }; |
| 677 id = { title = "Session ID"; width = 20; key = "id" }; | 676 id = { title = "Session ID"; width = 20; key = "id" }; |
| 678 type = { title = "Type"; width = #"c2s_unauthed"; key = "type" }; | 677 type = { title = "Type"; width = #"c2s_unauthed"; key = "type" }; |
| 679 method = { | 678 method = { |
| 691 }; | 690 }; |
| 692 ipv = { | 691 ipv = { |
| 693 title = "IPv"; | 692 title = "IPv"; |
| 694 width = 4; | 693 width = 4; |
| 695 key = "ip"; | 694 key = "ip"; |
| 696 mapper = function(ip) return ip:find(":") and "IPv6" or "IPv4"; end; | 695 mapper = function(ip) if ip then return ip:find(":") and "IPv6" or "IPv4"; end end; |
| 697 }; | 696 }; |
| 698 ip = { title = "IP address"; width = 40; key = "ip" }; | 697 ip = { title = "IP address"; width = 40; key = "ip" }; |
| 699 status = { | 698 status = { |
| 700 title = "Status"; | 699 title = "Status"; |
| 701 width = 11; | 700 width = 11; |
| 702 key = "presence"; | 701 key = "presence"; |
| 703 mapper = function(p) | 702 mapper = function(p) |
| 704 if not p or p == "" then return "unavailable"; end | 703 if not p then return "unavailable"; end |
| 705 return p:get_child_text("show") or "available"; | 704 return p:get_child_text("show") or "available"; |
| 706 end; | 705 end; |
| 707 }; | 706 }; |
| 708 secure = { | 707 secure = { |
| 709 title = "Security"; | 708 title = "Security"; |
| 710 key = "conn"; | 709 key = "conn"; |
| 711 width = 11; | 710 width = 11; |
| 712 mapper = function(conn, session) | 711 mapper = function(conn, session) |
| 713 if not session.secure then return "insecure"; end | 712 if not session.secure then return "insecure"; end |
| 714 if conn == "" or not conn:ssl() then return "secure" end | 713 if not conn:ssl() then return "secure" end |
| 715 local sock = conn ~= "" and conn:socket(); | 714 local sock = conn and conn:socket(); |
| 716 if not sock then return "unknown TLS"; end | 715 if not sock then return "unknown TLS"; end |
| 717 local tls_info = sock.info and sock:info(); | 716 local tls_info = sock.info and sock:info(); |
| 718 return tls_info and tls_info.protocol or "unknown TLS"; | 717 return tls_info and tls_info.protocol or "unknown TLS"; |
| 719 end; | 718 end; |
| 720 }; | 719 }; |
| 721 encryption = { | 720 encryption = { |
| 722 title = "Encryption"; | 721 title = "Encryption"; |
| 723 width = 30; | 722 width = 30; |
| 724 key = "conn"; | 723 key = "conn"; |
| 725 mapper = function(conn) | 724 mapper = function(conn) |
| 726 local sock = conn ~= "" and conn:socket(); | 725 local sock = conn:socket(); |
| 727 local info = sock and sock.info and sock:info(); | 726 local info = sock and sock.info and sock:info(); |
| 728 if info then return info.cipher end | 727 if info then return info.cipher end |
| 729 return "" | |
| 730 end; | 728 end; |
| 731 }; | 729 }; |
| 732 cert = { | 730 cert = { |
| 733 title = "Certificate"; | 731 title = "Certificate"; |
| 734 key = "cert_identity_status"; | 732 key = "cert_identity_status"; |
| 735 width = 13; | 733 width = 13; |
| 736 mapper = function(cert_status, session) | 734 mapper = function(cert_status, session) |
| 737 if cert_status ~= "" then return capitalize(cert_status); end | 735 if cert_status then return capitalize(cert_status); end |
| 738 if session.cert_chain_status == "Invalid" then | 736 if session.cert_chain_status == "Invalid" then |
| 739 local cert_errors = set.new(session.cert_chain_errors[1]); | 737 local cert_errors = set.new(session.cert_chain_errors[1]); |
| 740 if cert_errors:contains("certificate has expired") then | 738 if cert_errors:contains("certificate has expired") then |
| 741 return "Expired"; | 739 return "Expired"; |
| 742 elseif cert_errors:contains("self signed certificate") then | 740 elseif cert_errors:contains("self signed certificate") then |
| 751 }; | 749 }; |
| 752 sni = { | 750 sni = { |
| 753 title = "SNI"; | 751 title = "SNI"; |
| 754 width = 22; | 752 width = 22; |
| 755 mapper = function(_, session) | 753 mapper = function(_, session) |
| 756 if not session.conn then return "" end | 754 if not session.conn then return end |
| 757 local sock = session.conn:socket(); | 755 local sock = session.conn:socket(); |
| 758 return sock and sock.getsniname and sock:getsniname() or ""; | 756 return sock and sock.getsniname and sock:getsniname() or ""; |
| 759 end; | 757 end; |
| 760 }; | 758 }; |
| 761 alpn = { | 759 alpn = { |
| 762 title = "ALPN"; | 760 title = "ALPN"; |
| 763 width = 11; | 761 width = 11; |
| 764 mapper = function(_, session) | 762 mapper = function(_, session) |
| 765 if not session.conn then return "" end | 763 if not session.conn then return end |
| 766 local sock = session.conn:socket(); | 764 local sock = session.conn:socket(); |
| 767 return sock and sock.getalpn and sock:getalpn() or ""; | 765 return sock and sock.getalpn and sock:getalpn() or ""; |
| 768 end; | 766 end; |
| 769 }; | 767 }; |
| 770 smacks = { | 768 smacks = { |
| 771 title = "SM"; | 769 title = "SM"; |
| 772 key = "smacks"; | 770 key = "smacks"; |
| 773 width = 11; | 771 width = 11; |
| 774 mapper = function(smacks_xmlns, session) | 772 mapper = function(smacks_xmlns, session) |
| 775 if smacks_xmlns == "" then return "no"; end | 773 if not smacks_xmlns then return "no"; end |
| 776 if session.hibernating then return "hibernating"; end | 774 if session.hibernating then return "hibernating"; end |
| 777 return "yes"; | 775 return "yes"; |
| 778 end; | 776 end; |
| 779 }; | 777 }; |
| 780 smacks_queue = { | 778 smacks_queue = { |
| 781 title = "SM Queue"; | 779 title = "SM Queue"; |
| 782 key = "outgoing_stanza_queue"; | 780 key = "outgoing_stanza_queue"; |
| 783 width = 8; | 781 width = 8; |
| 784 align = "right"; | 782 align = "right"; |
| 785 mapper = function (queue) | 783 mapper = function (queue) |
| 786 return tostring(#queue); | 784 return queue and tostring(#queue); |
| 787 end | 785 end |
| 788 }; | 786 }; |
| 789 csi = { | 787 csi = { |
| 790 title = "CSI State"; | 788 title = "CSI State"; |
| 791 key = "state"; | 789 key = "state"; |
| 800 dialback = { | 798 dialback = { |
| 801 title = "Dialback"; | 799 title = "Dialback"; |
| 802 key = "dialback_key"; | 800 key = "dialback_key"; |
| 803 width = 13; | 801 width = 13; |
| 804 mapper = function (dialback_key, session) | 802 mapper = function (dialback_key, session) |
| 805 if dialback_key == "" then | 803 if not dialback_key then |
| 806 if session.type == "s2sin" or session.type == "s2sout" then | 804 if session.type == "s2sin" or session.type == "s2sout" then |
| 807 return "Not used"; | 805 return "Not used"; |
| 808 end | 806 end |
| 809 return "Not initiated"; | 807 return "Not initiated"; |
| 810 elseif session.type == "s2sin_unauthed" or session.type == "s2sout_unauthed" then | 808 elseif session.type == "s2sin_unauthed" or session.type == "s2sout_unauthed" then |