28667e96bdcc072a7485ff50021f54f555c59ea3
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

1) <?php
2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

5) Written by schokokeks.org Hosting, namely
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

9) This code is published under a 0BSD license.
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

10) 
11) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
12) */
13) 
14) require_once('inc/debug.php');
15) require_once('inc/api.php');
16) use_module('contacts');
17) require_once('contacts.php');
18) require_once('contactapi.php');
19) 
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

20) 
21) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

22) function api_download_domain($id)
23) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

24)     $result = db_query("SELECT id, CONCAT_WS('.', domainname, tld) AS fqdn, owner, admin_c, registrierungsdatum, kuendigungsdatum FROM kundendaten.domains WHERE id=?", [$id]);
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

25)     if ($result->rowCount() < 1) {
26)         system_failure('Domain nicht gefunden');
27)     }
28)     $dom = $result->fetch();
Hanno remove whitespace in empty...

Hanno authored 6 years ago

29) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

30)     $data = ["domainName" => $dom['fqdn']];
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

31)     $result = api_request('domainInfo', $data);
32)     if ($result['status'] != 'success') {
33)         system_failure("Abfrage nicht erfolgreich!");
34)     }
35)     $apidomain = $result['response'];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

36)     $apiowner = null;
37)     $apiadmin_c = null;
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

38)     foreach ($apidomain['contacts'] as $ac) {
39)         if ($ac['type'] == 'owner') {
40)             $apiowner = $ac['contact'];
41)         }
42)         if ($ac['type'] == 'admin') {
43)             $apiadmin_c = $ac['contact'];
44)         }
45)     }
46) 
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

47)     if (!$apiowner || !$apiadmin_c) {
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

48)         system_failure("Ungültige Daten erhalten!");
49)     }
50)     $owner = download_contact($apiowner);
51)     $admin_c = $owner;
52)     if ($apiadmin_c != $apiowner) {
53)         $admin_c = download_contact($apiadmin_c);
54)     }
55)     if ($owner != $dom['owner'] || $admin_c != $dom['admin_c']) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

56)         db_query("UPDATE kundendaten.domains SET owner=?, admin_c=? WHERE id=?", [$owner, $admin_c, $id]);
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

57)     }
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

58)     return $apidomain;
Bernd Wurst Aktualisiere Domain- und In...

Bernd Wurst authored 6 years ago

59) }
60) 
61) 
Bernd Wurst Domain-Update (Ownerchange)...

Bernd Wurst authored 6 years ago

62) function api_upload_domain($fqdn)
63) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

64)     $result = db_query("SELECT id,CONCAT_WS('.', domainname, tld) AS fqdn, owner, admin_c FROM kundendaten.domains WHERE CONCAT_WS('.', domainname, tld)=?", [$fqdn]);
Bernd Wurst Domain-Update (Ownerchange)...

Bernd Wurst authored 6 years ago

65)     if ($result->rowCount() < 1) {
66)         system_failure("Unbekannte Domain");
67)     }
68)     $dom = $result->fetch();
69)     $owner = get_contact($dom['owner']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

70)     if (!$owner['nic_id']) {
Bernd Wurst Domain-Update (Ownerchange)...

Bernd Wurst authored 6 years ago

71)         upload_contact($owner);
72)         $owner = get_contact($dom['owner']);
73)     }
74)     $admin_c = get_contact($dom['admin_c']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

75)     if (!$admin_c['nic_id']) {
Bernd Wurst Domain-Update (Ownerchange)...

Bernd Wurst authored 6 years ago

76)         upload_contact($admin_c);
77)         $admin_c = get_contact($dom['admin_c']);
78)     }
79)     $owner = $owner['nic_id'];
80)     $admin_c = $admin_c['nic_id'];
81) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

82)     $data = ["domainName" => $dom['fqdn']];
Bernd Wurst Domain-Update (Ownerchange)...

Bernd Wurst authored 6 years ago

83)     $result = api_request('domainInfo', $data);
84)     if ($result['status'] != 'success') {
85)         system_failure("Abfrage nicht erfolgreich!");
86)     }
87)     $apidomain = $result['response'];
88)     foreach ($apidomain['contacts'] as $key => $ac) {
89)         if ($ac['type'] == 'owner') {
90)             $apidomain['contacts'][$key]['contact'] = $owner;
91)         }
92)         if ($ac['type'] == 'admin') {
93)             $apidomain['contacts'][$key]['contact'] = $admin_c;
94)         }
95)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

96)     $args = ["domain" => $apidomain];
Bernd Wurst Logging eingebaut

Bernd Wurst authored 6 years ago

97)     logger(LOG_INFO, "modules/domains/include/domainapi", "domains", "uploading domain »{$fqdn}«");
Bernd Wurst Zuverlässigeres Logging bei...

Bernd Wurst authored 6 years ago

98)     $result = api_request('domainUpdate', $args);
99)     if ($result['status'] == 'error') {
100)         $msg = $result['errors'][0]['text'];
101)         logger(LOG_ERR, "modules/domains/include/domainapi", "domains", "ERROR uploading domain »{$fqdn}«: {$msg}");
102)         system_failure("Es trat ein interner Fehler auf. Bitte dem Support Bescheid geben!");
103)     }
104)     return $result;
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

105) }
Bernd Wurst Domain-Update (Ownerchange)...

Bernd Wurst authored 6 years ago

106) 
107) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 1 year ago

108) function api_register_domain($domainname, $authinfo = null)
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

109) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

110)     $result = db_query("SELECT id,status,CONCAT_WS('.', domainname, tld) AS fqdn, owner, admin_c FROM kundendaten.domains WHERE CONCAT_WS('.', domainname, tld)=?", [$domainname]);
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

111)     if ($result->rowCount() < 1) {
112)         system_failure("Unbekannte Domain");
113)     }
114)     $dom = $result->fetch();
115)     $owner = get_contact($dom['owner']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

116)     if (!$owner['nic_id']) {
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

117)         upload_contact($owner);
118)         $owner = get_contact($dom['owner']);
119)     }
120)     $admin_c = get_contact($dom['admin_c']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

121)     if (!$admin_c['nic_id']) {
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

122)         upload_contact($admin_c);
123)         $admin_c = get_contact($dom['admin_c']);
124)     }
125)     $owner = $owner['nic_id'];
126)     $admin_c = $admin_c['nic_id'];
127) 
128)     // Frage die Masterdomain ab, von dort übernehmen wir Nameserver und zone/tech handles
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

129)     $data = ["domainName" => config('masterdomain')];
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

130)     $result = api_request('domainInfo', $data);
131)     if ($result['status'] != 'success') {
132)         system_failure("Abfrage nicht erfolgreich!");
133)     }
134)     $masterdomain = $result['response'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

135)     $newdomain = [];
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

136)     $newdomain['name'] = $domainname;
137)     $newdomain['transferLockEnabled'] = true;
138)     $newdomain['nameservers'] = $masterdomain['nameservers'];
139)     $newdomain['contacts'] = $masterdomain['contacts'];
140) 
141)     foreach ($masterdomain['contacts'] as $key => $ac) {
142)         if ($ac['type'] == 'owner') {
143)             $newdomain['contacts'][$key]['contact'] = $owner;
144)         }
145)         if ($ac['type'] == 'admin') {
146)             $newdomain['contacts'][$key]['contact'] = $admin_c;
147)         }
148)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

149)     $result = null;
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

150)     if ($dom['status'] == 'prereg') {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

151)         $args = ["domain" => $newdomain];
Bernd Wurst Logging eingebaut

Bernd Wurst authored 6 years ago

152)         logger(LOG_WARNING, "modules/domains/include/domainapi", "domains", "register new domain »{$newdomain['name']}«");
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

153)         $result = api_request('domainCreate', $args);
154)     } else {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

155)         $args = ["domain" => $newdomain, "transferData" => ["authInfo" => $authinfo]];
Bernd Wurst Logging eingebaut

Bernd Wurst authored 6 years ago

156)         logger(LOG_WARNING, "modules/domains/include/domainapi", "domains", "transfer-in domain »{$newdomain['name']}« with authinfo »{$authinfo}«");
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

157)         $result = api_request('domainTransfer', $args);
158)     }
Bernd Wurst Gebe eine generische Fehler...

Bernd Wurst authored 6 years ago

