浏览代码

add domain automatic soa

develop
Robin Thoni 9 年前
父节点
当前提交
d3441e14b5

+ 8
- 1
conf/hosts.json.default 查看文件

@@ -5,7 +5,14 @@
5 5
     "reverse_domain": "1.168.192",
6 6
     "reverse_enabled": true,
7 7
     "record_type": "A",
8
-    "dhcp_mac": ""
8
+    "dhcp_mac": "",
9
+    "record_ttl": 84600,
10
+    "soa_ns": "ns.example.com",
11
+    "soa_mail": "root.example.com",
12
+    "soa_refresh": 86400,
13
+    "soa_retry": 7200,
14
+    "soa_expire": 3600000,
15
+    "soa_ttl": 172800
9 16
   },
10 17
   "actions":[
11 18
   {

+ 80
- 3
src/DBO/Actions/ActionAddDomain.cpp 查看文件

@@ -8,9 +8,86 @@ ActionAddDomain::ActionAddDomain()
8 8
 {
9 9
 }
10 10
 
11
-const std::string ActionAddDomain::getSql() const
11
+const std::string &ActionAddDomain::getSoaNs() const
12 12
 {
13
+    return _soaNs;
14
+}
15
+
16
+void ActionAddDomain::setSoaNs(const std::string &soaNs)
17
+{
18
+    _soaNs = soaNs;
19
+}
20
+
21
+const std::string &ActionAddDomain::getSoaMail() const
22
+{
23
+    return _soaMail;
24
+}
25
+
26
+void ActionAddDomain::setSoaMail(const std::string &soaMail)
27
+{
28
+    _soaMail = soaMail;
29
+}
30
+
31
+int ActionAddDomain::getSoaRefresh() const
32
+{
33
+    return _soaRefresh;
34
+}
35
+
36
+void ActionAddDomain::setSoaRefresh(int soaRefresh)
37
+{
38
+    _soaRefresh = soaRefresh;
39
+}
40
+
41
+int ActionAddDomain::getSoaRetry() const
42
+{
43
+    return _soaRetry;
44
+}
45
+
46
+void ActionAddDomain::setSoaRetry(int soaRetry)
47
+{
48
+    _soaRetry = soaRetry;
49
+}
50
+
51
+int ActionAddDomain::getSoaExpire() const
52
+{
53
+    return _soaExpire;
54
+}
55
+
56
+void ActionAddDomain::setSoaExpire(int soaExpire)
57
+{
58
+    _soaExpire = soaExpire;
59
+}
60
+
61
+int ActionAddDomain::getSoaTtl() const
62
+{
63
+    return _soaTtl;
64
+}
65
+
66
+void ActionAddDomain::setSoaTtl(int soaTtl)
67
+{
68
+    _soaTtl = soaTtl;
69
+}
70
+
71
+int ActionAddDomain::getTtl() const
72
+{
73
+    return _ttl;
74
+}
75
+
76
+void ActionAddDomain::setTtl(int ttl)
77
+{
78
+    _ttl = ttl;
79
+}
80
+
81
+const std::string ActionAddDomain::getSql() const //ns.rthoni.com rthoni.hotmail.fr 2015080600 28800 7200 604800 86400
82
+{
83
+    auto soa = _soaNs + " " + _soaMail + " " + std::to_string(time(nullptr)) + " " + std::to_string(_soaRefresh)
84
+             + " " + std::to_string(_soaRetry)+ " " + std::to_string(_soaExpire) + " " + std::to_string(_soaTtl);
85
+
13 86
     return "INSERT INTO domains (name, type) VALUES (\"" + _domain + "\", \"MASTER\");\n"
14
-            "INSERT INTO zones (domain_id, owner, zone_templ_id) VALUES ((SELECT id FROM domains WHERE name=\""
15
-           + _domain + "\"), (SELECT id FROM users ORDER BY id LIMIT 1), 0);";
87
+            "SET @domain_id=(SELECT id FROM domains WHERE name=\"" + _domain + "\");\n"
88
+            "INSERT INTO zones (domain_id, owner, zone_templ_id) VALUES (@domain_id, "
89
+            "(SELECT id FROM users ORDER BY id LIMIT 1), 0);\n"
90
+            "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date)\n"
91
+            "    VALUES(@domain_id, \"" + _domain + "\", \"SOA\","
92
+            " \"" + soa + "\", " + std::to_string(_ttl) + ", 0, " + std::to_string(time(nullptr)) + ");\n";
16 93
 }

+ 43
- 0
src/DBO/Actions/ActionAddDomain.h 查看文件

@@ -12,8 +12,51 @@ class ActionAddDomain : public Action
12 12
 public:
13 13
     ActionAddDomain();
14 14
 
15
+    int getSoaRefresh() const;
16
+
17
+    void setSoaRefresh(int soaRefresh);
18
+
19
+    int getSoaRetry() const;
20
+
21
+    void setSoaRetry(int soaRetry);
22
+
23
+    int getSoaExpire() const;
24
+
25
+    void setSoaExpire(int soaExpire);
26
+
27
+    int getSoaTtl() const;
28
+
29
+    void setSoaTtl(int soaTtl);
30
+
31
+    int getTtl() const;
32
+
33
+    void setTtl(int ttl);
34
+
35
+    const std::string &getSoaNs() const;
36
+
37
+    void setSoaNs(const std::string &soaNs);
38
+
39
+    const std::string &getSoaMail() const;
40
+
41
+    void setSoaMail(const std::string &soaMail);
42
+
15 43
 protected:
16 44
     const std::string getSql() const override;
45
+
46
+private:
47
+    std::string _soaNs;
48
+
49
+    std::string _soaMail;
50
+
51
+    int _soaRefresh;
52
+
53
+    int _soaRetry;
54
+
55
+    int _soaExpire;
56
+
57
+    int _soaTtl;
58
+
59
+    int _ttl;
17 60
 };
18 61
 
19 62
 

+ 11
- 1
src/DBO/Actions/ActionAddHost.cpp 查看文件

@@ -30,7 +30,7 @@ const std::string ActionAddHost::getSql() const
30 30
     auto host = _host.empty() ? _domain : _host + "." + _domain;
31 31
     auto query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date)\n"
