dldinternet-opensrs 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +223 -0
- data/bin/opensrs +41 -0
- data/dldinternet-opensrs.gemspec +34 -0
- data/lib/dldinternet/opensrs/api/base.rb +41 -0
- data/lib/dldinternet/opensrs/api/domain/get.rb +25 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/get/all_info.rb +35 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/get/domaindns.rb +34 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/get/domainstatus.rb +33 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/get/getdomain.rb +68 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/modify/domainassign_ns.rb +32 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/modify/domainlockstate.rb +34 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/zone/getdnszone.rb +34 -0
- data/lib/dldinternet/opensrs/api/domain/mixins/zone/setdnszone.rb +35 -0
- data/lib/dldinternet/opensrs/api/domain/modify.rb +19 -0
- data/lib/dldinternet/opensrs/api/domain/zone.rb +19 -0
- data/lib/dldinternet/opensrs/api/domain.rb +3 -0
- data/lib/dldinternet/opensrs/api/mixins/cookie.rb +46 -0
- data/lib/dldinternet/opensrs/api/nameservers/get.rb +16 -0
- data/lib/dldinternet/opensrs/api/nameservers/mixins/get/getnameservers.rb +61 -0
- data/lib/dldinternet/opensrs/api/nameservers.rb +1 -0
- data/lib/dldinternet/opensrs/domain/command.rb +27 -0
- data/lib/dldinternet/opensrs/domain/get/command.rb +85 -0
- data/lib/dldinternet/opensrs/domain/get/mixins/no_commands.rb +16 -0
- data/lib/dldinternet/opensrs/domain/mixins/no_commands.rb +12 -0
- data/lib/dldinternet/opensrs/domain/modify/command.rb +40 -0
- data/lib/dldinternet/opensrs/domain/modify/mixins/no_commands.rb +16 -0
- data/lib/dldinternet/opensrs/domain/zone/command.rb +188 -0
- data/lib/dldinternet/opensrs/domain/zone/mixins/no_commands.rb +28 -0
- data/lib/dldinternet/opensrs/main.rb +26 -0
- data/lib/dldinternet/opensrs/mixins/no_commands.rb +10 -0
- data/lib/dldinternet/opensrs/nameservers/command.rb +37 -0
- data/lib/dldinternet/opensrs/nameservers/mixins/no_commands.rb +12 -0
- data/lib/dldinternet/opensrs/version.rb +6 -0
- data/lib/dldinternet/opensrs.rb +2 -0
- metadata +253 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'hashie/mash'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module API
|
|
6
|
+
module Domain
|
|
7
|
+
module MixIns
|
|
8
|
+
module Zone
|
|
9
|
+
module SetDNSZone
|
|
10
|
+
|
|
11
|
+
# noinspection RubyUnnecessaryReturnValue
|
|
12
|
+
def SetDomainDNSZone(domain,records,cookiep=nil,registrant_ip=nil)
|
|
13
|
+
|
|
14
|
+
data = {
|
|
15
|
+
object: 'DOMAIN',
|
|
16
|
+
action: 'set_dns_zone',
|
|
17
|
+
attributes: {
|
|
18
|
+
domain: domain,
|
|
19
|
+
records: records,
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
data[:cookie] = cookiep if cookiep
|
|
23
|
+
data[:domain] = domain
|
|
24
|
+
data[:registrant_ip] = registrant_ip if registrant_ip
|
|
25
|
+
|
|
26
|
+
getResponse(data)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/api/base'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module API
|
|
6
|
+
module Domain
|
|
7
|
+
class Modify < DLDInternet::OpenSRS::API::Base
|
|
8
|
+
|
|
9
|
+
require 'dldinternet/opensrs/api/domain/mixins/modify/domainlockstate'
|
|
10
|
+
include DLDInternet::OpenSRS::API::Domain::MixIns::Modify::DomainLockState
|
|
11
|
+
|
|
12
|
+
require 'dldinternet/opensrs/api/domain/mixins/modify/domainassign_ns'
|
|
13
|
+
include DLDInternet::OpenSRS::API::Domain::MixIns::Modify::DomainAssignNS
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/api/base'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module API
|
|
6
|
+
module Domain
|
|
7
|
+
class Zone < DLDInternet::OpenSRS::API::Base
|
|
8
|
+
|
|
9
|
+
require 'dldinternet/opensrs/api/domain/mixins/zone/getdnszone'
|
|
10
|
+
include DLDInternet::OpenSRS::API::Domain::MixIns::Zone::GetDNSZone
|
|
11
|
+
|
|
12
|
+
require 'dldinternet/opensrs/api/domain/mixins/zone/setdnszone'
|
|
13
|
+
include DLDInternet::OpenSRS::API::Domain::MixIns::Zone::SetDNSZone
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'hashie/mash'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module API
|
|
6
|
+
module MixIns
|
|
7
|
+
module Cookie
|
|
8
|
+
|
|
9
|
+
def cookie(domain='delionsden.com')
|
|
10
|
+
domain ||= 'dldinternet.com'
|
|
11
|
+
@cookie ||= (
|
|
12
|
+
response = server.call(
|
|
13
|
+
action: 'SET',
|
|
14
|
+
object: 'COOKIE',
|
|
15
|
+
attributes: {
|
|
16
|
+
domain: domain,
|
|
17
|
+
reg_username: options[:username],
|
|
18
|
+
reg_password: options[:password],
|
|
19
|
+
},
|
|
20
|
+
)
|
|
21
|
+
hash = Hashie::Mash.new(response.response)
|
|
22
|
+
@logger.debug.ai
|
|
23
|
+
unless hash['is_success'].to_i == 1
|
|
24
|
+
@logger.fatal StandardError.new(hash['response_text'])
|
|
25
|
+
exit 1
|
|
26
|
+
end
|
|
27
|
+
hash['attributes']['cookie'] rescue nil)
|
|
28
|
+
rescue ::OpenSRS::BadResponse => e
|
|
29
|
+
@logger.error e.message
|
|
30
|
+
exit 1
|
|
31
|
+
rescue ::Net::HTTPServerException => e
|
|
32
|
+
@logger.error "#{e.message}: #{(e.response && e.response[:body]) ? e.response.body : ''}"
|
|
33
|
+
exit 1
|
|
34
|
+
rescue SystemExit => e
|
|
35
|
+
exit e.status
|
|
36
|
+
rescue StandardError => e
|
|
37
|
+
raise e
|
|
38
|
+
rescue Exception => e
|
|
39
|
+
@logger.error "Unknown exception: #{e}"
|
|
40
|
+
raise e
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/api/base'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module API
|
|
6
|
+
module NameServers
|
|
7
|
+
class Get < DLDInternet::OpenSRS::API::Base
|
|
8
|
+
|
|
9
|
+
require 'dldinternet/opensrs/api/nameservers/mixins/get/getnameservers'
|
|
10
|
+
include DLDInternet::OpenSRS::API::NameServers::MixIns::Get::GetNameServers
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'hashie/mash'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module API
|
|
6
|
+
module NameServers
|
|
7
|
+
module MixIns
|
|
8
|
+
module Get
|
|
9
|
+
module GetNameServers
|
|
10
|
+
|
|
11
|
+
# noinspection RubyUnnecessaryReturnValue
|
|
12
|
+
def GetNameServers(domain=nil,cookiep=nil, attr='nameserver_list')
|
|
13
|
+
|
|
14
|
+
list = []
|
|
15
|
+
limit = 25
|
|
16
|
+
pn = 0
|
|
17
|
+
pgnos = nil
|
|
18
|
+
page = getnameserverspage(domain, cookiep || cookie(domain), nil, nil, limit)
|
|
19
|
+
while page && page.is_a?(Hash)
|
|
20
|
+
list += page[attr]
|
|
21
|
+
pgnos ||= page['count'].to_i/limit
|
|
22
|
+
if page['remainder'].eql?('1') && pn < pgnos
|
|
23
|
+
pn += 1
|
|
24
|
+
page = getdomainpage(domain, cookiep || cookie, nil, pn, limit)
|
|
25
|
+
else
|
|
26
|
+
page = nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
list
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
# noinspection RubyUnnecessaryReturnValue
|
|
35
|
+
def getnameserverspage(domain=nil,cookiep=nil,registrant_ip=nil, page=nil, limit=nil)
|
|
36
|
+
|
|
37
|
+
data = {
|
|
38
|
+
object: 'nameserver',
|
|
39
|
+
action: 'get',
|
|
40
|
+
cookie: (cookiep || cookie(domain)),
|
|
41
|
+
attributes: {
|
|
42
|
+
name: 'all',
|
|
43
|
+
domain: domain,
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
data[:cookie] = cookiep if cookiep
|
|
47
|
+
data[:domain] = domain if domain && !cookiep
|
|
48
|
+
data[:registrant_ip] = registrant_ip if registrant_ip
|
|
49
|
+
data[:attributes][:limit] = limit if limit
|
|
50
|
+
data[:attributes][:page] = page if page
|
|
51
|
+
|
|
52
|
+
getResponse(data)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/api/nameservers/get'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/domain/get/command'
|
|
2
|
+
require 'dldinternet/opensrs/domain/modify/command'
|
|
3
|
+
require 'dldinternet/opensrs/domain/zone/command'
|
|
4
|
+
|
|
5
|
+
module DLDInternet
|
|
6
|
+
module OpenSRS
|
|
7
|
+
module Domain
|
|
8
|
+
class Command < DLDInternet::Thor::Command
|
|
9
|
+
no_commands do
|
|
10
|
+
|
|
11
|
+
require 'dldinternet/opensrs/domain/mixins/no_commands'
|
|
12
|
+
include DLDInternet::OpenSRS::Domain::MixIns::NoCommands
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
desc 'get SUBCOMMAND ... ARGS', 'get domain stuff'
|
|
17
|
+
subcommand 'get', ::DLDInternet::OpenSRS::Domain::Get::Command
|
|
18
|
+
|
|
19
|
+
desc 'modify SUBCOMMAND ... ARGS', 'manipulate domains'
|
|
20
|
+
subcommand 'modify', ::DLDInternet::OpenSRS::Domain::Modify::Command
|
|
21
|
+
|
|
22
|
+
desc 'zone SUBCOMMAND ... ARGS', 'manipulate domains'
|
|
23
|
+
subcommand 'zone', ::DLDInternet::OpenSRS::Domain::Zone::Command
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/api/domain'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module Domain
|
|
6
|
+
module Get
|
|
7
|
+
class Command < DLDInternet::Thor::Command
|
|
8
|
+
no_commands do
|
|
9
|
+
|
|
10
|
+
require 'dldinternet/opensrs/domain/get/mixins/no_commands'
|
|
11
|
+
include DLDInternet::OpenSRS::Domain::Get::MixIns::NoCommands
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'all_info', 'all domain info'
|
|
16
|
+
def all_info(domain)
|
|
17
|
+
command_pre(domain)
|
|
18
|
+
|
|
19
|
+
answer = DLDInternet::OpenSRS::API::Domain::Get.new(options, @logger).GetAllInfo(domain)
|
|
20
|
+
case @config[:format].to_s
|
|
21
|
+
when /none|text/
|
|
22
|
+
@config[:format] = :awesome
|
|
23
|
+
end
|
|
24
|
+
command_out answer
|
|
25
|
+
0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc 'list', 'list domains'
|
|
29
|
+
def list()
|
|
30
|
+
command_pre()
|
|
31
|
+
@header = ->{ sprintf("%-48s", 'Domainname') }
|
|
32
|
+
@format = ->(res) { sprintf("%-48s", res ) }
|
|
33
|
+
|
|
34
|
+
answer = DLDInternet::OpenSRS::API::Domain::Get.new(options, @logger).GetDomainList
|
|
35
|
+
command_out answer
|
|
36
|
+
0
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
desc 'nameservers DOMAIN', 'domain dns'
|
|
40
|
+
def nameservers(domain)
|
|
41
|
+
dns(domain)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
desc 'dns DOMAIN', 'domain dns'
|
|
45
|
+
def dns(domain)
|
|
46
|
+
command_pre(domain)
|
|
47
|
+
@header = ->{ sprintf("%-10s\t%-48s", 'Nameserver','Hostname') }
|
|
48
|
+
@format = ->(res) { sprintf("%-10s\t%-48s", res['sortorder'], res['name'] ) }
|
|
49
|
+
|
|
50
|
+
answer = DLDInternet::OpenSRS::API::Domain::Get.new(options, @logger).GetDomainNameservers(domain).sort_by { |ns| ns['sortorder'].to_i }
|
|
51
|
+
case @config[:format].to_s
|
|
52
|
+
when /text|none/
|
|
53
|
+
@header = ->{ sprintf("#{domain}\n%-10s\t%-48s", 'Nameserver','Hostname') }
|
|
54
|
+
# output domain
|
|
55
|
+
# output answer.sort_by { |ns| ns['sortorder'].to_i }.each { |ns| write "nameserver #{ns['sortorder']}: #{ns['name']}" }
|
|
56
|
+
# else
|
|
57
|
+
# output answer
|
|
58
|
+
end
|
|
59
|
+
command_out answer
|
|
60
|
+
0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
desc 'status DOMAIN', 'domain status'
|
|
64
|
+
def status(domain)
|
|
65
|
+
command_pre domain
|
|
66
|
+
@header = ->{ sprintf("%-10s\t%-10s\t%-14s", 'Lock state','Can modify','Domain supports') }
|
|
67
|
+
@format = ->(res) { sprintf("%-10s\t%-10s\t%-14s", res['lock_state'], res['can_modify'], res['domain_supports'] ) }
|
|
68
|
+
|
|
69
|
+
answer = DLDInternet::OpenSRS::API::Domain::Get.new(options, @logger).GetDomainStatus(domain)
|
|
70
|
+
case @config[:format].to_s
|
|
71
|
+
when /text|none/
|
|
72
|
+
@header = ->{ sprintf("#{domain}\n%-10s\t%-10s\t%-14s", 'Lock state','Can modify','Domain supports') }
|
|
73
|
+
# write domain
|
|
74
|
+
# answer.each { |k,v| write "#{k}: #{v}" }
|
|
75
|
+
# else
|
|
76
|
+
# output answer
|
|
77
|
+
end
|
|
78
|
+
command_out answer
|
|
79
|
+
0
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module DLDInternet
|
|
2
|
+
module OpenSRS
|
|
3
|
+
module Domain
|
|
4
|
+
module Get
|
|
5
|
+
module MixIns
|
|
6
|
+
module NoCommands
|
|
7
|
+
|
|
8
|
+
require 'dldinternet/opensrs/domain/mixins/no_commands'
|
|
9
|
+
include DLDInternet::OpenSRS::Domain::MixIns::NoCommands
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/api/domain'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module Domain
|
|
6
|
+
module Modify
|
|
7
|
+
class Command < DLDInternet::Thor::Command
|
|
8
|
+
no_commands do
|
|
9
|
+
|
|
10
|
+
require 'dldinternet/opensrs/domain/modify/mixins/no_commands'
|
|
11
|
+
include DLDInternet::OpenSRS::Domain::Modify::MixIns::NoCommands
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'lock_state', 'modify domain lock_state'
|
|
16
|
+
def lock_state(domain, state)
|
|
17
|
+
parse_options
|
|
18
|
+
@logger.info "domain lock_state for #{domain} = #{state}" if options[:verbose]
|
|
19
|
+
|
|
20
|
+
answer = DLDInternet::OpenSRS::API::Domain::Modify.new(options, @logger).SetDomainLockState(domain, state)
|
|
21
|
+
puts domain
|
|
22
|
+
puts answer.ai
|
|
23
|
+
0
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
desc 'assign_ns', 'modify domain nameservers'
|
|
27
|
+
def assign_ns(domain, nameserverscsv)
|
|
28
|
+
parse_options
|
|
29
|
+
@logger.info "domain assign_ns for #{domain} = #{nameserverscsv}" if options[:verbose]
|
|
30
|
+
|
|
31
|
+
answer = DLDInternet::OpenSRS::API::Domain::Modify.new(options, @logger).AssignDomainNameServers(domain, nameserverscsv)
|
|
32
|
+
puts domain
|
|
33
|
+
puts answer.ai
|
|
34
|
+
0
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module DLDInternet
|
|
2
|
+
module OpenSRS
|
|
3
|
+
module Domain
|
|
4
|
+
module Modify
|
|
5
|
+
module MixIns
|
|
6
|
+
module NoCommands
|
|
7
|
+
|
|
8
|
+
require 'dldinternet/opensrs/domain/mixins/no_commands'
|
|
9
|
+
include DLDInternet::OpenSRS::Domain::MixIns::NoCommands
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
require 'dldinternet/opensrs/api/domain'
|
|
2
|
+
|
|
3
|
+
module DLDInternet
|
|
4
|
+
module OpenSRS
|
|
5
|
+
module Domain
|
|
6
|
+
module Zone
|
|
7
|
+
class Command < DLDInternet::Thor::Command
|
|
8
|
+
no_commands do
|
|
9
|
+
|
|
10
|
+
require 'dldinternet/opensrs/domain/zone/mixins/no_commands'
|
|
11
|
+
include DLDInternet::OpenSRS::Domain::Zone::MixIns::NoCommands
|
|
12
|
+
|
|
13
|
+
def showDNSZoneAnswer(answer,domain)
|
|
14
|
+
if answer['records']
|
|
15
|
+
case @config[:format].to_s
|
|
16
|
+
when /none|text/
|
|
17
|
+
#@config[:format] = :awesome
|
|
18
|
+
output domain if options[:verbose]
|
|
19
|
+
output header_line unless options[:header] === false
|
|
20
|
+
width = 32
|
|
21
|
+
answer['records'].map { |type,list|
|
|
22
|
+
list.map{ |entry|
|
|
23
|
+
case type
|
|
24
|
+
when %r'^A'
|
|
25
|
+
output sprintf("%#{width}s\t%3s\t%3s\t%s", entry['subdomain'], type, '', entry['ip_address'])
|
|
26
|
+
when 'MX'
|
|
27
|
+
output sprintf("%#{width}s\t%3s\t%3s\t%s", entry['subdomain'], type, entry['priority'], entry['hostname'])
|
|
28
|
+
when 'SRV'
|
|
29
|
+
output sprintf("%#{width}s\t%3s\t%3s\t%s\t%s\t%s", entry['subdomain'], type, entry['priority'], entry['weight'], entry['hostname'], entry['port'])
|
|
30
|
+
when 'TXT'
|
|
31
|
+
output sprintf("%#{width}s\t%3s\t%3s\t%s", entry['subdomain'], type, '', entry['text'])
|
|
32
|
+
when 'CNAME'
|
|
33
|
+
output sprintf("%#{width}s\t%3s\t%3s\t%s", entry['subdomain'], type, '', entry['hostname'])
|
|
34
|
+
else
|
|
35
|
+
output "#{type}\t#{entry.to_s}"
|
|
36
|
+
end
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
output answer
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
output answer
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# noinspection RubyStringKeysInHashInspection
|
|
48
|
+
def mapDNSZoneAnswer(answer,domain)
|
|
49
|
+
if answer['records']
|
|
50
|
+
case @config[:format].to_s
|
|
51
|
+
when /none|text|awesome/
|
|
52
|
+
records = []
|
|
53
|
+
answer['records'].each { |type,list|
|
|
54
|
+
list.each { |entry|
|
|
55
|
+
case type
|
|
56
|
+
when %r'^A'
|
|
57
|
+
records << { 'subdomain' => entry['subdomain'], 'type' => type, 'priority' => '', 'data' => entry['ip_address'], 'weight' => '', 'port' => '' }
|
|
58
|
+
when 'MX'
|
|
59
|
+
records << { 'subdomain' => entry['subdomain'], 'type' => type, 'priority' => entry['priority'], 'data' => entry['hostname'], 'weight' => '', 'port' => '' }
|
|
60
|
+
when 'SRV'
|
|
61
|
+
records << { 'subdomain' => entry['subdomain'], 'type' => type, 'priority' => entry['priority'], 'data' => entry['hostname'], 'weight' => entry['weight'], 'port' => entry['port'] }
|
|
62
|
+
when 'TXT'
|
|
63
|
+
records << { 'subdomain' => entry['subdomain'], 'type' => type, 'priority' => '', 'data' => entry['text'], 'weight' => '', 'port' => '' }
|
|
64
|
+
when 'CNAME'
|
|
65
|
+
records << { 'subdomain' => entry['subdomain'], 'type' => type, 'priority' => '', 'data' => entry['hostname'], 'weight' => '', 'port' => '' }
|
|
66
|
+
else
|
|
67
|
+
records << { 'subdomain' => '', 'type' => type, 'priority' => '', 'data' => entry.to_s, 'weight' => '', 'port' => '' }
|
|
68
|
+
end
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
records
|
|
72
|
+
else
|
|
73
|
+
answer['records']
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
desc 'get', 'domain zone info'
|
|
81
|
+
def get(domain)
|
|
82
|
+
command_pre(domain)
|
|
83
|
+
zone_records_format
|
|
84
|
+
answer = DLDInternet::OpenSRS::API::Domain::Zone.new(options, @logger).GetDomainDNSZone(domain)
|
|
85
|
+
# showDNSZoneAnswer(answer, domain)
|
|
86
|
+
res = mapDNSZoneAnswer(answer, domain)
|
|
87
|
+
command_out(res)
|
|
88
|
+
0
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
desc 'set', 'domain zone set'
|
|
92
|
+
def set(domain, info)
|
|
93
|
+
command_pre(domain)
|
|
94
|
+
zone_records_format
|
|
95
|
+
|
|
96
|
+
answer = DLDInternet::OpenSRS::API::Domain::Zone.new(options, @logger).GetDomainDNSZone(domain)
|
|
97
|
+
if answer['records']
|
|
98
|
+
records = answer['records']
|
|
99
|
+
delta = nil
|
|
100
|
+
begin
|
|
101
|
+
delta = JSON.parse(File.exists?(info) ? File.read(info) : info)
|
|
102
|
+
op = '='
|
|
103
|
+
rescue JSON::ParserError => e
|
|
104
|
+
logger.debug e.ai
|
|
105
|
+
matches = info.match(%r{^([+\-]*)([a-z\.0-9]*)\s*(A|AAAA|CNAME|MX|SRV|TXT)\s+(.*)$})
|
|
106
|
+
if matches
|
|
107
|
+
logger.debug matches.ai
|
|
108
|
+
_, op, subdomain, type, ip_address = matches.to_a
|
|
109
|
+
op = '+' if op.nil? || op.empty?
|
|
110
|
+
case type
|
|
111
|
+
when /^A+/
|
|
112
|
+
delta = { 'A' => [ { 'ip_address' => ip_address } ] }
|
|
113
|
+
delta['A'][0]['subdomain'] = subdomain unless subdomain.empty?
|
|
114
|
+
when 'CNAME'
|
|
115
|
+
raise "ERROR: #{type} not implemented"
|
|
116
|
+
when 'MX'
|
|
117
|
+
raise "ERROR: #{type} not implemented"
|
|
118
|
+
when 'SRV'
|
|
119
|
+
raise "ERROR: #{type} not implemented"
|
|
120
|
+
when 'TXT'
|
|
121
|
+
raise "ERROR: #{type} not implemented"
|
|
122
|
+
else
|
|
123
|
+
raise "ERROR: #{info} cannot be parsed!"
|
|
124
|
+
end
|
|
125
|
+
else
|
|
126
|
+
delta = {}
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
logger.info delta.ai
|
|
130
|
+
if op == '='
|
|
131
|
+
records = delta
|
|
132
|
+
else
|
|
133
|
+
delta.each do |typ,lst|
|
|
134
|
+
lst.each{ |ent|
|
|
135
|
+
case typ
|
|
136
|
+
when %r'^A'
|
|
137
|
+
case op
|
|
138
|
+
when '+'
|
|
139
|
+
existing = records[typ].select { |rec|
|
|
140
|
+
(ent['subdomain'] && ent['subdomain'].eql?(rec['subdomain'])) ||
|
|
141
|
+
(ent['subdomain'].nil? && rec['subdomain'].nil?)
|
|
142
|
+
}
|
|
143
|
+
logger.warn existing.ai
|
|
144
|
+
if existing.size > 0
|
|
145
|
+
existing.each do |rec|
|
|
146
|
+
rec['ip_address'] = ent['ip_address']
|
|
147
|
+
end
|
|
148
|
+
else
|
|
149
|
+
records[typ].push(ent)
|
|
150
|
+
end
|
|
151
|
+
when '-'
|
|
152
|
+
records[typ] = records[typ].select { |rec|
|
|
153
|
+
((ent['subdomain'] && !ent['subdomain'].eql?(rec['subdomain'])) ||
|
|
154
|
+
(ent['subdomain'].nil? && rec['subdomain'].nil?)) && !ent['ip_address'].eql?(rec['ip_address'])
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
logger.error "Invalid operation: #{op}"
|
|
158
|
+
raise
|
|
159
|
+
end
|
|
160
|
+
when 'MX'
|
|
161
|
+
raise "#{typ} update not implemented"
|
|
162
|
+
when 'SRV'
|
|
163
|
+
raise "#{typ} update not implemented"
|
|
164
|
+
when 'TXT'
|
|
165
|
+
raise "#{typ} update not implemented"
|
|
166
|
+
when 'CNAME'
|
|
167
|
+
else
|
|
168
|
+
logger.error "Unknown entry: #{ent}"
|
|
169
|
+
raise
|
|
170
|
+
end
|
|
171
|
+
}
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
logger.debug records.ai
|
|
175
|
+
answer = DLDInternet::OpenSRS::API::Domain::Zone.new(options, @logger).SetDomainDNSZone(domain,records)
|
|
176
|
+
# showDNSZoneAnswer(answer, domain)
|
|
177
|
+
res = mapDNSZoneAnswer(answer, domain)
|
|
178
|
+
command_out(res)
|
|
179
|
+
else
|
|
180
|
+
logger.error "Unable to retrieve DNS zone info for #{domain}"
|
|
181
|
+
end
|
|
182
|
+
0
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module DLDInternet
|
|
2
|
+
module OpenSRS
|
|
3
|
+
module Domain
|
|
4
|
+
module Zone
|
|
5
|
+
module MixIns
|
|
6
|
+
module NoCommands
|
|
7
|
+
|
|
8
|
+
require 'dldinternet/opensrs/domain/mixins/no_commands'
|
|
9
|
+
include DLDInternet::OpenSRS::Domain::MixIns::NoCommands
|
|
10
|
+
|
|
11
|
+
=begin
|
|
12
|
+
f556592444564103d2c17317bebca3de.ds1 CNAME 896e2ecc4a5528f39b306a5bb96afaedc7bf7824.comodoca.com
|
|
13
|
+
=end
|
|
14
|
+
def zone_records_format(*args)
|
|
15
|
+
if args.size > 0
|
|
16
|
+
raise "TODO: Set column widths to fit data"
|
|
17
|
+
else
|
|
18
|
+
@header = -> { sprintf("%-48s\t%-5s\t%-8s\t%-64s\t%-5s\t%-5s", 'Subdomain', 'Type', 'Priority', 'Host', 'Weight', 'Port') }
|
|
19
|
+
@format = ->(res) { sprintf("%-48s\t%-5s\t%-8s\t%-64s\t%-5s\t%-5s", res['subdomain'], res['type'], res['priority'], res['data'], res['weight'], res['port']) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'dldinternet/thor/command'
|
|
2
|
+
require 'dldinternet/opensrs/domain/command'
|
|
3
|
+
require 'dldinternet/opensrs/nameservers/command'
|
|
4
|
+
|
|
5
|
+
module DLDInternet
|
|
6
|
+
module OpenSRS
|
|
7
|
+
class Main < DLDInternet::Thor::Command
|
|
8
|
+
class_option :verbose, type: :boolean
|
|
9
|
+
class_option :debug, type: :boolean
|
|
10
|
+
class_option :trace, type: :boolean
|
|
11
|
+
class_option :log_level, type: :string, banner: 'Log level ([:trace, :debug, :info, :step, :warn, :error, :fatal, :todo])'
|
|
12
|
+
class_option :server, type: :string, default: "https://rr-n1-tor.opensrs.net:55443"
|
|
13
|
+
class_option :username, type: :string, default: 'dldinternet'
|
|
14
|
+
class_option :password, type: :string
|
|
15
|
+
class_option :key, type: :string
|
|
16
|
+
class_option :inifile, type: :string, default: '~/.opensrs.ini'
|
|
17
|
+
class_option :format, type: :string, default: :none, aliases: [ '--output']
|
|
18
|
+
|
|
19
|
+
desc 'domain SUBCOMMAND ... ARGS', 'do domains'
|
|
20
|
+
subcommand 'domain', ::DLDInternet::OpenSRS::Domain::Command
|
|
21
|
+
|
|
22
|
+
desc 'nameservers SUBCOMMAND ... ARGS', 'do domains'
|
|
23
|
+
subcommand 'nameservers', ::DLDInternet::OpenSRS::NameServers::Command
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|