c208bd906b3991555db11b9229846c4601ca408c
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) 
5) Written 2008-2012 by schokokeks.org Hosting, namely
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/db_connect.php');
19) require_once('inc/base.php');
20) require_once('inc/security.php');
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

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

bernd authored 15 years ago

22) 
23) require_once('class/domain.php');
24) 
25) 
26) function get_dyndns_accounts() 
27) {
28)   $uid = (int) $_SESSION['userinfo']['uid'];
29)   $result = db_query("SELECT * FROM dns.dyndns WHERE uid={$uid}");
30)   $list = array();
31)   while ($item = mysql_fetch_assoc($result)) {
32)     array_push($list, $item);
33)   }
34)   DEBUG($list);
35)   return $list;
36) }
37) 
38) 
39) function get_dyndns_account($id) 
40) {
41)   $id = (int) $id;
42)   $uid = (int) $_SESSION['userinfo']['uid'];
43)   $result = db_query("SELECT * FROM dns.dyndns WHERE id={$id} AND uid={$uid}");
44)   if (mysql_num_rows($result) != 1) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

46)     system_failure("Account ungültig");
47)   }
48)   $item = mysql_fetch_assoc($result);
49)   DEBUG($item);
50)   return $item;
51) }
52) 
53) 
54) function create_dyndns_account($handle, $password_http, $sshkey)
55) {
56)   $uid = (int) $_SESSION['userinfo']['uid'];
bernd Warnings eliminiert und Plu...

bernd authored 14 years ago

57) 
58)   if ($password_http == '' && $sshkey == '')
59)     system_failure('Sie müssen entweder einen SSH-Key oder ein Passwort zum Web-Update eingeben.');  
60) 
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

70) }
71) 
72) 
73) function edit_dyndns_account($id, $handle, $password_http, $sshkey)
74) {
75)   $id = (int) $id;
76)   $handle = maybe_null(mysql_real_escape_string(filter_input_username($handle)));
77)   $sshkey = maybe_null(mysql_real_escape_string(filter_input_general($sshkey)));
78) 
79)   $pwhash = 'NULL';
80)   if ($password_http)
bernd HTTP-Passwort ignorieren we...

bernd authored 14 years ago

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

bernd authored 15 years ago

87) 
88)   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

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

99) }
100) 
101) 
102) function get_dyndns_records($id)
103) {
104)   $id = (int) $id;
105)   $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns={$id}");
106)   $data = array();
107)   while ($entry = mysql_fetch_assoc($result)) {
108)     $dom = new Domain((int) $entry['domain']);
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

138)     $rec['spec'] = '5';
139)   }
140)   return $rec;
141) }
142) 
143) function get_dns_record($id)
144) {
145)   $id = (int) $id;
146)   $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id={$id}");
147)   if (mysql_num_rows($result) != 1)
148)     system_failure('illegal ID');
149)   $data = mysql_fetch_assoc($result);
bernd add save function

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

161)   $data = array();
162)   while ($entry = mysql_fetch_assoc($result)) {
163)     $dom = new Domain((int) $entry['domain']);
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

174) function get_domain_auto_records($domainname)
175) {
176)   $domainname = mysql_real_escape_string($domainname);
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

177)   //$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

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

179)   $data = array();
180)   while ($entry = mysql_fetch_assoc($result)) {
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 DNs-record-Interface ist je...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

224)       $record['data'] = '';
225)       $record['spec'] = '';
226)       break;
227)     case 'mx':
228)       $record['dyndns'] = '';
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');
235)       $record['ip'] = '';
236)       break;
237)     case 'cname':
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

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

bernd authored 14 years ago

239)     case 'ns':
bernd add save function

bernd authored 15 years ago

240)       $record['dyndns'] = '';
241)       $record['spec'] = '';
242)       $record['ip'] = '';
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 14 years ago

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

bernd authored 14 years ago

250)       $record['dyndns'] = '';
251)       $record['spec'] = '';
252)       $record['ip'] = '';
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':
258)       $record['dyndns'] = '';
259)       $record['spec'] = max( (int) $record['spec'], 1);
260)       $record['ip'] = '';
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;
272)   $record['hostname'] = maybe_null($record['hostname']);
bernd DNs-record-Interface ist je...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

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

bernd authored 14 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

293) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 13 years ago

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

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 13 years ago

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

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

bernd authored 14 years ago

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

bernd authored 14 years ago

322)   $dom = $dom->id;
323) 
324)   db_query("UPDATE kundendaten.domains SET autodns=0 WHERE id={$dom} LIMIT 1");
325) }
326) 
327) 
328)