Proxy Script/Toggle

jrserapio
Contributor

Hey Guys,

Can't seem to get this work work as planned. Basically I need a way for the end user to be able to turn off the proxies with the least amount of effort. There are also 2 scenarios to this, 1 where they are admins and 2 where they are not admins. Also this has to be able to run when not connected to the JSS. Basically this will be used when at a location that has a captive portal to connect to wi-fi. Once the user has authenticated through the captive portal, they will need to enable the proxy back on for VPN access.

This is what I have so far.

#!/bin/bash

CD="/Users/Shared/CocoaDialog.app/Contents/MacOS/CocoaDialog"
ON='networksetup -setftpproxystate "Wi-Fi" on &&networksetup -setwebproxystate "Wi-Fi" on &&networksetup -setsecurewebproxystate "Wi-Fi" on'
OFF='networksetup -setftpproxystate Wi-Fi off&&networksetup -setwebproxystate Wi-Fi off&&networksetup -setsecurewebproxystate Wi-Fi off'

rv=`$CD msgbox --no-newline 
    --text "Proxy Toggler" 
    --informative-text "The Proxy can be toggled on or off." 
    --button1 "Proxy Off" --button2 "Proxy On" --button3 "Cancel"`

if [ "$rv" == "1" ]; then
    eval $OFF
    echo "Proxy has been disabled"
elif [ "$rv" == "2" ]; then
    eval $ON
    echo "Proxy has been enabled"
elif [ "$rv" == "3" ]; then
    echo "User has exited"
fi

My current stoppage is that the user has to authenticate 3 times (once for each command).
Also if the user is not an admin, they would not be able to run this script.

Ideally i would like to have the user click the script/command, select if they need the proxy on or off, and never authenticate or authenticate just 1 time.

Doing this through the GUI is 8 clicks, which is too many for some.

1 ACCEPTED SOLUTION

ctangora
Contributor III

You can invoke the root user then revoke the privileges with

sudo -K

at the end of it.

View solution in original post

4 REPLIES 4

calumhunter
Valued Contributor

Hmm could you not have multiple network locations setup? one with proxies enabled and one with out? and then just switch?

You can script the creation of the locations as well as populate the proxy settings via networksetup as well

networksetup -switchlocation <locationname>

jrserapio
Contributor

Thanks for the suggestion @calumhunter.
The only issue i can see happening is that switching network locations might knock them off the captive portal session. I don't have a test environment with a captive portal to test unfortunately. I will try creating a location and see if switching via script will require elevation.

ctangora
Contributor III

You can invoke the root user then revoke the privileges with

sudo -K

at the end of it.

jrserapio
Contributor

@ctangora This cut down the number of authentications to just 1, which should be good enough for the time being.

Thanks for all the replies.