Phoenix CE - Connection check at browser launch

A home for all kinds of Puppy related projects
Post Reply
Message
Author
User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

Phoenix CE - Connection check at browser launch

#1 Post by ecomoney »

Something I remember about internet explorer on windows (all those years ago) is that if an active internet connection was not found then a dialog box would come up and ask you if you wanted to configure your internet connection, or continue to work offline. When watching new users try puppy for the first timeI notice that as soon as puppy boots, they try going on the net using seamonkey, and the local launch page shows. They click on one of the links and the browser displays "page cannot be displayed" as they have not run the internet connection wizard as yet.

I believe it would make puppy a lot more friendly if a check for internet connectivity be made before starting the browser (and other applications that require an internet connection) and if one is not present, offer the user a choice to work offline or run the internet connection wizard. There are already several scripts called "defaultbrowser" and such which could be modified to run this?

How would this effect performance (perhaps with a test like "ping www.google.co.uk" ?).
Last edited by ecomoney on Mon 11 Feb 2008, 14:40, edited 1 time in total.
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
cb88
Posts: 1165
Joined: Mon 29 Jan 2007, 03:12
Location: USA
Contact:

#2 Post by cb88 »

can't you start a program from a browser? how about editing the connection error page to have relevant intructions or have it start up the net wizard if possible
Taking Puppy Linux to the limit of perfection. meanwhile try "puppy pfix=duct_tape" kernel parem eater.
X86: Sager NP6110 3630QM 16GB ram, Tyan Thunder 2 2x 300Mhz
Sun: SS2 , LX , SS5 , SS10 , SS20 ,Ultra 1, Ultra 10 , T2000
Mac: Platinum Plus, SE/30

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#3 Post by Pizzasgood »

I did some connection testing code for freshclam in pcPuppyOS, to make sure it waited until there was a connection to try updating (otherwise it would pop up an error message every two hours). This is what I did to make it wait:

Code: Select all

#don't bother starting until there's a network connection (else it spouts errors)
NOCONNECTION=1
while [ ! $NOCONNECTION = 0 ]; do
	ping -c 2 clamav.net
	NOCONNECTION=$?
	[ ! $NOCONNECTION = 0 ] && sleep 300
done
#if we're over here, then there is a connection
Taking out the waiting stuff and modifying it a little gives me this:

Code: Select all

ping -c 1 google.com
NOCONNECTION=$?
if [ ! $NOCONNECTION = 0 ]; then
	#no connection, do stuff here
	
else
	#there's a connection
	
fi
But don't forget that people might want to run the browser to read an HTML file on their drive, in which case they don't care if there's a network connection yet. I think cb88 has the right idea here.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#4 Post by HairyWill »

cb88 wrote:can't you start a program from a browser? how about editing the connection error page to have relevant intructions or have it start up the net wizard if possible
Think about the security implications of that, javascript executing local code.
quirksmode wrote:JavaScript cannot read files from or write them to the file system on the computer. This would be a clear security hazard
http://www.quirksmode.org/js/intro.html
The only way I can think of to do it that way would involve starting a web server to show the help page then you could use serverside scripting to do anything you like. This is a lot of overhead and opens an http port, so now you need a firewall. This reminds me that the local cups interface is automatically accessible over the network, users are currently not given any warning of this. I presume that the cups security model is reasonably well thought out.

You could include the check in the browser start script
show a dialogue box offering to start the net wizard and include a checkbox that says don't show this warning again.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

code

#5 Post by ecomoney »

so, if the "defaultbrowser" script read something like this:-

Code: Select all

ping -c 1 google.com
NOCONNECTION=$?
if [ ! $NOCONNECTION = 0 ]; then
   msgbox "Currently this computer cannot connect to the internet, please check your cables, modem, and run the internet connection wizard under 'menu>setup>setup>connection wizard'. You may continue and work offline, or exit."
else
   exec seamonkey
fi
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

Leachim
Posts: 229
Joined: Sun 27 May 2007, 23:04

better network wizard

#6 Post by Leachim »

I think the main problem is that one have to explicitly call the network wizard. The network setup could be done automatically in many cases - surely not in all cases.

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#7 Post by Pizzasgood »

I think this would be better:

Code: Select all

ping -c 1 google.com
NOCONNECTION=$?
if [ ! $NOCONNECTION = 0 ]; then
   Xdialog --title "No Internet Connection" --msgbox "Currently this computer cannot connect to the internet, please check\nyour cables, modem, and run the internet connection wizard under\n'menu>setup>setup>connection wizard'\nYou may continue and work offline, or exit." 0 0
