#!/usr/local/bin/perl # # send_report - Compose X2FTP MSDOS Uploading Report # V0.3 pl 00 - 11 Jan 1997 # # Written by # Jouko Valta (jopi@x2ftp.oulu.fi) # # # This program scans the .txt file for each archive and the output log # generated by the counterpart of this program. Used entries can be # removed from the log file via an option. # # Options # -E Print example form (debug) # # Return Values # 0 Completed OK. # 1 Error occurred while processing. # # # dostestlog: zipfile uploader debug log, zipcomment log # statuslog : required upload information fields # ## Filenames $YEAR = `/bin/date +%y`; # Year in 2 digits $PCWORK = "/pc/prg"; # Where to dissolve files $LOGHOME = "/pc/log"; if (! -d $LOGHOME || ! -w $LOGHOME) { printf STDERR "Cannot access $LOGHOME. Please, check the setting or run\n create_dosadm_logs script.\n"; $LOGHOME = "/var/tmp"; } $UPLOADLOG = $LOGHOME . "/uploadlog"; $STATUSFILE = $LOGHOME . "/status"; $TESTLOG = $LOGHOME . "/dostestlog"; # input data $OUTLOG = $LOGHOME . "/sendlog"; # sent verifications $MAIL_REPORTFILE = "/tmp/testmsg"; # message being composed $REUPLOADDIR = "/ftp-service/ftp/incoming/msdos/reupload_these"; $REJECTLOG = "/ftp-service/ftp/pub/msdos/programming/x2info/rejected.$YEAR"; $TEXTDIR = "/src/txt"; $REJECTDIR = "/src/junk"; $CDROMDIR = "/ftp-service/cdrom/pub/msdos/programming"; $BIN = "/ftp-service/bin/"; ## $MAIL = "/bin/mail"; # ----------------------------------------------------------------------------- # Declare Tests Result values $VS_NONE = 0; $VS_OK = 1; $VS_INFECTED = 2; $AS_NONE = 0; $AS_OK = 1; $AS_CORRUPT = 2; $AS_FORMAT = 3; $AS_TAMPER = 4; @ArchiveStatus = ( "N/A", "Passed OK.", "Failed: Archive corrupt.", "Failed: Archive format error.", # zip -l; both "ok" and "ERROR" "Failed: Archive tampered." ); @VirusStatus = ( "N/A", "Passed OK.", "Infected" ); @CheckMark = ( ' ', 'x' ); ## Declare CDROM Constants $CD_NONE = 0; $CD_YES = 1; $CD_FREE = 2; $CD_NONPROFIT = 3; $CD_GPL = 4; $CD_DEMO = 5; # Demo version, not for CD $CD_PERM = 6; # Prior permission required $CD_NO = 7; $CD_CONFL = 8; # Claimed yes, but contents seem suspicious $CD_ASKED = 16; @CDPrefix = ( "", "ON_", "ON_", "ON_", "", "OFF_", "OFF_", "OFF_", "OFF_", "", "", "", "", "", "", "", "ASKED_" ); @CDString = ( "N/A", "Yes", "Yes", "Yes", "N/A", "No", "No", "No", "No", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A" ); # Move $FILE_NONE = 0; # was it moved ? $FILE_MOVE = 1; $FILE_HOLD = 2; # re-upload requested $FILE_JUNK = 3; # ----------------------------------------------------------------------------- # set path $home=$ENV{HOME} || die "No HOME, are you homeless?\n"; $user=`/usr/ucb/whoami` || die "You don't exist.\n"; chop $user; $cwd = `/bin/pwd`; chop $cwd; # Defaults $TestMode = 0; $MailMode = 1; $LongOutput = 0; ### process any FOO=bar switches eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift; ### Command line options while ($_ = $ARGV[0], /^-/) { shift; last if /^--$/; if (/^-t/) { ++$TestMode; $LongOutput = 1; next; } if (/^-E/) { ++$TestMode; next; } if (/^-long/) { ++$LongOutput; next; } if (/^-m/) { ++$MailMode; next; } if (/^-nm/) { $MailMode = 0; next; } if (/^-/) { die "Unsupported argument near $_\n Stopped"; } } # ----------------------------------------------------------------------------- # Process moved files list. # # List of checked files and their categories is obtained from STATUSFILE # open (rst, "$STATUSFILE") || die "Can't open $STATUSFILE"; print STDERR "Reading Test Status Log\n"; while () { print $_; # View processing... if (/^\s*REMARK/) { } elsif (/^\s*CWD\s+(\S+)/) { $Path = $1; } # Find named files on the status list. elsif (/^\s*CHECK\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) { $CdRomStatus = $1; # $cat = $2; # Only used for MOVE on 'dosmove' $ZipName = $3; # Notice the name location ... $TxtName = $4; } # Flag the file types included. This entry is created by the dissolver routine. elsif (/^\s*CONTENT\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) { $DisCount = $2; # Total file count $IF_readme = $3; # Flag file types included $IF_docs = $4; $IF_miscinfo = $5; $IF_source = $6; $IF_exec = $7; $IF_config = $8; $IF_object = $9; $IF_winapp = $10; $IF_install = $11; $IF_data = $12; $IF_data_audio = $13; $IF_data_video = $14; $IF_archive = $15; $IF_system = $16; $IF_UnknownType = $17; $IF_shareware = $18; $IF_commercial = $19; } else { printf STDERR "Ambiguous keyword '$_'.\n"; } # ----- # if move,junk,hold # open (R, $MAIL_REPORTFILE); # select R; # Redirect STDOUT do print_headers(); do clear_records(); do scan_testlog_entries(); do compile_report(); do print_footers(); close R; # if ($Mailmode) { # send_mail(); # } } # while (rst) exit 0; # ----------------------------------------------------------------------------- sub clear_records { $BinMode = 0; $FileSize = 0; $Folded = 0; $Stripped = 0; $IsUpdate = 0; $CdRomStatus= 0; $FinalCategory = ""; $Uploader = ""; $Category = ""; $Replace = ""; $From = ""; $UploadDate = ""; $ArchiveTest = $AS_NONE; # Default: "Not Available" $VirusTest = $VS_NONE; $FileMoved = $FILE_NONE; # Was it moved ? $AdCnt = 0; $VirusCnt = 0; $ScanCnt = 0; $ReplCnt = 0; $DisCount = 0; $IF_readme = 0; # Flag file types included $IF_docs = 0; $IF_miscinfo = 0; $IF_source = 0; $IF_exec = 0; $IF_config = 0; # Program settings data $IF_object = 0; $IF_winapp = 0; $IF_install = 0; $IF_data = 0; # General data file $IF_data_audio = 0; $IF_data_image = 0; $IF_archive = 0; $IF_system = 0; # Non-distributable files $IF_UnknownType = 0; $IF_shareware = 0; $IF_commercial = 0; } # Read TESTLOG Entries for current file sub scan_testlog_entries { # Read Entries on Log File { # Uploader (2 sources) and upload mode if (/^MODE\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\.+)\s*/) { $BinMode = $2; $From = $3; # $RealHost $UploadDate = 5; } elsif (/^MAIL\s+(\S+)\s+(\S+)\s/) { $Uploader = $2; } # Info elsif (/^\s*FOLD\s+(\S+)\s+(\S+)/) { ++$Folded; } elsif (/^\s*STAT\s+(\S+)\s+(\S+)/) { $FileSize = $2; } elsif (/^\s*TYPE\s+(\S+)\s+(\S+)/) { $Category = $2; } elsif (/^\s*REPL\s+(\S+)\s+(\S+)/) { $Replace = $2; ++$IsUpdate; } elsif (/^\s*DIST\s+(\S+)/) { } # Scan + Fail error log elsif (/^\s*SCAN\s+(\S+)/) { $ScanErrs{$ScanCnt++} = $2; } elsif (/^\s*FAIL\s+(\S+)/) { $ScanErrs{$ScanCnt++} = $2; } # ZipComment Log elsif (/^\s*DELE\s+(\S+)\s+(\S+)/) { $AdList{$AdCnt++} = $2; } elsif (/^\s*STRIP\s+(\S+)\s*/) { ++$Stripped; } # Virus Test Log elsif (/^\s*CLEAN\s+(\S+)/) { $VirusTest = $VS_OK; } elsif (/^\s*VIRUS\s+(\S+)\s+(\.+)/) { $VirusTest = $VS_INFECTED; $VirusList{$VirusCnt++} = $2; } # ZipTest Log (Note: 'dosmove' stores these on MOVE/HOLD/JUNK entries.) elsif (/^\s*ok\s+(\S+)/) { $ArchiveTest = $AS_OK; } elsif (/^\s*ERROR\s+(\S+)/) { $ArchiveTest = $AS_CORRUPT; } # Moved ? Only one of these conditions should be true. elsif (/^\s*MOVE\s+(\S+)\s*/) { do parse_mode($1); $FileMoved = $FILE_MOVE; $FinalCategory = $rest; } elsif (/^\s*HOLD\s+(\S+)\s*/) { do parse_mode($1); $FileMoved = $FILE_HOLD; # re-upload } elsif (/^\s*JUNK\s+(\S+)\s*/) { do parse_mode($1); $FileMoved = $FILE_JUNK; } } # while } # scan_testlog_entries # ----------------------------------------------------------------------------- sub parse_mode { $rest = ""; if ($FileMoved != $FILE_NONE) { printf STDERR "*** Error in input file: Multiple MOVEs encountered.\n"; } # Get Status Parameters # 'dosmove' passes ZipTest Log on MOVE/HOLD/JUNK entries. # key file integrity rest ## key file integrity if (/\s*\S+\s+(\S+)\s+(\S+)\s+(\S+)/ || /\s*\S+\s+(\S+)\s+(\S+)/) { $atest = $2; $rest = $3; if ($atest < 0) { $ArchiveTest = $AS_CORRUPT; } elsif ($atest == 1) { $ArchiveTest = $AS_OK; } } # if } # parse_mode # ----------------------------------------------------------------------------- # # Print out report form. # # ----------------------------------------------------------------------------- sub print_headers { printf "\n\t\tX2FTP msdos/programming Upload processing Report\n"; } # ----------------------------------------------------------------------------- sub compile_report { printf "\n\n Product Info\n ------------\n"; printf " Filename: %7s", $ZipName; ($Folded) && printf "\t\t[Folded to lowercase / underscore]"; printf "\n FileSize: %5d bytes.\n\n", $FileSize; # [duplicated for multipart programs] printf " Received: %s\n", $UploadDate; printf " Short : %s\n", $Short; printf " Category: %s\n", $Category; printf " Distributable on CD-ROM: %s.\n", $CDString[$CdRomStatus]; if ($Replace) { printf "\tFile is an update.\n"; if ($ReplCnt) { printf "\nFiles removed: $Replace\n"; # for ($i = 0; $i < $ReplCnt; ++$i) { # printf "%s\n", $yy{$i}; # } # } # ReplCnt } # Replace # SCAN, FAIL if ($ScanCnt) { printf "\n\tWarning: Error reading input file '$TxtName'.\n\n"; if ($LongOutput) { for ($i = 0; $i < $ScanCnt; ++$i) { printf "%s\n", $ScanErrs{$i}; } } } # ScanCnt # ---------------------------------------------------------------------------- # Tests Results # printf "\n\n Tests\n ------------\n"; printf " Archive Integrity Test: %s\n", $ArchiveStatus[$ArchiveTest]; printf " Virus Test:\t\t %s\n", $VirusStatus[$VirusTest]; # : if ($VirusCnt) { if ($VirusTest != $VS_INFECTED) { printf STDERR "*** Error in input file: VIRUS status inconsistent.\n"; } for ($i = 0; $i < $VirusCnt; ++$i) { printf "%s\n", $VirusList{$i}; } # Some checking... ($ArchiveTest > $AS_OK) && printf STDERR "*** Error in input file: ARCHIVE status inconsistent.\n"; } # $VirusCnt if ($BinMode eq "a" && ($ArchiveTest == $AS_CORRUPT || $ArchiveTest == $AS_CORRUPT) ) { printf "\n\n NOTE: All archives must be uploaded with BINARY mode.\n"; printf " Please reupload.\n"; } if ($AdCnt) { printf "\n\n File Scan\n ------------\n"; printf " The following excess advertisements have been removed from the archive."; # : # if ($AdCnt != ) { # printf STDERR "*** Error in input file: DELETE count inconsistent.\n"; # } # DELE for ($i = 0; $i < $AdCnt; ++$i) { printf "%s\n", $AdList{$i}; # Deleted ads } } # $AdCnt # STRIP $Stripped && printf " Zip comment stripped.\n"; printf "\n\n Evaluation\n ------------\n"; printf " The archive was found to contain\n\n"; printf "\t[$CheckMark[$IF_readme]] Readme file.\n"; printf "\t[$CheckMark[$IF_docs]] Documentation\n"; # doc,txt,hlp,htm,faq printf "\t[$CheckMark[$IF_source]] Source Code\n"; # C,CC,asm,bas,pascal printf "\t[$CheckMark[$IF_exec]] Executable included.\n"; printf "\t[$CheckMark[$IF_data]] Data files included.\n"; printf "\t[$CheckMark[$IF_shareware]] Shareware product.\n"; $IF_commercial && printf "\t[x] Commercial product.\n"; if ($IF_exec && !$IF_source && !$IF_shareware && !$IF_commercial) { printf "\n\n If possible, full source code should be included on the next version.\n"; } printf "\n\n Conclusion\n ------------\n"; if ($FileMoved == $FILE_MOVE) { # MOVE, ok print " File has been placed available on '$FinalCategory'.\n"; } elsif ($FileMoved == $FILE_HOLD) { # HOLD, corrupt file if ($ArchiveTest > $AS_OK || $VirusTest > $VS_OK) { printf " Archive was not accepted, due to errors.\n"; printf " File should be checked again and reuploaded.\n"; } else { # HOLD, junk printf " File was not accepted, due to insufficient documentation or missing source.\n"; printf " Please, consider improving the product.\n"; } } elsif ($FileMoved == $FILE_JUNK) { # JUNK, junk print " File has been rejected, because it doesn't fit into the scope of\n"; print " Programming and Information.\n"; } else { # HOLD / JUNK ? print " [ Sorry, I forgot what I was supposed to say here. ]\n"; # print " File was not accepted in the current form, since better products"; # print " are available freely.\n"; } } # compile_report sub print_footers { print "\n\n Thank you for uploading on x2ftp. (-:\n"; print "\tThe specialists in Quality and Information.\n"; print "\n\n Feedback: ftpadm\@x2ftp.oulu.fi\n\n"; print "\tX2 FTP Administrators,\n"; print "\tX2 Support Group\n\n"; } # ----------------------------------------------------------------------------- # # Send completed report form. # # ----------------------------------------------------------------------------- sub send_mail { $Subject = "Your '$ZipName' upload on x2ftp"; if ($ArchiveTest > $AS_OK) { $Subject .= " is corrupt."; } elsif ($VirusTest == $VS_INFECTED) { $Subject .= " is infected by virus."; } printf STDERR "Send: Address = '$address' Subject = '$Subject'"; # system ("$MAIL -s $Subject $address < $MAIL_REPORTFILE"); }