From 74c8fb403fee972fbba825053a220265300ca4bb Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Thu, 25 Mar 2021 12:07:32 +0100 Subject: [PATCH] travelmate: minimal change to fix cp detection * fix cp detection proposed by @ChristianKuehnel * add/adapt mikrotik login script provided by @Christian Kuehnel Signed-off-by: Dirk Brenken --- net/travelmate/Makefile | 2 +- net/travelmate/files/mikrotik.login | 36 +++++++++++++++++++++++++++++ net/travelmate/files/travelmate.sh | 10 ++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100755 net/travelmate/files/mikrotik.login diff --git a/net/travelmate/Makefile b/net/travelmate/Makefile index 5f883f50f5..176c9afea9 100644 --- a/net/travelmate/Makefile +++ b/net/travelmate/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=travelmate PKG_VERSION:=1.5.5 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Dirk Brenken diff --git a/net/travelmate/files/mikrotik.login b/net/travelmate/files/mikrotik.login new file mode 100755 index 0000000000..aa526369f4 --- /dev/null +++ b/net/travelmate/files/mikrotik.login @@ -0,0 +1,36 @@ +#!/bin/sh +# This script will login to Mikrotik captive portals +# Arguments: +# username - user name for login +# password - password for login + +username="${1}" +password="${2}" +login_success="You are logged in" +cmd="$(command -v curl)" + +if [ "$#" -ne 2 ] +then + exit 1 +fi + +if [ ! -x "${cmd}" ] +then + exit 2 +fi + +# Get login domain from redirection information +domain="$("${cmd}" -I -s -X GET connectivity-check.ubuntu.com | grep Location | grep -o 'http://[^/]*')" +if [ "${domain}" = "" ] +then + exit 3 +fi + +# Login via username/password +response="$("${cmd}" -s -X POST -d "username=${username}&password=${password}&dst=&popup=true" "${domain}"/login)" +if [ -n "$(printf "%s" "${response}" | grep "${login_success}")" ] +then + exit 0 +else + exit 4 +fi diff --git a/net/travelmate/files/travelmate.sh b/net/travelmate/files/travelmate.sh index faf47c8c61..ba997538b5 100755 --- a/net/travelmate/files/travelmate.sh +++ b/net/travelmate/files/travelmate.sh @@ -228,12 +228,18 @@ f_net() { local IFS raw result - raw="$(${trm_fetch} --timeout=$((trm_maxwait/6)) "${trm_captiveurl}" -O /dev/null 2>&1 | tail -n 1)" + raw="$(${trm_fetch} --timeout=$((trm_maxwait/6)) "${trm_captiveurl}" -O /dev/null 2>&1)" + if [ "$(printf "%s" "${raw}" | grep -c "^Redirected")" = "1" ] + then + raw="$(printf "%s" "${raw}" | grep "^Redirected")" + else + raw="$(printf "%s" "${raw}" | tail -n 1)" + fi raw="$(printf "%s" "${raw//[\?\$\%\&\+\|\'\"\:\*\=\/]/ }")" result="$(printf "%s" "${raw}" | awk '/^Failed to redirect|^Redirected/{printf "%s","net cp";exit}/^Download completed/{printf "%s","net ok";exit}/^Failed|Connection error/{printf "%s","net nok";exit}')" if [ "${result}" = "net cp" ] then - result="$(printf "%s" "${raw//*on /}" | awk 'match($0,/^([[:alnum:]_-]+\.)+[[:alpha:]]+/){printf "%s","net cp \047"substr(tolower($0),RSTART,RLENGTH)"\047"}')" + result="$(printf "%s" "${raw//*on /}" | awk 'match($0,/^([[:alnum:]_-]+\.)+[[:alnum:]]+/){printf "%s","net cp \047"substr(tolower($0),RSTART,RLENGTH)"\047"}')" fi printf "%s" "${result}" f_log "debug" "f_net ::: fetch: ${trm_fetch}, timeout: $((trm_maxwait/6)), url: ${trm_captiveurl}, result: ${result}"