tunnelblick 0.0.6 → 0.1.15

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.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tunnel_blick.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # TunnelBlick
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tunnel_blick`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tunnel_blick'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tunnel_blick
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tunnel_blick.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tunnel_blick"
5
+
6
+ # (If you use this, don't forget to add pry to your Gemfile!)
7
+ # require "pry"
8
+ # Pry.start
9
+
10
+ TunnelBlick.database = {
11
+ host: '183.178.117.122', port: 5432,
12
+ user: 'eugene', password: 'demo3586',
13
+ database: 'wines', max_connects: 2
14
+ }
15
+ TunnelBlick.countries = ['Hong Kong']
16
+
17
+ @tunnel = TunnelBlick::Tunnel.new
18
+
19
+ require "irb"
20
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,194 +1,32 @@
1
- require 'flex_config'
2
- require 'flex_console'
3
- require 'flex_pg'
4
- require 'open-uri'
5
- require 'rb-scpt'
6
- require_relative 'tunnel_blick/express_vpn'
7
-
8
- include Appscript
9
-
10
- class TunnelBlick
11
-
12
- attr_accessor :tunnel, :module, :d_id, :max_requests, :arguments, :doms, :allowance
13
- attr_reader :database
14
-
15
- def initialize (database = Dummy.new('dummy database'))
16
- @config = FlexConfig.new('/Users/YCL/Documents/RubyProjects/gems/tunnel_blick', {})
17
- @database = database
18
- @tunnel = Appscript.app('Tunnelblick.app')
19
- @websites = []
20
- end
21
-
22
- def manual
23
-
24
- puts @my_ip = open('http://icanhazip.com').read.strip
25
- database[:ip_addresses].insert_ignore.insert(:public_ip => @my_ip)
26
-
27
- end
28
-
29
- def add_websites (*websites)
30
- websites.each { |w|
31
- w.tunnel = self
32
- w.allowance = @allowance
33
- }
34
- end
35
-
36
- def config_match (file_name)
37
- file_name
38
- case file_name
39
- when /\Amy_expressvpn.+/
40
- #puts 'Express VPN'
41
- @loaded_module = TunnelBlick::ExpressVPN
42
- else
43
- puts 'VPN not recognized.'
44
- end
45
- end
46
-
47
- def config_filter (countries)
48
- countries
49
- vpn_configs.inject([]) { |acc, conf|
50
- config_match(conf)
51
- details = @loaded_module.parse_config(conf)
52
- if countries.include?(details[:country])
53
- acc << conf
54
- acc
55
- else
56
- acc
57
- end
58
- }
59
- end
60
-
61
- def reallocate
62
- disconnect
63
- @allowance = 0
64
- connect_smart(@max_requests, @arguments, *@doms)
65
- end
66
-
67
- def connect_smart (limit, args = {}, *websites)
68
- @allowance = 0
69
- blocked = false
70
- domains = websites.map {|ws|
71
- extract = ws.home_url.scan(/[^\/]+/)
72
- dom = extract.size == 1 ? extract[0] : extract[1]
73
- database[:websites][domain_url: dom][:id]
74
- }
75
-
76
- puts @my_ip = open('http://icanhazip.com').read.strip if @my_ip.nil?
77
-
78
- while @allowance < 1 || blocked
79
- blocked = false
80
- database.disconnect
81
- connect_rand(3, args) unless connected?
82
-
83
- domains.each { |dom|
84
- result = database[:website_ip_status].where(public_ip: @my_ip, website: dom, status: 'blocked').count
85
-
86
- if result != 0
87
- puts 'This ip is blocked'
88
- blocked = true
89
- end
90
- }
91
- puts blocked
92
-
93
- unless blocked
94
- allowances = domains.map { |dom|
95
- limit - database[:browser_requests].where(ip_address: @my_ip, domain: dom).count
96
- }
97
- puts @allowance = allowances.min
98
- end
99
-
100
- disconnect if blocked || @allowance < 0
101
- end
1
+ require "tunnel_blick/version"
102
2
 
103
- @max_requests = limit
104
- @arguments = args
105
- @doms = domains
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.require(:default)
106
6
 
107
- @allowance
108
- end
109
-
110
- def connected?
111
- vpn_states.include?('CONNECTED')
112
- end
113
-
114
- def connect_rand (extra_waits = 2, args = {})
115
-
116
- unless connected?
117
- puts 'connect_rand'
118
- if args[:filter].nil?
119
- @tunnel.connect(vpn_configs.sample)
120
- else
121
- puts shortlist = config_filter(args[:filter])
122
- @tunnel.connect(shortlist.sample)
123
- end
124
-
125
- count = 0
126
-
127
- while count <= extra_waits && !connected?
128
- sleep(5)
129
- count += 1
130
- end
131
-
132
- if connected?
133
- puts @my_ip = open('http://icanhazip.com').read.strip
134
- else
135
- puts 'VPN did not connect in time'
136
- return
137
- end
138
-
139
- end
140
-
141
- config_file_name = vpn_configs[vpn_states.index('CONNECTED')]
142
- config_match(config_file_name)
143
- details = @loaded_module.parse_config(config_file_name)
144
-
145
- sleep(3)
146
- puts @my_ip = open('http://icanhazip.com').read.strip
147
-
148
- details.store(:public_ip, @my_ip)
149
-
150
- sleep(6)
151
- database[:ip_addresses].upsert(details)
152
- end
7
+ require 'facets/string/titlecase'
8
+ require 'open-uri'
9
+ require 'ostruct'
10
+ require 'pg'
11
+ require 'rb-scpt'
12
+ require 'sequel'
153
13
 
154
- def method_missing (method, *args, &block)
155
- tunnel.send(method, *args, &block)
156
- end
14
+ module TunnelBlick
157
15
 
158
- # def self.included(base)
159
- # TunnelBlick.tunnel = Appscript.app('Tunnelblick.app')
160
- # TunnelBlick.tunnel.extend(TunnelBlick)
161
- # end
16
+ class << self
17
+ attr_accessor :ip_db, :details
162
18
 
163
- def connected_vpn
164
- p vpn_states
165
- if vpn_state == 'CONNECTED'
166
- vpn_configs[0]
167
- else
168
- nil
19
+ def database= (database)
20
+ TunnelBlick.ip_db = database
21
+ require_relative 'tunnel_blick/models'
169
22
  end
170
- end
171
-
172
- def disconnect
173
- puts 'Disconnecting from prior tunnels'
174
- tunnel.disconnect_all
175
- puts 'Sleep(6)'
176
- sleep(6)
177
- end
178
23
 
179
- def vpn_state
180
- vpn_states[0]
181
- end
182
-
183
- def vpn_configs
184
- configurations.name.get
185
- end
186
-
187
- def vpn_states
188
- configurations.state.get
189
24
  end
190
25
 
191
26
  end
192
27
 
193
-
194
-
28
+ require_relative 'tunnel_blick/module_methods'
29
+ require_relative 'tunnel_blick/tunnel'
30
+ require_relative 'tunnel_blick/express_vpn'
31
+ require_relative 'tunnel_blick/ip_methods'
32
+ require_relative 'tunnel_blick/logging'
@@ -1,66 +1,48 @@
1
- require 'facets/hash/op_push'
2
- require 'facets/string/titlecase'
1
+ require_relative '../tunnel_blick'
3
2
 
4
- class TunnelBlick
3
+ module TunnelBlick
5
4
 
6
5
  module ExpressVPN
7
6
 
8
7
  class << self
9
8
 
10
9
  def parse_config (string)
11
- details = {provider: 'ExpressVPN'}
10
+
11
+ details = OpenStruct.new
12
+ details.provider = 'ExpressVPN'
12
13
 
13
14
  string = string.sub('my_expressvpn_', '')
14
15
  string.sub!(/_\D{3}\z/, '')
15
16
 
16
17
  if string.split('_').size == 2
17
- details << {:country => string.sub('_', ' ').titlecase}
18
- details << {:label => details[:country]}
18
+ details.country = string.sub('_', ' ').titlecase
19
+ details.label = details.country
19
20
  return details
21
+ else
22
+
20
23
  end
21
24
 
22
25
  country = string.split('-')[0]
23
26
  string.sub!(country, '')
24
27
  country.gsub!('_', ' ').strip!
28
+ country = %w"usa".include?(country) ? country.upcase : country.titlecase
29
+ details.country = country
25
30
 
26
- country =
27
- if %w"usa".include?(country)
28
- country.upcase
29
- else
30
- country.titlecase
31
- end
32
-
33
- city =
34
- if ['Hong Kong'].include?(country)
35
- country
36
- else
37
- string.split('-_')[1]
38
- end
39
-
31
+ city = ['Hong Kong'].include?(country) ? country : string.split('-_')[1]
40
32
  string.gsub!(city, '')
41
33
  city = city.gsub('_', ' ').strip.titlecase.sub('Dc', 'DC')
34
+ details.city = city
42
35
 
43
- label =
44
- if country == city
45
- country
46
- else
47
- "#{country} - #{city}"
48
- end
36
+ label = country == city ? country : "#{country} - #{city}"
49
37
  number = string.scan(/\d/)
38
+ label = label + " - #{number[0]}" unless number.empty?
39
+ details.label = label
50
40
 
51
- unless number.empty?
52
- label = label + " - #{number[0]}"
53
- end
54
-
55
- details = {
56
- :country => country,
57
- :city => city,
58
- :label => label
59
- }
60
-
41
+ details
61
42
  end
62
43
 
63
44
  end
64
45
 
65
46
  end
47
+
66
48
  end
@@ -0,0 +1,78 @@
1
+ require_relative '../tunnel_blick'
2
+ require_relative 'tunnel'
3
+
4
+ module TunnelBlick
5
+
6
+ class Tunnel
7
+
8
+ def connect_same
9
+
10
+ if @cycle_num == -1
11
+ @cycle_num = 0
12
+ end
13
+
14
+ connect(@cycle_num)
15
+ end
16
+
17
+ def connect_cycle (reset = false)
18
+
19
+ last_num = @shortlist.size - 1
20
+
21
+ if reset
22
+ @cycle_num = 0
23
+ else
24
+ @cycle_num += 1
25
+ end
26
+
27
+ if @cycle_num > last_num
28
+ @cycle_num = 0
29
+ end
30
+ disconnect if connected?
31
+ connect(@cycle_num)
32
+ end
33
+
34
+ def change_ip (allow_bare = false)
35
+ start_ip = TunnelBlick.my_ip
36
+
37
+ if connected?
38
+ disconnect
39
+ sleep(3)
40
+
41
+ if allow_bare
42
+ return TunnelBlick.my_ip
43
+ end
44
+ end
45
+
46
+ new_ip = start_ip.dup
47
+ until new_ip != start_ip
48
+ disconnect
49
+ new_ip = connect_cycle
50
+ end
51
+ new_ip
52
+ end
53
+
54
+ def change_ip_unique (reset = false)
55
+
56
+ TunnelBlick.set_unique_attempts(6) if TunnelBlick.uniq_tries.nil?
57
+ @checked_ips = [] if @checked_ips.nil? || reset
58
+ my_ip = change_ip
59
+ counter = 1
60
+
61
+ while @checked_ips.include?(my_ip) && counter < TunnelBlick.uniq_tries
62
+ my_ip = change_ip
63
+ counter += 1
64
+ end
65
+ @checked_ips << my_ip
66
+
67
+ if counter == TunnelBlick.uniq_tries
68
+ sputs "unique ip change failed after #{counter} tries"
69
+ false
70
+ else
71
+ my_ip
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ end