From 91b6b387e19ad2b2f686e8a27bfc0a027e9eb4d9 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 22 Mar 2021 23:25:34 +0300 Subject: eliminate a lot of copypasta by using functions --- include.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include.sh') 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 -- cgit v1.2.3