3490c29038f1262d92793b56d46d33aebdfd0d41
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

1) <?php
2) 
3) require_once('inc/debug.php');
4) require_once('inc/db_connect.php');
5) require_once('inc/base.php');
6) require_once('inc/security.php');
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

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

bernd authored 15 years ago

8) 
9) require_once('class/domain.php');
10) 
11) 
12) function get_dyndns_accounts() 
13) {
14)   $uid = (int) $_SESSION['userinfo']['uid'];
15)   $result = db_query("SELECT * FROM dns.dyndns WHERE uid={$uid}");
16)   $list = array();
17)   while ($item = mysql_fetch_assoc($result)) {
18)     array_push($list, $item);
19)   }
20)   DEBUG($list);
21)   return $list;
22) }
23) 
24) 
25) function get_dyndns_account($id) 
26) {
27)   $id = (int) $id;
28)   $uid = (int) $_SESSION['userinfo']['uid'];
29)   $result = db_query("SELECT * FROM dns.dyndns WHERE id={$id} AND uid={$uid}");
30)   if (mysql_num_rows($result) != 1) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

32)     system_failure("Account ungültig");
33)   }
34)   $item = mysql_fetch_assoc($result);
35)   DEBUG($item);
36)   return $item;
37) }
38) 
39) 
40) function create_dyndns_account($handle, $password_http, $sshkey)
41) {
42)   $uid = (int) $_SESSION['userinfo']['uid'];
bernd Warnings eliminiert und Plu...

bernd authored 14 years ago

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

bernd authored 15 years ago

47)   $handle = maybe_null(mysql_real_escape_string(filter_input_username($handle)));
48)   $sshkey = maybe_null(mysql_real_escape_string(filter_input_general($sshkey)));
49) 
50)   $pwhash = 'NULL';
51)   if ($password_http)
52)     $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
53) 
54)   db_query("INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ({$uid}, {$handle}, {$pwhash}, {$sshkey})");
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 15 years ago

56) }
57) 
58) 
59) function edit_dyndns_account($id, $handle, $password_http, $sshkey)
60) {
61)   $id = (int) $id;
62)   $handle = maybe_null(mysql_real_escape_string(filter_input_username($handle)));
63)   $sshkey = maybe_null(mysql_real_escape_string(filter_input_general($sshkey)));
64) 
65)   $pwhash = 'NULL';
66)   if ($password_http)
bernd HTTP-Passwort ignorieren we...

bernd authored 15 years ago

67)   {
68)     if ($password_http == '************')
69)       $pwhash = 'password';
70)     else
71)       $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
72)   }
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

73) 
74)   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

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

bernd authored 15 years ago

76) }
77) 
78) 
79) function delete_dyndns_account($id)
80) {
81)   $id = (int) $id;
82) 
83)   db_query("DELETE FROM dns.dyndns WHERE id={$id} LIMIT 1");
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 15 years ago

85) }
86) 
87) 
88) function get_dyndns_records($id)
89) {
90)   $id = (int) $id;
91)   $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns={$id}");
92)   $data = array();
93)   while ($entry = mysql_fetch_assoc($result)) {
94)     $dom = new Domain((int) $entry['domain']);
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 15 years ago

96)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
97)     if (! $entry['hostname'])
98)       $entry['fqdn'] = $dom->fqdn;
99)     array_push($data, $entry);
100)   }
101)   DEBUG($data);
102)   return $data;
103) }
104) 
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

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

bernd authored 15 years ago

106) 
107) 
108) function blank_dns_record($type)
109) { 
110)   global $valid_record_types;
111)   if (!in_array(strtolower($type), $valid_record_types))
112)     system_failure('invalid type: '.$type);
113)   $rec = array('hostname' => NULL,
114)                'domain' => 0,
115)                'type' => strtolower($type),
116)                'ttl' => 3600,
117)                'ip' => NULL,
118)                'dyndns' => NULL,
119)                'data' => NULL,
120)                'spec' => NULL);
121)   if (strtolower($type) == 'mx')
122)   {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 15 years ago

124)     $rec['spec'] = '5';
125)   }
126)   return $rec;
127) }
128) 
129) function get_dns_record($id)
130) {
131)   $id = (int) $id;
132)   $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id={$id}");
133)   if (mysql_num_rows($result) != 1)
134)     system_failure('illegal ID');
135)   $data = mysql_fetch_assoc($result);
bernd add save function

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

141) 
142) 
143) function get_domain_records($dom)
144) {
145)   $dom = (int) $dom;
bernd some updates

bernd authored 15 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

151)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
152)     if (! $entry['hostname'])
153)       $entry['fqdn'] = $dom->fqdn;
154)     array_push($data, $entry);
155)   }
156)   DEBUG($data);
157)   return $data;
158) }
159) 
bernd some updates

bernd authored 15 years ago

160) function get_domain_auto_records($domainname)
161) {
162)   $domainname = mysql_real_escape_string($domainname);
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

163)   //$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 15 years ago

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

165)   $data = array();
166)   while ($entry = mysql_fetch_assoc($result)) {
167)     array_push($data, $entry);
168)   }
169)   DEBUG($data);
170)   return $data;
171) }
172) 
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

175) 
176) function save_dns_record($id, $record)
177) {
178)   global $valid_record_types;
179)   global $implemented_record_types;
180)   $record['type'] = strtolower($record['type']);
181)   if (!in_array($record['type'], $valid_record_types))
182)     system_failure('invalid type: '.$record['type']);
183)   if (!in_array($record['type'], $implemented_record_types))
184)     system_failure('record type '.$record['type'].' not implemented at the moment.');
185)   $dom = new Domain( (int) $record['domain'] );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

190)   if ($record['ttl'] &&  (int) $record['ttl'] < 1)
191)     system_failure('Fehler bei TTL');
192)   switch ($record['type']) 
193)   {
194)     case 'a':
195)       if ($record['dyndns'])
196)       {
197)         get_dyndns_account( $record['dyndns'] );
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

199)       }
200)       else
201)       {
202)         verify_input_ipv4($record['ip']);
203)         $record['data'] = '';
204)         $record['spec'] = '';
205)       }
206)       break;
207)     case 'aaaa':
208)       $record['dyndns'] = '';
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

210)       $record['data'] = '';
211)       $record['spec'] = '';
212)       break;
213)     case 'mx':
214)       $record['dyndns'] = '';
215)       $record['spec'] = (int) $record['spec'];
216)       if ($record['spec'] < 1)
217)         systen_failure("invalid priority");
218)       verify_input_hostname($record['data']);
219)       if (! $record['data'] )
220)         system_failure('MX hostname missing');
221)       $record['ip'] = '';
222)       break;
223)     case 'cname':
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 14 years ago

225)     case 'ns':
bernd add save function

bernd authored 15 years ago

226)       $record['dyndns'] = '';
227)       $record['spec'] = '';
228)       $record['ip'] = '';
229)       verify_input_hostname($record['data']);
230)       if (! $record['data'] )
bernd SPF und TXT records

bernd authored 14 years ago

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

bernd authored 15 years ago

232)       break;
233) 
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

234)     case 'spf':
235)     case 'txt':
bernd SPF und TXT records

bernd authored 14 years ago

236)       $record['dyndns'] = '';
237)       $record['spec'] = '';
238)       $record['ip'] = '';
239)       if (! $record['data'] )
240)         system_failure('text entry missing');
241)       break;
242) 
bernd SSHFP-Records (Thanks to Ma...

bernd authored 12 years ago

243)     case 'sshfp':
244)       $record['dyndns'] = '';
245)       $record['spec'] = max( (int) $record['spec'], 1);
246)       $record['ip'] = '';
247)       if (! $record['data'] )
248)         system_failure('text entry missing');
249)       break;
250) 
251) 
bernd add save function

bernd authored 15 years ago

252)     case 'srv':
253)       system_failure('not implemented yet');
254)     default:
255)       system_failure('Not implemented');
256)   }
257)   $id = (int) $id;
258)   $record['hostname'] = maybe_null($record['hostname']);
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

260)   $record['ip'] = maybe_null($record['ip']);
261)   $record['data'] = maybe_null($record['data']);
262)   $record['spec'] = maybe_null($record['spec']);
263)   $record['dyndns'] = maybe_null($record['dyndns']);
264)   if ($id)
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

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

bernd authored 15 years ago

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

268) 
269) }
270) 
271) 
272) function delete_dns_record($id)
273) {
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

279) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

280) 
281) function convert_from_autorecords($domainid)
282) {
283)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 14 years ago

285)   $dom = $dom->id;
286) 
287)   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}");
288)   disable_autorecords($dom);
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

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

291) }
292) 
293) 
294) function enable_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("UPDATE kundendaten.domains SET autodns=1 WHERE id={$dom} LIMIT 1");
bernd Neue Autorecords-Tabelle

bernd authored 13 years ago

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

302) }
303) 
304) function disable_autorecords($domainid)
305) {
306)   $dom = new Domain( (int) $domainid );
bernd DNS-Admin-Kram erfordert Us...

bernd authored 14 years ago

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

bernd authored 14 years ago

308)   $dom = $dom->id;
309) 
310)   db_query("UPDATE kundendaten.domains SET autodns=0 WHERE id={$dom} LIMIT 1");
311) }
312) 
313) 
314)