void Timing() { try { while (timing) { Thread.Sleep(1000); UpdateAdapterList(); } } catch (ArgumentOutOfRangeException e) { LogCenter.WriteErrorLog(e); } }
public void LoadModule(string file) { FirewallModule mod = null; lock (loadedAssemblies) { if (file.Contains("FirewallModule.dll") || !file.Contains(".dll")) { return; } try { if (loadedMods.ContainsValue(file)) { return; } Assembly assembly; if (!loadedAssemblies.TryGetValue(file, out assembly)) { assembly = Assembly.Load(File.ReadAllBytes(file)); loadedAssemblies.Add(file, assembly); } Type[] type = assembly.GetTypes(); foreach (Type t in type) { if (typeof(FirewallModule).IsAssignableFrom(t)) { mod = (FirewallModule)Activator.CreateInstance(t); mod.adapter = na; mod.Enabled = false; //mod.ModuleStart(); AddModule(mod); loadedMods.Add(mod.MetaData.Name, file); } } } catch (ArgumentException ae) { LogCenter.Instance.Push(mod.MetaData.Name, "Module attempted load twice."); LogCenter.WriteErrorLog(ae); } catch (Exception e) { LogCenter.WriteErrorLog(e); } } }
static void OpenNDISDriver() { if (hNdisapi != IntPtr.Zero) { LogCenter.Instance.Push("NetworkAdapter-static", "Bad state was found, attempting to open the NDIS Filter Driver while the IntPtr != IntPtr.Zero, continuing"); } hNdisapi = Ndisapi.OpenFilterDriver(Ndisapi.NDISRD_DRIVER_NAME); TCP_AdapterList adList = new TCP_AdapterList(); Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList); if (adList.m_nAdapterCount == 0) { LogCenter.WriteErrorLog(new Exception("No adapters found on this driver interface")); return; } isNdisFilterDriverOpen = true; }
/// <summary> /// Save the general configuration /// </summary> public void SaveGeneralConfig() { try { string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); folder = folder + Path.DirectorySeparatorChar + "firebwall"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string file = folder + Path.DirectorySeparatorChar + "generalconfig.cfg"; FileStream stream = File.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; bFormatter.Serialize(stream, gSettings); stream.Close(); } catch (Exception e) { LogCenter.WriteErrorLog(e); } }
/* * Method called once per run, used to check log paths to * clean up any old logs. Called from MainWindow.cs - Load(). * * Logs are retained for however long the user requests (default is 5 days) */ public static void cleanLogs() { if (OptionsDisplay.gSettings == null) { OptionsDisplay.LoadGeneralConfig(); } try { // // first clean up the /Log/ folder // string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); folder = folder + Path.DirectorySeparatorChar + "firebwall"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } folder = folder + Path.DirectorySeparatorChar + "Log"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string filepath = folder; if (Directory.Exists(filepath)) { // grab all the logs in the directory string[] files = Directory.GetFiles(filepath); // iterate through them all looking for any that are old (>5) foreach (string s in files) { // grab the log date from file path name and // convert to DateTime for day check string logdate = s.Substring(s.LastIndexOf("_") + 1, (s.LastIndexOf(".") - s.LastIndexOf("_")) - 1); DateTimeFormatInfo dtfi = new DateTimeFormatInfo(); dtfi.ShortDatePattern = "MM-dd-yyyy"; dtfi.DateSeparator = "-"; DateTime logDate = Convert.ToDateTime(logdate, dtfi); // if it's old, get rid of it if ((DateTime.Now - logDate).Days > OptionsDisplay.gSettings.max_logs) { if (isFileLocked(new FileInfo(s))) { continue; } File.Delete(s); } } } // // Now clean up the pcap logs folder // folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); folder = folder + Path.DirectorySeparatorChar + "firebwall"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } folder = folder + Path.DirectorySeparatorChar + "pcapLogs"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } filepath = folder; if (Directory.Exists(filepath)) { string[] files = Directory.GetFiles(filepath); if (files.Length > OptionsDisplay.gSettings.max_pcap_logs) { // hack off the number of files found in Settings (default should be 25), starting // from the oldest for (int i = 0; i < (files.Length - OptionsDisplay.gSettings.max_pcap_logs); ++i) { // if it's not accessible, skip it for next time if (isFileLocked(new FileInfo(files[i]))) { continue; } File.Delete(files[i]); } } } } catch (Exception e) { LogCenter.WriteErrorLog(e); } }