/usr/sbin/fiaif-update is in fiaif 1.23.1-4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | #!/bin/bash
# FIAIF is an Intelligent firewall
#
# Startup script to add firewall functionality.
#
# Script Author: Anders Fugmann <afu at fugmann dot net>
#
# FIAIF is an Intelligent firewall
# Copyright (C) 2002-2011 Anders Peter Fugmann
# This package comes with ABSOLUTELY NO WARRANTY
# Use strictly at your own risk.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
shopt -s extglob
WEB_HOME="http://www.fiaif.net/"
WEB_VERSION="${WEB_HOME}/VERSION"
FILES="RESERVED_NETWORKS PRIVATE_NETWORKS"
WEB_RESERVED_NETWORKS="${WEB_HOME}/conf/reserved_networks"
WEB_PRIVATE_NETWORKS="${WEB_HOME}/conf/private_networks"
WGET_PARAM="--user-agent=FIAIF --quiet --cache=off"
DIFF_OPTIONS="-U 0 -bB"
source /usr/share/fiaif/constants.sh
source ${CONF_FILE}
function check_version ()
{
local RETURN
local TMP_FILE=$(mktemp /tmp/fiaif-tmp.XXXXXX)
if ! wget ${WGET_PARAM} --output-document=${TMP_FILE} ${WEB_VERSION}; then
if (( VERBOSE == 1 )); then
echo "Could not download version info from ${WEB_VERSION}"
fi
exit 1
fi
local NEW_VERSION=$(<${TMP_FILE})
local CURR_VERSION=$(<${VERSION_FILE})
local V
NEW_VERSION_NR=0
for V in ${NEW_VERSION//./ }; do
let NEW_VERSION_NR=NEW_VERSION_NR*1000+V
done
CURR_VERSION_NR=0
for V in ${CURR_VERSION//./ }; do
let CURR_VERSION_NR=CURR_VERSION_NR*1000+V
done
if (( NEW_VERSION_NR > CURR_VERSION_NR )); then
if (( VERBOSE == 1 )); then
echo "New FIAIF version ${NEW_VERSION} available."
fi
RETURN=0
else
if (( VERBOSE == 1 )); then
echo "FIAIF is up-to-date."
fi
RETURN=1
fi
rm -f ${TMP_FILE}
return ${RETURN}
}
function update_file ()
{
ORIG_FILE=$1
NEW_FILE=$2
NEW_VERSION=$3
local ANS=""
echo "New version of $(basename ${ORIG_FILE}) found."
diff ${DIFF_OPTIONS} ${ORIG_FILE} ${NEW_FILE}
if (( VERBOSE == 1 )); then
while [[ "${ANS}" != @(Y|y|N|n) ]]; do
read -p "Update $(basename ${ORIG_FILE}) to version ${NEW_VERSION} (y|n)" ANS
done
else
ANS="y"
fi
case ${ANS} in
Y|y)
echo "${ORIG_FILE} updated to version ${NEW_VERSION}"
mv -f ${ORIG_FILE} ${ORIG_FILE}.old
mv -f ${NEW_FILE} ${ORIG_FILE}
;;
N|n)
mv -f ${NEW_FILE} ${ORIG_FILE}.new
;;
esac
}
function update_networks ()
{
local FILE=$1
local WEB_FILE=WEB_${FILE}
WEB_FILE=${!WEB_FILE}
local LOCAL_FILE=${CONF_DIR}/${!FILE}
local RETURN
local TMP_FILE=$(mktemp /tmp/fiaif-tmp.XXXXXX)
if ! wget ${WGET_PARAM} --output-document=${TMP_FILE} ${WEB_FILE}; then
if (( VERBOSE == 1 )); then
echo "Could not download network info from ${WEB_FILE}"
fi
exit 1
fi
# Examine if an update is nessesary, by looking at the first line.
local V
local NEW_VERSION=$(head -n 1 ${TMP_FILE} | cut -d" " -f 4)
local NEW_VERSION_NR=0
for V in ${NEW_VERSION//./ }; do
let NEW_VERSION_NR=NEW_VERSION_NR*1000+V
done
declare -a LINE=( $(head -n 1 ${LOCAL_FILE}) )
local CURR_VERSION=$(head -n 1 ${LOCAL_FILE} | cut -d" " -f 4)
local CURR_VERSION_NR=0
for V in ${CURR_VERSION//./ }; do
let CURR_VERSION_NR=CURR_VERSION_NR*1000+V
done
if (( NEW_VERSION_NR > CURR_VERSION_NR )); then
update_file ${LOCAL_FILE} ${TMP_FILE} ${NEW_VERSION}
RETURN=0
else
if (( VERBOSE == 1 )); then
echo "${FILE} is up-to-date."
fi
RETURN=1
fi
rm -f ${TMP_FILE}
return ${RETURN}
}
function usage ()
{
echo "Usage: $0 [--silent] [--help] <check|update>"
}
# Read all options
VERBOSE=1
while [[ "${1:0:2}" == "--" ]]; do
case $1 in
--silent)
VERBOSE=0
;;
--help)
usage
exit 0
;;
*)
echo "Unknown option: '$1'"
;;
esac
shift 1
done
case $1 in
check)
check_version
;;
update)
RETURN=1
for FILE in ${FILES}; do
if update_networks ${FILE}; then
RETURN=0
fi
done
exit ${RETURN}
;;
*)
usage
;;
esac
|