1721d2c38c096d416e239395a4904061f4ab4801
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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

5) Written 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) 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.
12) */
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

13) 
14) require_once('inc/debug.php');
15) require_once('inc/base.php');
16) require_once('inc/security.php');
bernd Neue Autorecords-Tabelle

bernd authored 14 years ago

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

bernd authored 16 years ago

18) 
19) require_once('class/domain.php');
20) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 1 year ago

21) $caa_properties = [ 0 => "issue", 1 => "issuewild", 2 => "iodef" ];
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

25)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

28)     while ($item = $result->fetch()) {
29)         array_push($list, $item);
30)     }
31)     DEBUG($list);
32)     return $list;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

33) }
34) 
35) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 1 year ago

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

bernd authored 16 years ago

37) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

38)     $args = [":id" => (int) $id,
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 8 months ago

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

Hanno authored 6 years ago

40)     $result = db_query("SELECT * FROM dns.dyndns WHERE id=:id AND uid=:uid", $args);
41)     if ($result->rowCount() != 1) {
42)         if ($ignore) {
43)             return null;
44)         }
45)         logger(LOG_WARNING, "modules/dns/include/dnsinclude", "dyndns", "account »{$id}« invalid for uid »{$_SESSION['userinfo']['uid']}«.");
46)         system_failure("Account ungültig");
47)     }
48)     $item = $result->fetch();
49)     DEBUG($item);
50)     return $item;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

51) }
52) 
53) 
54) function create_dyndns_account($handle, $password_http, $sshkey)
55) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

bernd authored 15 years ago

61) 
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 7 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

70)     $pwhash = null;
71)     if ($password_http) {
Hanno Böck dyndns: use gen_pw_hash for...

Hanno Böck authored 11 months ago

72)         if (($check = strong_password($password_http)) !== true) {
73)             system_failure($check);
74)         }
75)         $pwhash = gen_pw_hash($password_http);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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 Böck Spaces between string conca...

Hanno Böck authored 1 year 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);
Bernd Wurst nutze filter_ssh_key für de...

Bernd Wurst authored 6 months ago

98)     $sshkey = filter_ssh_key($sshkey);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 5 years ago

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 != '************') {
Hanno Böck dyndns: use gen_pw_hash for...

Hanno Böck authored 11 months ago

106)         if (($check = strong_password($password_http)) !== true) {
107)             system_failure($check);
108)         }
109)         $args[":pwhash"] = gen_pw_hash($password_http);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

110)         db_query("UPDATE dns.dyndns SET handle=:handle, password=:pwhash, sshkey=:sshkey WHERE id=:id", $args);
111)     } else {
112)         db_query("UPDATE dns.dyndns SET handle=:handle, sshkey=:sshkey WHERE id=:id", $args);
113)     }
114)     logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "edited account »{$id}«");
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

115) }
116) 
117) 
118) function delete_dyndns_account($id)
119) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

124) }
125) 
126) 
127) function get_dyndns_records($id)
128) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

132)     while ($entry = $result->fetch()) {
133)         $dom = new Domain((int) $entry['domain']);
134)         if ($dom->fqdn != config('masterdomain') && $dom->fqdn != config('user_vhosts_domain')) {
135)             $dom->ensure_userdomain();
136)         }
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

137)         $entry['fqdn'] = $entry['hostname'] . '.' . $dom->fqdn;
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

138)         if (!$entry['hostname']) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

139)             $entry['fqdn'] = $dom->fqdn;
140)         }
141)         array_push($data, $entry);
Bernd Wurst Erzeuge DNS-Records der For...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

145) }
146) 
Hanno Böck add HTTPS DNS record type s...

Hanno Böck authored 5 months ago

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

bernd authored 16 years ago

148) 
149) 
150) function blank_dns_record($type)
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

151) {
152)     global $valid_record_types;
153)     if (!in_array(strtolower($type), $valid_record_types)) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

154)         system_failure('invalid type: ' . $type);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

156)     $rec = ['hostname' => null,
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 8 months ago

157)         'domain' => 0,
158)         'type' => strtolower($type),
159)         'ttl' => 3600,
160)         'ip' => null,
161)         'dyndns' => null,
162)         'data' => null,
163)         'spec' => null, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 16 years ago

169) }
170) 
171) function get_dns_record($id)
172) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

174)     $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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

184) 
185) 
186) function get_domain_records($dom)
187) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

191)     while ($entry = $result->fetch()) {
192)         $dom = new Domain((int) $entry['domain']);
193)         $dom->ensure_userdomain();
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

194)         $entry['fqdn'] = $entry['hostname'] . '.' . $dom->fqdn;
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

195)         if (!$entry['hostname']) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

196)             $entry['fqdn'] = $dom->fqdn;
197)         }
198)         array_push($data, $entry);
199)     }
200)     DEBUG($data);
201)     return $data;
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

202) }
203) 
bernd some updates

bernd authored 16 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

208)     while ($entry = $result->fetch()) {
209)         array_push($data, $entry);
210)     }
211)     DEBUG($data);
212)     return $data;
bernd some updates

bernd authored 16 years ago

213) }
214) 
bernd Stub für dns-Admin-Interface

bernd authored 16 years ago

215) 
Hanno Böck Spezialfall TXT/SPF-Record...

Hanno Böck authored 1 year ago

216) function warn_autorecord_collission($hostname, $domain, $type, $data)
Hanno Böck fix codingstyle

Hanno Böck authored 4 years ago

217) {
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

218)     $autorecords = get_domain_auto_records($domain);
219)     foreach ($autorecords as $ar) {
Bernd Wurst warnings vermeiden

Bernd Wurst authored 7 months ago

220)         if (is_string($data) && !str_starts_with($data, "v=spf1") && $hostname == null) {
Hanno Böck Spezialfall TXT/SPF-Record...

Hanno Böck authored 1 year ago

221)             // Spezialfall SPF-Record
222)             continue;
223)         }
Bernd Wurst added support for SRV recor...

Bernd Wurst authored 4 years ago

224)         if ($ar['hostname'] == $hostname && $ar['type'] == $type) {
225)             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.');
226)             break;
227)         }
228)     }
229) }
230) 
231) 
Hanno Böck add HTTPS DNS record type s...

Hanno Böck authored 5 months ago

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

bernd authored 16 years ago

233) 
234) function save_dns_record($id, $record)
235) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

236)     global $valid_record_types;
237)     global $implemented_record_types;
238)     $record['type'] = strtolower($record['type']);
239)     if (!in_array($record['type'], $valid_record_types)) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

240)         system_failure('invalid type: ' . $record['type']);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

241)     }
242)     if (!in_array($record['type'], $implemented_record_types)) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

243)         system_failure('record type ' . $record['type'] . ' not implemented at the moment.');
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

244)     }
245)     $dom = new Domain((int) $record['domain']);
246)     $dom->ensure_userdomain();
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

247)     if (!$dom->id) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

248)         system_failure('invalid domain');
249)     }
250)     if ($record['hostname'] == '') {
251)         $record['hostname'] = null;
252)     }
253)     verify_input_hostname($record['hostname'], true);
Hanno Böck add HTTPS DNS record type s...

Hanno Böck authored 5 months ago

254)     /* HTTPS record type allows quotes, we check format below */
255)     if ($record['type'] != 'https') {
256)         verify_input_recorddata($record['data']);
257)     }
Hanno Böck Remove some unneeded whites...

Hanno Böck authored 1 year ago

258)     if ($record['ttl'] && (int) $record['ttl'] < 1) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

259)         system_failure('Fehler bei TTL');
260)     }
Hanno Böck Spezialfall TXT/SPF-Record...

Hanno Böck authored 1 year ago

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

Hanno authored 6 years ago

262)     switch ($record['type']) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

263)         case 'a':
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;
271)             }
272)             break;
273)         case 'aaaa':
274)             if ($record['dyndns']) {
275)                 get_dyndns_account($record['dyndns']);
276)                 $record['ip'] = null;
277)             } else {
278)                 $record['dyndns'] = null;
279)                 verify_input_ipv6($record['ip']);
280)                 $record['data'] = null;
281)                 $record['spec'] = null;
282)             }
283)             break;
284)         case 'mx':
285)             $record['dyndns'] = null;
286)             $record['spec'] = (int) $record['spec'];
287)             if ($record['spec'] < 0) {
288)                 system_failure("invalid priority");
289)             }
Bernd Wurst check length of DNS records...

Bernd Wurst authored 1 year ago

290)             if (strlen($record['data']) > 255) {
291)                 system_failure('data field is too long');
292)             }
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

293)             verify_input_hostname($record['data']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

294)             if (!$record['data']) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

295)                 system_failure('MX hostname missing');
296)             }
297)             $record['ip'] = null;
298)             break;
299)         case 'ptr':
300)         case 'ns':
301)             if (!$record['hostname']) {
302)                 system_failure("Die angestrebte Konfiguration wird nicht funktionieren, Speichern wurde daher verweigert.");
303)             }
304)             // no break
305)         case 'cname':
306)             $record['dyndns'] = null;
307)             $record['spec'] = null;
308)             $record['ip'] = null;
Bernd Wurst check length of DNS records...

Bernd Wurst authored 1 year ago

309)             if (strlen($record['data']) > 255) {
310)                 system_failure('data field is too long');
311)             }
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

312)             verify_input_hostname($record['data']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

313)             if (!$record['data']) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

314)                 system_failure('destination host missing');
315)             }
316)             break;
317) 
318)         case 'spf':
319)         case 'txt':
320)             $record['dyndns'] = null;
321)             $record['spec'] = null;
322)             $record['ip'] = null;
Bernd Wurst check length of DNS records...

Bernd Wurst authored 1 year ago

323)             if (strlen($record['data']) > 1024) {
324)                 system_failure('data field is too long');
325)             }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

326)             if (!$record['data']) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

327)                 system_failure('text entry missing');
328)             }
329)             break;
330) 
331)         case 'sshfp':
332)             $record['dyndns'] = null;
333)             $record['spec'] = max((int) $record['spec'], 1);
334)             $record['ip'] = null;
Bernd Wurst check length of DNS records...

Bernd Wurst authored 1 year ago

335)             if (strlen($record['data']) > 255) {
336)                 system_failure('data field is too long');
337)             }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

338)             if (!$record['data']) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

339)                 system_failure('text entry missing');
340)             }
341)             break;
342) 
343)         case 'caa':
344)             $record['dyndns'] = null;
345)             $record['ip'] = null;
Bernd Wurst check length of DNS records...

Bernd Wurst authored 1 year ago

346)             if (strlen($record['data']) > 255) {
347)                 system_failure('data field is too long');
348)             }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

349)             if (!$record['data']) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

350)                 system_failure('text entry missing');
351)             }
352)             break;
353) 
354)         case 'srv':
355)             $record['dyndns'] = null;
356)             $record['spec'] = (int) $record['spec'];
357)             if ($record['spec'] < 0) {
358)                 system_failure("invalid priority");
359)             }
Bernd Wurst check length of DNS records...

Bernd Wurst authored 1 year ago

360)             if (strlen($record['data']) > 255) {
361)                 system_failure('data field is too long');
362)             }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

363)             if (!$record['data']) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

364)                 system_failure('SRV target missing');
365)             }
366)             $data = explode(':', $record['data']);
367)             if (count($data) != 2) {
368)                 system_failure('Das eingegebene Ziel war nicht im Format hostname:port');
369)             }
370)             [$hostname, $port] = $data;
371)             verify_input_hostname($hostname);
Hanno Böck codingstyle - spaces with c...

Hanno Böck authored 11 months ago

372)             if ($port !== (string) (int) $port || (int) $port < 1 || (int) $port > 65535) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

373)                 system_failure('Ungültige Portnummer');
374)             }
375)             $record['ip'] = null;
376)             break;
Hanno Böck add HTTPS DNS record type s...

Hanno Böck authored 5 months ago

377) 
378)         case 'https':
379)             $record['dyndns'] = null;
380)             $record['ip'] = null;
381)             $record['spec'] = (int) $record['spec'];
382)             if ($record['spec'] < 0) {
383)                 system_failure("invalid priority");
384)             }
385)             if ((!$record['data']) || (strlen($record['data']) == 0)) {
386)                 system_failure('data is missing');
387)             }
388)             if (strlen($record['data']) > 255) {
389)                 system_failure('data field is too long');
390)             }
391)             $data = explode(' ', $record['data']);
392)             $host = array_shift($data);
393)             if ($host != "." && !filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
394)                 system_failure("Ungültiger Hostname!");
395)             }
396)             foreach($data as $d) {
397)                 if (!(preg_match('/[a-z0-9]+=([a-z0-9,:.]+|"[a-z0-9,:.]+")/', $d))) {
398)                     system_failure("Ungültiger HTTPS record!");
399)                 }
400)             }
401)             break;
402) 
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 2 years ago

403)         default:
404)             system_failure('Not implemented');
405)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

407)     $args = [":domain" => $dom->id,
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 8 months ago

408)         ":hostname" => $record['hostname'],
409)         ":type" => $record['type'],
410)         ":ttl" => ($record['ttl'] == 0 ? null : (int) $record['ttl']),
411)         ":ip" => $record['ip'],
412)         ":dyndns" => $record['dyndns'],
413)         ":data" => $record['data'],
414)         ":spec" => $record['spec'], ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

415)     if ($id) {
416)         $args[":id"] = $id;
417)         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);
418)     } else {
419)         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);
420)     }
bernd add save function

bernd authored 16 years ago

421) }
422) 
423) 
424) function delete_dns_record($id)
425) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

431) 
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

432) 
433) function convert_from_autorecords($domainid)
434) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

435)     $dom = new Domain((int) $domainid);
436)     $dom->ensure_userdomain();
437)     $dom = $dom->id;
438) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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

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

443) }
444) 
445) 
446) function enable_autorecords($domainid)
447) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

448)     $dom = new Domain((int) $domainid);
449)     $dom->ensure_userdomain();
450)     $dom = $dom->id;
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

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

Hanno Böck authored 3 years ago

452)     db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id=?", [$dom]);
453)     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

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

455) }
456) 
457) function disable_autorecords($domainid)
458) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

459)     $dom = new Domain((int) $domainid);
460)     $dom->ensure_userdomain();
461)     $dom = $dom->id;
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

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

Hanno Böck authored 3 years ago

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

bernd authored 15 years ago

464) }
465) 
466) 
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 12 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 12 years ago

473) }
474) 
bernd Autodns ein- und ausschaltb...

bernd authored 15 years ago

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

Hanno Böck authored 3 years ago

476) $own_ns = [];
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) function own_ns()
479) {
480)     global $own_ns;
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

482)     if (count($own_ns) < 1) {
483)         $auth = dns_get_record(config('masterdomain'), DNS_NS);
484)         foreach ($auth as $ns) {
485)             $own_ns[] = $ns['target'];
486)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 10 years ago

490) }
491) 
492) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

495) function check_dns($domainname, $tld)
496) {
497)     global $tld_ns;
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

498)     $domain = idn_to_ascii($domainname . "." . $tld, 0, INTL_IDNA_VARIANT_UTS46);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

499) 
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

500)     if (!isset($tld_ns[$tld])) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

501)         $resp = shell_exec('dig @a.root-servers.net. +noall +authority -t ns ' . $tld . '.');
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

502)         $line = explode("\n", $resp, 2)[0];
503)         $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+)$/", '\1', $line);
504)         $tld_ns[$tld] = $NS;
505)     }
Hanno remove whitespace in empty...

Hanno authored 6 years ago

506) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 1 year ago

507)     $resp = shell_exec('dig @' . $tld_ns[$tld] . ' +noall +authority -t ns ' . $domain . '.');
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

508)     $line = explode("\n", $resp, 2)[0];
509)     if (preg_match('/^.*\\sIN\\s+NS\\s+/', $line) === 0) {
510)         return "NXDOMAIN";
511)     }
512)     $NS = preg_replace("/^.*\\sIN\\s+NS\\s+(\\S+).$/", '\1', $line);
Hanno remove whitespace in empty...

Hanno authored 6 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 6 years ago

516)     if (in_array($NS, $own_ns)) {
517)         return true;
518)     }
519)     return $NS;
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

520) }
521) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

522) function remove_from_dns($dom)
523) {
524)     $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
525)     $current = null;
526)     foreach ($domains as $d) {
527)         if ($d->id == $dom && $d->dns == 1) {
528)             $current = $d;
529)             break;
530)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

531)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

532)     if (!$current) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

533)         system_failure("Domain nicht gefunden!");
534)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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

536) }
537) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

538) function add_to_dns($dom)
539) {
540)     $domains = get_domain_list($_SESSION['customerinfo']['customerno'], $_SESSION['userinfo']['uid']);
541)     $current = null;
542)     foreach ($domains as $d) {
543)         if ($d->id == $dom && $d->dns == 0) {
544)             $current = $d;
545)             break;
546)         }
Bernd Wurst Warne, wenn bei den DNS-Ser...

Bernd Wurst authored 10 years ago

547)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

548)     if (!$current) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

549)         system_failure("Domain nicht gefunden!");
550)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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