#!/bin/bash # # fp.dialog (C) 2001 Malte J. Wetz # # A dialog-based frontend to f-prot command line virus scanner for linux. # # This script allows you to launch f-prot, a virus scanner for linux, and # configure its command line parameters via a dialog-interface. # # Current beta versions of F-Prot are freely available from http://www.frisk.is # # TODO: # - Perhaps it would be nice if output of f-prot could be parsed back into # fp.linux and evaluated. # - Altough it may be ironical to add command line options to a frontend # for a command line program, some people might want to have them. We'll # see about that. # - Possibilty to store profiles in a unique repository. # # # Please note that this script allow you to setup all options that f-prot # claims to allow (use 'f-prot -h' to see them). However, some options that # appear in that help text, are in fact *not* supported by f-prot. For example, # the '-BEEP' option is not available in F-Prot 3.10a Beta. # Using those option can cause f-prot to refuse operation and complain about # unkown options. But that's not my fault! # BASENAME=`basename $0` DIRNAME=`dirname $0` VERSION=0.1 ############################################################################### # Change these value to meet your requirements ############################################################################### # Full path of your f-prot binary file FPROT=/usr/local/f-prot/f-prot # Full path to your dialog binary DIALOG=/usr/bin/dialog # What is the filename of the default scanning profile? DEFAULTPROFILE=default.scan # Full path to your sed program SED=/usr/bin/sed # Where can I put my temporary files? TMP=/tmp/$BASENAME.tmp ############################################################################### # There should be nothing to change below this point ############################################################################### BACKTITLE="$BASENAME (Version $VERSION) (C) 2001 Malte J. Wetz " # # Do cleanup and exit program with optional message and error code. # function quit { code=$1 msg=$2 [ -e "$TMP" ] && rm -rf $TMP [ "$code" = "" ] && code=0 [ "$msg" = "" ] && msg="good bye" echo echo $msg echo exit $code } # # Initialize all scan parameters # function initialize { OPT_AI=off OPT_APPEND=off OPT_ARCHIVE=off OPT_AUTO=off OPT_BEEP=off OPT_CDROM=off OPT_COLLECT=off OPT_DELETE=off OPT_DISINF=off OPT_DUMB=off OPT_EXT=off OPT_FREEZE=off OPT_HARD=off OPT_INTER=off OPT_LIST=off OPT_LOADDEF=off OPT_NET=off OPT_NOBOOT=off OPT_NOBREAK=off OPT_NOFILES=off OPT_NOFLOPPY=off OPT_NOHEUR=off OPT_NOLFN=off OPT_NOMEM=off OPT_NOSUB=off OPT_OLD=off OPT_ONLYHEUR=off OPT_PACKED=off OPT_RENAME=off OPT_TYPE=off OPT_PAGE=off OPT_SILENT=off OPT_NOMACRO=off OPT_ONLYMACRO=off OPT_REMOVEALL=off OPT_REMOVENEW=off OPT_SAFEREMOVE=off OPT_SCANEXT="" OPT_REPORTFILE="" } # # Display a checklist which allows the user to enable/disable any boolean # scanning switch. # function checkoptions { $DIALOG --backtitle "$BACKTITLE" --title "Scan Switches" \ --checklist "Enable or disable any of these options. Note that some of them \ are not recognized by beta versions of f-prot." 20 75 12 \ "AI" "Enable neural-network virus detection" "${OPT_AI}" \ "APPEND" "Append to existing report file" "${OPT_APPEND}" \ "ARCHIVE" "Scan inside .ZIP and .ARJ files" "${OPT_ARCHIVE}" \ "AUTO" "Automatic virus removal" "${OPT_AUTO}" \ "BEEP" "Beep when a virus is found" "${OPT_BEEP}" \ "CDROM" "Scan any attached CD-ROM drives" "${OPT_CDROM}" \ "COLLECT" "Scan a virus collection" "${OPT_COLLECT}" \ "DELETE" "Delete infected files" "${OPT_DELETE}" \ "DISINF" "Disinfect whenever possible" "${OPT_DISINF}" \ "DUMB" "Do a \"dumb\" scan of all files" "${OPT_DUMB}" \ "EXT" "Scan only files with default extensions" "${OPT_EXT}" \ "FREEZE" "\"Freeze\" the program if a virus is found" "${OPT_FREEZE}" \ "HARD" "Scan the hard disk(s)" "${OPT_HARD}" \ "INTER" "Force interactive mode" "${OPT_INTER}" \ "LIST" "List all files checked" "${OPT_LIST}" \ "LOADDEF" "Load DEF files from a floppy" "${OPT_LOADDEF}" \ "NET" "Scan network directories mapped to a drive" "${OPT_NET}" \ "NOBOOT" "Do not scan boot sectors" "${OPT_NOBOOT}" \ "NOBREAK" "Do not abort scan on ESC is pressed" "${OPT_NOBREAK}" \ "NOFILE" "Do not scan files" "${OPT_NOFILES}" \ "NOFLOPPY" "For use on systems without floppy drives" "${OPT_NOFLOPPY}" \ "NOHEUR" "Disable heuristics" "${OPT_NOHEUR}" \ "NOLFN" "Disable long file name support" "${OPT_NOLFN}" \ "NOMEM" "Do not scan memory for viruses" "${OPT_NOMEM}" \ "NOSUB" "Do not scan subdirectories" "${OPT_NOSUB}" \ "OLD" "Do not complain when using outdated DEF files" "${OPT_OLD}" \ "ONLYHEUR" "Only use heuristics, not \"normal\" scanning" "${OPT_ONLYHEUR}" \ "PACKED" "Unpack compressed executables" "${OPT_PACKED}" \ "RENAME" "Rename infected COM-EXE files to VOM-VXE" "${OPT_RENAME}" \ "TYPE" "Select files by type" "${OPT_TYPE}" \ "PAGE" "Pause after each page" "${OPT_PAGE}" \ "SILENT" "Do not generate any screen output" "${OPT_TYPE}" \ "NOMACRO" "Do not scan for macro viruses" "${OPT_NOMACRO}" \ "ONLYMACRO" "Only scan for macro viruses" "${OPT_ONLYMACRO}" \ "REMOVEALL" "Remove all macros from all documents" "${OPT_REMOVEALL}" \ "REMOVENEW" "Remove all macros from infected documents" "${OPT_REMOVENEW}" \ "SAFEREMOVE" "Remove all macros from documents if known virus found" "${OPT_SAFEREMOVE}" \ 2>$TMP || return read items < $TMP rm -f $TMP for item in $items; do item=`echo $item | $SED -e 's/\"//g;'` var=OPT_${item} echo "${var}=on" >> $TMP done . $TMP } # # Change the default file extensions for scanning # function changeext { $DIALOG --backtitle "$BACKTITLE" --title "File extensions" \ --inputbox "What file extension should be scanned (enter nothing for \ all files)?" 7 75 $OPT_SCANEXT \ 2>$TMP && read OPT_SCANEXT < $TMP } # # Change the report file # function changerep { $DIALOG --backtitle "$BACKTITLE" --title "Report File" \ --inputbox "Report result to this file (leave blank for no report \ file)" 7 75 $OPT_REPORTFILE \ 2>$TMP && read OPT_REPORTFILE < $TMP } # # Display the options menu # function optionsmenu { while true; do $DIALOG --backtitle "$BACKTITLE" --title "Main Menu" \ --menu "Choose an action from the menu below" 15 75 5 \ "SWITCHES" "Enable or disable scanning switches" \ "EXT" "Change extensions of files which should be scanned" \ "REPORT" "Change name of report file" \ "BACK" "Back to main menu" \ 2>$TMP read sel < $TMP case "$sel" in SWITCHES) checkoptions ;; EXT) changeext ;; REPORT) changerep ;; ""|BACK) return ;; esac done } # # Ask for a file name (if not specified as parameter) and then load options # from that file # function loadprofile { fname=$1 if [ -z "$fname" ]; then $DIALOG --backtitle "$BACKTITLE" --title "Load profile" \ --inputbox "Load scan profile from this file:" 7 75 $DEFAULTPROFILE \ 2>$TMP || return read fname < $TMP test -z "$fname" && return fi . $fname } # # Ask for a file name (if not specified as parameter) and then load options # from that file # function saveprofile { fname=$1 if [ -z "$fname" ]; then $DIALOG --backtitle "$BACKTITLE" --title "Save profile" \ --inputbox "Save scan profile to this file:" 7 75 $DEFAULTPROFILE \ 2>$TMP || return read fname < $TMP test -z "$fname" && return fi items=`echo ${!OPT_*}` test -e "$fname" && rm -rf $fname for item in $items; do echo "${item}=${!item}" >> $fname done } # # Ask for something to scan and then do it! # function scan { $DIALOG --backtitle "$BACKTITLE" --title "Scan" \ --inputbox "Enter drive, directory or file to scan:" 7 75 \ 2>$TMP || return read fname < $TMP test -z "$fname" && return cmd="$FPROT" items=`echo ${!OPT_*}` for item in $items; do if [ "${!item}" = on ]; then cmd="$cmd -${item##OPT_}" fi done [ -z "$REPORTFILE" ] || cmd="$cmd -REPORT=${REPORTFILE}" [ -z "$SCANEXT" ] || cmd="$cmd -EXT=${SCANEXT}" cmd="$cmd $fname" clear exec $cmd } # # This function displays the main menu an handles selected options # function mainmenu { while true; do $DIALOG --backtitle "$BACKTITLE" --title "Main Menu" \ --menu "Choose an action from the menu below" 15 75 5 \ "SCAN" "Scan for viruses" \ "OPTION" "Change scanning options for f-prot" \ "LOAD" "Load scanning options from file" \ "SAVE" "Save scanning options to file" \ "EXIT" "Leave this program" \ 2>$TMP read sel < $TMP case "$sel" in SCAN) scan ;; OPTION) optionsmenu ;; LOAD) loadprofile ;; SAVE) saveprofile ;; ""|EXIT) quit ;; esac done } initialize [ -r $DEFAULTPROFILE ] && loadprofile $DEFAULTPROFILE mainmenu exit 0