Browse code

remove obsolete code

Bernd Wurst authored on06/02/2021 17:16:09
Showing1 changed files
... ...
@@ -100,16 +100,6 @@ function edit_dyndns_account($id, $handle, $password_http, $sshkey)
100 100
         $sshkey = null;
101 101
     }
102 102
 
103
-    if ($oldaccount['handle'] != $handle) {
104
-        $masterdomain = new Domain(config('masterdomain'));
105
-        db_query(
106
-            "UPDATE dns.custom_records SET hostname=:newhostname WHERE ".
107
-             "hostname=:oldhostname AND domain=:dom AND dyndns=:dyndns AND ip IS NULL",
108
-            array(":dom" => $masterdomain->id, ":newhostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'],
109
-                   ":oldhostname" => $oldaccount['handle'].'.'.$_SESSION['userinfo']['username'],  ":dyndns" => $id)
110
-        );
111
-    }
112
-
113 103
     $args = array(":handle" => $handle, ":sshkey" => $sshkey, ":id" => $id);
114 104
     $pwhash = null;
115 105
     if ($password_http && $password_http != '************') {
Browse code

more robust SRV record filter, disallow multiple :, negative and too high port numbers

Hanno Böck authored on07/05/2020 11:46:41
Showing1 changed files
... ...
@@ -345,13 +345,13 @@ function save_dns_record($id, $record)
345 345
       if (! $record['data']) {
346 346
           system_failure('SRV target missing');
347 347
       }
348
-      $data = explode(':', $record['data'], 2);
348
+      $data = explode(':', $record['data']);
349 349
       if (count($data) != 2) {
350 350
           system_failure('Das eingegebene Ziel war nicht im Format hostname:port');
351 351
       }
352 352
       list($hostname, $port) = $data;
353 353
       verify_input_hostname($hostname);
354
-      if ($port != (int) $port || $port == 0) {
354
+      if ($port !== (string)(int) $port || (int)$port < 1 || (int)$port > 65535) {
355 355
           system_failure('Ungültige Portnummer');
356 356
       }
357 357
       $record['ip'] = null;
Browse code

validate SRV record data field

Bernd Wurst authored on06/05/2020 18:44:00
Showing1 changed files
... ...
@@ -345,8 +345,15 @@ function save_dns_record($id, $record)
345 345
       if (! $record['data']) {
346 346
           system_failure('SRV target missing');
347 347
       }
348
-      list($hostname, $port) = explode(':', $record['data'], 2);
348
+      $data = explode(':', $record['data'], 2);
349
+      if (count($data) != 2) {
350
+          system_failure('Das eingegebene Ziel war nicht im Format hostname:port');
351
+      }
352
+      list($hostname, $port) = $data;
349 353
       verify_input_hostname($hostname);
354
+      if ($port != (int) $port || $port == 0) {
355
+          system_failure('Ungültige Portnummer');
356
+      }
350 357
       $record['ip'] = null;
351 358
       break;
352 359
     default:
Browse code

fix codingstyle

Hanno Böck authored on02/05/2020 12:01:35
Showing1 changed files
... ...
@@ -220,7 +220,8 @@ function get_domain_auto_records($domainname)
220 220
 }
221 221
 
222 222
 
223
-function warn_autorecord_collission($hostname, $domain, $type) {
223
+function warn_autorecord_collission($hostname, $domain, $type)
224
+{
224 225
     $autorecords = get_domain_auto_records($domain);
225 226
     foreach ($autorecords as $ar) {
226 227
         if ($ar['hostname'] == $hostname && $ar['type'] == $type) {
Browse code

added support for SRV records and warning at collission

Bernd Wurst authored on01/05/2020 08:07:42
Showing1 changed files
... ...
@@ -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
   }
Browse code

Fix codingstyle

Hanno authored on27/10/2019 08:54:14
Showing1 changed files
... ...
@@ -79,7 +79,7 @@ function create_dyndns_account($handle, $password_http, $sshkey)
79 79
         "INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
80 80
            "(:uid, :handle, :pwhash, :sshkey)",
81 81
         array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey)
82
-  );
82
+    );
83 83
     $dyndns_id = db_insert_id();
84 84
     //$masterdomain = new Domain(config('masterdomain'));
85 85
     //db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
... ...
@@ -107,7 +107,7 @@ function edit_dyndns_account($id, $handle, $password_http, $sshkey)
107 107
              "hostname=:oldhostname AND domain=:dom AND dyndns=:dyndns AND ip IS NULL",
108 108
             array(":dom" => $masterdomain->id, ":newhostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'],
109 109
                    ":oldhostname" => $oldaccount['handle'].'.'.$_SESSION['userinfo']['username'],  ":dyndns" => $id)
110
-    );
110
+        );
111 111
     }
112 112
 
113 113
     $args = array(":handle" => $handle, ":sshkey" => $sshkey, ":id" => $id);
Browse code

Umstellung von filter_input_general() auf filter_output_html()

Bernd Wurst authored on21/09/2019 17:07:48
Showing1 changed files
... ...
@@ -62,7 +62,7 @@ function create_dyndns_account($handle, $password_http, $sshkey)
62 62
         system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');
63 63
     }
64 64
 
65
-    $handle = filter_input_username($handle);
65
+    $handle = verify_input_identifier($handle);
66 66
 
67 67
     if (strlen(trim($sshkey)) == 0) {
68 68
         $sshkey = null;
... ...
@@ -94,9 +94,9 @@ function edit_dyndns_account($id, $handle, $password_http, $sshkey)
94 94
 {
95 95
     $id = (int) $id;
96 96
     $oldaccount = get_dyndns_account($id);
97
-    $handle = filter_input_username($handle);
98
-    $sshkey = filter_input_general($sshkey);
99
-    if (chop($sshkey) == '') {
97
+    $handle = verify_input_identifier($handle);
98
+    $sshkey = verify_input_ascii($sshkey);
99
+    if (trim($sshkey) == '') {
100 100
         $sshkey = null;
101 101
     }
102 102
 
Browse code

Update codingstyle according to latest PHP CS Fixer 2.14.2

Hanno authored on28/03/2019 18:56:56
Showing1 changed files
... ...
@@ -76,9 +76,9 @@ function create_dyndns_account($handle, $password_http, $sshkey)
76 76
     }
77 77
 
78 78
     db_query(
79
-      "INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
79
+        "INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
80 80
            "(:uid, :handle, :pwhash, :sshkey)",
81
-           array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey)
81
+        array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey)
82 82
   );
83 83
     $dyndns_id = db_insert_id();
84 84
     //$masterdomain = new Domain(config('masterdomain'));
... ...
@@ -103,9 +103,9 @@ function edit_dyndns_account($id, $handle, $password_http, $sshkey)
103 103
     if ($oldaccount['handle'] != $handle) {
104 104
         $masterdomain = new Domain(config('masterdomain'));
105 105
         db_query(
106
-        "UPDATE dns.custom_records SET hostname=:newhostname WHERE ".
106
+            "UPDATE dns.custom_records SET hostname=:newhostname WHERE ".
107 107
              "hostname=:oldhostname AND domain=:dom AND dyndns=:dyndns AND ip IS NULL",
108
-             array(":dom" => $masterdomain->id, ":newhostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'],
108
+            array(":dom" => $masterdomain->id, ":newhostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'],
109 109
                    ":oldhostname" => $oldaccount['handle'].'.'.$_SESSION['userinfo']['username'],  ":dyndns" => $id)
110 110
     );
111 111
     }
Browse code

Fixed mx-priority can be 0 (and typo in error handling)

Bernd Wurst authored on04/01/2019 15:37:42
Showing1 changed files
... ...
@@ -271,8 +271,8 @@ function save_dns_record($id, $record)
271 271
     case 'mx':
272 272
       $record['dyndns'] = null;
273 273
       $record['spec'] = (int) $record['spec'];
274
-      if ($record['spec'] < 1) {
275
-          systen_failure("invalid priority");
274
+      if ($record['spec'] < 0) {
275
+          system_failure("invalid priority");
276 276
       }
277 277
       verify_input_hostname($record['data']);
278 278
       if (! $record['data']) {
Browse code

remove whitespace in empty lines

Hanno authored on26/06/2018 23:36:40
Showing1 changed files
... ...
@@ -429,14 +429,14 @@ function check_dns($domainname, $tld)
429 429
         $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+)$/", '\1', $line);
430 430
         $tld_ns[$tld] = $NS;
431 431
     }
432
-  
432
+
433 433
     $resp = shell_exec('dig @'.$tld_ns[$tld].' +noall +authority -t ns '.$domain.'.');
434 434
     $line = explode("\n", $resp, 2)[0];
435 435
     if (preg_match('/^.*\\sIN\\s+NS\\s+/', $line) === 0) {
436 436
         return "NXDOMAIN";
437 437
     }
438 438
     $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+).$/", '\1', $line);
439
-  
439
+
440 440
     $own_ns = own_ns();
441 441
 
442 442
     if (in_array($NS, $own_ns)) {
Browse code

Fix coding style with php-cs-checker, see https://cs.sensiolabs.org/

Hanno authored on26/06/2018 13:58:19
Showing1 changed files
... ...
@@ -8,7 +8,7 @@ Written 2008-2018 by schokokeks.org Hosting, namely
8 8
 
9 9
 To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10 10
 
11
-You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
12 12
 http://creativecommons.org/publicdomain/zero/1.0/
13 13
 
14 14
 Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
... ...
@@ -23,192 +23,200 @@ require_once('class/domain.php');
23 23
 
24 24
 $caa_properties= array( 0 => "issue", 1 => "issuewild", 2 => "iodef" );
25 25
 
26
-function get_dyndns_accounts() 
26
+function get_dyndns_accounts()
27 27
 {
28
-  $uid = (int) $_SESSION['userinfo']['uid'];
29
-  $result = db_query("SELECT * FROM dns.dyndns WHERE uid=?", array($uid));
30
-  $list = array();
31
-  while ($item = $result->fetch()) {
32
-    array_push($list, $item);
33
-  }
34
-  DEBUG($list);
35
-  return $list;
28
+    $uid = (int) $_SESSION['userinfo']['uid'];
29
+    $result = db_query("SELECT * FROM dns.dyndns WHERE uid=?", array($uid));
30
+    $list = array();
31
+    while ($item = $result->fetch()) {
32
+        array_push($list, $item);
33
+    }
34
+    DEBUG($list);
35
+    return $list;
36 36
 }
37 37
 
38 38
 
39
-function get_dyndns_account($id, $ignore=true) 
39
+function get_dyndns_account($id, $ignore=true)
40 40
 {
41
-  $args = array(":id" => (int) $id,
41
+    $args = array(":id" => (int) $id,
42 42
                 ":uid" => (int) $_SESSION['userinfo']['uid']);
43
-  $result = db_query("SELECT * FROM dns.dyndns WHERE id=:id AND uid=:uid", $args);
44
-  if ($result->rowCount() != 1) {
45
-    if ($ignore) {
46
-      return NULL;
47
-    } 
48
-    logger(LOG_WARNING, "modules/dns/include/dnsinclude", "dyndns", "account »{$id}« invalid for uid »{$_SESSION['userinfo']['uid']}«.");
49
-    system_failure("Account ungültig");
50
-  }
51
-  $item = $result->fetch();
52
-  DEBUG($item);
53
-  return $item;
43
+    $result = db_query("SELECT * FROM dns.dyndns WHERE id=:id AND uid=:uid", $args);
44
+    if ($result->rowCount() != 1) {
45
+        if ($ignore) {
46
+            return null;
47
+        }
48
+        logger(LOG_WARNING, "modules/dns/include/dnsinclude", "dyndns", "account »{$id}« invalid for uid »{$_SESSION['userinfo']['uid']}«.");
49
+        system_failure("Account ungültig");
50
+    }
51
+    $item = $result->fetch();
52
+    DEBUG($item);
53
+    return $item;
54 54
 }
55 55
 
56 56
 
57 57
 function create_dyndns_account($handle, $password_http, $sshkey)
58 58
 {
59
-  $uid = (int) $_SESSION['userinfo']['uid'];
59
+    $uid = (int) $_SESSION['userinfo']['uid'];
60 60
 
61
-  if ($password_http == '' && $sshkey == '')
62
-    system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');  
61
+    if ($password_http == '' && $sshkey == '') {
62
+        system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');
63
+    }
63 64
 
64
-  $handle = filter_input_username($handle);
65
+    $handle = filter_input_username($handle);
65 66
 
66
-  if (strlen(trim($sshkey)) == 0) {
67
-    $sshkey = NULL;
68
-  } else {
69
-    $sshkey = filter_ssh_key($sshkey);
70
-  }
67
+    if (strlen(trim($sshkey)) == 0) {
68
+        $sshkey = null;
69
+    } else {
70
+        $sshkey = filter_ssh_key($sshkey);
71
+    }
71 72
 
72
-  $pwhash = NULL;
73
-  if ($password_http)
74
-    $pwhash = "{SHA}".base64_encode(sha1($password_http, true));
73
+    $pwhash = null;
74
+    if ($password_http) {
75
+        $pwhash = "{SHA}".base64_encode(sha1($password_http, true));
76
+    }
75 77
 
76
-  db_query("INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
78
+    db_query(
79
+      "INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
77 80
            "(:uid, :handle, :pwhash, :sshkey)",
78
-           array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey));
79
-  $dyndns_id = db_insert_id();
80
-  //$masterdomain = new Domain(config('masterdomain'));
81
-  //db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
82
-  //         "('a', :dom, :hostname, :dyndns, 120)",
83
-  //         array(":dom" => $masterdomain->id, ":hostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'], ":dyndns" => $dyndns_id));
84
-  logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account {$dyndns_id}");
85
-  return $dyndns_id;
81
+           array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey)
82
+  );
83
+    $dyndns_id = db_insert_id();
84
+    //$masterdomain = new Domain(config('masterdomain'));
85
+    //db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
86
+    //         "('a', :dom, :hostname, :dyndns, 120)",
87
+    //         array(":dom" => $masterdomain->id, ":hostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'], ":dyndns" => $dyndns_id));
88
+    logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account {$dyndns_id}");
89
+    return $dyndns_id;
86 90
 }
87 91
 
88 92
 
89 93
 function edit_dyndns_account($id, $handle, $password_http, $sshkey)
90 94
 {
91
-  $id = (int) $id;
92
-  $oldaccount = get_dyndns_account($id);
93
-  $handle = filter_input_username($handle);
94
-  $sshkey = filter_input_general($sshkey);
95
-  if (chop($sshkey) == '') {
96
-    $sshkey = NULL;
97
-  }
95
+    $id = (int) $id;
96
+    $oldaccount = get_dyndns_account($id);
97
+    $handle = filter_input_username($handle);
98
+    $sshkey = filter_input_general($sshkey);
99
+    if (chop($sshkey) == '') {
100
+        $sshkey = null;
101
+    }
98 102
 
99
-  if ($oldaccount['handle'] != $handle) {
100
-    $masterdomain = new Domain(config('masterdomain'));
101
-    db_query("UPDATE dns.custom_records SET hostname=:newhostname WHERE ".
103
+    if ($oldaccount['handle'] != $handle) {
104
+        $masterdomain = new Domain(config('masterdomain'));
105
+        db_query(
106
+        "UPDATE dns.custom_records SET hostname=:newhostname WHERE ".
102 107
              "hostname=:oldhostname AND domain=:dom AND dyndns=:dyndns AND ip IS NULL",
103 108
              array(":dom" => $masterdomain->id, ":newhostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'],
104
-                   ":oldhostname" => $oldaccount['handle'].'.'.$_SESSION['userinfo']['username'],  ":dyndns" => $id));
105
-
106
-  }
109
+                   ":oldhostname" => $oldaccount['handle'].'.'.$_SESSION['userinfo']['username'],  ":dyndns" => $id)
110
+    );
111
+    }
107 112
 
