1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Remove from luci packages some files that can work without luci interface

This commit is contained in:
Ycarus (Yannick Chabanois) 2023-10-18 11:00:33 +02:00
parent 8369094924
commit 05a4db1523
35 changed files with 2616 additions and 8 deletions

View file

@ -0,0 +1,34 @@
#
# Copyright (C) 2018-2023 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=openmptcprouter-api
PKG_VERSION:=0.1
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=OMR
CATEGORY:=OpenMPTCProuter
DEPENDS:=+tracebox +bind-dig +curl
TITLE:=OpenMPTCProuter API
endef
define Package/$(PKG_NAME)/description
OpenMPTCProuter API package
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View file

@ -0,0 +1,10 @@
#!/bin/sh
MODEM_INTF=$1
[ -z "$MODEM_INTF" ] && return
SIGNAL_INFO=$(timeout 1 gcom info -d $MODEM_INTF)
[ -z "$SIGNAL_INFO" ] && return
RSSI=$(echo $SIGNAL_INFO | grep RSSI | awk -F: '{print $2}')
[ -z "$RSSI" ] && return
ASU=$(((RSSI + 113) / 2 ))
PERCENT=$((((ASU - 0) * 100) / ( 91 - 0 )))
echo $PERCENT

View file

@ -0,0 +1,50 @@
#!/bin/sh
INTF_IP=`echo $1 | grep -E '^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)'`
[ -z "$INTF_IP" ] && return
MODEM_IP=`echo $2 | grep -E '^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)'`
[ -z "$MODEM_IP" ] && return
INFO=$3
SESTOK=$(curl -s -m 1 -X GET "http://$MODEM_IP/api/webserver/SesTokInfo")
[ -z "$SESTOK" ] && return
COOKIE=$(echo $SESTOK | sed -ne '/SesInfo/{s/.*<SesInfo>\(.*\)<\/SesInfo>.*/\1/p;q;}')
COOKIE=$(echo $COOKIE | sed 's:SessionID=::')
TOKEN=$(echo $SESTOK | sed -ne '/TokInfo/{s/.*<TokInfo>\(.*\)<\/TokInfo>.*/\1/p;q;}')
tmpfile=$(mktemp)
curl -s -m 1 -X GET "http://$MODEM_IP/api/monitoring/status" -H "Cookie: SessionID=$COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml" > ${tmpfile}
SIGNAL_STRENGTH=$(cat ${tmpfile} | grep SignalStrength | sed -e 's/<[^>]*>//g' | sed 's/[^\x00-\x7F]//g')
if [ "$SIGNAL_STRENGTH" = "" ]; then
SIGNAL_ICON=$(cat ${tmpfile} | grep SignalIcon | sed -e 's/<[^>]*>//g' | sed 's/[^\x00-\x7F]//g')
MAX_SIGNAL=$(cat ${tmpfile} | grep maxsignal | sed -e 's/<[^>]*>//g' | sed 's/[^\x00-\x7F]//g')
if [ -n "$SIGNAL_ICON" ] && [ -n "$MAX_SIGNAL" ]; then
PERCENT=$((100 * ${SIGNAL_ICON} / ${MAX_SIGNAL}))
fi
else
echo "signal"
PERCENT=$SIGNAL_STRENGTH
fi
STATE=""
CONNECTSTATE=$(cat ${tmpfile} | grep ConnectionStatus | sed -e 's/<[^>]*>//g' | sed 's/[^\x00-\x7F]//g')
[ "$CONNECTSTATE" = "201" ] && STATE="connection failed, bandwidth exceeded"
[ "$CONNECTSTATE" = "900" ] && STATE="connecting"
[ "$CONNECTSTATE" = "901" ] && STATE="connected"
[ "$CONNECTSTATE" = "902" ] && STATE="disconnected"
[ "$CONNECTSTATE" = "903" ] && STATE="disconnecting"
[ "$CONNECTSTATE" = "904" ] && STATE="connection failed or disabled"
TYPE=""
NETWORKTYPE=$(cat ${tmpfile} | grep CurrentNetworkType\> | sed -e 's/<[^>]*>//g' | sed 's/[^\x00-\x7F]//g' | tr -d "\n")
[ "$NETWORKTYPE" = "2" ] || [ "$NETWORKTYPE" = "3" ] && TYPE="2g"
[ "$NETWORKTYPE" = "4" ] || [ "$NETWORKTYPE" = "5" ] || [ "$NETWORKTYPE" = "6" ] || [ "$NETWORKTYPE" = "7" ] || [ "$NETWORKTYPE" = "8" ] || [ "$NETWORKTYPE" = "9" ] || [ "$NETWORKTYPE" = "17" ] || [ "$NETWORKTYPE" = "18" ] || [ "$NETWORKTYPE" = "41" ] || [ "$NETWORKTYPE" = "44" ] || [ "$NETWORKTYPE" = "45" ] || [ "$NETWORKTYPE" = "46" ] || [ "$NETWORKTYPE" = "64" ] || [ "$NETWORKTYPE" = "65" ] && TYPE="3g"
[ "$NETWORKTYPE" = "19" ] || [ "$NETWORKTYPE" = "101" ] && TYPE="lte"
rm -f ${tmpfile}
OPERATOR=""
if [ "$CONNECTSTATE" = "901" ]; then
tmpfile=$(mktemp)
curl -s -m 1 -X GET "http://$MODEM_IP/api/net/current-plmn" -H "Cookie: SessionID=$COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml" > ${tmpfile}
OPERATOR=$(grep FullName ${tmpfile} | cut -f2 -d'>' | cut -f1 -d'<')
#$(cat ${tmpfile} | grep FullName | sed -e 's/<[^>]*>//g' | sed 's/[^\x00-\x7F]//g' | tr -d "\n")
rm -f ${tmpfile}
fi
NUMBER=""
[ -z "$INFO" ] && echo "$PERCENT"
[ "$INFO" = "all" ] && echo "$PERCENT;$OPERATOR;$NUMBER;$STATE;$TYPE"

