Ejemplo n.º 1
0
        private void updateDomainRecord()
        {
            string[] symbols = new string[1] {
                "."
            };
            string[] data       = fullDomainName.Text.Split(symbols, 30, StringSplitOptions.RemoveEmptyEntries);
            string   domainRR   = data[0];
            string   domainName = data[1] + "." + data[2];

            UpdateDomainRecordRequest request = new UpdateDomainRecordRequest();

            request.Type     = "A";
            request.RR       = domainRR;
            request.RecordId = recordId.Text;
            request.Value    = localIP.Text;
            try
            {
                UpdateDomainRecordResponse response = client.GetAcsResponse(request);
                recordId.Text = response.RecordId;
            }
            //处理错误
            catch (ServerException e)
            {
                MessageBox.Show(e.ErrorCode + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                MessageBox.Show(e.ErrorCode + e.ErrorMessage);
            }
        }
Ejemplo n.º 2
0
        public static UpdateDomainRecordResponse Unmarshall(UnmarshallerContext _ctx)
        {
			UpdateDomainRecordResponse updateDomainRecordResponse = new UpdateDomainRecordResponse();

			updateDomainRecordResponse.HttpResponse = _ctx.HttpResponse;
			updateDomainRecordResponse.RequestId = _ctx.StringValue("UpdateDomainRecord.RequestId");
			updateDomainRecordResponse.RecordId = _ctx.StringValue("UpdateDomainRecord.RecordId");
        
			return updateDomainRecordResponse;
        }
Ejemplo n.º 3
0
        public static UpdateDomainRecordResponse Unmarshall(UnmarshallerContext context)
        {
            UpdateDomainRecordResponse updateDomainRecordResponse = new UpdateDomainRecordResponse();

            updateDomainRecordResponse.HttpResponse = context.HttpResponse;
            updateDomainRecordResponse.RequestId    = context.StringValue("UpdateDomainRecord.RequestId");
            updateDomainRecordResponse.RecordId     = context.StringValue("UpdateDomainRecord.RecordId");

            return(updateDomainRecordResponse);
        }
        public static void UpdateDomainRecords(DescribeDomainRecordsResponse.Record record)
        {
            IClientProfile            clientProfile = DefaultProfile.GetProfile("cn-hangzhou", CGlobalConfig.AccessKey, CGlobalConfig.AccessKeySecret);
            DefaultAcsClient          client        = new DefaultAcsClient(clientProfile);
            UpdateDomainRecordRequest request       = new UpdateDomainRecordRequest();

            request.RecordId = record.RecordId;
            request.RR       = record.RR;
            request.Type     = record.Type;
            request.Value    = record.Value;
            UpdateDomainRecordResponse response = client.GetAcsResponse(request);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 更新域名记录
        /// </summary>
        private void updateDomainRecord()
        {
            string[] symbols = new string[1] {
                "."
            };
            string[] data       = fullDomainName.Text.Split(symbols, 30, StringSplitOptions.RemoveEmptyEntries);
            string   domainRR   = data[0];
            string   domainName = data[1] + "." + data[2];

            clientProfile = DefaultProfile.GetProfile("cn-hangzhou", textBox_accessKeyId.Text.ToString(), textBox_accessKeySecret.Text.ToString());
            client        = new DefaultAcsClient(clientProfile);
            UpdateDomainRecordRequest request = new UpdateDomainRecordRequest();

            request.Type     = "A";
            request.RR       = domainRR;
            request.RecordId = textBox_recordId.Text;
            request.TTL      = Convert.ToInt32(textBox_TTL.Text);
            request.Value    = localIP.Text;
            try
            {
                textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "正在将WAN口IP:" + localIP.Text + "与域名" + fullDomainName.Text + "绑定..." + "\r\n");
                UpdateDomainRecordResponse response = client.GetAcsResponse(request);
                if (response.RecordId != null)
                {
                    domainIP.Text = localIP.Text; //更新窗体数据
                    textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "域名绑定IP更新成功!" + "\r\n");
                }
                textBox_recordId.Text = response.RecordId;
            }
            //处理错误
            catch (Exception error)
            {
                textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "updateDomainRecord() Exception:  " + error + "\r\n");
            }

            /*
             * catch (ServerException e)
             * {
             *  textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Server Exception:  " + e.ErrorCode + e.ErrorMessage + "\r\n");
             * }
             * catch (ClientException e)
             * {
             *  textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Client Exception:  " + e.ErrorCode + e.ErrorMessage + "\r\n");
             * }*/
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 修改解析记录
 /// </summary>
 /// <param name="record"></param>
 /// <param name="strContent"></param>
 /// <returns></returns>
 public static bool UpdateDomainRecords(DescribeDomainRecordsResponse.Record record, out string strContent)
 {
     try
     {
         IClientProfile            clientProfile = DefaultProfile.GetProfile("cn-hangzhou", CGlobalConfig.AccessKey, CGlobalConfig.AccessKeySecret);
         DefaultAcsClient          client        = new DefaultAcsClient(clientProfile);
         UpdateDomainRecordRequest request       = new UpdateDomainRecordRequest();
         request.RecordId = record.RecordId;
         request.RR       = record.RR;
         request.Type     = record.Type;
         request.Value    = record.Value;
         request.Line     = record.Line;
         try
         {
             UpdateDomainRecordResponse response = client.GetAcsResponse(request);
             strContent = response.RecordId;
             return(!string.IsNullOrEmpty(strContent));
         }
         catch (ServerException e)
         {
             strContent = " UpdateDomainRecords 发送异常:" + e.ErrorCode + "\t" + e.ErrorMessage;
             CLogHelper.WriteError(strContent);
         }
         catch (ClientException e)
         {
             strContent = " UpdateDomainRecords 发送异常:" + e.ErrorCode + "\t" + e.ErrorMessage;
             CLogHelper.WriteError(strContent);
         }
     }
     catch (Exception ex)
     {
         strContent = " UpdateDomainRecords 发送异常:" + ex.ToString();
         CLogHelper.WriteError(strContent);
     }
     return(false);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 更新域名记录
        /// </summary>
        private void updateDomainRecord()
        {
            string[] symbols = new string[1] {
                "."
            };
            string[] data       = fullDomainName.Text.Split(symbols, 30, StringSplitOptions.RemoveEmptyEntries);
            string   domainRR   = data[0];
            string   domainName = data[1] + "." + data[2];

            clientProfile = DefaultProfile.GetProfile("cn-hangzhou", textBox_accessKeyId.Text.ToString(), textBox_accessKeySecret.Text.ToString());
            client        = new DefaultAcsClient(clientProfile);
            UpdateDomainRecordRequest request = new UpdateDomainRecordRequest();

            request.Type     = "A";
            request.RR       = domainRR;
            request.RecordId = textBox_recordId.Text;
            request.TTL      = Convert.ToInt32(textBox_TTL.Text);
            request.Value    = localIP.Text;
            try
            {
                textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "正在将WAN口IP:" + localIP.Text + "与域名" + fullDomainName.Text + "绑定..." + "\r\n");
                UpdateDomainRecordResponse response = client.GetAcsResponse(request);
                if (response.RecordId != null)
                {
                    domainIP.Text = localIP.Text; //更新窗体数据
                    textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "域名绑定IP更新成功!" + "\r\n");
                    if (checkBox_ngrok.Checked == true)
                    {
                        //button_ngrok.Enabled = false;
                        //cfg.SaveAppSetting("ngrokauto", "On");
                        //检测ngrok.exe是否存在
                        if (ngrok.IsExists())
                        {
                            textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "IP地址变化,Ngrok功能重启!本机浏览器打开:http://127.0.0.1:4040 查看运行状态。" + "\r\n");
                            ngrok.Stop();
                            ngrok.Start();
                        }
                        //else
                        //{
                        //textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Ngrok功能启用,但当前目录没有发现ngrok.exe,请往官网下载自行编译:https://ngrok.com/download" + "\r\n");
                        //}
                    }
                }
                textBox_recordId.Text = response.RecordId;
            }
            //处理错误
            catch (Exception error)
            {
                textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "updateDomainRecord() Exception:  " + error + "\r\n");
            }

            /*
             * catch (ServerException e)
             * {
             *  textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Server Exception:  " + e.ErrorCode + e.ErrorMessage + "\r\n");
             * }
             * catch (ClientException e)
             * {
             *  textBox_log.AppendText(System.DateTime.Now.ToString() + " " + "Client Exception:  " + e.ErrorCode + e.ErrorMessage + "\r\n");
             * }*/
        }
        public void UpdateDomainRecord(string currentIp)
        {
            //基础参数
            string regionId        = Options.Config.RegionId;
            string accessKeyId     = Options.Config.AccessKeyId;
            string accessKeySecret = Options.Config.AccessKeySecret;
            int    globalPageSize  = Options.Config.PageSize;

            //string domainName = "mydomain.com";
            //string rr = "www";
            //string currentIp = GetCurrentIp();

            Logger.LogDebug($"This computer's network IP address is \"{currentIp}\"");

            foreach (var domainRecord in Options.DomainRecords)
            {
                Logger.LogDebug($"Ready to update the domain name is \"{domainRecord.DomainName}\"");
                Logger.LogDebug($"The RR is \"{domainRecord.RR}\"");
                Logger.LogDebug($"Current DateTime is \"{DateTime.Now.ToLongDateTime()}\"");
                Logger.LogDebug(string.Empty);

                try
                {
                    int pageSize = domainRecord.PageSize > 0 ? domainRecord.PageSize : globalPageSize;
                    //初始化默认的ACS客户端
                    IClientProfile   clientProfile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret);
                    DefaultAcsClient client        = new DefaultAcsClient(clientProfile);

                    //初始化指定域名的解析记录信息查询请求
                    DescribeDomainRecordsRequest describeDomainRecordsRequest = new DescribeDomainRecordsRequest
                    {
                        PageNumber  = 1,
                        PageSize    = pageSize,
                        RRKeyWord   = domainRecord.RR,
                        TypeKeyWord = Type,
                        DomainName  = domainRecord.DomainName
                                      //AcceptFormat = FormatType.JSON
                    };
                    //执行并且获取查询指定域名的解析记录信息的响应结果
                    DescribeDomainRecordsResponse describeDomainRecordsResponse = client.GetAcsResponse(describeDomainRecordsRequest);
                    Logger.LogDebug($"No.0 <<DescribeDomainRecordsResponse>> The request id is \"{describeDomainRecordsResponse.RequestId}\"");
                    Logger.LogDebug($"No.0 <<DescribeDomainRecordsResponse>> Total number of records matching your query is \"{describeDomainRecordsResponse.TotalCount}\"");
                    Logger.LogDebug($"No.0 <<DescribeDomainRecordsResponse>> The raw content is \"{Encoding.UTF8.GetString(describeDomainRecordsResponse.HttpResponse.Content)}\"");
                    Logger.LogDebug(string.Empty);

                    if (describeDomainRecordsResponse.TotalCount.HasValue && describeDomainRecordsResponse.TotalCount.Value > 0 && describeDomainRecordsResponse.DomainRecords.Any())
                    {
                        //待更新的解析记录总列表
                        var domainRecords = describeDomainRecordsResponse.DomainRecords;

                        //总页数
                        int totalPage = Convert.ToInt32(describeDomainRecordsResponse.TotalCount.Value / pageSize);
                        if ((describeDomainRecordsResponse.TotalCount.Value % pageSize) > 0)
                        {
                            totalPage++;
                        }

                        //当总页数大于1时,表示还有下一页
                        if (totalPage > 1)
                        {
                            //从第二页开始获取待更新的解析记录列表
                            for (int pageNumber = 2; pageNumber <= totalPage; pageNumber++)
                            {
                                describeDomainRecordsRequest.PageNumber = pageNumber;
                                describeDomainRecordsResponse           = client.GetAcsResponse(describeDomainRecordsRequest);
                                if (describeDomainRecordsResponse.DomainRecords.Any())
                                {
                                    //添加到待解析记录总列表
                                    domainRecords.AddRange(describeDomainRecordsResponse.DomainRecords);
                                }
                            }
                        }

                        //更新指定域名的解析记录值
                        int index = 0;
                        foreach (var item in domainRecords)
                        {
                            index++;
                            if (item.Value == currentIp)
                            {
                                Logger.LogDebug($"No.{index} <<DescribeDomainRecordsResponse>> The record id is \"{item.RecordId}\", Domain Name is \"{item.DomainName}\", RR is \"{item.RR}\", value is \"{item.Value}\", does not need to be updated");
                                Logger.LogDebug(string.Empty);
                                continue;
                            }

                            //初始化指定域名的解析记录更新请求
                            UpdateDomainRecordRequest updateDomainRecordRequest = new UpdateDomainRecordRequest
                            {
                                RecordId = item.RecordId,
                                RR       = item.RR,
                                Type     = item.Type,
                                Value    = currentIp
                            };
                            //执行并且获取更新指定域名的解析记录的响应结果
                            UpdateDomainRecordResponse updateDomainRecordResponse = client.GetAcsResponse(updateDomainRecordRequest);
                            Logger.LogDebug($"No.{index} <<UpdateDomainRecordRequest>> updating the domain name is \"{item.RR}.{item.DomainName}\"");
                            Logger.LogDebug($"No.{index} <<UpdateDomainRecordRequest>> Before updating the record value is \"{item.Value}\"");
                            Logger.LogDebug($"No.{index} <<UpdateDomainRecordRequest>> Updated the record value is \"{currentIp}\"");
                            Logger.LogDebug($"No.{index} <<UpdateDomainRecordRequest>> The request id is \"{updateDomainRecordResponse.RequestId}\"");
                            Logger.LogDebug($"No.{index} <<UpdateDomainRecordRequest>> The record id is \"{updateDomainRecordResponse.RecordId}\"");
                            Logger.LogDebug(string.Empty);
                        }
                    }

                    Logger.LogDebug($"Update \"{domainRecord.DomainName}\" completed!");
                    Logger.LogDebug(string.Empty);
                }
                catch (ServerException ex)
                {
                    Logger.LogDebug(0, ex, $"Throw {nameof(ServerException)}");
                }
                catch (ClientException ex)
                {
                    Logger.LogDebug(0, ex, $"Throw {nameof(ClientException)}");
                }
                catch (Exception ex)
                {
                    Logger.LogDebug(0, ex, $"Throw {nameof(Exception)}");
                }
            }

            Logger.LogDebug("Update all completed!");
        }
