Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

OpenWrt Telegram ntfy & Auto-Ban (fw4)

Tip

🇪🇸 Leer en español: Haz clic aquí

This script monitors your OpenWrt router (specifically tested on fw4 / nftables based firewalls) and sends real-time notifications to Telegram regarding:

  • Successful and failed logins to the web interface (LuCI).
  • SSH login attempts (Keys and passwords).
  • New WireGuard VPN connections (identifying the device by its description in uci).
  • Auto-Ban: Automatically blocks IPs that fail login for 3 minutes using nftables.

🚀 Installation

1. Firewall Configuration

For the banning to work, you need to create a list named banlist in your firewall. Run these commands on the router:

uci add firewall ipset
uci set firewall.@ipset[-1].name='banlist'
uci set firewall.@ipset[-1].family='ipv4'
uci set firewall.@ipset[-1].match='src_ip'
uci set firewall.@ipset[-1].timeout='180'
uci commit firewall
/etc/init.d/firewall restart

2. Script Configuration

  1. Create a Telegram Bot with @BotFather and get your Token.
  2. Get your Chat ID (you can use @userinfobot).
  3. Download the telegram-ntfy.sh script to /usr/bin/ and edit the TOKEN and ID variables.
  4. Give it execution permissions: chmod +x /usr/bin/telegram-ntfy.sh.

3. Automatic Execution (Procd)

To make the script start automatically with the router, create the file /etc/init.d/ntfy:

#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1

start_service() {
    procd_open_instance
    procd_set_param command /bin/sh /usr/bin/telegram-ntfy.sh
    procd_set_param respawn
    procd_close_instance
}

Enable the service:

chmod +x /etc/init.d/ntfy
/etc/init.d/ntfy enable
/etc/init.d/ntfy start

🛠️ Requirements

  • OpenWrt 21.02 or higher (with fw4).
  • curl package installed (opkg update && opkg install curl).
  • jsonfilter package (usually comes by default).

Versión en Español

Este script monitoriza tu router OpenWrt (especialmente probado en firewalls basados en fw4 / nftables) y envía notificaciones en tiempo real a Telegram sobre:

  • Conexiones exitosas y fallidas a la interfaz web (LuCI).
  • Inicios de sesión por SSH (Llaves y contraseñas).
  • Nuevas conexiones VPN WireGuard (identificando el dispositivo por su descripción en uci).
  • Auto-Ban: Bloquea automáticamente las IPs que fallan en el login durante 3 minutos mediante nftables.

🚀 Instalación

1. Configuración del Firewall

Para que el baneo funcione, necesitas crear una lista llamada banlist en tu firewall. Ejecuta estos comandos en el router:

uci add firewall ipset
uci set firewall.@ipset[-1].name='banlist'
uci set firewall.@ipset[-1].family='ipv4'
uci set firewall.@ipset[-1].match='src_ip'
uci set firewall.@ipset[-1].timeout='180'
uci commit firewall
/etc/init.d/firewall restart

2. Configuración del Script

  1. Crea un Bot en Telegram con @BotFather y obtén tu Token.
  2. Obtén tu Chat ID (puedes usar @userinfobot).
  3. Descarga el script telegram-ntfy.sh en /usr/bin/ y edita las variables TOKEN e ID.
  4. Dale permisos de ejecución: chmod +x /usr/bin/telegram-ntfy.sh.

3. Ejecución Automática (Procd)

Para que el script arranque solo con el router, crea el archivo /etc/init.d/ntfy:

#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1

start_service() {
    procd_open_instance
    procd_set_param command /bin/sh /usr/bin/telegram-ntfy.sh
    procd_set_param respawn
    procd_close_instance
}

Habilita el servicio:

chmod +x /etc/init.d/ntfy
/etc/init.d/ntfy enable
/etc/init.d/ntfy start

🛠️ Requisitos

  • OpenWrt 21.02 o superior (con fw4).
  • Paquete curl instalado (opkg update && opkg install curl).
  • Paquete jsonfilter (suele venir por defecto).

About

Real-time Telegram notifications & Auto-Ban system for OpenWrt (fw4/nftables). Monitor SSH, LuCI, and WireGuard activity with automated security.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages