01e41c2c5bc5ca4f503da01a39ced46ae8fed99c
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) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

191)     global $domainlist, $config;
192)     if ($domainlist == null) {
193)         $domainlist = get_domain_list(
194)         $_SESSION['customerinfo']['customerno'],
195)                                   $_SESSION['userinfo']['uid']
196)     );
197)     }
198)     $selected = (int) $selected;
199) 
200)     $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
201)     $found = false;
202)     foreach ($domainlist as $dom) {
203)         $s = '';
204)         if ($selected == $dom->id) {
205)             $s = ' selected="selected" ';
206)             $found = true;
207)         }
208)         $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
209)     }
210)     $userdomain = userdomain();
Hanno usersubdomain immer verfügb...

Hanno authored 5 years ago

211)     $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
212)     if ($userdomain) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

213)         $s = ($selected == -1 ? ' selected="selected"' : '');
214)         $ret .= ' <option value="-1"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.$userdomain['name'].'</option>';
215)     }
216)     if ($selected == -2) {
217)         $s = ($selected == -2 ? ' selected="selected"' : '');
218)         $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').' (Bitte nicht mehr benutzen!)</option>';
219)         if ($selected > 0 and ! $found) {
220)             system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
221)         }
222)     }
223)     $ret .= '</select>';
224)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

225) }
226) 
227) 
228) 
229) function get_vhost_details($id)
230) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

231)     DEBUG("Lese #{$id}...");
232)     $id = (int) $id;
233)     $uid = (int) $_SESSION['userinfo']['uid'];
234)     $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));
235)     if ($result->rowCount() != 1) {
236)         system_failure('Interner Fehler beim Auslesen der Daten');
237)     }
238) 
239)     $ret = $result->fetch();
240) 
241)     if ($ret['domain_id'] === null) {
242)         $ret['domain_id'] = -2;
243)     }
244)     $ret['cert'] = $ret['certid'];
245)     $userdomain = userdomain();
246)     if ($ret['domain_id'] == $userdomain['id']) {
247)         $user = $_SESSION['userinfo']['username'];
248)         $ret['domain_id'] = -1;
249)         if ($ret['hostname'] == $user) {
250)             $ret['hostname'] = null;
251)         } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
252)             $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user)-1); // Punkt mit entfernen!
253)         } else {
254)             system_failure('Userdomain ohne Username!');
255)         }
256)     }
257)     if ($ret['hsts'] === null) {
258)         DEBUG('HSTS: '.$ret['hsts']);
259)         $ret['hsts'] = -1;
260)     }
261)     $ret['server'] = $ret['server_id'];
262)     DEBUG($ret);
263)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

264) }
265) 
266) 
267) function get_aliases($vhost)
268) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

269)     $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost=?", array($vhost));
270)     $ret = array();
271)     while ($item = $result->fetch()) {
272)         array_push($ret, $item);
273)     }
274)     return $ret;
bernd Aliases editieren

bernd authored 16 years ago

275) }
276) 
277) 
278) 
279) function get_all_aliases($vhost)
280) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

281)     //$vhost = get_vhost_details( (int) $vhost );
282)     $aliases = get_aliases($vhost['id']);
283)     $ret = array();
284)     if (strstr($vhost['options'], 'aliaswww')) {
285)         array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : null)));
286)     }
287)     foreach ($aliases as $item) {
288)         array_push($ret, $item);
289)         if (strstr($item['options'], 'aliaswww')) {
290)             array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : null)));
291)         }
292)     }
293)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

294) }
295) 
bernd Aliases editieren

bernd authored 16 years ago

296) 
bernd Webapps implementiert

bernd authored 16 years ago

297) function list_available_webapps()
298) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

299)     $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
300)     $ret = array();
301)     while ($item = $result->fetch()) {
302)         array_push($ret, $item);
303)     }
304)     return $ret;
bernd Webapps implementiert

bernd authored 16 years ago

305) }
306) 
307) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

310)     $id = (int) $id;
311)     if ($id == 0) {
312)         system_failure("id == 0");
313)     }
314)     $vhost = get_vhost_details($id);
315)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
316)     db_query("DELETE FROM vhosts.vhost WHERE id=?", array($vhost['id']));
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

317) }
318) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

