bd044f1842232fe8cff79d833e81d9629db1fadb
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 eliminate .php extensions f...

bernd authored 15 years ago

30)     logger("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'];
42)   $handle = maybe_null(mysql_real_escape_string(filter_input_username($handle)));
43)   $sshkey = maybe_null(mysql_real_escape_string(filter_input_general($sshkey)));
44) 
45)   $pwhash = 'NULL';
46)   if ($password_http)
47)     $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
48) 
49)   db_query("INSERT INTO dns.dyndns (uid, handle, password, sshkey) VALUES ({$uid}, {$handle}, {$pwhash}, {$sshkey})");
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 15 years ago

51) }
52) 
53) 
54) function edit_dyndns_account($id, $handle, $password_http, $sshkey)
55) {
56)   $id = (int) $id;
57)   $handle = maybe_null(mysql_real_escape_string(filter_input_username($handle)));
58)   $sshkey = maybe_null(mysql_real_escape_string(filter_input_general($sshkey)));
59) 
60)   $pwhash = 'NULL';
61)   if ($password_http)
bernd HTTP-Passwort ignorieren we...

bernd authored 14 years ago

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

bernd authored 15 years ago

68) 
69)   db_query("UPDATE dns.dyndns SET handle={$handle}, password={$pwhash}, sshkey={$sshkey} WHERE id={$id} LIMIT 1");
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 15 years ago

71) }
72) 
73) 
74) function delete_dyndns_account($id)
75) {
76)   $id = (int) $id;
77) 
78)   db_query("DELETE FROM dns.dyndns WHERE id={$id} LIMIT 1");
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

91)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
92)     if (! $entry['hostname'])
93)       $entry['fqdn'] = $dom->fqdn;
94)     array_push($data, $entry);
95)   }
96)   DEBUG($data);
97)   return $data;
98) }
99) 
bernd some updates

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

133)   DEBUG($data);
134)   return $data;
135) }
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

136) 
137) 
138) function get_domain_records($dom)
139) {
140)   $dom = (int) $dom;
bernd some updates

bernd authored 15 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

146)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
147)     if (! $entry['hostname'])
148)       $entry['fqdn'] = $dom->fqdn;
149)     array_push($data, $entry);
150)   }
151)   DEBUG($data);
152)   return $data;
153) }
154) 
bernd some updates

bernd authored 15 years ago

155) function get_domain_auto_records($domainname)
156) {
157)   $domainname = mysql_real_escape_string($domainname);
bernd Benutze temporäre Tabelle f...

bernd authored 14 years ago

158)   #$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}'");
159)   $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

160)   $data = array();
161)   while ($entry = mysql_fetch_assoc($result)) {
162)     array_push($data, $entry);
163)   }
164)   DEBUG($data);
165)   return $data;
166) }
167) 
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

168) 
bernd add save function

bernd authored 15 years ago

169) $implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv');
170) 
171) function save_dns_record($id, $record)
172) {
173)   global $valid_record_types;
174)   global $implemented_record_types;
175)   $record['type'] = strtolower($record['type']);
176)   if (!in_array($record['type'], $valid_record_types))
177)     system_failure('invalid type: '.$record['type']);
178)   if (!in_array($record['type'], $implemented_record_types))
179)     system_failure('record type '.$record['type'].' not implemented at the moment.');
180)   $dom = new Domain( (int) $record['domain'] );
bernd Prüfe, ob Domain wirklich d...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

219)     case 'ptr':
bernd add save function

bernd authored 15 years ago

220)       $record['dyndns'] = '';
221)       $record['spec'] = '';
222)       $record['ip'] = '';
223)       verify_input_hostname($record['data']);
224)       if (! $record['data'] )
bernd SPF und TXT records

bernd authored 14 years ago

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

bernd authored 15 years ago

226)       break;
227) 
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

228)     case 'spf':
229)     case 'txt':
bernd SPF und TXT records

bernd authored 14 years ago

230)       $record['dyndns'] = '';
231)       $record['spec'] = '';
232)       $record['ip'] = '';
233)       if (! $record['data'] )
234)         system_failure('text entry missing');
235)       break;
236) 
bernd add save function

bernd authored 15 years ago

237)     case 'srv':
238)       system_failure('not implemented yet');
239)     default:
240)       system_failure('Not implemented');
241)   }
242)   $id = (int) $id;
243)   $record['hostname'] = maybe_null($record['hostname']);
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

245)   $record['ip'] = maybe_null($record['ip']);
246)   $record['data'] = maybe_null($record['data']);
247)   $record['spec'] = maybe_null($record['spec']);
248)   $record['dyndns'] = maybe_null($record['dyndns']);
249)   if ($id)
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

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

bernd authored 15 years ago

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

253) 
254) }
255) 
256) 
257) function delete_dns_record($id)
258) {
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

263) }