-
Notifications
You must be signed in to change notification settings - Fork 6
/
HostConfig.cs
109 lines (94 loc) · 3.36 KB
/
HostConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
R&M PDDNS: A Promiscuous Dynamic DNS Client
Copyright (C) 2013 Rick Parrish, R&M Software
This file is part of PDDNS.
PDDNS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
PDDNS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PDDNS. If not, see <http://www.gnu.org/licenses/>.
*/
using RandM.RMLib;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Text;
namespace RandM.PDDNS
{
public class HostConfig : ConfigHelper
{
public const string CLOUDFLARE_REC_ID = "rec_id";
public const string CLOUDFLARE_ZONE_NAME = "zone_name";
public const string POINT_RECORD_ID = "RecordId";
public const string POINT_ZONE_ID = "ZoneId";
public bool Disabled { get; set; }
public string DisabledReason { get; set; }
public string Hostname { get; set; }
public DateTime LastUpdateDate { get; set; }
public string LastUpdateIP { get; set; }
public RMSecureString Password { get; set; }
public ProviderName Provider { get; set; }
public StringDictionary ProviderSpecificSettings { get; set; }
public string Username { get; set; }
public HostConfig(string hostname) : base()
{
Disabled = false;
DisabledReason = "";
Hostname = hostname;
LastUpdateDate = DateTime.MinValue;
LastUpdateIP = "";
Password = "";
Provider = ProviderName.None;
ProviderSpecificSettings = new StringDictionary();
Username = "";
base.Load(hostname);
}
public new void Delete()
{
base.Delete();
}
public static string[] GetHostnames()
{
List<string> Result = new List<string>();
using (IniFile Ini = new IniFile(Config.Default.FileName))
{
// Get section names (but not the CONFIGURATION section, since that's not a host)
string[] Sections = Ini.ReadSections();
foreach (string Section in Sections)
{
if (Section.ToUpper() != "CONFIGURATION") Result.Add(Section);
}
}
Result.Sort();
return Result.ToArray();
}
public IPAddress[] GetRemoteIPs()
{
return Providers.GetProvider(Provider).GetRemoteIPs(this);
}
public new void Save()
{
base.Save();
}
public string Status
{
get
{
if (Disabled)
{
return "Disabled: " + DisabledReason;
}
else
{
return "Last Updated: " + (LastUpdateDate == DateTime.MinValue ? "Never" : LastUpdateDate.ToShortDateString() + " " + LastUpdateDate.ToLongTimeString());
}
}
}
}
}