|
@@ -82,20 +82,57 @@ BResult PgSql::insertSlave(const std::string &file)
|
82
|
82
|
|
83
|
83
|
std::string PgSql::getAddDomainQuery(const ActionAddDomain &action)
|
84
|
84
|
{
|
85
|
|
- return "";
|
|
85
|
+ auto soa = action.getSoaNs() + " " + action.getSoaMail() + " " + std::to_string(time(nullptr)) + " "
|
|
86
|
+ + std::to_string(action.getSoaRefresh()) + " " + std::to_string(action.getSoaRetry()) + " "
|
|
87
|
+ + std::to_string(action.getSoaExpire()) + " " + std::to_string(action.getSoaTtl());
|
|
88
|
+
|
|
89
|
+ return "INSERT INTO domains (name, type) VALUES (\'" + action.getDomain() + "\', \'MASTER\');\n"
|
|
90
|
+ "INSERT INTO zones (domain_id, owner, zone_templ_id) VALUES "
|
|
91
|
+ "((SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\'), "
|
|
92
|
+ "(SELECT id FROM users ORDER BY id LIMIT 1), 0);\n"
|
|
93
|
+ "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date)\n"
|
|
94
|
+ " VALUES((SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\'), \'"
|
|
95
|
+ + action.getDomain() + "\', \'SOA\', \'" + soa + "\', " + std::to_string(action.getTtl()) + ", 0, "
|
|
96
|
+ + std::to_string(time(nullptr)) + ");\n";
|
86
|
97
|
}
|
87
|
98
|
|
88
|
99
|
std::string PgSql::getAddHostQuery(const ActionAddHost &action)
|
89
|
100
|
{
|
90
|
|
- return "";
|
|
101
|
+ auto host = action.getHost().empty() ? action.getDomain() : action.getHost() + "." + action.getDomain();
|
|
102
|
+ auto query = "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date)\n"
|
|
103
|
+ " VALUES((SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\'), \'"
|
|
104
|
+ + host + "\', \'" + action.getRecordType() + "\', \'"
|
|
105
|
+ + action.getRecordValue() + "\', " + std::to_string(action.getTtl())
|
|
106
|
+ + ", 0, " + std::to_string(time(nullptr)) + ");\n";
|
|
107
|
+
|
|
108
|
+ if (action.isReverseEnabled() && action.getRecordType() == "A")
|
|
109
|
+ {
|
|
110
|
+ auto reversedValue = action.getReversedValue();
|
|
111
|
+ auto reverseDomain = action.getReverseDomain().empty() ? "in-addr.arpa" :
|
|
112
|
+ action.getReverseDomain() + ".in-addr.arpa";
|
|
113
|
+
|
|
114
|
+ query += "INSERT INTO records (domain_id, name, type, content, ttl, prio, change_date)\n"
|
|
115
|
+ " VALUES((SELECT id FROM domains WHERE name=\'" + reverseDomain + "\'), \'"
|
|
116
|
+ + reversedValue + "." + reverseDomain + "\', \'PTR\', \'" + action.getHost()
|
|
117
|
+ + "." + action.getDomain() + "\', " + std::to_string(action.getTtl()) + ", 0, "
|
|
118
|
+ + std::to_string(time(nullptr)) + ");\n";
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ return query;
|
91
|
122
|
}
|
92
|
123
|
|
93
|
124
|
std::string PgSql::getDelDomainQuery(const ActionDelDomain &action)
|
94
|
125
|
{
|
95
|
|
- return "";
|
|
126
|
+ return "DELETE FROM records WHERE domain_id=(SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\');\n"
|
|
127
|
+ "DELETE FROM comments WHERE domain_id=(SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\');\n"
|
|
128
|
+ "DELETE FROM zones WHERE domain_id=(SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\');\n"
|
|
129
|
+ "DELETE FROM cryptokeys WHERE domain_id=(SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\');\n"
|
|
130
|
+ "DELETE FROM domainmetadata WHERE domain_id=(SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\');\n"
|
|
131
|
+ "DELETE FROM domains WHERE id=(SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\');\n";
|
96
|
132
|
}
|
97
|
133
|
|
98
|
134
|
std::string PgSql::getDelHostQuery(const ActionDelHost &action)
|
99
|
135
|
{
|
100
|
|
- return "";
|
|
136
|
+ return "DELETE FROM records WHERE name=\'" + action.getHost() + "." + action.getDomain() + "\' AND "
|
|
137
|
+ "domain_id=(SELECT id FROM domains WHERE name=\'" + action.getDomain() + "\');";
|
101
|
138
|
}
|