WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: wifi.sh : proposed patch  (Read 3854 times)

Offline homsky

  • WikiUser
  • *
  • Posts: 2
wifi.sh : proposed patch
« on: September 16, 2012, 06:21:34 AM »
Hello,

wifi.sh proposed patch.
In sort :
1) A wlan is already connected when an ip address is set and associated with an access point
2) Add a new choice (in menu) in order to set manually :
    2.1) Ip host address
    2.2) network mask
    2.3) gateway ip address
    2.4) Ip address for DNS server

How to make an attachment ?
I can't use "Insert code " have message : "Sorry, you are not allowed to post external links" so using a "Insert quote".

diff -u results :
Quote
--- /usr/local/bin/wifi.sh
+++ ./wifi.sh
@@ -25,18 +25,22 @@
 fi
 
 echo "Found wifi device $WIFI"
-# Check if already connected!
 if [ ${MODE} == "menu" ]; then
+   # Check if IP are already set (Access point may be connected or not)
    ifconfig|awk 'BEGIN{RS=""}/'${WIFI}'/'|grep -q 'inet addr'
    if [ "$?" == 0 ]; then
-      echo
-      echo "Already connected!"
-      ifconfig ${WIFI}
-      echo -n "Disconnect and Scan? (y/n): ";read ans
-      [ "${ans:0:1}" != "y" ] && exit
-      cleanup
-      sleep 5
-   fi   
+      # Check if Acces point Associated!
+      iwconfig ${WIFI}| grep -q  Not-Associated
+      if [ "$?" != 0 ]; then
+         echo
+         echo "Already connected!"
+         ifconfig ${WIFI}
+         echo -n "Disconnect and Scan? (y/n): ";read ans
+         [ "${ans:0:1}" != "y" ] && exit
+         cleanup
+         sleep 5
+      fi
+   fi
 fi
 
 echo "Standby for scan of available networks..."
@@ -95,6 +99,36 @@
       }
 }
 
+function setipaddresses(d) {
+   do {
+      addr ="192.168.1.1"
+      printf("Enter host ip address (i.e " addr ") : ")
+      ipaddr = read_console()
+      if (ipaddr == "") { ipaddr = addr }
+      mask ="255.255.255.0"
+      printf("Enter host net mask (i.e " mask ") : ")
+      netmask = read_console()
+      if (netmask == "") { netmask = mask }
+   }
+   while (system("ifconfig " d  " " ipaddr " netmask " netmask " up") != 0)
+   do {
+      addr ="192.168.1.254"
+      printf("Enter ip gateway address (i.e " addr ") : ")
+      ipaddr = read_console()
+      if (ipaddr == "") { ipaddr = addr }
+   }
+   while (system("route add default gw " ipaddr ) != 0)
+   
+   #Fortunaly nslookup belongs to busybox so no need to check if it is presents
+   do {
+      addr = "127.0.0.1"
+      printf("Enter DNS ip address (i.e " addr ") : ")
+      ipaddr = read_console()
+      if (ipaddr == "") { ipaddr = addr }
+   }
+   while (system("nslookup " addr ipaddr " 2>&1 1>/dev/null ") != 0)
+}
+
 # Awk Main()
 {
    if ($1 ~ /Cell/)
@@ -190,10 +224,18 @@
       } else {
          system("iwconfig " wifi " essid " sid[selection] " channel " chan[selection])
       }
-      results = system( "udhcpc -n -i " wifi " 2>/dev/null")
-      if ( results == 0 )
-         if ( newitem == 1 )
-            printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile
+      #Choose automatic or manual setting IP adresses
+      printf "(a)utomatic or (m)anual IP adresses configuration ? "
+      selection = read_console()
+      if (selection == "m") {
+         setipaddresses(wifi)
+      }
+      else {
+         results = system( "udhcpc -n -i " wifi " 2>/dev/null")
+         if ( results == 0 )
+            if ( newitem == 1 )
+               printf("%s\t%s\t%s\n", sid[selection] ,password, type[selection] ) >> dbfile
+      }
    }
 } '
 ifconfig|awk 'BEGIN{RS=""}/'${WIFI}'/'|grep -q 'inet addr'

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.sh : proposed patch
« Reply #1 on: September 16, 2012, 01:39:40 PM »
It is hard to copy and paste from post. Please email me your patch and I will apply. Thanks!
10+ Years Contributing to Linux Open Source Projects.

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.sh : proposed patch
« Reply #2 on: September 17, 2012, 02:01:05 PM »
Received patch. Thanks! One small change in:
Code: [Select]
while (system("nslookup " addr ipaddr " 2>&1 1>/dev/null ") != 0)
to be:
Code: [Select]
while (system("nslookup " addr " " ipaddr " 2>&1 1>/dev/null ") != 0)
And then it works fine.
Thanks. It is a nice addition.

Posted in repository.
« Last Edit: September 17, 2012, 02:14:33 PM by roberts »
10+ Years Contributing to Linux Open Source Projects.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: wifi.sh : proposed patch
« Reply #3 on: October 17, 2012, 11:17:36 PM »
This patch, thanks.   as nice an addition as it is, has introduced one small feature and broken or if you like inhibited the ability for the wifi script to successfully auto connect with a DHCP AP without user intervention.  Whereas with wifi.sh version 0.8 (I believe) allows to be run at system start-up and continues to run until completion of the wifi connection ( assuming of course the AP credentials are stored in the db ). 

The immediate issue I face is that the script stops at this prompt, while waiting for selection of both " a " and " Enter ".   neither should be necessary..

Code: [Select]
printf "(a)utomatic or (m)anual IP adresses configuration ? "
selection = read_console()


In my limited shell scripting experience I normally resolve this scenario by utilizing a read command with an echoed default selection on timeout followed by a case construct to provide a default choice after 2 or 3 seconds.  something like this:

Code: [Select]
read -n1 -t 2 ans
echo -e "${ans:=a}"

Unfortunately I am still trying to implement this into the patch or offer as a patch to the  read_console() function.  Actually am trying to resolve the issue in a simplistic manor, so far all my resolutions have been far too extensive.    So am looking for some help here.

My goals are
to restore automatic connection on boot up (as in pre-patch application) without loosing features
have default selections on time out wherever possible
continuation of script after single character selection ( as in -n1 ) without additionally selecting "Enter" in places where a string is not required.
 

Maybe there is another way ?  Am sure Roberts will show us an easy fix.



PS the spelling of addresses in the echoed auto or manual IP prompt of the patch is incorrect also.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: wifi.sh : proposed patch
« Reply #4 on: October 17, 2012, 11:27:30 PM »
Additionally, I'd like to propose a patch that improves the " Disconnect and Scan " selection with a simple syntax and message addition.  It achieves a reduction in required user input.


from this:
Code: [Select]
echo "Found wifi device $WIFI"
if [ ${MODE} == "menu" ]; then
# Check if IP are already set (Access point may be connected or not)
ifconfig|awk 'BEGIN{RS=""}/'${WIFI}'/'|grep -q 'inet addr'
if [ "$?" == 0 ]; then
# Check if Acces point Associated!
iwconfig ${WIFI}| grep -q  Not-Associated
if [ "$?" != 0 ]; then
echo
echo "Already connected!"
ifconfig ${WIFI}
echo -n "Disconnect and Scan? (y/n): ";read ans
[ "${ans:0:1}" != "y" ] && exit
cleanup
sleep 5
fi
fi
fi


to this
Code: [Select]
echo "Found wifi device $WIFI"
if [ ${MODE} == "menu" ]; then
# Check if IP are already set (Access point may be connected or not)
ifconfig|awk 'BEGIN{RS=""}/'${WIFI}'/'|grep -q 'inet addr'
if [ "$?" == 0 ]; then
# Check if Acces point Associated!
iwconfig ${WIFI}| grep -q  Not-Associated
if [ "$?" != 0 ]; then
echo
echo "Already connected!"
ifconfig ${WIFI}
echo -n "Disconnect and Scan? (y/n): "
read -n1 rescan
[ "${rescan:0:1}" != "y" ] && exit
echo -e "\ncleaning up... \n"
cleanup
sleep 5
fi
fi
fi
« Last Edit: October 17, 2012, 11:44:25 PM by coreplayer2 »

Offline homsky

  • WikiUser
  • *
  • Posts: 2
Re: wifi.sh : proposed patch
« Reply #5 on: October 18, 2012, 06:02:37 AM »
Hello,

A
"
if [ -f /home/tc/wifi.db ] ; then
Yes "a" | wifi.sh 
else
 wifi.sh
fi
"
should do the job for automatic connecting.

Regards

Offline ananix

  • Full Member
  • ***
  • Posts: 174
