1 #!/bin/ksh -ph 2 3 APP_TMP_DIR=`mktemp -d -t net_admin_XXXXXX` 4 5 trap "rm -rf ${APP_TMP_DIR}" 0 1 2 11 15 6 7 #Figure out location of BASEDIR 8 BASEDIR=${0%/bin/*} 9 BASEDIR=${BASEDIR:-/usr} 10 11 PATH=/usr/sbin:/sbin:${BASEDIR}/sbin:${PATH} 12 export PATH 13 14 zenity=$BASEDIR/bin/zenity 15 16 NET_PHYSICAL_SVC=svc:/network/physical 17 18 LING=$LC_ALL 19 LING=${LING:-$LC_MESSAGES} 20 LING=${LING:-$LANG} 21 22 TEXTDOMAINDIR=${BASEDIR}/share/locale 23 TEXTDOMAIN=gnome-system-tools 24 export TEXTDOMAINDIR TEXTDOMAIN 25 26 27 N_() { 28 printf "%s\n" "$@" 29 } 30 31 _() { 32 if [ x"$LING" = x -o x"$LING" = x"C" -o x"$LING" = x"POSIX" ] ; then 33 printf "%s\n" "$@" 34 else 35 MSGID=`printf "%s\n" "$@" | sed -e 's|\\\\|\\\\\\\\|g'` 36 gettext "$MSGID" 37 fi 38 } 39 40 isRunningNWAM() { 41 state_nwam=`/usr/bin/svcs -H -o state svc:/network/physical:nwam 2>/dev/null` 42 43 if [ "${state_nwam}" = "online" ] 44 then 45 return 0 46 else 47 return 1 48 fi 49 } 50 51 set_network_physical () { 52 if [ "$1" = "auto" ]; then 53 to_enable=nwam 54 to_disable=default 55 else 56 to_enable=default 57 to_disable=nwam 58 fi 59 60 # Try svcadm directly, use might have sufficient auths. 61 switch_completed=false 62 if pfexec -P all svcadm disable -s "${NET_PHYSICAL_SVC}:${to_disable}" 2>/dev/null; then 63 if pfexec -P all svcadm enable -s "${NET_PHYSICAL_SVC}:${to_enable}" 2>/dev/null; then 64 switch_completed=true 65 else 66 # Restore to previous state. 67 pfexec -P all svcadm enable -s "${NET_PHYSICAL_SVC}:${to_disable}" 2>/dev/null 68 fi 69 fi 70 71 if [ "$switch_completed" = "false" ]; then 72 # Try again using gksu since svcadm failed. 73 TMPFILE=${APP_TMP_DIR}/switch_to_${1}.$$.sh 74 cat > ${TMPFILE} <<_EOF 75 #!/bin/sh 76 if svcadm disable -s "${NET_PHYSICAL_SVC}:${to_disable}"; then 77 if svcadm enable -s "${NET_PHYSICAL_SVC}:${to_enable}"; then 78 : 79 else 80 # Restore to previous state 81 svcadm enable -s "${NET_PHYSICAL_SVC}:${to_disable}" 82 fi 83 fi 84 _EOF 85 chmod 555 ${TMPFILE} 86 gksu --title="$TITLE" /bin/sh ${TMPFILE} 87 fi 88 89 #Check to see if we successfully completed all tasks. 90 sleep 3 # Slight delay to give SMF time to switch. 91 if [ "${to_enable}" = "nwam" ]; then 92 if isRunningNWAM; then 93 rval=0 94 else 95 # If NWAM is not running then we failed. 96 rval=1 97 fi 98 else 99 # NWAM should be disabled in this case. 100 if isRunningNWAM; then 101 # If NWAM still running we failed. 102 rval=1 103 else 104 rval=0 105 fi 106 fi 107 108 return $rval 109 } 110 111 # SUN_BRANDING 112 _TITLE=`N_ "Network Administration"` 113 114 # SUN_BRANDING 115 _MANUAL_OK_BUTTON=`N_ "Manual"` 116 # SUN_BRANDING 117 _MANUAL_CANCEL_BUTTON=`N_ "Cancel"` 118 # SUN_BRANDING 119 _MANUAL_ERROR=`N_ "An error occured switching to Manual mode."` 120 # SUN_BRANDING 121 _MANUAL_MESSAGE_1=`N_ "\ 122 Your system is currently configured to manage the\\n\ 123 network automatically. Click \"%s\" to manually\\n\ 124 configure the network connection."` 125 126 # SUN_BRANDING 127 _AUTO_OK_BUTTON=`N_ "Automatic"` 128 # SUN_BRANDING 129 _AUTO_CANCEL_BUTTON=`N_ "Continue"` 130 # SUN_BRANDING 131 _AUTO_ERROR=`N_ "An error occured switching to Automatic mode."` 132 # SUN_BRANDING 133 _AUTO_MESSAGE=`N_ "\ 134 Your system is currently configured to manage the\\n\ 135 network manually. Click \"%s\" to have the\\n\ 136 network configured automatically.\\n\ 137 \\n\ 138 Otherwise click \"%s\" to continue to\\n\ 139 configure the network manually."` 140 141 TITLE=`_ "${_TITLE}"` 142 143 if isRunningNWAM; then 144 ALTMODE='MANUAL' 145 OK_BUTTON=`_ "${_MANUAL_OK_BUTTON}"` 146 CANCEL_BUTTON=`_ "${_MANUAL_CANCEL_BUTTON}"` 147 ERROR_MSG=`_ "${_MANUAL_ERROR}"` 148 MSG=`_ "${_MANUAL_MESSAGE}"` 149 MSG=`printf "$MSG\n" "${OK_BUTTON}"` 150 else 151 ALTMODE='AUTO' 152 OK_BUTTON=`_ "${_AUTO_OK_BUTTON}"` 153 CANCEL_BUTTON=`_ "${_AUTO_CANCEL_BUTTON}"` 154 ERROR_MSG=`_ "${_AUTO_ERROR}"` 155 MSG=`_ "${_AUTO_MESSAGE}"` 156 MSG=`printf "$MSG\n" "${OK_BUTTON}" "${CANCEL_BUTTON}"` 157 fi 158 159 160 if [ -n "${1}" -a "X${1}" = "X--switch-to-manual" ]; then 161 shift 162 if [ "$ALTMODE" = "MANUAL" ]; then 163 if set_network_physical manual; then 164 : 165 else 166 $zenity --error --title="${TITLE}" --text="${ERROR_MSG}" 167 fi 168 fi 169 elif [ -n "${1}" -a "X${1}" = "X--switch-to-auto" ]; then 170 shift 171 if [ "$ALTMODE" = "AUTO" ]; then 172 if set_network_physical auto; then 173 : 174 else 175 $zenity --error --title="${TITLE}" --text="${ERROR_MSG}" 176 fi 177 fi 178 else 179 $zenity --question --ok-label="${OK_BUTTON}" --cancel-label="${CANCEL_BUTTON}" \ 180 --title="${TITLE}" --text="${MSG}" 181 response_code=$? 182 183 if [ "$ALTMODE" = "MANUAL" ]; then 184 if [ $response_code -eq 0 ]; then # Switch to Manual 185 if set_network_physical manual; then 186 exec ${BASEDIR}/lib/network-admin ${1+"$@"} 187 else 188 $zenity --error --title="${TITLE}" --text="${ERROR_MSG}" 189 fi 190 else 191 exit 0 # Do nothing 192 fi 193 elif [ "$ALTMODE" = "AUTO" ]; then 194 if [ $response_code -eq 0 ]; then # Switch to Auto 195 if set_network_physical auto; then 196 : 197 else 198 $zenity --error --title="${TITLE}" --text="${ERROR_MSG}" 199 fi 200 else 201 exec ${BASEDIR}/lib/network-admin ${1+"$@"} 202 fi 203 fi 204 fi 205