"Fossies" - the Fresh Open Source Software Archive

Member "aif-2.1.1/share/arno-iptables-firewall/plugins/50dyndns-host-open.plugin" (16 Sep 2020, 4835 Bytes) of package /linux/privat/aif-2.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "50dyndns-host-open.plugin": 2.1.0_vs_2.1.1.

    1 # ------------------------------------------------------------------------------
    2 #         -= Arno's Iptables Firewall(AIF) - DynDNS Host Open plugin =-
    3 #
    4 PLUGIN_NAME="DynDNS Host Open plugin"
    5 PLUGIN_VERSION="1.42a"
    6 PLUGIN_CONF_FILE="dyndns-host-open.conf"
    7 #
    8 # Last changed          : May 9, 2019
    9 # Requirements          : AIF 2.1.0 (or newer)
   10 # Comments              : This implements dynamic DNS (DynDNS) support for eg. opening ports
   11 #
   12 # Author                : (C) Copyright 2008-2019 by Arno van Amersfoort
   13 # Homepage              : https://rocky.eld.leidenuniv.nl/
   14 # Email                 : a r n o v a AT r o c k y DOT e l d DOT l e i d e n u n i v DOT n l
   15 #                         (note: you must remove all spaces and substitute the @ and the .
   16 #                         at the proper locations!)
   17 # ------------------------------------------------------------------------------
   18 # This program is free software; you can redistribute it and/or
   19 # modify it under the terms of the GNU General Public License
   20 # version 2 as published by the Free Software Foundation.
   21 #
   22 # This program is distributed in the hope that it will be useful,
   23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   25 # GNU General Public License for more details.
   26 #
   27 # You should have received a copy of the GNU General Public License
   28 # along with this program; if not, write to the Free Software
   29 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   30 # ------------------------------------------------------------------------------
   31 
   32 # (Background) job name
   33 JOB_NAME="dyndns-host-open"
   34 
   35 # (Background) job helper script
   36 JOB_HELPER_SCRIPT="$PLUGIN_BIN_PATH/dyndns-host-open-helper"
   37 
   38 dyndns_host_open_init()
   39 {
   40   # Insert rule into the main chain:
   41   iptables -A EXT_INPUT_CHAIN -j DYNDNS_CHAIN
   42 
   43   # Remove old cron job (this is in case a legacy plugin left it)
   44   rm -f /etc/cron.d/dyndns-host-open
   45 
   46   # Create background job
   47   if ! job_add "$JOB_NAME" "${DYNDNS_HOST_OPEN_TIME:-60}" "$JOB_HELPER_SCRIPT"; then
   48     return 1
   49   fi
   50 
   51   return 0
   52 }
   53 
   54 
   55 # Plugin start function
   56 plugin_start()
   57 {
   58   # Create new DYNDNS_CHAIN chain:
   59   iptables -N DYNDNS_CHAIN 2>/dev/null
   60   iptables -F DYNDNS_CHAIN
   61 
   62   # Initialize
   63   if ! dyndns_host_open_init; then
   64     return 1
   65   fi
   66 
   67   return 0
   68 }
   69 
   70 
   71 # Plugin restart function
   72 plugin_restart()
   73 {
   74   # Re-add standard chain rules that are flushed on a restart
   75   echo "${INDENT}Restarting..."
   76 
   77   # Initialize
   78   if ! dyndns_host_open_init; then
   79     return 1
   80   fi
   81 
   82   return 0
   83 }
   84 
   85 
   86 # Plugin stop function
   87 plugin_stop()
   88 {
   89   # Remove old cron job (this is in case a legacy plugin left it)
   90   rm -f /etc/cron.d/dyndns-host-open
   91 
   92   iptables -D EXT_INPUT_CHAIN -j DYNDNS_CHAIN 2>/dev/null
   93 
   94   iptables -F DYNDNS_CHAIN
   95   iptables -X DYNDNS_CHAIN 2>/dev/null
   96 
   97   return 0
   98 }
   99 
  100 
  101 # Plugin status function
  102 plugin_status()
  103 {
  104   iptables -L DYNDNS_CHAIN |sed -e "s/^/$INDENT/"
  105 
  106   return 0
  107 }
  108 
  109 
  110 # Check sanity of eg. environment
  111 plugin_sanity_check()
  112 {
  113   if [ -z "$DYNDNS_HOST_OPEN_TCP" -a -z "$DYNDNS_HOST_OPEN_UDP"  -a \
  114        -z "$DYNDNS_HOST_OPEN_IP"  -a -z "$DYNDNS_HOST_OPEN_ICMP" ]; then
  115     printf "\033[40m\033[1;31m${INDENT}ERROR: The plugin config file is not (properly) setup!\033[0m\n" >&2
  116     return 1
  117   fi
  118 
  119   if [ ! -f "$JOB_HELPER_SCRIPT" ]; then
  120     printf "\033[40m\033[1;31m${INDENT}ERROR: The job helper script($JOB_HELPER_SCRIPT) can not be found!\033[0m\n" >&2
  121     return 1
  122   fi
  123 
  124   return 0
  125 }
  126 
  127 
  128 ############
  129 # Mainline #
  130 ############
  131 
  132 # Check where to find the config file
  133 CONF_FILE=""
  134 if [ -n "$PLUGIN_CONF_PATH" ]; then
  135   CONF_FILE="$PLUGIN_CONF_PATH/$PLUGIN_CONF_FILE"
  136 fi
  137 
  138 # Preinit to success:
  139 PLUGIN_RET_VAL=0
  140 
  141 # Check if the config file exists
  142 if [ ! -f "$CONF_FILE" ]; then
  143   printf "NOTE: Config file \"$CONF_FILE\" not found!\n        Plugin \"$PLUGIN_NAME v$PLUGIN_VERSION\" ignored!\n" >&2
  144 else
  145   # Source the plugin config file
  146   . "$CONF_FILE"
  147 
  148   if [ "$ENABLED" = "1" -a "$PLUGIN_CMD" != "stop-restart" ] ||
  149      [ "$ENABLED" = "0" -a "$PLUGIN_CMD" = "stop-restart" ] ||
  150      [ -n "$PLUGIN_LOAD_FILE" -a "$PLUGIN_CMD" = "stop" ] ||
  151      [ -n "$PLUGIN_LOAD_FILE" -a "$PLUGIN_CMD" = "status" ]; then
  152     # Show who we are:
  153     echo "${INDENT}$PLUGIN_NAME v$PLUGIN_VERSION"
  154 
  155     # Increment indention
  156     INDENT="$INDENT "
  157 
  158     # Only proceed if environment ok
  159     if ! plugin_sanity_check; then
  160       PLUGIN_RET_VAL=1
  161     else
  162       case $PLUGIN_CMD in
  163         start|'') plugin_start; PLUGIN_RET_VAL=$? ;;
  164         restart ) plugin_restart; PLUGIN_RET_VAL=$? ;;
  165         stop|stop-restart) plugin_stop; PLUGIN_RET_VAL=$? ;;
  166         status  ) plugin_status; PLUGIN_RET_VAL=$? ;;
  167         *       ) PLUGIN_RET_VAL=1; printf "\033[40m\033[1;31m${INDENT}ERROR: Invalid plugin option \"$PLUGIN_CMD\"!\033[0m\n" >&2 ;;
  168       esac
  169     fi
  170   fi
  171 fi