Advertisement
JudeAustin

EWOC UPDATE

Mar 22nd, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.75 KB | None | 0 0
  1. #! /bin/bash
  2. # ewoc-z2sid.sh Jan-05-2011 aka Easy Wifi Configurator -- EWoC
  3. # By Russell K. Davis with input from jaldher, g8787/geordy, Ray Dios Haque, pcurtis, wicknix, brianith, lfod, and mozzwald
  4. backtitle="Easy Wifi Configurator -- EWoC"
  5.  
  6. wifidevice=wlan0
  7.  
  8. ifconfig "$wifidevice" up > /dev/null 2>&1
  9.  
  10. if [ -n "`pidof wpa_supplicant`" ]; then
  11.     kill `pidof wpa_supplicant`
  12. fi
  13.  
  14. if [ -n "`pidof udhcpc`" ]; then
  15.     kill `pidof udhcpc`
  16. fi
  17.  
  18. current=1
  19. if [ -e /etc/wpa.conf ]; then
  20.     #currentssid=`grep ssid /etc/wpa.conf | sed -e 's/.*ssid="//' -e 's/"//'`
  21.     dialog --backtitle "$backtitle" --title "wpa.conf" --yesno "Use previously saved access points?" 6 0
  22.     current=$?
  23. fi
  24.  
  25. if [ $current -ne 0 ]; then
  26.     iwlist $wifidevice scan | grep 'ESSID' | sed -e 's/.*ESSID:"\([^"]\+\)".*/  \1/' > /tmp/ap_list.txt
  27. #todo: needs rewriting to use --file
  28.     echo "dialog --nocancel --backtitle \"$backtitle\" \\" > /tmp/choose_ap.sh
  29.     echo "--title \"Choose SSID\" \\" >> /tmp/choose_ap.sh
  30.     echo "--radiolist \"\" \\" >> /tmp/choose_ap.sh
  31.  
  32.     LINES=`wc -l < /tmp/ap_list.txt`
  33.     LINES=$((${LINES}+1))
  34.     echo "8 30 ${LINES} \\" >> /tmp/choose_ap.sh
  35.     CNT=1
  36.     for LINE in `cat /tmp/ap_list.txt`
  37.     do
  38.         echo "${CNT} $LINE off \\" >> /tmp/choose_ap.sh
  39.             CNT=$((${CNT}+1))
  40.         done
  41.         echo "${CNT} NAMED\ SSID on 2>/tmp/ssidnumber.ans" >>/tmp/choose_ap.sh
  42.  
  43.     chmod 777 /tmp/choose_ap.sh
  44.         . /tmp/choose_ap.sh
  45.  
  46.         CHOOSENSSID=`cat /tmp/ssidnumber.ans`
  47.  
  48.         if [ $CHOOSENSSID == $LINES ]; then
  49.         dialog --nocancel --ok-label "Submit" \
  50.         --backtitle "$backtitle" \
  51.         --title "SSID" \
  52.         --inputbox ""  8 30 2>/tmp/ssid.ans
  53.     else
  54.         count=1
  55.         while read ssid; do
  56.             if [ $count = $CHOOSENSSID ]; then
  57.                 echo "`echo $ssid | sed -e 's/^[ \t]*//'`" >/tmp/ssid.ans
  58.             fi
  59.             let count=$count+1
  60.         done </tmp/ap_list.txt
  61.  
  62.         #cat /tmp/ap_list.txt | gawk -v SSID=$CHOOSENSSID '{ if (NR==SSID) print $0 }' | sed -e 's/^[ \t]*//' >/tmp/ssid.ans
  63.     fi
  64.  
  65.     dialog --nocancel --backtitle "$backtitle" \
  66.          --title "Cipher Method" \
  67.          --radiolist "" \
  68.          8 30 4 \
  69.          1 "WPA/WPA2" on \
  70.          2 "WEP (hex)" off \
  71.          3 "WEP (ascii)" off \
  72.          4 "None" off 2>/tmp/cipher.ans
  73.  
  74.  
  75.     SSID=`cat /tmp/ssid.ans`
  76.     ENCRYPTION=`cat /tmp/cipher.ans`
  77.  
  78.     case $ENCRYPTION in
  79.         '1')
  80.             dialog --nocancel --ok-label "Submit" \
  81.                 --backtitle "$backtitle" \
  82.                     --title "Passphrase" \
  83.                     --inputbox ""  8 30 2>/tmp/passphrase.ans
  84.                     PASSPHRASE=`cat /tmp/passphrase.ans`
  85.             wpa_passphrase $SSID $PASSPHRASE >>/etc/wpa.conf
  86.             wpa_supplicant -B -i$wifidevice -c /etc/wpa.conf
  87.         ;;
  88.         '2')
  89.             dialog --nocancel --ok-label "Submit" \
  90.             --backtitle "$backtitle" \
  91.             --title "Passphrase" \
  92.             --inputbox "WEP key (hex)"  8 30 2>/tmp/passphrase.ans
  93.             PASSPHRASE=`cat /tmp/passphrase.ans`
  94.  
  95.                     echo "network={
  96.                             ssid=\"$SSID\"
  97.                             key_mgmt=NONE
  98.                             wep_key0=$PASSPHRASE
  99.                             }" >> /etc/wpa.conf
  100.                 wpa_supplicant -B -i$wifidevice -c /etc/wpa.conf
  101.         ;;
  102.         '3')
  103.             dialog --nocancel --ok-label "Submit" \
  104.               --backtitle "$backtitle" \
  105.               --title "Passphrase" \
  106.               --inputbox "WEP key (ascii)"  8 30 2>/tmp/passphrase.ans
  107.             PASSPHRASE=`cat /tmp/passphrase.ans`
  108.  
  109.             echo "network={
  110.                        ssid=\"$SSID\"
  111.                        key_mgmt=NONE
  112.                        wep_key0=\"$PASSPHRASE\"
  113.                        }" >> /etc/wpa.conf
  114.                 wpa_supplicant -B -i$wifidevice -c /etc/wpa.conf
  115.         ;;
  116.         '4')
  117.             iwconfig wlan0 mode managed
  118.             iwconfig wlan0 essid \"$SSID\"
  119.             iwconfig wlan0 key OPEN
  120.             iwconfig wlan0 channel auto
  121.  
  122.  
  123.         ;;
  124.     esac
  125. fi
  126.  
  127. clear
  128. udhcpc -i $wifidevice -n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement