tunnelblick 0.0.1 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b66f4735c7dfe937fc36c330ab403cc67c080aef
4
- data.tar.gz: 4f8955327de66bcc3d9bf846c5b2feeecfef8664
3
+ metadata.gz: 4f36c8ae27a7e36bf54072b78fa2681cc9387514
4
+ data.tar.gz: 73350a0eede1e321a4c4dee3a44a946897d0d4fb
5
5
  SHA512:
6
- metadata.gz: 0c4061147ecf0e5b51a0de51166399ebf59727f0be81779d734ff97e22668e50d5bcab86f4fa6b917823082138015190f909f733a9a988bb746791fea927e500
7
- data.tar.gz: c3da8c77a288113d08514f2e89091dae6d6e9ea8632ac2fc9ef88b04fe9575b2dc0d2dea35d5d41070a595c1b23a5b3240610fc14c2e881812b91d3c486d63fe
6
+ metadata.gz: 66d8cf838fb232b4c6e4ad2d4de91f9a64e74dbd915fde14f8f9b1546d2f210e5788a0f26afc42b9e7c2c189f67dcbcd0050cf596a8f50cb32fe3d29fc9674bd
7
+ data.tar.gz: 12293c3f760876abf43c23a62dfa6a6caa536327ff62ffc9f8d9f76e59755e5ea72a610d27af7a11813919c09561a8b112915276cb1e3aff3faca35c14dd7662
@@ -1,62 +1,155 @@
1
+ require 'flex_config'
2
+ require 'flex_console'
3
+ require 'flex_pg'
4
+ require 'open-uri'
1
5
  require 'rb-scpt'
2
6
  require 'tunnel_blick/express_vpn'
3
7
 
4
8
  include Appscript
5
9
 
6
- module TunnelBlick
10
+ class TunnelBlick
7
11
 
8
- class << self
9
- attr_accessor :tunnel, :module, :d_id
12
+ attr_accessor :tunnel, :module, :d_id, :my_ip, :max_requests, :arguments,
13
+ :doms, :allowance
14
+ attr_reader :database
10
15
 
11
- def config_match (file_name)
12
- case file_name
13
- when /\Amy_expressvpn.+/
14
- puts 'Express VPN'
15
- else
16
- puts 'VPN not recognized.'
17
- end
18
- end
16
+ def initialize (database = Dummy.new('dummy database'))
17
+ @config = FlexConfig.new('/Users/YCL/Documents/RubyProjects/gems/tunnel_blick', {})
18
+ @database = database
19
+ @tunnel = Appscript.app('Tunnelblick.app')
20
+ @websites = []
21
+ end
22
+
23
+ def manual
24
+
25
+ puts @my_ip = open('http://icanhazip.com').read.strip
26
+ database[:ip_addresses].insert_ignore.insert(:public_ip => @my_ip)
27
+
28
+ end
29
+
30
+ def add_websites (*websites)
31
+ websites.each { |w|
32
+ w.tunnel = self
33
+ w.allowance = allowance
34
+ }
35
+ end
19
36
 
20
- def connected?
21
- vpn_states.include?('CONNECTED')
37
+ def config_match (file_name)
38
+ file_name
39
+ case file_name
40
+ when /\Amy_expressvpn.+/
41
+ #puts 'Express VPN'
42
+ @loaded_module = TunnelBlick::ExpressVPN
43
+ else
44
+ puts 'VPN not recognized.'
22
45
  end
46
+ end
47
+
48
+ def config_filter (countries)
49
+ countries
50
+ vpn_configs.inject([]) { |acc, conf|
51
+ config_match(conf)
52
+ details = @loaded_module.parse_config(conf)
53
+ if countries.include?(details[:country])
54
+ acc << conf
55
+ acc
56
+ else
57
+ acc
58
+ end
59
+ }
60
+ end
61
+
62
+ def reallocate
63
+ disconnect
64
+ @allowance = 0
65
+ connect_smart(max_requests, arguments, *doms)
66
+ end
23
67
 
24
- def connect_rand (extra_waits = 2)
68
+ def connect_smart (limit, args = {}, *domains)
69
+ @allowance = 0
70
+ blocked = true
25
71
 
26
- unless TunnelBlick.connected?
72
+ while @allowance < 1 || blocked
73
+ database.disconnect
74
+ puts @my_ip = open('http://icanhazip.com').read.strip if my_ip.nil?
27
75
 
28
- TunnelBlick.connect(vpn_configs.sample)
76
+ blocked = false
77
+ connect_rand(3, args) unless connected?
29
78
 
