Created
August 11, 2013 16:29
-
-
Save bsdmad/6205574 to your computer and use it in GitHub Desktop.
3009/tcp に接続して quarantine-search を投げ、その結果を切り貼りするスクリプト。
notify.reml というテンプレートファイルを使って、mail[:to] 毎に HTML ファイルを出力する。
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/ruby -Ku | |
require 'net/telnet' | |
require 'nkf' | |
require 'date' | |
require 'time' | |
require 'tempfile' | |
require 'erb' | |
mails = {} | |
file = Tempfile.new('drweb-quarantine-list') | |
begin | |
drweb = Net::Telnet.new('Host' => '127.0.0.1', 'Port' => 3009, 'Output_log' => file.path) | |
drweb.cmd('quarantine-search') | |
drweb.close | |
File.open(file.path, 'r') do |io| | |
count = 0 | |
mail = {} | |
while line = io.gets | |
count += 1 | |
next unless count > 4 | |
line.chomp!.gsub!(/^> /, '') | |
break if line =~ /^$/ | |
if line =~ /^[0-9]{1,}\. [^ ]+ <([^>]+)> <([^>]+)>/ | |
values = line.split[2..-1] | |
mail = { | |
:from => values[0].gsub(/[<>]/, ''), | |
:to => values[1..-1].map {|v| v.gsub(/[<>]/, '')} | |
} | |
elsif line =~ / ([0-9]{1,}) ([^ ]+) (-?[0-9]{1,}) (.*)$/ | |
mail.update({ | |
:size => $1, | |
:date => DateTime.parse($2), | |
:score => $3, | |
:subject => $4 | |
}) | |
mail[:to].each do |to| | |
if mails[to].nil? | |
mails[to] = [] | |
end | |
mails[to] << mail | |
end | |
end | |
end | |
end | |
template = File.read('notify.reml') | |
mails.keys.each do |to| | |
values = mails[to].sort do |a, b| | |
b[:date] <=> a[:date] | |
end | |
File.open("#{to}.html", 'w') do |io| | |
io.puts ERB.new(template).result(binding) | |
end | |
end | |
ensure | |
file.close | |
file.unlink | |
end | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment