noip 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1bcf997ac319fd48ed1b67f31f4d7f985d8b1be6
4
+ data.tar.gz: c1ecfca9c825fc289cab3b515f6fad09d46c6d72
5
+ SHA512:
6
+ metadata.gz: 8f85d623a85aaffce2c67b140257a8ea77d9f5b49d5b01ae7df484c6665538d0083ffb01640d03fab26f4ce1ab7ecf6189919c4502efface892fa2b8ac4cc6f9
7
+ data.tar.gz: dc13e1dacc583c0b739fb873e8c38351cd8c8a13df7887923f706068ccc6aa6ee34574c2859ef978bcc82c23d76338fae9d89f7983240d8117b5d2ae08ba2729
@@ -0,0 +1 @@
1
+ pkg
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p547
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ noip (0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.0)
10
+ diff-lcs (1.2.5)
11
+ method_source (0.8.2)
12
+ pry (0.10.3)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.8.1)
15
+ slop (~> 3.4)
16
+ rake (10.4.2)
17
+ rspec (3.3.0)
18
+ rspec-core (~> 3.3.0)
19
+ rspec-expectations (~> 3.3.0)
20
+ rspec-mocks (~> 3.3.0)
21
+ rspec-core (3.3.2)
22
+ rspec-support (~> 3.3.0)
23
+ rspec-expectations (3.3.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.3.0)
26
+ rspec-mocks (3.3.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.3.0)
29
+ rspec-support (3.3.0)
30
+ slop (3.6.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler
37
+ noip!
38
+ pry
39
+ rake
40
+ rspec
41
+
42
+ BUNDLED WITH
43
+ 1.10.6
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 asellitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # noip
2
+
3
+ A simple utility for updating [noip](https://www.noip.com/integrate/request)
4
+ dynamic DNS records for when your router kinda shit.
5
+
6
+ ## Usage
7
+
8
+ ### Command Line Interface
9
+
10
+ You will need to provide your credentials and host to update as environment variables:
11
+
12
+ ```bash
13
+ NOIP_HOST=host.to.update NOIP_USERNAME=username NOIP_PASSWORD=h4h-t0tez-l3g1t noip
14
+ ```
15
+
16
+ ### Crontab
17
+
18
+ As before, environment variables will need to be provided, here's a sample crontab that will run every 4 hours:
19
+
20
+ ```crontab
21
+ 0 0,4,8,12,16,20 * * * NOIP_HOST=host.to.update NOIP_USERNAME=username NOIP_PASSWORD=h4h-t0tez-l3g1t noip
22
+ ```
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( https://github.com/asellitt/noip/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ Rake.add_rakelib 'lib/tasks'
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'noip'
4
+
5
+ Noip.update
@@ -0,0 +1,13 @@
1
+ require 'noip/agent'
2
+ require 'noip/credentials'
3
+ require 'noip/remote_ip'
4
+ require 'noip/updater'
5
+ require 'noip/version'
6
+
7
+ module Noip
8
+
9
+ def self.update
10
+ Noip::Updater.new.update
11
+ end
12
+
13
+ end
@@ -0,0 +1,23 @@
1
+ module Noip
2
+ class Agent
3
+
4
+ def user_agent
5
+ "#{update_program}/#{version_number} #{maintainer_email}"
6
+ end
7
+
8
+ private
9
+
10
+ def update_program
11
+ "noip ruby gem"
12
+ end
13
+
14
+ def version_number
15
+ "v#{Noip::VERSION}"
16
+ end
17
+
18
+ def maintainer_email
19
+ "anthony.noip_gem@asellitt.com"
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Noip
2
+ class Credentials
3
+
4
+ def initialize(username = nil, password = nil, host = nil)
5
+ @username = username || ENV['NOIP_USERNAME']
6
+ @password = password || ENV['NOIP_PASSWORD']
7
+ @host = host || ENV['NOIP_HOST']
8
+ end
9
+
10
+ attr_reader :username, :password, :host
11
+
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'net/http'
2
+
3
+ module Noip
4
+ class RemoteIp
5
+
6
+ def address
7
+ @address ||= fetch_remote_address
8
+ end
9
+
10
+ private
11
+
12
+ def fetch_remote_address
13
+ remote_ip = Net::HTTP.get(resolver)
14
+ end
15
+
16
+ def resolver
17
+ URI('http://whatismyip.akamai.com')
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ require 'net/http'
2
+
3
+ module Noip
4
+ class Updater
5
+
6
+ def initialize
7
+ initialize_http_request
8
+ end
9
+
10
+ def update
11
+ @response ||= http.request(request)
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :http, :request, :response
17
+
18
+ def initialize_http_request
19
+ @http = Net::HTTP.new('dynupdate.no-ip.com')
20
+
21
+ @request = Net::HTTP::Get.new(
22
+ "/nic/update?hostname=#{credentials.host}&ip=#{remote_ip.address}",
23
+ { 'User-Agent' => agent.user_agent }
24
+ )
25
+ @request.basic_auth(
26
+ credentials.username,
27
+ credentials.password
28
+ )
29
+ end
30
+
31
+ def agent
32
+ @agent ||= Noip::Agent.new
33
+ end
34
+
35
+ def remote_ip
36
+ @remote_ip ||= Noip::RemoteIp.new
37
+ end
38
+
39
+ def credentials
40
+ @credentials ||= Noip::Credentials.new
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Noip
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'noip'
2
+ namespace :noip do
3
+
4
+ desc "Push a dynamic DNS update to noip"
5
+ task :update do
6
+ Noip.update
7
+ end
8
+
9
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "noip/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "noip"
8
+ spec.version = Noip::VERSION
9
+ spec.executables = ["noip"]
10
+ spec.authors = ["Anthony Sellitti"]
11
+ spec.email = ["anthony.noip_gem@asellitt.com"]
12
+ spec.summary = "Dynamic DNS updater for No-IP"
13
+ spec.homepage = "https://github.com/asellitt/noip"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Noip::Agent do
4
+ describe '#user_agent' do
5
+ before do
6
+ stub_const("Noip::VERSION", "DEAD.BEEF")
7
+ end
8
+
9
+ subject(:user_agent) { Noip::Agent.new.user_agent }
10
+
11
+ it { is_expected.to eq "noip ruby gem/vDEAD.BEEF anthony.noip_gem@asellitt.com" }
12
+ end
13
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Noip::Credentials do
4
+ context 'with ENV variables set' do
5
+ before do
6
+ allow(ENV).to receive(:[]).with('NOIP_USERNAME').and_return('env_noip_username')
7
+ allow(ENV).to receive(:[]).with('NOIP_PASSWORD').and_return('env_noip_password')
8
+ allow(ENV).to receive(:[]).with('NOIP_HOST').and_return('env_noip_host')
9
+ end
10
+
11
+ describe 'username' do
12
+ subject(:username) { Noip::Credentials.new(username, password, host).username }
13
+
14
+ context 'with values provided' do
15
+ let(:username) { 'provided_username'}
16
+ let(:password) { 'provided_password'}
17
+ let(:host) { 'provided_host'}
18
+
19
+ it { is_expected.to eq 'provided_username' }
20
+ end
21
+
22
+ context 'with no values provided' do
23
+ let(:username) { nil }
24
+ let(:password) { nil }
25
+ let(:host) { nil }
26
+
27
+ it { is_expected.to eq 'env_noip_username' }
28
+ end
29
+ end
30
+
31
+ describe 'password' do
32
+ subject(:password) { Noip::Credentials.new(username, password, host).password }
33
+
34
+ context 'with values provided' do
35
+ let(:username) { 'provided_username'}
36
+ let(:password) { 'provided_password'}
37
+ let(:host) { 'provided_host'}
38
+
39
+ it { is_expected.to eq 'provided_password' }
40
+ end
41
+
42
+ context 'with no values provided' do
43
+ let(:username) { nil }
44
+ let(:password) { nil }
45
+ let(:host) { nil }
46
+
47
+ it { is_expected.to eq 'env_noip_password' }
48
+ end
49
+ end
50
+
51
+ describe 'host' do
52
+ subject(:host) { Noip::Credentials.new(username, password, host).host }
53
+
54
+ context 'with values provided' do
55
+ let(:username) { 'provided_username'}
56
+ let(:password) { 'provided_password'}
57
+ let(:host) { 'provided_host'}
58
+
59
+ it { is_expected.to eq 'provided_host' }
60
+ end
61
+
62
+ context 'with no values provided' do
63
+ let(:username) { nil }
64
+ let(:password) { nil }
65
+ let(:host) { nil }
66
+
67
+ it { is_expected.to eq 'env_noip_host' }
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Noip::RemoteIp do
4
+ describe '#address' do
5
+ let(:ip_address) { '12.34.56.78' }
6
+
7
+ before do
8
+ allow(Net::HTTP).to receive(:get).and_return(ip_address)
9
+ end
10
+
11
+ subject(:address) { Noip::RemoteIp.new.address }
12
+
13
+ it { is_expected.to eq '12.34.56.78' }
14
+
15
+ it 'resolves the ip via akamai' do
16
+ address
17
+ expect(Net::HTTP).to have_received(:get).with(URI('http://whatismyip.akamai.com'))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Noip::Updater do
4
+ describe '#update' do
5
+ let(:agent) do
6
+ instance_double(Noip::Agent,
7
+ :user_agent => 'porkchop/vsammiches gi@jo.e',
8
+ )
9
+ end
10
+ before { allow(Noip::Agent).to receive(:new).and_return(agent) }
11
+
12
+ let(:remote_ip) do
13
+ instance_double(Noip::RemoteIp,
14
+ :address => '1.2.3.4',
15
+ )
16
+ end
17
+ before { allow(Noip::RemoteIp).to receive(:new).and_return(remote_ip) }
18
+
19
+ let(:credentials) do
20
+ instance_double(Noip::Credentials,
21
+ :username => 'username',
22
+ :password => 'password',
23
+ :host => 'host',
24
+ )
25
+ end
26
+ before { allow(Noip::Credentials).to receive(:new).and_return(credentials) }
27
+
28
+ let(:http) { instance_double(Net::HTTP) }
29
+ before do
30
+ allow(http).to receive(:request)
31
+ allow(Net::HTTP).to receive(:new).and_return(http)
32
+ end
33
+
34
+ let(:request) { instance_double(Net::HTTP::Get) }
35
+ before do
36
+ allow(request).to receive(:basic_auth)
37
+ allow(Net::HTTP::Get).to receive(:new).and_return(request)
38
+ end
39
+
40
+ subject(:update) { Noip::Updater.new.update }
41
+ before { update }
42
+
43
+ it 'requests the correct domain' do
44
+ expect(Net::HTTP).to have_received(:new).with(
45
+ 'dynupdate.no-ip.com'
46
+ )
47
+ end
48
+
49
+ it 'sets the correct path, with host and address and user agent information' do
50
+ expect(Net::HTTP::Get).to have_received(:new).with(
51
+ '/nic/update?hostname=host&ip=1.2.3.4',
52
+ { 'User-Agent' => 'porkchop/vsammiches gi@jo.e' }
53
+ )
54
+ end
55
+
56
+ it 'sets up the request to use basic authentication' do
57
+ expect(request).to have_received(:basic_auth).with(
58
+ 'username',
59
+ 'password'
60
+ )
61
+ end
62
+
63
+ it 'makes the request to update the dynamic dns record' do
64
+ expect(http).to have_received(:request).with(
65
+ request
66
+ )
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Noip do
4
+ describe '.update' do
5
+ let(:updater) { instance_double(Noip::Updater) }
6
+ before do
7
+ allow(updater).to receive(:update)
8
+ allow(Noip::Updater).to receive(:new).and_return(updater)
9
+ end
10
+
11
+ subject(:update) { Noip.update }
12
+ before { update }
13
+
14
+ it 'pushes a new update to noip' do
15
+ expect(updater).to have_received(:update)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ require 'noip'
2
+
3
+ RSpec.configure do |config|
4
+ config.color = true
5
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: noip
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Sellitti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - anthony.noip_gem@asellitt.com
72
+ executables:
73
+ - noip
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".ruby_version"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.md
82
+ - README.md
83
+ - Rakefile
84
+ - bin/noip
85
+ - lib/noip.rb
86
+ - lib/noip/agent.rb
87
+ - lib/noip/credentials.rb
88
+ - lib/noip/remote_ip.rb
89
+ - lib/noip/updater.rb
90
+ - lib/noip/version.rb
91
+ - lib/tasks/noip.rake
92
+ - noip.gemspec
93
+ - spec/noip/agent_spec.rb
94
+ - spec/noip/credentials_spec.rb
95
+ - spec/noip/remote_ip_spec.rb
96
+ - spec/noip/updater_spec.rb
97
+ - spec/noip_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: https://github.com/asellitt/noip
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.4.5
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Dynamic DNS updater for No-IP
123
+ test_files:
124
+ - spec/noip/agent_spec.rb
125
+ - spec/noip/credentials_spec.rb
126
+ - spec/noip/remote_ip_spec.rb
127
+ - spec/noip/updater_spec.rb
128
+ - spec/noip_spec.rb
129
+ - spec/spec_helper.rb