2b7dc7178fc07fcc16613f78e19bb9f6467acef2
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'];
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

28)   $result = db_query("SELECT * FROM dns.dyndns WHERE uid=?", array($uid));
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

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) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

40)   $args = array(":id" => (int) $id,
41)                 ":uid" => (int) $_SESSION['userinfo']['uid']);
42)   $result = db_query("SELECT * FROM dns.dyndns WHERE id=:id AND uid=:uid", $args);
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 * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

62) 
Bernd Wurst String 'NULL' eliminiert

Bernd Wurst authored 10 years ago

63)   $pwhash = NULL;
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

64)   if ($password_http)
Bernd Wurst String 'NULL' eliminiert

Bernd Wurst authored 10 years ago

65)     $pwhash = "{SHA}".base64_encode(sha1($password_http, true));
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

66) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

67)   db_query("INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ".
68)            "(:uid, :handle, :pwhash, :sshkey)",
69)            array(":uid" => $uid, ":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey));
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 15 years ago

71) }
72) 
73) 
74) function edit_dyndns_account($id, $handle, $password_http, $sshkey)
75) {
76)   $id = (int) $id;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

77)   $handle = filter_input_username($handle);
78)   $sshkey = filter_input_general($sshkey);
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

79) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

80)   $pwhash = NULL;
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

81)   if ($password_http)
bernd HTTP-Passwort ignorieren we...

bernd authored 14 years ago

82)   {
83)     if ($password_http == '************')
84)       $pwhash = 'password';
85)     else
86)       $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
87)   }
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

88)   
89)   $args = array(":handle" => $handle, ":pwhash" => $pwhash, ":sshkey" => $sshkey, ":id" => $id);
90)   db_query("UPDATE dns.dyndns SET handle=:handle, password=:pwhash, sshkey=:sshkey WHERE id=:id", $args);
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 15 years ago

92) }
93) 
94) 
95) function delete_dyndns_account($id)
96) {
97)   $id = (int) $id;
98) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

99)   db_query("DELETE FROM dns.dyndns WHERE id=?", array($id));
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 15 years ago

101) }
102) 
103) 
104) function get_dyndns_records($id)
105) {
106)   $id = (int) $id;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

107)   $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns=?", array($id));
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

140)     $rec['spec'] = '5';
141)   }
142)   return $rec;
143) }
144) 
145) function get_dns_record($id)
146) {
147)   $id = (int) $id;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

148)   $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id=?", array($id));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

154)   DEBUG($data);
155)   return $data;
156) }
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

157) 
158) 
159) function get_domain_records($dom)
160) {
161)   $dom = (int) $dom;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

176) function get_domain_auto_records($domainname)
177) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

204)   if ($record['ttl'] &&  (int) $record['ttl'] < 1)
205)     system_failure('Fehler bei TTL');
206)   switch ($record['type']) 
207)   {
208)     case 'a':
209)       if ($record['dyndns'])
210)       {
211)         get_dyndns_account( $record['dyndns'] );
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

213)       }
214)       else
215)       {
216)         verify_input_ipv4($record['ip']);
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

217)         $record['data'] = NULL;
218)         $record['spec'] = NULL;
bernd add save function

bernd authored 15 years ago

219)       }
220)       break;
221)     case 'aaaa':
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

222)       $record['dyndns'] = NULL;
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

223)       verify_input_ipv6($record['ip']);
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

224)       $record['data'] = NULL;
225)       $record['spec'] = NULL;
bernd add save function

bernd authored 15 years ago

226)       break;
227)     case 'mx':
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

228)       $record['dyndns'] = NULL;
bernd add save function

bernd authored 15 years ago

229)       $record['spec'] = (int) $record['spec'];
230)       if ($record['spec'] < 1)
231)         systen_failure("invalid priority");
232)       verify_input_hostname($record['data']);
233)       if (! $record['data'] )
234)         system_failure('MX hostname missing');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

236)       break;
237)     case 'cname':
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 14 years ago

239)     case 'ns':
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

240)       $record['dyndns'] = NULL;
241)       $record['spec'] = NULL;
242)       $record['ip'] = NULL;
bernd add save function

bernd authored 15 years ago

243)       verify_input_hostname($record['data']);
244)       if (! $record['data'] )
bernd SPF und TXT records

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

248)     case 'spf':
249)     case 'txt':
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

250)       $record['dyndns'] = NULL;
251)       $record['spec'] = NULL;
252)       $record['ip'] = NULL;
bernd SPF und TXT records

bernd authored 14 years ago

253)       if (! $record['data'] )
254)         system_failure('text entry missing');
255)       break;
256) 
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

257)     case 'sshfp':
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

258)       $record['dyndns'] = NULL;
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

259)       $record['spec'] = max( (int) $record['spec'], 1);
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

260)       $record['ip'] = NULL;
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

261)       if (! $record['data'] )
262)         system_failure('text entry missing');
263)       break;
264) 
265) 
bernd add save function

bernd authored 15 years ago

266)     case 'srv':
267)       system_failure('not implemented yet');
268)     default:
269)       system_failure('Not implemented');
270)   }
271)   $id = (int) $id;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

272)   $args = array(":domain" => $dom->id,
273)                 ":hostname" => $record['hostname'],
274)                 ":type" => $record['type'],
275)                 ":ttl" => ($record['ttl'] == 0 ? NULL : (int) $record['ttl']),
276)                 ":ip" => $record['ip'],
277)                 ":dyndns" => $record['dyndns'],
278)                 ":data" => $record['data'],
279)                 ":spec" => $record['spec']);
280)   if ($id) {
281)     $args[":id"] = $id;
282)     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);
283)   } else {
284)     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);
285)   }
bernd add save function

bernd authored 15 years ago

286) 
287) }
288) 
289) 
290) function delete_dns_record($id)
291) {
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

292)   $id = (int) $id;
293)   // Diese Funktion prüft, ob der Eintrag einer eigenen Domain gehört
294)   $record = get_dns_record($id);
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

297) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

298) 
299) function convert_from_autorecords($domainid)
300) {
301)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 14 years ago

303)   $dom = $dom->id;
304) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

305)   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));
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

306)   disable_autorecords($dom);
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

307)   db_query("UPDATE dns.dnsstatus SET status='outdated'");
308)   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

309) }
310) 
311) 
312) function enable_autorecords($domainid)
313) {
314)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 14 years ago

316)   $dom = $dom->id;
317) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

318)   db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id=?", array($dom));
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

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

320) }
321) 
322) function disable_autorecords($domainid)
323) {
324)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 14 years ago

326)   $dom = $dom->id;
327) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

329) }
330) 
331) 
Bernd Wurst Warnung, wenn man bei einer...

Bernd Wurst authored 11 years ago

332) function domain_is_maildomain($domain)
333) {
334)   $domain = (int) $domain;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

335)   $result = db_query("SELECT mail FROM kundendaten.domains WHERE id=?", array($domain));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

337)   return ($dom['mail'] != 'none');
338) }
339) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

340)