96649f21ba18d07757afa9d98998f7a22c0d86a3
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 Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

24) $caa_properties= [ 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'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

29)     $result = db_query("SELECT * FROM dns.dyndns WHERE uid=?", [$uid]);
30)     $list = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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 Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

41)     $args = [":id" => (int) $id,
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 Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

81)         [":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 Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

103)     $args = [":handle" => $handle, ":sshkey" => $sshkey, ":id" => $id];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

104)     $pwhash = null;
105)     if ($password_http && $password_http != '************') {
106)         $args[":pwhash"] = "{SHA}".base64_encode(sha1($password_http, true));
107)         db_query("UPDATE dns.dyndns SET handle=:handle, password=:pwhash, sshkey=:sshkey WHERE id=:id", $args);
108)     } else {
109)         db_query("UPDATE dns.dyndns SET handle=:handle, sshkey=:sshkey WHERE id=:id", $args);
110)     }
111)     logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "edited account »{$id}«");
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

112) }
113) 
114) 
115) function delete_dyndns_account($id)
116) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 16 years ago

118) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

119)     db_query("DELETE FROM dns.dyndns WHERE id=?", [$id]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

120)     logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "deleted account »{$id}«");
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

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

Hanno authored 6 years ago

126)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

127)     $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns=?", [$id]);
128)     $data = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

129)     while ($entry = $result->fetch()) {
130)         $dom = new Domain((int) $entry['domain']);
131)         if ($dom->fqdn != config('masterdomain') && $dom->fqdn != config('user_vhosts_domain')) {
132)             $dom->ensure_userdomain();
133)         }
134)         $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
135)         if (! $entry['hostname']) {
136)             $entry['fqdn'] = $dom->fqdn;
137)         }
138)         array_push($data, $entry);
Bernd Wurst Erzeuge DNS-Records der For...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

142) }
143) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

144) $valid_record_types = ['a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw', 'sshfp', 'caa', 'srv'];
bernd some updates

bernd authored 16 years ago

145) 
146) 
147) function blank_dns_record($type)
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

148) {
149)     global $valid_record_types;
150)     if (!in_array(strtolower($type), $valid_record_types)) {
151)         system_failure('invalid type: '.$type);
152)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

153)     $rec = ['hostname' => null,
bernd some updates

bernd authored 16 years ago

154)                'domain' => 0,
155)                'type' => strtolower($type),
156)                'ttl' => 3600,
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

157)                'ip' => null,
158)                'dyndns' => null,
159)                'data' => null,
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

160)                'spec' => null, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

161)     if (strtolower($type) == 'mx') {
162)         $rec['data'] = config('default_mx');
163)         $rec['spec'] = '5';
164)     }
165)     return $rec;
bernd some updates

bernd authored 16 years ago

166) }
167) 
168) function get_dns_record($id)
169) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

170)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

171)     $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id=?", [$id]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

172)     if ($result->rowCount() != 1) {
173)         system_failure('illegal ID');
174)     }
175)     $data = $result->fetch();
176)     $dom = new Domain((int) $data['domain']);
177)     $dom->ensure_userdomain();
178)     DEBUG($data);
179)     return $data;
bernd some updates

bernd authored 16 years ago

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

bernd authored 16 years ago

181) 
182) 
183) function get_domain_records($dom)
184) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

185)     $dom = (int) $dom;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

186)     $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl, id FROM dns.custom_records WHERE domain=?", [$dom]);
187)     $data = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

188)     while ($entry = $result->fetch()) {
189)         $dom = new Domain((int) $entry['domain']);
190)         $dom->ensure_userdomain();
191)         $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
192)         if (! $entry['hostname']) {
193)             $entry['fqdn'] = $dom->fqdn;
194)         }
195)         array_push($data, $entry);
196)     }
197)     DEBUG($data);
198)     return $data;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

199) }
200) 
bernd some updates

bernd authored 16 years ago

201) function get_domain_auto_records($domainname)
202) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

203)     $result = db_query("SELECT hostname, domain, CONCAT_WS('.', hostname, domain) AS fqdn, type, ip, spec, data, ttl FROM dns.tmp_autorecords WHERE domain=?", [$domainname]);
204)     $data = [];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

205)     while ($entry = $result->fetch()) {
206)         array_push($data, $entry);
207)     }
208)     DEBUG($data);
209)     return $data;
bernd some updates

bernd authored 16 years ago

210) }
211) 
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

212) 
Hanno Böck fix codingstyle

Hanno Böck authored 4 years ago

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

Bernd Wurst authored 4 years ago

215)     $autorecords = get_domain_auto_records($domain);
216)     foreach ($autorecords as $ar) {
217)         if ($ar['hostname'] == $hostname && $ar['type'] == $type) {
218)             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.');
219)             break;
220)         }
221)     }
222) }
223) 
224) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

225) $implemented_record_types = ['a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv', 'ns', 'sshfp', 'caa'];
bernd add save function

bernd authored 16 years ago

226) 
227) function save_dns_record($id, $record)
228) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

229)     global $valid_record_types;
230)     global $implemented_record_types;
231)     $record['type'] = strtolower($record['type']);
232)     if (!in_array($record['type'], $valid_record_types)) {
233)         system_failure('invalid type: '.$record['type']);
234)     }
235)     if (!in_array($record['type'], $implemented_record_types)) {
236)         system_failure('record type '.$record['type'].' not implemented at the moment.');
237)     }
238)     $dom = new Domain((int) $record['domain']);
239)     $dom->ensure_userdomain();
240)     if (! $dom->id) {
241)         system_failure('invalid domain');
242)     }
243)     if ($record['hostname'] == '') {
244)         $record['hostname'] = null;
245)     }
246)     verify_input_hostname($record['hostname'], true);
247)     verify_input_recorddata($record['data']);
248)     if ($record['ttl'] &&  (int) $record['ttl'] < 1) {
249)         system_failure('Fehler bei TTL');
250)     }
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

254)       if ($record['dyndns']) {
255)           get_dyndns_account($record['dyndns']);
256)           $record['ip'] = null;
257)       } else {
258)           verify_input_ipv4($record['ip']);
259)           $record['data'] = null;
260)           $record['spec'] = null;
bernd add save function

bernd authored 16 years ago

261)       }
262)       break;
263)     case 'aaaa':
Bernd Wurst IPv6-support für DynDNS

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 6 years ago

272)       }
bernd add save function

bernd authored 16 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno authored 6 years ago

279)       }
bernd add save function

bernd authored 16 years ago

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

Hanno authored 6 years ago

281)       if (! $record['data']) {
282)           system_failure('MX hostname missing');
283)       }
284)       $record['ip'] = null;
bernd add save function

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

293)       $record['dyndns'] = null;
294)       $record['spec'] = null;
295)       $record['ip'] = null;
bernd add save function

bernd authored 16 years ago

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

Hanno authored 6 years ago

297)       if (! $record['data']) {
298)           system_failure('destination host missing');
299)       }
bernd add save function

bernd authored 16 years ago

300)       break;
301) 
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

302)     case 'spf':
303)     case 'txt':
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

304)       $record['dyndns'] = null;
305)       $record['spec'] = null;
306)       $record['ip'] = null;
307)       if (! $record['data']) {
308)           system_failure('text entry missing');
309)       }
bernd SPF und TXT records

bernd authored 15 years ago

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

bernd authored 13 years ago

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

Hanno authored 6 years ago

313)       $record['dyndns'] = null;
314)       $record['spec'] = max((int) $record['spec'], 1);
315)       $record['ip'] = null;
316)       if (! $record['data']) {
317)           system_failure('text entry missing');
318)       }
bernd SSHFP-Records (Thanks to Ma...

bernd authored 13 years ago

319)       break;
320) 
Hanno Böck add caa support

Hanno Böck authored 7 years ago

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

Hanno authored 6 years ago

322)       $record['dyndns'] = null;
323)       $record['ip'] = null;
324)       if (! $record['data']) {
325)           system_failure('text entry missing');
326)       }
Hanno Böck add caa support

Hanno Böck authored 7 years ago

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

bernd authored 13 years ago

328) 
bernd add save function

bernd authored 16 years ago

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

Bernd Wurst authored 4 years ago

330)       $record['dyndns'] = null;
331)       $record['spec'] = (int) $record['spec'];
332)       if ($record['spec'] < 0) {
333)           system_failure("invalid priority");
334)       }
335)       if (! $record['data']) {
336)           system_failure('SRV target missing');
337)       }
Hanno Böck more robust SRV record filt...

Hanno Böck authored 4 years ago

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

Bernd Wurst authored 4 years ago

339)       if (count($data) != 2) {
340)           system_failure('Das eingegebene Ziel war nicht im Format hostname:port');
341)       }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

342)       [$hostname, $port] = $data;
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

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

Hanno Böck authored 4 years ago

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

