summarylogtreecommitdiffstats
path: root/vuurmuur.script
blob: a643d6fbd42ff619fd30bcaf1827bda5f5b46892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash

VUURMUURPID='/run/vuurmuur.pid'
VUURMUURLOGPID='/run/vuurmuur_log.pid'
start() {
    IFNUM=`/usr/bin/vuurmuur_script --list --interface any | wc -l`
    if [ $IFNUM = 0 ]; then
        echo "Please configure Vuurmuur first by defining at least one interface."
        exit 1
    fi

    # load modules
    . /etc/vuurmuur/modules.conf
    for MODULE in `echo $MODULES_TO_LOAD`; do
        /sbin/modprobe $MODULE &>/dev/null
        if [ $? != 0 ]; then
            echo "Error when loading module $MODULE. Check log files."
            exit 1
        fi
    done

    # start vuurmuur daemon
    if [ ! -f $VUURMUURPID ]; then
        /usr/bin/vuurmuur -l
        if [ $? != 0 ]; then
            echo "Error when starting Vuurmuur daemon. Check log files."
            STATUS="failed"
        fi
    else
        PID=`cat $VUURMUURPID | cut -d " " -f 1`
        echo "Error when starting Vuurmuur daemon. Already running at pid $PID."
        STATUS="failed"
    fi

    # start vuurmuur log parsing daemon
    if [ ! -f $VUURMUURLOGPID ]; then
        /usr/bin/vuurmuur_log
        if [ $? != 0 ]; then
            echo "Error when starting Vuurmuur log parsing daemon. Check log files."
            STATUS="failed"
        fi
    else
        PID=`cat $VUURMUURLOGPID | cut -d " " -f 1`
        echo "Error when starting Vuurmuur log parsing daemon. Already running at pid $PID."
        STATUS="failed"
    fi

    # finalize
    if [ $STATUS = "failed" ]; then
        exit 1
    fi
}
stop() {
    # initialize
    echo "Stopping Vuurmuur Firewall"
    STATUS="ok"

    # stop vuurmuur log parsing daemon
    PID=`cat $VUURMUURLOGPID | cut -d " " -f 1`
    if [[ ! -z $PID ]] && kill "$PID" &>/dev/null; then
        rm -f $VUURMUURLOGPID
    else
        echo "Error when stopping Vuurmuur log parsing daemon. Check log files."
        STATUS="failed"
    fi

    # stop vuurmuur daemon
    PID=`cat $VUURMUURPID | cut -d " " -f 1`
    if [[ ! -z $PID ]] && kill "$PID" &>/dev/null; then
        rm -f $VUURMUURPID
    else
        echo "Error when stopping Vuurmuur daemon. Check log files."
        STATUS="failed"
    fi

    # finalize
    if [ $STATUS = "false" ]; then
        exit 1
    fi
}
restart() {
    $0 stop
    $0 start
}

case $1 in
    start|stop|restart) "$1" ;;
esac