c9a403b2fffb887a5cdb312fc55cd4bd126a0456
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']);
90)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
91)     if (! $entry['hostname'])
92)       $entry['fqdn'] = $dom->fqdn;
93)     array_push($data, $entry);
94)   }
95)   DEBUG($data);
96)   return $data;
97) }
98) 
bernd some updates

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

130)   $dom = new Domain( (int) $data['domain']);
bernd some updates

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

140)   $data = array();
141)   while ($entry = mysql_fetch_assoc($result)) {
142)     $dom = new Domain((int) $entry['domain']);
143)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
144)     if (! $entry['hostname'])
145)       $entry['fqdn'] = $dom->fqdn;
146)     array_push($data, $entry);
147)   }
148)   DEBUG($data);
149)   return $data;
150) }
151) 
bernd some updates

bernd authored 15 years ago

152) function get_domain_auto_records($domainname)
153) {
154)   $domainname = mysql_real_escape_string($domainname);
bernd Benutze temporäre Tabelle f...

bernd authored 15 years ago

155)   #$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}'");
156)   $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

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

bernd authored 15 years ago

165) 
bernd add save function

bernd authored 15 years ago

166) $implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv');
167) 
168) function save_dns_record($id, $record)
169) {
170)   global $valid_record_types;
171)   global $implemented_record_types;
172)   $record['type'] = strtolower($record['type']);
173)   if (!in_array($record['type'], $valid_record_types))
174)     system_failure('invalid type: '.$record['type']);
175)   if (!in_array($record['type'], $implemented_record_types))
176)     system_failure('record type '.$record['type'].' not implemented at the moment.');
177)   $dom = new Domain( (int) $record['domain'] );
178)   if (! $dom->id)
179)     system_failure('invalid domain');
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

215)     case 'ptr':
bernd add save function

bernd authored 15 years ago

216)       $record['dyndns'] = '';
217)       $record['spec'] = '';
218)       $record['ip'] = '';
219)       verify_input_hostname($record['data']);
220)       if (! $record['data'] )
221)         system_failure('MX hostname missing');
222)       break;
223) 
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

224)     case 'spf':
225)     case 'txt':
bernd add save function

bernd authored 15 years ago

226)     case 'srv':
227)       system_failure('not implemented yet');
228)     default:
229)       system_failure('Not implemented');
230)   }
231)   $id = (int) $id;
232)   $record['hostname'] = maybe_null($record['hostname']);
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

234)   $record['ip'] = maybe_null($record['ip']);
235)   $record['data'] = maybe_null($record['data']);
236)   $record['spec'] = maybe_null($record['spec']);
237)   $record['dyndns'] = maybe_null($record['dyndns']);
238)   if ($id)
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

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

bernd authored 15 years ago

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

242) 
243) }
244) 
245) 
246) function delete_dns_record($id)
247) {
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

252) }