96649f21ba18d07757afa9d98998f7a22c0d86a3
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

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

bernd authored 14 years ago

23) require_once("certs.php");
24) 
bernd Aliases editieren

bernd authored 16 years ago

25) 
Hanno codingstyle

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 3 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 3 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

78)     $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

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

Bernd Wurst authored 11 years ago

81) }
82) 
bernd Zusätzlicher Haken für eige...

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno Böck authored 2 years ago

85)     $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

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

98) }
99) 
100) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

103)     $uid = (int) $_SESSION['userinfo']['uid'];
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 uid=:uid ORDER BY domain,hostname";
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 4 years ago

107)         $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

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

116) }
117) 
bernd IPv6-fähigkeit auch richtig...

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

125) }
126) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

127) function empty_vhost()
128) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

129)     $vhost['id'] = null;
130)     $vhost['hostname'] = 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['domain_id'] = null;
133)     $vhost['domain'] = null;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 3 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

158) }
159) 
160) 
bernd Aliases editieren

bernd authored 16 years ago

161) function empty_alias()
162) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

163)     $alias['hostname'] = null;
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['domain_id'] = -1;
166)     $alias['domain'] = $_SESSION['userinfo']['username'].'.'.config('masterdomain');
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

168)     $alias['options'] = null;
169)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

170) }
171) 
172) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

178)     $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

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

Bernd Wurst authored 9 years ago

181) }
182) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 4 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

229)     $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

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

bernd authored 16 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

279)     if (strstr($vhost['options'], 'aliaswww')) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

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

281)     }
282)     foreach ($aliases as $item) {
283)         array_push($ret, $item);
284)         if (strstr($item['options'], 'aliaswww')) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

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

286)         }
287)     }
288)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

289) }
290) 
bernd Aliases editieren

bernd authored 16 years ago

291) 
bernd Webapps implementiert

bernd authored 16 years ago

292) function list_available_webapps()
293) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

300) }
301) 
302) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

305)     $id = (int) $id;
306)     if ($id == 0) {
307)         system_failure("id == 0");
308)     }
309)     $vhost = get_vhost_details($id);
310)     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

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

bernd authored 16 years ago

312) }
313) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

318)     $id = (int) $id;
319)     if ($id == 0) {
320)         system_failure("id == 0");
321)     }
322)     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

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

bernd authored 16 years ago

325) }
326) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

329)     $id = (int) $id;
330)     if ($id == 0) {
331)         system_failure("id == 0");
332)     }
333)     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

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

bernd authored 16 years ago

336) }
337) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

340)     $id = (int) $id;
341)     if ($id == 0) {
342)         system_failure("id == 0");
343)     }
344)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to regular');
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

358)     if ($result->rowCount() == 0) {
359)         system_failure("webapp-id invalid");
360)     }
361)     $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
362)     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

363)     db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", [$id, $webapp]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

365) }
366) 
367) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

404) }
405) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

429)     $available_suexec = available_suexec_users();
430)     foreach ($available_suexec as $u) {
431)         if ($u['uid'] == $vhost['suexec_user']) {
432)             $suexec_user = $u['uid'];
433)         }
434)     }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

467)     $autoipv6 = 1;
468)     if ($vhost['autoipv6'] == 0 ||  $vhost['autoipv6'] == 2) {
469)         $autoipv6 = $vhost['autoipv6'];
470)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

480)                 ":php" => $vhost['php'],
481)                 ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
482)                 ":ssl" => $vhost['ssl'],
483)                 ":hsts" => $hsts,
484)                 ":suexec_user" => $suexec_user,
485)                 ":server" => $server,
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

487)                 ":errorlog" => (int) $vhost['errorlog'],
488)                 ":cert" => $cert,
489)                 ":ipv4" => $ipv4,
490)                 ":autoipv6" => $autoipv6,
Bernd Wurst $vhost["options"] darf in d...

Bernd Wurst authored 10 years ago

491)                 ":options" => $vhost['options'],
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

493)     if ($id != 0) {
494)         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

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

496)     } else {
497)         $args[":user"] = $_SESSION['userinfo']['uid'];
498)         unset($args[":id"]);
499)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
Bernd Wurst Statistik-Funktion entfernt

Bernd Wurst authored 4 years ago

500)         $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 ".
501)                        "(: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

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

bernd authored 16 years ago

518) }
519) 
520) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

533)     if ($alias['domain_id'] == null) {
534)         $alias['domain_id'] = -1;
535)     }
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

540)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

541) }
542) 
543) 
544) function delete_alias($id)
545) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

546)     $id = (int) $id;
547)     $alias = get_alias_details($id);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

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

bernd authored 16 years ago

551) }
552) 
553) function save_alias($alias)
554) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

555)     if (! is_array($alias)) {
556)         system_failure('$alias kein array!');
557)     }
558)     $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
559)     $domain = (int) $alias['domain_id'];
560)     if ($domain == 0) {
561)         system_failure('$domain == 0');
562)     }
563)     if ($alias['domain_id'] == -2) {
564)         $domain = null;
565)     }
566)     $vhost = get_vhost_details((int) $alias['vhost']);
567)     if (! $alias['hostname']) {
568)         $alias['hostname'] = null;
569)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

570)     $args = [":hostname" => $alias['hostname'],
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

571)                 ":domain" => $domain,
572)                 ":vhost" => $vhost['id'],
573)                 ":options" => $alias['options'],
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

575)     if ($id == 0) {
576)         unset($args[":id"]);
577)         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

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

579)     } else {
580)         unset($args[":vhost"]);
581)         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

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

583)     }
bernd Aliases editieren

bernd authored 16 years ago

584) }
585) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

586) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

587) function available_suexec_users()
588) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

592)     while ($i = $result->fetch()) {
593)         $ret[] = $i;
594)     }
595)     DEBUG('available suexec-users:');
596)     DEBUG($ret);
597)     return $ret;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

bernd authored 16 years ago

599) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

600) 
601) function user_ipaddrs()
602) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 5 years ago

606)     while ($i = $result->fetch()) {
607)         $ret[] = $i['ipaddr'];
608)     }
609)     DEBUG($ret);
610)     return $ret;