62165a5745bd942eb0f5ea95e84555a938e7e832
bernd neues VHosts-Modul (unbenut...

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 neues VHosts-Modul (unbenut...

bernd authored 16 years ago

16) 
17) require_once("inc/base.php");
18) require_once("inc/error.php");
19) require_once("inc/security.php");
20) 
21) require_once('class/domain.php');
22) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

23) require_once("certs.php");
24) 
bernd Aliases editieren

bernd authored 16 years ago

25) 
Hanno codingstyle

Hanno authored 5 years ago

26) function valid_php_versions()
27) {
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 5 years ago

28)     /* In der konfiguration ist die Variable "php_versions" eine kommaseparierte Liste der unterstützten Versionen.
29)         Dabei gelten folgende Suffixe (nicht kombinierbar!):
30)             *: Standardversion für neue Konfigurationen
31)             /: Deprecated
32)             +: Beta-Version
33)     */
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

34)     $tags = explode(',', config('php_versions'));
35)     $ret = array();
36)     foreach ($tags as $t) {
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 5 years ago

37)         $key = $t;
38)         $ver = array('major' => null, 'minor' => null, 'status' => 'regular', 'default' => false);
39)         if (substr($t, -1, 1) == '+') {
40)             $ver['status'] = 'beta';
41)             $key = substr($t, 0, -1);
42)         } elseif (substr($t, -1, 1) == '/') {
43)             $ver['status'] = 'deprecated';
44)             $key = substr($t, 0, -1);
45)         } elseif (substr($t, -1, 1) == '*') {
46)             $ver['default'] = true;
47)             $key = substr($t, 0, -1);
48)         }
49) 
Hanno codingstyle

Hanno authored 5 years ago

50)         /* Wir nehmen an, dass unsere Tags immer an zweitletzter Stelle die Major-Version und
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

51)         an letzter Stelle die Minor-Version enthalten */
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 5 years ago

52)         $ver['major'] = substr($key, -2, 1);
53)         $ver['minor'] = substr($key, -1, 1);
54)         $ret[$key] = $ver;
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

55)     }
Bernd Wurst Bestandsschutz für eigentli...

Bernd Wurst authored 5 years ago

56)     /* Bis hier: aus der Datenbank ausgelesen */
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

57)     DEBUG($ret);
Bernd Wurst Bestandsschutz für eigentli...

Bernd Wurst authored 5 years ago

58)     /* Sonderfall: Wenn ein User noch Vhosts einer anderen Version hat, dann bleibt diese erlaubt */
59)     $list = list_vhosts();
60)     foreach ($list as $vhost) {
61)         if ($vhost['php'] && !array_key_exists($vhost['php'], $ret)) {
62)             $key = $vhost['php'];
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 5 years ago

63)             $ret = array($key => array('major' => null, 'minor' => null, 'status' => 'used', 'default' => false)) + $ret;
Hanno codingstyle

Hanno authored 5 years ago

64)             /* Wir nehmen an, dass unsere Tags immer an zweitletzter Stelle die Major-Version und
Bernd Wurst Bestandsschutz für eigentli...

Bernd Wurst authored 5 years ago

65)             an letzter Stelle die Minor-Version enthalten */
66)             $ret[$key]['major'] = substr($key, -2, 1);
67)             $ret[$key]['minor'] = substr($key, -1, 1);
68)         }
69)     }
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

70)     return $ret;
71) }
72) 
73) 
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

74) function traffic_month($vhost_id)
75) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

76)     $vhost_id = (int) $vhost_id;
77)     $result = db_query("SELECT sum(mb_in+mb_out) as mb FROM vhosts.traffic where date > CURDATE() - INTERVAL 1 MONTH AND vhost_id = ?", array($vhost_id));
78)     $data = $result->fetch();
79)     return $data['mb'];
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

80) }
81) 
bernd Zusätzlicher Haken für eige...

bernd authored 13 years ago

82) function autoipv6_address($vhost_id, $mode = 1)
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

83) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