fi
exec seamonkey
The one you used wouldn't run Seamonkey at all unless there was a connection.
You could include the check in the browser start script
show a dialogue box offering to start the net wizard and include a checkbox that says don't show this warning again.
That would be even better.

I think the main problem is that one have to explicitly call the network wizard. The network setup could be done automatically in many cases - surely not in all cases.
For most people, just having the boot process run dhcpcd eth0 (but with the extra options I never use) would get most people online. It would need to be run in parallel though, or it could really slow down the boot.

An issue with doing that is whether the user wants the machine to auto connect without permission. It wouldn't bother me much, but I know several people who wouldn't like that at all.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

Everitt
Posts: 331
Joined: Tue 19 Dec 2006, 21:59
Location: Leeds,UK or Birmingham, UK

#8 Post by Everitt »

First off, wouldn't it make more sense to export this code to a seperate script, so it could be called from any app startup script. That way it can easily be used for email and IM etc too.
Secondly, couldn't we be more verbose? Try and tell the user why their internet isn't up, not just that it's missing. We could check that there is an interface up, that it has an ip address, that there is a nameserver set, that the name server is accessable etc. That way we aren't dependent on google being up.
If no connection is found then offer to run the wizard, or display a list of results for the above tests, and offer generic solutions (check cables, run wizard, scream, the usual. :) )
I'm using my phone in a lecture ATM, but I'll have a play and maybe suggest some code this afternoon., when I get home.

Everitt
Posts: 331
Joined: Tue 19 Dec 2006, 21:59
Location: Leeds,UK or Birmingham, UK

#9 Post by Everitt »

Ah, here's a problem, Puppy comes with the busybox version of ping, which doesn't support setting the time out, so even with -c 1 it can cause a noticeable delay.

Everitt
Posts: 331
Joined: Tue 19 Dec 2006, 21:59
Location: Leeds,UK or Birmingham, UK

#10 Post by Everitt »

This gets around the ping problem most of the time by using faster methods to determine if it is possible there is a connection first. It also checks that wireless devices are set up, so we have the option give a bit more advice on this slightly trickier area.

Code: Select all

#!/bin/sh
#Script to check fr inet connectivity.
UP=""
for IF in `ifconfig -a | grep encap | grep -v "lo" | cut -d " " -f 1 | tr "\n" " "`; do #some diagnostics on each device
  printf "\n______________________________\n\n$IF\n" #DEBUG
  if [ `ifplugstatus -q $IF; echo $?` == 2 ]; then
    echo "  $IF is plugged in"
    iwconfig $IF &> /tmp/chknetwirelesstempfile
    if ! grep " no wireless extensions." /tmp/chknetwirelesstempfile &> /dev/null; then 
      #it is wireless, so run some extra checks first
      echo "    $IF is wireless"
      #the iwconfig commands refuse to not output to the console for some reason :S
      if grep "radio off" /tmp/chknetwirelesstempfile&> /dev/null; then
        echo "      Wireless not configured. Interface not powered up. Run wizard"
      else
        echo "      Wireless powered on"
      fi
      if grep "ESSID:off/any" /tmp/chknetwirelesstempfile &> /dev/null; then
        echo "      Wireless not configured. No ESSID selected. Run wizard"
      else
        echo "      Wireless ESSID selected"
      fi
    else
      echo "    $IF is wired"
    fi
    if ifconfig $IF | grep "inet addr" > /dev/null; then
      echo "      $IF has an address"
      echo "      adding $IF to list"
      UP=$UP$IF" "
    else
      echo "      $IF has no address"
    fi
  else
    echo "  $IF is not plugged in"
  fi
  rm /tmp/chknetwirelesstempfile > /dev/null #remove tempfile, if it exists
done
if [ `echo "$UP" | wc -c` -gt 1 ]; then
  #it seems everything is in order, so try a ping
  if ping -c 1 www.google.com > /dev/null; then
    exit 0
  else
    if Xdialog --wrap --stdout --yesno "Puppy can't find the internet! Do you want to try and fix this using the network wizard?" 25% 50%; then
      echo "run wizard"
      . /usr/sbin/connectwizard
      exit $? #return the connectwizard's exit value
    else
      echo "exit"
      exit 1
    fi
  fi
