b314bdc8d3104d26240fcaf27b25525c1fb8d170
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

1) <?php
2) 
3) require_once("inc/base.php");
4) require_once("inc/error.php");
5) require_once("inc/security.php");
6) 
7) require_once('class/domain.php');
8) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

9) require_once("certs.php");
10) 
bernd Aliases editieren

bernd authored 16 years ago

11) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

12) function list_vhosts()
13) {
14)   $uid = (int) $_SESSION['userinfo']['uid'];
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

15)   $result = db_query("SELECT vh.id,fqdn,docroot,docroot_is_default,php,vh.certid AS cert, vh.ssl, vh.options,logtype,errorlog,IF(dav.id IS NULL OR dav.type='svn', 0, 1) AS is_dav,IF(dav.id IS NULL OR dav.type='dav', 0, 1) AS is_svn, IF(webapps.id IS NULL, 0, 1) AS is_webapp FROM vhosts.v_vhost AS vh LEFT JOIN vhosts.dav ON (dav.vhost=vh.id) LEFT JOIN vhosts.webapps ON (webapps.vhost = vh.id) WHERE uid={$uid} ORDER BY domain,hostname");
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

16)   $ret = array();
17)   while ($item = mysql_fetch_assoc($result))
18)     array_push($ret, $item);
19)   return $ret;
20) }
21) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

22) function empty_vhost()
23) {
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

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

bernd authored 16 years ago

25)   $vhost['hostname'] = '';
26)   
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 14 years ago

28)   $vhost['domain'] = $_SESSION['userinfo']['username'].'.'.config('masterdomain');
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

29)   
30)   $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
31)   $vhost['docroot'] = NULL;
bernd fcgi ist jetzt default

bernd authored 16 years ago

32)   $vhost['php'] = 'fastcgi';
bernd SSL auch über webinterface...

bernd authored 16 years ago

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

bernd authored 16 years ago

34)   $vhost['logtype'] = NULL;
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

35)   $vhost['is_dav'] = 0;
36)   $vhost['is_svn'] = 0;
37)   $vhost['is_webapp'] = 0;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

38)   $vhost['webapp_id'] = NULL;
39)   
40)   $vhost['cert'] = NULL;
bernd IP-Adressen aktivieren

bernd authored 14 years ago

41)   $vhost['ipv4'] = NULL;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 16 years ago

43)   $vhost['options'] = '';
44)   return $vhost;
45) }
46) 
47) 
bernd Aliases editieren

bernd authored 16 years ago

48) function empty_alias()
49) {
50)   $alias['hostname'] = '';
51)   
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

54)   
55)   $alias['options'] = '';
56)   return $alias;
57) }
58) 
59) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

63)   if ($domainlist == NULL)
64)     $domainlist = get_domain_list($_SESSION['customerinfo']['customerno'],
65)                                   $_SESSION['userinfo']['uid']);
66)   $selected = (int) $selected;
67) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

68)   $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
bernd Mehr config-optionen und co...

bernd authored 14 years ago

69)   $ret .= ' <option value="-1">'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').'</option>';
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

70)   $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

71)   foreach ($domainlist as $dom)
72)   {
bernd Aliases editieren

bernd authored 16 years ago

73)     $s = ($selected == $dom->id) ? ' selected="selected" ': '';
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

74)     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
75)   }
76)   $ret .= '</select>';
77)   return $ret;
78) }
79) 
80) 
81) 
82) function get_vhost_details($id)
83) {
84)   $id = (int) $id;
85)   $uid = (int) $_SESSION['userinfo']['uid'];
bernd VHosts-Modul mit neuem Layo...

bernd authored 16 years ago

86)   $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}");
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

87)   if (mysql_num_rows($result) != 1)
88)     system_failure('Interner Fehler beim Auslesen der Daten');
89) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

90)   $ret = mysql_fetch_assoc($result);
91)   DEBUG($ret);
92)   return $ret;
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

93) }
94) 
95) 
96) function get_aliases($vhost)
97) {
98)   $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost={$vhost}");
99)   $ret = array();
bernd Aliases editieren

bernd authored 16 years ago

100)   while ($item = mysql_fetch_assoc($result)) {
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

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

bernd authored 16 years ago

102)   }
103)   return $ret;
104) }
105) 
106) 
107) 
108) function get_all_aliases($vhost)
109) {
110)   $vhost = get_vhost_details( (int) $vhost );
111)   $aliases = get_aliases($vhost['id']);
112)   $ret = array();
113)   if (strstr($vhost['options'], 'aliaswww')) {
114)     array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : '')));
115)   }
116)   foreach ($aliases as $item) {
117)     array_push($ret, $item);
118)     if (strstr($item['options'], 'aliaswww')) {
119)       array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : '')));
120)     }
121)   }
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

122)   return $ret;
123) }
124) 
bernd Aliases editieren

bernd authored 16 years ago

125) 
bernd Webapps implementiert

bernd authored 16 years ago

