7fb0aeba3e1621945895343e67edcf5be0648c98
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;
30)   $vhost['php'] = 'mod_php';
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 VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

118) function delete_vhost($id)
119) {
120)   $id = (int) $id;
121)   if ($id == 0)
122)     system_failure("id == 0");
123)   $vhost = get_vhost_details($id);
bernd Logging

bernd authored 16 years ago

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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

129) 
130) function make_svn_vhost($id) 
131) {
132)   $id = (int) $id;
133)   if ($id == 0)
134)     system_failure("id == 0");
135)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to SVN');
136)   db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES ({$id}, 'svn')");
137) }
138) 
139) function make_dav_vhost($id) 
140) {
141)   $id = (int) $id;
142)   if ($id == 0)
143)     system_failure("id == 0");
144)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to WebDAV');
145)   db_query("REPLACE INTO vhosts.dav (vhost, type) VALUES ({$id}, 'dav')");
146) }
147) 
148) function no_dav_or_svn($id)
149) {
150)   $id = (int) $id;
151)   if ($id == 0)
152)     system_failure("id == 0");
153)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Converting vhost #'.$id.' to regular');
154)   db_query("DELETE FROM vhosts.dav WHERE vhost={$id}");
155) }
156) 
157) 
158) /*
159) function make_webapp_vhost($id, $webapp) 
160) {
161)   $id = (int) $id;
162)   $webapp = (int) $webapp;
163)   if ($id == 0)
164)     system_failure("id == 0");
165)   logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Setting up webapp # '.$webapp.' on vhost #'.$id);
166)   db_query("INSERT INTO vhosts.webapps (vhost, webapp) VALUES ({$id}, {$webapp})");
167) 
168) }
169) */
170) 
171) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

172) function save_vhost($vhost)
173) {
174)   if (! is_array($vhost))
175)     system_failure('$vhost kein array!');
176)   $id = (int) $vhost['id'];
177)   $hostname = maybe_null($vhost['hostname']);
178)   $domain = (int) $vhost['domainid'];
179)   if ($domain == 0)
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

188)   $options = mysql_real_escape_string( $vhost['options'] );
189) 
bernd Logging

bernd authored 16 years ago

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

bernd authored 16 years ago

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

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

bernd authored 16 years ago

196)     $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}')");
197)     $id = mysql_insert_id();
bernd Logging

bernd authored 16 years ago

198)   }
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

199)   if ($vhost['is_dav'] == 1)
200)       make_dav_vhost($id);
201)   elseif ($vhost['is_svn'] == 1)
202)       make_svn_vhost($id);
203)   else
204)       no_dav_or_svn($id);
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

205) }
206) 
207) 
bernd Aliases editieren

bernd authored 16 years ago

208) function get_alias_details($id)
209) {
210)   $id = (int) $id;
211)   $uid = (int) $_SESSION['userinfo']['uid'];
212)   $result = db_query("SELECT * FROM vhosts.v_alias WHERE id={$id}");
213)   
214)   if (mysql_num_rows($result) != 1)
215)     system_failure('Interner Fehler beim Auslesen der Alias-Daten');
216)   
217)   $alias = mysql_fetch_assoc($result);
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

221)   }
bernd Aliases editieren

bernd authored 16 years ago

222) 
223)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
224)   get_vhost_details( (int) $alias['vhost'] );
225) 
226)   return $alias;
227) }
228) 
229) 
230) function delete_alias($id)
231) {
232)   $id = (int) $id;
233)   $alias = get_alias_details($id);
234) 
235)   logger('modules/vhosts/include/vhosts.php', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
236)   db_query("DELETE FROM vhosts.alias WHERE id={$id}");
237) }
238) 
239) function save_alias($alias)
240) {
241)   if (! is_array($alias))
242)     system_failure('$alias kein array!');
243)   $id = (int) $alias['id'];
244)   $hostname = maybe_null($alias['hostname']);
245)   $domain = (int) $alias['domainid'];
246)   if ($domain == 0)
247)     system_failure('$domain == 0');
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

250)   $vhost = get_vhost_details( (int) $alias['vhost']);
251)   $options = mysql_real_escape_string( $alias['options'] );
252)   if ($id == 0) {
253)     logger('modules/vhosts/include/vhosts.php', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
254)     db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES ({$hostname}, {$domain}, {$vhost['id']}, '{$options}')");
255)   }
256)   else {
257)     logger('modules/vhosts/include/vhosts.php', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
258)     db_query("UPDATE vhosts.alias SET hostname={$hostname}, domain={$domain}, options='{$options}' WHERE id={$id} LIMIT 1");
259)   }
260) }
261)