84)     $result = db_query("SELECT uid, v6_prefix FROM vhosts.v_vhost LEFT JOIN system.servers ON (servers.hostname = server) WHERE v_vhost.id=?", array($vhost_id));
85)     $data = $result->fetch();
86)     if (!$data['v6_prefix']) {
87)         warning("IPv6-Adresse nicht verfügbar, Server unterstützt kein IPv6");
88)         return "";
89)     }
90)     list($prefix, $null) = explode('/', $data['v6_prefix']);
91)     $vh = ':1';
92)     if ($mode == 2) {
93)         $vh = implode(':', str_split(sprintf("%08x", $vhost_id), 4));
94)     }
95)     $ipv6 = $prefix . sprintf("%04s", $data['uid']) . ':' . $vh;
96)     return $ipv6;
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

97) }
98) 
99) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

100) function list_vhosts($filter=null)
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

101) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

102)     $uid = (int) $_SESSION['userinfo']['uid'];
103)     $query = "SELECT vh.id,fqdn,domain,docroot,docroot_is_default,php,cgi,vh.certid AS cert, vh.ssl, vh.options,logtype,errorlog,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp, stats FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE uid=:uid ORDER BY domain,hostname";
104)     $params = array(":uid" => $uid);
105)     if ($filter) {
106)         $query = "SELECT vh.id,fqdn,domain,docroot,docroot_is_default,php,cgi,vh.certid AS cert, vh.ssl, vh.options,logtype,errorlog,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp, stats FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE (vh.fqdn LIKE :filter OR vh.id IN (SELECT vhost FROM vhosts.v_alias WHERE fqdn LIKE :filter)) AND uid=:uid ORDER BY hostname";
107)         $params[":filter"] = "%$filter%";
108)     }
109)     $result = db_query($query, $params);
110)     $ret = array();
111)     while ($item = $result->fetch()) {
112)         array_push($ret, $item);
113)     }
114)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

115) }
116) 
bernd IPv6-fähigkeit auch richtig...

bernd authored 13 years ago

117) function ipv6_possible($server)
bernd IPv6-Option nur anzeigen we...

bernd authored 13 years ago

118) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

119)     $args = array(":server" => $server);
120)     $result = db_query("SELECT v6_prefix FROM system.servers WHERE id=:server OR hostname=:server", $args);
121)     $line = $result->fetch();
122)     DEBUG("Server {$server} is v6-capable: ". ($line['v6_prefix'] != null));
123)     return ($line['v6_prefix'] != null);
bernd IPv6-Option nur anzeigen we...

bernd authored 13 years ago

124) }
125) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

126) function empty_vhost()
127) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

128)     $vhost['id'] = null;
129)     $vhost['hostname'] = null;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

131)     $vhost['domain_id'] = null;
132)     $vhost['domain'] = null;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

134)     $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
135)     $vhost['docroot'] = null;
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 5 years ago

136) 
137)     $vhost['php'] = null;
138)     $phpversions = valid_php_versions();
139)     foreach ($phpversions as $tag => $info) {
140)         if ($info['default']) {
141)             $vhost['php'] = $tag;
142)         }
143)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

144)     $vhost['cgi'] = 1;
145)     $vhost['ssl'] = null;
146)     $vhost['hsts'] = -1;
147)     $vhost['suexec_user'] = null;
148)     $vhost['server'] = null;
149)     $vhost['logtype'] = null;
150)     $vhost['errorlog'] = 0;
151)     $vhost['is_dav'] = 0;
152)     $vhost['is_svn'] = 0;
153)     $vhost['is_webapp'] = 0;
154)     $vhost['webapp_id'] = null;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

156)     $vhost['cert'] = null;
157)     $vhost['certid'] = null;
158)     $vhost['ipv4'] = null;
159)     $vhost['autoipv6'] = 2; // 1 => Eine IP pro User, 2 => Eine IP pro VHost
160) 
161)     $vhost['options'] = 'forwardwww';
162)     $vhost['stats'] = null;
163)     return $vhost;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

164) }
165) 
166) 
bernd Aliases editieren

bernd authored 16 years ago

167) function empty_alias()
168) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

169)     $alias['hostname'] = null;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

171)     $alias['domain_id'] = -1;
172)     $alias['domain'] = $_SESSION['userinfo']['username'].'.'.config('masterdomain');
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

174)     $alias['options'] = null;
175)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

176) }
177) 
178) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

179) function userdomain()
180) {
181)     if (config('user_vhosts_domain') === null) {
182)         return null;
183)     }
184)     $result = db_query("SELECT id,name FROM vhosts.v_domains WHERE name=:dom", array(":dom" => config('user_vhosts_domain')));
185)     $res = $result->fetch();
186)     return $res;
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

