├── .gitignore ├── usr └── lib │ └── telegramopenwrt │ └── plugins │ ├── help │ ├── start │ ├── fw_list │ ├── get_ip │ ├── reboot │ ├── cam_mv │ ├── cam_shot │ ├── fw_disable │ ├── fwr_list │ ├── interface_up │ ├── lights │ ├── msg_tv │ ├── opkg_install │ ├── proc_start │ ├── proc_stop │ ├── wifi_list │ ├── fw_enable │ ├── interface_down │ ├── interface_restart │ ├── interfaces_list │ ├── opkg_update │ ├── proc_list │ ├── proc_restart │ ├── cam_vdo │ ├── fwr_disable │ ├── fwr_enable │ ├── get_uptime │ ├── proxy_list │ ├── swports_list │ ├── wifi_disable │ ├── wifi_restart │ ├── cam_movie │ ├── get_mac │ ├── get_ping │ ├── wifi_enable │ ├── proxy_disable │ ├── proxy_enable │ ├── wll_list │ ├── netstat │ ├── ping_udp │ ├── ignoredmac_add │ ├── hst_list │ ├── ignoredmac_list │ ├── chromego_add │ ├── chromego_del │ ├── fw_add │ ├── fw_delete │ ├── fw_unblock │ └── chromego_list │ ├── get_uptime │ ├── cam_mv │ ├── lights │ ├── fw_enable │ ├── fw_delete │ ├── fwr_enable │ ├── reboot │ ├── fw_disable │ ├── proc_start │ ├── proc_stop │ ├── fwr_disable │ ├── opkg_update │ ├── proc_restart │ ├── wifi_enable │ ├── wifi_disable │ ├── wifi_restart │ ├── ctx │ ├── reboot │ ├── service_list │ ├── interfaces_list │ ├── proxy │ ├── light_list │ ├── fw_list │ ├── fwr_list │ ├── cam_kbd │ ├── wifi_list │ └── chromego │ ├── interface_up │ ├── interface_down │ ├── interface_restart │ ├── get_ip │ ├── ignoredmac_list │ ├── get_ping │ ├── ignoredmac_add │ ├── netstat │ ├── opkg_install │ ├── actions │ ├── proc_start │ ├── proc_stop │ ├── proc_restart │ ├── interface_up │ ├── interface_down │ ├── fw_delete │ ├── fw_disable │ ├── fw_enable │ ├── fwr_disable │ ├── fwr_enable │ ├── interface_restart │ ├── wifi_disable │ ├── wifi_enable │ ├── wifi_restart │ ├── light_control │ ├── proxy_disable │ ├── proxy_enable │ ├── chromego │ └── cam_mv │ ├── start │ ├── chromego_del │ ├── chromego_add │ ├── fw_unblock │ ├── proc_list │ ├── fw_list │ ├── fwr_list │ ├── proxy_list │ ├── hst_list │ ├── proxy_enable │ ├── wifi_list │ ├── proxy_disable │ ├── swports_list │ ├── get_mac │ ├── cam_shot │ ├── ping_udp │ ├── cam_movie │ ├── cam_vdo │ ├── wll_list │ ├── fw_add │ ├── chromego_list │ ├── msg_tv │ └── interfaces_list ├── etc ├── telegramopenwrt │ └── macaddr.ignore ├── init.d │ ├── lanports │ ├── hosts_scan │ └── telegram_bot └── config │ └── telegramopenwrt ├── SECURITY.md ├── sbin ├── typing ├── telebot ├── telekeyboard ├── hosts_scan ├── camkeyboard ├── telegram_sender ├── lanports ├── proxy └── telegram_bot ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── workflows │ └── build-package.yml ├── CODE_OF_CONDUCT.md ├── Makefile ├── README.md ├── LICENSE └── CONTRIBUTING.md /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/start: -------------------------------------------------------------------------------- 1 | This menu help! 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fw_list: -------------------------------------------------------------------------------- 1 | List all fw rules. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/get_ip: -------------------------------------------------------------------------------- 1 | Get WAN IPAddress. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/reboot: -------------------------------------------------------------------------------- 1 | Reboot the router. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/get_uptime: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | uptime 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/cam_mv: -------------------------------------------------------------------------------- 1 | Move the camera arround. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/cam_shot: -------------------------------------------------------------------------------- 1 | Get a Pic from the camera. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fw_disable: -------------------------------------------------------------------------------- 1 | Disable a firewall rule. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fwr_list: -------------------------------------------------------------------------------- 1 | List all redirect fw rules. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/interface_up: -------------------------------------------------------------------------------- 1 | Start up a interface by name. -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/lights: -------------------------------------------------------------------------------- 1 | Turn On or Off house Lights. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/msg_tv: -------------------------------------------------------------------------------- 1 | Send Message to Samsung TV 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/opkg_install: -------------------------------------------------------------------------------- 1 | Install a package from opkg. -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/proc_start: -------------------------------------------------------------------------------- 1 | Start a process in init.d 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/proc_stop: -------------------------------------------------------------------------------- 1 | Stop a process in init.d 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/wifi_list: -------------------------------------------------------------------------------- 1 | List all wireless devices. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fw_enable: -------------------------------------------------------------------------------- 1 | Enable a firewall rule. 2 | 3 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/interface_down: -------------------------------------------------------------------------------- 1 | Shutdown a interface by name. -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/interface_restart: -------------------------------------------------------------------------------- 1 | Restart a interface by name. -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/interfaces_list: -------------------------------------------------------------------------------- 1 | Get interfaces configuration. -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/opkg_update: -------------------------------------------------------------------------------- 1 | Update list of packages avaliable. -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/proc_list: -------------------------------------------------------------------------------- 1 | List all process in execution 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/proc_restart: -------------------------------------------------------------------------------- 1 | Restart a process in init.d 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/cam_mv: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | ./ctx/cam_kbd >/dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/cam_vdo: -------------------------------------------------------------------------------- 1 | Get a 25 seconds record from a camIP. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fwr_disable: -------------------------------------------------------------------------------- 1 | Disable a redirect firewall rule. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fwr_enable: -------------------------------------------------------------------------------- 1 | Enable a redirect firewall rule. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/get_uptime: -------------------------------------------------------------------------------- 1 | Return the uptime from this Device. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/proxy_list: -------------------------------------------------------------------------------- 1 | List proxy rules that is enabled. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/swports_list: -------------------------------------------------------------------------------- 1 | Switch ports list with states. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/wifi_disable: -------------------------------------------------------------------------------- 1 | Disable a wireless device radio. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/wifi_restart: -------------------------------------------------------------------------------- 1 | Restart a wireless device radio. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/cam_movie: -------------------------------------------------------------------------------- 1 | Record 25 seconds of a camIP and send it. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/get_mac: -------------------------------------------------------------------------------- 1 | Get the Organization that onwer the MacAddr. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/get_ping: -------------------------------------------------------------------------------- 1 | Ping a address or host, return Up or Down. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/wifi_enable: -------------------------------------------------------------------------------- 1 | Enable a wireless device radio. 2 | 3 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/lights: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/light_list > /dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/proxy_disable: -------------------------------------------------------------------------------- 1 | Disable HTTP and HTTPS or HTTP or HTTPS proxy. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/proxy_enable: -------------------------------------------------------------------------------- 1 | Enable HTTP and HTTPS or HTTP or HTTPS proxy. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/wll_list: -------------------------------------------------------------------------------- 1 | Get a wifi clients list that is connected to this devices. 2 | -------------------------------------------------------------------------------- /etc/telegramopenwrt/macaddr.ignore: -------------------------------------------------------------------------------- 1 | # Fill this list with your mac address that don't want to be notified about -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/netstat: -------------------------------------------------------------------------------- 1 | Prints netstat table in ESTABLISHED, CLOSED and TIME\_WAIT State. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/ping_udp: -------------------------------------------------------------------------------- 1 | Create a UDP packet to puncture a hole through a NAT firewall of your ISP 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fw_enable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/fw_list "fw_enable" "Choose a rule to enable:" >/dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/ignoredmac_add: -------------------------------------------------------------------------------- 1 | Add a new macaddress to the allowlist and avoid being notified about it. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fw_delete: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/fw_list "fw_delete" "Choose a rule to delete:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fwr_enable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/fwr_list "fwr_enable" "Choose a rule to enable:" >/dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/reboot: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/reboot& >>/dev/null 4 | 5 | echo "Rebooting in 15 seconds...." 6 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fw_disable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/fw_list "fw_disable" "Choose a rule to disable:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/hst_list: -------------------------------------------------------------------------------- 1 | Get hosts in the dhcp Leases. If a hostname is present, search only for this hostname. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/ignoredmac_list: -------------------------------------------------------------------------------- 1 | Shows the list of ignored mac addresses that will not be notified by the bot. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/proc_start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/service_list "proc_start" "Choose a service to start:" >/dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/proc_stop: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/service_list "proc_stop" "Choose a service to stop:" >/dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fwr_disable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/fwr_list "fwr_disable" "Choose a rule to disable:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/opkg_update: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | OUTPUT=$(/bin/opkg update) 4 | 5 | echo $OUTPUT 6 | echo "Update packages done!" -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/proc_restart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/service_list "proc_restart" "Choose a service to restart:" >/dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/chromego_add: -------------------------------------------------------------------------------- 1 | Include to a user in chromego, a word to be used in permissions (block url/youtube channel/etc). -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/chromego_del: -------------------------------------------------------------------------------- 1 | Remove a word from a user in chromego to be used in permissions (block url/youtube channel/etc). -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/wifi_enable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./ctx/wifi_list "wifi_enable" "Choose a Wireless radio to enable:" >/dev/null 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fw_add: -------------------------------------------------------------------------------- 1 | Block a hostname using a deny rule in firewall, if append time to command will block from 23:00 to 8:00 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/wifi_disable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/wifi_list "wifi_disable" "Choose a Wireless radio disable:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/wifi_restart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/wifi_list "wifi_restart" "Choose a Wireless radio restart:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/reboot: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sleep 15 && echo "rebooting" | logger -t "telegram_bot[$$]" -p daemon.info && /sbin/reboot 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/interface_up: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/interfaces_list "interface_up" "Choose a Network interface to up:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fw_delete: -------------------------------------------------------------------------------- 1 | Remove a hostname from a deny firewall rule, if hostname is empty, will remove all rules created by this bot. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/fw_unblock: -------------------------------------------------------------------------------- 1 | Remove a hostname from a deny firewall rule, if hostname is empty, will remove all rules created by this bot. 2 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/interface_down: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/interfaces_list "interface_down" "Choose a Network interface to down:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/help/chromego_list: -------------------------------------------------------------------------------- 1 | List all permissions in chromego (block url/youtube channel/etc). -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/interface_restart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ./ctx/interfaces_list "interface_restart" "Choose a Network interface to restart:" >/dev/null 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/get_ip: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ip=$(ifconfig eth0.2 | grep inet | grep -v inet6 | awk '{print $2}' | awk -F : '{print "*IP:* " $2}') 4 | echo $ip 5 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ignoredmac_list: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | ignored_macaddrs_file=$(uci -q get telegramopenwrt.global.ignored_macaddrs_file) 3 | 4 | echo "*Ignored MAC Addresses*" 5 | cat "$ignored_macaddrs_file" 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | There is no know `security` issues found on this sets of bash script. 6 | 7 | ## Reporting a Vulnerability 8 | 9 | Send us a email, or open a issue. 10 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/get_ping: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DEVICE="$1" 4 | NL="$2" 5 | 6 | ping ${DEVICE} -w 1 -q &>/dev/null; [ $? == 0 ] && echo -en "Up" || echo -en "Down" 7 | if [ -z ${NL} ];then 8 | echo -en "\n" 9 | fi 10 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ignoredmac_add: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | NEWMAC="$*" 3 | ignored_macaddrs_file=$(uci -q get telegramopenwrt.global.ignored_macaddrs_file) 4 | echo "${NEWMAC}" >> "$ignored_macaddrs_file" 5 | echo "Adding ${NEWMAC} to known MAC Addresses..." 6 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/netstat: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | netstat -ntu | grep -v "127.0.0.1" | grep -v "::ffff:" |grep "ESTABLISHED\|CLOSED\|TIME_WAIT" | sed -e 's/_/\\_/g' | awk '{print "Protocolo: " $1 " \nOrigem: " $4 "\nDestino: " $5 "\nState: " $6 "\n" } ' 4 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/opkg_install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NAME="$1" 4 | 5 | OUTPUT=$(/bin/opkg install $NAME) 6 | if [ $? == 255 ]; then 7 | echo "error installing package $NAME!" 8 | echo $OUTPUT 9 | else 10 | echo "install package done!" 11 | echo $OUTPUT 12 | fi 13 | 14 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/proc_start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SCRIPT_NAME="$1" 4 | 5 | if [ "$SCRIPT_NAME" == "" ]; then 6 | echo "1|Service dont exist !!" 7 | return 1 8 | else 9 | /etc/init.d/$SCRIPT_NAME start &> /dev/null 10 | echo "1|Service $SCRIPT_NAME was started." 11 | exit 0 12 | fi 13 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/proc_stop: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SCRIPT_NAME="$1" 4 | 5 | if [ "$SCRIPT_NAME" == "" ]; then 6 | echo "1|Service dont exist !!" 7 | return 1 8 | else 9 | /etc/init.d/$SCRIPT_NAME stop &> /dev/null 10 | echo "1|Service $SCRIPT_NAME was stopped." 11 | exit 0 12 | fi 13 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/proc_restart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SCRIPT_NAME="$1" 4 | 5 | if [ "$SCRIPT_NAME" == "" ]; then 6 | echo "1|Service dont exist !!" 7 | return 1 8 | else 9 | /etc/init.d/$SCRIPT_NAME restart &> /dev/null 10 | echo "1|Service $SCRIPT_NAME was restarted." 11 | exit 0 12 | fi 13 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo -en "I can help you to manage and get some informations about your OpenWRT Router.\nThis is the avaliable commands list:\n\n" 4 | ALLPLUGINS=$(ls -1 -p | grep -v "/") 5 | for plug in $ALLPLUGINS 6 | do 7 | help=$(cat "help/${plug}") 8 | echo "[/${plug}](/${plug}) - ${help}" 9 | done 10 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/chromego_del: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | USER="$1" 4 | WORD="$2" 5 | 6 | VALID_USER=$(uci -q get chromego.$USER | awk '{printf $0}') 7 | 8 | if [ "$VALID_USER" = "chromego" ]; then 9 | ./ctx/chromego "chromego" "del" "$USER" "$WORD" >/dev/null 10 | exit 0; 11 | fi 12 | echo "Error creating new rule for ${USER} word ${WORD}!" 13 | exit 1 14 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/chromego_add: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | USER="$1" 4 | WORD="$2" 5 | 6 | VALID_USER=$(uci -q get chromego.$USER | awk '{printf $0}') 7 | 8 | if [ "$VALID_USER" = "chromego" ]; then 9 | ./ctx/chromego "chromego" "add" "$USER" "$WORD" >/dev/null 10 | exit 0; 11 | fi 12 | echo "Error creating new rule for ${USER} word ${WORD}!" 13 | exit 1 14 | 15 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/interface_up: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | IFACE="$1" 4 | 5 | if [ "$IFACE" == "" ]; then 6 | echo "1|Network interface dont exist !!" 7 | return 1 8 | else 9 | uci -q set network.$IFACE.disabled='0' 10 | uci -q commit network &> /dev/null 11 | /sbin/ifup $IFACE &> /dev/null 12 | echo "1|Network Interface $IFACE is enabled." 13 | exit 0 14 | fi 15 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/interface_down: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | IFACE="$1" 4 | 5 | if [ "$IFACE" == "" ]; then 6 | echo "1|Network interface dont exist !!" 7 | return 1 8 | else 9 | uci -q set network.$IFACE.disabled='1' 10 | uci -q commit network &> /dev/null 11 | /sbin/ifdown $IFACE &> /dev/null 12 | echo "1|Network Interface $IFACE is disabled." 13 | exit 0 14 | fi 15 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/fw_delete: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RULE_NUM="$1" 4 | RULE_NAME="$2" 5 | 6 | if [ "$RULE_NUM" == "" ]; then 7 | echo "1|Rule Num Error!!" 8 | return 1 9 | else 10 | uci -q delete firewall.@rule${RULE_NUM} 11 | uci -q commit firewall &> /dev/null 12 | /etc/init.d/firewall restart &> /dev/null 13 | echo "1|Rule $RULE_NAME deleted!" 14 | return 0 15 | fi 16 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/fw_disable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RULE_NUM="$1" 4 | RULE_NAME="$2" 5 | 6 | if [ "$RULE_NUM" == "" ]; then 7 | echo "1|Rule Num Error!!" 8 | return 1 9 | else 10 | uci -q set firewall.@rule[$RULE_NUM].enabled='0' 11 | uci -q commit firewall &> /dev/null 12 | /etc/init.d/firewall restart &> /dev/null 13 | echo "1|rule $RULE_NAME is disabled." 14 | exit 0 15 | fi 16 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/fw_enable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RULE_NUM="$1" 4 | RULE_NAME="$2" 5 | 6 | if [ "$RULE_NUM" == "" ]; then 7 | echo "1|Rule Num Error!!" 8 | return 1 9 | else 10 | uci -q set firewall.@rule[$RULE_NUM].enabled='1' 11 | uci -q commit firewall &> /dev/null 12 | /etc/init.d/firewall restart &> /dev/null 13 | echo "1|rule $RULE_NAME is enabled." 14 | exit 0 15 | fi 16 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/fwr_disable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RULE_NUM="$1" 4 | RULE_NAME="$2" 5 | 6 | if [ "$RULE_NUM" == "" ]; then 7 | echo "1|Rule Num Error!!" 8 | return 1 9 | else 10 | uci -q set firewall.@redirect[$RULE_NUM].enabled='0' 11 | uci -q commit firewall &> /dev/null 12 | /etc/init.d/firewall restart &> /dev/null 13 | echo "1|rule $RULE_NAME is disabled." 14 | exit 0 15 | fi 16 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/fwr_enable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RULE_NUM="$1" 4 | RULE_NAME="$2" 5 | 6 | if [ "$RULE_NUM" == "" ]; then 7 | echo "1|Rule Num Error!!" 8 | return 1 9 | else 10 | uci -q set firewall.@redirect[$RULE_NUM].enabled='1' 11 | uci -q commit firewall &> /dev/null 12 | /etc/init.d/firewall restart &> /dev/null 13 | echo "1|rule $RULE_NAME is enabled." 14 | exit 0 15 | fi 16 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/interface_restart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | IFACE="$1" 4 | 5 | if [ "$IFACE" == "" ]; then 6 | echo "1|Network interface dont exist !!" 7 | return 1 8 | else 9 | uci -q set network.$IFACE.disabled='0' 10 | uci -q commit network &> /dev/null 11 | /sbin/ifdown $IFACE && /sbin/ifup $IFACE &> /dev/null 12 | echo "1|Network Interface $IFACE was restarted." 13 | exit 0 14 | fi 15 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/wifi_disable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | RULE_NUM="$1" 3 | RULE_NAME="$2" 4 | if [ "$RULE_NUM" == "" ]; then 5 | echo "1|Rule Num Error!!" 6 | return 1 7 | else 8 | uci -q set wireless.radio$RULE_NUM.__toggle='Disable' 9 | uci -q set wireless.radio$RULE_NUM.disabled='1' 10 | uci -q commit wireless &> /dev/null 11 | /sbin/wifi &> /dev/null 12 | echo "1|Radio $RULE_NAME is disabled." 13 | exit 0 14 | fi 15 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/wifi_enable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | RULE_NUM="$1" 3 | RULE_NAME="$2" 4 | if [ "$RULE_NUM" == "" ]; then 5 | echo "1|Rule Num Error!!" 6 | return 1 7 | else 8 | uci -q set wireless.radio$RULE_NUM.__toggle='Enable' 9 | uci -q delete wireless.radio$RULE_NUM.disabled 10 | uci -q commit wireless &> /dev/null 11 | /sbin/wifi &> /dev/null 12 | echo "1|Radio $RULE_NAME is enabled." 13 | exit 0 14 | fi 15 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fw_unblock: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NAME="$1" 4 | 5 | TOTAL=0 6 | for rule in $(uci -q show firewall | grep "Telegram ${NAME}" | grep -oE "\[([[:digit:]])\]") 7 | do 8 | uci -q delete firewall.@rule${rule} 9 | TOTAL=$(($TOTAL+1)) 10 | done 11 | 12 | if [ $TOTAL > 0 ]; then 13 | uci -q commit firewall &> /dev/null 14 | /etc/init.d/firewall restart &> /dev/null 15 | echo "Deleted $TOTAL rules !" 16 | return 0 17 | fi 18 | return 1 19 | -------------------------------------------------------------------------------- /sbin/typing: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PATH='/usr/bin:/usr/sbin:/bin:/sbin' 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | 11 | while [ true ] 12 | do 13 | curl -s -k -X POST $api/sendChatAction -d "chat_id=$my_chat_id" -d "action=typing" | logger -t "telegram_bot[$$]" -p daemon.info 14 | echo "Typing" 15 | sleep 6 16 | done 17 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/proc_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ps_cmd=$([[ $(readlink -fn /bin/ps) == "/bin/busybox" ]] && echo "ps w" || echo "ps ax") 4 | 5 | 6 | for i in $(${ps_cmd} | grep -v get_services | grep -v grep | grep -v PID | awk '{print $1}') 7 | do 8 | if [ -e /proc/$i/status ];then 9 | cat /proc/$i/status 2>/dev/null| grep "^Name:\|^State:\|^Threads:\|^Pid:" |awk '{gsub( "*","\\*" ); gsub( "_","\\_" ); print $0 }' 10 | echo "------------------" 11 | fi 12 | done 13 | -------------------------------------------------------------------------------- /sbin/telebot: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH='/usr/bin:/usr/sbin:/bin:/sbin' 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | 12 | command_new=${command//_/\\_} 13 | 14 | curl -k -s -X POST $api/sendMessage -d chat_id=$my_chat_id -d parse_mode=Markdown --data-urlencode text="$command_new" | logger -t "telegram_bot[$$]" -p daemon.info 15 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fw_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | old=$IFS 4 | IFS=$'\n' 5 | TOTAL=0 6 | 7 | echo "*Rules*" 8 | 9 | for rule in $(uci -q show firewall | grep "@rule" ) 10 | do 11 | line=$(echo ${rule} | awk -F "." '{print $3}') 12 | id=$(echo ${rule} | grep ".name" | grep -oE "\[[[:digit:]]+\]" | awk '{gsub("\\[|]","");printf $1}') 13 | if [ "$id" != "" ]; then 14 | echo "id: $id" 15 | fi 16 | new=${line//\'/} 17 | new2=${new//_/\\_} 18 | new3=${new2//=/: } 19 | echo ${new3//\*/all} 20 | done 21 | IFS=$old 22 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fwr_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | old=$IFS 4 | IFS=$'\n' 5 | TOTAL=0 6 | 7 | echo "*Rules*" 8 | 9 | for rule in $(uci -q show firewall | grep "@redirect" ) 10 | do 11 | line=$(echo ${rule} | awk -F "." '{ if (NF > 3) print $3"."$4"."$5"."$6; else print $3 }' ) 12 | id=$(echo ${rule} | grep ".name" | grep -oE "\[[[:digit:]]+\]" | awk '{gsub("\\[|]","");printf $1}') 13 | if [ "$id" != "" ]; then 14 | echo "id: $id" 15 | fi 16 | new=${line//\'/} 17 | new2=${new//_/\\_} 18 | new3=${new2//=/: } 19 | echo ${new3//\*/all} 20 | done 21 | IFS=$old 22 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/wifi_restart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | RULE_NUM="$1" 3 | RULE_NAME="$2" 4 | if [ "$RULE_NUM" == "" ]; then 5 | echo "1|Rule Num Error!!" 6 | return 1 7 | else 8 | uci -q set wireless.radio$RULE_NUM.__toggle='Disable' 9 | uci -q set wireless.radio$RULE_NUM.disabled='1' 10 | uci -q commit wireless &> /dev/null 11 | /sbin/wifi &> /dev/null 12 | uci -q set wireless.radio$RULE_NUM.__toggle='Enable' 13 | uci -q delete wireless.radio$RULE_NUM.disabled 14 | uci -q commit wireless &> /dev/null 15 | /sbin/wifi &> /dev/null 16 | echo "1|Radio $RULE_NAME was restarted." 17 | exit 0 18 | fi 19 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/light_control: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NAME="$1" 4 | STATE="$2" 5 | 6 | if [ "$NAME" == "" ] || [ "$STATE" == "" ]; then 7 | echo "1|Light Error!!" 8 | return 1 9 | else 10 | ipaddr=$(avahi-resolve -n ${NAME} | awk '{printf $2}') 11 | if [ "${STATE}" == "off" ];then 12 | curl -s "$ipaddr/light/on" &>/dev/null 13 | elif [ "${STATE}" == "on" ]; then 14 | curl -s "$ipaddr/light/off" &>/dev/null 15 | fi 16 | light_is=$(curl -s "$ipaddr/state" 2>/dev/null) 17 | state=$(jsonfilter -s "$light_is" -e $.state) 18 | name=$(jsonfilter -s "$light_is" -e $.name) 19 | echo "1|Light $name is $state." 20 | exit 0 21 | fi 22 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/proxy_disable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RULE_NUM="$1" 4 | RULE_NAME="$2" 5 | 6 | if [ "$RULE_NUM" == "" ]; then 7 | echo "1|Rule Num Error!!" 8 | return 1 9 | fi 10 | 11 | /etc/init.d/proxy stop &> /dev/null 12 | 13 | if [ "$RULE_NUM" == "0" ]; then 14 | uci -q set telegramopenwrt.proxy.config.http=false 15 | elif [ "$RULE_NUM" == "1" ]; then 16 | uci -q telegramopenwrt.proxy.config.https=false 17 | elif [ "$RULE_NUM" == "2" ]; then 18 | uci -q telegramopenwrt.proxy.config.http=false 19 | uci -q telegramopenwrt.proxy.config.https=false 20 | fi 21 | uci -q commit proxy &> /dev/null 22 | echo "1|Proxy $RULE_NAME is stopped." 23 | exit 0 24 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/proxy_enable: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RULE_NUM="$1" 4 | RULE_NAME="$2" 5 | 6 | if [ "$RULE_NUM" == "" ]; then 7 | echo "1|Rule Num Error!!" 8 | return 1 9 | fi 10 | 11 | if [ "$RULE_NUM" == "0" ]; then 12 | uci -q set telegramopenwrt.proxy.config.http=true 13 | elif [ "$RULE_NUM" == "1" ]; then 14 | uci -q set telegramopenwrt.proxy.config.https=true 15 | elif [ "$RULE_NUM" == "2" ]; then 16 | uci -q set telegramopenwrt.proxy.config.http=true 17 | uci -q set telegramopenwrt.proxy.config.https=true 18 | fi 19 | uci -q commit proxy &> /dev/null 20 | /etc/init.d/proxy start &> /dev/null 21 | echo "1|Proxy $RULE_NAME is started." 22 | exit 0 23 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/proxy_list: -------------------------------------------------------------------------------- 1 | HTTP=$(uci -q get telegramopenwrt.proxy.http | awk '{printf $1}') 2 | HTTPS=$(uci -q get telegramopenwrt.proxy.https | awk '{printf $1}') 3 | HTTP_ENABLE=$(iptables -t mangle -nL |grep MARK | grep -Eo "dpt:80" |awk -F ":" '{printf $2}') 4 | HTTPS_ENABLE=$(iptables -t mangle -nL |grep MARK | grep -Eo "dpt:443" |awk -F ":" '{printf $2}') 5 | 6 | if [ "$HTTP_ENABLE" == "" ] ; then 7 | HTTP_ENABLE="--" 8 | fi 9 | if [ "$HTTPS_ENABLE" == "" ] ; then 10 | HTTPS_ENABLE="--" 11 | fi 12 | 13 | echo -en "HTTP\n\tConfig enabled: ${HTTP}\n\tEnabled Iptables Port: ${HTTP_ENABLE}\nHTTPS\n\tConfig enabled: ${HTTPS}\n\tEnabled Iptables Port: ${HTTPS_ENABLE}\n\n" 14 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/hst_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | parms="$1" 4 | 5 | echo "*Hosts*" 6 | 7 | if [ "$parms" != "" ]; then 8 | cat /tmp/dhcp.leases | grep "$parms" | awk '{gsub("*","\\*"); gsub( "_","\\_" ); printf "Acquire Date: " ; system("date \"+%d/%m/%Y %T %Z\" -d \"@$(( "$1" - 43200))\"");printf "Device: " $4 "\nIP: " $3 "\nMac: " toupper($2)"\nState: "; system("./get_ping "$4" 1") ;printf "\n\n" }' 9 | else 10 | cat /tmp/dhcp.leases | awk '{gsub("*","\\*"); gsub( "_","\\_" ); printf "Acquire Date: " ; system("date \"+%d/%m/%Y %T %Z\" -d \"@$(( "$1" - 43200))\"");printf "Device: " $4 "\nIP: " $3 "\nMac: " toupper($2)"\nState: "; system("./get_ping "$4" 1") ;printf "\n\n" }' 11 | fi 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/service_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | text="$2" 12 | 13 | SERVICES=$(ls -1 /etc/init.d/ | awk '{print " [ {\"callback_data\": \"##CMD##|"$0"^\" ,\"text\" : \""$0"\"} ],"}') 14 | rules=${SERVICES:0:$((${#SERVICES}-1))} 15 | rls=${rules//##CMD##/$command} 16 | keyboard='{"inline_keyboard": ['$rls'] }' 17 | 18 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 19 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/proxy_enable: -------------------------------------------------------------------------------- 1 | HTTP=$(uci -q get telegramopenwrt.proxy.http | awk '{printf $1}') 2 | HTTPS=$(uci -q get telegramopenwrt.proxy.https | awk '{printf $1}') 3 | HTTP_ENABLE=$(iptables -t mangle -nL |grep MARK | grep -Eo "dpt:80" |awk -F ":" '{printf $2}') 4 | HTTPS_ENABLE=$(iptables -t mangle -nL |grep MARK | grep -Eo "dpt:443" |awk -F ":" '{printf $2}') 5 | 6 | if [ "$HTTP_ENABLE" == "" ] ; then 7 | HTTP_ENABLE="--" 8 | fi 9 | if [ "$HTTPS_ENABLE" == "" ] ; then 10 | HTTPS_ENABLE="--" 11 | fi 12 | ./ctx/proxy "proxy_enable" "Enable" "HTTP\n\tConfig enabled: ${HTTP}\n\tEnabled Iptables Port: ${HTTP_ENABLE}\nHTTPS\n\tConfig enabled: ${HTTPS}\n\tEnabled Iptables Port: ${HTTPS_ENABLE}\n\n">/dev/null 13 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/wifi_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | old=$IFS 4 | IFS=$'\n' 5 | TOTAL=0 6 | 7 | echo "*Wireless*" 8 | 9 | for rule in $(uci -q show wireless | grep "default_radio" ) 10 | do 11 | line=$(echo ${rule} | awk -F "." '{print $3}') 12 | id=$(echo ${rule} | grep ".ssid" | grep -oE "\[[[:digit:]]+\]" | awk '{gsub("\\[|]","");printf $1}') 13 | if [ "$id" != "" ]; then 14 | echo "rate: "$(iwinfo wlan${id} info | grep -oE "[[:digit:]]+\.[[:digit:]]+ MBit\/s") 15 | awk 'BEGIN{x='$(iwinfo wlan${id} info | grep -oE "[[:digit:]]+/[[:digit:]]+")' * 100; printf "quality: %.0f%%\n", x}' 16 | fi 17 | new=${line//\'/} 18 | new2=${new//_/\\_} 19 | new3=${new2//=/: } 20 | echo ${new3//\*/all} 21 | done 22 | IFS=$old 23 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/interfaces_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | text="$2" 12 | 13 | INTERFACES=$(ubus list network.interface.* | awk -F"." '{print " [ {\"callback_data\": \"##CMD##|"$3"^\" ,\"text\" : \""$3"\"} ],"}') 14 | rules=${INTERFACES:0:$((${#INTERFACES}-1))} 15 | rls=${rules//##CMD##/$command} 16 | keyboard='{"inline_keyboard": ['$rls'] }' 17 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 18 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/proxy_disable: -------------------------------------------------------------------------------- 1 | 2 | HTTP=$(uci -q get telegramopenwrt.proxy.http | awk '{printf $1}') 3 | HTTPS=$(uci -q get telegramopenwrt.proxy.https | awk '{printf $1}') 4 | HTTP_ENABLE=$(iptables -t mangle -nL |grep MARK | grep -Eo "dpt:80" |awk -F ":" '{printf $2}') 5 | HTTPS_ENABLE=$(iptables -t mangle -nL |grep MARK | grep -Eo "dpt:443" |awk -F ":" '{printf $2}') 6 | 7 | if [ "$HTTP_ENABLE" == "" ] ; then 8 | HTTP_ENABLE="--" 9 | fi 10 | if [ "$HTTPS_ENABLE" == "" ] ; then 11 | HTTPS_ENABLE="--" 12 | fi 13 | ./ctx/proxy "proxy_disable" "Disable" "HTTP\n\tConfig enabled: ${HTTP}\n\tEnabled Iptables Port: ${HTTP_ENABLE}\nHTTPS\n\tConfig enabled: ${HTTPS}\n\tEnabled Iptables Port: ${HTTPS_ENABLE}\n\n" >/dev/null 14 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/swports_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | IFS=$'\n' 4 | PORTS=$(swconfig dev switch0 show | grep link | grep -oE "port:[[:digit:]][[:space:]]link:(up|down)([[:space:]]speed:[[:digit:]]+|$)") 5 | for port in $PORTS 6 | do 7 | id=$(echo $port | grep -oE "port:[[:digit:]]" | cut -d ':' -f 2) 8 | if [ "$id" == "0" ] 9 | then 10 | echo "CPU-0" 11 | elif [ "$id" == "1" ] 12 | then 13 | echo "LAN 1" 14 | elif [ "$id" == "2" ] 15 | then 16 | echo "LAN 2" 17 | elif [ "$id" == "3" ] 18 | then 19 | echo "LAN 3" 20 | elif [ "$id" == "4" ] 21 | then 22 | echo "LAN 4" 23 | elif [ "$id" == "5" ] 24 | then 25 | echo "WAN" 26 | elif [ "$id" == "6" ] 27 | then 28 | echo "CPU-1" 29 | fi 30 | echo -en "${port// /\\n}\n\n" 31 | done 32 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/chromego: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | action="$1" 4 | user="$2" 5 | word="$3" 6 | field="$4" 7 | 8 | if [ "$action" = "" ] || [ "$user" = "" ] || [ "$word" = "" ] || [ "$field" = "" ]; then 9 | echo "1|Missing parameters!!" 10 | return 1 11 | fi 12 | 13 | if [ "$action" == "add" ]; then 14 | uci -q add_list chromego.$user.$field="${word}" 15 | uci -q commit chromego &> /dev/null 16 | /etc/init.d/uhttpd restart &> /dev/null 17 | echo "1|Added ${word} in ${field} to user ${user}." 18 | exit 0 19 | elif [ "$action" == "del" ]; then 20 | uci -q del_list chromego.$user.$field="${word}" 21 | uci -q commit chromego &> /dev/null 22 | /etc/init.d/uhttpd restart &> /dev/null 23 | echo "1|Removed ${word} in ${field} to user ${user}." 24 | exit 0 25 | fi 26 | -------------------------------------------------------------------------------- /sbin/telekeyboard: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | 12 | command_new=${command//_/\\_} 13 | 14 | firewall=$(uci -q show firewall |grep "@rule" | grep name |grep -oE "\[[[:digit:]]+\].name='([[:graph:]]|[[:blank:]])+'" | awk -F ".name=" '{gsub(/[\047]|\[|\]/,"");print "[ {\"callback_data\": \""$1 "\" ,\"text\" : \"" $2 "\"} ],"}') 15 | rules=${firewall:0:$((${#firewall}-1))} 16 | 17 | keyboard='{"inline_keyboard": ['$rules'] }' 18 | 19 | echo $keyboard 20 | 21 | #curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=Choose one:" 22 | -------------------------------------------------------------------------------- /etc/init.d/lanports: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # Copyright (C) 2006-2011 OpenWrt.org 3 | 4 | START=95 5 | STOP=15 6 | 7 | USE_PROCD=1 8 | PROG=/sbin/lanports 9 | CONFIGURATION=tbot 10 | 11 | start_service () { 12 | PID=$(pgrep -f ${PROG}) 13 | if [ -z "$PID" ] ; then 14 | config_load "${CONFIGURATION}" 15 | 16 | procd_open_instance 17 | procd_set_param command /bin/sh "$PROG" 18 | procd_set_param file /etc/config/telegramopenwrt 19 | procd_set_param stdout 1 20 | procd_set_param stderr 1 21 | procd_close_instance 22 | fi 23 | } 24 | 25 | stop_service() { 26 | pids=$(pgrep -f ${PROG} | xargs echo) 27 | for i in $pids; do extra_pids="${extra_pids} $(pgrep -P $i | xargs echo)"; done; 28 | kill $(echo "${extra_pids} ${pids}") 2> /dev/null 29 | } 30 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/proxy: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | msg="$2" 12 | txt="$3" 13 | 14 | HTTP='[ {"callback_data": "'${command}'|0^'${msg}' HTTP" ,"text" : "'${msg}' HTTP"} ]' 15 | HTTPS='[ {"callback_data": "'${command}'|1^'${msg}' HTTPS" ,"text" : "'${msg}' HTTPS"} ]' 16 | HTTP_and_HTTPS='[ {"callback_data": "'${command}'|2^'${msg}' HTTP and HTTPS" ,"text" : "'${msg}' HTTP and HTTPS"} ]' 17 | 18 | keyboard='{"inline_keyboard": ['$HTTP','$HTTPS','$HTTP_and_HTTPS'] }' 19 | text=$(echo -en $txt) 20 | 21 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 22 | -------------------------------------------------------------------------------- /etc/init.d/hosts_scan: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # Copyright (C) 2006-2011 OpenWrt.org 3 | 4 | START=95 5 | STOP=15 6 | 7 | USE_PROCD=1 8 | PROG=/sbin/host_scan 9 | CONFIGURATION=telegramopenwrt 10 | 11 | start_service () { 12 | PID=$(pgrep -f ${PROG}) 13 | if [ -z "$PID" ] ; then 14 | config_load "${CONFIGURATION}" 15 | 16 | procd_open_instance 17 | procd_set_param command /bin/sh "$PROG" 18 | procd_set_param file /etc/config/telegramopenwrt 19 | procd_set_param stdout 1 20 | procd_set_param stderr 1 21 | procd_close_instance 22 | fi 23 | } 24 | 25 | stop_service() { 26 | pids=$(pgrep -f ${PROG} | xargs echo) 27 | for i in $pids; do extra_pids="${extra_pids} $(pgrep -P $i | xargs echo)"; done; 28 | kill $(echo "${extra_pids} ${pids}") 2> /dev/null 29 | } 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Please make sure that the issue subject starts with `: ` 11 | 12 | Also make sure that the package is maintained in this repository and not in base which should be submitted at https://bugs.openwrt.org or in the LuCI repository which should be submitted at https://github.com/openwrt/luci/issues. 13 | 14 | Issues related to releases below 18.06 and forks are not supported or maintained and will be closed. 15 | 16 | # Issue template (remove lines from top till here) 17 | 18 | Maintainer: @\ (find it by checking history of the package Makefile) 19 | Environment: (put here arch, model, OpenWrt version) 20 | 21 | Description: 22 | 23 | ``` 24 | Formating code blocks by wrapping them with pairs of ``` 25 | ``` 26 | -------------------------------------------------------------------------------- /etc/init.d/telegram_bot: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # Copyright (C) 2006-2011 OpenWrt.org 3 | 4 | START=95 5 | STOP=15 6 | 7 | USE_PROCD=1 8 | PROG=/sbin/telegram_bot 9 | CONFIGURATION=telegramopenwrt 10 | 11 | start_service () { 12 | PID=$(pgrep -f ${PROG}) 13 | if [ -z "$PID" ] ; then 14 | config_load "${CONFIGURATION}" 15 | 16 | procd_open_instance 17 | procd_set_param command /bin/sh "$PROG" 18 | procd_set_param file /etc/config/telegramopenwrt 19 | procd_set_param stdout 1 20 | procd_set_param stderr 1 21 | procd_close_instance 22 | fi 23 | } 24 | 25 | stop_service() { 26 | pids=$(pgrep -f ${PROG} | xargs echo) 27 | for i in $pids; do extra_pids="${extra_pids} $(pgrep -P $i | xargs echo)"; done; 28 | kill $(echo "${extra_pids} ${pids}") 2> /dev/null 29 | } 30 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/get_mac: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PUREMAC="${1:0:8}" 4 | LMAC=$(echo $PUREMAC | awk '{ print toupper($0) }') 5 | MAC=${LMAC//:/} 6 | 7 | maclist=$(curl -s -k -L -X GET -H "Content-Type: application/json; charset=utf-8" \ 8 | -H "Origin: https://regauth.standards.ieee.org" \ 9 | -H "Referer: https://regauth.standards.ieee.org/standards-ra-web/pub/view.html" \ 10 | "https://services13.ieee.org/RST/standards-ra-web/rest/assignments/?registry=MA-L&sortby=organization&sortorder=asc&text=${MAC}") 11 | 12 | IDS=${MAC//-/} 13 | HEX=$(jsonfilter -s "$maclist" -e $.data.hits[*].assignmentNumberHex) 14 | 15 | i=0 16 | for hexs in $HEX 17 | do 18 | if [ "$hexs" == "$IDS" ]; then 19 | name=$(jsonfilter -s "$maclist" -e $.data.hits[$i].organizationName) 20 | #echo "Identifier: $LMAC" 21 | echo "Organization: $name" 22 | exit 23 | fi 24 | i=$((i+1)) 25 | done 26 | echo "Organization: Not Found!" 27 | -------------------------------------------------------------------------------- /sbin/hosts_scan: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | mkdir -p /usr/lib/telegramopenwrt/arps &>/dev/null 4 | 5 | (while [ true ] 6 | do 7 | 8 | for IP in $(cat /proc/net/arp | grep "192.168.250" | awk '{print $1}') 9 | do 10 | LAST="NULL" 11 | ping $IP -w 1 -q &>/dev/null 12 | [ $? == 0 ] && RESULT="UP" || RESULT="DOWN" 13 | if [ -e /usr/lib/telegramopenwrt/arps/$IP ]; then 14 | LAST=$(cat /usr/lib/telegramopenwrt/arps/$IP) 15 | fi 16 | if [ "${LAST}" != "${RESULT}" ];then 17 | name=$(cat /tmp/dhcp.leases | grep " ${IP} " | awk '{print $4}') 18 | [ "${name}" == "" ] && name=$(cat /tmp/hosts/dhcp.cfg01411c | grep "^${IP}" | awk '{print $2}') 19 | date=$(date "+%d/%m/%Y %H:%M") 20 | telegram=$(echo "*Device:* ${name}"$'\n'"*Data:* ${date}"$'\n'"*IP:* ${IP}"$'\n'"*State:* ${RESULT}") 21 | /sbin/telebot "$telegram" 22 | fi 23 | echo -en "${RESULT}" > /usr/lib/telegramopenwrt/arps/$IP 24 | done 25 | sleep 300 26 | done)& 27 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/cam_shot: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | id="$1" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | curl -s -k -X POST $api/sendChatAction -d "chat_id=$my_chat_id" -d "action=upload_photo" | logger -t "telegram_bot[$$]" -p daemon.info 11 | 12 | curl -s -k -H "Authorization:Basic ${header_auth}" "http://${ipaddr}/snapshot.cgi?user=${user}&pwd=${passwd}" -o /tmp/pic.jpg -D /tmp/header 13 | 14 | DATE=$(cat /tmp/header |grep Date | sed -e 's/Date: //') 15 | NEW_DATE=$(date "+%d/%m/%Y %T %Z" -d "@$(($(date -u +%s -D "%a, %e %b %Y %T" -d "${DATE}")))") 16 | 17 | curl -s -k -X POST $api/sendPhoto -H "Content-Type: multipart/form-data" -F "chat_id=$my_chat_id" -F "photo=@/tmp/pic.jpg" -F "reply_to_message_id=$id" -F "caption=Date: $NEW_DATE" | logger -t "telegram_bot[$$]" -p daemon.info 18 | -------------------------------------------------------------------------------- /etc/config/telegramopenwrt: -------------------------------------------------------------------------------- 1 | config telegramopenwrt 'global' 2 | option key '[PUT YOUR BOT KEY HERE]' 3 | option url 'https://api.telegram.org/bot' 4 | option my_chat_id '[PUT ID OF THE CHAT THAT YOU START WITH BOT]' 5 | option timeout '60' 6 | option ignored_macaddrs_file '/etc/telegramopenwrt/macaddr.ignore' 7 | 8 | config telegramopenwrt 'ipcam' 9 | option header_auth '[HEADER AUTH]' 10 | option ipaddr '[CAMERA IP OR HOSTNAME]' 11 | option user '[CAMERA USER]' 12 | option passwd '[CAMERA PASSWD]' 13 | 14 | config telegramopenwrt 'smtp' 15 | option from '[MAIL FROM]' 16 | option to '[MAIL TO]' 17 | 18 | config telegramopenwrt 'television' 19 | option ipaddr '[TV IP]' 20 | option sender_name '[Sender Name]' 21 | option sender_number '[Sender Number]' 22 | option receiver_name '[Receiver Name]' 23 | option receiver_number '[Receiver Number]' 24 | 25 | config telegramopenwrt 'proxy' 26 | option http false 27 | option https false 28 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/light_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | lights=$(for i in $(avahi-browse -t -d local _light._tcp |grep -Eo "lgt[0-9]+") ;\ 11 | do \ 12 | content=$(avahi-resolve -n $i.local | awk 'system("curl -s "$2"/state")');\ 13 | name=$(jsonfilter -s "$content" -e $.name);\ 14 | state=$(jsonfilter -s "$content" -e $.state); \ 15 | echo -en "[{\"callback_data\": \"light_control|${i}.local^${state}\" , \"text\": \"${name} (${state})\"}]," ; done ) 16 | 17 | rules=${lights:0:$((${#lights}-1))} 18 | keyboard='{"inline_keyboard": ['$rules']}' 19 | 20 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=Choose a light to switch:" 21 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/fw_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | text="$2" 12 | 13 | firewall=$(uci -q show firewall |grep "@rule" | grep name |grep -oE "\[[[:digit:]]+\].name='([[:graph:]]|[[:blank:]])+'" | awk -F ".name=" '{gsub(/[\047]|\[|\]/,"");printf "[ {\"callback_data\": \"##CMD##|" $1 "\^" $2 "\" ,\"text\" : \"" $2 ;system("[ \"$(uci -q -q get firewall.@rule["$1"].enabled)\" == \"0\" ] && echo -en \" (Disabled)\" || echo -en \" (Enabled)\"") ; print "\"} ],"}') 14 | rules=${firewall:0:$((${#firewall}-1))} 15 | rls=${rules//##CMD##/$command} 16 | keyboard='{"inline_keyboard": ['$rls'] }' 17 | 18 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 19 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ping_udp: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Create a UDP packet to puncture a hole through a NAT firewall of your ISP 3 | # Useful with OpenVPN in UDP mode 4 | # Needs nping to create raw IP packet (cannot use nc/ncat because local socket is already used) 5 | # Use DDNS, STUN or chekip service to find your current public NAT IP 6 | 7 | SPORT="$1" 8 | DADDR="$2" 9 | DPORT="$3" 10 | 11 | if echo "$SPORT"|grep -q -E -e '^[0-9]{1,5}$'; then 12 | if echo "$DPORT"|grep -q -E -e '^[0-9]{1,5}$'; then 13 | if echo "$DADDR"|grep -q -E -e '^[0-9a-zA-Z][0-9a-zA-Z\.\-]*\.[0-9a-zA-Z\.\-]*[0-9a-zA-Z]$'; then 14 | if [ -x /usr/bin/nping ]; then 15 | nping --udp -N --send-ip -v4 -g "${SPORT}" -p "${DPORT}" -c 1 "${DADDR}"|grep SENT 16 | exit 0 17 | else 18 | echo "NPING not installed. Use '*opkg install nping*'." 19 | exit 1 20 | fi 21 | fi 22 | fi 23 | fi 24 | 25 | echo "Wrong parameters. Use '*/ping_udp *'." 26 | exit 1 27 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/actions/cam_mv: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | num="$1" 4 | 5 | ipaddr=$(uci -q get telegramopenwrt.ipcam.ipaddr) 6 | header_auth=$(uci -q get telegramopenwrt.ipcam.header_auth) 7 | user=$(uci -q get telegramopenwrt.ipcam.user) 8 | passwd=$(uci -q get telegramopenwrt.ipcam.passwd) 9 | 10 | # command: 11 | # 1 -> para camera 12 | # 2 -> cima 13 | # 0 -> baixo 14 | # 4 -> direita 15 | # 6 -> esquerda 16 | # 92 -> cima direita 17 | # 93 -> cima esquerda 18 | # 91 -> baixo esquerda 19 | # 90 -> baixo direita 20 | # 25 -> movimenta todos lados. 21 | 22 | if [ "$num" == "-1" ];then 23 | echo "1|Camera new position OK." 24 | return 25 | fi 26 | 27 | curl -s -k -H "Authorization:Basic ${header_auth}" "http://${ipaddr}/decoder_control.cgi?command=${num}&user=${user}&pwd=${passwd}" &>/dev/null 28 | 29 | sleep 1 30 | 31 | mv=$(curl -s -k -H "Authorization:Basic ${header_auth}" "http://${ipaddr}/decoder_control.cgi?command=1&user=${user}&pwd=${passwd}") 32 | 33 | echo "0|$mv" 34 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/fwr_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | text="$2" 12 | 13 | firewall=$(uci -q show firewall |grep "@redirect" | grep name |grep -oE "\[[[:digit:]]+\].name='([[:graph:]]|[[:blank:]])+'" | awk -F ".name=" '{gsub(/[\047]|\[|\]/,"");printf "[ {\"callback_data\": \"##CMD##|" $1 "\^" $2 "\" ,\"text\" : \"" $2 ;system("[ \"$(uci -q -q get firewall.@redirect["$1"].enabled)\" == \"0\" ] && echo -en \" (Disabled)\" || echo -en \" (Enabled)\"") ; print "\"} ],"}') 14 | rules=${firewall:0:$((${#firewall}-1))} 15 | rls=${rules//##CMD##/$command} 16 | keyboard='{"inline_keyboard": ['$rls'] }' 17 | 18 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 19 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/cam_movie: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | id="$1" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | curl -s -k -X POST $api/sendChatAction -d "chat_id=$my_chat_id" -d "action=record_video" | logger -t "telegram_bot[$$]" -p daemon.info 11 | 12 | curl -s -k -H "Authorization:Basic ${header_auth}" "http://${ipaddr}/videostream.asf?user=${user}&pwd=${passwd}" -m 25 -o /tmp/movie.asf -D /tmp/header 13 | 14 | curl -s -k -X POST $api/sendChatAction -d "chat_id=$my_chat_id" -d "action=record_video" | logger -t "telegram_bot[$$]" -p daemon.info 15 | 16 | DETAILS=$(cat /tmp/header | grep "Date\|Server") 17 | 18 | curl -s -k -X POST $api/sendVideo -H "Content-Type: multipart/form-data" -F "chat_id=$my_chat_id" -F "video=@/tmp/movie.asf" -F "reply_to_message_id=$id" -F "caption=$DETAILS" | logger -t "telegram_bot[$$]" -p daemon.info 19 | rm -f /tmp/movie.asf 20 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/cam_kbd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | 11 | keyboard='{"inline_keyboard": 12 | [[ {"callback_data": "cam_mv|93","text": "\u2196\ufe0f" }, {"callback_data": "cam_mv|2","text": "\u2b06\ufe0f" }, {"callback_data": "cam_mv|92","text": "\u2197\ufe0f" } ], 13 | [ {"callback_data": "cam_mv|6","text": "\u2b05\ufe0f" }, {"callback_data": "cam_mv|-1","text": "\u23f9" }, {"callback_data": "cam_mv|4","text": "\u27a1\ufe0f"} ], 14 | [ {"callback_data": "cam_mv|91","text": "\u2199\ufe0f" }, {"callback_data": "cam_mv|0","text": "\u2b07\ufe0f" }, {"callback_data": "cam_mv|90","text": "\u2198\ufe0f"} ]]}' 15 | 16 | text="Now move the camera" 17 | 18 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 19 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/wifi_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | text="$2" 12 | 13 | wireless=$(uci -q show wireless |grep "default_radio" | grep ssid |grep -oE "[[:digit:]]+.ssid='([[:graph:]]|[[:blank:]])+'" | awk -F ".ssid=" '{gsub(/[\047]|\[|\]/,"");printf "[ {\"callback_data\": \"##CMD##|" $1 "\^" $2 "\" ,\"text\" : \"" $2 ;system("[ \"$(uci -q -q get wireless.radio"$1".__toggle)\" == \"Disable\" ] && echo -en \" (Disabled)\" || echo -en \" (Enabled)\"") ; print "\"} ],"}') 14 | rules=${wireless:0:$((${#wireless}-1))} 15 | rls=${rules//##CMD##/$command} 16 | keyboard='{"inline_keyboard": ['$rls'] }' 17 | 18 | echo "$keyboard" 19 | 20 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 21 | -------------------------------------------------------------------------------- /sbin/camkeyboard: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | #"text":"\u27a1\ufe0f" > 11 | #"text":"\u2b05\ufe0f" < 12 | #"text":"\u2b06\ufe0f" ^ 13 | #"text":"\u2b07\ufe0f" D^ 14 | #"text":"\u2197\ufe0f" U> 15 | #"text":"\u2198\ufe0f" D> 16 | #"text":"\u2199\ufe0f" D< 17 | #"text":"\u2196\ufe0f" U< 18 | 19 | # command: 20 | # 1 -> para camera 21 | # 2 -> cima 22 | # 0 -> baixo 23 | # 4 -> direita 24 | # 6 -> esquerda 25 | # 92 -> cima direita 26 | # 93 -> cima esquerda 27 | # 91 -> baixo esquerda 28 | # 90 -> baixo direita 29 | # 25 -> movimenta todos lados. 30 | 31 | keyboard='{"keyboard": [["\u2196\ufe0f","\u2b06\ufe0f","\u2197\ufe0f"],["\u2b05\ufe0f","O","\u27a1\ufe0f"],["\u2199\ufe0f","\u2b07\ufe0f", "\u2198\ufe0f"]],"one_time_keyboard": true}' 32 | 33 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=Now move the camera, to stop send /cam_mv" 34 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/cam_vdo: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | id="$1" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | 11 | curl -s -k -X POST $api/sendChatAction -d "chat_id=$my_chat_id" -d "action=record_video" | logger -t "telegram_bot[$$]" -p daemon.info 12 | 13 | curl -s -k -H "Authorization:Basic ${header_auth}" "http://${ipaddr}/videostream.asf?user=${user}&pwd=${passwd}" -m 25 -o /tmp/movie.asf -D /tmp/header 14 | 15 | curl -s -k -X POST $api/sendChatAction -d "chat_id=$my_chat_id" -d "action=record_video" | logger -t "telegram_bot[$$]" -p daemon.info 16 | 17 | DATE=$(cat /tmp/header |grep Date | sed -e 's/Date: //') 18 | NEW_DATE=$(date "+%d/%m/%Y %T %Z" -d "@$(($(date -u +%s -D "%a, %e %b %Y %T" -d "${DATE}")))") 19 | 20 | curl -s -k -X POST $api/sendVideo -H "Content-Type: multipart/form-data" -F "chat_id=$my_chat_id" -F "video=@/tmp/movie.mp4" -F "reply_to_message_id=$id" -F "caption=Date: $NEW_DATE" | logger -t "telegram_bot[$$]" -p daemon.info 21 | 22 | rm -f /tmp/movie.asf 23 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/wll_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for wifi in wlan0 wlan1 4 | do 5 | if [ "${wifi}" == "wlan0" ]; then 6 | echo -en "--------------*${wifi} - 2.4 Ghz*--------------------\n" 7 | else 8 | echo -en "--------------*${wifi} - 5 Ghz*----------------------\n" 9 | fi 10 | macaddr=$(iwinfo ${wifi} assoclist |grep -oE "([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}" | awk '{printf $0 " "}') 11 | for lease in ${macaddr} 12 | do 13 | line=$(cat /tmp/dhcp.leases | grep -i ${lease}) 14 | if [ $? == 0 ]; then 15 | echo "${line}" | awk '{gsub( "*","\\*" ); gsub( "_","\\_" ); printf "Device: " $4 "\nIP: " $3 "\nMac: " toupper($2) "\nState: ";system("./get_ping "$4" 1");printf "\n"}' 16 | else 17 | cat /proc/net/arp | grep -i ${lease} | awk '{gsub( "_","\\_" ); printf "IP: " $1 "\nMac: " toupper($4) "\nState: ";system("./get_ping "$1" 1");printf "\n"}' 18 | fi 19 | ./get_mac "${lease}" 20 | echo -e "=+=+=+=+=+=+=+=+=\n" 21 | done 22 | #echo -en "-----------------------------------------------------------\n" 23 | done 24 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/ctx/chromego: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH="/usr/bin:/usr/sbin:/bin:/sbin" 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | 10 | command="$1" 11 | action="$2" 12 | user="$3" 13 | word="$4" 14 | 15 | WORD='[ {"callback_data": "'${command}'|'${action}'^'${user}'^'${word}'^by_word" ,"text" : "'${action}' word '${word}' in by_word"} ]' 16 | URL='[ {"callback_data": "'${command}'|'${action}'^'${user}'^'${word}'^by_url" ,"text" : "'${action}' word '${word}' in by_url"} ]' 17 | TITLE='[ {"callback_data": "'${command}'|'${action}'^'${user}'^'${word}'^by_title" ,"text" : "'${action}' word '${word}' in by_title"} ]' 18 | AUTHOR='[ {"callback_data": "'${command}'|'${action}'^'${user}'^'${word}'^by_author" ,"text" : "'${action}' word '${word}' in by_author"} ]' 19 | GENRE='[ {"callback_data": "'${command}'|'${action}'^'${user}'^'${word}'^by_genre" ,"text" : "'${action}' word '${word}' in by_genre"} ]' 20 | 21 | 22 | keyboard='{"inline_keyboard": ['$WORD','$URL','$TITLE', '$AUTHOR', '$GENRE'] }' 23 | text=$(echo -en "Choose a action") 24 | 25 | curl -k -s -X POST -H "Charset: UTF-8" $api/sendMessage -d chat_id=$my_chat_id -d "reply_markup=${keyboard}" -d "text=${text}" 26 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/fw_add: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NAME="$1" 4 | TIME="$2" 5 | 6 | if [ "$NAME" != "" ]; then 7 | IDX=$(uci -q show dhcp | grep "$NAME" |grep -oE "\[(\d+)\]") 8 | if [ "$IDX" != "" ];then 9 | MAC=$(uci -q get dhcp.@host$IDX.mac) 10 | if [ "$MAC" != "" ]; then 11 | uci -q add firewall rule 12 | uci -q set firewall.@rule[-1].src='lan' 13 | uci -q set firewall.@rule[-1].dest='wan' 14 | uci -q set firewall.@rule[-1].proto='all' 15 | uci -q set firewall.@rule[-1].target='REJECT' 16 | uci -q set firewall.@rule[-1].src_mac="$MAC" 17 | if [ "$TIME" == "time" ]; then 18 | uci -q set firewall.@rule[-1].name="Bloqueio Time Telegram ${NAME}" 19 | uci -q set firewall.@rule[-1].start_time='23:00' 20 | uci -q set firewall.@rule[-1].stop_time='08:00' 21 | uci -q set firewall.@rule[-1].weekdays='mon tue wed thu fri sat sun' 22 | else 23 | uci -q set firewall.@rule[-1].name="Bloqueio Telegram ${NAME}" 24 | fi 25 | uci -q reorder firewall.@rule[-1]=1 26 | uci -q commit firewall &> /dev/null 27 | /etc/init.d/firewall restart &> /dev/null 28 | if [ "$TIME" == "time" ]; then 29 | echo "New rule between 23:00 and 8:00 for ${NAME} created successfully !" 30 | else 31 | echo "New rule for ${NAME} created successfully !" 32 | fi 33 | exit 0 34 | fi 35 | fi 36 | fi 37 | echo "Error creating new rule ${NAME} !" 38 | exit 1 39 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/chromego_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | old=$IFS 4 | IFS=$'\n' 5 | TOTAL=0 6 | 7 | echo "\`\`\`" 8 | echo "Chromego Permissions" 9 | 10 | for user in $(uci -q show chromego | grep "=chromego" | awk -F "." '{print $2}' | awk -F "=" '{print $1}') 11 | do 12 | echo -en "User: $user\n" 13 | echo -en "\tPermissions by_word\n" 14 | IFS=$'^' 15 | for word in $(uci -q -d "^" get chromego.$user.by_word) 16 | do 17 | v=$(echo "$word" | awk '{ gsub(/^[\047]|[\047]$/,""); print }') 18 | echo -en "\t\t\t$v\n" 19 | done 20 | echo -en "\tPermissions by_author\n" 21 | for word in $(uci -q -d "^" get chromego.$user.by_author) 22 | do 23 | v=$(echo "$word" | awk '{ gsub(/^[\047]|[\047]$/,""); print }') 24 | echo -en "\t\t\t$v\n" 25 | done 26 | echo -en "\tPermissions by_title\n" 27 | for word in $(uci -q -d "^" get chromego.$user.by_title) 28 | do 29 | v=$(echo "$word" | awk '{ gsub(/^[\047]|[\047]$/,""); print }') 30 | echo -en "\t\t\t$v\n" 31 | done 32 | echo -en "\tPermissions by_url\n" 33 | for word in $(uci -q -d "^" get chromego.$user.by_url) 34 | do 35 | v=$(echo "$word" | awk '{ gsub(/^[\047]|[\047]$/,""); print }') 36 | echo -en "\t\t\t$v\n" 37 | done 38 | echo -en "\tPermissions by_genre\n" 39 | for word in $(uci -q -d "^" get chromego.$user.by_genre) 40 | do 41 | v=$(echo "$word" | awk '{ gsub(/^[\047]|[\047]$/,""); print }') 42 | echo -en "\t\t\t$v\n" 43 | done 44 | done 45 | echo "\`\`\`" 46 | IFS=$old 47 | 48 | -------------------------------------------------------------------------------- /sbin/telegram_sender: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | PATH='/usr/bin:/usr/sbin:/bin:/sbin' 4 | 5 | url=$(uci -q get telegramopenwrt.global.url) 6 | key=$(uci -q get telegramopenwrt.global.key) 7 | api="$url$key" 8 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 9 | items=$1 10 | 11 | function log(){ 12 | TEXT=$@ 13 | ok=$(jsonfilter -s "${TEXT}" -e "$.ok") 14 | message_id=$(jsonfilter -s "${TEXT}" -e "$.result.message_id") 15 | from=$(jsonfilter -s "${TEXT}" -e "$.result.from") 16 | chat=$(jsonfilter -s "${TEXT}" -e "$.result.chat") 17 | date=$(jsonfilter -s "${TEXT}" -e "$.result.date") 18 | msg=$(echo -e $(jsonfilter -s "${TEXT}" -e "$.result.text")) 19 | entities=$(jsonfilter -s "${TEXT}" -e "$.result.entities[0]") 20 | echo "{\"ok\": ${ok},\"result\":{\"message_id\": ${message_id}, \"from\":${from}, \"chat\":${chat},\"date\": \"${date}\",\"text\": \"${msg:0:100}\",\"entities\": [${entities}]}}" | logger -t "telegram_bot[$$]" -p daemon.info 21 | } 22 | 23 | IFS=$'\n' 24 | count=0 25 | for item in $items 26 | do 27 | send=0 28 | count=$((count+${#item}+1)) 29 | if [ "$count" -eq "4096" ];then 30 | send=1 31 | elif [ "$count" -gt "4096" ];then 32 | send=2 33 | fi 34 | if [ "$send" -ne "2" ]; then 35 | full=${full}${item}$'\n' 36 | fi 37 | 38 | if [ "$send" -eq "1" ]; then 39 | response=$(curl -k -s -X POST $api/sendMessage -d chat_id=$my_chat_id -d parse_mode=Markdown --data-urlencode text="$full") 40 | log $response 41 | full="" 42 | count=0 43 | elif [ "$send" -eq "2" ]; then 44 | response=$(curl -k -s -X POST $api/sendMessage -d chat_id=$my_chat_id -d parse_mode=Markdown --data-urlencode text="$full") 45 | log $response 46 | full=${item}$'\n' 47 | count=${#item} 48 | fi 49 | done 50 | 51 | if [ $count -gt "0" ];then 52 | response=$(curl -k -s -X POST $api/sendMessage -d chat_id=$my_chat_id -d parse_mode=Markdown --data-urlencode text="$full") 53 | log $response 54 | fi 55 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/msg_tv: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | tvip=$(uci -q get telegramopenwrt.television.ipaddr) 4 | sender_name=$(uci -q get telegramopenwrt.television.sender_name) 5 | sender_number=$(uci -q get telegramopenwrt.television.sender_number) 6 | receiver_name=$(uci -q get telegramopenwrt.television.receiver_name) 7 | receiver_number=$(uci -q get telegramopenwrt.television.receiver_number) 8 | 9 | DATE=$(/bin/date +"%Y-%m-%d" | /usr/bin/awk '{printf $1}') 10 | TIME=$(/bin/date +"%T" | /usr/bin/awk '{printf $1}') 11 | 12 | MYMSG="$*" 13 | 14 | if [ $(ping ${tvip} -c 1 >/dev/null; echo -n $?) == 1 ];then 15 | echo "Television is Offline." 16 | else 17 | MSG=" 18 | 19 | 20 | 21 | 1 22 | text/xml 23 | 24 | <Category>SMS</Category> 25 | <DisplayType>Maximum</DisplayType> 26 | <ReceiveTime> 27 | <Date>${DATE}</Date> 28 | <Time>${TIME}</Time> 29 | </ReceiveTime> 30 | <Receiver> 31 | <Number>${receiver_number}</Number> 32 | <Name>${receiver_name}</Name> 33 | </Receiver> 34 | <Sender> 35 | <Number>${sender_number}</Number> 36 | <Name>${sender_name}</Name> 37 | </Sender> 38 | <Body>${MYMSG}</Body> 39 | 40 | 41 | 42 | " 43 | 44 | echo "Sending ${MYMSG} Message to TV ${tvip} ..." 45 | echo ${MSG} | curl -s -X POST -H 'Content-Type: text/xml' -H 'SOAPACTION: "urn:samsung.com:service:MessageBoxService:1#AddMessage"' -c 'text/xml' http://${tvip}:52235/PMR/control/MessageBoxService -d@- >/dev/null 46 | fi 47 | -------------------------------------------------------------------------------- /sbin/lanports: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | export PATH='/usr/bin:/usr/sbin:/bin:/sbin' 4 | 5 | has_offer=0 6 | count=0 7 | switch=$(swconfig list | awk '{printf $4}') 8 | 9 | (logread -f |while read line; do 10 | echo "${line}" | grep -q "$switch: Port" 11 | if [ $? == 0 ]; then 12 | ports=$(echo "${line}" | grep -oE "Port ([0-9]+) is (up|down)") 13 | date=$(echo "${line}" | grep -oE "^[a-zA-Z]+[[:space:]]+[a-zA-z]+[[:space:]]+[0-9]+[[:space:]]+[0-9:]+ [0-9]+") 14 | pnum=$(echo "${ports}" | cut -d ' ' -f 2) 15 | state=$(echo "${ports}" | cut -d ' ' -f 4) 16 | telegram=$(echo "*Port:* ${pnum}"$'\n'"*Data:* ${date}"$'\n'"*State:* ${state}") 17 | /sbin/telebot "$telegram" 18 | fi 19 | echo "${line}" | grep -q "DHCPOFFER" 20 | if [ $? == 0 ]; then 21 | has_offer=1 22 | count=4 23 | fi 24 | 25 | echo "${line}" | grep -q "DHCPACK" 26 | if [ $? == 0 ] && [ $has_offer == 1 ]; then 27 | dados=$(echo "${line}" | grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} \w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2} .*") 28 | if [ "${dados}" == "" ];then 29 | dados=$(echo "${line}" | grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} \w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2}") 30 | fi 31 | date=$(echo "${line}" | grep -oE "^[a-zA-Z]+[[:space:]]+[a-zA-z]+[[:space:]]+[0-9]+[[:space:]]+[0-9:]+ [0-9]+") 32 | ip=$(echo "${dados}" | cut -d ' ' -f 1) 33 | macaddr=$(echo "${dados}" | cut -d ' ' -f 2) 34 | name=$(echo "${dados}" | cut -d ' ' -f 3 | awk '{gsub("*","\*"); gsub( "_","\_" ); printf $0 }') 35 | if [ "${name}" == "" ];then 36 | name="\*" 37 | fi 38 | ignored_macaddrs_file=$(uci -q get telegramopenwrt.global.ignored_macaddrs_file) 39 | if ! grep -q "$macaddr" $ignored_macaddrs_file; then 40 | telegram=$(echo "*Device:* ${name}"$'\n'"*Data:* ${date}"$'\n'"*IP:* ${ip}"$'\n'"*MACADDR:* ${macaddr}") 41 | /sbin/telebot "$telegram" 42 | has_offer=0 43 | else 44 | echo "Ignored macaddr found in ignore list" 45 | fi 46 | fi 47 | if [ $count == 0 ]; then 48 | has_offer=0 49 | else 50 | count=$((count-1)) 51 | fi 52 | done)& 53 | -------------------------------------------------------------------------------- /sbin/proxy: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | 3 | START=95 4 | STOP=15 5 | 6 | PROXYIP=192.168.250.2 7 | NETWORK=192.168.250.0/24 8 | CLIENTIFACE=br-lan 9 | FWMARK=2 10 | 11 | HTTP=$(uci -q get telegramopenwrt.proxy.http | awk '{printf $0}') 12 | HTTPS=$(uci -q get telegramopenwrt.proxy.https | awk '{printf $0}') 13 | EXCEPTIONS=$(uci -q get telegramopenwrt.proxy.exceptions | awk '{printf $0}') 14 | 15 | start() { 16 | if [ "$HTTP" == "true" ]; then 17 | iptables -t mangle -A PREROUTING -i $CLIENTIFACE ! -d $NETWORK -p tcp --dport 80 -j MARK --set-mark $FWMARK &>/dev/null 18 | iptables -t mangle -I PREROUTING -p tcp --dport 80 -s $PROXYIP -j ACCEPT &>/dev/null 19 | fi 20 | if [ "$HTTPS" == "true" ]; then 21 | iptables -t mangle -A PREROUTING -i $CLIENTIFACE ! -d $NETWORK -p tcp --dport 443 -j MARK --set-mark $FWMARK &>/dev/null 22 | iptables -t mangle -I PREROUTING -p tcp --dport 443 -s $PROXYIP -j ACCEPT &>/dev/null 23 | fi 24 | if [[ "$HTTP" == "true" || "$HTTPS" == "true" ]];then 25 | HAS_PROXY=$(cat /etc/iproute2/rt_tables &>/dev/null| grep -c proxy) 26 | if [ $HAS_PROXY == 0 ]; then 27 | echo "201 proxy" >> /etc/iproute2/rt_tables 28 | fi 29 | # permit Squid box out to the Internet 30 | for except in ${EXCEPTIONS} 31 | do 32 | if [ "$HTTP" == "true" ]; then 33 | iptables -t mangle -I PREROUTING -p tcp --dport 80 -s $except -j ACCEPT &>/dev/null 34 | fi 35 | if [ "$HTTPS" == "true" ]; then 36 | iptables -t mangle -I PREROUTING -p tcp --dport 443 -s $except -j ACCEPT &>/dev/null 37 | fi 38 | done 39 | iptables -t mangle -A PREROUTING -m mark --mark $FWMARK -j ACCEPT &>/dev/null 40 | iptables -t filter -A FORWARD -i $CLIENTIFACE -o $CLIENTIFACE -p tcp --dport 80 -j ACCEPT &>/dev/null 41 | iptables -t filter -A FORWARD -i $CLIENTIFACE -o $CLIENTIFACE -p tcp --dport 443 -j ACCEPT &>/dev/null 42 | ip rule add fwmark 2 table proxy &>/dev/null 43 | ip route add default via ${PROXYIP} table proxy &>/dev/null 44 | fi 45 | } 46 | 47 | stop() { 48 | iptables -t mangle -D PREROUTING -i $CLIENTIFACE ! -d $NETWORK -p tcp --dport 80 -j MARK --set-mark $FWMARK &>/dev/null 49 | iptables -t mangle -D PREROUTING -p tcp --dport 80 -s $PROXYIP -j ACCEPT &>/dev/null 50 | iptables -t mangle -D PREROUTING -i $CLIENTIFACE ! -d $NETWORK -p tcp --dport 443 -j MARK --set-mark $FWMARK &>/dev/null 51 | iptables -t mangle -D PREROUTING -p tcp --dport 443 -s $PROXYIP -j ACCEPT &>/dev/null 52 | for except in ${EXCEPTIONS} 53 | do 54 | iptables -t mangle -D PREROUTING -p tcp --dport 80 -s $except -j ACCEPT &>/dev/null 55 | iptables -t mangle -D PREROUTING -p tcp --dport 443 -s $except -j ACCEPT &>/dev/null 56 | done 57 | iptables -t mangle -D PREROUTING -m mark --mark $FWMARK -j ACCEPT &>/dev/null 58 | iptables -t filter -D FORWARD -i $CLIENTIFACE -o $CLIENTIFACE -p tcp --dport 80 -j ACCEPT &>/dev/null 59 | iptables -t filter -D FORWARD -i $CLIENTIFACE -o $CLIENTIFACE -p tcp --dport 443 -j ACCEPT &>/dev/null 60 | ip rule del fwmark 2 table proxy &>/dev/null 61 | ip route del default via ${PROXYIP} table proxy &>/dev/null 62 | } 63 | 64 | restart(){ 65 | stop 66 | sleep 1 67 | start 68 | } 69 | -------------------------------------------------------------------------------- /sbin/telegram_bot: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo -n "telegram_bot" >/proc/$$/comm; 4 | 5 | { 6 | PATH='/usr/bin:/usr/sbin:/bin:/sbin' 7 | 8 | echo "starting" 9 | 10 | url=$(uci -q get telegramopenwrt.global.url) 11 | key=$(uci -q get telegramopenwrt.global.key) 12 | timeout=$(uci -q get telegramopenwrt.global.timeout) 13 | api="$url$key" 14 | my_chat_id=$(uci -q get telegramopenwrt.global.my_chat_id) 15 | from=$(uci -q get telegramopenwrt.smtp.from) 16 | to=$(uci -q get telegramopenwrt.smtp.to) 17 | path="/sbin" 18 | plugins="/usr/lib/telegramopenwrt/plugins" 19 | actions="${plugins}/actions" 20 | ps_cmd=$([[ $(readlink -fn /bin/ps) == "/bin/busybox" ]] && echo "ps w" || echo "ps ax") 21 | touch /var/run/bot_vars 22 | 23 | command_not_found="Sorry, 24 | I only recognize *commands*. 25 | Commands are words beginning with a slash. 26 | Try it ! 27 | Send [/start](/start) to get my commands list." 28 | starting=1 29 | 30 | while [ true ] 31 | do 32 | source /var/run/bot_vars 33 | offset=$(($offset+1)) 34 | status='false' 35 | updates=$(curl -s -k -X GET $api/getUpdates?offset=$offset\&timeout=$timeout) 36 | status=$(jsonfilter -s "$updates" -e $.ok) 37 | if [ $status = 'true' ]; then 38 | update_ids=$(jsonfilter -s "$updates" -e $.result[*].update_id) 39 | 40 | for update_id in $update_ids 41 | do 42 | #this avoid reboot router after reboot 43 | echo "offset=$update_id" > /var/run/bot_vars 44 | origin=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].message.chat.id") 45 | msg_id=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].message.message_id") 46 | username=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].message.chat.username") 47 | name=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].message.chat.first_name") 48 | lastname=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].message.chat.last_name") 49 | command=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].message.text") 50 | is_a_cmd=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].message.entities[*].type") 51 | query_ans=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].callback_query.id") 52 | origin_ans=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].callback_query.message.chat.id") 53 | 54 | if [[ "$origin" != "$my_chat_id" && "$origin_ans" != "$my_chat_id" ]];then 55 | echo "From: ${from}"$'\n'"To: ${to}"$'\n'"Subject: TelegramBOT"$'\n\n'"Someone with username ${username} (${name} ${lastname}) is trying to use your bot, sending the ${command}" | ssmtp "${to}" 56 | curl -k -s -X POST $api/sendMessage -d reply_to_message_id=$msg_id -d chat_id=$origin -d parse_mode=Markdown --data-urlencode \ 57 | text="This is a Private bot. If you want to implement one for you, check this out https://github.com/alexwbaule/telegramopenwrt" 58 | curl -k -s -X POST $api/leaveChat -d chat_id=$origin 59 | else 60 | 61 | /sbin/typing > /tmp/typing.log & 62 | #curl -k -X POST $api/sendChatAction -d "chat_id=$my_chat_id" -d "action=typing" 63 | if [ $(echo "$is_a_cmd" | grep "bot_command" -q; echo -n $?) == 0 ]; then 64 | cmd=$(echo $command | awk '{print $1}') 65 | prms=$(echo $command | awk '{$1=""; sub(/^[ \t]+/, ""); print }') 66 | parms=${prms//[\"\&\;\\\>\<\|]/} 67 | if [ -f "${plugins}$cmd" ]; then 68 | if [[ "$cmd" == "/reboot" && $starting == 1 ]]; then 69 | continue; 70 | fi 71 | cd ${plugins} 72 | (echo "Call $cmd [$parms]" | logger -t "telegram_bot[$$]" -p daemon.info)& 73 | result=$("./$cmd" $parms) 74 | /sbin/telegram_sender "$result" 75 | cd ${path} 76 | else 77 | curl -k -s -X POST $api/sendMessage -d chat_id=$origin -d parse_mode=Markdown --data-urlencode text="Command *${cmd}* not found!" 78 | fi 79 | elif [ "$query_ans" != "" ]; then 80 | msg_id_ans=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].callback_query.message.message_id") 81 | final_cmd=$(jsonfilter -s "$updates" -e "$.result[@.update_id=$update_id].callback_query.data") 82 | fcmd=$(echo $final_cmd | awk -F "\|" '{printf $1}') 83 | fprms=$(echo $final_cmd | awk -F "\|" '{printf $2}') 84 | parameter=${fprms//[\&\;\\\>\<\|]/} 85 | if [ -f "${actions}/$fcmd" ]; then 86 | cd ${actions} 87 | (echo "Call $fcmd" | logger -t "telegram_bot[$$]" -p daemon.info)& 88 | result=$(IFS="\^" ; "./$fcmd" ${parameter}) 89 | remove=$(echo $result | awk -F "\|" '{print $1}') 90 | msg=$(echo $result | awk -F "\|" '{print $2}') 91 | curl -k -s -X POST $api/answerCallbackQuery -d chat_id=$origin_ans -d callback_query_id=$query_ans -d text="${msg}" 92 | if [ "$remove" == "1" ]; then 93 | curl -k -s -X POST $api/editMessageText -d chat_id=$origin_ans -d message_id=$msg_id_ans -d text="${msg}" 94 | fi 95 | cd ${path} 96 | else 97 | curl -k -s -X POST $api/sendMessage -d chat_id=$origin_ans -d parse_mode=Markdown --data-urlencode text="Command Action *${fcmd}* not found!" 98 | fi 99 | else 100 | curl -k -s -X POST $api/sendMessage -d reply_to_message_id=$msg_id -d chat_id=$origin -d parse_mode=Markdown --data-urlencode text="${command_not_found}" 101 | fi 102 | kill $(${ps_cmd} | grep -v grep | grep typing | awk '{print $1}') 103 | fi 104 | done 105 | fi 106 | starting=0 107 | done& 108 | } | (logger -t "telegram_bot" -p daemon.info)& 109 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | email. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /usr/lib/telegramopenwrt/plugins/interfaces_list: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | old=$IFS 4 | IFS=$'\n' 5 | TOTAL=0 6 | 7 | echo "*Network Interfaces*" 8 | 9 | to_parse=$(ubus call network.interface dump) 10 | 11 | for iface in $(jsonfilter -s "$to_parse" -e '@.interface[*].interface') 12 | do 13 | echo "interface: $iface" 14 | echo "up:" $(jsonfilter -s "$to_parse" -e "@.interface[@.interface=\"$iface\"].up") 15 | echo "device:" $(jsonfilter -s "$to_parse" -e "@.interface[@.interface=\"$iface\"].device") 16 | echo "proto:" $(jsonfilter -s "$to_parse" -e "@.interface[@.interface=\"$iface\"].proto") 17 | echo "ipv4-address:" 18 | for addr in $(jsonfilter -s "$to_parse" -e "@.interface[@.interface=\"$iface\"]['ipv4-address'][*]") 19 | do 20 | ip=$(jsonfilter -s "$addr" -e "@['address']") 21 | mask=$(jsonfilter -s "$addr" -e "@['mask']") 22 | echo -en "\t $ip/$mask\n" 23 | done 24 | echo "routes:" 25 | for routes in $(jsonfilter -s "$to_parse" -e "@.interface[@.interface=\"$iface\"]['route'][*]") 26 | do 27 | source=$(jsonfilter -s "$routes" -e "@['source']") 28 | target=$(jsonfilter -s "$routes" -e "@['target']") 29 | nexthop=$(jsonfilter -s "$routes" -e "@['nexthop']") 30 | echo -en "\tfrom $source to $target via $nexthop\n" 31 | done 32 | echo "dns-server:" $(jsonfilter -s "$to_parse" -F "|" -e "@.interface[@.interface=\"$iface\"]['dns-server'][*]") 33 | echo "dns-search:" $(jsonfilter -s "$to_parse" -F "|" -e "@.interface[@.interface=\"$iface\"]['dns-search'][*]") 34 | echo "--------------------------------------------------" 35 | done 36 | IFS=$old -------------------------------------------------------------------------------- /.github/workflows/build-package.yml: -------------------------------------------------------------------------------- 1 | # Nome do Workflow: Exibido na interface do GitHub Actions 2 | name: Build telegram-openwrt Package 3 | 4 | # Gatilhos (Triggers): Quando este workflow será executado 5 | on: 6 | push: 7 | branches: 8 | - master # Branch principal do seu repositório telegramopenwrt 9 | # Se você usa 'main' ou outra branch, ajuste aqui. 10 | # Permite acionamento manual a partir da aba "Actions" do GitHub 11 | workflow_dispatch: 12 | inputs: 13 | openwrt_version: 14 | description: 'Versão do OpenWrt ou "snapshots"' 15 | required: true 16 | default: 'v23.05.3' # Sugestão de uma versão estável recente 17 | target_architecture: 18 | description: 'Target OpenWrt (ex: x86/64, mediatek/filogic, ou deixe em branco para x86/64 padrão)' 19 | required: false 20 | default: 'x86/64' # Target genérico para compilar pacotes .ipk 21 | 22 | # Jobs: Define um ou mais trabalhos a serem executados 23 | jobs: 24 | build_package: 25 | name: Build for OpenWrt ${{ github.event.inputs.openwrt_version || 'v23.05.3' }} (${{ github.event.inputs.target_architecture || 'x86/64' }}) 26 | runs-on: ubuntu-latest # Ambiente de execução 27 | 28 | env: 29 | # Variáveis de ambiente disponíveis para todas as etapas deste job 30 | PACKAGE_NAME: telegram-openwrt # Nome do seu pacote (com hífen) 31 | # Define a versão do OpenWrt. Usa o input do workflow_dispatch ou um padrão. 32 | OPENWRT_VERSION: ${{ github.event.inputs.openwrt_version || 'v23.05.3' }} 33 | # Define o target. Usa o input ou um padrão. 34 | TARGET_ARCH_INPUT: ${{ github.event.inputs.target_architecture || 'x86/64' }} 35 | 36 | steps: 37 | # Etapa 1: Checkout do código do seu pacote telegram-openwrt 38 | - name: Checkout telegram-openwrt package repository 39 | uses: actions/checkout@v4 40 | 41 | # Etapa 2: Instalação das dependências de compilação do OpenWrt no executor Ubuntu 42 | - name: Install OpenWrt build dependencies 43 | run: | 44 | sudo apt-get update 45 | sudo apt-get install -y --no-install-recommends \ 46 | build-essential clang flex bison g++ gawk \ 47 | gcc-multilib g++-multilib gettext git libncurses5-dev \ 48 | libssl-dev python3 python3-distutils rsync \ 49 | unzip zlib1g-dev file wget subversion ca-certificates 50 | 51 | # Etapa 3: Configuração do ambiente de compilação do OpenWrt SDK 52 | - name: Setup OpenWrt build environment 53 | run: | 54 | echo "Usando OpenWrt versão/branch: ${OPENWRT_VERSION}" 55 | if [[ "${OPENWRT_VERSION}" == "snapshots" ]]; then 56 | # Para snapshots, clonamos a branch master (ou a principal de desenvolvimento) 57 | git clone https://github.com/openwrt/openwrt.git --depth 1 openwrt_sdk 58 | else 59 | # Para releases, clonamos a tag específica 60 | git clone https://github.com/openwrt/openwrt.git -b ${OPENWRT_VERSION} --depth 1 openwrt_sdk 61 | fi 62 | cd openwrt_sdk 63 | 64 | echo "Atualizando e instalando feeds..." 65 | ./scripts/feeds update -a 66 | ./scripts/feeds install -a 67 | 68 | echo "Copiando código do pacote ${PACKAGE_NAME}..." 69 | mkdir -p package/${PACKAGE_NAME} 70 | # GITHUB_WORKSPACE é o diretório onde o seu repo (alexwbaule/telegramopenwrt) foi clonado 71 | cp -R ${GITHUB_WORKSPACE}/* package/${PACKAGE_NAME}/ 72 | echo "Conteúdo copiado para package/${PACKAGE_NAME}:" 73 | ls -lA package/${PACKAGE_NAME} 74 | 75 | echo "Gerando configuração .config para target: ${TARGET_ARCH_INPUT}..." 76 | # Configuração do .config baseada no input TARGET_ARCH_INPUT 77 | # Exemplos: 78 | # 'x86/64' -> CONFIG_TARGET_x86=y, CONFIG_TARGET_x86_64=y, CONFIG_TARGET_x86_64_DEVICE_generic=y 79 | # 'mediatek/filogic' -> CONFIG_TARGET_mediatek=y, CONFIG_TARGET_mediatek_filogic=y (precisaria de um DEVICE específico) 80 | # 'ath79/generic' -> CONFIG_TARGET_ath79=y, CONFIG_TARGET_ath79_generic=y 81 | 82 | # NOTA: Para gerar pacotes .apk, você DEVE selecionar um target que sabidamente os utilize 83 | # em snapshots (ex: mediatek/filogic). A configuração abaixo é um exemplo para x86/64 (gera .ipk). 84 | # Adapte esta seção CUIDADOSAMENTE para o target desejado. 85 | 86 | # Limpa o .config para começar 87 | echo "" > .config 88 | 89 | if [[ "${TARGET_ARCH_INPUT}" == "x86/64" ]]; then 90 | echo "CONFIG_TARGET_x86=y" >> .config 91 | echo "CONFIG_TARGET_x86_64=y" >> .config 92 | echo "CONFIG_TARGET_x86_64_DEVICE_generic=y" >> .config 93 | elif [[ "${TARGET_ARCH_INPUT}" == "ath79/generic" ]]; then 94 | echo "CONFIG_TARGET_ath79=y" >> .config 95 | echo "CONFIG_TARGET_ath79_generic=y" >> .config 96 | echo "CONFIG_TARGET_BOARD=\"generic\"" >> .config 97 | elif [[ "${TARGET_ARCH_INPUT}" == "mediatek/filogic" ]]; then 98 | # Exemplo para mediatek/filogic - você precisará de um DEVICE específico. 99 | # Este é um placeholder e provavelmente precisará de ajuste para um device real. 100 | echo "CONFIG_TARGET_mediatek=y" >> .config 101 | echo "CONFIG_TARGET_mediatek_filogic=y" >> .config 102 | echo "CONFIG_TARGET_mediatek_filogic_DEVICE_generic=y" >> .config # Substitua 'generic' por um device válido se necessário 103 | echo "CONFIG_ALL_KMODS=y" >> .config # Pode ser necessário para alguns targets de snapshot 104 | echo "CONFIG_ALL_NONSHARED=y" >> .config 105 | else 106 | echo "::warning::Target não configurado explicitamente no workflow: ${TARGET_ARCH_INPUT}. Usando fallback para seleção manual ou erro." 107 | # Poderia adicionar uma configuração padrão ou falhar aqui 108 | fi 109 | 110 | # Seleciona o seu pacote para ser compilado como 'm' (módulo/pacote) 111 | # Hífens no nome do pacote são convertidos para underscores para CONFIG_PACKAGE_* 112 | CONFIG_PKG_NAME="CONFIG_PACKAGE_${PACKAGE_NAME//-/_}" 113 | echo "${CONFIG_PKG_NAME}=m" >> .config 114 | 115 | echo "Rodando make defconfig..." 116 | make defconfig 117 | 118 | echo "Configuração gerada (.config). Verificando seleção do pacote e dependências (curl, jq, libustream-openssl):" 119 | grep -E "${CONFIG_PKG_NAME}|CONFIG_PACKAGE_curl|CONFIG_PACKAGE_jq|CONFIG_PACKAGE_libustream_openssl" .config || echo "Algumas dependências podem não estar explicitamente no .config se forem parte do perfil do target." 120 | 121 | # Etapa 4: Compilação do pacote especificado 122 | - name: Compile the ${PACKAGE_NAME} package 123 | id: compile_step # ID para referenciar o status desta etapa 124 | run: | 125 | cd openwrt_sdk 126 | echo "Iniciando compilação do pacote ${PACKAGE_NAME}..." 127 | # V=s mostra mais detalhes da compilação (útil para depuração) 128 | # O comando make package//compile constrói apenas o pacote e suas dependências. 129 | if make package/${PACKAGE_NAME}/compile V=s -j$(nproc); then 130 | echo "Compilação do pacote concluída com sucesso." 131 | echo "::set-output name=status::success" 132 | echo "Verificando arquivos de pacote gerados..." 133 | echo "Arquivos .ipk encontrados:" 134 | find bin/packages/ -name "${PACKAGE_NAME}*.ipk" -print || true 135 | echo "Arquivos .apk encontrados:" 136 | find bin/packages/ -name "${PACKAGE_NAME}*.apk" -print || true 137 | else 138 | echo "::error::Compilação do pacote ${PACKAGE_NAME} falhou." 139 | echo "::set-output name=status::failure" 140 | exit 1 # Falha o workflow se a compilação falhar 141 | fi 142 | 143 | # Etapa 5: Upload do pacote compilado como um artefato do GitHub Actions 144 | - name: Upload ${PACKAGE_NAME} package artifact 145 | # Executa apenas se a etapa de compilação (id: compile_step) foi bem-sucedida 146 | if: steps.compile_step.outputs.status == 'success' 147 | uses: actions/upload-artifact@v4 148 | with: 149 | # Nome do artefato que será exibido no GitHub 150 | name: ${{ env.PACKAGE_NAME }}-package-${{ env.OPENWRT_VERSION }}-${{ env.TARGET_ARCH_INPUT//\//_ }} 151 | # Caminhos para os arquivos a serem incluídos no artefato 152 | # Procura por .ipk e .apk para cobrir ambos os formatos 153 | path: | 154 | openwrt_sdk/bin/packages/*/*/${{ env.PACKAGE_NAME }}*.ipk 155 | openwrt_sdk/bin/packages/*/*/*/${{ env.PACKAGE_NAME }}*.ipk 156 | openwrt_sdk/bin/packages/*/*/${{ env.PACKAGE_NAME }}*.apk 157 | openwrt_sdk/bin/packages/*/*/*/${{ env.PACKAGE_NAME }}*.apk 158 | # O que fazer se nenhum arquivo for encontrado nos paths especificados 159 | if-no-files-found: error # Gera um erro se nenhum pacote for encontradoi 160 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include $(TOPDIR)/rules.mk 2 | 3 | PKG_NAME:=telegram-openwrt 4 | 5 | PKG_VERSION:=1.1.1 6 | PKG_RELEASE:=1 7 | 8 | PKG_LICENSE:=GPL-2.0 9 | 10 | include $(INCLUDE_DIR)/package.mk 11 | 12 | define Package/telegram-openwrt 13 | SECTION:=net 14 | CATEGORY:=Network 15 | TITLE:=Telegram BOT for openwrt 16 | URL:=https://github.com/alexwbaule/telegramopenwrt 17 | PKGARCH:=all 18 | TITLE:=Telegram for openwrt BOT 19 | endef 20 | 21 | define Package/telegram-openwrt/description 22 | Telegram for use in openwrt. Its a BOT 23 | that executes selected commands in your router. 24 | Version: $(PKG_VERSION)-$(PKG_RELEASE) 25 | Info : https://github.com/alexwbaule/telegramopenwrt 26 | endef 27 | 28 | define Package/telegram-openwrt/conffiles 29 | /etc/config/telegramopenwrt 30 | endef 31 | 32 | define Build/Configure 33 | endef 34 | 35 | define Build/Compile 36 | endef 37 | 38 | define Package/telegram-openwrt/install 39 | $(INSTALL_DIR) $(1)/etc/init.d 40 | $(INSTALL_BIN) ./etc/init.d/telegram_bot \ 41 | ./etc/init.d/lanports \ 42 | ./etc/init.d/hosts_scan \ 43 | $(1)/etc/init.d 44 | 45 | $(INSTALL_DIR) $(1)/etc/config 46 | $(INSTALL_CONF) ./etc/config/telegramopenwrt \ 47 | $(1)/etc/config/telegramopenwrt 48 | 49 | $(INSTALL_DIR) $(1)/etc/telegramopenwrt 50 | $(INSTALL_CONF) ./etc/telegramopenwrt/macaddr.ignore \ 51 | $(1)/etc/telegramopenwrt/macaddr.ignore 52 | 53 | $(INSTALL_DIR) $(1)/usr/share/telegramopenwrt 54 | echo "$(PKG_VERSION)-$(PKG_RELEASE)" > $(1)/usr/share/telegramopenwrt/version 55 | 56 | $(INSTALL_DIR) $(1)/usr/lib/telegramopenwrt/plugins/actions 57 | $(INSTALL_BIN) ./usr/lib/telegramopenwrt/plugins/actions/cam_mv \ 58 | ./usr/lib/telegramopenwrt/plugins/actions/fwr_disable \ 59 | ./usr/lib/telegramopenwrt/plugins/actions/fw_delete \ 60 | ./usr/lib/telegramopenwrt/plugins/actions/proc_stop \ 61 | ./usr/lib/telegramopenwrt/plugins/actions/fwr_enable \ 62 | ./usr/lib/telegramopenwrt/plugins/actions/chromego \ 63 | ./usr/lib/telegramopenwrt/plugins/actions/fw_disable \ 64 | ./usr/lib/telegramopenwrt/plugins/actions/wifi_disable \ 65 | ./usr/lib/telegramopenwrt/plugins/actions/proxy_enable \ 66 | ./usr/lib/telegramopenwrt/plugins/actions/wifi_restart \ 67 | ./usr/lib/telegramopenwrt/plugins/actions/proc_restart \ 68 | ./usr/lib/telegramopenwrt/plugins/actions/proxy_disable \ 69 | ./usr/lib/telegramopenwrt/plugins/actions/wifi_enable \ 70 | ./usr/lib/telegramopenwrt/plugins/actions/light_control \ 71 | ./usr/lib/telegramopenwrt/plugins/actions/proc_start \ 72 | ./usr/lib/telegramopenwrt/plugins/actions/fw_enable \ 73 | ./usr/lib/telegramopenwrt/plugins/actions/interface_down \ 74 | ./usr/lib/telegramopenwrt/plugins/actions/interface_restart \ 75 | ./usr/lib/telegramopenwrt/plugins/actions/interface_up \ 76 | $(1)/usr/lib/telegramopenwrt/plugins/actions 77 | 78 | $(INSTALL_DIR) $(1)/usr/lib/telegramopenwrt/plugins/ctx 79 | $(INSTALL_BIN) ./usr/lib/telegramopenwrt/plugins/ctx/wifi_list \ 80 | ./usr/lib/telegramopenwrt/plugins/ctx/fwr_list \ 81 | ./usr/lib/telegramopenwrt/plugins/ctx/service_list \ 82 | ./usr/lib/telegramopenwrt/plugins/ctx/chromego \ 83 | ./usr/lib/telegramopenwrt/plugins/ctx/reboot \ 84 | ./usr/lib/telegramopenwrt/plugins/ctx/cam_kbd \ 85 | ./usr/lib/telegramopenwrt/plugins/ctx/proxy \ 86 | ./usr/lib/telegramopenwrt/plugins/ctx/fw_list \ 87 | ./usr/lib/telegramopenwrt/plugins/ctx/light_list \ 88 | ./usr/lib/telegramopenwrt/plugins/ctx/interfaces_list \ 89 | $(1)/usr/lib/telegramopenwrt/plugins/ctx 90 | 91 | $(INSTALL_DIR) $(1)/usr/lib/telegramopenwrt/plugins/help 92 | $(INSTALL_DATA) ./usr/lib/telegramopenwrt/plugins/help/cam_mv \ 93 | ./usr/lib/telegramopenwrt/plugins/help/fw_unblock \ 94 | ./usr/lib/telegramopenwrt/plugins/help/fw_add \ 95 | ./usr/lib/telegramopenwrt/plugins/help/cam_vdo \ 96 | ./usr/lib/telegramopenwrt/plugins/help/fwr_disable \ 97 | ./usr/lib/telegramopenwrt/plugins/help/msg_tv \ 98 | ./usr/lib/telegramopenwrt/plugins/help/wifi_list \ 99 | ./usr/lib/telegramopenwrt/plugins/help/swports_list \ 100 | ./usr/lib/telegramopenwrt/plugins/help/fwr_list \ 101 | ./usr/lib/telegramopenwrt/plugins/help/fw_delete \ 102 | ./usr/lib/telegramopenwrt/plugins/help/chromego_list \ 103 | ./usr/lib/telegramopenwrt/plugins/help/get_mac \ 104 | ./usr/lib/telegramopenwrt/plugins/help/proc_stop \ 105 | ./usr/lib/telegramopenwrt/plugins/help/proc_list \ 106 | ./usr/lib/telegramopenwrt/plugins/help/proxy_list \ 107 | ./usr/lib/telegramopenwrt/plugins/help/get_uptime \ 108 | ./usr/lib/telegramopenwrt/plugins/help/fwr_enable \ 109 | ./usr/lib/telegramopenwrt/plugins/help/wll_list \ 110 | ./usr/lib/telegramopenwrt/plugins/help/start \ 111 | ./usr/lib/telegramopenwrt/plugins/help/ignoredmac_list \ 112 | ./usr/lib/telegramopenwrt/plugins/help/fw_disable \ 113 | ./usr/lib/telegramopenwrt/plugins/help/lights \ 114 | ./usr/lib/telegramopenwrt/plugins/help/wifi_disable \ 115 | ./usr/lib/telegramopenwrt/plugins/help/proxy_enable \ 116 | ./usr/lib/telegramopenwrt/plugins/help/wifi_restart \ 117 | ./usr/lib/telegramopenwrt/plugins/help/proc_restart \ 118 | ./usr/lib/telegramopenwrt/plugins/help/reboot \ 119 | ./usr/lib/telegramopenwrt/plugins/help/proxy_disable \ 120 | ./usr/lib/telegramopenwrt/plugins/help/wifi_enable \ 121 | ./usr/lib/telegramopenwrt/plugins/help/get_ip \ 122 | ./usr/lib/telegramopenwrt/plugins/help/cam_shot \ 123 | ./usr/lib/telegramopenwrt/plugins/help/cam_movie \ 124 | ./usr/lib/telegramopenwrt/plugins/help/get_ping \ 125 | ./usr/lib/telegramopenwrt/plugins/help/fw_list \ 126 | ./usr/lib/telegramopenwrt/plugins/help/chromego_add \ 127 | ./usr/lib/telegramopenwrt/plugins/help/proc_start \ 128 | ./usr/lib/telegramopenwrt/plugins/help/ignoredmac_add \ 129 | ./usr/lib/telegramopenwrt/plugins/help/chromego_del \ 130 | ./usr/lib/telegramopenwrt/plugins/help/fw_enable \ 131 | ./usr/lib/telegramopenwrt/plugins/help/hst_list \ 132 | ./usr/lib/telegramopenwrt/plugins/help/netstat \ 133 | ./usr/lib/telegramopenwrt/plugins/help/interface_restart \ 134 | ./usr/lib/telegramopenwrt/plugins/help/interface_up \ 135 | ./usr/lib/telegramopenwrt/plugins/help/interface_down \ 136 | ./usr/lib/telegramopenwrt/plugins/help/interfaces_list \ 137 | ./usr/lib/telegramopenwrt/plugins/help/opkg_install \ 138 | ./usr/lib/telegramopenwrt/plugins/help/opkg_update \ 139 | $(1)/usr/lib/telegramopenwrt/plugins/help 140 | 141 | $(INSTALL_DIR) $(1)/usr/lib/telegramopenwrt/plugins 142 | $(INSTALL_BIN) ./usr/lib/telegramopenwrt/plugins/cam_mv \ 143 | ./usr/lib/telegramopenwrt/plugins/fw_unblock \ 144 | ./usr/lib/telegramopenwrt/plugins/fw_add \ 145 | ./usr/lib/telegramopenwrt/plugins/cam_vdo \ 146 | ./usr/lib/telegramopenwrt/plugins/fwr_disable \ 147 | ./usr/lib/telegramopenwrt/plugins/msg_tv \ 148 | ./usr/lib/telegramopenwrt/plugins/wifi_list \ 149 | ./usr/lib/telegramopenwrt/plugins/swports_list \ 150 | ./usr/lib/telegramopenwrt/plugins/fwr_list \ 151 | ./usr/lib/telegramopenwrt/plugins/fw_delete \ 152 | ./usr/lib/telegramopenwrt/plugins/chromego_list \ 153 | ./usr/lib/telegramopenwrt/plugins/get_mac \ 154 | ./usr/lib/telegramopenwrt/plugins/proc_stop \ 155 | ./usr/lib/telegramopenwrt/plugins/proc_list \ 156 | ./usr/lib/telegramopenwrt/plugins/proxy_list \ 157 | ./usr/lib/telegramopenwrt/plugins/get_uptime \ 158 | ./usr/lib/telegramopenwrt/plugins/fwr_enable \ 159 | ./usr/lib/telegramopenwrt/plugins/wll_list \ 160 | ./usr/lib/telegramopenwrt/plugins/start \ 161 | ./usr/lib/telegramopenwrt/plugins/ignoredmac_list \ 162 | ./usr/lib/telegramopenwrt/plugins/fw_disable \ 163 | ./usr/lib/telegramopenwrt/plugins/lights \ 164 | ./usr/lib/telegramopenwrt/plugins/wifi_disable \ 165 | ./usr/lib/telegramopenwrt/plugins/proxy_enable \ 166 | ./usr/lib/telegramopenwrt/plugins/wifi_restart \ 167 | ./usr/lib/telegramopenwrt/plugins/proc_restart \ 168 | ./usr/lib/telegramopenwrt/plugins/reboot \ 169 | ./usr/lib/telegramopenwrt/plugins/proxy_disable \ 170 | ./usr/lib/telegramopenwrt/plugins/wifi_enable \ 171 | ./usr/lib/telegramopenwrt/plugins/get_ip \ 172 | ./usr/lib/telegramopenwrt/plugins/cam_shot \ 173 | ./usr/lib/telegramopenwrt/plugins/cam_movie \ 174 | ./usr/lib/telegramopenwrt/plugins/get_ping \ 175 | ./usr/lib/telegramopenwrt/plugins/fw_list \ 176 | ./usr/lib/telegramopenwrt/plugins/chromego_add \ 177 | ./usr/lib/telegramopenwrt/plugins/proc_start \ 178 | ./usr/lib/telegramopenwrt/plugins/ignoredmac_add \ 179 | ./usr/lib/telegramopenwrt/plugins/chromego_del \ 180 | ./usr/lib/telegramopenwrt/plugins/fw_enable \ 181 | ./usr/lib/telegramopenwrt/plugins/hst_list \ 182 | ./usr/lib/telegramopenwrt/plugins/netstat \ 183 | ./usr/lib/telegramopenwrt/plugins/interface_down \ 184 | ./usr/lib/telegramopenwrt/plugins/interface_restart \ 185 | ./usr/lib/telegramopenwrt/plugins/interface_up \ 186 | ./usr/lib/telegramopenwrt/plugins/interfaces_list \ 187 | ./usr/lib/telegramopenwrt/plugins/opkg_install \ 188 | ./usr/lib/telegramopenwrt/plugins/opkg_update \ 189 | $(1)/usr/lib/telegramopenwrt/plugins 190 | 191 | $(INSTALL_DIR) $(1)/sbin 192 | $(INSTALL_BIN) ./sbin/telebot \ 193 | ./sbin/camkeyboard \ 194 | ./sbin/telegram_bot \ 195 | ./sbin/telekeyboard \ 196 | ./sbin/hosts_scan \ 197 | ./sbin/proxy \ 198 | ./sbin/typing \ 199 | ./sbin/telegram_sender \ 200 | ./sbin/lanports \ 201 | $(1)/sbin/ 202 | endef 203 | 204 | define Package/telegram-openwrt/postinst 205 | #!/bin/sh 206 | if [ -z "$${IPKG_INSTROOT}" ]; then 207 | /etc/init.d/telegram_bot enabled 208 | /etc/init.d/lanports enabled 209 | /etc/init.d/hosts_scan enabled 210 | /etc/init.d/telegram_bot start 211 | /etc/init.d/lanports start 212 | /etc/init.d/hosts_scan start 213 | fi 214 | exit 0 215 | endef 216 | 217 | define Package/telegram-openwrt/prerm 218 | #!/bin/sh 219 | if [ -n "$${IPKG_INSTROOT}" ]; then 220 | /etc/init.d/telegram_bot stop 221 | /etc/init.d/lanports stop 222 | /etc/init.d/hosts_scan stop 223 | /etc/init.d/telegram_bot disable 224 | /etc/init.d/lanports disable 225 | /etc/init.d/hosts_scan disable 226 | fi 227 | exit 0 228 | endef 229 | 230 | $(eval $(call BuildPackage,telegram-openwrt)) 231 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegram Scripts for OpenWrt 2 | 3 | This is a set of scripts with a plugins API written in bash, you can use it to manage and get informations on OpenWRT Routers. 4 | 5 | ### How its works ? 6 | 7 | First of all, 8 | Make a bot for you ! 9 | https://core.telegram.org/bots/api#authorizing-your-bot 10 | 11 | With the bot created, you need to replace "[PUT YOUR BOT KEY HERE]" in the telegramopenwrt config file with your bot key. 12 | 13 | Second, you need to send a initial message to your bot in Telegram App. 14 | After you send the message, in the OpenWRT run this: 15 | 16 | ``` curl -s -k -X GET https://api.telegram.org/bot/getUpdates | grep -oE "\"id\":[[:digit:]]+" | head -n1 | awk -F : '{print $2}'``` 17 | 18 | Get the number and replace "[PUT ID OF THE CHAT THAT YOU START WITH BOT]" in the telegramopenwrt config. 19 | 20 | ### Directory structure 21 | 22 | ``` 23 | ├── etc 24 | │   ├── config 25 | │   │   └── telegramopenwrt 26 | │   ├── init.d 27 | │   │   ├── hosts_scan 28 | │   │   ├── lanports 29 | │   │   └── telegram_bot 30 | │   └── telegramopenwrt 31 | │   └── macaddr.ignore 32 | ├── sbin 33 | │   ├── camkeyboard 34 | │   ├── hosts_scan 35 | │   ├── lanports 36 | │   ├── proxy 37 | │   ├── telebot 38 | │   ├── telegram_bot 39 | │   ├── telegram_sender 40 | │   ├── telekeyboard 41 | │   └── typing 42 | └── usr 43 | └── lib 44 | └── telegramopenwrt 45 | └── plugins 46 | ├── actions 47 | │   ├── cam_mv 48 | │   ├── chromego 49 | │   ├── fw_delete 50 | │   ├── fw_disable 51 | │   ├── fw_enable 52 | │   ├── fwr_disable 53 | │   ├── fwr_enable 54 | │   ├── interface_down 55 | │   ├── interface_restart 56 | │   ├── interface_up 57 | │   ├── light_control 58 | │   ├── proc_restart 59 | │   ├── proc_start 60 | │   ├── proc_stop 61 | │   ├── proxy_disable 62 | │   ├── proxy_enable 63 | │   ├── wifi_disable 64 | │   ├── wifi_enable 65 | │   └── wifi_restart 66 | ├── cam_movie 67 | ├── cam_mv 68 | ├── cam_shot 69 | ├── cam_vdo 70 | ├── chromego_add 71 | ├── chromego_del 72 | ├── chromego_list 73 | ├── ctx 74 | │   ├── cam_kbd 75 | │   ├── chromego 76 | │   ├── fw_list 77 | │   ├── fwr_list 78 | │   ├── interfaces_list 79 | │   ├── light_list 80 | │   ├── proxy 81 | │   ├── reboot 82 | │   ├── service_list 83 | │   └── wifi_list 84 | ├── fw_add 85 | ├── fw_delete 86 | ├── fw_disable 87 | ├── fw_enable 88 | ├── fw_list 89 | ├── fwr_disable 90 | ├── fwr_enable 91 | ├── fwr_list 92 | ├── fw_unblock 93 | ├── get_ip 94 | ├── get_mac 95 | ├── get_ping 96 | ├── get_uptime 97 | ├── help 98 | │   ├── cam_movie 99 | │   ├── cam_mv 100 | │   ├── cam_shot 101 | │   ├── cam_vdo 102 | │   ├── chromego_add 103 | │   ├── chromego_del 104 | │   ├── chromego_list 105 | │   ├── fw_add 106 | │   ├── fw_delete 107 | │   ├── fw_disable 108 | │   ├── fw_enable 109 | │   ├── fw_list 110 | │   ├── fwr_disable 111 | │   ├── fwr_enable 112 | │   ├── fwr_list 113 | │   ├── fw_unblock 114 | │   ├── get_ip 115 | │   ├── get_mac 116 | │   ├── get_ping 117 | │   ├── get_uptime 118 | │   ├── hst_list 119 | │   ├── ignoredmac_add 120 | │   ├── ignoredmac_list 121 | │   ├── interface_down 122 | │   ├── interface_restart 123 | │   ├── interfaces_list 124 | │   ├── interface_up 125 | │   ├── lights 126 | │   ├── msg_tv 127 | │   ├── netstat 128 | │   ├── opkg_install 129 | │   ├── opkg_update 130 | │   ├── ping_udp 131 | │   ├── proc_list 132 | │   ├── proc_restart 133 | │   ├── proc_start 134 | │   ├── proc_stop 135 | │   ├── proxy_disable 136 | │   ├── proxy_enable 137 | │   ├── proxy_list 138 | │   ├── reboot 139 | │   ├── start 140 | │   ├── swports_list 141 | │   ├── wifi_disable 142 | │   ├── wifi_enable 143 | │   ├── wifi_list 144 | │   ├── wifi_restart 145 | │   └── wll_list 146 | ├── hst_list 147 | ├── ignoredmac_add 148 | ├── ignoredmac_list 149 | ├── interface_down 150 | ├── interface_restart 151 | ├── interfaces_list 152 | ├── interface_up 153 | ├── lights 154 | ├── msg_tv 155 | ├── netstat 156 | ├── opkg_install 157 | ├── opkg_update 158 | ├── ping_udp 159 | ├── proc_list 160 | ├── proc_restart 161 | ├── proc_start 162 | ├── proc_stop 163 | ├── proxy_disable 164 | ├── proxy_enable 165 | ├── proxy_list 166 | ├── reboot 167 | ├── start 168 | ├── swports_list 169 | ├── wifi_disable 170 | ├── wifi_enable 171 | ├── wifi_list 172 | ├── wifi_restart 173 | └── wll_list 174 | ``` 175 | #### lanports file 176 | 177 | This file reads the router logs with the logread -f command, and sends messages via bot telegram if a router port is turned off / on or the router delivers an IP address via DHCP. 178 | 179 | #### init.d directory 180 | 181 | Contains the necessary files for the scripts to be started at the router boot, just move them to the /etc/init.d/ of the router and run: 182 | ```sh 183 | /etc/init.d/lanports enable 184 | /etc/init.d/telegram_bot enable 185 | ``` 186 | 187 | And then: 188 | 189 | ```sh 190 | /etc/init.d/lanports start 191 | /etc/init.d/telegram_bot start 192 | ``` 193 | 194 | #### plugins directory 195 | 196 | This is the main directory, it contains all the commands that the telegram bot can execute. 197 | 198 | There are some pre-built commands, which are: 199 | 200 | * cam_movie: Record 25 seconds of a camIP and send it. 201 | * cam_mv: Move the camera arround. 202 | * cam_shot: Get a Pic from the camera. 203 | * cam_vdo: Get a 25 seconds record from a camIP. 204 | * chromego_add: Include to a user in chromego, a word to be used in permissions (block url/youtube channel/etc). 205 | * chromego_del: Remove a word from a user in chromego to be used in permissions (block url/youtube channel/etc). 206 | * chromego_list: List all permissions in chromego (block url/youtube channel/etc). 207 | * fw_add: Block a hostname using a deny rule in firewall, if append time to command will block from 23:00 to 8:00 208 | * fw_delete: Remove a hostname from a deny firewall rule, if hostname is empty, will remove all rules created by this bot. 209 | * fw_disable: Disable a firewall rule. 210 | * fw_enable: Enable a firewall rule. 211 | * fw_list: List all fw rules. 212 | * fwr_disable: Disable a redirect firewall rule. 213 | * fwr_enable: Enable a redirect firewall rule. 214 | * fwr_list: List all redirect fw rules. 215 | * fw_unblock: Remove a hostname from a deny firewall rule, if hostname is empty, will remove all rules created by this bot. 216 | * get_ip: Get WAN IPAddress. 217 | * get_mac: Get the Organization that onwer the MacAddr. 218 | * get_ping: Ping a address or host, return Up or Down. 219 | * get_uptime: Return the uptime from this Device. 220 | * hst_list: Get hosts in the dhcp Leases. If a hostname is present, search only for this hostname. 221 | * ignoredmac_add: Add a new macaddress to the allowlist and avoid being notified about it. 222 | * ignoredmac_list: Shows the list of ignored mac addresses that will not be notified by the bot. 223 | * interface_down: Shutdown a interface by name. 224 | * interface_restart: Restart a interface by name. 225 | * interfaces_list: Get interfaces configuration. 226 | * interface_up: Start up a interface by name. 227 | * lights: Turn On or Off house Lights. 228 | * msg_tv: Send Message to Samsung TV 229 | * netstat: Prints netstat table in ESTABLISHED, CLOSED and TIME\_WAIT State. 230 | * opkg_install: Install a package from opkg. 231 | * opkg_update: Update list of packages avaliable. 232 | * ping_udp: Create a UDP packet to puncture a hole through a NAT firewall of your ISP 233 | * proc_list: List all process in execution 234 | * proc_restart: Restart a process in init.d 235 | * proc_start: Start a process in init.d 236 | * proc_stop: Stop a process in init.d 237 | * proxy_disable: Disable HTTP and HTTPS or HTTP or HTTPS proxy. 238 | * proxy_enable: Enable HTTP and HTTPS or HTTP or HTTPS proxy. 239 | * proxy_list: List proxy rules that is enabled. 240 | * reboot: Reboot the router. 241 | * start: This menu help! 242 | * swports_list: Switch ports list with states. 243 | * wifi_disable: Disable a wireless device radio. 244 | * wifi_enable: Enable a wireless device radio. 245 | * wifi_list: List all wireless devices. 246 | * wifi_restart: Restart a wireless device radio. 247 | * wll_list: Get a wifi clients list that is connected to this devices. 248 | 249 | 250 | 251 | #### help directory inside plugins 252 | 253 | This is the directory containing the help files, with the same name as the command, to be displayed by the start command. 254 | 255 | #### how to build a plugin ? 256 | 257 | Basically it to create a bash script, with openwrt commands (from uci, files, etc). 258 | If a plugin has "user interaction" (like choose between itens), the script that will provide thats choices, wil be in the 259 | ctx directory (ctx is from `context`, the script gives context to the user), inside plugins. Once the user choose, the script to be 260 | called, will stay on actions directory, inside plugins. (every context has one or more `action`). 261 | 262 | #### telebot file 263 | 264 | This file sends the telegram bot messages generated by lanports 265 | 266 | 267 | #### telegram_bot 268 | 269 | The telegram_bot script is a loop that receives the updates every second and checks to see if there is a command to execute. If there is a command, the script checks to see if there is a file with the same name as the command inside the plugins directory and runs it, if it exists. The output of the executed script is sent as a response message from the command. 270 | Inside the plugins directory, there is the special command "start", which returns a message with the commands and a brief help on each command. 271 | For this command to work properly, you need to create a file inside the plugins / help directory, with the name equal to the command. 272 | 273 | ## License 274 | 275 | See [LICENSE](LICENSE) file. 276 | 277 | ## Package Guidelines 278 | 279 | See [CONTRIBUTING.md](CONTRIBUTING.md) file. 280 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Ref: for overall format and construction 4 | 5 | ## Basic guidelines 6 | 7 | All packages you commit or submit by pull-request should follow these simple 8 | guidelines: 9 | 10 | - Package a version which is still maintained by the upstream author and will 11 | be updated regularly with supported versions. 12 | - Have no dependencies outside the OpenWrt core packages or this repository 13 | feed. 14 | - Have been tested to compile with the correct includes and dependencies. 15 | Please also test with "Compile with full language support" found under 16 | "General Build Settings" set if language support is relevant to your package. 17 | - Best of all -- it works as expected! 18 | 19 | ## Package Sources (archives and repositories) 20 | 21 | - PKG_SOURCE should reference the smallest available archive. In order of 22 | preference: xz (most compressed), bzip2, gz and zip. As a last resort, 23 | downloads from source repositories can be used. 24 | - PKG_SOURCE_URL should link to an official release archive. Use of HTTPS: 25 | is preferred. If a source archive is not available, a locally generated 26 | archive fetched using git, svn, cvs or in rare circumstances, hg or bzr. 27 | - Convenience macros for popular mirrors are defined. Using these macros will 28 | make your package downloads more robust by mapping to a list of possible 29 | source mirrors for archive availability. 30 | - @SF - Sourceforge (downloads.sourceforge.net) with 5 retries due to 31 | re-directs 32 | - @GITHUB - Github (raw.githubusercontent.com) with 5 retries due to 33 | re-directs 34 | - @GNU - 8 regional servers 35 | - @GNOME - 8 regional servers 36 | - @SAVANNAH - 8 regional servers 37 | - @APACHE - 8 regional servers 38 | - @KERNEL - Linux kernel archives & mirrors 39 | - Please _DO NOT_ use an archive which changes over time. A version labeled 40 | "latest" is not constant each download. Also, using the head of a branch will 41 | create unpredictable results which can be different each build. 42 | 43 | ### Makefile contents should contain 44 | 45 | - Provide an up-to-date Copyright notice or **none**. Copyright should not be 46 | assigned to OpenWrt unless you are explicitly requested by or working under 47 | contract to OpenWrt. Assigning a Copyright to yourself or organization you 48 | represent is acceptable. 49 | - A (PKG\_)MAINTAINER definition listing either yourself and/or another person 50 | responsible for this package (E.g.: PKG_MAINTAINER:= Joe D. Hacker 51 | `). Listing multiple maintainers is encouraged in 52 | order to keep the package active and up-to-date. Leaving this blank will also 53 | be accepted, however the review process may not be as quick as one with a 54 | maintainer. 55 | - A PKG_LICENSE tag declaring the main license of the package. (E.g.: 56 | PKG_LICENSE:=GPL-2.0-or-later) Please use SPDX identifiers if possible (see 57 | list at the bottom). 58 | - An optional PKG_LICENSE_FILES tag including the filenames of the 59 | license-files in the source-package. (E.g.: PKG_LICENSE_FILES:=COPYING) 60 | - PKG_RELEASE should be initially set to 1 or reset to 1 if the software 61 | version is changed. You should increment it if the package itself has 62 | changed. For example, modifying a support script, changing configure options 63 | like --disable_ or --enable\_ switches, or if you changed something in the 64 | package which causes the resulting binaries to be different. Changes like 65 | correcting md5sums, changing mirror URLs, adding a maintainer field or updating 66 | a comment or copyright year in a Makefile do not require a change to 67 | PKG_RELEASE. 68 | - Avoid reuse of PKG_NAME in call, define and eval lines to improve 69 | readability. 70 | 71 | ### Commits in your pull-requests should 72 | 73 | - Have a useful description prefixed with the package name (E.g.: "foopkg: Add 74 | libzot dependency") 75 | - Include Signed-off-by tag in the commit comments. See: [Sign your 76 | work](https://openwrt.org/submitting-patches#sign_your_work) 77 | 78 | ## Advice on pull requests 79 | 80 | Pull requests are the easiest way to contribute changes to git repos at Github. 81 | They are the preferred contribution method, as they offer a nice way for 82 | commenting and amending the proposed changes. 83 | 84 | - You need a local "fork" of the Github repo. 85 | 86 | - Use a "feature branch" for your changes. That separates the changes in the 87 | pull request from your other changes and makes it easy to edit/amend commits 88 | in the pull request. Workflow using "feature_x" as the example: 89 | - Update your local git fork to the tip (of the master, usually) 90 | - Create the feature branch with `git checkout -b feature_x` 91 | - Edit changes and commit them locally 92 | - Push them to your Github fork by `git push -u origin feature_x`. That 93 | creates the "feature_x" branch at your Github fork and sets it as the 94 | remote of this branch 95 | - When you now visit Github, you should see a proposal to create a pull 96 | request 97 | 98 | - If you later need to add new commits to the pull request, you can simply 99 | commit the changes to the local branch and then use `git push` to 100 | automatically update the pull request. 101 | 102 | - If you need to change something in the existing pull request (e.g. to add a 103 | missing signed-off-by line to the commit message), you can use `git push -f` 104 | to overwrite the original commits. That is easy and safe when using a feature 105 | branch. Example workflow: 106 | - Checkout the feature branch by `git checkout feature_x` 107 | - Edit changes and commit them locally. If you are just updating the commit 108 | message in the last commit, you can use `git commit --amend` to do that 109 | - If you added several new commits or made other changes that require 110 | cleaning up, you can use `git rebase -i HEAD~X` (X = number of commits to 111 | edit) to possibly squash some commits 112 | - Push the changed commits to Github with `git push -f` to overwrite the 113 | original commits in the "feature_x" branch with the new ones. The pull 114 | request gets automatically updated 115 | 116 | ## If you have commit access 117 | 118 | - Do NOT use git push --force. 119 | - Do NOT commit to other maintainer's packages without their consent. 120 | - Use Pull Requests if you are unsure and to suggest changes to other 121 | maintainers. 122 | 123 | ### Gaining commit access 124 | 125 | - We will gladly grant commit access to responsible contributors who have made 126 | useful pull requests and / or feedback or patches to this repository or 127 | OpenWrt in general. Please include your request for commit access in your next 128 | pull request or ticket. 129 | 130 | ## Release Branches 131 | 132 | - Old stable branches were named after the following pattern "for-XX.YY" (e.g. 133 | for-14.07) before the LEDE split. During the LEDE split there was only one 134 | release branch with the name "lede-17.01". After merging the LEDE fork with 135 | OpenWrt the release branches are named according to the following pattern 136 | "openwrt-XX.YY" (e.g. openwrt-18.06). 137 | - These branches are built with the respective OpenWrt release and are created 138 | during the release stabilisation phase. 139 | - Please ONLY cherry-pick or commit security and bug-fixes to these branches. 140 | - Do NOT add new packages and do NOT do major upgrades of packages here. 141 | - If you are unsure if your change is suitable, please use a pull request. 142 | 143 | ## Common LICENSE tags (short list) 144 | 145 | (Complete list can be found at: ) 146 | 147 | | Full Name | Identifier | 148 | | ------------------------------------------------ | :----------------------- | 149 | | Apache License 1.0 | Apache-1.0 | 150 | | Apache License 1.1 | Apache-1.1 | 151 | | Apache License 2.0 | Apache-2.0 | 152 | | Artistic License 1.0 | Artistic-1.0 | 153 | | Artistic License 1.0 w/clause 8 | Artistic-1.0-cl8 | 154 | | Artistic License 1.0 (Perl) | Artistic-1.0-Perl | 155 | | Artistic License 2.0 | Artistic-2.0 | 156 | | BSD 2-Clause "Simplified" License | BSD-2-Clause | 157 | | BSD 2-Clause FreeBSD License | BSD-2-Clause-FreeBSD | 158 | | BSD 2-Clause NetBSD License | BSD-2-Clause-NetBSD | 159 | | BSD 3-Clause "New" or "Revised" License | BSD-3-Clause | 160 | | BSD with attribution | BSD-3-Clause-Attribution | 161 | | BSD 3-Clause Clear License | BSD-3-Clause-Clear | 162 | | BSD 4-Clause "Original" or "Old" License | BSD-4-Clause | 163 | | BSD-4-Clause (University of California-Specific) | BSD-4-Clause-UC | 164 | | BSD Protection License | BSD-Protection | 165 | | GNU General Public License v1.0 only | GPL-1.0-only | 166 | | GNU General Public License v1.0 or later | GPL-1.0-or-later | 167 | | GNU General Public License v2.0 only | GPL-2.0-only | 168 | | GNU General Public License v2.0 or later | GPL-2.0-or-later | 169 | | GNU General Public License v3.0 only | GPL-3.0-only | 170 | | GNU General Public License v3.0 or later | GPL-3.0-or-later | 171 | | GNU Lesser General Public License v2.1 only | LGPL-2.1-only | 172 | | GNU Lesser General Public License v2.1 or later | LGPL-2.1-or-later | 173 | | GNU Lesser General Public License v3.0 only | LGPL-3.0-only | 174 | | GNU Lesser General Public License v3.0 or later | LGPL-3.0-or-later | 175 | | GNU Library General Public License v2 only | LGPL-2.0-only | 176 | | GNU Library General Public License v2 or later | LGPL-2.0-or-later | 177 | | Fair License | Fair | 178 | | ISC License | ISC | 179 | | MIT License | MIT | 180 | | No Limit Public License | NLPL | 181 | | OpenSSL License | OpenSSL | 182 | | X11 License | X11 | 183 | | zlib License | Zlib | 184 | 185 | ## Continuous Integration 186 | 187 | To simplify review and require less human resources, a CI tests all packages. 188 | Passing CI tests are not a hard requirement but a good indicator what the 189 | Buildbots will think about the proposed patch. 190 | 191 | The CI builds modified packages for multiple architectures using the latest 192 | snapshot SDK. For supported architectures (`aarch64_generic`, 193 | `arm_cortex-a15_neon-vfpv4`, `i386_pentium4` and `x86_64`) an additional 194 | runtime test is executed. A running OpenWrt is simulated which tries to install 195 | created packages and runs a script called `test.sh` located next to the package 196 | Makefile. The script is executed with the two arguments `PKG_NAME` and 197 | `PKG_VERSION`. The `PKG_NAME` can be used to distinguish package variants, e.g. 198 | `foobar` vs. `foobar-full`. The `PKG_VERSION` can be used for a trivial test 199 | checking if `foobar --version` prints the correct version. `PKG_VERSION` is the 200 | OpenWrt version and therefore includes the `PKG_RELEASE`, which isn't usually 201 | part of the running programs version. 202 | 203 | The following snippet show a script that tests different binaries, depending 204 | what IPK package was installed. The `gpsd` Makefile produces both a `gpsd` and 205 | a `gpsd-clients` IPK package. 206 | 207 | ```shell 208 | #!/bin/sh 209 | 210 | case "$1" in 211 | "gpsd") 212 | gpsd -V 2>&1 | grep "$2" 213 | ;; 214 | "gpsd-clients") 215 | cgps -V 2>&1 | grep "$2" 216 | ;; 217 | esac 218 | ``` 219 | --------------------------------------------------------------------------------