View file

@ -0,0 +1,44 @@
#!/bin/sh
. /lib/functions.sh
intf=$1
timeout=$(uci -q get openmptcprouter.settings.status_getip_timeout)
[ -z "$timeout" ] && timeout="1"
get_ip_from_server() {
serverport=$(uci -q get openmptcprouter.$1.port)
get_ip() {
serverip=$1
getip="$(curl -s -k -4 -m ${timeout} --interface $intf https://$serverip:$serverport/clienthost)"
[ -n "$getip" ] && getip=$(echo $getip | jsonfilter -e '@.client_host')
if expr "$getip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
ip=$getip
break
fi
}
config_list_foreach $1 ip get_ip
[ -n "$ip" ] && break
}
get_ip_from_website() {
check_ipv4_website="$(uci -q get openmptcprouter.settings.check_ipv4_website)"
[ -z "$check_ipv4_website" ] && check_ipv4_website="http://ip.openmptcprouter.com"
checkip=$(echo $check_ipv4_website | sed -e 's/https:\/\///' -e 's/http:\/\///' | xargs dig +short A | tr -d "\n")
ipset add ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
getip="$(curl -s -4 -m ${timeout} --interface $intf $check_ipv4_website)"
ipset del ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
if expr "$getip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
ip=$getip
break
fi
}
[ -z "$intf" ] && return
if [ -n "$(ip -4 a show dev $intf)" ]; then
ip=""
config_load openmptcprouter
config_foreach get_ip_from_server server
[ -z "$ip" ] && get_ip_from_website
echo $ip
fi

View file

@ -0,0 +1,43 @@
#!/bin/sh
. /lib/functions.sh
intf=$1
timeout=$(uci -q get openmptcprouter.settings.status_getip_timeout)
[ -z "$timeout" ] && timeout="1"
get_ip_from_server() {
serverport=$(uci -q get openmptcprouter.$1.port)
get_ip() {
getip="$(curl -s -k -6 -m ${timeout} --interface $intf https://$serverip:$serverport/clienthost)"
[ -n "$getip" ] && getip=$(echo $getip | jsonfilter -e '@.client_host')
if [ -n "$(echo "$getip" | grep :)" ]; then
ip=$getip
break
fi
}
config_list_foreach $1 ip get_ip
[ -n "$ip" ] && break
}
get_ip_from_website() {
check_ipv6_website="$(uci -q get openmptcprouter.settings.check_ipv6_website)"
[ -z "$check_ipv6_website" ] && check_ipv6_website="http://ipv6.openmptcprouter.com"
checkip=$(echo $check_ipv6_website | sed -e 's/https:\/\///' -e 's/http:\/\///' | xargs dig +short AAAA | tr -d "\n")
ipset add ss_rules6_dst_bypass_all $checkip > /dev/null 2>&1
getip="$(curl -s -6 -m ${timeout} --interface $intf $check_ipv6_website)"
ipset del ss_rules6_dst_bypass_all $checkip > /dev/null 2>&1
if [ -n "$(echo "$getip" | grep :)" ]; then
ip=$getip
break
fi
}
[ -z "$intf" ] && return
if [ -n "$(ip -6 a show dev $intf)" ]; then
ip=""
config_load openmptcprouter
config_foreach get_ip_from_server server
[ -z "$ip" ] && get_ip_from_website
echo $ip
fi

