6962c43ce62fb257544a45ed4f04845b04993541
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 Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
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) {
28)   $vhost_id = (int) $vhost_id;
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

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));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

30)   $data = $result->fetch();
Bernd Wurst Traffic-Statistik im Webint...

Bernd Wurst authored 11 years ago

31)   return $data['mb'];
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) {
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 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));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

37)   $data = $result->fetch();
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

38)   if (!$data['v6_prefix'])
39)   {
40)     warning("IPv6-Adresse nicht verfügbar, Server unterstützt kein IPv6");
41)     return "";
42)   }
bernd Prefix-Länge herauslöschen

bernd authored 13 years ago

43)   list($prefix, $null) = explode('/', $data['v6_prefix']);
bernd Zusätzlicher Haken für eige...

bernd authored 13 years ago

44)   $vh = ':1';
45)   if ($mode == 2) {
46)     $vh = implode(':', str_split(sprintf("%08x", $vhost_id), 4));
47)   }
bernd Prefix-Länge herauslöschen

bernd authored 13 years ago

48)   $ipv6 = $prefix . sprintf("%04s", $data['uid']) . ':' . $vh;
bernd IPv6-Regelbetrieb vorbereit...

bernd authored 13 years ago

49)   return $ipv6;
50) }
51) 
52) 
Bernd Wurst Link auf Website / Ermöglic...

Bernd Wurst authored 9 years ago

53) function list_vhosts($domainname=NULL)
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

54) {
55)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Link auf Website / Ermöglic...

Bernd Wurst authored 9 years ago

56)   $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";
57)   $params = array(":uid" => $uid);
58)   if ($domainname) {
59)     $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 domain=:domain AND uid=:uid ORDER BY hostname";
60)     $params[":domain"] = $domainname;
61)   }
62)   $result = db_query($query, $params);
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

63)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

64)   while ($item = $result->fetch())
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

65)     array_push($ret, $item);
66)   return $ret;
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) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

71)   $args = array(":server" => $server);
72)   $result = db_query("SELECT v6_prefix FROM system.servers WHERE id=:server OR hostname=:server", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

73)   $line = $result->fetch();
bernd IPv6-fähigkeit auch richtig...

bernd authored 13 years ago

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) {
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

80)   $vhost['id'] = NULL;
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

81)   $vhost['hostname'] = NULL;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

82)   
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

83)   $vhost['domain_id'] = NULL;
84)   $vhost['domain'] = NULL;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

85)   
86)   $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
87)   $vhost['docroot'] = NULL;
Hanno Böck php 5.6 zum default, php 5....

Hanno Böck authored 9 years ago

88)   $vhost['php'] = 'php56';
bernd CGI abschaltbar

bernd authored 14 years ago

89)   $vhost['cgi'] = 1;
bernd SSL auch über webinterface...

bernd authored 16 years ago

90)   $vhost['ssl'] = NULL;
Bernd Wurst JQuery als Include HSTS-Int...

Bernd Wurst authored 10 years ago

91)   $vhost['hsts'] = -1;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

92)   $vhost['suexec_user'] = NULL;
Bernd Wurst Ermögliche das Auswählen de...

Bernd Wurst authored 11 years ago

93)   $vhost['server'] = NULL;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

94)   $vhost['logtype'] = NULL;
bernd Einige notices (undefined i...

bernd authored 14 years ago

95)   $vhost['errorlog'] = 0;
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

96)   $vhost['is_dav'] = 0;
97)   $vhost['is_svn'] = 0;
98)   $vhost['is_webapp'] = 0;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

99)   $vhost['webapp_id'] = NULL;
100)   
101)   $vhost['cert'] = NULL;
bernd Einige notices (undefined i...

bernd authored 14 years ago

102)   $vhost['certid'] = NULL;
bernd IP-Adressen aktivieren

bernd authored 14 years ago

103)   $vhost['ipv4'] = NULL;
bernd r1864 war Blöd, reverted

bernd authored 13 years ago

104)   $vhost['autoipv6'] = 2; // 1 => Eine IP pro User, 2 => Eine IP pro VHost
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

105) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

106)   $vhost['options'] = '';
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

107)   $vhost['stats'] = NULL;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