32 32
             "    VALUES(@domain_id, \"" + host + "\", \"" + _recordType + "\","
33
-            " \"" + _recordValue + "\", 84600, 0, " + std::to_string(time(nullptr)) + ");\n";
33
+            " \"" + _recordValue + "\", " + std::to_string(_ttl) + ", 0, " + std::to_string(time(nullptr)) + ");\n";
34 34
 
35 35
     if (_reverseEnabled && _recordType == "A")
36 36
     {
@@ -105,6 +105,16 @@ void ActionAddHost::setReverseEnabled(bool reverseEnabled)
105 105
     _reverseEnabled = reverseEnabled;
106 106
 }
107 107
 
108
+int ActionAddHost::getTtl() const
109
+{
110
+    return _ttl;
111
+}
112
+
113
+void ActionAddHost::setTtl(int ttl)
114
+{
115
+    _ttl = ttl;
116
+}
117
+
108 118
 const std::string ActionAddHost::getReversedValue() const
109 119
 {
110 120
     auto splitValue = split(_recordValue, '.');

+ 6
- 0
src/DBO/Actions/ActionAddHost.h 查看文件

@@ -36,6 +36,10 @@ public:
36 36
 
37 37
     void setReverseEnabled(bool reverseEnabled);
38 38
 
39
+    int getTtl() const;
40
+
41
+    void setTtl(int ttl);
42
+
39 43
 protected:
40 44
     const std::string getSql() const override;
41 45
 
@@ -55,6 +59,8 @@ private:
55 59
     std::string _reverseDomain;
56 60
 
57 61
     bool _reverseEnabled;
62
+
63
+    int _ttl;
58 64
 };
59 65
 
60 66
 

+ 10
- 0
src/DataAccess/HostsConfig.cpp 查看文件

@@ -33,6 +33,8 @@
33 33
 
34 34
 #define SET_VALUE_BOOL(VALUE, METHOD) SET_VALUE(VALUE, METHOD, Bool)
35 35
 
36
+#define SET_VALUE_INT(VALUE, METHOD) SET_VALUE(VALUE, METHOD, Int)
37
+
36 38
 HostsConfig::HostsConfig(const std::string &filePath)
37 39
     : _filePath(filePath)
38 40
 {
@@ -129,6 +131,7 @@ std::shared_ptr<Action> HostsConfig::readAddHost(const Json::Value &act, const J
129 131
     SET_VALUE_STRING("dhcp_mac", setDhcpMac);
130 132
     SET_VALUE_STRING("reverse_domain", setReverseDomain);
131 133
     SET_VALUE_BOOL("reverse_enabled", setReverseEnabled);
134
+    SET_VALUE_INT("record_ttl", setTtl);
132 135
     return action;
133 136
 }
134 137
 
@@ -146,6 +149,13 @@ std::shared_ptr<Action> HostsConfig::readAddDomain(const Json::Value &act, const
146 149
 {
147 150
     auto action = std::make_shared<ActionAddDomain>();
148 151
     SET_VALUE_STRING("domain", setDomain);
152
+    SET_VALUE_STRING("soa_ns", setSoaNs);
153
+    SET_VALUE_STRING("soa_mail", setSoaMail);
154
+    SET_VALUE_INT("soa_refresh", setSoaRefresh);
155
+    SET_VALUE_INT("soa_retry", setSoaRetry);
156
+    SET_VALUE_INT("soa_expire", setSoaExpire);
157
+    SET_VALUE_INT("soa_ttl", setSoaTtl);
158
+    SET_VALUE_INT("record_ttl", setTtl);
149 159
     return action;
150 160
 }
151 161
 

正在加载...
取消
保存