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

bernd authored 14 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

55) }
56) 
57) 
58) function edit_dyndns_account($id, $handle, $password_http, $sshkey)
59) {
60)   $id = (int) $id;
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)
bernd HTTP-Passwort ignorieren we...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

84) }
85) 
86) 
87) function get_dyndns_records($id)
88) {
89)   $id = (int) $id;
90)   $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns={$id}");
91)   $data = array();
92)   while ($entry = mysql_fetch_assoc($result)) {
93)     $dom = new Domain((int) $entry['domain']);
bernd Prüfe, ob Domain wirklich d...

bernd authored 14 years ago

94)     $dom->ensure_customerdomain();
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

95)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
96)     if (! $entry['hostname'])
97)       $entry['fqdn'] = $dom->fqdn;
98)     array_push($data, $entry);
99)   }
100)   DEBUG($data);
101)   return $data;
102) }
103) 
bernd some updates

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

135)   $dom = new Domain( (int) $data['domain']);
bernd Prüfe, ob Domain wirklich d...

bernd authored 14 years ago

136)   $dom->ensure_customerdomain();
bernd some updates

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

146)   $data = array();
147)   while ($entry = mysql_fetch_assoc($result)) {
148)     $dom = new Domain((int) $entry['domain']);
bernd Prüfe, ob Domain wirklich d...

bernd authored 14 years ago

149)     $dom->ensure_customerdomain();
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

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

bernd authored 15 years ago

159) function get_domain_auto_records($domainname)
160) {
161)   $domainname = mysql_real_escape_string($domainname);
bernd Benutze temporäre Tabelle f...

bernd authored 14 years ago

162)   #$result = db_query("SELECT hostname, domain, CONCAT_WS('.', hostname, domain) AS fqdn, type, ip, spec, data, ttl FROM dns.v_autogenerated_records WHERE domain='{$domainname}'");
163)   $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

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

bernd authored 15 years ago

172) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

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

bernd authored 15 years ago

174) 
175) function save_dns_record($id, $record)
176) {
177)   global $valid_record_types;
178)   global $implemented_record_types;
179)   $record['type'] = strtolower($record['type']);
180)   if (!in_array($record['type'], $valid_record_types))
181)     system_failure('invalid type: '.$record['type']);
182)   if (!in_array($record['type'], $implemented_record_types))
183)     system_failure('record type '.$record['type'].' not implemented at the moment.');
184)   $dom = new Domain( (int) $record['domain'] );
bernd Prüfe, ob Domain wirklich d...

bernd authored 14 years ago

185)   $dom->ensure_customerdomain();
bernd add save function

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

224)     case 'ns':
bernd add save function

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

235)       $record['dyndns'] = '';
236)       $record['spec'] = '';
237)       $record['ip'] = '';
238)       if (! $record['data'] )
239)         system_failure('text entry missing');
240)       break;
241) 
bernd add save function

bernd authored 15 years ago

242)     case 'srv':
243)       system_failure('not implemented yet');
244)     default:
245)       system_failure('Not implemented');
246)   }
247)   $id = (int) $id;
248)   $record['hostname'] = maybe_null($record['hostname']);
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

250)   $record['ip'] = maybe_null($record['ip']);
251)   $record['data'] = maybe_null($record['data']);
252)   $record['spec'] = maybe_null($record['spec']);
253)   $record['dyndns'] = maybe_null($record['dyndns']);
254)   if ($id)
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

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

bernd authored 15 years ago

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

258) 
259) }
260) 
261) 
262) function delete_dns_record($id)
263) {
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

269) 
bernd Autodns ein- und ausschaltb...

bernd authored 14 years ago

270) 
271) function convert_from_autorecords($domainid)
272) {
273)   $dom = new Domain( (int) $domainid );
274)   $dom->ensure_customerdomain();
275)   $dom = $dom->id;
276) 
277)   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}");
278)   disable_autorecords($dom);
279) }
280) 
281) 
282) function enable_autorecords($domainid)
283) {
284)   $dom = new Domain( (int) $domainid );
285)   $dom->ensure_customerdomain();
286)   $dom = $dom->id;
287) 
288)   db_query("UPDATE kundendaten.domains SET autodns=1 WHERE id={$dom} LIMIT 1");
289) }
290) 
291) function disable_autorecords($domainid)
292) {
293)   $dom = new Domain( (int) $domainid );
294)   $dom->ensure_customerdomain();
295)   $dom = $dom->id;
296) 
297)   db_query("UPDATE kundendaten.domains SET autodns=0 WHERE id={$dom} LIMIT 1");
298) }
299) 
300) 
301) function sync_autorecords()
302) {
303)   db_query("CALL dns.sync_autorecords()");
304) }
305) 
306)