187) }
188) 
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

189) function user_uses_userdomain()
190) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

191)     global $config;
192)     $uid = (int) $_SESSION['userinfo']['uid'];
193)     $userdomain = userdomain();
194)     $result = db_query("SELECT id FROM vhosts.vhost WHERE domain=:domid AND user=:uid", array(":uid" => $uid, ":domid" => $userdomain['id']));
195)     if ($result->rowCount() > 0) {
196)         DEBUG("User hat ".$result->rowCount()." Domains *.schokokeks.net");
197)         return true;
198)     }
199)     DEBUG("User hat keine Domains *.schokokeks.net");
200)     return false;
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

201) }
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

203) function domainselect($selected = null, $selectattribute = '')
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

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

Hanno authored 5 years ago

205)     global $domainlist, $config;
206)     if ($domainlist == null) {
207)         $domainlist = get_domain_list(
208)         $_SESSION['customerinfo']['customerno'],
209)                                   $_SESSION['userinfo']['uid']
210)     );
211)     }
212)     $selected = (int) $selected;
213) 
214)     $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
215)     $found = false;
216)     foreach ($domainlist as $dom) {
217)         $s = '';
218)         if ($selected == $dom->id) {
219)             $s = ' selected="selected" ';
220)             $found = true;
221)         }
222)         $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
223)     }
224)     $userdomain = userdomain();
225)     $user_needs_userdomain = $userdomain && (count($domainlist) == 0 || user_uses_userdomain());
226)     $user_needs_userdomain = $user_needs_userdomain || ($selected == -2);
227)     if (count($domainlist) > 0 && $user_needs_userdomain) {
228)         $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
229)     }
230)     if ($userdomain && (count($domainlist) == 0 || user_uses_userdomain())) {
231)         $s = ($selected == -1 ? ' selected="selected"' : '');
232)         $ret .= ' <option value="-1"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.$userdomain['name'].'</option>';
233)     }
234)     if ($selected == -2) {
235)         $s = ($selected == -2 ? ' selected="selected"' : '');
236)         $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').' (Bitte nicht mehr benutzen!)</option>';
237)         if ($selected > 0 and ! $found) {
238)             system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
239)         }
240)     }
241)     $ret .= '</select>';
242)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

243) }
244) 
245) 
246) 
247) function get_vhost_details($id)
248) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

249)     DEBUG("Lese #{$id}...");
250)     $id = (int) $id;
251)     $uid = (int) $_SESSION['userinfo']['uid'];
252)     $result = db_query("SELECT vh.*,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE uid=:uid AND vh.id=:id", array(":uid" => $uid, ":id" => $id));
253)     if ($result->rowCount() != 1) {
254)         system_failure('Interner Fehler beim Auslesen der Daten');
255)     }
256) 
257)     $ret = $result->fetch();
258) 
259)     if ($ret['domain_id'] === null) {
260)         $ret['domain_id'] = -2;
261)     }
262)     $ret['cert'] = $ret['certid'];
263)     $userdomain = userdomain();
264)     if ($ret['domain_id'] == $userdomain['id']) {
265)         $user = $_SESSION['userinfo']['username'];
266)         $ret['domain_id'] = -1;
267)         if ($ret['hostname'] == $user) {
268)             $ret['hostname'] = null;
269)         } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
270)             $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user)-1); // Punkt mit entfernen!
271)         } else {
272)             system_failure('Userdomain ohne Username!');
273)         }
274)     }
275)     if ($ret['hsts'] === null) {
276)         DEBUG('HSTS: '.$ret['hsts']);
277)         $ret['hsts'] = -1;
278)     }
279)     $ret['server'] = $ret['server_id'];
280)     DEBUG($ret);
281)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

282) }
283) 
284) 
285) function get_aliases($vhost)
286) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

287)     $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost=?", array($vhost));
288)     $ret = array();
289)     while ($item = $result->fetch()) {
290)         array_push($ret, $item);
291)     }
292)     return $ret;
bernd Aliases editieren

bernd authored 16 years ago

293) }
294) 
295) 
296) 
297) function get_all_aliases($vhost)
298) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

