4f9eac39f56eaf675e1ce21038360f2af6e635c7
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) 
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

49)         /* Wir nehmen an, dass unsere Tags immer an zweitletzter Stelle die Major-Version und 
50)         an letzter Stelle die Minor-Version enthalten */
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

62)             $ret = array($key => array('major' => null, 'minor' => null, 'status' => 'used', 'default' => false)) + $ret;
Bernd Wurst Bestandsschutz für eigentli...

Bernd Wurst authored 5 years ago

63)             /* Wir nehmen an, dass unsere Tags immer an zweitletzter Stelle die Major-Version und 
64)             an letzter Stelle die Minor-Version enthalten */
65)             $ret[$key]['major'] = substr($key, -2, 1);
66)             $ret[$key]['minor'] = substr($key, -1, 1);
67)         }
68)     }
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

75)     $vhost_id = (int) $vhost_id;
76)     $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));
77)     $data = $result->fetch();
78)     return $data['mb'];
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

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

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno authored 5 years ago

83)     $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));
84)     $data = $result->fetch();
85)     if (!$data['v6_prefix']) {
86)         warning("IPv6-Adresse nicht verfügbar, Server unterstützt kein IPv6");
87)         return "";
88)     }
89)     list($prefix, $null) = explode('/', $data['v6_prefix']);
90)     $vh = ':1';
91)     if ($mode == 2) {
92)         $vh = implode(':', str_split(sprintf("%08x", $vhost_id), 4));
93)     }
94)     $ipv6 = $prefix . sprintf("%04s", $data['uid']) . ':' . $vh;
95)     return $ipv6;
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

101)     $uid = (int) $_SESSION['userinfo']['uid'];
102)     $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";
103)     $params = array(":uid" => $uid);
104)     if ($filter) {
105)         $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";
106)         $params[":filter"] = "%$filter%";
107)     }
108)     $result = db_query($query, $params);
109)     $ret = array();
110)     while ($item = $result->fetch()) {
111)         array_push($ret, $item);
112)     }
113)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

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

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

163) }
164) 
165) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

248)     DEBUG("Lese #{$id}...");
249)     $id = (int) $id;
250)     $uid = (int) $_SESSION['userinfo']['uid'];
251)     $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));
252)     if ($result->rowCount() != 1) {
253)         system_failure('Interner Fehler beim Auslesen der Daten');
254)     }
255) 
256)     $ret = $result->fetch();
257) 
258)     if ($ret['domain_id'] === null) {
259)         $ret['domain_id'] = -2;
260)     }
261)     $ret['cert'] = $ret['certid'];
262)     $userdomain = userdomain();
263)     if ($ret['domain_id'] == $userdomain['id']) {
264)         $user = $_SESSION['userinfo']['username'];
265)         $ret['domain_id'] = -1;
266)         if ($ret['hostname'] == $user) {
267)             $ret['hostname'] = null;
268)         } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
269)             $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user)-1); // Punkt mit entfernen!
270)         } else {
271)             system_failure('Userdomain ohne Username!');
272)         }
273)     }
274)     if ($ret['hsts'] === null) {
275)         DEBUG('HSTS: '.$ret['hsts']);
276)         $ret['hsts'] = -1;
277)     }
278)     $ret['server'] = $ret['server_id'];
279)     DEBUG($ret);
280)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

311) }
312) 
bernd Aliases editieren

bernd authored 16 years ago

313) 
bernd Webapps implementiert

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

334) }
335) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

358) }
359) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

516)     if ($id != 0) {
517)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
518)         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);
519)     } else {
520)         $args[":user"] = $_SESSION['userinfo']['uid'];
521)         unset($args[":id"]);
522)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
523)         $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

524)                        "(: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

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

bernd authored 16 years ago

541) }
542) 
543) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

563)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

598)     if ($id == 0) {
599)         unset($args[":id"]);
600)         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

601)         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

602)     } else {
603)         unset($args[":vhost"]);
604)         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

605)         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

606)     }
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

609) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

622) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

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