コード例 #1
0
ファイル: FrmMain.cs プロジェクト: newdraw/LinkHome
        private void btnAdd_Click(object sender, EventArgs e)
        {
            using var dlg = new DlgAdd();
            var domains = from i in ali.GetDomains()
                          select i.DomainName;

            while (true)
            {
                if (dlg.Show(domains.ToArray()) != DialogResult.OK)
                {
                    return;
                }

                var key = makeSubdomain(dlg.RR, dlg.Domain);
                if (!infos.ContainsKey(key))
                {
                    ali.SetupRecord(dlg.Domain, dlg.RR, dlg.DDns ? ServerIP.Get(errorHandler) : "0.0.0.0");
                    var info = new DomainInfo
                    {
                        DDns      = dlg.DDns,
                        Subdomain = key,
                        Row       = null
                    };
                    infos.Add(key, info);
                    refresh();
                    return;
                }

                MessageBox.Show("域名已经存在,请直接在列表中操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #2
0
ファイル: FrmMain.cs プロジェクト: newdraw/LinkHome
        void refresh()
        {
            if (string.IsNullOrWhiteSpace(config.AccessKeyID) || string.IsNullOrWhiteSpace(config.AccessKeySecret))
            {
                lblStatus.Text = "请先在设置中配置AccessKeyID和AccessKeySecret";
                return;
            }

            lock (infos)
            {
                var ip      = ServerIP.Get(errorHandler);
                var domains = ali.GetDomains();
                var exist   = new HashSet <string>();
                foreach (var domain in domains)
                {
                    foreach (var rec in ali.GetRecords(domain))
                    {
                        if (rec.Type != "A" && rec.Type != "CNAME")
                        {
                            continue;
                        }

                        var key = makeSubdomain(rec.RR, rec.DomainName);
                        exist.Add(key);

                        //
                        infos.TryGetValue(key, out var info);

                        if (info == null)
                        {
                            info = new DomainInfo
                            {
                                DDns      = false,
                                Subdomain = key
                            };
                            infos.Add(key, info);
                        }

                        if (info.Row == null)
                        {
                            var rowIndex = invoke(() => grid.Rows.Add(key, info.DDns, ""));
                            info.Row = grid.Rows[rowIndex];
                        }

                        //
                        var localDnsStatus  = @try(() => Dns.GetHostAddresses(key).FirstOrDefault(i => i.ToString() == ip) != null, false);
                        var dnsConfigStatus = rec._Value == ip && rec.Type == "A";
                        var status          = "";
                        if (info.DDns)
                        {
                            if (localDnsStatus && dnsConfigStatus)
                            {
                                status = "正常";
                            }
                            else
                            {
                                status = $"DNS配置{(dnsConfigStatus ? "正确" : "不正确")},本地解析{(localDnsStatus ? "正确" : "不正确")}";
                            }

                            //
                            if (rec._Value != ip)
                            {
                                ali.UpdateRecordIP(rec, ip);
                                info.LastIP = ip;
                            }
                        }
                        info.Row.Cells[2].Value = status;

                        //
                        info.ID = rec.RecordId;
                    }
                }

                var notexists = infos.Keys.Where(i => !exist.Contains(i)).ToArray();
                if (notexists.Count() > 0)
                {
                    foreach (var k in notexists)
                    {
                        var i = infos[k];
                        if (i.Row != null)
                        {
                            grid.Rows.Remove(i.Row);
                        }
                        infos.Remove(k);
                    }
                    saveSettings();
                }
                lblStatus.Text = $"当前IP:{ip} 最后更新时间:{DateTime.Now}";
            }
        }