You are not logged in.
Hi everyone !
I've been trying to automate the login process to a captive portal.
Basically, to be able to use the network, one must first open a browser, enter a random url to be redirected to the captive portal's page, then click on a button to be redirected to a second page and finally enter credentials and send the form. I managed to automate these steps with a python/selenium script which execute successfully when I run :
$ python [i]/path/to/script.py[/i]
I then tried to go one step further and make this script run automatically when I'm connected to the targeted network. After reading the wiki about NetworkManager's dispatcher, which seemed suitable for my need, I wrote a shell script, put it in
/etc/NetworkManager/dispatcher.d/
directory, named it "10-hotspot.sh" and finally changed its owner to root. Here's the content of the said script :
#!/bin/bash
echo $(date) >> /home/[i]my_user[/i]/test-nm-dispatcher
echo $CONNECTION_UUID >> /home/[i]my_user[/i]/test-nm-dispatcher
uuid=[i]uuid[/i]
if [[ "$CONNECTION_UUID" = "$uuid" ]] ; then
echo hello >> /home/[i]my_user[/i]/test-nm-dispatcher
which python >> /home/[i]my_user[/i]/test-nm-dispatcher
python [i]/path/to/script.py[/i]
Notice the "echo" lines at the beginning, used for debug purpose. The CONNECTION_UUID variable is available to all dispatcher's scripts and I found the wanted uuid by using the following command :
$ nmcli c | grep -i [i]hotspot_name[/i]
Now, when I look over my pseudo log file, I can see the date and wanted connection uuid (among several other ones, for some reason), but no record of the lines under the if statement. Do some of you guys have any idea as to why ?
Thanks !
Last edited by olhybrius (2019-12-23 13:54:03)
Offline
IIRC NM supplies variables 'per interface' and 'per status', both of which are missing from your script. That might be the reason why your log doesn't contain anything from inside the if-statement. Here's an example for comparison that you can try:
#!/bin/bash
#
# NM dispatcher script
### variables
_log="/path/to/test-nm-dispatcher.log"
_script="/path/to/script.py"
# NM-supplied variables
_interface="$1"
_status="$2"
# uuid found via `nmcli c | grep -i hotspot_name`
uuid="<uuid>"
### logic
# debug info
{
echo "$(date)"
which python
echo "$CONNECTION_UUID"
} >> "$_log"
# triage (regardless of interface)
case "$_status" in
up)
if [[ "$CONNECTION_UUID" = "$uuid" ]] ; then
echo "hello" >> "$_log"
python "$_script"
fi
;;
down)
if [[ "$CONNECTION_UUID" = "$uuid" ]] ; then
echo "bye" >> "$_log"
fi
;;
esac
exit 0
Offline
IIRC NM supplies variables 'per interface' and 'per status', both of which are missing from your script. That might be the reason why your log doesn't contain anything from inside the if-statement. Here's an example for comparison that you can try:
#!/bin/bash # # NM dispatcher script ### variables _log="/path/to/test-nm-dispatcher.log" _script="/path/to/script.py" # NM-supplied variables _interface="$1" _status="$2" # uuid found via `nmcli c | grep -i hotspot_name` uuid="<uuid>" ### logic # debug info { echo "$(date)" which python echo "$CONNECTION_UUID" } >> "$_log" # triage (regardless of interface) case "$_status" in up) if [[ "$CONNECTION_UUID" = "$uuid" ]] ; then echo "hello" >> "$_log" python "$_script" fi ;; down) if [[ "$CONNECTION_UUID" = "$uuid" ]] ; then echo "bye" >> "$_log" fi ;; esac exit 0
Thank you for your answer, I will definitely try that next time I need to/can log in to this network. Only drawback is it won't be until January 20th, but I'll keep you updated !
Offline