Пример #1
0
        /// <summary>
        /// GetCompterInformations method informations
        /// </summary>
        public static ADFSServerHost GetCompterInformations(string fqdn)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.GetComputerInformations(fqdn, true));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #2
0
        /// <summary>
        /// RemoveFirewallRules method implementation
        /// </summary>
        public static void RemoveFirewallRules()
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    client.RemoveFirewallRules();
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #3
0
        /// <summary>
        /// BroadcastNotification method implementation
        /// </summary>
        public static void BroadcastNotification(MFAConfig config, NotificationsKind kind, string message, bool local = true, bool dispatch = true)
        {
            WebAdminClient manager = new WebAdminClient();

            try
            {
                manager.Initialize();
                IWebAdminServices client = manager.Open();
                try
                {
                    client.BroadcastNotification(GetServers(config), GetConfig(config), kind, message, local, dispatch);
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #4
0
        /// <summary>
        /// CreateADFSCertificate method implementation
        /// </summary>
        public static bool CreateADFSCertificate(MFAConfig config, string subject, bool issigning, int years)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.CreateADFSCertificate(GetServers(config), subject, issigning, years));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #5
0
        /// <summary>
        /// AddFirewallRules method implmentation
        /// </summary>
        public static void AddFirewallRules(string computers)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    client.AddFirewallRules(computers);
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #6
0
        /// <summary>
        /// GetCertificate method implementation
        /// </summary>
        public static bool CertificateExists(string thumbprint, StoreLocation location)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.CertificateExists(thumbprint, (byte)location));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #7
0
        /// <summary>
        /// GetCompterInformations method informations
        /// </summary>
        public static ADFSNodeInformation GetNodeformations(RegistryVersion reg, string fqdn)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.GetNodeInformations(reg, fqdn, true));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #8
0
        /// <summary>
        /// UpdateCertificatesACL method implementation
        /// </summary>
        public static bool UpdateCertificatesACL(KeyMgtOptions options)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.UpdateCertificatesACL(options));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #9
0
        /// <summary>
        /// CleanOrphanedPrivateKeys method implementation
        /// </summary>
        public static int CleanOrphanedPrivateKeys(byte option, int delay)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.CleanOrphanedPrivateKeys(option, delay));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #10
0
        /// <summary>
        /// NewMFASystemAESCngKey method implementation
        /// </summary>
        public static bool NewMFASystemAESCngKey(MFAConfig config, bool deployonly = false, bool deleteonly = false)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.NewMFASystemAESCngKey(GetServers(config), deployonly, deleteonly));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #11
0
        /// <summary>
        /// ExistsMFASystemAESCngKeys method implementation
        /// </summary>
        public static bool ExistsMFASystemAESCngKeys()
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.ExistsMFASystemAESCngKeys());
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #12
0
        /// <summary>
        /// InitSecurityFile method implementation
        /// </summary>
        protected void InitSecurityFile()
        {
            string         fqdn    = Dns.GetHostEntry("localhost").HostName;
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                MFAConfig         config = CFGReaderUtilities.ReadConfiguration();
                IWebAdminServices client = manager.Open();
                try
                {
                    SIDs.Clear();
                    SIDs.Assign(client.GetSIDsInformations(GetServers(config)));
                    SIDs.InternalUpdateDirectoryACLs(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + Path.DirectorySeparatorChar + "MFA");
                }
                catch (Exception ex)
                {
                    Log.WriteEntry(string.Format("Error on WebAdminService Service GetSIDsInformations method : {0} / {1}.", fqdn, ex.Message), EventLogEntryType.Error, 2010);
                    SIDs.Assign(new SIDsParametersRecord()
                    {
                        Loaded = false
                    });
                }
                finally
                {
                    manager.Close(client);
                }
            }
            catch (Exception e)
            {
                Log.WriteEntry(string.Format("Error on WebAdminService Service GetSIDsInformations method : {0} / {1}.", fqdn, e.Message), EventLogEntryType.Error, 2010);
            }
            finally
            {
                manager.UnInitialize();
            }
            return;
        }
