mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Implement login for Hilink devices
This commit is contained in:
@@ -5,28 +5,31 @@
|
||||
# $2 : (optional) type - hilink or modem (default: hilink)
|
||||
# $3 : (optional) for hilink: ip address of the device (default: 192.168.8.1)
|
||||
# for modem: tty interface for communication (default: /dev/ttypUSB2)
|
||||
# $4 : more options can be added for Hilink devices ('-u user -P password -p pin'). These are passed to the corresponding script
|
||||
#
|
||||
# requires: bc
|
||||
# calls the scripts info_huawei_hilink.sh and info_huawei_modem.sh (same path as this script)
|
||||
#
|
||||
# zbchristian 2020
|
||||
#
|
||||
path=$(dirname "$0")
|
||||
opt="device"
|
||||
if [ ! -z "$1" ]; then opt=${1,,}; fi
|
||||
type="hilink"
|
||||
if [ ! -z "$2" ]; then type=${2,,}; fi
|
||||
|
||||
path=$(dirname "$0")
|
||||
parms=""
|
||||
if [ "$type" = "hilink" ]; then
|
||||
connect="192.168.8.1"
|
||||
if [ ! -z "$3" ]; then connect=$3; fi
|
||||
connect="-h 192.168.8.1"
|
||||
if [ ! -z "$3" ]; then connect="-h $3"; fi
|
||||
if [ ! -z "$4" ]; then parms="$4"; fi
|
||||
script="$path/info_huawei_hilink.sh"
|
||||
else
|
||||
connect="/dev/ttyUSB2"
|
||||
if [ ! -z "$3" ]; then connect=$3; fi
|
||||
script="$path/info_huawei_modem.sh"
|
||||
fi
|
||||
res=$($script $opt $connect)
|
||||
res=$($script $opt $connect $parms)
|
||||
|
||||
# some results require special treatment
|
||||
case $opt in
|
||||
|
@@ -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
|
||||
|
||||
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
|
||||
|
||||
host="192.168.8.1"
|
||||
|
||||
status="no option given"
|
||||
if [ ! -z "$2" ]; then host="$2"; 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
|
||||
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
|
||||
|
||||
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)
|
||||
source /usr/local/sbin/huawei_hilink_api.sh
|
||||
if ! _initHilinkAPI; then echo "none"; exit; fi
|
||||
_setAPIParams
|
||||
result=$(_getMobileDataStatus)
|
||||
_closeHilinkAPI
|
||||
if [ ! -z "$infos" ]; then echo "$infos" > /tmp/huawei_infos_$host.dat; fi
|
||||
fi
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
fi
|
||||
echo -n "$result"
|
||||
|
||||
|
@@ -1,42 +1,30 @@
|
||||
#!/bin/bash
|
||||
# connect/disconnect Huawei mobile data stick in Hilink mode (e.g. E3372h)
|
||||
# ========================================================================
|
||||
# - send xml formatted string via HTTP API to stick
|
||||
# - Requires session and verification token, which is obtained by an API call
|
||||
#
|
||||
# options: -l "user":"password" - login data - DOES NOT WORK YET
|
||||
# -h 192.168.8.1 - host ip address
|
||||
# -p 1234 - PIN of SIM card
|
||||
# -c 0/1 - connect - set datamode off/on
|
||||
# options: -u, --user - user name (default "admin")
|
||||
# -P, --password - password
|
||||
# -h, --host - host ip address (default 192.168.8.1)
|
||||
# -p, --pin - PIN of SIM card
|
||||
# -c, --connect - connect 0/1 to set datamode off/on
|
||||
#
|
||||
# required software: curl, base64, sha256sum
|
||||
#
|
||||
# zbchristian 2021
|
||||
|
||||
# include the hilink API
|
||||
# include the hilink API (defaults: user=admin, host=192.168.8.1)
|
||||
source /usr/local/sbin/huawei_hilink_api.sh
|
||||
|
||||
# handle options
|
||||
|
||||
host="192.168.8.1"
|
||||
pin=""
|
||||
user=""
|
||||
pw=""
|
||||
datamode=""
|
||||
|
||||
while getopts ":c:h:l:m:p:" opt; do
|
||||
case $opt in
|
||||
h) if [[ $OPTARG =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then host="$OPTARG"; fi
|
||||
;;
|
||||
p) if [[ $OPTARG =~ ^[0-9]{4,8} ]]; then pin="$OPTARG"; fi
|
||||
;;
|
||||
l) if [[ $OPTARG =~ ^[0-9a-zA-Z]*:.*$ ]]; then
|
||||
user=$(echo "$OPTARG" | cut -d':' -f1);
|
||||
pw=$(echo "$OPTARG" | cut -d':' -f2);
|
||||
fi
|
||||
;;
|
||||
c) if [[ $OPTARG == "1" ]]; then datamode=1; else datamode=0; fi
|
||||
;;
|
||||
esac
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
-u|--user) user="$2"; shift ;;
|
||||
-P|--password) pw="$2"; shift ;;
|
||||
-p|--pin) if [[ $2 =~ ^[0-9]{4,8} ]]; then pin="$2"; fi; shift ;;
|
||||
-h|--host) host="$2"; shift ;;
|
||||
-c|--connect) if [ "$2" = "1" ]; then datamode=1; else datamode=0; fi; shift ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
echo "Hilink: switch device at $host to mode $datamode" | systemd-cat
|
||||
@@ -44,7 +32,7 @@ echo "Hilink: switch device at $host to mode $datamode" | systemd-cat
|
||||
status="usage: -c 1/0 to disconnect/disconnect"
|
||||
if [ -z "$datamode" ] || [ ! _initHilinkAPI ]; then echo "Hilink: failed - return status: $status"; exit; fi
|
||||
|
||||
if ! _switchMobileData "$datamode"; then echo "Hilink: could not switch the data mode on/off . Error: ";_getErrorText; fi
|
||||
if ! _switchMobileData "$datamode"; then echo -n "Hilink: could not switch the data mode on/off . Error: ";_getErrorText; fi
|
||||
|
||||
if ! _closeHilinkAPI; then echo -n "Hilink: failed - return status: $status . Error: ";_getErrorText; fi
|
||||
|
||||
|
@@ -28,6 +28,7 @@ define('RASPI_LIGHTTPD_CONFIG', '/etc/lighttpd/lighttpd.conf');
|
||||
define('RASPI_ACCESS_CHECK_IP', '1.1.1.1');
|
||||
define('RASPI_ACCESS_CHECK_DNS', 'one.one.one.one');
|
||||
define('RASPI_CLIENT_CONFIG_PATH', '/etc/raspap/networking/client_udev_prototypes.json');
|
||||
define('RASPI_MOBILEDATA_CONFIG', '/etc/raspap/networking/mobiledata.ini');
|
||||
define('RASPI_CLIENT_SCRIPT_PATH', '/usr/local/sbin');
|
||||
|
||||
// Constant for the 5GHz wireless regulatory domain
|
||||
|
Reference in New Issue
Block a user