Advertisement
s243a

useWpaSupplicant () - /usr/sbin/wag-profiles.sh - puppylinux

Oct 2nd, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.81 KB | None | 0 0
  1. # Line 1523 of /usr/sbin/wag-profiles.sh
  2. # http://www.pearltrees.com/s243a/usewpasupplicant-puppylinux/id16403191
  3. useWpaSupplicant ()
  4. {
  5.     # add an option for running some parts only from the wizard
  6.     if [ "$1" = "wizard" ] ; then
  7.         # Dougal: moved all below code to a function
  8.         getWpaPSK || return 1
  9.         # Dougal: make wpa_supplicant config file match mac address
  10.         WPA_CONF="${WPA_SUPP_DIR}/${PROFILE_AP_MAC}.${PROFILE_ENCRYPTION}.conf"
  11.         if [ ! -e "$WPA_CONF" ] ; then
  12.             # copy template
  13.             #cp -a "${WPA_SUPP_DIR}/wpa_supplicant$PROFILE_WPA_TYPE.conf" "$WPA_CONF"
  14.             # no, now this is done while saving, give message if failed
  15.             giveErrorDialog "$L_MESSAGE_No_Wpaconfig_p1
  16. $WPA_CONF
  17. $L_MESSAGE_No_Wpaconfig_p2"
  18.             return 1
  19.         fi
  20.         #TMPLOG="/tmp/wag-profiles_tmp.log"
  21.         #rm "$TMPLOG" >> $DEBUG_OUTPUT 2>&1
  22.         cleanUpInterface "$INTERFACE" >> $DEBUG_OUTPUT 2>&1
  23.     else # running from rc.network
  24.         WPA_CONF="$1"
  25.     fi #if [ "$1" = "wizard" ] ; then  
  26.     # Dougal: give the text message even when using dialog (for debugging)
  27.     echo "Configuring interface $INTERFACE to network $PROFILE_ESSID with wpa_supplicant..." >> $DEBUG_OUTPUT
  28.    
  29.     ###### run dialog
  30.     if [ "$HAVEX" = "yes" ]; then
  31.         # Create a temporary fifo to pass messages to progressbar (can't just pipe to it)
  32.         PROGRESS_OUTPUT=/tmp/progress-fifo$$
  33.         mkfifo $PROGRESS_OUTPUT
  34.         # The progressbar dialog
  35.         # It contains a loop that starts from 1 and increments by 3, so 1+33*3=100%
  36.         # (33= first three messages + 30 iterations of loop in validate...)
  37.         # If it recieves "end" it will skip to 100.
  38.         export NETWIZ_Scan_Progress_Dialog="<window title=\"$L_TITLE_Network_Wizard\" icon-name=\"gtk-network\" window-position=\"1\">
  39. <vbox>
  40.  <text><label>\"${L_TEXT_WPA_Progress_p1}${PROFILE_ENCRYPTION}${L_TEXT_WPA_Progress_p2}${PROFILE_ESSID}${L_TEXT_WPA_Progress_p3}\"</label></text>
  41.  <frame $L_FRAME_Progress>
  42.      <progressbar>
  43.      <label>Connecting</label>
  44.      <input>i=1 ; while read bla ; do i=\$((i+3)) ; case \$bla in end) i=100 ;; esac ; echo \$i ;echo \"\$bla\" ; done</input>
  45.      <action type=\"exit\">Ready</action>
  46.    </progressbar>
  47.  </frame>
  48.  <hbox>
  49.   <button>
  50.     <label>$L_BUTTON_Abort</label>
  51.     <input file stock=\"gtk-stop\"></input>
  52.     <action>EXIT:Abort</action>
  53.   </button>
  54.  </hbox>
  55. </vbox>
  56. </window>"
  57.         gtkdialog3 --program=NETWIZ_Scan_Progress_Dialog <$PROGRESS_OUTPUT &
  58.         local XPID=$!
  59.     else
  60.         PROGRESS_OUTPUT=$DEBUG_OUTPUT
  61.     fi
  62.     # Use a subshell to redirect echoes to fifo
  63.     # (need one subshell, since redirecting something like a function will
  64.     #+ freeze the progress bar when it ends)
  65.     ####################################################################
  66.     (
  67.         echo "$L_ECHO_Starting"
  68.         # Dougal: add increasing of rate for ath5k
  69.         case $INTMODULE in ath5k*) iwconfig "$INTERFACE" rate 11M >> $DEBUG_OUTPUT 2>&1;; esac  
  70.         echo "$L_ECHO_Initializing_Wpa"
  71.         wpa_supplicant -i "$INTERFACE" -D "$PROFILE_WPA_DRV" -c "$WPA_CONF" -B >> $DEBUG_OUTPUT 2>&1
  72.         echo "Waiting for connection... " >> $DEBUG_OUTPUT 2>&1
  73.         echo "trying to connect"
  74.         # Dougal: use function based on wicd code
  75.         # (note that it echoes the X's for the progress dialog)
  76.         # have different return values:
  77.         validateWpaAuthentication "$INTERFACE" "$XPID"
  78.         case $? in
  79.          0) # success  
  80.            #WPA_STATUS="COMPLETED"
  81.            echo "COMPLETED" >/tmp/wpa_status.txt
  82.            echo "completed" >> $DEBUG_OUTPUT
  83.            # end the progress bar
  84.            echo end
  85.            ;;
  86.          1) # timeout
  87.            echo "timeout" >> $DEBUG_OUTPUT
  88.            # end the progress bar
  89.            echo end
  90.            ;;
  91.          2) # user aborted
  92.            echo aborted >>$DEBUG_OUTPUT
  93.            ;;
  94.          3) # error
  95.            echo "error while running:" >>$DEBUG_OUTPUT
  96.            echo "wpa_cli -i $INTERFACE status | grep 'wpa_state=' " >>$DEBUG_OUTPUT
  97.            # end the progress bar
  98.            echo end
  99.            ;;
  100.         esac
  101.        
  102.         # Dougal: close the -n above
  103.         echo  >> $DEBUG_OUTPUT 2>&1
  104.         #echo -n "$WPA_STATUS" > /tmp/wpa_status.txt
  105.         #echo "---" >> ${TMPLOG} 2>&1
  106.     ) >>$PROGRESS_OUTPUT
  107.     ####################################################################
  108.   #| Xdialog --title "Puppy Ethernet Wizard" --progress "Acquiring WPA connection\n\nThere may be a delay up to 60 seconds." 0 0 20
  109.     if [ "$XPID" ] ;then
  110.       kill $XPID >/dev/null 2>&1
  111.       clean_up_gtkdialog NETWIZ_Scan_Progress_Dialog
  112.     fi
  113.     unset NETWIZ_Scan_Progress_Dialog
  114.     ###########
  115.     if [ "$HAVEX" = "yes" ]; then # it's a pipe
  116.         rm $PROGRESS_OUTPUT
  117.     fi
  118.     #cat $TMPLOG >> $DEBUG_OUTPUT
  119.     WPA_STATUS="$(cat /tmp/wpa_status.txt)"
  120.     rm /tmp/wpa_status.txt
  121.    
  122.     if [ "$WPA_STATUS" = "COMPLETED" ] ; then
  123.         return 0
  124.     fi
  125.     # if we're here, it failed
  126.     if [ "$1" = "wizard" ] && [ "$HAVEX" = "yes" ] ; then
  127.         export NETWIZ_No_WPA_Connection_Dialog="<window title=\"$L_TITLE_Puppy_Network_Wizard\" icon-name=\"gtk-dialog-error\" window-position=\"1\">
  128. <vbox>
  129.  <pixmap icon_size=\"6\"><input file stock=\"gtk-dialog-error\"></input></pixmap>
  130.  <text>
  131.    <label>\"$L_MESSAGE_WPA_Failed\"</label>
  132.  </text>
  133.  <hbox>
  134.   <button ok></button>
  135.   <button>
  136.    <label>$L_BUTTON_Details</label>
  137.    <input file stock=\"gtk-info\"></input>
  138.    <action>EXIT:Details</action>
  139.   </button>
  140.  </hbox>
  141. </vbox>
  142. </window>"
  143.         I=$IFS; IFS=""
  144.         for STATEMENT in  $(gtkdialog3 --program NETWIZ_No_WPA_Connection_Dialog); do
  145.             eval $STATEMENT
  146.         done
  147.         IFS=$I
  148.         clean_up_gtkdialog NETWIZ_No_WPA_Connection_Dialog
  149.         unset NETWIZ_No_WPA_Connection_Dialog
  150.         if [ "$EXIT" = "Details" ] ; then
  151.           EXIT="Refresh"
  152.           while [ "$EXIT" = "Refresh" ] ; do
  153.             # iwconfig info
  154.             IW_INFO="$(iwconfig $INTERFACE |grep -o 'Access Point: .*\|Link Quality:[0-9]* ' )"
  155.             export NETWIZ_WPA_Status_Dialog="<window title=\"$L_TITLE_Puppy_Network_Wizard\" icon-name=\"gtk-network\" window-position=\"1\">
  156. <vbox>
  157.  <frame $L_FRAME_Connection_Info >
  158.  <text>
  159.    <label>\"$IW_INFO\"</label>
  160.  </text>
  161.  </frame>
  162.  <frame ${L_FRAME_wpa_cli_Outeput}'wpa_cli -i $INTERFACE status' >
  163.   <edit cursor-visible=\"false\" accepts-tab=\"false\">
  164.    <variable>EDITOR</variable>
  165.    <width>300</width><height>150</height>
  166.    <default>\"$(wpa_cli -i $INTERFACE status 2>&1)\"</default>
  167.   </edit>
  168.  </frame>
  169.  <hbox>
  170.   <button>
  171.    <label>$L_BUTTON_Refresh</label>
  172.    <input file stock=\"gtk-refresh\"></input>
  173.    <action>EXIT:Refresh</action>
  174.   </button>
  175.   <button ok></button>
  176.  </hbox>
  177. </vbox>
  178. </window>"
  179.             I=$IFS; IFS=""
  180.             for STATEMENT in  $(gtkdialog3 --program NETWIZ_WPA_Status_Dialog); do
  181.               eval $STATEMENT
  182.             done
  183.             IFS=$I
  184.           done # while [ "$EXIT" = "Refresh" ]
  185.           clean_up_gtkdialog NETWIZ_WPA_Status_Dialog
  186.           unset NETWIZ_WPA_Status_Dialog
  187.         fi #if [ "$EXIT" = "Details" ] ; then
  188.     fi #if [ "$1" = "wizard" ] && [ "$HAVEX" = "yes" ] ; then
  189.     # if we're here, connection failed -- kill wpa_supplicant!
  190.     wpa_cli -i "$INTERFACE" terminate >>$DEBUG_OUTPUT
  191.     return 1
  192. } # end useWpaSupplicant
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement