List:Commits« Previous MessageNext Message »
From:Iggy Galarza Date:May 31 2011 1:31pm
Subject:bzr commit into wex-installer-1.0 branch (iggy:488)
View as plain text  
#At file:///C:/src/bzr.mysql/wex/installer/ based on revid:mike.lischke@stripped

  488 Iggy Galarza	2011-05-31
      ServerConfigurationController - Automatically create Windows firewall rule for user configured port using netsh.exe.

    modified:
      StandardPlugins/Server/ConfigurationController.cs
=== modified file 'StandardPlugins/Server/ConfigurationController.cs'
--- a/StandardPlugins/Server/ConfigurationController.cs	2011-05-17 15:40:12 +0000
+++ b/StandardPlugins/Server/ConfigurationController.cs	2011-05-31 13:31:15 +0000
@@ -83,9 +83,9 @@ namespace WexInstaller.Plugins
         {
           if (ProcessService())
           {
-            ProcessSecuritySettings();
             if (Template.EnableNetworking)
               CreateFirewallRule();
+            ProcessSecuritySettings();
           }
         }
       }
@@ -439,6 +439,23 @@ namespace WexInstaller.Plugins
       return processedSecuritySettings;
     }
 
+    private bool RunNetShellProcess(string action, string port, string additionalParameters)
+    {
+      Process p = new Process();
+
+      p.StartInfo.FileName = "netsh.exe";
+      p.StartInfo.Arguments = String.Format(" firewall {0} portopening protocol=TCP port={1} profile=ALL{2}", action, port, additionalParameters);
+      p.StartInfo.UseShellExecute = false;
+      p.StartInfo.CreateNoWindow = true;
+      p.StartInfo.RedirectStandardOutput = true;
+      p.Start();
+
+      string output = p.StandardOutput.ReadToEnd();
+      p.WaitForExit();
+
+      return (output == "Ok.\r\n\r\n");
+    }
+
     /// <summary>
     /// Create a firewall rule for this server instance.
     /// </summary>
@@ -465,6 +482,13 @@ namespace WexInstaller.Plugins
       }
       ReportConfigStatus(new ConfigurationEventArgs(eventType, "FIREWALL_RULE"));
       */
+      ReportConfigStatus(new ConfigurationEventArgs(ConfigurationEventType.Info, "FIREWALL_RULE"));
+
+      ConfigurationEventType eventType = ConfigurationEventType.Error;
+      if ( RunNetShellProcess("add", Port.ToString(), String.Format(" name={0} mode=ENABLE scope=ALL", ServiceName)))
+        eventType = ConfigurationEventType.Success;
+
+      ReportConfigStatus(new ConfigurationEventArgs(eventType, "FIREWALL_RULE"));
     }
 
     private void RemoveFirewallRule()
@@ -474,6 +498,7 @@ namespace WexInstaller.Plugins
       if (ports != null)
         ports.Remove(Port, NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP);
       */
+      RunNetShellProcess("delete", Port.ToString(), String.Empty);
     }
 
     private void GetPages()


Attachment: [text/bzr-bundle] bzr/iggy@mysql.com-20110531133115-hfwyjlqsbsfy2mnb.bundle
Thread
bzr commit into wex-installer-1.0 branch (iggy:488) Iggy Galarza31 May