Re: wifi.sh : proposed patch
« Reply #6 on: October 18, 2012, 06:47:57 AM »
Funny this post pops up as i have just written about this subject else where.
The auto option seems to be broken because of field one (SSID) is missing in the wifi.db
The workaround to the problem is to add the field yourself by hand.
The solution to the problem would be to fix it in the script when it writes the wifi.db

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.sh : proposed patch
« Reply #7 on: October 18, 2012, 07:00:01 AM »
The latest patch must have broken wifi,sh as auto connect as per the info file still works as expected on wifi.db prior to patch, I will look to fix.
10+ Years Contributing to Linux Open Source Projects.

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.sh : proposed patch
« Reply #8 on: October 18, 2012, 07:42:01 AM »
Found bug in last accepted patch. Fixed it.
wifi.db is once again correctly created upon a successful connection.
Posting corrected wifi.tcz in repository now.
10+ Years Contributing to Linux Open Source Projects.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: wifi.sh : proposed patch
« Reply #9 on: October 19, 2012, 09:42:54 PM »
Thank you Roberts,  we appreciate your efforts to continuously improve the core project.

The bug fix rectified an issue thanks,  Yet am still unable to auto connect, mostly due to required user input.     Additionally some other minor issues have risen which also prevent auto connection from being established.

Currently the bug fix allows for correct creation of the wifi.db file, ok great, thank you.   unfortunately the db file does not get appended with new AP information.    when attempting to connect with a new AP, the wifi script attempts to connect with the ID and password from the previously saved AP credentials.  as a result no list of AP's are enumerated and no connection is made.    eg. my notebook with wifi.sh v 1.0 is attempting to connect with an AP located in Chicago using the credentials of the AP at my home in California.  ??

I am more than willing to devote some time to help in resolving these issues, please let me know what I can do to help.   If testing is time consuming, I can definitely help with that.



 
« Last Edit: October 19, 2012, 09:46:59 PM by coreplayer2 »

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.sh : proposed patch
« Reply #10 on: October 20, 2012, 06:54:31 AM »
I auto connect daily with no user input using wifi.sh v1.0.
An open wifi does not update wifi.db as no credentials are required.
I will have to travel to some other wifi that requires credentials to test your claim.
Hopefully you are not always launching with the auto option as such is typically the case in bootlocal.sh
The icon, menu, or from the command prompt one would normally not use the auto option.
10+ Years Contributing to Linux Open Source Projects.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: wifi.sh : proposed patch
« Reply #11 on: October 20, 2012, 07:14:10 AM »
I use the AUTO option every single boot.  Actually use a script to give priority to an Ethernet connection, if none available the script launches wifi.sh to auto connect with no user intervention needed, unless a new AP is found and a password is required.

One selection should require one keystroke, not double the effort..

Roberts am just trying to improve what we have is all.


I'll chattr 0.8 to prevent further disruption by possible updates in the meantime.  I can't utilize v1.0 at all sorry.  But am more than willing to help in any way I can to rectify the issues

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.sh : proposed patch
« Reply #12 on: October 20, 2012, 08:04:11 AM »
Then is it my understanding that you feel having the choice of specifying an IP or having an automatic assignment is a regression?
10+ Years Contributing to Linux Open Source Projects.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
wifi.sh : proposed patch
« Reply #13 on: October 20, 2012, 11:41:59 AM »
Not at all, i regard this patch as a positive addition which is absolutely worth the challenge.  If it adds features, or improves user experience even for only one or two folks I'm 100% all for it.   I just don't feel it fair to create and accommodate a minority at the expense of inconveniencing the majority in the process.  everybody deserves a slick interface and awesome experience,  auto or man selection is an issue but only one of several. 
Roberts there is no question you are a God of coding and have already found and fixed one flaw in minutes, thank you.  But there are others, some mentioned above which am sure you can fix in minutes what has been a week of head scratching and coffee for me.   
 
 I'm sure everyone welcomes the manual IP feature, hopefully there'll be many more features to come.  but please let's not forget how this addition has impacted the experience of the majority of users who use DHCP and prefer to keep the slick interface and ability to connect easily with a minimal if any key strokes.






Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: wifi.sh : proposed patch
« Reply #14 on: October 20, 2012, 06:51:18 PM »
Agree that manual IP configuration for a wireless device is less usual if not unusual.
Therefore I have added flags to wifi.tcz v1.1 for such case.

Usage:
  Default select AP from menu and request IP via DHCP.
  -a Auto connect to first wifi.db entry via DHCP.
  -p Select AP from menu and prompt for IP configuration type.
  -? Displays this help message.

Note: Requires a change from current "auto" to -a
And for those that require or wish to specify configuration type -p for "prompt".

Note: However, I do not agree with suggestion regarding input. I prefer consistent use of Enter key. Rather than sometimes it is required and sometimes it is not.

This update should provide that same "auto" user experience as v0.8.
10+ Years Contributing to Linux Open Source Projects.