299)     //$vhost = get_vhost_details( (int) $vhost );
300)     $aliases = get_aliases($vhost['id']);
301)     $ret = array();
302)     if (strstr($vhost['options'], 'aliaswww')) {
303)         array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : null)));
304)     }
305)     foreach ($aliases as $item) {
306)         array_push($ret, $item);
307)         if (strstr($item['options'], 'aliaswww')) {
308)             array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : null)));
309)         }
310)     }
311)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

312) }
313) 
bernd Aliases editieren

bernd authored 16 years ago

314) 
bernd Webapps implementiert

bernd authored 16 years ago

315) function list_available_webapps()
316) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

317)     $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
318)     $ret = array();
319)     while ($item = $result->fetch()) {
320)         array_push($ret, $item);
321)     }
322)     return $ret;
bernd Webapps implementiert

bernd authored 16 years ago

323) }
324) 
325) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

326) function delete_vhost($id)
327) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

328)     $id = (int) $id;
329)     if ($id == 0) {
330)         system_failure("id == 0");
331)     }
332)     $vhost = get_vhost_details($id);
333)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
334)     db_query("DELETE FROM vhosts.vhost WHERE id=?", array($vhost['id']));
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

335) }
336) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

339) function make_svn_vhost($id)
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

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

Hanno authored 5 years ago

341)     $id = (int) $id;
342)     if ($id == 0) {
343)         system_failure("id == 0");
344)     }
345)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to SVN');
346)     db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES (?, 'svn')", array($id));
347)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

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

Hanno authored 5 years ago

350) function make_dav_vhost($id)
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

351) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

352)     $id = (int) $id;
353)     if ($id == 0) {
354)         system_failure("id == 0");
355)     }
356)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
357)     db_query("REPLACE INTO vhosts.dav (vhost, type, options) VALUES (?, 'dav', 'nouserfile')", array($id));
358)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

359) }
360) 
bernd Webapps implementiert

bernd authored 16 years ago

361) function make_regular_vhost($id)
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

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

Hanno authored 5 years ago

363)     $id = (int) $id;
364)     if ($id == 0) {
365)         system_failure("id == 0");
366)     }
367)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to regular');
368)     db_query("DELETE FROM vhosts.dav WHERE vhost=?", array($id));
369)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

370) }
371) 
372) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

373) function make_webapp_vhost($id, $webapp)
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

374) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

375)     $id = (int) $id;
376)     $webapp = (int) $webapp;
377)     if ($id == 0) {
378)         system_failure("id == 0");
379)     }
380)     $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id=?", array($webapp));
381)     if ($result->rowCount() == 0) {
382)         system_failure("webapp-id invalid");
383)     }
384)     $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
385)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
386)     db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", array($id, $webapp));
387)     mail('webapps-setup@schokokeks.org', 'setup', 'setup');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

388) }
389) 
390) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

391) function check_hostname_collision($hostname, $domain)
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

392) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

393)     $uid = (int) $_SESSION['userinfo']['uid'];
394)     # Neuer vhost => Prüfe Duplikat
395)     $args = array(":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid);
396)     $domaincheck = "domain=:domain";
397)     if ($domain == -1) {
398)         $userdomain = userdomain();
399)         if ($hostname) {
400)             $hostname .= ".".$_SESSION['userinfo']['username'];
401)         }
402)         $args[":domain"] = $userdomain['id'];
403)     }
404)     if ($domain == -2) {
405)         unset($args[":domain"]);
406)         $domaincheck = "domain IS NULL";
407)     }
408)     $hostnamecheck = "hostname=:hostname";
409)     if (! $hostname) {
410)         $hostnamecheck = "hostname IS NULL";
411)         unset($args[":hostname"]);
412)     }
413)     $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid", $args);
414)     if ($result->rowCount() > 0) {
415)         system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
416)     }
417)     if ($domain <= -1) {
418)         return ;
419)     }
420)     unset($args[":uid"]);
421)     $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
422)     if ($result->rowCount() > 0) {
423)         $data = $result->fetch();
424)         $vh = get_vhost_details($data['vhost']);
425)         system_failure('Dieser Hostname ist bereits als Alias für »'.$vh['fqdn'].'« eingerichtet');
426)     }
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

427) }
428) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

429) function save_vhost($vhost)
430) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

