#!/bin/sh # -*- coding: utf-8 -*- # vim: ai ts=4 sts=4 et sw=4 # 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 3 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, see . # # This file was forked from MailScanner in June 2020. # Original author, and relevant copyright and licensing information is below: # :author: Julian Field # :copyright: Copyright (C) 2002 Julian Field # PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/etc:/usr/local/bin:/usr/sfw/bin export PATH DOWNLOAD_URL=https://datafeeds.baruwa.com/phishing.safe.sites/phishing.safe.sites.conf.master CONFIGDIR=/etc/BaruwaScanner RUN_UPDATE=0 MASTER_FILE=phishing.safe.sites.conf.master if [ -d $CONFIGDIR ]; then cd $CONFIGDIR || { echo Failed to cd into $CONFIGDIR exit } else logger -p mail.warn -t update.phishing.sites Cannot find BaruwaScanner configuration directory, update failed. echo Cannot find BaruwaScanner configuration directory. echo Auto-updates of phishing.safe.sites.conf will not happen. exit 1 fi # Sanity check for custom file, exit if not a regular file. [ -e "$CONFIGDIR/phishing.safe.sites.custom" ] && [ ! -f "$CONFIGDIR/phishing.safe.sites.custom" ] && { echo $CONFIGDIR/phishing.safe.sites.custom exists and is not a regular file. echo Auto-updates of phishing.safe.sites.conf will not happen. exit 2 } [ ! -f "$CONFIGDIR/phishing.safe.sites.custom" ] && { touch "$CONFIGDIR/phishing.safe.sites.custom" logger -p mail.info -t update.phishing.sites created $CONFIGDIR/phishing.safe.sites.custom } if [ -f phishing.safe.sites.conf ]; then ts=$(date --rfc-2822 -d "$(stat -c %y phishing.safe.sites.conf)") curl -O -z "$ts" $DOWNLOAD_URL else curl -O $DOWNLOAD_URL fi if [ -s phishing.safe.sites.conf.master ]; then logger -p mail.info -t update.phishing.sites new phishing.safe.sites.conf.master downloaded sort -u phishing.safe.sites.custom | grep -Ev '((^(\s+)?#)|(^(\s+)?\.)|(\*))' > phishing.safe.sites.custom.tmp RUN_UPDATE=1 else os=$(stat -c %Y phishing.safe.sites.conf) cs=$(stat -c %Y phishing.safe.sites.custom) if [ "$cs" -ge "$os" ]; then logger -p mail.info -t update.phishing.sites phishing.safe.sites.custom updated MASTER_FILE=phishing.safe.sites.conf.master.old sort -u phishing.safe.sites.custom | grep -Ev '((^(\s+)?#)|(^(\s+)?\.)|(\*))' > phishing.safe.sites.custom.tmp RUN_UPDATE=1 fi fi if [ "$RUN_UPDATE" = "1" ]; then if [ ! -f $MASTER_FILE ]; then echo Master file $MASTER_FILE not found echo Auto-updates of phishing.safe.sites.conf will not happen. exit 3 fi grep '#' $MASTER_FILE > $MASTER_FILE.head grep -v '#' $MASTER_FILE > $MASTER_FILE.body cat $MASTER_FILE.body phishing.safe.sites.custom.tmp | \ sort | uniq > phishing.safe.sites.conf.new [ -f phishing.safe.sites.conf ] && cp -f phishing.safe.sites.conf phishing.safe.sites.conf.old cat $MASTER_FILE.head phishing.safe.sites.conf.new > phishing.safe.sites.conf chmod a+r phishing.safe.sites.conf logger -p mail.info -t update.phishing.sites Phishing safe sites list updated else logger -p mail.info -t update.phishing.sites Phishing safe sites list update skipped! fi [ -f phishing.safe.sites.conf.master ] && mv -f phishing.safe.sites.conf.master phishing.safe.sites.conf.master.old [ -f phishing.safe.sites.custom.tmp ] && rm -f phishing.safe.sites.custom.tmp [ -f $MASTER_FILE.head ] && rm -f $MASTER_FILE.head [ -f $MASTER_FILE.body ] && rm -f $MASTER_FILE.body [ -f phishing.safe.sites.conf.new ] && rm -f phishing.safe.sites.conf.new exit 0