Open WindowsFirewall-Port for Webserver
This commit is contained in:
1 parent
33252ab19c
commit
37e4108249
3 files changed
+52
No files matched your search
@@ -9,6 +9,7 @@ using System.Security.Cryptography.X509Certificates;
|
|||||||
using System.Security.Permissions;
|
using System.Security.Permissions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using NetFwTypeLib;
|
||||||
|
|
||||||
namespace WebserverInitalConfig
|
namespace WebserverInitalConfig
|
||||||
{
|
{
|
||||||
@@ -84,7 +85,44 @@ namespace WebserverInitalConfig
|
|||||||
return cert;
|
return cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addFirewallrule(string exePath, int port, bool isTCP)
|
||||||
|
{
|
||||||
|
INetFwMgr manage = (INetFwMgr)Activator.CreateInstance(
|
||||||
|
Type.GetTypeFromCLSID(new Guid("{304CE942-6E39-40D8-943A-B913C40C9CD4}")));
|
||||||
|
bool isFirewallEnabled = manage.LocalPolicy.CurrentProfile.FirewallEnabled;
|
||||||
|
|
||||||
|
if (isFirewallEnabled)
|
||||||
|
{
|
||||||
|
INetFwAuthorizedApplications applications = manage.LocalPolicy.CurrentProfile.AuthorizedApplications;
|
||||||
|
if ((from INetFwAuthorizedApplication a in applications
|
||||||
|
where a.ProcessImageFileName == exePath
|
||||||
|
select a).Count() == 0)
|
||||||
|
{
|
||||||
|
INetFwAuthorizedApplication application = (INetFwAuthorizedApplication)Activator.CreateInstance(
|
||||||
|
Type.GetTypeFromCLSID(new Guid("{EC9846B3-2762-4A6B-A214-6ACB603462D2}")));
|
||||||
|
|
||||||
|
application.Name = "Vocaluxe";
|
||||||
|
application.ProcessImageFileName = exePath;
|
||||||
|
application.Enabled = true;
|
||||||
|
applications.Add(application);
|
||||||
|
}
|
||||||
|
INetFwOpenPorts openPorts = manage.LocalPolicy.CurrentProfile.GloballyOpenPorts;
|
||||||
|
if ((from INetFwOpenPort p in openPorts
|
||||||
|
where (p.Port == port &&
|
||||||
|
(p.Protocol == (isTCP?NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP : NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP)))
|
||||||
|
select p).Count() == 0)
|
||||||
|
{
|
||||||
|
INetFwOpenPort openPort = (INetFwOpenPort)Activator.CreateInstance(
|
||||||
|
Type.GetTypeFromCLSID(new Guid("{0CA545C6-37AD-4A6C-BF92-9F7610067EF5}")));
|
||||||
|
openPort.Enabled = true;
|
||||||
|
openPort.Port = port;
|
||||||
|
openPort.Protocol = (isTCP ? NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP : NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP);
|
||||||
|
openPort.Name = "Vocaluxe";
|
||||||
|
|
||||||
|
openPorts.Add(openPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/*public static X509Certificate2 getCert(string subject)
|
/*public static X509Certificate2 getCert(string subject)
|
||||||
{
|
{
|
||||||
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
|
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
@@ -18,6 +19,8 @@ namespace WebserverInitalConfig
|
|||||||
Console.WriteLine("Usage: WebserverInitalConfig port isHttps");
|
Console.WriteLine("Usage: WebserverInitalConfig port isHttps");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigHttpApi.addFirewallrule(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Vocaluxe.exe"), Int32.Parse(args[0]), true);
|
||||||
|
|
||||||
if (args[1].ToLower() == "true")
|
if (args[1].ToLower() == "true")
|
||||||
{
|
{
|
||||||
string hostname = Dns.GetHostName();
|
string hostname = Dns.GetHostName();
|
||||||
|
|||||||
@@ -61,6 +61,17 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<COMReference Include="NetFwTypeLib">
|
||||||
|
<Guid>{58FBCF7C-E7A9-467C-80B3-FC65E8FCCA08}</Guid>
|
||||||
|
<VersionMajor>1</VersionMajor>
|
||||||
|
<VersionMinor>0</VersionMinor>
|
||||||
|
<Lcid>0</Lcid>
|
||||||
|
<WrapperTool>tlbimp</WrapperTool>
|
||||||
|
<Isolated>False</Isolated>
|
||||||
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
|
</COMReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
Reference in new issue
Block a user