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