     '$include "Code\3rdParty\3rdParty.WCC"

     // Assumes no two users have same name (UserID_From_UserName)
     // Door counter needs to be safe for multinode

     const Log_Str_Scanned        = "Log Scan:  activity log scanned"
     const Log_Str_Wrong_Password = "SECURITY VERIFICATION ERROR: Wrong password"
     const Log_Str_Door           = "* DOOR : Door "
     const Log_Str_Downloaded     = "] downloaded from (Area "
     const Log_Str_Login          = " on "

     const DoorSort_BBS = "Disp\DoorSort.BBS"
     const Doors_BBS    = "Disp\Doors.BBS"
     const Doors_Old    = "Disp\Doors.Old"
     const DoorList_BBS = "Disp\DoorList.BBS"
     const DoorHead_BBS = "Disp\DoorHead.BBS"
     const DoorTail_BBS = "Disp\DoorTail.BBS"
     const Download_Pre = "LogScanD."
     const Download_Txt = "Download.Txt"

     const Door_Max = 99
     dim Door_Count ( Door_Max ) as long

     sub Door_Opened ( \
       byval Line as string )
     //////////////////////////////////////////////////////////////////////
       dim Door_Num as integer
     //////////////////////////////////////////////////////////////////////
       Line = Trim ( Line )
       Line = Right ( Line, len ( Line ) - len ( Log_Str_Door ) )
       Line = Left ( Line, InStr ( Line, " executed " ) - 1 )
       Door_Num = Val ( Line )
       ? "Door "; Door_Num
       Door_Count ( Door_Num ) = Door_Count ( Door_Num ) + 1
     end sub

     sub Door_Sort_Init
     //////////////////////////////////////////////////////////////////////
       dim Line_Num as long
       dim Door_Num as integer
       dim Line     as string
     //////////////////////////////////////////////////////////////////////
       for Door_Num = 1 to Door_Max
         Door_Count ( Door_Num ) = 0
       next Door_Num
       if Exists ( DoorSort_BBS ) then
         open DoorSort_BBS for input as #2
         Line_Num = 0
         while not EOF ( 2 )
           input #2, Line
           Line_Num = Line_Num + 1
           if Line_Num >= 6 then
             Door_Num = Val ( Mid ( Line, 1, 5 ) )
             Door_Count ( Door_Num ) = Val ( Mid ( Line, 8, 10 ) )
           end if
         wend
         close ( 2 )
       end if
     end sub

     sub Door_Sort ( \
       byval Copyright as string )
     //////////////////////////////////////////////////////////////////////
       dim Line_Num as integer
       dim Door_Num as integer
       dim Line as string
     //////////////////////////////////////////////////////////////////////
       SortStart
       for Door_Num = 1 to Door_Max
         SortAdd ( \
           FormatNumber ( Door_Count ( Door_Num ), "@#########" ), Door_Num )
       next Door_Num
       Door_Num = SortPrev
       open DoorSort_BBS for output as #4
       ? #4, "Doors Sorted by Popularity"
       ? #4, Copyright
       ? #4, ""
       ? #4, "Door#  Times Used"
       ? #4, "-----  ----------"
       if Exists ( DoorList_BBS ) then
         CopyFile ( Doors_BBS, Doors_Old )
         open Doors_BBS for output as #3
         if Exists ( DoorHead_BBS ) then
           open DoorHead_BBS for input as #2
           while not EOF ( 2 )
             input #2, Line
             print #3, Line
           wend
           close ( 2 )
         else
           ? DoorHead_BBS + " missing."
         end if
       else
         ? DoorList_BBS + " missing."
       end if
       while Door_Num >= 0
         ? FormatNumber ( Door_Num, "#####" ); "  ";
         ? FormatNumber ( Door_Count ( Door_Num ), "##########" )
         if Door_Count ( Door_Num ) > 0 then
           ? #4, FormatNumber ( Door_Num, "#####" ); "  ";
           ? #4, FormatNumber ( Door_Count ( Door_Num ), "##########" )
         end if
         if Exists ( DoorList_BBS ) then
           open DoorList_BBS for input as #2
           Line_Num = 0
           Line = ""
           do
             if EOF ( 2 ) then
               Line = ""
               exit do
             end if
             Line_Num = Line_Num + 1
             if Line_Num > Door_Num then
               exit do
             end if
             input #2, Line
             if Line_Num = Door_Num then
               exit do
             end if
           loop
           close #2
           if Trim ( Line ) > "" then
             ? #3, Line
           end if
         end if
         Door_Num = SortPrev
       wend
       if Exists ( DoorList_BBS ) then
         if Exists ( DoorTail_BBS ) then
           open DoorTail_BBS for input as #2
           while not EOF ( 2 )
             input #2, Line
             print #3, Line
           wend
           close ( 2 )
         else
           ? DoorTail_BBS + " missing."
         end if
         close ( 3 )
       end if
       close ( 4 )
     end sub

     sub Downloaded ( byval Line as string, \
       byval Download_Tmp as string )
     //////////////////////////////////////////////////////////////////////
       dim File_Name as string*12
       dim File_Num_Download as integer
       dim Cost as integer
       dim FileRec as FileRecord
     //////////////////////////////////////////////////////////////////////
       Line = Mid  ( Line, InStr ( Line, "[" ) + 1, 13 )
       File_Name = Left ( Line, InStr ( Line, "]" ) - 1 )
       ? "Downloaded:  "; File_Name
       File_Num_Download = FreeFile
       open Download_Tmp for append as File_Num_Download
       ? #File_Num_Download, Pad ( File_Name, 12 ); " ";
       Cost = 0
       if GetFileInfo ( FileRec, File_Name ) then
         Cost = FileRec.Cost
       end if
       ? #File_Num_Download, "$"; FormatNumber ( Cost / 100, "@##.##" )
       close ( File_Num_Download )
     end sub

     function Login ( byval Line as string ) as string
     //////////////////////////////////////////////////////////////////////
       dim Login_User as string
     //////////////////////////////////////////////////////////////////////
       Login = ""
       if Line ( 3 ) <> ":" then
         exit function
       end if
       if ( InStr ( Line, "[" ) = 0 ) or ( InStr ( Line, "]" ) = 0 ) then
         exit function
       end if
       Login_User = Mid ( Line, 7, InStr ( Line, " [" ) - 6 )
       ? "Login:  "; Login_User
       Login = Login_User
     end function

     sub Wrong_Password ( \
       Line as string, \
       byval Temp_File as string, \
       byval Copyright as string )
     //////////////////////////////////////////////////////////////////////
       dim Tried as string
       dim Victim as string
       dim TimeBaud as string
       dim Time as string
       dim Baud as string
       dim MsgHdr as MessageHeader
     //////////////////////////////////////////////////////////////////////
       ? trim ( Line )
       tried = READBACKNEXT
       tried = right (tried, len ( tried ) -15)
       tried = left (tried, len (tried) -2)
       ? tried
       victim = Mid (READBACKNEXT, 38)
       victim = left (victim, len ( victim ) -1)
       ? victim
       timebaud = READBACKNEXT
       time = Left (timebaud, 5)
       ? time
       baud = Mid (timebaud, 32)
       baud = left (baud, len (baud) -4)
       ? baud
       MsgHdr.From = MakeWild.SysopName
       MsgHdr.FromTitle = "Log Scan"
       MsgHdr.To = Victim
       MsgHdr.Subject = "Warning:  Bad Login"
       MsgHdr.Flags = 1 :REM Makes it private
       open Temp_File for output as #1
       ? #1, victim + ":"
       ? #1, "A failed login attempt was recently made using your username."
       ? #1, "The user called at " + time + " connecting at " + baud + "bps."
       ? #1, "The user attempted the following passwords:"
       ? #1, tried
       ? #1, ""
       ? #1, "You may want to change your password.  If so, be sure to"
       ? #1, "select a password that you are not using on another BBS."
       ? #1, ""
       ? #1, Copyright;
       close #1
       AddMessage ( MsgHdr, Temp_File )
       Del Temp_File
     end sub

     sub Main_Loop ( \
             Downloads_Found as boolean, \
       byval First_Sweep as boolean, \
       byval Temp_File as string, \
       byval Copyright as string,\
       byval Node_Str as string, \
       byval Download_Tmp as string )
     //////////////////////////////////////////////////////////////////////
       dim Login_User as string
       dim Line as string
     //////////////////////////////////////////////////////////////////////
       do while not ReadBackTOF
         Line = READBACKNEXT
         if InStr ( Line, Log_Str_Login ) <> 0 then
           Login_User = Login ( Line )
           if Login_User <> "" then
             if Downloads_Found then
               File_Text_Insert ( Download_Tmp, \
                 UserData_Dir ( UserID_From_UserName ( Login_User ), \
                   Login_User ) + Download_Txt )
               Downloads_Found = false
               del Download_Tmp
               if not First_Sweep then
                 exit do
               end if
             end if
           end if
         elseif Instr (Line, Log_Str_Scanned) <> 0 then
           exit do
         elseif First_Sweep then
           if Instr (Line, Log_Str_Wrong_Password ) <> 0 then
             Wrong_Password ( Line, Temp_File, Copyright )
           elseif InStr ( Line, Log_Str_Door ) <> 0 then
             if Node_Str = "1" then
               Door_Opened ( Line )
             end if
           elseif InStr ( Line, Log_Str_Downloaded ) <> 0 then
             Downloaded ( Line, Download_Tmp )
             Downloads_Found = true
           end if
         end if
       loop
     end sub

     sub Log_Scan_Start ( \
       byval Copyright as string )
     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////
       dim Temp_File as string
       Dim Line As String
       Dim linenumber As Integer
       Dim tried As String
       Dim victim As String
       Dim timebaud As String
       Dim time as String
       Dim baud as String
       dim Node_Str as string
       dim Door_Num as integer
       dim Downloads_Found as boolean
       dim First_Sweep as boolean
       dim Download_Tmp as string
     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

       if Copyright = "" then
         Copyright = "Log Scan v1.2 (C) 1995 David & Shannon Croft"
       end if
       MorePrompt Off
       ? Copyright

       Node_Str = Trim ( Str ( MakeWild.NodeID ) )
       Temp_File = "Log_Scan." + Node_Str
       ? "Scanning the activity log for node " + Node_Str + "."
       if not READBACKOPEN ("activity." + Node_Str ) then
         Beep
         ? "Error.  Unable to open file activity." + Node_Str + "!"
         Delay 10
         end
       end if

       if Node_Str = "1" then
         Door_Sort_Init
       end if

       Download_Tmp = WCWork_Dir + "Download.Tmp"
       Del ( Download_Tmp )
       Downloads_Found = false
       First_Sweep = true
       do while not ReadBackTOF
         Main_Loop ( Downloads_Found, First_Sweep, \
           Temp_File, Copyright, Node_Str, Download_Tmp )
         if not Exists ( Download_Tmp ) then
           exit do
         end if
         First_Sweep = false
       loop
       ReadBackClose
       Activitylog ( Log_Str_Scanned )
       if Node_Str = "1" then
         Door_Sort ( Copyright )
       end if
       ? Log_Str_Scanned
       ? "Delaying 5 seconds..."
       delay 5
     end sub