#!/bin/bash

# Определяем правила iptables
add_rules() {
    iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 22222 -j DNAT --to-destination 10.25.10.109:22
	iptables -t nat -A PREROUTING -i vmbr0 -p tcp --match multiport --dports 44000:44500 -j DNAT --to-destination 10.25.10.109
	iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 21 -j DNAT --to-destination 10.25.10.109
}

remove_rules() {
    iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 22222 -j DNAT --to-destination 10.25.10.109:22
	iptables -t nat -D PREROUTING -i vmbr0 -p tcp --match multiport --dports 44000:44500 -j DNAT --to-destination 10.25.10.109
	iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 21 -j DNAT --to-destination 10.25.10.109	
}

# Проверяем количество аргументов
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 {start|stop}"
    exit 1
fi

# Обработка аргументов
case "$2" in
    pre-start)
        add_rules
        ;;
    post-stop)
        remove_rules
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac
