appoxy-nettica 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ == 0.3.0 / 2008-01-29
2
+
3
+ * Fixed update_record in command line script
4
+
5
+ == 0.2.0 / 2008-01-28
6
+
7
+ * Expanded api in command line script
8
+
9
+ == 0.1.0 / 2008-01-28
10
+
11
+ * Initial release
12
+
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/nettica
6
+ lib/nettica.rb
7
+ lib/nettica/client.rb
8
+ lib/nettica/stubs/DnsApiAsmxClient.rb
9
+ lib/nettica/stubs/nettica.rb
10
+ lib/nettica/stubs/nettica.wsdl
11
+ lib/nettica/stubs/netticaDriver.rb
12
+ lib/nettica/stubs/netticaMappingRegistry.rb
13
+ test/test_nettica.rb
@@ -0,0 +1,50 @@
1
+ nettica
2
+ by Matt Conway
3
+ http://simplygenius.com
4
+
5
+ == DESCRIPTION:
6
+
7
+ A ruby client for managing nettica bulk-dns entries using the Nettica SOAP API
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * A thin wrapper for convenience around the soap4r generated stubs for the nettica wsdl.
12
+
13
+ == SYNOPSIS:
14
+
15
+ require 'nettica/client'
16
+ client = Neticca::Client.new('joe_user', 'secret_password')
17
+ puts client.list_zones
18
+
19
+ == REQUIREMENTS:
20
+
21
+ * soap4r gem
22
+
23
+ == INSTALL:
24
+
25
+ * sudo gem install nettica
26
+
27
+ == LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2008 FIX
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/nettica.rb'
6
+
7
+ Hoe.new('nettica', Nettica::VERSION) do |p|
8
+ p.rubyforge_name = 'nettica'
9
+ p.author = 'Matt Conway'
10
+ p.email = 'wr0ngway@yahoo.com'
11
+ p.summary = 'A ruby client for managing nettica bulk-dns entries using the Nettica SOAP API'
12
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
13
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
14
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.extra_deps << ['soap4r']
16
+ p.remote_rdoc_dir = '' # Release to root
17
+ end
18
+
19
+ # vim: syntax=Ruby
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'ostruct'
5
+
6
+ require 'rubygems'
7
+ require 'nettica/client'
8
+
9
+ options = OpenStruct.new
10
+ options.ttl = [0]
11
+ options.priority = [0]
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: nettica -u username -p password -c command [options]"
15
+ opts.separator "Runs the given nettica service command, for example:"
16
+ opts.separator ""
17
+ opts.separator " nettica -u my_user -p my_pass -c list_domain -d foo.com"
18
+ opts.separator " nettica -u my_user -p my_pass -c add_record -h bar -d foo.com -r A -t 300"
19
+ opts.separator " -a 192.168.1.1"
20
+ opts.separator " nettica -u my_user -p my_pass -c update_record -h bar -d foo.com"
21
+ opts.separator " -a 192.168.1.1,10.0.0.1"
22
+ opts.separator " nettica -u my_user -p my_pass -c update_record -h bar -d foo.com -a 10.0.0.1"
23
+ opts.separator " -t 60,300"
24
+ opts.separator ""
25
+ opts.separator "Options:"
26
+
27
+ opts.on("-u", "--user USER", "Nettica username to use for authentication") do |val|
28
+ options.username = val
29
+ end
30
+ opts.on("-p", "--password PASSWORD", "Nettica password to use for authentication") do |val|
31
+ options.password = val
32
+ end
33
+ opts.on("-d", "--domain DOMAIN_NAME", Array, "Domain name to apply command to") do |val|
34
+ options.domain = val
35
+ end
36
+ opts.on("-h", "--host HOST_NAME", Array, "Hostname to act upon") do |val|
37
+ options.host = val
38
+ end
39
+ opts.on("-i", "--ip IP", "IP address") do |val|
40
+ options.ip = val
41
+ end
42
+ opts.on("-r", "--recordtype RECORD_TYPE", Array, "Domain record type (A, CNAME, MX, F, TXT,", "SRV)") do |val|
43
+ options.recordtype = val
44
+ end
45
+ opts.on("-t", "--ttl TIME_TO_LIVE", Array, "TTL for domain entries") do |val|
46
+ options.ttl = val.collect {|each| each.to_i}
47
+ end
48
+ opts.on("-o", "--priority PRIORITY", Array, "Priority for MX/F records") do |val|
49
+ options.priority = val.collect {|each| each.to_i}
50
+ end
51
+ opts.on("-g", "--group GROUP", "Domain group") do |val|
52
+ options.group = val
53
+ end
54
+ opts.on("-m", "--master MASTER", "Master domain") do |val|
55
+ options.master = val
56
+ end
57
+ opts.on("-a", "--data DATA", Array, "IP when creating/deleting records") do |val|
58
+ options.data = val
59
+ end
60
+
61
+ opts.on("-c", "--command COMMAND",
62
+ [:list_zones, :get_service_info, :update_record, :delete_record, :apply_template,
63
+ :list_domain, :create_secondary_zone, :delete_zone, :create_zone, :add_record],
64
+ "Command to execute against nettica service.",
65
+ "One of list_zones, get_service_info,",
66
+ "list_domain, update_record, delete_record,",
67
+ "apply_template, create_secondary_zone,",
68
+ "delete_zone, create_zone, add_record") do |val|
69
+ options.command = val
70
+ end
71
+
72
+ opts.on_tail("--help", "Show this message") do
73
+ puts opts
74
+ exit
75
+ end
76
+ end
77
+
78
+ begin
79
+ args = opts.parse!(ARGV)
80
+ raise "Missing required flag" if ! options.username || ! options.password || ! options.command
81
+ rescue Exception => e
82
+ puts e, "", opts
83
+ exit
84
+ end
85
+
86
+ result = nil
87
+ client = Nettica::Client.new(options.username, options.password)
88
+ case options.command
89
+ when :list_zones
90
+ result = client.list_zones()
91
+ when :get_service_info
92
+ result = client.get_service_info()
93
+ when :list_domain
94
+ result = client.list_domain(options.domain.first)
95
+ when :update_record
96
+ drold = client.create_domain_record(options.domain.first, options.host.first, options.recordtype.first,
97
+ options.data.first, options.ttl.first, options.priority.first)
98
+ drnew = client.create_domain_record(options.domain[1] || options.domain.first,
99
+ options.host[1] || options.host.first,
100
+ options.recordtype[1] || options.recordtype.first,
101
+ options.data[1] || options.data.first,
102
+ options.ttl[1] || options.ttl.first,
103
+ options.priority[1] || options.priority.first)
104
+ result = client.update_record(drold, drnew)
105
+ when :delete_record
106
+ dr = client.create_domain_record(options.domain.first, options.host.first, options.recordtype.first,
107
+ options.data.first, options.ttl.first, options.priority.first)
108
+ result = client.delete_record(dr)
109
+ when :apply_template
110
+ result = client.apply_template(options.domain.first, options.group)
111
+ when :create_secondary_zone
112
+ result = client.create_secondary_zone(options.domain.first, options.master, options.ip)
113
+ when :delete_zone
114
+ result = client.delete_zone(options.domain.first)
115
+ when :create_zone
116
+ result = client.create_zone(options.domain.first)
117
+ when :add_record
118
+ dr = client.create_domain_record(options.domain.first, options.host.first, options.recordtype.first,
119
+ options.data.first, options.ttl.first, options.priority.first)
120
+ result = client.add_record(dr)
121
+ end
122
+
123
+ puts result.inspect
@@ -0,0 +1,3 @@
1
+ class Nettica
2
+ VERSION = '0.3.0'
3
+ end
@@ -0,0 +1,99 @@
1
+ require 'rubygems'
2
+ gem 'soap4r'
3
+ require "nettica/stubs/netticaDriver"
4
+ require 'base64'
5
+
6
+ # http://dev.ctor.org/soap4r
7
+ # http://markthomas.org/2007/09/12/getting-started-with-soap4r/
8
+ # wsdl2ruby.rb --module_path Nettica::Stubs --wsdl 'https://www.nettica.com/DNS/DnsApi.asmx?WSDL' --type client --classdef nettica --force
9
+
10
+ module Nettica
11
+
12
+ class Client
13
+
14
+ include Nettica::Stubs
15
+
16
+ def initialize(username, password)
17
+ @username = username
18
+ @password = Base64.encode64(password).strip
19
+ @proxy = DnsApiAsmxSoap.new
20
+ end
21
+
22
+
23
+ # domainName - SOAP::SOAPString
24
+ # hostName - SOAP::SOAPString
25
+ # recordType - SOAP::SOAPString
26
+ # data - SOAP::SOAPString
27
+ # ttl - SOAP::SOAPInt
28
+ # priority - SOAP::SOAPInt
29
+ def create_domain_record(domainName = nil, hostName = nil, recordType = nil, data = nil, ttl = 0, priority = 0)
30
+ valid_ttls = [0, 1, 60, 300, 600, 900, 1800, 2700, 3600, 7200, 14400, 28800, 43200, 64800, 86400, 172800]
31
+ raise "Ttl must be one of #{valid_ttls.join(',')}" if ttl && ! valid_ttls.include?(ttl)
32
+
33
+ mx_prio = [5, 10, 20, 30, 40, 50, 60, 70, 80, 90]
34
+ f_prio = [1, 2, 3]
35
+ raise "MX priority must be one of #{mx_prio.join(',')}" if recordType == "MX" and ! mx_prio.include?(priority)
36
+ raise "F priority must be one of #{f_prio.join(',')}" if recordType == "F" and ! f_prio.include?(priority)
37
+
38
+ valid_types = ["A", "CNAME", "MX", "F", "TXT", "SRV"]
39
+ raise "Record type must be one of #{valid_types.join(',')}" if recordType && ! valid_types.include?(recordType)
40
+
41
+ DomainRecord.new(domainName, hostName, recordType, data, ttl, priority)
42
+ end
43
+
44
+ def decode_status(result)
45
+ case result.result.status
46
+ when 200 then "Success"
47
+ when 401 then "Access Denied"
48
+ when 404 then "Not Found"
49
+ when 430 then "Domain Exists"
50
+ when 431 then "Record already exists"
51
+ when 432 then "Invalid record type. Must be A, CNAME, MX, F, TXT, SRV"
52
+ when 450 then "No Service"
53
+ when 451 then "No credits"
54
+ when 460 then "Your service has expired"
55
+ end
56
+ end
57
+
58
+ def update_record(old_domain_record, new_domain_record)
59
+ @proxy.updateRecord(UpdateRecord.new(@username, @password, old_domain_record, new_domain_record)).updateRecordResult
60
+ end
61
+
62
+ def delete_record(domain_record)
63
+ @proxy.deleteRecord(DeleteRecord.new(@username, @password, domain_record)).deleteRecordResult
64
+ end
65
+
66
+ def list_zones()
67
+ @proxy.listZones(ListZones.new(@username, @password)).listZonesResult
68
+ end
69
+
70
+ def apply_template(domainName, groupName)
71
+ @proxy.applyTemplate(ApplyTemplate.new(@username, @password, domainName, groupName)).applyTemplateResult
72
+ end
73
+
74
+ def list_domain(domainName)
75
+ @proxy.listDomain(ListDomain.new(@username, @password, domainName)).listDomainResult
76
+ end
77
+
78
+ def create_secondary_zone(domainName, master, ipAddress)
79
+ @proxy.createSecondaryZone(CreateSecondaryZone.new(@username, @password, domainName, master, ipAddress)).createSecondaryZoneResult
80
+ end
81
+
82
+ def get_service_info()
83
+ @proxy.getServiceInfo(GetServiceInfo.new(@username, @password)).getServiceInfoResult
84
+ end
85
+
86
+ def delete_zone(domainName)
87
+ @proxy.deleteZone(DeleteZone.new(@username, @password, domainName)).deleteZoneResult
88
+ end
89
+
90
+ def create_zone(domainName)
91
+ @proxy.createZone(CreateZone.new(@username, @password, domainName, "")).createZoneResult
92
+ end
93
+
94
+ def add_record(domain_record)
95
+ @proxy.addRecord(AddRecord.new(@username, @password, domain_record)).addRecordResult
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env ruby
2
+ require 'nettica/stubs/netticaDriver.rb'
3
+
4
+
5
+ module Nettica::Stubs
6
+
7
+ endpoint_url = ARGV.shift
8
+ obj = DnsApiAsmxSoap.new(endpoint_url)
9
+
10
+ # run ruby with -d to see SOAP wiredumps.
11
+ obj.wiredump_dev = STDERR if $DEBUG
12
+
13
+ # SYNOPSIS
14
+ # GetServiceInfo(parameters)
15
+ #
16
+ # ARGS
17
+ # parameters GetServiceInfo - {http://www.nettica.com/DNS/DnsApi}GetServiceInfo
18
+ #
19
+ # RETURNS
20
+ # parameters GetServiceInfoResponse - {http://www.nettica.com/DNS/DnsApi}GetServiceInfoResponse
21
+ #
22
+ parameters = nil
23
+ puts obj.getServiceInfo(parameters)
24
+
25
+ # SYNOPSIS
26
+ # CreateZone(parameters)
27
+ #
28
+ # ARGS
29
+ # parameters CreateZone - {http://www.nettica.com/DNS/DnsApi}CreateZone
30
+ #
31
+ # RETURNS
32
+ # parameters CreateZoneResponse - {http://www.nettica.com/DNS/DnsApi}CreateZoneResponse
33
+ #
34
+ parameters = nil
35
+ puts obj.createZone(parameters)
36
+
37
+ # SYNOPSIS
38
+ # CreateSecondaryZone(parameters)
39
+ #
40
+ # ARGS
41
+ # parameters CreateSecondaryZone - {http://www.nettica.com/DNS/DnsApi}CreateSecondaryZone
42
+ #
43
+ # RETURNS
44
+ # parameters CreateSecondaryZoneResponse - {http://www.nettica.com/DNS/DnsApi}CreateSecondaryZoneResponse
45
+ #
46
+ parameters = nil
47
+ puts obj.createSecondaryZone(parameters)
48
+
49
+ # SYNOPSIS
50
+ # DeleteZone(parameters)
51
+ #
52
+ # ARGS
53
+ # parameters DeleteZone - {http://www.nettica.com/DNS/DnsApi}DeleteZone
54
+ #
55
+ # RETURNS
56
+ # parameters DeleteZoneResponse - {http://www.nettica.com/DNS/DnsApi}DeleteZoneResponse
57
+ #
58
+ parameters = nil
59
+ puts obj.deleteZone(parameters)
60
+
61
+ # SYNOPSIS
62
+ # ListZones(parameters)
63
+ #
64
+ # ARGS
65
+ # parameters ListZones - {http://www.nettica.com/DNS/DnsApi}ListZones
66
+ #
67
+ # RETURNS
68
+ # parameters ListZonesResponse - {http://www.nettica.com/DNS/DnsApi}ListZonesResponse
69
+ #
70
+ parameters = nil
71
+ puts obj.listZones(parameters)
72
+
73
+ # SYNOPSIS
74
+ # ListDomain(parameters)
75
+ #
76
+ # ARGS
77
+ # parameters ListDomain - {http://www.nettica.com/DNS/DnsApi}ListDomain
78
+ #
79
+ # RETURNS
80
+ # parameters ListDomainResponse - {http://www.nettica.com/DNS/DnsApi}ListDomainResponse
81
+ #
82
+ parameters = nil
83
+ puts obj.listDomain(parameters)
84
+
85
+ # SYNOPSIS
86
+ # AddRecord(parameters)
87
+ #
88
+ # ARGS
89
+ # parameters AddRecord - {http://www.nettica.com/DNS/DnsApi}AddRecord
90
+ #
91
+ # RETURNS
92
+ # parameters AddRecordResponse - {http://www.nettica.com/DNS/DnsApi}AddRecordResponse
93
+ #
94
+ parameters = nil
95
+ puts obj.addRecord(parameters)
96
+
97
+ # SYNOPSIS
98
+ # UpdateRecord(parameters)
99
+ #
100
+ # ARGS
101
+ # parameters UpdateRecord - {http://www.nettica.com/DNS/DnsApi}UpdateRecord
102
+ #
103
+ # RETURNS
104
+ # parameters UpdateRecordResponse - {http://www.nettica.com/DNS/DnsApi}UpdateRecordResponse
105
+ #
106
+ parameters = nil
107
+ puts obj.updateRecord(parameters)
108
+
109
+ # SYNOPSIS
110
+ # DeleteRecord(parameters)
111
+ #
112
+ # ARGS
113
+ # parameters DeleteRecord - {http://www.nettica.com/DNS/DnsApi}DeleteRecord
114
+ #
115
+ # RETURNS
116
+ # parameters DeleteRecordResponse - {http://www.nettica.com/DNS/DnsApi}DeleteRecordResponse
117
+ #
118
+ parameters = nil
119
+ puts obj.deleteRecord(parameters)
120
+
121
+ # SYNOPSIS
122
+ # ApplyTemplate(parameters)
123
+ #
124
+ # ARGS
125
+ # parameters ApplyTemplate - {http://www.nettica.com/DNS/DnsApi}ApplyTemplate
126
+ #
127
+ # RETURNS
128
+ # parameters ApplyTemplateResponse - {http://www.nettica.com/DNS/DnsApi}ApplyTemplateResponse
129
+ #
130
+ parameters = nil
131
+ puts obj.applyTemplate(parameters)
132
+
133
+
134
+
135
+
136
+ end