this_ip 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 030fa8500cdc6cceb22b06b352c10bb68be62bd1
4
+ data.tar.gz: 488812e826c2f7cc59f0611acd019bc2e857b399
5
+ SHA512:
6
+ metadata.gz: 82cc2a1ee2d009c3dda0eaa39e9f248ddd914b689618d7248d29b0da3cfc6ea0dfe1416fbfa01f8dce1cbeac5565b9a5bae7d851bfec09cf692903ae1f9e5060
7
+ data.tar.gz: 50273f8a91a8969214c4df585bc9b6bef7dfc58e18b18ac7e98e3c058974ce15ed3ae7a23bcd319460ab9d6761fb2475869db8b04e7810f91092cf36e3ff3a75
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.this_ip.example ADDED
@@ -0,0 +1,9 @@
1
+ services:
2
+ AWS:
3
+ EC2:
4
+ :group_name: 'default'
5
+ :from_port: 22
6
+ :to_port: 22
7
+ :ip_protocol: 'tcp'
8
+ RDS:
9
+ :db_security_group_name: 'default'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in this_ip.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryan Caught
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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # this_ip
2
+
3
+ Auth and deauth your current IP address.
4
+
5
+ ## Installation
6
+
7
+ $ gem install this_ip
8
+
9
+ For extra configuration options, copy `.this_ip.example` into `~/.this_ip` and change the defaults.
10
+
11
+ For AWS support, make sure you have your AWS authorization details loaded into your environment:
12
+
13
+ ```
14
+ export AWS_ACCESS_KEY_ID='...'
15
+ export AWS_SECRET_ACCESS_KEY='...'
16
+ export AWS_REGION='...'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ $ this_ip auth
22
+ $ this_ip deauth
23
+
24
+ ## Services
25
+ - AWS
26
+ - EC2
27
+ - RDS
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/this_ip/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/this_ip ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'this_ip'
4
+
5
+ Signal.trap(:INT, "EXIT")
6
+
7
+ action = ARGV[0]
8
+ this_ip = ThisIp::Main.new(action)
9
+ this_ip.execute
@@ -0,0 +1,80 @@
1
+ require 'aws-sdk'
2
+
3
+ module ThisIp
4
+ module AWS
5
+ class EC2
6
+ def self.defaults
7
+ {
8
+ group_name: 'default',
9
+ ip_protocol: 'tcp',
10
+ from_port: 22,
11
+ to_port: 22
12
+ }
13
+ end
14
+
15
+ def self.auth(ip_address, config)
16
+ puts "AWS::EC2\n"
17
+
18
+ begin
19
+ result = ::AWS::EC2::Client.new.authorize_security_group_ingress(
20
+ ::ThisIp::AWS::EC2.defaults.merge(config).merge(cidr_ip: ::ThisIp::Main.masked_ip_address(ip_address))
21
+ )
22
+ puts " Authorized \"#{ip_address}\""
23
+ rescue Exception => e
24
+ puts " Failed to authorize \"#{ip_address}\""
25
+ puts " Reason: \"#{e.message}\""
26
+ end
27
+ end
28
+
29
+ def self.deauth(ip_address, config)
30
+ puts "AWS::EC2\n"
31
+
32
+ begin
33
+ result = ::AWS::EC2::Client.new.revoke_security_group_ingress(
34
+ ::ThisIp::AWS::EC2.defaults.merge(config).merge(cidr_ip: ::ThisIp::Main.masked_ip_address(ip_address))
35
+ )
36
+ puts " Deauthorized \"#{ip_address}\""
37
+ rescue Exception => e
38
+ puts " Failed to deauthorize \"#{ip_address}\""
39
+ puts " Reason: \"#{e.message}\""
40
+ end
41
+ end
42
+ end
43
+
44
+ class RDS
45
+ def self.defaults
46
+ {
47
+ db_security_group_name: 'default',
48
+ }
49
+ end
50
+
51
+ def self.auth(ip_address, config)
52
+ puts "AWS::RDS\n"
53
+
54
+ begin
55
+ result = ::AWS::RDS::Client.new.authorize_db_security_group_ingress(
56
+ ::ThisIp::AWS::RDS.defaults.merge(config).merge(cidrip: ::ThisIp::Main.masked_ip_address(ip_address))
57
+ )
58
+ puts " Authorized \"#{ip_address}\""
59
+ rescue Exception => e
60
+ puts " Failed to authorize \"#{ip_address}\""
61
+ puts " Reason: \"#{e.message}\""
62
+ end
63
+ end
64
+
65
+ def self.deauth(ip_address, config)
66
+ puts "AWS::RDS\n"
67
+
68
+ begin
69
+ result = ::AWS::RDS::Client.new.revoke_db_security_group_ingress(
70
+ ::ThisIp::AWS::RDS.defaults.merge(config).merge(cidrip: ::ThisIp::Main.masked_ip_address(ip_address))
71
+ )
72
+ puts " Deauthorized \"#{ip_address}\""
73
+ rescue Exception => e
74
+ puts " Failed to deauthorize \"#{ip_address}\""
75
+ puts " Reason: \"#{e.message}\""
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module ThisIp
2
+ VERSION = "0.0.1"
3
+ end
data/lib/this_ip.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'this_ip/version'
2
+ require 'faraday'
3
+
4
+ require 'services/aws'
5
+
6
+ module ThisIp
7
+ class Main
8
+ attr_accessor :action
9
+
10
+ def initialize(action)
11
+ @action ||= action
12
+ end
13
+
14
+ def ip_address
15
+ Faraday.get('http://checkip.amazonaws.com/').body.strip
16
+ end
17
+
18
+ def self.masked_ip_address(ip_address)
19
+ "#{ip_address}/32"
20
+ end
21
+
22
+ def load_config
23
+ YAML.load_file(File.expand_path('~/.this_ip'))
24
+ rescue Errno::ENOENT
25
+ nil
26
+ end
27
+
28
+ def execute
29
+ puts load_config
30
+ if load_config
31
+ config = self.load_config['services']['AWS']
32
+ else
33
+ config = { 'EC2' => {}, 'RDS' => {} }
34
+ end
35
+
36
+ ::ThisIp::AWS::EC2.public_send(@action, ip_address, config['EC2'])
37
+ ::ThisIp::AWS::RDS.public_send(@action, ip_address, config['RDS'])
38
+ end
39
+ end
40
+ end
data/this_ip.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'this_ip/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "this_ip"
8
+ spec.version = ThisIp::VERSION
9
+ spec.authors = ["Ryan Caught"]
10
+ spec.email = ["rcaught@gmail.com"]
11
+ spec.summary = %q{Auth and deauth your current IP address.}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/rcaught/this_ip"
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", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_runtime_dependency "aws-sdk"
25
+ spec.add_runtime_dependency "faraday"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: this_ip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Caught
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-04 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: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Auth and deauth your current IP address.
70
+ email:
71
+ - rcaught@gmail.com
72
+ executables:
73
+ - this_ip
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".this_ip.example"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/this_ip
84
+ - lib/services/aws.rb
85
+ - lib/this_ip.rb
86
+ - lib/this_ip/version.rb
87
+ - this_ip.gemspec
88
+ homepage: https://github.com/rcaught/this_ip
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Auth and deauth your current IP address.
112
+ test_files: []