HotSpot auto login Script for all *nix and adaptation to OpenWRT GL-MT300N v1

On the Internet, I found a script that allows to automatically maintain permanent authorization in WISP mode when connecting to the hotspot (mikrotik standart: login / password). BUT I was not able to correctly run it on the GL-MT300N v1 even just for execution, not to mention the startup at boot.

LUCI Startup string: sh /usr/bin/login-hs.sh yj627p jxbvhp &
The original code and the corrected by me one and the same error:
BusyBox v1.24.1 (2016-09-08 17:43:22 HKT) built-in shell (ash)

O P E N W R T W I R E L E S S F R E E D O M

root@GL-MT300N:~# /usr/bin/login-hs.sh

-ash: /usr/bin/login-hs.sh: not found

root@GL-MT300N:~# sh /usr/bin/login-hs.sh

: not foundgin-hs.sh: line 2:

: not foundgin-hs.sh: line 10:

: not foundgin-hs.sh: line 22:

: not foundgin-hs.sh: line 29:

: not foundgin-hs.sh: line 30:

: not foundgin-hs.sh: line 31:

: not foundgin-hs.sh: line 32:

/usr/bin/login-hs.sh: line 232: syntax error: unexpected “done” (expecting "then ")

root@GL-MT300N:~#


As it seems to me in the environment of the use of something that is not configured, but I could not make out in connection with which I ask you to help.
I think that if we manage to adapt the script, it will be very much in demand not only by me.
If there are any questions about mikrotik (very popular in Europe and Russia), I will try to answer to the best of my competence.

While for authorization I use this link in the browser http://192.168.13.1/login?&username=yj627p&password=jxbvhp
It also works on the MT300N according to the syntax of wget and curl.

This is firmware specific and I don’t think it can just works. I don’t have a Mikrotik router so I don’t know how it works.

Is there any link for reference?

Do not think for advertising …

Almost all modern HotSpot in hotels and cafes in Europe function using Mikrotik their solutions are the most flexible, reliable enough, easy to operate (there are graphical shells both web and graphic winbox) and most importantly for commercial operation are cost.

Mini info

manufacturer page mikrotik.com

All hardware - router board - for it the unified operating system RouterOS

description customize HotSpot https://wiki.mikrotik.com/wiki/Manual:Customizing_Hotspot

a little later if you need for example I can post a web page mikrotik hotspot.


it seemed strange to me to react to empty lines of the script “>: not foundgin-hs.sh: line 2:” in the runtime it’s obviously something wrong.

Can you tell me where I can find “login-hs.sh”

Or do you have the content to post here?

The link in the first message is not underlined “corrected by me”, I tried to select it differently “bold” (very uncomfortable engine for the forum). When you click on a link to download a file, on the opened page, click the second button on the right.

The content of the file is quite large and uncomfortable for reading, that is why I did not place it in the post but gave link to it instead. If it is difficult or impossible to download it, I’ll post it here.

UP…

you can just zip and upload there.

OK, i upload it…

…UP…

How can i debug this error?

=(

I modified the file and now it runs on OpenWrt.

It was modified in windows causing it fails to execute in Linux.

It also has grammar errors and not sure how this was running. Use of [ ] was not correct.

Now it is your turn to debug

Greetings, I’m sorry that I did not answer for so long. I connect to this Hotspot rarely. Now again there was such a need.
You could not send me the corrected script file or explain in detail what to fix in it?

Oops, the attachment is lost after transferring the forum.

Can you reupload again?

On the old forum it was impossible to attach the file, so I inserted an external link,
-it works now. For your convenience, I will attach a file login-hs.zip (1.6 KB), Thanks!
I run it from Local Startup (/etc/rc.local.) adding here this.

========== HOTSPOT AUTO LOGIN SCRIPT =============

INPUT YOUR CREDENTIAL IN FORMAT “UserName&password=Pass”

/usr/bin/login-hs.sh &

I do not know why the text is so large =)

I’ve seen some simple scripts, but they are not convenient for changing the password and login.
hadrcode and not passed in variables.

Because you used “====” which is for making the text above like title.

I only fixed the grammer. if [ $a -eq $b ] there should be a space after $b. Otherwise it does not work in openwrt.

I have no idea if this will work as I don’t have the portal for testing.

#!/bin/sh


# BASIC CONFIGURATION ========================================================================
# HOTSPOT'S LOGIN WEBPAGE URL

HOTSPOT_URL="http://192.168.13.1"

# INPUT YOUR CREDENTIAL IN FORMAT "UserName&password=Pass"

#CREDENTIAL="yj627p&password=jxbvhp"

CREDENTIAL="$1&password=$2"

# ============================================================================================


# ADVANCED CONFIGURATION =====================================================================

# PATH FOR LOG FILE STORAGE

LOG_FILE="/tmp/login-hs_LOG.log"

# ENABLE LOG FILE 1/0 = on/off

LOG=1

# LEAVE EVERYTHING ELSE AS IS!!

MAIN_SLEEP=60

BOOT_SLEEP=30

LOGOUT_WHEN_LEFT_S=$(($MAIN_SLEEP+5))

AQUIRE_TIME_RETRY=10

# ============================================================================================


# STATIC VAR ALLOC ===========================================================================

LOGIN_URL="$HOTSPOT_URL/login?username=$CREDENTIAL"

LOGOUT="$HOTSPOT_URL/logout"

LOGIN="$HOTSPOT_URL/login"

STATUS_URL="$HOTSPOT_URL/status"

# ============================================================================================



#before first login sleep for 60s

if [ $LOG -eq 1 ]

then

	echo "$(date), BOOT OK. Waiting $BOOT_SLEEP seconds." >> $LOG_FILE

fi


sleep $BOOT_SLEEP


LOGIN_NR=1

RUN=1


# UNCOMENT FOR DEBUGING

#set -x


while [ $RUN -eq 1 ]

do

#LOGIN

	CONN_STATUS=0

	R=1
	

	if [ $LOG -eq 1 ]

	then

		echo -n "$(date), Connecting ... " >> $LOG_FILE

	fi

	while [ $CONN_STATUS -eq 0 ]

	do

		if [ $LOG -eq 1 ]

		then

			echo -n "$R " >> $LOG_FILE

		fi

		CONN_STATUS=$(wget -T 2 -q -O - "$@" "$LOGIN_URL" | grep -c "You are logged in")

		if [ $CONN_STATUS -eq 0 ]

		then

			sleep 1

		fi

		R=$((R+1))

	done

	if [ $LOG -eq 1 ]

	then

		echo "OK: $(date +%H:%M:%S)" >> $LOG_FILE

	fi

#AQUIRE TIME LEFT


	#WAIT FOR NTP SERVER

	TIME_NOW=$(date +%s)

	if [ $TIME_NOW -lt 300 ]

	then

		if [ $LOG -eq 1 ]

		then

 			echo -n "$(date), NTP Time ... " >> $LOG_FILE

 		fi

		NTP=1

 		while true                                 

		do

			if [ $LOG -eq 1 ]

			then

				echo -n "$NTP " >> $LOG_FILE

			fi

			

			SEC=$(date +%s)                                                         

			if [ $SEC -gt 300 ]

			then

				if [ $LOG -eq 1 ]

				then

					echo "OK: $(date +%H:%M:%S)" >> $LOG_FILE

				fi

				

				break

			fi

			NTP=$((NTP+1))

			sleep 1

		done

	fi

	WHOLE_START=$(date +%s)

	if [ $LOG -eq 1 ]

	then

		echo -n "$(date), Login time ... " >> $LOG_FILE

	fi
	

	I=1

	T=0

	TIME_OK=0

	while [ $TIME_OK -eq 0 ]

	do

		if [ $LOG -eq 1 ]

		then

			echo -n "$I " >> $LOG_FILE

		fi

		STATUS_PAGE=$(wget -T 2 -q -O - "$@" "$STATUS_URL")

		STA=$?

		if [ "$STATUS_PAGE" = "" ]

		then

			if [ $LOG -eq 1 ]

			then

				echo -n  "PAGE_ERR " >> $LOG_FILE

			fi

			sleep 1

			I=$((I+1))

			continue

		fi

		MINUTES=$(echo $STATUS_PAGE | grep -o '/ [0-9]*m' | tr -d 'm' | tr -d ' ' | tr -d '/')

		if [ "$MINUTES" = "" ]

		then

			if [ $LOG -eq 1 ]

			then

				echo -n "TIME_ERR " >> $LOG_FILE

			fi

			sleep 1

			I=$((I+1))

			continue

		fi

		T=$MINUTES

		if [ $T -gt 0 ]

		then

			TIME_OK=1

			if [ $LOG -eq 1 ]

			then

				echo "OK: $MINUTES minutes left." >> $LOG_FILE

			fi

			I=$((I+1))

			break

		fi

		if [ $I -gt $AQUIRE_TIME_RETRY ]

		then

			if [ $LOG -eq 1]

			then

				echo "FAIL. Restarting script ..." >> $LOG_FILE

			fi

			TIME_OK=1

			sleep 1

			continue 1

		fi

		I=$((I+1))

	done

	if [ $LOG -eq 1]

	then

        	echo "1...5....10...15...20...25...30...35...40...45...50...55...60" >> $LOG_FILE

	fi

#WAIT PERIOD

	#CALC TIME	

	S=$(($T*60))

	NOW=$(date +%s)

	ELPASSED=$(($NOW-$WHOLE_START))

	LEFT=$(($S-$ELPASSED))

	while [ $LEFT -gt $LOGOUT_WHEN_LEFT_S ]

	do

		#  check for internet connection - ping google DNS

		P=$(ping -c 1 -w 2 8.8.4.4 &> /dev/null)

		PING_OK=$?

		# SET PING ms TO 0 ON FAIL

		if [ $PING_OK -eq 1 ]

		then

			PING=0

			if [ $LOG -eq 1 ]

			then

				echo -n "-" >> $LOG_FILE

			fi

		else

			PING=1

			if [ $LOG -eq 1 ]

			then

				echo -n "+" >> $LOG_FILE

			fi

		fi

		sleep $MAIN_SLEEP

		#CALC TIME

		NOW=$(date +%s)

		ELPASSED=$(($NOW-$WHOLE_START))

		LEFT=$(($S-$ELPASSED))

	done

	echo "|" >> $LOG_FILE

#LOGOUT

	if [ $LOG -eq 1 ]

	then

		echo "$(date), Connection finished ..." >> $LOG_FILE

	fi

	OUT=$(wget -T 2 -q -O - "$@"  $LOGOUT)

	LOGIN_NR=$(($LOGIN_NR+1))

done

1 Like