sns 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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. #131227 zigbert: gui (gtkdialog) improvements.
  32. export TEXTDOMAIN=sns___sns
  33. export OUTPUT_CHARSET=UTF-8
  34. . gettext.sh
  35. [ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505
  36. #each line of /etc/simple_network_setup/connections has everything known about a connection:
  37. #(please ignore spaces, put here for readability only)
  38. #Wireless:
  39. # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  40. #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|
  41. #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 | | |
  42. #Wired:
  43. # 1 2 3 4 5 6 7
  44. #format: INTERFACE|IF_INTTYPE|IF_DRIVER|IF_BUS |IF_INFO |MACADDRESS |DHCPCDFIX|
  45. #ex: eth0 |Wired |sky2 |pci |Marvell Yukon 2 Gigabit Ethernet driver|00:17:36:84:E5:1A| |
  46. BIGGESTCNT=0
  47. echo -n '' > /tmp/sns_interfaces
  48. INTERFACES="`ifconfig -a | grep -F 'Link encap:Ethernet' | cut -f1 -d' ' | tr '\n' ' '`"
  49. for INTERFACE in $INTERFACES #exs: wlan0 eth0
  50. do
  51. IF_DRIVER="`readlink /sys/class/net/$INTERFACE/device/driver | rev | cut -f1 -d'/' | rev`" #ex: ath5k
  52. #fix k2.6.27.47 anomaly...
  53. [ "$IF_DRIVER" = "ath5k_pci" ] && [ "`lsmod | grep '^ath5k '`" != "" ] && IF_DRIVER='ath5k'
  54. dPATTERN="^$IF_DRIVER "
  55. WHATWEWANT="`grep "$dPATTERN" /etc/networkmodules | tr '|' '_' | tr '"' '|'`" #'geany
  56. IF_BUS="`echo -n "$WHATWEWANT" | cut -f 2 -d '|' | cut -f 1 -d ':'`" #ex: usb
  57. IF_INFO="`echo -n "$WHATWEWANT" | cut -f 2 -d '|' | tr -s ' ' | cut -f 2-29 -d ' '`" #ex: Ralink RT73 USB Wireless LAN driver
  58. [ "$IF_BUS" = "" ] && IF_BUS="x"
  59. [ "$IF_INFO" = "" ] && IF_INFO="x"
  60. if [ "$IF_DRIVER" == "ndiswrapper" ];then
  61. WINDRVR="`ndiswrapper -l | grep '^[a-zA-Z0-9]' | cut -f 1 -d ' '`"
  62. IF_INFO="MS Windows driver '${WINDRVR}'"
  63. FINDTYPE="`readlink /sys/class/net/$INTERFACE/device/driver`"
  64. if [ "$FINDTYPE" ];then
  65. case $FINDTYPE in
  66. */bus/usb*) IF_BUS="usb" ;;
  67. */bus/pci*) IF_BUS="pci" ;;
  68. esac
  69. fi
  70. fi
  71. #want to manipulate the info string for display purposes...
  72. CNTLINE=0;FINALINFO=""
  73. for ONEWORD in $IF_INFO
  74. do
  75. CNTWORD=`echo "$ONEWORD" | wc -c`
  76. CNTLINE=`expr $CNTLINE + $CNTWORD`
  77. [ $CNTLINE -gt $BIGGESTCNT ] && BIGGESTCNT=$CNTLINE #use for window width.
  78. [ $CNTLINE -gt 60 ] && break
  79. FINALINFO="${FINALINFO}${ONEWORD} " #ensures whole words only in string.
  80. done
  81. IF_INFO="`echo -n "$FINALINFO" | tr '[&|"<>]' ' ' | tr -s ' '`" #'geany. filter out chars that mess up xml.
  82. IF_INTTYPE='Wired'
  83. ePATTERN="${INTERFACE}:"
  84. [ "`grep "$ePATTERN" /proc/net/wireless`" != "" ] && IF_INTTYPE='Wireless'
  85. [ "$IF_DRIVER" = "prism2_usb" ] && IF_INTTYPE='Wireless'
  86. [ -d /sys/class/net/${INTERFACE}/wireless ] && IF_INTTYPE='Wireless'
  87. #accumulate the results into columns...
  88. ALL_IF_INTERFACE="${ALL_IF_INTERFACE}|${INTERFACE}"
  89. ALL_IF_INTTYPE="${ALL_IF_INTTYPE}|${IF_INTTYPE}"
  90. ALL_IF_DRIVER="${ALL_IF_DRIVER}|${IF_DRIVER}"
  91. ALL_IF_BUS="${ALL_IF_BUS}|${IF_BUS}"
  92. ALL_IF_INFO="${ALL_IF_INFO}|${IF_INFO}"
  93. INTERFACEBUTTONS="${INTERFACEBUTTONS}
  94. <button><label>${INTERFACE}</label><action type=\"exit\">Interface_${INTERFACE}</action></button>"
  95. #save all data about each interface on one line...
  96. #ex: wlan1|Wireless|ath5k|pci|Support for 5xxx series of Atheros 802.11 wireless LAN cards
  97. echo "${INTERFACE}|${IF_INTTYPE}|${IF_DRIVER}|${IF_BUS}|${IF_INFO}" >> /tmp/sns_interfaces
  98. done
  99. ALL_IF_INTERFACE="`echo -n "$ALL_IF_INTERFACE" | sed -e 's%^|%%' | tr '|' '\n'`"
  100. ALL_IF_INTTYPE="`echo -n "$ALL_IF_INTTYPE" | sed -e 's%^|%%' | tr '|' '\n'`"
  101. ALL_IF_DRIVER="`echo -n "$ALL_IF_DRIVER" | sed -e 's%^|%%' | tr '|' '\n'`"
  102. ALL_IF_BUS="`echo -n "$ALL_IF_BUS" | sed -e 's%^|%%' | tr '|' '\n'`"
  103. ALL_IF_INFO="`echo -n "$ALL_IF_INFO" | sed -e 's%^|%%' | tr '|' '\n'`"
  104. INTERFACEDESCR=" <hbox border-width=\"7\" spacing=\"10\">
  105. <text use-markup=\"true\"><label>\"<b>$(gettext 'Interface')</b>
  106. $ALL_IF_INTERFACE\"</label></text>
  107. <text use-markup=\"true\"><label>\"<b>$(gettext 'Type')</b>
  108. $ALL_IF_INTTYPE\"</label></text>
  109. <text use-markup=\"true\"><label>\"<b>$(gettext 'Driver')</b>
  110. $ALL_IF_DRIVER\"</label></text>
  111. <text use-markup=\"true\"><label>\"<b>$(gettext 'Bus')</b>
  112. $ALL_IF_BUS\"</label></text>
  113. <text use-markup=\"true\"><label>\"<b>$(gettext 'Description')</b>
  114. $ALL_IF_INFO\"</label></text>
  115. </hbox>"
  116. #test if connected to internet...
  117. FLAGINTERNETSTATUS='no'
  118. WORKINGIF=''
  119. if [ "`pidof dhcpcd`" != "" ];then
  120. if [ "`grep -v '^#' /etc/resolv.conf`" != "" ];then
  121. PSALL="`ps`"
  122. PSDHCPCD="`echo "$PSALL" | grep 'dhcpcd'`"
  123. for ONEIF in `ifconfig | grep '^[a-z]' | cut -f 1 -d ' ' | grep -v '^lo' | tr '\n' ' '`
  124. do
  125. if [ "`echo "$PSDHCPCD" | grep "$ONEIF"`" != "" ];then
  126. WORKINGIF="${WORKINGIF}${ONEIF} "
  127. FLAGINTERNETSTATUS='yes'
  128. fi
  129. done
  130. fi
  131. fi
  132. if [ "$FLAGINTERNETSTATUS" == "yes" ];then
  133. WORKINGIF="`echo -n "$WORKINGIF" | sed -e 's% $%%'`"
  134. MSGWIF="interface <b>${WORKINGIF}</b>"
  135. [ `echo -n "$WORKINGIF" | wc -w` -gt 1 ] && MSGWIF="interfaces <b>${WORKINGIF}</b>"
  136. MSGSTATUS="$(gettext 'Currently a working Internet connection on') ${MSGWIF}"
  137. COLOR_BG='#80CE7F'; COLOR_FG='#235123'
  138. else
  139. MSGSTATUS="$(gettext 'Currently no Internet connection')"
  140. COLOR_BG='#CE837F'; COLOR_FG='#512323'
  141. fi
  142. CLICKMSG="`/usr/lib/gtkdialog/xml_info fixed "internet_connect.svg" 60 "$(gettext 'Puppy has identified these network interfaces on your computer. Click a button to configure the interface for use.')"`"
  143. #100313 add a button for loading a Windows driver...
  144. if [ "`echo "$ALL_IF_DRIVER" | grep 'ndiswrapper'`" == "" ];then
  145. CLICKMSG="`/usr/lib/gtkdialog/xml_info fixed "internet_connect.svg" 60 "$(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.')"`"
  146. INTERFACEBUTTONS="${INTERFACEBUTTONS}
  147. <button><label>Windows</label><action type=\"exit\">Interface_Windows</action></button>"
  148. fi
  149. #120107 new 'Profile' frame...
  150. PROFILE_XML=""
  151. 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
  152. if [ -s /etc/simple_network_setup/connections ];then
  153. CNT=0
  154. [ "grep '|Wireless|' /etc/simple_network_setup/connections" != "" ] && echo "<b>$(gettext 'Network')</b>" >/tmp/sns_S_P
  155. cat /etc/simple_network_setup/connections |
  156. while read ONECONNECTION
  157. do
  158. CNT=$(($CNT + 1))
  159. echo "<b>$CNT</b>" >> /tmp/sns_CNT_P
  160. INTERFACE_P="`echo -n "$ONECONNECTION" | cut -f 1 -d '|'`"
  161. echo "$INTERFACE_P" >> /tmp/sns_I_P
  162. TYPE_P="`echo -n "$ONECONNECTION" | cut -f 2 -d '|'`"
  163. echo "$TYPE_P" >> /tmp/sns_T_P
  164. DRIVER_P="`echo -n "$ONECONNECTION" | cut -f 3 -d '|'`"
  165. echo "$DRIVER_P" >> /tmp/sns_D_P
  166. BUS_P="`echo -n "$ONECONNECTION" | cut -f 4 -d '|'`"
  167. echo "$BUS_P" >> /tmp/sns_B_P
  168. MAC_P="`echo -n "$ONECONNECTION" | cut -f 6 -d '|'`"
  169. echo "$MAC_P" >> /tmp/sns_M_P
  170. if [ "$TYPE_P" = "Wireless" ];then
  171. SSID_P="`echo -n "$ONECONNECTION" | cut -f 12 -d '|'`"
  172. echo "$SSID_P" >> /tmp/sns_S_P
  173. SEC_P="`echo -n "$ONECONNECTION" | cut -f 14 -d '|'`"
  174. [ "$SEC_P" = "" ] && SEC_P="none"
  175. echo "$SEC_P" >> /tmp/sns_SEC_P
  176. else
  177. echo " " >> /tmp/sns_S_P
  178. echo " " >> /tmp/sns_SEC_P
  179. fi
  180. if [ $CNT -gt 12 ];then
  181. echo "<i>more...</i>" >> /tmp/sns_I_P
  182. break
  183. fi
  184. 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
  185. done
  186. if [ "$FLAGINTERNETSTATUS" = "yes" ];then
  187. CONNECTBTN_XML="<button>`/usr/lib/gtkdialog/xml_button-icon internet_connect_no.svg`<label>$(gettext 'Disconnect Now')</label><action>/usr/sbin/networkdisconnect</action><action type=\"exit\">EXITNOW</action></button>"
  188. else
  189. CONNECTBTN_XML="<button>`/usr/lib/gtkdialog/xml_button-icon internet_connect_yes.svg`<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>"
  190. fi
  191. PROFILE_XML="`/usr/lib/gtkdialog/xml_info fixed "internet_connect.svg" 60 "$(gettext 'Connection profiles have previously been created by SNS.')" "$(gettext "The 'Connect' button will try to establish an internet connection by any of the available profiles.")"`
  192. <hbox border-width=\"7\" 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>
  193. <hbox><text><label>$(gettext 'Delete:')</label></text>`cat /tmp/sns_DEL_BTN`</hbox>
  194. "
  195. fi
  196. if [ "$PROFILE_XML" ]; then
  197. PAGE_NR=0
  198. else
  199. PAGE_NR=1
  200. PROFILE_XML="`/usr/lib/gtkdialog/xml_info scale "internet_connect.svg" 60 "$(gettext '<b>No profiles</b>')" "$(gettext 'Set up an interface first, and when connected, a profile will be built for next run.')"`"
  201. fi
  202. #bring up the main window...
  203. export SNS='
  204. <window title="SNS - '$(gettext "Barry's Simple Network Setup")'" icon-name="gtk-network">
  205. <vbox spacing="0" space-expand="true" space-fill="true">
  206. <eventbox name="status" space-expand="false" space-fill="false">
  207. <text name="status_text" wrap="false" height-request="20" use-markup="true" space-expand="true" space-fill="true"><label>"'${MSGSTATUS}'"</label></text>
  208. </eventbox>
  209. <text height-request="7" space-expand="false" space-fill="false"><label>""</label></text>
  210. <vbox spacing="5" space-expand="true" space-fill="true">
  211. <notebook tab-pos="2" page="'$PAGE_NR'" labels="'$(gettext 'Profiles')'|'$(gettext 'Interfaces')'" space-expand="true" space-fill="true">
  212. <frame '$(gettext 'Profiles')'>
  213. '${PROFILE_XML}'
  214. <text height-request="5" space-expand="false" space-fill="false"><label>""</label></text>
  215. </frame>
  216. <frame '$(gettext 'Interfaces')'>
  217. '${CLICKMSG}'
  218. '${INTERFACEDESCR}'
  219. <hbox space-expand="false" space-fill="false">'${INTERFACEBUTTONS}'</hbox>
  220. <text height-request="5" space-expand="false" space-fill="false"><label>""</label></text>
  221. </frame>
  222. </notebook>
  223. <hbox space-expand="false" space-fill="false">
  224. <button>
  225. <label>'$(gettext "Help")'</label>
  226. '"`/usr/lib/gtkdialog/xml_button-icon help`"'
  227. <action>/usr/local/simple_network_setup/help_profiles &</action>
  228. </button>
  229. <button space-expand="false" space-fill="false">
  230. <label>'$(gettext 'Network Information')'</label>
  231. '"`/usr/lib/gtkdialog/xml_button-icon info`"'
  232. <action>ipinfo & </action>
  233. </button>
  234. <text space-expand="true" space-fill="true"><label>""</label></text>
  235. '${CONNECTBTN_XML}'
  236. <button space-expand="false" space-fill="false">
  237. '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
  238. <label>'$(gettext 'Quit')'</label>
  239. </button>
  240. </hbox>
  241. </vbox>
  242. </vbox>
  243. </window>'
  244. echo 'style "status"
  245. {
  246. fg[NORMAL] = "'$COLOR_FG'"
  247. bg[NORMAL] = "'$COLOR_BG'"
  248. }
  249. widget "*status*" style "status"' > /tmp/gtkrc_sns
  250. export GTK2_RC_FILES=/tmp/gtkrc_sns:/root/.gtkrc-2.0
  251. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  252. RETSTRING="`gtkdialog -p SNS`" ###main window###
  253. echo "$RETSTRING"
  254. EXIT="`echo "$RETSTRING" | grep '^EXIT' | cut -f2 -d'"'`" #'geany
  255. [ "`echo "$EXIT" | grep 'EXITRESTART'`" != "" ] && exec sns ###restarting sns###
  256. [ "`echo "$EXIT" | grep 'Interface'`" = "" ] && exit
  257. INTERFACE="`echo -n "$EXIT" | cut -f2 -d '_'`" #ex: wlan1
  258. if [ "$INTERFACE" == "Windows" ];then #100313
  259. if [ -d /etc/ndiswrapper ];then
  260. if [ "`ls /etc/ndiswrapper/*/*.inf 2>/dev/null`" != "" ];then
  261. modprobe ndiswrapper
  262. sleep 1
  263. exec sns
  264. fi
  265. fi
  266. export SNS_ndiswrapper='<window title="'$(gettext 'SNS: Install MS Windows driver')'" icon-name="gtk-network">
  267. <vbox>
  268. '"`/usr/lib/gtkdialog/xml_info scale "internet_connect.svg" 60 "$(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...")"`"'
  269. <chooser>
  270. <height>300</height><width>550</width>
  271. <variable>INF_FILE_NAME</variable>
  272. </chooser>
  273. <hbox>
  274. <button space-expand="false" space-fill="false">
  275. <label>'$(gettext "Cancel")'</label>
  276. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  277. <action>exit:Cancel</action>
  278. </button>
  279. <button space-expand="false" space-fill="false">
  280. <label>'$(gettext "Ok")'</label>
  281. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  282. <action>exit:OK</action>
  283. </button>
  284. </hbox>
  285. </vbox>
  286. </window>'
  287. RETSTRND="`gtkdialog -p SNS_ndiswrapper`"
  288. if [ "`echo "$RETSTRND" | grep '^EXIT' | grep 'OK'`" != "" ];then
  289. INFFILE="`echo "$RETSTRND" | grep '^INF_FILE_NAME' | cut -f 2 -d '"'`" #'geany
  290. case "$INFFILE" in
  291. *.[iI][nN][fF])
  292. FLAGND=""
  293. ndiswrapper -i "$INFFILE" #installs driver at /etc/ndiswrapper.
  294. if [ $? -eq 0 ];then
  295. ndiswrapper -l #tests the driver
  296. if [ $? -eq 0 ];then
  297. modprobe ndiswrapper
  298. [ $? -eq 0 ] && FLAGND="ok"
  299. [ "$FLAGND" != "ok" ] && rmmod ndiswrapper 2>/dev/null
  300. fi
  301. fi
  302. [ "$FLAGND" != "ok" ] && rm -rf /etc/ndiswrapper
  303. [ "$FLAGND" != "ok" ] && pupmessage -center -bg red "$(gettext 'ERROR: Windows driver does not seem to work, it has been uninstalled')"
  304. [ "$FLAGND" == "ok" ] && sleep 1
  305. ;;
  306. *)
  307. pupmessage -center -bg red "`eval_gettext \"ERROR, \\\${INFFILE} is not a .inf file\"`"
  308. ;;
  309. esac
  310. fi
  311. exec sns
  312. fi
  313. ifPATTERN='^'"$INTERFACE"' '
  314. if [ "`ifconfig | grep "$ifPATTERN"`" != "" ];then
  315. yaf-splash -bg orange -placement center -text "$(gettext 'Please wait, bringing down') '$INTERFACE'..." &
  316. PIDX1=$!
  317. ifconfig $INTERFACE down
  318. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  319. iwconfig $INTERFACE key off #100320 think need this for when I'm experimenting with different wep/wpa/open settings on the same interface.
  320. dhcpcd --release $INTERFACE 2>/dev/null
  321. ip route flush dev $INTERFACE #100703
  322. sleep 1
  323. kill $PIDX1
  324. fi
  325. fPATTERN='^'"${INTERFACE}"'|'
  326. IFDATA="`grep "$fPATTERN" /tmp/sns_interfaces`"
  327. IF_INTTYPE="`echo "$IFDATA" | cut -f2 -d'|'`" #ex: Wireless
  328. IF_DRIVER="`echo "$IFDATA" | cut -f3 -d'|'`" #ex: ath5k
  329. IF_BUS="`echo "$IFDATA" | cut -f4 -d'|'`" #ex: pci
  330. IF_INFO="`echo "$IFDATA" | cut -f5 -d'|'`"
  331. MACADDRESS="`ifconfig $INTERFACE | grep -o 'HWaddr .*' | cut -f 2 -d ' '`"
  332. ############WIRELESS SETUP###############
  333. if [ "$IF_INTTYPE" == "Wireless" ];then
  334. #scan for networks...
  335. FLAGERR=
  336. rm -f /tmp/sns_scan_radiobuttons
  337. rm -f /tmp/sns_scan_radiobuttons_shield
  338. rm -f /tmp/sns_scan_radiobuttons_strength
  339. rm -f /tmp/sns_scan_rawoneline
  340. rm -f /tmp/sns_scan_oneline
  341. yaf-splash -placement center -bg orange -text "$(gettext 'Please wait, scanning for wireless networks...')" &
  342. PIDXMSG=$!
  343. echo "Information about this interface:
  344. Interface: $INTERFACE Driver: $IF_DRIVER Bus: $IF_BUS MacAddress: $MACADDRESS
  345. Description: $IF_INFO
  346. " > /tmp/sns_wireless_log
  347. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  348. echo "STEP1a: ifconfig $INTERFACE up" >> /tmp/sns_wireless_log
  349. ifconfig $INTERFACE up >> /tmp/sns_wireless_log 2>&1
  350. if [ $? -ne 0 ];then
  351. FLAGERR=1
  352. else
  353. sleep 2 #100513 increase from 1.
  354. echo "STEP1b: iwlist $INTERFACE scan" >> /tmp/sns_wireless_log
  355. SCANRESULT="`iwlist $INTERFACE scan`" ###SCANNING### 110203
  356. if [ "`echo "$SCANRESULT" | grep 'Scan completed'`" = "" ];then #100513 110203
  357. sleep 2
  358. SCANRESULT="`iwlist $INTERFACE scan`" ###SCANNING### 110203
  359. fi
  360. echo "$SCANRESULT" >> /tmp/sns_wireless_log
  361. echo "STEP1c: ifconfig $INTERFACE down" >> /tmp/sns_wireless_log
  362. ifconfig $INTERFACE down #100313
  363. #convert each found network into a single line... 110203
  364. SRLINES="`echo "$SCANRESULT" | grep -v 'Scan completed' | tr '|' ' ' | tr '\n' '|' | sed -e 's% Cell %\n%g' | tr -s ' '`"
  365. echo "$SRLINES" |
  366. while read ONELINE
  367. do
  368. [ "$ONELINE" = "" ] && continue
  369. [ "$ONELINE" = " " ] && continue
  370. [ "`echo -n "$ONELINE" | grep 'No scan results'`" != "" ] && continue #101029
  371. [ "`echo -n "$ONELINE" | grep ' ESSID:'`" = "" ] && continue #101029
  372. CELL_NUMBER="`echo -n "$ONELINE" | cut -f1 -d' '`"
  373. CELL_ADDRESS="`echo -n "$ONELINE" | grep -o ' Address: .*' | cut -f 3 -d ' ' | cut -f1 -d '|'`"
  374. CELL_CHANNEL="`echo -n "$ONELINE" | grep -o ' Channel:.*' | cut -f2 -d':' | cut -f1 -d'|'`"
  375. [ "$CELL_CHANNEL" == "" ] && CELL_CHANNEL="`echo -n "$ONELINE" | grep -o ' (Channel .*' | cut -f 3 -d ' ' | cut -f 1 -d')'`"
  376. CELL_QUALITY="`echo -n "$ONELINE" | grep -o ' Quality[:=].*' | cut -f 2 -d ' ' | cut -f 2 -d '=' | cut -f 2 -d ':'`"
  377. CELL_ESSID="`echo -n "$ONELINE" | grep -o ' ESSID:.*' | cut -f 2 -d '"'`" #'geany
  378. CELL_ENCRYPTIONKEY="`echo -n "$ONELINE" | grep -o 'Encryption key:.*' | cut -f 2 -d ':' | cut -f1 -d '|'`" #ex: off
  379. #build network list
  380. if [ $CELL_ENCRYPTIONKEY = on ]; then
  381. IMG_SHIELD=shield_no
  382. TXT_SHIELD="$(gettext 'Encrypted')"
  383. else
  384. IMG_SHIELD=shield_yes
  385. TXT_SHIELD="$(gettext 'Open')"
  386. fi
  387. IMG_QUALITY=quality_0
  388. if [ $(echo "100"'*'"$CELL_QUALITY" | bc) -gt 80 ]; then
  389. IMG_QUALITY=quality_5
  390. elif [ $(echo "100"'*'"$CELL_QUALITY" | bc) -gt 60 ]; then
  391. IMG_QUALITY=quality_4
  392. elif [ $(echo "100"'*'"$CELL_QUALITY" | bc) -gt 40 ]; then
  393. IMG_QUALITY=quality_3
  394. elif [ $(echo "100"'*'"$CELL_QUALITY" | bc) -gt 20 ]; then
  395. IMG_QUALITY=quality_2
  396. elif [ $(echo "100"'*'"$CELL_QUALITY" | bc) -gt 5 ]; then
  397. IMG_QUALITY=quality_1
  398. fi
  399. echo '<radiobutton height-request="25" space-expand="false" space-fill="false">
  400. <label>'$CELL_ESSID'</label>
  401. <variable>RADIO_'${CELL_NUMBER}'</variable>
  402. </radiobutton>' >> /tmp/sns_scan_radiobuttons
  403. echo '
  404. <hbox space-expand="false" space-fill="false">
  405. <text xalign="1" yalign="1" use-markup="true" space-expand="true" space-fill="true">
  406. <label>"<small><small>'${TXT_SHIELD}'</small></small>"</label>
  407. </text>
  408. <pixmap height-request="25" space-expand="false" space-fill="false">
  409. <input file>/usr/share/pixmaps/puppy/'${IMG_SHIELD}'.svg</input>
  410. <height>25</height>
  411. </pixmap>
  412. </hbox>' >> /tmp/sns_scan_radiobuttons_shield
  413. echo '
  414. <hbox space-expand="false" space-fill="false">
  415. <text xalign="0" yalign="1" use-markup="true" space-expand="true" space-fill="true">
  416. <label>"<small><small>'$(gettext 'Strength')': '${CELL_QUALITY}' </small></small>"</label>
  417. </text>
  418. <pixmap height-request="25" space-expand="false" space-fill="false">
  419. <input file>/usr/share/pixmaps/puppy/'${IMG_QUALITY}'.svg</input>
  420. <height>25</height>
  421. </pixmap>
  422. </hbox>' >> /tmp/sns_scan_radiobuttons_strength
  423. #---
  424. echo "$ONELINE" >> /tmp/sns_scan_rawoneline
  425. echo "${CELL_NUMBER}|${CELL_ADDRESS}|${CELL_CHANNEL}|${CELL_QUALITY}|${CELL_ENCRYPTIONKEY}|${CELL_ESSID}" >> /tmp/sns_scan_oneline
  426. done
  427. #my wpa_supplicant only supports: wext hostap atmel wired ralink roboswitch
  428. case $IF_DRIVER in
  429. hostap*) WPA_DRIVER="hostap" ;;
  430. rt61|rt73) WPA_DRIVER="ralink" ;;
  431. *) WPA_DRIVER="wext" ;;
  432. esac
  433. if [ ! -f /tmp/sns_scan_radiobuttons ];then
  434. FRAME1='<text space-expand="true" space-fill="true"><label>""</label></text>'
  435. FRAME2=""
  436. WIN2MSG1="$(gettext 'No wireless networks found')"
  437. WIN2BUT1=""
  438. WIN2BUT2=""
  439. else
  440. WIN2MSG1="$(gettext "Choose which network you want to use, type of encryption, then click 'Connect' button.")"
  441. RADIOBUTTONS='
  442. <hbox space-expand="true" space-fill="true">
  443. <vbox space-expand="false" space-fill="false">'`cat /tmp/sns_scan_radiobuttons`'</vbox>
  444. <text space-expand="true" space-fill="true"><label>""</label></text>
  445. <vbox space-expand="false" space-fill="false">'`cat /tmp/sns_scan_radiobuttons_shield`'</vbox>
  446. <text width-request="10" space-expand="false" space-fill="false"><label>""</label></text>
  447. <vbox space-expand="false" space-fill="false">'`cat /tmp/sns_scan_radiobuttons_strength`'</vbox>
  448. </hbox>'
  449. FRAME1='
  450. <vbox space-expand="true" space-fill="true">
  451. <frame '$(gettext 'Wireless networks')'>
  452. <vbox scrollable="true" shadow-type="1" space-expand="false" space-fill="false">
  453. <eventbox name="bg" above-child="false" visible-window="true" space-expand="true" space-fill="true">
  454. <vbox border-width="5" space-expand="true" space-fill="true">
  455. '${RADIOBUTTONS}'
  456. </vbox>
  457. </eventbox>
  458. </vbox>
  459. </frame>
  460. </vbox>'
  461. FRAME2='
  462. <vbox space-expand="false" space-fill="false">
  463. <frame '$(gettext 'Encryption')'>
  464. <hbox border-width="5" space-expand="true" space-fill="true">
  465. <vbox space-expand="false" space-fill="false">
  466. <radiobutton space-expand="false" space-fill="false">
  467. <label>'$(gettext 'None')'</label>
  468. <variable>BUTSEC_NONE</variable>
  469. </radiobutton>
  470. <radiobutton space-expand="false" space-fill="false">
  471. <label>WEP</label>
  472. <variable>BUTSEC_WEP</variable>
  473. </radiobutton>
  474. <radiobutton space-expand="false" space-fill="false">
  475. <label>WPA</label>
  476. <variable>BUTSEC_WPAPSK</variable>
  477. </radiobutton>
  478. </vbox>
  479. <text width-request="30" space-expand="false" space-fill="false"><label>""</label></text>
  480. <vbox space-expand="true" space-fill="true">
  481. <text space-expand="true" space-fill="true"><label>""</label></text>
  482. <hbox space-expand="true" space-fill="true">
  483. <text space-expand="false" space-fill="false"><label>'$(gettext 'Key:')'</label></text>
  484. <entry space-expand="true" space-fill="true"><variable>BOX_KEY</variable></entry>
  485. </hbox>
  486. </vbox>
  487. </hbox>
  488. </frame>
  489. </vbox>'
  490. WIN2BUT1='
  491. <button space-expand="false" space-fill="false">
  492. <label>'$(gettext "Connect")'</label>
  493. '"`/usr/lib/gtkdialog/xml_button-icon internet_connect`"'
  494. <action type="exit">BUT_CONNECT</action>
  495. </button>'
  496. WIN2BUT2='
  497. <button space-expand="false" space-fill="false">
  498. <label>'$(gettext 'Help')'</label>
  499. '"`/usr/lib/gtkdialog/xml_button-icon help`"'
  500. <action>/usr/local/simple_network_setup/help_security & </action>
  501. </button>'
  502. fi
  503. kill $PIDXMSG ; PIDXMSG=""
  504. export SNS_setup='<window title="'$(gettext 'Simple Network Setup')'" icon-name="gtk-network" height-request="400">
  505. <vbox space-expand="true" space-fill="true">
  506. '"`/usr/lib/gtkdialog/xml_info fixed "internet_connect.svg" 60 "$(gettext "${WIN2MSG1}")"`"'
  507. '${FRAME1}'
  508. '${FRAME2}'
  509. <hbox space-expand="false" space-fill="false">
  510. '${WIN2BUT2}'
  511. <text space-expand="true" space-fill="true"><label>""</label></text>
  512. <button space-expand="false" space-fill="false">
  513. <label>'$(gettext "Cancel")'</label>
  514. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  515. <action type="exit">BUT_GOBACK</action>
  516. </button>
  517. '${WIN2BUT1}'
  518. </hbox>
  519. </vbox>
  520. </window>'
  521. #darker bg
  522. echo '<?xml version="1.1" encoding="UTF-8"?><svg height="10" width="10">
  523. <rect style="fill:#000000;fill-opacity:0.2" width="10" height="10" x="0" y="0"/></svg>' > /tmp/sns_bg.svg
  524. echo '
  525. pixmap_path "/tmp"
  526. style "bg" { bg_pixmap[NORMAL] = "sns_bg.svg" }
  527. widget "*bg*" style "bg"' > /tmp/gtkrc_mono
  528. export GTK2_RC_FILES=/tmp/gtkrc_mono:/root/.gtkrc-2.0
  529. #---
  530. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  531. RETSTRING="`gtkdialog -p SNS_setup`"
  532. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_GOBACK'`" != "" ] && exec sns
  533. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_CONNECT'`" == "" ] && exit
  534. SEC_MGMT=""; WPA_ENC=""
  535. SEC_KEY="`echo "$RETSTRING" | grep '^BOX_KEY' | cut -f 2 -d '"' | tr -d '-'`" #'geany
  536. BUTSEC="`echo "$RETSTRING" | grep '^BUTSEC_' | grep 'true' | cut -f 1 -d '=' | cut -f 2 -d '_'`"
  537. case $BUTSEC in
  538. WEP) SEC_MGMT="WEP"; WPA_ENC="" ;;
  539. WPAPSK) SEC_MGMT="WPA-PSK"; WPA_ENC="" ;;
  540. WPAPSKTKIP) SEC_MGMT="WPA-PSK"; WPA_ENC="TKIP" ;;
  541. WPAPSKAES) SEC_MGMT="WPA-PSK"; WPA_ENC="AES" ;;
  542. WPA2PSKAES) SEC_MGMT="WPA2-PSK"; WPA_ENC="AES" ;;
  543. *) SEC_KEY="" ;; #no encryption.
  544. esac
  545. CELL_NUMBER="`echo "$RETSTRING" | grep '^RADIO' | grep 'true' | cut -f1 -d'=' | cut -f2 -d'_'`" #ex: 01
  546. cnPATTERN='^'"$CELL_NUMBER"'|'
  547. CELLDATA="`grep "$cnPATTERN" /tmp/sns_scan_oneline`"
  548. CELL_ADDRESS="`echo -n "$CELLDATA" | cut -f2 -d'|'`"
  549. CELL_CHANNEL="`echo -n "$CELLDATA" | cut -f3 -d'|'`"
  550. CELL_QUALITY="`echo -n "$CELLDATA" | cut -f4 -d'|'`"
  551. CELL_ENCRYPTIONKEY="`echo -n "$CELLDATA" | cut -f5 -d'|'`"
  552. CELL_ESSID="`echo -n "$CELLDATA" | cut -f6 -d'|'`"
  553. if [ "$CELL_ENCRYPTIONKEY" == "on" ];then
  554. [ "$SEC_KEY" == "" ] && FLAGERR=2
  555. [ "$SEC_MGMT" == "" ] && FLAGERR=3
  556. fi
  557. if [ ! $FLAGERR ];then
  558. yaf-splash -placement center -bg orange -text "$(gettext 'Please wait, attempting to connect to') '${CELL_ESSID}'..." &
  559. PIDX=$!
  560. echo "STEP2: iwconfig $INTERFACE mode managed" >> /tmp/sns_wireless_log
  561. iwconfig $INTERFACE mode managed >> /tmp/sns_wireless_log 2>&1
  562. echo "STEP3: iwconfig $INTERFACE channel $CELL_CHANNEL" >> /tmp/sns_wireless_log
  563. iwconfig $INTERFACE channel $CELL_CHANNEL >> /tmp/sns_wireless_log 2>&1
  564. echo "STEP4: iwconfig $INTERFACE essid \"$CELL_ESSID\"" >> /tmp/sns_wireless_log
  565. iwconfig $INTERFACE essid "$CELL_ESSID" >> /tmp/sns_wireless_log 2>&1
  566. #test essid is associated...
  567. if [ $? -ne 0 ];then
  568. FLAGERR=4
  569. else
  570. RUNWPASUPP='no'
  571. [ -f "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}" ] && rm -f "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}"
  572. FIXUP='1 1 2 0'
  573. [ "$IF_DRIVER" = "ndiswrapper" ] && FIXUP='2 1 0'
  574. [ "$BUTSEC" = "WEP" ] && FIXUP='restricted open'
  575. fuCNT=`echo -n "$FIXUP" | wc -w`
  576. fuCNT=$(($fuCNT + 1)) #100321 bug fix.
  577. for ONEFIX in $FIXUP ###BIG FOR LOOP###
  578. do
  579. FLAGERR= #100323
  580. fuCNT=$(($fuCNT - 1))
  581. if [ "$CELL_ENCRYPTIONKEY" == "on" ];then
  582. case $BUTSEC in
  583. WEP)
  584. echo "STEP5: iwconfig $INTERFACE key $ONEFIX $SEC_KEY" >> /tmp/sns_wireless_log
  585. iwconfig $INTERFACE key $ONEFIX $SEC_KEY
  586. ;;
  587. WPAPSK) #very simple, handles all ciphers.
  588. #it works psk="passphrase" (with quotes), but for security encode psk into hex string...
  589. hexSEC_KEY=`wpa_passphrase "$CELL_ESSID" $SEC_KEY | grep '[^#]psk=' | cut -f 2 -d '='`
  590. echo "ctrl_interface=/var/run/wpa_supplicant
  591. ap_scan=${ONEFIX}
  592. network={
  593. ssid=\"${CELL_ESSID}\"
  594. key_mgmt=${SEC_MGMT}
  595. psk=${hexSEC_KEY}
  596. }" > "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}"
  597. RUNWPASUPP='yes'
  598. if [ "`pidof wpa_supplicant`" != "" ];then
  599. wpa_cli terminate
  600. killall wpa_supplicant
  601. fi
  602. ;;
  603. WPA*)
  604. #it works psk="passphrase" (with quotes), but for security encode psk into hex string...
  605. hexSEC_KEY=`wpa_passphrase "$CELL_ESSID" $SEC_KEY | grep '[^#]psk=' | cut -f 2 -d '='`
  606. echo "ctrl_interface=/var/run/wpa_supplicant
  607. ap_scan=${ONEFIX}
  608. network={
  609. ssid=\"${CELL_ESSID}\"
  610. proto=WPA
  611. key_mgmt=${SEC_MGMT}
  612. pairwise=${WPA_ENC}
  613. group=${WPA_ENC}
  614. psk=${SEC_KEY}
  615. wpa_ptk_rekey=600
  616. }" > "/etc/simple_network_setup/wpa_supplicant.conf-${CELL_ESSID}-${MACADDRESS}"
  617. RUNWPASUPP='yes'
  618. if [ "`pidof wpa_supplicant`" != "" ];then
  619. wpa_cli terminate #kills any running wpa_supplicant. no it doesn't, just brings down interface.
  620. killall wpa_supplicant
  621. fi
  622. ;;
  623. esac
  624. fi
  625. echo "STEP5a: ifconfig $INTERFACE up" >> /tmp/sns_wireless_log
  626. ifconfig $INTERFACE up
  627. if [ "$RUNWPASUPP" = "yes" ];then
  628. 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
  629. 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
  630. wCNT=0
  631. while [ 1 ];do
  632. [ "`wpa_cli -i $INTERFACE status | grep '^bssid=[0-9a-f]'`" != "" ] && break
  633. sleep 1
  634. wCNT=`expr $wCNT + 1`
  635. if [ $wCNT -gt 20 ];then
  636. echo "Running: wpa_cli -i ${INTERFACE} status" >> /tmp/sns_wireless_log
  637. wpa_cli -i $INTERFACE status >> /tmp/sns_wireless_log 2>&1
  638. #FLAGERR=5
  639. #100314 http://wiki.archlinux.org/index.php/WPA_supplicant has following advice...
  640. #really weird, works for my wg311 ndiswrapper driver. but must have the ap_scan sequence 2 1 0...
  641. #ignore error, do this instead...
  642. killall -SIGHUP wpa_supplicant
  643. iwconfig $INTERFACE essid "$CELL_ESSID"
  644. break
  645. fi
  646. done
  647. fi
  648. if [ $FLAGERR ];then
  649. if [ $fuCNT -ne 0 ];then
  650. kill $PIDX
  651. case $fuCNT in
  652. 1) BGCOLOR="HotPink" ;;
  653. 2) BGCOLOR="pink" ;;
  654. *) BGCOLOR="DeepPink" ;;
  655. esac
  656. yaf-splash -placement center -bg $BGCOLOR -text "$(gettext 'Please keep waiting, retrying encrypted connection...')" &
  657. PIDX=$!
  658. continue #try next FIXUP value (see for-loop above). ###BIG FOR LOOP###
  659. fi
  660. if [ "`pidof wpa_supplicant`" != "" ];then
  661. wpa_cli terminate
  662. killall wpa_supplicant
  663. fi
  664. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  665. ifconfig $INTERFACE down
  666. else
  667. #wait until access point becomes available...
  668. sCNT=0
  669. while [ 1 ];do
  670. TESTAP="`iwconfig ${INTERFACE} | grep -o 'Access Point: .*' | tr -s ' ' | cut -f 3 -d ' ' | sed -e 's%[^:]%%g'`"
  671. [ "`echo -n "$TESTAP" | grep '::::'`" != "" ] && break
  672. sleep 1
  673. sCNT=`expr $sCNT + 1`
  674. if [ $sCNT -gt 20 ];then
  675. echo "" >> /tmp/sns_wireless_log #100320
  676. echo "ERROR, TIMEOUT. Have not got an Access Point." >> /tmp/sns_wireless_log #100320
  677. echo "Result of 'iwconfig ${INTERFACE}':" >> /tmp/sns_wireless_log #100320
  678. iwconfig ${INTERFACE} >> /tmp/sns_wireless_log 2>&1 #100320
  679. echo "" >> /tmp/sns_wireless_log #100320
  680. FLAGERR=7
  681. break
  682. fi
  683. done
  684. if [ $FLAGERR ];then
  685. if [ $fuCNT -ne 0 ];then
  686. kill $PIDX
  687. case $fuCNT in
  688. 1) BGCOLOR="HotPink" ;;
  689. 2) BGCOLOR="pink" ;;
  690. *) BGCOLOR="DeepPink" ;;
  691. esac
  692. yaf-splash -placement center -bg $BGCOLOR -text "$(gettext 'Please keep waiting, retrying encrypted connection...')" &
  693. PIDX=$!
  694. continue #try next FIXUP parameter (see for-loop above). ###BIG FOR LOOP###
  695. fi
  696. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  697. ifconfig $INTERFACE down
  698. else
  699. #finally, run dhcpcd...
  700. MODTIME1="`stat --format=%Y /etc/resolv.conf`"
  701. for iterDHCPCD in a b #100320
  702. do
  703. [ "$iterDHCPCD" = "a" ] && DHCPCDFIX=""
  704. [ "$iterDHCPCD" = "b" ] && DHCPCDFIX="-I ''" #some dhcp servers require empty Client ID (default is macaddress).
  705. echo "STEP6${iterDHCPCD}: dhcpcd $DHCPCDFIX $INTERFACE" >> /tmp/sns_wireless_log
  706. dhcpcd $DHCPCDFIX $(dhcpcd_dropwait_option) $INTERFACE >> /tmp/sns_wireless_log 2>&1 ####DHCP CLIENT#### 121117
  707. mCNT=0
  708. while [ 1 ];do
  709. MODTIME2="`stat --format=%Y /etc/resolv.conf`"
  710. [ "$MODTIME2" != "$MODTIME1" ] && break 2
  711. sleep 1
  712. mCNT=`expr $mCNT + 1`
  713. if [ $mCNT -gt 20 ];then
  714. [ "$iterDHCPCD" != "b" ] && dhcpcd --release $INTERFACE
  715. break
  716. fi
  717. done
  718. done
  719. [ "$MODTIME2" == "$MODTIME1" ] && FLAGERR=6
  720. [ "`grep -v '^#' /etc/resolv.conf`" == "" ] && FLAGERR=6
  721. if [ $FLAGERR ];then
  722. if [ "`pidof wpa_supplicant`" != "" ];then
  723. wpa_cli terminate
  724. killall wpa_supplicant
  725. fi
  726. [ "`iwconfig $INTERFACE | grep "$INTERFACE" | grep "ESSID"`" != "" ] && iwconfig $INTERFACE essid off
  727. ifconfig $INTERFACE down
  728. dhcpcd --release $INTERFACE 2>/dev/null
  729. ip route flush dev $INTERFACE #100703
  730. else
  731. #success!
  732. echo "$INTERFACE" > /tmp/sns_interface_success #101118
  733. #100413 have one pc where blinky did not start. try again...
  734. [ "`which blinky_tray`" ] && [ "`pidof blinky_tray`" = "" ] && blinky_tray &
  735. essidPATTERN='|'"$CELL_ESSID"'|'
  736. touch /etc/simple_network_setup/connections
  737. grep -v "$essidPATTERN" /etc/simple_network_setup/connections > /tmp/sns_temp2
  738. mv -f /tmp/sns_temp2 /etc/simple_network_setup/connections
  739. case $SEC_MGMT in
  740. WEP) ENCODEPROTO="$ONEFIX"; WPA_DRIVER="" ;; #exs: restricted, open
  741. *) ENCODEPROTO="$WPA_ENC" ;; #exs: AES, TKIP
  742. esac
  743. echo "${IFDATA}|${MACADDRESS}|${CELLDATA}|${SEC_KEY}|${SEC_MGMT}|${ENCODEPROTO}|${WPA_DRIVER}|${DHCPCDFIX}|" >> /etc/simple_network_setup/connections
  744. XML_FIREWALL=""
  745. if [ ! -f /etc/rc.d/rc.firewall ];then
  746. XML_FIREWALL='
  747. <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>"
  748. <checkbox>
  749. <label>'$(gettext 'Start firewall')'</label>
  750. <default>true</default>
  751. <variable>CHK_FIREWALL</variable>
  752. </checkbox>
  753. <hseparator></hseparator>'
  754. fi
  755. kill $PIDX
  756. export SNS_complete='
  757. <window title="'$(gettext 'SNS: Simple Network Setup')'" icon-name="gtk-network">
  758. <vbox>
  759. <frame>
  760. '"`/usr/lib/gtkdialog/xml_pixmap dialog-complete popup`"'
  761. <text use-markup="true"><label>"<b>'$(gettext 'Successful connection to wireless network')' '${CELL_ESSID}'</b>"</label></text>
  762. <text><label>""</label></text>
  763. '${XML_FIREWALL}'
  764. <hseparator></hseparator>
  765. <text xalign="0"><label>'$(gettext "Let SNS automatically connect to the Internet at bootup. Also clicking the 'connect' icon on the desktop will immediately launch SNS...")'</label></text>
  766. <checkbox>
  767. <label>'$(gettext 'Set SNS as default network setup tool')'</label>
  768. <default>true</default>
  769. <variable>CHK_SNSDEF</variable>
  770. </checkbox>
  771. </frame>
  772. <hbox>
  773. <button space-expand="false" space-fill="false">
  774. <label>'$(gettext "Ok")'</label>
  775. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  776. <action>exit:OK</action>
  777. </button>
  778. </hbox>
  779. </vbox>
  780. </window>'
  781. RETSTR3="`gtkdialog -p SNS_complete --center`"
  782. if [ "`echo "$RETSTR3" | grep '^CHK_SNSDEF' | grep 'true'`" != "" ];then
  783. echo -e '#!/bin/sh\nexec sns' > /usr/local/bin/defaultconnect
  784. else
  785. echo -e '#!/bin/sh\nexec connectwizard' > /usr/local/bin/defaultconnect
  786. fi
  787. if [ "`echo "$RETSTR3" | grep '^CHK_FIREWALL' | grep 'true'`" != "" ];then
  788. rxvt -e firewallinstallshell
  789. fi
  790. fi #end test dhcpcd timeout.
  791. fi #end test access point.
  792. fi #end test wpa_supplicant timeout.
  793. break
  794. done #end for-loop. ###END BIG FOR LOOP###
  795. fi #end test associate essid.
  796. fi #end test exist security entries.
  797. fi #end test ifconfig up
  798. if [ $FLAGERR ];then
  799. [ $PIDXMSG ] && kill $PIDXMSG
  800. [ $PIDX ] && kill $PIDX
  801. case $SEC_MGMT in
  802. 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.')" ;;
  803. *) ERR_EXTRA1="" ;;
  804. esac
  805. case $FLAGERR in
  806. 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="" ;; #'`"geany
  807. 2) ERR_MSG="$(gettext 'ERROR: you did not specify a Key')" ; ERR_EXTRA1="" ;;
  808. 3) ERR_MSG="$(gettext 'ERROR: you need to choose WEP or WPA security')" ; ERR_EXTRA1="" ;;
  809. 4) ERR_MSG="`eval_gettext \"Failed to associate '\\\${CELL_ESSID}' with ESSID.\"`"; ERR_EXTRA1="" ;; #'`"geany
  810. 7) ERR_MSG="$(gettext 'Failed to obtain Access Point of network.')"; ERR_EXTRA1="" ;;
  811. 5) ERR_MSG="$(gettext 'wpa_supplicant has timed out trying to associate with the network card.')" ;;
  812. 6) ERR_MSG="$(gettext 'DHCP client failed to negotiate with wireless network') '${CELL_ESSID}'" ;;
  813. *) ERR_MSG="$(gettext 'Failed to connect to wireless network') '${CELL_ESSID}'" ;;
  814. esac
  815. export SNS_error='
  816. <window title="'$(gettext 'Simple Network Setup')'" icon-name="gtk-network">
  817. <vbox>
  818. <frame>
  819. '"`/usr/lib/gtkdialog/xml_pixmap dialog-error popup`"'
  820. <text use-markup="true"><label>"<b>'${ERR_MSG}'</b>
  821. '${ERR_EXTRA1}'"</label></text>
  822. <text xalign="0"><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>
  823. </frame>
  824. <hbox space-expand="false" space-fill="false">
  825. <button tooltip-text="'$(gettext 'View log of attempted connection:')'" space-expand="false" space-fill="false">
  826. <label>'$(gettext 'View Log')'</label>'"
  827. <action>echo ' ' >> /tmp/sns_wireless_log</action>
  828. <action>echo '*********************************************************' >> /tmp/sns_wireless_log</action>
  829. <action>echo 'LAST 10 LINES of /var/log/messages:' >> /tmp/sns_wireless_log</action>
  830. <action>tail -n 10 /var/log/messages >> /tmp/sns_wireless_log</action>
  831. <action>defaulttextviewer /tmp/sns_wireless_log & </action>"'
  832. </button>
  833. <text space-expand="true" space-fill="true"><label>""</label></text>
  834. <button space-expand="false" space-fill="false">
  835. <label>'$(gettext "Retry")'</label>
  836. '"`/usr/lib/gtkdialog/xml_button-icon refresh`"'
  837. <action type="exit">BUT_GOBACK</action>
  838. </button>
  839. <button space-expand="false" space-fill="false">
  840. <label>'$(gettext "Quit")'</label>
  841. '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
  842. <action type="exit">BUT_QUIT</action>
  843. </button>
  844. </hbox>
  845. </vbox>
  846. </window>'
  847. RETSTRING="`gtkdialog -p SNS_error --center`"
  848. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_GOBACK'`" != "" ] && exec sns
  849. fi
  850. exit
  851. fi #end test "$IF_INTTYPE" == "Wireless"
  852. ############Wired setup###############
  853. if [ "$IF_INTTYPE" == "Wired" ];then
  854. yaf-splash -placement center -bg orange -text "$(gettext 'Please wait, trying to connect to interface') '${INTERFACE}'..." &
  855. PIDXX=$!
  856. echo "Information about this interface:
  857. Interface: $INTERFACE Driver: $IF_DRIVER Bus: $IF_BUS MacAddress: $MACADDRESS
  858. Description: $IF_INFO
  859. " > /tmp/sns_wired_log
  860. MODTIME1="1"; MODTIME2="1"
  861. ifconfig $INTERFACE up >> /tmp/sns_wired_log 2>&1
  862. [ $? -eq 0 ] && MODTIME2="0"
  863. if [ "$MODTIME2" == "0" ];then
  864. if ! ifplugstatus-0.18 "$INTERFACE" | grep -F -q 'link beat detected' ;then
  865. sleep 1
  866. if ! ifplugstatus "$INTERFACE" | grep -F -q 'link beat detected' ;then
  867. sleep 1
  868. if ! ifplugstatus-0.18 "$INTERFACE" | grep -F -q 'link beat detected' ;then
  869. sleep 1
  870. if ! ifplugstatus "$INTERFACE" | grep -F -q 'link beat detected' ;then
  871. # add ethtool test, just in case it helps at times...
  872. sleep 1
  873. if ! ethtool "$INTERFACE" | grep -Fq 'Link detected: yes' ; then
  874. ifconfig $INTERFACE down
  875. kill $PIDXX
  876. /usr/lib/gtkdialog/box_ok "$(gettext 'Simple Network Setup')" error "<b>$(gettext 'There does not seem to be any network connected to') ${INTERFACE}</b>" " " "$(gettext "Is the network cable unplugged? Modem router turned off? If you can fix it, great, otherwise try a different interface.")"
  877. exec sns
  878. exit
  879. fi
  880. fi
  881. fi
  882. fi
  883. fi
  884. MODTIME1="`stat --format=%Y /etc/resolv.conf`"
  885. DHCPCDFIX=""
  886. dhcpcd $INTERFACE >> /tmp/sns_wired_log 2>&1
  887. MODTIME2="`stat --format=%Y /etc/resolv.conf`"
  888. [ "`grep -v '^#' /etc/resolv.conf`" == "" ] && MODTIME2=$MODTIME1 #fail.
  889. if [ "$MODTIME2" = "$MODTIME1" ];then #100325 fail, try again.
  890. DHCPCDFIX="-I ''"
  891. dhcpcd --release $INTERFACE
  892. dhcpcd -I '' $INTERFACE >> /tmp/sns_wired_log 2>&1
  893. MODTIME2="`stat --format=%Y /etc/resolv.conf`"
  894. [ "`grep -v '^#' /etc/resolv.conf`" == "" ] && MODTIME2=$MODTIME1 #fail.
  895. fi
  896. fi
  897. kill $PIDXX
  898. if [ "$MODTIME2" != "$MODTIME1" ];then
  899. export SNS_complete='
  900. <window title="'$(gettext 'SNS: Simple Network Setup')'" icon-name="gtk-network">
  901. <vbox>
  902. <frame>
  903. '"`/usr/lib/gtkdialog/xml_pixmap dialog-complete popup`"'
  904. <text use-markup="true"><label>"<b>'$(gettext 'Successful connection to wired network')' '${INTERFACE}'</b>"</label></text>
  905. <text><label>""</label></text>
  906. <hseparator></hseparator>
  907. <text xalign="0"><label>'$(gettext "Let SNS automatically connect to the Internet at bootup. Also clicking the 'connect' icon on the desktop will immediately launch SNS...")'</label></text>
  908. <checkbox>
  909. <label>'$(gettext 'Set SNS as default network setup tool')'</label>
  910. <default>true</default>
  911. <variable>CHK_SNSDEF</variable>
  912. </checkbox>
  913. </frame>
  914. <hbox>
  915. <button space-expand="false" space-fill="false">
  916. <label>'$(gettext "Ok")'</label>
  917. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  918. <action>exit:OK</action>
  919. </button>
  920. </hbox>
  921. </vbox>
  922. </window>'
  923. RETSTR5="`gtkdialog -p SNS_complete --center`"
  924. if [ "`echo "$RETSTR5" | grep '^CHK_SNSDEF' | grep 'true'`" != "" ];then
  925. echo -e '#!/bin/sh\nexec sns' > /usr/local/bin/defaultconnect
  926. else
  927. echo -e '#!/bin/sh\nexec connectwizard' > /usr/local/bin/defaultconnect
  928. fi
  929. MACADDRESS="`ifconfig $INTERFACE | grep -o 'HWaddr .*' | cut -f 2 -d ' '`"
  930. aPATTERN='|'"$MACADDRESS"'|'
  931. touch /etc/simple_network_setup/connections
  932. grep -v "$aPATTERN" /etc/simple_network_setup/connections > /tmp/sns_temp2
  933. mv -f /tmp/sns_temp2 /etc/simple_network_setup/connections
  934. echo "${IFDATA}|${MACADDRESS}|${DHCPCDFIX}|" >> /etc/simple_network_setup/connections
  935. else
  936. ifconfig $INTERFACE down
  937. dhcpcd --release $INTERFACE 2>/dev/null
  938. ip route flush dev $INTERFACE #100703
  939. export SNS_error='
  940. <window title="'$(gettext 'Simple Network Setup')'" icon-name="gtk-network">
  941. <vbox>
  942. <frame>
  943. '"`/usr/lib/gtkdialog/xml_pixmap dialog-error popup`"'
  944. <text use-markup="true"><label>"<b>'$(gettext 'Failed to connect to wired network')' '${INTERFACE}'</b>"</label></text>
  945. <text xalign="0"><label>'$(gettext "The network does exist, however failed to negotiate with the DHCP server. Is there a wireless interface? -- maybe try that.")'</label></text>
  946. </frame>
  947. <hbox space-expand="false" space-fill="false">
  948. <button tooltip-text="'$(gettext 'View log of attempted connection:')'" space-expand="false" space-fill="false">
  949. <label>'$(gettext 'View Log')'</label>
  950. <action>defaulttextviewer /tmp/sns_wired_log & </action>
  951. </button>
  952. <text space-expand="true" space-fill="true"><label>""</label></text>
  953. <button space-expand="false" space-fill="false">
  954. <label>'$(gettext "Retry")'</label>
  955. '"`/usr/lib/gtkdialog/xml_button-icon refresh`"'
  956. <action type="exit">BUT_GOBACK</action>
  957. </button>
  958. <button space-expand="false" space-fill="false">
  959. <label>'$(gettext "Quit")'</label>
  960. '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
  961. <action type="exit">BUT_QUIT</action>
  962. </button>
  963. </hbox>
  964. </vbox>
  965. </window>'
  966. RETSTRING="`gtkdialog -p SNS_error --center`"
  967. [ "`echo "$RETSTRING" | grep '^EXIT' | grep 'BUT_GOBACK'`" != "" ] && exec sns
  968. fi
  969. exit
  970. fi
  971. ###END###