71e87c960a844568bbe0c2a7dd012d8b9247b037
bernd neues VHosts-Modul (unbenut...

bernd authored 18 years ago

1) <?php
Hanno Böck Add newlines before comment...

Hanno Böck authored 1 year ago

2) 
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 14 years ago

3) /*
4) This file belongs to the Webinterface of schokokeks.org Hosting
5) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 3 years ago

6) Written by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 14 years ago

7)   Bernd Wurst <bernd@schokokeks.org>
8)   Hanno Böck <hanno@schokokeks.org>
9) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 3 years ago

10) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 14 years ago

11) 
12) 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.
13) */
bernd neues VHosts-Modul (unbenut...

bernd authored 18 years ago

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

bernd authored 16 years ago

21) require_once("certs.php");
22) 
bernd Aliases editieren

bernd authored 18 years ago

23) 
Hanno codingstyle

Hanno authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

32)     $tags = explode(',', config('php_versions'));
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

33)     $ret = [];
Bernd Wurst read available php versions...

Bernd Wurst authored 7 years ago

34)     foreach ($tags as $t) {
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 7 years ago

35)         $key = $t;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

36)         $ver = ['major' => null, 'minor' => null, 'status' => 'regular', 'default' => false];
Bernd Wurst Definiere Markierungen für...

Bernd Wurst authored 7 years ago

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

Hanno authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

54)     /* Bis hier: aus der Datenbank ausgelesen */
Bernd Wurst added php version tag "defa...

Bernd Wurst authored 6 years ago

55)     krsort($ret);
Bernd Wurst read available php versions...

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 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) {
Bernd Wurst added php version tag "defa...

Bernd Wurst authored 6 years ago

60)         if ($vhost['php'] && $vhost['php'] != 'default' && !array_key_exists($vhost['php'], $ret)) {
Bernd Wurst Bestandsschutz für eigentli...

Bernd Wurst authored 7 years ago

61)             $key = $vhost['php'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

62)             $ret = [$key => ['major' => null, 'minor' => null, 'status' => 'used', 'default' => false]] + $ret;
Hanno codingstyle

Hanno authored 7 years ago

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

Bernd Wurst authored 7 years ago

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 7 years ago

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

Bernd Wurst authored 13 years ago

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

Hanno authored 8 years ago

75)     $vhost_id = (int) $vhost_id;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

76)     $result = db_query("SELECT sum(mb_in+mb_out) as mb FROM vhosts.traffic where date > CURDATE() - INTERVAL 1 MONTH AND vhost_id = ?", [$vhost_id]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

77)     $data = $result->fetch();
78)     return $data['mb'];
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

82) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 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=?", [$vhost_id]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

84)     $data = $result->fetch();
85)     if (!$data['v6_prefix']) {
86)         warning("IPv6-Adresse nicht verfügbar, Server unterstützt kein IPv6");
87)         return "";
88)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

89)     [$prefix, $null] = explode('/', $data['v6_prefix']);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

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 15 years ago

96) }
97) 
98) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 2 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

101)     $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Statistik-Funktion entfernt

Bernd Wurst authored 6 years ago

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 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";
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

103)     $params = [":uid" => $uid];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

104)     if ($filter) {
Bernd Wurst Statistik-Funktion entfernt

Bernd Wurst authored 6 years ago

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 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";
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

106)         $params[":filter"] = "%$filter%";
107)     }
108)     $result = db_query($query, $params);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

109)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

110)     while ($item = $result->fetch()) {
111)         array_push($ret, $item);
112)     }
113)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 18 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

117) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

118)     $args = [":server" => $server];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

119)     $result = db_query("SELECT v6_prefix FROM system.servers WHERE id=:server OR hostname=:server", $args);
120)     $line = $result->fetch();
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

121)     DEBUG("Server {$server} is v6-capable: " . ($line['v6_prefix'] != null));
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

122)     return ($line['v6_prefix'] != null);
bernd IPv6-Option nur anzeigen we...

bernd authored 15 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

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

Hanno authored 8 years ago

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

Hanno authored 8 years ago

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

Hanno authored 8 years ago

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

Hanno authored 8 years ago

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

Bernd Wurst authored 7 years ago

135) 
Bernd Wurst added php version tag "defa...

Bernd Wurst authored 6 years ago

136)     $vhost['php'] = 'default';
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