431)     if (! is_array($vhost)) {
432)         system_failure('$vhost kein array!');
433)     }
434)     $id = (int) $vhost['id'];
435)     $hostname = $vhost['hostname'];
436)     $domain = (int) $vhost['domain_id'];
437)     if ($domain == 0) {
438)         system_failure('$domain == 0');
439)     }
440)     if ($vhost['domain_id'] == -2) {
441)         $domain = null;
442)     }
443)     if ($id == 0) {
444)         check_hostname_collision($vhost['hostname'], $vhost['domain_id']);
445)     }
446)     $hsts = (int) $vhost['hsts'];
447)     if ($hsts < 0) {
448)         $hsts = null;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

450)     $suexec_user = null;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

452)     $available_suexec = available_suexec_users();
453)     foreach ($available_suexec as $u) {
454)         if ($u['uid'] == $vhost['suexec_user']) {
455)             $suexec_user = $u['uid'];
456)         }
457)     }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

459)     $server = null;
460)     $available_servers = additional_servers();
461)     if (in_array($vhost['server'], $available_servers)) {
462)         $server = (int) $vhost['server'];
463)     }
464)     if ($server == my_server_id()) {
465)         $server = null;
466)     }
467) 
468)     if ($vhost['is_svn']) {
469)         if (! $vhost['options']) {
470)             $vhost['options']='nodocroot';
471)         } else {
472)             $vhost['options'].=",nodocroot";
473)         }
474)     }
475) 
476)     $cert = null;
477)     $certs = user_certs();
478)     foreach ($certs as $c) {
479)         if ($c['id'] == $vhost['cert']) {
480)             $cert = $c['id'];
481)         }
482)     }
483) 
484)     $ipv4 = null;
485)     $ipv4_avail = user_ipaddrs();
486)     if (in_array($vhost['ipv4'], $ipv4_avail)) {
487)         $ipv4 = $vhost['ipv4'];
488)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

490)     $autoipv6 = 1;
491)     if ($vhost['autoipv6'] == 0 ||  $vhost['autoipv6'] == 2) {
492)         $autoipv6 = $vhost['autoipv6'];
493)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

495)     if (!($vhost['ssl'] == 'forward' || $vhost['ssl'] == 'http' ||
Bernd Wurst Typo korrigiert

Bernd Wurst authored 9 years ago

496)         $vhost['ssl'] == 'https')) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

497)         $vhost['ssl'] = null;
498)     }
Bernd Wurst Setze SSL-Option beim erste...

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

500)     $args = array(":hostname" => ($hostname ? $hostname : null),
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

501)                 ":domain" => $domain,
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

502)                 ":docroot" => ($vhost['docroot'] ? $vhost['docroot'] : null),
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

503)                 ":php" => $vhost['php'],
504)                 ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
505)                 ":ssl" => $vhost['ssl'],
506)                 ":hsts" => $hsts,
507)                 ":suexec_user" => $suexec_user,
508)                 ":server" => $server,
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

509)                 ":logtype" => ($vhost['logtype'] ? $vhost['logtype'] : null),
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

510)                 ":errorlog" => (int) $vhost['errorlog'],
511)                 ":cert" => $cert,
512)                 ":ipv4" => $ipv4,
513)                 ":autoipv6" => $autoipv6,
Bernd Wurst $vhost["options"] darf in d...

Bernd Wurst authored 10 years ago

514)                 ":options" => $vhost['options'],
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

515)                 ":stats" => ($vhost['stats'] ? $vhost['stats'] : null),
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

516)                 ":id" => $id);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

517)     if ($id != 0) {
518)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
519)         db_query("UPDATE vhosts.vhost SET hostname=:hostname, domain=:domain, docroot=:docroot, php=:php, cgi=:cgi, `ssl`=:ssl, hsts=:hsts, `suexec_user`=:suexec_user, `server`=:server, logtype=:logtype, errorlog=:errorlog, certid=:cert, ipv4=:ipv4, autoipv6=:autoipv6, options=:options, stats=:stats WHERE id=:id", $args);
520)     } else {
521)         $args[":user"] = $_SESSION['userinfo']['uid'];
522)         unset($args[":id"]);
523)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
524)         $result = db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, cgi, `ssl`, hsts, `suexec_user`, `server`, logtype, errorlog, certid, ipv4, autoipv6, options, stats) VALUES ".
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