159)     if ($result['status'] == 'error') {
Bernd Wurst Logging eingebaut

Bernd Wurst authored 6 years ago

160)         $errstr = $result['errors'][0]['text'];
Bernd Wurst Zuverlässigeres Logging bei...

Bernd Wurst authored 6 years ago

161)         logger(LOG_ERR, "modules/domains/include/domainapi", "domains", "error registering domain $domainname: {$errstr}");
Bernd Wurst Gebe eine generische Fehler...

Bernd Wurst authored 6 years ago

162)         system_failure("Es trat ein interner Fehler auf. Bitte dem Support Bescheid geben!");
163)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

164)     return $result;
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

165) }
166) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

167) function api_domain_available($domainname)
Bernd Wurst Ermögliche das Hinzufügen e...

Bernd Wurst authored 6 years ago

168) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

169)     $args = ["domainNames" => [$domainname]];
Bernd Wurst Ermögliche das Hinzufügen e...

Bernd Wurst authored 6 years ago

170)     $result = api_request('domainStatus', $args);
171)     $resp = $result["responses"][0];
Bernd Wurst Domain-Transfer und -Regist...

Bernd Wurst authored 6 years ago

172)     return $resp;
Bernd Wurst Ermögliche das Hinzufügen e...

Bernd Wurst authored 6 years ago

173) }
174) 
175) 
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

176) function api_cancel_domain($domainname)
177) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

178)     $data = ["domainName" => $domainname];
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

179)     $result = api_request('domainInfo', $data);
180)     if ($result['status'] != 'success') {
181)         system_failure("Abfrage nicht erfolgreich!");
182)     }
183)     $apidomain = $result['response'];
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

184)     if (!$apidomain['latestDeletionDateWithoutRenew']) {
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

185)         system_failure("Konnte Vertragsende nicht herausfinden.");
186)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

187)     $args = ["domainName" => $domainname, "execDate" => $apidomain['latestDeletionDateWithoutRenew']];
Bernd Wurst fixed logfile string

Bernd Wurst authored 6 years ago

188)     logger(LOG_WARNING, "modules/domains/include/domainapi", "domains", "cancel domain »{$domainname}« at time {$apidomain['latestDeletionDateWithoutRenew']}");
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

189)     $result = api_request('domainDelete', $args);
190)     if ($result['status'] == 'error') {
Bernd Wurst Zuverlässigeres Logging bei...

Bernd Wurst authored 6 years ago

191)         $errstr = $result['errors'][0]['text'];
192)         logger(LOG_ERR, "modules/domains/include/domainapi", "domains", "error canceling domain $domainname: {$errstr}");
193)         system_failure("Es trat ein interner Fehler auf. Bitte dem Support Bescheid geben!");
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

194)     }
Bernd Wurst Zuverlässigeres Logging bei...

Bernd Wurst authored 6 years ago

195)     return $result;
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

196) }
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

197) 
198) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

199) function api_unlock_domain($domainname)
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

200) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

201)     $data = ["domainName" => $domainname];
Bernd Wurst Transfer-Freigabe und Kündi...

Bernd Wurst authored 6 years ago

202)     $result = api_request('domainInfo', $data);
203)     if ($result['status'] != 'success') {
204)         system_failure("Abfrage nicht erfolgreich!");
205)     }
206)     $apidomain = $result['response'];
207)     $apidomain['transferLockEnabled'] = false;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

208)     $args = ["domain" => $apidomain];
Bernd Wurst Logging eingebaut

Bernd Wurst authored 6 years ago

209)     logger(LOG_WARNING, "modules/domains/include/domainapi", "domains", "allow transfer for domain »{$domainname}«");
Bernd Wurst Zuverlässigeres Logging bei...

Bernd Wurst authored 6 years ago

210)     $result = api_request('domainUpdate', $args);
211)     if ($result['status'] == 'error') {
212)         $errstr = $result['errors'][0]['text'];
213)         logger(LOG_ERR, "modules/domains/include/domainapi", "domains", "error unlocking domain $domainname: {$errstr}");
214)         system_failure("Es trat ein interner Fehler auf. Bitte dem Support Bescheid geben!");
215)     }
216)     return $result;