2014-04-18 12:39:50 +02:00
|
|
|
|
using System;
|
2015-05-12 13:49:52 +02:00
|
|
|
|
using System.IO;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
using System.Windows.Forms;
|
2015-05-12 13:49:52 +02:00
|
|
|
|
using Microsoft.Win32;
|
2016-03-30 11:47:39 +02:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
|
|
|
|
namespace Icinga
|
|
|
|
|
{
|
|
|
|
|
static class Program
|
|
|
|
|
{
|
2016-02-26 13:42:36 +01:00
|
|
|
|
[DllImport("msi.dll", SetLastError = true)]
|
|
|
|
|
static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
|
|
|
|
|
static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
|
2016-03-30 11:47:39 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
public static string Icinga2InstallDir
|
2015-05-12 13:49:52 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-26 13:42:36 +01:00
|
|
|
|
StringBuilder szProduct;
|
2016-03-30 11:47:39 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
for (int index = 0; ; index++) {
|
|
|
|
|
szProduct = new StringBuilder(39);
|
|
|
|
|
if (MsiEnumProducts(index, szProduct) != 0)
|
|
|
|
|
break;
|
2016-03-30 11:47:39 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
int cbName = 128;
|
|
|
|
|
StringBuilder szName = new StringBuilder(cbName);
|
2016-03-30 11:47:39 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
if (MsiGetProductInfo(szProduct.ToString(), "ProductName", szName, ref cbName) != 0)
|
|
|
|
|
continue;
|
2016-03-30 11:47:39 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
if (szName.ToString() != "Icinga 2")
|
|
|
|
|
continue;
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
int cbLocation = 1024;
|
|
|
|
|
StringBuilder szLocation = new StringBuilder(cbLocation);
|
|
|
|
|
if (MsiGetProductInfo(szProduct.ToString(), "InstallLocation", szLocation, ref cbLocation) == 0)
|
|
|
|
|
return szLocation.ToString();
|
|
|
|
|
}
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
return "";
|
2015-05-12 13:49:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
public static string Icinga2DataDir
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\icinga2";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Icinga2User
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(Icinga2DataDir + "\\etc\\icinga2\\user"))
|
|
|
|
|
return "NT AUTHORITY\\NetworkService";
|
|
|
|
|
System.IO.StreamReader file = new System.IO.StreamReader(Icinga2DataDir + "\\etc\\icinga2\\user");
|
|
|
|
|
string line = file.ReadLine();
|
|
|
|
|
file.Close();
|
|
|
|
|
|
|
|
|
|
if (line != null)
|
|
|
|
|
return line;
|
|
|
|
|
else
|
|
|
|
|
return "NT AUTHORITY\\NetworkService";
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-01 11:40:01 +02:00
|
|
|
|
|
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
public static void FatalError(Form owner, string message)
|
2015-05-12 13:49:52 +02:00
|
|
|
|
{
|
2015-11-23 14:12:25 +01:00
|
|
|
|
MessageBox.Show(owner, message, "Icinga 2 Setup Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2015-05-12 13:49:52 +02:00
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-18 12:39:50 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
static void Main()
|
|
|
|
|
{
|
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
|
|
|
|
string installDir = Program.Icinga2InstallDir;
|
|
|
|
|
|
2016-02-26 13:42:36 +01:00
|
|
|
|
if (installDir == "") {
|
|
|
|
|
FatalError(null, "Icinga 2 does not seem to be installed properly.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
|
|
|
|
Form form;
|
|
|
|
|
|
2016-04-01 11:40:01 +02:00
|
|
|
|
if (File.Exists(Program.Icinga2DataDir + "\\etc\\icinga2\\features-enabled\\api.conf"))
|
2015-05-12 13:49:52 +02:00
|
|
|
|
form = new ServiceStatus();
|
|
|
|
|
else
|
|
|
|
|
form = new SetupWizard();
|
|
|
|
|
|
|
|
|
|
Application.Run(form);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|