2014-04-18 12:39:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Runtime.InteropServices;
|
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 Microsoft.Win32;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
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;
|
|
|
|
|
|
2014-10-31 13:08:09 +01:00
|
|
|
|
public SetupWizard()
|
2014-04-18 12:39:50 +02:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
txtInstanceName.Text = Icinga2InstanceName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FatalError(string message)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Warning(string message)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string Icinga2InstallDir
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Icinga Development Team\\ICINGA2");
|
|
|
|
|
|
|
|
|
|
if (rk == null)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
return (string)rk.GetValue("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string Icinga2InstanceName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
IPGlobalProperties props = IPGlobalProperties.GetIPGlobalProperties();
|
|
|
|
|
|
|
|
|
|
string fqdn = props.HostName;
|
|
|
|
|
|
|
|
|
|
if (props.DomainName != "")
|
|
|
|
|
fqdn += "." + props.DomainName;
|
|
|
|
|
|
|
|
|
|
return fqdn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
host = lvi.SubItems[1].Text;
|
|
|
|
|
port = lvi.SubItems[2].Text;
|
|
|
|
|
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 {
|
|
|
|
|
fp = File.Open(Icinga2InstallDir + 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)) {
|
|
|
|
|
proc.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs args) {
|
|
|
|
|
result += args.Data + "\r\n";
|
|
|
|
|
};
|
|
|
|
|
proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs args) {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
string pathPrefix = Icinga2InstallDir + "\\etc\\icinga2\\pki\\" + txtInstanceName.Text;
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
string output;
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
|
|
|
|
if (!File.Exists(pathPrefix + ".crt")) {
|
2014-10-22 09:34:09 +02:00
|
|
|
|
if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
"pki new-cert --cn \"" + txtInstanceName.Text + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\"",
|
|
|
|
|
out output)) {
|
2014-10-22 09:34:09 +02:00
|
|
|
|
ShowErrorText(output);
|
|
|
|
|
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
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
"pki save-cert --host \"" + host + "\" --port \"" + port + "\" --key \"" + pathPrefix + ".key\" --cert \"" + pathPrefix + ".crt\" --trustedcert \"" + _TrustedFile + "\"",
|
|
|
|
|
out output)) {
|
2014-10-22 09:34:09 +02:00
|
|
|
|
ShowErrorText(output);
|
|
|
|
|
return;
|
2014-10-21 16:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetRetrievalStatus(100);
|
2014-10-22 09:34:09 +02:00
|
|
|
|
|
|
|
|
|
X509Certificate2 cert = new X509Certificate2(_TrustedFile);
|
2014-10-21 16:07:22 +02:00
|
|
|
|
Invoke((MethodInvoker)delegate { ShowCertificatePrompt(cert); });
|
|
|
|
|
}
|
|
|
|
|
|
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 = "";
|
|
|
|
|
|
|
|
|
|
if (rdoNewMaster.Checked)
|
|
|
|
|
args += " --master";
|
|
|
|
|
|
|
|
|
|
Invoke((MethodInvoker)delegate {
|
2014-10-23 04:23:22 +02:00
|
|
|
|
string master_host, master_port;
|
|
|
|
|
GetMasterHostPort(out master_host, out master_port);
|
|
|
|
|
|
|
|
|
|
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) {
|
2014-10-23 04:23:22 +02:00
|
|
|
|
args += " --endpoint " + lvi.SubItems[0].Text;
|
|
|
|
|
|
|
|
|
|
if (lvi.SubItems.Count > 1)
|
|
|
|
|
args += "," + lvi.SubItems[1].Text + "," + lvi.SubItems[2].Text;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
2014-10-22 09:34:09 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (rdoListener.Checked)
|
|
|
|
|
args += " --listen ::," + txtListenerPort.Text;
|
|
|
|
|
|
2015-03-27 14:11:21 +01:00
|
|
|
|
if (chkAcceptConfig.Checked)
|
|
|
|
|
args += " --accept-config";
|
|
|
|
|
|
|
|
|
|
if (chkAcceptCommands.Checked)
|
|
|
|
|
args += " --accept-commands";
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
args += " --ticket " + txtTicket.Text;
|
|
|
|
|
args += " --trustedcert " + _TrustedFile;
|
|
|
|
|
args += " --cn " + txtInstanceName.Text;
|
2014-11-18 16:19:32 +01:00
|
|
|
|
args += " --zone " + txtInstanceName.Text;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
if (!RunProcess(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)) {
|
2014-10-22 09:34:09 +02:00
|
|
|
|
ShowErrorText(output);
|
|
|
|
|
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...");
|
2014-04-18 12:39:50 +02:00
|
|
|
|
DirectoryInfo di = new DirectoryInfo(Icinga2InstallDir);
|
|
|
|
|
DirectorySecurity ds = di.GetAccessControl();
|
|
|
|
|
FileSystemAccessRule rule = new FileSystemAccessRule("NT AUTHORITY\\NetworkService",
|
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);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
ds.AddAccessRule(rule);
|
|
|
|
|
di.SetAccessControl(ds);
|
|
|
|
|
|
2014-04-20 15:35:51 +02:00
|
|
|
|
SetConfigureStatus(75, "Installing the Icinga 2 service...");
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
"--scm-uninstall",
|
|
|
|
|
out output);
|
2014-10-21 16:07:22 +02:00
|
|
|
|
|
2014-10-23 04:23:22 +02:00
|
|
|
|
if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
"daemon --validate",
|
|
|
|
|
out output)) {
|
2014-10-23 04:23:22 +02:00
|
|
|
|
ShowErrorText(output);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
if (!RunProcess(Icinga2InstallDir + "\\sbin\\icinga2.exe",
|
2014-11-13 20:18:41 +01:00
|
|
|
|
"--scm-install daemon",
|
|
|
|
|
out output)) {
|
2014-10-22 09:34:09 +02:00
|
|
|
|
ShowErrorText(output);
|
|
|
|
|
return;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetConfigureStatus(100, "Finished.");
|
|
|
|
|
|
|
|
|
|
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 AgentWizard_Shown(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string installDir = Icinga2InstallDir;
|
|
|
|
|
|
|
|
|
|
if (installDir == "")
|
|
|
|
|
FatalError("Icinga 2 does not seem to be installed properly.");
|
|
|
|
|
|
|
|
|
|
/* TODO: This is something the NSIS installer should do */
|
2014-10-22 22:02:31 +02:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\etc\\icinga2\\pki");
|
2014-04-18 12:39:50 +02:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\cache\\icinga2");
|
2014-10-22 21:49:41 +02:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\pki");
|
2014-04-18 12:39:50 +02:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\agent\\inventory");
|
2014-11-18 18:33:51 +01:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\api\\config");
|
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\api\\log");
|
2015-02-10 09:02:31 +01:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\lib\\icinga2\\api\\zones");
|
2014-04-18 12:39:50 +02:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\log\\icinga2\\compat\\archive");
|
2015-02-10 09:31:41 +01:00
|
|
|
|
Directory.CreateDirectory(installDir + "\\var\\log\\icinga2\\crash");
|
2014-04-18 12:39:50 +02:00
|
|
|
|
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)
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 09:34:09 +02:00
|
|
|
|
if (txtTicket.Text.Length == 0) {
|
|
|
|
|
Warning("Please enter an agent ticket.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 04:23:22 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rdoListener.Checked && (txtListenerPort.Text == "")) {
|
|
|
|
|
Warning("You need to specify a listener port.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*if (tbcPages.SelectedTab == tabParameters &&
|
2014-11-13 20:18:41 +01:00
|
|
|
|
!File.Exists(Icinga2InstallDir + "\\etc\\icinga2\\pki\\agent\\agent.crt")) {
|
2014-04-18 12:39:50 +02:00
|
|
|
|
byte[] bytes = Convert.FromBase64String(txtBundle.Text);
|
|
|
|
|
MemoryStream ms = new MemoryStream(bytes);
|
|
|
|
|
GZipStream gz = new GZipStream(ms, CompressionMode.Decompress);
|
|
|
|
|
MemoryStream ms2 = new MemoryStream();
|
2014-04-18 21:16:26 +02:00
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[512];
|
|
|
|
|
int rc;
|
|
|
|
|
while ((rc = gz.Read(buffer, 0, buffer.Length)) > 0)
|
|
|
|
|
ms2.Write(buffer, 0, rc);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
ms2.Position = 0;
|
|
|
|
|
TarReader tr = new TarReader(ms2);
|
|
|
|
|
tr.ReadToEnd(Icinga2InstallDir + "\\etc\\icinga2\\pki\\agent");
|
2014-10-21 16:07:22 +02:00
|
|
|
|
}*/
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
|
|
|
|
if (tbcPages.SelectedTab == tabConfigure) {
|
|
|
|
|
Thread thread = new Thread(ConfigureService);
|
|
|
|
|
thread.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RadioMaster_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-21 16:07:22 +02:00
|
|
|
|
lvwEndpoints.Enabled = !rdoNewMaster.Checked;
|
|
|
|
|
btnAddEndpoint.Enabled = !rdoNewMaster.Checked;
|
|
|
|
|
btnRemoveEndpoint.Enabled = !rdoNewMaster.Checked && lvwEndpoints.SelectedItems.Count > 0;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lvwX509Fields_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (lvwX509Fields.SelectedItems.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ListViewItem lvi = lvwX509Fields.SelectedItems[0];
|
|
|
|
|
|
|
|
|
|
txtX509Field.Text = (string)lvi.Tag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnRemoveEndpoint_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
while (lvwEndpoints.SelectedItems.Count > 0) {
|
|
|
|
|
lvwEndpoints.Items.Remove(lvwEndpoints.SelectedItems[0]);
|
|
|
|
|
}
|
2015-03-27 14:11:21 +01:00
|
|
|
|
}
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|