public async Task <Process> Run() { string exePath = Path.Combine(MainWindow.WGSM_PATH, @"installer\steamcmd\steamcmd.exe"); if (!File.Exists(exePath)) { Error = $"steamcmd.exe not found ({exePath})"; return(null); } WindowsFirewall firewall = new WindowsFirewall("steamcmd.exe", exePath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); p.StartInfo.FileName = exePath; p.StartInfo.Arguments = _param; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p); }
public async Task <Process> Start(string param) { string workingDir = Functions.Path.GetServerFiles(_serverId); string hldsPath = Path.Combine(workingDir, "hlds.exe"); if (!File.Exists(hldsPath)) { Error = $"hlds.exe not found ({hldsPath})"; return(null); } if (string.IsNullOrWhiteSpace(param)) { Error = "Start Parameter not set"; return(null); } WindowsFirewall firewall = new WindowsFirewall("hlds.exe", hldsPath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); p.StartInfo.WorkingDirectory = workingDir; p.StartInfo.FileName = hldsPath; p.StartInfo.Arguments = param; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p); }
private static bool WindowsFirewallEntryExists(string appPath) { switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: if (Environment.OSVersion.Version.Major > 5) { //vista and above try { return(WindowsFirewall.RuleExistsVista("", appPath) == RuleStatus.Allowed); } catch { return(false); } } else { try { return(WindowsFirewall.ApplicationExists(appPath) == RuleStatus.Allowed); } catch { return(false); } } default: return(false); } }
public Process Run() { string exePath = MainWindow.WGSM_PATH + @"\installer\steamcmd\steamcmd.exe"; if (!File.Exists(exePath)) { Error = "steamcmd.exe not found (" + exePath + ")"; return(null); } WindowsFirewall firewall = new WindowsFirewall("steamcmd.exe", exePath); if (!firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); p.StartInfo.FileName = exePath; p.StartInfo.Arguments = Param; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p); }
public void TestAllowByDefault() { using (var ctx = new Context()) { IPAddress allowed = IPAddress.Parse("128.0.0.1"); string lowerBlock = "X\tYes\tBlock\tAny\t0.0.0.0-128.0.0.0\tAny\tAny"; string upperBlock = "Y\tYes\tBlock\tAny\t128.0.0.2-255.255.255.255\tAny\tAny"; string text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{lowerBlock}\n{upperBlock}"; var firewall = new WindowsFirewall { BlockByDefault = false, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; var packetVars = new WindowsFirewallPacketVariables(ctx); Solver s = ctx.MkSolver(); s.Assert(firewall.Allows(ctx, packetVars)); Status result = s.Check(); Assert.AreEqual(Status.SATISFIABLE, result); var packet = new WindowsFirewallPacket(s.Model); Assert.AreEqual(allowed, packet.SourceAddress); Assert.AreEqual(null, packet.SourcePort); Assert.AreEqual(null, packet.DestinationPort); Assert.AreEqual(null, packet.Protocol); } }
public void TestAllowSingle() { using (var ctx = new Context()) { int localPort = 80; IPAddress remoteAddress = IPAddress.Parse("192.168.1.1"); int remotePort = 128; int protocol = 6; string record = $"X\tYes\tAllow\t{localPort}\t{remoteAddress}\t{remotePort}\t{protocol}"; string text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}"; var firewall = new WindowsFirewall { BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; var packetVars = new WindowsFirewallPacketVariables(ctx); Solver s = ctx.MkSolver(); s.Assert(firewall.Allows(ctx, packetVars)); Status result = s.Check(); Assert.AreEqual(Status.SATISFIABLE, result); var packet = new WindowsFirewallPacket(s.Model); Assert.AreEqual(remoteAddress, packet.SourceAddress); Assert.AreEqual(remotePort, packet.SourcePort); Assert.AreEqual(localPort, packet.DestinationPort); Assert.AreEqual(protocol, packet.Protocol); } }
private static bool AddWindowsFirewallEntry(string appPath) { switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: if (Environment.OSVersion.Version.Major > 5) { //vista and above try { RuleStatus status = WindowsFirewall.RuleExistsVista("", appPath); switch (status) { case RuleStatus.Blocked: case RuleStatus.Disabled: WindowsFirewall.RemoveRuleVista("", appPath); break; case RuleStatus.Allowed: return(true); } WindowsFirewall.AddRuleVista("Technitium DNS Server", "Allow incoming connection request to the DNS server.", FirewallAction.Allow, appPath, Protocol.ANY, null, null, null, null, InterfaceTypeFlags.All, true, Direction.Inbound, true); return(true); } catch { } } else { try { RuleStatus status = WindowsFirewall.ApplicationExists(appPath); switch (status) { case RuleStatus.Disabled: WindowsFirewall.RemoveApplication(appPath); break; case RuleStatus.Allowed: return(true); } WindowsFirewall.AddApplication("Technitium DNS Server", appPath); return(true); } catch { } } break; } return(false); }
public void Start() { //Make sure WUA Is up to Date WUA.Run(); WUA.DisableAutomaticWindowsUpdates(); _updateChecker.Enable(SendNewUpdatesHandler); //Disable Java, Adobe, Acrobat Updaters DisableUpdaters.DisableAll(); //Check WSUS Status Logger.Log("WSUS enabled? {0}", LogLevel.Info, WSUS.IsWSUSEnabled()); Logger.Log("WSUS address? {0}", LogLevel.Info, WSUS.GetServerWSUS); Logger.Log("Automatic updates Enabled? {0}", LogLevel.Info, WSUS.IsAutomaticUpdatesEnabled()); try { var sysTimeZone = GetTimeZone.GetMyTimeZone(); Logger.Log("Current time zone {0}, utc off set {1}.", LogLevel.Info, sysTimeZone.time_zone, sysTimeZone.utc_offset); } catch { Logger.Log("Unable to obtain timezone.", LogLevel.Error); } switch (WSUS.GetAutomaticUpdatesOptions()) { case WSUS.AutomaticUpdateStatus.AutomaticDownloadAndNotifyOfInstall: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Automatic download and notify of install."); break; case WSUS.AutomaticUpdateStatus.AutomaticDownloadAndScheduleInstall: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Automatic download and schedule install."); break; case WSUS.AutomaticUpdateStatus.AutomaticUpdatesIsRequiredAndUsersCanConfigureIt: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Automatic updates is required and users can configure it."); break; case WSUS.AutomaticUpdateStatus.NotifyBeforeDownload: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Notify before download."); break; default: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Not set."); break; } //Check AntiMalware and Firewall Settings Logger.Log("Anti Spyware protection? {0}", LogLevel.Info, WindowsAntiSpyware.IsProtectionEnabled()); Logger.Log("Windows firewall protection? {0}", LogLevel.Info, WindowsFirewall.IsProtectionEnabled()); //Check if system is Windows 8 and Disable automatic restarts //after critical system updates are installed. RvUtils.Windows8AutoRestart(false); }
private bool WindowsFirewallEntryExists(string appPath) { try { return(WindowsFirewall.RuleExistsVista("", appPath) == RuleStatus.Allowed); } catch { return(false); } }
public void TestMultipleDifferences() { int localPort = 8080; int remotePort = 256; int protocol = 17; string record = $"X\tYes\tAllow\t{localPort}\t255.255.255.0-255.255.255.15\t{remotePort}\t{protocol}"; string text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}"; var f1 = new WindowsFirewall { Name = "1", BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; record = $"X\tYes\tAllow\t{localPort}\t255.255.255.0-255.255.255.2\t{remotePort}\t{protocol}"; string record2 = $"Y\tYes\tAllow\t{localPort}\t255.255.255.4-255.255.255.6\t{remotePort}\t{protocol}"; string record3 = $"Y\tYes\tAllow\t{localPort}\t255.255.255.8-255.255.255.10\t{remotePort}\t{protocol}"; string record4 = $"Y\tYes\tAllow\t{localPort}\t255.255.255.12-255.255.255.15\t{remotePort}\t{protocol}"; text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}\n{record2}\n{record3}\n{record4}"; var f2 = new WindowsFirewall { Name = "2", BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; var inconsistencies = WindowsFirewallEquivalenceCheck.CheckEquivalence(f1, f2).ToList(); var expected = new HashSet <IPAddress> { IPAddress.Parse("255.255.255.3"), IPAddress.Parse("255.255.255.7"), IPAddress.Parse("255.255.255.11") }; Assert.AreEqual(3, inconsistencies.Count); foreach (var inconsistency in inconsistencies) { Assert.AreEqual("1", inconsistency.Firewalls.Item1.Name); Assert.IsTrue(inconsistency.Allowed.Item1); Assert.AreEqual("2", inconsistency.Firewalls.Item2.Name); Assert.IsFalse(inconsistency.Allowed.Item2); Assert.AreEqual(1, inconsistency.RuleMatches.Item1.Count); Assert.AreEqual("X", inconsistency.RuleMatches.Item1.Single().Name); Assert.AreEqual(0, inconsistency.RuleMatches.Item2.Count); Assert.AreEqual(remotePort, inconsistency.Packet.SourcePort); Assert.AreEqual(localPort, inconsistency.Packet.DestinationPort); Assert.AreEqual(protocol, inconsistency.Packet.Protocol); Assert.IsTrue(expected.Contains(inconsistency.Packet.SourceAddress)); expected.Remove(inconsistency.Packet.SourceAddress); } Assert.IsFalse(expected.Any()); }
private static void AddWindowsFirewallEntry(string appPath) { switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: if (Environment.OSVersion.Version.Major > 5) { //vista and above try { RuleStatus status = WindowsFirewall.RuleExistsVista("", appPath); switch (status) { case RuleStatus.Blocked: case RuleStatus.Disabled: WindowsFirewall.RemoveRuleVista("", appPath); break; case RuleStatus.Allowed: return; } WindowsFirewall.AddRuleVista("Bit Chat", "Allow incoming connection request to Bit Chat application.", FirewallAction.Allow, appPath, Protocol.ANY); } catch { } } else { try { RuleStatus status = WindowsFirewall.ApplicationExists(appPath); switch (status) { case RuleStatus.Disabled: WindowsFirewall.RemoveApplication(appPath); break; case RuleStatus.Allowed: return; } WindowsFirewall.AddApplication("Bit Chat", appPath); } catch { } } break; } }
public async Task <Process> Run() { string exeFile = "steamcmd.exe"; string exePath = Path.Combine(_installPath, exeFile); if (!File.Exists(exePath)) { //If steamcmd.exe not exists, download steamcmd.exe if (!await Download()) { Error = $"Fail to download {exeFile}"; return(null); } } if (_param == null) { Error = "Steam account is not set"; return(null); } Console.WriteLine($"SteamCMD Param: {_param}"); WindowsFirewall firewall = new WindowsFirewall(exeFile, exePath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process { StartInfo = { WorkingDirectory = _installPath, FileName = exePath, Arguments = _param, WindowStyle = ProcessWindowStyle.Minimized, CreateNoWindow = true, UseShellExecute = false, RedirectStandardInput = true, StandardOutputEncoding = System.Text.Encoding.UTF8, RedirectStandardOutput = true, RedirectStandardError = true }, EnableRaisingEvents = true }; p.Start(); return(p); }
public async Task <Process> Start() { string fxServerPath = Functions.Path.GetServerFiles(_serverId, @"server\FXServer.exe"); if (!File.Exists(fxServerPath)) { Error = $"FXServer.exe not found ({fxServerPath})"; return(null); } string citizenPath = Functions.Path.GetServerFiles(_serverId, @"server\citizen"); if (!Directory.Exists(citizenPath)) { Error = $"Directory citizen not found ({citizenPath})"; return(null); } string serverDataPath = Functions.Path.GetServerFiles(_serverId, "cfx-server-data-master"); if (!Directory.Exists(serverDataPath)) { Error = $"Directory cfx-server-data-master not found ({serverDataPath})"; return(null); } string configPath = Path.Combine(serverDataPath, "server.cfg"); if (!File.Exists(configPath)) { Notice = $"server.cfg not found ({configPath})"; } WindowsFirewall firewall = new WindowsFirewall("FXServer.exe", fxServerPath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); p.StartInfo.WorkingDirectory = serverDataPath; p.StartInfo.FileName = fxServerPath; p.StartInfo.Arguments = $"+set citizen_dir \"{citizenPath}\" {_param}"; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p); }
public async Task <string> GetRemoteBuild(string appId) { string exePath = Path.Combine(_installPath, "steamcmd.exe"); if (!File.Exists(exePath)) { //If steamcmd.exe not exists, download steamcmd.exe if (!await Download()) { Error = "Fail to download steamcmd.exe"; return(""); } } WindowsFirewall firewall = new WindowsFirewall("steamcmd.exe", exePath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process { StartInfo = { FileName = exePath, //Sometimes it fails to get if appID < 90 Arguments = $"+login anonymous +app_info_update 1 +app_info_print {appId} +app_info_print {appId} +app_info_print {appId} +app_info_print {appId} +quit", WindowStyle = ProcessWindowStyle.Minimized, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true } }; p.Start(); string output = await p.StandardOutput.ReadToEndAsync(); Regex regex = new Regex("\"public\"\r\n.{0,}{\r\n.{0,}\"buildid\".{1,}\"(.*?)\""); var matches = regex.Matches(output); if (matches.Count < 1 || matches[1].Groups.Count < 2) { Error = $"Fail to get remote build"; return(""); } return(matches[0].Groups[1].Value); }
public void TestSameFirewall() { string record = "X\tYes\tAllow\t80\t192.168.1.1\t128\t6"; string record2 = "Y\tYes\tAllow\t8080\t127.0.0.1\t256\t6"; string text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}\n{record2}"; var firewall = new WindowsFirewall { BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; var inconsistencies = WindowsFirewallEquivalenceCheck.CheckEquivalence(firewall, firewall); Assert.IsFalse(inconsistencies.Any()); }
public async Task <Process> Start() { int isJavaInstalled = IsJavaJREInstalled(); if (isJavaInstalled == 0) { Error = "Java is not installed"; return(null); } string workingDir = Functions.Path.GetServerFiles(_serverId); string serverJarPath = Path.Combine(workingDir, "server.jar"); if (!File.Exists(serverJarPath)) { Error = $"server.jar not found ({serverJarPath})"; return(null); } string configPath = Path.Combine(workingDir, "server.properties"); if (!File.Exists(configPath)) { Notice = $"server.properties not found ({configPath}). Generated a new one."; } string javaPath = (isJavaInstalled == 1) ? "java" : "C:\\Program Files (x86)\\Java\\jre1.8.0_231\\bin\\java.exe"; if (isJavaInstalled == 2) { WindowsFirewall firewall = new WindowsFirewall("java.exe", javaPath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } } Process p = new Process(); p.StartInfo.WorkingDirectory = workingDir; p.StartInfo.FileName = javaPath; p.StartInfo.Arguments = $"{_param} -jar server.jar nogui"; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p); }
public static string AddFirewallRule(Connection connection) { var result = string.Empty; switch (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { case true: result = WindowsFirewall.BlockIpConnection(connection); break; case false: result = LinuxFirewall.BlockIpConnection(connection); break; } return(result); }
public async Task <Process> Start() { string workingDir = Functions.Path.GetServerFiles(_serverId); string phpPath = workingDir + @"\bin\php\php.exe"; if (!File.Exists(phpPath)) { Error = $"php.exe not found ({phpPath})"; return(null); } string PMMPPath = workingDir + @"\PocketMine-MP.phar"; if (!File.Exists(PMMPPath)) { Error = $"PocketMine-MP.phar not found ({PMMPPath})"; return(null); } string serverConfigPath = workingDir + @"\server.properties"; if (!File.Exists(serverConfigPath)) { Error = $"server.properties not found ({serverConfigPath})"; return(null); } WindowsFirewall firewall = new WindowsFirewall("php.exe", phpPath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); p.StartInfo.WorkingDirectory = workingDir; p.StartInfo.FileName = phpPath; p.StartInfo.Arguments = @"-c bin\php PocketMine-MP.phar"; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p); }
public PreferencesDlg(TeamTalk tt, Settings settings) { ttclient = tt; this.settings = settings; InitializeComponent(); this.CenterToScreen(); dsoundRadioButton.Checked = settings.soundsystem == SoundSystem.SOUNDSYSTEM_DSOUND; winmmRadioButton.Checked = settings.soundsystem == SoundSystem.SOUNDSYSTEM_WINMM; UpdateSoundSystem(null, null); vidcodecComboBox.SelectedIndex = 0; this.vidbitrateNumericUpDown.Value = settings.codec.webm_vp8.nRcTargetBitrate; UpdateVideoCaptureDevices(); fwCheckBox.Checked = WindowsFirewall.AppExceptionExists(Application.ExecutablePath); }
/// <summary> /// Returns a list of inconsistencies between two firewall files. /// </summary> /// <param name="options">Options controlling the check.</param> /// <returns>A list of firewall inconsistencies.</returns> public static List <WindowsFirewallInconsistency> CheckFirewalls(Options options) { Console.WriteLine("Parsing first firewall..."); WindowsFirewall f1 = new WindowsFirewall { BlockByDefault = options.Firewall1BlockByDefault, Rules = WindowsFirewallRuleParser.Parse(File.ReadAllText(options.Firewall1Filepath), '\t').ToList() }; Console.WriteLine("Parsing second firewall..."); WindowsFirewall f2 = new WindowsFirewall { BlockByDefault = options.Firewall2BlockByDefault, Rules = WindowsFirewallRuleParser.Parse(File.ReadAllText(options.Firewall2Filepath), '\t').ToList() }; Console.WriteLine("Running equivalence check..."); return(WindowsFirewallEquivalenceCheck.CheckEquivalence(f1, f2).Take(options.InconsistencyCount).ToList()); }
public (Process Process, string Error, string Notice) Start() { string workingDir = Functions.Path.GetServerFiles(ServerID); string phpPath = workingDir + @"\bin\php\php.exe"; if (!File.Exists(phpPath)) { return(null, "php.exe not found (" + phpPath + ")", ""); } string PMMPPath = workingDir + @"\PocketMine-MP.phar"; if (!File.Exists(PMMPPath)) { return(null, "PocketMine-MP.phar not found (" + PMMPPath + ")", ""); } string serverConfigPath = workingDir + @"\server.properties"; if (!File.Exists(serverConfigPath)) { return(null, "server.properties not found (" + serverConfigPath + ")", ""); } WindowsFirewall firewall = new WindowsFirewall("php.exe", phpPath); if (!firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); p.StartInfo.WorkingDirectory = workingDir; p.StartInfo.FileName = phpPath; p.StartInfo.Arguments = @"-c bin\php PocketMine-MP.phar"; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p, "", ""); }
public void TestSingleDifference() { int localPort = 80; int remotePort = 128; int protocol = 6; string record = $"X\tYes\tAllow\t{localPort}\t192.168.1.0-192.168.1.10\t{remotePort}\t{protocol}"; string text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}"; var f1 = new WindowsFirewall { Name = "1", BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; record = $"X\tYes\tAllow\t{localPort}\t192.168.1.0-192.168.1.4\t{remotePort}\t{protocol}"; string record2 = $"Y\tYes\tAllow\t{localPort}\t192.168.1.6-192.168.1.10\t{remotePort}\t{protocol}"; text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}\n{record2}"; var f2 = new WindowsFirewall { Name = "2", BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; var inconstistencies = WindowsFirewallEquivalenceCheck.CheckEquivalence(f1, f2).ToList(); Assert.AreEqual(1, inconstistencies.Count); WindowsFirewallInconsistency inconsistency = inconstistencies.Single(); Assert.AreEqual("1", inconsistency.Firewalls.Item1.Name); Assert.IsTrue(inconsistency.Allowed.Item1); Assert.AreEqual("2", inconsistency.Firewalls.Item2.Name); Assert.IsFalse(inconsistency.Allowed.Item2); Assert.AreEqual(1, inconsistency.RuleMatches.Item1.Count); Assert.AreEqual("X", inconsistency.RuleMatches.Item1.Single().Name); Assert.AreEqual(0, inconsistency.RuleMatches.Item2.Count); Assert.AreEqual(IPAddress.Parse("192.168.1.5"), inconsistency.Packet.SourceAddress); Assert.AreEqual(remotePort, inconsistency.Packet.SourcePort); Assert.AreEqual(localPort, inconsistency.Packet.DestinationPort); Assert.AreEqual(protocol, inconsistency.Packet.Protocol); }
private bool AddWindowsFirewallEntry(string appPath) { try { RuleStatus status = WindowsFirewall.RuleExistsVista("", appPath); switch (status) { case RuleStatus.Blocked: case RuleStatus.Disabled: WindowsFirewall.RemoveRuleVista("", appPath); break; case RuleStatus.Allowed: return(true); } WindowsFirewall.AddRuleVista("Technitium DNS Server", "Allows incoming connection request to the DNS server.", FirewallAction.Allow, appPath, Protocol.ANY, null, null, null, null, InterfaceTypeFlags.All, true, Direction.Inbound, true); //add web console rule try { WindowsFirewall.RemoveRuleVista("Technitium DNS Server Web Console", ""); } catch { } try { WindowsFirewall.AddRuleVista("Technitium DNS Server Web Console", "Allows access to the DNS server web console.", FirewallAction.Allow, null, Protocol.TCP, _service.WebServiceHttpPort + ", " + _service.WebServiceTlsPort, null, null, null, InterfaceTypeFlags.All, true, Direction.Inbound, true); } catch { } return(true); } catch { return(false); } }
public static string RemoveFirewallRule(Connection connection, PluginConfiguration config) { var result = string.Empty; switch (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { case true: result = WindowsFirewall.AllowIpConnection(connection); config.BannedConnections.Remove(connection); Plugin.Instance.UpdateConfiguration(config); break; case false: result = LinuxFirewall.AllowIpConnection(connection); config.BannedConnections.Remove(connection); Plugin.Instance.UpdateConfiguration(config); break; } return(result); }
public (Process Process, string Error, string Notice) Start() { string workingDir = Functions.Path.GetServerFiles(ServerID); string hldsPath = workingDir + @"\hlds.exe"; if (!File.Exists(hldsPath)) { return(null, "hlds.exe not found (" + hldsPath + ")", ""); } if (string.IsNullOrWhiteSpace(Param)) { return(null, "Start Parameter not set", ""); } string serverConfigPath = workingDir + @"\czero\server.cfg"; if (!File.Exists(serverConfigPath)) { return(null, "", "server.cfg not found (" + serverConfigPath + ")"); } WindowsFirewall firewall = new WindowsFirewall("hlds.exe", hldsPath); if (!firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); p.StartInfo.WorkingDirectory = workingDir; p.StartInfo.FileName = hldsPath; p.StartInfo.Arguments = Param; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p, "", ""); }
public async Task <Process> Start(string param, string customSrcdsName = "srcds.exe", bool setWorkingDirectory = true) { string workingDir = Functions.Path.GetServerFiles(_serverId); string srcdsPath = Path.Combine(workingDir, customSrcdsName); if (!File.Exists(srcdsPath)) { Error = $"{customSrcdsName} not found ({srcdsPath})"; return(null); } if (string.IsNullOrWhiteSpace(param)) { Error = "Start Parameter not set"; return(null); } WindowsFirewall firewall = new WindowsFirewall(customSrcdsName, srcdsPath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p = new Process(); if (setWorkingDirectory) { p.StartInfo.WorkingDirectory = workingDir; } p.StartInfo.FileName = srcdsPath; p.StartInfo.Arguments = param; p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; p.Start(); return(p); }
public void TestEquivalentFirewalls() { string record = "X\tYes\tAllow\t80\t192.168.1.0-192.168.1.10\t128\t6"; string text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}"; var f1 = new WindowsFirewall { BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; record = "X\tYes\tAllow\t80\t192.168.1.0-192.168.1.5\t128\t6"; string record2 = "Y\tYes\tAllow\t80\t192.168.1.6-192.168.1.10\t128\t6"; text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{record}\n{record2}"; var f2 = new WindowsFirewall { BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; var inconstistencies = WindowsFirewallEquivalenceCheck.CheckEquivalence(f1, f2); Assert.IsFalse(inconstistencies.Any()); }
private void AddWindowsFirewallEntry() { if (Environment.OSVersion.Version.Major < 6) { //below vista try { if (!WindowsFirewall.PortExists(Protocol.TCP, _service.ExternalSelfEP.Port)) { WindowsFirewall.AddPort("Bit Chat - TCP", Protocol.TCP, _service.ExternalSelfEP.Port, true); } if (!WindowsFirewall.PortExists(Protocol.UDP, 41733)) { WindowsFirewall.AddPort("Bit Chat - Local Discovery", Protocol.UDP, 41733, true); } } catch { } } else { //vista & above try { string appPath = Assembly.GetEntryAssembly().CodeBase.Replace("file:///", "").Replace("/", "\\"); if (!WindowsFirewall.RuleExistsVista("Bit Chat", appPath)) { WindowsFirewall.AddRuleVista("Bit Chat", "Allow incoming connection request to Bit Chat application.", FirewallAction.Allow, appPath, Protocol.ANY); } } catch { } } }
public void TestConflict() { using (var ctx = new Context()) { int localPort = 80; IPAddress remoteAddress = IPAddress.Parse("192.168.1.1"); int remotePort = 128; int protocol = 6; string allowRecord = $"X\tYes\tAllow\t{localPort}\t{remoteAddress}\t{remotePort}\t{protocol}"; string blockRecord = $"Y\tYes\tBlock\t{localPort}\t{remoteAddress}\t{remotePort}\t{protocol}"; string text = $"{WindowsFirewallRuleParserTest.HeaderText}\n{allowRecord}\n{blockRecord}"; var firewall = new WindowsFirewall { BlockByDefault = true, Rules = WindowsFirewallRuleParser.Parse(text, '\t').ToList() }; var packetVars = new WindowsFirewallPacketVariables(ctx); Solver s = ctx.MkSolver(); s.Assert(firewall.Allows(ctx, packetVars)); Status result = s.Check(); Assert.AreEqual(Status.UNSATISFIABLE, result); } }
public async Task <Process> Start() { string exeName = "7DaysToDieServer.exe"; string workingDir = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID); string exePath = Path.Combine(workingDir, exeName); if (!File.Exists(exePath)) { Error = $"{exeName} not found ({exePath})"; return(null); } string configPath = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, "serverconfig.xml"); if (!File.Exists(configPath)) { Notice = $"serverconfig.xml not found ({configPath})"; } string logFile = @"7DaysToDieServer_Data\output_log_dedi__" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".txt"; string param = $"-logfile \"{Path.Combine(workingDir, logFile)}\" -quit -batchmode -nographics -configfile=serverconfig.xml -dedicated {_serverData.ServerParam}"; WindowsFirewall firewall = new WindowsFirewall(exeName, exePath); if (!await firewall.IsRuleExist()) { firewall.AddRule(); } Process p; if (!AllowsEmbedConsole) { p = new Process { StartInfo = { WorkingDirectory = workingDir, FileName = exePath, Arguments = param, WindowStyle = ProcessWindowStyle.Minimized }, EnableRaisingEvents = true }; p.Start(); } else { p = new Process { StartInfo = { WorkingDirectory = workingDir, FileName = exePath, Arguments = param, WindowStyle = ProcessWindowStyle.Minimized, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true }, EnableRaisingEvents = true }; var serverConsole = new Functions.ServerConsole(_serverData.ServerID); p.OutputDataReceived += serverConsole.AddOutput; p.ErrorDataReceived += serverConsole.AddOutput; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); } return(p); }