tunnelblick 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tunnel_blick.rb +29 -20
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9020554bb01597251a84afa93fba28b1671af724
4
- data.tar.gz: fd009bc41776853bcb9f2e04e6a85d23c463db28
3
+ metadata.gz: fc3e6167cf01210b6feaec5ffebc749501876b83
4
+ data.tar.gz: 38d9e73b2c1a9e3a2afa1f46d6650353a6d10710
5
5
  SHA512:
6
- metadata.gz: 2a702b9771234bc39044122f84ae7e261f1fd5370ca68513343f759924fce7ac479d68420fe341f0016b9e69a41291f321b4ebf169576207a56f81b3a854d711
7
- data.tar.gz: d98223bba55c2de548553efcd3dfd8be9b87fde4bf8ba49ff390b5bae44643d9d201706df4793880e538b23e7f603be02dc0e88559fe54c114bce9178b3725f3
6
+ metadata.gz: 7c7f62780f49ba8cb5da03718e77b898366f79c2154d9c3c8dec4934a4abd3b562bcd6672973f3d1e97fd20b95a9fbf97e1b530fdeda802d11549c6861096d19
7
+ data.tar.gz: 2f8b9fd8f188da55978d7a1de510ed592041bdd89660698d278b4904022dba5bb702128ed7103815e5f53ba17e47db7446be827e5556882902f062cc6de9f44d
data/lib/tunnel_blick.rb CHANGED
@@ -3,14 +3,13 @@ require 'flex_console'
3
3
  require 'flex_pg'
4
4
  require 'open-uri'
5
5
  require 'rb-scpt'
6
- require 'tunnel_blick/express_vpn'
6
+ require_relative 'tunnel_blick/express_vpn'
7
7
 
8
8
  include Appscript
9
9
 
10
10
  class TunnelBlick
11
11
 
12
- attr_accessor :tunnel, :module, :d_id, :my_ip, :max_requests, :arguments,
13
- :doms, :allowance
12
+ attr_accessor :tunnel, :module, :d_id, :max_requests, :arguments, :doms, :allowance
14
13
  attr_reader :database
15
14
 
16
15
  def initialize (database = Dummy.new('dummy database'))
@@ -30,7 +29,7 @@ class TunnelBlick
30
29
  def add_websites (*websites)
31
30
  websites.each { |w|
32
31
  w.tunnel = self
33
- w.allowance = allowance
32
+ w.allowance = @allowance
34
33
  }
35
34
  end
36
35
 
@@ -62,33 +61,43 @@ class TunnelBlick
62
61
  def reallocate
63
62
  disconnect
64
63
  @allowance = 0
65
- connect_smart(max_requests, arguments, *doms)
64
+ connect_smart(@max_requests, @arguments, *@doms)
66
65
  end
67
66
 
68
- def connect_smart (limit, args = {}, *domains)
67
+ def connect_smart (limit, args = {}, *websites)
69
68
  @allowance = 0
70
- blocked = true
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
+ }
71
75
 
72
- while @allowance < 1 || blocked
73
- database.disconnect
74
- puts @my_ip = open('http://icanhazip.com').read.strip if my_ip.nil?
76
+ puts @my_ip = open('http://icanhazip.com').read.strip if @my_ip.nil?
75
77
 
78
+ while @allowance < 1 || blocked
76
79
  blocked = false
80
+ database.disconnect
77
81
  connect_rand(3, args) unless connected?
78
82
 
79
- allowances = domains.map { |dom|
80
- limit - database[:browser_requests].where(ip_address: my_ip, domain: dom).count
81
- }
82
-
83
83
  domains.each { |dom|
84
- result = database[:website_ip_status].where(public_ip: my_ip, website: dom, status: 'blocked').count
84
+ result = database[:website_ip_status].where(public_ip: @my_ip, website: dom, status: 'blocked').count
85
+
85
86
  if result != 0
86
87
  puts 'This ip is blocked'
87
88
  blocked = true
88
89
  end
89
90
  }
90
- puts @allowance = allowances.min
91
- disconnect if @allowance < 1 || blocked
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
92
101
  end
93
102
 
94
103
  @max_requests = limit
@@ -107,10 +116,10 @@ class TunnelBlick
107
116
  unless connected?
108
117
  puts 'connect_rand'
109
118
  if args[:filter].nil?
110
- tunnel.connect(vpn_configs.sample)
119
+ @tunnel.connect(vpn_configs.sample)
111
120
  else
112
121
  puts shortlist = config_filter(args[:filter])
113
- tunnel.connect(shortlist.sample)
122
+ @tunnel.connect(shortlist.sample)
114
123
  end
115
124
 
116
125
  count = 0
@@ -136,7 +145,7 @@ class TunnelBlick
136
145
  sleep(3)
137
146
  puts @my_ip = open('http://icanhazip.com').read.strip
138
147
 
139
- details.store(:public_ip, my_ip)
148
+ details.store(:public_ip, @my_ip)
140
149
 
141
150
  sleep(6)
142
151
  database[:ip_addresses].upsert(details)
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Lai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-05 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.5.2
82
+ rubygems_version: 2.6.1
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: A controller for Tunnelblick