Subversion Repositories livecd

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 beyerle@PS 1
#!/bin/bash
2
#
3
################################################################
4
#
5
# Virus Scanner GUI for 
6
#
7
# - f-prot 
8
# - uvscan (McAfee)
9
# - clamscan
10
#
11
################################################################
12
#
169 beyerle@PS 13
# Urs Beyerle
1 beyerle@PS 14
#
15
# (some parts taken from f-prot_gui.sh by Fabian Franz)
16
#
17
################################################################
18
#
19
MyVersion=0.3
20
#
21
################################################################
22
 
23
 
24
clean_exit()
25
{
26
  rm -rf /tmp/psi-scanvirus.$$
27
}
28
 
29
trap "clean_exit" EXIT
30
 
31
### ------------------------------------------------------------
32
### definitions
33
### ------------------------------------------------------------
34
 
35
### scan engine list
36
ENGINE_LIST=""
37
 
38
### fprot
39
FPROT=$(which f-prot)
40
if [ $FPROT ]; then
41
    FPROT_NAME="F-Prot"
42
    FPROT_OPT="-all -ai -archive -dumb -packed -list"
43
    FPROT_CHECKUPDATES=/usr/local/f-prot/tools/check-updates.pl
44
    FPROT_ON="1"
45
    ENGINE_LIST="$ENGINE_LIST $FPROT_NAME $FPROT On"    
46
fi
47
 
48
### uvscan (McAfee)
49
UVSCAN=$(which uvscan)
50
if [ $UVSCAN ]; then
51
    UVSCAN_NAME="McAfee"
52
    UVSCAN_OPT="--secure -v -r --summary"
53
    UVSCAN_CHECKUPDATES=/usr/local/uvscan/update-dat
54
    UVSCAN_ON="1"
55
    ENGINE_LIST="$ENGINE_LIST $UVSCAN_NAME $UVSCAN On"
56
fi
57
 
58
### clamscan (Clam)
59
CLAM=$(which clamscan)
60
if [ $CLAM ]; then
61
    CLAM_NAME="Clam"
62
    CLAM_OPT="-r"
63
    if [ -x /usr/bin/psi-freshclam ]; then
64
	CLAM_CHECKUPDATES=/usr/bin/psi-freshclam
65
    else
66
	CLAM_CHECKUPDATES=/usr/bin/freshclam
67
    fi
68
    CLAM_ON="1"
69
    ENGINE_LIST="$ENGINE_LIST $CLAM_NAME $CLAM On"
70
    # Starting Clam AntiVirus Daemon
71
    /etc/init.d/clamd start >/dev/null
72
fi
73
 
74
### tmpdir
75
TMPDIR=/tmp/psi-scanvirus.$$
76
TMP=$TMPDIR/dialog
77
mkdir -p $TMPDIR
78
 
79
### report dir
80
REPORT_DIR="/var/log/psi-scanvirus"
81
mkdir -p /var/log/psi-scanvirus
82
 
