Proxy

Firefox has this annoying habit of not acknowledging system-wide proxy settings on OSX. This creates problems for me when I switch between my home network (direct connection without a proxy) and the university network (via a proxy). Normally when I change network I have to manually change my Location setting in OSX. Fair enough, but because FireFox behaves badly I also have to manually change the application connection settings. Well things are better now thanks to SystemProxy, an addon for FireFox that handles the manual configuration automatically.

Sweet!

I’m also evaluating Location X, a tool that can automatically switch Location based on which wireless network it’s connected to.

One more step automated.
Double Sweet!



[Edit:2008_12_11]

Mark Assad has a Proxy Config Tool that’ll configure an appopriate proxy for your command line. Ryan Tomayko also discusses a similar tool in “OS X Network Location Support From The Command Line“. A comment on that page discusses ‘networksetup‘, a command line tool that’s invoked thus,

/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -getwebproxy “Built-in Ethernet”

Authoxy is a local proxy that handles authentication for you. Essentially all I really need to do is run this in my .bashrc,
export http_proxy="http://<username>:<password>@<proxy>:<port>"

[Edit: 2008_03_26]

LocationX doesn’t seem to be so great after all. For starters it’s closed source and the developer hasn’t updated it for a couple of years. It also seems buggy. Sometimes it doesn’t switch properly, and when I open the application’s main interface the context names are missing.

I tried MarcoPolo and had some success, but it now doesn’t seem to do anything when I launch the application. This is a shame as it’s open source. It’s also overkill for my simple needs.

I’m now looking at Locomatic which seems simple and appears to do all that I need.
Other possible solutions might include:

[Edit: 2009_04_14]

I finally decided on using LocationChanger, but customised it a little as some of my locations have spaces in them which the original script didn’t support. Following is my script. Make sure you replace ‘HOME LOCATION NAME’, ‘WORK LOCATION NAME’, HOME_SSID, WORK_SSID. Notice that all I’ve done is add “” around these terms (I also commented out some of the original author’s code that deals with synergy, etc.)

#!/bin/bash

# automatically change configuration of Mac OS X based on location
# author: Onne Gorter 
# url: http://tech.inhelsinki.nl/locationchanger/
# version: 0.4

# redirect all IO to /dev/null (comment this out if you want to debug)
exec 1>/dev/null 2>/dev/null

# get a little breather before we get data for things to settle down
sleep 2

# get various system information
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I\
 | grep ' SSID:' | cut -d ':' -f 2 | tr -d ' '`
EN0IP=`ifconfig en0 | grep 'inet ' | cut -d' ' -f 2`
EN1IP=`ifconfig en1 | grep 'inet ' | cut -d' ' -f 2`

echo "SSID is $SSID"

LOCATION=

# locations (use to be used Location name here)
ATHOME='HOME LOCATION NAME'
ATWORK='WORK LOCATION NAME'

# detect HOME
ATHOME_SSID=HOME_SSID
ATHOME_EN0IP=192.168.255.
ATHOME_EN1IP=192.168.255.

# detect Work
ATWORK_SSID=WORK_SSID
ATWORK_EN0IP=255.
ATWORK_EN1IP=255.

if [ -z "$LOCATION" ]; then
	case "$SSID" in
		"$ATHOME_SSID"	) LOCATION="$ATHOME";;
		"$ATWORK_SSID"	) LOCATION="$ATWORK";;
	esac
        REASON=SSID
fi

if [ -z "$LOCATION" ]; then
	case $EN0IP in
		$ATHOME_EN0IP*	) LOCATION="$ATHOME";;
		$ATWORK_EN0IP*	) LOCATION="$ATWORK";;
	esac
        REASON=EN0IP
fi

if [ -z "$LOCATION" ]; then
	case $EN1IP in
		$ATHOME_EN1IP*	) LOCATION="$ATHOME";;
		$ATWORK_EN1IP*	) LOCATIOn="$ATWORK";;
	esac
        REASON=EN1IP
fi

if [ -z "$LOCATION" ]; then
	# still didn't get a location, so do automatic
	LOCATION="Automatic"
        REASON=Fallback
fi

case "$LOCATION" in
	"$ATWORK" )
		scselect "$ATWORK"
		#lpoptions -d "Work Printer"

		# get some time to figure ip addresses out ...
		#sleep 3
		#if ping -c 1 linux; then
		#	# if necesairy, start a proxy for synergy on host 'linux'
		#	ps -x | grep -E '[0-9] ssh.*-R24800:'  || \
		#		ssh -fN linux -R24800:127.0.0.1:24800 
		#	# if not running, start synergys with display name macosx
		#	ps -x | grep -E '[0-9] synergys'  || \
		#		synergys -n macosx
		#fi
	;;

	"$ATHOME" )
		# do some stuff here if you want to
		scselect "$ATHOME"
		#lpoptions -d "Home Printer"
	;;

	Automatic )
		# do some stuff here if you want to
		scselect Automatic
		#lpoptions -d "Default Printer"
	;;

esac

# do some stuff here that needs to happen after every network change

echo `date` "Location: $LOCATION - $REASON" >> $HOME/.locationchanger.log

exit 0
cselect
Advertisements

One thought on “Proxy

  1. PS: You need to execute the following to get this to actually run once you’ve installed the scripts in the right locations (see Onne’s original post):


    launchctl load ~/Library/LaunchAgents/LocationChanger.plist
    launchctl start tech.inhelsinki.nl.locationchanger

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s