else
   if Xdialog --wrap --stdout --yesno "Puppy can't find the internet! Do you want to try and fix this using the network wizard?" 25% 50%; then
     echo "run wizard"
     . /usr/sbin/connectwizard
     exit $? #return the connectwizard's exit value
   else
     echo "exit"
     exit 1
   fi
fi
Last edited by Everitt on Mon 28 Jan 2008, 21:11, edited 1 time in total.

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

Logic

#11 Post by ecomoney »

Youve seen my bash coding, so I hope you understand why I need a written "pseudocode" explaination of what seems to be the start of a very promising internet connection wizard :-)

I have no idea of programming constructs in Bash, but I do know code needs to have "layers" and specific code for doing one thing kept in one place. This makes it easier for maintenence and legiability.

How would this routine be made into a subroutine/function/library (insert own preferred terminalogy here), say called ActivateConnection(), which returned a series of integer outcomes/return values/. That way the script for launching each application that requires the internet would read something like...

Code: Select all


Const ConnectionNotRequired =2
Const ConnectionActivated = 1
Const ConnectionUnavailable = 0

Select Case ActivateConnection() 
   Case ConnectionActivated
      exec Seamonkey # or any other app needing the web
   Case ConnectionNotRequired
      exec Seamonkey # but not apps that have no function if offline (like Transmission)
   Case ConnectionUnavailable
      exit 
End Case

This way the code for manageing the connection only needs to be programmed once, you never know what new and innovative ways people would have of connecting to the web in the future, this would mean that only one piece of code would be needed to be changed and kept updated.

One "achillies heel" I notice about the intended 2.14 base is that the internet connection is very difficult to find. There is an icon on the dektop (connect) that launches the connection wizard, but this would be obscured by the open seamonkey window. The user would most probably then click on the start menu, go on "internet connection" and try to run one of the wizards in their for modem dialup or one of the other methids. The main (and recommended) method that people use to connect to the web if via an ethernet cable, secondly via usb and then thirdly via wireless. Perhaps pictures of these types of plugs (usb, ethernet and an arial) would be handy to make a very uninitiated user able to understand which type of connection they have.
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

Everitt
Posts: 331
Joined: Tue 19 Dec 2006, 21:59
Location: Leeds,UK or Birmingham, UK

Re: Logic

#12 Post by Everitt »

ecomoney wrote:You've seen my bash coding, so I hope you understand why I need a written "pseudocode" explaination of what seems to be the start of a very promising internet connection wizard :-)
This isn't the nicest code to follow, and I'm not very good when it comes to commenting.

The for loop between lines 4 and 37 goes through all the interfaces listed by ifconfig, ie every network interface that has a driver loaded.
Within the loop are a series of tests. The tests are:

Code: Select all

Connected (Wire plugged in) [Uses ifplugged]
        Wireless. [Using iwconfig] (If wired then the following tests are skipped, ie it jumps to 'has ip address'
                Powered on. [radio on]
                Configured [has ESSID set, ie it has been connected to a wireless network]
         Has ip address [using ifconfig]
Line 39 tests if anything has been added to the list UP (note: I left in a debugging fudge, it should be 1, not 91. Now fixed in previous post) If it has then it tries to ping google.If this works then the script returns 0 (all ok. If not it offers to run the wizard.
If nothing has been added to the list then the script once again offers to run the script.
In both cases, when the script is offered a 'No' will return 1 (fail), or, for a 'yes', it will return the value returned by the connection script.

The end result is that if the Internet is found then 0 is returned. If the script can't find the inet, and nothing is done, then it returns 1. If the wizard is run, and succeeds then, with some luck (I haven't found time to test) a 0 is returned. If setup fails / is canceled then, once again, with luck, something other than 0 is returned.
The practicle upshot of this is that the existing 'exec sea monkey' could simply be replaced by '<script name> && exec seamonkey'
To allow offline mode all is needed is to call the script before calling seamonkey. This will cause the checks, and the offer of the setup dialog, then run seamonkey anyway.

The problem with having one single entity to run anything is that we need some way to know whether to run it in offline mode or not. I personally think it would be easier to leave than up to the individual launcher.
A basic template would be something like this (pseudo code)

Code: Select all

#Setup lines here as usual

#Followed by this:
if <script from this thread>; then
        #Returned 0, suggesting a connection
        exec <application>
else
        if [ ask if they want to run in offline mode ]; then
                #They said yes
                exec <application>
        else
                #They said no
                exit
         fi
fi

Post Reply