0a43c607e895f7861cdb7e4a2eb8dbad5f2023f8
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
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) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
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.
15) */
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

16) 
17) require_once('inc/debug.php');
18) require_once('inc/base.php');
19) require_once('inc/security.php');
bernd Neue Autorecords-Tabelle

bernd authored 14 years ago

20) require_once('inc/error.php');
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

21) 
22) require_once('class/domain.php');
23) 
Hanno Böck add caa support

Hanno Böck authored 7 years ago

24) $caa_properties= array( 0 => "issue", 1 => "issuewild", 2 => "iodef" );
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

25) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

26) function get_dyndns_accounts()
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

27) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

36) }
37) 
38) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

39) function get_dyndns_account($id, $ignore=true)
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

40) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

41)     $args = array(":id" => (int) $id,
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

42)                 ":uid" => (int) $_SESSION['userinfo']['uid']);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

54) }
55) 
56) 
57) function create_dyndns_account($handle, $password_http, $sshkey)
58) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

59)     $uid = (int) $_SESSION['userinfo']['uid'];
bernd Warnings eliminiert und Plu...

bernd authored 15 years ago

60) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

61)     if ($password_http == '' && $sshkey == '') {
62)         system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');
63)     }
bernd Warnings eliminiert und Plu...

bernd authored 15 years ago

64) 
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 5 years ago

65)     $handle = verify_input_identifier($handle);
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

66) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

67)     if (strlen(trim($sshkey)) == 0) {
68)         $sshkey = null;
69)     } else {
70)         $sshkey = filter_ssh_key($sshkey);
71)     }
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

72) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

73)     $pwhash = null;
74)     if ($password_http) {
75)         $pwhash = "{SHA}".base64_encode(sha1($password_http, true));
76)     }
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

77) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

78)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

79)         "INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

80)            "(:uid, :handle, :pwhash, :sshkey)",
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

81)         array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey)
Hanno Fix codingstyle

Hanno authored 5 years ago

82)     );
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

90) }
91) 
92) 
93) function edit_dyndns_account($id, $handle, $password_http, $sshkey)
94) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

95)     $id = (int) $id;
96)     $oldaccount = get_dyndns_account($id);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 5 years ago

97)     $handle = verify_input_identifier($handle);
98)     $sshkey = verify_input_ascii($sshkey);
99)     if (trim($sshkey) == '') {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

100)         $sshkey = null;
101)     }
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

102) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

103)     if ($oldaccount['handle'] != $handle) {
104)         $masterdomain = new Domain(config('masterdomain'));
105)         db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

106)             "UPDATE dns.custom_records SET hostname=:newhostname WHERE ".
Bernd Wurst Ändere automatisch erzeugte...

Bernd Wurst authored 10 years ago

107)              "hostname=:oldhostname AND domain=:dom AND dyndns=:dyndns AND ip IS NULL",
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

108)             array(":dom" => $masterdomain->id, ":newhostname" => filter_input_hostname($handle).'.'.$_SESSION['userinfo']['username'],
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

109)                    ":oldhostname" => $oldaccount['handle'].'.'.$_SESSION['userinfo']['username'],  ":dyndns" => $id)
Hanno Fix codingstyle

Hanno authored 5 years ago

110)         );
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

111)     }
Bernd Wurst Ändere automatisch erzeugte...

Bernd Wurst authored 10 years ago

112) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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}«");
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

122) }
123) 
124) 
125) function delete_dyndns_account($id)
126) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

127)     $id = (int) $id;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

128) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

129)     db_query("DELETE FROM dns.dyndns WHERE id=?", array($id));
130)     logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "deleted account »{$id}«");
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

131) }
132) 
133) 
134) function get_dyndns_records($id)
135) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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);
Bernd Wurst Erzeuge DNS-Records der For...

Bernd Wurst authored 10 years ago

149)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

150)     DEBUG($data);
151)     return $data;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

152) }
153) 
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

154) $valid_record_types = array('a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw', 'sshfp', 'caa', 'srv');
bernd some updates

bernd authored 16 years ago

155) 
156) 
157) function blank_dns_record($type)
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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,
bernd some updates

bernd authored 16 years ago

164)                'domain' => 0,
165)                'type' => strtolower($type),
166)                'ttl' => 3600,
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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;
bernd some updates

