title: Sending SMS messages via bash script using a Huawei E8372 hilink
body: <p>I am attempting to send an SMS message from a Huawei E8372, which unlike older versions of this product now requires a login (username/password) before it will allow API calls to be made. From <a href="https://github.com/arska/e3372/issues/1" rel="nofollow noreferrer">https://github.com/arska/e3372/issues/1</a> I have been able to update the code written by arasaahov as below which gets me past the login step (I can get a SESSION_ID cookie and token)</p>
  
  <pre><code>#!/bin/sh
  # Script updated from example here: https://github.com/arska/e3372/issues/1
  
  MODEM_IP="192.168.8.1"
  message="Hello world"
  phone="PHONE NUMBER HERE"
  
  echo "Get the Session token information from http://$MODEM_IP/api/webserver/SesTokInfo"
  curl -s -X GET "http://$MODEM_IP/api/webserver/SesTokInfo" &gt; ses_tok.xml
  
  
  # Echo the ses_tok.xml file
  #cat ses_tok.xml
  
  # Now pull out the important stuff
  echo ""
  echo ""
  echo "Now pull the important stuff out"
  COOKIE=`grep "SessionID=" ses_tok.xml | cut -b 10-147`
  TOKEN=`grep "TokInfo" ses_tok.xml | cut -b 10-41`
  LOGIN_REQ="&lt;request&gt;&lt;Username&gt;admin&lt;/Username&gt;&lt;Password&gt;YWRtaW4=&lt;/Password&gt;&lt;password_type&gt;3&lt;/password_type&gt;&lt;/request&gt;"
  
  echo "COOKIE: $COOKIE"
  echo "TOKEN: $TOKEN"
  echo "LOGIN REQ: $LOGIN_REQ"
  echo "\n"
  
  # Now lets actually login
  curl -v -X POST -d $LOGIN_REQ "http://$MODEM_IP/api/user/login" \
   -H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml" -H 'Connection: keep-alive' \
   --dump-header login_resp_hdr.txt # &gt; /dev/null
  
  # Pull the important parts out
  SESSION_ID=$(grep "SessionID=" login_resp_hdr.txt | cut -d ':' -f2 | cut -d ';' -f1)
  ADM_TOKEN=$(grep "__RequestVerificationTokenone" login_resp_hdr.txt | cut -d ':' -f2)
  
  echo "\n"
  echo "admin SESSION_ID is: $SESSION_ID"
  echo "admin TOKEN is: $ADM_TOKEN"
  
  message_data="&lt;request&gt;&lt;Index&gt;-1&lt;/Index&gt;&lt;Phones&gt;&lt;Phone&gt;$phone&lt;/Phone&gt;&lt;/Phones&gt;&lt;Sca&gt;&lt;/Sca&gt;&lt;Content&gt;hello&lt;/Content&gt;&lt;Length&gt;5&lt;/Length&gt;&lt;Reserved&gt;1&lt;/Reserved&gt;&lt;Date&gt;1&lt;/Date&gt;&lt;/request&gt;"
  
  # Send an SMS
  #curl -X POST -d $message_data "http://$MODEM_IP/api/sms/send-sms" -H "Cookie: $SESSION_ID" -H "__RequestVerificationToken: $ADM_TOKEN" -H "Content-Type: text/xml" #--dump-header send_result.txt
  
  curl -v http://192.168.8.1/api/sms/send-sms \
   -H "Cookie: $SESSION_ID" \
   -H "__RequestVerificationToken: $ADM_TOKEN" \
   -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" \
   -H "Accept: */*" \
   -H "Referer: http://192.168.8.1/html/smsinbox.html" \
   -H "Content-Type: text/xml" \
   -H "Connection: keep-alive" \
   -H "Origin: http://192.168.8.1" \
   --data $message_data \
   --dump-header send_result.txt
  </code></pre>
  
  <p>However, I get a error back "100005" which I think means my send-sms command is incorrect. Full output of the script is below:</p>
  
  <pre><code>Get the Session token information from http://192.168.8.1/api/webserver/SesTokInfo
  
  
  Now pull the important stuff out
  COOKIE: SessionID=bqveiiBGuCLn8kzilf/7JGUbly53F9EaGFpcJL5gNkg+HvkhC5NpE51pyC7wrTaZQGOJKfdYqnhGWEGU06BPyyknGvsPZvD2QbPzKPh7GvXIiBBL6N9BW7SnrFYh/X0J
  TOKEN: pFAF3FZcWziTDWlthllgIDRGbPSFERuH
  LOGIN REQ: &lt;request&gt;&lt;Username&gt;admin&lt;/Username&gt;&lt;Password&gt;YWRtaW4=&lt;/Password&gt;&lt;password_type&gt;3&lt;/password_type&gt;&lt;/request&gt;
  
  
  Note: Unnecessary use of -X or --request, POST is already inferred.
  *   Trying 192.168.8.1...
  * TCP_NODELAY set
  * Connected to 192.168.8.1 (192.168.8.1) port 80 (#0)
  &gt; POST /api/user/login HTTP/1.1
  &gt; Host: 192.168.8.1
  &gt; User-Agent: curl/7.52.1
  &gt; Accept: */*
  &gt; Cookie: SessionID=bqveiiBGuCLn8kzilf/7JGUbly53F9EaGFpcJL5gNkg+HvkhC5NpE51pyC7wrTaZQGOJKfdYqnhGWEGU06BPyyknGvsPZvD2QbPzKPh7GvXIiBBL6N9BW7SnrFYh/X0J
  &gt; __RequestVerificationToken: pFAF3FZcWziTDWlthllgIDRGbPSFERuH
  &gt; Content-Type: text/xml
  &gt; Connection: keep-alive
  &gt; Content-Length: 106
  &gt;
  * upload completely sent off: 106 out of 106 bytes
  &lt; HTTP/1.1 200 OK
  &lt; Date: Thu, 01 Jan 1970 00:00:00 GMT
  &lt; Server: WebServer
  &lt; Connection: close
  &lt; X-Download-Options: noopen
  &lt; X-Frame-Options: deny
  &lt; X-XSS-Protection: 1; mode=block
  &lt; Strict-Transport-Security: max-age=31536000; includeSubdomains
  &lt; Cache-Control: no-cache
  &lt; Content-Type: text/html
  &lt; Content-Length: 61
  &lt; __RequestVerificationTokenone:xDaZ9B6udQl7GRMyrfaI7WDKF6hM3Icr
  &lt; __RequestVerificationTokentwo:oTKseE/iBAYbF1FUJ8XJ9+/X0ulxh+jt
  &lt; __RequestVerificationToken:xDaZ9B6udQl7GRMyrfaI7WDKF6hM3Icr#oTKseE/iBAYbF1FUJ8XJ9+/X0ulxh+jt#4M8V6iAWXbfDDlKW0WSForGtB2ZhuUyC#0FWYnCHKcKRX36MD1tgOkiStsT6OF5+O#iLyskoatpK+Ch6pH4PpgZ8Pr8zErrg9P#0yBQ0bbowQL2iZ3QW3FN4q0Adls16LTR#5P6wjHVOMNgGQYkdvBqohZGyQRTr0968#xEdi5v1dsQerDVYXz1fH4HCHMYnEiwy2#BAMuBOJoiJOY33vUENbN+cnSc3yueLQ6#Or4N+mktvSse35qIh6YqLB3lbf2LccFf#il1DNPB/0iEjUMPBgN9icxp58dkHYdNB#ZkltJCROvVHhKf676y+bhBy1Sv27M2Np#tdZgoksZu2o1q3dvS/oYNRYoH+7kTcuv#oqML4IGNmrS06DR5n6jWjzTA4yYakO0S#5di87l60XdJF0xPs3QSKMt2LELP+pEJA#fhRNe9lpisoy+3hhJyM/FWhKVQ13Lu+k#AagfENLE7/Hqm/RReQi7fKhASsaX6qm8#BL3sFmPVQl4RUYwROo3pY31I1ee0sgCM#u+VyGVo2GBe1tX81gJK+hXoYi2jOo+iE#Y//frYpRi+BaeZ7ziflACD1KNgI7SsNI#KAyJoAu0c9reXYf3oBDyl11rU8pkj16h#Ohc04aUEkes0qw/UaGFwK3l5brC9kfEb#GJS9B0d9cFbi2ChCxD16KxpiCx2H3UZT#ECxR86GG9rxnYkVpENGR8Km0srn/Nc6W#cvBDKis3DNqw7a1mtJkvei/NhyPfg3vw#YBQeG0Btnf03ejEhMp/ciQ2T5Lj93bnL#uJ3K1UMLwjSQw+kq6L7slBZcwHFRDcBf#edK//KWWp6BmUsufzVeIG2TmgBqvZ6gL#12TMh7qa/AuBO+EkgXlvzSax/p4wRAAm#CiZltXfOF4jrSoiUm5MKffam0hBU55+s#FNoUhUP7xQtnyNO3tjX01pTjQbzqwkz9#HgPuo6xLxkBcQ3z7LwReWEohfnrlJNZI#
  &lt; Set-Cookie:SessionID=vfyx1z/vIhtiTPJxA3gnptVVeCVwYo18IIuolHeAIbHbsn8xphH++92zOgu4selkbQ+1CyuuC4nvzyrRj/DV/12Jma+nVsewcQyinv9eXGzsxtQcihQeqCp2RMEmm0xy;path=/;HttpOnly;
  &lt;
  * Curl_http_done: called premature == 0
  * Closing connection 0
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;response&gt;OK&lt;/response&gt;
  
  admin SESSION_ID is: SessionID=vfyx1z/vIhtiTPJxA3gnptVVeCVwYo18IIuolHeAIbHbsn8xphH++92zOgu4selkbQ+1CyuuC4nvzyrRj/DV/12Jma+nVsewcQyinv9eXGzsxtQcihQeqCp2RMEmm0xy
  admin TOKEN is: xDaZ9B6udQl7GRMyrfaI7WDKF6hM3Icr
  *   Trying 192.168.8.1...
  * TCP_NODELAY set
  * Connected to 192.168.8.1 (192.168.8.1) port 80 (#0)
  &gt; POST /api/sms/send-sms HTTP/1.1
  &gt; Host: 192.168.8.1
  &gt; User-Agent: curl/7.52.1
  &gt; Cookie: SessionID=vfyx1z/vIhtiTPJxA3gnptVVeCVwYo18IIuolHeAIbHbsn8xphH++92zOgu4selkbQ+1CyuuC4nvzyrRj/DV/12Jma+nVsewcQyinv9eXGzsxtQcihQeqCp2RMEmm0xy
  &gt; __RequestVerificationToken: xDaZ9B6udQl7GRMyrfaI7WDKF6hM3Icr
  &gt; Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  &gt; Accept: */*
  &gt; Referer: http://192.168.8.1/html/smsinbox.html
  &gt; Content-Type: text/xml
  &gt; Connection: keep-alive
  &gt; Origin: http://192.168.8.1
  &gt; Content-Length: 167
  &gt;
  * upload completely sent off: 167 out of 167 bytes
  &lt; HTTP/1.1 200 OK
  &lt; Date: Thu, 01 Jan 1970 00:00:00 GMT
  &lt; Server: WebServer
  &lt; Connection: close
  &lt; X-Download-Options: noopen
  &lt; X-Frame-Options: deny
  &lt; X-XSS-Protection: 1; mode=block
  &lt; Strict-Transport-Security: max-age=31536000; includeSubdomains
  &lt; Cache-Control: no-cache
  &lt; Content-Type: text/html
  &lt; Content-Length: 101
  &lt; __RequestVerificationToken:QKB4o80G00DALXLfhiwqjhJBhaSuE0mM
  &lt;
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;error&gt;
  &lt;code&gt;100005&lt;/code&gt;
  &lt;message&gt;&lt;/message&gt;
  &lt;/error&gt;
  * Curl_http_done: called premature == 0
  * Closing connection 0
  HTTP/1.1 200 OK
  Date: Thu, 01 Jan 1970 00:00:00 GMT
  Server: WebServer
  Connection: close
  X-Download-Options: noopen
  X-Frame-Options: deny
  X-XSS-Protection: 1; mode=block
  Strict-Transport-Security: max-age=31536000; includeSubdomains
  Cache-Control: no-cache
  Content-Type: text/html
  Content-Length: 101
  __RequestVerificationToken:QKB4o80G00DALXLfhiwqjhJBhaSuE0mM
  </code></pre>
  
  <p>Can anyone help with what I'm doing wrong? Thanks heaps!</p>