108
-  $args = array(":handle" => $handle, ":sshkey" => $sshkey, ":id" => $id);
109
-  $pwhash = NULL;
110
-  if ($password_http && $password_http != '************') {
111
-      $args[":pwhash"] = "{SHA}".base64_encode(sha1($password_http, true));
112
-      db_query("UPDATE dns.dyndns SET handle=:handle, password=:pwhash, sshkey=:sshkey WHERE id=:id", $args);
113
-  } else {
114
-      db_query("UPDATE dns.dyndns SET handle=:handle, sshkey=:sshkey WHERE id=:id", $args);
115
-  }
116
-  logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "edited account »{$id}«");
113
+    $args = array(":handle" => $handle, ":sshkey" => $sshkey, ":id" => $id);
114
+    $pwhash = null;
115
+    if ($password_http && $password_http != '************') {
116
+        $args[":pwhash"] = "{SHA}".base64_encode(sha1($password_http, true));
117
+        db_query("UPDATE dns.dyndns SET handle=:handle, password=:pwhash, sshkey=:sshkey WHERE id=:id", $args);
118
+    } else {
119
+        db_query("UPDATE dns.dyndns SET handle=:handle, sshkey=:sshkey WHERE id=:id", $args);
120
+    }
121
+    logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "edited account »{$id}«");
117 122
 }
118 123
 
119 124
 
120 125
 function delete_dyndns_account($id)
121 126
 {
122
-  $id = (int) $id;
127
+    $id = (int) $id;
123 128
 
124
-  db_query("DELETE FROM dns.dyndns WHERE id=?", array($id));
125
-  logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "deleted account »{$id}«");
129
+    db_query("DELETE FROM dns.dyndns WHERE id=?", array($id));
130
+    logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "deleted account »{$id}«");
126 131
 }
127 132
 
128 133
 
129 134
 function get_dyndns_records($id)
