1ab9db55d272aaa37a76d7a5c179e55c2ca52267
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) {
24)   $vhost['hostname'] = '';
25)   
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

37)   $vhost['webapp_id'] = NULL;
38)   
39)   $vhost['cert'] = NULL;
40) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

69)   foreach ($domainlist as $dom)
70)   {
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

120)   return $ret;
121) }
122) 
bernd Aliases editieren

bernd authored 16 years ago

123) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

164) }
165) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

190) }
191) 
192) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

213)   $options = mysql_real_escape_string( $vhost['options'] );
214) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

215)   $cert = 0;
216)   $certs = user_certs();
217)   foreach ($certs as $c)
218)     if ($c['id'] == $vhost['cert'])
219)       $cert = $c['id'];
220) 
221)   if ($cert == 0)
222)     $cert = 'NULL';
223) 
bernd Logging

bernd authored 16 years ago

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

bernd authored 15 years ago

225)     logger('modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 16 years ago

227)   }
228)   else {
bernd eliminate .php extensions f...

bernd authored 15 years ago

229)     logger('modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 16 years ago

231)     $id = mysql_insert_id();
bernd Logging

bernd authored 16 years ago

232)   }
bernd Webapps implementiert

bernd authored 16 years ago

233)   $oldvhost = get_vhost_details($id);
234)   /*
235)     these vars may be 0 or 1.
236)     So newval > oldval means that it has been switched on yet.
237)   */
238)   if ($vhost['is_dav'] > $oldvhost['is_dav'])
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

239)       make_dav_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

241)       make_svn_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

242)   elseif ($vhost['is_webapp'] > $oldvhost['is_webapp'])
243)       make_webapp_vhost($id, $vhost['webapp_id']);
244)   elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0)
245)       make_regular_vhost($id);
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

246) }
247) 
248) 
bernd Aliases editieren

bernd authored 16 years ago

249) function get_alias_details($id)
250) {
251)   $id = (int) $id;
252)   $uid = (int) $_SESSION['userinfo']['uid'];
253)   $result = db_query("SELECT * FROM vhosts.v_alias WHERE id={$id}");
254)   
255)   if (mysql_num_rows($result) != 1)
256)     system_failure('Interner Fehler beim Auslesen der Alias-Daten');
257)   
258)   $alias = mysql_fetch_assoc($result);
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

262)   }
bernd Aliases editieren

bernd authored 16 years ago

263) 
264)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
265)   get_vhost_details( (int) $alias['vhost'] );
266) 
267)   return $alias;
268) }
269) 
270) 
271) function delete_alias($id)
272) {
273)   $id = (int) $id;
274)   $alias = get_alias_details($id);
275) 
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 16 years ago

277)   db_query("DELETE FROM vhosts.alias WHERE id={$id}");
278) }
279) 
280) function save_alias($alias)
281) {
282)   if (! is_array($alias))
283)     system_failure('$alias kein array!');
284)   $id = (int) $alias['id'];
285)   $hostname = maybe_null($alias['hostname']);
286)   $domain = (int) $alias['domainid'];
287)   if ($domain == 0)
288)     system_failure('$domain == 0');
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

299)     db_query("UPDATE vhosts.alias SET hostname={$hostname}, domain={$domain}, options='{$options}' WHERE id={$id} LIMIT 1");
300)   }
301) }
302) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

303) 
304) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

305) 
306) function user_ipaddrs()
307) {
308)   $uid = (int) $_SESSION['userinfo']['uid'];
309)   $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid={$uid}");
310)   $ret = array();
311)   while ($i = mysql_fetch_assoc($result))
312)   {
313)     $ret[] = $i['ipaddr'];
314)   }
315)   DEBUG($ret);
316)   return $ret;
317) }
318) 
319)