generated from mjpcomp/clamav-cron-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpantimalware-cron.sh
106 lines (82 loc) · 4.16 KB
/
phpantimalware-cron.sh
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
#!/bin/bash
# =============================================================================
# - title : Scan and Report Sender for PHP-Antimalware-Scanner
# - description : Initiates a PHP-Antimalware-Scanner and sends a report
# - author : MJPComp
# - date : 2021-08-30
# - version : 2021-08-30
# - usage : bash clamav-cron.sh
# - oses : Ubuntu,Debian
# =============================================================================
# - fork : clamav-cron v. 0.8.3 - Copyright 2014, Mark Parraway
# - site : https://github.com/yangwithinyin/clamav-cron
#
# - fork : clamav-cron v. 0.6 - Copyright 2009, Stefano Stagnaro
# - site : https://code.google.com/p/clamav-cron/
#
# This is Free Software released under the GNU GPL license version 3
#
# =============================================================================
#
# Add to crontab, e.g. crontab -e
# 45 23 * * 5 /usr/local/bin/phpantimalware-cron.sh domainname.ext [email protected]
#
#============================================#
# User configuration section #
#============================================#
# Path to the PHP-Antimalware-Scanner "scanner" file (obtained from the "dist" folder from the Github repo)
PHPAS_PATH="/usr/local/bin/scanner"
# Setup the PHP-Antimalware-Scanner command line flags to use, refer to https://marcocesarato.github.io/PHP-Antimalware-Scanner/options:
PHPAS_ARGS=""
# Specify html or txt for the report:
#PHPAS_REPORT_FORMAT="html"
PHPAS_REPORT_FORMAT="txt"
# Using Virtualmin Default of /home/website.ext/public_html? Then set this to 1
PHPAS_VIRTUALMIN="1"
# Domain Name or Website Name for report subject
PHPAS_SITENAME="$1"
# If Using Virtualmin, enter the "website.ext" otherwise, the full path to scan:
PHPAS_SCANPATH="$1"
# Virtualmin path structure for websites
PHPAS_VIRTUALMIN_PATH="/home/$PHPAS_SCANPATH/public_html"
# Log file name and its path, if using Virtualmin, you can use /home/$PHPAS_SCANPATH/logs/$PHPAS_SCANPATH
# The extension will be set based on the format type above as per PHP-Antimalware-Scanner
PHPAS_LOGFILE="/home/$PHPAS_SCANPATH/logs/PHPAntiMalwareScanner-$PHPAS_SCANPATH"
# Notification e-mail sender:
PHPAS_MAILFROM="[email protected]"
PHPAS_MAILFROM_SENDER="The Administrator"
# Notification e-mail recipient, separate any additional with semicolons:
PHPAS_MAILTO="$2"
# Notification e-mail secondary recipients:
# PHPAS_MAILTO_CC="[email protected]; [email protected]"
#PHPAS_MAILTO_CC=""
# Notification e-mail subject:
PHPAS_SUBJECT="PHP Antimalware Scan report for $PHPAS_SITENAME"
#============================================#
# DO NOT EDIT DO NOT EDIT #
#============================================#
PHPAS_VERSION="2021-08-30.2214"
PHPAS_REPORT_FORMAT_EXT=".html"
if [ "$PHPAS_REPORT_FORMAT" = "txt" ]
then
PHPAS_REPORT_FORMAT_EXT=".log"
fi
#To be read on stdout (and root mail):
echo -e PHP-Antimalware-Scanner Automatic Scan v$PHPAS_VERSION - MJPComp - scanning $PHPAS_SCANPATH for $PHPAS_MAILTO'\n'
#To be read on logfile (sent via mail):
echo -e $PHPAS_SUBJECT - $(date) '\n' > "$PHPAS_LOGFILE".temp
echo -e PHP-Antimalware-Scanner Automatic Scan v$PHPAS_VERSION - MJPComp >> "$PHPAS_LOGFILE".temp
echo -e Scanned: $PHPAS_SITENAME '\n' >> "$PHPAS_LOGFILE".temp
echo -e '------------------------------------\n' >> "$PHPAS_LOGFILE".temp
php $PHPAS_PATH $PHPAS_VIRTUALMIN_PATH $PHPAS_ARGS -r --report-format $PHPAS_REPORT_FORMAT --path-report "$PHPAS_LOGFILE".scanreport --silent
lines=$(< "$PHPAS_LOGFILE".scanreport"$PHPAS_REPORT_FORMAT_EXT" wc -l)
#echo $lines
if [ "$lines" -gt "1" ]
then
cat "$PHPAS_LOGFILE".temp "$PHPAS_LOGFILE".scanreport"$PHPAS_REPORT_FORMAT_EXT" > "$PHPAS_LOGFILE".phpam
mail -s "ISSUE FOUND - $PHPAS_SUBJECT" $PHPAS_MAILTO -a From:"$PHPAS_MAILFROM_SENDER"\<$PHPAS_MAILFROM\> < "$PHPAS_LOGFILE".phpam
rm "$PHPAS_LOGFILE".temp "$PHPAS_LOGFILE".scanreport"$PHPAS_REPORT_FORMAT_EXT" "$PHPAS_LOGFILE".phpam
else
mail -s "SITE IS CLEAN - $PHPAS_SUBJECT" $PHPAS_MAILTO -a From:"$PHPAS_MAILFROM_SENDER"\<$PHPAS_MAILFROM\> < "$PHPAS_LOGFILE".temp
rm "$PHPAS_LOGFILE".temp "$PHPAS_LOGFILE".scanreport"$PHPAS_REPORT_FORMAT_EXT"
fi