Created
January 4, 2013 09:59
-
-
Save ebisawa/4451357 to your computer and use it in GitHub Desktop.
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 | |
# -*- coding: utf-8 -*- | |
require 'optparse' | |
require 'pp' | |
require 'yaml' | |
$options = {} | |
opt = OptionParser.new | |
opt.on('--list-ssl-cert') {|v| $options[:list_ssl_cert] = v } | |
opt.parse!(ARGV) | |
def make_domain_data(buf) | |
result = {} | |
a = buf.split(%r{<tr height="20">}).map {|a| a.gsub(/^\s*/, '') } | |
a.each do |b| | |
data = {} | |
data[:expire] = '' | |
b.split("\n").each do |l| | |
if l =~ %r{<td align=right bgcolor="#[0-9a-fA-F]+" style="background-color: #[0-9a-fA-F]+">(\d+)</td>} | |
data[:number] = $1.to_i | |
end | |
if l =~ %r{<td bgcolor="#[0-9a-fA-F]+" style="background-color: #[0-9a-fA-F]+" width="100"><b> (.+)</b></td>} | |
data[:domain] = $1 | |
end | |
if l =~ %r{<td bgcolor="#[0-9a-fA-F]+" style="background-color: #[0-9a-fA-F]+" align="center">(20\d+)[^\d]+(\d+)[^\d]+(\d+)[^\d]+</td>} | |
data[:expire] = "#{$1}-#{$2}-#{$3}" | |
end | |
end | |
if (dom = data[:domain]) != nil | |
result[dom] = data | |
end | |
end | |
result | |
end | |
def make_ssl_data(buf) | |
result = {} | |
a = buf.split(%r{<td class="sub_th">}).map {|a| a.gsub(/^\s*/, '') } | |
a.each do |b| | |
data = {} | |
if b =~ %r{^(RAPID.+)</td>.*<td>(.+)</td>.*<td>.*</td>.*<td>.*</td>.*<td>.*</td>.*<td>(\d+-\d+-\d+)</td>}m | |
data[:id] = $1 | |
data[:domain] = $2 | |
data[:expire] = $3 | |
end | |
if (dom = data[:domain]) != nil | |
result[dom] = data | |
end | |
end | |
result | |
end | |
def dom_merge_ssl(domain, ssl) | |
domain.keys.each do |k| | |
if ssl[k] != nil | |
domain[k][:ssl_id] = ssl[k][:id] | |
domain[k][:ssl_expire] = ssl[k][:expire] | |
else | |
domain[k][:ssl_id] = '' | |
domain[k][:ssl_expire] = '' | |
end | |
end | |
domain | |
end | |
def dom_resolv_addr(domain) | |
domain.keys.each do |dom| | |
domain[dom][:gaddr] = `dig +short #{dom} @8.8.8.8`.chomp | |
domain[dom][:paddr] = `dig +short #{dom}`.chomp | |
end | |
domain | |
end | |
def print_domain_list(dom) | |
dom.values.sort_by {|x| x[:number] }.each do |d| | |
puts "| #{d[:number]} | #{d[:domain]} | #{d[:gaddr]} | #{d[:paddr]} | #{d[:expire]} " + | |
"| #{d[:ssl_id]} | #{d[:ssl_expire]} |" | |
end | |
end | |
def print_ssl_list(ssl, dom) | |
ssl.values.sort_by {|x| x[:id] }.each do |s| | |
d = s[:domain] | |
if dom[d] != nil | |
puts "| #{s[:id]} | #{d} | #{s[:expire]} | #{dom[d][:expire]} |" | |
else | |
puts "| #{s[:id]} | #{d} | #{s[:expire]} | |" | |
end | |
end | |
end | |
file1 = ARGV.shift | |
file2 = ARGV.shift | |
if file1 == nil || file2 == nil | |
puts "usage: check_doamin_ssl.rb [options] [sakura_domain_list.html] [sslbox_cert_list.html]" | |
puts "optitions: --list-ssl-cert" | |
abort | |
end | |
domain = [] | |
ssl = [] | |
open(file1) do |io| | |
domain = make_domain_data(io.readlines.join) | |
end | |
open(file2) do |io| | |
ssl = make_ssl_data(io.readlines.join) | |
end | |
domain = dom_merge_ssl(domain, ssl) | |
domain = dom_resolv_addr(domain) | |
if $options[:list_ssl_cert] | |
print_ssl_list(ssl, domain) | |
else | |
print_domain_list(domain) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment