Erzeuge DNS-Records der Form "handle.username.masterdomain" bei jedem neuen DynDNS-Account
Bernd Wurst

Bernd Wurst commited on 2014-07-04 11:42:35
Zeige 2 geänderte Dateien mit 18 Einfügungen und 1 Löschungen.

... ...
@@ -40,12 +40,19 @@ output('<table><tr><th>Hostname</th><th>Typ</th><th>IP-Adresse/Inhalt</th><th>TT
40 40
 ');
41 41
 foreach ($records AS $rec)
42 42
 {
43
+  $editable = true;
43 44
   $data = ( $rec['ip'] ? $rec['ip'] : $rec['data'] );
44 45
   if ($rec['dyndns'])
45 46
   {
47
+    if ($domain->fqdn == config('masterdomain'))
48
+    { 
49
+      $data = '<em>DynDNS #'.$rec['dyndns'].'</em>';
50
+      $editable = false;
51
+    } else {
46 52
       $dyndns = get_dyndns_account($rec['dyndns']);
47 53
       $data = internal_link('dyndns_edit', '<em>DynDNS #'.$rec['dyndns'].' ('.$dyndns['handle'].')</em>', 'id='.$rec['dyndns']);
48 54
     }
55
+  }
49 56
   if ($rec['type'] == 'mx')
50 57
   {
51 58
     $data .= ' ('.$rec['spec'].')';
... ...
@@ -56,7 +63,10 @@ foreach ($records AS $rec)
56 63
   }
57 64
   $ttl = ($rec['ttl'] ? $rec['ttl'] : 3600);
58 65
   $link = $rec['fqdn'];
59
-  if (in_array($rec['type'], array('a', 'aaaa', 'mx', 'cname', 'ns', 'txt', 'spf', 'ptr', 'sshfp'))) {
66
+  if (!in_array($rec['type'], array('a', 'aaaa', 'mx', 'cname', 'ns', 'txt', 'spf', 'ptr', 'sshfp'))) {
67
+      $editable = false;
68
+  }
69
+  if ($editable) {
60 70
       $link = internal_link('dns_record_edit', $rec['fqdn'], "id={$rec['id']}");
61 71
   }
62 72
   output("<tr><td>{$link}</td><td>".strtoupper($rec['type'])."</td><td>$data</td><td>{$ttl} Sek.</td><td>".internal_link('dns_record_save', '<img src="'.$prefix.'images/delete.png" width="16" height="16" alt="löschen" title="Record löschen" />', "id={$rec['id']}&action=delete")."</td></tr>\n");
... ...
@@ -67,6 +67,11 @@ function create_dyndns_account($handle, $password_http, $sshkey)
67 67
   db_query("INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
68 68
            "(:uid, :handle, :pwhash, :sshkey)",
69 69
            array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey));
70
+  $dyndns_id = db_insert_id();
71
+  $masterdomain = new Domain(config('masterdomain'));
72
+  db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
73
+           "('a', :dom, :hostname, :dyndns, 120)",
74
+           array(":dom" => $masterdomain->id, ":hostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'], ":dyndns" => $dyndns_id));
70 75
   logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account");
71 76
 }
72 77
 
... ...
@@ -108,7 +113,9 @@ function get_dyndns_records($id)
108 113
   $data = array();
109 114
   while ($entry = $result->fetch()) {
110 115
     $dom = new Domain((int) $entry['domain']);
116
+    if ($dom->fqdn != config('masterdomain')) {
111 117
       $dom->ensure_userdomain();
118
+    }
112 119
     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
113 120
     if (! $entry['hostname'])
114 121
       $entry['fqdn'] = $dom->fqdn;
115 122