323)     $id = (int) $id;
324)     if ($id == 0) {
325)         system_failure("id == 0");
326)     }
327)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to SVN');
328)     db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES (?, 'svn')", array($id));
329)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

334)     $id = (int) $id;
335)     if ($id == 0) {
336)         system_failure("id == 0");
337)     }
338)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
339)     db_query("REPLACE INTO vhosts.dav (vhost, type, options) VALUES (?, 'dav', 'nouserfile')", array($id));
340)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

341) }
342) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

345)     $id = (int) $id;
346)     if ($id == 0) {
347)         system_failure("id == 0");
348)     }
349)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to regular');
350)     db_query("DELETE FROM vhosts.dav WHERE vhost=?", array($id));
351)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

352) }
353) 
354) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

357)     $id = (int) $id;
358)     $webapp = (int) $webapp;
359)     if ($id == 0) {
360)         system_failure("id == 0");
361)     }
362)     $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id=?", array($webapp));
363)     if ($result->rowCount() == 0) {
364)         system_failure("webapp-id invalid");
365)     }
366)     $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
367)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
368)     db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", array($id, $webapp));
369)     mail('webapps-setup@schokokeks.org', 'setup', 'setup');
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 check_hostname_collision($hostname, $domain)
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

375)     $uid = (int) $_SESSION['userinfo']['uid'];
376)     # Neuer vhost => Prüfe Duplikat
377)     $args = array(":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid);
378)     $domaincheck = "domain=:domain";
379)     if ($domain == -1) {
380)         $userdomain = userdomain();
381)         if ($hostname) {
382)             $hostname .= ".".$_SESSION['userinfo']['username'];
383)         }
384)         $args[":domain"] = $userdomain['id'];
385)     }
386)     if ($domain == -2) {
387)         unset($args[":domain"]);
388)         $domaincheck = "domain IS NULL";
389)     }
390)     $hostnamecheck = "hostname=:hostname";
391)     if (! $hostname) {
392)         $hostnamecheck = "hostname IS NULL";
393)         unset($args[":hostname"]);
394)     }
395)     $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid", $args);
396)     if ($result->rowCount() > 0) {
397)         system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
398)     }
399)     if ($domain <= -1) {
400)         return ;
401)     }
402)     unset($args[":uid"]);
403)     $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
404)     if ($result->rowCount() > 0) {
405)         $data = $result->fetch();
406)         $vh = get_vhost_details($data['vhost']);
407)         system_failure('Dieser Hostname ist bereits als Alias für »'.$vh['fqdn'].'« eingerichtet');
408)     }
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

409) }
410) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

413)     if (! is_array($vhost)) {
414)         system_failure('$vhost kein array!');
415)     }
416)     $id = (int) $vhost['id'];
417)     $hostname = $vhost['hostname'];
418)     $domain = (int) $vhost['domain_id'];
419)     if ($domain == 0) {
420)         system_failure('$domain == 0');
421)     }
422)     if ($vhost['domain_id'] == -2) {
423)         $domain = null;
424)     }
425)     if ($id == 0) {
426)         check_hostname_collision($vhost['hostname'], $vhost['domain_id']);
427)     }
428)     $hsts = (int) $vhost['hsts'];
429)     if ($hsts < 0) {
430)         $hsts = null;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

434)     $available_suexec = available_suexec_users();
435)     foreach ($available_suexec as $u) {
436)         if ($u['uid'] == $vhost['suexec_user']) {
437)             $suexec_user = $u['uid'];
438)         }
439)     }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

441)     $server = null;
442)     $available_servers = additional_servers();
443)     if (in_array($vhost['server'], $available_servers)) {
444)         $server = (int) $vhost['server'];
445)     }
446)     if ($server == my_server_id()) {
447)         $server = null;
448)     }
449) 
450)     if ($vhost['is_svn']) {
451)         if (! $vhost['options']) {
452)             $vhost['options']='nodocroot';
453)         } else {
454)             $vhost['options'].=",nodocroot";
455)         }
456)     }
457) 
458)     $cert = null;
459)     $certs = user_certs();
460)     foreach ($certs as $c) {
461)         if ($c['id'] == $vhost['cert']) {
462)             $cert = $c['id'];
463)         }
464)     }
465) 
466)     $ipv4 = null;
467)     $ipv4_avail = user_ipaddrs();
468)     if (in_array($vhost['ipv4'], $ipv4_avail)) {
469)         $ipv4 = $vhost['ipv4'];
470)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

