f1f231f5e074dfa038e70a67d39849e80f2b4b4d
bernd Stub für dns-Admin-Interface

bernd authored 15 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 Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 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) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
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 15 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 13 years ago

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

bernd authored 15 years ago

21) 
22) require_once('class/domain.php');
23) 
24) 
25) function get_dyndns_accounts() 
26) {
27)   $uid = (int) $_SESSION['userinfo']['uid'];
28)   $result = db_query("SELECT * FROM dns.dyndns WHERE uid={$uid}");
29)   $list = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

30)   while ($item = $result->fetch()) {
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

31)     array_push($list, $item);
32)   }
33)   DEBUG($list);
34)   return $list;
35) }
36) 
37) 
38) function get_dyndns_account($id) 
39) {
40)   $id = (int) $id;
41)   $uid = (int) $_SESSION['userinfo']['uid'];
42)   $result = db_query("SELECT * FROM dns.dyndns WHERE id={$id} AND uid={$uid}");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

43)   if ($result->rowCount() != 1) {
bernd Logger mit Logleveln

bernd authored 14 years ago

44)     logger(LOG_WARNING, "modules/dns/include/dnsinclude", "dyndns", "account »{$id}« invalid for uid »{$uid}«.");
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

45)     system_failure("Account ungültig");
46)   }
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

47)   $item = $result->fetch();
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

48)   DEBUG($item);
49)   return $item;
50) }
51) 
52) 
53) function create_dyndns_account($handle, $password_http, $sshkey)
54) {
55)   $uid = (int) $_SESSION['userinfo']['uid'];
bernd Warnings eliminiert und Plu...

bernd authored 14 years ago

56) 
57)   if ($password_http == '' && $sshkey == '')
58)     system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');  
59) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

60)   $handle = maybe_null(db_escape_string(filter_input_username($handle)));
61)   $sshkey = maybe_null(db_escape_string(filter_input_general($sshkey)));
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

62) 
63)   $pwhash = 'NULL';
64)   if ($password_http)
65)     $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
66) 
67)   db_query("INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ({$uid}, {$handle}, {$pwhash}, {$sshkey})");
bernd Logger mit Logleveln

bernd authored 14 years ago

68)   logger(LOG_INFO, "modules/dns/include/dnsinclude", "dyndns", "inserted account");
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

69) }
70) 
71) 
72) function edit_dyndns_account($id, $handle, $password_http, $sshkey)
73) {
74)   $id = (int) $id;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

75)   $handle = maybe_null(db_escape_string(filter_input_username($handle)));
76)   $sshkey = maybe_null(db_escape_string(filter_input_general($sshkey)));
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

77) 
78)   $pwhash = 'NULL';
79)   if ($password_http)
bernd HTTP-Passwort ignorieren we...

bernd authored 14 years ago

80)   {
81)     if ($password_http == '************')
82)       $pwhash = 'password';
83)     else
84)       $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
85)   }
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

86) 
87)   db_query("UPDATE dns.dyndns SET handle={$handle}, password={$pwhash}, sshkey={$sshkey} WHERE id={$id} LIMIT 1");
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 15 years ago

89) }
90) 
91) 
92) function delete_dyndns_account($id)
93) {
94)   $id = (int) $id;
95) 
96)   db_query("DELETE FROM dns.dyndns WHERE id={$id} LIMIT 1");
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 15 years ago

98) }
99) 
100) 
101) function get_dyndns_records($id)
102) {
103)   $id = (int) $id;
104)   $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns={$id}");
105)   $data = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

106)   while ($entry = $result->fetch()) {
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

107)     $dom = new Domain((int) $entry['domain']);
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

108)     $dom->ensure_userdomain();
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

109)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
110)     if (! $entry['hostname'])
111)       $entry['fqdn'] = $dom->fqdn;
112)     array_push($data, $entry);
113)   }
114)   DEBUG($data);
115)   return $data;
116) }
117) 
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

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

bernd authored 15 years ago

119) 
120) 
121) function blank_dns_record($type)
122) { 
123)   global $valid_record_types;
124)   if (!in_array(strtolower($type), $valid_record_types))
125)     system_failure('invalid type: '.$type);
126)   $rec = array('hostname' => NULL,
127)                'domain' => 0,
128)                'type' => strtolower($type),
129)                'ttl' => 3600,
130)                'ip' => NULL,
131)                'dyndns' => NULL,
132)                'data' => NULL,
133)                'spec' => NULL);
134)   if (strtolower($type) == 'mx')
135)   {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

136)     $rec['data'] = config('default_mx');
bernd some updates

