#!/bin/sh . ./myserver.conf install_firewall_packages(){ pkg_add ssh_guard curl useradd -s /sbin/nologin -d /var/empty _pfbadhost ftp https://geoghegan.ca/pub/pf-badhost/0.5/pf-badhost.sh install -m 755 -o root -g bin pf-badhost.sh /usr/local/bin/pf-badhost install -m 640 -o _pfbadhost -g wheel /dev/null /etc/pf-badhost.txt install -d -m 755 -o root -g wheel /var/log/pf-badhost install -m 640 -o _pfbadhost -g wheel /dev/null /var/log/pf-badhost/pf-badhost.log install -m 640 -o _pfbadhost -g wheel /dev/null /var/log/pf-badhost/pf-badhost.log.0.gz cp -v /etc/doas.conf /etc/doas.conf.old egrep -v "_pfbadhost" /etc/doas.conf > /tmp/doas.conf cat >> /tmp/doas.conf < /var/cron/tabs/_pfbadhost <> my_configuration/pf.conf < to port $web_ports pass in on egress proto tcp to port $web_ports flags S/SA keep state \ (max-src-conn 100, max-src-conn-rate 15/5, \ overload flush) EOF cat >> my_configuration/pf.conf EOF [ "$SERVICE_MAIL" == "yes" ] && echo "mail_ports = \"{ smtp submission imap }\"" >> default_configuration/pf.conf [ "$SERVICE_XMPP" == "yes" ] && echo "xmmp_ports = \"{ 5222 5269 }\"" >> default_configuration/pf.conf echo "ssh_port = \"$SSH_PORT\"" >> default_configuration/pf.conf [ "$SERVICE_TURN" == "yes" ] && echo "turn_port = \"TURN_PORT\"" >> default_configuration/pf.conf cat >> my_configuration/pf.conf < flush global) pass in quick on egress proto { tcp, udp } from to port $web_ports pass in on egress proto tcp to port $web_ports flags S/SA keep state \ (max-src-conn 100, max-src-conn-rate 15/5, \ overload flush) EOF [ "$SERVICE_MAIL" == "yes" ] && cat >> my_configuration/pf.conf < flush global) pass out log on egress proto tcp to any port smtp EOF [ "$SERVICE_XMPP" == "yes" ] && cat >> my_configuration/pf.conf < flush global) EOF [ "$SERVICE_TURN" == "yes" ] && cat >> my_configuration/pf.conf < flush global) pass in on egress proto udp to port $turn_port EOF } install_conf_and_enable(){ pfctl -nf my_configuration/pf.conf if [ $? == 0 ]; then cp -v /etc/pf.conf /etc/pf.old cp -v my_configuration/pf.conf /etc/pf.conf pfctl -f /etc/pf.conf else echo "Il y a un problème dans la configuration du firewall" fi } if [ "$1" == "gen-config-only" ]; then set_basic_configuration set_open_service elif [ "$1" == "install" ]; then install_firewall_packages set_basic_configuration set_open_service install_conf_and_enable fi