4b53992acd279ca46c5a12e40930639c942fb198
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';
Hanno remove whitespace in empty...

Hanno authored 5 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)         }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

91)         $phpinfo = valid_php_versions();
92)         if (array_key_exists($_POST['php'], $phpinfo)) {
93)             $php = $_POST['php'];
94)         } else {
95)             $php = null;
96)         }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

103)     if (isset($_POST['suexec_user'])) {
104)         $vhost['suexec_user'] = $_POST['suexec_user'];
105)     }
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

129) 
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

160)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

173)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

174) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

187)     $errorlog = 0;
188)     if (isset($_POST['errorlog']) and ($_POST['errorlog'] == 1)) {
189)         $errorlog = 1;
190)     }
bernd error_log konfigurierbar

bernd authored 16 years ago

191) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

193)     if (isset($_POST['stats']) && $_POST['stats'] == 1) {
194)         if ($vhost['stats'] == null) {
195)             $vhost['stats'] = 'private';
196)         }
197)     } else {
198)         $vhost['stats'] = null;
199)     }
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

Hanno authored 5 years ago

201)     if ($logtype == '') {
202)         $vhost['stats'] = null;
203)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

214)     if ($aliaswww) {
215)         array_push($new_options, 'aliaswww');
216)         if ($forwardwww) {
217)             array_push($new_options, $forwardwww);
218)         }
Bernd Wurst Funktionsfähiger Prototyp

Bernd Wurst authored 7 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

237)         } else {
238)             # Wenn vorher kein Zertifikat aktiv war, dann setze jetzt auch keines.
239)             # Der letsencrypt-Automatismus macht das dann schon.
240)             $cert = 0;
241)         }
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

243)         # Wenn kein Letsencrypt gewünscht ist, entferne die Letsencrypt-Option
244)         $key = array_search('letsencrypt', $new_options);
245)         if ($key !== false) {
246)             unset($new_options[$key]);
247)         }
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

268)     DEBUG($vhost);
269)     save_vhost($vhost);
270)     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

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

Hanno authored 5 years ago

272)     if (! $debugmode) {
273)         header('Location: vhosts');
274)     }
275) } elseif ($_GET['action'] == 'addalias') {
276)     check_form_token('vhosts_add_alias');
277)     $id = (int) $_GET['vhost'];
278)     $vhost = get_vhost_details($id);
279)     DEBUG($vhost);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

281)     $alias = empty_alias();
282)     $alias['vhost'] = $vhost['id'];
bernd Aliases editieren

bernd authored 16 years ago

283) 
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

285)     $hostname = filter_input_hostname($_POST['hostname'], true);
286)     $domainid = (int) $_POST['domain'];
287)     if ($domainid >= 0) {
288)         $domain = new Domain((int) $_POST['domain']);
289)         $domain->ensure_userdomain();
290)         $domainid = $domain->id;
291)     }
292)     if ($domainid == -1) {
293)         # use configured user_vhosts_domain
294)         $userdomain = userdomain();
295)         $domain = new Domain((int) $userdomain['id']);
296)         $domainid = $domain->id;
297)         $hostname = $hostname.'.'.$_SESSION['userinfo']['username'];
298)         $hostname = trim($hostname, " .-");
299)     }
300) 
301)     if (! is_array($_POST['options'])) {
302)         $_POST['options'] = array();
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 Fix coding style with php-c...

Hanno authored 5 years ago

307)     $new_options = array();
308)     if ($aliaswww) {
309)         array_push($new_options, 'aliaswww');
310)     }
311)     if ($forward) {
312)         array_push($new_options, 'forward');
313)     }
314)     DEBUG($new_options);
315)     $options = implode(',', $new_options);
316)     DEBUG('New options: '.$options);
317) 
318)     $alias['hostname'] = $hostname;
319)     $alias['domain_id'] = $domainid;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

323)     save_alias($alias);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

325)     if (! $debugmode) {
326)         header('Location: aliases?vhost='.$vhost['id']);
327)     }
328) } elseif ($_GET['action'] == 'deletealias') {
329)     $title = "Subdomain löschen";
330)     $section = 'vhosts_vhosts';
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

332)     $alias = get_alias_details((int) $_GET['alias']);
333)     DEBUG($alias);
334)     $alias_string = $alias['fqdn'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

336)     $vhost = get_vhost_details($alias['vhost']);
337)     DEBUG($vhost);
338)     $vhost_string = $vhost['fqdn'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

340)     $sure = user_is_sure();
341)     if ($sure === null) {
342)         are_you_sure("action=deletealias&alias={$_GET['alias']}", "Möchten Sie das Alias »{$alias_string}« für die Subdomain »{$vhost_string}« wirklich löschen?");
343)     } elseif ($sure === true) {
344)         delete_alias($alias['id']);
345)         if (! $debugmode) {
346)             header('Location: aliases?vhost='.$vhost['id']);
347)         }
348)     } elseif ($sure === false) {
349)         if (! $debugmode) {
350)             header('Location: aliases?vhost='.$vhost['id']);
351)         }
352)     }
353) } elseif ($_GET['action'] == 'delete') {
354)     $title = "Subdomain löschen";
355)     $section = 'vhosts_vhosts';
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

360)     $sure = user_is_sure();
361)     if ($sure === null) {
362)         are_you_sure("action=delete&vhost={$_GET['vhost']}", "Möchten Sie die Subdomain »{$vhost_string}« wirklich löschen?");
363)     } elseif ($sure === true) {
364)         delete_vhost($vhost['id']);
365)         if (! $debugmode) {
366)             header("Location: vhosts");
367)         }
368)     } elseif ($sure === false) {
369)         if (! $debugmode) {
370)             header("Location: vhosts");
371)         }
372)     }
373) } else {
374)     system_failure("Unimplemented action");