83
### dialog or xdialog?
84
DIALOG="dialog"
85
XDIALOG_HIGH_DIALOG_COMPAT=1
86
export XDIALOG_HIGH_DIALOG_COMPAT
87
[ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"; XDIALOG="yes"
88
 
89
### title
90
TITLE="PSI Virus Scanner v$MyVersion"
91
MENU_TITLE="PSI Virus Scanner v$MyVersion"
92
 
93
### need root rights to run!
94
### ------------------------------------------------------------
95
if [ "$UID" -ne "0" ]; then
96
    MESSAGE0="To use this program, you need to be root"
97
    $DIALOG --title "$TITLE" --msgbox "$MESSAGE0" 0 0
98
    exit 1
99
fi
100
 
101
 
102
 
103
### ------------------------------------------------------------
104
### functions
105
### ------------------------------------------------------------
106
 
107
 
108
psi-freshclam()
109
### ------------------------------------------------------------
110
{
111
 
112
echo
113
echo "***************************************"
114
echo "* Clam Antivirus Updater            *"
115
echo "***************************************"
116
echo
117
echo "Run /usr/bin/freshclam:"
118
/usr/bin/freshclam
119
echo
120
 
121
}
122
 
123
### ------------------------------------------------------------
124
welcome_message()
125
{
126
    WELCOME_MESSAGE=$( cat <<EOF
127
--------------------------------------------\n
128
Welcome to PSI Virus Scanner v$MyVersion\n
129
--------------------------------------------\n
130
PLEASE NOTE: No files will be delete.\n
131
\n
132
Press OK to continue\n
133
EOF)
134
    [ $XDIALOG ] && echo $TITLE
135
    $DIALOG --title "$TITLE" --infobox "$WELCOME_MESSAGE" 0 0 8
136
    [ $? -ne 0 ] && exit
137
}
138
 
139
 
140
### ------------------------------------------------------------
141
find_partitions()
142
{
143
    PART_ALL=$(LC_ALL=C fdisk -l | sed 's/*//g' | egrep -v "swap|Extended|Ext." | awk '{ print $1 }' | grep "/dev/")
144
    PART_LIST=$(LC_ALL=C fdisk -l | sed 's/*//g' | egrep -v "swap|Extended|Ext." | awk '{ printf("%s %s-Partition off\n",$1,$6 $7 $8 $9) }' | grep "/dev/")
145
    # add "Select all"
146
    PART_LIST="$PART_LIST Select All off"
147
}
148
 
149
 
150
### ------------------------------------------------------------
151
choose_parts()
152
{
153
    MESSAGE2="Found partitions"
154
    $DIALOG --title "$TITLE" --checklist "$MESSAGE2" 0 0 0 $PART_LIST 2>$TMP
155
    PARTS=$(sed 's,",,g;s,//, /,g' $TMP)
156
    # all selected ?
157
    grep -q "Select" $TMP
158
    if [ "$?" = "0" ]; then
159
	PARTS=$PART_ALL
160
    fi
161
    [ $XDIALOG ] && echo "Partition(s) selected:"
162
    [ $XDIALOG ] && echo $PARTS
163
    [ -n "$PARTS" ] && FILES=""
164
}
165
 
166
 
167
### ------------------------------------------------------------
168
choose_dirfile()
169
{ 
170
    $DIALOG --title $TITLE --fselect "$(pwd)/" 0 0 2>$TMP
171
    FILES=$(cat $TMP)
172
    [ -n "$FILES" ] && PARTS=""
173
}
174
 
175
 
176
### ------------------------------------------------------------
177
choose_engine()
178
{
179
    MESSAGE_ENGINE="Available Virus Scan Engine(s)"
180
    $DIALOG --title "$TITLE" --checklist "$MESSAGE_ENGINE" 0 0 4 $ENGINE_LIST 2>$TMP
181
    # create new engine list
182
    ENGINE_LIST=""
183
 
184
    # deselect f-prot ?
185
    grep -q $FPROT_NAME $TMP
186
    if [ "$?" = "0" ]; then
187
	ENGINE_LIST="$ENGINE_LIST $FPROT_NAME $FPROT On";  FPROT_ON="1"
188
    else
189
	ENGINE_LIST="$ENGINE_LIST $FPROT_NAME $FPROT Off"; FPROT_ON=""
190
 
191
    fi
192
 
193
    # deselect uvscan ?
194
    grep -q $UVSCAN_NAME $TMP
195
    if [ "$?" = "0" ]; then
196
	ENGINE_LIST="$ENGINE_LIST $UVSCAN_NAME $UVSCAN On";  UVSCAN_ON="1"
197
    else
198
	ENGINE_LIST="$ENGINE_LIST $UVSCAN_NAME $UVSCAN Off"; UVSCAN_ON=""
199
    fi
200
 
201
    # deselect clamscan ?
202
    grep -q $CLAM_NAME $TMP
203
    if [ "$?" = "0" ]; then
204
	ENGINE_LIST="$ENGINE_LIST $CLAM_NAME $CLAM On";  CLAM_ON="1"
205
    else
206
	ENGINE_LIST="$ENGINE_LIST $CLAM_NAME $CLAM Off"; CLAM_ON=""
207
    fi
208
}
209
 
210
### ------------------------------------------------------------
211
define_report()
212
{
213
    DATE=$(date +"%Y-%m-%d")
214
    DIVIDER="------------------------------------------------------------------------------------------"
215
    DOTS=".........\n.........\n........."
216
 
217
    ### where to report
218
    REPORT_TMP=$REPORT_DIR/report.tmp
219
    rm -rf $REPORT_TMP
220
    touch $REPORT_TMP
221
    NR=$(ls $REPORT_DIR/$PREFIX* 2>/dev/null | wc -l | tr -d " ")
222
 
223
    if [ $FPROT_ON ]; then
224
	FPROT_REPORT="$REPORT_DIR/report_fprot-$DATE-$NR.txt"
225
	FPROT_REPORT_MIN="$REPORT_DIR/report_fprot-$DATE-$NR.min.txt"
226
	echo $DIVIDER > $FPROT_REPORT
227
	echo "F-Prot Report:" >> $FPROT_REPORT
228
	cat $FPROT_REPORT > $FPROT_REPORT_MIN	
229
    fi
230
 
231
    if [ $UVSCAN_ON ]; then
232
	UVSCAN_REPORT="$REPORT_DIR/report_mcafee-$DATE-$NR.txt"
233
	UVSCAN_REPORT_MIN="$REPORT_DIR/report_mcafee-$DATE-$NR.min.txt"
234
	echo $DIVIDER > $UVSCAN_REPORT
235
	echo "McAfee Report:" >> $UVSCAN_REPORT
236
	echo $DIVIDER >> $UVSCAN_REPORT
237
	$UVSCAN --version >> $UVSCAN_REPORT
238
	cat $UVSCAN_REPORT > $UVSCAN_REPORT_MIN	
239
    fi
240
 
241
    if [ $CLAM_ON ]; then
242
	CLAM_REPORT="$REPORT_DIR/report_clam-$DATE-$NR.txt"
243
	CLAM_REPORT_MIN="$REPORT_DIR/report_clam-$DATE-$NR.min.txt"
244
	echo $DIVIDER > $CLAM_REPORT
245
	echo "Clam Report:" >> $CLAM_REPORT
246
	echo $DIVIDER >> $CLAM_REPORT
247
	$CLAM --version >> $CLAM_REPORT
248
	cat $CLAM_REPORT > $CLAM_REPORT_MIN	
249
    fi
250
}
251
 
252
 
253
### ------------------------------------------------------------
254
report_fprot()
255
{
256
    [ $XDIALOG ] && echo -n "Creating F-Prot report... "
257
 
258
    # create report (normal and min)
259
    # normal report
260
    echo $DIVIDER >> $FPROT_REPORT
261
    echo $PART_TOSCAN >> $FPROT_REPORT
262
    echo $DIVIDER >> $FPROT_REPORT
263
    cat $REPORT_TMP >> $FPROT_REPORT
264
    echo $DIVIDER >> $FPROT_REPORT
265
    echo >> $FPROT_REPORT
266
 
267
    # min report
268
    echo $DIVIDER >> $FPROT_REPORT_MIN
269
    echo $PART_TOSCAN >> $FPROT_REPORT_MIN
270
    echo $DIVIDER >> $FPROT_REPORT_MIN
271
    head -n 25 $REPORT_TMP >> $FPROT_REPORT_MIN
272
    echo -e $DOTS >> $FPROT_REPORT_MIN
273
    tail -n 20 $REPORT_TMP >> $FPROT_REPORT_MIN	      
274
    echo $DIVIDER >> $FPROT_REPORT_MIN
275
    grep " Infection: " $REPORT_TMP >> $FPROT_REPORT_MIN
276
    grep " Infection: " $REPORT_TMP
277
    if [ "$?" = "0" ]; then
278
	echo "VIRUS INFECTION FOUND !!!" >> $FPROT_REPORT_MIN
279
	[ $XDIALOG ] && echo "VIRUS INFECTION FOUND !!!"
280
	echo $DIVIDER >> $FPROT_REPORT_MIN
281
    fi 
282
    echo >> $FPROT_REPORT_MIN
283
 
284
    rm -f $REPORT_TMP
285
    touch $REPORT_TMP
286
 
287
    [ $XDIALOG ] && echo " done."
288
}
289
 
290
 
291
### ------------------------------------------------------------
292
report_uvscan()
293
{
294
    [ $XDIALOG ] && echo -n "Creating McAfee report... "
295
 
296
    # create report (normal and min)
297
    # normal report
298
    echo $DIVIDER >> $UVSCAN_REPORT
299
    echo $PART_TOSCAN >> $UVSCAN_REPORT
300
    echo $DIVIDER >> $UVSCAN_REPORT
301
    cat $REPORT_TMP >> $UVSCAN_REPORT
302
    echo $DIVIDER >> $UVSCAN_REPORT
303
    echo >> $UVSCAN_REPORT
304
 
305
    # min report
306
    echo $DIVIDER >> $UVSCAN_REPORT_MIN
307
    echo $PART_TOSCAN >> $UVSCAN_REPORT_MIN
308
    echo $DIVIDER >> $UVSCAN_REPORT_MIN
309
    head -n 10 $REPORT_TMP >> $UVSCAN_REPORT_MIN
310
    echo -e $DOTS >> $UVSCAN_REPORT_MIN
311
    tail -n 12 $REPORT_TMP >> $UVSCAN_REPORT_MIN	      
312
    echo $DIVIDER >> $UVSCAN_REPORT_MIN
313
    grep " Found: " $REPORT_TMP >> $UVSCAN_REPORT_MIN
314
    grep " Found: " $REPORT_TMP
315
    if [ "$?" = "0" ]; then
316
	echo "VIRUS INFECTION FOUND !!!" >> $UVSCAN_REPORT_MIN
317
	[ $XDIALOG ] && echo "VIRUS INFECTION FOUND !!!"
318
	echo $DIVIDER >> $UVSCAN_REPORT_MIN
319
    fi 
320
    echo >> $UVSCAN_REPORT_MIN
321
 
322
    rm -f $REPORT_TMP
323
    touch $REPORT_TMP
324
 
325
    [ $XDIALOG ] && echo " done."
326
}
327
 
328
 
329
### ------------------------------------------------------------
330
report_clam()
331
{
332
    [ $XDIALOG ] && echo -n "Creating Clam report... "
333
 
334
    # create report (normal and min)
335
    # normal report
336
    echo $DIVIDER >> $CLAM_REPORT
337
    echo $PART_TOSCAN >> $CLAM_REPORT
338
    echo $DIVIDER >> $CLAM_REPORT
339
    cat $REPORT_TMP >> $CLAM_REPORT
340
    echo $DIVIDER >> $CLAM_REPORT
341
    echo >> $CLAM_REPORT
342
 
343
    # min report
344
    echo $DIVIDER >> $CLAM_REPORT_MIN
345
    echo $PART_TOSCAN >> $CLAM_REPORT_MIN
346
    echo $DIVIDER >> $CLAM_REPORT_MIN
347
    head -n 5 $REPORT_TMP >> $CLAM_REPORT_MIN
348
    echo -e $DOTS >> $CLAM_REPORT_MIN
349
    tail -n 15 $REPORT_TMP >> $CLAM_REPORT_MIN	      
350
    echo $DIVIDER >> $CLAM_REPORT_MIN
351
    grep " FOUND$" $REPORT_TMP >> $CLAM_REPORT_MIN
352
    grep " FOUND$" $REPORT_TMP
353
    if [ "$?" = "0" ]; then
354
	echo "VIRUS INFECTION FOUND !!!" >> $CLAM_REPORT_MIN
355
	[ $XDIALOG ] && echo "VIRUS INFECTION FOUND !!!"
356
	echo $DIVIDER >> $CLAM_REPORT_MIN
357
    fi 
358
    echo >> $CLAM_REPORT_MIN
359
 
360
    rm -f $REPORT_TMP
361
    touch $REPORT_TMP
362
 
363
    [ $XDIALOG ] && echo " done."
364
}
365
 
366
 
367
### ------------------------------------------------------------
368
show_reports()
369
{
370
    ### show report 
371
    [ $FPROT_ON ]  && $DIALOG  --title "$TITLE: F-Prot Small Report" \
372
                           --textbox $FPROT_REPORT_MIN 0 0
373
    [ $UVSCAN_ON ] && $DIALOG --title "$TITLE: McAfee Small Report" \
374
                           --textbox $UVSCAN_REPORT_MIN 0 0
375
    [ $CLAM_ON ]   && $DIALOG --title "$TITLE: Clam Small Report" \
376
                           --textbox $CLAM_REPORT_MIN 0 0
377
 
378
    ### info about report files
379
    REPORT_MESSAGE="\nVirus Scan Reports can be found in $REPORT_DIR\n"
380
    $DIALOG --title "$TITLE" --no-close --infobox "$REPORT_MESSAGE" 0 0 5
381
    [ $XDIALOG ] && echo -e "$REPORT_MESSAGE"
382
 
383
}
384
 
385
 
386
### ------------------------------------------------------------
387
scan()
388
{
389
    if [ -z "$PARTS" -a -z "$FILES" ]; then
390
	MESSAGE3="Please select partition(s) or directory/file first."
391
	$DIALOG --title "$TITLE" --msgbox "$MESSAGE3" 0 0
392
	return
393
    fi
394
 
395
    if [ -z "$SCAN_WITH" ]; then
396
	MESSAGE_SORRY="Sorry, either no scan engine selected or available."
397
	$DIALOG --title "$TITLE" --msgbox "$MESSAGE_SORRY" 0 0
398
	return
399
    fi
400
 
401
    ### mount partitions
402
    TOSCAN=""
403
    for i in $PARTS; do
404
	mkdir -p /mnt/${i/\/dev\//}
405
	# first umount
406
	umount $i 2>/dev/null
407
	mount -o "ro" $i /mnt/${i/\/dev\//}
408
	if [ "$?" != "0" ]; then
409
	    MESSAGE_UMOUNT="Partiton $i could not be mounted."
410
	    $DIALOG --title "$TITLE" --msgbox "$MESSAGE_UMOUNT" 0 0
411
	fi
412
	TOSCAN="$TOSCAN /mnt/${i/\/dev\//}"
413
    done
414
    TOSCAN="$TOSCAN $FILES"
415
 
416
    MESSAGE4="Scanning files on"
417
    MESSAGE5="Searching for files, that will be scanned ..."
418
 
419
    ### define where to report
420
    define_report
421
 
422
    ### watch $REPORT_TMP
423
    if [ $XDIALOG ]; then 
424
	xterm -sb -title "tail -F $REPORT_TMP" -e tail -F $REPORT_TMP &
425
    fi
426
 
427
    ### scan each partition
428
    for PART_TOSCAN in $TOSCAN; do
429
 
430
	[ $XDIALOG ] && echo "Scanning $PART_TOSCAN... "
431
 
432
	### scan with FPROT
433
	if [ $FPROT_ON ]; then
434
 
435
	    {   max=$(find $PART_TOSCAN -type f | wc -l )
436
		echo -e "XXX\nF-Prot: $MESSAGE4: $PART_TOSCAN\nXXX"
437
		$FPROT $FPROT_OPT -report=$REPORT_TMP $PART_TOSCAN | grep "^$PART_TOSCAN" | sed 's/->.*//g' | uniq | while read a; do count=$[count+1]; echo $[count*100/max]; done 
438
	    } | $DIALOG --title "$TITLE" --gauge "$MESSAGE5 $PART_TOSCAN" 10 40
439
 
440
	    report_fprot
441
	fi
442
 
443
	### scan with UVSCAN (McAfee)
444
	if [ $UVSCAN_ON ]; then
445
 
446
	    {   max=$(find $PART_TOSCAN | wc -l )
447
		echo -e "XXX\nMcAfee: $MESSAGE4: $PART_TOSCAN\nXXX"
448
		$UVSCAN $UVSCAN_OPT $PART_TOSCAN 2>/dev/null | tee $REPORT_TMP 2>/dev/null | grep "^Scanning" | grep -v "\.zip" | grep -v "\.tar" | grep -v ".\tgz" | while read a; do count=$[count+1]; echo $[count*100/max]; done 
449
	    } | $DIALOG --title "$TITLE" --gauge "$MESSAGE5 $PART_TOSCAN" 10 40
450
 
451
	    report_uvscan
452
	fi
453
 
454
	### scan clamscan (Clam)
455
	if [ $CLAM_ON ]; then
456
 
457
	    {   max=$(find $PART_TOSCAN -type f | wc -l )
458
		echo -e "XXX\nClam: $MESSAGE4: $PART_TOSCAN\nXXX"
459
		$CLAM $CLAM_OPT $PART_TOSCAN 2>/dev/null | tee $REPORT_TMP 2>/dev/null | grep "^$PART_TOSCAN" | while read a; do count=$[count+1]; echo $[count*100/max]; done 
460
	    } | $DIALOG --title "$TITLE" --gauge "$MESSAGE5 $PART_TOSCAN" 10 40
461
 
462
	    report_clam
463
	fi
464
 
465
    done
466
 
467
    ### unmount partitions
468
    for i in $PARTS; do
469
	umount /mnt/${i/\/dev\//}
470
    done
471
 
472
    ### show reports
473
    show_reports
474
 
475
}
476
 
477
shutdown () 
478
{
479
    $DIALOG --title "$TITLE" --radiolist "Reboot or shutdown the PC?" 0 0 3 poweroff "" on reboot "" off 2>$TMP
480
    ACTION=$(cat $TMP)
481
    if [ $ACTION ]; then
482
	$ACTION
483
	exit 1
484
    fi
485
}
486
 
487
online_update ()
488
{
489
    # remove old temporary dir
490
    rm -rf /var/tmp/f-prot
491
    if [ -n "$DISPLAY" ]; then
492
	xterm -sb -e "$FPROT_CHECKUPDATES; $UVSCAN_CHECKUPDATES; $CLAM_CHECKUPDATES; echo 'Press a key to continue ...'; read -n1"
493
    else
494
	$FPROT_CHECKUPDATES; $UVSCAN_CHECKUPDATES; $CLAM_CHECKUPDATES; echo 'Press a key to continue ...'; read -n1
495
    fi
496
    rm -rf /var/tmp/f-prot
497
 
498
 
499
}
500
 
501
### ------------------------------------------------------------
502
### Main Program
503
### ------------------------------------------------------------
504
 
505
### find partitons
506
find_partitions
507
 
508
### print welcome message
509
welcome_message
510
 
511
### menu
512
### ------------------------------------------------------------
513
 
514
MENU_1="Select partition(s)"
515
MENU_2="(or: Select a directory/file)"
516
MENU_3="Choose Scan Engine(s)"
517
MENU_4="Start Scanning"
518
MENU_5="Do Online-Update"
519
MENU_6="Reboot/Shutdown"
520
MENU_7="Quit"
521
 
522
while true; do
523
 
524
    SCAN_WITH=""
525
    [ $FPROT_ON ]  && SCAN_WITH=" $FPROT_NAME"
526
    [ $UVSCAN_ON ] && SCAN_WITH="$SCAN_WITH $UVSCAN_NAME"
527
    [ $CLAM_ON ] && SCAN_WITH="$SCAN_WITH $CLAM_NAME"
528
 
529
    $DIALOG --title "$TITLE" \
530
	--menu "$MENU_TITLE" 0 0 7\
531
	1 "$MENU_1"\
532
	2 "$MENU_2"\
533
	3 "$MENU_3" \
534
	4 "$MENU_4 (with$SCAN_WITH)" \
535
	5 "$MENU_5" \
536
	6 "$MENU_6" \
537
	7 "$MENU_7" \
538
	2> $TMP
539
 
540
    [ $? -ne 0 ] && break
541
 
542
    CHOICE=$(cat $TMP)
543
 
544
    case "$CHOICE" in
545
     1)
546
      choose_parts
547
      ;;
548
     2)
549
      choose_dirfile
550
      ;;
551
     3)
552
      choose_engine
553
      ;;
554
     4)
555
      scan
556
      ;;
557
     5)
558
      online_update
559
      ;;
560
     6)
561
      shutdown || break
562
      ;;
563
     7)
564
      break
565
      ;;
566
    esac
567
done