Ejemplo n.º 9
0
        //定时执行事件
        private void TimedEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            //每次都重新获取配置(可以动态修改而不用重启服务)
            GetConfig();
            if (!configExist_)
            {
                logger.Error(" Not Config Yet ...... 【Skip】");
                return;
            }
            string currentInternetIp = GetInternetIP();

            if (currentInternetIp.Length == 0)
            {
                logger.Info("Can't Get Current Internet Ip ...... 【Skip】");
                return;
            }
            IClientProfile               clientProfile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId_, accessKeySecret_);
            DefaultAcsClient             client        = new DefaultAcsClient();
            DescribeDomainRecordsRequest reqFetch      = new DescribeDomainRecordsRequest();

            reqFetch.AcceptFormat = Aliyun.Acs.Core.Http.FormatType.JSON;
            reqFetch.DomainName   = domainName_;

            string dnsIp = "", recordId = "";

            try {
                DescribeDomainRecordsResponse resFetch = client.GetAcsResponse(reqFetch);
                foreach (var r in resFetch.DomainRecords)
                {
                    if (r.RR == subDomainName_)
                    {
                        dnsIp    = r.Value;
                        recordId = r.RecordId;
                    }
                }
            } catch (ServerException ex) {
                logger.Error("Server Error >> code : " + ex.ErrorCode + " | Error Message : " + ex.ErrorMessage);
            } catch (ClientException ex) {
                logger.Error("Client Error >> code : " + ex.ErrorCode + " | Error Message : " + ex.ErrorMessage);
            }
            if (dnsIp.Length == 0)
            {
                logger.Info("Can't Get Dns Record , Add New Record .");
                AddDomainRecordRequest reqAdd = new AddDomainRecordRequest();
                reqAdd.AcceptFormat = Aliyun.Acs.Core.Http.FormatType.JSON;
                reqAdd.DomainName   = domainName_;
                reqAdd.RR           = subDomainName_;
                reqAdd.Type         = "A";
                reqAdd.Value        = currentInternetIp;
                try {
                    //添加解析记录
                    AddDomainRecordResponse resAdd = client.GetAcsResponse(reqAdd);
                    logger.Info("\r\n Dns Record Add ...... 【OK】 \r\n New Dns Record Is : " + currentInternetIp);
                } catch (ServerException ex) {
                    logger.Error("Dns Record Add ...... 【Error】 \r\n Server Error >> code : " + ex.ErrorCode + " | Error Message : " + ex.ErrorMessage);
                } catch (ClientException ex) {
                    logger.Error("Dns Record Add ...... 【Error】 \r\n Client Error >> code : " + ex.ErrorCode + " | Error Message : " + ex.ErrorMessage);
                }
            }
            else
            {
                if (currentInternetIp == dnsIp)
                {
                    logger.Info("Current Internet Ip Is : " + currentInternetIp + " ,Same As Dns Record ...... 【Skip】");
                }
                else
                {
                    //更新记录
                    UpdateDomainRecordRequest reqUpdate = new UpdateDomainRecordRequest();
                    reqUpdate.AcceptFormat = Aliyun.Acs.Core.Http.FormatType.JSON;
                    reqUpdate.RecordId     = recordId;
                    reqUpdate.RR           = subDomainName_;
                    reqUpdate.Type         = "A";
                    reqUpdate.Value        = currentInternetIp;
                    try {
                        //更新解析记录
                        UpdateDomainRecordResponse resUpdate = client.GetAcsResponse(reqUpdate);
                        logger.Info("\r\n Update Dns  Record ...... 【OK】 \r\n New Dns Record Is : " + currentInternetIp);
                    } catch (ServerException ex) {
                        logger.Error("Dns Record Update ...... 【Error】 \r\n Server Error >> code : " + ex.ErrorCode + " | Error Message : " + ex.ErrorMessage);
                    } catch (ClientException ex) {
                        logger.Error("Dns Record Update ...... 【Error】 \r\n Client Error >> code : " + ex.ErrorCode + " | Error Message : " + ex.ErrorMessage);
                    }
                }
            }
        }