added support for SRV records and warning at collission
Bernd Wurst

Bernd Wurst commited on 2020-05-01 08:07:42
Zeige 3 geänderte Dateien mit 39 Einfügungen und 5 Löschungen.

... ...
@@ -72,7 +72,7 @@ foreach ($records as $rec) {
72 72
             }
73 73
         }
74 74
     }
75
-    if ($rec['type'] == 'mx') {
75
+    if ($rec['type'] == 'mx' || $rec['type'] == 'srv') {
76 76
         $data .= ' ('.(int) $rec['spec'].')';
77 77
     }
78 78
     if ($rec['type'] == 'sshfp') {
... ...
@@ -83,7 +83,7 @@ foreach ($records as $rec) {
83 83
     }
84 84
     $ttl = ($rec['ttl'] ? $rec['ttl'] : 3600);
85 85
     $link = $rec['fqdn'];
86
-    if (!in_array($rec['type'], array('a', 'aaaa', 'mx', 'cname', 'ns', 'txt', 'spf', 'ptr', 'sshfp', 'caa'))) {
86
+    if (!in_array($rec['type'], array('a', 'aaaa', 'mx', 'cname', 'ns', 'txt', 'spf', 'ptr', 'sshfp', 'srv', 'caa'))) {
87 87
         $editable = false;
88 88
     }
89 89
     $delete = internal_link('dns_record_save', icon_delete('Record löschen'), "id={$rec['id']}&action=delete");
... ...
@@ -98,6 +98,9 @@ foreach ($records as $rec) {
98 98
 }
99 99
 foreach ($auto_records as $rec) {
100 100
     $data = filter_output_html($rec['ip'] ? $rec['ip'] : $rec['data']);
101
+    if ($rec['type'] == 'mx' || $rec['type'] == 'srv') {
102
+        $data .= ' ('.(int) $rec['spec'].')';
103
+    }
101 104
     $ttl = ($rec['ttl'] ? $rec['ttl'] : 3600);
102 105
     output("<tr><td><em>{$rec['fqdn']}</em></td><td>".strtoupper($rec['type'])."</td><td>$data</td><td>{$ttl} Sek.</td><td>&#160;</td></tr>\n");
103 106
 }
... ...
@@ -128,6 +131,7 @@ output('<h4>Neuen DNS-Record anlegen</h4>
128 131
 <li>'.internal_link('dns_record_edit', 'TXT', 'id=new&type=txt&domain='.$domain->id).'</li>
129 132
 <li>'.internal_link('dns_record_edit', 'SSHFP', 'id=new&type=sshfp&domain='.$domain->id).'</li>
130 133
 <li>'.internal_link('dns_record_edit', 'CAA', 'id=new&type=caa&domain='.$domain->id).'</li>
134
+<li>'.internal_link('dns_record_edit', 'SRV', 'id=new&type=srv&domain='.$domain->id).'</li>
131 135
 </ul>
132 136
 
133 137
 <h4>Automatische DNS-Records</h4>
... ...
@@ -173,6 +173,14 @@ if ($type == 'mx') {
173 173
 }
174 174
 
175 175
 
176
+if ($type == 'srv') {
177
+    $form .= '
178
+<tr><td><label for="spec">Priorität:</label></td><td><input type="text" name="spec" id="spec" value="'.$data['spec'].'" /></td></tr>
179
+<tr><td><label for="data">Ziel (Server:Port):</label></td><td><input type="text" name="data" id="data" value="'.$data['data'].'" /></td></tr>
180
+';
181
+}
182
+
183
+
176 184
 output(html_form('dns_record_edit', 'dns_record_save', "type={$type}&domain={$domain->id}&id={$_REQUEST['id']}", '<table>
177 185
 <tr><td><label for="hostname">Hostname:</label></td><td><input type="text" name="hostname" id="hostname" value="'.$data['hostname'].'" />&#160;<strong>.'.$domain->fqdn.'</strong></td></tr>
178 186
 '.$form.'
... ...
@@ -151,7 +151,7 @@ function get_dyndns_records($id)
151 151
     return $data;
152 152
 }
153 153
 
154
-$valid_record_types = array('a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw', 'sshfp', 'caa');
154
+$valid_record_types = array('a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw', 'sshfp', 'caa', 'srv');
155 155
 
156 156
 
157 157
 function blank_dns_record($type)
... ...
@@ -220,6 +220,17 @@ function get_domain_auto_records($domainname)
220 220
 }
221 221
 
222 222
 
223
+function warn_autorecord_collission($hostname, $domain, $type) {
224
+    $autorecords = get_domain_auto_records($domain);
225
+    foreach ($autorecords as $ar) {
226
+        if ($ar['hostname'] == $hostname && $ar['type'] == $type) {
227
+            warning('Sie haben einen DNS-Record angelegt, für den bisher ein automatisch erzeuger Record vorhanden war. Ihr neuer Eintrag wird den bisherigen ersetzen. Bitte haben Sie einen Moment Geduld und laden Sie diese Seite in wenigen Minuten neu. Der automatisch erzeute Record sollte dann verschwunden sein.');
228
+            break;
229
+        }
230
+    }
231
+}
232
+
233
+
223 234
 $implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv', 'ns', 'sshfp', 'caa');
224 235
 
225 236
 function save_dns_record($id, $record)
... ...
@@ -246,6 +257,7 @@ function save_dns_record($id, $record)
246 257
     if ($record['ttl'] &&  (int) $record['ttl'] < 1) {
247 258
         system_failure('Fehler bei TTL');
248 259
     }
260
+    warn_autorecord_collission($record['hostname'], $dom->fqdn, $record['type']);
249 261
     switch ($record['type']) {
250 262
     case 'a':
251 263
       if ($record['dyndns']) {
... ...
@@ -324,8 +336,18 @@ function save_dns_record($id, $record)
324 336
       break;
325 337
 
326 338
     case 'srv':
327
-      system_failure('not implemented yet');
328
-      // no break
339
+      $record['dyndns'] = null;
340
+      $record['spec'] = (int) $record['spec'];
341
+      if ($record['spec'] < 0) {
342
+          system_failure("invalid priority");
343
+      }
344
+      if (! $record['data']) {
345
+          system_failure('SRV target missing');
346
+      }
347
+      list($hostname, $port) = explode(':', $record['data'], 2);
348
+      verify_input_hostname($hostname);
349
+      $record['ip'] = null;
350
+      break;
329 351
     default:
330 352
       system_failure('Not implemented');
331 353
   }
332 354