525)                        "(:user, :hostname, :domain, :docroot, :php, :cgi, :ssl, :hsts, :suexec_user, :server, :logtype, :errorlog, :cert, :ipv4, :autoipv6, :options, :stats)", $args);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

526)         $id = db_insert_id();
527)     }
528)     $oldvhost = get_vhost_details($id);
529)     /*
530)       these vars may be 0 or 1.
531)       So newval > oldval means that it has been switched on yet.
532)     */
533)     if ($vhost['is_dav'] > $oldvhost['is_dav']) {
534)         make_dav_vhost($id);
535)     } elseif ($vhost['is_svn'] > $oldvhost['is_svn']) {
536)         make_svn_vhost($id);
537)     } elseif ($vhost['is_webapp'] > $oldvhost['is_webapp']) {
538)         make_webapp_vhost($id, $vhost['webapp_id']);
539)     } elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0) {
540)         make_regular_vhost($id);
541)     }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

542) }
543) 
544) 
bernd Aliases editieren

bernd authored 16 years ago

545) function get_alias_details($id)
546) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

547)     $id = (int) $id;
548)     $uid = (int) $_SESSION['userinfo']['uid'];
549)     $result = db_query("SELECT * FROM vhosts.v_alias WHERE id=?", array($id));
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

551)     if ($result->rowCount() != 1) {
552)         system_failure('Interner Fehler beim Auslesen der Alias-Daten');
553)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

555)     $alias = $result->fetch();
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

557)     if ($alias['domain_id'] == null) {
558)         $alias['domain_id'] = -1;
559)     }
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

561)     /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
562)     get_vhost_details((int) $alias['vhost']);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

564)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

565) }
566) 
567) 
568) function delete_alias($id)
569) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

570)     $id = (int) $id;
571)     $alias = get_alias_details($id);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

573)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
574)     db_query("DELETE FROM vhosts.alias WHERE id=?", array($id));
bernd Aliases editieren

bernd authored 16 years ago

575) }
576) 
577) function save_alias($alias)
578) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

579)     if (! is_array($alias)) {
580)         system_failure('$alias kein array!');
581)     }
582)     $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
583)     $domain = (int) $alias['domain_id'];
584)     if ($domain == 0) {
585)         system_failure('$domain == 0');
586)     }
587)     if ($alias['domain_id'] == -2) {
588)         $domain = null;
589)     }
590)     $vhost = get_vhost_details((int) $alias['vhost']);
591)     if (! $alias['hostname']) {
592)         $alias['hostname'] = null;
593)     }
594)     $args = array(":hostname" => $alias['hostname'],
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

595)                 ":domain" => $domain,
596)                 ":vhost" => $vhost['id'],
597)                 ":options" => $alias['options'],
598)                 ":id" => $id);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

599)     if ($id == 0) {
600)         unset($args[":id"]);
601)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
Hanno optional parameter to not w...

Hanno authored 5 years ago

602)         db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES (:hostname, :domain, :vhost, :options)", $args, true);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

603)     } else {
604)         unset($args[":vhost"]);
605)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
Hanno optional parameter to not w...

Hanno authored 5 years ago

606)         db_query("UPDATE vhosts.alias SET hostname=:hostname, domain=:domain, options=:options WHERE id=:id", $args, true);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

607)     }
bernd Aliases editieren

bernd authored 16 years ago

608) }
609) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

610) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

611) function available_suexec_users()
612) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

613)     $uid = (int) $_SESSION['userinfo']['uid'];
614)     $result = db_query("SELECT uid, username FROM vhosts.available_users LEFT JOIN vhosts.v_useraccounts ON (uid = suexec_user) WHERE mainuser=?", array($uid));
615)     $ret = array();
616)     while ($i = $result->fetch()) {
617)         $ret[] = $i;
618)     }
619)     DEBUG('available suexec-users:');
620)     DEBUG($ret);
621)     return $ret;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

622) }
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

623) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

624) 
625) function user_ipaddrs()
626) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

627)     $uid = (int) $_SESSION['userinfo']['uid'];
628)     $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid=?", array($uid));
629)     $ret = array();
630)     while ($i = $result->fetch()) {
631)         $ret[] = $i['ipaddr'];
632)     }
633)     DEBUG($ret);
634)     return $ret;