home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / upchek_b.lzh / Upchek.cmd < prev    next >
OS/2 REXX Batch file  |  1993-08-22  |  16KB  |  352 lines

  1. /*
  2.  
  3.                            Upchek 1.0
  4.                            August 22, 1993
  5.                            Kim Bergman
  6.  
  7. */
  8. "@echo off"
  9. taboos=""
  10. configpath=directory()||"\upchek.cfg"
  11. j=lines(configpath)
  12. if j=0 then do
  13.    say "Aborting: Can't open Upchek.cfg"
  14.    exit
  15. end 
  16. else do until lines(configpath)=0
  17.    do until left(inline,1)<>"%"
  18.       inline=translate(strip(linein(configpath)))
  19.    end                              /* do until left(strip(inline),1)<>"%" */
  20.  
  21.    select
  22.       when lastpos("BADACT",inline)=1    then badact=translate(subword(inline,2,1))
  23.       when lastpos("LISTSCAND",inline)=1  then listscand=translate(subword(inline,2,1))
  24.       when lastpos("MAXDIR",inline)=1    then maxdir=translate(subword(inline,2,1))
  25.       when lastpos("WORKDIR",inline)=1   then workdir=translate(subword(inline,2,1))
  26.       when lastpos("TEMPFIL1",inline)=1   then tempfil1=translate(subword(inline,2,1))
  27.       when lastpos("TEMPFIL2",inline)=1   then tempfil2=translate(subword(inline,2,1))
  28.       when lastpos("LOGFILE",inline)=1     then hisfile=translate(subword(inline,2,1))
  29.       when lastpos("OPTSFILE",inline)=1     then optsfile=translate(subword(inline,2,1))
  30.       when lastpos("BADPATH",inline)=1    then badpath=translate(subword(inline,2,1))
  31.       when lastpos("FULLBADPATH",inline)=1 then fullbadpath=translate(subword(inline,2,1))
  32.       when lastpos("DOORFILE",inline)=1    then doorfile=translate(subword(inline,2,1))
  33.       when lastpos("DISCOURAGE",inline)=1 then discourage=translate(subword(inline,2,1))
  34.       when lastpos("RESTRICTED",inline)=1  then taboos=translate(subword(inline,2,1))
  35.       otherwise nop
  36.    end                            /* select */
  37. end  /* Do until lines(configpath)=0 */
  38. j=stream(configpath,c,'close')
  39.  
  40. /*
  41. say"badact =      ["||badact"]"
  42. say"listscand=    ["||listscand"]"
  43. say"maxdir =      ["||maxdir||"]"
  44. say"workdir =     ["||workdir||"]"
  45. say"tempfil1 =    ["||tempfil1||"]"
  46. say"tempfil2 =    ["||tempfil2||"]"
  47. say"hisfile =     ["||hisfile||"]"
  48. say"optsfile =    ["||optsfile||"]"
  49. say"badpath =     ["||badpath||"]"
  50. say"fullbadpath = ["||fullbadpath||"]"
  51. say"doorfile =    ["||doorfile||"]"
  52. say"taboos =      ["||taboos||"]"
  53.  
  54.  pull usin */
  55.  
  56.  
  57. /* The first 3 args expected are:
  58.     1. Path to file to be processed with trailing \
  59.     2. Filename stem of file to be processed
  60.     3. Filename extension of file to be processed
  61.  
  62. The fourth arg will be path to Max's miscellaneous directory when Upchek.cmd
  63. is called by Max.  If invoked on the command line then fourth arg must be "/L".
  64. */
  65.  
  66. parse arg ulpath filnam ext mecpath           /* get args au naturel */
  67. arg uculpath ufilnam uext mode           /* get args converted to uppercase */
  68.                                        /* to facilitate comparisons later*/
  69. /* check if parms valid */
  70. if ulpath="?" | uculpath="HELP" then signal usage
  71. if ulpath="" | filnam="" | ext="" | mecpath="" then signal noparms
  72.  
  73. /* build some strings */ 
  74. fullnam = filnam||ext
  75. fullpath = ulpath||fullnam
  76. stars = "***************************************************************************"
  77.  
  78. /* Check see if file to be processed exists */
  79. a = lines(fullpath)
  80. if a=0 then do
  81.        say "Upchek.cmd Error:  Can't find "||fullpath
  82.        r = lineout(hisfile, "Upchek.cmd Error:  Can't find "||fullpath)
  83.        r = lineout(hisfile,stars)
  84.        a = stream(hisfile,c,close)
  85.        exit                  /* Bogus path or filename, exit. */
  86.     end
  87. else a = stream(fullpath,c,close)  /* File exists so close it and go to work */
  88.  
  89. /*  If mode is not Local then prepare .... */
  90. if mode<>"/L" & mode<>"L" then do
  91.      badmec=mecpath||"file_bad.mec"                     /* delete old mecca files that have previous report */
  92.      okmec=mecpath||"file_ok.mec"                        /* see Max_ref.prn for more info on how Max uses these 2 files */
  93.      del badmec
  94.      del okmec
  95.      a=lineout(badmec," ")                               /* initialize caller reports with blank line */
  96.      a=lineout(okmec," ")
  97.      a=lines(doorfile)                                       /* read the door file */
  98.      if a<>0 then do
  99.            nodenum=linein(doorfile)
  100.            usernam=linein(doorfile)
  101.          end
  102.      else do                                               /* abort if can't find door file */
  103.           r=lineout(hisfile,"Can't read the doorfile from "||doorfile||".  Upchek.cmd aborted.")
  104.           r=lineout(hisfile,stars)
  105.           exit
  106.        end 
  107.    end
  108. else do
  109.      mode="L"
  110.      nodenum="00"
  111.    end
  112.  
  113.  
  114. /* initialize some variables */
  115. arcount = 0    /* counts archives found, good and grunged ones */
  116. filcount = 0    /* counts normal files scanned */
  117. workdir=workdir||nodenum
  118. tempfil1=tempfil1||nodenum
  119. tempfil2=tempfil2||nodenum
  120. note="blank"
  121.  
  122. /* build some commands */  
  123. getfile = "copy "||fullpath||" "||workdir
  124. beinworkdir = "cd "||workdir 
  125. makworkdir = "mkdir "||workdir
  126. cleardir = "del "||workdir||"\*.* /N"
  127. erasedir = "rd "||workdir
  128. scanfiles = "os2scan "||workdir||" @"||optsfile
  129.  
  130. makworkdir
  131. beinworkdir
  132. getfile
  133.  
  134. /* Write sysop report header to log file */
  135. r = lineout(hisfile,date("N")||" processing "||fullpath||".")
  136. if mode="L" then r=lineout(hisfile,"Local mode.")
  137.   else  r=lineout(hisfile,"Uploaded by "||usernam)
  138.  
  139. /* initialize some flags, accumulators */
  140. badcount=0                    /* counts corrupted archives */
  141. badarcnames=""               /* accumulates names of bad archives */
  142. clean="TRUE"                 /* goes FALSE and stays FALSE if scanner finds a virus */
  143. scanaborted="FALSE"         /* goes TRUE and stays TRUE if scanner aborts */
  144. abnormal="FALSE"            /* goes TRUE and stays TRUE if scanner exits with abnormal errorlevel */
  145. hastaboos="FALSE"           /* goes TRUE and stays TRUE if restrict finds taboo file extensions */
  146.  
  147. /* sniff the file, if it's archive then call the archive handler */
  148. instrg=charin(fullnam,,5)
  149. a=stream(fullnam,c,"close")
  150.  
  151. if left(instrg,3)="ZOO" then call arhand
  152.   else if substr(instrg,3,3)="-lh" then call arhand
  153.     else if c2d(left(instrg,1))=26 then call arhand
  154.       else if left(instrg,2)="PK" & c2d(substr(instrg,3,1))=3 & c2d(substr(instrg,4,1))=4 then call arhand
  155.         else if left(instrg,1)="`" & c2d(substr(instrg,2,1))=234 then call arhand
  156.           else do                               /* file is not an archive we can handle */
  157.               call restrict                      /* see if it's a restricted file */
  158.               scanfiles                         /* may as well scan it */
  159.               if RC=1 then clean="FALSE"    /* check return code from scanner, RC=0 means no virus found */
  160.                else if RC=2 then scanaborted="TRUE"
  161.                  else if RC<0 | RC>4 then abnormal="TRUE"
  162.              end                                 /* file is not an archive we can handle */
  163.  
  164. /* process all those flags and decide what to do if file is bad */
  165.   if badcount>0|clean="FALSE"|scanaborted="TRUE"|abnormal="TRUE"|hastaboos="TRUE" then do
  166.       if badact="MOVE"|badact="RENAME" then do
  167.             a=lines(fullbadpath||fullnam)             /* check if file already exists at destination */
  168.             if a=0 then do                           /* file not there yet */
  169.                 if badact="MOVE" then do
  170.                      "move "||fullpath||" "||badpath
  171.                       note="Moved "||fullpath||" to "||badpath||"."
  172.                 end  /* if badact=move */
  173.                 else do
  174.                       note="Renamed "||fullpath||" to bad"||fullnam"."
  175.                       ren fullpath "bad"||fullnam
  176.                 end  /* else */
  177.              end   /* if a=0 */
  178.               else do                                 /* file is there already */
  179.                   del fullpath
  180.                   note="Deleted "||fullpath||" because "||fullnam||" exists at "||badpath||"."
  181.                  end
  182.             end    /* if badact=move or badact=rename  */
  183.            else if badact="DELETE" then do
  184.                  note="Deleted "||fullpath||"."
  185.                  del fullpath
  186.                end    /* if badact=delete */
  187.     end /* if badcount>0|clean="FALSE"|scanaborted="TRUE"|abnormal="TRUE"  */
  188.  
  189. /* finish writing user report  */
  190. if mode<>"L" then do 
  191.    if clean="FALSE"  then do
  192.        r=lineout(badmec,"[white]")
  193.        r=lineout(badmec,"Scanned "||fullnam||" with McAfee's OS2Scan 1.06.")
  194.        r=lineout(badmec,"We suspect that it is [lightred blink]infected [white]by a virus.")
  195.        r=lineout(badmec,"Please examine "||fullnam||" with your own scanner.")
  196.        r=lineout(badmec,"If you feel an error has occurred then please contact the sysop.")
  197.       end
  198.  
  199.     if scanaborted="TRUE" then do
  200.        r=lineout(badmec,"[white]")
  201.        r=lineout(badmec,"The virus scanner crashed while processing "||fullnam||".")
  202.        r=lineout(badmec,"Please examine your "||fullnam||".")
  203.      end
  204.     if clean="TRUE" & scanaborted="FALSE" then do
  205.        r=lineout(okmec,"[white]")
  206.        r=lineout(okmec,"Scanned "||fullnam||" with McAfee's OS2Scan 1.06.")
  207.        r=lineout(okmec,"Found no viruses.")
  208.      end
  209.      if hastaboos="TRUE" & discourage="TRUE" then do
  210.          r=lineout(badmec,"[white]")
  211.          r=lineout(badmec,"You have uploaded a file with an extension that appears in the following list:")
  212.          r=lineout(badmec,taboos)
  213.          r=lineout(badmec,"Those kinds of files are not accepted here.")
  214.       end               /* if hastaboos="TRUE" */
  215.     r=lineout(badmec,"[yellow]")
  216.     r=lineout(badmec,"Hit <ENTER> to continue ......")
  217.     r=lineout(badmec,"[readln]")
  218.  
  219.     r=lineout(okmec,"[yellow]")
  220.     r=lineout(okmec,"Hit <ENTER> to continue ......")
  221.     r=lineout(okmec,"[readln]")
  222.  
  223.  end
  224. /* finish writing sysop report */
  225. "dir /B /L > "||tempfil1
  226. if listscand="TRUE" then a=lineout(hisfile,"Scanned the following normal files:")
  227. j=lines(tempfil1)  
  228. r=0 
  229. filcount=0
  230. do while (j<>0) & (r=0)
  231.      a=linein(tempfil1)
  232.      if listscand="TRUE" then r=lineout(hisfile," "||a)
  233.      filcount = filcount+1
  234.      j=lines(tempfil1)
  235. end 
  236. r = lineout(hisfile,"Counted "||filcount||" file(s) in "||arcount||" archive(s).")
  237. if clean="TRUE" then r=lineout(hisfile,"Found no viruses.")
  238.   else r=lineout(hisfile,"Found one or more viruses.")
  239. r=lineout(hisfile,"Detected "||badcount||" bad archive(s): "||badarcnames)
  240. if hastaboos="TRUE" then r=lineout(hisfile,"Is or has restricted file(s).")
  241. if note<>"blank" then a=lineout(hisfile,note)
  242. r = lineout(hisfile,stars)
  243.  
  244. a=stream(tempfil1,c,"close")
  245. a=stream(tempfil2,c,"close")
  246. a=stream(hisfile,c,"close")
  247. a=stream(okmec,c,"close")
  248. a=stream(badmec,c,"close")
  249.  
  250. if mode<>"L" then do
  251.     meccap badmec           /* recompile the new user report file */
  252.     meccap okmec
  253.   end
  254.  
  255. cd maxdir
  256. cleardir                       /* delete *.* from work directory */
  257. erasedir                       /* delete work directory */
  258. say "Upchek.cmd done."
  259. exit
  260.  
  261. noparms:
  262. say '' ''
  263. say "Error:  Upchek.cmd received insufficient number of parameters."
  264. usage:
  265. say " "
  266. say "Usage: upchek [path or ? or help] [filename] [.extension] /L"
  267. say "        eg.  upchek ? - displays help"
  268. say "        eg.  upchek d:\max\uncheck\ testfile .arj /L"
  269. say "        Extension must be preceeded by a period."
  270. say "        Path must end with a \."
  271. say "        /L = local mode, required when run from command line."
  272. say "  "
  273. exit
  274.  
  275. arhand: procedure expose badcount scanaborted clean abnormal filnam fullnam mode tempfil1 tempfil2 arcount scanfiles taboos hastaboos badarcnames badmec
  276.  
  277. do until alldone="TRUE"        /* do until no more archives are found in the work directory */
  278.  alldone="TRUE"                /* finding another archive makes alldone="FALSE" */
  279. "dir /B /L > "||tempfil1      /* write a directory listing of the working directory to the tempfil1 */
  280.  j=lines(tempfil1)              /* see if any files are in the directory */
  281.  do while j<>0                /* while there are more files we haven't looked at */
  282.   filnam=linein(tempfil1)      /* sniff the next file, determine archive type and build the dearchive command (burst) */
  283.  
  284.  
  285.   instrg=charin(filnam,,5)    /* get a string from the file certain to have the ID bytes if there are any */
  286.   a=stream(filnam,c,"close")  /* close the file and search the string for bytes indicating an archive we can handle */
  287.   IF left(instrg,1)="`" & c2d(substr(instrg,2,1))=234 THEN  burst = "unarj e "||filnam
  288.      ELSE if substr(instrg,3,3)="-lh" THEN burst = "lh x /io "||filnam
  289.         ELSE IF left(instrg,2)="PK" & c2d(substr(instrg,3,1))=3 & c2d(substr(instrg,4,1))=4 THEN  burst = "unzip -joqq "||filnam
  290.            ELSE IF c2d(left(instrg,1))=26 THEN burst = "arc2 xno "||filnam
  291.               ELSE IF left(instrg,3)="ZOO" THEN burst = "zoo xq "||filnam
  292.                  ELSE burst = ""       /* file is either not an archive or an archive format we don't know about */
  293.  
  294.   if burst<>"" then do                 /* need to dearchive */
  295.        alldone="FALSE"                  /* make sure we sift the directory one more time */
  296.        arcount = arcount+1
  297.        burst
  298.        if RC<>0 then do                     /* if error occurred while dearchiving */
  299.            del filnam
  300.            badcount=badcount+1
  301.            badarcnames=badarcnames||filnam||" "
  302.            if mode<>"L" then do          /* if not in local mode write to caller report */
  303.                r=lineout(badmec," ")
  304.                a=lineout(badmec,"[white]Unable to dearchive "||filnam||".")
  305.                if filnam<>fullnam then do   /* if the bad archive is not the archive he uploaded */
  306.                     a=lineout(badmec,filnam||" is an archive inside of "||fullnam||".")
  307.                    end
  308.                a=lineout(badmec,"Please examine your "||fullnam||".")
  309.               end                           /* end if not local mode */
  310.           end                               /* end of dearchiving error routine */
  311.  
  312.        else do                             /* no error occurred while dearchiving  */
  313.          del filnam                        /* delete archive so it won't be found in the directory listing again */
  314.          scanfiles                         /* call the scanner */
  315.                                            /* check return code from scanner, RC=0 means no virus found */
  316.          if RC=1 then clean="FALSE"
  317.            else if RC=2 then scanaborted="TRUE"
  318.              else if RC<0 | RC>4 then abnormal="TRUE"
  319.  
  320.          call restrict                        /* see if any restricted files in directory */
  321.         end                                  /* end of else do no error occurred while dearchiving  */
  322.  
  323.                /* at end of directory listing yet? */
  324.     end                                      /* need to dearchive */
  325.     j=lines(tempfil1)
  326.    end                                       /* do while j<>0, j=0=more files in dir list */
  327.  a=stream(tempfil1,c,"close")
  328.  end                                         /* do until alldone=TRUE */
  329.  
  330. return
  331.  
  332. restrict: procedure expose hastaboos tempfil2 taboos
  333.  
  334. "dir /B /L > "||tempfil2
  335. /* say "Tempfil2 is:"
  336. type tempfil2
  337. pull usin */
  338.  
  339. do while lines(tempfil2)<>0
  340.     filnam=translate(linein(tempfil2))
  341.     charpos=lastpos(".",filnam)
  342.     extension=substr(filnam,charpos+1)
  343.     j=lastpos(extension,taboos)
  344.     if j>0 then hastaboos="TRUE"
  345. end                                 /* while lines(tempfil2)<>0 */
  346. j=stream(tempfil2,c,"close")
  347. "del "||tempfil2
  348.  
  349. return
  350.  
  351.  
  352.