Created
October 20, 2014 16:08
-
-
Save mivasi/bc0046aa2277a64726c8 to your computer and use it in GitHub Desktop.
Enable charles proxy on juniper VPN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'optparse' | |
options = {} | |
def log(message, options) | |
if options[:verbose] | |
puts "DEBUG: " + message | |
end | |
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( '-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 | |
juniperState = `scutil<< EOF | |
show State:/Network/Service/net.juniper.pulse.nc.main/IPv4 | |
quit | |
EOF` | |
log(juniperState, options) | |
serviceKey = juniperState.gsub(/.*net\.juniper\.DSUnderlyingServiceName : (.*?)\s.*/m, "\\1").chomp | |
log(serviceKey, options) | |
if options[:on] | |
#now save it (must be root :-( ) | |
results = `scutil<< EOF | |
d.init | |
get Setup:/Network/Service/#{serviceKey}/Proxies | |
set State:/Network/Service/net.juniper.pulse.nc.main/Proxies | |
quit | |
EOF` | |
else | |
# disable proxying | |
results = `scutil<< EOF | |
d.init | |
get State:/Network/Service/net.juniper.pulse.nc.main/Proxies | |
d.add HTTPSEnable 0 | |
d.add HTTPEnable 0 | |
set State:/Network/Service/net.juniper.pulse.nc.main/Proxies | |
quit | |
EOF` | |
end | |
puts results | |
Thanks! Worked perfectly for me.
how to Enable stp plz help me
Lol. Glad someone's finding a use for this. FWIW the original is here: https://github.com/robfromca/random-scripts/blob/master/vpn-charles.rb with a slightly improved UI now and updated for the most recent pulse/macos (as this one has been tweaked too).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for sharing this code. I used it to create a bash script which I then packaged for node:
https://www.npmjs.com/package/psproxy