plewin / tp-link-modem-router

Goodies for TP-Link modem routers
GNU General Public License v3.0
87 stars 18 forks source link
archer lte mr600 mr6400 sms-gateway tp-link

Goodies for Archer LTE routers

Features

Implemented

Installation and requirements

You need nodejs and yarn. Install them first.

# clone this repository and execute to install required dependencies
yarn install

Usage

Limitations and warnings

Send SMS command

# example passing all arguments as command line args
./sms-send.js --url="http://192.168.1.1" --login="admin" --password="myrouterpassword" "0612345678" "my text message"

# returns 0 on success, 1 on error
# pipe output to /dev/null if you do not want debug output

# you can also hardcode the credentials in the file or in the default config file : config.json
./sms-send.js 0612345678 "my text message"

# it is possible to supply your own config file using the --config arg
./sms-send.js --config="/tmp/config.json" 0612345678 "my text message"

# sample config file (config.json) for sms-send.js
{
    "url": "http://192.168.1.1",
    "login": "admin",
    "password": "myrouterpassword"
}

REST API Bridge

# Start API bridge, using local config.json
./api-bridge.js

# Using custom config.json file
./api-bridge.js --config=/tmp/config.json

# Sample config.json file
{
    "url": "http://192.168.1.1",
    "login": "admin",
    "password": "myrouterpassword",
    "api_listen_host": "127.0.0.1",
    "api_listen_port": 3000,
    "api_users": { "apiuser": "pleasechangeme" }
}

# Explore API on http://127.0.0.1:3000

# Sample queries
# ==============
# List received SMS
curl --user apiuser:pleasechangeme -X GET "http://127.0.0.1:3000/api/v1/sms/inbox" -H  "accept: application/json"

# Sending SMS application/x-www-form-urlencoded style
curl --user apiuser:pleasechangeme -d to=0123456789 -d content=test1 -X POST "http://127.0.0.1:3000/api/v1/sms/outbox" -H  "accept: application/json"

# Sending SMS application/json style
curl --user apiuser:pleasechangeme -d '{"to":"0123456789", "content":"test2"}' -H 'Content-Type: application/json' -X POST "http://127.0.0.1:3000/api/v1/sms/outbox" -H  "accept: application/json"

Receive SMS with SMS cat

# Example piping new SMS to command to your own command process_incoming_sms
./sms-cat.js --config=/tmp/config.json | \
    jq -c 'select(.message|contains("Received SMS")) | .sms' | \
    jq -c --raw-output 'select(.from=="+33123456789") .content' | \
    while read smsContent; do ./process_incoming_sms "$smsContent"; done

# Sample config file for sms-cat.js
{
    "api_client_url": "http://localhost:3000",
    "api_client_login": "apiuser",
    "api_client_password": "pleasechangeme",
    "api_client_polling_delay": 5000
}

SMTP to SMS Gateway

# Start listening for emails
./smtp-gateway.js --config=/tmp/config.json

# Sample config file for smtp-gateway.js
{
    "sms_gateway_url": "http://localhost:3000",
    "sms_gateway_login": "apiuser",
    "sms_gateway_password": "pleasechangeme",
    "sms_gateway_domain": "smtp2sms.local",
    "sms_gateway_listen_host": "127.0.0.1",
    "sms_gateway_listen_port": 1025
}
# SMTP Example
curl -vv smtp://127.0.0.1:1025 --mail-rcpt 123456789@smtp2sms.local --upload-file <(echo && echo -n "Hello world from curl")
*   Trying 127.0.0.1:1025...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 127.0.0.1 (127.0.0.1) port 1025 (#0)
< 220 dom0 ESMTP SMTP gateway for SMS API
> EHLO 11
< 250-dom0 Nice to meet you, [127.0.0.1]
< 250-PIPELINING
< 250-8BITMIME
< 250-SMTPUTF8
< 250-AUTH LOGIN PLAIN
< 250 STARTTLS
> MAIL FROM:<>
< 250 Accepted
> RCPT TO:<123456789@smtp2sms.local>
< 250 Accepted
> DATA
< 354 End data with <CR><LF>.<CR><LF>
} [26 bytes data]
< 250 OK: message queued
100    26    0     0    0    26      0     49 --:--:-- --:--:-- --:--:--    49
* Connection #0 to host 127.0.0.1 left intact

Supported models

Common errors

HTTP 403 while sending SMS or using API bridge : You might want to double-check that the password supplied is correct and that you call the script from the same network/subnet as the router.

Development and debugging the router's protocol

To debug the interaction between your browser and the router, first log in on the router UI and then paste this code in the developer console of your browser. All traffic will be logged in plain text in the console.

$.Iencryptor.AESDecrypt_backup = $.Iencryptor.AESDecrypt;
$.Iencryptor.AESEncrypt_backup = $.Iencryptor.AESEncrypt;
$.Iencryptor.AESDecrypt = function(data) {
    let decrypted = $.Iencryptor.AESDecrypt_backup(data);
    console.log("RECV:\n" + decrypted);
    return decrypted;
}
$.Iencryptor.AESEncrypt = function(data) {
    console.log("SEND:\n" + data);
    return $.Iencryptor.AESEncrypt_backup(data);
}

Alternatives and projects of interest

I can offer no guarantees about the following projects