7 changed files with 131 additions and 122 deletions
-
28ajax/networking/save_net_dev_config.php
-
11config/client_config/info_huawei.sh
-
134config/client_config/info_huawei_hilink.sh
-
46config/client_config/onoff_huawei_hilink.sh
-
1config/config.php
-
31includes/get_clients.php
-
2templates/networking.php
@ -1,75 +1,93 @@ |
|||
#!/bin/bash |
|||
# Information about HUAWEI hilink (router) modem |
|||
# ---------------------------------------------- |
|||
# Information about HUAWEI hilink |
|||
# ------------------------------- |
|||
# get info about the device and signal |
|||
# parameter: $1 - see opts list below |
|||
# $2 - host ip address for API calls (optional) |
|||
# 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) |
|||
# returns the value of the parameter, or "none" if not found or empty |
|||
# |
|||
# All device informations are buffered for 5 secs to speed up subsequent calls |
|||
# |
|||
# zbchristian 2020 |
|||
# zbchristian 2021 |
|||
|
|||
if [ -z "$1" ]; then echo "none"; exit; fi |
|||
|
|||
host="192.168.8.1" |
|||
|
|||
status="no option given" |
|||
if [ ! -z "$2" ]; then host="$2"; fi |
|||
function _setAPIParams() { |
|||
if [ ! -z "$hostip" ]; then host="$hostip"; fi |
|||
if [ ! -z "$username" ]; then user="$username"; fi |
|||
if [ ! -z "$password" ]; then pw="$password"; fi |
|||
if [ ! -z "$simpin" ]; then pin="$simpin"; fi |
|||
} |
|||
|
|||
if [ -z "$1" ]; then echo "none"; exit; fi |
|||
opt="${1,,}" |
|||
shift |
|||
while [ -n "$1" ]; do |
|||
case "$1" in |
|||
-u|--user) username="$2"; shift ;; |
|||
-P|--password) password="$2"; shift ;; |
|||
-p|--pin) simpin="$2"; shift ;; |
|||
-h|--host) hostip="$2"; shift ;; |
|||
esac |
|||
shift |
|||
done |
|||
|
|||
status="no valid option given" |
|||
result="none" |
|||
if [ "$opt" = "connected" ]; then |
|||
source /usr/local/sbin/huawei_hilink_api.sh |
|||
if ! _initHilinkAPI; then echo "none"; exit; fi |
|||
result=$(_getMobileDataStatus) |
|||
_closeHilinkAPI |
|||
source /usr/local/sbin/huawei_hilink_api.sh |
|||
if ! _initHilinkAPI; then echo "none"; exit; fi |
|||
_setAPIParams |
|||
result=$(_getMobileDataStatus) |
|||
_closeHilinkAPI |
|||
else |
|||
info_file="/tmp/huawei_infos_$host.dat" |
|||
if [ -f "$info_file" ]; then |
|||
age=$(( $(date +%s) - $(stat $info_file -c %Y) )) |
|||
if [[ $age -gt 5 ]]; then rm -f $info_file; fi |
|||
fi |
|||
info_file="/tmp/huawei_infos_$host.dat" |
|||
if [ -f "$info_file" ]; then |
|||
age=$(( $(date +%s) - $(stat $info_file -c %Y) )) |
|||
if [[ $age -gt 5 ]]; then rm -f $info_file; fi |
|||
fi |
|||
|
|||
if [ -f "$info_file" ]; then |
|||
infos=$(cat $info_file) |
|||
else |
|||
source /usr/local/sbin/huawei_hilink_api.sh |
|||
if ! _initHilinkAPI; then echo "none"; exit; fi |
|||
infos=$(_getAllInformations) |
|||
_closeHilinkAPI |
|||
if [ ! -z "$infos" ]; then echo "$infos" > /tmp/huawei_infos_$host.dat; fi |
|||
fi |
|||
if [ -f "$info_file" ]; then |
|||
infos=$(cat $info_file) |
|||
else |
|||
source /usr/local/sbin/huawei_hilink_api.sh |
|||
if ! _initHilinkAPI; then echo "none"; exit; fi |
|||
_setAPIParams |
|||
infos=$(_getAllInformations) |
|||
_closeHilinkAPI |
|||
if [ ! -z "$infos" ]; then echo "$infos" > /tmp/huawei_infos_$host.dat; fi |
|||
fi |
|||
|
|||
case "$opt" in |
|||
device|devicename) |
|||
key="devicename" |
|||
;; |
|||
ipaddress|wanipaddress) |
|||
key="wanipaddress" |
|||
;; |
|||
mode) |
|||
key="workmode" |
|||
;; |
|||
telnumber) |
|||
key="msisdn" |
|||
;; |
|||
imei|imsi|rssi|rsrq|rsrp|sinr|ecio) |
|||
key="$opt" |
|||
;; |
|||
signal) |
|||
key="rsrq" |
|||
;; |
|||
operator|fullname) |
|||
key="fullname" |
|||
;; |
|||
*) |
|||
key="" |
|||
;; |
|||
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 |
|||
case "$opt" in |
|||
device|devicename) |
|||
key="devicename" |
|||
;; |
|||
ipaddress|wanipaddress) |
|||
key="wanipaddress" |
|||
;; |
|||
mode) |
|||
key="workmode" |
|||
;; |
|||
telnumber) |
|||
key="msisdn" |
|||
;; |
|||
imei|imsi|rssi|rsrq|rsrp|sinr|ecio) |
|||
key="$opt" |
|||
;; |
|||
signal) |
|||
key="rsrq" |
|||
;; |
|||
operator|fullname) |
|||
key="fullname" |
|||
;; |
|||
*) |
|||
key="" |
|||
;; |
|||
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 |
|||
fi |
|||
echo -n "$result" |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue