Applescript/Shell script that enable/disable vpn on edgerouter via ssh. The script can then be exported as an app to be used even more widely (mac) or be used as shell script.
The script should not be used without ssh key if possible. You can keystroke password in applescript but this is not recommend do to security. The script outputs commands to the edgerouters CLI to enable/disable vpn firewall rules so use your correct rule name. This script relies on errors and therefor not exiting to early. But after 10 tries it closes to not make it run infinity if any other errors occurs (mac). You can export this file to a program or shell script. Every time you run it you will enable/disable your firewall. Se bottom of page for more....
You have to configure firewall rules manually first time according to pictures below. Change the rule numbers in the script so that they correspond to the numbers on your firewall rules. This script only blocks VPN connections via firewall. First you need to configure and setup your vpn solution. I recommend using l2tp over iPsec. You can find tutorial about setting up a vpn on youtube especially for the edgerouter series.
--
You can activate/inactivate rules by adding/deleting this line in the script:
activate:
do script ("delete firewall name WAN_LOCAL rule <your_firewall_rulenumber> disable") in currentTab
inactivate:
do script ("set firewall name WAN_LOCAL rule <your_firewall_rulenumber> disable") in currentTab
Here are pictures of the GUI firewall rules:
ex of where to find rule name:
- In mac terminal: ssh-keygen -t rsa (You might need to input size for exampel -b 2048)
- To save the key to mac type: ssh-add
- ssh key saved in .ssh/id_rsa.pub give chmod 600.
- To show ssh key in terminal: cat .ssh/id_rsa.pub (load this text into edgerouter) OBS! include ex "ssh-rsa" and "[email protected]". Tutorial video: https://www.youtube.com/watch?v=E8-CfvumJBo
- Use loadkey to add key to edgrouter from a .pub file in edgrouters directory.
- cd into .ssh
- make a .pub file
- paste your ssh key and write, quit (:w!, :q!) ESC to ensure no mispressed keys.
- loadkey (.pub file) For more about edgerouter shh key: https://youtu.be/rpAOl8UgfXM
Guide here: https://thehomeofthefuture.com/how-to/use-an-ssh-key-with-an-ubiquiti-edgerouter/
Homebridge with plugin Applescript makes a switch in the HomeKit app to turn on/off the VPN easily. Use "do shell script '' open /path''" to run your .app. On Linux you can use any homebridge plugin that does command line or execute shell script.