4b53992acd279ca46c5a12e40930639c942fb198
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() {
27)     $tags = explode(',', config('php_versions'));
28)     $ret = array();
29)     foreach ($tags as $t) {
30)         $key = str_replace('*', '', $t);
31)         $ret[$key] = array('major' => null, 'minor' => null, 'status' => 'regular');
32)         /* Wir nehmen an, dass unsere Tags immer an zweitletzter Stelle die Major-Version und 
33)         an letzter Stelle die Minor-Version enthalten */
34)         $ret[$key]['major'] = substr(str_replace('*', '', $t), -2, 1);
35)         $ret[$key]['minor'] = substr(str_replace('*', '', $t), -1, 1);
36)         if (substr($t, -1) === '*') {
37)             $ret[$key]['status'] = 'deprecated';
38)         }
39)     }
40)     DEBUG($ret);
41)     return $ret;
42) }
43) 
44) 
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

47)     $vhost_id = (int) $vhost_id;
48)     $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));
49)     $data = $result->fetch();
50)     return $data['mb'];
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

51) }
52) 
bernd Zusätzlicher Haken für eige...

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno authored 5 years ago

55)     $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));
56)     $data = $result->fetch();
57)     if (!$data['v6_prefix']) {
58)         warning("IPv6-Adresse nicht verfügbar, Server unterstützt kein IPv6");
59)         return "";
60)     }
61)     list($prefix, $null) = explode('/', $data['v6_prefix']);
62)     $vh = ':1';
63)     if ($mode == 2) {
64)         $vh = implode(':', str_split(sprintf("%08x", $vhost_id), 4));
65)     }
66)     $ipv6 = $prefix . sprintf("%04s", $data['uid']) . ':' . $vh;
67)     return $ipv6;
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

68) }
69) 
70) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

73)     $uid = (int) $_SESSION['userinfo']['uid'];
74)     $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";
75)     $params = array(":uid" => $uid);
76)     if ($filter) {
77)         $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";
78)         $params[":filter"] = "%$filter%";
79)     }
80)     $result = db_query($query, $params);
81)     $ret = array();
82)     while ($item = $result->fetch()) {
83)         array_push($ret, $item);
84)     }
85)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

86) }
87) 
bernd IPv6-fähigkeit auch richtig...

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

95) }
96) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

97) function empty_vhost()
98) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

105)     $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
106)     $vhost['docroot'] = null;
Bernd Wurst read available php versions...

Bernd Wurst authored 5 years ago

107)     $phpversions = explode(',', config('php_versions'));
108)     $vhost['php'] = end($phpversions);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

109)     $vhost['cgi'] = 1;
110)     $vhost['ssl'] = null;
111)     $vhost['hsts'] = -1;
112)     $vhost['suexec_user'] = null;
113)     $vhost['server'] = null;
114)     $vhost['logtype'] = null;
115)     $vhost['errorlog'] = 0;
116)     $vhost['is_dav'] = 0;
117)     $vhost['is_svn'] = 0;
118)     $vhost['is_webapp'] = 0;
119)     $vhost['webapp_id'] = null;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

121)     $vhost['cert'] = null;
122)     $vhost['certid'] = null;
123)     $vhost['ipv4'] = null;
124)     $vhost['autoipv6'] = 2; // 1 => Eine IP pro User, 2 => Eine IP pro VHost
125) 
126)     $vhost['options'] = 'forwardwww';
127)     $vhost['stats'] = null;
128)     return $vhost;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

129) }
130) 
131) 
bernd Aliases editieren

bernd authored 16 years ago

132) function empty_alias()
133) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

139)     $alias['options'] = null;
140)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

141) }
142) 
143) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

144) function userdomain()
145) {
146)     if (config('user_vhosts_domain') === null) {
147)         return null;
148)     }
149)     $result = db_query("SELECT id,name FROM vhosts.v_domains WHERE name=:dom", array(":dom" => config('user_vhosts_domain')));
150)     $res = $result->fetch();
151)     return $res;
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

152) }
153) 
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

154) function user_uses_userdomain()
155) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

156)     global $config;
157)     $uid = (int) $_SESSION['userinfo']['uid'];
158)     $userdomain = userdomain();
159)     $result = db_query("SELECT id FROM vhosts.vhost WHERE domain=:domid AND user=:uid", array(":uid" => $uid, ":domid" => $userdomain['id']));
160)     if ($result->rowCount() > 0) {
161)         DEBUG("User hat ".$result->rowCount()." Domains *.schokokeks.net");
162)         return true;
163)     }
164)     DEBUG("User hat keine Domains *.schokokeks.net");
165)     return false;
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

170)     global $domainlist, $config;
171)     if ($domainlist == null) {
172)         $domainlist = get_domain_list(
173)         $_SESSION['customerinfo']['customerno'],
174)                                   $_SESSION['userinfo']['uid']
175)     );
176)     }
177)     $selected = (int) $selected;
178) 
179)     $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
180)     $found = false;
181)     foreach ($domainlist as $dom) {
182)         $s = '';
183)         if ($selected == $dom->id) {
184)             $s = ' selected="selected" ';
185)             $found = true;
186)         }
187)         $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
188)     }
189)     $userdomain = userdomain();
190)     $user_needs_userdomain = $userdomain && (count($domainlist) == 0 || user_uses_userdomain());
191)     $user_needs_userdomain = $user_needs_userdomain || ($selected == -2);
192)     if (count($domainlist) > 0 && $user_needs_userdomain) {
193)         $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
194)     }
195)     if ($userdomain && (count($domainlist) == 0 || user_uses_userdomain())) {
196)         $s = ($selected == -1 ? ' selected="selected"' : '');
197)         $ret .= ' <option value="-1"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.$userdomain['name'].'</option>';
198)     }
199)     if ($selected == -2) {
200)         $s = ($selected == -2 ? ' selected="selected"' : '');
201)         $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').' (Bitte nicht mehr benutzen!)</option>';
202)         if ($selected > 0 and ! $found) {
203)             system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
204)         }
205)     }
206)     $ret .= '</select>';
207)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

208) }
209) 
210) 
211) 
212) function get_vhost_details($id)
213) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

214)     DEBUG("Lese #{$id}...");
215)     $id = (int) $id;
216)     $uid = (int) $_SESSION['userinfo']['uid'];
217)     $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));
218)     if ($result->rowCount() != 1) {
219)         system_failure('Interner Fehler beim Auslesen der Daten');
220)     }
221) 
222)     $ret = $result->fetch();
223) 
224)     if ($ret['domain_id'] === null) {
225)         $ret['domain_id'] = -2;
226)     }
227)     $ret['cert'] = $ret['certid'];
228)     $userdomain = userdomain();
229)     if ($ret['domain_id'] == $userdomain['id']) {
230)         $user = $_SESSION['userinfo']['username'];
231)         $ret['domain_id'] = -1;
232)         if ($ret['hostname'] == $user) {
233)             $ret['hostname'] = null;
234)         } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
235)             $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user)-1); // Punkt mit entfernen!
236)         } else {
237)             system_failure('Userdomain ohne Username!');
238)         }
239)     }
240)     if ($ret['hsts'] === null) {
241)         DEBUG('HSTS: '.$ret['hsts']);
242)         $ret['hsts'] = -1;
243)     }
244)     $ret['server'] = $ret['server_id'];
245)     DEBUG($ret);
246)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

247) }
248) 
249) 
250) function get_aliases($vhost)
251) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

252)     $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost=?", array($vhost));
253)     $ret = array();
254)     while ($item = $result->fetch()) {
255)         array_push($ret, $item);
256)     }
257)     return $ret;
bernd Aliases editieren

bernd authored 16 years ago

258) }
259) 
260) 
261) 
262) function get_all_aliases($vhost)
263) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

264)     //$vhost = get_vhost_details( (int) $vhost );
265)     $aliases = get_aliases($vhost['id']);
266)     $ret = array();
267)     if (strstr($vhost['options'], 'aliaswww')) {
268)         array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : null)));
269)     }
270)     foreach ($aliases as $item) {
271)         array_push($ret, $item);
272)         if (strstr($item['options'], 'aliaswww')) {
273)             array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : null)));
274)         }
275)     }
276)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

277) }
278) 
bernd Aliases editieren

bernd authored 16 years ago

279) 
bernd Webapps implementiert

bernd authored 16 years ago

280) function list_available_webapps()
281) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

282)     $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
283)     $ret = array();
284)     while ($item = $result->fetch()) {
285)         array_push($ret, $item);
286)     }
287)     return $ret;
bernd Webapps implementiert

bernd authored 16 years ago

288) }
289) 
290) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

293)     $id = (int) $id;
294)     if ($id == 0) {
295)         system_failure("id == 0");
296)     }
297)     $vhost = get_vhost_details($id);
298)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
299)     db_query("DELETE FROM vhosts.vhost WHERE id=?", array($vhost['id']));
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

300) }
301) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

306)     $id = (int) $id;
307)     if ($id == 0) {
308)         system_failure("id == 0");
309)     }
310)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to SVN');
311)     db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES (?, 'svn')", array($id));
312)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

313) }
314) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

317)     $id = (int) $id;
318)     if ($id == 0) {
319)         system_failure("id == 0");
320)     }
321)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
322)     db_query("REPLACE INTO vhosts.dav (vhost, type, options) VALUES (?, 'dav', 'nouserfile')", array($id));
323)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

324) }
325) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to regular');
333)     db_query("DELETE FROM vhosts.dav WHERE vhost=?", array($id));
334)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

335) }
336) 
337) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

338) function make_webapp_vhost($id, $webapp)
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)     $webapp = (int) $webapp;
342)     if ($id == 0) {
343)         system_failure("id == 0");
344)     }
345)     $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id=?", array($webapp));
346)     if ($result->rowCount() == 0) {
347)         system_failure("webapp-id invalid");
348)     }
349)     $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
350)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
351)     db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", array($id, $webapp));
352)     mail('webapps-setup@schokokeks.org', 'setup', 'setup');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

358)     $uid = (int) $_SESSION['userinfo']['uid'];
359)     # Neuer vhost => Prüfe Duplikat
360)     $args = array(":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid);
361)     $domaincheck = "domain=:domain";
362)     if ($domain == -1) {
363)         $userdomain = userdomain();
364)         if ($hostname) {
365)             $hostname .= ".".$_SESSION['userinfo']['username'];
366)         }
367)         $args[":domain"] = $userdomain['id'];
368)     }
369)     if ($domain == -2) {
370)         unset($args[":domain"]);
371)         $domaincheck = "domain IS NULL";
372)     }
373)     $hostnamecheck = "hostname=:hostname";
374)     if (! $hostname) {
375)         $hostnamecheck = "hostname IS NULL";
376)         unset($args[":hostname"]);
377)     }
378)     $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid", $args);
379)     if ($result->rowCount() > 0) {
380)         system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
381)     }
382)     if ($domain <= -1) {
383)         return ;
384)     }
385)     unset($args[":uid"]);
386)     $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
387)     if ($result->rowCount() > 0) {
388)         $data = $result->fetch();
389)         $vh = get_vhost_details($data['vhost']);
390)         system_failure('Dieser Hostname ist bereits als Alias für »'.$vh['fqdn'].'« eingerichtet');
391)     }
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

392) }
393) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

396)     if (! is_array($vhost)) {
397)         system_failure('$vhost kein array!');
398)     }
399)     $id = (int) $vhost['id'];
400)     $hostname = $vhost['hostname'];
401)     $domain = (int) $vhost['domain_id'];
402)     if ($domain == 0) {
403)         system_failure('$domain == 0');
404)     }
405)     if ($vhost['domain_id'] == -2) {
406)         $domain = null;
407)     }
408)     if ($id == 0) {
409)         check_hostname_collision($vhost['hostname'], $vhost['domain_id']);
410)     }
411)     $hsts = (int) $vhost['hsts'];
412)     if ($hsts < 0) {
413)         $hsts = null;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

417)     $available_suexec = available_suexec_users();
418)     foreach ($available_suexec as $u) {
419)         if ($u['uid'] == $vhost['suexec_user']) {
420)             $suexec_user = $u['uid'];
421)         }
422)     }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

424)     $server = null;
425)     $available_servers = additional_servers();
426)     if (in_array($vhost['server'], $available_servers)) {
427)         $server = (int) $vhost['server'];
428)     }
429)     if ($server == my_server_id()) {
430)         $server = null;
431)     }
432) 
433)     if ($vhost['is_svn']) {
434)         if (! $vhost['options']) {
435)             $vhost['options']='nodocroot';
436)         } else {
437)             $vhost['options'].=",nodocroot";
438)         }
439)     }
440) 
441)     $cert = null;
442)     $certs = user_certs();
443)     foreach ($certs as $c) {
444)         if ($c['id'] == $vhost['cert']) {
445)             $cert = $c['id'];
446)         }
447)     }
448) 
449)     $ipv4 = null;
450)     $ipv4_avail = user_ipaddrs();
451)     if (in_array($vhost['ipv4'], $ipv4_avail)) {
452)         $ipv4 = $vhost['ipv4'];
453)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