137)     $vhost['cgi'] = 1;
138)     $vhost['ssl'] = null;
139)     $vhost['hsts'] = -1;
140)     $vhost['suexec_user'] = null;
141)     $vhost['server'] = null;
142)     $vhost['logtype'] = null;
143)     $vhost['errorlog'] = 0;
144)     $vhost['is_dav'] = 0;
145)     $vhost['is_svn'] = 0;
146)     $vhost['is_webapp'] = 0;
147)     $vhost['webapp_id'] = null;
Hanno remove whitespace in empty...

Hanno authored 8 years ago

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

Hanno authored 8 years ago

149)     $vhost['cert'] = null;
150)     $vhost['certid'] = null;
151)     $vhost['ipv4'] = null;
152)     $vhost['autoipv6'] = 2; // 1 => Eine IP pro User, 2 => Eine IP pro VHost
153) 
154)     $vhost['options'] = 'forwardwww';
155)     return $vhost;
bernd VHosts können bearbeitet we...

bernd authored 18 years ago

156) }
157) 
158) 
bernd Aliases editieren

bernd authored 18 years ago

159) function empty_alias()
160) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

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

Hanno authored 8 years ago

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

Hanno authored 8 years ago

163)     $alias['domain_id'] = -1;
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

164)     $alias['domain'] = $_SESSION['userinfo']['username'] . '.' . config('masterdomain');
Hanno remove whitespace in empty...

Hanno authored 8 years ago

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

Hanno authored 8 years ago

166)     $alias['options'] = null;
167)     return $alias;
bernd Aliases editieren

bernd authored 18 years ago

168) }
169) 
170) 
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

171) function userdomain()
172) {
173)     if (config('user_vhosts_domain') === null) {
174)         return null;
175)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

176)     $result = db_query("SELECT id,name FROM vhosts.v_domains WHERE name=:dom", [":dom" => config('user_vhosts_domain')]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

177)     $res = $result->fetch();
178)     return $res;
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 11 years ago

179) }
180) 
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

183)     global $domainlist, $config;
184)     if ($domainlist == null) {
Bernd Wurst Übergebe keine Kundennummer...

Bernd Wurst authored 6 years ago

185)         $uid = null;
186)         if (isset($_SESSION['userinfo']['uid'])) {
187)             $uid = $_SESSION['userinfo']['uid'];
188)         }
189)         $domainlist = get_domain_list(null, $uid);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

190)     }
191)     $selected = (int) $selected;
192) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

193)     $ret = '<select id="domain" name="domain" size="1" ' . $selectattribute . ' >';
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

194)     $found = false;
195)     foreach ($domainlist as $dom) {
196)         $s = '';
197)         if ($selected == $dom->id) {
198)             $s = ' selected="selected" ';
199)             $found = true;
200)         }
201)         $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
202)     }
203)     $userdomain = userdomain();
Hanno usersubdomain immer verfügb...

Hanno authored 7 years ago

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

Hanno authored 8 years ago

206)         $s = ($selected == -1 ? ' selected="selected"' : '');
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

207)         $ret .= ' <option value="-1"' . $s . '>' . $_SESSION['userinfo']['username'] . '.' . $userdomain['name'] . '</option>';
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

208)     }
209)     if ($selected == -2) {
210)         $s = ($selected == -2 ? ' selected="selected"' : '');
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

211)         $ret .= ' <option value="-2"' . $s . '>' . $_SESSION['userinfo']['username'] . '.' . config('masterdomain') . ' (Bitte nicht mehr benutzen!)</option>';
Bernd Wurst fix broken check for foreig...

Bernd Wurst authored 1 year ago

212)     }
213)     if ($selected > 0 and !$found) {
214)         system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

215)     }
216)     $ret .= '</select>';
217)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 18 years ago

218) }
219) 
220) 
221) 
222) function get_vhost_details($id)
223) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

224)     DEBUG("Lese #{$id}...");
225)     $id = (int) $id;
226)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

227)     $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", [":uid" => $uid, ":id" => $id]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

228)     if ($result->rowCount() != 1) {
229)         system_failure('Interner Fehler beim Auslesen der Daten');
230)     }
231) 
232)     $ret = $result->fetch();
233) 
234)     if ($ret['domain_id'] === null) {
235)         $ret['domain_id'] = -2;
236)     }
237)     $ret['cert'] = $ret['certid'];
238)     $userdomain = userdomain();
239)     if ($ret['domain_id'] == $userdomain['id']) {
240)         $user = $_SESSION['userinfo']['username'];
241)         $ret['domain_id'] = -1;
242)         if ($ret['hostname'] == $user) {
243)             $ret['hostname'] = null;
244)         } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 2 years ago

245)             $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user) - 1); // Punkt mit entfernen!
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

246)         } else {
247)             system_failure('Userdomain ohne Username!');
248)         }
249)     }
250)     if ($ret['hsts'] === null) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

251)         DEBUG('HSTS: ' . $ret['hsts']);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

252)         $ret['hsts'] = -1;
253)     }
254)     $ret['server'] = $ret['server_id'];
255)     DEBUG($ret);
256)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 18 years ago

257) }
258) 
259) 
260) function get_aliases($vhost)
261) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

262)     $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost=?", [$vhost]);
263)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

264)     while ($item = $result->fetch()) {
265)         array_push($ret, $item);
266)     }
267)     return $ret;
bernd Aliases editieren

bernd authored 18 years ago

268) }
269) 
270) 
271) 
272) function get_all_aliases($vhost)
273) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

274)     //$vhost = get_vhost_details( (int) $vhost );
275)     $aliases = get_aliases($vhost['id']);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

276)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

277)     if (strstr($vhost['options'], 'aliaswww')) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

278)         array_push($ret, ['id' => 'www', 'fqdn' => 'www.' . $vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : null)]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

279)     }
280)     foreach ($aliases as $item) {
281)         array_push($ret, $item);
282)         if (strstr($item['options'], 'aliaswww')) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

283)             array_push($ret, ['id' => 'www_' . $item['id'], 'fqdn' => 'www.' . $item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : null)]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

284)         }
285)     }
286)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 18 years ago

287) }
288) 
bernd Aliases editieren

bernd authored 18 years ago

289) 
bernd Webapps implementiert

bernd authored 18 years ago

290) function list_available_webapps()
291) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

292)     $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

293)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

294)     while ($item = $result->fetch()) {
295)         array_push($ret, $item);
296)     }
297)     return $ret;
bernd Webapps implementiert

bernd authored 18 years ago

298) }
299) 
300) 
bernd VHosts können bearbeitet we...

bernd authored 18 years ago

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

Hanno authored 8 years ago

303)     $id = (int) $id;
304)     if ($id == 0) {
305)         system_failure("id == 0");
306)     }
307)     $vhost = get_vhost_details($id);
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

308)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #' . $id . ' (' . $vhost['hostname'] . '.' . $vhost['domain'] . ')');
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

309)     db_query("DELETE FROM vhosts.vhost WHERE id=?", [$vhost['id']]);
bernd VHosts können bearbeitet we...

bernd authored 18 years ago

310) }
311) 
bernd Aliases editieren

bernd authored 18 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

316)     $id = (int) $id;
317)     if ($id == 0) {
318)         system_failure("id == 0");
319)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

320)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #' . $id . ' to SVN');
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

321)     db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES (?, 'svn')", [$id]);
322)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", [$id]);
bernd vhost-Modul kann jetzt SVN-...

bernd authored 18 years ago

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

Hanno authored 8 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

327)     $id = (int) $id;
328)     if ($id == 0) {
329)         system_failure("id == 0");
330)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

331)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #' . $id . ' to WebDAV');
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

332)     db_query("REPLACE INTO vhosts.dav (vhost, type, options) VALUES (?, 'dav', 'nouserfile')", [$id]);
333)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", [$id]);
bernd vhost-Modul kann jetzt SVN-...

bernd authored 18 years ago

334) }
335) 
bernd Webapps implementiert

bernd authored 18 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

338)     $id = (int) $id;
339)     if ($id == 0) {
340)         system_failure("id == 0");
341)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

342)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #' . $id . ' to regular');
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

343)     db_query("DELETE FROM vhosts.dav WHERE vhost=?", [$id]);
344)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", [$id]);
bernd vhost-Modul kann jetzt SVN-...

bernd authored 18 years ago

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

Hanno authored 8 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

350)     $id = (int) $id;
351)     $webapp = (int) $webapp;
352)     if ($id == 0) {
353)         system_failure("id == 0");
354)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

355)     $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id=?", [$webapp]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

356)     if ($result->rowCount() == 0) {
357)         system_failure("webapp-id invalid");
358)     }
359)     $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

360)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp ' . $webapp_name . ' on vhost #' . $id);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

361)     db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", [$id, $webapp]);
Hanno Böck Always use send_mail() wrap...

Hanno Böck authored 2 years ago

362)     send_mail('webapps-setup@schokokeks.org', 'setup', 'setup');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 18 years ago

363) }
364) 
365) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 2 years ago

366) function check_hostname_collision($hostname, $domain, $id = null)
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 13 years ago

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

