Introduction
Knock is a utility that enables the router to execute preselected commands without having to ssh in or access the GUI. The preselected commands are executed using port "knocks". This utility didn't need any special software to implement this as it utilizes the router's built-in firewall logging capability. Note that this concept was originally proposed in 2012 by @RMerlin here but as far as I could tell, no one took him up on the idea. I originally developed this tool to enable my family to wake-up a PC without requiring a special app or password access to the router. I then quickly realized it could have lots of other uses (see examples section below). I turned to @Viktor Jaep for help in order to make this generally available to the community. He graciously reviewed and provided lots of input, not only to fix bugs, but make it better follow @thelonelycoder well-thought-out AddOn guidelines.Install/Uninstall Instructions
To Install
- ssh into the router and enter the following command:
Code:
curl --retry 3 "https://raw.githubusercontent.com/Rung-Asus/Knock/main/knock.sh" -o /jffs/scripts/knock.sh && chmod 755 /jffs/scripts/knock.sh && sh /jffs/scripts/knock.sh -install - Next update the "knock.cfg" configuration file in the /jffs/addons/knock.d/ folder (see configuration file format section below):
Code:
nano /jffs/addons/knock.d/knock.cfg - Finally run the following command:
Code:
/jffs/scripts/knock.sh -start
To Update Configuration
- Stop knock from running:
Code:
/jffs/scripts/knock.sh -stop - Then update the configuration file:
Code:
nano /jffs/addons/knock.d/knock.cfg - Finally restart knock:
Code:
/jffs/scripts/knock.sh -start - To show the current configuration file with the URLs interpreted run:
Code:
/jffs/scripts/config.sh -config
To Download the Latest Version of Knock.sh
Run the following command:
Code:
/jffs/scripts/knock.sh -update
Knock will show the version installed and the version on Github and give you the option to download and update. Here is an example screenshot of the update process:
To Uninstall
Run the following command:
Code:
/jffs/scripts/knock.sh -uninstall
Configuration File Format
The format of the configuration file is:- Any line that doesn't start with a "#" or empty provides a new command to be executed
- Each command line provides three important items: the port number that will execute the command, the interface(s) which this port knock will be received, and the command itself:
Code:
Port Number <space> Interface(s) [comma separated] <space> Command to execute [to end of line]
Code:
#Comments and blank lines allowed
#Port_Num Interface(s) Commands
#The comment before each command will be shown when displaying the configuration
#This comment can describe the following command which here is ether-wake command to a specific PC
44444 br0 ether-wake -i br0 xx:xx:xx:xx:xx:xx
Example Use Cases
- Allow a user on local LAN, using the wireguard server, or the Tailscale server to wake up a specific PC. Put the following line in the config file:
Code:
44444 br0,lo,wgs1 ether-wake -i br0 xx:xx:xx:xx:xx:xx - Allow that same user to reboot router:
Code:
44445 br0,lo,wgs1 reboot - Allow a user on the local LAN to run a custom script that enables something (e.g. a VPN Director rule):
Code:
44446 br0 /jffs/scripts/enable-example.sh - Allow same user to run a complementary disable script:
Code:
44447 br0 /jffs/scripts/disable-example.sh
- Kick off a backup -- like using "sh /jffs/scripts/backupmon.sh -backup"
- Turn lights on and off with @JGrana 's huetil and uKasa apps
- Initiate a WAN failover with the wan_failover script
Acknowledgments
Many thanks to @Viktor Jaep for all his help, input, and testing of this script! Portions in this script were derved from @Viktor Jaep's awesome Tailmon script. Original concept credit to @RMerlin (https://www.snbforums.com/threads/wake-on-lan-per-http-https-script.7958/post-47811)Change Log
v1.0: Initial Releasev1.1: Added better reporting of current configuration including URL example based on interface and port (see new screen shot in the Install section), documented "Update" function which will download and install the latest version
Last edited:
