home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 15
/
CD_ASCQ_15_070894.iso
/
vrac
/
icom201b.zip
/
POSTFILE.SCR
< prev
next >
Wrap
Text File
|
1994-06-06
|
22KB
|
569 lines
;----------------------------------------------------------------------------
; POSTFILE.SCR Intellicomm v2 script to virus check and otherwise handle
; newly downloaded files. Run POSTINI.SCR to configure this script.
;
;----------------------------------------------------------------------------
; NOTE: There are many simple changes you can make to this script to
; do anything from adding support for new archive types to converting all
; non-ZIP archives to ZIP format. Many tips and examples were placed at the
; END of this script (press [Ctrl-PgDn] to get to the end) as well as a
; 'CustomWork' subroutine where you can perform customized work on newly
; downloaded archives.
;----------------------------------------------------------------------------
rxflush ;flush receive buffer (logoff garbage)
variable v
variable olddir $CURDIR ;save current directory
variable postfileini $SCRIPT_DIR "POSTFILE.INI"
notexist postfileini gosub Configure
if GlobalStr[0] <> 3 ;are the 3 filename parms there?
print "This is not a stand-alone script. Please run POSTINI.SCR for
pause "setup instructions. Press a key..."
return
endif
variable fh
fopen fh postfileini "r" ;open POSTFILE.INI for "r"eading
if $ERRORLEVEL <> 0
cls
print "Can't open POSTFILE.INI. Add FILES=45 to your CONFIG.SYS file."
pause "Press a key... "
exit
endif
variable virusrpt $HOME_DIR "VIRUS.RPT"
variable tmpdir $HOME_DIR "TESTDIR"
variable picview
variable picfiles
variable zipx
variable arcx
variable arjx
variable lhax
variable zoox
variable pakx
variable viruschk
variable virusaction
variable holdingarea
variable FILEMAN_if_clean
variable FILELIST_if_virus
variable describe_4DOS
fgets picview fh
fgets picfiles fh
fgets zipx fh
fgets arcx fh
fgets arjx fh
fgets lhax fh
fgets zoox fh
fgets pakx fh
fgets viruschk fh
fgets virusaction fh
fgets holdingarea fh
fgets FILEMAN_if_clean fh
fgets FILELIST_if_virus fh
fgets describe_4DOS fh
fclose fh
strpos v picfiles GlobalStr[2] ;extension matches a picture type?
if v > -1 goto ViewPicture ;check/view if a picture
menudefine "~Yes" "~No"
mkdir tmpdir ;create the temporary directory
chdir tmpdir ; and change to it for uncompress
if $ERRORLEVEL > 0 ;oops... couldn't create or change
print "WARNING: POSTFILE.SCR Unable to create or change to directory:
print tmpdir
print "Virus check not performed on file " GlobalStr[1] GlobalStr[2]
pause "Press a key..."
return
endif
addslash tmpdir
capture $CAP_NAME ;captures PRINT commands to ICOM.CAP
strset v "─" 0 75 ;a line, 75 chars long
print "^M^J" v ;print a blank, then the line
print "POSTFILE.SCR Testing file: ^B" GlobalStr[1] GlobalStr[2]
print
switch GlobalStr[2] ;GlobalStr[2] has the file extension (.EXT)
case ".ZIP"
dos zipx " " GlobalStr[3] ;GlobalStr[3] has the D:\PATH\FILENAME.EXT
endcase
case ".ARC"
dos arcx " " GlobalStr[3]
endcase
case ".ARJ"
dos arjx " " GlobalStr[3]
endcase
case ".LZH"
dos lhax " " GlobalStr[3]
endcase
case ".ZOO"
dos zoox " " GlobalStr[3]
endcase
case ".PAK"
dos pakx " " GlobalStr[3]
endcase
default ;not a recognized compression type
gosub DescribeFile
print GlobalStr[3]
print "Not a recognized archive type. No virus scan performed."
goto Cleanup
endcase
endswitch
;Now scan for viruses, redirecting the Virus Checker's output
; to VIRUS.RPT
EXEC viruschk " > " virusrpt
if $ERRORLEVEL < 0
print "WARNING: Can't execute command: " viruschk
print GlobalStr[3] " not virus checked!"
goto Cleanup
endif
if $ERRORLEVEL > 0 goto PossibleVirus ;checker returned an errorlevel
delete virusrpt ;we're done with this
print GlobalStr[1] GlobalStr[2] " is clean."
gosub UpdateDescription ;checks for FILE_ID.DIZ
if describe_4DOS <> 0 gosub DescribeFile
;NOTE: If you want to do any custom work on clean files, such as
; re-compressing the files into a .ZIP if another archive format was
; used, and/or deleting BBS Ads, etc., here is where you'd do it.
; Remove the semicolon (;) before GOSUB CustomWork below, then place the
; custom commands you want to perform at the end of this script
; (subroutine 'CustomWork:' is already in place, complete with examples).
;GOSUB CustomWork
variable InstallScr tmpdir "@ICOM.SCR"
notexist InstallScr goto ManualBrowse
;------------------------------------------------------------------------------
InstallScrMenu:
;------------------------------------------------------------------------------
menudefine "~Yes" "~No" "~View Script First"
print "^M^JAn auto-install script was found for " GlobalStr[1] GlobalStr[2] "!"
printnc "Execute it? "
menubar ;Yes/No menu MENUDEFINEd at startup
print
if $MENUSELECTION = 1
script InstallScr
goto Cleanup
endif
if $MENUSELECTION = 3 ;View First (option 3)
edit InstallScr ;(Edit allows user to customize)
goto InstallScrMenu
endif
; fall through... if any other menuselection or [Esc]
;------------------------------------------------------------------------------
ManualBrowse:
;------------------------------------------------------------------------------
if FILEMAN_if_clean = 1
print "Entering File Manager for inspection/installation..."
delay 20
FileMan tmpdir
endif
goto Cleanup
;------------------------------------------------------------------------------
PossibleVirus:
;------------------------------------------------------------------------------
print "Virus Checker reported error #" $ERRORLEVEL
print
capclose ;close: APPEND below does an FOPEN on the file
append virusrpt $CAP_NAME ;add error report to the .CAP as well.
capture $CAP_NAME
switch virusaction ;what to do... we have a possible nasty here
case 1 ;display error, enter the File Manager to check it out
pause "Press a key to view Virus Checker output..."
List virusrpt
FileMan tmpdir
;if file was deleted in the File Manager, we're done
; Otherwise, ask the user whether to delete it or not
notexist GlobalStr[3] endcase
assign v "^IDelete " GlobalStr[1] GlobalStr[2] "?"
menuboxh $SCRIPT_NAME v
if $MENUSELECTION = 1 delete GlobalStr[3] ;user selected "Yes"
endcase
case 2 ;delete the nasty
delete GlobalStr[3] ;the full d:\path\fname.ext of the archive
print GlobalStr[3] " deleted."
endcase
case 3 ;move nasty to 'holdingarea' directory
addslash holdingarea ;make sure it has a trailing \
assign v holdingarea GlobalStr[1] GlobalStr[2]
;rename MOVES files if destination on the same drive. If not on the
; same drive (can't move) it sets $ERRORLEVEL to 1
rename GlobalStr[3] v
if $ERRORLEVEL = 0
print GlobalStr[1] GlobalStr[2] " moved to " v
else
;use COPY/DELETE if get an error with RENAME
print "Copying " GlobalStr[1] GlobalStr[2] " to " v
copy GlobalStr[3] v
if $ERRORLEVEL = 0 delete GlobalStr[3]
endif
if $ERRORLEVEL > 0
print "WARNING: Unable to move " GlobalStr[1] GlobalStr[2] " to"
print v
endif
endcase
;case 4 or any other, we do nothing
endswitch
delete virusrpt ;we're done with this
;Icom checks the filename field (which will always have something in it
; since we just transferred the file) when POSTFILE.SCR returns, and if
; the field is BLANK, it skips adding the file to the FILELIST catalog.
; We caught a problem above with the virus check, so here we clear
; the filename field IF FILELIST_if_virus is turned off in POSTFILE.INI.
; If it's not set to zero then the filename remains intact and Icom adds
; the record to the FILELIST catalog.
if FILELIST_if_virus = 0
assign $CNAME_FLD ""
else
gosub UpdateDescription
endif
goto Cleanup
;------------------------------------------------------------------------------
UpdateDescription:
;------------------------------------------------------------------------------
assign v ""
exist "DESC.SDI" assign v "DESC.SDI"
exist "FILE_ID.DIZ" assign v "FILE_ID.DIZ"
strblank v return
ccleardesc ;clear out the existing description (if any)
variable f ;don't define variables in a subroutine unless you
variable linebuf ; know it'll only be called ONCE (error otherwise)
print "Getting official archive description from " v
fopen f v "r" ;open for reading
while 1
fgets linebuf f
if $ERRORLEVEL <> 0 break ;end of file
cputdesc linebuf 0 ;0 = append line
endwhile
fclose f
assign linebuf $HOME_DIR "FILE_ID.DIZ"
copy v linebuf ;update the FILE_ID.DIZ Icom wrote previously,
; in case something else (subroutine CustomWork)
; wants to use it
return
;------------------------------------------------------------------------------
DescribeFile:
;------------------------------------------------------------------------------
;Many thanks to Steve Willer for coming up with this idea.
;
;Modified 03/29/94 to use a text file to describe the file (bypassing the
; 128 character maximum DOS description size) instead of passing the
; description directly on the command line. The description is written
; to a text file (with no CR's to terminate each line; required) then
; uses input re-direction to input the description.
;------------------------------------------------------------------------------
variable DescMax 200 ;4DOS DescriptionMax
variable linenum 1
variable desclen
variable curlen
variable linelen
variable out_name $HOME_DIR "4DOS.TXT"
variable out
print "Describing file with 4DOS. If DESCRIBE beeps at you add the line:"
print "DescriptionMax = 200 to your 4DOS.INI file!^M^J"
fopen out out_name "w" ;create the temporary file
assign v "(FROM " $CLOC_FLD ") "
fputsnc out v
strlen desclen v
while desclen < DescMax
cgetdesc v linenum
if $ERRORLEVEL <> 0 break
inc linenum
strcat v " " ;a space separates each line; not CR/LF
strlen linelen v ;get length of current line
add curlen desclen linelen ;total length of description
if curlen >= DescMax
sub linelen DescMax desclen ;how many characters can we add?
setchr v "" linelen ;terminate 'v' at maxlen
endif
fputsnc out v
assign desclen curlen
endwhile
fputsnc out "^M" ;add a CR to terminate the description
fclose out
dos "DESCRIBE " GlobalStr[3] " < " out_name
delete out_name
return
;-----------------------------------------------------------------------------
Cleanup:
;-----------------------------------------------------------------------------
chdir tmpdir ;make sure we're still in the right place
if $ERRORLEVEL = 0 delete "*.*" ;clean up the temporary directory
chdir olddir ;change back to original directory
rmdir tmpdir ;delete the temp directory
print
capclose
return
;-----------------------------------------------------------------------------
ViewPicture:
;-----------------------------------------------------------------------------
variable percent
variable piclen
strblank picview exit ;no picview command, nothing to do
strchr percent picview "%" ;where is the %?
if percent = -1 ;-1 if no % found
strcat picview " " GlobalStr[3] ;just add the picture name
else
strlen piclen GlobalStr[3] ;store length of full picture filename
strdel picview percent 1 ;kill the %
strins picview GlobalStr[3] percent piclen
endif
fnstrip v GlobalStr[3] 12 ;mode 12 = D:\PATH\ only
chdir v ;in case the pic viewer has a file menu
; so you can delete the picture, etc.
print "Viewing " GlobalStr[1] GlobalStr[2]
dos picview
;Here you might want to add a menu that allows you to Delete or
; Move the picture to a special picture area. Defining menus in
; scripts is simple ... juse MENUDEFINE "~Delete" "~Move", then
; either MENUBAR, MENUBOXH, MENUBOXV to show the menu. See the
; menus above for examples.
chdir olddir ;return to original directory
exit ;exit the script from here
;------------------------------------------------------------------------------
Configure:
;------------------------------------------------------------------------------
assign v $SCRIPT_DIR "POSTINI.SCR"
notexist v goto INIMissing
wndopen $SCRIPT_NAME
print "^M^JImportant note: ^BPLEASE READ FULLY!^B^M^J"
print "^BPOSTFILE.SCR^B has not been configured as yet. This script allows you"
print "to automatically virus check and otherwise handle newly downloaded files,
print "but you must first look a few settings over and make any necessary (or
print "more preferable) changes.^M^J"
print "When you press a key, you will enter the POSTFILE.SCR ^Bmain setup program^B"
print "where you can change the way POSTFILE.SCR operates to suit your system and"
print "your preferences. Please press a key..."
pause
wndclose
script "POSTINI"
assign v $SCRIPT_DIR "POSTFILE.SCR"
notexist v exit ;Disabled
notexist postfileini exit ;Still no .INI file
return
:INIMissing
wndopen $SCRIPT_NAME
cls
print "NOTE: Neither POSTFILE.INI nor the POSTFILE.SCR main setup program POSTINI.SCR"
print "could be found! To use POSTFILE.SCR you must first install POSTINI.SCR in"
print "the " $SCRIPT_DIR " directory.^M^J"
pause "Press a key... "
wndclose
exit
;------------------------------------------------------------------------------
CustomWork:
;------------------------------------------------------------------------------
;Add your custom work for virus-free archives here (before the 'RETURN'),
; if desired. If you haven't already removed the semicolon before
; 'GOSUB CustomWork' above, you must do so or this subroutine will not
; be called.
;
; Note that the full file description has been written to:
;
; $HOME_DIR "FILE_ID.DIZ" ;C:\ICOM\FILE_ID.DIZ
;
; by Icom and you could add that file to the archive if it doesn't exist in
; the 'tmpdir' (i.e. in the achive). You'd need a 'switch' statement
; similar to the one above used to uncompress the archive, to make sure that
; the proper compression command was used. Example (remember, the current
; directory is the temp directory we uncompressed the archive to while
; POSTFILE.SCR is running):
;
; exist "FILE_ID.DIZ" return ;only if it doesn't exist...
; exist "DESC.SDI" return ;the other type of 'ID' file
;
; ;now we know the archive doesn't have a description file within, so
; ; we'll add the one Icom created:
;
; variable fileid_diz $HOME_DIR "FILE_ID.DIZ" ;build the filename Icom made
;
; switch GlobalStr[2] ;archive .EXTenstion
; case ".ZIP"
; exec "PKZIP -a " GlobalStr[3] " " fileid_diz
; endcase
; case ".ARC"
; exec "PKPAK -a " GlobalStr[3] " " fileid_diz
; endcase
; ... ;etc. for the others
; ...
; endswitch
;
; Note that if you modify the original archive, you'd normally lose the
; original archive date/time. But Icom automatically saves the archive
; date/time before calling POSTFILE.SCR, and restores it upon return
; in case you modify the archive here.
;
; However, if you change the FILENAME of the original archive (e.g. ARJ to ZIP)
; you must make sure to ASSIGN the new filename to the $CNAME_FLD, or Icom
; will place the wrong filename in the FILELIST catalog, and won't be able
; to restore the file date/time to what it was originally. For example you
; might do something like this to convert non-ZIP files to ZIP format:
;
; if GlobalStr[2] <> ".ZIP" ;not a .ZIP archive?
; variable archive_name
; fnstrip archive_name GlobalStr[3] 4 ;mode 4 = D:\PATH\FNAME (no .EXT)
; exec "PKZIP " archive_name " *.*" ;add all files to new .ZIP archive
; if $ERRORLEVEL = 0 ;successful?
; delete GlobalStr[3] ;kill the non-ZIP archive
; assign $CNAME_FLD GlobalStr[1] ".ZIP" ;same name, new extension. Icom now
; endif ; stores the proper filename in
; endif ; the FILELIST catalog, AND it
; ; restores the ORIGINAL archive date
; ; on the newly created ZIP.
CHDIR tmpdir ;First make sure we're in the right directory
;Remove this comment and insert your commands here (as many lines as you
; like).
RETURN ;LAST statement in subroutine.
;------------------------------------------------------------------------------
; POSTFILE.SCR TIPS AND NOTES:
;
; After the virus check (see above), all the files in the archive will be
; sitting in the temporary directory ready for whatever you want to do with
; them. You could choose to re-compress the files using PKZIP, to standardize
; all your files and avoid keeping other archive types on-disk; you could
; delete files that are known BBS advertisements, then re-compress the
; archive, etc. Please see the 'CustomWork' subroutine above for examples,
; if you're interested.
;
; Note also that the file description Icom had prior to the download
; (from the new files list you imported to tag the file) is written to
; \ICOM\FILE_ID.DIZ before this script is called. So you could choose to
; add that to the archive, if it doesn't exist. Again, see the CustomWork
; subroutine for an example.
;
; By looking closely at the script above, you should be able to clearly
; see how to add your own custom commands and routines to POSTFILE.SCR,
; even if you haven't read SCRTUTOR.DOC as yet. Of course, if you're
; happy with POSTFILE.SCR as is, you needn't change anything in this
; script. But you can do a whole lot more if you're inclined.
;
;----------------------------------------------------------------------------
; Intellicomm passes three parameters to this script (stored by the Script
; Processor in the GlobalStr array where passed parms always go):
;
; GlobalStr[1] has the FILENAME of the archive (no extension or .)
; GlobalStr[2] has the .EXT (extension with the . included)
; GlobalStr[3] has the full D:\PATH\FILENAME.EXT
;
;---------------------------------------------------------------------------
; ADDING SUPPORT FOR NEW ARCHIVE TYPES: See the first 'switch' command in
; this script where GlobalStr[2] is compared to the various .EXTensions. All
; you need is a new 'case/endcase' along with the proper decompression
; command to add support for more archive types:
;
; ...
; case ".XYZ" ;the extension of the archive
; dos "UN-XYZ.EXE -switches " GlobalStr[3] ;command to uncompress it
; endcase
; ...
;
; Self-extracting archives (.COM/.EXE) could also be supported by executing
; the archive. But if you do this you might want to run a virus check on
; the file before executing it -- if it's not a self-extracting archive and
; is simply a PROGRAM, you may install a virus on your system by
; executing the file. Example:
;
; ...
; case ".COM"
; case ".EXE"
; exec "SCAN " GlobalStr[3] " /A /nomem /noexpire >" virusrpt
; if $ERRORLEVEL <> 0 goto PossibleVirus
; exec GlobalStr[3]
; endcase
; ...
;
; This runs a scan on the .COM or .EXE, and if no errorlevel is returned
; it then executes the file to uncompress it. Of course, if the file ISN'T
; a self-extracting archive POSTFILE will simply run a program... and
; this is why self-extracting archives are ignored by default.
;
;----------------------------------------------------------------------------
; READER BONUS: If you've read the "Introduction to Database Commands" in
; SCRTUTOR.DOC, be aware that by the time Intellicomm calls POSTFILE.SCR
; it has already performed a CGETREC on the Tagger catalog record that is
; associated with the file we're virus checking here. So, you can use
; POSTFILE.SCR to do anything you want with the record -- BEFORE it is
; imported to the FILELIST catalog (or exported to your BBS listing, if
; you're a Sysop).
;
; Icom loads the catalog record into memory (CGETREC), it calls this script,
; and it then immediately writes the record (still in memory from CGETREC)
; into the FILELIST catalog, WITHOUT re-loading the record from disk after
; this script finishes. Thus, if you modify any of the fields (or the file
; description) here in POSTFILE.SCR, the changes will be written to the
; FILELIST catalog and will also be exported if any of the Sysop export
; options are turned on in the Icom main setup.
;
; For example, you could add notes or customized comments:
;
; CPUTDESC "Auto-downloaded by Intellicomm." 0
;
; The above appends a new comment line to the end of the existing description
; (due to the 0 specified as the comment line, which appends to the existing
; file description). You needn't CPUTREC to write the record to disk after
; modifying it in this script. Icom does a CPUTREC itself, into the
; FILELIST catalog, when POSTFILE.SCR finishes.
;
; Do NOT use CGETREC or any database functions other than CPUTDESC and
; CGETDESC in this script! You're free to modify the catalog record in
; memory (the $CXXX_FLD fields and the description), but you mustn't load
; new records from disk in this script, or otherwise mess around with the
; catalog on-disk.
;------------------------------[End of File]----------------------------------