Skip to content

Commit

Permalink
Merge pull request #74 from FN-FAL113/Dev/firewall-check-and-reset
Browse files Browse the repository at this point in the history
add firewall reset and status check function
  • Loading branch information
FN-FAL113 authored Oct 13, 2024
2 parents 8aa2289 + 56b1c1b commit 617d3ab
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CS2ServerPicker/App.vb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
Environment.NewLine +
"Author: FN-FAL113 (github username)" + Environment.NewLine +
"License: GNU General Public License V3" + Environment.NewLine +
"App Version: 2.2.3",
"App Version: 2.4.0",
"App Info"
)
End Sub
Expand Down
4 changes: 2 additions & 2 deletions CS2ServerPicker/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("2.2.3.0")>
<Assembly: AssemblyFileVersion("2.2.3.0")>
<Assembly: AssemblyVersion("2.4.0.0")>
<Assembly: AssemblyFileVersion("2.4.0.0")>
<Assembly: NeutralResourcesLanguage("en")>
6 changes: 3 additions & 3 deletions CS2ServerPicker/Services/ServerService.vb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Module ServerService
proc.WaitForExit()

If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
Throw New Exception(proc.StandardOutput.ReadToEnd().Split(".")(0))
Throw New Exception("StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())

Continue For
End If
Expand Down Expand Up @@ -215,7 +215,7 @@ Module ServerService
proc.WaitForExit()

If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
Throw New Exception(proc.StandardOutput.ReadToEnd().Split(".")(0))
Throw New Exception("StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())

Continue For
End If
Expand Down Expand Up @@ -274,7 +274,7 @@ Module ServerService
proc.WaitForExit()

If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
Throw New Exception(proc.StandardOutput.ReadToEnd().Split(".")(0))
Throw New Exception("StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())

Continue For
End If
Expand Down
56 changes: 53 additions & 3 deletions CS2ServerPicker/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions CS2ServerPicker/Settings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="BackgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
65 changes: 65 additions & 0 deletions CS2ServerPicker/Settings.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,69 @@
VersionCheckerCheckBox.Checked = My.Settings.VersionCheckOnStartup
End Sub

Private Sub ResetFirewallButton_Click(sender As Object, e As EventArgs) Handles ResetFirewallButton.Click
Dim resetWindowsFirewallRes As DialogResult = MessageBox.Show("This will attempt to reset windows firewall to its default state. Confirm action?", "Reset Windows Firewall", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)

If resetWindowsFirewallRes = DialogResult.Yes Then
Try
Dim proc As Process = Create_Custom_CMD_Process()

proc.StartInfo.Arguments = "/c netsh advfirewall reset"
proc.Start()
proc.WaitForExit()

If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
Throw New Exception("Sdtout: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "Stderr: " + proc.StandardError.ReadToEnd())
End If

MessageBox.Show("Windows firewall reset successful!", "Reset Windows Firewall", MessageBoxButtons.OK, MessageBoxIcon.Information)

proc.Dispose()
Catch ex As Exception
Log_Exception_To_File(ex, "An error has occurred while resetting windows firewall!")

MessageBox.Show("An error has occurred while resetting windows firewall!", "Error")
End Try
End If
End Sub

Private Sub CheckFirewallButton_Click(sender As Object, e As EventArgs) Handles CheckFirewallButton.Click
Dim checkWindowsFirewallRes As DialogResult = MessageBox.Show("This will attempt to check current state of windows firewall. Confirm action?", "Check Windows Firewall", MessageBoxButtons.YesNo, MessageBoxIcon.Information)

If checkWindowsFirewallRes = DialogResult.Yes Then
Try
Dim proc As Process = Create_Custom_CMD_Process()

proc.StartInfo.Arguments = "/c netsh advfirewall show allprofiles state"
proc.Start()
proc.WaitForExit()

If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
Throw New Exception("On firewall check" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
End If

If proc.StandardOutput.ReadToEnd().Contains("OFF") Then
Dim enableWinFirewallRes As DialogResult = MessageBox.Show("This will attempt to enable windows firewall. Confirm action?", "Enable Windows Firewall", MessageBoxButtons.YesNo, MessageBoxIcon.Information)

proc.StartInfo.Arguments = "/c netsh advfirewall set allprofiles state on"
proc.Start()
proc.WaitForExit()

If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
Throw New Exception("On firewall enable" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
End If

MessageBox.Show("Windows firewall profile states successfully enabled!", "Enable Windows Firewall", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Windows firewall profile states are all enabled.", "Windows Firewall Status", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

proc.Dispose()
Catch ex As Exception
Log_Exception_To_File(ex, "An error has occurred while checking/enabling windows firewall!")

MessageBox.Show("An error has occurred while checking/enabling windows firewall!", "Error")
End Try
End If
End Sub
End Class

0 comments on commit 617d3ab

Please sign in to comment.