View file

@ -0,0 +1,18 @@
#!/bin/sh
MODEM_INTF=$1
[ -z "$MODEM_INTF" ] && return
INFO=$2
timeout 1 mmcli -L | while read MODEM; do
MODEM_ID=$(echo $MODEM | awk -F' ' '{print $1}' | awk -F/ '{print $6}')
MODEM_INFO="$(timeout 1 mmcli -m $MODEM_ID --output-keyvalue)"
if [ -n "$MODEM_INFO" ] && [ "$(echo "$MODEM_INFO" | grep 'modem.generic.device ' | awk -F": " '{print $2}')" = "$MODEM_INTF" ]; then
PERCENT=$(echo "$MODEM_INFO" | grep -m 1 'modem.generic.signal-quality.value ' | awk -F": " '{print $2}')
OPERATOR=$(echo "$MODEM_INFO" | grep -m 1 'modem.3gpp.operator-name ' | awk -F": " '{print $2}')
NUMBER=$(echo "$MODEM_INFO" | grep -m 1 'modem.generic.own-numbders.value[1]' | awk -F": " '{print $2}')
STATE=$(echo "$MODEM_INFO" | grep -m 1 'modem.generic.state ' | awk -F": " '{print $2}')
TYPE=$(echo "$MODEM_INFO" | grep -m 1 'modem.generic.access-technologies.value\[1\]' | awk -F": " '{print $2}')
[ -z "$INFO" ] && echo $PERCENT
[ "$INFO" = "all" ] && echo "$PERCENT;$OPERATOR;$NUMBER;$STATE;$TYPE"
exit
fi
done

View file

@ -0,0 +1,75 @@
#!/bin/sh
. /lib/functions.sh
intf=$1
timeout="$(uci -q get openmptcprouter.settings.status_vps_timeout)"
[ -z "$timeout" ] && timeout="1"
[ -z "$intf" ] && return
get_mptcp_from_server() {
serverport=$(uci -q get openmptcprouter.$1.port)
get_mptcp() {
serverip=$1
if [ "$(echo $serverip | grep :)" ]; then
if [ -f /proc/sys/net/mptcp/enabled ]; then
support="$(mptcpize run curl -s -k -6 -m ${timeout} --interface $intf https://[$serverip]:$serverport/mptcpsupport)"
else
support="$(curl -s -k -6 -m ${timeout} --interface $intf https://[$serverip]:$serverport/mptcpsupport)"
fi
else
if [ -f /proc/sys/net/mptcp/enabled ]; then
support="$(mptcpize run curl -s -k -4 -m ${timeout} --interface $intf https://$serverip:$serverport/mptcpsupport)"
else
support="$(curl -s -k -4 -m ${timeout} --interface $intf https://$serverip:$serverport/mptcpsupport)"
fi
fi
[ -n "$support" ] && {
support=$(echo $support | jsonfilter -e '@.mptcp')
break
}
}
config_list_foreach $1 ip get_mptcp
[ -n "$support" ] && break
}
get_mptcp_from_website() {
multipathip=$(dig +short A multipath-tcp.org | tr -d "\n")
ipset add ss_rules_dst_bypass_all $multipathip > /dev/null 2>&1
support="$(curl -s -4 -m ${timeout} --interface $intf http://www.multipath-tcp.org)"
ipset del ss_rules_dst_bypass_all $multipathip > /dev/null 2>&1
[ -n "$support" ] && {
if [ "$support" = "Yay, you are MPTCP-capable! You can now rest in peace." ]; then
support="working"
else
support="not working"
fi
}
}
get_mptcp_from_website6() {
multipathip=$(dig +short AAAA multipath-tcp.org | tr -d "\n")
ipset add ss_rules6_dst_bypass_all $multipathip > /dev/null 2>&1
support="$(curl -s -6 -m ${timeout} --interface $intf http://www.multipath-tcp.org)"
ipset del ss_rules6_dst_bypass_all $multipathip > /dev/null 2>&1
[ -n "$support" ] && {
if [ "$support" = "Yay, you are MPTCP-capable! You can now rest in peace." ]; then
support="working"
else
support="not working"
fi
}
}
support=""
config_load openmptcprouter
config_foreach get_mptcp_from_server server
if [ ! -f /proc/sys/net/mptcp/enabled ] && [ -z "$support" ]; then
[ -n "$(ip -4 a show dev $intf)" ] && get_mptcp_from_website
[ -n "$(ip -6 a show dev $intf)" ] && get_mptcp_from_website6
fi
if [ "$support" = "working" ]; then
echo "MPTCP enabled"
elif [ "$support" = "not working" ]; then
echo "MPTCP disabled"
fi

