>> [demime 1.01d removed an attachment of type application/octet-stream which
>> had a name of ifstated.conf]
>>
>> [demime 1.01d removed an attachment of type application/x-sh which had a
>> name of manage-routes.sh]
>>

Since I have been receiving requests for the files, I am pasting them
here in full.

<file path="/etc/ifstated.conf">
dns = '"host google.com > /dev/null" every 10'
icap = '"ping -q -c 1 -w 3 icap.example.com > /dev/null" every 10'
wan1 = '"ping -q -c 1 -w 3 -I 74.125.71.2 74.125.71.1 > /dev/null" every 10'
wan2 = '"ping -q -c 1 -w 3 -I 75.125.71.66 75.125.71.65 > /dev/null" every 10'

state all {
        init {
                run "manage-routes.sh ALL"
                run "pf-create-nat.sh ALL"
                run "pf-create-route.sh LAN WAN-ALL"
        }
        if $dns
                run "/etc/rc.d/squid start"
        if ! $dns
                run "/etc/rc.d/squid stop"
        if $icap && $dns
                run "/etc/rc.d/dansguardian start"
        if ! $icap
                run "/etc/rc.d/dansguardian stop"
        if $wan1 && ! $wan2
                set-state wan1
        if $wan2 && ! $wan1
                set-state wan2
        if ! $wan1 && ! $wan2
                set-state none
}

state wan1 {
        init {
                run "manage-routes.sh WAN1"
                run "pf-create-nat.sh WAN1"
                run "pf-create-route.sh LAN WAN1"
        }
        if $dns
                run "/etc/rc.d/squid start"
        if ! $dns
                run "/etc/rc.d/squid stop"
        if $icap && $dns
                run "/etc/rc.d/dansguardian start"
        if ! $icap
                run "/etc/rc.d/dansguardian stop"
        if $wan1 && $wan2
                set-state all
        if $wan2 && ! $wan1
                set-state wan2
        if ! $wan1 && ! $wan2
                set-state none
}

state wan2 {
        init {
                run "manage-routes.sh WAN2"
                run "pf-create-nat.sh WAN2"
                run "pf-create-route.sh LAN WAN2"
        }
        if $dns
                run "/etc/rc.d/squid start"
        if ! $dns
                run "/etc/rc.d/squid stop"
        if $icap && $dns
                run "/etc/rc.d/dansguardian start"
        if ! $icap
                run "/etc/rc.d/dansguardian stop"
        if $wan1 && $wan2
                set-state all
        if $wan1 && ! $wan2
                set-state wan1
        if ! $wan1 && ! $wan2
                set-state none
}

state none {
        init {
                run "manage-routes.sh NONE"
                run "pfctl -a LAN -F all"
                run "pfctl -a NAT -F all"
                run "/etc/rc.d/squid stop"
                run "/etc/rc.d/dansguardian stop"
        }
        if $wan1 && $wan2
                set-state all
        if $wan1 && ! $wan2
                set-state wan1
        if $wan2 && ! $wan1
                set-state wan2
}
</file>

<file path="/usr/local/sbin/manage-routes.sh">
#!/bin/sh

SCRIPT="$0";

function help {
    echo "Usage: $SCRIPT ALL | WAN1 | WAN2 | NONE";
}

function in_table {
    GW="$1";

    route -n show | grep '^default' | awk '{ print $2 }' | grep $GW
2>&1 > /dev/null;
}

function add_route {
    GW="$1";
    route add -mpath default $GW 2>&1 > /dev/null;
}

function delete_route {
    GW="$1";
    route delete default $GW 2>&1 > /dev/null;
}

if [ $# -ne 1 ]; then
    help;
    exit 1;
fi

STATE="$1";
WAN1_GW="74.125.71.1";
WAN2_GW="75.125.71.65";

case "$STATE" in
    ALL)
        if ! in_table $WAN1_GW; then
            add_route $WAN1_GW;
        fi
        if ! in_table $WAN2_GW; then
            add_route $WAN2_GW;
        fi
        ;;
    WAN1)
        if ! in_table $WAN1_GW; then
            add_route $WAN1_GW;
        fi
        if in_table $WAN2_GW; then
            delete_route $WAN2_GW;
        fi
        ;;
    WAN2)
        if in_table $WAN1_GW; then
            delete_route $WAN1_GW;
        fi
        if ! in_table $WAN2_GW; then
            add_route $WAN2_GW;
        fi
        ;;
    NONE)
        if in_table $WAN1_GW; then
            delete_route $WAN1_GW;
        fi
        if in_table $WAN2_GW; then
            delete_route $WAN2_GW;
        fi
        ;;
    *)
        help;
        exit 1;
        ;;
esac
</file>

Regards,

-- 
Justin Jereza
LPIC-2

Reply via email to