2626dd47daad110c63a82c0560b134e2364eeac3
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) 
40)     $hostname = filter_input_hostname($_POST['hostname'], true);
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) 
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

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

Hanno authored 5 years ago

73)     if ($_POST['vhost_type'] == 'regular' || $_POST['vhost_type'] == 'dav') {
74)         $defaultdocroot = $vhost['homedir'].'/websites/'.((strlen($hostname) > 0) ? $hostname.'.' : '').($domainname).'/htdocs';
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

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

Hanno authored 5 years ago

76)         $docroot = '';
77)         if (isset($_POST['docroot'])) {
78)             if (! check_path($_POST['docroot'])) {
79)                 system_failure("Eingegebener Pfad enthält ungültige Angaben");
80)             }
81)             $docroot = $vhost['homedir'].'/websites/'.$_POST['docroot'];
82)         }
83)         if ((isset($_POST['use_default_docroot']) && $_POST['use_default_docroot'] == '1') || ($docroot == $defaultdocroot)) {
84)             $docroot = null;
85)         }
86)   
87)         DEBUG("Document-Root: ".$docroot);
88)     }
89)     $php = null;
90)     if ($_POST['vhost_type'] == 'regular' && isset($_POST['php'])) {
91)         switch ($_POST['php']) {
Bernd Wurst PHP 5.6 experimentell

Bernd Wurst authored 9 years ago

92)       case 'php56':
93)         $php = 'php56';
94)         break;
Bernd Wurst PHP <= 5.5 entfernt und Vor...

Bernd Wurst authored 7 years ago

95)       case 'fpm70':
Bernd Wurst zwinge PHP 7.0 auf FPM (har...

Bernd Wurst authored 8 years ago

96)         $php = 'fpm70';
Hanno Böck PHP 7.0 support

Hanno Böck authored 8 years ago

97)         break;
Bernd Wurst PHP <= 5.5 entfernt und Vor...

Bernd Wurst authored 7 years ago

98)       case 'fpm71':
99)         $php = 'fpm71';
100)         break;
Hanno Böck add PHP 7.2 support, re-cre...

Hanno Böck authored 6 years ago

101)       case 'fpm72':
102)         $php = 'fpm72';
103)         break;
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

104)       /* Wenn etwas anderes kommt, ist das "kein PHP". So einfach ist das. */
105)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

112)     if (isset($_POST['suexec_user'])) {
113)         $vhost['suexec_user'] = $_POST['suexec_user'];
114)     }
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

138) 
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

182)     }
bernd IPv6

bernd authored 14 years ago

183)   
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

196)     $errorlog = 0;
197)     if (isset($_POST['errorlog']) and ($_POST['errorlog'] == 1)) {
198)         $errorlog = 1;
199)     }
bernd error_log konfigurierbar

bernd authored 16 years ago

200) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

210)     if ($logtype == '') {
211)         $vhost['stats'] = null;
212)     }
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

223)     if ($aliaswww) {
224)         array_push($new_options, 'aliaswww');
225)         if ($forwardwww) {
226)             array_push($new_options, $forwardwww);
227)         }
Bernd Wurst Funktionsfähiger Prototyp

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 8 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

259)     DEBUG($old_options);
260)     DEBUG($new_options);
261)     $options = implode(',', $new_options);
262)     DEBUG('New options: '.$options);
263) 
264)     $vhost['hostname'] = $hostname;
265)     $vhost['domain_id'] = $domain_id;
266)     $vhost['docroot'] = $docroot;
267)     $vhost['php'] = $php;
268)     $vhost['cgi'] = $cgi;
269)     $vhost['ssl'] = $ssl;
270)     $vhost['hsts'] = $hsts;
271)     $vhost['cert'] = $cert;
272)     $vhost['ipv4'] = $ipv4;
273)     $vhost['logtype'] = $logtype;
274)     $vhost['errorlog'] = $errorlog;
275)     $vhost['options'] = $options;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

277)     DEBUG($vhost);
278)     save_vhost($vhost);
279)     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

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

290)     $alias = empty_alias();
291)     $alias['vhost'] = $vhost['id'];
bernd Aliases editieren

bernd authored 16 years ago

292) 
293)   
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

294)     $hostname = filter_input_hostname($_POST['hostname'], true);
295)     $domainid = (int) $_POST['domain'];
296)     if ($domainid >= 0) {
297)         $domain = new Domain((int) $_POST['domain']);
298)         $domain->ensure_userdomain();
299)         $domainid = $domain->id;
300)     }
301)     if ($domainid == -1) {
302)         # use configured user_vhosts_domain
303)         $userdomain = userdomain();
304)         $domain = new Domain((int) $userdomain['id']);
305)         $domainid = $domain->id;
306)         $hostname = $hostname.'.'.$_SESSION['userinfo']['username'];
307)         $hostname = trim($hostname, " .-");
308)     }
309) 
310)     if (! is_array($_POST['options'])) {
311)         $_POST['options'] = array();
312)     }
313)     $aliaswww = in_array('aliaswww', $_POST['options']);
314)     $forward = in_array('forward', $_POST['options']);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

316)     $new_options = array();
317)     if ($aliaswww) {
318)         array_push($new_options, 'aliaswww');
319)     }
320)     if ($forward) {
321)         array_push($new_options, 'forward');
322)     }
323)     DEBUG($new_options);
324)     $options = implode(',', $new_options);
325)     DEBUG('New options: '.$options);
326) 
327)     $alias['hostname'] = $hostname;
328)     $alias['domain_id'] = $domainid;
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

330)     $alias ['options'] = $options;
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

332)     save_alias($alias);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

334)     if (! $debugmode) {
335)         header('Location: aliases?vhost='.$vhost['id']);
336)     }
337) } elseif ($_GET['action'] == 'deletealias') {
338)     $title = "Subdomain löschen";
339)     $section = 'vhosts_vhosts';
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

341)     $alias = get_alias_details((int) $_GET['alias']);
342)     DEBUG($alias);
343)     $alias_string = $alias['fqdn'];
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

345)     $vhost = get_vhost_details($alias['vhost']);
346)     DEBUG($vhost);
347)     $vhost_string = $vhost['fqdn'];
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

349)     $sure = user_is_sure();
350)     if ($sure === null) {
351)         are_you_sure("action=deletealias&alias={$_GET['alias']}", "Möchten Sie das Alias »{$alias_string}« für die Subdomain »{$vhost_string}« wirklich löschen?");
352)     } elseif ($sure === true) {
353)         delete_alias($alias['id']);
354)         if (! $debugmode) {
355)             header('Location: aliases?vhost='.$vhost['id']);
356)         }
357)     } elseif ($sure === false) {
358)         if (! $debugmode) {
359)             header('Location: aliases?vhost='.$vhost['id']);
360)         }
361)     }
362) } elseif ($_GET['action'] == 'delete') {
363)     $title = "Subdomain löschen";
364)     $section = 'vhosts_vhosts';
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

366)     $vhost = get_vhost_details((int) $_GET['vhost']);
367)     $vhost_string = $vhost['fqdn'];
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

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