Revision: 74
http://svn.sourceforge.net/nmailserver/?rev=74&view=rev
Author: tmyroadctfig
Date: 2006-11-07 04:09:49 -0800 (Tue, 07 Nov 2006)
Log Message:
-----------
Work on setup wizard. Fixed some defects.
Modified Paths:
--------------
NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.Designer.cs
NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.cs
NMail/branches/luke-dev/NMail.SetupWizard/DnsConfigPanel.cs
NMail/branches/luke-dev/NMail.SetupWizard/LocalStoreConfigPanel.cs
NMail/branches/luke-dev/NMail.SetupWizard/MySqlHelper.cs
NMail/branches/luke-dev/NMail.SetupWizard/NMail.SetupWizard.csproj
NMail/branches/luke-dev/NMail.SetupWizard/SmtpSubSysConfigPanel.cs
Modified: NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.Designer.cs
===================================================================
--- NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.Designer.cs 2006-11-06 14:05:36 UTC (rev 73)
+++ NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.Designer.cs 2006-11-07 12:09:49 UTC (rev 74)
@@ -86,7 +86,7 @@
// password
//
this.password.Enabled = false;
- this.password.Location = new System.Drawing.Point(127, 168);
+ this.password.Location = new System.Drawing.Point(127, 191);
this.password.Name = "password";
this.password.PasswordChar = '*';
this.password.Size = new System.Drawing.Size(176, 20);
@@ -97,19 +97,20 @@
this.createDbUserCheckBox.AutoSize = true;
this.createDbUserCheckBox.Checked = true;
this.createDbUserCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
- this.createDbUserCheckBox.Location = new System.Drawing.Point(127, 194);
+ this.createDbUserCheckBox.Location = new System.Drawing.Point(127, 145);
this.createDbUserCheckBox.Name = "createDbUserCheckBox";
this.createDbUserCheckBox.Size = new System.Drawing.Size(159, 17);
this.createDbUserCheckBox.TabIndex = 8;
this.createDbUserCheckBox.Text = "Create a new database user";
this.createDbUserCheckBox.UseVisualStyleBackColor = true;
+ this.createDbUserCheckBox.CheckedChanged += new System.EventHandler(this.createDbUserCheckBox_CheckedChanged);
//
// autoPassCheckBox
//
this.autoPassCheckBox.AutoSize = true;
this.autoPassCheckBox.Checked = true;
this.autoPassCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
- this.autoPassCheckBox.Location = new System.Drawing.Point(127, 145);
+ this.autoPassCheckBox.Location = new System.Drawing.Point(127, 168);
this.autoPassCheckBox.Name = "autoPassCheckBox";
this.autoPassCheckBox.Size = new System.Drawing.Size(141, 17);
this.autoPassCheckBox.TabIndex = 6;
@@ -137,7 +138,7 @@
// passwordLbl
//
this.passwordLbl.AutoSize = true;
- this.passwordLbl.Location = new System.Drawing.Point(17, 171);
+ this.passwordLbl.Location = new System.Drawing.Point(17, 194);
this.passwordLbl.Name = "passwordLbl";
this.passwordLbl.Size = new System.Drawing.Size(104, 13);
this.passwordLbl.TabIndex = 9;
Modified: NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.cs
===================================================================
--- NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.cs 2006-11-06 14:05:36 UTC (rev 73)
+++ NMail/branches/luke-dev/NMail.SetupWizard/DatabaseConfigPanel.cs 2006-11-07 12:09:49 UTC (rev 74)
@@ -24,6 +24,7 @@
using System.Windows.Forms;
using NMail.SpoolData.MySql.Configuration;
+using NMail.LocalStoreData.MySql.Configuration;
namespace NMail.SetupWizard {
public partial class DatabaseConfigPanel : BasePanel {
@@ -39,8 +40,13 @@
// Make a random password
this.password.Text = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
+ this.password.Text = this.password.Text.Replace("=", "a");
+ this.password.Text = this.password.Text.Replace("+", "b");
+ this.password.Text = this.password.Text.Replace("/", "c");
this.createDbUserTask = new Task("Create a new database user.", new TaskDelegate(createDbUser));
+
+ this.grantDbUserPrivsTask = new Task("Grant privileges to the database user.", new TaskDelegate(grantDbPrivileges));
}
private LocalStoreConfigPanel localStoreConfigPanel;
@@ -49,6 +55,8 @@
private Task createDbUserTask;
+ private Task grantDbUserPrivsTask;
+
/// <summary>
/// The code that attempts to create a new database user.
/// </summary>
@@ -68,6 +76,28 @@
}
/// <summary>
+ /// Grants the database user the required privileges to the database.
+ /// </summary>
+ /// <param name="message">A message if an error occurs.</param>
+ /// <returns>The result of the attempt to grant the privileges.</returns>
+ private TaskResult grantDbPrivileges(out string message) {
+ try {
+ string dbUser = this.DatabaseUsername + "@'%'";
+ MySqlHelper.DatabaseHost = this.DatabaseHost;
+ MySqlHelper.GrantPrivileges(dbUser, "mysql.proc", "SELECT"); // TODO: remove for MySql connector 1.0.8 and higher
+ MySqlHelper.GrantPrivileges(dbUser, "NMailSpool.*", "INSERT,SELECT,UPDATE,DELETE,EXECUTE");
+ MySqlHelper.GrantPrivileges(dbUser, "NMailLocalStore.*", "INSERT,SELECT,UPDATE,DELETE,EXECUTE");
+
+ message = null;
+ return TaskResult.Ok;
+
+ } catch (Exception e) {
+ message = "Error granting privileges to database user: " + e.Message;
+ return TaskResult.Error;
+ }
+ }
+
+ /// <summary>
/// Gets the database host.
/// </summary>
public string DatabaseHost {
@@ -115,6 +145,24 @@
// Remove the configuration
MySqlSpoolDataConfiguration.RemoveFromConfigFile();
}
+
+ if (this.localStoreConfigPanel.LocalStoreSubSystemEnabled) {
+ // Ensure our config sections are there
+ MySqlLocalStoreDataConfiguration.AddToConfigFile();
+
+ MySqlLocalStoreDataConfiguration mlsdc = MySqlLocalStoreDataConfiguration.Current;
+
+ // Save the connection string
+ mlsdc.ConnectionString = string.Format(
+ "Host={0};Password={1};Uid={2};Database=NMailLocalStore",
+ this.hostname.Text,
+ this.password.Text,
+ this.username.Text);
+
+ } else {
+ // Remove the configuration
+ MySqlLocalStoreDataConfiguration.RemoveFromConfigFile();
+ }
}
private void loadConfiguration() {
@@ -137,9 +185,11 @@
if (makeTablesIndex == -1) {
this.BaseForm.Tasks.Add(this.createDbUserTask);
+ this.BaseForm.Tasks.Add(this.grantDbUserPrivsTask);
} else {
// Insert the create user task before the make spool tables task
this.BaseForm.Tasks.Insert(makeTablesIndex, this.createDbUserTask);
+ this.BaseForm.Tasks.Insert(makeTablesIndex + 1, this.grantDbUserPrivsTask);
}
}
@@ -148,8 +198,14 @@
protected override void OnBackButtonClick() {
this.BaseForm.Tasks.Remove(this.createDbUserTask);
+ this.BaseForm.Tasks.Remove(this.grantDbUserPrivsTask);
base.OnBackButtonClick();
}
+
+ private void createDbUserCheckBox_CheckedChanged(object sender, EventArgs e) {
+ this.autoPassCheckBox.Enabled = this.createDbUserCheckBox.Checked;
+ this.password.Enabled = this.createDbUserCheckBox.Checked && !this.autoPassCheckBox.Checked;
+ }
}
}
Modified: NMail/branches/luke-dev/NMail.SetupWizard/DnsConfigPanel.cs
===================================================================
--- NMail/branches/luke-dev/NMail.SetupWizard/DnsConfigPanel.cs 2006-11-06 14:05:36 UTC (rev 73)
+++ NMail/branches/luke-dev/NMail.SetupWizard/DnsConfigPanel.cs 2006-11-07 12:09:49 UTC (rev 74)
@@ -91,6 +91,23 @@
DnsClientConfiguration.Current.DnsServers.Add(element);
}
+ // Ensure we are in the list of named services
+ NMailConfiguration nc = NMailConfiguration.Current;
+ bool foundDnsClient = false;
+
+ for (int i = 0; i < nc.NamedServiceDetails.Count; i++) {
+ if (nc.NamedServiceDetails[i].Name == "DnsClient") {
+ foundDnsClient = true;
+ }
+ }
+
+ if (!foundDnsClient) {
+ NamedServiceElement service = new NamedServiceElement();
+ service.Name = "DnsClient";
+ service.ObjectType = typeof(DnsClient.DnsClient);
+ nc.NamedServiceDetails.Add(service);
+ }
+
base.OnNextButtonClick();
}
}
Modified: NMail/branches/luke-dev/NMail.SetupWizard/LocalStoreConfigPanel.cs
===================================================================
--- NMail/branches/luke-dev/NMail.SetupWizard/LocalStoreConfigPanel.cs 2006-11-06 14:05:36 UTC (rev 73)
+++ NMail/branches/luke-dev/NMail.SetupWizard/LocalStoreConfigPanel.cs 2006-11-07 12:09:49 UTC (rev 74)
@@ -143,12 +143,15 @@
// Ensure the local store and localstore data are in the list of named services
bool foundLocalStore = false;
bool foundLocalStoreData = false;
+ bool foundAuthProvider = false;
for (int i = 0; i < nc.NamedServiceDetails.Count; i++) {
if (nc.NamedServiceDetails[i].Name == "LocalStore") {
foundLocalStore = true;
} else if (nc.NamedServiceDetails[i].Name == "LocalStoreData") {
foundLocalStoreData = true;
+ } else if (nc.NamedServiceDetails[i].Name == "AuthProvider") {
+ foundAuthProvider = true;
}
}
@@ -166,6 +169,13 @@
nc.NamedServiceDetails.Add(service);
}
+ if (!foundAuthProvider) {
+ NamedServiceElement service = new NamedServiceElement();
+ service.Name = "AuthProvider";
+ service.ObjectType = typeof(MySqlAuthProvider);
+ nc.NamedServiceDetails.Add(service);
+ }
+
// Save the visible host
try {
isc.VisibleHost = new Host(this.visibleHostTextBox.Text);
Modified: NMail/branches/luke-dev/NMail.SetupWizard/MySqlHelper.cs
===================================================================
--- NMail/branches/luke-dev/NMail.SetupWizard/MySqlHelper.cs 2006-11-06 14:05:36 UTC (rev 73)
+++ NMail/branches/luke-dev/NMail.SetupWizard/MySqlHelper.cs 2006-11-07 12:09:49 UTC (rev 74)
@@ -84,18 +84,35 @@
MySqlCommand cmd = cnn.CreateCommand();
cmd.CommandText = "CREATE DATABASE ?Database";
- cmd.Parameters.Add("Database", databaseName);
+ cmd.Parameters.Add("?Database", databaseName);
cmd.ExecuteNonQuery();
}
+ /// <summary>
+ /// Grants privileges on a database to a user.
+ /// </summary>
+ /// <remarks><b>WARNING:</b> The strings used in this function are not
+ /// checked for SQL injection attacks. Only use input from a trusted
+ /// source!</remarks>
+ public static void GrantPrivileges(string username, string database, string privileges) {
+ MySqlConnection cnn = GetConnection();
+
+ string cmdText = string.Format("GRANT {0} ON {1} TO {2}", privileges, database, username);
+
+ MySqlCommand cmd = cnn.CreateCommand();
+ cmd.CommandText = cmdText;
+
+ cmd.ExecuteNonQuery();
+ }
+
public static void CreateUser(string username, string password) {
MySqlConnection cnn = GetConnection();
MySqlCommand cmd = cnn.CreateCommand();
cmd.CommandText = "CREATE USER ?User IDENTIFIED BY ?Password";
- cmd.Parameters.Add("User", username);
- cmd.Parameters.Add("Password", password);
+ cmd.Parameters.Add("?User", username);
+ cmd.Parameters.Add("?Password", password);
cmd.ExecuteNonQuery();
}
Modified: NMail/branches/luke-dev/NMail.SetupWizard/NMail.SetupWizard.csproj
===================================================================
--- NMail/branches/luke-dev/NMail.SetupWizard/NMail.SetupWizard.csproj 2006-11-06 14:05:36 UTC (rev 73)
+++ NMail/branches/luke-dev/NMail.SetupWizard/NMail.SetupWizard.csproj 2006-11-07 12:09:49 UTC (rev 74)
@@ -28,7 +28,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
+ <Reference Include="MySql.Data, Version=1.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\MySql.Data.dll</HintPath>
</Reference>
Modified: NMail/branches/luke-dev/NMail.SetupWizard/SmtpSubSysConfigPanel.cs
===================================================================
--- NMail/branches/luke-dev/NMail.SetupWizard/SmtpSubSysConfigPanel.cs 2006-11-06 14:05:36 UTC (rev 73)
+++ NMail/branches/luke-dev/NMail.SetupWizard/SmtpSubSysConfigPanel.cs 2006-11-07 12:09:49 UTC (rev 74)
@@ -62,7 +62,7 @@
loadConfiguration();
} else {
- this.relayList.Items.Add("localhost");
+ this.relayList.Items.Add("127.0.0.1");
}
this.makeTablesTask = new Task("Create tables for SMTP spool.", new TaskDelegate(makeSpoolTables));
@@ -128,9 +128,11 @@
SmtpServiceConfiguration.AddToConfigFile();
SpoolFilterServiceConfiguration.AddToConfigFile();
SpoolServiceConfiguration.AddToConfigFile();
-
+ MessageRouterConfiguration.AddToConfigFile();
+
SmtpClientConfiguration scc = SmtpClientConfiguration.Current;
SmtpServiceConfiguration ssc = SmtpServiceConfiguration.Current;
+ MessageRouterConfiguration mrc = MessageRouterConfiguration.Current;
// Ensure the SMTP service is in the list of services
bool foundSmtpService = false;
@@ -152,6 +154,7 @@
bool foundSpoolData = false;
bool foundSpoolService = false;
bool foundSpoolFilter = false;
+ bool foundMessageRouter = false;
for (int i = 0; i < nc.NamedServiceDetails.Count; i++) {
if (nc.NamedServiceDetails[i].Name == "SmtpClient") {
@@ -162,6 +165,8 @@
foundSpoolService = true;
} else if (nc.NamedServiceDetails[i].Name == "SpoolFilterService") {
foundSpoolFilter = true;
+ } else if (nc.NamedServiceDetails[i].Name == "MessageRouter") {
+ foundMessageRouter = true;
}
}
@@ -193,14 +198,22 @@
nc.NamedServiceDetails.Add(service);
}
+ if (!foundMessageRouter) {
+ NamedServiceElement service = new NamedServiceElement();
+ service.Name = "MessageRouter";
+ service.ObjectType = typeof(MessageRouter.MessageRouter);
+ nc.NamedServiceDetails.Add(service);
+ }
+
// Save the visible host
try {
ssc.VisibleHost = new Host(this.visibleHostTextBox.Text);
+ mrc.VisibleHost = ssc.VisibleHost;
} catch (Exception) {
throw new ArgumentException("Invalid host name: " + this.visibleHostTextBox.Text);
}
- // Save the relay hosts
+ // Save the relay hosts
ssc.RelaySubnets.Clear();
foreach (string host in this.relayList.Items) {
WildcardHostConfigurationElement element = new WildcardHostConfigurationElement();
@@ -208,12 +221,25 @@
ssc.RelaySubnets.Add(element);
}
+ // Set the listen endpoints
+ // TODO: make these configurable
+ ssc.ListenEndPoints.Clear();
+ IPEndPointElement endpoint = new IPEndPointElement();
+ endpoint.Address = System.Net.IPAddress.Any;
+ endpoint.Port = 25;
+ ssc.ListenEndPoints.Add(endpoint);
+
+ // Save message router config
+ mrc.WarningTemplate = "Warning.txt";
+ mrc.BounceTemplate = "Bounce.txt";
+
} else {
// Remove the configuration
SmtpClientConfiguration.RemoveFromConfigFile();
SmtpServiceConfiguration.RemoveFromConfigFile();
SpoolFilterServiceConfiguration.RemoveFromConfigFile();
SpoolServiceConfiguration.RemoveFromConfigFile();
+ MessageRouterConfiguration.RemoveFromConfigFile();
// Ensure the Smtp service is not in the list of services
for (int i = 0; i < nc.ServiceDetails.Count; i++) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|