455)     $autoipv6 = 1;
456)     if ($vhost['autoipv6'] == 0 ||  $vhost['autoipv6'] == 2) {
457)         $autoipv6 = $vhost['autoipv6'];
458)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

468)                 ":php" => $vhost['php'],
469)                 ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
470)                 ":ssl" => $vhost['ssl'],
471)                 ":hsts" => $hsts,
472)                 ":suexec_user" => $suexec_user,
473)                 ":server" => $server,
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

475)                 ":errorlog" => (int) $vhost['errorlog'],
476)                 ":cert" => $cert,
477)                 ":ipv4" => $ipv4,
478)                 ":autoipv6" => $autoipv6,
Bernd Wurst $vhost["options"] darf in d...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

482)     if ($id != 0) {
483)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
484)         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);
485)     } else {
486)         $args[":user"] = $_SESSION['userinfo']['uid'];
487)         unset($args[":id"]);
488)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
489)         $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

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

491)         $id = db_insert_id();
492)     }
493)     $oldvhost = get_vhost_details($id);
494)     /*
495)       these vars may be 0 or 1.
496)       So newval > oldval means that it has been switched on yet.
497)     */
498)     if ($vhost['is_dav'] > $oldvhost['is_dav']) {
499)         make_dav_vhost($id);
500)     } elseif ($vhost['is_svn'] > $oldvhost['is_svn']) {
501)         make_svn_vhost($id);
502)     } elseif ($vhost['is_webapp'] > $oldvhost['is_webapp']) {
503)         make_webapp_vhost($id, $vhost['webapp_id']);
504)     } elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0) {
505)         make_regular_vhost($id);
506)     }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

507) }
508) 
509) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

522)     if ($alias['domain_id'] == null) {
523)         $alias['domain_id'] = -1;
524)     }
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

529)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

530) }
531) 
532) 
533) function delete_alias($id)
534) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

535)     $id = (int) $id;
536)     $alias = get_alias_details($id);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

540) }
541) 
542) function save_alias($alias)
543) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

544)     if (! is_array($alias)) {
545)         system_failure('$alias kein array!');
546)     }
547)     $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
548)     $domain = (int) $alias['domain_id'];
549)     if ($domain == 0) {
550)         system_failure('$domain == 0');
551)     }
552)     if ($alias['domain_id'] == -2) {
553)         $domain = null;
554)     }
555)     $vhost = get_vhost_details((int) $alias['vhost']);
556)     if (! $alias['hostname']) {
557)         $alias['hostname'] = null;
558)     }
559)     $args = array(":hostname" => $alias['hostname'],
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

560)                 ":domain" => $domain,
561)                 ":vhost" => $vhost['id'],
562)                 ":options" => $alias['options'],
563)                 ":id" => $id);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

564)     if ($id == 0) {
565)         unset($args[":id"]);
566)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
567)         db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES (:hostname, :domain, :vhost, :options)", $args);
568)     } else {
569)         unset($args[":vhost"]);
570)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
571)         db_query("UPDATE vhosts.alias SET hostname=:hostname, domain=:domain, options=:options WHERE id=:id", $args);
572)     }
bernd Aliases editieren

bernd authored 16 years ago

573) }
574) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

575) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

576) function available_suexec_users()
577) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

578)     $uid = (int) $_SESSION['userinfo']['uid'];
579)     $result = db_query("SELECT uid, username FROM vhosts.available_users LEFT JOIN vhosts.v_useraccounts ON (uid = suexec_user) WHERE mainuser=?", array($uid));
580)     $ret = array();
581)     while ($i = $result->fetch()) {
582)         $ret[] = $i;
583)     }
584)     DEBUG('available suexec-users:');
585)     DEBUG($ret);
586)     return $ret;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

bernd authored 16 years ago

588) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

589) 
590) function user_ipaddrs()
591) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

592)     $uid = (int) $_SESSION['userinfo']['uid'];
593)     $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid=?", array($uid));
594)     $ret = array();
595)     while ($i = $result->fetch()) {
596)         $ret[] = $i['ipaddr'];
597)     }
598)     DEBUG($ret);
599)     return $ret;