⬆️ ⬇️

Automatic work with SMS on the modem ZTE-MF823

This modem is not a modem as such. This is a router with an arm v7 processor based on Linux, it is displayed in the system as a network card, it runs without problems in Linux (usb0 network interface, subnet 192.168.0.0).



You can connect to the device via telnet (ip: 192.168.0.1, login: root, password: zte9x15), continue to deploy your iptables, hang scripts in a crontab and much more, even install your own software, but today this is not about that.



To perform modem operations, it is necessary to perform CGI requests to the web interface, wget or curl will do. In the modem from the megaphone there is no web muzzle, but in the biline there is. A web-muzzle is a browser-based JavaScript application that sends these same CGI requests to the AJAX, but I couldn’t find any suitable documentation for working with sms on the Internet, so I decided to upload the web-muzzle and catch the requests.



To work with SMS, you need to send POST requests to the address 192.168.0.1/goform/goform_set_cmd_process .

')

Sending SMS:

goformId = SEND_SMS

notCallback = true

Number = subscriber number

sms_time = date in the format y; m; d; h; i; s

MessageBody = message text

ID = -1

encode_type = UNICODE



Delete SMS:

goformId = DELETE_SMS

msg_id = list id of messages, separated by semicolons

notCallback = true



Receiving SMS:

To receive all messages in json format, you need to contact: 192.168.0.1/goform/goform_get_cmd_process?cmd=sms_data_total&page=0&data_per_page=5000&mem_store=1&tags=10&order_by=orderbybyididdesdes



In response, we will get an array of all SMS in JSON format.



With the removal of sms, everything is simple, but with the receipt and sending of the following misfortune - each character is encoded with a UTF HEX code, we get the character code with the function ord (), we translate what we got into the hexadecimal number system and finish up to 4 characters with zeros, for inverse decoding messages we divide the text by 4 characters, translate into a 10-number number system, and get the character by its number by the function chr (). It would seem that everything is so simple, but only php doesn’t work very well with Unicode, so I had to invent some kind of bicycles and bydlokodit, as a result of 3-hour experiments, the PHP class turned out to work with sms on this modem.



<?php mb_internal_encoding("UTF-8"); class ZTE_WEB { public $ip="192.168.0.1",$tz="+5"; public function url($url,$post="") { $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_BINARYTRANSFER,false); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch,CURLOPT_TIMEOUT, 90); $header = array(); $header[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; $header[] = 'Accept-Charset: Windows-1251,utf-8;q=0.7,*;q=0.7'; $header[] = 'Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3'; $header[] = 'Pragma: '; curl_setopt($ch, CURLOPT_HTTPHEADER, $header); unset ($header); if(!empty($post)) {curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post);} $content = curl_exec($ch); curl_close($ch); return $content; } public function utf2hex($str) { $l=mb_strlen($str); $res=''; for ($i=0;$i<$l;$i++) { $s = mb_substr($str,$i,1); $s = mb_convert_encoding($s, 'UCS-2LE', 'UTF-8'); $s = dechex(ord(substr($s, 1, 1))*256+ord(substr($s, 0, 1))); if (mb_strlen($s)<4) $s = str_repeat("0",(4-mb_strlen($s))).$s; $res.=$s; } return $res; } public function hex2utf($str) { $l=mb_strlen($str)/4; $res=''; for ($i=0;$i<$l;$i++) $res.=html_entity_decode('&#'.hexdec(mb_substr($str,$i*4,4)).';',ENT_NOQUOTES,'UTF-8'); return $res; } //  public function send($number,$text) { $url = 'http://'.$this->ip.'/goform/goform_set_cmd_process'; $post='isTest=false&'; $post.= 'goformId=SEND_SMS&'; $post.= 'notCallback=true&'; $post.= 'Number='.urlencode($number).'&'; $date = gmdate('y;m;d;h;i;s;'.$this->tz,time()+($this->tz*3600)); $post.= 'sms_time='.urlencode($date).'&'; $post.= 'MessageBody='.($this->utf2hex($text)).'&'; $post.= 'ID=-1&'; $post.= 'encode_type=UNICODE'; return $this->url($url,$post); } //    public function get_sms() { $cont=$this->url('http://'.$this->ip.'/goform/goform_get_cmd_process?cmd=sms_data_total&page=0&data_per_page=5000&mem_store=1&tags=10&order_by=order+by+id+desc'); $cont = json_decode($cont,true); $cont = $cont['messages']; foreach ($cont as $id => $arr) $cont[$id]['content']=$this->hex2utf(($cont[$id]['content'])); return $cont; } //   public function clear_sms($cont=0) { if ($cont===0) $cont=$this->get_sms(); $list_id=''; $url = 'http://'.$this->ip.'/goform/goform_set_cmd_process'; foreach ($cont as $id => $arr) $list_id.=$cont[$id]['id'].';'; $post='isTest=false&goformId=DELETE_SMS&msg_id='.urlencode($list_id).'¬Callback=true'; return $this->url($url,$post); } } $zte = new ZTE_WEB; // $zte->send("+79220000000",""); // $zte->clear_sms($zte->get_sms()); // $zte->get_sms(); ?> 


It is assumed that php scripts will receive all messages, and then do a modem memory sweep. This modem is connected to the Raspberry Pi, various sms and bot handlers will hang in the crontab, which will respond to commands sent from trusted numbers and make certain decisions.

Source: https://habr.com/ru/post/277637/



All Articles