bernd authored 15 years ago

137)     $rec['spec'] = '5';
138)   }
139)   return $rec;
140) }
141) 
142) function get_dns_record($id)
143) {
144)   $id = (int) $id;
145)   $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id={$id}");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

146)   if ($result->rowCount() != 1)
bernd some updates

bernd authored 15 years ago

147)     system_failure('illegal ID');
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

148)   $data = $result->fetch();
bernd add save function

bernd authored 15 years ago

149)   $dom = new Domain( (int) $data['domain']);
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

150)   $dom->ensure_userdomain();
bernd some updates

bernd authored 15 years ago

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

bernd authored 15 years ago

154) 
155) 
156) function get_domain_records($dom)
157) {
158)   $dom = (int) $dom;
bernd some updates

bernd authored 15 years ago

159)   $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl, id FROM dns.custom_records WHERE domain={$dom}");
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

160)   $data = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

161)   while ($entry = $result->fetch()) {
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

162)     $dom = new Domain((int) $entry['domain']);
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

163)     $dom->ensure_userdomain();
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

164)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
165)     if (! $entry['hostname'])
166)       $entry['fqdn'] = $dom->fqdn;
167)     array_push($data, $entry);
168)   }
169)   DEBUG($data);
170)   return $data;
171) }
172) 
bernd some updates

bernd authored 15 years ago

173) function get_domain_auto_records($domainname)
174) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

175)   $domainname = db_escape_string($domainname);
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

176)   //$result = db_query("SELECT hostname, domain, CONCAT_WS('.', hostname, domain) AS fqdn, type, ip, spec, data, TRIM(ttl) FROM dns.v_autogenerated_records WHERE domain='{$domainname}'");
bernd Benutze temporäre Tabelle f...

bernd authored 14 years ago

177)   $result = db_query("SELECT hostname, domain, CONCAT_WS('.', hostname, domain) AS fqdn, type, ip, spec, data, ttl FROM dns.tmp_autorecords WHERE domain='{$domainname}'");
bernd some updates

bernd authored 15 years ago

178)   $data = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

179)   while ($entry = $result->fetch()) {
bernd some updates

bernd authored 15 years ago

180)     array_push($data, $entry);
181)   }
182)   DEBUG($data);
183)   return $data;
184) }
185) 
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

186) 
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

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

bernd authored 15 years ago

188) 
189) function save_dns_record($id, $record)
190) {
191)   global $valid_record_types;
192)   global $implemented_record_types;
193)   $record['type'] = strtolower($record['type']);
194)   if (!in_array($record['type'], $valid_record_types))
195)     system_failure('invalid type: '.$record['type']);
196)   if (!in_array($record['type'], $implemented_record_types))
197)     system_failure('record type '.$record['type'].' not implemented at the moment.');
198)   $dom = new Domain( (int) $record['domain'] );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

199)   $dom->ensure_userdomain();
bernd add save function

bernd authored 15 years ago

200)   if (! $dom->id)
201)     system_failure('invalid domain');
bernd Erlaube * im Hostname

bernd authored 14 years ago

202)   verify_input_hostname($record['hostname'], true);
bernd add save function

bernd authored 15 years ago

203)   if ($record['ttl'] &&  (int) $record['ttl'] < 1)
204)     system_failure('Fehler bei TTL');
205)   switch ($record['type']) 
206)   {
207)     case 'a':
208)       if ($record['dyndns'])
209)       {
210)         get_dyndns_account( $record['dyndns'] );
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

211)       	$record['ip'] = '';
bernd add save function

bernd authored 15 years ago

212)       }
213)       else
214)       {
215)         verify_input_ipv4($record['ip']);
216)         $record['data'] = '';
217)         $record['spec'] = '';
218)       }
219)       break;
220)     case 'aaaa':
221)       $record['dyndns'] = '';
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

222)       verify_input_ipv6($record['ip']);
bernd add save function

bernd authored 15 years ago

223)       $record['data'] = '';
224)       $record['spec'] = '';
225)       break;
226)     case 'mx':
227)       $record['dyndns'] = '';
228)       $record['spec'] = (int) $record['spec'];
229)       if ($record['spec'] < 1)
230)         systen_failure("invalid priority");
231)       verify_input_hostname($record['data']);
232)       if (! $record['data'] )
233)         system_failure('MX hostname missing');
234)       $record['ip'] = '';
235)       break;
236)     case 'cname':
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

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

bernd authored 14 years ago

238)     case 'ns':
bernd add save function

bernd authored 15 years ago

239)       $record['dyndns'] = '';
240)       $record['spec'] = '';
241)       $record['ip'] = '';
242)       verify_input_hostname($record['data']);
243)       if (! $record['data'] )
bernd SPF und TXT records

bernd authored 14 years ago

244)         system_failure('destination host missing');
bernd add save function

bernd authored 15 years ago

245)       break;
246) 
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

247)     case 'spf':
248)     case 'txt':
bernd SPF und TXT records

bernd authored 14 years ago

249)       $record['dyndns'] = '';
250)       $record['spec'] = '';
251)       $record['ip'] = '';
252)       if (! $record['data'] )
253)         system_failure('text entry missing');
254)       break;
255) 
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

256)     case 'sshfp':
257)       $record['dyndns'] = '';
258)       $record['spec'] = max( (int) $record['spec'], 1);
259)       $record['ip'] = '';
260)       if (! $record['data'] )
261)         system_failure('text entry missing');
262)       break;
263) 
264) 
bernd add save function

bernd authored 15 years ago

265)     case 'srv':
266)       system_failure('not implemented yet');
267)     default:
268)       system_failure('Not implemented');
269)   }
270)   $id = (int) $id;
271)   $record['hostname'] = maybe_null($record['hostname']);
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

272)   $record['ttl'] = ($record['ttl'] == 0 ? 'NULL' : (int) $record['ttl']);
bernd add save function

bernd authored 15 years ago

273)   $record['ip'] = maybe_null($record['ip']);
274)   $record['data'] = maybe_null($record['data']);
275)   $record['spec'] = maybe_null($record['spec']);
276)   $record['dyndns'] = maybe_null($record['dyndns']);
277)   if ($id)
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

278)     db_query("UPDATE dns.custom_records SET hostname={$record['hostname']}, domain={$dom->id}, type='{$record['type']}', ttl={$record['ttl']}, ip={$record['ip']}, dyndns={$record['dyndns']}, data={$record['data']}, spec={$record['spec']} WHERE id={$id} LIMIT 1");
bernd add save function

bernd authored 15 years ago

279)   else
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

280)     db_query("INSERT INTO dns.custom_records (hostname, domain, type, ttl, ip, dyndns, data, spec) VALUES ({$record['hostname']}, {$dom->id}, '{$record['type']}', {$record['ttl']}, {$record['ip']}, {$record['dyndns']}, {$record['data']}, {$record['spec']})");
bernd add save function

bernd authored 15 years ago

281) 
282) }
283) 
284) 
285) function delete_dns_record($id)
286) {
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

287)   $id = (int) $id;
288)   // Diese Funktion prüft, ob der Eintrag einer eigenen Domain gehört
289)   $record = get_dns_record($id);
290)   db_query("DELETE FROM dns.custom_records WHERE id={$id} LIMIT 1");
bernd add save function

bernd authored 15 years ago

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

bernd authored 15 years ago

292) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

293) 
294) function convert_from_autorecords($domainid)
295) {
296)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

297)   $dom->ensure_userdomain();
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

298)   $dom = $dom->id;
299) 
300)   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}");
301)   disable_autorecords($dom);
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

302)   db_query("UPDATE dns.dnsstatus SET status='outdated'");
303)   warning("Die automatischen Einträge werden in Kürze abgeschaltet, bitte haben Sie einen Moment Geduld.");
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

304) }
305) 
306) 
307) function enable_autorecords($domainid)
308) {
309)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

310)   $dom->ensure_userdomain();
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

311)   $dom = $dom->id;
312) 
313)   db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id={$dom} LIMIT 1");
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

314)   warning("Die automatischen Einträge werden in Kürze aktiviert, bitte haben Sie einen Moment Geduld.");
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

315) }
316) 
317) function disable_autorecords($domainid)
318) {
319)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

320)   $dom->ensure_userdomain();
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

321)   $dom = $dom->id;
322) 
323)   db_query("UPDATE kundendaten.domains SET autodns=0 WHERE id={$dom} LIMIT 1");
324) }
325) 
326) 
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 11 years ago

327) function domain_is_maildomain($domain)
328) {
329)   $domain = (int) $domain;
330)   $result = db_query("SELECT mail FROM kundendaten.domains WHERE id={$domain}");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

331)   $dom = $result->fetch();
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 11 years ago

332)   return ($dom['mail'] != 'none');
333) }
334) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

335)