9086c9ad77db90633e0629e9e86a88366265ded0
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 12 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

25) 
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

28)     $vhost_id = (int) $vhost_id;
29)     $result = db_query("SELECT sum(mb_in+mb_out) as mb FROM vhosts.traffic where date > CURDATE() - INTERVAL 1 MONTH AND vhost_id = ?", array($vhost_id));
30)     $data = $result->fetch();
31)     return $data['mb'];
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

32) }
33) 
bernd Zusätzlicher Haken für eige...

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno authored 5 years ago

36)     $result = db_query("SELECT uid, v6_prefix FROM vhosts.v_vhost LEFT JOIN system.servers ON (servers.hostname = server) WHERE v_vhost.id=?", array($vhost_id));
37)     $data = $result->fetch();
38)     if (!$data['v6_prefix']) {
39)         warning("IPv6-Adresse nicht verfügbar, Server unterstützt kein IPv6");
40)         return "";
41)     }
42)     list($prefix, $null) = explode('/', $data['v6_prefix']);
43)     $vh = ':1';
44)     if ($mode == 2) {
45)         $vh = implode(':', str_split(sprintf("%08x", $vhost_id), 4));
46)     }
47)     $ipv6 = $prefix . sprintf("%04s", $data['uid']) . ':' . $vh;
48)     return $ipv6;
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

49) }
50) 
51) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

54)     $uid = (int) $_SESSION['userinfo']['uid'];
55)     $query = "SELECT vh.id,fqdn,domain,docroot,docroot_is_default,php,cgi,vh.certid AS cert, vh.ssl, vh.options,logtype,errorlog,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp, stats FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE uid=:uid ORDER BY domain,hostname";
56)     $params = array(":uid" => $uid);
57)     if ($filter) {
58)         $query = "SELECT vh.id,fqdn,domain,docroot,docroot_is_default,php,cgi,vh.certid AS cert, vh.ssl, vh.options,logtype,errorlog,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp, stats FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE (vh.fqdn LIKE :filter OR vh.id IN (SELECT vhost FROM vhosts.v_alias WHERE fqdn LIKE :filter)) AND uid=:uid ORDER BY hostname";
59)         $params[":filter"] = "%$filter%";
60)     }
61)     $result = db_query($query, $params);
62)     $ret = array();
63)     while ($item = $result->fetch()) {
64)         array_push($ret, $item);
65)     }
66)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

67) }
68) 
bernd IPv6-fähigkeit auch richtig...

bernd authored 13 years ago

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

bernd authored 13 years ago

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

Hanno authored 5 years ago

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

bernd authored 13 years ago

76) }
77) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

78) function empty_vhost()
79) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

86)     $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
87)     $vhost['docroot'] = null;
88)     $vhost['php'] = 'fpm72';
89)     $vhost['cgi'] = 1;
90)     $vhost['ssl'] = null;
91)     $vhost['hsts'] = -1;
92)     $vhost['suexec_user'] = null;
93)     $vhost['server'] = null;
94)     $vhost['logtype'] = null;
95)     $vhost['errorlog'] = 0;
96)     $vhost['is_dav'] = 0;
97)     $vhost['is_svn'] = 0;
98)     $vhost['is_webapp'] = 0;
99)     $vhost['webapp_id'] = null;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

101)     $vhost['cert'] = null;
102)     $vhost['certid'] = null;
103)     $vhost['ipv4'] = null;
104)     $vhost['autoipv6'] = 2; // 1 => Eine IP pro User, 2 => Eine IP pro VHost
105) 
106)     $vhost['options'] = 'forwardwww';
107)     $vhost['stats'] = null;
108)     return $vhost;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

109) }
110) 
111) 
bernd Aliases editieren

bernd authored 16 years ago

112) function empty_alias()
113) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

119)     $alias['options'] = null;
120)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

121) }
122) 
123) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

124) function userdomain()
125) {
126)     if (config('user_vhosts_domain') === null) {
127)         return null;
128)     }
129)     $result = db_query("SELECT id,name FROM vhosts.v_domains WHERE name=:dom", array(":dom" => config('user_vhosts_domain')));
130)     $res = $result->fetch();
131)     return $res;
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

132) }
133) 
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

134) function user_uses_userdomain()
135) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

136)     global $config;
137)     $uid = (int) $_SESSION['userinfo']['uid'];
138)     $userdomain = userdomain();
139)     $result = db_query("SELECT id FROM vhosts.vhost WHERE domain=:domid AND user=:uid", array(":uid" => $uid, ":domid" => $userdomain['id']));
140)     if ($result->rowCount() > 0) {
141)         DEBUG("User hat ".$result->rowCount()." Domains *.schokokeks.net");
142)         return true;
143)     }
144)     DEBUG("User hat keine Domains *.schokokeks.net");
145)     return false;
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

