Remote control OpenWrt device via instant messengers (Telegram, XMPP) and EMail

A device can send notifications and receive commands directly to you.

To send an email see SMTP clients. Receiving email can be done with postfix or E-MailRelay and custom scripts. But email server is problematic to set up on a router because of many limitations: it needs for a static IP, ISP often blocks the SMTP port, spam and DDoS problems.

This is the most used option. The Telegram has an advanced Bots API with easy access via simple HTTP API with a long pooling.

The alexwbaule/telegramopenwrt is a TG bot based on the curl and supports many commands:

  • cam_movie: Record 25 seconds of a camIP and send it.
  • cam_mv: Move the camera around.
  • cam_shot: Get a Pic from the camera.
  • cam_vdo: Get a 25 seconds record from a camIP.
  • chromego_add: Include to a user in chromego, a word to be used in permissions (block url/YouTube channel/etc).
  • chromego_del: Remove a word from a user in chromego to be used in permissions (block url/YouTube channel/etc).
  • chromego_list: List all permissions in chromego (block url/YouTube channel/etc).
  • fw_add: Block a hostname using a deny rule in firewall, if append time to command will block from 23:00 to 8:00
  • fw_delete: Remove a hostname from a deny firewall rule, if hostname is empty, will remove all rules created by this bot.
  • fw_disable: Disable a firewall rule.
  • fw_enable: Enable a firewall rule.
  • fw_list: List all fw rules.
  • fwr_disable: Disable a redirect firewall rule.
  • fwr_enable: Enable a redirect firewall rule.
  • fwr_list: List all redirect fw rules.
  • fw_unblock: Remove a hostname from a deny firewall rule, if hostname is empty, will remove all rules created by this bot.
  • get_ip: Get WAN IPAddress.
  • get_mac: Get the Organization that own the MacAddr.
  • get_ping: Ping an address or host, return Up or Down.
  • get_uptime: Return the uptime from this Device.
  • hst_list: Get hosts in the dhcp Leases. If a hostname is present, search only for this hostname.
  • ignoredmac_add: Add a new macaddress to the allowlist and avoid being notified about it.
  • ignoredmac_list: Shows the list of ignored mac addresses that will not be notified by the bot.
  • interface_down: Shutdown an interface by name.
  • interface_restart: Restart an interface by name.
  • interfaces_list: Get interfaces configuration.
  • interface_up: Start up an interface by name.
  • lights: Turn On or Off house Lights.
  • msg_tv: Send Message to Samsung TV
  • netstat: Prints netstat table in ESTABLISHED, CLOSED and TIME_WAIT State.
  • opkg_install: Install a package from opkg.
  • opkg_update: Update list of packages available.
  • ping_udp: Create a UDP packet to puncture a hole through a NAT firewall of your ISP
  • proc_list: List all process in execution
  • proc_restart: Restart a process in init.d
  • proc_start: Start a process in init.d
  • proc_stop: Stop a process in init.d
  • proxy_disable: Disable HTTP and HTTPS or HTTP or HTTPS proxy.
  • proxy_enable: Enable HTTP and HTTPS or HTTP or HTTPS proxy.
  • proxy_list: List proxy rules that is enabled.
  • reboot: Reboot the router.
  • start: This menu help!
  • swports_list: Switch ports list with states.
  • wifi_disable: Disable a wireless device radio.
  • wifi_enable: Enable a wireless device radio.
  • wifi_list: List all wireless devices.
  • wifi_restart: Restart a wireless device radio.
  • wll_list: Get a Wi-Fi clients list that is connected to this device

The XMPP (Jabber) is badly supported but used. You can install the Prosody XMPP server and use it as client too with a little Lua scripting. The sendxmpp is a perl-script to send xmpp, similar to what sendmail does for email. To send and receive messages over HTTP API with wget or curl you may install REST API plugin on the XMPP server (mod_http_rest for Prosody). The XEP-0124 BOSH probably can be used.

UnifiedPush is an open specification and tools that lets the user choose how push notifications are delivered. Different apps supports it:

  • ntfy.sh (pronounced “notify”) is an HTTP-based publish-subscriber notification service. It allows you to send notifications to your phone or desktop via scripts from any computer, and/or using a REST API. It has apps for Android and iOS.
  • The same but I want to use Google for some reason: gCompat-UP Distrib (Android)
  • I have a Nextcloud server: NextPush (Android)
  • I use Conversations XMPP client: Conversations (Android)

Example of a script to send a notification via the ntfy.sh into the example queue (you should create your own private queue):

NTFY_QUEUE="example"
NEW_CLIENT_IP="192.168.1.42"
MSG="Someone joined network
 
A new client with IP $NEW_CLIENT_IP joined.
Please check if it's not an intruder."
 
wget -q -O - "ntfy.sh/$NTFY_QUEUE" \
  --header "Priority: urgent" \
  --header "Tags: ghost" \
  --header "Click: http://192.168.1.1/" \
  --header "Actions: http, Open Luci, https://192.168.1.1/cgi-bin/ntfy-action.cgi?block=$NEW_CLIENT_IP, clear=true" \
  --header "Email: root@OpenWrt" \
  --post-data="$MSG"

NOTE: the --header option was added to the uclient-fetch on Jul 2024 so if you wish to use extended properties you'll need to install the wget-ssl package.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2024/12/17 16:07
  • by stokito