public Credentials(long id, string p_Email, DomainDns domainDns) { DomainDns = domainDns; Email = p_Email; PlainPassword = DefaultRNG.GetPassword(25, ASCII.Strings.SafeUrlOptions); var dom = new DynDnsDomain() { ID = id, Username = domainDns.Name, }; dom.CreatePasswordHash(PlainPassword); DynDnsDomain = dom; }
/// <summary>Updates the domain entry address.</summary> /// <param name="dom">The domain.</param> /// <param name="address">The address.</param> /// <returns></returns> /// <exception cref="System.Exception"> /// </exception> public string UpdateDomainEntryAddress(DynDnsDomain dom, IPAddress address) { List <string> errors = new List <string>(); int updates = 0; var entries = DomainEntries.GetStructs(Search.FieldLike(nameof(DomainDns.NameAndTTL), dom.Username + "\t%")); foreach (var entry in entries) { bool update = IsSameDomainType(entry, address) && (entry.DomainText != address.ToString()); if (update) { DomainDns domainEntry = entry; if (domainEntry.DomainText != address.ToString()) { if (domainEntry.Status != "ok") { throw new Exception(string.Format("Cannot update domain {0} status {1}", domainEntry.Name, domainEntry.Status)); } Domain domain = Domains[domainEntry.DomainID]; if (domain.Status != "ok") { throw new Exception(string.Format("Cannot update domain {0} status {1}", domain.Name, domain.Status)); } domainEntry.DomainText = address.ToString(); domainEntry.Status = "tochange"; try { DomainEntries.Update(domainEntry); } catch (Exception ex) { string msg = string.Format("Cannot update domain {0}", domainEntry); this.LogWarning(ex, msg); errors.Add(msg); continue; } domain.Status = "tochange"; Domains.Update(domain); this.LogInfo("Update {0}", domainEntry); } updates++; } } if (errors.Count == 0) { return($"{updates} datasets updated."); } return($"{updates} datasets updated - {errors.Count} Errors.\n" + errors.JoinNewLine()); }
/// <summary> /// Determines whether [is same domain type] [the specified domain DNS]. /// </summary> /// <param name="domainDns">The domain DNS.</param> /// <param name="address">The address.</param> /// <returns><c>true</c> if [is same domain type] [the specified domain DNS]; otherwise, <c>false</c>.</returns> public bool IsSameDomainType(DomainDns domainDns, IPAddress address) { if (domainDns.DomainClass != "IN") { return(false); } if ((domainDns.DomainType == "A") && (address.AddressFamily == AddressFamily.InterNetwork)) { return(true); } if ((domainDns.DomainType == "AAAA") && (address.AddressFamily == AddressFamily.InterNetworkV6)) { return(true); } return(false); }
private void ImscpDeleteDomainDns(DomainDns todelete) { this.LogInfo("<red>Deleted<default> domain {0}", todelete); todelete.Status = "todelete"; imscpDomainDns.Update(todelete); }
private void SyncFromInternetX(AutodnsRecordList zones) { foreach (AutodnsRecordItem item in zones.Items) { this.LogDebug("Sync {0}", item); autodnsCache[item.Zone] = item; string domainName = item.Zone; if (!imscpDomain.TryGetStruct(nameof(Domain.Name), domainName, out Domain domain)) { this.LogInfo("InternetX Domain <red>{0}<default> is not present in <red>imscp<default>!", domainName); continue; } var oldDoms = imscpDomainDns.GetStructs( Search.FieldEquals(nameof(DomainDns.DomainID), domain.ID) & Search.FieldEquals(nameof(DomainDns.DomainClass), "IN")); bool updated = false; foreach (DnsResourceRecord record in item.Records) { string name = record.Name; switch (record.Name) { case "www": continue; } if (name == null) { name = ""; } else { name = name + "."; } if (name.Contains("*")) { name = name.Replace("*", "wildcard"); } string nameAndTTL = name + domainName + ".\t" + record.TTL; string domainText; switch (record.Type) { case "A": case "AAAA": case "CNAME": case "SPF": case "TXT": case "NS": domainText = record.Value; break; case "SRV": case "MX": domainText = Math.Max(0, record.Pref) + " " + record.Value; break; default: throw new NotImplementedException(); } DomainDns domainDns = oldDoms.SingleOrDefault(d => d.NameAndTTL == nameAndTTL && d.DomainType == record.Type && d.DomainText == domainText); if (domainDns.ID == 0) { //create new domainDns = new DomainDns() { //dont care ID = 0, AliasID = 0, OwnedBy = "custom_dns_feature", //fixed DomainClass = "IN", DomainID = (int)domain.ID, //data NameAndTTL = nameAndTTL, DomainType = record.Type, DomainText = domainText, Status = "tochange", }; this.LogInfo("New <green>{0}<default>.", domainDns); imscpDomainDns.Insert(domainDns); updated = true; continue; } else { oldDoms.Remove(domainDns); } } foreach (var dom in oldDoms) { var copy = dom; copy.Status = "todelete"; updated = true; this.LogInfo("Deleted <red>{0}<default>.", copy); imscpDomainDns.Replace(copy); } if (updated) { domain.Status = "tochange"; imscpDomain.Update(domain); } } }