150)     global $domainlist, $config;
151)     if ($domainlist == null) {
152)         $domainlist = get_domain_list(
153)         $_SESSION['customerinfo']['customerno'],
154)                                   $_SESSION['userinfo']['uid']
155)     );
156)     }
157)     $selected = (int) $selected;
158) 
159)     $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
160)     $found = false;
161)     foreach ($domainlist as $dom) {
162)         $s = '';
163)         if ($selected == $dom->id) {
164)             $s = ' selected="selected" ';
165)             $found = true;
166)         }
167)         $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
168)     }
169)     $userdomain = userdomain();
170)     $user_needs_userdomain = $userdomain && (count($domainlist) == 0 || user_uses_userdomain());
171)     $user_needs_userdomain = $user_needs_userdomain || ($selected == -2);
172)     if (count($domainlist) > 0 && $user_needs_userdomain) {
173)         $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
174)     }
175)     if ($userdomain && (count($domainlist) == 0 || user_uses_userdomain())) {
176)         $s = ($selected == -1 ? ' selected="selected"' : '');
177)         $ret .= ' <option value="-1"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.$userdomain['name'].'</option>';
178)     }
179)     if ($selected == -2) {
180)         $s = ($selected == -2 ? ' selected="selected"' : '');
181)         $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').' (Bitte nicht mehr benutzen!)</option>';
182)         if ($selected > 0 and ! $found) {
183)             system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
184)         }
185)     }
186)     $ret .= '</select>';
187)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

188) }
189) 
190) 
191) 
192) function get_vhost_details($id)
193) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

194)     DEBUG("Lese #{$id}...");
195)     $id = (int) $id;
196)     $uid = (int) $_SESSION['userinfo']['uid'];
197)     $result = db_query("SELECT vh.*,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE uid=:uid AND vh.id=:id", array(":uid" => $uid, ":id" => $id));
198)     if ($result->rowCount() != 1) {
199)         system_failure('Interner Fehler beim Auslesen der Daten');
200)     }
201) 
202)     $ret = $result->fetch();
203) 
204)     if ($ret['domain_id'] === null) {
205)         $ret['domain_id'] = -2;
206)     }
207)     $ret['cert'] = $ret['certid'];
208)     $userdomain = userdomain();
209)     if ($ret['domain_id'] == $userdomain['id']) {
210)         $user = $_SESSION['userinfo']['username'];
211)         $ret['domain_id'] = -1;
212)         if ($ret['hostname'] == $user) {
213)             $ret['hostname'] = null;
214)         } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
215)             $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user)-1); // Punkt mit entfernen!
216)         } else {
217)             system_failure('Userdomain ohne Username!');
218)         }
219)     }
220)     if ($ret['hsts'] === null) {
221)         DEBUG('HSTS: '.$ret['hsts']);
222)         $ret['hsts'] = -1;
223)     }
224)     $ret['server'] = $ret['server_id'];
225)     DEBUG($ret);
226)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

227) }
228) 
229) 
230) function get_aliases($vhost)
231) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

232)     $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost=?", array($vhost));
233)     $ret = array();
234)     while ($item = $result->fetch()) {
235)         array_push($ret, $item);
236)     }
237)     return $ret;
bernd Aliases editieren

bernd authored 16 years ago

238) }
239) 
240) 
241) 
242) function get_all_aliases($vhost)
243) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

244)     //$vhost = get_vhost_details( (int) $vhost );
245)     $aliases = get_aliases($vhost['id']);
246)     $ret = array();
247)     if (strstr($vhost['options'], 'aliaswww')) {
248)         array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : null)));
249)     }
250)     foreach ($aliases as $item) {
251)         array_push($ret, $item);
252)         if (strstr($item['options'], 'aliaswww')) {
253)             array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : null)));
254)         }
255)     }
256)     return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

257) }
258) 
bernd Aliases editieren

bernd authored 16 years ago

259) 
bernd Webapps implementiert

bernd authored 16 years ago

260) function list_available_webapps()
261) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

262)     $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
263)     $ret = array();
264)     while ($item = $result->fetch()) {
265)         array_push($ret, $item);
266)     }
267)     return $ret;
bernd Webapps implementiert

bernd authored 16 years ago

268) }
269) 
270) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

273)     $id = (int) $id;
274)     if ($id == 0) {
275)         system_failure("id == 0");
276)     }
277)     $vhost = get_vhost_details($id);
278)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
279)     db_query("DELETE FROM vhosts.vhost WHERE id=?", array($vhost['id']));
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

