"Fossies" - the Fresh Open Source Software Archive

Member "shorewall-init-5.2.8/shorewall-init" (24 Sep 2020, 3272 Bytes) of package /linux/misc/shorewall/shorewall-init-5.2.8.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "shorewall-init": 5.2.3.6_vs_5.2.6.

    1 #!/bin/bash
    2 #   The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V5.2
    3 #
    4 #   (c) 2012-2014 - Tom Eastep (teastep@shorewall.net)
    5 #
    6 #   On most distributions, this file should be called
    7 #   /etc/init.d/shorewall.
    8 #
    9 #   Complete documentation is available at https://shorewall.org
   10 #
   11 #   This program is part of Shorewall.
   12 #
   13 #   This program is free software; you can redistribute it and/or modify
   14 #   it under the terms of the GNU General Public License as published by
   15 #   the Free Software Foundation, either version 2 of the license or,
   16 #   at your option, any later version.
   17 #
   18 #   This program is distributed in the hope that it will be useful,
   19 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
   20 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   21 #   GNU General Public License for more details.
   22 #
   23 #   You should have received a copy of the GNU General Public License
   24 #   along with this program; if not, see <http://www.gnu.org/licenses/>.
   25 #
   26 ###############################################################################
   27 # set the STATEDIR variable
   28 
   29 setstatedir() {
   30     local statedir
   31     if [ -f ${CONFDIR}/${PRODUCT}/vardir ]; then
   32     statedir=$( . /${CONFDIR}/${PRODUCT}/vardir && echo $VARDIR )
   33     fi
   34 
   35     [ -n "$statedir" ] && STATEDIR=${statedir} || STATEDIR=${VARLIB}/${PRODUCT}
   36 
   37     if [ -x ${STATEDIR}/firewall ]; then
   38         return 0
   39     elif [ $PRODUCT = shorewall ]; then
   40     ${SBINDIR}/shorewall compile
   41     elif [ $PRODUCT = shorewall6 ]; then
   42     ${SBINDIR}/shorewall -6 compile
   43     fi
   44 }
   45 
   46 # Initialize the firewalls
   47 
   48 shorewall_init_start () {
   49     local PRODUCT
   50     local STATEDIR
   51 
   52     printf "Initializing \"Shorewall-based firewalls\": "
   53 
   54     if [ -n "$SAVE_IPSETS" -a -f "$SAVE_IPSETS" ]; then
   55     ipset -R < "$SAVE_IPSETS"
   56     fi
   57 
   58     for PRODUCT in $PRODUCTS; do
   59     if setstatedir; then
   60         #
   61         # Run in a sub-shell to avoid name collisions
   62         #
   63         (
   64         if ! ${STATEDIR}/firewall status > /dev/null 2>&1; then
   65             ${STATEDIR}/firewall ${OPTIONS} stop
   66         fi
   67         )
   68     fi
   69     done
   70 
   71     return 0
   72 }
   73 
   74 # Clear the firewalls
   75 
   76 shorewall_init_stop () {
   77     local PRODUCT
   78     local STATEDIR
   79 
   80     printf "Clearing \"Shorewall-based firewalls\": "
   81 
   82     for PRODUCT in $PRODUCTS; do
   83     if setstatedir; then
   84         #
   85         # Run in sub-shell to avoid name collisions
   86         #
   87         (
   88         if ! ${STATEDIR}/firewall status > /dev/null 2>&1; then
   89             ${STATEDIR}/firewall ${OPTIONS} clear
   90         fi
   91         )
   92     fi
   93     done
   94 
   95     if [ -n "$SAVE_IPSETS" ]; then
   96     mkdir -p $(dirname "$SAVE_IPSETS")
   97     if ipset -S > "${SAVE_IPSETS}.tmp"; then
   98         grep -qE -- '^(-N|create )' "${SAVE_IPSETS}.tmp" && mv -f "${SAVE_IPSETS}.tmp" "$SAVE_IPSETS" || rm -f "${SAVE_IPSETS}.tmp"
   99     else
  100         rm -f "${SAVE_IPSETS}.tmp"
  101     fi
  102     fi
  103 
  104     return 0
  105 }
  106 
  107 #
  108 # This is modified by the installer when ${SHAREDIR} <> /usr/share
  109 #
  110 . /usr/share/shorewall/shorewallrc
  111 
  112 # check if shorewall-init is configured or not
  113 if [ -f "$SYSCONFDIR/shorewall-init" ]; then
  114     . $SYSCONFDIR/shorewall-init
  115     if [ -z "$PRODUCTS" ]; then
  116     echo "ERROR: No products configured" >&2
  117     exit 1
  118     fi
  119 else
  120     echo "ERROR: ${SYSCONFDIR}/shorewall-init not found" >&2
  121     exit 1
  122 fi
  123 
  124 case "$1" in
  125     start)
  126     shorewall_init_start
  127     ;;
  128     stop)
  129     shorewall_init_stop
  130     ;;
  131     *)
  132     echo "Usage: $0 {start|stop}"
  133     exit 1
  134 esac
  135 
  136 exit 0