updateafraid 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/updateafraid +48 -0
  2. data/lib/updateafraid.rb +57 -0
  3. metadata +94 -0
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ %w{rubygems optiflag updateafraid}.each { |r| require r }
3
+
4
+ module AfraidCLI extend OptiFlagSet
5
+ flag 'user' do
6
+ description 'Your Afraid.org username'
7
+ alternate_forms 'u','U'
8
+ long_form 'username'
9
+ end
10
+ flag 'pass' do
11
+ description 'Your Afraid.org password'
12
+ alternate_forms 'p','P'
13
+ long_form 'password'
14
+ end
15
+ optional_flag 'domain' do
16
+ description 'Update IP address for one domain: -domain <name>'
17
+ alternate_forms 'd','D'
18
+ end
19
+ optional_switch_flag 'all' do
20
+ description 'Update IP address for all domains in your account'
21
+ alternate_forms 'a','A'
22
+ end
23
+ and_process!
24
+ end
25
+
26
+ flag = AfraidCLI.flags
27
+ include Updateafraid
28
+
29
+ @account = AfraidAccount.new(flag.user, flag.pass)
30
+
31
+ if !flag.domain and !flag.all
32
+ @account.print_domains
33
+ elsif flag.all
34
+ @account.update_all.each {|r|
35
+ puts r
36
+ }
37
+ elsif flag.domain
38
+ # Update this specific domain
39
+ updated = @account.update(flag.domain)
40
+ if !updated
41
+ puts "You don't have that domain!\n"
42
+ @account.print_domains
43
+ else
44
+ puts updated
45
+ end
46
+ else
47
+ puts "See --help for usage"
48
+ end
@@ -0,0 +1,57 @@
1
+ %w{rubygems digest/sha1 happymapper open-uri}.each { |r| require r }
2
+
3
+ module Updateafraid
4
+ class AfraidAccount
5
+ attr_accessor :username, :password, :domains
6
+ def initialize(username, password)
7
+ @username, @password = username, password
8
+ @domains = self.getdyndns
9
+ end
10
+
11
+ def getdyndns
12
+ sha1 = Digest::SHA1.hexdigest(@username+'|'+@password)
13
+ xml = open("http://freedns.afraid.org/api/" +
14
+ "?action=getdyndns"+"&sha="+sha1+"&style=xml", "User-Agent" => 'updateafraid.rb').read
15
+ return Domain.parse(xml)
16
+ end
17
+
18
+ def update_all
19
+ responses = Array.new
20
+ @domains.each do |domain|
21
+ responses.push domain.host + " - " + domain.update
22
+ end
23
+ return responses
24
+ end
25
+
26
+ def update(domain)
27
+ o = false
28
+ self.domains.each { |d|
29
+ if d.host == domain
30
+ o = d.update
31
+ break
32
+ end
33
+ }
34
+ return o
35
+ end
36
+
37
+ def print_domains
38
+ puts "You have " + self.domains.size.to_s + " domains:"
39
+ self.domains.each do |d| puts d.host + "\t(" + d.address + ")" end
40
+ end
41
+
42
+ end
43
+
44
+ class Domain
45
+ include HappyMapper
46
+ tag 'item'
47
+ element :host, String
48
+ element :address, String
49
+ element :url, String
50
+
51
+ def update
52
+ open(@url).read
53
+ end
54
+
55
+ end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: updateafraid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
10
+ platform: ruby
11
+ authors:
12
+ - Logan Koester
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-17 00:00:00 -04:00
18
+ default_executable: bin/updateafraid
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: happymapper
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 1
31
+ - 2
32
+ version: 0.1.2
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: optiflag
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 6
46
+ - 5
47
+ version: 0.6.5
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description:
51
+ email: logan@logankoester.com
52
+ executables:
53
+ - updateafraid
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - bin/updateafraid
60
+ - lib/updateafraid.rb
61
+ has_rdoc: true
62
+ homepage: http://logankoester.com
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project: updateafraid
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: A Dynamic DNS client for domains parked at afraid.org
93
+ test_files: []
94
+