fe8d7c2025e33349ab1e51c0e906ec3ee69dcff2
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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

22) 
Hanno codingstyle

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno authored 5 years ago

47)         /* 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

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 3 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

56)     /* Sonderfall: Wenn ein User noch Vhosts einer anderen Version hat, dann bleibt diese erlaubt */
57)     $list = list_vhosts();
58)     foreach ($list as $vhost) {
Bernd Wurst added php version tag "defa...

Bernd Wurst authored 3 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

62)             /* 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

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

75)     $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 5 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno Böck authored 2 years ago

82)     $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 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

89)     $vh = ':1';
90)     if ($mode == 2) {
91)         $vh = implode(':', str_split(sprintf("%08x", $vhost_id), 4));
92)     }
93)     $ipv6 = $prefix . sprintf("%04s", $data['uid']) . ':' . $vh;
94)     return $ipv6;
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

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

Hanno Böck authored 8 months ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 4 years ago

101)     $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 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 4 years ago

104)         $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 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 3 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

155) }
156) 
157) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

175)     $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 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 4 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

210)         $ret .= ' <option value="-2"' . $s . '>' . $_SESSION['userinfo']['username'] . '.' . config('masterdomain') . ' (Bitte nicht mehr benutzen!)</option>';
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

211)         if ($selected > 0 and !$found) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

212)             system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
213)         }
214)     }
215)     $ret .= '</select>';
216)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

226)     $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 5 years ago

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

Hanno Böck authored 8 months ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

277)         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 5 years ago

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

Hanno Böck authored 6 months ago

282)             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 5 years ago

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

bernd authored 16 years ago

286) }
287) 
bernd Aliases editieren

bernd authored 16 years ago

288) 
bernd Webapps implementiert

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

307)     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 2 years ago

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

bernd authored 16 years ago

309) }
310) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno Böck authored 2 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno Böck authored 2 years ago

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

bernd authored 16 years ago

333) }
334) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno Böck authored 2 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

359)     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 2 years ago

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

Hanno Böck authored 2 months ago

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

bernd authored 16 years ago

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

Hanno Böck authored 8 months ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 2 years ago

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

Hanno Böck authored 6 months ago

392)     $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 5 years ago

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

Bernd Wurst authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Hanno Böck authored 8 months ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 8 months ago

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

Hanno authored 5 years ago

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;
Hanno Böck Remove some unneeded whites...

Hanno Böck authored 5 months ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 1 month ago

483)         ":domain" => $domain,
484)         ":docroot" => ($vhost['docroot'] ? $vhost['docroot'] : null),
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,
491)         ":logtype" => ($vhost['logtype'] ? $vhost['logtype'] : null),
492)         ":errorlog" => (int) $vhost['errorlog'],
493)         ":cert" => $cert,
494)         ":ipv4" => $ipv4,
495)         ":autoipv6" => $autoipv6,
496)         ":options" => $vhost['options'],
497)         ":id" => $id, ];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

Bernd Wurst authored 4 years ago

500)         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 5 years ago

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

Hanno Böck authored 6 months ago

504)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost ' . $vhost['hostname'] . '.' . $vhost['domain'] . '');
505)         $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 " .
Bernd Wurst Statistik-Funktion entfernt

Bernd Wurst authored 4 years ago

506)                        "(: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 5 years ago

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

bernd authored 16 years ago

523) }
524) 
525) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

545)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 6 months ago

554)     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 2 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

561)         system_failure('$alias kein array!');
562)     }
563)     $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
564)     $domain = (int) $alias['domain_id'];
565)     if ($domain == 0) {
566)         system_failure('$domain == 0');
567)     }
568)     if ($alias['domain_id'] == -2) {
569)         $domain = null;
570)     }
571)     $vhost = get_vhost_details((int) $alias['vhost']);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 1 month ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

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

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

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

Hanno Böck authored 6 months ago

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

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

588)     }
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

591) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

597)     while ($i = $result->fetch()) {
598)         $ret[] = $i;
599)     }
600)     DEBUG('available suexec-users:');
601)     DEBUG($ret);
602)     return $ret;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

bernd authored 16 years ago

604) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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