108)   return $vhost;
109) }
110) 
111) 
bernd Aliases editieren

bernd authored 16 years ago

112) function empty_alias()
113) {
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

114)   $alias['hostname'] = NULL;
bernd Aliases editieren

bernd authored 16 years ago

115)   
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

116)   $alias['domain_id'] = -1;
bernd Mehr config-optionen und co...

bernd authored 14 years ago

117)   $alias['domain'] = $_SESSION['userinfo']['username'].'.'.config('masterdomain');
bernd Aliases editieren

bernd authored 16 years ago

118)   
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

119)   $alias['options'] = NULL;
bernd Aliases editieren

bernd authored 16 years ago

120)   return $alias;
121) }
122) 
123) 
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

124) function userdomain() {
125)   if (config('user_vhosts_domain') === NULL) {
126)     return NULL;
127)   }
128)   $result = db_query("SELECT id,name FROM vhosts.v_domains WHERE name=:dom", array(":dom" => config('user_vhosts_domain')));
129)   $res = $result->fetch();
130)   return $res;
131) }
132) 
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

133) function user_uses_userdomain()
134) {
135)   global $config;
136)   $uid = (int) $_SESSION['userinfo']['uid'];
137)   $userdomain = userdomain();
138)   $result = db_query("SELECT id FROM vhosts.vhost WHERE domain=:domid AND user=:uid", array(":uid" => $uid, ":domid" => $userdomain['id']));
139)   if ($result->rowCount() > 0) {
140)     DEBUG("User hat ".$result->rowCount()." Domains *.schokokeks.net");
141)     return True;
142)   }
143)   DEBUG("User hat keine Domains *.schokokeks.net");
144)   return false;
145) }
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

146) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

148) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

149)   global $domainlist, $config;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

150)   if ($domainlist == NULL)
151)     $domainlist = get_domain_list($_SESSION['customerinfo']['customerno'],
152)                                   $_SESSION['userinfo']['uid']);
153)   $selected = (int) $selected;
154) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

155)   $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
Bernd Wurst Sperre VHosts gegen Änderun...

Bernd Wurst authored 10 years ago

156)   $found = false;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

157)   foreach ($domainlist as $dom)
158)   {
Bernd Wurst Sperre VHosts gegen Änderun...

Bernd Wurst authored 10 years ago

159)     $s = '';
160)     if ($selected == $dom->id) {
161)       $s = ' selected="selected" ';
162)       $found = true;
163)     }
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

164)     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
165)   }
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

166)   $userdomain = userdomain();
167)   $user_needs_userdomain = $userdomain && (count($domainlist) == 0 || user_uses_userdomain());
168)   $user_needs_userdomain = $user_needs_userdomain || ($selected == -2);
169)   if (count($domainlist) > 0 && $user_needs_userdomain) {
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

170)     $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
171)   }
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

172)   if ($userdomain && (count($domainlist) == 0 || user_uses_userdomain())) {
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

173)     $s = ($selected == -1 ? ' selected="selected"' : '');
174)     $ret .= ' <option value="-1"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.$userdomain['name'].'</option>';
175)   }
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

176)   if ($selected == -2) {
177)     $s = ($selected == -2 ? ' selected="selected"' : '');
178)     $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').' (Bitte nicht mehr benutzen!)</option>';
179)     if ($selected > 0 and ! $found) {
180)       system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
181)     }
Bernd Wurst Sperre VHosts gegen Änderun...

Bernd Wurst authored 10 years ago

182)   }
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

183)   $ret .= '</select>';
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

184)   return $ret;
185) }
186) 
187) 
188) 
189) function get_vhost_details($id)
190) {
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

191)   DEBUG("Lese #{$id}...");
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

192)   $id = (int) $id;
193)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

194)   $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));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

195)   if ($result->rowCount() != 1)
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

196)     system_failure('Interner Fehler beim Auslesen der Daten');
197) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

198)   $ret = $result->fetch();
Bernd Wurst bugfix: server vorausgewählt

Bernd Wurst authored 11 years ago

199) 
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

200)   if ($ret['domain_id'] === NULL) {
201)     $ret['domain_id'] = -2;
202)   }
Bernd Wurst Lege certid im Feld cert ab...

Bernd Wurst authored 8 years ago