Bernd Wurst authored 4 years ago

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

Bernd Wurst authored 4 years ago

347)       $record['ip'] = null;
348)       break;
bernd add save function

bernd authored 16 years ago

349)     default:
350)       system_failure('Not implemented');
351)   }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

352)     $id = (int) $id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

353)     $args = [":domain" => $dom->id,
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 10 years ago

357)                 ":ip" => $record['ip'],
358)                 ":dyndns" => $record['dyndns'],
359)                 ":data" => $record['data'],
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

360)                 ":spec" => $record['spec'], ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

361)     if ($id) {
362)         $args[":id"] = $id;
363)         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);
364)     } else {
365)         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);
366)     }
bernd add save function

bernd authored 16 years ago

367) }
368) 
369) 
370) function delete_dns_record($id)
371) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

372)     $id = (int) $id;
373)     // Diese Funktion prüft, ob der Eintrag einer eigenen Domain gehört
374)     $record = get_dns_record($id);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

375)     db_query("DELETE FROM dns.custom_records WHERE id=?", [$id]);
bernd add save function

bernd authored 16 years ago

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

bernd authored 16 years ago

377) 
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

378) 
379) function convert_from_autorecords($domainid)
380) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

381)     $dom = new Domain((int) $domainid);
382)     $dom->ensure_userdomain();
383)     $dom = $dom->id;
384) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

385)     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=?", [$dom]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

386)     disable_autorecords($dom);
387)     db_query("UPDATE dns.dnsstatus SET status='outdated'");
388)     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

389) }
390) 
391) 
392) function enable_autorecords($domainid)
393) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

394)     $dom = new Domain((int) $domainid);
395)     $dom->ensure_userdomain();
396)     $dom = $dom->id;
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

397) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

398)     db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id=?", [$dom]);
399)     db_query("DELETE FROM dns.custom_records WHERE type='ns' AND domain=? AND hostname IS NULL", [$dom]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

400)     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

401) }
402) 
403) function disable_autorecords($domainid)
404) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

408) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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

bernd authored 15 years ago

410) }
411) 
412) 
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 12 years ago

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

Hanno authored 6 years ago

415)     $domain = (int) $domain;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

416)     $result = db_query("SELECT mail FROM kundendaten.domains WHERE id=?", [$domain]);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

417)     $dom = $result->fetch();
418)     return ($dom['mail'] != 'none');
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 12 years ago

419) }
420) 
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

421) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

422) $own_ns = [];
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

424) function own_ns()
425) {
426)     global $own_ns;
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

428)     if (count($own_ns) < 1) {
429)         $auth = dns_get_record(config('masterdomain'), DNS_NS);
430)         foreach ($auth as $ns) {
431)             $own_ns[] = $ns['target'];
432)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

433)     }
434) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Bernd Wurst authored 10 years ago

436) }
437) 
438) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

439) $tld_ns = [];
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

441) function check_dns($domainname, $tld)
442) {
443)     global $tld_ns;
444)     $domain=idn_to_ascii($domainname.".".$tld, 0, INTL_IDNA_VARIANT_UTS46);
445) 
446)     if (! isset($tld_ns[$tld])) {
447)         $resp = shell_exec('dig @a.root-servers.net. +noall +authority -t ns '.$tld.'.');
448)         $line = explode("\n", $resp, 2)[0];
449)         $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+)$/", '\1', $line);
450)         $tld_ns[$tld] = $NS;
451)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

462)     if (in_array($NS, $own_ns)) {
463)         return true;
464)     }
465)     return $NS;
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

466) }
467) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

468) function remove_from_dns($dom)
469) {
470)     $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
471)     $current = null;
472)     foreach ($domains as $d) {
473)         if ($d->id == $dom && $d->dns == 1) {
474)             $current = $d;
475)             break;
476)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

478)     if (! $current) {
479)         system_failure("Domain nicht gefunden!");
480)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

481)     db_query("UPDATE kundendaten.domains SET dns=0 WHERE id=?", [$current->id]);
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

482) }
483) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

484) function add_to_dns($dom)
485) {
486)     $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
487)     $current = null;
488)     foreach ($domains as $d) {
489)         if ($d->id == $dom && $d->dns == 0) {
490)             $current = $d;
491)             break;
492)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

494)     if (! $current) {
495)         system_failure("Domain nicht gefunden!");
496)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

497)     db_query("UPDATE kundendaten.domains SET dns=1, autodns=1 WHERE id=?", [$current->id]);