2014-04-18 12:39:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2014-10-21 16:07:22 +02:00
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Net.NetworkInformation;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Security.AccessControl;
|
|
|
|
|
|
|
|
|
|
namespace Icinga
|
|
|
|
|
{
|
2014-10-31 13:08:09 +01:00
|
|
|
|
public partial class SetupWizard : Form
|
2014-04-18 12:39:50 +02:00
|
|
|
|
{
|
2014-10-22 09:34:09 +02:00
|
|
|
|
private string _TrustedFile;
|
2016-02-26 13:42:36 +01:00
|
|
|
|
private string Icinga2User;
|
2014-10-22 09:34:09 +02:00
|
|
|
|
|
2014-10-31 13:08:09 +01:00
|
|
|
|
public SetupWizard()
|
2014-04-18 12:39:50 +02:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
txtInstanceName.Text = Icinga2InstanceName;
|
2016-02-26 13:42:36 +01:00
|
|
|
|
|
|
|
|
|
Icinga2User = Program.Icinga2User;
|
|
|
|
|
txtUser.Text = Icinga2User;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Warning(string message)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string Icinga2InstanceName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
IPGlobalProperties props = IPGlobalProperties.GetIPGlobalProperties();
|
|
|
|
|
|
|
|
|
|
string fqdn = props.HostName;
|
|
|
|
|
|
|
|
|
|
if (props.DomainName != "")
|
|
|
|
|
fqdn += "." + props.DomainName;
|
|
|
|
|
|
2020-11-02 14:08:56 +01:00
|
|
|
|
return fqdn.ToLower();
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 04:23:22 +02:00
|
|
|
|
private bool GetMasterHostPort(out string host, out string port)
|
|
|
|
|
{
|
|
|
|
|
foreach (ListViewItem lvi in lvwEndpoints.Items) {
|
|
|
|
|
if (lvi.SubItems.Count > 1) {
|
2017-11-09 09:28:05 +01:00
|
|
|
|
host = lvi.SubItems[1].Text.Trim();
|
|
|
|
|
port = lvi.SubItems[2].Text.Trim();
|
2014-10-23 04:23:22 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
host = null;
|
|
|
|
|
port = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-18 12:39:50 +02:00
|
|
|
|
private void EnableFeature(string feature)
|
|
|
|
|
{
|
2014-11-13 20:18:41 +01:00
|
|
|
|
FileStream fp = null;
|
|
|
|
|
try {
|
2016-04-01 11:40:01 +02:00
|
|
|
|
fp = File.Open(Program.Icinga2DataDir + String.Format("\\etc\\icinga2\\features-enabled\\{0}.conf", feature), FileMode.Create);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
using (StreamWriter sw = new StreamWriter(fp, Encoding.ASCII)) {
|
2014-11-13 20:18:41 +01:00
|
|
|
|
fp = null;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
sw.Write(String.Format("include \"../features-available/{0}.conf\"\n", feature));
|
|
|
|
|
}
|
2014-11-13 20:18:41 +01:00
|
|
|
|
} finally {
|
|
|
|
|
if (fp != null)
|
|
|
|
|
fp.Dispose();
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 16:07:22 +02:00
|
|
|
|
private void SetRetrievalStatus(int pct)
|
2014-04-18 12:39:50 +02:00
|
|
|
|
{
|
|
|
|
|
if (InvokeRequired) {
|
2014-10-21 16:07:22 +02:00
|
|
|
|
Invoke((MethodInvoker)delegate { SetRetrievalStatus(pct); });
|
2014-04-18 12:39:50 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 16:07:22 +02:00
|
|
|
|
prgRetrieveCertificate.Value = pct;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetConfigureStatus(int pct, string message)
|
|
|
|
|
{
|
|
|
|
|
if (InvokeRequired) {
|
2014-10-21 16:07:22 +02:00
|
|
|
|
Invoke((MethodInvoker)delegate { SetConfigureStatus(pct, message); });
|
2014-04-18 12:39:50 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prgConfig.Value = pct;
|
|
|
|
|
lblConfigStatus.Text = message;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
private void ShowErrorText(string text)
|
|
|
|
|
{
|
|
|
|
|
if (InvokeRequired) {
|
|
|
|
|
Invoke((MethodInvoker)delegate { ShowErrorText(text); });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txtError.Text = text;
|
|
|
|
|
tbcPages.SelectedTab = tabError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool RunProcess(string filename, string arguments, out string output)
|
|
|
|
|
{
|
|
|
|
|
ProcessStartInfo psi = new ProcessStartInfo();
|
|
|
|
|
psi.FileName = filename;
|
|
|
|
|
psi.Arguments = arguments;
|
|
|
|
|
psi.CreateNoWindow = true;
|
|
|
|
|
psi.UseShellExecute = false;
|
|
|
|
|
psi.RedirectStandardOutput = true;
|
|
|
|
|
psi.RedirectStandardError = true;
|
|
|
|
|
|
|
|
|
|
String result = "";
|
|
|
|
|
|
|
|
|
|
using (Process proc = Process.Start(psi)) {
|
2016-02-26 13:42:36 +01:00
|
|
|
|
proc.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs args)
|
|
|
|
|
{
|
2014-10-22 09:34:09 +02:00
|
|
|
|
result += args.Data + "\r\n";
|
|
|
|
|
};
|
2016-02-26 13:42:36 +01:00
|
|
|
|
proc.OutputDataReceived += delegate (object sender, DataReceivedEventArgs args)
|
|
|
|
|
{
|
2014-10-22 09:34:09 +02:00
|
|
|
|
result += args.Data + "\r\n";
|
|
|
|
|
};
|
|
|
|
|
proc.BeginOutputReadLine();
|
|
|
|
|
proc.BeginErrorReadLine();
|
|
|
|
|
proc.WaitForExit();
|
|
|
|
|
|
|
|
|
|
output = result;
|
|
|
|
|
|
|
|
|
|
if (proc.ExitCode != 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 16:07:22 +02:00
|
|
|
|
private void VerifyCertificate(string host, string port)
|
|
|
|
|
{
|
|
|
|
|
SetRetrievalStatus(25);
|
|
|
|
|
|
2016-04-01 11:40:01 +02:00
|
|
|
|
string pathPrefix = Program.Icinga2DataDir + "\\etc\\icinga2\\pki\\" + txtInstanceName.Text;
|
2016-03-15 16:16:40 +01:00
|
|
|
|
string processArguments = "pki new-cert --cn \"" + txtInstanceName.Text + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\"";
|
2014-10-22 09:34:09 +02:00
|
|
|
|
string output;
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
|
|
|
|
if (!File.Exists(pathPrefix + ".crt")) {
|
2015-05-12 13:49:52 +02:00
|
|
|
|
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2016-03-15 16:16:40 +01:00
|
|
|
|
processArguments,
|
2014-11-13 20:18:41 +01:00
|
|
|
|
out output)) {
|
2016-03-15 16:16:40 +01:00
|
|
|
|
ShowErrorText("Running command 'icinga2.exe " + processArguments + "' produced the following output:\n" + output);
|
2014-10-22 09:34:09 +02:00
|
|
|
|
return;
|
2014-10-21 16:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetRetrievalStatus(50);
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
_TrustedFile = Path.GetTempFileName();
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
2020-02-25 12:50:06 +01:00
|
|
|
|
processArguments = "pki save-cert --host \"" + host + "\" --port \"" + port + "\" --trustedcert \"" + _TrustedFile + "\"";
|
2015-05-12 13:49:52 +02:00
|
|
|
|
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2016-03-15 16:16:40 +01:00
|
|
|
|
processArguments,
|
2014-11-13 20:18:41 +01:00
|
|
|
|
out output)) {
|
2016-03-15 16:16:40 +01:00
|
|
|
|
ShowErrorText("Running command 'icinga2.exe " + processArguments + "' produced the following output:\n" + output);
|
2014-10-22 09:34:09 +02:00
|
|
|
|
return;
|
2014-10-21 16:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetRetrievalStatus(100);
|
2018-04-05 13:36:12 +02:00
|
|
|
|
try {
|
|
|
|
|
X509Certificate2 cert = new X509Certificate2(_TrustedFile);
|
|
|
|
|
Invoke((MethodInvoker)delegate { ShowCertificatePrompt(cert); });
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
ShowErrorText("Failed to receive certificate: " + e.Message);
|
|
|
|
|
}
|
2014-10-21 16:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-18 12:39:50 +02:00
|
|
|
|
private void ConfigureService()
|
|
|
|
|
{
|
|
|
|
|
SetConfigureStatus(0, "Updating configuration files...");
|
2014-10-22 09:34:09 +02:00
|
|
|
|
|
|
|
|
|
string output;
|
|
|
|
|
|
|
|
|
|
string args = "";
|
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
Invoke((MethodInvoker)delegate
|
|
|
|
|
{
|
2014-10-23 04:23:22 +02:00
|
|
|
|
string master_host, master_port;
|
|
|
|
|
GetMasterHostPort(out master_host, out master_port);
|
|
|
|
|
|
2017-12-19 15:50:05 +01:00
|
|
|
|
args += " --master_host " + master_host + "," + master_port;
|
2014-10-22 21:49:41 +02:00
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
foreach (ListViewItem lvi in lvwEndpoints.Items) {
|
2017-11-09 09:27:15 +01:00
|
|
|
|
args += " --endpoint " + lvi.SubItems[0].Text.Trim();
|
2016-02-26 13:42:36 +01:00
|
|
|
|
|
2017-12-19 15:50:05 +01:00
|
|
|
|
if (lvi.SubItems.Count > 1)
|
|
|
|
|
args += "," + lvi.SubItems[1].Text.Trim() + "," + lvi.SubItems[2].Text.Trim();
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
2014-10-22 09:34:09 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (rdoListener.Checked)
|
2017-11-09 09:27:15 +01:00
|
|
|
|
args += " --listen ::," + txtListenerPort.Text.Trim();
|
2014-10-22 09:34:09 +02:00
|
|
|
|
|
2015-03-27 14:11:21 +01:00
|
|
|
|
if (chkAcceptConfig.Checked)
|
|
|
|
|
args += " --accept-config";
|
|
|
|
|
|
|
|
|
|
if (chkAcceptCommands.Checked)
|
|
|
|
|
args += " --accept-commands";
|
|
|
|
|
|
2017-11-09 09:27:15 +01:00
|
|
|
|
string ticket = txtTicket.Text.Trim();
|
2017-11-03 13:51:45 +01:00
|
|
|
|
|
|
|
|
|
if (ticket.Length > 0)
|
|
|
|
|
args += " --ticket \"" + ticket + "\"";
|
2017-10-16 18:01:43 +02:00
|
|
|
|
|
2016-03-14 16:37:15 +01:00
|
|
|
|
args += " --trustedcert \"" + _TrustedFile + "\"";
|
2017-11-09 09:27:15 +01:00
|
|
|
|
args += " --cn \"" + txtInstanceName.Text.Trim() + "\"";
|
|
|
|
|
args += " --zone \"" + txtInstanceName.Text.Trim() + "\"";
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
2018-03-18 16:19:15 +01:00
|
|
|
|
foreach (ListViewItem lvi in lvwGlobalZones.Items) {
|
|
|
|
|
args += " --global_zones " + lvi.SubItems[0].Text.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 17:45:07 +02:00
|
|
|
|
if (chkDisableConf.Checked)
|
|
|
|
|
args += " --disable-confd";
|
|
|
|
|
|
2015-05-12 13:49:52 +02:00
|
|
|
|
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-18 16:06:50 +01:00
|
|
|
|
"node setup" + args,
|
2014-11-13 20:18:41 +01:00
|
|
|
|
out output)) {
|
2016-03-15 16:16:40 +01:00
|
|
|
|
ShowErrorText("Running command 'icinga2.exe " + "node setup" + args + "' produced the following output:\n" + output);
|
2014-10-22 09:34:09 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
2014-04-20 15:35:51 +02:00
|
|
|
|
SetConfigureStatus(50, "Setting ACLs for the Icinga 2 directory...");
|
2017-11-03 13:51:45 +01:00
|
|
|
|
|
2017-11-09 09:27:15 +01:00
|
|
|
|
string serviceUser = txtUser.Text.Trim();
|
2017-11-03 13:51:45 +01:00
|
|
|
|
|
2015-05-12 13:49:52 +02:00
|
|
|
|
DirectoryInfo di = new DirectoryInfo(Program.Icinga2InstallDir);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
DirectorySecurity ds = di.GetAccessControl();
|
2017-11-03 13:51:45 +01:00
|
|
|
|
FileSystemAccessRule rule = new FileSystemAccessRule(serviceUser,
|
2014-11-18 18:33:51 +01:00
|
|
|
|
FileSystemRights.Modify,
|
2014-11-13 20:18:41 +01:00
|
|
|
|
InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow);
|
2016-02-26 13:42:36 +01:00
|
|
|
|
try {
|
|
|
|
|
ds.AddAccessRule(rule);
|
|
|
|
|
di.SetAccessControl(ds);
|
|
|
|
|
} catch (System.Security.Principal.IdentityNotMappedException) {
|
2017-11-03 13:51:45 +01:00
|
|
|
|
ShowErrorText("Could not set ACLs for user \"" + serviceUser + "\". Identitiy is not mapped.\n");
|
2016-02-26 13:42:36 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
2014-04-20 15:35:51 +02:00
|
|
|
|
SetConfigureStatus(75, "Installing the Icinga 2 service...");
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
2015-05-12 13:49:52 +02:00
|
|
|
|
RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
"--scm-uninstall",
|
|
|
|
|
out output);
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
2015-05-12 13:49:52 +02:00
|
|
|
|
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
"daemon --validate",
|
|
|
|
|
out output)) {
|
2016-03-15 16:16:40 +01:00
|
|
|
|
ShowErrorText("Running command 'icinga2.exe daemon --validate' produced the following output:\n" + output);
|
2014-10-23 04:23:22 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-12 13:49:52 +02:00
|
|
|
|
if (!RunProcess(Program.Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2017-11-03 13:51:45 +01:00
|
|
|
|
"--scm-install --scm-user \"" + serviceUser + "\" daemon",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
out output)) {
|
2016-02-26 13:42:36 +01:00
|
|
|
|
ShowErrorText("\nRunning command 'icinga2.exe --scm-install --scm-user \"" +
|
2017-11-03 13:51:45 +01:00
|
|
|
|
serviceUser + "\" daemon' produced the following output:\n" + output);
|
2014-10-22 09:34:09 +02:00
|
|
|
|
return;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetConfigureStatus(100, "Finished.");
|
|
|
|
|
|
2017-11-02 17:01:52 +01:00
|
|
|
|
// Override the completed text
|
2019-07-20 13:31:12 +02:00
|
|
|
|
lblSetupCompleted.Text = "The Icinga Windows agent was set up successfully.";
|
2017-11-02 17:01:52 +01:00
|
|
|
|
|
|
|
|
|
// Add a note for the user for ticket-less signing
|
2017-11-03 13:51:45 +01:00
|
|
|
|
if (ticket.Length == 0) {
|
2017-11-02 17:01:52 +01:00
|
|
|
|
lblSetupCompleted.Text += "\n\nTicket was not specified. Please sign the certificate request on the Icinga 2 master node (requires v2.8+).";
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-18 12:39:50 +02:00
|
|
|
|
FinishConfigure();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FinishConfigure()
|
|
|
|
|
{
|
|
|
|
|
if (InvokeRequired) {
|
2014-10-21 16:07:22 +02:00
|
|
|
|
Invoke((MethodInvoker)FinishConfigure);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tbcPages.SelectedTab = tabFinish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnBack_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-22 09:34:09 +02:00
|
|
|
|
if (tbcPages.SelectedTab == tabError) {
|
|
|
|
|
tbcPages.SelectedIndex = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 16:07:22 +02:00
|
|
|
|
int offset = 1;
|
|
|
|
|
|
|
|
|
|
if (tbcPages.SelectedTab == tabVerifyCertificate)
|
|
|
|
|
offset++;
|
|
|
|
|
|
|
|
|
|
tbcPages.SelectedIndex -= offset;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnNext_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (tbcPages.SelectedTab == tabParameters) {
|
2014-10-21 16:07:22 +02:00
|
|
|
|
if (txtInstanceName.Text.Length == 0) {
|
|
|
|
|
Warning("Please enter an instance name.");
|
2014-04-18 12:39:50 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-16 18:01:43 +02:00
|
|
|
|
if (lvwEndpoints.Items.Count == 0) {
|
|
|
|
|
Warning("You need to add at least one master/satellite endpoint.");
|
2014-10-22 09:34:09 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-16 18:01:43 +02:00
|
|
|
|
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;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rdoListener.Checked && (txtListenerPort.Text == "")) {
|
|
|
|
|
Warning("You need to specify a listener port.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-26 13:42:36 +01:00
|
|
|
|
|
|
|
|
|
if (txtUser.Text.Length == 0) {
|
2017-11-03 13:51:45 +01:00
|
|
|
|
Warning("Icinga 2 service user may not be empty.");
|
2016-02-26 13:42:36 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
if (tbcPages.SelectedTab == tabFinish || tbcPages.SelectedTab == tabError)
|
2014-04-18 12:39:50 +02:00
|
|
|
|
Application.Exit();
|
|
|
|
|
|
|
|
|
|
tbcPages.SelectedIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tbcPages_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Refresh();
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
btnBack.Enabled = (tbcPages.SelectedTab == tabVerifyCertificate || tbcPages.SelectedTab == tabError);
|
2014-10-21 16:07:22 +02:00
|
|
|
|
btnNext.Enabled = (tbcPages.SelectedTab == tabParameters || tbcPages.SelectedTab == tabVerifyCertificate || tbcPages.SelectedTab == tabFinish);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
|
|
|
|
if (tbcPages.SelectedTab == tabFinish) {
|
|
|
|
|
btnNext.Text = "&Finish >";
|
|
|
|
|
btnCancel.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 16:07:22 +02:00
|
|
|
|
if (tbcPages.SelectedTab == tabRetrieveCertificate) {
|
|
|
|
|
ListViewItem lvi = lvwEndpoints.Items[0];
|
|
|
|
|
|
2014-10-23 04:23:22 +02:00
|
|
|
|
string master_host, master_port;
|
|
|
|
|
GetMasterHostPort(out master_host, out master_port);
|
|
|
|
|
|
|
|
|
|
Thread thread = new Thread((ThreadStart)delegate { VerifyCertificate(master_host, master_port); });
|
2014-10-21 16:07:22 +02:00
|
|
|
|
thread.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
if (tbcPages.SelectedTab == tabConfigure) {
|
2014-04-18 12:39:50 +02:00
|
|
|
|
Thread thread = new Thread(ConfigureService);
|
|
|
|
|
thread.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RadioListener_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
txtListenerPort.Enabled = rdoListener.Checked;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 16:07:22 +02:00
|
|
|
|
private void AddCertificateField(string name, string shortValue, string longValue = null)
|
|
|
|
|
{
|
|
|
|
|
ListViewItem lvi = new ListViewItem();
|
|
|
|
|
lvi.Text = name;
|
|
|
|
|
lvi.SubItems.Add(shortValue);
|
|
|
|
|
if (longValue == null)
|
|
|
|
|
longValue = shortValue;
|
|
|
|
|
lvi.Tag = longValue;
|
|
|
|
|
lvwX509Fields.Items.Add(lvi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string PadText(string input)
|
2014-04-18 12:39:50 +02:00
|
|
|
|
{
|
2014-10-21 16:07:22 +02:00
|
|
|
|
string output = "";
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < input.Length; i += 2) {
|
|
|
|
|
if (output != "")
|
|
|
|
|
output += " ";
|
|
|
|
|
|
|
|
|
|
int len = 2;
|
|
|
|
|
if (input.Length - i < 2)
|
|
|
|
|
len = input.Length - i;
|
|
|
|
|
output += input.Substring(i, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowCertificatePrompt(X509Certificate2 certificate)
|
|
|
|
|
{
|
|
|
|
|
txtX509Issuer.Text = certificate.Issuer;
|
|
|
|
|
txtX509Subject.Text = certificate.Subject;
|
|
|
|
|
|
2014-10-23 04:23:22 +02:00
|
|
|
|
lvwX509Fields.Items.Clear();
|
|
|
|
|
|
2014-10-21 16:07:22 +02:00
|
|
|
|
AddCertificateField("Version", "V" + certificate.Version.ToString());
|
|
|
|
|
AddCertificateField("Serial number", certificate.SerialNumber);
|
|
|
|
|
AddCertificateField("Signature algorithm", certificate.SignatureAlgorithm.FriendlyName);
|
|
|
|
|
AddCertificateField("Valid from", certificate.NotBefore.ToString());
|
|
|
|
|
AddCertificateField("Valid to", certificate.NotAfter.ToString());
|
|
|
|
|
|
|
|
|
|
string pkey = BitConverter.ToString(certificate.PublicKey.EncodedKeyValue.RawData).Replace("-", " ");
|
|
|
|
|
AddCertificateField("Public key", certificate.PublicKey.Oid.FriendlyName + " (" + certificate.PublicKey.Key.KeySize + " bits)", pkey);
|
|
|
|
|
|
|
|
|
|
string thumbprint = PadText(certificate.Thumbprint);
|
|
|
|
|
AddCertificateField("Thumbprint", thumbprint);
|
|
|
|
|
|
|
|
|
|
tbcPages.SelectedTab = tabVerifyCertificate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnAddEndpoint_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EndpointInputBox eib = new EndpointInputBox();
|
|
|
|
|
|
|
|
|
|
if (eib.ShowDialog(this) == DialogResult.Cancel)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ListViewItem lvi = new ListViewItem();
|
2014-10-23 04:23:22 +02:00
|
|
|
|
lvi.Text = eib.txtInstanceName.Text;
|
|
|
|
|
|
|
|
|
|
if (eib.chkConnect.Checked) {
|
|
|
|
|
lvi.SubItems.Add(eib.txtHost.Text);
|
|
|
|
|
lvi.SubItems.Add(eib.txtPort.Text);
|
|
|
|
|
}
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
|
|
|
|
lvwEndpoints.Items.Add(lvi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lvwEndpoints_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
btnRemoveEndpoint.Enabled = lvwEndpoints.SelectedItems.Count > 0;
|
2017-10-16 14:43:09 +02:00
|
|
|
|
btnEditEndpoint.Enabled = lvwEndpoints.SelectedItems.Count > 0;
|
2014-10-21 16:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lvwX509Fields_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (lvwX509Fields.SelectedItems.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ListViewItem lvi = lvwX509Fields.SelectedItems[0];
|
|
|
|
|
|
2017-11-03 16:56:28 +01:00
|
|
|
|
txtX509Field.Text = Convert.ToString(lvi.Tag);
|
2014-10-21 16:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnRemoveEndpoint_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
while (lvwEndpoints.SelectedItems.Count > 0) {
|
|
|
|
|
lvwEndpoints.Items.Remove(lvwEndpoints.SelectedItems[0]);
|
|
|
|
|
}
|
2016-02-26 13:42:36 +01:00
|
|
|
|
}
|
2017-10-16 14:43:09 +02:00
|
|
|
|
|
|
|
|
|
private void chkRunServiceAsThisUser_CheckedChanged(object sender, EventArgs e)
|
2016-02-26 13:42:36 +01:00
|
|
|
|
{
|
2016-10-26 10:30:12 +02:00
|
|
|
|
txtUser.Enabled = !txtUser.Enabled;
|
|
|
|
|
if (!txtUser.Enabled)
|
2016-02-26 13:42:36 +01:00
|
|
|
|
txtUser.Text = Icinga2User;
|
|
|
|
|
}
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|
2017-10-16 14:43:09 +02:00
|
|
|
|
private void btnEditEndpoint_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ListViewItem lvi = lvwEndpoints.SelectedItems[0];
|
|
|
|
|
EndpointInputBox eib = new EndpointInputBox();
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|
2017-10-16 14:43:09 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|
2017-10-16 14:43:09 +02:00
|
|
|
|
if (eib.ShowDialog(this) == DialogResult.Cancel)
|
|
|
|
|
return;
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|
2017-10-16 14:43:09 +02:00
|
|
|
|
lvwEndpoints.Items.Remove(lvi);
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|
2017-10-16 14:43:09 +02:00
|
|
|
|
ListViewItem lvi2 = new ListViewItem();
|
|
|
|
|
lvi2.Text = eib.txtInstanceName.Text;
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|
2017-10-16 14:43:09 +02:00
|
|
|
|
if (eib.chkConnect.Checked) {
|
|
|
|
|
lvi2.SubItems.Add(eib.txtHost.Text);
|
|
|
|
|
lvi2.SubItems.Add(eib.txtPort.Text);
|
|
|
|
|
}
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|
2017-10-16 14:43:09 +02:00
|
|
|
|
lvwEndpoints.Items.Add(lvi2);
|
|
|
|
|
}
|
2018-03-18 16:19:15 +01:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2018-05-02 17:45:07 +02:00
|
|
|
|
|
2018-07-20 21:46:23 +02:00
|
|
|
|
private void SetupWizard_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.MinimumSize = this.Size;
|
|
|
|
|
this.MaximumSize = this.Size;
|
|
|
|
|
}
|
2019-07-31 13:35:42 +02:00
|
|
|
|
|
|
|
|
|
private void linkLabelDocs_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
linkLabelDocs.LinkVisited = true;
|
|
|
|
|
|
|
|
|
|
Process.Start("https://icinga.com/docs/icinga2/latest/");
|
|
|
|
|
}
|
2017-10-16 14:43:09 +02:00
|
|
|
|
}
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
2017-09-07 11:30:19 +02:00
|
|
|
|
|