sns 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2010, bkhome.org
  3. #2010 Lesser GPL licence v2 (/usr/share/doc/legal/lgpl-2.1.txt)
  4. #100308 first version of script, open and wep networks only.
  5. #100309 supports wpa. 100310 bug fixes.
  6. #100312 wireless code cleanup, bug fixes.
  7. #100313 wpa_supplicant, try different values for ap_scan.
  8. #100313 added support for ndiswrapper.
  9. #100314 bugfixes.
  10. #100320 fix if essid has spaces. Extra logging. handle special cases.
  11. #100321 fuCNT fix. 100323 FLAGERR fix.
  12. #100324 Start firewall, change from button to checkbox.
  13. #100325 DHCPCDFIX option for wired.
  14. #100405 append last 10 lines of /var/log/messages to error log.
  15. #100413 attempt restart blinky_tray.
  16. #100513 more delay, repeat scan attempt.
  17. #100608 k2.6.27.47: anomaly, 'readlink /sys/class/net/$INTERFACE/device/driver' returns 'ath5k_pci' but module is 'ath5k'.
  18. #100608 have changed most xmessage displays to yaf-splash.
  19. #100703 extra flush seems to be needed when release interface.
  20. #101029 fix when no wireless networks found.
  21. #101118 bugfix, so network-disconnect works.
  22. #110203 improve scanning.
  23. #110505 support sudo for non-root user.
  24. #120107 gtkdialog3 to gtkdialog4, new 'Profile' frame in main window, new profiles help window.
  25. #120204 rodin.s: internationalized.
  26. #120222 small change to 'connect now' button.
  27. #120323 replace remaining 'xmessage' with 'pupmessage'.
  28. #120324 fix syntax error gettext.
  29. #121117 rerwin: add dropwait option to dhcpcd startup. see also rc.network.
  30. #130221 vertical scrollbar if more than 9 wireless networks found.
  31. export TEXTDOMAIN=sns___sns
  32. export OUTPUT_CHARSET=UTF-8
  33. . gettext.sh
  34. [ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505
  35. #each line of /etc/simple_network_setup/connections has everything known about a connection:
  36. #(please ignore spaces, put here for readability only)
  37. #Wireless:
  38. # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  39. #format: INTERFACE|IF_INTTYPE|IF_DRIVER|IF_BUS |IF_INFO |MACADDRESS |CELL_NUMBER|CELL_ADDRESS |CELL_CHANNEL|CELL_QUALITY|CELL_ENCRYPTIONKEY|CELL_ESSID|SEC_KEY |SEC_MGMT|ENCODEPROTO|WPA_DRIVER|DHCPCDFIX|
  40. #ex: wlan1 |Wireless |rt73usb |usb |Ralink RT73 USB Wireless LAN driver|00:26:19:F5:AC:3D|01 |00:17:3F:68:33:7E|11 |70/70 |on |belkin54g |000102030405060708090a0b0c|WEP | | |
  41. #Wired:
  42. # 1 2 3 4 5 6 7
  43. #format: INTERFACE|IF_INTTYPE|IF_DRIVER|IF_BUS |IF_INFO |MACADDRESS |DHCPCDFIX|
  44. #ex: eth0 |Wired |sky2 |pci |Marvell Yukon 2 Gigabit Ethernet driver|00:17:36:84:E5:1A| |
  45. ##find all the interfaces...
  46. #IF_NUM=`ifconfig -a | grep -Fc 'Link encap:Ethernet'`
  47. #if [ $IF_NUM -eq 0 ];then
  48. # xmessage -center -bg red "SORRY, CANNOT FIND ANY NETWORK INTERFACES"
  49. # exit
  50. #fi
  51. GTKDIALOGEXE="gtkdialog"
  52. [ "`which gtkdialog4`" ] && GTKDIALOGEXE="gtkdialog4"
  53. BIGGESTCNT=0
  54. echo -n '' > /tmp/sns_interfaces
  55. INTERFACES="`ifconfig -a | grep -F 'Link encap:Ethernet' | cut -f1 -d' ' | tr '\n' ' '`"
  56. for INTERFACE in $INTERFACES #exs: wlan0 eth0
  57. do
  58. IF_DRIVER="`readlink /sys/class/net/$INTERFACE/device/driver | rev | cut -f1 -d'/' | rev`" #ex: ath5k
  59. #fix k2.6.27.47 anomaly...
  60. [ "$IF_DRIVER" = "ath5k_pci" ] && [ "`lsmod | grep '^ath5k '`" != "" ] && IF_DRIVER='ath5k'
  61. dPATTERN="^$IF_DRIVER "
  62. WHATWEWANT="`grep "$dPATTERN" /etc/networkmodules | tr '|' '_' | tr '"' '|'`" #'geany
  63. IF_BUS="`echo -n "$WHATWEWANT" | cut -f 2 -d '|' | cut -f 1 -d ':'`" #ex: usb
  64. IF_INFO="`echo -n "$WHATWEWANT" | cut -f 2 -d '|' | tr -s ' ' | cut -f 2-29 -d ' '`" #ex: Ralink RT73 USB Wireless LAN driver
  65. [ "$IF_BUS" = "" ] && IF_BUS="x"
  66. [ "$IF_INFO" = "" ] && IF_INFO="x"
  67. if [ "$IF_DRIVER" == "ndiswrapper" ];then
  68. WINDRVR="`ndiswrapper -l | grep '^[a-zA-Z0-9]' | cut -f 1 -d ' '`"
  69. IF_INFO="MS Windows driver '${WINDRVR}'"
  70. FINDTYPE="`readlink /sys/class/net/$INTERFACE/device/driver`"
  71. if [ "$FINDTYPE" ];then
  72. case $FINDTYPE in
  73. */bus/usb*) IF_BUS="usb" ;;
  74. */bus/pci*) IF_BUS="pci" ;;
  75. esac
  76. fi
  77. fi
  78. #want to manipulate the info string for display purposes...
  79. CNTLINE=0;FINALINFO=""
  80. for ONEWORD in $IF_INFO
  81. do
  82. CNTWORD=`echo "$ONEWORD" | wc -c`
  83. CNTLINE=`expr $CNTLINE + $CNTWORD`
  84. [ $CNTLINE -gt $BIGGESTCNT ] && BIGGESTCNT=$CNTLINE #use for window width.
  85. [ $CNTLINE -gt 60 ] && break
  86. FINALINFO="${FINALINFO}${ONEWORD} " #ensures whole words only in string.
  87. done
  88. IF_INFO="`echo -n "$FINALINFO" | tr '[&|"<>]' ' ' | tr -s ' '`" #'geany. filter out chars that mess up xml.
  89. IF_INTTYPE='Wired'
  90. ePATTERN="${INTERFACE}:"
  91. [ "`grep "$ePATTERN" /proc/net/wireless`" != "" ] && IF_INTTYPE='Wireless'
  92. [ "$IF_DRIVER" = "prism2_usb" ] && IF_INTTYPE='Wireless'
  93. [ -d /sys/class/net/${INTERFACE}/wireless ] && IF_INTTYPE='Wireless'
  94. #accumulate the results into columns...
  95. ALL_IF_INTERFACE="${ALL_IF_INTERFACE}|${INTERFACE}"
  96. ALL_IF_INTTYPE="${ALL_IF_INTTYPE}|${IF_INTTYPE}"
  97. ALL_IF_DRIVER="${ALL_IF_DRIVER}|${IF_DRIVER}"
  98. ALL_IF_BUS="${ALL_IF_BUS}|${IF_BUS}"
  99. ALL_IF_INFO="${ALL_IF_INFO}|${IF_INFO}"
  100. INTERFACEBUTTONS="${INTERFACEBUTTONS}
  101. <button><label>${INTERFACE}</label><action type=\"exit\">Interface_${INTERFACE}</action></button>"
  102. #save all data about each interface on one line...
  103. #ex: wlan1|Wireless|ath5k|pci|Support for 5xxx series of Atheros 802.11 wireless LAN cards
  104. echo "${INTERFACE}|${IF_INTTYPE}|${IF_DRIVER}|${IF_BUS}|${IF_INFO}" >> /tmp/sns_interfaces
  105. done
  106. ALL_IF_INTERFACE="`echo -n "$ALL_IF_INTERFACE" | sed -e 's%^|%%' | tr '|' '\n'`"
  107. ALL_IF_INTTYPE="`echo -n "$ALL_IF_INTTYPE" | sed -e 's%^|%%' | tr '|' '\n'`"
  108. ALL_IF_DRIVER="`echo -n "$ALL_IF_DRIVER" | sed -e 's%^|%%' | tr '|' '\n'`"
  109. ALL_IF_BUS="`echo -n "$ALL_IF_BUS" | sed -e 's%^|%%' | tr '|' '\n'`"
  110. ALL_IF_INFO="`echo -n "$ALL_IF_INFO" | sed -e 's%^|%%' | tr '|' '\n'`"
  111. INTERFACEDESCR=" <hbox spacing=\"10\">
  112. <text use-markup=\"true\"><label>\"<b>$(gettext 'Interface')</b>
  113. $ALL_IF_INTERFACE\"</label></text>
  114. <text use-markup=\"true\"><label>\"<b>$(gettext 'Type')</b>
  115. $ALL_IF_INTTYPE\"</label></text>
  116. <text use-markup=\"true\"><label>\"<b>$(gettext 'Driver')</b>
  117. $ALL_IF_DRIVER\"</label></text>
  118. <text use-markup=\"true\"><label>\"<b>$(gettext 'Bus')</b>
  119. $ALL_IF_BUS\"</label></text>
  120. <text use-markup=\"true\"><label>\"<b>$(gettext 'Description')</b>
  121. $ALL_IF_INFO\"</label></text>
  122. </hbox>"
  123. #test if connected to internet...
  124. FLAGINTERNETSTATUS='no'
  125. WORKINGIF=''
  126. if [ "`pidof dhcpcd`" != "" ];then
  127. if [ "`grep -v '^#' /etc/resolv.conf`" != "" ];then
  128. PSALL="`ps`"
  129. PSDHCPCD="`echo "$PSALL" | grep 'dhcpcd'`"
  130. for ONEIF in `ifconfig | grep '^[a-z]' | cut -f 1 -d ' ' | grep -v '^lo' | tr '\n' ' '`
  131. do
  132. if [ "`echo "$PSDHCPCD" | grep "$ONEIF"`" != "" ];then
  133. WORKINGIF="${WORKINGIF}${ONEIF} "
  134. FLAGINTERNETSTATUS='yes'
  135. fi
  136. done
  137. fi
  138. fi
  139. if [ "$FLAGINTERNETSTATUS" == "yes" ];then
  140. WORKINGIF="`echo -n "$WORKINGIF" | sed -e 's% $%%'`"
  141. MSGWIF="interface '${WORKINGIF}'"
  142. [ `echo -n "$WORKINGIF" | wc -w` -gt 1 ] && MSGWIF="interfaces '${WORKINGIF}'"
  143. MSGSTATUS="<text use-markup=\"true\"><label>\"<b>$(gettext 'STATUS: Currently there is a working Internet connection, on') ${MSGWIF}</b>\"</label></text>"
  144. else
  145. MSGSTATUS="<text use-markup=\"true\"><label>\"<b>$(gettext 'STATUS: Currently there is no Internet connection')</b>\"</label></text>"
  146. fi
  147. CLICKMSG="<text><label>$(gettext 'Puppy has identified these network interfaces on your computer. Click a button to configure the interface for use:')</label></text>"
  148. #100313 add a button for loading a Windows driver...
  149. if [ "`echo "$ALL_IF_DRIVER" | grep 'ndiswrapper'`" == "" ];then
  150. CLICKMSG="<text><label>`gettext \"Puppy has identified these network interfaces on your computer. Click a button to configure the interface for use, or click 'Windows' button if you want to install and use a MS Windows driver:\"`</label></text>"
  151. INTERFACEBUTTONS="${INTERFACEBUTTONS}
  152. <button><label>Windows</label><action type=\"exit\">Interface_Windows</action></button>"
  153. fi
  154. # <text><label>Find out stuff about what is currently working (if anything)</label></text>
  155. #120107 new 'Profile' frame...
  156. PROFILE_XML=""
  157. echo "<b>$(gettext 'Interface')</b>" >/tmp/sns_I_P; echo "<b>$(gettext 'Type')</b>" >/tmp/sns_T_P; echo "<b>$(gettext 'Driver')</b>" >/tmp/sns_D_P; echo "<b>$(gettext 'Bus')</b>" >/tmp/sns_B_P; echo "<b>$(gettext 'Hardware')</b>" >/tmp/sns_M_P; echo "" >/tmp/sns_S_P; echo "" >/tmp/sns_DEL_BTN; echo "" >/tmp/sns_CNT_P; echo "<b>$(gettext 'Security')</b>" >/tmp/sns_SEC_P
  158. if [ -s /etc/simple_network_setup/connections ];then
  159. CNT=0
  160. [ "grep '|Wireless|' /etc/simple_network_setup/connections" != "" ] && echo "<b>$(gettext 'Network')</b>" >/tmp/sns_S_P
  161. cat /etc/simple_network_setup/connections |
  162. while read ONECONNECTION
  163. do
  164. CNT=$(($CNT + 1))
  165. echo "<b>$CNT</b>" >> /tmp/sns_CNT_P
  166. INTERFACE_P="`echo -n "$ONECONNECTION" | cut -f 1 -d '|'`"
  167. echo "$INTERFACE_P" >> /tmp/sns_I_P
  168. TYPE_P="`echo -n "$ONECONNECTION" | cut -f 2 -d '|'`"
  169. echo "$TYPE_P" >> /tmp/sns_T_P
  170. DRIVER_P="`echo -n "$ONECONNECTION" | cut -f 3 -d '|'`"
  171. echo "$DRIVER_P" >> /tmp/sns_D_P
  172. BUS_P="`echo -n "$ONECONNECTION" | cut -f 4 -d '|'`"
  173. echo "$BUS_P" >> /tmp/sns_B_P
  174. MAC_P="`echo -n "$ONECONNECTION" | cut -f 6 -d '|'`"
  175. echo "$MAC_P" >> /tmp/sns_M_P
  176. if [ "$TYPE_P" = "Wireless" ];then
  177. SSID_P="`echo -n "$ONECONNECTION" | cut -f 12 -d '|'`"
  178. echo "$SSID_P" >> /tmp/sns_S_P
  179. SEC_P="`echo -n "$ONECONNECTION" | cut -f 14 -d '|'`"
  180. [ "$SEC_P" = "" ] && SEC_P="none"
  181. echo "$SEC_P" >> /tmp/sns_SEC_P
  182. else
  183. echo "" >> /tmp/sns_S_P
  184. echo "" >> /tmp/sns_SEC_P
  185. fi
  186. if [ $CNT -gt 12 ];then
  187. echo "<i>more...</i>" >> /tmp/sns_I_P
  188. break
  189. fi
  190. echo "<button><label>${CNT}</label><action>grep -v '${ONECONNECTION}' /etc/simple_network_setup/connections > /tmp/sns_action1</action><action>mv -f /tmp/sns_action1 /etc/simple_network_setup/connections</action><action type=\"exit\">EXITRESTART></action></button>" >> /tmp/sns_DEL_BTN
  191. done
  192. if [ "$FLAGINTERNETSTATUS" = "yes" ];then
  193. CONNECTBTN_XML="<button><label>$(gettext 'DISCONNECT NOW')</label><action>/usr/sbin/networkdisconnect</action><action type=\"exit\">EXITNOW</action></button>"
  194. else
  195. CONNECTBTN_XML="<button><label>$(gettext 'CONNECT NOW')</label><action>/usr/sbin/networkdisconnect</action><action>/usr/local/simple_network_setup/rc.network start & </action><action>yaf-splash -timeout 2 -bg orange -close never -fontsize large -text \"Please wait...\"</action><action type=\"exit\">EXITNOW</action></button>"
  196. fi
  197. PROFILE_XML="<frame $(gettext 'Profiles')>
  198. <text><label>$(gettext 'Connection profiles have previously been created with SNS. These are:')</label></text>
  199. <hbox spacing=\"10\"><text use-markup=\"true\"><label>\"`cat /tmp/sns_CNT_P`\"</label></text><text use-markup=\"true\"><label>\"`cat /tmp/sns_I_P`\"</label></text><text use-markup=\"true\"><label>\"`cat /tmp/sns_T_P`\"</label></text><text use-markup=\"true\"><label>\"`cat /tmp/sns_D_P`\"</label></text><text use-markup=\"true\"><label>\"`cat /tmp/sns_B_P`\"</label></text><text use-markup=\"true\"><label>\"`cat /tmp/sns_M_P`\"</label></text><text use-markup=\"true\"><label>\"`cat /tmp/sns_S_P`\"</label></text><text use-markup=\"true\"><label>\"`cat /tmp/sns_SEC_P`\"</label></text></hbox>
  200. <hbox><text><label>$(gettext 'Delete:')</label></text>`cat /tmp/sns_DEL_BTN`
  201. <text><label>\" \"</label></text>
  202. ${CONNECTBTN_XML}
  203. <hbox><button><input file>/usr/local/lib/X11/mini-icons/mini-question.xpm</input><action>/usr/local/simple_network_setup/help_profiles & </action></button></hbox>
  204. </hbox>
  205. </frame>"
  206. fi
  207. #bring up the main window...
  208. export WIN1_DLG="<window title=\"$(gettext 'Simple Network Setup')\" icon-name=\"gtk-network\" resizable=\"false\">
  209. <vbox>
  210. <text use-markup=\"true\"><label>\"<b>`gettext \"Welcome to Barry's Simple Network Setup!\"`</b>\"</label></text>
  211. <frame $(gettext 'Current status')>
  212. ${MSGSTATUS}
  213. <hbox>
  214. <text><label>$(gettext 'Detailed network interface Information:')</label></text>
  215. <button><input file>/usr/local/lib/X11/mini-icons/info16.xpm</input><action>ipinfo & </action></button>
  216. </hbox>
  217. </frame>
  218. ${PROFILE_XML}
  219. <frame $(gettext 'Interfaces')>
  220. ${CLICKMSG}
  221. ${INTERFACEDESCR}
  222. <hbox>${INTERFACEBUTTONS}</hbox>
  223. </frame>
  224. </vbox>
  225. </window>"
  226. RETSTRING="`${GTKDIALOGEXE} --program=WIN1_DLG --center`" ###main window###
  227. echo "$RETSTRING"
  228. EXIT="`echo "$RETSTRING" | grep '^EXIT' | cut -f2 -d'"'`" #'geany
  229. [ "`echo "$EXIT" | grep 'EXITRESTART'`" != "" ] && exec sns ###restarting sns###
  230. [ "`echo "$EXIT" | grep 'Interface'`" = "" ] && exit
  231. INTERFACE="`echo -n "$EXIT" | cut -f2 -d '_'`" #ex: wlan1
  232. if [ "$INTERFACE" == "Windows" ];then #100313
  233. if [ -d /etc/ndiswrapper ];then
  234. if [ "`ls /etc/ndiswrapper/*/*.inf 2>/dev/null`" != "" ];then
  235. modprobe ndiswrapper
  236. sleep 1
  237. exec sns
  238. fi
  239. fi
  240. export NDISWRAPPER_DLG="<window title=\"$(gettext 'SNS: Install MS Windows driver')\" icon-name=\"gtk-network\">
  241. <vbox>
  242. <pixmap><input file>/usr/local/lib/X11/mini-icons/mini.win95.xpm</input></pixmap>
  243. <text><label>\"`gettext \"Select the '.inf' file of the required MS Windows driver. If on a CD, you will have to mount it, then navigate to where the '.inf' file is. Note, choose a Windows XP driver if available...\"`\"</label></text>
  244. <text><label>\" \"</label></text>
  245. <chooser>
  246. <height>300</height><width>550</width>
  247. <variable>INF_FILE_NAME</variable>
  248. </chooser>
  249. <hbox>
  250. <button ok></button>
  251. <button cancel></button>
  252. </hbox>
  253. </vbox>
  254. </window>"
  255. RETSTRND="`${GTKDIALOGEXE} --program=NDISWRAPPER_DLG`"
  256. if [ "`echo "$RETSTRND" | grep '^EXIT' | grep 'OK'`" != "" ];then
  257. INFFILE="`echo "$RETSTRND" | grep '^INF_FILE_NAME' | cut -f 2 -d '"'`" #'geany
  258. case "$INFFILE" in
  259. *.[iI][nN][fF])
  260. FLAGND=""
  261. ndiswrapper -i "$INFFILE" #installs driver at /etc/ndiswrapper.
  262. if [ $? -eq 0 ];then
  263. ndiswrapper -l #tests the driver
  264. if [ $? -eq 0 ];then
  265. modprobe ndiswrapper
  266. [ $? -eq 0 ] && FLAGND="ok"
  267. [ "$FLAGND" != "ok" ] && rmmod ndiswrapper 2>/dev/null
  268. fi
  269. fi
  270. [ "$FLAGND" != "ok" ] && rm -rf /etc/ndiswrapper
  271. [ "$FLAGND" != "ok" ] && pupmessage -center -bg red "$(gettext 'ERROR: Windows driver does not seem to work, it has been uninstalled')"
  272. [ "$FLAGND" == "ok" ] && sleep 1
  273. ;;
  274. *)
  275. pupmessage -center -bg red "`eval_gettext \"ERROR, \\\${INFFILE} is not a .inf file\"`"
  276. ;;
  277. esac
  278. fi
  279. exec sns
  280. fi
  281. ifPATTERN='^'"$INTERFACE"' '
  282. if [ "`ifconfig | grep "$ifPATTERN"`" != "" ];then
  283. #xmessage -center -bg orange -buttons "" "Please wait, bringing down '$INTERFACE'..." &
  284. yaf-splash -bg orange -placement center -text "$(gettext 'Please wait, bringing down') '$INTERFACE'..." &
  285. PIDX1=$!
  286. ifconfig $INTERFACE down
  287. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  288. iwconfig $INTERFACE key off #100320 think need this for when I'm experimenting with different wep/wpa/open settings on the same interface.
  289. #killall dhcpcd
  290. dhcpcd --release $INTERFACE 2>/dev/null
  291. ip route flush dev $INTERFACE #100703
  292. sleep 1
  293. kill $PIDX1
  294. fi
  295. fPATTERN='^'"${INTERFACE}"'|'
  296. IFDATA="`grep "$fPATTERN" /tmp/sns_interfaces`"
  297. IF_INTTYPE="`echo "$IFDATA" | cut -f2 -d'|'`" #ex: Wireless
  298. IF_DRIVER="`echo "$IFDATA" | cut -f3 -d'|'`" #ex: ath5k
  299. IF_BUS="`echo "$IFDATA" | cut -f4 -d'|'`" #ex: pci
  300. IF_INFO="`echo "$IFDATA" | cut -f5 -d'|'`"
  301. MACADDRESS="`ifconfig $INTERFACE | grep -o 'HWaddr .*' | cut -f 2 -d ' '`"
  302. ############WIRELESS SETUP###############
  303. if [ "$IF_INTTYPE" == "Wireless" ];then
  304. #scan for networks...
  305. FLAGERR=
  306. rm -f /tmp/sns_scan_radiobuttons
  307. rm -f /tmp/sns_scan_rawoneline
  308. rm -f /tmp/sns_scan_oneline
  309. #xmessage -center -bg orange -buttons "" "Please wait, scanning for wireless networks..." &
  310. yaf-splash -placement center -bg orange -text "$(gettext 'Please wait, scanning for wireless networks...')" &
  311. PIDXMSG=$!
  312. echo "Information about this interface:
  313. Interface: $INTERFACE Driver: $IF_DRIVER Bus: $IF_BUS MacAddress: $MACADDRESS
  314. Description: $IF_INFO
  315. " > /tmp/sns_wireless_log
  316. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  317. echo "STEP1a: ifconfig $INTERFACE up" >> /tmp/sns_wireless_log
  318. ifconfig $INTERFACE up >> /tmp/sns_wireless_log 2>&1
  319. if [ $? -ne 0 ];then
  320. FLAGERR=1
  321. else
  322. sleep 2 #100513 increase from 1.
  323. echo "STEP1b: iwlist $INTERFACE scan" >> /tmp/sns_wireless_log
  324. SCANRESULT="`iwlist $INTERFACE scan`" ###SCANNING### 110203
  325. if [ "`echo "$SCANRESULT" | grep 'Scan completed'`" = "" ];then #100513 110203
  326. sleep 2
  327. SCANRESULT="`iwlist $INTERFACE scan`" ###SCANNING### 110203
  328. fi
  329. echo "$SCANRESULT" >> /tmp/sns_wireless_log
  330. echo "STEP1c: ifconfig $INTERFACE down" >> /tmp/sns_wireless_log
  331. ifconfig $INTERFACE down #100313
  332. #convert each found network into a single line... 110203
  333. SRLINES="`echo "$SCANRESULT" | grep -v 'Scan completed' | tr '|' ' ' | tr '\n' '|' | sed -e 's% Cell %\n%g' | tr -s ' '`"
  334. echo "$SRLINES" |
  335. while read ONELINE
  336. do
  337. [ "$ONELINE" = "" ] && continue
  338. [ "$ONELINE" = " " ] && continue
  339. [ "`echo -n "$ONELINE" | grep 'No scan results'`" != "" ] && continue #101029
  340. [ "`echo -n "$ONELINE" | grep ' ESSID:'`" = "" ] && continue #101029
  341. CELL_NUMBER="`echo -n "$ONELINE" | cut -f1 -d' '`"
  342. CELL_ADDRESS="`echo -n "$ONELINE" | grep -o ' Address: .*' | cut -f 3 -d ' ' | cut -f1 -d '|'`"
  343. CELL_CHANNEL="`echo -n "$ONELINE" | grep -o ' Channel:.*' | cut -f2 -d':' | cut -f1 -d'|'`"
  344. [ "$CELL_CHANNEL" == "" ] && CELL_CHANNEL="`echo -n "$ONELINE" | grep -o ' (Channel .*' | cut -f 3 -d ' ' | cut -f 1 -d')'`"
  345. CELL_QUALITY="`echo -n "$ONELINE" | grep -o ' Quality[:=].*' | cut -f 2 -d ' ' | cut -f 2 -d '=' | cut -f 2 -d ':'`"
  346. CELL_ESSID="`echo -n "$ONELINE" | grep -o ' ESSID:.*' | cut -f 2 -d '"'`" #'geany
  347. CELL_ENCRYPTIONKEY="`echo -n "$ONELINE" | grep -o 'Encryption key:.*' | cut -f 2 -d ':' | cut -f1 -d '|'`" #ex: off
  348. CELLMSG="Name: $CELL_ESSID Encryption: $CELL_ENCRYPTIONKEY Strength: $CELL_QUALITY"
  349. echo "<radiobutton><label>${CELLMSG}</label><variable>RADIO_${CELL_NUMBER}</variable></radiobutton>" >> /tmp/sns_scan_radiobuttons
  350. echo "$ONELINE" >> /tmp/sns_scan_rawoneline
  351. echo "${CELL_NUMBER}|${CELL_ADDRESS}|${CELL_CHANNEL}|${CELL_QUALITY}|${CELL_ENCRYPTIONKEY}|${CELL_ESSID}" >> /tmp/sns_scan_oneline
  352. done
  353. #my wpa_supplicant only supports: wext hostap atmel wired ralink roboswitch
  354. case $IF_DRIVER in
  355. hostap*) WPA_DRIVER="hostap" ;;
  356. rt61|rt73) WPA_DRIVER="ralink" ;;
  357. *) WPA_DRIVER="wext" ;;
  358. esac
  359. if [ ! -f /tmp/sns_scan_radiobuttons ];then
  360. FRAME1="<frame $(gettext 'Wireless networks')><text><label>\" \"</label></text><text><label>$(gettext 'No wireless networks found')</label></text></frame><text><label>\" \"</label></text>"
  361. FRAME2=""
  362. WIN2MSG1=""
  363. WIN2BUT1=""
  364. else
  365. WIN2MSG1="<text><label>`gettext \"Choose which network you want to use, type of encryption, then click 'CONNECT' button:\"`</label></text>"
  366. RADIOBUTTONS="`cat /tmp/sns_scan_radiobuttons`"
  367. if [ `cat /tmp/sns_scan_radiobuttons | wc -l` -lt 12 ];then #130221
  368. FRAME1="<frame $(gettext 'Wireless networks')><text><label>\" \"</label></text>${RADIOBUTTONS}<text><label>\" \"</label></text></frame>"
  369. else
  370. #130221 vertical scrollbar...
  371. FRAME1="<frame $(gettext 'Wireless networks')><vbox scrollable=\"true\" height=\"250\" width-request=\"450\" width=\"450\">
  372. <text><label>\" \"</label></text>${RADIOBUTTONS}<text><label>\" \"</label></text>
  373. </vbox></frame>"
  374. fi
  375. FRAME2="<frame $(gettext 'Encryption')>
  376. <hbox>
  377. <vbox>
  378. <radiobutton><label>$(gettext 'none')</label><variable>BUTSEC_NONE</variable></radiobutton>
  379. <radiobutton><label>WEP</label><variable>BUTSEC_WEP</variable></radiobutton>
  380. <radiobutton><label>WPA</label><variable>BUTSEC_WPAPSK</variable></radiobutton>
  381. </vbox>
  382. <text><label>\" \"</label></text>
  383. <vbox>
  384. <hbox><text><label>$(gettext 'Key:')</label></text><entry><variable>BOX_KEY</variable></entry></hbox>
  385. <hbox><button><label>$(gettext 'HELP')</label><action>/usr/local/simple_network_setup/help_security & </action></button></hbox>
  386. </vbox>
  387. </hbox>
  388. </frame>"
  389. WIN2BUT1="<button><label>$(gettext 'CONNECT')</label><action type=\"exit\">BUT_CONNECT</action></button>"
  390. fi
  391. kill $PIDXMSG ; PIDXMSG=""
  392. export WIN2_DLG="<window title=\"$(gettext 'Simple Network Setup')\" icon-name=\"gtk-network\">
  393. <vbox>
  394. ${FRAME1}
  395. ${FRAME2}
  396. ${WIN2MSG1}
  397. <hbox>
  398. ${WIN2BUT1}
  399. <button><label>$(gettext 'GO BACK TO MAIN WINDOW')</label><action type=\"exit\">BUT_GOBACK</action></button>
  400. </hbox>
  401. </vbox>
  402. </window>"
  403. RETSTRING="`${GTKDIALOGEXE} --program=WIN2_DLG --center`"
  404. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_GOBACK'`" != "" ] && exec sns
  405. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_CONNECT'`" == "" ] && exit
  406. SEC_MGMT=""; WPA_ENC=""
  407. SEC_KEY="`echo "$RETSTRING" | grep '^BOX_KEY' | cut -f 2 -d '"' | tr -d '-'`" #'geany
  408. BUTSEC="`echo "$RETSTRING" | grep '^BUTSEC_' | grep 'true' | cut -f 1 -d '=' | cut -f 2 -d '_'`"
  409. case $BUTSEC in
  410. WEP) SEC_MGMT="WEP"; WPA_ENC="" ;;
  411. WPAPSK) SEC_MGMT="WPA-PSK"; WPA_ENC="" ;;
  412. WPAPSKTKIP) SEC_MGMT="WPA-PSK"; WPA_ENC="TKIP" ;;
  413. WPAPSKAES) SEC_MGMT="WPA-PSK"; WPA_ENC="AES" ;;
  414. WPA2PSKAES) SEC_MGMT="WPA2-PSK"; WPA_ENC="AES" ;;
  415. *) SEC_KEY="" ;; #no encryption.
  416. esac
  417. CELL_NUMBER="`echo "$RETSTRING" | grep '^RADIO' | grep 'true' | cut -f1 -d'=' | cut -f2 -d'_'`" #ex: 01
  418. cnPATTERN='^'"$CELL_NUMBER"'|'
  419. CELLDATA="`grep "$cnPATTERN" /tmp/sns_scan_oneline`"
  420. CELL_ADDRESS="`echo -n "$CELLDATA" | cut -f2 -d'|'`"
  421. CELL_CHANNEL="`echo -n "$CELLDATA" | cut -f3 -d'|'`"
  422. CELL_QUALITY="`echo -n "$CELLDATA" | cut -f4 -d'|'`"
  423. CELL_ENCRYPTIONKEY="`echo -n "$CELLDATA" | cut -f5 -d'|'`"
  424. CELL_ESSID="`echo -n "$CELLDATA" | cut -f6 -d'|'`"
  425. if [ "$CELL_ENCRYPTIONKEY" == "on" ];then
  426. [ "$SEC_KEY" == "" ] && FLAGERR=2
  427. [ "$SEC_MGMT" == "" ] && FLAGERR=3
  428. fi
  429. if [ ! $FLAGERR ];then
  430. #xmessage -center -bg orange -buttons "" "Please wait, attempting to connect to '${CELL_ESSID}'..." &
  431. yaf-splash -placement center -bg orange -text "$(gettext 'Please wait, attempting to connect to') '${CELL_ESSID}'..." &
  432. PIDX=$!
  433. echo "STEP2: iwconfig $INTERFACE mode managed" >> /tmp/sns_wireless_log
  434. iwconfig $INTERFACE mode managed >> /tmp/sns_wireless_log 2>&1
  435. echo "STEP3: iwconfig $INTERFACE channel $CELL_CHANNEL" >> /tmp/sns_wireless_log
  436. iwconfig $INTERFACE channel $CELL_CHANNEL >> /tmp/sns_wireless_log 2>&1
  437. echo "STEP4: iwconfig $INTERFACE essid \"$CELL_ESSID\"" >> /tmp/sns_wireless_log
  438. iwconfig $INTERFACE essid "$CELL_ESSID" >> /tmp/sns_wireless_log 2>&1
  439. #test essid is associated...
  440. if [ $? -ne 0 ];then
  441. FLAGERR=4
  442. else
  443. RUNWPASUPP='no'
  444. [ -f "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}" ] && rm -f "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}"
  445. FIXUP='1 1 2 0'
  446. [ "$IF_DRIVER" = "ndiswrapper" ] && FIXUP='2 1 0'
  447. [ "$BUTSEC" = "WEP" ] && FIXUP='restricted open'
  448. fuCNT=`echo -n "$FIXUP" | wc -w`
  449. fuCNT=$(($fuCNT + 1)) #100321 bug fix.
  450. for ONEFIX in $FIXUP ###BIG FOR LOOP###
  451. do
  452. FLAGERR= #100323
  453. fuCNT=$(($fuCNT - 1))
  454. if [ "$CELL_ENCRYPTIONKEY" == "on" ];then
  455. case $BUTSEC in
  456. WEP)
  457. echo "STEP5: iwconfig $INTERFACE key $ONEFIX $SEC_KEY" >> /tmp/sns_wireless_log
  458. iwconfig $INTERFACE key $ONEFIX $SEC_KEY
  459. ;;
  460. WPAPSK) #very simple, handles all ciphers.
  461. #it works psk="passphrase" (with quotes), but for security encode psk into hex string...
  462. hexSEC_KEY=`wpa_passphrase "$CELL_ESSID" $SEC_KEY | grep '[^#]psk=' | cut -f 2 -d '='`
  463. echo "ctrl_interface=/var/run/wpa_supplicant
  464. ap_scan=${ONEFIX}
  465. network={
  466. ssid=\"${CELL_ESSID}\"
  467. key_mgmt=${SEC_MGMT}
  468. psk=${hexSEC_KEY}
  469. }" > "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}"
  470. RUNWPASUPP='yes'
  471. if [ "`pidof wpa_supplicant`" != "" ];then
  472. wpa_cli terminate
  473. killall wpa_supplicant
  474. fi
  475. ;;
  476. WPA*)
  477. #it works psk="passphrase" (with quotes), but for security encode psk into hex string...
  478. hexSEC_KEY=`wpa_passphrase "$CELL_ESSID" $SEC_KEY | grep '[^#]psk=' | cut -f 2 -d '='`
  479. echo "ctrl_interface=/var/run/wpa_supplicant
  480. ap_scan=${ONEFIX}
  481. network={
  482. ssid=\"${CELL_ESSID}\"
  483. proto=WPA
  484. key_mgmt=${SEC_MGMT}
  485. pairwise=${WPA_ENC}
  486. group=${WPA_ENC}
  487. psk=${SEC_KEY}
  488. wpa_ptk_rekey=600
  489. }" > "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}"
  490. RUNWPASUPP='yes'
  491. if [ "`pidof wpa_supplicant`" != "" ];then
  492. wpa_cli terminate #kills any running wpa_supplicant. no it doesn't, just brings down interface.
  493. killall wpa_supplicant
  494. fi
  495. ;;
  496. esac
  497. fi
  498. echo "STEP5a: ifconfig $INTERFACE up" >> /tmp/sns_wireless_log
  499. ifconfig $INTERFACE up
  500. if [ "$RUNWPASUPP" = "yes" ];then
  501. echo "STEP5b: wpa_supplicant -B -D${WPA_DRIVER} -i${INTERFACE} -c\"/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}\"" >> /tmp/sns_wireless_log
  502. wpa_supplicant -B -D${WPA_DRIVER} -i${INTERFACE} -c"/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}" >> /tmp/sns_wireless_log 2>&1
  503. wCNT=0
  504. while [ 1 ];do
  505. [ "`wpa_cli -i $INTERFACE status | grep '^bssid=[0-9a-f]'`" != "" ] && break
  506. sleep 1
  507. wCNT=`expr $wCNT + 1`
  508. if [ $wCNT -gt 20 ];then
  509. echo "Running: wpa_cli -i ${INTERFACE} status" >> /tmp/sns_wireless_log
  510. wpa_cli -i $INTERFACE status >> /tmp/sns_wireless_log 2>&1
  511. #FLAGERR=5
  512. #100314 http://wiki.archlinux.org/index.php/WPA_supplicant has following advice...
  513. #really weird, works for my wg311 ndiswrapper driver. but must have the ap_scan sequence 2 1 0...
  514. #ignore error, do this instead...
  515. killall -SIGHUP wpa_supplicant
  516. iwconfig $INTERFACE essid "$CELL_ESSID"
  517. break
  518. fi
  519. done
  520. fi
  521. if [ $FLAGERR ];then
  522. #if [ "$RUNWPASUPP" == "yes" ];then
  523. if [ $fuCNT -ne 0 ];then
  524. kill $PIDX
  525. case $fuCNT in
  526. 1) BGCOLOR="HotPink" ;;
  527. 2) BGCOLOR="pink" ;;
  528. *) BGCOLOR="DeepPink" ;;
  529. esac
  530. #xmessage -center -bg $BGCOLOR -buttons "" "Please keep waiting, retrying encrypted connection..." &
  531. yaf-splash -placement center -bg $BGCOLOR -text "$(gettext 'Please keep waiting, retrying encrypted connection...')" &
  532. PIDX=$!
  533. continue #try next FIXUP value (see for-loop above). ###BIG FOR LOOP###
  534. fi
  535. #fi
  536. if [ "`pidof wpa_supplicant`" != "" ];then
  537. wpa_cli terminate
  538. killall wpa_supplicant
  539. fi
  540. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  541. ifconfig $INTERFACE down
  542. else
  543. #wait until access point becomes available...
  544. sCNT=0
  545. while [ 1 ];do
  546. TESTAP="`iwconfig ${INTERFACE} | grep -o 'Access Point: .*' | tr -s ' ' | cut -f 3 -d ' ' | sed -e 's%[^:]%%g'`"
  547. [ "`echo -n "$TESTAP" | grep '::::'`" != "" ] && break
  548. sleep 1
  549. sCNT=`expr $sCNT + 1`
  550. if [ $sCNT -gt 20 ];then
  551. echo "" >> /tmp/sns_wireless_log #100320
  552. echo "ERROR, TIMEOUT. Have not got an Access Point." >> /tmp/sns_wireless_log #100320
  553. echo "Result of 'iwconfig ${INTERFACE}':" >> /tmp/sns_wireless_log #100320
  554. iwconfig ${INTERFACE} >> /tmp/sns_wireless_log 2>&1 #100320
  555. echo "" >> /tmp/sns_wireless_log #100320
  556. FLAGERR=7
  557. break
  558. fi
  559. done
  560. if [ $FLAGERR ];then
  561. #if [ "$RUNWPASUPP" == "yes" ];then
  562. if [ $fuCNT -ne 0 ];then
  563. kill $PIDX
  564. case $fuCNT in
  565. 1) BGCOLOR="HotPink" ;;
  566. 2) BGCOLOR="pink" ;;
  567. *) BGCOLOR="DeepPink" ;;
  568. esac
  569. #xmessage -center -bg $BGCOLOR -buttons "" "Please keep waiting, retrying encrypted connection..." &
  570. yaf-splash -placement center -bg $BGCOLOR -text "$(gettext 'Please keep waiting, retrying encrypted connection...')" &
  571. PIDX=$!
  572. continue #try next FIXUP parameter (see for-loop above). ###BIG FOR LOOP###
  573. fi
  574. #fi
  575. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  576. ifconfig $INTERFACE down
  577. else
  578. #finally, run dhcpcd...
  579. MODTIME1="`stat --format=%Y /etc/resolv.conf`"
  580. for iterDHCPCD in a b #100320
  581. do
  582. [ "$iterDHCPCD" = "a" ] && DHCPCDFIX=""
  583. [ "$iterDHCPCD" = "b" ] && DHCPCDFIX="-I ''" #some dhcp servers require empty Client ID (default is macaddress).
  584. echo "STEP6${iterDHCPCD}: dhcpcd $DHCPCDFIX $INTERFACE" >> /tmp/sns_wireless_log
  585. dhcpcd $DHCPCDFIX $(dhcpcd_dropwait_option) $INTERFACE >> /tmp/sns_wireless_log 2>&1 ####DHCP CLIENT#### 121117
  586. mCNT=0
  587. while [ 1 ];do
  588. MODTIME2="`stat --format=%Y /etc/resolv.conf`"
  589. [ "$MODTIME2" != "$MODTIME1" ] && break 2
  590. sleep 1
  591. mCNT=`expr $mCNT + 1`
  592. if [ $mCNT -gt 20 ];then
  593. [ "$iterDHCPCD" != "b" ] && dhcpcd --release $INTERFACE
  594. break
  595. fi
  596. done
  597. done
  598. [ "$MODTIME2" == "$MODTIME1" ] && FLAGERR=6
  599. [ "`grep -v '^#' /etc/resolv.conf`" == "" ] && FLAGERR=6
  600. if [ $FLAGERR ];then
  601. if [ "`pidof wpa_supplicant`" != "" ];then
  602. wpa_cli terminate
  603. killall wpa_supplicant
  604. fi
  605. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  606. ifconfig $INTERFACE down
  607. dhcpcd --release $INTERFACE 2>/dev/null
  608. ip route flush dev $INTERFACE #100703
  609. else
  610. #success!
  611. echo "$INTERFACE" > /tmp/sns_interface_success #101118
  612. #100413 have one pc where blinky did not start. try again...
  613. [ "`which blinky_tray`" ] && [ "`pidof blinky_tray`" = "" ] && blinky_tray &
  614. essidPATTERN='|'"$CELL_ESSID"'|'
  615. touch /etc/simple_network_setup/connections
  616. grep -v "$essidPATTERN" /etc/simple_network_setup/connections > /tmp/sns_temp2
  617. mv -f /tmp/sns_temp2 /etc/simple_network_setup/connections
  618. case $SEC_MGMT in
  619. WEP) ENCODEPROTO="$ONEFIX"; WPA_DRIVER="" ;; #exs: restricted, open
  620. *) ENCODEPROTO="$WPA_ENC" ;; #exs: AES, TKIP
  621. esac
  622. echo "${IFDATA}|${MACADDRESS}|${CELLDATA}|${SEC_KEY}|${SEC_MGMT}|${ENCODEPROTO}|${WPA_DRIVER}|${DHCPCDFIX}|" >> /etc/simple_network_setup/connections
  623. MSGFIREWALL=""
  624. CHKFIREWALL=""
  625. if [ ! -f /etc/rc.d/rc.firewall ];then
  626. MSGFIREWALL="<text><label>`gettext \"However, there is one item of recommended housekeeping: you really should be running a firewall. Puppy is inherently secure, however a firewall will give you that extra protection while online. Recommend that you tick the 'Start firewall' checkbox (the firewall will install and will automatically run at all future boots)...\"`</label></text>"
  627. CHKFIREWALL="<checkbox><label>$(gettext 'Start firewall')</label><default>true</default><variable>CHK_FIREWALL</variable></checkbox>"
  628. fi
  629. kill $PIDX
  630. export WIN3_DLG="<window title=\"$(gettext 'SNS: Simple Network Setup')\" icon-name=\"gtk-network\">
  631. <vbox>
  632. <pixmap><input file>/usr/local/lib/X11/pixmaps/ok.xpm</input></pixmap>
  633. <text><label>$(gettext 'Successful connection to wireless network') '${CELL_ESSID}'!</label></text>
  634. <text><label>$(gettext 'Your Internet should now be working!')</label></text>
  635. ${MSGFIREWALL}
  636. ${CHKFIREWALL}
  637. <text><label>`gettext \"Recommend leave this checkbox ticked, so that Puppy will use SNS to automatically connect to the Internet at bootup. Also clicking the 'connect' icon on the desktop will immediately launch SNS...\"`</label></text>
  638. <checkbox><label>$(gettext 'Set SNS as default network setup tool')</label><default>true</default><variable>CHK_SNSDEF</variable></checkbox>
  639. <hbox>
  640. <button ok></button>
  641. </hbox>
  642. </vbox>
  643. </window>"
  644. RETSTR3="`${GTKDIALOGEXE} --program=WIN3_DLG --center`"
  645. if [ "`echo "$RETSTR3" | grep '^CHK_SNSDEF' | grep 'true'`" != "" ];then
  646. echo -e '#!/bin/sh\nexec sns' > /usr/local/bin/defaultconnect
  647. else
  648. echo -e '#!/bin/sh\nexec connectwizard' > /usr/local/bin/defaultconnect
  649. fi
  650. if [ "`echo "$RETSTR3" | grep '^CHK_FIREWALL' | grep 'true'`" != "" ];then
  651. rxvt -e firewallinstallshell
  652. fi
  653. fi #end test dhcpcd timeout.
  654. fi #end test access point.
  655. fi #end test wpa_supplicant timeout.
  656. break
  657. done #end for-loop. ###END BIG FOR LOOP###
  658. fi #end test associate essid.
  659. fi #end test exist security entries.
  660. fi #end test ifconfig up
  661. if [ $FLAGERR ];then
  662. [ $PIDXMSG ] && kill $PIDXMSG
  663. [ $PIDX ] && kill $PIDX
  664. case $SEC_MGMT in
  665. WPA*) ERR_EXTRA1="$(gettext 'Note: the network card and/or Linux driver might not support WPA2, in which case you will need to set the wireless router to WPA. Or, WPA might not be supported at all, in which case you will have to set the router and network card to use WEP.')" ;;
  666. *) ERR_EXTRA1="" ;;
  667. esac
  668. case $FLAGERR in
  669. 1) ERR_MSG="`eval_gettext \"Failed to activate interface '\\\${INTERFACE}. Sometimes this is just a temporary problem. Go back to the main window, and you can try again...\"`" ; ERR_EXTRA1="" ;;
  670. 2) ERR_MSG="$(gettext 'ERROR: you did not specify a Key')" ; ERR_EXTRA1="" ;;
  671. 3) ERR_MSG="$(gettext 'ERROR: you need to choose WEP or WPA security')" ; ERR_EXTRA1="" ;;
  672. 4) ERR_MSG="`eval_gettext \"Failed to associate '\\\${CELL_ESSID}' with ESSID.\"`"; ERR_EXTRA1="" ;;
  673. 7) ERR_MSG="$(gettext 'Failed to obtain Access Point of network.')"; ERR_EXTRA1="" ;;
  674. 5) ERR_MSG="$(gettext 'wpa_supplicant has timed out trying to associate with the network card.')" ;;
  675. 6) ERR_MSG="$(gettext 'DHCP client failed to negotiate with wireless network') '${CELL_ESSID}'" ;;
  676. *) ERR_MSG="$(gettext 'Failed to connect to wireless network') '${CELL_ESSID}'" ;;
  677. esac
  678. export WIN3_DLG="<window title=\"$(gettext 'Simple Network Setup')\" icon-name=\"gtk-network\">
  679. <vbox>
  680. <pixmap><input file>/usr/local/lib/X11/pixmaps/error.xpm</input></pixmap>
  681. <text use-markup=\"true\"><label>\"<b>${ERR_MSG}</b>
  682. ${ERR_EXTRA1}\"</label></text>
  683. <text><label>`gettext \"So, what do you want to do? If you go back to the main window, you could test a different interface or network. Note, sometimes an error 'goes away' if you retry.\"`</label></text>
  684. <text><label>\" \"</label></text>
  685. <hbox>
  686. <text><label>$(gettext 'View log of attempted connection:')</label></text>
  687. <button><label>$(gettext 'LOG')</label><action>echo ' ' >> /tmp/sns_wireless_log</action><action>echo '*********************************************************' >> /tmp/sns_wireless_log</action><action>echo 'LAST 10 LINES of /var/log/messages:' >> /tmp/sns_wireless_log</action><action>tail -n 10 /var/log/messages >> /tmp/sns_wireless_log</action><action>defaulttextviewer /tmp/sns_wireless_log & </action></button>
  688. </hbox>
  689. <text><label>\" \"</label></text>
  690. <hbox>
  691. <button><label>$(gettext 'GO BACK TO MAIN WINDOW')</label><action type=\"exit\">BUT_GOBACK</action></button>
  692. <button><label>$(gettext 'QUIT')</label><action type=\"exit\">BUT_QUIT</action></button>
  693. </hbox>
  694. </vbox>
  695. </window>"
  696. RETSTRING="`${GTKDIALOGEXE} --program=WIN3_DLG --center`"
  697. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_GOBACK'`" != "" ] && exec sns
  698. fi
  699. exit
  700. fi #end test "$IF_INTTYPE" == "Wireless"
  701. ############Wired setup###############
  702. if [ "$IF_INTTYPE" == "Wired" ];then
  703. #xmessage -center -bg orange -buttons "" "Please wait, trying to connect to interface '${INTERFACE}'..." &
  704. yaf-splash -placement center -bg orange -text "$(gettext 'Please wait, trying to connect to interface') '${INTERFACE}'..." &
  705. PIDXX=$!
  706. echo "Information about this interface:
  707. Interface: $INTERFACE Driver: $IF_DRIVER Bus: $IF_BUS MacAddress: $MACADDRESS
  708. Description: $IF_INFO
  709. " > /tmp/sns_wired_log
  710. MODTIME1="1"; MODTIME2="1"
  711. ifconfig $INTERFACE up >> /tmp/sns_wired_log 2>&1
  712. [ $? -eq 0 ] && MODTIME2="0"
  713. if [ "$MODTIME2" == "0" ];then
  714. if ! ifplugstatus-0.18 "$INTERFACE" | grep -F -q 'link beat detected' ;then
  715. sleep 1
  716. if ! ifplugstatus "$INTERFACE" | grep -F -q 'link beat detected' ;then
  717. sleep 1
  718. if ! ifplugstatus-0.18 "$INTERFACE" | grep -F -q 'link beat detected' ;then
  719. sleep 1
  720. if ! ifplugstatus "$INTERFACE" | grep -F -q 'link beat detected' ;then
  721. # add ethtool test, just in case it helps at times...
  722. sleep 1
  723. if ! ethtool "$INTERFACE" | grep -Fq 'Link detected: yes' ; then
  724. ifconfig $INTERFACE down
  725. kill $PIDXX
  726. export WIN4_DLG="<window title=\"$(gettext 'Simple Network Setup')\" icon-name=\"gtk-network\">
  727. <vbox>
  728. <pixmap><input file>/usr/local/lib/X11/pixmaps/error.xpm</input></pixmap>
  729. <text><label>$(gettext 'There does not seem to be any network connected to') '${INTERFACE}'</label></text>
  730. <text><label>`gettext \"Is the network cable unplugged? Modem router turned off? If you can fix it, great, otherwise try a different interface. Click 'GO BACK TO MAIN WINDOW' button to try again...\"`</label></text>
  731. <hbox>
  732. <button><label>$(gettext 'GO BACK TO MAIN WINDOW')</label><action type=\"exit\">BUT_GOBACK</action></button>
  733. <button><label>$(gettext 'QUIT')</label><action type=\"exit\">BUT_QUIT</action></button>
  734. </hbox>
  735. </vbox>
  736. </window>"
  737. RETSTRING="`${GTKDIALOGEXE} --program=WIN4_DLG --center`"
  738. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_GOBACK'`" != "" ] && exec sns
  739. exit
  740. fi
  741. fi
  742. fi
  743. fi
  744. fi
  745. MODTIME1="`stat --format=%Y /etc/resolv.conf`"
  746. DHCPCDFIX=""
  747. dhcpcd $INTERFACE >> /tmp/sns_wired_log 2>&1
  748. MODTIME2="`stat --format=%Y /etc/resolv.conf`"
  749. [ "`grep -v '^#' /etc/resolv.conf`" == "" ] && MODTIME2=$MODTIME1 #fail.
  750. if [ "$MODTIME2" = "$MODTIME1" ];then #100325 fail, try again.
  751. DHCPCDFIX="-I ''"
  752. dhcpcd --release $INTERFACE
  753. dhcpcd -I '' $INTERFACE >> /tmp/sns_wired_log 2>&1
  754. MODTIME2="`stat --format=%Y /etc/resolv.conf`"
  755. [ "`grep -v '^#' /etc/resolv.conf`" == "" ] && MODTIME2=$MODTIME1 #fail.
  756. fi
  757. fi
  758. kill $PIDXX
  759. if [ "$MODTIME2" != "$MODTIME1" ];then
  760. export WIN5_DLG="<window title=\"$(gettext 'Simple Network Setup')\" icon-name=\"gtk-network\">
  761. <vbox>
  762. <pixmap><input file>/usr/local/lib/X11/pixmaps/ok.xpm</input></pixmap>
  763. <text><label>$(gettext 'Successful connection to wired network'): '${INTERFACE}'!</label></text>
  764. <text><label>$(gettext 'Your Internet should now be working!')</label></text>
  765. <text><label>$(gettext "Recommend leave this checkbox ticked, so that Puppy will use SNS to automatically connect to the Internet at bootup. Also clicking the 'connect' icon on the desktop will immediately launch SNS...")</label></text>
  766. <checkbox><label>$(gettext 'Set SNS as default network setup tool')</label><default>true</default><variable>CHK_SNSDEF</variable></checkbox>
  767. <hbox><button ok></button></hbox>
  768. </vbox>
  769. </window>"
  770. RETSTR5="`${GTKDIALOGEXE} --program=WIN5_DLG --center`"
  771. if [ "`echo "$RETSTR5" | grep '^CHK_SNSDEF' | grep 'true'`" != "" ];then
  772. echo -e '#!/bin/sh\nexec sns' > /usr/local/bin/defaultconnect
  773. else
  774. echo -e '#!/bin/sh\nexec connectwizard' > /usr/local/bin/defaultconnect
  775. fi
  776. MACADDRESS="`ifconfig $INTERFACE | grep -o 'HWaddr .*' | cut -f 2 -d ' '`"
  777. aPATTERN='|'"$MACADDRESS"'|'
  778. touch /etc/simple_network_setup/connections
  779. grep -v "$aPATTERN" /etc/simple_network_setup/connections > /tmp/sns_temp2
  780. mv -f /tmp/sns_temp2 /etc/simple_network_setup/connections
  781. echo "${IFDATA}|${MACADDRESS}|${DHCPCDFIX}|" >> /etc/simple_network_setup/connections
  782. else
  783. ifconfig $INTERFACE down
  784. dhcpcd --release $INTERFACE 2>/dev/null
  785. ip route flush dev $INTERFACE #100703
  786. export WIN6_DLG="<window title=\"$(gettext 'Simple Network Setup')\" icon-name=\"gtk-network\">
  787. <vbox>
  788. <pixmap><input file>/usr/local/lib/X11/pixmaps/error.xpm</input></pixmap>
  789. <text><label>$(gettext 'Failed to connect to wired network') '${INTERFACE}'</label></text>
  790. <text><label>$(gettext "The network does exist, however failed to negotiate with the DHCP server. Is there a wireless interface? -- maybe try that. Click 'GO BACK TO MAIN WINDOW' button to try again...")</label></text>
  791. <text><label>\" \"</label></text>
  792. <hbox>
  793. <text><label>$(gettext 'View log of attempted connection:')</label></text>
  794. <button><label>$(gettext 'LOG')</label><action>defaulttextviewer /tmp/sns_wired_log & </action></button>
  795. </hbox>
  796. <text><label>\" \"</label></text>
  797. <hbox>
  798. <button><label>$(gettext 'GO BACK TO MAIN WINDOW')</label><action type=\"exit\">BUT_GOBACK</action></button>
  799. <button><label>$(gettext 'QUIT')</label><action type=\"exit\">BUT_QUIT</action></button>
  800. </hbox>
  801. </vbox>
  802. </window>"
  803. RETSTRING="`${GTKDIALOGEXE} --program=WIN6_DLG --center`"
  804. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_GOBACK'`" != "" ] && exec sns
  805. fi
  806. exit
  807. fi
  808. ###END###