bernd authored 16 years ago

176) }
177) 
178) function get_dns_record($id)
179) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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;
bernd some updates

bernd authored 16 years ago

190) }
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

191) 
192) 
193) function get_domain_records($dom)
194) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

209) }
210) 
bernd some updates

bernd authored 16 years ago

211) function get_domain_auto_records($domainname)
212) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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;
bernd some updates

bernd authored 16 years ago

220) }
221) 
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

222) 
Hanno Böck fix codingstyle

Hanno Böck authored 4 years ago

223) function warn_autorecord_collission($hostname, $domain, $type)
224) {
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

225)     $autorecords = get_domain_auto_records($domain);
226)     foreach ($autorecords as $ar) {
227)         if ($ar['hostname'] == $hostname && $ar['type'] == $type) {
228)             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.');
229)             break;
230)         }
231)     }
232) }
233) 
234) 
Hanno Böck add caa support

Hanno Böck authored 7 years ago

235) $implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv', 'ns', 'sshfp', 'caa');
bernd add save function

bernd authored 16 years ago

236) 
237) function save_dns_record($id, $record)
238) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

239)     global $valid_record_types;
240)     global $implemented_record_types;
241)     $record['type'] = strtolower($record['type']);
242)     if (!in_array($record['type'], $valid_record_types)) {
243)         system_failure('invalid type: '.$record['type']);
244)     }
245)     if (!in_array($record['type'], $implemented_record_types)) {
246)         system_failure('record type '.$record['type'].' not implemented at the moment.');
247)     }
248)     $dom = new Domain((int) $record['domain']);
249)     $dom->ensure_userdomain();
250)     if (! $dom->id) {
251)         system_failure('invalid domain');
252)     }
253)     if ($record['hostname'] == '') {
254)         $record['hostname'] = null;
255)     }
256)     verify_input_hostname($record['hostname'], true);
257)     verify_input_recorddata($record['data']);
258)     if ($record['ttl'] &&  (int) $record['ttl'] < 1) {
259)         system_failure('Fehler bei TTL');
260)     }
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

261)     warn_autorecord_collission($record['hostname'], $dom->fqdn, $record['type']);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

262)     switch ($record['type']) {
bernd add save function

bernd authored 16 years ago

263)     case 'a':
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

264)       if ($record['dyndns']) {
265)           get_dyndns_account($record['dyndns']);
266)           $record['ip'] = null;
267)       } else {
268)           verify_input_ipv4($record['ip']);
269)           $record['data'] = null;
270)           $record['spec'] = null;
bernd add save function

bernd authored 16 years ago

271)       }
272)       break;
273)     case 'aaaa':
Bernd Wurst IPv6-support für DynDNS

Bernd Wurst authored 6 years ago

274)       if ($record['dyndns']) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

275)           get_dyndns_account($record['dyndns']);
276)           $record['ip'] = null;
Bernd Wurst IPv6-support für DynDNS

Bernd Wurst authored 6 years ago

277)       } else {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

278)           $record['dyndns'] = null;
Bernd Wurst IPv6-support für DynDNS

Bernd Wurst authored 6 years ago

279)           verify_input_ipv6($record['ip']);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

280)           $record['data'] = null;
281)           $record['spec'] = null;
Bernd Wurst IPv6-support für DynDNS

Bernd Wurst authored 6 years ago

282)       }
bernd add save function

bernd authored 16 years ago

283)       break;
284)     case 'mx':
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

285)       $record['dyndns'] = null;
bernd add save function

bernd authored 16 years ago

286)       $record['spec'] = (int) $record['spec'];
Bernd Wurst Fixed mx-priority can be 0...

Bernd Wurst authored 5 years ago

287)       if ($record['spec'] < 0) {
288)           system_failure("invalid priority");
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

289)       }
bernd add save function

bernd authored 16 years ago

290)       verify_input_hostname($record['data']);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

291)       if (! $record['data']) {
292)           system_failure('MX hostname missing');
293)       }
294)       $record['ip'] = null;
bernd add save function

bernd authored 16 years ago

295)       break;
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

296)     case 'ptr':
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

297)     case 'ns':
Bernd Wurst Text für Autorecords geände...

Bernd Wurst authored 6 years ago

298)       if (!$record['hostname']) {
299)           system_failure("Die angestrebte Konfiguration wird nicht funktionieren, Speichern wurde daher verweigert.");
300)       }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

301)       // no break
Bernd Wurst Text für Autorecords geände...

Bernd Wurst authored 6 years ago

302)     case 'cname':
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

303)       $record['dyndns'] = null;
304)       $record['spec'] = null;
305)       $record['ip'] = null;
bernd add save function

bernd authored 16 years ago

306)       verify_input_hostname($record['data']);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

307)       if (! $record['data']) {
308)           system_failure('destination host missing');
309)       }
bernd add save function

bernd authored 16 years ago

310)       break;
311) 
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

312)     case 'spf':
313)     case 'txt':
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

314)       $record['dyndns'] = null;
315)       $record['spec'] = null;
316)       $record['ip'] = null;
317)       if (! $record['data']) {
318)           system_failure('text entry missing');
319)       }
bernd SPF und TXT records

bernd authored 15 years ago

320)       break;
321) 
bernd SSHFP-Records (Thanks to Ma...

bernd authored 13 years ago

322)     case 'sshfp':
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

323)       $record['dyndns'] = null;
324)       $record['spec'] = max((int) $record['spec'], 1);
325)       $record['ip'] = null;
326)       if (! $record['data']) {
327)           system_failure('text entry missing');
328)       }
bernd SSHFP-Records (Thanks to Ma...

bernd authored 13 years ago

329)       break;
330) 
Hanno Böck add caa support

Hanno Böck authored 7 years ago

331)     case 'caa':
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

332)       $record['dyndns'] = null;
333)       $record['ip'] = null;
334)       if (! $record['data']) {
335)           system_failure('text entry missing');
336)       }
Hanno Böck add caa support

Hanno Böck authored 7 years ago

337)       break;
bernd SSHFP-Records (Thanks to Ma...

bernd authored 13 years ago

338) 
bernd add save function

bernd authored 16 years ago

339)     case 'srv':
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

340)       $record['dyndns'] = null;
341)       $record['spec'] = (int) $record['spec'];
342)       if ($record['spec'] < 0) {
343)           system_failure("invalid priority");
344)       }
345)       if (! $record['data']) {
346)           system_failure('SRV target missing');
347)       }
Hanno Böck more robust SRV record filt...

Hanno Böck authored 4 years ago

348)       $data = explode(':', $record['data']);
Bernd Wurst validate SRV record data field

Bernd Wurst authored 4 years ago

349)       if (count($data) != 2) {
350)           system_failure('Das eingegebene Ziel war nicht im Format hostname:port');
351)       }
352)       list($hostname, $port) = $data;
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

353)       verify_input_hostname($hostname);
Hanno Böck more robust SRV record filt...

Hanno Böck authored 4 years ago

354)       if ($port !== (string)(int) $port || (int)$port < 1 || (int)$port > 65535) {
Bernd Wurst validate SRV record data field

Bernd Wurst authored 4 years ago

355)           system_failure('Ungültige Portnummer');
356)       }
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

357)       $record['ip'] = null;
358)       break;
bernd add save function

bernd authored 16 years ago

359)     default:
360)       system_failure('Not implemented');
361)   }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

362)     $id = (int) $id;
363)     $args = array(":domain" => $dom->id,
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

364)                 ":hostname" => $record['hostname'],
365)                 ":type" => $record['type'],
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

366)                 ":ttl" => ($record['ttl'] == 0 ? null : (int) $record['ttl']),
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

367)                 ":ip" => $record['ip'],
368)                 ":dyndns" => $record['dyndns'],
369)                 ":data" => $record['data'],
370)                 ":spec" => $record['spec']);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

371)     if ($id) {
372)         $args[":id"] = $id;
373)         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);
374)     } else {
375)         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);
376)     }
bernd add save function

bernd authored 16 years ago

377) }
378) 
379) 
380) function delete_dns_record($id)
381) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

382)     $id = (int) $id;
383)     // Diese Funktion prüft, ob der Eintrag einer eigenen Domain gehört
384)     $record = get_dns_record($id);
385)     db_query("DELETE FROM dns.custom_records WHERE id=?", array($id));
bernd add save function

bernd authored 16 years ago

386) }
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

387) 
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

388) 
389) function convert_from_autorecords($domainid)
390) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

391)     $dom = new Domain((int) $domainid);
392)     $dom->ensure_userdomain();
393)     $dom = $dom->id;
394) 
395)     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));
396)     disable_autorecords($dom);
397)     db_query("UPDATE dns.dnsstatus SET status='outdated'");
398)     warning("Die automatischen Einträge werden in Kürze abgeschaltet, bitte haben Sie einen Moment Geduld.");
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

399) }
400) 
401) 
402) function enable_autorecords($domainid)
403) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

404)     $dom = new Domain((int) $domainid);
405)     $dom->ensure_userdomain();
406)     $dom = $dom->id;
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

407) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

408)     db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id=?", array($dom));
409)     db_query("DELETE FROM dns.custom_records WHERE type='ns' AND domain=? AND hostname IS NULL", array($dom));
410)     warning("Die automatischen Einträge werden in Kürze aktiviert, bitte haben Sie einen Moment Geduld.");
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

411) }
412) 
413) function disable_autorecords($domainid)
414) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

415)     $dom = new Domain((int) $domainid);
416)     $dom->ensure_userdomain();
417)     $dom = $dom->id;
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

418) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

419)     db_query("UPDATE kundendaten.domains SET autodns=0 WHERE id=?", array($dom));
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

420) }
421) 
422) 
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 12 years ago

423) function domain_is_maildomain($domain)
424) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

425)     $domain = (int) $domain;
426)     $result = db_query("SELECT mail FROM kundendaten.domains WHERE id=?", array($domain));
427)     $dom = $result->fetch();
428)     return ($dom['mail'] != 'none');
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 12 years ago

429) }
430) 
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

431) 
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

432) $own_ns = array();
433) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

434) function own_ns()
435) {
436)     global $own_ns;
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

437) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

438)     if (count($own_ns) < 1) {
439)         $auth = dns_get_record(config('masterdomain'), DNS_NS);
440)         foreach ($auth as $ns) {
441)             $own_ns[] = $ns['target'];
442)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

443)     }
444) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

445)     return $own_ns;
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

446) }
447) 
448) 
449) $tld_ns = array();
450) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

451) function check_dns($domainname, $tld)
452) {
453)     global $tld_ns;
454)     $domain=idn_to_ascii($domainname.".".$tld, 0, INTL_IDNA_VARIANT_UTS46);
455) 
456)     if (! isset($tld_ns[$tld])) {
457)         $resp = shell_exec('dig @a.root-servers.net. +noall +authority -t ns '.$tld.'.');
458)         $line = explode("\n", $resp, 2)[0];
459)         $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+)$/", '\1', $line);
460)         $tld_ns[$tld] = $NS;
461)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

462) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

463)     $resp = shell_exec('dig @'.$tld_ns[$tld].' +noall +authority -t ns '.$domain.'.');
464)     $line = explode("\n", $resp, 2)[0];
465)     if (preg_match('/^.*\\sIN\\s+NS\\s+/', $line) === 0) {
466)         return "NXDOMAIN";
467)     }
468)     $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+).$/", '\1', $line);
Hanno remove whitespace in empty...

Hanno authored 6 years ago

469) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

470)     $own_ns = own_ns();
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

471) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

472)     if (in_array($NS, $own_ns)) {
473)         return true;
474)     }
475)     return $NS;
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

476) }
477) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

478) function remove_from_dns($dom)
479) {
480)     $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
481)     $current = null;
482)     foreach ($domains as $d) {
483)         if ($d->id == $dom && $d->dns == 1) {
484)             $current = $d;
485)             break;
486)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

487)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

488)     if (! $current) {
489)         system_failure("Domain nicht gefunden!");
490)     }
491)     db_query("UPDATE kundendaten.domains SET dns=0 WHERE id=?", array($current->id));
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

492) }
493) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

494) function add_to_dns($dom)
495) {
496)     $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
497)     $current = null;
498)     foreach ($domains as $d) {
499)         if ($d->id == $dom && $d->dns == 0) {
500)             $current = $d;
501)             break;
502)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

503)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

504)     if (! $current) {
505)         system_failure("Domain nicht gefunden!");
506)     }
507)     db_query("UPDATE kundendaten.domains SET dns=1, autodns=1 WHERE id=?", array($current->id));