Robin Thoni 8 лет назад
Родитель
Сommit
08d8a407c8
3 измененных файлов: 44 добавлений и 8 удалений
  1. 2
    2
      conf/hosts.json.default
  2. 1
    2
      src/DataAccess/MySql.cpp
  3. 41
    4
      src/DataAccess/PgSql.cpp

+ 2
- 2
conf/hosts.json.default Просмотреть файл

@@ -6,10 +6,10 @@
6 6
     "reverse_enabled": true,
7 7
     "record_type": "A",
8 8
     "dhcp_mac": "",
9
-    "record_ttl": 84600,
9
+    "record_ttl": 600,
10 10
     "soa_ns": "ns.example.com",
11 11
     "soa_mail": "root.example.com",
12
-    "soa_refresh": 86400,
12
+    "soa_refresh": 600,
13 13
     "soa_retry": 7200,
14 14
     "soa_expire": 3600000,
15 15
     "soa_ttl": 172800

+ 1
- 2
src/DataAccess/MySql.cpp Просмотреть файл

@@ -85,8 +85,7 @@ std::string MySql::getAddDomainQuery(const ActionAddDomain &action)
85 85
                + std::to_string(action.getSoaRefresh()) + " " + std::to_string(action.getSoaRetry()) + " "
86 86
                + std::to_string(action.getSoaExpire()) + " " + std::to_string(action.getSoaTtl());
87 87
 
88
-    return "SET @domain_id=(SELECT id FROM domains WHERE name=\"" + action.getDomain() + "\");\n"
89
-            "INSERT INTO domains (name, type) VALUES (\"" + action.getDomain() + "\", \"MASTER\");\n"
88
+    return "INSERT INTO domains (name, type) VALUES (\"" + action.getDomain() + "\", \"MASTER\");\n"
90 89
             "SET @domain_id=(SELECT id FROM domains WHERE name=\"" + action.getDomain() + "\");\n"
91 90
                    "INSERT INTO zones (domain_id, owner, zone_templ_id) VALUES (@domain_id, "
92 91
                    "(SELECT id FROM users ORDER BY id LIMIT 1), 0);\n"

+ 41
- 4
src/DataAccess/PgSql.cpp Просмотреть файл

@@ -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
 }

Загрузка…
Отмена
Сохранить