/********************************************************************* * scanit() v.1.1 by Stig Johansen 9529.57 * * * * scanit(): is a function made for handling virusscanning of files * * uploaded by users. The function shows a very simple output which * * informs the user what goes on. If the archive/file is infected, * * it will be moved to a safe location. * * * * usage: * * scanit(); * * * * example: * * ->uscript.bz<- * * #include scan11.bz * * * * function main() { * * scanit(); * * } * * ->end<- * * * * You may have to change the paths etc. before using this function. * * It uses the following paths: * * * * $temp/ : temporary storage, ALL FILES ARE DELETED * * $data/ : datafiles storage, should always be there * * * * scanit() also expects the directory d:\bbs\opack to contain the * * following unpackers: UNZIP, LHA, UNARJ, ARC, ZOO * * the parameters is valid for OS/2 versions only. * * * * Infected files are moved to e:\file\in\infected * * * * scanit() is set up for use with McAffes OS2SCAN.EXE * * * * This source file is hereby released to the Public Domain by the * * author: Stig Johansen. * * I can be reached at these addresses: * * BBBSnet: Stig Johansen@47:1000/101 * * FidoNet: Stig Johansen@2:210/20 * * SigNet: Stig Johansen@27:1347/106 * * SkyNet: Stig Johansen@47:300:110 * * * * Have fun... and: release all of your source codes!!! * **********************************************************************/ var $packers, $pstr, $parr, $p_temp, $ptype, $extract_cmd; var $safeplace, $from, $to, $subject, $max_packers; function init_packers() { $max_packers = 5; $packers[0] = "copy %s%s >NUL\n"; $packers[1] = "d:\\bbs\\opack\\unzip -x -j -o -s %s%s >NUL\n"; $packers[2] = "d:\\bbs\\opack\\lha efib %s%s >NUL\n"; $packers[3] = "d:\\bbs\\opack\\unarj e %s%s >NUL\n"; $packers[4] = "d:\\bbs\\opack\\arc ewno %s%s >NUL\n"; $packers[5] = "d:\\bbs\\opack\\zoo -e:o -j %s%s >NUL\n"; $pstr[0] = ""; $pstr[1] = "\e[1mPlease wait while extracting using ZIP\e[0m\n"; $pstr[2] = "\e[1mPlease wait while extracting using LHA\e[0m\n"; $pstr[3] = "\e[1mPlease wait while extracting using UNARJ\e[0m\n"; $pstr[4] = "\e[1mPlease wait while extracting using ARC\e[0m\n"; $pstr[5] = "\e[1mPlease wait while extracting using ZOO\e[0m\n"; $parr = "ZIP/LZH/ARJ/ARC/ZOO"; // The following paths may be changed to fit your setup // The files in this path will ALWAYS be deleted!!! $p_temp = "\\bbs\\$temp\\"; // Here's the place the infected files will be placed. $safeplace = "e:\\file\\in\\infected\\"; // This is the OS/2 command (batch) file which will actually extract/copy // files to the temporary path <$p_temp> $extract_cmd= "d:\\bbs\\$data\\extract.cmd"; // These are the names used in the msg. left to person in post-conf // when a virus is detected. $from = "VirusScanner 1.1"; $to = "SysOp"; $subject = "Virus Report!"; } function bd($s) { while (pos("/",$s)) { $s=sprintf("%s\\%s",copy($s,1,pos("/",$s)-1),copy($s,pos("/",$s)+1,255)); } return($s); } function gettype() { var $ext; if (fopen(0,$extract_cmd,"wt")) { $ext = copy($bv_filna,pos(".",$bv_filna)+1,3); $ptype = parsecom($parr,$ext); if ($ptype > $max_packers) $ptype = 0; fprintf(0,"@echo off\n"); fprintf(0,"cd %s\n",$p_temp); fprintf(0,sprintf($packers[$ptype],bd($bg_updir),$bv_filna)); fclose(0); } else printf("Sorry pc, can't write to extract.cmd!\n"); } function unpack() { if ($pstr[$ptype]!="") printf("%s\n",$pstr[$ptype]); system($extract_cmd,1); } function reportit() { if (fopen(0,strcat($p_temp,"tempfile"),"wt")) { fprintf(0,"Filename : %s\n",$bv_filna); fprintf(0,"Uploaded by : %s\n",$bu_name); fprintf(0,"Uploaded at : %02i:%02i the %i/%i-%i\n\n",$bf_hour,$bf_min,$bf_day,$bf_month,$bf_year); if (fopen(1,strcat($p_temp,"found.vir"),"rt")) { while (!feof(1)) fprintf(0,"%s\n",fgets(1)); fclose(1); } else fprintf(0,"Error opening virus-log.\n"); fclose(0); system(sprintf("bbbs.exe btxt2bbs %i %stempfile /F %s /T %s /S %s",$bc_post_conf,$p_temp,$from,$to,$subject),1); } else printf("Sorry pc, can't open tempfile for \"wt\"\n"); } function moveit() { system(sprintf("move %s%s %s >NUL",bd($bg_updir),$bv_filna,$safeplace),0); } function vscan() { var $err; printf("\e[1mPlease wait while scanning files....\e[0m\n"); $err = system(sprintf("os2scan /ALL %s* /REPORT %sfound.vir >NUL",$p_temp,$p_temp),1); switch ($err) { case 0: { printf("\e[1;32mAll files were ok, good!\e[0;37m\n"); break; } case 13: { printf("\e[1;31m\a\aVIRUS found, please do NOT distribute this archive!\e[33m\n"); printf("The archive will be placed into a safe place and the SysOp will be notified.\e[0;37m\n"); reportit(); moveit(); break; } default: { printf("\e[1;33mERROR:\e[37m virus scanner error %i, please report to SysOp.\e[0m\n",$err); break; } } } function cleanup() { printf("\e[1mPlease wait while cleaning up....\e[0m\n"); system(sprintf("echo y|del %s* >NUL",$p_temp),0); } function scanit() { printf("\e[1;36mYour file will now be checked for virus\e[0;37m\n"); init_packers(); gettype(); unpack(); vscan(); cleanup(); printf("\e[1;36mFinished...\e[0;37m\n"); }