6e6b6d2f074d7b478a3e6b19c3aa6df1ecdea586
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)
62)     $pwhash = "'{SHA}".base64_encode(sha1($password_http, true))."'";
63) 
64)   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

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

bernd authored 15 years ago

66) }
67) 
68) 
69) function delete_dyndns_account($id)
70) {
71)   $id = (int) $id;
72) 
73)   db_query("DELETE FROM dns.dyndns WHERE id={$id} LIMIT 1");
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 15 years ago

75) }
76) 
77) 
78) function get_dyndns_records($id)
79) {
80)   $id = (int) $id;
81)   $result = db_query("SELECT hostname, domain, type, ttl, lastchange, id FROM dns.custom_records WHERE dyndns={$id}");
82)   $data = array();
83)   while ($entry = mysql_fetch_assoc($result)) {
84)     $dom = new Domain((int) $entry['domain']);
85)     $entry['fqdn'] = $entry['hostname'].'.'.$dom->fqdn;
86)     if (! $entry['hostname'])
87)       $entry['fqdn'] = $dom->fqdn;
88)     array_push($data, $entry);
89)   }
90)   DEBUG($data);
91)   return $data;
92) }
93) 
bernd some updates

bernd authored 15 years ago

94) $valid_record_types = array('a', 'aaaa', 'mx', 'ns', 'spf', 'txt', 'cname', 'ptr', 'srv', 'raw');
95) 
96) 
97) function blank_dns_record($type)
98) { 
99)   global $valid_record_types;
100)   if (!in_array(strtolower($type), $valid_record_types))
101)     system_failure('invalid type: '.$type);
102)   $rec = array('hostname' => NULL,
103)                'domain' => 0,
104)                'type' => strtolower($type),
105)                'ttl' => 3600,
106)                'ip' => NULL,
107)                'dyndns' => NULL,
108)                'data' => NULL,
109)                'spec' => NULL);
110)   if (strtolower($type) == 'mx')
111)   {
112)     $rec['data'] = 'zucker.schokokeks.org';
113)     $rec['spec'] = '5';
114)   }
115)   return $rec;
116) }
117) 
118) function get_dns_record($id)
119) {
120)   $id = (int) $id;
121)   $result = db_query("SELECT hostname, domain, type, ip, dyndns, spec, data, ttl FROM dns.custom_records WHERE id={$id}");
122)   if (mysql_num_rows($result) != 1)
123)     system_failure('illegal ID');
124)   $data = mysql_fetch_assoc($result);
bernd add save function

bernd authored 15 years ago

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

bernd authored 15 years ago

126)   DEBUG($data);
127)   return $data;
128) }
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

129) 
130) 
131) function get_domain_records($dom)
132) {
133)   $dom = (int) $dom;
bernd some updates

bernd authored 15 years ago

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

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

bernd authored 15 years ago

147) function get_domain_auto_records($domainname)
148) {
149)   $domainname = mysql_real_escape_string($domainname);
150)   $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}'");
151)   $data = array();
152)   while ($entry = mysql_fetch_assoc($result)) {
153)     array_push($data, $entry);
154)   }
155)   DEBUG($data);
156)   return $data;
157) }
158) 
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

159) 
bernd add save function

bernd authored 15 years ago

160) $implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv');
161) 
162) function save_dns_record($id, $record)
163) {
164)   global $valid_record_types;
165)   global $implemented_record_types;
166)   $record['type'] = strtolower($record['type']);
167)   if (!in_array($record['type'], $valid_record_types))
168)     system_failure('invalid type: '.$record['type']);
169)   if (!in_array($record['type'], $implemented_record_types))
170)     system_failure('record type '.$record['type'].' not implemented at the moment.');
171)   $dom = new Domain( (int) $record['domain'] );
172)   if (! $dom->id)
173)     system_failure('invalid domain');
174)   verify_input_hostname($record['hostname']);
175)   if ($record['ttl'] &&  (int) $record['ttl'] < 1)
176)     system_failure('Fehler bei TTL');
177)   switch ($record['type']) 
178)   {
179)     case 'a':
180)       if ($record['dyndns'])
181)       {
182)         get_dyndns_account( $record['dyndns'] );
183) 	$record['ip'] = '';
184)       }
185)       else
186)       {
187)         verify_input_ipv4($record['ip']);
188)         $record['data'] = '';
189)         $record['spec'] = '';
190)       }
191)       break;
192)     case 'aaaa':
193)       $record['dyndns'] = '';
194)       verify_input_ipv4($record['ip']);
195)       $record['data'] = '';
196)       $record['spec'] = '';
197)       break;
198)     case 'mx':
199)       $record['dyndns'] = '';
200)       $record['spec'] = (int) $record['spec'];
201)       if ($record['spec'] < 1)
202)         systen_failure("invalid priority");
203)       verify_input_hostname($record['data']);
204)       if (! $record['data'] )
205)         system_failure('MX hostname missing');
206)       $record['ip'] = '';
207)       break;
208)     case 'spf':
209)     case 'txt':
210)       system_failure('not implemented yet');
211)     case 'cname':
212)       $record['dyndns'] = '';
213)       $record['spec'] = '';
214)       $record['ip'] = '';
215)       verify_input_hostname($record['data']);
216)       if (! $record['data'] )
217)         system_failure('MX hostname missing');
218)       break;
219) 
220)     case 'ptr':
221)     case 'srv':
222)       system_failure('not implemented yet');
223)     default:
224)       system_failure('Not implemented');
225)   }
226)   $id = (int) $id;
227)   $record['hostname'] = maybe_null($record['hostname']);
228)   $record['ttl'] = ($recory['ttl'] == 0 ? 'NULL' : (int) $record['ttl']);
229)   $record['ip'] = maybe_null($record['ip']);
230)   $record['data'] = maybe_null($record['data']);
231)   $record['spec'] = maybe_null($record['spec']);
232)   $record['dyndns'] = maybe_null($record['dyndns']);
233)   if ($id)
234)     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");
235)   else
236)     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']})");
237) 
238) }
239) 
240) 
241) function delete_dns_record($id)
242) {
243)  // ...
244) }