#!/bin/sh # # Simple control script for Juniper Network Connect VPN clients # # Copyright 2008 Paul D. Smith # Version 1.3 (15 June 2008) # # Minor edits by Edward Harman (5 June 2009) # # This script is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. # # This script is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # Requires that 'zenity' be installed. # Need sun-java6-jdk and sun-java6-plugin (or equivalent) for GUI mode. # # Default realm: view page source and look for: # # and use "XXXX" (no quotes) as the realm value. _vpntitle='Network Connect VPN' _vpncfg="$HOME/.vpn.cfg" _jpath="$HOME/.juniper_networks" _ncpath="$_jpath/network_connect" _jarfile="$_jpath/ncLinuxApp.jar" _gui=true JDK_HOME=/usr/lib/jvm/ia32-java-6-sun # Try to find a program on PATH findprog () { r=1 _oldIFS="$IFS" IFS=: for d in $PATH; do case $d in '') d=. ;; esac if [ -f "$d/$1" ] && [ -x "$d/$1" ]; then r=0 break fi done IFS="$_oldIFS" return $r } # If we don't have zenity, give up. We could rewrite to fall back to # echo etc. Someday maybe. if findprog zenity; then : found it else echo "This script requires the program 'zenity'." echo "Please use your package manager to install it." exit 1 fi # See if we have gksudo or kdesudo _sudo= if findprog gksudo; then _sudo=gksudo elif findprog kdesudo; then _sudo=kdesudo else _sudo=sudo fi _errlog="${TMPDIR:-/tmp}/junipernc.$$" # Default config values HOST= : ${USER:=`id -u -n`} CERT="$HOME/.vpn.crt" REALM='Users' die () { _loginfo='' [ -s "$_errlog" ] && _loginfo=" Check the error log file '$_errlog' for more information." if $_gui; then zenity --error --title="$_vpntitle" --text="$*$_loginfo" else echo "$*$_loginfo" fi exit 1 } msg () { if $_gui; then zenity --info --title="$_vpntitle" --text="$*" else echo "$*" fi } log () { echo "$*" >> "$_errlog" } uninstall_nc () { zenity --question --title="$_vpntitle" --text='Are you sure you want to uninstall Juniper Network Connect?' \ || exit 0 rm -f "$_vpncfg" "$CERT" && rm -rf "$_jpath" && exit 0 die 'Uninstall has failed!' } # Set up the Juniper app, if it's not done yet. setup () { _svc="$_ncpath/ncsvc" # If ncsvc is not available, unpack it if [ ! -f "$_svc" ]; then (cd "$_ncpath" && jar xf "$_jarfile" && [ -f "$_svc" ]) >> "$_errlog" 2>&1 \ || die "Could not unpack Juniper Network Connect!" fi # If the ownership or permissions are not correct, fix them if [ `stat -c '%u:%g:%a' "$_svc"` != 0:0:6711 ]; then msg "Initial setup requires administrator privileges. Please enter your password." ( $_sudo chown 0:0 "$_svc" && $_sudo chmod 06711 "$_svc" ) >> "$_errlog" 2>&1 \ || die "Failed to set permissions on '$_svc'!" fi } # Allow the user to customize the system config () { # Get a hostname--needs to be valid err='' while true; do HOST=`zenity --entry --title="$_vpntitle" --text="${err}Enter the Network Connect server:" --entry-text="$HOST"` \ || exit 1 # Some folks enter the HTTP part; remove it. case $HOST in http://*) HOST=${HOST#http://} ;; https://*) HOST=${HOST#https://} ;; esac HOST=${HOST%%/*} # If it's a hostname, make sure we can look it up. case $HOST in *[^.0-9]*) host "$HOST" >/dev/null 2>&1 && break err="Cannot resolve hostname $HOST. Please try again. " ;; esac done USER=`zenity --entry --title="$_vpntitle" --text='Enter the VPN account username' --entry-text="$USER"` \ || exit 1 REALM=`zenity --entry --title="$_vpntitle" --text='Enter the VPN service realm' --entry-text="$REALM"` \ || exit 1 cat > "$_vpncfg" <