Пример #13
0
        /// <summary>
        /// GetNodeType method informations
        /// </summary>
        public static string GetNodeType(string fqdn)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.GetNodeType(fqdn, true));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #14
0
        /// <summary>
        /// UpdateDirectoriesACL method implementation
        /// </summary>
        public static void UpdateDirectoriesACL()
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    client.UpdateDirectoriesACL(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + Path.DirectorySeparatorChar + "MFA");
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #15
0
        /// <summary>
        /// GetAllComputerInformations method informations
        /// </summary>
        public static Dictionary <string, ADFSServerHost> GetAllComputerInformations(Dictionary <string, bool> servers)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.GetAllComputerInformations(servers));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #16
0
        /// <summary>
        /// CreateRSACertificateForSQLEncryption method implementation
        /// </summary>
        public static string CreateRSACertificateForSQLEncryption(MFAConfig config, string subject, int years)
        {
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.CreateRSACertificateForSQLEncryption(GetServers(config), subject, years));
                }
                finally
                {
                    manager.Close(client);
                }
            }
            finally
            {
                manager.UnInitialize();
            }
        }
Пример #17
0
        /// <summary>
        /// GetSIDsInformations method implmentation
        /// </summary>
        public static SIDsParametersRecord GetSIDsInformations(MFAConfig config)
        {
            string         fqdn    = Dns.GetHostEntry("localhost").HostName;
            WebAdminClient manager = new WebAdminClient();

            manager.Initialize();
            try
            {
                IWebAdminServices client = manager.Open();
                try
                {
                    return(client.GetSIDsInformations(GetServers(config)));
                }
                catch (Exception ex)
                {
                    Log.WriteEntry(string.Format("Error on WebAdminService Service GetSIDsInformations method : {0} / {1}.", fqdn, ex.Message), EventLogEntryType.Error, 2010);
                    return(new SIDsParametersRecord()
                    {
                        Loaded = false
                    });
                }
                finally
                {
                    manager.Close(client);
                }
            }
            catch (Exception e)
            {
                Log.WriteEntry(string.Format("Error on WebAdminService Service GetSIDsInformations method : {0} / {1}.", fqdn, e.Message), EventLogEntryType.Error, 2010);
            }
            finally
            {
                manager.UnInitialize();
            }
            return(null);
        }
        /// <summary>
        /// ExportMailTemplates method implementation
        /// </summary>
        internal bool ExportMailTemplates(Dictionary <string, bool> servers, byte[] config, int lcid, Dictionary <string, string> templates, bool dispatch = true)
        {
            char   sep      = Path.DirectorySeparatorChar;
            string htmlpath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + sep + "MFA" + sep + "MailTemplates" + sep + lcid.ToString();

            try
            {
                if (!Directory.Exists(htmlpath))
                {
                    Directory.CreateDirectory(htmlpath);
                }

                foreach (var item in templates)
                {
                    if (!File.Exists(htmlpath + sep + item.Key))
                    {
                        File.WriteAllText(htmlpath + sep + item.Key, item.Value, Encoding.UTF8);
                    }
                }

                if (dispatch)
                {
                    string        fqdn        = Dns.GetHostEntry("localhost").HostName;
                    List <string> servernames = (from server in servers
                                                 where (server.Key.ToLower() != fqdn.ToLower())
                                                 select server.Key.ToLower()).ToList <string>();

                    foreach (string srv in servernames)
                    {
                        WebAdminClient manager = new WebAdminClient();
                        manager.Initialize(srv);
                        try
                        {
                            IWebAdminServices client = manager.Open();
                            try
                            {
                                client.ExportMailTemplates(servers, config, lcid, templates, false);
                            }
                            catch (Exception e)
                            {
                                _log.WriteEntry(string.Format("Error on WebAdminService Service ExportMailTemplates method : {0} - {1} / {2}.", srv, lcid, e.Message), EventLogEntryType.Error, 2010);
                            }
                            finally
                            {
                                manager.Close(client);
                            }
                        }
                        catch (Exception e)
                        {
                            _log.WriteEntry(string.Format("Error on WebAdminService Service ExportMailTemplates method : {0} / {1}.", srv, e.Message), EventLogEntryType.Error, 2010);
                        }
                        finally
                        {
                            manager.UnInitialize();
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                _log.WriteEntry(string.Format("Error on WebAdminService Service ExportMailTemplates method : {0}.", e.Message), EventLogEntryType.Error, 2010);
                return(false);
            }
        }
        /// <summary>
        /// CreateRSACertificateForSQLEncryption method implementation
        /// </summary>
        internal string CreateRSACertificateForSQLEncryption(Dictionary <string, bool> servers, string subject, int years)
        {
            SIDs.Initialize();

            string thumbprint = null;

            try
            {
                string           strcert = string.Empty;
                X509Certificate2 cert    = null;
                try
                {
                    cert = Certs.CreateRSACertificateForSQLEncryption(subject, years, out strcert);
                    if (cert == null)
                    {
                        return(null);
                    }
                    else
                    {
                        thumbprint = cert.Thumbprint;
                    }
                }
                finally
                {
                    cert.Reset();
                }

                SIDs.internalUpdateCertificatesACLs(KeyMgtOptions.MFACerts);

                string        fqdn        = Dns.GetHostEntry("localhost").HostName;
                List <string> servernames = (from server in servers
                                             where (server.Key.ToLower() != fqdn.ToLower())
                                             select server.Key.ToLower()).ToList <string>();
                foreach (string srv in servernames)
                {
                    WebAdminClient manager = new WebAdminClient();
                    manager.Initialize(srv);
                    try
                    {
                        IWebAdminServices client = manager.Open();
                        try
                        {
                            client.PushCertificate(strcert);
                        }
                        finally
                        {
                            manager.Close(client);
                        }
                    }
                    catch (Exception e)
                    {
                        _log.WriteEntry(string.Format("Error on WebAdminService Service CreateRSACertificateForSQLEncryption method : {0} / {1}.", srv, e.Message), EventLogEntryType.Error, 2010);
                    }
                    finally
                    {
                        manager.UnInitialize();
                    }
                }
            }
            catch (Exception e)
            {
                _log.WriteEntry(string.Format("Error on WebAdminService Service CreateRSACertificateForSQLEncryption method : {0}.", e.Message), EventLogEntryType.Error, 2010);
                throw e;
            }
            return(thumbprint);
        }
        /// <summary>
        /// GetComputerInformations method implementation
        /// </summary>
        internal ADFSServerHost GetComputerInformations(string servername, bool dispatch = true)
        {
            string fqdn = Dns.GetHostEntry("localhost").HostName.ToLower();

            if (fqdn.ToLower().Equals(servername.ToLower()))
            {
                RegistryVersion     reg      = new RegistryVersion();
                string              nodetype = GetLocalNodeType();
                ADFSNodeInformation node     = GetLocalNodeInformations(reg, fqdn);
                node.NodeType = nodetype;
                return(new ADFSServerHost()
                {
                    FQDN = fqdn,
                    BehaviorLevel = node.BehaviorLevel,
                    HeartbeatTmeStamp = node.HeartbeatTmeStamp,
                    NodeType = node.NodeType,
                    CurrentVersion = reg.CurrentVersion,
                    CurrentBuild = reg.CurrentBuild,
                    InstallationType = reg.InstallationType,
                    ProductName = reg.ProductName,
                    CurrentMajorVersionNumber = reg.CurrentMajorVersionNumber,
                    CurrentMinorVersionNumber = reg.CurrentMinorVersionNumber
                });
            }
            else
            {
                if (dispatch)
                {
                    WebAdminClient manager = new WebAdminClient();
                    manager.Initialize(servername);
                    try
                    {
                        IWebAdminServices client = manager.Open();
                        try
                        {
                            return(client.GetComputerInformations(servername, false));
                        }
                        catch (CommunicationException nf)
                        {
                            _log.WriteEntry(nf.Message, EventLogEntryType.Error, 2010);
                            return(null);
                        }
                        finally
                        {
                            manager.Close(client);
                        }
                    }
                    catch (Exception e)
                    {
                        _log.WriteEntry(string.Format("Error on WebAdminService Service GetComputerInformations method : {0} / {1}.", servername, e.Message), EventLogEntryType.Error, 2010);
                        throw e;
                    }
                    finally
                    {
                        manager.UnInitialize();
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
        }
        /// <summary>
        /// BroadcastNotification method implementation
        /// </summary>
        public void BroadcastNotification(Dictionary <string, bool> servers, byte[] config, NotificationsKind kind, string message, bool local = true, bool dispatch = true, bool mustwrite = false)
        {
            try
            {
                if (local)
                {
                    switch (kind)
                    {
                    case NotificationsKind.ConfigurationReload:
                        if (!File.Exists(CFGUtilities.ConfigCacheFile))
                        {
                            mustwrite = true;
                        }
                        if (!File.Exists(SystemUtilities.SystemCacheFile))
                        {
                            mustwrite = true;
                        }
                        if (mustwrite)
                        {
                            WriteConfigurationToCache(config);
                        }
                        PushNotification(NotificationsKind.ConfigurationReload, message, null);
                        break;

                    case NotificationsKind.ConfigurationCreated:
                        WriteConfigurationToCache(config);
                        PushNotification(NotificationsKind.ConfigurationCreated, message, null);
                        break;

                    case NotificationsKind.ConfigurationDeleted:
                        DeleteConfigurationFromCache();
                        PushNotification(NotificationsKind.ConfigurationDeleted, message, null);
                        break;

                    case NotificationsKind.ServiceStatusInError:
                        PushNotification(NotificationsKind.ServiceStatusInError, message, "MGT");
                        break;

                    case NotificationsKind.ServiceStatusPending:
                        PushNotification(NotificationsKind.ServiceStatusPending, message, "MGT");
                        break;

                    case NotificationsKind.ServiceStatusRunning:
                        PushNotification(NotificationsKind.ServiceStatusRunning, message, "MGT");
                        break;

                    case NotificationsKind.ServiceStatusStopped:
                        PushNotification(NotificationsKind.ServiceStatusStopped, message, "MGT");
                        break;
                    }
                }
                if (dispatch)
                {
                    string        fqdn        = Dns.GetHostEntry("localhost").HostName;
                    List <string> servernames = (from server in servers
                                                 where (server.Key.ToLower() != fqdn.ToLower())
                                                 select server.Key.ToLower()).ToList <string>();

                    foreach (string srv in servernames)
                    {
                        WebAdminClient manager = new WebAdminClient();
                        manager.Initialize(srv);
                        try
                        {
                            IWebAdminServices client = manager.Open();
                            try
                            {
                                client.BroadcastNotification(servers, config, kind, message, true, false, true);
                            }
                            finally
                            {
                                manager.Close(client);
                            }
                        }
                        catch (Exception e)
                        {
                            _log.WriteEntry(string.Format("Error on WebAdminService Service BroadcastNotification method : {0} / {1}.", srv, e.Message), EventLogEntryType.Error, 2010);
                        }
                        finally
                        {
                            manager.UnInitialize();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.WriteEntry(string.Format("Error on WebAdminService Service BroadcastNotification method : {0}.", e.Message), EventLogEntryType.Error, 2010);
                throw e;
            }
        }