Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds zone in Power DNS domains table and creates a SOA record for it.
        /// </summary>
        /// <param name="zoneName">Domain name in Power DNS database.</param>
        /// <param name="zoneType"></param>
        /// <param name="nameServers"></param>
        protected void PDNSAddZone(string zoneName, string zoneType, string[] nameServers)
        {
            string domainId = AddDomainAndReturnDomainId(zoneName, zoneType);

            if (string.IsNullOrEmpty(domainId))
            {
                throw new ArgumentOutOfRangeException(string.Format("Unable to add Power DNS zone '{0}'.", zoneName));
            }

            //create SOA record
            PowerDnsSOARecordData data = new PowerDnsSOARecordData();

            data.DefaultTTL = SOAMinimumTTL;
            data.Expire     = SOAExpireLimit;
            data.Refresh    = SOARefreshInterval;
            data.Retry      = SOARetryDelay;
            data.Serial     = DateTime.Now.ToString("yyyyMMdd") + "01";

            //add SOA record
            AddRecord(
                domainId
                , zoneName
                , data.ToString()
                , ConvertDnsRecordTypeToString(DnsRecordType.SOA)
                , GetDefaultRecordTTL(DnsRecordType.SOA)
                , "0"
                );


            //add NS records for secondary servers
            foreach (string server in nameServers)
            {
                AddRecord(
                    domainId
                    , zoneName
                    , server
                    , ConvertDnsRecordTypeToString(DnsRecordType.NS)
                    , GetDefaultRecordTTL(DnsRecordType.NS)
                    , "0"
                    );
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds zone in Power DNS domains table and creates a SOA record for it.
        /// </summary>
        /// <param name="zoneName">Domain name in Power DNS database.</param>
        /// <param name="zoneType"></param>
        /// <param name="nameServers"></param>
        protected void PDNSAddZone(string zoneName, string zoneType, string[] nameServers)
        {
            string domainId = AddDomainAndReturnDomainId(zoneName, zoneType);
            if (string.IsNullOrEmpty(domainId))
                throw new ArgumentOutOfRangeException(string.Format("Unable to add Power DNS zone '{0}'.", zoneName));

            //create SOA record
            PowerDnsSOARecordData data = new PowerDnsSOARecordData();

            data.DefaultTTL = SOAMinimumTTL;
            data.Expire = SOAExpireLimit;
            data.Refresh = SOARefreshInterval;
            data.Retry = SOARetryDelay;
            data.Serial = DateTime.Now.ToString("yyyyMMdd") + "01";

            //add SOA record
            AddRecord(
                  domainId
                , zoneName
                , data.ToString()
                , ConvertDnsRecordTypeToString(DnsRecordType.SOA)
                , GetDefaultRecordTTL(DnsRecordType.SOA)
                , "0"
            );


            //add NS records for secondary servers
            foreach (string server in nameServers)
            {
                AddRecord(
                      domainId
                    , zoneName
                    , server
                    , ConvertDnsRecordTypeToString(DnsRecordType.NS)
                    , GetDefaultRecordTTL(DnsRecordType.NS)
                    , "0"
                );
            }
        }