d0416d23b70a701e7c12b884bd947d4c670cc50e
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) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) 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.
15) */
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

16) 
17) require_once('session/start.php');
18) 
19) require_once('vhosts.php');
20) 
Bernd Wurst Weise Benutzer auf Wartezei...

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 7 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 5 years ago

72)     $fqdn = ($hostname!==""?$hostname.".":"").$domainname;
73)     verify_input_hostname_utf8($fqdn);
74)     if ($aliaswww) {
75)         verify_input_hostname_utf8("www.".$fqdn);
76)     }
77) 
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

97)         $phpinfo = valid_php_versions();
98)         if (array_key_exists($_POST['php'], $phpinfo)) {
99)             $php = $_POST['php'];
100)         } else {
101)             $php = null;
102)         }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

109)     if (isset($_POST['suexec_user'])) {
110)         $vhost['suexec_user'] = $_POST['suexec_user'];
111)     }
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

135) 
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

166)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

179)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

180) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

193)     $errorlog = 0;
194)     if (isset($_POST['errorlog']) and ($_POST['errorlog'] == 1)) {
195)         $errorlog = 1;
196)     }
bernd error_log konfigurierbar

bernd authored 16 years ago

197) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

199)     if (isset($_POST['stats']) && $_POST['stats'] == 1) {
200)         if ($vhost['stats'] == null) {
201)             $vhost['stats'] = 'private';
202)         }
203)     } else {
204)         $vhost['stats'] = null;
205)     }
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

207)     if ($logtype == '') {
208)         $vhost['stats'] = null;
209)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

211)     DEBUG("PHP: {$php} / Logging: {$logtype}");
212) 
213)     $old_options = explode(',', $vhost['options']);
214)     $new_options = array();
215)     foreach ($old_options as $op) {
216)         if (! in_array($op, array('aliaswww', 'forwardwww', 'forwardnowww', 'hsts_subdomains', 'hsts_preload'))) {
217)             array_push($new_options, $op);
218)         }
Bernd Wurst * Ermögliche SAN bei CSRs *...

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

220)     if ($aliaswww) {
221)         array_push($new_options, 'aliaswww');
222)         if ($forwardwww) {
223)             array_push($new_options, $forwardwww);
224)         }
Bernd Wurst Funktionsfähiger Prototyp

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

226)     if ($hsts_subdomains) {
227)         array_push($new_options, 'hsts_subdomains');
228)     }
229)     if ($hsts_preload) {
230)         array_push($new_options, 'hsts_preload');
231)     }
232)     $letsencrypt = ($cert == 0 ? false : ($cert == -1 || cert_is_letsencrypt($cert)));
233) 
234)     if ($letsencrypt) {
235)         array_push($new_options, 'letsencrypt');
236)         if ($vhost['cert'] != 0) {
237)             # Wenn der User manuell von einem gültigen Cert auf "letsencrypt" umgestellt hat,
238)             # dann sollte das alte Cert noch so lange eingetragen bleiben bis das neue da ist.
239)             $cert = $vhost['cert'];
240)         } elseif ($cert > 0) {
241)             # Das Cert was der user gewählt hat, ist von Lets encrypt
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

243)         } else {
244)             # Wenn vorher kein Zertifikat aktiv war, dann setze jetzt auch keines.
245)             # Der letsencrypt-Automatismus macht das dann schon.
246)             $cert = 0;
247)         }
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

249)         # Wenn kein Letsencrypt gewünscht ist, entferne die Letsencrypt-Option
250)         $key = array_search('letsencrypt', $new_options);
251)         if ($key !== false) {
252)             unset($new_options[$key]);
253)         }
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

256)     DEBUG($old_options);
257)     DEBUG($new_options);
258)     $options = implode(',', $new_options);
259)     DEBUG('New options: '.$options);
260) 
261)     $vhost['hostname'] = $hostname;
262)     $vhost['domain_id'] = $domain_id;
263)     $vhost['docroot'] = $docroot;
264)     $vhost['php'] = $php;
265)     $vhost['cgi'] = $cgi;
266)     $vhost['ssl'] = $ssl;
267)     $vhost['hsts'] = $hsts;
268)     $vhost['cert'] = $cert;
269)     $vhost['ipv4'] = $ipv4;
270)     $vhost['logtype'] = $logtype;
271)     $vhost['errorlog'] = $errorlog;
272)     $vhost['options'] = $options;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

274)     DEBUG($vhost);
275)     save_vhost($vhost);
276)     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

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

Hanno authored 5 years ago

278)     if (! $debugmode) {
279)         header('Location: vhosts');
280)     }
281) } elseif ($_GET['action'] == 'addalias') {
282)     check_form_token('vhosts_add_alias');
283)     $id = (int) $_GET['vhost'];
284)     $vhost = get_vhost_details($id);
285)     DEBUG($vhost);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

287)     $alias = empty_alias();
288)     $alias['vhost'] = $vhost['id'];
bernd Aliases editieren

bernd authored 16 years ago

289) 
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno Böck authored 5 years ago

291)     $hostname = strtolower(trim($_POST['hostname']));
292) 
293)     $domain_id = (int) $_POST['domain'];
294)     if ($domain_id >= 0) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 5 years ago

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

Hanno authored 5 years ago

305)         $hostname = $hostname.'.'.$_SESSION['userinfo']['username'];
306)         $hostname = trim($hostname, " .-");
307)     }
308) 
309)     if (! is_array($_POST['options'])) {
310)         $_POST['options'] = array();
311)     }
312)     $aliaswww = in_array('aliaswww', $_POST['options']);
313)     $forward = in_array('forward', $_POST['options']);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno Böck authored 5 years ago

315)     $fqdn = ($hostname!==""?$hostname.".":"").$domainname;
316)     verify_input_hostname_utf8($fqdn);
317)     if ($aliaswww) {
318)         verify_input_hostname_utf8("www.".$fqdn);
319)     }
320) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

321)     $new_options = array();
322)     if ($aliaswww) {
323)         array_push($new_options, 'aliaswww');
324)     }
325)     if ($forward) {
326)         array_push($new_options, 'forward');
327)     }
328)     DEBUG($new_options);
329)     $options = implode(',', $new_options);
330)     DEBUG('New options: '.$options);
331) 
332)     $alias['hostname'] = $hostname;
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

337)     save_alias($alias);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

339)     if (! $debugmode) {
340)         header('Location: aliases?vhost='.$vhost['id']);
341)     }
342) } elseif ($_GET['action'] == 'deletealias') {
343)     $title = "Subdomain löschen";
344)     $section = 'vhosts_vhosts';
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

346)     $alias = get_alias_details((int) $_GET['alias']);
347)     DEBUG($alias);
348)     $alias_string = $alias['fqdn'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

350)     $vhost = get_vhost_details($alias['vhost']);
351)     DEBUG($vhost);
352)     $vhost_string = $vhost['fqdn'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

354)     $sure = user_is_sure();
355)     if ($sure === null) {
356)         are_you_sure("action=deletealias&alias={$_GET['alias']}", "Möchten Sie das Alias »{$alias_string}« für die Subdomain »{$vhost_string}« wirklich löschen?");
357)     } elseif ($sure === true) {
358)         delete_alias($alias['id']);
359)         if (! $debugmode) {
360)             header('Location: aliases?vhost='.$vhost['id']);
361)         }
362)     } elseif ($sure === false) {
363)         if (! $debugmode) {
364)             header('Location: aliases?vhost='.$vhost['id']);
365)         }
366)     }
367) } elseif ($_GET['action'] == 'delete') {
368)     $title = "Subdomain löschen";
369)     $section = 'vhosts_vhosts';
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

374)     $sure = user_is_sure();
375)     if ($sure === null) {
376)         are_you_sure("action=delete&vhost={$_GET['vhost']}", "Möchten Sie die Subdomain »{$vhost_string}« wirklich löschen?");
377)     } elseif ($sure === true) {
378)         delete_vhost($vhost['id']);
379)         if (! $debugmode) {
380)             header("Location: vhosts");
381)         }
382)     } elseif ($sure === false) {
383)         if (! $debugmode) {
384)             header("Location: vhosts");
385)         }
386)     }
387) } else {
388)     system_failure("Unimplemented action");