2021-03-07 18:36:48 +01:00
|
|
|
#!/bin/bash
|
2021-05-21 14:57:14 +02:00
|
|
|
# Information about HUAWEI hilink
|
|
|
|
# -------------------------------
|
2021-03-07 18:36:48 +01:00
|
|
|
# get info about the device and signal
|
2021-05-21 14:57:14 +02:00
|
|
|
# parameter: $1 - "connected", "device", "ipaddress", "mode", "signal" (see case statement below)
|
|
|
|
# -u,--user - username
|
|
|
|
# -P,--password - password
|
|
|
|
# -p,--pin - SIM pin
|
|
|
|
# -h,--host - host ip address for API calls (optional)
|
2021-03-07 18:36:48 +01:00
|
|
|
# returns the value of the parameter, or "none" if not found or empty
|
|
|
|
#
|
2021-05-19 21:04:31 +02:00
|
|
|
# All device informations are buffered for 5 secs to speed up subsequent calls
|
|
|
|
#
|
2021-05-21 14:57:14 +02:00
|
|
|
# zbchristian 2021
|
2021-03-07 18:36:48 +01:00
|
|
|
|
2021-05-21 14:57:14 +02:00
|
|
|
function _setAPIParams() {
|
2021-06-18 14:04:56 +02:00
|
|
|
if [ ! -z "$hostip" ]; then hilink_host="$hostip"; fi
|
|
|
|
if [ ! -z "$username" ]; then hilink_user="$username"; fi
|
|
|
|
if [ ! -z "$password" ]; then hilink_password="$password"; fi
|
|
|
|
if [ ! -z "$simpin" ]; then hilink_pin="$simpin"; fi
|
2021-05-21 14:57:14 +02:00
|
|
|
}
|
2021-03-07 18:36:48 +01:00
|
|
|
|
2021-05-21 14:57:14 +02:00
|
|
|
if [ -z "$1" ]; then echo "none"; exit; fi
|
2021-05-23 09:04:08 +02:00
|
|
|
property="${1,,}"
|
2021-05-21 14:57:14 +02:00
|
|
|
shift
|
2021-05-21 22:07:04 +02:00
|
|
|
hostip="192.168.8.1"
|
2021-05-21 14:57:14 +02:00
|
|
|
while [ -n "$1" ]; do
|
|
|
|
case "$1" in
|
2021-05-21 22:07:04 +02:00
|
|
|
-u|--user) username="$2"; shift ;;
|
|
|
|
-P|--password) password="$2"; shift ;;
|
|
|
|
-p|--pin) simpin="$2"; shift ;;
|
|
|
|
-h|--host) hostip="$2"; shift ;;
|
2021-05-21 14:57:14 +02:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
status="no valid option given"
|
2021-05-19 21:04:31 +02:00
|
|
|
result="none"
|
2021-05-21 22:07:04 +02:00
|
|
|
hostip="192.168.8.1"
|
2021-05-19 21:04:31 +02:00
|
|
|
if [ "$opt" = "connected" ]; then
|
2021-05-21 14:57:14 +02:00
|
|
|
source /usr/local/sbin/huawei_hilink_api.sh
|
|
|
|
_setAPIParams
|
2021-05-21 22:07:04 +02:00
|
|
|
if ! _initHilinkAPI; then echo "none"; exit; fi
|
2021-05-21 14:57:14 +02:00
|
|
|
result=$(_getMobileDataStatus)
|
|
|
|
_closeHilinkAPI
|
2021-05-19 21:04:31 +02:00
|
|
|
else
|
2021-06-18 14:04:56 +02:00
|
|
|
info_file="/tmp/huawei_infos_${hostip}_$(id -u).dat"
|
2021-05-21 14:57:14 +02:00
|
|
|
if [ -f "$info_file" ]; then
|
|
|
|
age=$(( $(date +%s) - $(stat $info_file -c %Y) ))
|
2021-05-23 09:04:08 +02:00
|
|
|
if [[ $age -gt 10 ]]; then rm -f $info_file; fi
|
2021-05-21 14:57:14 +02:00
|
|
|
fi
|
2021-03-07 18:36:48 +01:00
|
|
|
|
2021-05-21 14:57:14 +02:00
|
|
|
if [ -f "$info_file" ]; then
|
|
|
|
infos=$(cat $info_file)
|
|
|
|
else
|
|
|
|
source /usr/local/sbin/huawei_hilink_api.sh
|
2021-05-21 22:07:04 +02:00
|
|
|
_setAPIParams
|
2021-05-21 14:57:14 +02:00
|
|
|
if ! _initHilinkAPI; then echo "none"; exit; fi
|
|
|
|
infos=$(_getAllInformations)
|
|
|
|
_closeHilinkAPI
|
2021-05-23 09:04:08 +02:00
|
|
|
if [ ! -z "$infos" ]; then echo -n "$infos" > $info_file; fi
|
2021-05-21 14:57:14 +02:00
|
|
|
fi
|
2021-03-07 18:36:48 +01:00
|
|
|
|
2021-05-23 09:04:08 +02:00
|
|
|
case "$property" in
|
2021-05-21 14:57:14 +02:00
|
|
|
device|devicename)
|
|
|
|
key="devicename"
|
|
|
|
;;
|
|
|
|
ipaddress|wanipaddress)
|
|
|
|
key="wanipaddress"
|
|
|
|
;;
|
|
|
|
mode)
|
|
|
|
key="workmode"
|
|
|
|
;;
|
|
|
|
telnumber)
|
|
|
|
key="msisdn"
|
|
|
|
;;
|
|
|
|
imei|imsi|rssi|rsrq|rsrp|sinr|ecio)
|
2021-06-18 14:04:56 +02:00
|
|
|
key="$property"
|
2021-05-21 14:57:14 +02:00
|
|
|
;;
|
|
|
|
signal)
|
|
|
|
key="rsrq"
|
|
|
|
;;
|
|
|
|
operator|fullname)
|
|
|
|
key="fullname"
|
|
|
|
;;
|
|
|
|
*)
|
2021-05-23 09:04:08 +02:00
|
|
|
key="device"
|
2021-05-21 14:57:14 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ -z "$key" ]; then result="none"; fi
|
|
|
|
result=$(echo "$infos" | sed -rn 's/'$key'=\"([^ \s]*)\"/\1/ip')
|
|
|
|
if [ -z "$result" ]; then result="none"; fi
|
2021-05-19 21:04:31 +02:00
|
|
|
fi
|
|
|
|
echo -n "$result"
|
2021-03-07 18:36:48 +01:00
|
|
|
|