Exemple #1
0
        //partially tested
        public void UpdateSoaRecord(string zoneName, string host, string primaryNsServer, string primaryPerson)
        {
            string recordId      = string.Empty;
            string recordContent = string.Empty;

            try
            {
                MySqlParameter ZoneName = new MySqlParameter("?Name", MySqlDbType.VarString);
                ZoneName.Value = zoneName;

                MySqlParameter RecordType = new MySqlParameter("?Type", MySqlDbType.VarString);
                RecordType.Value = ConvertDnsRecordTypeToString(DnsRecordType.SOA);

                IDataReader reader = ExecuteReader(
                    "SELECT id, content FROM records WHERE name = ?Name AND type = ?Type LIMIT 1"
                    , ZoneName
                    , RecordType
                    );

                if (reader.Read())
                {
                    recordId      = reader["id"].ToString();
                    recordContent = reader["content"].ToString();
                }

                reader.Close();


                if (string.IsNullOrEmpty(recordId))
                {
                    throw new ArgumentOutOfRangeException(string.Format("Not SOA record for Power DNS zone '{0}'", zoneName));
                }

                PowerDnsSOARecordData soaData = PowerDnsSOARecordData.FromString(recordContent);

                soaData.PrimaryNameServer = primaryNsServer;
                soaData.HostMaster        = primaryPerson;
                soaData.Refresh           = SOARefreshInterval;
                soaData.Retry             = SOARetryDelay;
                soaData.DefaultTTL        = SOAMinimumTTL;
                soaData.Expire            = SOAExpireLimit;

                soaData.IncrementSerial(
                    GetDomainNotifiedSerial(zoneName)
                    );

                UpdateRecord(recordId, soaData.ToString());
            }
            catch (Exception ex)
            {
                Log.WriteError(String.Format("Error updating SOA record for '{0}' Power DNS zone", zoneName), ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates SOA record of the corresponding zone
        /// </summary>
        /// <param name="zoneName">Domain name in Power DNS database</param>
        protected void PDNSUpdateSoaRecord(string zoneName)
        {
            try
            {
                string domainId = GetDomainId(zoneName);
                if (string.IsNullOrEmpty(domainId))
                {
                    throw new ArgumentOutOfRangeException(string.Format("Power DNS zone '{0}' does not exist.", domainId));
                }


                MySqlParameter DomainId = new MySqlParameter("?DomainId", MySqlDbType.Int32);
                DomainId.Value = domainId;

                IDataReader reader = ExecuteReader(
                    "SELECT id, content FROM records WHERE domain_id = ?DomainId AND type='SOA' LIMIT 1"
                    , DomainId
                    );

                string
                    recordId      = string.Empty,
                    recordContent = string.Empty;

                if (reader.Read())
                {
                    recordId      = reader["id"].ToString();
                    recordContent = reader["content"].ToString();
                }

                reader.Close();

                if (string.IsNullOrEmpty(recordId))
                {
                    throw new ArgumentOutOfRangeException(string.Format("SOA record for Power DNS zone '{0}' not found", zoneName));
                }


                PowerDnsSOARecordData data = PowerDnsSOARecordData.FromString(recordContent);

                data.Refresh    = SOARefreshInterval;
                data.Retry      = SOARetryDelay;
                data.DefaultTTL = SOAMinimumTTL;
                data.Expire     = SOAExpireLimit;

                data.IncrementSerial(GetDomainNotifiedSerial(zoneName));

                UpdateRecord(recordId, data.ToString());
            }
            catch (Exception ex)
            {
                Log.WriteError(String.Format("Error updating SOA record for '{0}' Power DNS zone", zoneName), ex);
            }
        }