コード例 #1
1
ファイル: PointProvider.cs プロジェクト: rickparrish/PDDNS
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null) throw new ArgumentNullException("HC");
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");

            using (RMWebClient WC = new RMWebClient())
            {
                WC.ContentType = "application/xml";
                WC.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(HC.Username + ":" + HC.Password.GetPlainText()));
                WC.Headers["Accept"] = "application/xml";
                WC.UseDefaultCredentials = false;

                try
                {
                    string Url = "https://pointhq.com";
                    Url += "/zones/" + HC.ProviderSpecificSettings[HostConfig.POINT_ZONE_ID];
                    Url += "/records/" + HC.ProviderSpecificSettings[HostConfig.POINT_RECORD_ID];

                    string ResponseText = WC.UploadString(Url, "PUT", "<zone-record><data>" + ipAddress.ToString() + "</data><ttl type=\"integer\">60</ttl></zone-record>").Trim();
                    if (!ResponseText.Contains(ipAddress.ToString()))
                    {
                        HC.Disabled = true;
                        HC.DisabledReason = "Reason not known.";
                        HC.Save();

                        Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                    }
                }
                catch (WebException wex)
                {
                    HC.Disabled = true;
                    switch (((HttpWebResponse)wex.Response).StatusCode)
                    {
                        case HttpStatusCode.Forbidden: HC.DisabledReason = "Current user does not have access to requested resource."; break;
                        case HttpStatusCode.NotFound: HC.DisabledReason = "Record not found."; break;
                        default: HC.DisabledReason = "An unknown response code was received: \"" + ((HttpWebResponse)wex.Response).StatusCode + "\""; break;
                    }
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
                catch (Exception ex)
                {
                    HC.Disabled = true;
                    HC.DisabledReason = "Unhandled exception (" + ex.Message + ")";
                    HC.Save();

                    Logging.instance.LogException("Unable to update host \"" + HC.Hostname + "\"", ex);
                }
            }
        }
コード例 #2
0
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null)
            {
                throw new ArgumentNullException("HC");
            }
            if (ipAddress == null)
            {
                throw new ArgumentNullException("ipAddress");
            }

            using (RMWebClient WC = new RMWebClient())
            {
                WC.ContentType = "application/xml";
                WC.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(HC.Username + ":" + HC.Password.GetPlainText()));
                WC.Headers["Accept"]     = "application/xml";
                WC.UseDefaultCredentials = false;

                try
                {
                    string Url = "https://pointhq.com";
                    Url += "/zones/" + HC.ProviderSpecificSettings[HostConfig.POINT_ZONE_ID];
                    Url += "/records/" + HC.ProviderSpecificSettings[HostConfig.POINT_RECORD_ID];

                    string ResponseText = WC.UploadString(Url, "PUT", "<zone-record><data>" + ipAddress.ToString() + "</data><ttl type=\"integer\">60</ttl></zone-record>").Trim();
                    if (!ResponseText.Contains(ipAddress.ToString()))
                    {
                        HC.Disabled       = true;
                        HC.DisabledReason = "Reason not known.";
                        HC.Save();

                        Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                    }
                }
                catch (WebException wex)
                {
                    HC.Disabled = true;
                    switch (((HttpWebResponse)wex.Response).StatusCode)
                    {
                    case HttpStatusCode.Forbidden: HC.DisabledReason = "Current user does not have access to requested resource."; break;

                    case HttpStatusCode.NotFound: HC.DisabledReason = "Record not found."; break;

                    default: HC.DisabledReason = "An unknown response code was received: \"" + ((HttpWebResponse)wex.Response).StatusCode + "\""; break;
                    }
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
                catch (Exception ex)
                {
                    HC.Disabled       = true;
                    HC.DisabledReason = "Unhandled exception (" + ex.Message + ")";
                    HC.Save();

                    Logging.instance.LogException("Unable to update host \"" + HC.Hostname + "\"", ex);
                }
            }
        }
コード例 #3
0
        void cmdSave_Click(object sender, EventArgs e)
        {
            if (!Dialog.ValidateIsEmailAddress(txtEmailAddress))
            {
                return;
            }
            if (!Dialog.ValidateIsNotEmpty(txtAPIKey))
            {
                return;
            }

            HostConfig HC = new HostConfig(txtHostname.Text.Trim());

            HC.LastUpdateDate = DateTime.MinValue;
            HC.Password       = txtAPIKey.SecureText.GetSecureText();
            HC.Username       = txtEmailAddress.Text.Trim();
            if (HC.Disabled)
            {
                // Saving changes should reset the disabled state and last update date, so a new update can be attempted right away
                HC.Disabled = false;
            }
            HC.Save();

            DialogResult = DialogResult.OK;
        }
コード例 #4
0
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null)
            {
                throw new ArgumentNullException("HC");
            }
            if (ipAddress == null)
            {
                throw new ArgumentNullException("ipAddress");
            }

            using (RMWebClient WC = new RMWebClient())
            {
                string Url = "https://www.dtdns.com/api/autodns.cfm";
                Url += "?id=" + Uri.EscapeDataString(HC.Hostname);
                Url += "&pw=" + Uri.EscapeDataString(HC.Password.GetPlainText());
                Url += "&ip=" + ipAddress.ToString();
                Url += "&client=PDDNS";

                string ResponseText = WC.DownloadString(Url).Trim();
                if (!ResponseText.Contains(ipAddress.ToString()))
                {
                    HC.Disabled       = true;
                    HC.DisabledReason = ResponseText;
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
            }
        }
コード例 #5
0
ファイル: AddCloudFlareForm.cs プロジェクト: orf53975/PDDNS
        void cmdSave_Click(object sender, EventArgs e)
        {
            if (lvZoneRecords.CheckedItems.Count == 0)
            {
                Dialog.Error("Please select one or more hostnames you want to keep updated", "Error");
                return;
            }

            for (int i = 0; i < lvZoneRecords.CheckedItems.Count; i++)
            {
                HostConfig HC = new HostConfig(lvZoneRecords.CheckedItems[i].SubItems[0].Text.Trim());
                HC.Password = txtAPIKey.Text.Trim();
                HC.Provider = ProviderName.CloudFlare;
                HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_ZONE_NAME] = lvZoneRecords.CheckedItems[i].SubItems[1].Text.Trim();
                HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_REC_ID]    = lvZoneRecords.CheckedItems[i].SubItems[2].Text.Trim();
                HC.Username = txtEmailAddress.Text.Trim();
                HC.Save();
            }

            if (chkSaveEmailAddressAndAPIKey.Checked)
            {
                Config.Default.CloudFlareAPIKey       = txtAPIKey.Text;
                Config.Default.CloudFlareEmailAddress = txtEmailAddress.Text;
            }
            else
            {
                Config.Default.CloudFlareAPIKey       = "";
                Config.Default.CloudFlareEmailAddress = "";
            }
            Config.Default.Save();

            DialogResult = DialogResult.OK;
        }
コード例 #6
0
        void cmdSave_Click(object sender, EventArgs e)
        {
            if (!Dialog.ValidateIsNotEmpty(txtHostname))
            {
                return;
            }
            if (!Dialog.ValidateIsNotEmpty(txtPassword))
            {
                return;
            }

            if (txtHostname.Text.Trim().ToUpper() != _OriginalHostname)
            {
                using (IniFile Ini = new IniFile(Config.Default.FileName))
                {
                    Ini.EraseSection(_OriginalHostname);
                    Ini.Save();
                }
            }

            HostConfig HC = new HostConfig(txtHostname.Text.Trim());

            HC.LastUpdateDate = DateTime.MinValue;
            HC.Password       = txtPassword.SecureText.GetSecureText();
            HC.Provider       = ProviderName.DtDNS;
            HC.Username       = HC.Hostname;
            if (HC.Disabled)
            {
                // Saving changes should reset the disabled state and last update date, so a new update can be attempted right away
                HC.Disabled = false;
            }
            HC.Save();

            DialogResult = DialogResult.OK;
        }
コード例 #7
0
ファイル: NoIPProvider.cs プロジェクト: orf53975/PDDNS
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null)
            {
                throw new ArgumentNullException("HC");
            }
            if (ipAddress == null)
            {
                throw new ArgumentNullException("ipAddress");
            }

            using (RMWebClient WC = new RMWebClient())
            {
                WC.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(HC.Username + ":" + HC.Password.GetPlainText()));
                WC.UseDefaultCredentials = false;
                WC.UserAgent             = ProcessUtils.CompanyName + " " + ProcessUtils.ProductName + "/" + ProcessUtils.ProductVersion + " [email protected]";

                string Url = "https://dynupdate.no-ip.com/nic/update";
                Url += "?hostname=" + Uri.EscapeDataString(HC.Hostname);
                Url += "&myip=" + ipAddress.ToString();

                string ResponseText = WC.DownloadString(Url).Trim().ToLower();
                if (ResponseText.Contains(ipAddress.ToString()))
                {
                    if (ResponseText.Contains("nochg"))
                    {
                        Logging.instance.LogWarning("Host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + ") successfully updated, but returned NOCHG response.  Too many of these could cause your account to be banned by the provider.");
                    }
                }
                else
                {
                    HC.Disabled = true;
                    switch (ResponseText)
                    {
                    case "nohost": HC.DisabledReason = "Hostname supplied does not exist under specified account"; break;

                    case "badauth": HC.DisabledReason = "Invalid username password combination"; break;

                    case "badagent": HC.DisabledReason = "Client disabled."; break;

                    case "!donator": HC.DisabledReason = "An update request was sent including a feature that is not available to that particular user such as offline options."; break;

                    case "abuse": HC.DisabledReason = "Username is blocked due to abuse. Either for not following our update specifications or disabled due to violation of the No-IP terms of service."; break;

                    case "911":
                        Logging.instance.LogWarning("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): A fatal error on the provider's side such as a database outage.  Will retry in 1 hour.");
                        return;

                    default: HC.DisabledReason = "An unknown response code was received: \"" + ResponseText + "\""; break;
                    }
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
            }
        }
コード例 #8
0
ファイル: EditPointForm.cs プロジェクト: rickparrish/PDDNS
        void cmdSave_Click(object sender, EventArgs e)
        {
            if (!Dialog.ValidateIsEmailAddress(txtEmailAddress)) return;
            if (!Dialog.ValidateIsNotEmpty(txtAPIKey)) return;

            HostConfig HC = new HostConfig(txtHostname.Text.Trim());
            HC.LastUpdateDate = DateTime.MinValue;
            HC.Password = txtAPIKey.SecureText.GetSecureText();
            HC.Username = txtEmailAddress.Text.Trim();
            if (HC.Disabled)
            {
                // Saving changes should reset the disabled state and last update date, so a new update can be attempted right away
                HC.Disabled = false;
            }
            HC.Save();

            DialogResult = DialogResult.OK;
        }
コード例 #9
0
ファイル: DtDNSProvider.cs プロジェクト: rickparrish/PDDNS
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null) throw new ArgumentNullException("HC");
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");

            using (RMWebClient WC = new RMWebClient())
            {
                string Url = "https://www.dtdns.com/api/autodns.cfm";
                Url += "?id=" + Uri.EscapeDataString(HC.Hostname);
                Url += "&pw=" + Uri.EscapeDataString(HC.Password.GetPlainText());
                Url += "&ip=" + ipAddress.ToString();
                Url += "&client=PDDNS";

                string ResponseText = WC.DownloadString(Url).Trim();
                if (!ResponseText.Contains(ipAddress.ToString()))
                {
                    HC.Disabled = true;
                    HC.DisabledReason = ResponseText;
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
            }
        }
コード例 #10
0
        void cmdSave_Click(object sender, EventArgs e)
        {
            if (lvZoneRecords.CheckedItems.Count == 0)
            {
                Dialog.Error("Please select one or more hostnames you want to keep updated", "Error");
                return;
            }

            for (int i = 0; i < lvZoneRecords.CheckedItems.Count; i++)
            {
                HostConfig HC = new HostConfig(lvZoneRecords.CheckedItems[i].SubItems[0].Text.Trim());
                HC.Password = txtAPIKey.Text.Trim();
                HC.Provider = ProviderName.CloudFlare;
                HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_ZONE_NAME] = lvZoneRecords.CheckedItems[i].SubItems[1].Text.Trim();
                HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_REC_ID] = lvZoneRecords.CheckedItems[i].SubItems[2].Text.Trim();
                HC.Username = txtEmailAddress.Text.Trim();
                HC.Save();
            }

            if (chkSaveEmailAddressAndAPIKey.Checked)
            {
                Config.Default.CloudFlareAPIKey = txtAPIKey.Text;
                Config.Default.CloudFlareEmailAddress = txtEmailAddress.Text;
            }
            else
            {
                Config.Default.CloudFlareAPIKey = "";
                Config.Default.CloudFlareEmailAddress = "";
            }
            Config.Default.Save();

            DialogResult = DialogResult.OK;
        }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: orf53975/PDDNS
        private bool CheckHosts(IPAddress localIPAddress)
        {
            bool Result = true;

            List <string> Hostnames = new List <string>();

            foreach (ListViewItem LVI in lvHosts.Items)
            {
                Hostnames.Add(LVI.SubItems[0].Text);
            }

            foreach (string Hostname in Hostnames)
            {
                try
                {
                    HostConfig HC = new HostConfig(Hostname);
                    if (HC.Loaded)
                    {
                        bool HostNeedsUpdate = true;

                        // Get current IP for host (to see if it differs from detected IP)
                        try
                        {
                            foreach (IPAddress RemoteIPAddress in HC.GetRemoteIPs().Reverse())
                            {
                                SetCurrentIP(HC.Hostname, RemoteIPAddress.ToString());
                                if (RemoteIPAddress.ToString() == localIPAddress.ToString())
                                {
                                    HostNeedsUpdate = false;
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SetCurrentIP(HC.Hostname, "Unable to resolve");
                            Logging.instance.LogException("Unable to resolve \"" + HC.Hostname + "\"", ex);
                        }

                        // Also check if it has been > 7 days since we updated, and if so, force an update to ensure our host doesn't expire
                        if (DateTime.Now.Subtract(HC.LastUpdateDate).TotalDays >= 7.0)
                        {
                            HostNeedsUpdate = true;
                        }

                        if (HostNeedsUpdate && !HC.Disabled)
                        {
                            // If we get here it means the IP retrieved from DNS doesn't match our detected external IP, so
                            // in theory we need to send an update to the provider.  The problem is if the provider has a
                            // large TTL value then we may have already sent an update and just got a cached IP from the DNS
                            // lookup -- and in that case we don't want to send another update.  So we'll check if the last
                            // IP we updated with matches the current IP.  If it does, then we won't send another update
                            // unless one hour has passed since the last update
                            if ((localIPAddress.ToString() != HC.LastUpdateIP) || (DateTime.Now.Subtract(HC.LastUpdateDate).TotalHours > 1))
                            {
                                if (!Debugger.IsAttached || (Dialog.YesNo("Do you want to update " + HC.Hostname + "?", "Confirm Update") == DialogResult.Yes))
                                {
                                    Logging.instance.LogMessage("Updating \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + ") to " + localIPAddress);
                                    HC.LastUpdateIP   = localIPAddress.ToString();
                                    HC.LastUpdateDate = DateTime.Now;
                                    HC.Save();

                                    Provider P = Providers.GetProvider(HC.Provider);
                                    P.Update(HC, localIPAddress);
                                    SetStatus(HC.Hostname, HC.Status);
                                }
                            }
                        }

                        if (HC.Disabled)
                        {
                            Result = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Don't let a single host fail the whole update process
                    Logging.instance.LogException("Error checking \"" + Hostname + "\"", ex);
                    if (Debugger.IsAttached)
                    {
                        Dialog.Error("Error checking " + Hostname + ":\r\n\r\n" + ex.Message, "Error");
                    }
                    Result = false;
                }
            }

            return(Result);
        }
コード例 #12
0
ファイル: AddEditDtDNSForm.cs プロジェクト: rickparrish/PDDNS
        void cmdSave_Click(object sender, EventArgs e)
        {
            if (!Dialog.ValidateIsNotEmpty(txtHostname)) return;
            if (!Dialog.ValidateIsNotEmpty(txtPassword)) return;

            if (txtHostname.Text.Trim().ToUpper() != _OriginalHostname) {
                using (IniFile Ini = new IniFile(Config.Default.FileName))
                {
                    Ini.EraseSection(_OriginalHostname);
                    Ini.Save();
                }
            }

            HostConfig HC = new HostConfig(txtHostname.Text.Trim());
            HC.LastUpdateDate = DateTime.MinValue;
            HC.Password = txtPassword.SecureText.GetSecureText();
            HC.Provider = ProviderName.DtDNS;
            HC.Username = HC.Hostname;
            if (HC.Disabled)
            {
                // Saving changes should reset the disabled state and last update date, so a new update can be attempted right away
                HC.Disabled = false;
            }
            HC.Save();

            DialogResult = DialogResult.OK;
        }
コード例 #13
0
ファイル: MainForm.cs プロジェクト: rickparrish/PDDNS
        private bool CheckHosts(IPAddress localIPAddress)
        {
            bool Result = true;

            List<string> Hostnames = new List<string>();

            foreach (ListViewItem LVI in lvHosts.Items)
            {
                Hostnames.Add(LVI.SubItems[0].Text);
            }

            foreach (string Hostname in Hostnames)
            {
                try
                {
                    HostConfig HC = new HostConfig(Hostname);
                    if (HC.Loaded)
                    {
                        bool HostNeedsUpdate = true;

                        // Get current IP for host (to see if it differs from detected IP)
                        try
                        {
                            foreach (IPAddress RemoteIPAddress in HC.GetRemoteIPs().Reverse())
                            {
                                SetCurrentIP(HC.Hostname, RemoteIPAddress.ToString());
                                if (RemoteIPAddress.ToString() == localIPAddress.ToString())
                                {
                                    HostNeedsUpdate = false;
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SetCurrentIP(HC.Hostname, "Unable to resolve");
                            Logging.instance.LogException("Unable to resolve \"" + HC.Hostname + "\"", ex);
                        }

                        // Also check if it has been > 7 days since we updated, and if so, force an update to ensure our host doesn't expire
                        if (DateTime.Now.Subtract(HC.LastUpdateDate).TotalDays >= 7.0)
                        {
                            HostNeedsUpdate = true;
                        }

                        if (HostNeedsUpdate && !HC.Disabled)
                        {
                            // If we get here it means the IP retrieved from DNS doesn't match our detected external IP, so
                            // in theory we need to send an update to the provider.  The problem is if the provider has a
                            // large TTL value then we may have already sent an update and just got a cached IP from the DNS
                            // lookup -- and in that case we don't want to send another update.  So we'll check if the last
                            // IP we updated with matches the current IP.  If it does, then we won't send another update
                            // unless one hour has passed since the last update
                            if ((localIPAddress.ToString() != HC.LastUpdateIP) || (DateTime.Now.Subtract(HC.LastUpdateDate).TotalHours > 1))
                            {
                                if (!Debugger.IsAttached || (Dialog.YesNo("Do you want to update " + HC.Hostname + "?", "Confirm Update") == DialogResult.Yes))
                                {
                                    Logging.instance.LogMessage("Updating \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + ") to " + localIPAddress);
                                    HC.LastUpdateIP = localIPAddress.ToString();
                                    HC.LastUpdateDate = DateTime.Now;
                                    HC.Save();

                                    Provider P = Providers.GetProvider(HC.Provider);
                                    P.Update(HC, localIPAddress);
                                    SetStatus(HC.Hostname, HC.Status);
                                }
                            }
                        }

                        if (HC.Disabled) Result = false;
                    }
                }
                catch (Exception ex)
                {
                    // Don't let a single host fail the whole update process
                    Logging.instance.LogException("Error checking \"" + Hostname + "\"", ex);
                    if (Debugger.IsAttached) Dialog.Error("Error checking " + Hostname + ":\r\n\r\n" + ex.Message, "Error");
                    Result = false;
                }
            }

            return Result;
        }
コード例 #14
0
ファイル: CloudFlareProvider.cs プロジェクト: orf53975/PDDNS
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null)
            {
                throw new ArgumentNullException("HC");
            }
            if (ipAddress == null)
            {
                throw new ArgumentNullException("ipAddress");
            }

            using (RMWebClient WC = new RMWebClient())
            {
                try
                {
                    NameValueCollection Params = new NameValueCollection();
                    Params.Add("a", "rec_edit");
                    Params.Add("content", ipAddress.ToString());
                    Params.Add("email", HC.Username);
                    Params.Add("id", HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_REC_ID]);
                    int HostnamePeriodCount = HC.Hostname.Count(x => x == '.'); // TODO Do this for other providers too
                    switch (HostnamePeriodCount)
                    {
                    case 0: throw new Exception("Hostname has 0 periods?");

                    case 1: Params.Add("name", HC.Hostname); break;                                                           // One period == full domain name (ie github.com)

                    default: Params.Add("name", string.Join(".", HC.Hostname.Split('.'), 0, HostnamePeriodCount - 1)); break; // More than one period == all but last element (ie www.github.com or a.b.c.d.github.com)
                    }
                    Params.Add("tkn", HC.Password.GetPlainText());
                    Params.Add("ttl", "1");
                    Params.Add("type", "A");
                    Params.Add("z", HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_ZONE_NAME]);
                    Hashtable rec_edit_response = (Hashtable)JSON.JsonDecode(Encoding.UTF8.GetString(WC.UploadValues("https://www.cloudflare.com/api_json.html", "POST", Params)));
                    if (rec_edit_response["result"].ToString() == "success")
                    {
                        Hashtable Response = (Hashtable)rec_edit_response["response"];
                        Hashtable Rec      = (Hashtable)Response["rec"];
                        Hashtable Obj      = (Hashtable)Rec["obj"];

                        if (!Obj["content"].ToString().Contains(ipAddress.ToString()))
                        {
                            HC.Disabled       = true;
                            HC.DisabledReason = rec_edit_response["msg"].ToString();
                            HC.Save();

                            Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                        }
                    }
                    else
                    {
                        HC.Disabled       = true;
                        HC.DisabledReason = (rec_edit_response["msg"] == null) ? "Unknown reason" : rec_edit_response["msg"].ToString();
                        HC.Save();

                        Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                    }
                }
                catch (Exception ex)
                {
                    HC.Disabled       = true;
                    HC.DisabledReason = "Unhandled exception (" + ex.Message + ")";
                    HC.Save();

                    Logging.instance.LogException("Unable to update host \"" + HC.Hostname + "\"", ex);
                }
            }
        }
コード例 #15
0
ファイル: NoIPProvider.cs プロジェクト: rickparrish/PDDNS
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null) throw new ArgumentNullException("HC");
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");

            using (RMWebClient WC = new RMWebClient())
            {
                WC.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(HC.Username + ":" + HC.Password.GetPlainText()));
                WC.UseDefaultCredentials = false;
                WC.UserAgent = ProcessUtils.CompanyName + " " + ProcessUtils.ProductName + "/" + ProcessUtils.ProductVersion + " [email protected]";

                string Url = "https://dynupdate.no-ip.com/nic/update";
                Url += "?hostname=" + Uri.EscapeDataString(HC.Hostname);
                Url += "&myip=" + ipAddress.ToString();

                string ResponseText = WC.DownloadString(Url).Trim().ToLower();
                if (ResponseText.Contains(ipAddress.ToString()))
                {
                    if (ResponseText.Contains("nochg"))
                    {
                        Logging.instance.LogWarning("Host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + ") successfully updated, but returned NOCHG response.  Too many of these could cause your account to be banned by the provider.");
                    }
                }
                else
                {
                    HC.Disabled = true;
                    switch (ResponseText)
                    {
                        case "nohost": HC.DisabledReason = "Hostname supplied does not exist under specified account"; break;
                        case "badauth": HC.DisabledReason = "Invalid username password combination"; break;
                        case "badagent": HC.DisabledReason = "Client disabled."; break;
                        case "!donator": HC.DisabledReason = "An update request was sent including a feature that is not available to that particular user such as offline options."; break;
                        case "abuse": HC.DisabledReason = "Username is blocked due to abuse. Either for not following our update specifications or disabled due to violation of the No-IP terms of service."; break;
                        case "911":
                            Logging.instance.LogWarning("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): A fatal error on the provider's side such as a database outage.  Will retry in 1 hour.");
                            return;
                        default: HC.DisabledReason = "An unknown response code was received: \"" + ResponseText + "\""; break;
                    }
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
            }
        }
コード例 #16
0
        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null) throw new ArgumentNullException("HC");
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");

            using (RMWebClient WC = new RMWebClient())
            {
                try
                {
                    NameValueCollection Params = new NameValueCollection();
                    Params.Add("a", "rec_edit");
                    Params.Add("content", ipAddress.ToString());
                    Params.Add("email", HC.Username);
                    Params.Add("id", HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_REC_ID]);
                    int HostnamePeriodCount = HC.Hostname.Count(x => x == '.'); // TODO Do this for other providers too
                    switch (HostnamePeriodCount) {
                        case 0: throw new Exception("Hostname has 0 periods?");
                        case 1: Params.Add("name", HC.Hostname); break; // One period == full domain name (ie github.com)
                        default: Params.Add("name", string.Join(".", HC.Hostname.Split('.'), 0, HostnamePeriodCount - 1)); break; // More than one period == all but last element (ie www.github.com or a.b.c.d.github.com)
                    }
                    Params.Add("tkn", HC.Password.GetPlainText());
                    Params.Add("ttl", "1");
                    Params.Add("type", "A");
                    Params.Add("z", HC.ProviderSpecificSettings[HostConfig.CLOUDFLARE_ZONE_NAME]);
                    Hashtable rec_edit_response = (Hashtable)JSON.JsonDecode(Encoding.UTF8.GetString(WC.UploadValues("https://www.cloudflare.com/api_json.html", "POST", Params)));
                    if (rec_edit_response["result"].ToString() == "success")
                    {
                        Hashtable Response = (Hashtable)rec_edit_response["response"];
                        Hashtable Rec = (Hashtable)Response["rec"];
                        Hashtable Obj = (Hashtable)Rec["obj"];

                        if (!Obj["content"].ToString().Contains(ipAddress.ToString()))
                        {
                            HC.Disabled = true;
                            HC.DisabledReason = rec_edit_response["msg"].ToString();
                            HC.Save();

                            Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                        }
                    }
                    else
                    {
                        HC.Disabled = true;
                        HC.DisabledReason = (rec_edit_response["msg"] == null) ? "Unknown reason" : rec_edit_response["msg"].ToString();
                        HC.Save();

                        Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                    }
                }
                catch (Exception ex)
                {
                    HC.Disabled = true;
                    HC.DisabledReason = "Unhandled exception (" + ex.Message + ")";
                    HC.Save();

                    Logging.instance.LogException("Unable to update host \"" + HC.Hostname + "\"", ex);
                }
            }
        }