Hanno authored 8 years ago

368)     $uid = (int) $_SESSION['userinfo']['uid'];
369)     # Neuer vhost => Prüfe Duplikat
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

370)     $args = [":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

371)     $domaincheck = "domain=:domain";
372)     if ($domain == -1) {
373)         $userdomain = userdomain();
374)         if ($hostname) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

375)             $hostname .= "." . $_SESSION['userinfo']['username'];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

376)         }
377)         $args[":domain"] = $userdomain['id'];
378)     }
379)     if ($domain == -2) {
380)         unset($args[":domain"]);
381)         $domaincheck = "domain IS NULL";
382)     }
383)     $hostnamecheck = "hostname=:hostname";
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

384)     if (!$hostname) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

385)         $hostnamecheck = "hostname IS NULL";
386)         unset($args[":hostname"]);
387)     }
Bernd Wurst prevent duplicate vhost hos...

Bernd Wurst authored 4 years ago

388)     $idcheck = '';
389)     if ($id) {
390)         $idcheck = ' AND id != :id';
391)         $args[':id'] = (int) $id;
392)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

393)     $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid " . $idcheck, $args);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

394)     if ($result->rowCount() > 0) {
395)         system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
396)     }
397)     if ($domain <= -1) {
398)         return ;
399)     }
400)     unset($args[":uid"]);
Bernd Wurst prevent duplicate vhost hos...

Bernd Wurst authored 4 years ago

401)     unset($args[":id"]);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

402)     $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
403)     if ($result->rowCount() > 0) {
404)         $data = $result->fetch();
405)         $vh = get_vhost_details($data['vhost']);
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

406)         system_failure('Dieser Hostname ist bereits als Alias für »' . $vh['fqdn'] . '« eingerichtet');
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

407)     }
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 13 years ago

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

bernd authored 18 years ago

410) function save_vhost($vhost)
411) {
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

412)     if (!is_array($vhost)) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

413)         system_failure('$vhost kein array!');
414)     }
415)     $id = (int) $vhost['id'];
416)     $hostname = $vhost['hostname'];
417)     $domain = (int) $vhost['domain_id'];
418)     if ($domain == 0) {
419)         system_failure('$domain == 0');
420)     }
421)     if ($vhost['domain_id'] == -2) {
422)         $domain = null;
423)     }
424)     if ($id == 0) {
425)         check_hostname_collision($vhost['hostname'], $vhost['domain_id']);
Bernd Wurst prevent duplicate vhost hos...

Bernd Wurst authored 4 years ago

426)     } else {
427)         check_hostname_collision($vhost['hostname'], $vhost['domain_id'], $id);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

428)     }
429)     $hsts = (int) $vhost['hsts'];
430)     if ($hsts < 0) {
431)         $hsts = null;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 12 years ago

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

Hanno authored 8 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 years ago

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

bernd authored 16 years ago

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

Hanno authored 8 years ago

442)     $server = null;
443)     $available_servers = additional_servers();
444)     if (in_array($vhost['server'], $available_servers)) {
445)         $server = (int) $vhost['server'];
446)     }
447)     if ($server == my_server_id()) {
448)         $server = null;
449)     }
450) 
451)     if ($vhost['is_svn']) {
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

452)         if (!$vhost['options']) {
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 2 years ago

453)             $vhost['options'] = 'nodocroot';
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

454)         } else {
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 2 years ago

455)             $vhost['options'] .= ",nodocroot";
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

456)         }
457)     }
458) 
459)     $cert = null;
460)     $certs = user_certs();
461)     foreach ($certs as $c) {
462)         if ($c['id'] == $vhost['cert']) {
463)             $cert = $c['id'];
464)         }
465)     }
466) 
467)     $ipv4 = null;
468)     $ipv4_avail = user_ipaddrs();
469)     if (in_array($vhost['ipv4'], $ipv4_avail)) {
470)         $ipv4 = $vhost['ipv4'];
471)     }
bernd IPv6

bernd authored 16 years ago

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

Hanno authored 8 years ago

473)     $autoipv6 = 1;
Hanno Böck Remove some unneeded whites...

Hanno Böck authored 2 years ago

474)     if ($vhost['autoipv6'] == 0 || $vhost['autoipv6'] == 2) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

475)         $autoipv6 = $vhost['autoipv6'];
476)     }
bernd IPv6

bernd authored 16 years ago

477) 
Hanno Böck Neuer @PER codingstyle mit...

Hanno Böck authored 10 months ago

478)     if (!($vhost['ssl'] == 'forward' || $vhost['ssl'] == 'http'
479)         || $vhost['ssl'] == 'https')) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

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

Bernd Wurst authored 11 years ago

482) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

483)     $args = [":hostname" => ($hostname ? $hostname : null),
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 2 years ago

484)         ":domain" => $domain,
485)         ":docroot" => ($vhost['docroot'] ? $vhost['docroot'] : null),
486)         ":php" => $vhost['php'],
487)         ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
488)         ":ssl" => $vhost['ssl'],
489)         ":hsts" => $hsts,
490)         ":suexec_user" => $suexec_user,
491)         ":server" => $server,
492)         ":logtype" => ($vhost['logtype'] ? $vhost['logtype'] : null),
493)         ":errorlog" => (int) $vhost['errorlog'],
494)         ":cert" => $cert,
495)         ":ipv4" => $ipv4,
496)         ":autoipv6" => $autoipv6,
497)         ":options" => $vhost['options'],
498)         ":id" => $id, ];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

499)     if ($id != 0) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

500)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #' . $id . ' (' . $vhost['hostname'] . '.' . $vhost['domain'] . ')');
Bernd Wurst Statistik-Funktion entfernt

Bernd Wurst authored 6 years ago

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 WHERE id=:id", $args);
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

502)     } else {
503)         $args[":user"] = $_SESSION['userinfo']['uid'];
504)         unset($args[":id"]);
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

505)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost ' . $vhost['hostname'] . '.' . $vhost['domain'] . '');
Hanno Böck Neuer @PER codingstyle mit...

Hanno Böck authored 10 months ago

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) VALUES "
507)                        . "(:user, :hostname, :domain, :docroot, :php, :cgi, :ssl, :hsts, :suexec_user, :server, :logtype, :errorlog, :cert, :ipv4, :autoipv6, :options)", $args, true);
Hanno Fix coding style with php-c...

Hanno authored 8 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 18 years ago

524) }
525) 
526) 
bernd Aliases editieren

bernd authored 18 years ago

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

Hanno authored 8 years ago

529)     $id = (int) $id;
530)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

531)     $result = db_query("SELECT * FROM vhosts.v_alias WHERE id=?", [$id]);
Hanno remove whitespace in empty...

Hanno authored 8 years ago

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

Hanno authored 8 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 8 years ago

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

Hanno authored 8 years ago

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

Hanno authored 8 years ago

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

Hanno authored 8 years ago

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

bernd authored 18 years ago

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

Hanno authored 8 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 18 years ago

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

Hanno authored 8 years ago

546)     return $alias;
bernd Aliases editieren

bernd authored 18 years ago

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

Hanno authored 8 years ago

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

bernd authored 18 years ago

554) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

555)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Removing alias #' . $id . ' (' . $alias['hostname'] . '.' . $alias['domain'] . ')');
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

556)     db_query("DELETE FROM vhosts.alias WHERE id=?", [$id]);
bernd Aliases editieren

bernd authored 18 years ago

557) }
558) 
559) function save_alias($alias)
560) {
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

561)     if (!is_array($alias)) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

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']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

573)     if (!$alias['hostname']) {
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

574)         $alias['hostname'] = null;
575)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

576)     $args = [":hostname" => $alias['hostname'],
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 2 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 8 years ago

581)     if ($id == 0) {
582)         unset($args[":id"]);
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

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 7 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 8 years ago

585)     } else {
586)         unset($args[":vhost"]);
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

587)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Updating alias #' . $id . ' (' . $alias['hostname'] . '.' . $alias['domain'] . ')');
Hanno optional parameter to not w...

Hanno authored 7 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 8 years ago

589)     }
bernd Aliases editieren

bernd authored 18 years ago

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

bernd authored 18 years ago

592) 
bernd SuExec-Useraccount einstellbar

bernd authored 16 years ago

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

Hanno authored 8 years ago

595)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

596)     $result = db_query("SELECT uid, username FROM vhosts.available_users LEFT JOIN vhosts.v_useraccounts ON (uid = suexec_user) WHERE mainuser=?", [$uid]);
597)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

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 16 years ago

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

bernd authored 18 years ago

605) 
bernd Neue Zertifikatsverwaltung

bernd authored 16 years ago

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

Hanno authored 8 years ago

609)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 4 years ago

610)     $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid=?", [$uid]);
611)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 8 years ago

612)     while ($i = $result->fetch()) {
613)         $ret[] = $i['ipaddr'];
614)     }
615)     DEBUG($ret);
616)     return $ret;