/opt/jp-secure/siteguardlite
Edit: /opt/jp-secure/siteguardlite/dbupdate_waf (5888B)
#!/bin/sh
#
# dbupdate_waf -- script for updating databases.
# -- for SiteGuard Lite
# -- use wget command to retrieve latest-lite.zip
# -- get the latest pattern file from ${LATEST_URL} to ${databasedirectory}
# -- write update log to log/dbupdate_waf.log
#
export LANG=C
PRODUCT=siteguardlite
prefix=/opt/jp-secure/siteguardlite
WGET_CMD=wget
WGET_CMD_BSD=/usr/local/bin/wget
LICENSE=`grep "^..*$" ${prefix}/conf/license.txt`
WGET_OPTION="--timeout=60 --tries=1 --cache=off --ca-certificate=${prefix}/misc/ca-cert.crt"
UNZIP_CMD=unzip
UNZIP_OPTION=-qo
LATEST_URL=https://www.jp-secure.com/download/siteguardlite/updates_lite/latest-lite.zip
updatedirectory=./update_waf
databasedirectory=./databases_waf
latestfile=${updatedirectory}/latest-lite.zip
logdir=./logs
logfile=$logdir/dbupdate_waf.log
resultfile=$logdir/dbupdate_waf_last_result.txt
tty=false
### Read Configuration file###
for var in use_proxy http_proxy_host http_proxy_port use_proxyauth http_proxyauth_user http_proxyauth_pass sig_download_user sig_download_pass ; do
eval ${var}="\`perl -ne 'if(/^${var}=(.*)/){\$v=\$1; \$v =~ s/([^\w\.\-])/chr(0x25) . sprintf(\"%02x\", ord(\$1))/eg; print \$v;}' conf/dbupdate.conf\`" # '
done
if [ -r conf/dbupdate_waf.conf ] ; then
. conf/dbupdate_waf.conf
fi
if [ "${use_proxy}" = "yes" ] ; then
if [ "${use_proxyauth}" = "yes" ];then
export https_proxy="http://${http_proxyauth_user}:${http_proxyauth_pass}@${http_proxy_host}:${http_proxy_port}/"
else
export https_proxy="http://${http_proxy_host}:${http_proxy_port}/"
fi
fi
USER_AUTH="--http-user=${sig_download_user} --http-password=${sig_download_pass}"
### Exec Local Update Command ###
if [ -r dbupdate-latest.local -a "X`basename $0`" != "Xdbupdate-latest.local" ] ; then
exec dbupdate-latest.local
fi
# Print messages to log
printlog(){
if [ -n "$logfile" ]; then
echo `date +"%b %d %H:%M:%S"` "$*" >>$logfile
fi
}
# Only print messages to stdout if it is a terminal
message(){
if $tty; then
echo "$*"
fi
}
logmessage(){
if $tty; then
echo "$*"
fi
printlog "$*"
}
error(){
if $tty; then
echo `basename $0`: "$*" >&2
fi
printlog error: "$*"
}
programinfo()
{
message "SiteGuard Lite"
message "Database Update"
message
}
usage(){
message "Usage:"
message
message "$0 [-f
|--configfile ] []"
message
exit 1
}
parsecommandline() {
conffile=""
doupdate=true
while [ "$#" != 0 ]; do
case $1 in
-v)
tty=true
;;
-f)
shift
conffile=$1
;;
--configfile)
shift
conffile=$1
;;
--help)
usage
;;
-*)
error "Invalid option $1"
usage
;;
*)
if $doupdate; then
latestfile=$1
doupdate=false
else
# We already got update directory
error "Too many arguments"
usage
fi
;;
esac
shift
done
}
programinfo
parsecommandline $*
cd $prefix || (echo "Cannot change to directory [$logdirectory]"; exit 1)
# Set update directory given from command-line.
mkdir $updatedirectory >/dev/null 2>&1
if [ ! -w $updatedirectory ]; then
error "Update directory $updatedirectory not writable. Cannot fetch database updates."
exit 1
fi
mkdir $databasedirectory >/dev/null 2>&1
if [ ! -w $databasedirectory ]; then
error "Database directory not writable. Cannot update databases."
exit 1
fi
if [ "$updatedirectory" = "$databasedirectory" ]; then
error "Can't do update from database directory: $updatedirectory"
exit 1
fi
which $WGET_CMD >/dev/null 2>&1
result=$?
if [ $result -eq 1 ]; then
if [ -x $WGET_CMD_BSD ]; then
WGET_CMD=$WGET_CMD_BSD
else
error "wget command not found."
exit 1
fi
fi
if $doupdate; then
logmessage "Fetching update from web site to $updatedirectory"
${WGET_CMD} ${WGET_OPTION} --header="License-No: ${LICENSE}" ${USER_AUTH} ${LATEST_URL} -O ${latestfile} >$resultfile 2>&1
result=$?
if egrep "[Ff]ailed:? " $resultfile >/dev/null 2>&1 ; then
result_str=`perl -ne 'print "$1\n" if/[Ff]ailed:? (.*)$/' $resultfile | head -n1`
else
result_str=`cat $resultfile | tail -n1`
fi
if [ $result != 0 ]; then
error "Database update failed. Error code: $result msg: $result_str"
echo $result_str
exit 1
fi
logmessage "Updated database files in $updatedirectory from web site."
fi
logmessage "Extracting ${latestfile}"
if ${UNZIP_CMD} -qo ${latestfile} -d "${updatedirectory}" >>$logfile 2>&1 ; then
logmessage "Databases in $updatedirectory are valid."
else
error "Database validation failed. "
exit 1
fi
if cmp -s $updatedirectory/header.ini $databasedirectory/header.ini; then
logmessage "Database file not changed."
exit 0
fi
for f in $updatedirectory/*; do \
if [ -f "$f" ] && [ "$f" != "$updatedirectory/latest-lite.zip" ]; then
if ! cp "$f" "$databasedirectory/" ; then
error "Database update failed. [cp $f $databasedirectory]"
exit 1
fi
fi
done
cp $databasedirectory/sig_official_base.txt conf/waf/
cp $databasedirectory/sig_official_date.txt conf/waf/
cp $databasedirectory/sig_official_comment.*.txt conf/waf/
if [ "X$add_monitor" != "Xyes" ]; then
add_monitor="no"
fi
if ! ( ./waf_sig_merge.pl --use-dbsettings=${use_dbsettings} --add-monitor=${add_monitor} conf/waf/sig_official.txt conf/waf/sig_official_base.txt > conf/waf/sig_official_new.txt && cp conf/waf/sig_official_new.txt conf/waf/sig_official.txt ) ; then
error "sig_merge failed."
exit 1
fi
if [ "X${service_restart}" = "Xyes" ] && egrep '^http_service=yes' conf/${PRODUCT}.ini >/dev/null; then
make reconfig >> $logfile 2>&1
fi
logmessage "Databases updated successfully."
logmessage `grep Version= $databasedirectory/header.ini 2>&1`
exit 0