From: <mis...@us...> - 2007-03-18 22:09:30
|
Revision: 36 http://svn.sourceforge.net/mp-webinterface/?rev=36&view=rev Author: misterd_sf Date: 2007-03-18 10:33:15 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Added possibility to bind to any interface Added Table for allowed IPs for restricted access mode Fixed Start/Stop Buttons of Systray Fixed Reload of the web server Changed read/write of configuration file to web server methods Modified Paths: -------------- trunk/Version2/Control Center/Control_Center_App.Designer.cs trunk/Version2/Control Center/Control_Center_App.cs trunk/Version2/Control Center/Control_Center_App.resx trunk/Version2/WebServer/Server.cs Modified: trunk/Version2/Control Center/Control_Center_App.Designer.cs =================================================================== --- trunk/Version2/Control Center/Control_Center_App.Designer.cs 2007-03-11 10:11:22 UTC (rev 35) +++ trunk/Version2/Control Center/Control_Center_App.Designer.cs 2007-03-18 17:33:15 UTC (rev 36) @@ -40,8 +40,8 @@ this.LblMPWWebsiteLink = new System.Windows.Forms.Label(); this.LLblMPWWebsiteLink = new System.Windows.Forms.LinkLabel(); this.gBxMPWWebServerSetup = new System.Windows.Forms.GroupBox(); + this.bindIPAddressDropDown = new System.Windows.Forms.ComboBox(); this.saveButton = new System.Windows.Forms.Button(); - this.bindIPBox = new System.Windows.Forms.TextBox(); this.accessModeDropDown = new System.Windows.Forms.ComboBox(); this.LblSetupAccessMode = new System.Windows.Forms.Label(); this.LblSetupBindLocalIP = new System.Windows.Forms.Label(); @@ -69,6 +69,9 @@ this.gBxLogs = new System.Windows.Forms.GroupBox(); this.CmdOpenAccessLog = new System.Windows.Forms.Button(); this.CmdOpenEventViewer = new System.Windows.Forms.Button(); + this.LblallowedIPs = new System.Windows.Forms.Label(); + this.allowedIPs = new System.Windows.Forms.DataGridView(); + this.allowedIP = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.gBxStatus.SuspendLayout(); this.gBxMPWWebServerSetup.SuspendLayout(); this.gBxMPWWebServer.SuspendLayout(); @@ -76,6 +79,7 @@ this.gBxAboutMPW.SuspendLayout(); this.gBxVersion.SuspendLayout(); this.gBxLogs.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.allowedIPs)).BeginInit(); this.SuspendLayout(); // // gBxStatus @@ -169,8 +173,10 @@ // // gBxMPWWebServerSetup // + this.gBxMPWWebServerSetup.Controls.Add(this.allowedIPs); + this.gBxMPWWebServerSetup.Controls.Add(this.LblallowedIPs); + this.gBxMPWWebServerSetup.Controls.Add(this.bindIPAddressDropDown); this.gBxMPWWebServerSetup.Controls.Add(this.saveButton); - this.gBxMPWWebServerSetup.Controls.Add(this.bindIPBox); this.gBxMPWWebServerSetup.Controls.Add(this.accessModeDropDown); this.gBxMPWWebServerSetup.Controls.Add(this.LblSetupAccessMode); this.gBxMPWWebServerSetup.Controls.Add(this.LblSetupBindLocalIP); @@ -178,14 +184,23 @@ this.gBxMPWWebServerSetup.Controls.Add(this.LblSetupWebserverPort); this.gBxMPWWebServerSetup.Location = new System.Drawing.Point(318, 12); this.gBxMPWWebServerSetup.Name = "gBxMPWWebServerSetup"; - this.gBxMPWWebServerSetup.Size = new System.Drawing.Size(300, 314); + this.gBxMPWWebServerSetup.Size = new System.Drawing.Size(325, 314); this.gBxMPWWebServerSetup.TabIndex = 1; this.gBxMPWWebServerSetup.TabStop = false; this.gBxMPWWebServerSetup.Text = "MPW Webserver setup"; // + // bindIPAddressDropDown + // + this.bindIPAddressDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.bindIPAddressDropDown.FormattingEnabled = true; + this.bindIPAddressDropDown.Location = new System.Drawing.Point(126, 58); + this.bindIPAddressDropDown.Name = "bindIPAddressDropDown"; + this.bindIPAddressDropDown.Size = new System.Drawing.Size(193, 21); + this.bindIPAddressDropDown.TabIndex = 11; + // // saveButton // - this.saveButton.Location = new System.Drawing.Point(126, 132); + this.saveButton.Location = new System.Drawing.Point(169, 279); this.saveButton.Name = "saveButton"; this.saveButton.Size = new System.Drawing.Size(115, 23); this.saveButton.TabIndex = 10; @@ -193,29 +208,24 @@ this.saveButton.UseVisualStyleBackColor = true; this.saveButton.Click += new System.EventHandler(this.saveButton_Click); // - // bindIPBox - // - this.bindIPBox.Location = new System.Drawing.Point(126, 59); - this.bindIPBox.Name = "bindIPBox"; - this.bindIPBox.Size = new System.Drawing.Size(115, 20); - this.bindIPBox.TabIndex = 9; - // // accessModeDropDown // + this.accessModeDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.accessModeDropDown.FormattingEnabled = true; this.accessModeDropDown.Items.AddRange(new object[] { "Local", "Global", "Restricted"}); - this.accessModeDropDown.Location = new System.Drawing.Point(126, 94); + this.accessModeDropDown.Location = new System.Drawing.Point(126, 85); this.accessModeDropDown.Name = "accessModeDropDown"; - this.accessModeDropDown.Size = new System.Drawing.Size(115, 21); + this.accessModeDropDown.Size = new System.Drawing.Size(193, 21); this.accessModeDropDown.TabIndex = 8; + this.accessModeDropDown.SelectedIndexChanged += new System.EventHandler(this.accessModeDropDown_SelectedIndexChanged); // // LblSetupAccessMode // this.LblSetupAccessMode.AutoSize = true; - this.LblSetupAccessMode.Location = new System.Drawing.Point(6, 102); + this.LblSetupAccessMode.Location = new System.Drawing.Point(6, 88); this.LblSetupAccessMode.Name = "LblSetupAccessMode"; this.LblSetupAccessMode.Size = new System.Drawing.Size(74, 13); this.LblSetupAccessMode.TabIndex = 7; @@ -224,7 +234,7 @@ // LblSetupBindLocalIP // this.LblSetupBindLocalIP.AutoSize = true; - this.LblSetupBindLocalIP.Location = new System.Drawing.Point(6, 67); + this.LblSetupBindLocalIP.Location = new System.Drawing.Point(6, 61); this.LblSetupBindLocalIP.Name = "LblSetupBindLocalIP"; this.LblSetupBindLocalIP.Size = new System.Drawing.Size(81, 13); this.LblSetupBindLocalIP.TabIndex = 6; @@ -234,8 +244,9 @@ // this.portBox.Location = new System.Drawing.Point(126, 32); this.portBox.Name = "portBox"; - this.portBox.Size = new System.Drawing.Size(115, 20); + this.portBox.Size = new System.Drawing.Size(193, 20); this.portBox.TabIndex = 1; + this.portBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.portBox_KeyPress); // // LblSetupWebserverPort // @@ -312,27 +323,27 @@ this.stopToolStripMenuItem, this.exitToolStripMenuItem}); this.trayContextMenu.Name = "trayContextMenu"; - this.trayContextMenu.Size = new System.Drawing.Size(99, 70); + this.trayContextMenu.Size = new System.Drawing.Size(110, 70); this.trayContextMenu.Text = "MPW"; // // trayStart // this.trayStart.Name = "trayStart"; - this.trayStart.Size = new System.Drawing.Size(98, 22); + this.trayStart.Size = new System.Drawing.Size(109, 22); this.trayStart.Text = "Start"; this.trayStart.Click += new System.EventHandler(this.trayStart_Click); // // stopToolStripMenuItem // this.stopToolStripMenuItem.Name = "stopToolStripMenuItem"; - this.stopToolStripMenuItem.Size = new System.Drawing.Size(98, 22); + this.stopToolStripMenuItem.Size = new System.Drawing.Size(109, 22); this.stopToolStripMenuItem.Text = "Stop"; this.stopToolStripMenuItem.Click += new System.EventHandler(this.stopToolStripMenuItem_Click); // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(98, 22); + this.exitToolStripMenuItem.Size = new System.Drawing.Size(109, 22); this.exitToolStripMenuItem.Text = "Exit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -348,7 +359,7 @@ this.gBxAboutMPW.Controls.Add(this.LblMPWWebsiteLink); this.gBxAboutMPW.Location = new System.Drawing.Point(12, 332); this.gBxAboutMPW.Name = "gBxAboutMPW"; - this.gBxAboutMPW.Size = new System.Drawing.Size(606, 38); + this.gBxAboutMPW.Size = new System.Drawing.Size(631, 38); this.gBxAboutMPW.TabIndex = 3; this.gBxAboutMPW.TabStop = false; this.gBxAboutMPW.Text = "About MPW"; @@ -453,11 +464,39 @@ this.CmdOpenEventViewer.UseVisualStyleBackColor = true; this.CmdOpenEventViewer.Click += new System.EventHandler(this.CmdOpenEventViewer_Click); // + // LblallowedIPs + // + this.LblallowedIPs.AutoSize = true; + this.LblallowedIPs.Location = new System.Drawing.Point(6, 115); + this.LblallowedIPs.Name = "LblallowedIPs"; + this.LblallowedIPs.Size = new System.Drawing.Size(65, 13); + this.LblallowedIPs.TabIndex = 12; + this.LblallowedIPs.Text = "Allowed IPs:"; + // + // allowedIPs + // + this.allowedIPs.AllowUserToResizeColumns = false; + this.allowedIPs.AllowUserToResizeRows = false; + this.allowedIPs.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.allowedIPs.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.allowedIP}); + this.allowedIPs.Location = new System.Drawing.Point(126, 112); + this.allowedIPs.Name = "allowedIPs"; + this.allowedIPs.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.allowedIPs.Size = new System.Drawing.Size(193, 161); + this.allowedIPs.TabIndex = 13; + // + // allowedIP + // + this.allowedIP.HeaderText = "IP"; + this.allowedIP.Name = "allowedIP"; + this.allowedIP.Width = 150; + // // Control_Center_App // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(632, 384); + this.ClientSize = new System.Drawing.Size(655, 384); this.Controls.Add(this.gBxLogs); this.Controls.Add(this.gBxAboutMPW); this.Controls.Add(this.gBxMPWWebServer); @@ -482,6 +521,7 @@ this.gBxVersion.ResumeLayout(false); this.gBxVersion.PerformLayout(); this.gBxLogs.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.allowedIPs)).EndInit(); this.ResumeLayout(false); } @@ -505,8 +545,7 @@ private System.Windows.Forms.Label statusTVService; private System.Windows.Forms.ComboBox accessModeDropDown; private System.Windows.Forms.Label LblSetupAccessMode; - private System.Windows.Forms.Label LblSetupBindLocalIP; - private System.Windows.Forms.TextBox bindIPBox; + private System.Windows.Forms.Label LblSetupBindLocalIP; private System.Windows.Forms.Button saveButton; private System.Windows.Forms.GroupBox gBxMPWWebServer; private System.Windows.Forms.NotifyIcon trayIcon; @@ -527,6 +566,10 @@ private System.Windows.Forms.GroupBox gBxLogs; private System.Windows.Forms.Button CmdOpenEventViewer; private System.Windows.Forms.Button CmdOpenAccessLog; + private System.Windows.Forms.ComboBox bindIPAddressDropDown; + private System.Windows.Forms.DataGridView allowedIPs; + private System.Windows.Forms.Label LblallowedIPs; + private System.Windows.Forms.DataGridViewTextBoxColumn allowedIP; } } Modified: trunk/Version2/Control Center/Control_Center_App.cs =================================================================== --- trunk/Version2/Control Center/Control_Center_App.cs 2007-03-11 10:11:22 UTC (rev 35) +++ trunk/Version2/Control Center/Control_Center_App.cs 2007-03-18 17:33:15 UTC (rev 36) @@ -8,388 +8,373 @@ using System.IO; using System.ServiceProcess; using System.Xml; +using System.Net; +using System.Net.NetworkInformation; +using MPW.WebServer; -namespace MPW.Control_Center -{ - public partial class Control_Center_App : Form - { - //Service Controllers - private ServiceController TVServiceController = new ServiceController("TVService"); - private ServiceController MPWServiceController = new ServiceController("MPW"); - - //MPW Webserver settings - private int port; - private String bindIP; - private int accesMode; - - private String configFile; +namespace MPW.Control_Center { + public partial class Control_Center_App : Form { + //Service Controllers + private ServiceController TVServiceController = new ServiceController("TVService"); + private ServiceController MPWServiceController = new ServiceController("MPW"); - private bool exitRequested; + //MPW Webserver settings + private ServerConfiguration configuration; - public Control_Center_App() - { - InitializeComponent(); - configFile = System.AppDomain.CurrentDomain.BaseDirectory + "Configuration.xml"; - RefreshControllers(); - LoadSettings(); + private String configFile; - LoadVersionInfo(); - } + private bool exitRequested; - /// <summary> - /// gets version info for MPW components and puts it on labels on form - /// </summary> - private void LoadVersionInfo() - { - LblMPWCCVersion.Text = System.Reflection.Assembly.GetCallingAssembly().GetName().Version.ToString(); - - string fileName; + private List<string> ipAddresses; - try - { - fileName = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "WebServer.dll"); - LblMPWWebserverVersion.Text = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName).ProductVersion; - } - catch - { } + public Control_Center_App() { + InitializeComponent(); + configFile = System.AppDomain.CurrentDomain.BaseDirectory + "Configuration.xml"; + RefreshControllers(); + InitializeIPList(); + LoadSettings(); - try - { - fileName = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "MPW Service.exe"); - LblMPWServiceVersion.Text = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName).ProductVersion; - } - catch - { } - - } + LoadVersionInfo(); + } - /// <summary> - /// refreshes the status indicators for MPW webserver and TV services - /// </summary> - private void RefreshControllers() - { - //MPW Webserver - MPWServiceController.Refresh(); - try - { - statusMPWServerConn.Text = MPWServiceController.Status.ToString(); - - if (MPWServiceController.Status == ServiceControllerStatus.Running) - { - statusMPWServerConn.ForeColor = Color.Green; - startstopButton.Text = "Stop"; + /// <summary> + /// Initialize the dropdown list with all available IPs + /// </summary> + private void InitializeIPList() { + ipAddresses = new List<string>(); + bindIPAddressDropDown.Items.Add("0.0.0.0 - All interfaces"); + ipAddresses.Add("0.0.0.0"); + bindIPAddressDropDown.Items.Add("127.0.0.1 - Loopback interface"); + ipAddresses.Add("127.0.0.1"); + IPHostEntry local = Dns.GetHostEntry(Environment.MachineName); + foreach (IPAddress ipaddress in local.AddressList) { + bindIPAddressDropDown.Items.Add(ipaddress.ToString()); + ipAddresses.Add(ipaddress.ToString()); + } } - else - { - statusMPWServerConn.ForeColor = Color.Red; - startstopButton.Text = "Start"; - } - } - catch - { - statusMPWServerConn.Text = "Error: Service not found!"; - startstopButton.Enabled = false; - } - - //TV Server - TVServiceController.Refresh(); - try - { - statusTVService.Text = TVServiceController.Status.ToString(); - if (TVServiceController.Status == ServiceControllerStatus.Running) - statusTVService.ForeColor = Color.Green; - else - statusTVService.ForeColor = Color.Red; - } - catch - { - statusTVService.Text = "Error: Service not found!"; - } - } + /// <summary> + /// gets version info for MPW components and puts it on labels on form + /// </summary> + private void LoadVersionInfo() { + LblMPWCCVersion.Text = System.Reflection.Assembly.GetCallingAssembly().GetName().Version.ToString(); - private void startstopButton_Click(object sender, EventArgs e) - { - if (startstopButton.Text == "Start") - Start(); - else - Stop(); - } + string fileName; - private void LLblMPWWebsiteLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - System.Diagnostics.Process.Start(LLblMPWWebsiteLink.Text); - } + try { + fileName = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "WebServer.dll"); + LblMPWWebserverVersion.Text = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName).ProductVersion; + } catch { } - private void LLblMPWServerURL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - System.Diagnostics.Process.Start(LLblMPWServerURL.Text); - } + try { + fileName = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "MPW Service.exe"); + LblMPWServiceVersion.Text = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName).ProductVersion; + } catch { } - /// <summary> - /// Start the server - /// </summary> - private void Start() - { - RefreshControllers(); - try - { - MPWServiceController.Start(); - startstopButton.Text = "Stop"; - } - catch - { - statusMPWServerConn.Text = "Error, could not start Service."; - } - RefreshControllers(); - } + } - /// <summary> - /// Stop the server - /// </summary> - private void Stop() - { - RefreshControllers(); - if (MPWServiceController.Status == ServiceControllerStatus.Running) - { - MPWServiceController.Stop(); - startstopButton.Text = "Start"; - } - RefreshControllers(); - } + /// <summary> + /// refreshes the status indicators for MPW webserver and TV services + /// </summary> + private void RefreshControllers() { + //MPW Webserver + MPWServiceController.Refresh(); + try { + statusMPWServerConn.Text = MPWServiceController.Status.ToString(); - /// <summary> - /// Build a string with the server URL - /// </summary> - /// <returns>server URL</returns> - private String ConstructServerURL() - { - String url = "http://"; - url += bindIP; - url += ":" + port.ToString(); - url += "/"; - return url; - } + if (MPWServiceController.Status == ServiceControllerStatus.Running) { + statusMPWServerConn.ForeColor = Color.Green; + startstopButton.Text = "Stop"; + } else { + statusMPWServerConn.ForeColor = Color.Red; + startstopButton.Text = "Start"; + } + } catch { + statusMPWServerConn.Text = "Error: Service not found!"; + startstopButton.Enabled = false; + } - /// <summary> - /// Load the configuration - /// </summary> - /// <returns>true if settings loaded successfully</returns> - private bool LoadSettings() - { - try - { - XmlDocument doc = new XmlDocument(); - doc.Load(configFile); - XmlNode node = doc.DocumentElement.SelectSingleNode("/configuration/bindAddress"); - bindIP = node.InnerText; - node = doc.DocumentElement.SelectSingleNode("/configuration/port"); - port = int.Parse(node.InnerText); - node = doc.DocumentElement.SelectSingleNode("/configuration/allowedAccesMode"); - accesMode = int.Parse(node.InnerText); + //TV Server + TVServiceController.Refresh(); + try { + statusTVService.Text = TVServiceController.Status.ToString(); + + if (TVServiceController.Status == ServiceControllerStatus.Running) + statusTVService.ForeColor = Color.Green; + else + statusTVService.ForeColor = Color.Red; + } catch { + statusTVService.Text = "Error: Service not found!"; + } } - catch (Exception ex) - { - MessageBox.Show("An error occurred when trying to load the settings." + Environment.NewLine + Environment.NewLine + ex.ToString(), "Error when loading settings", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; + + private void startstopButton_Click(object sender, EventArgs e) { + if (startstopButton.Text == "Start") + Start(); + else + Stop(); } - //Set the read values to the various TextBoxes - portBox.Text = port.ToString(); - bindIPBox.Text = bindIP; - accessModeDropDown.SelectedIndex = accesMode; - LLblMPWServerURL.Text = ConstructServerURL(); + private void LLblMPWWebsiteLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { + System.Diagnostics.Process.Start(LLblMPWWebsiteLink.Text); + } - return true; - } + private void LLblMPWServerURL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { + System.Diagnostics.Process.Start(LLblMPWServerURL.Text); + } - /// <summary> - /// save server configuration settings - /// </summary> - /// <returns>true if configuration settings were successfully saved.</returns> - private bool SaveSettings() - { - try - { - XmlDocument doc = new XmlDocument(); - doc.Load(configFile); + /// <summary> + /// Start the server + /// </summary> + private void Start() { + RefreshControllers(); + try { + MPWServiceController.Start(); + startstopButton.Text = "Stop"; + } catch { + statusMPWServerConn.Text = "Error, could not start Service."; + } + RefreshControllers(); + } - XmlNode node = doc.DocumentElement.SelectSingleNode("/configuration/bindAddress"); - node.InnerText = bindIP; - node = doc.DocumentElement.SelectSingleNode("/configuration/port"); - node.InnerText = port.ToString(); - node = doc.DocumentElement.SelectSingleNode("/configuration/allowedAccesMode"); - node.InnerText = accesMode.ToString(); - node = doc.DocumentElement.SelectSingleNode("/configuration/physicalPath"); - node.InnerText = System.AppDomain.CurrentDomain.BaseDirectory + @"wwwroot\"; + /// <summary> + /// Stop the server + /// </summary> + private void Stop() { + RefreshControllers(); + if (MPWServiceController.Status == ServiceControllerStatus.Running) { + MPWServiceController.Stop(); + startstopButton.Text = "Start"; + } + RefreshControllers(); + } - doc.Save(configFile); + /// <summary> + /// Build a string with the server URL + /// </summary> + /// <returns>server URL</returns> + private String ConstructServerURL() { + String url = "http://"; + url += configuration.BindAddress; + url += ":" + configuration.Port.ToString(); + url += "/"; + return url; } - catch (Exception ex) - { - MessageBox.Show("An error occurred when trying to save the settings." + Environment.NewLine + Environment.NewLine + ex.ToString(), "Error when saving settings", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; + + /// <summary> + /// Load the configuration + /// </summary> + /// <returns>true if settings loaded successfully</returns> + private bool LoadSettings() { + try { + configuration = ServerConfiguration.readConfiguration(configFile); + } catch (Exception ex) { + MessageBox.Show("An error occurred when trying to load the settings." + Environment.NewLine + Environment.NewLine + ex.ToString(), "Error when loading settings", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + //Set the read values to the various TextBoxes + portBox.Text = configuration.Port.ToString(); + if (ipAddresses.Contains(configuration.BindAddress)) { + bindIPAddressDropDown.SelectedIndex = ipAddresses.IndexOf(configuration.BindAddress); + } else { + bindIPAddressDropDown.SelectedIndex = 0; + } + accessModeDropDown.SelectedIndex = (int)configuration.AllowedAccessMode; + foreach(String allowedAddress in configuration.AllowedIP){ + allowedIPs.Rows.Add(allowedAddress); + } + LLblMPWServerURL.Text = ConstructServerURL(); + + return true; } - return true; - } + /// <summary> + /// save server configuration settings + /// </summary> + /// <returns>true if configuration settings were successfully saved.</returns> + private bool SaveSettings() { + try { + configuration.PhysicalPath = System.AppDomain.CurrentDomain.BaseDirectory + @"wwwroot\"; + ServerConfiguration.writeConfiguration(configFile, configuration); - /// <summary> - /// save configuration changes and reload configuration for server - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void saveButton_Click(object sender, EventArgs e) - { - //data validation - if (!int.TryParse(portBox.Text,out port)) - { - MessageBox.Show("The port number must be numerical only.", "Invalid port number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; + } catch (Exception ex) { + MessageBox.Show("An error occurred when trying to save the settings." + Environment.NewLine + Environment.NewLine + ex.ToString(), "Error when saving settings", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + return true; } - System.Net.IPAddress bindIPAddress; - if (!System.Net.IPAddress.TryParse(bindIPBox.Text, out bindIPAddress)) - { - MessageBox.Show("The bind IP address is not valid. It must be in the form of xxx.xxx.xxx.xxx, where x is a number.", "Invalid bind IP address", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; + /// <summary> + /// save configuration changes and reload configuration for server + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void saveButton_Click(object sender, EventArgs e) { + //data validation + int port; + if (!int.TryParse(portBox.Text, out port)) { + MessageBox.Show("The port number must be numerical only.", "Invalid port number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + configuration.BindAddress = ipAddresses[bindIPAddressDropDown.SelectedIndex]; + configuration.Port = port; + configuration.AllowedAccessMode = (AccessMode)accessModeDropDown.SelectedIndex; + List<String> newAllowedIP = new List<String>(); + object value; + String ipString; + IPAddress testAddress; + foreach (DataGridViewRow row in allowedIPs.Rows) { + value = row.Cells[0].Value; + if (value != null) { + ipString = value.ToString(); + if (IPAddress.TryParse(ipString, out testAddress)) { + newAllowedIP.Add(ipString); + } + } + } + configuration.AllowedIP = newAllowedIP; + SaveSettings(); + try { + if (MPWServiceController.Status == ServiceControllerStatus.Running) + MPWServiceController.ExecuteCommand((int)CustomCommands.ReloadConfiguration); //ReloadConfiguration + else + MessageBox.Show("You will need to restart the server to use the new configuration!"); + } catch { + MessageBox.Show("Error setting the new configuration."); + } + LLblMPWServerURL.Text = ConstructServerURL(); } - //port = portBox.Text; //already set if valid from TryParse - bindIP = bindIPBox.Text; - accesMode = accessModeDropDown.SelectedIndex; - SaveSettings(); - try - { - if (MPWServiceController.Status == ServiceControllerStatus.Running) - MPWServiceController.ExecuteCommand(0); //ReloadConfiguration - else - MessageBox.Show("You will need to restart the server to use the new configuration!"); - } - catch - { - MessageBox.Show("Error setting the new configuration."); - } - LLblMPWServerURL.Text = ConstructServerURL(); - } + /// <summary> + /// Restore by double-clicking the tray icon + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e) { + this.WindowState = System.Windows.Forms.FormWindowState.Normal; + trayIcon.Visible = true; + this.ShowInTaskbar = true; + RefreshControllers(); + } - /// <summary> - /// Restore by double-clicking the tray icon - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e) - { - this.WindowState = System.Windows.Forms.FormWindowState.Normal; - trayIcon.Visible = true; - this.ShowInTaskbar = true; - RefreshControllers(); - } + /// <summary> + /// Minimize to tray on closing + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void Control_Center_App_FormClosing(object sender, FormClosingEventArgs e) { + if (!exitRequested) { + e.Cancel = true; + this.WindowState = System.Windows.Forms.FormWindowState.Minimized; + this.ShowInTaskbar = false; + } + } - /// <summary> - /// Minimize to tray on closing - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void Control_Center_App_FormClosing(object sender, FormClosingEventArgs e) - { - if (!exitRequested) - { - e.Cancel = true; - this.WindowState = System.Windows.Forms.FormWindowState.Minimized; - this.ShowInTaskbar = false; + /// <summary> + /// Tray menu action "Exit" + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void exitToolStripMenuItem_Click(object sender, EventArgs e) { + exitRequested = true; + this.Close(); } - } - /// <summary> - /// Tray menu action "Exit" - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void exitToolStripMenuItem_Click(object sender, EventArgs e) - { - exitRequested = true; - this.Close(); - } + /// <summary> + /// Tray menu action "Stop" + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void stopToolStripMenuItem_Click(object sender, EventArgs e) { + Stop(); + } - /// <summary> - /// Tray menu action "Stop" - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void stopToolStripMenuItem_Click(object sender, EventArgs e) - { - Start(); - } + /// <summary> + /// Tray menu action "Start" + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void trayStart_Click(object sender, EventArgs e) { + Start(); + } - /// <summary> - /// Tray menu action "Start" - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void trayStart_Click(object sender, EventArgs e) - { - Stop(); - } + /// <summary> + /// Status refresh button + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void CmdRefreshStatusInfo_Click(object sender, EventArgs e) { + RefreshControllers(); + } - /// <summary> - /// Status refresh button - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void CmdRefreshStatusInfo_Click(object sender, EventArgs e) - { - RefreshControllers(); - } + /// <summary> + /// Minimize to tray on minimize + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void Control_Center_App_Resize(object sender, EventArgs e) { + if (this.WindowState == FormWindowState.Minimized) + this.ShowInTaskbar = false; + } - /// <summary> - /// Minimize to tray on minimize - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void Control_Center_App_Resize(object sender, EventArgs e) - { - if (this.WindowState == FormWindowState.Minimized) - this.ShowInTaskbar = false; - } + /// <summary> + /// Update the Service status + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void refreshTimer_Tick(object sender, EventArgs e) { + if (this.WindowState != System.Windows.Forms.FormWindowState.Minimized) + RefreshControllers(); + } - /// <summary> - /// Update the Service status - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void refreshTimer_Tick(object sender, EventArgs e) - { - if (this.WindowState != System.Windows.Forms.FormWindowState.Minimized) - RefreshControllers(); - } + /// <summary> + /// Open Windows Event Viewer for user to browse logs + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void CmdOpenEventViewer_Click(object sender, EventArgs e) { + string fileName = System.IO.Path.Combine(Environment.SystemDirectory, "eventvwr.msc"); + System.Diagnostics.Process.Start(fileName); + } - /// <summary> - /// Open Windows Event Viewer for user to browse logs - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void CmdOpenEventViewer_Click(object sender, EventArgs e) - { - string fileName = System.IO.Path.Combine(Environment.SystemDirectory, "eventvwr.msc"); - System.Diagnostics.Process.Start(fileName); - } + /// <summary> + /// Open access log in text editor + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void CmdOpenAccessLog_Click(object sender, EventArgs e) { + string fileName; + fileName = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "access.log"); - /// <summary> - /// Open access log in text editor - /// </summary> - /// <param name="sender"></param> - /// <param name="e"></param> - private void CmdOpenAccessLog_Click(object sender, EventArgs e) - { - string fileName; - fileName = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "access.log"); + if (System.IO.File.Exists(fileName)) + System.Diagnostics.Process.Start(fileName); + else + MessageBox.Show("No access log file cound be found, most likely because no attempts of accessing MPW have been made.", "Access log not found", MessageBoxButtons.OK, MessageBoxIcon.Information); - if (System.IO.File.Exists(fileName)) - System.Diagnostics.Process.Start(fileName); - else - MessageBox.Show("No access log file cound be found, most likely because no attempts of accessing MPW have been made.", "Access log not found", MessageBoxButtons.OK, MessageBoxIcon.Information); + } - } - } + /// <summary> + /// Only accept numbers and control keys + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void portBox_KeyPress(object sender, KeyPressEventArgs e) { + if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar)) { + e.Handled = true; + } + + } + + /// <summary> + /// Activates/Deactivates the ip data grid + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void accessModeDropDown_SelectedIndexChanged(object sender, EventArgs e) { + allowedIPs.Enabled = accessModeDropDown.SelectedIndex == (int)AccessMode.Restricted; + } + } } \ No newline at end of file Modified: trunk/Version2/Control Center/Control_Center_App.resx =================================================================== --- trunk/Version2/Control Center/Control_Center_App.resx 2007-03-11 10:11:22 UTC (rev 35) +++ trunk/Version2/Control Center/Control_Center_App.resx 2007-03-18 17:33:15 UTC (rev 36) @@ -117,6 +117,9 @@ <resheader name="writer"> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> + <metadata name="allowedIP.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> + <value>True</value> + </metadata> <metadata name="trayIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>17, 17</value> </metadata> @@ -9179,6 +9182,9 @@ <metadata name="refreshTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>246, 17</value> </metadata> + <metadata name="allowedIP.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> + <value>True</value> + </metadata> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <value> AAABAA8AAAAAAAEACAAoJAEA9gAAADAwAAABAAgAqA4AAB4lAQAgIAAAAQAIAKgIAADGMwEAGBgAAAEA Modified: trunk/Version2/WebServer/Server.cs =================================================================== --- trunk/Version2/WebServer/Server.cs 2007-03-11 10:11:22 UTC (rev 35) +++ trunk/Version2/WebServer/Server.cs 2007-03-18 17:33:15 UTC (rev 36) @@ -174,11 +174,18 @@ _socket.ExclusiveAddressUse = true; try { - - _socket.Bind(new IPEndPoint(IPAddress.Parse(_configuration.BindAddress), _configuration.Port)); + if (_configuration.BindAddress.Equals("0.0.0.0")) { + _socket.Bind(new IPEndPoint(IPAddress.Any, _configuration.Port)); + } else { + _socket.Bind(new IPEndPoint(IPAddress.Parse(_configuration.BindAddress), _configuration.Port)); + } } catch { _socket.ExclusiveAddressUse = false; - _socket.Bind(new IPEndPoint(IPAddress.Parse(_configuration.BindAddress), _configuration.Port)); + if (_configuration.BindAddress.Equals("0.0.0.0")) { + _socket.Bind(new IPEndPoint(IPAddress.Any, _configuration.Port)); + } else { + _socket.Bind(new IPEndPoint(IPAddress.Parse(_configuration.BindAddress), _configuration.Port)); + } } _socket.Listen((int)SocketOptionName.MaxConnections); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |