dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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 1 year ago

5) Written by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 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 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 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) */
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

13) 
14) require_once('session/start.php');
15) 
16) require_once('vhosts.php');
17) 
Bernd Wurst Weise Benutzer auf Wartezei...

Bernd Wurst authored 11 years ago

18) require_once('inc/error.php');
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

19) require_once('inc/security.php');
20) require_once('class/domain.php');
21) 
22) require_role(ROLE_SYSTEMUSER);
23) 
24) require_once("inc/debug.php");
25) global $debugmode;
26) 
27) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

28) if ($_GET['action'] == 'edit') {
29)     check_form_token('vhosts_edit_vhost');
30)     $id = (int) $_GET['vhost'];
31)     $vhost = empty_vhost();
32)     if ($id != 0) {
33)         $vhost = get_vhost_details($id);
34)     }
35)     DEBUG($vhost);
36) 
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

37)     $hostname = strtolower(trim($_POST['hostname']));
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

38) 
39)     $domainname = null;
40)     $domain_id = (int) $_POST['domain'];
41)     if ($domain_id >= 0) {
42)         $domain = new Domain((int) $_POST['domain']);
43)         $domain->ensure_userdomain();
44)         $domain_id = $domain->id;
45)         $domainname = $domain->fqdn;
46)     } elseif ($domain_id == -1) {
47)         # use configured user_vhosts_domain
48)         $userdomain = userdomain();
49)         $domain = new Domain((int) $userdomain['id']);
50)         $domain_id = $domain->id;
51)         $domainname = $domain->fqdn;
52)         $hostname = $hostname.'.'.$_SESSION['userinfo']['username'];
53)         $hostname = trim($hostname, " .-");
54)     } elseif ($domain_id == -2) {
55)         # use system masterdomain
56)         $domainname = $_SESSION['userinfo']['username'].".".config('masterdomain');
57)     }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

58) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

59)     $aliaswww = (isset($_POST['aliaswww']) && $_POST['aliaswww'] == 'aliaswww');
60)     $forwardwww = null;
61)     if ($aliaswww && isset($_POST['forwardwww'])) {
62)         if ($_POST['forwardwww'] == 'forwardwww') {
63)             $forwardwww = 'forwardwww';
64)         } elseif ($_POST['forwardwww'] == 'forwardnowww') {
65)             $forwardwww = 'forwardnowww';
66)         }
Bernd Wurst Funktionsfähiger Prototyp

Bernd Wurst authored 7 years ago

67)     }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno Böck authored 2 years ago

69)     $fqdn = ($hostname!=="" ? $hostname."." : "").$domainname;
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

70)     verify_input_hostname_utf8($fqdn);
71)     if ($aliaswww) {
72)         verify_input_hostname_utf8("www.".$fqdn);
73)     }
74) 
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

75)     $docroot = '';
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

76)     if ($_POST['vhost_type'] == 'regular' || $_POST['vhost_type'] == 'dav') {
77)         $defaultdocroot = $vhost['homedir'].'/websites/'.((strlen($hostname) > 0) ? $hostname.'.' : '').($domainname).'/htdocs';
Hanno remove whitespace in empty...

Hanno authored 5 years ago

78) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

79)         $docroot = '';
80)         if (isset($_POST['docroot'])) {
81)             if (! check_path($_POST['docroot'])) {
82)                 system_failure("Eingegebener Pfad enthält ungültige Angaben");
83)             }
84)             $docroot = $vhost['homedir'].'/websites/'.$_POST['docroot'];
85)         }
86)         if ((isset($_POST['use_default_docroot']) && $_POST['use_default_docroot'] == '1') || ($docroot == $defaultdocroot)) {
87)             $docroot = null;
88)         }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

89) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

90)         DEBUG("Document-Root: ".$docroot);
91)     }
92)     $php = null;
93)     if ($_POST['vhost_type'] == 'regular' && isset($_POST['php'])) {
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

94)         $phpinfo = valid_php_versions();
Bernd Wurst added php version tag "defa...

Bernd Wurst authored 3 years ago

95)         if ($_POST['php'] == 'default' || array_key_exists($_POST['php'], $phpinfo)) {
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

96)             $php = $_POST['php'];
97)         } else {
98)             $php = null;
99)         }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

100)     }
101)     $cgi = 1;
102)     if (isset($_POST['safemode']) && $_POST['safemode'] == 'yes') {
103)         $cgi = 0;
104)     }
bernd CGI abschaltbar

bernd authored 14 years ago

105) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

106)     if (isset($_POST['suexec_user'])) {
107)         $vhost['suexec_user'] = $_POST['suexec_user'];
108)     }
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

109) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

110)     if (isset($_POST['server'])) {
111)         $vhost['server'] = $_POST['server'];
112)     }
Bernd Wurst Ermögliche das Auswählen de...

Bernd Wurst authored 11 years ago

113) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

114)     if ($_POST['vhost_type'] == 'regular') {
115)         $vhost['is_dav'] = 0;
116)         $vhost['is_svn'] = 0;
117)         $vhost['is_webapp'] = 0;
118)     } elseif ($_POST['vhost_type'] == 'dav') {
119)         $vhost['is_dav'] = 1;
120)         $vhost['is_svn'] = 0;
121)         $vhost['is_webapp'] = 0;
122)     } elseif ($_POST['vhost_type'] == 'svn') {
123)         $vhost['is_dav'] = 0;
124)         $vhost['is_svn'] = 1;
125)         $vhost['is_webapp'] = 0;
126)     } elseif ($_POST['vhost_type'] == 'webapp') {
127)         $vhost['is_dav'] = 0;
128)         $vhost['is_svn'] = 0;
129)         $vhost['is_webapp'] = 1;
130)         $vhost['webapp_id'] = (int) $_POST['webapp'];
131)     }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

132) 
Hanno remove whitespace in empty...

Hanno authored 5 years ago

133) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

134)     $ssl = null;
135)     switch ($_POST['ssl']) {
bernd SSL auch über webinterface...

bernd authored 16 years ago

136)     case 'http':
137)       $ssl = 'http';
138)       break;
139)     case 'https':
140)       $ssl = 'https';
141)       break;
142)     case 'forward':
143)       $ssl = 'forward';
144)       break;
145)     /* Wenn etwas anderes kommt, ist das "beides". So einfach ist das. */
146)   }
147) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

148)     $hsts = null;
149)     $hsts_subdomains = false;
150)     $hsts_preload = false;
151)     if (isset($_POST['hsts'])) {
152)         if (is_numeric($_POST['hsts']) && (int) $_POST['hsts'] > -2) {
153)             $hsts = (int) $_POST['hsts'];
154)         } else {
155)             system_failure('Es wurde ein ungültiger HSTS-Wert eingegeben. Dort sind nur Sekunden erlaubt.');
156)         }
157)         if (isset($_POST['hsts_subdomains']) and $_POST['hsts_subdomains'] == 1) {
158)             $hsts_subdomains = true;
159)             if (isset($_POST['hsts_preload']) and $_POST['hsts_preload'] == 1) {
160)                 $hsts_preload = true;
161)             }
162)         }
Bernd Wurst JQuery als Include HSTS-Int...

Bernd Wurst authored 10 years ago

163)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

164) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

165)     $cert = (isset($_POST['cert']) ? (int) $_POST['cert'] : null);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno Böck authored 2 years ago

167)     $ipv4 = ($_POST['ipv4'] ?? null);
bernd IP-Adressen aktivieren

bernd authored 14 years ago

168) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

169)     if (isset($_POST['ipv6']) && $_POST['ipv6'] == 'yes') {
170)         $vhost['autoipv6'] = 1;
171)         if (isset($_POST['ipv6_separate']) && $_POST['ipv6_separate'] = 'yes') {
172)             $vhost['autoipv6'] = 2;
173)         }
174)     } else {
175)         $vhost['autoipv6'] = 0;
bernd Zusätzlicher Haken für eige...

bernd authored 13 years ago

176)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

177) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

178) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

179)     $logtype = '';
180)     switch ($_POST['logtype']) {
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

181)     case 'anonymous':
182)       $logtype = 'anonymous';
183)       break;
184)     case 'default':
185)       $logtype = 'default';
186)       break;
187)     /* Wenn etwas anderes kommt, ist das "kein Logging". So einfach ist das. */
188)   }
189) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

190)     $errorlog = 0;
191)     if (isset($_POST['errorlog']) and ($_POST['errorlog'] == 1)) {
192)         $errorlog = 1;
193)     }
bernd error_log konfigurierbar

bernd authored 16 years ago

194) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

195) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

196)     DEBUG("PHP: {$php} / Logging: {$logtype}");
197) 
198)     $old_options = explode(',', $vhost['options']);
Bernd Wurst Behandle Sonderfall des lee...

Bernd Wurst authored 5 years ago

199)     if ($vhost['options'] == '') {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

200)         $old_options = [];
Bernd Wurst Behandle Sonderfall des lee...

Bernd Wurst authored 5 years ago

201)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

202)     $new_options = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

203)     foreach ($old_options as $op) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

204)         if (! in_array($op, ['aliaswww', 'forwardwww', 'forwardnowww', 'hsts_subdomains', 'hsts_preload'])) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

205)             array_push($new_options, $op);
206)         }
Bernd Wurst * Ermögliche SAN bei CSRs *...

Bernd Wurst authored 8 years ago

207)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

208)     if ($aliaswww) {
209)         array_push($new_options, 'aliaswww');
210)         if ($forwardwww) {
211)             array_push($new_options, $forwardwww);
212)         }
Bernd Wurst Funktionsfähiger Prototyp

Bernd Wurst authored 7 years ago

213)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

214)     if ($hsts_subdomains) {
215)         array_push($new_options, 'hsts_subdomains');
216)     }
217)     if ($hsts_preload) {
218)         array_push($new_options, 'hsts_preload');
219)     }
220)     $letsencrypt = ($cert == 0 ? false : ($cert == -1 || cert_is_letsencrypt($cert)));
221) 
222)     if ($letsencrypt) {
223)         array_push($new_options, 'letsencrypt');
224)         if ($vhost['cert'] != 0) {
225)             # Wenn der User manuell von einem gültigen Cert auf "letsencrypt" umgestellt hat,
226)             # dann sollte das alte Cert noch so lange eingetragen bleiben bis das neue da ist.
227)             $cert = $vhost['cert'];
228)         } elseif ($cert > 0) {
229)             # Das Cert was der user gewählt hat, ist von Lets encrypt
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

230)       # tu nix, $cert ist schon korrekt
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

231)         } else {
232)             # Wenn vorher kein Zertifikat aktiv war, dann setze jetzt auch keines.
233)             # Der letsencrypt-Automatismus macht das dann schon.
234)             $cert = 0;
235)         }
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

236)     } else {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

237)         # Wenn kein Letsencrypt gewünscht ist, entferne die Letsencrypt-Option
238)         $key = array_search('letsencrypt', $new_options);
239)         if ($key !== false) {
240)             unset($new_options[$key]);
241)         }
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

242)     }
Hanno codingstyle fixes

Hanno authored 5 years ago

243) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

244) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

245)     DEBUG($old_options);
246)     DEBUG($new_options);
247)     $options = implode(',', $new_options);
248)     DEBUG('New options: '.$options);
249) 
250)     $vhost['hostname'] = $hostname;
251)     $vhost['domain_id'] = $domain_id;
252)     $vhost['docroot'] = $docroot;
253)     $vhost['php'] = $php;
254)     $vhost['cgi'] = $cgi;
255)     $vhost['ssl'] = $ssl;
256)     $vhost['hsts'] = $hsts;
257)     $vhost['cert'] = $cert;
258)     $vhost['ipv4'] = $ipv4;
259)     $vhost['logtype'] = $logtype;
260)     $vhost['errorlog'] = $errorlog;
261)     $vhost['options'] = $options;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

262) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

263)     DEBUG($vhost);
264)     save_vhost($vhost);
265)     success_msg("Ihre Einstellungen wurden gespeichert. Es dauert jedoch einige Minuten bis die Änderungen wirksam werden.");
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

266) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

267)     if (! $debugmode) {
268)         header('Location: vhosts');
269)     }
270) } elseif ($_GET['action'] == 'addalias') {
271)     check_form_token('vhosts_add_alias');
272)     $id = (int) $_GET['vhost'];
273)     $vhost = get_vhost_details($id);
274)     DEBUG($vhost);
bernd Aliases editieren

bernd authored 16 years ago

275) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

276)     $alias = empty_alias();
277)     $alias['vhost'] = $vhost['id'];
bernd Aliases editieren

bernd authored 16 years ago

278) 
Hanno remove whitespace in empty...

Hanno authored 5 years ago

279) 
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

280)     $hostname = strtolower(trim($_POST['hostname']));
281) 
282)     $domain_id = (int) $_POST['domain'];
283)     if ($domain_id >= 0) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

284)         $domain = new Domain((int) $_POST['domain']);
285)         $domain->ensure_userdomain();
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

286)         $domain_id = $domain->id;
287)         $domainname = $domain->fqdn;
288)     } elseif ($domain_id == -1) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

289)         # use configured user_vhosts_domain
290)         $userdomain = userdomain();
291)         $domain = new Domain((int) $userdomain['id']);
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

292)         $domain_id = $domain->id;
293)         $domainname = $domain->fqdn;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

294)         $hostname = $hostname.'.'.$_SESSION['userinfo']['username'];
295)         $hostname = trim($hostname, " .-");
Hanno fix usersubdomain / -2

Hanno authored 5 years ago

296)     } elseif ($domain_id == -2) {
297)         # use system masterdomain
298)         $domainname = $_SESSION['userinfo']['username'].".".config('masterdomain');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

299)     }
300) 
301)     if (! is_array($_POST['options'])) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

302)         $_POST['options'] = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

303)     }
304)     $aliaswww = in_array('aliaswww', $_POST['options']);
305)     $forward = in_array('forward', $_POST['options']);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno Böck authored 2 years ago

307)     $fqdn = ($hostname!=="" ? $hostname."." : "").$domainname;
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

308)     verify_input_hostname_utf8($fqdn);
309)     if ($aliaswww) {
310)         verify_input_hostname_utf8("www.".$fqdn);
311)     }
312) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

313)     $new_options = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

314)     if ($aliaswww) {
315)         array_push($new_options, 'aliaswww');
316)     }
317)     if ($forward) {
318)         array_push($new_options, 'forward');
319)     }
320)     DEBUG($new_options);
321)     $options = implode(',', $new_options);
322)     DEBUG('New options: '.$options);
323) 
324)     $alias['hostname'] = $hostname;
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

325)     $alias['domain_id'] = $domain_id;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

326) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

327)     $alias ['options'] = $options;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

328) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

329)     save_alias($alias);
bernd Aliases editieren

bernd authored 16 years ago

330) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

331)     if (! $debugmode) {
332)         header('Location: aliases?vhost='.$vhost['id']);
333)     }
334) } elseif ($_GET['action'] == 'deletealias') {
Bernd Wurst Beschriftung im VHosts-Modu...

Bernd Wurst authored 5 years ago

335)     $title = "Website-Alias löschen";
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

336)     $section = 'vhosts_vhosts';
Hanno remove whitespace in empty...

Hanno authored 5 years ago

337) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

338)     $alias = get_alias_details((int) $_GET['alias']);
339)     DEBUG($alias);
340)     $alias_string = $alias['fqdn'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

341) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

342)     $vhost = get_vhost_details($alias['vhost']);
343)     DEBUG($vhost);
344)     $vhost_string = $vhost['fqdn'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

345) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

346)     $sure = user_is_sure();
347)     if ($sure === null) {
Bernd Wurst Beschriftung im VHosts-Modu...

Bernd Wurst authored 5 years ago

348)         are_you_sure("action=deletealias&alias={$_GET['alias']}", "Möchten Sie das Alias »{$alias_string}« für die Website »{$vhost_string}« wirklich löschen?");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

349)     } elseif ($sure === true) {
350)         delete_alias($alias['id']);
351)         if (! $debugmode) {
352)             header('Location: aliases?vhost='.$vhost['id']);
353)         }
354)     } elseif ($sure === false) {
355)         if (! $debugmode) {
356)             header('Location: aliases?vhost='.$vhost['id']);
357)         }
358)     }
359) } elseif ($_GET['action'] == 'delete') {
Bernd Wurst Beschriftung im VHosts-Modu...

Bernd Wurst authored 5 years ago

360)     $title = "Website löschen";
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

361)     $section = 'vhosts_vhosts';
Hanno remove whitespace in empty...

Hanno authored 5 years ago

362) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

363)     $vhost = get_vhost_details((int) $_GET['vhost']);
364)     $vhost_string = $vhost['fqdn'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

365) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

366)     $sure = user_is_sure();
367)     if ($sure === null) {
Bernd Wurst Beschriftung im VHosts-Modu...

Bernd Wurst authored 5 years ago

368)         are_you_sure("action=delete&vhost={$_GET['vhost']}", "Möchten Sie die Website »{$vhost_string}« wirklich löschen?");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

369)     } elseif ($sure === true) {
370)         delete_vhost($vhost['id']);
371)         if (! $debugmode) {
372)             header("Location: vhosts");
373)         }
374)     } elseif ($sure === false) {
375)         if (! $debugmode) {
376)             header("Location: vhosts");
377)         }
378)     }
379) } else {
380)     system_failure("Unimplemented action");