コード例 #1
0
ファイル: NetIPStatus.cs プロジェクト: Eric7Apps/BlogSource
        internal void ShowIPStatus()
        {
            ECTime RecTime = new ECTime();
            MForm.ShowStatus( " " );

            string ShowS = "IP Address\t" +
                   "Server Time\t" +
                   "Server Date\t" +
                   "Hacker Count\t" +
                   "Timed Out Count\t" +
                   "Bad Web Page Count\t" +
                   "Good Web Request Count\t" +
                   "Total Good Web Request Count\t" +
                   "Port 80 Count\t" +
                   "GetPublicKeyCount\t" +
                   "TotalGetPublicKeyCount\t" +
                   "ConfirmBillingCount\t" +
                   "TotalConfirmBillingCount\t" +
                   "Referrer\t" +
                   "User Agent\t" +
                   "Host Name\t" +
                   "Sent Text";

            MForm.ShowStatus( ShowS );

            int HowMany = 0;
            foreach( KeyValuePair<string, IPStatusRec> Kvp in IPsDictionary )
              {
              // Don't show too many.  This is only meant as a quick way to show
              // some records.
              HowMany++;
              if( HowMany > 1000 )
            {
            MForm.ShowStatus( " " );
            MForm.ShowStatus( "Can't show more than 1000 IPs." );
            MForm.ShowStatus( " " );
            return;
            }

              RecTime.SetFromIndex( Kvp.Value.TimeIndex );

              ShowS = Kvp.Key + "\t" +
             RecTime.ToLocalTimeString() + "\t" +
             RecTime.ToLocalDateString() + "\t" +
             Kvp.Value.HackerCount.ToString( "N0" ) + "\t" +
             Kvp.Value.TimedOutCount.ToString( "N0" ) + "\t" +
             Kvp.Value.BadWebPageCount.ToString( "N0" ) + "\t" +
             Kvp.Value.GoodWebRequestCount.ToString( "N0" ) + "\t" +
             Kvp.Value.TotalGoodWebRequestCount.ToString( "N0" ) + "\t" +
             Kvp.Value.Port80Count.ToString( "N0" ) + "\t" +
             Kvp.Value.Port443Count.ToString( "N0" ) + "\t" +
             Kvp.Value.GetPublicKeyCount.ToString( "N0" ) + "\t" +
             Kvp.Value.TotalGetPublicKeyCount.ToString( "N0" ) + "\t" +
             Kvp.Value.ConfirmBillingCount.ToString( "N0" ) + "\t" +
             Kvp.Value.TotalConfirmBillingCount.ToString( "N0" ) + "\t" +
             Utility.CleanAsciiString( Kvp.Value.Referer, 300 ) + "\t" +
             Utility.CleanAsciiString( Kvp.Value.UserAgent, 300 ) + "\t" +
             Utility.CleanAsciiString( Kvp.Value.HostName, 300 ) + "\t" +
             Utility.CleanAsciiString( Kvp.Value.SentText, 300 );

              MForm.ShowStatus( ShowS );
              }

            MForm.ShowStatus( " " );
        }
