[SOLVED] Send sms failed in report

I have setup an openvox gateway and smsc. All messages are sent successfully but in sent messages report shows some messages are tagged as failed but sent successfully.

I’ve check the log it shows the recorded response was empty. I also dump the $resp in the log using _log(print_r($resp,…) it is really empty.

I tried to run the url manually with for loop to stress test the gateway:

for i in {1…100}; lynx --dump “http://192.168.201.206:80/sendsms?username=openvox&password=openvox&phonenumber=XXXXXXXXXXX&message=stress+test+$i+%40admin&report=JSON&smslog_id=485]”; done

    {
            "message":"stress test 1 @admin",
            "report":[{
                    "1":[{
                            "port":"gsm-1.2",
                            "phonenumber":"XXXXXXXXXXX",
                            "time":"2016-08-26 14:09:54",
                            "result":"success"
                    }]
            }]
    }

All the 100 url in the loop returns response and sent successfully.

Note: I’ve already done the fixed in fn.php: “$data = $resp[‘report’][0][1][0];” as reported in Openvox Send Reports

@anton please help… :sweat:

I found out the problem when you send sms with line breaks like:
Line1
Line2

it will be sent successfully but failed in the sent report status.

I’ve traced the problem in fn.php that json_decode() can’t handle strings with line breaks.

$resp = json_decode(file_get_contents($url), true);

@anton please help.

I also tried to dump the return values of the file_get_contents($url) function:

fn.php


$result = file_get_contents($url);
$resp = json_decode($result, true);
$data = $resp[‘report’][0][1][0];
_log(“result value:” . $result, 3, ‘openvox_hook_sendsms’);
_log(“resp value:” . print_r($resp, true), 3, ‘openvox_hook_sendsms’);

here is the output from the log file:

– 2016-08-27 21:51:24 PID57c19adcb1198 - L3 openvox_hook_sendsms # enter smsc:openvox smslog_id:267 uid:5 to:09228797593

    • 2016-08-27 21:51:32 PID57c19adcb1198 - L3 openvox_hook_sendsms # response result: port: to: time:
    • 2016-08-27 21:51:32 PID57c19adcb1198 - L3 openvox_hook_sendsms # result value: { “message”:“Line 1Line 2 @end”, “report”:[{ “1”:[{ “port”:“gsm-1.2”, “phonenumber”:“XXXXXXXXXXX”, “time”:“2016-08-27 21:51:32”, “result”:“success” }] }] }
    • 2016-08-27 21:51:32 PID57c19adcb1198 - L3 openvox_hook_sendsms # resp value:
    • 2016-08-27 21:51:32 PID57c19adcb1198 - L3 dlr # isdlrd:1 smslog_id:267 p_status:2 uid:5

If I reformat the response string from the log file it shows like this:

  {
           "message":"Line 1Line 2 @end",
      "report":[{
                 "1":[{
  "port":"gsm-1.2",
                            "phonenumber":"XXXXXXXXXXX",
                        "time":"2016-08-27 21:51:32",
                       "result":"success"
      }]
           }]
  }

but this is the return string if I manually run the url:

xxx@caleb:~$ lynx --dump “http://192.168.201.206:80/sendsms?username=openvox&password=openvox&phonenumber=XXXXXXXXXXX&message=Line+1 Line+2+%40end&report=JSON&smslog_id=267

    {
            "message":"Line 1Line 2 @end",
            "report":[{
                    "1":[{
                            "port":"gsm-1.2",
                            "phonenumber":"XXXXXXXXXXX",
                            "time":"2016-08-27 21:57:45",
                            "result":"success"
                    }]
            }]
    }

I finally fixed the problem. It is in the json string response from the openvox that returns invalid json when you send a message with line break, double quote ("), and backslash (\).

So what I’ve done was I removed all non printing characters first. Then I copied the message value to add with backslashes before characters that need to be escaped. Then I replaced the old message value with the escaped string before calling json_decode().

This is also related to Openvox returns empty report.

can you re-check and confirm that the issue was caused by those characters ?

I can try to fix it for next release if it was

thanks
anton

Yes anton, it is really those characters that cause the problem. I already verified and tested the fix for several days now and the problem was gone.

Here is my fix to the problem:

            $result = file_get_contents($url);

            $result = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $result);
            $mesg_start = stripos($result, '":"');
            $mesg_end = strrpos($result, '","report":');

            if ($mesg_start and $mesg_end) {
                    $mesg_start += 3;
                    $mesg = substr($result, $mesg_start, $mesg_end - $mesg_start);
                    if ($mesg != '') {
                            $escaped_mesg = addcslashes($mesg, '"\\/');
                            $result = str_replace($mesg, $escaped_mesg, $result);
                    }
            }

            $resp = json_decode($result, true);
            //$data = $resp['report'][0][0][0];
            $data = $resp['report'][0][1][0];
            $data['message'] = $resp['message'];

ok cool, if you’re not planning to pull request your changes then I will change it based on your fix

thanks,
anton

Yes anton, I will try to pull request my changes in github.