Example #1
0
        private void LoadConfig()
        {
            IniReader config = IniReader.FromLocation(RootLocation.AllUserConfig);

            this.LogInfo("Loading {0}", config);
            imscpConfig = config.ReadStruct <ImscpConfig>("Imscp", true);

            if (imscpConfig.Hostname == null || imscpConfig.Hostname.EndsWith("."))
            {
                throw new Exception(string.Format("Invalid hostname {0}", imscpConfig.Hostname));
            }
            foreach (string section in config.ReadSection("InternetX", true))
            {
                this.LogDebug("Loading InternetX account <cyan>{0}", section);
                InternetXConfig internetXConfig = config.ReadStruct <InternetXConfig>(section, true);
                autodnsAccounts.Add(new Autodns(internetXConfig));
                this.LogInfo("Loaded InternetX account <green>{0}", section);
            }

            var cs      = new ConnectionString("mysql", imscpConfig.UserName, imscpConfig.Password, imscpConfig.Database);
            var storage = new MySqlStorage(cs, DbConnectionOptions.AllowUnsafeConnections);

            imscp = storage.GetDatabase("imscp", false);

            imscpDomain = new ReadCachedTable <Domain>(imscp.GetTable <Domain>());
            this.LogDebug("Loaded {0}", imscpDomain);
            imscpSubdomain = new ReadCachedTable <Subdomain>(imscp.GetTable <Subdomain>());
            this.LogDebug("Loaded {0}", imscpSubdomain);
            imscpDomainDns = new ReadCachedTable <DomainDns>(imscp.GetTable <DomainDns>());
            this.LogDebug("Loaded {0}", imscpDomainDns);
            imscpAdmins = new ReadCachedTable <Admin>(imscp.GetTable <Admin>());
            this.LogDebug("Loaded {0}", imscpAdmins);

            #region MAIL
            string server = config.ReadSetting("MAIL", "SERVER");
            m_MailSender = config.ReadSetting("MAIL", "SENDER");
            if (string.IsNullOrEmpty(server))
            {
                server = "localhost";
            }
            m_SmtpClient = new SmtpClient(server);
            string username = config.ReadSetting("MAIL", "USERNAME");
            string password = config.ReadSetting("MAIL", "PASSWORD");
            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                m_SmtpClient.Credentials = new NetworkCredential(username, password);
            }
            m_SmtpClient.Send(m_MailSender, "*****@*****.**", "CaveSystems AutoDNS", "AutoDNS restarted.");
            #endregion
        }