203)   $ret['cert'] = $ret['certid'];
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

204)   $userdomain = userdomain();
205)   if ($ret['domain_id'] == $userdomain['id']) {
206)     $user = $_SESSION['userinfo']['username'];
207)     $ret['domain_id'] = -1;
208)     if ($ret['hostname'] == $user) {
209)       $ret['hostname'] = NULL;
Bernd Wurst count($string) ist falsch!

Bernd Wurst authored 9 years ago

210)     } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
211)       $ret['hostname'] = substr($ret['hostname'], 0, -strlen($user)-1); // Punkt mit entfernen!
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

212)     } else {
213)       system_failure('Userdomain ohne Username!');
214)     }
215)   }
Bernd Wurst JQuery als Include HSTS-Int...

Bernd Wurst authored 10 years ago

216)   if ($ret['hsts'] === NULL) {
217)     DEBUG('HSTS: '.$ret['hsts']);
218)     $ret['hsts'] = -1;
219)   }
Bernd Wurst bugfix: server vorausgewählt

Bernd Wurst authored 11 years ago

220)   $ret['server'] = $ret['server_id'];
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

221)   DEBUG($ret);
222)   return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

223) }
224) 
225) 
226) function get_aliases($vhost)
227) {
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

228)   $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost=?", array($vhost));
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

229)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

230)   while ($item = $result->fetch()) {
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

231)     array_push($ret, $item);
bernd Aliases editieren

bernd authored 16 years ago

232)   }
233)   return $ret;
234) }
235) 
236) 
237) 
238) function get_all_aliases($vhost)
239) {
bernd Weniger Datenbankzugriffe b...

bernd authored 14 years ago

240)   //$vhost = get_vhost_details( (int) $vhost );
bernd Aliases editieren

bernd authored 16 years ago

241)   $aliases = get_aliases($vhost['id']);
242)   $ret = array();
243)   if (strstr($vhost['options'], 'aliaswww')) {
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

244)     array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : NULL)));
bernd Aliases editieren

bernd authored 16 years ago

245)   }
246)   foreach ($aliases as $item) {
247)     array_push($ret, $item);
248)     if (strstr($item['options'], 'aliaswww')) {
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

249)       array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : NULL)));
bernd Aliases editieren

bernd authored 16 years ago

250)     }
251)   }
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

252)   return $ret;
253) }
254) 
bernd Aliases editieren

bernd authored 16 years ago

255) 
bernd Webapps implementiert

bernd authored 16 years ago

256) function list_available_webapps()
257) {
258)   $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
259)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

260)   while ($item = $result->fetch())
bernd Webapps implementiert

bernd authored 16 years ago

261)     array_push($ret, $item);
262)   return $ret;
263) }
264) 
265) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

266) function delete_vhost($id)
267) {
268)   $id = (int) $id;
269)   if ($id == 0)
270)     system_failure("id == 0");
271)   $vhost = get_vhost_details($id);
bernd Logger mit Logleveln

bernd authored 14 years ago

272)   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

274) }
275) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

277) 
278) function make_svn_vhost($id) 
279) {
280)   $id = (int) $id;
281)   if ($id == 0)
282)     system_failure("id == 0");
bernd Logger mit Logleveln

bernd authored 14 years ago

283)   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to SVN');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

286) }
287) 
288) function make_dav_vhost($id) 
289) {
290)   $id = (int) $id;
291)   if ($id == 0)
292)     system_failure("id == 0");
bernd Logger mit Logleveln

bernd authored 14 years ago

293)   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

296) }
297) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

299) {
300)   $id = (int) $id;
301)   if ($id == 0)
302)     system_failure("id == 0");
bernd Logger mit Logleveln

bernd authored 14 years ago

303)   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to regular');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

304)   db_query("DELETE FROM vhosts.dav WHERE vhost=?", array($id));
305)   db_query("DELETE FROM vhosts.webapps WHERE vhost=?", array($id));
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

306) }
307) 
308) 
309) function make_webapp_vhost($id, $webapp) 
310) {
311)   $id = (int) $id;
312)   $webapp = (int) $webapp;
313)   if ($id == 0)
314)     system_failure("id == 0");
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

315)   $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id=?", array($webapp));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

