Beispiel #1
0
        static bool SaveApplySettings(SQLLib sql, ServerSettings newsettings)
        {
            if (Certificates.CertificateExists(newsettings.UseCertificate, System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine) == false)
            {
                return(false);
            }

            if (newsettings.EMailPort < 1 || newsettings.EMailPort > 65535)
            {
                return(false);
            }

            if (newsettings.KeepEventLogDays < 0)
            {
                return(false);
            }
            if (newsettings.KeepNonPresentDisks < 0)
            {
                return(false);
            }
            if (newsettings.KeepReports < 0)
            {
                return(false);
            }
            if (newsettings.KeepChatLogs < 0)
            {
                return(false);
            }
            if (newsettings.KeepBitlockerRK < 0)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(newsettings.AdministratorName) == true)
            {
                newsettings.AdministratorName = "Administrator";
            }

            if (string.IsNullOrWhiteSpace(newsettings.AdminIPAddresses) == true)
            {
                newsettings.AdminIPAddresses = "";
            }
            else
            {
                foreach (string s in newsettings.AdminIPAddresses.Split(','))
                {
                    if (s.Contains("/") == false)
                    {
                        return(false);
                    }
                    IPNetwork ip;
                    if (IPNetwork.TryParse(s, out ip) == false)
                    {
                        return(false);
                    }
                }
            }

            Settings.UseCertificate        = newsettings.UseCertificate;
            Settings.KeepEventLogDays      = newsettings.KeepEventLogDays;
            Settings.KeepBitlockerRK       = newsettings.KeepBitlockerRK;
            Settings.KeepChatLogs          = newsettings.KeepChatLogs;
            Settings.KeepNonPresentDisks   = newsettings.KeepNonPresentDisks;
            Settings.EMailAdminTo          = newsettings.EMailAdminTo;
            Settings.EMailFrom             = newsettings.EMailFrom;
            Settings.EMailFromFriendly     = newsettings.EMailFromFriendly;
            Settings.EMailPort             = newsettings.EMailPort;
            Settings.EMailServer           = newsettings.EMailServer;
            Settings.EMailUsername         = newsettings.EMailUsername;
            Settings.EMailPassword         = newsettings.EMailPassword;
            Settings.EMailUseSSL           = newsettings.EMailUseSSL;
            Settings.EMailAdminScheduling  = newsettings.EMailAdminScheduling;
            Settings.EMailClientScheduling = newsettings.EMailClientScheduling;
            Settings.EMailAdminIsHTML      = newsettings.EMailAdminIsHTML;
            Settings.EMailClientIsHTML     = newsettings.EMailClientIsHTML;
            Settings.EMailAdminText        = newsettings.EMailAdminText;
            Settings.EMailClientText       = newsettings.EMailClientText;
            Settings.EMailAdminSubject     = newsettings.EMailAdminSubject;
            Settings.EMailClientSubject    = newsettings.EMailClientSubject;
            Settings.AdminIPAddresses      = newsettings.AdminIPAddresses;
            Settings.AdministratorName     = newsettings.AdministratorName;
            Settings.KeepReports           = newsettings.KeepReports;
            Settings.MessageDisclaimer     = newsettings.MessageDisclaimer;

            PutString(sql, "UseCertificate", Settings.UseCertificate);
            PutInt64(sql, "KeepEventLogDays", Settings.KeepEventLogDays);
            PutInt64(sql, "KeepNonPresentDisks", Settings.KeepNonPresentDisks);
            PutInt64(sql, "KeepBitlockerRK", Settings.KeepBitlockerRK);
            PutInt64(sql, "KeepReports", Settings.KeepReports);
            PutInt64(sql, "KeepChatLogs", Settings.KeepChatLogs);
            PutString(sql, "EMailAdminTo", Settings.EMailAdminTo);
            PutString(sql, "EMailFrom", Settings.EMailFrom);
            PutString(sql, "EMailFromFriendly", Settings.EMailFromFriendly);
            PutInt(sql, "EMailPort", Settings.EMailPort);
            PutString(sql, "EMailServer", Settings.EMailServer);
            PutString(sql, "EMailUsername", Settings.EMailUsername);
            PutString(sql, "EMailPassword", Settings.EMailPassword);
            PutBool(sql, "EMailUseSSL", Settings.EMailUseSSL);
            PutBool(sql, "EMailAdminIsHTML", Settings.EMailAdminIsHTML);
            PutBool(sql, "EMailClientIsHTML", Settings.EMailClientIsHTML);
            PutString(sql, "EMailAdminText", Settings.EMailAdminText);
            PutString(sql, "EMailClientText", Settings.EMailClientText);
            PutString(sql, "EMailAdminSubject", Settings.EMailAdminSubject);
            PutString(sql, "EMailClientSubject", Settings.EMailClientSubject);
            PutString(sql, "AdminIPAddresses", Settings.AdminIPAddresses);
            PutString(sql, "AdminstratorName", Settings.AdministratorName);
            PutString(sql, "MessageDisclaimer", Settings.MessageDisclaimer);
            PutString(sql, "EMailAdminSched", JsonConvert.SerializeObject(Settings.EMailAdminScheduling));
            PutString(sql, "EMailClientSched", JsonConvert.SerializeObject(Settings.EMailClientScheduling));
            return(true);
        }