d7e7556a1b10e07654def506344d9a808a096627
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);
bernd Benutze temporäre Tabelle f...

bernd authored 14 years ago

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

152)   $data = array();
153)   while ($entry = mysql_fetch_assoc($result)) {
154)     array_push($data, $entry);
155)   }
156)   DEBUG($data);
157)   return $data;
158) }
159) 
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

160) 
bernd add save function

bernd authored 15 years ago

161) $implemented_record_types = array('a', 'aaaa', 'mx', 'spf', 'txt', 'cname', 'ptr', 'srv');
162) 
163) function save_dns_record($id, $record)
164) {
165)   global $valid_record_types;
166)   global $implemented_record_types;
167)   $record['type'] = strtolower($record['type']);
168)   if (!in_array($record['type'], $valid_record_types))
169)     system_failure('invalid type: '.$record['type']);
170)   if (!in_array($record['type'], $implemented_record_types))
171)     system_failure('record type '.$record['type'].' not implemented at the moment.');
172)   $dom = new Domain( (int) $record['domain'] );
173)   if (! $dom->id)
174)     system_failure('invalid domain');
175)   verify_input_hostname($record['hostname']);
176)   if ($record['ttl'] &&  (int) $record['ttl'] < 1)
177)     system_failure('Fehler bei TTL');
178)   switch ($record['type']) 
179)   {
180)     case 'a':
181)       if ($record['dyndns'])
182)       {
183)         get_dyndns_account( $record['dyndns'] );
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

185)       }
186)       else
187)       {
188)         verify_input_ipv4($record['ip']);
189)         $record['data'] = '';
190)         $record['spec'] = '';
191)       }
192)       break;
193)     case 'aaaa':
194)       $record['dyndns'] = '';
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

210)     case 'ptr':
bernd add save function

bernd authored 15 years ago

211)       $record['dyndns'] = '';
212)       $record['spec'] = '';
213)       $record['ip'] = '';
214)       verify_input_hostname($record['data']);
215)       if (! $record['data'] )
216)         system_failure('MX hostname missing');
217)       break;
218) 
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

219)     case 'spf':
220)     case 'txt':
bernd add save function

bernd authored 15 years ago

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']);
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

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)
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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");
bernd add save function

bernd authored 15 years ago

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

bernd authored 15 years ago

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']})");
bernd add save function

bernd authored 15 years ago

237) 
238) }
239) 
240) 
241) function delete_dns_record($id)
242) {
bernd DNs-record-Interface ist je...

bernd authored 15 years ago

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

bernd authored 15 years ago

247) }