View file

@ -0,0 +1,29 @@
#!/bin/sh
MODEM_INTF=$1
[ -z "$MODEM_INTF" ] && return
INFO=$2
SIGNAL_INFO=$(timeout 1 uqmi -d $MODEM_INTF --get-signal-info)
[ -z "$SIGNAL_INFO" ] && return
TYPE=$(echo $SIGNAL_INFO | jsonfilter -e '@.type' | tr -d '\n')
PERCENT=""
if [ "$TYPE" = "gsm" ]; then
RSSI=$(echo $SIGNAL_INFO | jsonfilter -e '@.rssi' | tr -d '\n')
[ -z "$RSSI" ] && return
ASU=$(((RSSI + 113) / 2 ))
PERCENT=$((((ASU - 0) * 100) / ( 91 - 0 )))
elif [ "$TYPE" = "umts" ]; then
RSCP=$(echo $SIGNAL_INFO | jsonfilter -e '@.rscp' | tr -d '\n')
[ -z "$RSCP" ] && return
ASU=$((RSCP + 116))
PERCENT=$((((ASU - 0) * 100) / ( 91 - 0 )))
elif [ "$TYPE" = "lte" ]; then
RSRP=$(echo $SIGNAL_INFO | jsonfilter -e '@.rsrp' | tr -d '\n')
[ -z "$RSRP" ] && return
ASU=$((RSRP + 140))
PERCENT=$((((ASU - 3) * 100) / ( 70 - 3 )))
fi
[ -z "$INFO" ] && echo $PERCENT && return
OPERATOR=$(timeout 1 uqmi -d $MODEM_INTF --get-serving-system | jsonfilter -e '@.plmn_description' | tr -d '\n')
NUMBER=$(timeout 1 uqmi -d $MODEM_INTF --get-msisdn | jsonfilter -e '@' | tr -d '\n')
STATE=$(timeout 1 uqmi -d $MODEM_INTF --get-data-status | jsonfilter -e '@' | tr -d '\n')
[ "$INFO" = "all" ] && echo "$PERCENT;$OPERATOR;$NUMBER;$TATE;$TYPE"

View file

@ -0,0 +1,10 @@
#!/bin/sh
VPS=$1
LANIP=$2
INTF=$3
if [ -n "$(traceroute -q 1 -i ${INTF} -w 1 -n -m 5 ${VPS} | grep ${LANIP})" ]; then
echo "detected"
else
echo "no loop"
fi

View file

@ -0,0 +1,16 @@
#!/bin/sh
INTERFACE=$2
SERVER=$1
if [ -n "$(resolveip -4 $SERVER)" ]; then
if [ -z "$INTERFACE" ]; then
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" $SERVER
else
tracebox -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" -i $INTERFACE $SERVER
fi
else
if [ -z "$INTERFACE" ]; then
tracebox -6 -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" $SERVER
else
tracebox -6 -m 20 -l "pkt = ip{dst=to} / tcp{dst=65101} / MPCAPABLE / MSS / WSCALE if string.find(tostring(tracebox(pkt)),'-TCPOptionMPTCPCapable') then print 'MPTCP disabled' elseif string.find(tostring(tracebox(pkt)),'MPTCP') then print 'MPTCP enabled' end" -i $INTERFACE $SERVER
fi
fi

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
{
"admin/system/openmptcprouter": {
"title": "OpenMPTCProuter",
"order": 1,
"action": {
"type": "template",
"path": "openmptcprouter/wizard"
},
"depends": {
"acl": [ "luci-app-openmptcprouter" ]
}
}
}

View file

@ -0,0 +1,14 @@
{
"luci-app-openmptcprouter": {
"description": "Grant UCI access for luci-app-openmptcprouter",
"read": {
"uci": [ "*" ],
"ubus": {
"openmptcprouter": [ "*" ]
}
},
"write": {
"uci": [ "*" ]
}
}
}