"Fossies" - the Fresh Open Source Software Archive

Member "shorewall-init-5.2.8/init.openwrt.sh" (24 Sep 2020, 3468 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.

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