472)     $autoipv6 = 1;
473)     if ($vhost['autoipv6'] == 0 ||  $vhost['autoipv6'] == 2) {
474)         $autoipv6 = $vhost['autoipv6'];
475)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

485)                 ":php" => $vhost['php'],
486)                 ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
487)                 ":ssl" => $vhost['ssl'],
488)                 ":hsts" => $hsts,
489)                 ":suexec_user" => $suexec_user,
490)                 ":server" => $server,
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

492)                 ":errorlog" => (int) $vhost['errorlog'],
493)                 ":cert" => $cert,
494)                 ":ipv4" => $ipv4,
495)                 ":autoipv6" => $autoipv6,
Bernd Wurst $vhost["options"] darf in d...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

499)     if ($id != 0) {
500)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
501)         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);
502)     } else {
503)         $args[":user"] = $_SESSION['userinfo']['uid'];
504)         unset($args[":id"]);
505)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
506)         $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 ".
Hanno Warnung bei vhost anlegen v...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

508)         $id = db_insert_id();
509)     }
510)     $oldvhost = get_vhost_details($id);
511)     /*
512)       these vars may be 0 or 1.
513)       So newval > oldval means that it has been switched on yet.
514)     */
515)     if ($vhost['is_dav'] > $oldvhost['is_dav']) {
516)         make_dav_vhost($id);
517)     } elseif ($vhost['is_svn'] > $oldvhost['is_svn']) {
518)         make_svn_vhost($id);
519)     } elseif ($vhost['is_webapp'] > $oldvhost['is_webapp']) {
520)         make_webapp_vhost($id, $vhost['webapp_id']);
521)     } elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0) {
522)         make_regular_vhost($id);
523)     }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

524) }
525) 
526) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

539)     if ($alias['domain_id'] == null) {
540)         $alias['domain_id'] = -1;
541)     }
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

546)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

547) }
548) 
549) 
550) function delete_alias($id)
551) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

552)     $id = (int) $id;
553)     $alias = get_alias_details($id);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

557) }
558) 
559) function save_alias($alias)
560) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

561)     if (! is_array($alias)) {
562)         system_failure('$alias kein array!');
563)     }
564)     $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
565)     $domain = (int) $alias['domain_id'];
566)     if ($domain == 0) {
567)         system_failure('$domain == 0');
568)     }
569)     if ($alias['domain_id'] == -2) {
570)         $domain = null;
571)     }
572)     $vhost = get_vhost_details((int) $alias['vhost']);
573)     if (! $alias['hostname']) {
574)         $alias['hostname'] = null;
575)     }
576)     $args = array(":hostname" => $alias['hostname'],
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

577)                 ":domain" => $domain,
578)                 ":vhost" => $vhost['id'],
579)                 ":options" => $alias['options'],
580)                 ":id" => $id);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

581)     if ($id == 0) {
582)         unset($args[":id"]);
583)         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

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

585)     } else {
586)         unset($args[":vhost"]);
587)         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

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

589)     }
bernd Aliases editieren

bernd authored 16 years ago

590) }
591) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

592) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

593) function available_suexec_users()
594) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

595)     $uid = (int) $_SESSION['userinfo']['uid'];
596)     $result = db_query("SELECT uid, username FROM vhosts.available_users LEFT JOIN vhosts.v_useraccounts ON (uid = suexec_user) WHERE mainuser=?", array($uid));
597)     $ret = array();
598)     while ($i = $result->fetch()) {
599)         $ret[] = $i;
600)     }
601)     DEBUG('available suexec-users:');
602)     DEBUG($ret);
603)     return $ret;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

bernd authored 16 years ago

605) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

606) 
607) function user_ipaddrs()
608) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

609)     $uid = (int) $_SESSION['userinfo']['uid'];
610)     $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid=?", array($uid));
611)     $ret = array();
612)     while ($i = $result->fetch()) {
613)         $ret[] = $i['ipaddr'];
614)     }
615)     DEBUG($ret);
616)     return $ret;