130 135
 {
131
-  $id = (int) $id;
132
-  $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns=?", array($id));
133
-  $data = array();
134
-  while ($entry = $result->fetch()) {
135
-    $dom = new Domain((int) $entry['domain']);
136
-    if ($dom->fqdn != config('masterdomain') && $dom->fqdn != config('user_vhosts_domain')) {
137
-      $dom->ensure_userdomain();
136
+    $id = (int) $id;
137
+    $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns=?", array($id));
138
+    $data = array();
139
+    while ($entry = $result->fetch()) {
140
+        $dom = new Domain((int) $entry['domain']);
141
+        if ($dom->fqdn != config('masterdomain') && $dom->fqdn != config('user_vhosts_domain')) {
142
+            $dom->ensure_userdomain();
143
+        }
144
+        $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
145
+        if (! $entry['hostname']) {
146
+            $entry['fqdn'] = $dom->fqdn;
147
+        }
148
+        array_push($data, $entry);
138 149
     }
139
-    $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
140
-    if (! $entry['hostname'])
141
-      $entry['fqdn'] = $dom->fqdn;
142
-    array_push($data, $entry);
143
-  }
144
-  DEBUG($data);
145
-  return $data;
150
+    DEBUG($data);
151
+    return $data;
146 152
 }
147 153
 
148 154
 $valid_record_types = array('a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw', 'sshfp', 'caa');
149 155
 
150 156
 
151 157
 function blank_dns_record($type)
152
-{ 
153
-  global $valid_record_types;
154
-  if (!in_array(strtolower($type), $valid_record_types))
155
-    system_failure('invalid type: '.$type);
156
-  $rec = array('hostname' => NULL,
158
+{
159
+    global $valid_record_types;
160
+    if (!in_array(strtolower($type), $valid_record_types)) {
161
+        system_failure('invalid type: '.$type);
162
+    }
163
+    $rec = array('hostname' => null,
157 164
                'domain' => 0,
158 165
                'type' => strtolower($type),
159 166
                'ttl' => 3600,
160
-               'ip' => NULL,
161
-               'dyndns' => NULL,
162
-               'data' => NULL,
163
-               'spec' => NULL);
164
-  if (strtolower($type) == 'mx')
165
-  {
166
-    $rec['data'] = config('default_mx');
167
-    $rec['spec'] = '5';
168
-  }
169
-  return $rec;
167
+               'ip' => null,
168
+               'dyndns' => null,
169
+               'data' => null,
170
+               'spec' => null);
171
+    if (strtolower($type) == 'mx') {
172
+        $rec['data'] = config('default_mx');
173
+        $rec['spec'] = '5';
174
+    }
175
+    return $rec;
170 176
 }
171 177
 
172 178
 function get_dns_record($id)
173 179
 {
174
-  $id = (int) $id;
175
-  $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id=?", array($id));
176
-  if ($result->rowCount() != 1)
177
-    system_failure('illegal ID');
178
-  $data = $result->fetch();
179
-  $dom = new Domain( (int) $data['domain']);
180
-  $dom->ensure_userdomain();
181
-  DEBUG($data);
182
-  return $data;
180
+    $id = (int) $id;
181
+    $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id=?", array($id));
182
+    if ($result->rowCount() != 1) {
183
+        system_failure('illegal ID');
184
+    }
185
+    $data = $result->fetch();
186
+    $dom = new Domain((int) $data['domain']);
187
+    $dom->ensure_userdomain();
188
+    DEBUG($data);
189
+    return $data;
183 190
 }
184 191
 
185 192
 
186 193
 function get_domain_records($dom)
187 194
 {
188
-  $dom = (int) $dom;
189
-  $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl, id FROM dns.custom_records WHERE domain=?", array($dom));
190
-  $data = array();
191
-  while ($entry = $result->fetch()) {
192
-    $dom = new Domain((int) $entry['domain']);
193
-    $dom->ensure_userdomain();
194
-    $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
195
-    if (! $entry['hostname'])
196
-      $entry['fqdn'] = $dom->fqdn;
197
-    array_push($data, $entry);
198
-  }
199
-  DEBUG($data);
200
-  return $data;
195
+    $dom = (int) $dom;
196
+    $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl, id FROM dns.custom_records WHERE domain=?", array($dom));
197
+    $data = array();
198
+    while ($entry = $result->fetch()) {
199
+        $dom = new Domain((int) $entry['domain']);
200
+        $dom->ensure_userdomain();
201
+        $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
202
+        if (! $entry['hostname']) {
203
+            $entry['fqdn'] = $dom->fqdn;
204
+        }
205
+        array_push($data, $entry);
206
+    }
207
+    DEBUG($data);
208
+    return $data;
201 209
 }
202 210
 
203 211
 function get_domain_auto_records($domainname)
204 212
 {
205
-  $result = db_query("SELECT hostname, domain, CONCAT_WS('.', hostname, domain) AS fqdn, type, ip, spec, data, ttl FROM dns.tmp_autorecords WHERE domain=?", array($domainname));
206
-  $data = array();
207
-  while ($entry = $result->fetch()) {
208
-    array_push($data, $entry);
209
-  }
210
-  DEBUG($data);
211
-  return $data;
213
+    $result = db_query("SELECT hostname, domain, CONCAT_WS('.', hostname, domain) AS fqdn, type, ip, spec, data, ttl FROM dns.tmp_autorecords WHERE domain=?", array($domainname));
214
+    $data = array();
215
+    while ($entry = $result->fetch()) {
216
+        array_push($data, $entry);
217
+    }
218
+    DEBUG($data);
219
+    return $data;
212 220
 }
213 221
 
214 222
 
... ...
@@ -216,245 +224,255 @@ $implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr
216 224
 
217 225
 function save_dns_record($id, $record)
218 226
 {
219
-  global $valid_record_types;
220
-  global $implemented_record_types;
221
-  $record['type'] = strtolower($record['type']);
222
-  if (!in_array($record['type'], $valid_record_types))
223
-    system_failure('invalid type: '.$record['type']);
224
-  if (!in_array($record['type'], $implemented_record_types))
225
-    system_failure('record type '.$record['type'].' not implemented at the moment.');
226
-  $dom = new Domain( (int) $record['domain'] );
227
-  $dom->ensure_userdomain();
228
-  if (! $dom->id)
229
-    system_failure('invalid domain');
230
-  if ($record['hostname'] == '') {
231
-    $record['hostname'] = NULL;
232
-  }
233
-  verify_input_hostname($record['hostname'], true);
234
-  verify_input_recorddata($record['data']);
235
-  if ($record['ttl'] &&  (int) $record['ttl'] < 1)
236
-    system_failure('Fehler bei TTL');
237
-  switch ($record['type']) 
238
-  {
227
+    global $valid_record_types;
228
+    global $implemented_record_types;
229
+    $record['type'] = strtolower($record['type']);
230
+    if (!in_array($record['type'], $valid_record_types)) {
231
+        system_failure('invalid type: '.$record['type']);
232
+    }
233
+    if (!in_array($record['type'], $implemented_record_types)) {
234
+        system_failure('record type '.$record['type'].' not implemented at the moment.');
235
+    }
236
+    $dom = new Domain((int) $record['domain']);
237
+    $dom->ensure_userdomain();
238
+    if (! $dom->id) {
239
+        system_failure('invalid domain');
240
+    }
241
+    if ($record['hostname'] == '') {
242
+        $record['hostname'] = null;
243
+    }
244
+    verify_input_hostname($record['hostname'], true);
245
+    verify_input_recorddata($record['data']);
246
+    if ($record['ttl'] &&  (int) $record['ttl'] < 1) {
247
+        system_failure('Fehler bei TTL');
248
+    }
249
+    switch ($record['type']) {
239 250
     case 'a':
240
-      if ($record['dyndns'])
241
-      {
242
-        get_dyndns_account( $record['dyndns'] );
243
-      	$record['ip'] = NULL;
244
-      }
245
-      else
246
-      {
247
-        verify_input_ipv4($record['ip']);
248
-        $record['data'] = NULL;
249
-        $record['spec'] = NULL;
251
+      if ($record['dyndns']) {
252
+          get_dyndns_account($record['dyndns']);
253
+          $record['ip'] = null;
254
+      } else {
255
+          verify_input_ipv4($record['ip']);
256
+          $record['data'] = null;
257
+          $record['spec'] = null;
250 258
       }
251 259
       break;
252 260
     case 'aaaa':
253 261
       if ($record['dyndns']) {
254
-          get_dyndns_account( $record['dyndns'] );
255
-          $record['ip'] = NULL;
262
+          get_dyndns_account($record['dyndns']);
263
+          $record['ip'] = null;
256 264
       } else {
257
-          $record['dyndns'] = NULL;
265
+          $record['dyndns'] = null;
258 266
           verify_input_ipv6($record['ip']);
259
-          $record['data'] = NULL;
260
-          $record['spec'] = NULL;
267
+          $record['data'] = null;
268
+          $record['spec'] = null;
261 269
       }
262 270
       break;
263 271
     case 'mx':
264
-      $record['dyndns'] = NULL;
272
+      $record['dyndns'] = null;
265 273
       $record['spec'] = (int) $record['spec'];
266
-      if ($record['spec'] < 1)
267
-        systen_failure("invalid priority");
274
+      if ($record['spec'] < 1) {
275
+          systen_failure("invalid priority");
276
+      }
268 277
       verify_input_hostname($record['data']);
269
-      if (! $record['data'] )
270
-        system_failure('MX hostname missing');
271
-      $record['ip'] = NULL;
278
+      if (! $record['data']) {
279
+          system_failure('MX hostname missing');
280
+      }
281
+      $record['ip'] = null;
272 282
       break;
273 283
     case 'ptr':
274 284
     case 'ns':
275 285
       if (!$record['hostname']) {
276 286
           system_failure("Die angestrebte Konfiguration wird nicht funktionieren, Speichern wurde daher verweigert.");
277 287
       }
288
+      // no break
278 289
     case 'cname':
279
-      $record['dyndns'] = NULL;
280
-      $record['spec'] = NULL;
281
-      $record['ip'] = NULL;
290
+      $record['dyndns'] = null;
291
+      $record['spec'] = null;
292
+      $record['ip'] = null;
282 293
       verify_input_hostname($record['data']);
283
-      if (! $record['data'] )
284
-        system_failure('destination host missing');
294
+      if (! $record['data']) {
295
+          system_failure('destination host missing');
296
+      }
285 297
       break;
286 298
 
287 299
     case 'spf':
288 300
     case 'txt':
289
-      $record['dyndns'] = NULL;
290
-      $record['spec'] = NULL;
291
-      $record['ip'] = NULL;
292
-      if (! $record['data'] )
293
-        system_failure('text entry missing');
301
+      $record['dyndns'] = null;
302
+      $record['spec'] = null;
303
+      $record['ip'] = null;
304
+      if (! $record['data']) {
305
+          system_failure('text entry missing');
306
+      }
294 307
       break;
295 308
 
296 309
     case 'sshfp':
297
-      $record['dyndns'] = NULL;
298
-      $record['spec'] = max( (int) $record['spec'], 1);
299
-      $record['ip'] = NULL;
300
-      if (! $record['data'] )
301
-        system_failure('text entry missing');
310
+      $record['dyndns'] = null;
311
+      $record['spec'] = max((int) $record['spec'], 1);
312
+      $record['ip'] = null;
313
+      if (! $record['data']) {
314
+          system_failure('text entry missing');
315
+      }
302 316
       break;
303 317
 
304 318
     case 'caa':
305
-      $record['dyndns'] = NULL;
306
-      $record['ip'] = NULL;
307
-      if (! $record['data'] )
308
-        system_failure('text entry missing');
319
+      $record['dyndns'] = null;
320
+      $record['ip'] = null;
321
+      if (! $record['data']) {
322
+          system_failure('text entry missing');
323
+      }
309 324
       break;
310 325
 
311 326
     case 'srv':
312 327
       system_failure('not implemented yet');
328
+      // no break
313 329
     default:
314 330
       system_failure('Not implemented');
315 331
   }
316
-  $id = (int) $id;
317
-  $args = array(":domain" => $dom->id,
332
+    $id = (int) $id;
333
+    $args = array(":domain" => $dom->id,
318 334
                 ":hostname" => $record['hostname'],
319 335
                 ":type" => $record['type'],
320
-                ":ttl" => ($record['ttl'] == 0 ? NULL : (int) $record['ttl']),
336
+                ":ttl" => ($record['ttl'] == 0 ? null : (int) $record['ttl']),
321 337
                 ":ip" => $record['ip'],
322 338
                 ":dyndns" => $record['dyndns'],
323 339
                 ":data" => $record['data'],
324 340
                 ":spec" => $record['spec']);
325
-  if ($id) {
326
-    $args[":id"] = $id;
327
-    db_query("UPDATE dns.custom_records SET hostname=:hostname, domain=:domain, type=:type, ttl=:ttl, ip=:ip, dyndns=:dyndns, data=:data, spec=:spec WHERE id=:id", $args);
328
-  } else {
329
-    db_query("INSERT INTO dns.custom_records (hostname, domain, type, ttl, ip, dyndns, data, spec) VALUES (:hostname, :domain, :type, :ttl, :ip, :dyndns, :data, :spec)", $args);
330
-  }
331
-
341
+    if ($id) {
342
+        $args[":id"] = $id;
343
+        db_query("UPDATE dns.custom_records SET hostname=:hostname, domain=:domain, type=:type, ttl=:ttl, ip=:ip, dyndns=:dyndns, data=:data, spec=:spec WHERE id=:id", $args);
344
+    } else {
345
+        db_query("INSERT INTO dns.custom_records (hostname, domain, type, ttl, ip, dyndns, data, spec) VALUES (:hostname, :domain, :type, :ttl, :ip, :dyndns, :data, :spec)", $args);
346
+    }
332 347
 }
333 348
 
334 349
 
335 350
 function delete_dns_record($id)
336 351
 {
337
-  $id = (int) $id;
338
-  // Diese Funktion prüft, ob der Eintrag einer eigenen Domain gehört
339
-  $record = get_dns_record($id);
340
-  db_query("DELETE FROM dns.custom_records WHERE id=?", array($id));
352
+    $id = (int) $id;
353
+    // Diese Funktion prüft, ob der Eintrag einer eigenen Domain gehört
354
+    $record = get_dns_record($id);
355
+    db_query("DELETE FROM dns.custom_records WHERE id=?", array($id));
341 356
 }
342 357
 
343 358
 
344 359
 function convert_from_autorecords($domainid)
345 360
 {
346
-  $dom = new Domain( (int) $domainid );
347
-  $dom->ensure_userdomain();
348
-  $dom = $dom->id;
349
-
350
-  db_query("INSERT IGNORE INTO dns.custom_records SELECT r.id, r.lastchange, type, d.id, hostname, ip, NULL AS dyndns, data, spec, ttl FROM dns.v_tmptable_allrecords AS r INNER JOIN dns.v_domains AS d ON (d.name=r.domain) WHERE d.id=?", array($dom));
351
-  disable_autorecords($dom);
352
-  db_query("UPDATE dns.dnsstatus SET status='outdated'");
353
-  warning("Die automatischen Einträge werden in Kürze abgeschaltet, bitte haben Sie einen Moment Geduld.");
361
+    $dom = new Domain((int) $domainid);
362
+    $dom->ensure_userdomain();
363
+    $dom = $dom->id;
364
+
365
+    db_query("INSERT IGNORE INTO dns.custom_records SELECT r.id, r.lastchange, type, d.id, hostname, ip, NULL AS dyndns, data, spec, ttl FROM dns.v_tmptable_allrecords AS r INNER JOIN dns.v_domains AS d ON (d.name=r.domain) WHERE d.id=?", array($dom));
366
+    disable_autorecords($dom);
367
+    db_query("UPDATE dns.dnsstatus SET status='outdated'");
368
+    warning("Die automatischen Einträge werden in Kürze abgeschaltet, bitte haben Sie einen Moment Geduld.");
354 369
 }
355 370
 
356 371
 
357 372
 function enable_autorecords($domainid)
358 373
 {
359
-  $dom = new Domain( (int) $domainid );
360
-  $dom->ensure_userdomain();
361
-  $dom = $dom->id;
374
+    $dom = new Domain((int) $domainid);
375
+    $dom->ensure_userdomain();
376
+    $dom = $dom->id;
362 377
 
363
-  db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id=?", array($dom));
364
-  db_query("DELETE FROM dns.custom_records WHERE type='ns' AND domain=? AND hostname IS NULL", array($dom));
365
-  warning("Die automatischen Einträge werden in Kürze aktiviert, bitte haben Sie einen Moment Geduld.");
378
+    db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id=?", array($dom));
379
+    db_query("DELETE FROM dns.custom_records WHERE type='ns' AND domain=? AND hostname IS NULL", array($dom));
380
+    warning("Die automatischen Einträge werden in Kürze aktiviert, bitte haben Sie einen Moment Geduld.");
366 381
 }
367 382
 
368 383
 function disable_autorecords($domainid)
369 384
 {
370
-  $dom = new Domain( (int) $domainid );
371
-  $dom->ensure_userdomain();
372
-  $dom = $dom->id;
385
+    $dom = new Domain((int) $domainid);
386
+    $dom->ensure_userdomain();
387
+    $dom = $dom->id;
373 388
 
374
-  db_query("UPDATE kundendaten.domains SET autodns=0 WHERE id=?", array($dom));
389
+    db_query("UPDATE kundendaten.domains SET autodns=0 WHERE id=?", array($dom));
375 390
 }
376 391
 
377 392
 
378 393
 function domain_is_maildomain($domain)
379 394
 {
380
-  $domain = (int) $domain;
381
-  $result = db_query("SELECT mail FROM kundendaten.domains WHERE id=?", array($domain));
382
-  $dom = $result->fetch();
383
-  return ($dom['mail'] != 'none');
395
+    $domain = (int) $domain;
396
+    $result = db_query("SELECT mail FROM kundendaten.domains WHERE id=?", array($domain));
397
+    $dom = $result->fetch();
398
+    return ($dom['mail'] != 'none');
384 399
 }
385 400
 
386 401
 
387 402
 $own_ns = array();
388 403
 
389
-function own_ns() {
390
-  global $own_ns;
404
+function own_ns()
405
+{
406
+    global $own_ns;
391 407
 
392
-  if (count($own_ns) < 1) {
393
-    $auth = dns_get_record(config('masterdomain'), DNS_NS);
394
-    foreach ($auth as $ns) {
395
-      $own_ns[] = $ns['target'];   
408
+    if (count($own_ns) < 1) {
409
+        $auth = dns_get_record(config('masterdomain'), DNS_NS);
410
+        foreach ($auth as $ns) {
411
+            $own_ns[] = $ns['target'];
412
+        }
396 413
     }
397
-  }
398 414
 
399
-  return $own_ns;  
415
+    return $own_ns;
400 416
 }
401 417
 
402 418
 
403 419
 $tld_ns = array();
404 420
 
405
-function check_dns($domainname, $tld) {
406
-  global $tld_ns;
407
-  $domain=idn_to_ascii($domainname.".".$tld, 0, INTL_IDNA_VARIANT_UTS46);
408
-
409
-  if (! isset($tld_ns[$tld])) {
410
-    $resp = shell_exec('dig @a.root-servers.net. +noall +authority -t ns '.$tld.'.');
411
-    $line = explode("\n", $resp, 2)[0];
412
-    $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+)$/", '\1', $line);
413
-    $tld_ns[$tld] = $NS;
414
-  }
421
+function check_dns($domainname, $tld)
422
+{
423
+    global $tld_ns;
424
+    $domain=idn_to_ascii($domainname.".".$tld, 0, INTL_IDNA_VARIANT_UTS46);
425
+
426
+    if (! isset($tld_ns[$tld])) {
427
+        $resp = shell_exec('dig @a.root-servers.net. +noall +authority -t ns '.$tld.'.');
428
+        $line = explode("\n", $resp, 2)[0];
429
+        $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+)$/", '\1', $line);
430
+        $tld_ns[$tld] = $NS;
431
+    }
415 432
   
416
-  $resp = shell_exec('dig @'.$tld_ns[$tld].' +noall +authority -t ns '.$domain.'.');
417
-  $line = explode("\n", $resp, 2)[0];
418
-  if (preg_match('/^.*\\sIN\\s+NS\\s+/', $line) === 0) {
419
-    return "NXDOMAIN";
420
-  }
421
-  $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+).$/", '\1', $line);
433
+    $resp = shell_exec('dig @'.$tld_ns[$tld].' +noall +authority -t ns '.$domain.'.');
434
+    $line = explode("\n", $resp, 2)[0];
435
+    if (preg_match('/^.*\\sIN\\s+NS\\s+/', $line) === 0) {
436
+        return "NXDOMAIN";
437
+    }
438
+    $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+).$/", '\1', $line);
422 439
   
423
-  $own_ns = own_ns();
440
+    $own_ns = own_ns();
424 441
 
425
-  if (in_array($NS, $own_ns)) {
426
-    return True;
427
-  }
428
-  return $NS;
442
+    if (in_array($NS, $own_ns)) {
443
+        return true;
444
+    }
445
+    return $NS;
429 446
 }
430 447
 
431
-function remove_from_dns($dom) {
432
-  $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
433
-  $current = NULL;
434
-  foreach ($domains as $d) {
435
-    if ($d->id == $dom && $d->dns == 1) {
436
-      $current = $d;
437
-      break;
448
+function remove_from_dns($dom)
449
+{
450
+    $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
451
+    $current = null;
452
+    foreach ($domains as $d) {
453
+        if ($d->id == $dom && $d->dns == 1) {
454
+            $current = $d;
455
+            break;
456
+        }
438 457
     }
439
-  }
440
-  if (! $current) {
441
-    system_failure("Domain nicht gefunden!");
442
-  }
443
-  db_query("UPDATE kundendaten.domains SET dns=0 WHERE id=?", array($current->id));
458
+    if (! $current) {
459
+        system_failure("Domain nicht gefunden!");
460
+    }
461
+    db_query("UPDATE kundendaten.domains SET dns=0 WHERE id=?", array($current->id));
444 462
 }
445 463
 
446
-function add_to_dns($dom) {
447
-  $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
448
-  $current = NULL;
449
-  foreach ($domains as $d) {
450
-    if ($d->id == $dom && $d->dns == 0) {
451
-      $current = $d;
452
-      break;
464
+function add_to_dns($dom)
465
+{
466
+    $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
467
+    $current = null;
468
+    foreach ($domains as $d) {
469
+        if ($d->id == $dom && $d->dns == 0) {
470
+            $current = $d;
471
+            break;
472
+        }
453 473
     }
454
-  }
455
-  if (! $current) {
456
-    system_failure("Domain nicht gefunden!");
457
-  }
458
-  db_query("UPDATE kundendaten.domains SET dns=1, autodns=1 WHERE id=?", array($current->id));
474
+    if (! $current) {
475
+        system_failure("Domain nicht gefunden!");
476
+    }
477
+    db_query("UPDATE kundendaten.domains SET dns=1, autodns=1 WHERE id=?", array($current->id));
459 478
 }
460
-
Browse code

IPv6-support für DynDNS

Bernd Wurst authored on14/05/2018 07:37:12
Showing1 changed files
... ...
@@ -250,10 +250,15 @@ function save_dns_record($id, $record)
250 250
       }
251 251
       break;
252 252
     case 'aaaa':
253
-      $record['dyndns'] = NULL;
254
-      verify_input_ipv6($record['ip']);
255
-      $record['data'] = NULL;
256
-      $record['spec'] = NULL;
253
+      if ($record['dyndns']) {
254
+          get_dyndns_account( $record['dyndns'] );
255
+          $record['ip'] = NULL;
256
+      } else {
257
+          $record['dyndns'] = NULL;
258
+          verify_input_ipv6($record['ip']);
259
+          $record['data'] = NULL;
260
+          $record['spec'] = NULL;
261
+      }
257 262
       break;
258 263
     case 'mx':
259 264
       $record['dyndns'] = NULL;
Browse code

Mache manuelle NS-Records nicht mehr editier- und löschbar, Lösche sie aber automatisch wenn Autorecords eingeschaltet werden

Bernd Wurst authored on02/02/2018 06:29:18
Showing1 changed files
... ...
@@ -356,6 +356,7 @@ function enable_autorecords($domainid)
356 356
   $dom = $dom->id;
357 357
 
358 358
   db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id=?", array($dom));
359
+  db_query("DELETE FROM dns.custom_records WHERE type='ns' AND domain=? AND hostname IS NULL", array($dom));
359 360
   warning("Die automatischen Einträge werden in Kürze aktiviert, bitte haben Sie einen Moment Geduld.");
360 361
 }
361 362
 
Browse code

Text für Autorecords geändert, NS-Records auf der Stammdomain verbieten

Bernd Wurst authored on02/02/2018 05:43:37
Showing1 changed files
... ...
@@ -265,9 +265,12 @@ function save_dns_record($id, $record)
265 265
         system_failure('MX hostname missing');
266 266
       $record['ip'] = NULL;
267 267
       break;
268
-    case 'cname':
269 268
     case 'ptr':
270 269
     case 'ns':
270
+      if (!$record['hostname']) {
271
+          system_failure("Die angestrebte Konfiguration wird nicht funktionieren, Speichern wurde daher verweigert.");
272
+      }
273
+    case 'cname':
271 274
       $record['dyndns'] = NULL;
272 275
       $record['spec'] = NULL;
273 276
       $record['ip'] = NULL;
Browse code

Copyright year update

Bernd Wurst authored on13/01/2018 06:07:05
Showing1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 /*
3 3
 This file belongs to the Webinterface of schokokeks.org Hosting
4 4
 
5
-Written 2008-2014 by schokokeks.org Hosting, namely
5
+Written 2008-2018 by schokokeks.org Hosting, namely
6 6
   Bernd Wurst <bernd@schokokeks.org>
7 7
   Hanno Böck <hanno@schokokeks.org>
8 8
 
Browse code

Ermögliche die Verwendung von erweiterten Zeichen (z.B. im Domainnamen)

Bernd Wurst authored on22/12/2017 07:39:52
Showing1 changed files
... ...
@@ -395,7 +395,7 @@ $tld_ns = array();
395 395
 
396 396
 function check_dns($domainname, $tld) {
397 397
   global $tld_ns;
398
-  $domain=idn_to_ascii($domainname.".".$tld);
398
+  $domain=idn_to_ascii($domainname.".".$tld, 0, INTL_IDNA_VARIANT_UTS46);
399 399
 
400 400
   if (! isset($tld_ns[$tld])) {
401 401
     $resp = shell_exec('dig @a.root-servers.net. +noall +authority -t ns '.$tld.'.');
Browse code

fix spec for caa

Hanno Böck authored on08/03/2017 23:59:02
Showing1 changed files
... ...
@@ -295,7 +295,6 @@ function save_dns_record($id, $record)
295 295
 
296 296
     case 'caa':
297 297
       $record['dyndns'] = NULL;
298
-      $record['spec'] = max( (int) $record['spec'], 1);
299 298
       $record['ip'] = NULL;
300 299
       if (! $record['data'] )
301 300
         system_failure('text entry missing');
Browse code

add caa support

Hanno Böck authored on08/03/2017 23:39:30
Showing1 changed files
... ...
@@ -21,6 +21,7 @@ require_once('inc/error.php');
21 21
 
22 22
 require_once('class/domain.php');
23 23
 
24
+$caa_properties= array( 0 => "issue", 1 => "issuewild", 2 => "iodef" );
24 25
 
25 26
 function get_dyndns_accounts() 
26 27
 {
... ...
@@ -144,7 +145,7 @@ function get_dyndns_records($id)
144 145
   return $data;
145 146
 }
146 147
 
147
-$valid_record_types = array('a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw', 'sshfp');
148
+$valid_record_types = array('a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw', 'sshfp', 'caa');
148 149
 
149 150
 
150 151
 function blank_dns_record($type)
... ...
@@ -211,7 +212,7 @@ function get_domain_auto_records($domainname)
211 212
 }
212 213
 
213 214
 
214
-$implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv', 'ns', 'sshfp');
215
+$implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv', 'ns', 'sshfp', 'caa');
215 216
 
216 217
 function save_dns_record($id, $record)
217 218
 {
... ...
@@ -292,6 +293,13 @@ function save_dns_record($id, $record)
292 293
         system_failure('text entry missing');
293 294
       break;
294 295
 
296
+    case 'caa':
297
+      $record['dyndns'] = NULL;
298
+      $record['spec'] = max( (int) $record['spec'], 1);
299
+      $record['ip'] = NULL;
300
+      if (! $record['data'] )
301
+        system_failure('text entry missing');
302
+      break;
295 303
 
296 304
     case 'srv':
297 305
       system_failure('not implemented yet');
Browse code

validiere SSH-Keys korrekt

Hanno Böck authored on03/03/2017 12:22:44
Showing1 changed files
... ...
@@ -61,9 +61,11 @@ function create_dyndns_account($handle, $password_http, $sshkey)
61 61
     system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');  
62 62
 
63 63
   $handle = filter_input_username($handle);
64
-  $sshkey = filter_input_general($sshkey);
65
-  if (strlen($sshkey) == 0) {
64
+
65
+  if (strlen(trim($sshkey)) == 0) {
66 66
     $sshkey = NULL;
67
+  } else {
68
+    $sshkey = filter_ssh_key($sshkey);
67 69
   }
68 70
 
69 71
   $pwhash = NULL;
Browse code

Prüfe DNS-Records auf problematische Zeichen für die Zone-Files

Hanno Böck authored on02/03/2017 12:31:40
Showing1 changed files
... ...
@@ -228,6 +228,7 @@ function save_dns_record($id, $record)
228 228
     $record['hostname'] = NULL;
229 229
   }
230 230
   verify_input_hostname($record['hostname'], true);
231
+  verify_input_recorddata($record['data']);
231 232
   if ($record['ttl'] &&  (int) $record['ttl'] < 1)
232 233
     system_failure('Fehler bei TTL');
233 234
   switch ($record['type']) 
Browse code

Erzeuge nicht einen DynDNS-Hostname unser der Masterdomain sondern frage gleich vom User ab welcher Hostname verwendet werden soll

Bernd Wurst authored on01/07/2016 10:19:58
Showing1 changed files
... ...
@@ -62,6 +62,9 @@ function create_dyndns_account($handle, $password_http, $sshkey)
62 62
 
63 63
   $handle = filter_input_username($handle);
64 64
   $sshkey = filter_input_general($sshkey);
65
+  if (strlen($sshkey) == 0) {
66
+    $sshkey = NULL;
67
+  }
65 68
 
66 69
   $pwhash = NULL;
67 70
   if ($password_http)
... ...
@@ -71,11 +74,12 @@ function create_dyndns_account($handle, $password_http, $sshkey)
71 74
            "(:uid, :handle, :pwhash, :sshkey)",
72 75
            array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey));
73 76
   $dyndns_id = db_insert_id();
74
-  $masterdomain = new Domain(config('masterdomain'));
75
-  db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
76
-           "('a', :dom, :hostname, :dyndns, 120)",
77
-           array(":dom" => $masterdomain->id, ":hostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'], ":dyndns" => $dyndns_id));
78
-  logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account");
77
+  //$masterdomain = new Domain(config('masterdomain'));
78
+  //db_query("INSERT INTO dns.custom_records (type, domain, hostname, dyndns, ttl) VALUES ".
79
+  //         "('a', :dom, :hostname, :dyndns, 120)",
80
+  //         array(":dom" => $masterdomain->id, ":hostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'], ":dyndns" => $dyndns_id));
81
+  logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account {$dyndns_id}");
82
+  return $dyndns_id;
79 83
 }
80 84
 
81 85
 
Browse code

Zeige DNS-Records eine Domain auch dann an, wenn ein DynDNS eines anderen Users enthalten ist (z.B. für schokokeks.net)

Bernd Wurst authored on19/02/2016 04:57:23
Showing1 changed files
... ...
@@ -35,13 +35,16 @@ function get_dyndns_accounts()
35 35
 }
36 36
 
37 37
 
38
-function get_dyndns_account($id) 
38
+function get_dyndns_account($id, $ignore=true) 
39 39
 {
40 40
   $args = array(":id" => (int) $id,
41 41
                 ":uid" => (int) $_SESSION['userinfo']['uid']);
42 42
   $result = db_query("SELECT * FROM dns.dyndns WHERE id=:id AND uid=:uid", $args);
43 43
   if ($result->rowCount() != 1) {
44
-    logger(LOG_WARNING, "modules/dns/include/dnsinclude", "dyndns", "account »{$id}« invalid for uid »{$uid}«.");
44
+    if ($ignore) {
45
+      return NULL;
46
+    } 
47
+    logger(LOG_WARNING, "modules/dns/include/dnsinclude", "dyndns", "account »{$id}« invalid for uid »{$_SESSION['userinfo']['uid']}«.");
45 48
     system_failure("Account ungültig");
46 49
   }
47 50
   $item = $result->fetch();
Browse code

Erlaube auch die user_vhosts_domain für DynDNS

Bernd Wurst authored on18/05/2015 09:53:13
Showing1 changed files
... ...
@@ -123,7 +123,7 @@ function get_dyndns_records($id)
123 123
   $data = array();
124 124
   while ($entry = $result->fetch()) {
125 125
     $dom = new Domain((int) $entry['domain']);
126
-    if ($dom->fqdn != config('masterdomain')) {
126
+    if ($dom->fqdn != config('masterdomain') && $dom->fqdn != config('user_vhosts_domain')) {
127 127
       $dom->ensure_userdomain();
128 128
     }
129 129
     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
Browse code

Ändere automatisch erzeugten DNS-Record wenn das Handle geändert wird

Bernd Wurst authored on04/07/2014 11:49:55
Showing1 changed files
... ...
@@ -79,12 +79,22 @@ function create_dyndns_account($handle, $password_http, $sshkey)
79 79
 function edit_dyndns_account($id, $handle, $password_http, $sshkey)
80 80
 {
81 81
   $id = (int) $id;
82
+  $oldaccount = get_dyndns_account($id);
82 83
   $handle = filter_input_username($handle);
83 84
   $sshkey = filter_input_general($sshkey);
84 85
   if (chop($sshkey) == '') {
85 86
     $sshkey = NULL;
86 87
   }
87 88
 
89
+  if ($oldaccount['handle'] != $handle) {
90
+    $masterdomain = new Domain(config('masterdomain'));
91
+    db_query("UPDATE dns.custom_records SET hostname=:newhostname WHERE ".
92
+             "hostname=:oldhostname AND domain=:dom AND dyndns=:dyndns AND ip IS NULL",
93
+             array(":dom" => $masterdomain->id, ":newhostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'],
94
+                   ":oldhostname" => $oldaccount['handle'].'.'.$_SESSION['userinfo']['username'],  ":dyndns" => $id));
95
+
96
+  }
97
+
88 98
   $args = array(":handle" => $handle, ":sshkey" => $sshkey, ":id" => $id);
89 99
   $pwhash = NULL;
90 100
   if ($password_http && $password_http != '************') {
Browse code

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

Bernd Wurst authored on04/07/2014 11:42:35
Showing1 changed files
... ...
@@ -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']);
111
-    $dom->ensure_userdomain();
116
+    if ($dom->fqdn != config('masterdomain')) {
117
+      $dom->ensure_userdomain();
118
+    }
112 119
     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
113 120
     if (! $entry['hostname'])
114 121
       $entry['fqdn'] = $dom->fqdn;
Browse code

Setze leeren Hostname auf NULL

Bernd Wurst authored on28/04/2014 10:02:27
Showing1 changed files
... ...
@@ -200,6 +200,9 @@ function save_dns_record($id, $record)
200 200
   $dom->ensure_userdomain();
201 201
   if (! $dom->id)
202 202
     system_failure('invalid domain');
203
+  if ($record['hostname'] == '') {
204
+    $record['hostname'] = NULL;
205
+  }
203 206
   verify_input_hostname($record['hostname'], true);
204 207
   if ($record['ttl'] &&  (int) $record['ttl'] < 1)
205 208
     system_failure('Fehler bei TTL');
Browse code

Warne, wenn bei den DNS-Servern etwas nicht stimmt

Bernd Wurst authored on25/03/2014 09:50:08
Showing1 changed files
... ...
@@ -338,4 +338,77 @@ function domain_is_maildomain($domain)
338 338
 }
339 339
 
340 340
 
341
-?>
341
+$own_ns = array();
342
+
343
+function own_ns() {
344
+  global $own_ns;
345
+
346
+  if (count($own_ns) < 1) {
347
+    $auth = dns_get_record(config('masterdomain'), DNS_NS);
348
+    foreach ($auth as $ns) {
349
+      $own_ns[] = $ns['target'];   
350
+    }
351
+  }
352
+
353
+  return $own_ns;  
354
+}
355
+
356
+
357
+$tld_ns = array();
358
+
359
+function check_dns($domainname, $tld) {
360
+  global $tld_ns;
361
+  $domain=idn_to_ascii($domainname.".".$tld);
362
+
363
+  if (! isset($tld_ns[$tld])) {
364
+    $resp = shell_exec('dig @a.root-servers.net. +noall +authority -t ns '.$tld.'.');
365
+    $line = explode("\n", $resp, 2)[0];
366
+    $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+)$/", '\1', $line);
367
+    $tld_ns[$tld] = $NS;
368
+  }
369
+  
370
+  $resp = shell_exec('dig @'.$tld_ns[$tld].' +noall +authority -t ns '.$domain.'.');
371
+  $line = explode("\n", $resp, 2)[0];
372
+  if (preg_match('/^.*\\sIN\\s+NS\\s+/', $line) === 0) {
373
+    return "NXDOMAIN";
374
+  }
375
+  $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+).$/", '\1', $line);
376
+  
377
+  $own_ns = own_ns();
378
+
379
+  if (in_array($NS, $own_ns)) {
380
+    return True;
381
+  }
382
+  return $NS;
383
+}
384
+
385
+function remove_from_dns($dom) {
386
+  $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
387
+  $current = NULL;
388
+  foreach ($domains as $d) {
389
+    if ($d->id == $dom && $d->dns == 1) {
390
+      $current = $d;
391
+      break;
392
+    }
393
+  }
394
+  if (! $current) {
395
+    system_failure("Domain nicht gefunden!");
396
+  }
397
+  db_query("UPDATE kundendaten.domains SET dns=0 WHERE id=?", array($current->id));
398
+}
399
+
400
+function add_to_dns($dom) {
401
+  $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
402
+  $current = NULL;
403
+  foreach ($domains as $d) {
404
+    if ($d->id == $dom && $d->dns == 0) {
405
+      $current = $d;
406
+      break;
407
+    }
408
+  }
409
+  if (! $current) {
410
+    system_failure("Domain nicht gefunden!");
411
+  }
412
+  db_query("UPDATE kundendaten.domains SET dns=1, autodns=1 WHERE id=?", array($current->id));
413
+}
414
+
Browse code

Passwort bei DynDNS-Änderung richtig speichern

Bernd Wurst authored on07/03/2014 11:30:28
Showing1 changed files
... ...
@@ -76,18 +76,18 @@ function edit_dyndns_account($id, $handle, $password_http, $sshkey)
76 76
   $id = (int) $id;
77 77
   $handle = filter_input_username($handle);
78 78
   $sshkey = filter_input_general($sshkey);
79
+  if (chop($sshkey) == '') {
80
+    $sshkey = NULL;
81
+  }
79 82
 
83
+  $args = array(":handle" => $handle, ":sshkey" => $sshkey, ":id" => $id);
80 84
   $pwhash = NULL;
81
-  if ($password_http)
82
-  {
83
-    if ($password_http == '************')
84
-      $pwhash = 'password';
85
-    else
86
-      $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
85
+  if ($password_http && $password_http != '************') {
86
+      $args[":pwhash"] = "{SHA}".base64_encode(sha1($password_http, true));
87
+      db_query("UPDATE dns.dyndns SET handle=:handle, password=:pwhash, sshkey=:sshkey WHERE id=:id", $args);
88
+  } else {
89
+      db_query("UPDATE dns.dyndns SET handle=:handle, sshkey=:sshkey WHERE id=:id", $args);
87 90
   }
88
-  
89
-  $args = array(":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey, ":id" => $id);
90
-  db_query("UPDATE dns.dyndns SET handle=:handle, password=:pwhash, sshkey=:sshkey WHERE id=:id", $args);
91 91
   logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "edited account »{$id}«");
92 92
 }
93 93
 
Browse code

Lizenzinfos in eigenes Modul ausgelagert und Copyright auf 2014 angepasst

Bernd Wurst authored on08/02/2014 05:45:07
Showing1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 /*
3 3
 This file belongs to the Webinterface of schokokeks.org Hosting
4 4
 
5
-Written 2008-2013 by schokokeks.org Hosting, namely
5
+Written 2008-2014 by schokokeks.org Hosting, namely
6 6
   Bernd Wurst <bernd@schokokeks.org>
7 7
   Hanno Böck <hanno@schokokeks.org>
8 8
 
Browse code

String 'NULL' eliminiert

Bernd Wurst authored on07/02/2014 14:21:11
Showing1 changed files
... ...
@@ -60,9 +60,9 @@ function create_dyndns_account($handle, $password_http, $sshkey)
60 60
   $handle = filter_input_username($handle);
61 61
   $sshkey = filter_input_general($sshkey);
62 62
 
63
-  $pwhash = 'NULL';
63
+  $pwhash = NULL;
64 64
   if ($password_http)
65
-    $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
65
+    $pwhash = "{SHA}".base64_encode(sha1($password_http, true));
66 66
 
67 67
   db_query("INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
68 68
            "(:uid, :handle, :pwhash, :sshkey)",
Browse code

* Weitere Module auf prepared-statements umgestellt * Warnung beim Aufruf von db_escape_string() und maybe_null() hinzugefügt

Bernd Wurst authored on03/02/2014 16:57:44
Showing1 changed files
... ...
@@ -25,7 +25,7 @@ require_once('class/domain.php');
25 25
 function get_dyndns_accounts() 
26 26
 {
27 27
   $uid = (int) $_SESSION['userinfo']['uid'];
28
-  $result = db_query("SELECT * FROM dns.dyndns WHERE uid={$uid}");
28
+  $result = db_query("SELECT * FROM dns.dyndns WHERE uid=?", array($uid));
29 29
   $list = array();
30 30
   while ($item = $result->fetch()) {
31 31
     array_push($list, $item);
... ...
@@ -37,9 +37,9 @@ function get_dyndns_accounts()
37 37
 
38 38
 function get_dyndns_account($id) 
39 39
 {
40
-  $id = (int) $id;
41
-  $uid = (int) $_SESSION['userinfo']['uid'];
42
-  $result = db_query("SELECT * FROM dns.dyndns WHERE id={$id} AND uid={$uid}");
40
+  $args = array(":id" => (int) $id,
41
+                ":uid" => (int) $_SESSION['userinfo']['uid']);
42
+  $result = db_query("SELECT * FROM dns.dyndns WHERE id=:id AND uid=:uid", $args);
43 43
   if ($result->rowCount() != 1) {
44 44
     logger(LOG_WARNING, "modules/dns/include/dnsinclude", "dyndns", "account »{$id}« invalid for uid »{$uid}«.");
45 45
     system_failure("Account ungültig");
... ...
@@ -57,14 +57,16 @@ function create_dyndns_account($handle, $password_http, $sshkey)
57 57
   if ($password_http == '' && $sshkey == '')
58 58
     system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');  
59 59
 
60
-  $handle = maybe_null(db_escape_string(filter_input_username($handle)));
61
-  $sshkey = maybe_null(db_escape_string(filter_input_general($sshkey)));
60
+  $handle = filter_input_username($handle);
61
+  $sshkey = filter_input_general($sshkey);