List:Commits« Previous MessageNext Message »
From:Mike Lischke Date:April 7 2011 6:04pm
Subject:bzr commit into wex-installer-1.0 branch (mike.lischke:417)
View as plain text  
#At file:///D:/Work/MySQL/installer/ based on revid:mike.lischke@stripped

  417 Mike Lischke	2011-04-07
      Added firewall handling for server port (add/remove).

    added:
      WexInstaller.Core/Networking.cs
    modified:
      StandardPlugins/Properties/Resources.Designer.cs
      StandardPlugins/Properties/Resources.resx
      StandardPlugins/Server/ConfigurationController.cs
      StandardPlugins/StandardPlugins.csproj
      WexInstaller.Core/Utilities.cs
      WexInstaller.Core/WexInstaller.Core.csproj
      WexInstaller/Controls/WelcomeControl.cs
      WexInstaller/Program.cs
=== modified file 'StandardPlugins/Properties/Resources.Designer.cs'
=== modified file 'StandardPlugins/Properties/Resources.Designer.cs'
--- a/StandardPlugins/Properties/Resources.Designer.cs	2011-03-29 16:10:30 +0000
+++ b/StandardPlugins/Properties/Resources.Designer.cs	2011-04-07 18:04:48 +0000
@@ -416,6 +416,33 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Adding firewall rule failed..
+        /// </summary>
+        internal static string ServerConfigFirewallSettingFailed {
+            get {
+                return ResourceManager.GetString("ServerConfigFirewallSettingFailed", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Adding firewall rule for {0} on port {1}..
+        /// </summary>
+        internal static string ServerConfigFirewallSettingInfo {
+            get {
+                return ResourceManager.GetString("ServerConfigFirewallSettingInfo", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Adding firewall rule was successful..
+        /// </summary>
+        internal static string ServerConfigFirewallSettingSucceeded {
+            get {
+                return ResourceManager.GetString("ServerConfigFirewallSettingSucceeded", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to The specified value is not valid..
         /// </summary>
         internal static string ServerConfigInvalidPort {

=== modified file 'StandardPlugins/Properties/Resources.resx'
--- a/StandardPlugins/Properties/Resources.resx	2011-03-29 16:10:30 +0000
+++ b/StandardPlugins/Properties/Resources.resx	2011-04-07 18:04:48 +0000
@@ -256,7 +256,6 @@
   <data name="ServerConfigPasswordsDoNotMatch" xml:space="preserve">
     <value>The passwords do not match.</value>
   </data>
-  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   <data name="config_logs" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\config_logs.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
@@ -266,4 +265,13 @@
   <data name="config_win_integration" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\config_win_integration.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
+  <data name="ServerConfigFirewallSettingInfo" xml:space="preserve">
+    <value>Adding firewall rule for {0} on port {1}.</value>
+  </data>
+  <data name="ServerConfigFirewallSettingFailed" xml:space="preserve">
+    <value>Adding firewall rule failed.</value>
+  </data>
+  <data name="ServerConfigFirewallSettingSucceeded" xml:space="preserve">
+    <value>Adding firewall rule was successful.</value>
+  </data>
 </root>
\ No newline at end of file

=== modified file 'StandardPlugins/Server/ConfigurationController.cs'
--- a/StandardPlugins/Server/ConfigurationController.cs	2011-03-29 16:10:30 +0000
+++ b/StandardPlugins/Server/ConfigurationController.cs	2011-04-07 18:04:48 +0000
@@ -6,6 +6,7 @@
 using System.Windows.Forms;
 using System.ServiceProcess;
 
+using NetFwTypeLib;
 using MySql.Data.MySqlClient;
 
 using WexInstaller.Core;
@@ -81,7 +82,11 @@
         if (CreateService)
         {
           if (ProcessService())
+          {
             ProcessSecuritySettings();
+            if (Template.EnableNetworking)
+              CreateFirewallRule();
+          }
         }
       }
     }
@@ -189,13 +194,12 @@
       switch (Owner.CurrentState)
       {
         case ProductState.RemoveStarted:
+          RemoveFirewallRule();
+
           if (ServiceName != null)
           {
             if (ScManager.GetServiceStatus(ServiceName) == System.ServiceProcess.ServiceControllerStatus.Running)
-            {
               ScManager.Stop(ServiceName);
-              //ScManager.Delete(ServiceName);
-            }
           }
 
           break;
@@ -217,6 +221,7 @@
         case (ConfigurationEventType.Info):
           switch (e.Action)
           {
+            // TODO: use enum instead strings.
             case "VALID_TEMPLATE":
               message = Properties.Resources.ServerConfigEventValidTemplateInfo;
               percent *= 1;
@@ -237,6 +242,10 @@
               percent *= 9;
               message = Properties.Resources.ServerConfigEventSecuritySettingsInfo;
               break;
+            case "FIREWALL_RULE":
+              percent *= 10;
+              message = string.Format(Properties.Resources.ServerConfigFirewallSettingInfo, ServiceName, Port);
+              break;
           }
           Logger.LogInformation(message);
           break;
@@ -264,6 +273,10 @@
               percent *= 10;
               message = Properties.Resources.ServerConfigEventSecuritySettingsSuccess;
               break;
+            case "FIREWALL_RULE":
+              percent *= 11;
+              message = Properties.Resources.ServerConfigFirewallSettingSucceeded;
+              break;
           }
           Logger.LogInformation(message);
           break;
@@ -286,6 +299,9 @@
             case "SECURITY_SETTING":
               message = Properties.Resources.ServerConfigEventSecuritySettingsError;
               break;
+            case "FIREWALL_RULE":
+              message = Properties.Resources.ServerConfigFirewallSettingFailed;
+              break;
           }
           percent *= 11;
           CurrentState = ConfigState.ConfigurationError;
@@ -422,6 +438,39 @@
       return processedSecuritySettings;
     }
 
+    /// <summary>
+    /// Create a firewall rule for this server instance.
+    /// </summary>
+    private void CreateFirewallRule()
+    {
+      ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "FIREWALL_RULE"));
+
+      ConfigurationEventType eventType = ConfigurationEventType.Error;
+      INetFwOpenPort portRule = Firewall.CreateINetFwOpenPort();
+      if (portRule != null)
+      {
+        portRule.Port = Port;
+        portRule.Protocol = NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP;
+        portRule.Scope = NET_FW_SCOPE_.NET_FW_SCOPE_ALL;
+        portRule.Name = ServiceName; // Using the service name allows simpler identification.
+
+        INetFwOpenPorts ports = Firewall.AuthorizedPorts;
+        if (ports != null)
+        {
+          ports.Add(portRule);
+          eventType = ConfigurationEventType.Success;
+        }
+      }
+      ReportConfigStatus(new ConfigurationEventArgs(eventType, "FIREWALL_RULE"));
+    }
+
+    private void RemoveFirewallRule()
+    {
+      INetFwOpenPorts ports = Firewall.AuthorizedPorts;
+      if (ports != null)
+        ports.Remove(Port, NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP);
+    }
+
     private void GetPages()
     {
       if (pages != null) return;

=== modified file 'StandardPlugins/StandardPlugins.csproj'
--- a/StandardPlugins/StandardPlugins.csproj	2011-03-31 14:36:15 +0000
+++ b/StandardPlugins/StandardPlugins.csproj	2011-04-07 18:04:48 +0000
@@ -139,6 +139,17 @@
   <ItemGroup>
     <None Include="Resources\config_win_integration.png" />
   </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" />
   <PropertyGroup>
     <PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)\WexInstaller\bin\$(ConfigurationName)\$(TargetFileName)"

=== added file 'WexInstaller.Core/Networking.cs'
--- a/WexInstaller.Core/Networking.cs	1970-01-01 00:00:00 +0000
+++ b/WexInstaller.Core/Networking.cs	2011-04-07 18:04:48 +0000
@@ -0,0 +1,158 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NetFwTypeLib;
+
+namespace WexInstaller.Core
+{
+  public class Firewall
+  {
+    private static Type firewallManagerType;
+    private static Type FirewallManagerType
+    {
+      get
+      {
+        if (firewallManagerType == null)
+          firewallManagerType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
+        return firewallManagerType;
+      }
+    }
+
+    private static INetFwMgr firewallManager;
+    private static INetFwMgr FirewallManager
+    {
+      get
+      {
+        if (firewallManager == null)
+          firewallManager = Activator.CreateInstance(FirewallManagerType) as INetFwMgr;
+      return firewallManager;
+      }
+    }
+
+    /// <summary>
+    /// Read or set the enabled state of the firewall.
+    /// </summary>
+    public static bool Enabled
+    {
+      get
+      {
+        bool Firewallenabled = FirewallManager.LocalPolicy.CurrentProfile.FirewallEnabled;
+        return Firewallenabled;
+      }
+      set
+      {
+        FirewallManager.LocalPolicy.CurrentProfile.FirewallEnabled = value;
+      }
+    }
+
+    /// <summary>
+    /// Create interface for port rule.
+    /// </summary>
+    public static INetFwOpenPort CreateINetFwOpenPort()
+    {
+      Type portClass = Type.GetTypeFromProgID("HNetCfg.FWOpenPort");
+      return Activator.CreateInstance(portClass) as INetFwOpenPort;
+    }
+
+    /// <summary>
+    /// Create interface for authorized application rule.
+    /// </summary>
+    public static INetFwAuthorizedApplication CreateINetFwAuthorizedApplication()
+    {
+      Type applicationClass = Type.GetTypeFromProgID("HNetCfg.FwAuthorizedApplication");
+      return Activator.CreateInstance(applicationClass) as INetFwAuthorizedApplication;
+    }
+
+    /// <summary>
+    /// Obtain list of authorized ports.
+    /// </summary>
+    public static INetFwOpenPorts AuthorizedPorts
+    {
+      get { return FirewallManager.LocalPolicy.CurrentProfile.GloballyOpenPorts; }
+    }
+
+    /// <summary>
+    /// Obtain List of Authorized Applications
+    /// </summary>
+    public static INetFwAuthorizedApplications AuthorizedApplications
+    {
+      get { return FirewallManager.LocalPolicy.CurrentProfile.AuthorizedApplications; }
+    }
+  }
+
+/*
+    Listing ports
+    INetFwOpenPorts ports = FireWall.AuthorizedPorts;
+    System.Collections.IEnumerator enumerate;
+    if (ports != null)
+    {
+    enumerate = ports.GetEnumerator();
+    if (enumerate != null)
+    {
+    Console.WriteLine("Authorized Ports");
+    while (enumerate.MoveNext())
+    {
+    INetFwOpenPort port = enumerate.Current as INetFwOpenPort;
+    if (port != null)
+    {
+    Console.Write(" ");
+    Console.WriteLine(string.Format("{0} ", port.Port));
+    }
+    }
+    }
+    }
+
+    listing apps
+    INetFwAuthorizedApplications applications = FireWall.AuthorizedApplications;
+    if (applications != null)
+    {
+    System.Collections.IEnumerator enumerate;
+    enumerate = applications.GetEnumerator();
+    Console.WriteLine("Authorized Applications");
+    while (enumerate.MoveNext())
+    {
+    INetFwAuthorizedApplication app = enumerate.Current as INetFwAuthorizedApplication;
+    if (app != null)
+    {
+    Console.Write(" ");
+    Console.WriteLine(string.Format("{0} ", app.Name));
+    }
+    }
+    }
+
+    adding a port
+
+    INetFwOpenPort _PortToTest = FireWall.CreateINetFwOpenPort();
+    if (_PortToTest != null)
+    {
+    _PortToTest.Port = 7657;
+    _PortToTest.Protocol = NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP;
+    _PortToTest.Scope = NET_FW_SCOPE_.NET_FW_SCOPE_ALL;
+    _PortToTest.Name = "Test";
+
+    INetFwOpenPorts ports = MOAEC_FireWall.AuthorizedPorts;
+    if (ports != null)
+    {
+    ports.Add(_PortToTest);
+    }
+    }
+
+
+
+    adding an application
+    INetFwAuthorizedApplication _ApplicationToTest = MOAEC_FireWall.CreateINetFwAuthorizedApplication();
+    if (_ApplicationToTest != null)
+    {
+
+    Process p = Process.GetCurrentProcess();
+    _ApplicationToTest.ProcessImageFileName = p.MainModule.FileVersionInfo.FileName;
+    _ApplicationToTest.Name = p.ProcessName;
+
+    INetFwAuthorizedApplications applications = MOAEC_FireWall.AuthorizedApplications;
+    if (applications != null)
+    {
+    applications.Add(_ApplicationToTest);
+    }
+    }
+ * */
+}

=== modified file 'WexInstaller.Core/Utilities.cs'
--- a/WexInstaller.Core/Utilities.cs	2011-04-07 16:15:24 +0000
+++ b/WexInstaller.Core/Utilities.cs	2011-04-07 18:04:48 +0000
@@ -94,5 +94,6 @@
       foreach (Control child in control.Controls)
         MakeFontsNonAmbient(child);
     }
+
   }
 }

=== modified file 'WexInstaller.Core/WexInstaller.Core.csproj'
--- a/WexInstaller.Core/WexInstaller.Core.csproj	2011-04-06 16:58:45 +0000
+++ b/WexInstaller.Core/WexInstaller.Core.csproj	2011-04-07 18:04:48 +0000
@@ -54,6 +54,7 @@
     <Compile Include="LoggerListener.cs" />
     <Compile Include="MirrorsXML.cs" />
     <Compile Include="MsiInterop.cs" />
+    <Compile Include="Networking.cs" />
     <Compile Include="Options.cs" />
     <Compile Include="Package.cs" />
     <Compile Include="PluginManager.cs" />
@@ -137,6 +138,17 @@
   <ItemGroup>
     <None Include="Resources\BottomDivider.png" />
   </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" />
   <!-- 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.

=== modified file 'WexInstaller/Controls/WelcomeControl.cs'
--- a/WexInstaller/Controls/WelcomeControl.cs	2011-04-07 14:04:55 +0000
+++ b/WexInstaller/Controls/WelcomeControl.cs	2011-04-07 18:04:48 +0000
@@ -118,5 +118,6 @@
     {
       (ParentForm as MainForm).RemoveAll();
     }
+
   }
 }

=== modified file 'WexInstaller/Program.cs'
--- a/WexInstaller/Program.cs	2011-04-04 09:04:40 +0000
+++ b/WexInstaller/Program.cs	2011-04-07 18:04:48 +0000
@@ -1,5 +1,6 @@
 using System;
 using System.Windows.Forms;
+using System.IO;
 
 using WexInstaller.Core;
 
@@ -37,6 +38,8 @@
       Application.Run(new MainForm());
 
       InstallerConfiguration.Save();
+      InstallerInfo.SaveAndSend(InstallerConfiguration.SendSystemInfo);
+
       Logger.LogInformation("Installer exit");
     }
 

Attachment: [text/bzr-bundle] bzr/mike.lischke@oracle.com-20110407180448-u1wwnoub11ictgzv.bundle
Thread
bzr commit into wex-installer-1.0 branch (mike.lischke:417) Mike Lischke7 Apr