コード例 #2
0
        private void ProcessWebRequests()
        {
            if( MForm.GetIsClosing())
              return;

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            for( int Count = 0; Count < ClientsLast; Count++ )
              {
              if( Clients[Count] == null ) // This should never happen but...
            continue;

              // If this is something that has already been processed.
              if( Clients[Count].GetProcessingStarted())
            continue;

              // IsShutDown is a little slower than the above checks.
              if( Clients[Count].IsShutDown())
            continue;

              if( !Clients[Count].IsBrowserRequest())
            continue;

              if( !Clients[Count].IsBrowserRequestReady())
            continue;

              // ShowStatus( "Got a browser request 2." );

              Clients[Count].SetProcessingStarted( true );

              string InputS = Utility.GetCleanUnicodeString( Clients[Count].GetAllInputS(), 2000 );

              // This FileName is already cleaned ASCII.
              string FileName = Clients[Count].GetHTTPFileRequested();
              string OriginalFileName = FileName;

              FileName = FileName.ToLower();
              FileName = FileName.Replace( "/", "" );
              // ShowStatus( "FileName is: " + FileName );

              if( FileName.StartsWith( "bad http:" ))
            {
            MForm.NetStats.AddToHackerCount( Clients[Count].GetRemoteAddress(), InputS );
            // MForm.ServerLog.AddToLog( "Bad HTTP", InputS, Clients[Count].GetRemoteAddress() );
            Clients[Count].FreeEverything();
            ShowStatus( FileName );
            continue;
            }

              if( FileName.StartsWith( "hacking:" ))
            {
            DailyHackCount++;
            MForm.NetStats.AddToHackerCount( Clients[Count].GetRemoteAddress(), InputS );
            // MForm.ServerLog.AddToLog( "Hacking", InputS, Clients[Count].GetRemoteAddress() );
            Clients[Count].FreeEverything();
            RightNow.SetToNow();
            ShowStatus( RightNow.ToLocalTimeString() + " on " + RightNow.ToLocalDateString() );
            ShowStatus( FileName );
            ShowStatus( " " );
            continue;
            }

              RightNow.SetToNow();
              string Referer = "None";
              string UserAgent = "None";

              if( FileName == "laplata.htm" )
            {
            if( MForm.GetIsClosing())
              return;

            // MForm.NetStats.AddTo...

            byte[] ToSendBuf = MForm.LaPlataData1.GetHTML( "smith" );
            if( ToSendBuf != null )
              Clients[Count].SendGenericWebResponse( ToSendBuf, RightNow.GetIndex(), UniqueEntityTag, "text/html" );

            Referer = Clients[Count].GetReferer();
            UserAgent = Clients[Count].GetUserAgent();
            // MForm.ServerLog.AddToLog() ...
            continue;
            }

              if( !MForm.WebFData.ContainsFile( FileName ))
            {
            Clients[Count].FreeEverything();
             // This is already clean ASCII.
            string LogText = FileName + ": " + InputS;
            // MForm.ServerLog.AddToLog( "No Web File", LogText, Clients[Count].GetRemoteAddress() );
            MForm.NetStats.AddToBadWebPageCount( Clients[Count].GetRemoteAddress(), InputS );
            ShowStatus( " " );
            RightNow.SetToNow();
            ShowStatus( RightNow.ToLocalTimeString() + " on " + RightNow.ToLocalDateString() );
            ShowStatus( "No Web File" );
            ShowStatus( "Original: " + OriginalFileName );
            ShowStatus( "Fixed: " + FileName );
            ShowStatus( "From IP: " + Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".exe" ) || FileName.EndsWith( ".apk" ))
            {
            ShowStatus( " " );
            RightNow.SetToNow();
            ShowStatus( RightNow.ToLocalTimeString() + " on " + RightNow.ToLocalDateString() );
            ShowStatus( "Request for: " + FileName );
            ShowStatus( "From IP: " + Clients[Count].GetRemoteAddress() );
            ShowStatus( " " );
            }

              Referer = Clients[Count].GetReferer();
              UserAgent = Clients[Count].GetUserAgent();
              MForm.NetStats.AddToUserAgentAndReferer( Clients[Count].GetRemoteAddress(), Referer, UserAgent );

              // Increment UniqueEntityTag when it sends something.
              UniqueEntityTag++;
              // FileName is already clean ASCII, it's lower case, and trimmed.

              // This is a reference to the buffer, but the client copies from it.
              byte[] Buffer = MForm.WebFData.GetBuffer( FileName );
              if( Buffer == null )
            {
            ShowStatus( "The buffer was null for a good web request: " + FileName );
            continue;
            }

              if( FileName.EndsWith( ".jpg" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "image/jpeg" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".gif" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "image/gif" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".htm" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "text/html" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".txt" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "text/plain" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".pdf" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "application/pdf" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName == "favicon.ico" )
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "image/vnd.microsoft.icon" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              // Default to sending text unless there's some other way to send it.
              Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "text/plain" );
              // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
              }
        }
コード例 #3
0
ファイル: NetIPStatus.cs プロジェクト: Eric7Apps/BlogSource
        internal bool SaveToFile()
        {
            string FileName = MForm.GetDataDirectory() + "NetStats.txt";

            ECTime RecTime = new ECTime();
            // OldTime.SetToYear1999();
            // ulong OldIndex = OldTime.GetIndex();

            try
            {
            using( StreamWriter SWriter = new StreamWriter( FileName  ))
              {
              foreach( KeyValuePair<string, IPStatusRec> Kvp in IPsDictionary )
            {
            RecTime.SetFromIndex( Kvp.Value.TimeIndex );

            string Line = Kvp.Key + "\t" +
              RecTime.ToLocalTimeString() + "\t" +
              RecTime.ToLocalDateString() + "\t" +
              Kvp.Value.TimeIndex.ToString() + "\t" +
              Kvp.Value.HackerCount.ToString() + "\t" +
              Kvp.Value.TimedOutCount.ToString() + "\t" +
              Kvp.Value.GoodWebRequestCount.ToString() + "\t" +
              Kvp.Value.TotalGoodWebRequestCount.ToString() + "\t" +
              Kvp.Value.Port80Count.ToString() + "\t" +
              Kvp.Value.Port443Count.ToString() + "\t" +
              Kvp.Value.Referer + "\t" +
              Kvp.Value.UserAgent + "\t" +
              Kvp.Value.HostName + "\t" +
              Kvp.Value.LastHostNameUpdate.ToString() + "\t" +
              Kvp.Value.BadWebPageCount.ToString(); //  + "\t" +
              // Kvp.Value.SentText;

            SWriter.WriteLine( Line );
            }

              SWriter.WriteLine( " " );
              }

            return true;

            }
            catch( Exception ) //  Except )
              {
              // "Error: Could not write
              return false;
              }
        }