Browse Source

add domain automatic soa

develop
Robin Thoni 9 years ago
parent
commit
d3441e14b5

+ 8
- 1
conf/hosts.json.default View File

5
     "reverse_domain": "1.168.192",
5
     "reverse_domain": "1.168.192",
6
     "reverse_enabled": true,
6
     "reverse_enabled": true,
7
     "record_type": "A",
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
   "actions":[
17
   "actions":[
11
   {
18
   {

+ 80
- 3
src/DBO/Actions/ActionAddDomain.cpp View File

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
     return "INSERT INTO domains (name, type) VALUES (\"" + _domain + "\", \"MASTER\");\n"
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 View File

12
 public:
12
 public:
13
     ActionAddDomain();
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
 protected:
43
 protected:
16
     const std::string getSql() const override;
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 View File

30
     auto host = _host.empty() ? _domain : _host + "." + _domain;
30
     auto host = _host.empty() ? _domain : _host + "." + _domain;
31
     auto query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date)\n"
31
     auto query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date)\n"
32
             "    VALUES(@domain_id, \"" + host + "\", \"" + _recordType + "\","
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
     if (_reverseEnabled && _recordType == "A")
35
     if (_reverseEnabled && _recordType == "A")
36
     {
36
     {
105
     _reverseEnabled = reverseEnabled;
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
 const std::string ActionAddHost::getReversedValue() const
118
 const std::string ActionAddHost::getReversedValue() const
109
 {
119
 {
110
     auto splitValue = split(_recordValue, '.');
120
     auto splitValue = split(_recordValue, '.');

+ 6
- 0
src/DBO/Actions/ActionAddHost.h View File

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

+ 10
- 0
src/DataAccess/HostsConfig.cpp View File

33
 
33
 
34
 #define SET_VALUE_BOOL(VALUE, METHOD) SET_VALUE(VALUE, METHOD, Bool)
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
 HostsConfig::HostsConfig(const std::string &filePath)
38
 HostsConfig::HostsConfig(const std::string &filePath)
37
     : _filePath(filePath)
39
     : _filePath(filePath)
38
 {
40
 {
129
     SET_VALUE_STRING("dhcp_mac", setDhcpMac);
131
     SET_VALUE_STRING("dhcp_mac", setDhcpMac);
130
     SET_VALUE_STRING("reverse_domain", setReverseDomain);
132
     SET_VALUE_STRING("reverse_domain", setReverseDomain);
131
     SET_VALUE_BOOL("reverse_enabled", setReverseEnabled);
133
     SET_VALUE_BOOL("reverse_enabled", setReverseEnabled);
134
+    SET_VALUE_INT("record_ttl", setTtl);
132
     return action;
135
     return action;
133
 }
136
 }
134
 
137
 
146
 {
149
 {
147
     auto action = std::make_shared<ActionAddDomain>();
150
     auto action = std::make_shared<ActionAddDomain>();
148
     SET_VALUE_STRING("domain", setDomain);
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
     return action;
159
     return action;
150
 }
160
 }
151
 
161
 

Loading…
Cancel
Save