0c8b89b37a5e6f130274744d594a081052113b33
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)   }
203)   $userdomain = userdomain();
204)   if ($ret['domain_id'] == $userdomain['id']) {
205)     $user = $_SESSION['userinfo']['username'];
206)     $ret['domain_id'] = -1;
207)     if ($ret['hostname'] == $user) {
208)       $ret['hostname'] = NULL;
Bernd Wurst count($string) ist falsch!

Bernd Wurst authored 9 years ago

209)     } elseif (substr($ret['hostname'], -strlen($user), strlen($user)) == $user) {
210)       $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

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

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

Bernd Wurst authored 10 years ago

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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

254) 
bernd Webapps implementiert

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

273) }
274) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

295) }
296) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

schokokeks.org GbR authored 10 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 9 years ago

341)   $hostnamecheck = "hostname=:hostname";
342)   if (! $hostname) {
343)     $hostnamecheck = "hostname IS NULL";
344)     unset($args[":hostname"]);
345)   }
346)   $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

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 9 years ago

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

schokokeks.org GbR authored 10 years ago

351)     return ;
352)   }
Bernd Wurst Zeige Userdomains nur noch...

Bernd Wurst authored 9 years ago

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

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

393)   }
394) 
bernd fix für svn/nodocroot

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

396)     if (! $vhost['options']) {
397)       $vhost['options']='nodocroot';
398)     } else {
399)       $vhost['options']+=",nodocroot";
400)     }
bernd nodocroot für svn-hosts

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

403)   $cert = NULL;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

414)   }
bernd IPv6

bernd authored 14 years ago

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

bernd authored 13 years ago

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

bernd authored 14 years ago

420) 
Bernd Wurst Typo korrigiert

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

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

446)   }
447)   else {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

451)     $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 ".
452)                        "(: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

453)     $id = db_insert_id();
bernd Logging

bernd authored 16 years ago

454)   }
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

461)       make_dav_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

463)       make_svn_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

468) }
469) 
470) 
bernd Aliases editieren

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

484)   }
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 9 years ago

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

Bernd Wurst authored 10 years ago

511)     $domain = NULL;
bernd Aliases editieren

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

525)   }
526)   else {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

530)   }
531) }
532) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

533) 
bernd SuExec-Useraccount einstellbar

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

546) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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