Skip to content

Instantly share code, notes, and snippets.

@spaetz
Created November 6, 2016 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spaetz/be487e01e3958f72fa86ae66eef8c931 to your computer and use it in GitHub Desktop.
Save spaetz/be487e01e3958f72fa86ae66eef8c931 to your computer and use it in GitHub Desktop.
#!/bin/sh -e
# Script to set up the University of Hamburg web proxy when the Openconnect VPN connected
# credits to https://wiki.ubuntuusers.de/NetworkManager/Dispatcher/
VPN_CONNECTION_NAME="UniHH"
USER="UserNameHere"
# VPN connection started or stopped?
case "$2" in
vpn-up)
active_vpn=$(nmcli -t --fields NAME con show --active|grep "${VPN_CONNECTION_NAME}" -q)
if $active_vpn; then
echo "UNI HH VPN started"
echo $(whoami)
else
#Irrelevant VPN started, do nothing
exit 0
fi
# gsettings will fail if dbus is not launched with:
# "dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
sudo -u "$USER" dbus-launch gsettings set org.gnome.system.proxy mode 'manual'
sudo -u "$USER" dbus-launch gsettings set org.gnome.system.proxy.http host 'proxy.uni-hamburg.de'
sudo -u "$USER" dbus-launch gsettings set org.gnome.system.proxy.http port 3128
##gsettings set org.gnome.system.proxy.ftp host 'proxy.localdomain.com'
##gsettings set org.gnome.system.proxy.ftp port 3128
sudo -u "$USER" dbus-launch gsettings set org.gnome.system.proxy.https host 'proxy.uni-hamburg.de'
sudo -u "$USER" dbus-launch gsettings set org.gnome.system.proxy.https port 3128
sudo -u "$USER" dbus-launch gsettings set org.gnome.system.proxy ignore-hosts "['localhost', '127.0.0.0/8', '10.0.0.0/8', '192.168.0.0/16', '172.16.0.0/12' , 'fc00::/8' , '*.fritz.box' ]"
;;
vpn-down)
# Disable all proxies on VPN shutdown, this might be to simple
# for your case, it works for me.
echo "VPN connection was stopped"
sudo -u "$USER" dbus-launch gsettings set org.gnome.system.proxy mode 'none'
;;
esac
exit 0;
@spaetz
Copy link
Author

spaetz commented Nov 6, 2016

I am the first to admit that the multiple sudo dbus-launch constructs are ugly, but they were the first thing that actually worked. Improvements welcome :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment