f7ff31f2e8f4fb0c7559f54c29510e5a407572aa
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);
125)   DEBUG($data);
126)   return $data;
127) }
bernd Stub für dns-Admin-Interface

bernd authored 15 years ago

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

bernd authored 15 years ago

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

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

bernd authored 15 years ago

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