Skip to content

Instantly share code, notes, and snippets.

@dadatuputi
Last active May 16, 2020 22:41
Show Gist options
  • Save dadatuputi/5a1108791cc28c16e39213547d7ed8e8 to your computer and use it in GitHub Desktop.
Save dadatuputi/5a1108791cc28c16e39213547d7ed8e8 to your computer and use it in GitHub Desktop.
Proxmox access lockout script - lock out access to webui/SSH, best used with crontab schedule
#!/usr/bin/env bash
file=/etc/pve/firewall/cluster.fw
drop_rule="IN DROP -log nolog"
group_rule="IN ACCEPT -source 192.168.1.0\/24 -log nolog"
function comment {
replace "$1" "|$1" $2
}
function uncomment {
replace "|$1" "$1" $2
}
function replace {
eval "sed -i '/^$1/ c$2' $3"
}
case "$1" in
"disable")
uncomment "$drop_rule" "$file"
comment "$group_rule" "$file"
;;
"enable")
comment "$drop_rule" "$file"
uncomment "$group_rule" "$file"
;;
esac
@dadatuputi
Copy link
Author

Set up a crontab entry by entering crontab -e and adding the following lines:

0       5       *       *       *       /bin/bash /root/scripts/access.sh enable
0       22      *       *       *       /bin/bash /root/scripts/access.sh disable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment