8e3ab1b25432f3ae30cf9a4d0d089426e8e7829b
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 Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

10) function list_vhosts()
11) {
12)   $uid = (int) $_SESSION['userinfo']['uid'];
bernd VHosts-Modul mit neuem Layo...

bernd authored 16 years ago

13)   $result = db_query("SELECT vh.id,fqdn,docroot,docroot_is_default,php,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

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

bernd authored 16 years ago

21) function empty_vhost()
22) {
23)   $vhost['hostname'] = '';
24)   
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

25)   $vhost['domain_id'] = -1;
26)   $vhost['domain'] = $_SESSION['userinfo']['username'].'.schokokeks.org';
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

33)   $vhost['is_dav'] = 0;
34)   $vhost['is_svn'] = 0;
35)   $vhost['is_webapp'] = 0;
bernd Webapps implementiert

bernd authored 16 years ago

36)   $vhsot['webapp_id'] = NULL;
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

37)     
38)   $vhost['options'] = '';
39)   return $vhost;
40) }
41) 
42) 
bernd Aliases editieren

bernd authored 16 years ago

43) function empty_alias()
44) {
45)   $alias['hostname'] = '';
46)   
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

47)   $alias['domain_id'] = -1;
48)   $alias['domain'] = $_SESSION['userinfo']['username'].'.schokokeks.org';
bernd Aliases editieren

bernd authored 16 years ago

49)   
50)   $alias['options'] = '';
51)   return $alias;
52) }
53) 
54) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

56) {
57)   global $domainlist;
58)   if ($domainlist == NULL)
59)     $domainlist = get_domain_list($_SESSION['customerinfo']['customerno'],
60)                                   $_SESSION['userinfo']['uid']);
61)   $selected = (int) $selected;
62) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

63)   $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

64)   $ret .= ' <option value="-1">'.$_SESSION['userinfo']['username'].'.schokokeks.org</option>';
65)   $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

66)   foreach ($domainlist as $dom)
67)   {
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

82)   if (mysql_num_rows($result) != 1)
83)     system_failure('Interner Fehler beim Auslesen der Daten');
84) 
85)   return mysql_fetch_assoc($result);
86) }
87) 
88) 
89) function get_aliases($vhost)
90) {
91)   $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost={$vhost}");
92)   $ret = array();
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

115)   return $ret;
116) }
117) 
bernd Aliases editieren

bernd authored 16 years ago

118) 
bernd Webapps implementiert

bernd authored 16 years ago

119) function list_available_webapps()
120) {
121)   $result = db_query("SELECT id,displayname FROM vhosts.global_webapps");
122)   $ret = array();
123)   while ($item = mysql_fetch_assoc($result))
124)     array_push($ret, $item);
125)   return $ret;
126) }
127) 
128) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

129) function delete_vhost($id)
130) {
131)   $id = (int) $id;
132)   if ($id == 0)
133)     system_failure("id == 0");
134)   $vhost = get_vhost_details($id);
bernd Logging

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

140) 
141) function make_svn_vhost($id) 
142) {
143)   $id = (int) $id;
144)   if ($id == 0)
145)     system_failure("id == 0");
146)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to SVN');
147)   db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES ({$id}, 'svn')");
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

149) }
150) 
151) function make_dav_vhost($id) 
152) {
153)   $id = (int) $id;
154)   if ($id == 0)
155)     system_failure("id == 0");
156)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
bernd Docroot auch bei WebDAV anz...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

159) }
160) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

162) {
163)   $id = (int) $id;
164)   if ($id == 0)
165)     system_failure("id == 0");
166)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to regular');
167)   db_query("DELETE FROM vhosts.dav WHERE vhost={$id}");
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

169) }
170) 
171) 
172) function make_webapp_vhost($id, $webapp) 
173) {
174)   $id = (int) $id;
175)   $webapp = (int) $webapp;
176)   if ($id == 0)
177)     system_failure("id == 0");
bernd Webapps implementiert

bernd authored 16 years ago

178)   $result = db_query("SELECT displayname FROM vhosts.global_webapps WHERE id={$webapp};");
179)   if (mysql_num_rows($result) == 0)
180)     system_failure("webapp-id invalid");
181)   $webapp_name = mysql_fetch_object($result)->displayname;
182)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Setting up webapp '.$webapp_name.' on vhost #'.$id);
183)   db_query("REPLACE INTO vhosts.webapps (vhost, webapp) VALUES ({$id}, {$webapp})");
184)   mail('webapps-setup@schokokeks.org', 'setup', 'setup');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

185) }
186) 
187) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

188) function save_vhost($vhost)
189) {
190)   if (! is_array($vhost))
191)     system_failure('$vhost kein array!');
192)   $id = (int) $vhost['id'];
193)   $hostname = maybe_null($vhost['hostname']);
194)   $domain = (int) $vhost['domainid'];
195)   if ($domain == 0)
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

203)   $errorlog = (int) $vhost['errorlog'];
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

204)   $options = mysql_real_escape_string( $vhost['options'] );
205) 
bernd Logging

bernd authored 16 years ago

206)   if ($id != 0) {
207)     logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
bernd error_log konfigurierbar

bernd authored 16 years ago

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

bernd authored 16 years ago

209)   }
210)   else {
211)     logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

212)     $result = db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, `ssl`, logtype, errorlog, options) VALUES ({$_SESSION['userinfo']['uid']}, {$hostname}, {$domain}, {$docroot}, {$php}, {$ssl}, {$logtype}, {$errorlog}, '{$options}')");
213)     $id = mysql_insert_id();
bernd Logging

bernd authored 16 years ago

214)   }
bernd Webapps implementiert

bernd authored 16 years ago

215)   $oldvhost = get_vhost_details($id);
216)   /*
217)     these vars may be 0 or 1.
218)     So newval > oldval means that it has been switched on yet.
219)   */
220)   if ($vhost['is_dav'] > $oldvhost['is_dav'])
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

221)       make_dav_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

223)       make_svn_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

224)   elseif ($vhost['is_webapp'] > $oldvhost['is_webapp'])
225)       make_webapp_vhost($id, $vhost['webapp_id']);
226)   elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0)
227)       make_regular_vhost($id);
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

228) }
229) 
230) 
bernd Aliases editieren

bernd authored 16 years ago

231) function get_alias_details($id)
232) {
233)   $id = (int) $id;
234)   $uid = (int) $_SESSION['userinfo']['uid'];
235)   $result = db_query("SELECT * FROM vhosts.v_alias WHERE id={$id}");
236)   
237)   if (mysql_num_rows($result) != 1)
238)     system_failure('Interner Fehler beim Auslesen der Alias-Daten');
239)   
240)   $alias = mysql_fetch_assoc($result);
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

244)   }
bernd Aliases editieren

bernd authored 16 years ago

245) 
246)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
247)   get_vhost_details( (int) $alias['vhost'] );
248) 
249)   return $alias;
250) }
251) 
252) 
253) function delete_alias($id)
254) {
255)   $id = (int) $id;
256)   $alias = get_alias_details($id);
257) 
258)   logger('modules/vhosts/include/vhosts.php', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
259)   db_query("DELETE FROM vhosts.alias WHERE id={$id}");
260) }
261) 
262) function save_alias($alias)
263) {
264)   if (! is_array($alias))
265)     system_failure('$alias kein array!');
266)   $id = (int) $alias['id'];
267)   $hostname = maybe_null($alias['hostname']);
268)   $domain = (int) $alias['domainid'];
269)   if ($domain == 0)
270)     system_failure('$domain == 0');
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

273)   $vhost = get_vhost_details( (int) $alias['vhost']);
274)   $options = mysql_real_escape_string( $alias['options'] );
275)   if ($id == 0) {
276)     logger('modules/vhosts/include/vhosts.php', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
277)     db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES ({$hostname}, {$domain}, {$vhost['id']}, '{$options}')");
278)   }
279)   else {
280)     logger('modules/vhosts/include/vhosts.php', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
281)     db_query("UPDATE vhosts.alias SET hostname={$hostname}, domain={$domain}, options='{$options}' WHERE id={$id} LIMIT 1");
282)   }
283) }
284)