Exemplo n.º 1
0
 /// <summary>
 /// test all sentinal files
 /// </summary>
 private void TestSentinalFiles()
 {
     foreach (FileRecord File in config.Files)
     {
         if (File.Sentinal)
         {
             Sentinal sentinal = new Sentinal(File.Path);
             if (sentinal.Test())
             {
                 log.Write("   Passed: " + File.Path, 2402);
             }
             else
             {
                 log.Write("   Failed: " + File.Path + "  " + sentinal.Error, 2404, System.Diagnostics.EventLogEntryType.Warning);
                 try
                 {
                     if (sentinal.Randomness < 400)
                     {
                         log.Write("           " + File.Path + "  POSSIBLY ENCRYPTED", 2492, System.Diagnostics.EventLogEntryType.Warning);
                     }
                 }
                 catch (Exception e)
                 {
                     // probably a permission issue, more details will be in the exception message
                     log.Write("           " + File.Path + "  Unknown status - " + e.Message,
                               4916, System.Diagnostics.EventLogEntryType.Warning);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Event handler called when a file changes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventargs"></param>
        private void File_Changed(object sender, System.IO.FileSystemEventArgs eventargs)
        {
            string filepath   = eventargs.FullPath;
            string changetype = eventargs.ChangeType.ToString();

            // If its a sentinal file, check for content change
            if (config.IsSentinal(filepath))
            {
                log.Write("Sentinal file: " + filepath + " " + changetype + " Detected", 2406);
                Sentinal sentinal = new Sentinal(filepath);
                if (sentinal.Test())
                {
                    log.Write("Sentinal file: " + filepath + " Contents unchanged", 2408);
                    return;
                }
                else
                {
                    log.Write("Sentinal file: " + filepath + " Contents changed", 2407, System.Diagnostics.EventLogEntryType.Warning);
                    try
                    {
                        if (sentinal.Randomness < 400)
                        {
                            log.Write("              " + filepath + " POSSIBLY ENCRYPTED", 2491, System.Diagnostics.EventLogEntryType.Warning);
                        }
                    }
                    catch (Exception e)
                    {
                        // probably a permission issue, more details will be in the exception message
                        log.Write("           " + filepath + "  Unknown status - " + e.Message,
                                  4918, System.Diagnostics.EventLogEntryType.Warning);
                    }
                }
            }
            else  // not a sentinal file
            {
                StringBuilder message = new StringBuilder();
                message.Append("File: " + filepath + "  " + changetype);
                log.Write(message.ToString(), 2001, System.Diagnostics.EventLogEntryType.Warning);
            }

            // Do any action specified for the particular change that occured
            DoAction(filepath, "", changetype);
        }