public partial class SetupWizard : Form
{
private string _TrustedFile;
+ private string Icinga2User;
public SetupWizard()
{
InitializeComponent();
txtInstanceName.Text = Icinga2InstanceName;
+
+ Icinga2User = Program.Icinga2User;
+ txtUser.Text = Icinga2User;
}
private void Warning(string message)
{
foreach (ListViewItem lvi in lvwEndpoints.Items) {
if (lvi.SubItems.Count > 1) {
- host = lvi.SubItems[1].Text;
- port = lvi.SubItems[2].Text;
+ host = lvi.SubItems[1].Text.Trim();
+ port = lvi.SubItems[2].Text.Trim();
return true;
}
}
{
FileStream fp = null;
try {
- fp = File.Open(Program.Icinga2InstallDir + String.Format("\\etc\\icinga2\\features-enabled\\{0}.conf", feature), FileMode.Create);
+ fp = File.Open(Program.Icinga2DataDir + String.Format("\\etc\\icinga2\\features-enabled\\{0}.conf", feature), FileMode.Create);
using (StreamWriter sw = new StreamWriter(fp, Encoding.ASCII)) {
fp = null;
sw.Write(String.Format("include \"../features-available/{0}.conf\"\n", feature));
String result = "";
using (Process proc = Process.Start(psi)) {
- proc.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs args) {
+ proc.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs args)
+ {
result += args.Data + "\r\n";
};
- proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs args) {
+ proc.OutputDataReceived += delegate (object sender, DataReceivedEventArgs args)
+ {
result += args.Data + "\r\n";
};
proc.BeginOutputReadLine();
{
SetRetrievalStatus(25);
- string pathPrefix = Program.Icinga2InstallDir + "\\etc\\icinga2\\pki\\" + txtInstanceName.Text;
-
+ string pathPrefix = Program.Icinga2DataDir + "\\etc\\icinga2\\pki\\" + txtInstanceName.Text;
+ string processArguments = "pki new-cert --cn \"" + txtInstanceName.Text + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\"";
string output;
if (!File.Exists(pathPrefix + ".crt")) {
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
- "pki new-cert --cn \"" + txtInstanceName.Text + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\"",
+ processArguments,
out output)) {
- ShowErrorText(output);
+ ShowErrorText("Running command 'icinga2.exe " + processArguments + "' produced the following output:\n" + output);
return;
}
}
_TrustedFile = Path.GetTempFileName();
+ processArguments = "pki save-cert --host \"" + host + "\" --port \"" + port + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\" --trustedcert \"" + _TrustedFile + "\"";
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
- "pki save-cert --host \"" + host + "\" --port \"" + port + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\" --trustedcert \"" + _TrustedFile + "\"",
+ processArguments,
out output)) {
- ShowErrorText(output);
+ ShowErrorText("Running command 'icinga2.exe " + processArguments + "' produced the following output:\n" + output);
return;
}
SetRetrievalStatus(100);
-
- X509Certificate2 cert = new X509Certificate2(_TrustedFile);
- Invoke((MethodInvoker)delegate { ShowCertificatePrompt(cert); });
+ try {
+ X509Certificate2 cert = new X509Certificate2(_TrustedFile);
+ Invoke((MethodInvoker)delegate { ShowCertificatePrompt(cert); });
+ } catch (Exception e) {
+ ShowErrorText("Failed to receive certificate: " + e.Message);
+ }
}
private void ConfigureService()
string args = "";
- if (rdoNewMaster.Checked)
- args += " --master";
-
- Invoke((MethodInvoker)delegate {
+ Invoke((MethodInvoker)delegate
+ {
string master_host, master_port;
GetMasterHostPort(out master_host, out master_port);
args += " --master_host " + master_host + "," + master_port;
foreach (ListViewItem lvi in lvwEndpoints.Items) {
- args += " --endpoint " + lvi.SubItems[0].Text;
-
+ args += " --endpoint " + lvi.SubItems[0].Text.Trim();
+
if (lvi.SubItems.Count > 1)
- args += "," + lvi.SubItems[1].Text + "," + lvi.SubItems[2].Text;
+ args += "," + lvi.SubItems[1].Text.Trim() + "," + lvi.SubItems[2].Text.Trim();
}
});
if (rdoListener.Checked)
- args += " --listen ::," + txtListenerPort.Text;
+ args += " --listen ::," + txtListenerPort.Text.Trim();
if (chkAcceptConfig.Checked)
args += " --accept-config";
if (chkAcceptCommands.Checked)
args += " --accept-commands";
- args += " --ticket " + txtTicket.Text;
- args += " --trustedcert " + _TrustedFile;
- args += " --cn " + txtInstanceName.Text;
- args += " --zone " + txtInstanceName.Text;
+ string ticket = txtTicket.Text.Trim();
+
+ if (ticket.Length > 0)
+ args += " --ticket \"" + ticket + "\"";
+
+ args += " --trustedcert \"" + _TrustedFile + "\"";
+ args += " --cn \"" + txtInstanceName.Text.Trim() + "\"";
+ args += " --zone \"" + txtInstanceName.Text.Trim() + "\"";
+
+ foreach (ListViewItem lvi in lvwGlobalZones.Items) {
+ args += " --global_zones " + lvi.SubItems[0].Text.Trim();
+ }
+
+ if (chkDisableConf.Checked)
+ args += " --disable-confd";
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"node setup" + args,
out output)) {
- ShowErrorText(output);
+ ShowErrorText("Running command 'icinga2.exe " + "node setup" + args + "' produced the following output:\n" + output);
return;
}
SetConfigureStatus(50, "Setting ACLs for the Icinga 2 directory...");
+
+ string serviceUser = txtUser.Text.Trim();
+
DirectoryInfo di = new DirectoryInfo(Program.Icinga2InstallDir);
DirectorySecurity ds = di.GetAccessControl();
- FileSystemAccessRule rule = new FileSystemAccessRule("NT AUTHORITY\\NetworkService",
+ FileSystemAccessRule rule = new FileSystemAccessRule(serviceUser,
FileSystemRights.Modify,
InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
- ds.AddAccessRule(rule);
- di.SetAccessControl(ds);
+ try {
+ ds.AddAccessRule(rule);
+ di.SetAccessControl(ds);
+ } catch (System.Security.Principal.IdentityNotMappedException) {
+ ShowErrorText("Could not set ACLs for user \"" + serviceUser + "\". Identitiy is not mapped.\n");
+ return;
+ }
SetConfigureStatus(75, "Installing the Icinga 2 service...");
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
"daemon --validate",
out output)) {
- ShowErrorText(output);
+ ShowErrorText("Running command 'icinga2.exe daemon --validate' produced the following output:\n" + output);
return;
}
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
- "--scm-install daemon",
+ "--scm-install --scm-user \"" + serviceUser + "\" daemon",
out output)) {
- ShowErrorText(output);
+ ShowErrorText("\nRunning command 'icinga2.exe --scm-install --scm-user \"" +
+ serviceUser + "\" daemon' produced the following output:\n" + output);
return;
}
- if (chkInstallNSCP.Checked)
- {
+ if (chkInstallNSCP.Checked) {
SetConfigureStatus(85, "Waiting for NSClient++ installation to complete...");
Process proc = new Process();
proc.StartInfo.FileName = "msiexec.exe";
- proc.StartInfo.Arguments = "/i \"" + Program.Icinga2InstallDir + "\\sbin\\NSCP-Win32.msi\"";
+ proc.StartInfo.Arguments = "/i \"" + Program.Icinga2InstallDir + "\\sbin\\NSCP.msi\"";
proc.Start();
proc.WaitForExit();
}
SetConfigureStatus(100, "Finished.");
+ // Override the completed text
+ lblSetupCompleted.Text = "The Icinga 2 Windows client was set up successfully.";
+
+ // Add a note for the user for ticket-less signing
+ if (ticket.Length == 0) {
+ lblSetupCompleted.Text += "\n\nTicket was not specified. Please sign the certificate request on the Icinga 2 master node (requires v2.8+).";
+ }
+
FinishConfigure();
}
tbcPages.SelectedTab = tabFinish;
}
- private void AgentWizard_Shown(object sender, EventArgs e)
- {
- string installDir = Program.Icinga2InstallDir;
-
- /* TODO: This is something the NSIS installer should do */
- Directory.CreateDirectory(installDir + "\\etc\\icinga2\\pki");
- Directory.CreateDirectory(installDir + "\\var\\cache\\icinga2");
- Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\pki");
- Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\agent\\inventory");
- Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\api\\config");
- Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\api\\log");
- Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\api\\zones");
- Directory.CreateDirectory(installDir + "\\var\\log\\icinga2\\compat\\archive");
- Directory.CreateDirectory(installDir + "\\var\\log\\icinga2\\crash");
- Directory.CreateDirectory(installDir + "\\var\\run\\icinga2\\cmd");
- Directory.CreateDirectory(installDir + "\\var\\spool\\icinga2\\perfdata");
- Directory.CreateDirectory(installDir + "\\var\\spool\\icinga2\\tmp");
- }
-
private void btnBack_Click(object sender, EventArgs e)
{
if (tbcPages.SelectedTab == tabError) {
return;
}
- if (txtTicket.Text.Length == 0) {
- Warning("Please enter an agent ticket.");
+ if (lvwEndpoints.Items.Count == 0) {
+ Warning("You need to add at least one master/satellite endpoint.");
return;
}
- if (rdoNoMaster.Checked) {
- if (lvwEndpoints.Items.Count == 0) {
- Warning("You need to add at least one master endpoint.");
- return;
- }
-
- string host, port;
- if (!GetMasterHostPort(out host, out port)) {
- Warning("Please enter a remote host and port for at least one of your endpoints.");
- return;
- }
+ string host, port;
+ if (!GetMasterHostPort(out host, out port)) {
+ Warning("Please enter a remote host and port for at least one of your endpoints.");
+ return;
}
if (rdoListener.Checked && (txtListenerPort.Text == "")) {
Warning("You need to specify a listener port.");
return;
}
+
+ if (txtUser.Text.Length == 0) {
+ Warning("Icinga 2 service user may not be empty.");
+ return;
+ }
}
if (tbcPages.SelectedTab == tabFinish || tbcPages.SelectedTab == tabError)
thread.Start();
}
- /*if (tbcPages.SelectedTab == tabParameters &&
- !File.Exists(Icinga2InstallDir + "\\etc\\icinga2\\pki\\agent\\agent.crt")) {
- byte[] bytes = Convert.FromBase64String(txtBundle.Text);
- MemoryStream ms = new MemoryStream(bytes);
- GZipStream gz = new GZipStream(ms, CompressionMode.Decompress);
- MemoryStream ms2 = new MemoryStream();
-
- byte[] buffer = new byte[512];
- int rc;
- while ((rc = gz.Read(buffer, 0, buffer.Length)) > 0)
- ms2.Write(buffer, 0, rc);
- ms2.Position = 0;
- TarReader tr = new TarReader(ms2);
- tr.ReadToEnd(Icinga2InstallDir + "\\etc\\icinga2\\pki\\agent");
- }*/
-
if (tbcPages.SelectedTab == tabConfigure) {
Thread thread = new Thread(ConfigureService);
thread.Start();
}
}
- private void RadioMaster_CheckedChanged(object sender, EventArgs e)
- {
- lvwEndpoints.Enabled = !rdoNewMaster.Checked;
- btnAddEndpoint.Enabled = !rdoNewMaster.Checked;
- btnRemoveEndpoint.Enabled = !rdoNewMaster.Checked && lvwEndpoints.SelectedItems.Count > 0;
- }
-
private void RadioListener_CheckedChanged(object sender, EventArgs e)
{
txtListenerPort.Enabled = rdoListener.Checked;
private void lvwEndpoints_SelectedIndexChanged(object sender, EventArgs e)
{
btnRemoveEndpoint.Enabled = lvwEndpoints.SelectedItems.Count > 0;
+ btnEditEndpoint.Enabled = lvwEndpoints.SelectedItems.Count > 0;
}
private void lvwX509Fields_SelectedIndexChanged(object sender, EventArgs e)
ListViewItem lvi = lvwX509Fields.SelectedItems[0];
- txtX509Field.Text = (string)lvi.Tag;
+ txtX509Field.Text = Convert.ToString(lvi.Tag);
}
private void btnRemoveEndpoint_Click(object sender, EventArgs e)
while (lvwEndpoints.SelectedItems.Count > 0) {
lvwEndpoints.Items.Remove(lvwEndpoints.SelectedItems[0]);
}
- }
+ }
+
+ private void chkRunServiceAsThisUser_CheckedChanged(object sender, EventArgs e)
+ {
+ txtUser.Enabled = !txtUser.Enabled;
+ if (!txtUser.Enabled)
+ txtUser.Text = Icinga2User;
+ }
+
+ private void btnEditEndpoint_Click(object sender, EventArgs e)
+ {
+ ListViewItem lvi = lvwEndpoints.SelectedItems[0];
+ EndpointInputBox eib = new EndpointInputBox();
+
+ eib.Text = "Edit Endpoint";
+ eib.txtInstanceName.Text = lvi.SubItems[0].Text;
+
+ if (lvi.SubItems.Count >= 2) {
+ eib.txtHost.Text = lvi.SubItems[1].Text;
+ eib.txtPort.Text = lvi.SubItems[2].Text;
+ eib.chkConnect.Checked = true;
+ }
+
+ if (eib.ShowDialog(this) == DialogResult.Cancel)
+ return;
+
+ lvwEndpoints.Items.Remove(lvi);
+
+ ListViewItem lvi2 = new ListViewItem();
+ lvi2.Text = eib.txtInstanceName.Text;
+
+ if (eib.chkConnect.Checked) {
+ lvi2.SubItems.Add(eib.txtHost.Text);
+ lvi2.SubItems.Add(eib.txtPort.Text);
+ }
+
+ lvwEndpoints.Items.Add(lvi2);
+ }
+
+ private void btnAddGlobalZone_Click(object sender, EventArgs e)
+ {
+ GlobalZonesInputBox gzib = new GlobalZonesInputBox(lvwGlobalZones.Items);
+
+ if (gzib.ShowDialog(this) == DialogResult.Cancel)
+ return;
+
+ ListViewItem lvi = new ListViewItem();
+ lvi.Text = gzib.txtGlobalZoneName.Text;
+
+ lvwGlobalZones.Items.Add(lvi);
+ }
+
+ private void btnRemoveGlobalZone_Click(object sender, EventArgs e)
+ {
+ while (lvwGlobalZones.SelectedItems.Count > 0) {
+ lvwGlobalZones.Items.Remove(lvwGlobalZones.SelectedItems[0]);
+ }
+ }
+
+ private void lvwGlobalZones_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ btnEditGlobalZone.Enabled = lvwGlobalZones.SelectedItems.Count > 0;
+ btnRemoveGlobalZone.Enabled = lvwGlobalZones.SelectedItems.Count > 0;
+ }
+
+ private void btnEditGlobalZone_Click(object sender, EventArgs e)
+ {
+ ListViewItem lvi = lvwGlobalZones.SelectedItems[0];
+ GlobalZonesInputBox gzib = new GlobalZonesInputBox(lvwGlobalZones.Items);
+
+ gzib.Text = "Edit Global Zone";
+ gzib.txtGlobalZoneName.Text = lvi.SubItems[0].Text;
+
+ if (gzib.ShowDialog(this) == DialogResult.Cancel)
+ return;
+
+ lvwGlobalZones.Items.Remove(lvi);
+
+ ListViewItem lvi2 = new ListViewItem();
+ lvi2.Text = gzib.txtGlobalZoneName.Text;
+
+ lvwGlobalZones.Items.Add(lvi2);
+ }
+
+ private void checkBox1_CheckedChanged(object sender, EventArgs e)
+ {
+
+ }
+
+ private void SetupWizard_Load(object sender, EventArgs e)
+ {
+ this.MinimumSize = this.Size;
+ this.MaximumSize = this.Size;
+ }
}
}
+