From bb2afd3394a36b13fa484311702a6260d729bbed Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 4 Jun 2022 01:16:42 +0200 Subject: [PATCH] jabber: update prosody-stats.rb to newer prosody version --- hosts/containers/jabber/prosody-stats.rb | 53 ++++++++++++++---------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/hosts/containers/jabber/prosody-stats.rb b/hosts/containers/jabber/prosody-stats.rb index c6fd59b0..15e7e715 100644 --- a/hosts/containers/jabber/prosody-stats.rb +++ b/hosts/containers/jabber/prosody-stats.rb @@ -19,37 +19,48 @@ def recv sock results end +=begin +def parse_table lines + fields = lines.shift.split(/\|/).collect { |s| s.strip } + p :fields => fields + lines.collect { |s| + data = s.split(/\|/).collect { |s| s.strip } + obj = {} + fields.each_with_index do |field,i| + obj[field] = data[i] + end + obj + } +end +=end + sock = TCPSocket.new "localhost", 5582 loop do stats = {} sock.puts "c2s:show()" recv(sock).each do |line| - if line.start_with? "| " - encrypted = line.index " (encrypted)" - ipv6 = line.index " (IPv6)" - k = "c2s:#{encrypted ? 'encrypted' : 'unencrypted'}-#{ipv6 ? 'ipv6' : 'ipv4'}" - stats[k] = 0 unless stats[k] - stats[k] += 1 - end + encrypted = line.index(" secure ") or line.index(" TLSv") + ipv6 = line.index " IPv6 " + k = "c2s:#{encrypted ? 'encrypted' : 'unencrypted'}-#{ipv6 ? 'ipv6' : 'ipv4'}" + stats[k] = 0 unless stats[k] + stats[k] += 1 end sock.puts "s2s:show()" recv(sock).each do |line| - if line.start_with? "| " - out = if line.index "<-" - false - elsif line.index "->" - true - else - next - end - encrypted = line.index " (encrypted)" - ipv6 = line.index " (IPv6)" - k = "s2s-#{out ? 'out' : 'in'}:#{encrypted ? 'encrypted' : 'unencrypted'}-#{ipv6 ? 'ipv6' : 'ipv4'}" - stats[k] = 0 unless stats[k] - stats[k] += 1 - end + out = if line.index "<-" + false + elsif line.index "->" + true + else + next + end + encrypted = line.index " TLSv" + ipv6 = line.index " IPv6 " + k = "s2s-#{out ? 'out' : 'in'}:#{encrypted ? 'encrypted' : 'unencrypted'}-#{ipv6 ? 'ipv6' : 'ipv4'}" + stats[k] = 0 unless stats[k] + stats[k] += 1 end stats.each do |k,v|