316)   if ($result->rowCount() == 0)
bernd Webapps implementiert

bernd authored 16 years ago

317)     system_failure("webapp-id invalid");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

318)   $webapp_name = $result->fetch(PDO::FETCH_OBJ)->displayname;
bernd Logger mit Logleveln

bernd authored 14 years ago

319)   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

320)   db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES (?, ?)", array($id, $webapp));
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

322) }
323) 
324) 
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

325) function check_hostname_collision($hostname, $domain) 
326) {
schokokeks.org GbR Kollisions-Check für VHosts...

schokokeks.org GbR authored 10 years ago

327)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

328)   # Neuer vhost => Prüfe Duplikat
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

329)   $args = array(":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid);
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

330)   $domaincheck = "domain=:domain";
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

331)   if ($domain == -1) {
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

332)     $userdomain = userdomain();
333)     if ($hostname) {
334)       $hostname .= ".".$_SESSION['userinfo']['username'];
335)     }
336)     $args[":domain"] = $userdomain['id'];
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

337)   }
338)   if ($domain == -2) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

339)     unset($args[":domain"]);
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

340)     $domaincheck = "domain IS NULL";
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

341)   }
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

342)   $hostnamecheck = "hostname=:hostname";
343)   if (! $hostname) {
344)     $hostnamecheck = "hostname IS NULL";
345)     unset($args[":hostname"]);
346)   }
347)   $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

348)   if ($result->rowCount() > 0) {
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

349)     system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
350)   }
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

351)   if ($domain <= -1) {
schokokeks.org GbR Kollisions-Check für VHosts...

schokokeks.org GbR authored 10 years ago

352)     return ;
353)   }
Bernd Wurst Überflüssiger Query-Paramet...

Bernd Wurst authored 9 years ago

354)   unset($args[":uid"]);
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

355)   $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

356)   if ($result->rowCount() > 0) {
357)     $data = $result->fetch();
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

358)     $vh = get_vhost_details($data['vhost']);
359)     system_failure('Dieser Hostname ist bereits als Alias für »'.$vh['fqdn'].'« eingerichtet');
360)   }
361) }
362) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

363) function save_vhost($vhost)
364) {
365)   if (! is_array($vhost))
366)     system_failure('$vhost kein array!');
367)   $id = (int) $vhost['id'];
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

368)   $hostname = $vhost['hostname'];
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

369)   $domain = (int) $vhost['domain_id'];
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

370)   if ($domain == 0)
bernd Aliases editieren

bernd authored 16 years ago

371)     system_failure('$domain == 0');
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

372)   if ($vhost['domain_id'] == -2)
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

373)     $domain = NULL;
Bernd Wurst Sperre das Eintragen doppel...

Bernd Wurst authored 11 years ago

374)   if ($id == 0) {
Bernd Wurst Kollissionsprüfung auf Alia...

Bernd Wurst authored 11 years ago

375)     check_hostname_collision($vhost['hostname'], $vhost['domain_id']);
Bernd Wurst Sperre das Eintragen doppel...

Bernd Wurst authored 11 years ago

376)   }
Bernd Wurst JQuery als Include HSTS-Int...

Bernd Wurst authored 10 years ago

377)   $hsts = (int) $vhost['hsts'];
378)   if ($hsts < 0) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

379)     $hsts = NULL;
Bernd Wurst JQuery als Include HSTS-Int...

Bernd Wurst authored 10 years ago

380)   }
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

381)   $suexec_user = NULL;
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

382) 
383)   $available_suexec = available_suexec_users();
384)   foreach ($available_suexec AS $u)
385)     if ($u['uid'] == $vhost['suexec_user'])
386)       $suexec_user = $u['uid'];
387) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

388)   $server = NULL;
Bernd Wurst Ermögliche das Auswählen de...

Bernd Wurst authored 11 years ago

389)   $available_servers = additional_servers();
390)   if (in_array($vhost['server'], $available_servers)) {
391)     $server = (int) $vhost['server'];
392)   }
393)   if ($server == my_server_id()) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

394)     $server = NULL;
Bernd Wurst Ermögliche das Auswählen de...

Bernd Wurst authored 11 years ago

395)   }
396) 
bernd fix für svn/nodocroot

bernd authored 16 years ago

397)   if ($vhost['is_svn']) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

398)     if (! $vhost['options']) {
399)       $vhost['options']='nodocroot';
400)     } else {
Bernd Wurst Typo

Bernd Wurst authored 8 years ago

401)       $vhost['options'].=",nodocroot";
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

402)     }
bernd nodocroot für svn-hosts

bernd authored 16 years ago

403)   }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

404) 
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

405)   $cert = NULL;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

406)   $certs = user_certs();
407)   foreach ($certs as $c)
408)     if ($c['id'] == $vhost['cert'])
409)       $cert = $c['id'];
410) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

411)   $ipv4 = NULL;
bernd IP-Adressen aktivieren

bernd authored 14 years ago

412)   $ipv4_avail = user_ipaddrs();
413)   if (in_array($vhost['ipv4'], $ipv4_avail))
414)   {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

415)     $ipv4 = $vhost['ipv4'];
bernd IP-Adressen aktivieren

bernd authored 14 years ago

416)   }
bernd IPv6

bernd authored 14 years ago

417) 
bernd Zusätzlicher Haken für eige...

bernd authored 13 years ago

418)   $autoipv6 = 1;
419)   if ($vhost['autoipv6'] == 0 ||  $vhost['autoipv6'] == 2) {
420)     $autoipv6 = $vhost['autoipv6'];
421)   }
bernd IPv6

bernd authored 14 years ago

422) 
Bernd Wurst Typo korrigiert

Bernd Wurst authored 9 years ago

423)   if (!($vhost['ssl'] == 'forward' || $vhost['ssl'] == 'http' ||
424)         $vhost['ssl'] == 'https')) {
Bernd Wurst Setze SSL-Option beim erste...

Bernd Wurst authored 9 years ago

425)     $vhost['ssl'] = NULL;
426)   }
427) 
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

429)                 ":domain" => $domain,
Bernd Wurst Setze SSL-Option beim erste...

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 10 years ago

431)                 ":php" => $vhost['php'],
432)                 ":cgi" => ($vhost['cgi'] == 1 ? 1 : 0),
433)                 ":ssl" => $vhost['ssl'],
434)                 ":hsts" => $hsts,
435)                 ":suexec_user" => $suexec_user,
436)                 ":server" => $server,
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

438)                 ":errorlog" => (int) $vhost['errorlog'],
439)                 ":cert" => $cert,
440)                 ":ipv4" => $ipv4,
441)                 ":autoipv6" => $autoipv6,
Bernd Wurst $vhost["options"] darf in d...

Bernd Wurst authored 10 years ago

442)                 ":options" => $vhost['options'],
Bernd Wurst Bugfix: Werte dürfen nicht...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

444)                 ":id" => $id);
bernd Logging

bernd authored 16 years ago

445)   if ($id != 0) {
bernd Logger mit Logleveln

bernd authored 14 years ago

446)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

447)     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);
bernd Logging

bernd authored 16 years ago

448)   }
449)   else {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

450)     $args[":user"] = $_SESSION['userinfo']['uid'];
451)     unset($args[":id"]);
bernd Logger mit Logleveln

bernd authored 14 years ago

452)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

453)     $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 ".
454)                        "(:user, :hostname, :domain, :docroot, :php, :cgi, :ssl, :hsts, :suexec_user, :server, :logtype, :errorlog, :cert, :ipv4, :autoipv6, :options, :stats)", $args);
Bernd Wurst Warnung im dev-branch bzgl....

Bernd Wurst authored 10 years ago

455)     $id = db_insert_id();
bernd Logging

bernd authored 16 years ago

456)   }
bernd Webapps implementiert

bernd authored 16 years ago

457)   $oldvhost = get_vhost_details($id);
458)   /*
459)     these vars may be 0 or 1.
460)     So newval > oldval means that it has been switched on yet.
461)   */
462)   if ($vhost['is_dav'] > $oldvhost['is_dav'])
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

463)       make_dav_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

464)   elseif ($vhost['is_svn'] > $oldvhost['is_svn'])
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

465)       make_svn_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

466)   elseif ($vhost['is_webapp'] > $oldvhost['is_webapp'])
467)       make_webapp_vhost($id, $vhost['webapp_id']);
468)   elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0)
469)       make_regular_vhost($id);
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

470) }
471) 
472) 
bernd Aliases editieren

bernd authored 16 years ago

473) function get_alias_details($id)
474) {
475)   $id = (int) $id;
476)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

477)   $result = db_query("SELECT * FROM vhosts.v_alias WHERE id=?", array($id));
bernd Aliases editieren

bernd authored 16 years ago

478)   
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

479)   if ($result->rowCount() != 1)
bernd Aliases editieren

bernd authored 16 years ago

480)     system_failure('Interner Fehler beim Auslesen der Alias-Daten');
481)   
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

482)   $alias = $result->fetch();
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

483)   
bernd auch aliases dürfen usernam...

bernd authored 16 years ago

484)   if ($alias['domain_id'] == NULL) {
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

485)     $alias['domain_id'] = -1;
bernd auch aliases dürfen usernam...

bernd authored 16 years ago

486)   }
bernd Aliases editieren

bernd authored 16 years ago

487) 
488)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
489)   get_vhost_details( (int) $alias['vhost'] );
490) 
491)   return $alias;
492) }
493) 
494) 
495) function delete_alias($id)
496) {
497)   $id = (int) $id;
498)   $alias = get_alias_details($id);
499) 
bernd Logger mit Logleveln

bernd authored 14 years ago

500)   logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

501)   db_query("DELETE FROM vhosts.alias WHERE id=?", array($id));
bernd Aliases editieren

bernd authored 16 years ago

502) }
503) 
504) function save_alias($alias)
505) {
506)   if (! is_array($alias))
507)     system_failure('$alias kein array!');
bernd Neue aliase haben keine ID

bernd authored 14 years ago

508)   $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

509)   $domain = (int) $alias['domain_id'];
bernd Aliases editieren

bernd authored 16 years ago

510)   if ($domain == 0)
511)     system_failure('$domain == 0');
Bernd Wurst Ermögliche dem user Hosts m...

Bernd Wurst authored 9 years ago

512)   if ($alias['domain_id'] == -2)
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

513)     $domain = NULL;
bernd Aliases editieren

bernd authored 16 years ago

514)   $vhost = get_vhost_details( (int) $alias['vhost']);
Bernd Wurst Bei Aliasnamen darf kein le...

Bernd Wurst authored 10 years ago

515)   if (! $alias['hostname']) {
516)     $alias['hostname'] = NULL;
517)   }
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

518)   $args = array(":hostname" => $alias['hostname'],
519)                 ":domain" => $domain,
520)                 ":vhost" => $vhost['id'],
521)                 ":options" => $alias['options'],
522)                 ":id" => $id);
bernd Aliases editieren

bernd authored 16 years ago

523)   if ($id == 0) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

524)     unset($args[":id"]);
bernd Logger mit Logleveln

bernd authored 14 years ago

525)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

526)     db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES (:hostname, :domain, :vhost, :options)", $args);
bernd Aliases editieren

bernd authored 16 years ago

527)   }
528)   else {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

529)     unset($args[":vhost"]);
bernd Logger mit Logleveln

bernd authored 14 years ago

530)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

531)     db_query("UPDATE vhosts.alias SET hostname=:hostname, domain=:domain, options=:options WHERE id=:id", $args);
bernd Aliases editieren

bernd authored 16 years ago

532)   }
533) }
534) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

535) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

536) function available_suexec_users()
537) {
538)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

539)   $result = db_query("SELECT uid, username FROM vhosts.available_users LEFT JOIN vhosts.v_useraccounts ON (uid = suexec_user) WHERE mainuser=?", array($uid));
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

540)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

541)   while ($i = $result->fetch())
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

542)     $ret[] = $i;
543)   DEBUG('available suexec-users:');
544)   DEBUG($ret);
545)   return $ret;
546) 
547) }
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

548) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

549) 
550) function user_ipaddrs()
551) {
552)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

553)   $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid=?", array($uid));
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

554)   $ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

555)   while ($i = $result->fetch())
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

556)   {
557)     $ret[] = $i['ipaddr'];
558)   }
559)   DEBUG($ret);
560)   return $ret;
561) }
562) 
563)