-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvpn-charles.rb
More file actions
executable file
·96 lines (84 loc) · 2.3 KB
/
vpn-charles.rb
File metadata and controls
executable file
·96 lines (84 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/ruby
require 'optparse'
options = {}
def log(message, options)
if options[:verbose]
puts "DEBUG: " + message
end
end
def retrieveServiceKey(options, versionIdentifier)
juniperState = `scutil<< EOF
show State:/Network/Service/#{versionIdentifier}/IPv4
quit
EOF`
log(juniperState, options)
serviceKey = juniperState.gsub(/.*net\.pulsesecure\.DSUnderlyingServiceName : (.*?)\s.*/m, "\\1").chomp
log(serviceKey, options)
return serviceKey
end
optparse = OptionParser.new do |opts|
opts.banner = "Usage: vpn-charles.rb\n Copies proxy settings from your active connection to your juniper vpn settings."
options[:verbose] = false
opts.on( '-v', '--verbose', 'Spit out extra debugging info') do
options[:verbose] = true
end
opts.on( '-a', '--on', 'Activate charles on your VPN' ) do
options[:on] = true
end
opts.on( '-d', '--off', 'Deactivate charles on your VPN' ) do
options[:on] = false
end
opts.on( '-o', '--old', 'Use for older versions of pulse' ) do
options[:old] = true
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
begin
optparse.parse!
onMissing = [:on].select{ |param| options[param].nil? }
if not onMissing.empty?
puts "Must specify --on or --off"
puts optparse
exit
end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
puts $!.to_s
puts optparse
exit
end
versionIdentifier = "net.pulsesecure.pulse.nc.main"
if options[:old]
versionIdentifier = "net.juniper.ncproxyd.main"
end
serviceKey = retrieveServiceKey(options, versionIdentifier)
if options[:on]
puts "Please make sure your VPN is connected and Charles is running, then"
puts "press any key to continue..."
STDIN.gets
#now save it (must be root :-( )
results = `scutil<< EOF
d.init
get Setup:/Network/Service/#{serviceKey}/Proxies
set State:/Network/Service/#{versionIdentifier}/Proxies
quit
EOF`
puts "Charles should be recording now. Don't forget to run:"
puts
puts "sudo ./vpn-charles.rb --off"
puts
puts "to disable proxying when you either close charles or disconnect from the VPN"
else
# disable proxying
results = `scutil<< EOF
d.init
get State:/Network/Service/#{versionIdentifier}/Proxies
d.add HTTPSEnable 0
d.add HTTPEnable 0
set State:/Network/Service/#{versionIdentifier}/Proxies
quit
EOF`
end
puts results