3e7cffe2a79b64c9f6fa5617a19a7c9c43d4ed26
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 Webalizer/Statistik-Funktio...

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, stats 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 IPv6

bernd authored 14 years ago

44)   $vhost['autoipv6'] = 0;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 16 years ago

46)   $vhost['options'] = '';
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

bernd authored 16 years ago

48)   return $vhost;
49) }
50) 
51) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

75)   foreach ($domainlist as $dom)
76)   {
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

126)   return $ret;
127) }
128) 
bernd Aliases editieren

bernd authored 16 years ago

129) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

170) }
171) 
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

196) }
197) 
198) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

199) function save_vhost($vhost)
200) {
201)   if (! is_array($vhost))
202)     system_failure('$vhost kein array!');
203)   $id = (int) $vhost['id'];
204)   $hostname = maybe_null($vhost['hostname']);
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

205)   $domain = (int) $vhost['domain_id'];
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

206)   if ($domain == 0)
bernd Aliases editieren

bernd authored 16 years ago

207)     system_failure('$domain == 0');
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

208)   if ($vhost['domain_id'] == -1)
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

209)     $domain = 'NULL';
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

219)   $options = mysql_real_escape_string( $vhost['options'] );
220) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

235) 
236)   $autoipv6 = ( $vhost['autoipv6'] == 1) ? '1' : '0';
237) 
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

238)   $stats = maybe_null($vhost['stats']);
bernd IP-Adressen aktivieren

bernd authored 14 years ago

239) 
bernd Logging

bernd authored 16 years ago

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

bernd authored 14 years ago

241)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
bernd IPv6

bernd authored 14 years ago

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

bernd authored 16 years ago

243)   }
244)   else {
bernd Logger mit Logleveln

bernd authored 14 years ago

245)     logger(LOG_INFO, 'modules/vhosts/include/vhosts', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
bernd IPv6

bernd authored 14 years ago

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

bernd authored 16 years ago

247)     $id = mysql_insert_id();
bernd Logging

bernd authored 16 years ago

248)   }
bernd Webapps implementiert

bernd authored 16 years ago

249)   $oldvhost = get_vhost_details($id);
250)   /*
251)     these vars may be 0 or 1.
252)     So newval > oldval means that it has been switched on yet.
253)   */
254)   if ($vhost['is_dav'] > $oldvhost['is_dav'])
bernd vhost-Modul kann jetzt SVN-...

bernd authored 16 years ago

255)       make_dav_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

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

bernd authored 16 years ago

257)       make_svn_vhost($id);
bernd Webapps implementiert

bernd authored 16 years ago

258)   elseif ($vhost['is_webapp'] > $oldvhost['is_webapp'])
259)       make_webapp_vhost($id, $vhost['webapp_id']);
260)   elseif ($vhost['is_dav'] == 0 && $vhost['is_svn'] == 0 && $vhost['is_webapp'] == 0)
261)       make_regular_vhost($id);
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

262) }
263) 
264) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

278)   }
bernd Aliases editieren

bernd authored 16 years ago

279) 
280)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
281)   get_vhost_details( (int) $alias['vhost'] );
282) 
283)   return $alias;
284) }
285) 
286) 
287) function delete_alias($id)
288) {
289)   $id = (int) $id;
290)   $alias = get_alias_details($id);
291) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

293)   db_query("DELETE FROM vhosts.alias WHERE id={$id}");
294) }
295) 
296) function save_alias($alias)
297) {
298)   if (! is_array($alias))
299)     system_failure('$alias kein array!');
bernd Neue aliase haben keine ID

bernd authored 14 years ago

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

bernd authored 16 years ago

301)   $hostname = maybe_null($alias['hostname']);
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

302)   $domain = (int) $alias['domain_id'];
bernd Aliases editieren

bernd authored 16 years ago

303)   if ($domain == 0)
304)     system_failure('$domain == 0');
bernd Webalizer/Statistik-Funktio...

bernd authored 14 years ago

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

bernd authored 16 years ago

306)     $domain = 'NULL';
bernd Aliases editieren

bernd authored 16 years ago

307)   $vhost = get_vhost_details( (int) $alias['vhost']);
308)   $options = mysql_real_escape_string( $alias['options'] );
309)   if ($id == 0) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

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

bernd authored 14 years ago

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

bernd authored 16 years ago

315)     db_query("UPDATE vhosts.alias SET hostname={$hostname}, domain={$domain}, options='{$options}' WHERE id={$id} LIMIT 1");
316)   }
317) }
318) 
bernd neues VHosts-Modul (unbenut...

bernd authored 16 years ago

319) 
320) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

321) 
322) function user_ipaddrs()
323) {
324)   $uid = (int) $_SESSION['userinfo']['uid'];
325)   $result = db_query("SELECT ipaddr FROM vhosts.ipaddr_available WHERE uid={$uid}");
326)   $ret = array();
327)   while ($i = mysql_fetch_assoc($result))
328)   {
329)     $ret[] = $i['ipaddr'];
330)   }
331)   DEBUG($ret);
332)   return $ret;
333) }
334) 
335)