void Test() { try { var cfg = Cfg(); var result = new WhmDnsUpdater(cfg.WhmHost, cfg.WhmPort, cfg.WhmUsername, cfg.WhmSecurityToken) .Update(HostnameToUpdate, IpToUpdate, 3600); Assert.True(result); } catch (Exception ex) { throw ex; } }
public ActionResult <string> Get(string authCode, string fromHost, string toIp, int?ttl = null) { IPAddress ip; try { if (!config.Value.RequestAuthCode.IsNullOrWhiteSpace()) { if (authCode.Trim() != config.Value.RequestAuthCode.Trim()) { throw new Exception("Unauthorized"); } } ip = ParseIpAddress(toIp); if (!Regex.IsMatch(fromHost, @".+\..+")) { throw new Exception("WhmHost is invalid"); } const int ttl_min = 300; if (ttl.HasValue && ttl.Value < ttl_min) { throw new Exception($"TTL is invalid, set to at least {ttl_min}"); } } catch (Exception ex) { return($"FAIL - {ex.Message}"); } try { var result = new WhmDnsUpdater(config.Value.WhmHost, config.Value.WhmPort, config.Value.WhmUsername, config.Value.WhmSecurityToken) .Update(fromHost, ip, ttl); return(result ? $"OK updated '{fromHost}' to '{toIp}'" : "FAIL"); } catch (Exception ex) { Logging.Logger.Error(ex, "Unexpected error updating '{FromHost}' to '{ToIp}'", fromHost, toIp); return("FAIL - internal error"); } }