6b5987ded6e6019c7a34a4053cd8be9015844c0f
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 mehr VHost-Optionen von der...

bernd authored 14 years ago

15)   $result = db_query("SELECT vh.id,fqdn,domain,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 Einige notices (undefined i...

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

39)   $vhost['webapp_id'] = NULL;
40)   
41)   $vhost['cert'] = NULL;
bernd Einige notices (undefined i...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

73)   foreach ($domainlist as $dom)
74)   {
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

124)   return $ret;
125) }
126) 
bernd Aliases editieren

bernd authored 16 years ago

127) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

138) function delete_vhost($id)
139) {
140)   $id = (int) $id;
141)   if ($id == 0)
142)     system_failure("id == 0");
143)   $vhost = get_vhost_details($id);
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

149) 
150) function make_svn_vhost($id) 
151) {
152)   $id = (int) $id;
153)   if ($id == 0)
154)     system_failure("id == 0");
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

158) }
159) 
160) function make_dav_vhost($id) 
161) {
162)   $id = (int) $id;
163)   if ($id == 0)
164)     system_failure("id == 0");
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

168) }
169) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

171) {
172)   $id = (int) $id;
173)   if ($id == 0)
174)     system_failure("id == 0");
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

187)   $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id={$webapp};");
188)   if (mysql_num_rows($result) == 0)
189)     system_failure("webapp-id invalid");
190)   $webapp_name = mysql_fetch_object($result)->displayname;
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

194) }
195) 
196) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

217)   $options = mysql_real_escape_string( $vhost['options'] );
218) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

237)   }
238)   else {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

241)     $id = mysql_insert_id();
bernd Logging

bernd authored 16 years ago

242)   }
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

249)       make_dav_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

251)       make_svn_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

256) }
257) 
258) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

272)   }
bernd Aliases editieren

bernd authored 16 years ago

273) 
274)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
275)   get_vhost_details( (int) $alias['vhost'] );
276) 
277)   return $alias;
278) }
279) 
280) 
281) function delete_alias($id)
282) {
283)   $id = (int) $id;
284)   $alias = get_alias_details($id);
285) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

301)   $vhost = get_vhost_details( (int) $alias['vhost']);
302)   $options = mysql_real_escape_string( $alias['options'] );
303)   if ($id == 0) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

305)     db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES ({$hostname}, {$domain}, {$vhost['id']}, '{$options}')");
306)   }
307)   else {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

313) 
314) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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