Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Runs the off-device test suite on Linux without Android.

name: 'Tests'

on:
push:
branches:
- main
- develop
paths:
- 'app/**'
- '.github/workflows/tests.yml'
pull_request:
paths:
- 'app/**'
- '.github/workflows/tests.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
linux_tests:
name: 'Unit tests (Linux)'
runs-on: 'ubuntu-24.04'

steps:

- name: GIT Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v7
with:
python-version: '3.13'
cache: 'pip'

- name: Install Dependencies
working-directory: ./app
run: |
pip install fastapi uvicorn psutil pyserial -r requirements-dev.txt

- name: Run unit tests
working-directory: ./app
run: |
python -m unittest discover -s tests -p "test_*.py" -v
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Changes

### 1.2.0
- Add a bearer-authenticated remote Settings and control API: `GET /api/health`, `GET /api/status`, `GET/PUT /api/settings`, `POST /api/webhook/test`, and `POST /api/server/restart`, with Revision-based optimistic concurrency and human-readable validation errors.
- Add named API keys with `sms:write` and `settings:write` Scopes, immediate revocation, and phone-key rotation that leaves proxy keys intact.
- Make Webhook retry timeout, attempts, backoff, and Outbox capacity live Settings, so a longer proxy outage does not lose Inbound SMS; reject credentialed Webhook targets.
- Keep the on-device UI consistent with remote changes through fresh read-merge-write saves; `GET /api/status` reports forwarding health and warnings.

### 1.1.0
- Forward received SMS to a configurable webhook (Android), with optional HMAC-SHA256 signing, ordered delivery, retries and a persisted outbox. See the [README](./README.md#-receiving-sms-android).
- Show the last webhook delivery result and a test button in Settings; log inbound SMS and delivery outcomes.
Expand Down
20 changes: 20 additions & 0 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ _Avoid_: retry, send, try
**Outbox**:
The persisted queue of Webhooks that are waiting to be delivered.
_Avoid_: queue, buffer, backlog

**Settings**:
The operator-chosen configuration that OpenSMS keeps across restarts: the API port, whether the server starts at launch, and the Webhook configuration.
_Avoid_: config, preferences, options

**Revision**:
The identifier of one persisted version of Settings. A write that expects an older Revision than the stored one is refused.
_Avoid_: version, generation, counter

**Scope**:
A permission attached to an API key that allows a class of operations, such as sending SMS or changing Settings.
_Avoid_: role, permission level, grant

**API key**:
The secret credential an external client presents to call the OpenSMS API.
_Avoid_: token, password, secret

**Restart**:
Replacing the running API server with a new one that uses the current Settings, notably the port.
_Avoid_: reload, reboot, bounce
73 changes: 70 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ You may need to run this first to generate the first API Key.
```bash
python openSmsCli.py interactive --serial /dev/ttyUSB0 # change your serial port, on windows: COM1 (example)

# generate a new API key
# replace this phone's API key (other keys keep working)
newkey

# get other interactive commands
Expand Down Expand Up @@ -132,14 +132,81 @@ curl -i -X POST 'http://127.0.0.1:9292/sms/' \
-d '{"number": "+1234567890", "text": "Hello from OpenSMS API!"}'
```

### 🔐 Remote Settings and control API

The API server can also read and change Settings, manage API keys, test the Webhook, and restart the server. This is meant for a proxy or automation on the **same LAN or VPN** as the phone. The API uses bearer keys over plain HTTP, with no TLS or CORS, so never expose the port to the internet; use a VPN or an authenticated tunnel for remote access.

Every `/api/` route, including `GET /api/health`, requires an API key with the `settings:write` Scope. `POST /sms/` requires `sms:write`.

| Scope | Allows |
| --- | --- |
| `sms:write` | `POST /sms/` |
| `settings:write` | every `/api/` route: health, status, Settings, key management, Webhook test, Restart |

The first API key is created from the phone UI the first time you tap Start Server. Create a separate key for each integration; the raw key is returned only once. Set it once in your shell:

```bash
export OSMS_KEY='osms_…'

curl -sS -X POST 'http://192.168.1.50:9292/api/keys' \
-H "Authorization: Bearer $OSMS_KEY" \
-H 'Content-Type: application/json' \
-d '{"name": "sms-proxy", "scopes": ["sms:write"]}'
```

`GET /api/keys` lists keys without hashes, and `DELETE /api/keys/{id}` revokes one immediately. The last remaining key cannot be deleted.

Check the phone and read Settings:

```bash
curl -sS -H "Authorization: Bearer $OSMS_KEY" \
'http://192.168.1.50:9292/api/health'

curl -sS -H "Authorization: Bearer $OSMS_KEY" \
'http://192.168.1.50:9292/api/settings'
```

`PUT /api/settings` replaces the full writable subset, so send every field you want to keep. Include the `revision` from `GET` for optimistic concurrency; a stale Revision returns `409`.

```bash
curl -sS -X PUT 'http://192.168.1.50:9292/api/settings' \
-H "Authorization: Bearer $OSMS_KEY" \
-H 'Content-Type: application/json' \
-d '{
"revision": 7,
"port": 9292,
"boot": true,
"webhook": {
"enabled": true,
"url": "https://proxy.example.lan/hooks/opensms",
"timeout": 10,
"max_attempts": 3,
"backoff": [5, 30],
"capacity": 100
}
}'
```

Omit `webhook.secret` to keep the stored secret, send `""` to clear it, or send a new string to replace it. Webhook and retry changes take effect immediately. Changing `boot` is read at the next app launch; it does not start or stop the current service. A port change is two-step: the response sets `restart_required`, then call:

```bash
curl -sS -X POST 'http://192.168.1.50:9292/api/server/restart' \
-H "Authorization: Bearer $OSMS_KEY"
```

Restart requires the background service loop; the standalone CLI runs the
server directly and refuses Restart with `409`.

`GET /api/status` reports the bound and configured port, network addresses, Outbox depth, the last Delivery attempt, and warnings (for example when forwarding is disabled or the Outbox is near capacity). `POST /api/webhook/test` tests a Webhook target without saving it. The full contract, error codes, and persisted schema are in [docs/remote-api.md](./docs/remote-api.md).

## 📥 Receiving SMS (Android)

OpenSMS can forward every SMS received by the phone to your own HTTP endpoint as a webhook. Receiving works independently of the API server: it runs in the same background service, so the API can be stopped while webhooks keep flowing.

### Configure it

1. Open `Settings` and find the **Webhook (Inbound SMS)** section.
2. Enter the **Webhook URL** (`http://` or `https://`).
2. Enter the **Webhook target** (`http://` or `https://`) without `username:password@` userinfo.
3. Optionally set a **Signing Secret** to sign every request.
4. Enable the switch and tap **Save**.
5. Tap **Send Test Webhook** to check the endpoint. This sends `event: "webhook.test"`.
Expand All @@ -153,7 +220,7 @@ Every Inbound SMS produces one `POST` with a JSON body:
```http
POST /your-hook HTTP/1.1
Content-Type: application/json
User-Agent: OpenSMS/1.1.0
User-Agent: OpenSMS/1.2.0
X-OpenSMS-Event: sms.received
X-OpenSMS-Delivery: 6f1c2f5e-0d7a-4c55-9f0e-2b1c8b7f0a11
X-OpenSMS-Signature: sha256=...
Expand Down
Loading
Loading