# ISP agent on an Android phone (Termux) — Celcom & Digi

Goal: turn a spare Android + a Celcom (or Digi) **prepaid SIM** into an agent that
checks all your domains over that real ISP and pushes the result to the dashboard.
One phone per ISP (one Celcom, one Digi).

---

## ⚠️ Prerequisite: the dashboard must be reachable over the internet
The phone tests Celcom/Digi by using **mobile data** (Wi-Fi OFF). On mobile data it
**cannot** reach `localhost` or your PC's LAN IP (`192.168.x.x`). So the dashboard's
`api/agent.php` must be reachable from the internet. Pick ONE:

- **Easiest (free, keeps it on your PC): Cloudflare Tunnel**
  On the PC, install `cloudflared`, then:
  ```
  cloudflared tunnel --url http://localhost/domain-monitor
  ```
  It prints a public `https://something.trycloudflare.com` URL. Your API URL becomes:
  `https://something.trycloudflare.com/api/agent.php`
  (For a permanent URL, set up a named tunnel with your own domain.)
- **Or** host the dashboard on a public server (ideally Malaysian).
- **Or** port-forward your router to the PC (works, least secure — needs a static/DDNS IP).

> The block CHECK happens on the phone over Celcom/Digi regardless; the internet URL
> is only needed so the phone can REPORT back.

---

## Your values (from dashboard → Settings → ISP agents)
- **Agent token:** `f0ea49da9a5cff286c7ced4723a31b78`
- **Agent API URL:** `https://<your-public-url>/api/agent.php`  ← use the public URL, not localhost

---

## Steps on the phone

1. **Install Termux** from **F-Droid** (https://f-droid.org) — NOT the Play Store version (it's outdated).

2. In Termux, install bash + curl:
   ```
   pkg update -y && pkg install -y bash curl
   ```

3. Download the agent script from your dashboard (replace the host):
   ```
   curl -O https://<your-public-url>/agent/isp-agent.sh
   ```

4. Edit the 3 values at the top:
   ```
   nano isp-agent.sh
   ```
   Set:
   ```
   API="https://<your-public-url>/api/agent.php"
   TOKEN="f0ea49da9a5cff286c7ced4723a31b78"
   ISP="Celcom"            # or "Digi" on the other phone
   ```
   Save in nano: `Ctrl+O`, `Enter`, then `Ctrl+X`.

5. **Turn Wi-Fi OFF** so the phone uses the Celcom/Digi SIM's mobile data (this is what makes the check test that ISP).

6. Test once:
   ```
   bash isp-agent.sh
   ```
   You should see `checked N, blocked M → ok: stored ...`. The Celcom/Digi status now
   shows on the dashboard Block column and in the bot's `/status`.

7. Run it on a loop (every 30 min):
   ```
   bash isp-agent.sh --loop 1800
   ```

---

## Keep it running unattended
- Keep Termux awake: `termux-wake-lock` (run once), and in Android settings disable
  **battery optimization** for Termux.
- Auto-start on boot: install **Termux:Boot** (from F-Droid), then:
  ```
  mkdir -p ~/.termux/boot
  printf '#!/data/data/com.termux/files/usr/bin/bash\ntermux-wake-lock\ncd ~ && bash isp-agent.sh --loop 1800\n' > ~/.termux/boot/start-agent.sh
  chmod +x ~/.termux/boot/start-agent.sh
  ```
- Leave the phone plugged into power.

Repeat all steps on a second phone with a **Digi** SIM, setting `ISP="Digi"`.
