mirror of
https://github.com/internetee/registry.git
synced 2025-05-29 17:10:08 +02:00
Basic whois data scp
This commit is contained in:
parent
65d2be7c46
commit
960e6e42d7
4 changed files with 96 additions and 18 deletions
4
Gemfile
4
Gemfile
|
@ -70,6 +70,10 @@ gem 'therubyracer', platforms: :ruby
|
||||||
# for settings
|
# for settings
|
||||||
gem 'rails-settings-cached', '0.4.1'
|
gem 'rails-settings-cached', '0.4.1'
|
||||||
|
|
||||||
|
# for scp to whois server
|
||||||
|
gem 'net-ssh'
|
||||||
|
gem 'net-scp'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'capybara', '~> 2.4.1'
|
gem 'capybara', '~> 2.4.1'
|
||||||
# For feature testing
|
# For feature testing
|
||||||
|
|
|
@ -168,6 +168,9 @@ GEM
|
||||||
mini_portile (0.6.0)
|
mini_portile (0.6.0)
|
||||||
minitest (5.4.2)
|
minitest (5.4.2)
|
||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
|
net-scp (1.2.1)
|
||||||
|
net-ssh (>= 2.6.5)
|
||||||
|
net-ssh (2.9.1)
|
||||||
nokogiri (1.6.2.1)
|
nokogiri (1.6.2.1)
|
||||||
mini_portile (= 0.6.0)
|
mini_portile (= 0.6.0)
|
||||||
nprogress-rails (0.1.3.1)
|
nprogress-rails (0.1.3.1)
|
||||||
|
@ -378,6 +381,8 @@ DEPENDENCIES
|
||||||
jbuilder (~> 2.0)
|
jbuilder (~> 2.0)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
kaminari (~> 0.16.1)
|
kaminari (~> 0.16.1)
|
||||||
|
net-scp
|
||||||
|
net-ssh
|
||||||
nokogiri (~> 1.6.2.1)
|
nokogiri (~> 1.6.2.1)
|
||||||
nprogress-rails (~> 0.1.3.1)
|
nprogress-rails (~> 0.1.3.1)
|
||||||
paper_trail (~> 3.0.5)
|
paper_trail (~> 3.0.5)
|
||||||
|
|
|
@ -77,3 +77,8 @@ Setting.ns_min_count = 2
|
||||||
Setting.ns_max_count = 11
|
Setting.ns_max_count = 11
|
||||||
|
|
||||||
Setting.transfer_wait_time = 0
|
Setting.transfer_wait_time = 0
|
||||||
|
|
||||||
|
Setting['whois.host'] = '54.171.175.81'
|
||||||
|
Setting['whois.username']= 'whois_app'
|
||||||
|
Setting['whois.port'] = '20'
|
||||||
|
Setting['whois.remote_path'] = 'whois/shared/data/'
|
||||||
|
|
|
@ -1,28 +1,92 @@
|
||||||
|
require 'net/ssh'
|
||||||
|
require 'net/scp'
|
||||||
|
|
||||||
desc 'Commands for whois'
|
desc 'Commands for whois'
|
||||||
|
|
||||||
desc 'generate whois files'
|
desc 'generate whois file(s)'
|
||||||
task 'whois:generate' => :environment do
|
task 'whois:generate' => :environment do
|
||||||
Dir.mkdir('./tmp/whois') unless File.exist?('./tmp/whois') # a folder for ze stuff
|
Dir.mkdir('./tmp/whois') unless File.exist?('./tmp/whois') # a folder for ze stuff
|
||||||
|
letter = ENV['letter']
|
||||||
|
@path = "tmp/whois/"
|
||||||
|
letter.nil? ? generate_whois : whois_data(letter)
|
||||||
|
end
|
||||||
|
|
||||||
alphabet = (('a'..'z').to_a << %w(ö õ ü ä)).flatten!
|
# TODO refactor
|
||||||
@domains = {}
|
desc 'Generate and copy one file'
|
||||||
alphabet.each do |letter|
|
task 'whois:handle_domain' => :environment do
|
||||||
domains = Domain.where(['name LIKE ?', "#{letter}%"])
|
letter = ENV['letter']
|
||||||
@domains[letter] = {}
|
@path = "tmp/whois/"
|
||||||
|
whois_data(letter)
|
||||||
|
copy_files(["tmp/whois/#{letter}_domain.yaml"])
|
||||||
|
end
|
||||||
|
|
||||||
domains.each do |domain|
|
desc 'copy whois files'
|
||||||
@domains[letter][domain.name] = {
|
task 'whois:scp' => :environment do
|
||||||
valid_to: domain.valid_to,
|
letter = ENV['letter']
|
||||||
status: domain.status,
|
files = letter.nil? ? Dir['tmp/whois/*_domain.yaml'] : ["tmp/whois/#{letter}_domain.yaml"]
|
||||||
contacts: [
|
|
||||||
{ name: domain.owner_contact.name, email: domain.owner_contact.email },
|
unless files.present?
|
||||||
{ registrar: domain.registrar.name, address: domain.registrar.address }
|
Rails.logger.warn("tmp/whois/ is empty, no files copied at #{Time.now}")
|
||||||
]
|
return
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@domains.each do |k, v|
|
copy_files(files)
|
||||||
File.open("tmp/whois/#{k}_domain.yaml", 'w') { |f| f.write(v.to_yaml) }
|
end
|
||||||
|
|
||||||
|
# Generates whois data for all domains
|
||||||
|
def generate_whois
|
||||||
|
alphabet = (('a'..'z').to_a << %w(ö õ ü ä)).flatten!
|
||||||
|
alphabet.each do |letter|
|
||||||
|
whois_data(letter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generates whois data for a domains starting with 'letter'
|
||||||
|
def whois_data(letter)
|
||||||
|
data = {}
|
||||||
|
domains = Domain.where(['name LIKE ?', "#{letter}%"])
|
||||||
|
domains.each do |domain|
|
||||||
|
data[domain.name] = {
|
||||||
|
valid_to: domain.valid_to,
|
||||||
|
status: domain.status,
|
||||||
|
contacts: [
|
||||||
|
{ name: domain.owner_contact.name, email: domain.owner_contact.email },
|
||||||
|
{ registrar: domain.registrar.name, address: domain.registrar.address }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
File.open(@path + "#{letter}_domain.yaml", 'w') { |f| f.write(data.to_yaml) }
|
||||||
|
end
|
||||||
|
|
||||||
|
# copies files from paths passed in ( files = [ path_to_file, path_to_another_file ] )
|
||||||
|
def copy_files(files)
|
||||||
|
connection_info
|
||||||
|
generate_sum
|
||||||
|
|
||||||
|
Net::SSH.start(@host, @username, port: @port) do |session|
|
||||||
|
session.scp.upload!('tmp/whois/checklist.chk', @remote_path)
|
||||||
|
files.each do |file|
|
||||||
|
session.scp.upload!(file, @remote_path ) do |ch, name, sent, total|
|
||||||
|
puts "#{name}: #{sent}/#{total}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_sum
|
||||||
|
result = `( cd tmp/whois/; md5sum *.yaml > checklist.chk )`
|
||||||
|
Rails.logger.info(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Describes the connection info for scp, ssh keys have to in order (passwordless login) for this to work
|
||||||
|
def connection_info
|
||||||
|
@host = '95.215.45.231'
|
||||||
|
@username = 'whois_app'
|
||||||
|
@port = 65520
|
||||||
|
@remote_path = 'whois/shared/data/'
|
||||||
|
# @host ||= Setting['whois.host']
|
||||||
|
# @username ||= Setting['whois.username']
|
||||||
|
# @port ||= Setting['whois.port']
|
||||||
|
# @remote_path ||= Setting['whois.remote_path']
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue