plewin / tp-link-modem-router

Goodies for TP-Link modem routers
GNU General Public License v3.0
82 stars 17 forks source link

Cannot send SMS with carriage return '\n' inside. #4

Closed Pierrad closed 3 years ago

Pierrad commented 3 years ago

Good evening,

First of all thank you for this work. It was a great help.

I'm working on a project and I need to send an SMS with multiple '\n' inside. However, when I ask to send an SMS with one '\n' I get the following error: "TypeError: "SMS send operation was not accepted" is not a constructor" which occurs in the "verify_submission" method.

I tried to debug a bit and I have the impression that the error occurs from the "execute"function of routerClient.mjswith the result of "return httpClient.post(cgiUrl, encryptedPayload, {...".

What is sent causes an error during the request but I don't know how to fix this problem...

Do you have an idea ? Thanks in advance

plewin commented 3 years ago

Hi @Pierrad

Happy this code can be useful to someone.

Yes a workaround exists.

This router use a custom protocol (before encryption) that is similar to an ini file. Strings in the payload cannot contain \n or it will mess with the protocol. The protocol solution to this is to escape/replace line returns with \x12 (ascii device control 2) bytes.

You can verify this using this command

./sms-send.js --url="http://192.168.1.1" --login="admin" --password="myrouterpassword" "0612345678" $(printf "hello\x12world")

This project correctly translates this special character when the string is received from the router c.f. https://github.com/plewin/tp-link-modem-router/blob/master/src/routerProtocol.mjs#L127 But implementing the escape before sending to the router was forgotten.

For your project, either escape with \x12 bytes or better, fix it in the javascript. If you happen to do that, please open a pull request.

https://github.com/plewin/tp-link-modem-router/blob/master/src/routerProtocol.mjs#L139 obj[key] is suppose to be escaped \r\n | \r | \n -> \x12

Best regards,

Pierrad commented 3 years ago

Hi,

Thank you for your response! It was a great help to me.

I fixed the problem in Javascript, so I took the liberty of creating a pull request as you suggested. Also, I don't have the same modem model as you and your code still works, so I added my version in the README.

Thanks again.

plewin commented 3 years ago

Fixed by https://github.com/plewin/tp-link-modem-router/pull/5 thanks @Pierrad