30
- count = 0
31
- while count <= extra_waits && !TunnelBlick.connected?
32
- sleep(5)
33
- count += 1
34
- end
79
+ allowances = domains.map { |dom|
80
+ limit - database[:browser_requests].where(ip_address: my_ip, domain: dom).count
81
+ }
35
82
 
36
- unless TunnelBlick.connected?
37
- puts 'VPN did not connect in time'
38
- return
83
+ domains.each { |dom|
84
+ result = database[:website_ip_status].where(public_ip: my_ip, website: dom, status: 'blocked').count
85
+ if result != 0
86
+ puts 'This ip is blocked'
87
+ blocked = true
88
+ break
39
89
  end
90
+ }
91
+ puts @allowance = allowances.min
92
+ disconnect if @allowance < 1 || blocked
93
+ end
94
+
95
+ @max_requests = limit
96
+ @arguments = args
97
+ @doms = domains
98
+
99
+ @allowance
100
+ end
40
101
 
102
+ def connected?
103
+ vpn_states.include?('CONNECTED')
104
+ end
105
+
106
+ def connect_rand (extra_waits = 2, args = {})
107
+
108
+ unless connected?
109
+ puts 'connect_rand'
110
+ if args[:filter].nil?
111
+ tunnel.connect(vpn_configs.sample)
112
+ else
113
+ puts shortlist = config_filter(args[:filter])
114
+ tunnel.connect(shortlist.sample)
41
115
  end
42
116
 
43
- config_file_name = vpn_configs[vpn_states.index('CONNECTED')]
44
- loaded_module = TunnelBlick::TunnelBlick.module
117
+ count = 0
45
118
 
46
- loaded_module.parse_config(config_file_name)
47
- end
119
+ while count <= extra_waits && !connected?
120
+ sleep(5)
121
+ count += 1
122
+ end
123
+
124
+ unless connected?
125
+ puts 'VPN did not connect in time'
126
+ return
127
+ end
48
128
 
49
- def method_missing (method, *args, &block)
50
- @tunnel.send(method, *args, &block)
51
129
  end
52
130
 
131
+ config_file_name = vpn_configs[vpn_states.index('CONNECTED')]
132
+ config_match(config_file_name)
133
+ details = @loaded_module.parse_config(config_file_name)
134
+
135
+ sleep(3)
136
+ puts @my_ip = open('http://icanhazip.com').read.strip
137
+
138
+ details.store(:public_ip, my_ip)
139
+
140
+ sleep(6)
141
+ database[:ip_addresses].upsert(details)
53
142
  end
54
143
 
55
- def self.included(base)
56
- TunnelBlick.tunnel = Appscript.app('Tunnelblick.app')
57
- TunnelBlick.tunnel.extend(TunnelBlick)
144
+ def method_missing (method, *args, &block)
145
+ tunnel.send(method, *args, &block)
58
146
  end
59
147
 
148
+ # def self.included(base)
149
+ # TunnelBlick.tunnel = Appscript.app('Tunnelblick.app')
150
+ # TunnelBlick.tunnel.extend(TunnelBlick)
151
+ # end
152
+
60
153
  def connected_vpn
61
154
  p vpn_states
62
155
  if vpn_state == 'CONNECTED'
@@ -67,7 +160,10 @@ module TunnelBlick
67
160
  end
68
161
 
69
162
  def disconnect
70
- TunnelBlick.disconnect_all
163
+ puts 'Disconnecting from prior tunnels'
164
+ tunnel.disconnect_all
165
+ puts 'Sleep(6)'
166
+ sleep(6)
71
167
  end
72
168
 
73
169
  def vpn_state
@@ -75,11 +171,11 @@ module TunnelBlick
75
171
  end
76
172
 
77
173
  def vpn_configs
78
- TunnelBlick.configurations.name.get
174
+ configurations.name.get
79
175
  end
80
176
 
81
177
  def vpn_states
82
- TunnelBlick.configurations.state.get
178
+ configurations.state.get
83
179
  end
84
180
 
85
181
  end
@@ -1,14 +1,14 @@
1
1
  require 'facets/hash/op_push'
2
2
  require 'facets/string/titlecase'
3
3
 
4
- module TunnelBlick
4
+ class TunnelBlick
5
5
 
6
6
  module ExpressVPN
7
7
 
8
8
  class << self
9
9
 
10
10
  def parse_config (string)
11
- details = {}
11
+ details = {provider: 'ExpressVPN'}
12
12
 
13
13
  string = string.sub('my_expressvpn_', '')
14
14
  string.sub!(/_\D{3}\z/, '')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tunnelblick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Lai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: flex_config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rb-scpt
29
43
  requirement: !ruby/object:Gem::Requirement