Skip to content

Commit

Permalink
Update 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kurxz committed Feb 24, 2022
1 parent dd5fedf commit 538158d
Show file tree
Hide file tree
Showing 13 changed files with 2,260 additions and 175 deletions.
Binary file added .vs/FirewallBlocker/v17/.suo
Binary file not shown.
12 changes: 8 additions & 4 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<appSettings>
<add key="langCode" value="pt" />
</appSettings>

</configuration>
39 changes: 36 additions & 3 deletions FirewallBlocker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<ProjectGuid>{1A97060C-6709-47AF-A5D5-4B73E94C07D4}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>FirewallBlocker</RootNamespace>
<AssemblyName>Firewall Blocker</AssemblyName>
<AssemblyName>FirewallBlocker</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<Install>false</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
Expand All @@ -22,10 +23,12 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down Expand Up @@ -56,10 +59,24 @@
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>065A5A488BBBA567AE16A4791B9573FD14826559</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>FirewallBlocker_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -79,6 +96,17 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>strings.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="Form1.en.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.pt-BR.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -92,6 +120,11 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Properties\strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\strings.en.resx" />
<None Include="app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
150 changes: 56 additions & 94 deletions Form1.Designer.cs

Large diffs are not rendered by default.

119 changes: 100 additions & 19 deletions Form1.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Configuration;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace FirewallBlocker
Expand All @@ -15,15 +18,37 @@ public partial class Form1 : Form

private int borderSize = 2;
private Color borderColor = Color.FromArgb(57, 62, 70);
private string langCode = ConfigurationManager.AppSettings["langCode"];

