3 ## Samba-VirusFilter VFS modules
4 ## Copyright (C) 2010-2016 SATOH Fumiyasu @ OSS Technology Corp., Japan
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
22 pdie() { echo "$0: ERROR: ${1-}" 1>&2; exit "${2-1}"; }
24 ## ======================================================================
26 sendmail="${VIRUSFILTER_NOTIFY_SENDMAIL_COMMAND:-/usr/sbin/sendmail}"
27 sendmail_opts="${VIRUSFILTER_NOTIFY_SENDMAIL_OPTIONS:-}"
29 smbclient="${VIRUSFILTER_NOTIFY_SMBCLIENT_COMMAND:-@SAMBA_BINDIR@/smbclient}"
30 smbclient_opts="${VIRUSFILTER_NOTIFY_SMBCLIENT_OPTIONS:-}"
32 ## ======================================================================
34 if [ -n "${VIRUSFILTER_RESULT_IS_CACHE-}" ]; then
35 ## Result is cache. Ignore!
39 if [ ! -t 1 ] && [ -z "${VIRUSFILTER_NOTIFY_BG-}" ]; then
40 export VIRUSFILTER_NOTIFY_BG=1
41 "$0" ${1+"$@"} </dev/null >/dev/null &
45 ## ----------------------------------------------------------------------
47 if [ -n "${VIRUSFILTER_INFECTED_FILE_ACTION-}" ]; then
48 report="$VIRUSFILTER_INFECTED_FILE_REPORT"
50 report="$VIRUSFILTER_SCAN_ERROR_REPORT"
53 if [ X"$VIRUSFILTER_SERVER_NAME" != X"$VIRUSFILTER_SERVER_IP" ]; then
54 server_name="$VIRUSFILTER_SERVER_NAME"
56 server_name="$VIRUSFILTER_SERVER_NETBIOS_NAME"
59 if [ X"$VIRUSFILTER_CLIENT_NAME" != X"$VIRUSFILTER_CLIENT_IP" ]; then
60 client_name="$VIRUSFILTER_CLIENT_NAME"
62 client_name="$VIRUSFILTER_CLIENT_NETBIOS_NAME"
72 content_type="text/plain"
73 content_encoding="UTF-8"
75 cmd_usage="Usage: $0 [OPTIONS]
79 Send a notice message to this e-mail address(es)
81 Send a \"WinPopup\" message to this NetBIOS name
83 Envelope sender address for mail
85 From: e-mail address for mail
87 Cc: e-mail address(es) for mail
89 Bcc: e-mail address(es) for mail
90 --subject-prefix PREFIX
91 Subject: prefix string for mail
93 --content-encoding ENCODING
94 Content-Type: TYPE; charset=\"ENCODING\" for mail [$content_type; charset=\"$content_encoding\"]
96 Prepend the content of FILE to the message
98 Append the content of FILE to the message
101 ## ----------------------------------------------------------------------
105 if [ "$#" -lt 2 ]; then
106 pdie "Option requires an argument: $1"
108 if [ "$#" -ge 3 ]; then
109 if expr x"$2" : x"$3\$" >/dev/null; then
112 pdie "Invalid value for option: $1 $2"
117 while [ "$#" -gt 0 ]; do
125 getopts_want_arg "$OPT" ${1+"$1"}
126 mail_to="${mail_to:+$mail_to, }$1"; shift
129 getopts_want_arg "$OPT" ${1+"$1"}
130 winpopup_to="$1"; shift
133 getopts_want_arg "$OPT" ${1+"$1"}
137 getopts_want_arg "$OPT" ${1+"$1"}
141 getopts_want_arg "$OPT" ${1+"$1"}
142 cc="${cc:+$cc, }$1"; shift
145 getopts_want_arg "$OPT" ${1+"$1"}
146 bcc="${bcc:+$bcc, }$1"; shift
149 getopts_want_arg "$OPT" ${1+"$1"}
150 subject_prefix="$1"; shift
153 getopts_want_arg "$OPT" ${1+"$1"}
154 content_type="$1"; shift
157 getopts_want_arg "$OPT" ${1+"$1"}
158 content_encoding="$1"; shift
161 getopts_want_arg "$OPT" ${1+"$1"}
162 header_file="$1"; shift
165 getopts_want_arg "$OPT" ${1+"$1"}
166 footer_file="$1"; shift
172 pdie "Invalid option: $OPT"
175 set -- "$OPT" ${1+"$@"}
181 [ -z "$sender" ] && sender="$from"
182 subject="$subject_prefix$report"
184 ## ======================================================================
188 Content-Type: $content_type; charset=$content_encoding
189 X-VIRUSFILTER-Version: $VIRUSFILTER_VERSION
190 X-VIRUSFILTER-Module-Name: $VIRUSFILTER_MODULE_NAME
193 if [ -n "${VIRUSFILTER_MODULE_VERSION-}" ]; then
194 msg_header="${msg_header}\
195 X-VIRUSFILTER-Module-Version: $VIRUSFILTER_MODULE_VERSION
199 if [ -n "${from-}" ]; then
200 msg_header="${msg_header}\
205 if [ -n "${mail_to-}" ]; then
206 msg_header="${msg_header}\
211 if [ -n "${cc-}" ]; then
212 msg_header="${msg_header}\
217 if [ -n "${bcc-}" ]; then
218 msg_header="${msg_header}\
223 ## ----------------------------------------------------------------------
227 if [ -n "${header_file-}" ] && [ -f "$header_file" ]; then
228 msg_body="${msg_body}\
233 msg_body="${msg_body}\
234 Server: $server_name ($VIRUSFILTER_SERVER_IP)
235 Server PID: $VIRUSFILTER_SERVER_PID
236 Service name: $VIRUSFILTER_SERVICE_NAME
237 Service path: $VIRUSFILTER_SERVICE_PATH
238 Client: $client_name ($VIRUSFILTER_CLIENT_IP)
239 User: $VIRUSFILTER_USER_DOMAIN\\$VIRUSFILTER_USER_NAME
242 if [ -n "${VIRUSFILTER_INFECTED_FILE_ACTION-}" ]; then
243 msg_body="${msg_body}\
244 Infected file report: $VIRUSFILTER_INFECTED_FILE_REPORT
246 msg_body="${msg_body}\
247 Infected file path: $VIRUSFILTER_SERVICE_PATH/$VIRUSFILTER_INFECTED_SERVICE_FILE_PATH
249 msg_body="${msg_body}\
250 Infected file action: $VIRUSFILTER_INFECTED_FILE_ACTION
253 msg_body="${msg_body}\
254 Scan error report: $VIRUSFILTER_SCAN_ERROR_REPORT
255 Scan error file path: $VIRUSFILTER_SERVICE_PATH/$VIRUSFILTER_SCAN_ERROR_SERVICE_FILE_PATH
259 if [ -n "${VIRUSFILTER_QUARANTINED_FILE_PATH-}" ]; then
260 msg_body="${msg_body}\
261 Quarantined/Renamed file path: ${VIRUSFILTER_QUARANTINED_FILE_PATH-}
265 if [ -n "${footer_file-}" ] && [ -f "$footer_file" ]; then
266 msg_body="${msg_body}\
271 ## ======================================================================
273 if [ -n "$mail_to" ]; then
274 (echo "$msg_header"; echo "$msg_body") \
275 |"$sendmail" -t -i ${sender:+-f "$sender"} $sendmail_opts
278 if [ -n "$winpopup_to" ]; then
280 |"$smbclient" -M "$winpopup_to" -U% $smbclient_opts \