summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xe3372-clear-traffic-stats.sh10
-rwxr-xr-xe3372-dataswitch-off.sh10
-rwxr-xr-xe3372-dataswitch-on.sh10
-rwxr-xr-xe3372-dhcp-setting.sh8
-rwxr-xr-xe3372-readsms-xmlstarlet.sh13
-rwxr-xr-xe3372-readsms.sh11
-rwxr-xr-xe3372-reboot.sh7
-rwxr-xr-xe3372-sendsms.sh11
-rwxr-xr-xe3372-stats.sh22
-rwxr-xr-xe3372.sh16
-rwxr-xr-xinclude.sh21
11 files changed, 54 insertions, 85 deletions
diff --git a/e3372-clear-traffic-stats.sh b/e3372-clear-traffic-stats.sh
index 56b27b4..96409a5 100755
--- a/e3372-clear-traffic-stats.sh
+++ b/e3372-clear-traffic-stats.sh
@@ -4,11 +4,5 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
get_token
-
-curl -s -X POST "http://$MODEM_IP/api/monitoring/clear-traffic" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" \
- -d "<request><ClearTraffic>1</ClearTraffic></request>" >modem_status.xml
-
-cat modem_status.xml
+post_xml "monitoring/clear-traffic" \
+ "<request><ClearTraffic>1</ClearTraffic></request>"
diff --git a/e3372-dataswitch-off.sh b/e3372-dataswitch-off.sh
index 83ae7e0..446708a 100755
--- a/e3372-dataswitch-off.sh
+++ b/e3372-dataswitch-off.sh
@@ -4,11 +4,5 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
get_token
-
-curl -s -X POST "http://$MODEM_IP/api/dialup/mobile-dataswitch" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" \
- -d "<request><dataswitch>0</dataswitch></request>" >modem_status.xml
-
-cat modem_status.xml
+post_xml "dialup/mobile-dataswitch" \
+ "<request><dataswitch>0</dataswitch></request>" \ No newline at end of file
diff --git a/e3372-dataswitch-on.sh b/e3372-dataswitch-on.sh
index f270561..9662a7d 100755
--- a/e3372-dataswitch-on.sh
+++ b/e3372-dataswitch-on.sh
@@ -4,11 +4,5 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
get_token
-
-curl -s -X POST "http://$MODEM_IP/api/dialup/mobile-dataswitch" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" \
- -d "<request><dataswitch>1</dataswitch></request>" >modem_status.xml
-
-cat modem_status.xml
+post_xml "dialup/mobile-dataswitch" \
+ "<request><dataswitch>1</dataswitch></request>" \ No newline at end of file
diff --git a/e3372-dhcp-setting.sh b/e3372-dhcp-setting.sh
index f76e6ae..c3af87b 100755
--- a/e3372-dhcp-setting.sh
+++ b/e3372-dhcp-setting.sh
@@ -4,10 +4,4 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
get_token
-
-curl -s -X GET "http://$MODEM_IP/api/dhcp/settings" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" >modem_status.xml
-
-cat modem_status.xml
+get_xml "dhcp/settings"
diff --git a/e3372-readsms-xmlstarlet.sh b/e3372-readsms-xmlstarlet.sh
index 17399a8..b8fc086 100755
--- a/e3372-readsms-xmlstarlet.sh
+++ b/e3372-readsms-xmlstarlet.sh
@@ -5,16 +5,11 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
get_token
-curl -s -X POST "http://$MODEM_IP/api/sms/sms-list" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" \
- -d "<request><PageIndex>1</PageIndex><ReadCount>10</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>" >modem_status.xml
+post_xml "sms/sms-list" \
+ "<request><PageIndex>1</PageIndex><ReadCount>10</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>" > $STATUS_FILE
-#cat modem_status.xml
-
-readarray -t array_phone <<<"$(xmlstarlet sel -t -m "//Phone" -v . -n modem_status.xml)"
-readarray -t array_content <<<"$(xmlstarlet sel -t -m "//Content" -v . -n modem_status.xml)"
+readarray -t array_phone <<<"$(xmlstarlet sel -t -m "//Phone" -v . -n $STATUS_FILE)"
+readarray -t array_content <<<"$(xmlstarlet sel -t -m "//Content" -v . -n $STATUS_FILE)"
for ((i = 0; i < ${#array_content[@]}; i++)); do
echo -e "------\n${array_phone[$i]}"
diff --git a/e3372-readsms.sh b/e3372-readsms.sh
index c265dfa..cf54c5f 100755
--- a/e3372-readsms.sh
+++ b/e3372-readsms.sh
@@ -4,15 +4,10 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
get_token
+post_xml "sms/sms-list" "<request><PageIndex>1</PageIndex><ReadCount>10</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>"
-curl -s -X POST "http://$MODEM_IP/api/sms/sms-list" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" \
- -d "<request><PageIndex>1</PageIndex><ReadCount>10</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>" >modem_status.xml
+#cat $STATUS_FILE
-#cat modem_status.xml
-
-message=$(grep -r -E 'Phone|Content' modem_status.xml | sed -e 's/<[^>]*>//g' | sed -e 's/^[ \t]*/------\n/g')
+message=$(grep -r -E 'Phone|Content' $STATUS_FILE | sed -e 's/<[^>]*>//g' | sed -e 's/^[ \t]*/------\n/g')
echo "$message\n------"
diff --git a/e3372-reboot.sh b/e3372-reboot.sh
index 8f09b95..f4e8526 100755
--- a/e3372-reboot.sh
+++ b/e3372-reboot.sh
@@ -5,8 +5,5 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
get_token
-curl -s -X POST "http://$MODEM_IP/api/device/control" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" \
- -d "<?xml version='1.0' encoding='UTF-8'?><request><Control>1</Control></request>"
+post_xml "device/control" \
+ "<?xml version='1.0' encoding='UTF-8'?><request><Control>1</Control></request>" \ No newline at end of file
diff --git a/e3372-sendsms.sh b/e3372-sendsms.sh
index 9740775..6b7e3fa 100755
--- a/e3372-sendsms.sh
+++ b/e3372-sendsms.sh
@@ -3,12 +3,9 @@
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
-get_token
+SMS_DATA="<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>363</Phone></Phones><Sca></Sca><Content>USAGE</Content><Length>5</Length><Reserved>1</Reserved><Date>-1</Date></request>"
-curl -s -X POST "http://$MODEM_IP/api/sms/send-sms" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" \
- -d "<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>363</Phone></Phones><Sca></Sca><Content>USAGE</Content><Length>5</Length><Reserved>1</Reserved><Date>-1</Date></request>" >modem_status.xml
+get_token
+post_xml "sms/send-sms" "$SMS_DATA" > $STATUS_FILE
-cat modem_status.xml \ No newline at end of file
+cat $STATUS_FILE \ No newline at end of file
diff --git a/e3372-stats.sh b/e3372-stats.sh
index 1df3f5e..413fe9c 100755
--- a/e3372-stats.sh
+++ b/e3372-stats.sh
@@ -4,18 +4,14 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
get_token
+get_xml "monitoring/traffic-statistics" > $STATUS_FILE
-curl -s -X GET "http://$MODEM_IP/api/monitoring/traffic-statistics" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" > modem_status.xml
-
-CurConnTime=$(cat modem_status.xml | grep CurrentConnectTime | sed -e 's/<[^>]*>//g')
-CurrUpload=$(cat modem_status.xml | grep "<CurrentUpload>" | sed -e 's/<[^>]*>//g')
-CurrDownload=$(cat modem_status.xml | grep "<CurrentDownload>" | sed -e 's/<[^>]*>//g')
-TotalUpload=$(cat modem_status.xml | grep "<TotalUpload>" | sed -e 's/<[^>]*>//g')
-TotalDownload=$(cat modem_status.xml | grep "<TotalDownload>" | sed -e 's/<[^>]*>//g')
-TotalConnectTime=$(cat modem_status.xml | grep "<TotalConnectTime>" | sed -e 's/<[^>]*>//g')
+CurConnTime=$(cat $STATUS_FILE | grep CurrentConnectTime | sed -e 's/<[^>]*>//g')
+CurrUpload=$(cat $STATUS_FILE | grep "<CurrentUpload>" | sed -e 's/<[^>]*>//g')
+CurrDownload=$(cat $STATUS_FILE | grep "<CurrentDownload>" | sed -e 's/<[^>]*>//g')
+TotalUpload=$(cat $STATUS_FILE | grep "<TotalUpload>" | sed -e 's/<[^>]*>//g')
+TotalDownload=$(cat $STATUS_FILE | grep "<TotalDownload>" | sed -e 's/<[^>]*>//g')
+TotalConnectTime=$(cat $STATUS_FILE | grep "<TotalConnectTime>" | sed -e 's/<[^>]*>//g')
#------------------------------
# Current Connect Time
@@ -29,7 +25,7 @@ printf 'Current Connect Time : %d days: %02d hours: %02d minutes: %02d sseconds\
tct_secs=$TotalConnectTime
printf 'Total Connect Time : %d days: %02d hours: %02d minutes: %02d sseconds\n' $((tct_secs / 86400)) $((tct_secs % 86400 / 3600)) $((tct_secs % 3600 / 60)) $((tct_secs % 60))
-#cat modem_status.xml
+#cat $STATUS_FILE
#------------------------------
# Current Upload
#------------------------------
@@ -44,7 +40,7 @@ else
fi
#------------------------------
-# Current Downloae
+# Current Download
#------------------------------
if [ $CurrDownload -lt 1024 ]; then
echo "Current Download : ${CurrDownload}B"
diff --git a/e3372.sh b/e3372.sh
index 2310c72..1e1ad16 100755
--- a/e3372.sh
+++ b/e3372.sh
@@ -4,19 +4,11 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/include.sh"
get_token
+get_xml "device/information" > $STATUS_FILE
+get_xml "device/signal" >> $SIGNAL_FILE
-curl -s -X GET "http://$MODEM_IP/api/device/information" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" >modem_status.xml
-
-curl -s -X GET "http://$MODEM_IP/api/device/signal" \
- -H "Cookie: $COOKIE" \
- -H "__RequestVerificationToken: $TOKEN" \
- -H "Content-Type: text/xml" >>modem_status.xml
-
-wmode=$(cat modem_status.xml | grep workmode | sed -e 's/<[^>]*>//g')
-rssi=$(cat modem_status.xml | grep rssi | sed -e 's/<[^>]*>//g')
+wmode=$(cat $STATUS_FILE | grep workmode | sed -e 's/<[^>]*>//g')
+rssi=$(cat $STATUS_FILE | grep rssi | sed -e 's/<[^>]*>//g')
echo "mode: $wmode"
echo "signal: $rssi"
diff --git a/include.sh b/include.sh
index e09000b..01c0cbf 100755
--- a/include.sh
+++ b/include.sh
@@ -2,10 +2,31 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
[ -z "$MODEM_IP" ] && MODEM_IP="192.168.9.1"
+STATUS_FILE="modem_status.xml"
get_token() {
curl -s -X GET "http://$MODEM_IP/api/webserver/SesTokInfo" > ses_tok.xml
COOKIE=$(grep "SessionID=" ses_tok.xml | cut -b 10-147)
TOKEN=$(grep "TokInfo" ses_tok.xml | cut -b 10-41`)
rm ses_tok.xml
+}
+
+get_xml() {
+ local endpoint="$1"
+
+ curl -s -X GET "http://$MODEM_IP/api/$endpoint" \
+ -H "Cookie: $COOKIE" \
+ -H "__RequestVerificationToken: $TOKEN" \
+ -H "Content-Type: text/xml"
+}
+
+post_xml() {
+ local endpoint="$1"
+ local data="$2"
+
+ curl -s -X POST "http://$MODEM_IP/api/$endpoint" \
+ -H "Cookie: $COOKIE" \
+ -H "__RequestVerificationToken: $TOKEN" \
+ -H "Content-Type: text/xml" \
+ -d "$data"
} \ No newline at end of file