public Form1()
{
InitializeComponent();
var configFile = File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
if (configFile == true)
{
try
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(langCode);
}
catch
{
MessageBox.Show("langCode inválido. Código Ex1", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
System.Environment.Exit(1);
}

this.FormBorderStyle = FormBorderStyle.None;
this.Padding = new Padding(borderSize);
this.mainPanel.BackColor = borderColor;
this.BackColor = borderColor;
InitializeComponent();

this.FormBorderStyle = FormBorderStyle.None;
this.Padding = new Padding(borderSize);
this.mainPanel.BackColor = borderColor;
this.BackColor = borderColor;
}
else
{
MessageBox.Show("Arquivo de configuração inválido. Código Ex2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
System.Environment.Exit(1);
}
}

private void Form1_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -58,7 +83,6 @@ private void createRuleButton_Click(object sender, EventArgs e)
String Program = AppPathTextBox.Text;
String IPs = ipListRichText.Text;
bool InOutRule = false;
bool shouldCreate = false;

if (inoutCheckbox.Checked)
{
Expand All @@ -67,24 +91,22 @@ private void createRuleButton_Click(object sender, EventArgs e)

if (string.IsNullOrEmpty(Program) || Program.Substring(Program.Length - 4) != ".exe")
{
MessageBox.Show("Você não selecionou um aplicativo. Inclua o executável terminando em .exe", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(Properties.strings.notValidExe, Properties.strings.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (string.IsNullOrEmpty(ipListRichText.Text))
{
DialogResult dialogResult = MessageBox.Show("Você deixou a lista de IPs em branco. O app irá block TODOS os IPs para o processo selecionado. Deseja prosseguir?", "Aviso!", MessageBoxButtons.YesNo);
DialogResult dialogResult = MessageBox.Show(Properties.strings.emptyIPList, Properties.strings.Alert, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
shouldCreate = true;
createRule(Program, IPs, InOutRule);
}
else if (dialogResult == DialogResult.No)
{
shouldCreate = false;
}
}

if (shouldCreate == true)
else
{
createRule(Program, IPs, InOutRule);
}
Expand Down Expand Up @@ -116,7 +138,7 @@ private void createRule(String App, String IPs, bool InOutRule)
}
else
{
MessageBox.Show($"Um dos IPs é inválido: {line}", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show($"{Properties.strings.invalidIP} {line}", Properties.strings.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
ipIsOk = false;
break;
}
Expand All @@ -127,7 +149,7 @@ private void createRule(String App, String IPs, bool InOutRule)
block = block.Remove(block.Length - 1);
var cmdCommand = "netsh advfirewall firewall add rule name=\"" + name + "\" ^ dir =in interface=any action = block remoteip=\"" + block + "\"" + " program=\"" + program + "\"";
System.Diagnostics.Process.Start("CMD.exe", "/c" + cmdCommand);
MessageBox.Show("Regra criada", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(Properties.strings.ruleCreated, Properties.strings.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
Expand All @@ -136,7 +158,7 @@ private void createRule(String App, String IPs, bool InOutRule)
{
var cmdCommand = "netsh advfirewall firewall add rule name=\"" + name + "\" ^ dir =in interface=any action = block program=\"" + program + "\"";
System.Diagnostics.Process.Start("CMD.exe", "/c" + cmdCommand);
MessageBox.Show("Regra criada", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(Properties.strings.ruleCreated, Properties.strings.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

Expand All @@ -155,7 +177,7 @@ private void createRule(String App, String IPs, bool InOutRule)
}
else
{
MessageBox.Show($"Um dos IPs é inválido: {line}", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show($"{Properties.strings.invalidIP} {line}", Properties.strings.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
ipIsOk = false;
break;
}
Expand All @@ -168,7 +190,7 @@ private void createRule(String App, String IPs, bool InOutRule)
var blockIn = "netsh advfirewall firewall add rule name=\"" + name + "\" ^ dir =in interface=any action = block remoteip=\"" + block + "\"" + " program=\"" + program + "\"";
System.Diagnostics.Process.Start("CMD.exe", "/c" + blockOut);
System.Diagnostics.Process.Start("CMD.exe", "/c" + blockIn);
MessageBox.Show("Regra criada", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(Properties.strings.ruleCreated, Properties.strings.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
Expand All @@ -179,7 +201,7 @@ private void createRule(String App, String IPs, bool InOutRule)
var blockIn = "netsh advfirewall firewall add rule name=\"" + name + "\" ^ dir =in interface=any action = block program=\"" + program + "\"";
System.Diagnostics.Process.Start("CMD.exe", "/c" + blockOut);
System.Diagnostics.Process.Start("CMD.exe", "/c" + blockIn);
MessageBox.Show("Regra criada", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show(Properties.strings.ruleCreated, Properties.strings.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

Expand Down Expand Up @@ -208,7 +230,7 @@ private void closeButton_Click(object sender, EventArgs e)

private void appHelpButton_Click_1(object sender, EventArgs e)
{
DialogResult dialogResult = MessageBox.Show("Ao continuar irá abrir uma aba no navegador com a página de ajuda. Deseja prosseguir?", "Aviso!", MessageBoxButtons.YesNo);
DialogResult dialogResult = MessageBox.Show(Properties.strings.openHelpWarning, Properties.strings.Alert, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dialogResult == DialogResult.Yes)
{
Process.Start("https://github.com/kurxz/FirewallBlocker/wiki/Help-Page");
Expand Down Expand Up @@ -386,5 +408,64 @@ private void dragArround()
ReleaseCapture();
SendMessage(this.Handle, 0x112, 0xf012, 0);
}

private void langSelectBox_SelectedIndexChanged(object sender, EventArgs e)
{
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
switch (langSelectBox.SelectedIndex)
{
case 0:

AddUpdateAppSettings("langCode", "pt");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pt");

applyTranslations();

break;

case 1:

AddUpdateAppSettings("langCode", "en");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");

applyTranslations();

break;
}
}

private void applyTranslations()
{
pathTitleLabel.Text = Properties.strings.pathTitleLabel;
ipListLabel.Text = Properties.strings.ipListLabel;
selectAppButton.Text = Properties.strings.selectAppButton;
createRuleButton.Text = Properties.strings.createRuleButton;
githubButton.Text = Properties.strings.githubButton;
appHelpButton.Text = Properties.strings.appHelpButton;
inoutCheckbox.Text = Properties.strings.inoutCheckbox;
}

public static void AddUpdateAppSettings(string key, string value)
{
try
{
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (settings.Count == 0 | settings[key] == null)
{
settings.Add(key, value);
}
else
{
settings[key].Value = value;
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
}
catch (ConfigurationErrorsException exc)
{
MessageBox.Show("Falha ao salvar Ex3", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Loading

0 comments on commit 538158d

Please sign in to comment.