proxy_pac_rb 0.2.4 → 0.2.5
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/files/sample2.pac +1 -1
- data/lib/proxy_pac_rb/environment.rb +0 -90
- data/lib/proxy_pac_rb/proxy_pac_js.rb +1 -1
- data/lib/proxy_pac_rb/version.rb +1 -1
- data/spec/environment_spec.rb +1 -71
- data/spec/file_spec.rb +1 -1
- data/spec/parser_spec.rb +1 -1
- data/tmp/script.rb +1 -1
- metadata +3 -3
data/files/sample2.pac
CHANGED
@@ -28,12 +28,8 @@ module ProxyPacRb
|
|
28
28
|
:isResolvable,
|
29
29
|
:isInNet,
|
30
30
|
:dnsResolve,
|
31
|
-
# :MyIpAddress ,
|
32
31
|
:dnsDomainLevels,
|
33
32
|
:shExpMatch,
|
34
|
-
# :weekdayRange,
|
35
|
-
# :dateRange,
|
36
|
-
# :timeRange,
|
37
33
|
]
|
38
34
|
end
|
39
35
|
|
@@ -65,10 +61,6 @@ module ProxyPacRb
|
|
65
61
|
resolve_host(host)
|
66
62
|
end
|
67
63
|
|
68
|
-
def myIpAddress
|
69
|
-
IPAddr.new(client_ip).to_s
|
70
|
-
end
|
71
|
-
|
72
64
|
def dnsDomainLevels(host)
|
73
65
|
host.scan(".").size
|
74
66
|
end
|
@@ -77,90 +69,8 @@ module ProxyPacRb
|
|
77
69
|
::File.fnmatch(shexp, str)
|
78
70
|
end
|
79
71
|
|
80
|
-
def weekdayRange(wd1, wd2 = nil, gmt = nil)
|
81
|
-
fail Exceptions::InvalidArgument, "wd1 needs to be one of #{days.keys.collect {|k| "\"#{k}\""}.join(', ')}" unless days.key?(wd1)
|
82
|
-
fail Exceptions::InvalidArgument, "wd2 needs to be one of #{days.keys.collect {|k| "\"#{k}\""}.join(', ')}" if wd2 and !days.key?(wd2)
|
83
|
-
|
84
|
-
if gmt == "GMT"
|
85
|
-
local_time = time.utc
|
86
|
-
else
|
87
|
-
local_time = time
|
88
|
-
end
|
89
|
-
|
90
|
-
(days[wd1]..days[wd2 || wd1]).include? local_time.wday
|
91
|
-
end
|
92
|
-
|
93
|
-
def dateRange(*args)
|
94
|
-
fail Exceptions::InvalidArgument, "range needs to be one of #{months.keys.collect {|k| "\"#{k}\""}.join(', ')}" if args.any? { |a| !months.key?(a) }
|
95
|
-
|
96
|
-
if args.last == "GMT" and args.pop
|
97
|
-
local_time = time.utc
|
98
|
-
else
|
99
|
-
local_time = time
|
100
|
-
end
|
101
|
-
|
102
|
-
case args.size
|
103
|
-
when 1
|
104
|
-
check_date_part(local_time, args[0])
|
105
|
-
when 2
|
106
|
-
check_date_part(local_time, args[0]..args[1])
|
107
|
-
when 4
|
108
|
-
check_date_part(local_time, args[0]..args[2]) and
|
109
|
-
check_date_part(local_time, args[1]..args[3])
|
110
|
-
when 6
|
111
|
-
check_date_part(local_time, args[0]..args[3]) and
|
112
|
-
check_date_part(local_time, args[1]..args[4]) and
|
113
|
-
check_date_part(local_time, args[2]..args[5])
|
114
|
-
else
|
115
|
-
fail ArgumentError, "wrong number of arguments"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def timeRange(*args)
|
120
|
-
fail Exceptions::InvalidArgument, "args need to be integer values" if args.any? { |a| !a.kind_of? Fixnum }
|
121
|
-
|
122
|
-
if args.last == "GMT" and args.pop
|
123
|
-
local_time = time.utc
|
124
|
-
else
|
125
|
-
local_time = time
|
126
|
-
end
|
127
|
-
|
128
|
-
case args.size
|
129
|
-
when 1
|
130
|
-
local_time.hour == args[0]
|
131
|
-
when 2
|
132
|
-
(args[0]..args[1]).include? local_time.hour
|
133
|
-
when 4
|
134
|
-
(args[0]..args[2]).include? local_time.hour and
|
135
|
-
(args[1]..args[3]).include? local_time.min
|
136
|
-
when 6
|
137
|
-
(args[0]..args[3]).include? local_time.hour and
|
138
|
-
(args[1]..args[4]).include? local_time.min and
|
139
|
-
(args[2]..args[5]).include? local_time.sec
|
140
|
-
else
|
141
|
-
fail ArgumentError, "wrong number of arguments"
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
72
|
private
|
146
73
|
|
147
|
-
def check_date_part(time, part, operation = :==)
|
148
|
-
case part
|
149
|
-
when String
|
150
|
-
time.month.send(operation, months[part])
|
151
|
-
when Integer
|
152
|
-
if part < 100
|
153
|
-
time.day.send(operation, part)
|
154
|
-
else
|
155
|
-
time.year.send(operation, part)
|
156
|
-
end
|
157
|
-
when Range
|
158
|
-
check_date_part(time, part.begin, :>=) and check_date_part(time, part.end, :<=)
|
159
|
-
else
|
160
|
-
fail ArgumentError, "wrong type"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
74
|
def resolve_host(host)
|
165
75
|
Resolv.each_address(host) do |address|
|
166
76
|
begin
|
data/lib/proxy_pac_rb/version.rb
CHANGED
data/spec/environment_spec.rb
CHANGED
@@ -77,15 +77,6 @@ describe ProxyPacRb::Environment do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
describe '#myIpAddress ' do
|
81
|
-
it 'returns the given ip address' do
|
82
|
-
ip = '127.0.0.1'
|
83
|
-
environment = Environment.new(client_ip: ip, time: Time.now)
|
84
|
-
|
85
|
-
expect(environment.myIpAddress).to eq(ip)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
80
|
describe '#dnsDomainLevels' do
|
90
81
|
it 'returns the count of domain levels (dots)' do
|
91
82
|
result = environment.dnsDomainLevels('maps.google.com')
|
@@ -105,67 +96,6 @@ describe ProxyPacRb::Environment do
|
|
105
96
|
end
|
106
97
|
end
|
107
98
|
|
108
|
-
describe '#weekdayRange' do
|
109
|
-
let(:environment) { Environment.new(client_ip: '127.0.0.1', time: Time.parse('1991-08-25 12:00')) }
|
110
|
-
|
111
|
-
it 'returns true for SUN - MON' do
|
112
|
-
result = environment.weekdayRange("SUN", "MON")
|
113
|
-
expect(result).to be_true
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'returns false for FR' do
|
117
|
-
result = environment.weekdayRange("FRI")
|
118
|
-
expect(result).to be_false
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'fails if wd1 or wd2 are not valid, e.g. German SO for Sunday' do
|
122
|
-
expect {
|
123
|
-
environment.weekdayRange("SO")
|
124
|
-
}.to raise_error Exceptions::InvalidArgument
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
describe '#dateRange' do
|
130
|
-
let(:environment) { Environment.new(client_ip: '127.0.0.1', time: Time.parse('1991-08-25 12:00')) }
|
131
|
-
|
132
|
-
it 'returns true for JUL - SEP' do
|
133
|
-
result = environment.dateRange("JUL", "SEP")
|
134
|
-
expect(result).to be_true
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'returns false for MAR' do
|
138
|
-
result = environment.dateRange("MAR")
|
139
|
-
expect(result).to be_false
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'fails if range is not valid' do
|
143
|
-
expect {
|
144
|
-
environment.dateRange("SEPT")
|
145
|
-
}.to raise_error Exceptions::InvalidArgument
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe '#timeRange' do
|
150
|
-
let(:environment) { Environment.new(client_ip: '127.0.0.1', time: Time.parse('1991-08-25 12:00')) }
|
151
|
-
|
152
|
-
it 'returns true for 8 - 18h' do
|
153
|
-
result = environment.timeRange(8, 18)
|
154
|
-
expect(result).to be_true
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'returns false for MAR' do
|
158
|
-
result = environment.timeRange(13,14)
|
159
|
-
expect(result).to be_false
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'fails if range is not valid' do
|
163
|
-
expect {
|
164
|
-
environment.timeRange("SEPT")
|
165
|
-
}.to raise_error Exceptions::InvalidArgument
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
99
|
describe '#alert' do
|
170
100
|
it 'outputs msg' do
|
171
101
|
result = capture(:stderr) do
|
@@ -182,7 +112,7 @@ describe ProxyPacRb::Environment do
|
|
182
112
|
environment.prepare(string)
|
183
113
|
|
184
114
|
%w[
|
185
|
-
|
115
|
+
myIpAddress
|
186
116
|
weekdayRange
|
187
117
|
dateRange
|
188
118
|
timeRange
|
data/spec/file_spec.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe ProxyPacRb::Parser do
|
|
35
35
|
it 'supports a changeable ip address' do
|
36
36
|
string = <<-EOS
|
37
37
|
function FindProxyForURL(url, host) {
|
38
|
-
if (
|
38
|
+
if ( myIpAddress() == '127.0.0.2' ) {
|
39
39
|
return "DIRECT";
|
40
40
|
} else {
|
41
41
|
return "PROXY localhost:8080";
|
data/tmp/script.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proxy_pac_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: 2846235873076525490
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
none: false
|
127
127
|
requirements:
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash:
|
133
|
+
hash: 2846235873076525490
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
136
|
rubygems_version: 1.8.23
|