126) function list_available_webapps()
127) {
128)   $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
129)   $ret = array();
130)   while ($item = mysql_fetch_assoc($result))
131)     array_push($ret, $item);
132)   return $ret;
133) }
134) 
135) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

136) function delete_vhost($id)
137) {
138)   $id = (int) $id;
139)   if ($id == 0)
140)     system_failure("id == 0");
141)   $vhost = get_vhost_details($id);
bernd eliminate .php extensions f...

bernd authored 15 years ago

142)   logger('modules/vhosts/include/vhosts', 'vhosts', 'Removing vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

143)   db_query("DELETE FROM vhosts.vhost WHERE id={$vhost['id']} LIMIT 1");
144) }
145) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

147) 
148) function make_svn_vhost($id) 
149) {
150)   $id = (int) $id;
151)   if ($id == 0)
152)     system_failure("id == 0");
bernd eliminate .php extensions f...

bernd authored 15 years ago

153)   logger('modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to SVN');
bernd letzter commit rückgängig

bernd authored 16 years ago

154)   db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES ({$id}, 'svn')");
bernd Webapps implementiert

bernd authored 16 years ago

155)   db_query("DELETE FROM vhosts.webapps WHERE vhost={$id}");
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

156) }
157) 
158) function make_dav_vhost($id) 
159) {
160)   $id = (int) $id;
161)   if ($id == 0)
162)     system_failure("id == 0");
bernd eliminate .php extensions f...

bernd authored 15 years ago

163)   logger('modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
bernd Docroot auch bei WebDAV anz...

bernd authored 16 years ago

164)   db_query("REPLACE INTO vhosts.dav (vhost, type, options) VALUES ({$id}, 'dav', 'nouserfile')");
bernd Webapps implementiert

bernd authored 16 years ago

165)   db_query("DELETE FROM vhosts.webapps WHERE vhost={$id}");
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

166) }
167) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

169) {
170)   $id = (int) $id;
171)   if ($id == 0)
172)     system_failure("id == 0");
bernd eliminate .php extensions f...

bernd authored 15 years ago

173)   logger('modules/vhosts/include/vhosts', 'vhosts', 'Converting vhost #'.$id.' to regular');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

174)   db_query("DELETE FROM vhosts.dav WHERE vhost={$id}");
bernd Webapps implementiert

bernd authored 16 years ago

175)   db_query("DELETE FROM vhosts.webapps WHERE vhost={$id}");
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

176) }
177) 
178) 
179) function make_webapp_vhost($id, $webapp) 
180) {
181)   $id = (int) $id;
182)   $webapp = (int) $webapp;
183)   if ($id == 0)
184)     system_failure("id == 0");
bernd Webapps implementiert

bernd authored 16 years ago

185)   $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id={$webapp};");
186)   if (mysql_num_rows($result) == 0)
187)     system_failure("webapp-id invalid");
188)   $webapp_name = mysql_fetch_object($result)->displayname;
bernd eliminate .php extensions f...

bernd authored 15 years ago

189)   logger('modules/vhosts/include/vhosts', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
bernd Webapps implementiert

bernd authored 16 years ago

190)   db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES ({$id}, {$webapp})");
191)   mail('webapps-setup@schokokeks.org', 'setup', 'setup');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

192) }
193) 
194) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

195) function save_vhost($vhost)
196) {
197)   if (! is_array($vhost))
198)     system_failure('$vhost kein array!');
199)   $id = (int) $vhost['id'];
200)   $hostname = maybe_null($vhost['hostname']);
201)   $domain = (int) $vhost['domainid'];
202)   if ($domain == 0)
bernd Aliases editieren

bernd authored 16 years ago

203)     system_failure('$domain == 0');
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

204)   if ($vhost['domainid'] == -1)
205)     $domain = 'NULL';
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

206)   $docroot = maybe_null($vhost['docroot']);
207)   $php = maybe_null($vhost['php']);
bernd SSL auch über webinterface...

bernd authored 16 years ago

208)   $ssl = maybe_null($vhost['ssl']);
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

209)   $logtype = maybe_null($vhost['logtype']);
bernd error_log konfigurierbar

bernd authored 16 years ago

210)   $errorlog = (int) $vhost['errorlog'];
bernd fix für svn/nodocroot

bernd authored 16 years ago

211)   if ($vhost['is_svn']) {
bernd nodocroot für svn-hosts

bernd authored 16 years ago

212)     if (! $vhost['options']) $vhost['options']='nodocroot';
213)     else $vhost['options']+=",nodocroot";
214)   }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

215)   $options = mysql_real_escape_string( $vhost['options'] );
216) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

217)   $cert = 0;
218)   $certs = user_certs();
219)   foreach ($certs as $c)
220)     if ($c['id'] == $vhost['cert'])
221)       $cert = $c['id'];
222)   if ($cert == 0)
223)     $cert = 'NULL';
224) 
bernd IP-Adressen aktivieren

bernd authored 14 years ago

225)   $ipv4 = 'NULL';
226)   $ipv4_avail = user_ipaddrs();
227)   if (in_array($vhost['ipv4'], $ipv4_avail))
228)   {
229)     $ipv4 = maybe_null($vhost['ipv4']);
230)   }
231) 
bernd Logging

bernd authored 16 years ago

232)   if ($id != 0) {
bernd eliminate .php extensions f...

bernd authored 15 years ago

233)     logger('modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
bernd IP-Adressen aktivieren

bernd authored 14 years ago

234)     db_query("UPDATE vhosts.vhost SET hostname={$hostname}, domain={$domain}, docroot={$docroot}, php={$php}, `ssl`={$ssl}, logtype={$logtype}, errorlog={$errorlog}, certid={$cert}, ipv4={$ipv4}, options='{$options}' WHERE id={$id} LIMIT 1");
bernd Logging

bernd authored 16 years ago

235)   }
236)   else {
bernd eliminate .php extensions f...

bernd authored 15 years ago

237)     logger('modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
bernd IP-Adressen aktivieren

bernd authored 14 years ago

238)     $result = db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, `ssl`, logtype, errorlog, certid, ipv4, options) VALUES ({$_SESSION['userinfo']['uid']}, {$hostname}, {$domain}, {$docroot}, {$php}, {$ssl}, {$logtype}, {$errorlog}, {$cert}, {$ipv4}, '{$options}')");
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

239)     $id = mysql_insert_id();
bernd Logging

bernd authored 16 years ago

240)   }
bernd Webapps implementiert

bernd authored 16 years ago

241)   $oldvhost = get_vhost_details($id);
242)   /*
243)     these vars may be 0 or 1.
244)     So newval > oldval means that it has been switched on yet.
245)   */
246)   if ($vhost['is_dav'] > $oldvhost['is_dav'])
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

247)       make_dav_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

249)       make_svn_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

250)   elseif ($vhost['is_webapp'] > $oldvhost['is_webapp'])
251)       make_webapp_vhost($id, $vhost['webapp_id']);
252)   elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0)
253)       make_regular_vhost($id);
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

254) }
255) 
256) 
bernd Aliases editieren

bernd authored 16 years ago

257) function get_alias_details($id)
258) {
259)   $id = (int) $id;
260)   $uid = (int) $_SESSION['userinfo']['uid'];
261)   $result = db_query("SELECT * FROM vhosts.v_alias WHERE id={$id}");
262)   
263)   if (mysql_num_rows($result) != 1)
264)     system_failure('Interner Fehler beim Auslesen der Alias-Daten');
265)   
266)   $alias = mysql_fetch_assoc($result);
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

270)   }
bernd Aliases editieren

bernd authored 16 years ago

271) 
272)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
273)   get_vhost_details( (int) $alias['vhost'] );
274) 
275)   return $alias;
276) }
277) 
278) 
279) function delete_alias($id)
280) {
281)   $id = (int) $id;
282)   $alias = get_alias_details($id);
283) 
bernd eliminate .php extensions f...

bernd authored 15 years ago

284)   logger('modules/vhosts/include/vhosts', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
bernd Aliases editieren

bernd authored 16 years ago

285)   db_query("DELETE FROM vhosts.alias WHERE id={$id}");
286) }
287) 
288) function save_alias($alias)
289) {
290)   if (! is_array($alias))
291)     system_failure('$alias kein array!');
bernd Neue aliase haben keine ID

bernd authored 14 years ago

292)   $id = (isset($alias['id']) ? (int) $alias['id'] : 0);
bernd Aliases editieren

bernd authored 16 years ago

293)   $hostname = maybe_null($alias['hostname']);
294)   $domain = (int) $alias['domainid'];
295)   if ($domain == 0)
296)     system_failure('$domain == 0');
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

297)   if ($alias['domainid'] == -1)
298)     $domain = 'NULL';
bernd Aliases editieren

bernd authored 16 years ago

299)   $vhost = get_vhost_details( (int) $alias['vhost']);
300)   $options = mysql_real_escape_string( $alias['options'] );
301)   if ($id == 0) {
bernd eliminate .php extensions f...

bernd authored 15 years ago

302)     logger('modules/vhosts/include/vhosts', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
bernd Aliases editieren

bernd authored 16 years ago

303)     db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES ({$hostname}, {$domain}, {$vhost['id']}, '{$options}')");
304)   }
305)   else {
bernd eliminate .php extensions f...

bernd authored 15 years ago

306)     logger('modules/vhosts/include/vhosts', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
bernd Aliases editieren

bernd authored 16 years ago

307)     db_query("UPDATE vhosts.alias SET hostname={$hostname}, domain={$domain}, options='{$options}' WHERE id={$id} LIMIT 1");
308)   }
309) }
310) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

311) 
312) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

313) 
314) function user_ipaddrs()
315) {
316)   $uid = (int) $_SESSION['userinfo']['uid'];
317)   $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid={$uid}");
318)   $ret = array();
319)   while ($i = mysql_fetch_assoc($result))
320)   {
321)     $ret[] = $i['ipaddr'];
322)   }
323)   DEBUG($ret);
324)   return $ret;
325) }
326) 
327)