Reply
Thread Tools
Posts: 53 | Thanked: 20 times | Joined on Jan 2010
#1
I'd like to be able to have a script run automatically when I connect to a wifi network.

It's the main university one and it's one of those which wants me to give my username and password in a web page before I'm allowed proper access to the internet.

The script would be easy -- it'd check which wifi network we just connected to (by SSID, for instance) and then if it matched the uni network it'd just be a simple curl job to send my username and password.

(Come to think of it I haven't even checked if curl's available -- I can work around that if not.)

Does something like this exist? I'm not new to Linux, I'm happy editing system configs and scripts etc.

This is on my new N900.
 
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#2
dbus-scripts allows that. Install this package, and create a file called /etc/dbus-scripts.d/wlan containing

/usr/local/bin/myscript * * com.nokia.icd status_changed * WLAN_INFRA CONNECTED

And the script will run whenever you connect to a WLAN (infrastructure mode only not for ad-hoc connections).

You can replace the third star with connection id of your university connection, so the script will only run when connected to university network, not to any network.

There is a GUI for dbus-scripts, if you don't want to create the file by yourself, which is called dbus-scripts-settings.

Both packages are available in extras-devel and in my repository (see my signature).

curl is available in SDK repository, but there is also wget in extras.
__________________
My repository

"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".

No more Nokia devices for me.
 

The Following 5 Users Say Thank You to Matan For This Useful Post:
Posts: 118 | Thanked: 59 times | Joined on May 2007
#3
You'll find some discussion of this in this thread: http://talk.maemo.org/showthread.php?t=43028 and still more if you follow the link in the first post.

Please share any solution you come up with!
 
Posts: 67 | Thanked: 28 times | Joined on Oct 2009 @ Switzerland
#4
Originally Posted by tremby View Post
I'd like to be able to have a script run automatically when I connect to a wifi network.

It's the main university one and it's one of those which wants me to give my username and password in a web page before I'm allowed proper access to the internet.

The script would be easy -- it'd check which wifi network we just connected to (by SSID, for instance) and then if it matched the uni network it'd just be a simple curl job to send my username and password.

(Come to think of it I haven't even checked if curl's available -- I can work around that if not.)

Does something like this exist? I'm not new to Linux, I'm happy editing system configs and scripts etc.

This is on my new N900.
If you want to automatically visit web pages, fill out forms, etc. you may also want to have a look at python-mechanize (it's in extras-devel). That'd be ways easier than using curl IMO.

Edit: Aditionally to Matan's solution, you could maybe also use /etc/network/if-up.d. It seems like scripts in there are executed when connecting to a network. However, i haven't tried it myself.

Last edited by gidoca; 2010-03-04 at 12:27.
 
Posts: 376 | Thanked: 511 times | Joined on Aug 2009 @ Greece
#5
Originally Posted by tremby View Post
I'd like to be able to have a script run automatically when I connect to a wifi network.

[...]

The script would be easy -- it'd check which wifi network we just connected to (by SSID, for instance) and then if it matched the uni network it'd just be a simple curl job to send my username and password.
You can run such scripts by putting them in /etc/network/if-*.d. What you want is /etc/network/if-up.d. Most probably you'll have to determine the ssid yourself (e.g. with iwconfig) but that will be easy.

You can find documentation in interfaces(5) man page. Look at "IFACE OPTIONS".
 
Posts: 53 | Thanked: 20 times | Joined on Jan 2010
#6
I have it working.

I couldn't find iwconfig (though I didn't look very hard) and so found no way right away of getting the SSID.

So I took the dbus-scripts approach. I was confused at first that the script wasn't called and tried restarting dbus and dbus-scripts. Restarting dbus gave me an error -- it was calling sort with --reverse which doesn't exist on this device. I replaced the --reverse with -r (beware, --reverse appears twice and only one of them is to do with sort) and then dbus restarted properly. I don't know if this was a necessary change.

But then I lost all wifi. I double checked my scripts and they were fine. I rebooted the device and then everything was working.

I had the script append all arguments to a file at first so I could check what was what and get the network ID I needed. Then I commented that line out and wrote the rest of the script. (I left the line in since it may be helpful to others.)

The scripts I'm left with:

/etc/dbus-scripts/wlan
Code:
/home/user/isslogin.sh * * com.nokia.icd status_changed * WLAN_INFRA
/home/user/isslogin.sh
Code:
#!/bin/bash
USER='--my university username--'
PASS='--my university password--'
IP=$(ifconfig wlan0 | grep "inet addr" | cut -d : -f 2 | awk '{print $1}')

#echo $* >>/home/user/dbus

if [ $5 = "d49d3--my university network ID--3e410" -a $7 = "CONNECTED" ]; then
	wget --no-check-certificate --post-data '_FORM_SUBMIT=1&which_form=reg&destination=http%3A%2F%2Fgoogle.com%2F&source='$IP'&error=&bs_name='$USER'&bs_password='$PASS https://--network login URL--.pl -O /dev/null
fi
Obviously the form data and URL will have to be different for different networks.

I generated mine by connecting to the network and then, before logging in, doing wget http://google.com and then inspecting the HTML returned.
 

The Following 5 Users Say Thank You to tremby For This Useful Post:
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#7
If your script is only does something for one connection, then the test is better done in dbus-scripts then in your script. Use the following line:

/home/user/isslogin.sh * * com.nokia.icd status_changed d49d3--my university network ID--3e410 WLAN_INFRA CONNECTED

And the script will only be called for this connection, so you don't need the if statement in your script.

dbus-scripts needs to be restarted after changing configuration - the easiest way is to run (as root) killall dbus-scripts . It is then restarted automatically by upstart.
__________________
My repository

"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".

No more Nokia devices for me.
 

The Following User Says Thank You to Matan For This Useful Post:
Posts: 53 | Thanked: 20 times | Joined on Jan 2010
#8
Yeah, I realized I could put the logic in the dbus script -- I just thought I'd leave myself flexibility in case I wanted to do other things for other networks or events. Thanks for your help.
 
Posts: 13 | Thanked: 4 times | Joined on Dec 2009 @ France
#9
I was doing some thing very similar and someone suggest me to don't use "--no-check-certificate".

So you can try with : "--ca-directory=/etc/certs/common-ca/" instead.

In my case, I was not using dbus but an /etc/if-up.d/ script.

Regards,
 
Posts: 10 | Thanked: 1 time | Joined on Mar 2010
#10
What do I need to put in to the dbus-script to excute a script on gprs connect and disconnect?

EDIT: Figured it out, instead of:
Code:
/some/script.sh * * com.nokia.icd status_changed * WLAN_INFRA
it's
Code:
/some/script.sh * * com.nokia.icd status_changed * GPRS

Last edited by matthewbpt; 2011-05-03 at 17:31.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 00:23.