]> granicus.if.org Git - icinga2/blobdiff - agent/windows-setup-agent/SetupWizard.cs
Merge pull request #6503 from peteeckel/fix/reduce-loglevel-plugin-env-6460
[icinga2] / agent / windows-setup-agent / SetupWizard.cs
index 418a8516b24a41f58f4c50d18b8ad021c7443958..018b2ababd02e3050d748a43ddf3cc341f2716b6 100644 (file)
@@ -54,8 +54,8 @@ namespace Icinga
                {
                        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;
                                }
                        }
@@ -176,9 +176,12 @@ namespace Icinga
                        }
 
                        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()
@@ -189,9 +192,6 @@ namespace Icinga
 
                        string args = "";
 
-                       if (rdoNewMaster.Checked)
-                               args += " --master";
-
                        Invoke((MethodInvoker)delegate
                        {
                                string master_host, master_port;
@@ -200,15 +200,15 @@ namespace Icinga
                                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";
@@ -216,10 +216,21 @@ namespace Icinga
                        if (chkAcceptCommands.Checked)
                                args += " --accept-commands";
 
-                       args += " --ticket \"" + txtTicket.Text + "\"";
+                       string ticket = txtTicket.Text.Trim();
+
+                       if (ticket.Length > 0)
+                               args += " --ticket \"" + ticket + "\"";
+
                        args += " --trustedcert \"" + _TrustedFile + "\"";
-                       args += " --cn \"" + txtInstanceName.Text + "\"";
-                       args += " --zone \"" + txtInstanceName.Text + "\"";
+                       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,
@@ -229,16 +240,19 @@ namespace Icinga
                        }
 
                        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(txtUser.Text,
+                       FileSystemAccessRule rule = new FileSystemAccessRule(serviceUser,
                                FileSystemRights.Modify,
                                InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
                        try {
                                ds.AddAccessRule(rule);
                                di.SetAccessControl(ds);
                        } catch (System.Security.Principal.IdentityNotMappedException) {
-                               ShowErrorText("Could not set ACLs for \"" + txtUser.Text + "\". Identitiy is not mapped.\n");
+                               ShowErrorText("Could not set ACLs for user \"" + serviceUser + "\". Identitiy is not mapped.\n");
                                return;
                        }
 
@@ -256,10 +270,10 @@ namespace Icinga
                        }
 
                        if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
-                               "--scm-install --scm-user \"" + txtUser.Text + "\" daemon",
+                               "--scm-install --scm-user \"" + serviceUser + "\" daemon",
                                out output)) {
                                ShowErrorText("\nRunning command 'icinga2.exe --scm-install --scm-user \"" +
-                                       txtUser.Text + "\" daemon' produced the following output:\n" + output);
+                                       serviceUser + "\" daemon' produced the following output:\n" + output);
                                return;
                        }
 
@@ -275,6 +289,14 @@ namespace Icinga
 
                        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();
                }
 
@@ -311,22 +333,15 @@ namespace Icinga
                                        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 == "")) {
@@ -335,7 +350,7 @@ namespace Icinga
                                }
 
                                if (txtUser.Text.Length == 0) {
-                                       Warning("Icinga2 user may not be empty.");
+                                       Warning("Icinga 2 service user may not be empty.");
                                        return;
                                }
                        }
@@ -373,35 +388,12 @@ namespace Icinga
                                thread.Start();
                        }
 
-                       /*if (tbcPages.SelectedTab == tabParameters &&
-                               !File.Exists(Icinga2DataDir + "\\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(Icinga2DataDir + "\\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;
@@ -488,7 +480,7 @@ namespace Icinga
 
                        ListViewItem lvi = lvwX509Fields.SelectedItems[0];
 
-                       txtX509Field.Text = (string)lvi.Tag;
+                       txtX509Field.Text = Convert.ToString(lvi.Tag);
                }
 
                private void btnRemoveEndpoint_Click(object sender, EventArgs e)
@@ -534,6 +526,62 @@ namespace Icinga
 
                        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;
+               }
        }
 }