280) }
281) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

286)     $id = (int) $id;
287)     if ($id == 0) {
288)         system_failure("id == 0");
289)     }
290)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to SVN');
291)     db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES (?, 'svn')", array($id));
292)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

293) }
294) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

297)     $id = (int) $id;
298)     if ($id == 0) {
299)         system_failure("id == 0");
300)     }
301)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
302)     db_query("REPLACE INTO vhosts.dav (vhost, type, options) VALUES (?, 'dav', 'nouserfile')", array($id));
303)     db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

304) }
305) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

315) }
316) 
317) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

320)     $id = (int) $id;
321)     $webapp = (int) $webapp;
322)     if ($id == 0) {
323)         system_failure("id == 0");
324)     }
325)     $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id=?", array($webapp));
326)     if ($result->rowCount() == 0) {
327)         system_failure("webapp-id invalid");
328)     }
329)     $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
330)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
331)     db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", array($id, $webapp));
332)     mail('webapps-setup@schokokeks.org', 'setup', 'setup');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

333) }
334) 
335) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 11 years ago

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

Hanno authored 5 years ago

338)     $uid = (int) $_SESSION['userinfo']['uid'];
339)     # Neuer vhost => Prüfe Duplikat
340)     $args = array(":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid);
341)     $domaincheck = "domain=:domain";
342)     if ($domain == -1) {
343)         $userdomain = userdomain();
344)         if ($hostname) {
345)             $hostname .= ".".$_SESSION['userinfo']['username'];
346)         }
347)         $args[":domain"] = $userdomain['id'];
348)     }
349)     if ($domain == -2) {
350)         unset($args[":domain"]);
351)         $domaincheck = "domain IS NULL";
352)     }
353)     $hostnamecheck = "hostname=:hostname";
354)     if (! $hostname) {
355)         $hostnamecheck = "hostname IS NULL";
356)         unset($args[":hostname"]);
357)     }
358)     $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid", $args);
359)     if ($result->rowCount() > 0) {
360)         system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
361)     }
362)     if ($domain <= -1) {
363)         return ;
364)     }
365)     unset($args[":uid"]);
366)     $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
367)     if ($result->rowCount() > 0) {
368)         $data = $result->fetch();
369)         $vh = get_vhost_details($data['vhost']);
370)         system_failure('Dieser Hostname ist bereits als Alias für »'.$vh['fqdn'].'« eingerichtet');
371)     }
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

372) }
373) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

Hanno authored 5 years ago

376)     if (! is_array($vhost)) {
377)         system_failure('$vhost kein array!');
378)     }
379)     $id = (int) $vhost['id'];
380)     $hostname = $vhost['hostname'];
381)     $domain = (int) $vhost['domain_id'];
382)     if ($domain == 0) {
383)         system_failure('$domain == 0');
384)     }
385)     if ($vhost['domain_id'] == -2) {
386)         $domain = null;
387)     }
388)     if ($id == 0) {
389)         check_hostname_collision($vhost['hostname'], $vhost['domain_id']);
390)     }
391)     $hsts = (int) $vhost['hsts'];
392)     if ($hsts < 0) {
393)         $hsts = null;
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

397)     $available_suexec = available_suexec_users();
398)     foreach ($available_suexec as $u) {
399)         if ($u['uid'] == $vhost['suexec_user']) {
400)             $suexec_user = $u['uid'];
401)         }
402)     }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

404)     $server = null;
405)     $available_servers = additional_servers();
406)     if (in_array($vhost['server'], $available_servers)) {
407)         $server = (int) $vhost['server'];
408)     }
409)     if ($server == my_server_id()) {
410)         $server = null;
411)     }
412) 
413)     if ($vhost['is_svn']) {
414)         if (! $vhost['options']) {
415)             $vhost['options']='nodocroot';
416)         } else {
417)             $vhost['options'].=",nodocroot";
418)         }
419)     }
420) 
421)     $cert = null;
422)     $certs = user_certs();
423)     foreach ($certs as $c) {
424)         if ($c['id'] == $vhost['cert']) {
425)             $cert = $c['id'];
426)         }
427)     }
428) 
429)     $ipv4 = null;
430)     $ipv4_avail = user_ipaddrs();
431)     if (in_array($vhost['ipv4'], $ipv4_avail)) {
432)         $ipv4 = $vhost['ipv4'];
433)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

435)     $autoipv6 = 1;
436)     if ($vhost['autoipv6'] == 0 ||  $vhost['autoipv6'] == 2) {
437)         $autoipv6 = $vhost['autoipv6'];
438)     }
bernd IPv6

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 9 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

448)                 ":php" => $vhost['php'],
449)                 ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
450)                 ":ssl" => $vhost['ssl'],
451)                 ":hsts" => $hsts,
452)                 ":suexec_user" => $suexec_user,
453)                 ":server" => $server,
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

455)                 ":errorlog" => (int) $vhost['errorlog'],
456)                 ":cert" => $cert,
457)                 ":ipv4" => $ipv4,
458)                 ":autoipv6" => $autoipv6,
Bernd Wurst $vhost["options"] darf in d...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

462)     if ($id != 0) {
463)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
464)         db_query("UPDATE vhosts.vhost SET hostname=:hostname, domain=:domain, docroot=:docroot, php=:php, cgi=:cgi, `ssl`=:ssl, hsts=:hsts, `suexec_user`=:suexec_user, `server`=:server, logtype=:logtype, errorlog=:errorlog, certid=:cert, ipv4=:ipv4, autoipv6=:autoipv6, options=:options, stats=:stats WHERE id=:id", $args);
465)     } else {
466)         $args[":user"] = $_SESSION['userinfo']['uid'];
467)         unset($args[":id"]);
468)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
469)         $result = db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, cgi, `ssl`, hsts, `suexec_user`, `server`, logtype, errorlog, certid, ipv4, autoipv6, options, stats) VALUES ".
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

471)         $id = db_insert_id();
472)     }
473)     $oldvhost = get_vhost_details($id);
474)     /*
475)       these vars may be 0 or 1.
476)       So newval > oldval means that it has been switched on yet.
477)     */
478)     if ($vhost['is_dav'] > $oldvhost['is_dav']) {
479)         make_dav_vhost($id);
480)     } elseif ($vhost['is_svn'] > $oldvhost['is_svn']) {
481)         make_svn_vhost($id);
482)     } elseif ($vhost['is_webapp'] > $oldvhost['is_webapp']) {
483)         make_webapp_vhost($id, $vhost['webapp_id']);
484)     } elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0) {
485)         make_regular_vhost($id);
486)     }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

487) }
488) 
489) 
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

502)     if ($alias['domain_id'] == null) {
503)         $alias['domain_id'] = -1;
504)     }
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

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

Hanno authored 5 years ago

509)     return $alias;
bernd Aliases editieren

bernd authored 16 years ago

510) }
511) 
512) 
513) function delete_alias($id)
514) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

515)     $id = (int) $id;
516)     $alias = get_alias_details($id);
bernd Aliases editieren

bernd authored 16 years ago

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

Hanno authored 5 years ago

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

bernd authored 16 years ago

520) }
521) 
522) function save_alias($alias)
523) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

524)     if (! is_array($alias)) {
525)         system_failure('$alias kein array!');
526)     }
527)     $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
528)     $domain = (int) $alias['domain_id'];
529)     if ($domain == 0) {
530)         system_failure('$domain == 0');
531)     }
532)     if ($alias['domain_id'] == -2) {
533)         $domain = null;
534)     }
535)     $vhost = get_vhost_details((int) $alias['vhost']);
536)     if (! $alias['hostname']) {
537)         $alias['hostname'] = null;
538)     }
539)     $args = array(":hostname" => $alias['hostname'],
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

540)                 ":domain" => $domain,
541)                 ":vhost" => $vhost['id'],
542)                 ":options" => $alias['options'],
543)                 ":id" => $id);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

544)     if ($id == 0) {
545)         unset($args[":id"]);
546)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
547)         db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES (:hostname, :domain, :vhost, :options)", $args);
548)     } else {
549)         unset($args[":vhost"]);
550)         logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
551)         db_query("UPDATE vhosts.alias SET hostname=:hostname, domain=:domain, options=:options WHERE id=:id", $args);
552)     }
bernd Aliases editieren

bernd authored 16 years ago

553) }
554) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

555) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

556) function available_suexec_users()
557) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

558)     $uid = (int) $_SESSION['userinfo']['uid'];
559)     $result = db_query("SELECT uid, username FROM vhosts.available_users LEFT JOIN vhosts.v_useraccounts ON (uid = suexec_user) WHERE mainuser=?", array($uid));
560)     $ret = array();
561)     while ($i = $result->fetch()) {
562)         $ret[] = $i;
563)     }
564)     DEBUG('available suexec-users:');
565)     DEBUG($ret);
566)     return $ret;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

bernd authored 16 years ago

568) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

569) 
570) function user_ipaddrs()
571) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

572)     $uid = (int) $_SESSION['userinfo']['uid'];
573)     $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid=?", array($uid));
574)     $ret = array();
575)     while ($i = $result->fetch()) {
576)         $ret[] = $i['ipaddr'];
577)     }
578)     DEBUG($ret);
579)     return $ret;