Exemplo n.º 1
0
        private void btnSetDDNS_Click(object sender, EventArgs e)
        {
            FormSetDDNS frm = new FormSetDDNS();

            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
            }
        }
Exemplo n.º 2
0
        public static string updateDDNS()
        {
            try
            {
                if (string.IsNullOrEmpty(SystemConfig.AccessKeyId) || string.IsNullOrEmpty(SystemConfig.AccessKeySecret) || string.IsNullOrEmpty(SystemConfig.Domain))
                {
                    FormSetDDNS frm = new FormSetDDNS();
                    if (frm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return("【请输入正确配置】");
                    }
                }
                Dictionary <string, string> parameters;
                List <string>  typeARecordIdList = new List <string>();
                string         updateIP          = getCurIP();
                List <XmlNode> typeANodeList     = DomainRequestHelper.getTypeAList(ref typeARecordIdList);
                if (typeARecordIdList.Count >= 0)
                {
                    if (typeARecordIdList.Count == 1)
                    {
                        XmlNode node      = typeANodeList[0];
                        XmlNode valueNode = node.SelectSingleNode("Value");
                        if (valueNode.InnerText.Equals(updateIP))
                        {
                            return("");
                        }
                    }
                    else if (typeARecordIdList.Count > 0)
                    {
                        foreach (string recordId in typeARecordIdList)
                        {
                            parameters = new Dictionary <string, string>()
                            {
                                { "Action", "DeleteDomainRecord" },
                                { "RecordId", recordId },
                            };
                            DomainRequestHelper.requestAli(parameters);
                        }
                    }
                    // 添加记录
                    parameters = new Dictionary <string, string>()
                    {
                        { "Action", "AddDomainRecord" },
                        { "DomainName", SystemConfig.Domain },
                        { "RR", SystemConfig.Prefix },
                        { "Type", "A" },
                        { "Value", updateIP },
                    };
                    DomainRequestHelper.requestAli(parameters);
                }

                // 验证
                typeANodeList = DomainRequestHelper.getTypeAList(ref typeARecordIdList);
                if (typeANodeList.Count > 1 || typeANodeList.Count == 0)
                {
                    updateDDNS();
                }
                else
                {
                    XmlNode node      = typeANodeList[0];
                    XmlNode valueNode = node.SelectSingleNode("Value");
                    if (!valueNode.InnerText.Equals(updateIP))
                    {
                        updateDDNS();
                    }
                }
                if (SystemConfig.SendMessageToServerChan)
                {
                    sendMsgToServerChan("DDNS已更新(" + updateIP + ")");
                }
                return(updateIP);
            }
            catch
            {
                return("error");
            }
        }