Created
October 2, 2009 18:30
-
-
Save FiXato/199973 to your computer and use it in GitHub Desktop.
Gets list of hosts and other details from the Anope services logs based on successful nickserv registrations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# get_details_by_nick_registrations.rb | |
# Gets a list of hosts and other details from Anope services logs based on successful nickserv registrations. | |
require 'set' | |
require 'yaml' | |
SERVICES_LOGS_PATH = File.expand_path("~/services/data/logs/services.log*") | |
nicks = ARGV | |
if nicks.size == 0 | |
puts('Get a list of hosts and other details from the Anope services logs based on successful nickserv registrations.') | |
abort('Usage: get_details_by_registered_nicks nick [nick-2] [..] [nick-n]') | |
end | |
used_usermasks = Hash.new {|h,k| h[k] = Array.new} | |
used_hosts_by_nickservnick = Hash.new {|h,k| h[k] = Set.new} | |
grep_strings = {} | |
nicks.each do |nick| | |
grep_string = "grep -i \"'#{nick}' registered by\" #{SERVICES_LOGS_PATH}" | |
identified_lines_for_nick = `#{grep_string}`.squeeze(' ').strip.split("\n") | |
identified_lines_for_nick.each do |line| | |
line.slice!(0..line.index('[')) | |
date = line.slice!(0..line.index(']')).gsub('[','').gsub(']','') | |
cols = line.strip.split(' ') | |
origin = cols[0] | |
nickserv_nick = cols[1].gsub("'",'') | |
usermask = cols[4] | |
ident = usermask.split('@')[0] | |
host = usermask.split('@')[1] | |
email = cols[-1].strip.chop | |
used_usermasks[nickserv_nick] << {:date => date, :nick => nickserv_nick, :usermask => usermask, :ident => ident, :host => host, :email => email} | |
used_hosts_by_nickservnick[nickserv_nick] << host | |
grep_strings[nickserv_nick] = grep_string | |
end | |
end | |
puts "A list of nickserv nicks and their hosts:" | |
used_hosts_by_nickservnick.each do |nick,hosts| | |
puts "#{nick}:" | |
puts hosts.to_a.sort.map{|a|' %s' % a}.join("\n") | |
puts | |
end | |
puts '-'*80 | |
puts "A list of nickserv nicks and their details:" | |
used_usermasks.each do |nick,details| | |
puts "#{nick} (`#{grep_strings[nick]}`):" | |
puts details.sort_by{|h|h[:host]}.to_yaml | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment