f1d119a959c433c20269927761fd1ccef08de0a3
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 können bearbeitet we...

bernd authored 16 years ago

13)   $result = db_query("SELECT id,fqdn,docroot,docroot_is_default,php,options FROM vhosts.v_vhost 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';
31)   $vhost['logtype'] = NULL;
32)     
33)   $vhost['options'] = '';
34)   return $vhost;
35) }
36) 
37) 
bernd Aliases editieren

bernd authored 16 years ago

38) function empty_alias()
39) {
40)   $alias['hostname'] = '';
41)   
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

44)   
45)   $alias['options'] = '';
46)   return $alias;
47) }
48) 
49) 
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

61)   foreach ($domainlist as $dom)
62)   {
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

64)     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
65)   }
66)   $ret .= '</select>';
67)   return $ret;
68) }
69) 
70) 
71) 
72) function get_vhost_details($id)
73) {
74)   $id = (int) $id;
75)   $uid = (int) $_SESSION['userinfo']['uid'];
76)   $result = db_query("SELECT * FROM vhosts.v_vhost WHERE uid={$uid} AND id={$id}");
77)   if (mysql_num_rows($result) != 1)
78)     system_failure('Interner Fehler beim Auslesen der Daten');
79) 
80)   return mysql_fetch_assoc($result);
81) }
82) 
83) 
84) function get_aliases($vhost)
85) {
86)   $result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost={$vhost}");
87)   $ret = array();
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

110)   return $ret;
111) }
112) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

114) function delete_vhost($id)
115) {
116)   $id = (int) $id;
117)   if ($id == 0)
118)     system_failure("id == 0");
119)   $vhost = get_vhost_details($id);
bernd Logging

bernd authored 16 years ago

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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

125) function save_vhost($vhost)
126) {
127)   if (! is_array($vhost))
128)     system_failure('$vhost kein array!');
129)   $id = (int) $vhost['id'];
130)   $hostname = maybe_null($vhost['hostname']);
131)   $domain = (int) $vhost['domainid'];
132)   if ($domain == 0)
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

136)   $docroot = maybe_null($vhost['docroot']);
137)   $php = maybe_null($vhost['php']);
138)   $logtype = maybe_null($vhost['logtype']);
139)   $options = mysql_real_escape_string( $vhost['options'] );
140) 
bernd Logging

bernd authored 16 years ago

141)   if ($id != 0) {
142)     logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

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

bernd authored 16 years ago

144)   }
145)   else {
146)     logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

147)     db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, logtype, options) VALUES ({$_SESSION['userinfo']['uid']}, {$hostname}, {$domain}, {$docroot}, {$php}, {$logtype}, '{$options}')");
bernd Logging

bernd authored 16 years ago

148)   }
bernd VHosts können bearbeitet we...

bernd authored 16 years ago

149) }
150) 
151) 
bernd Aliases editieren

bernd authored 16 years ago

152) function get_alias_details($id)
153) {
154)   $id = (int) $id;
155)   $uid = (int) $_SESSION['userinfo']['uid'];
156)   $result = db_query("SELECT * FROM vhosts.v_alias WHERE id={$id}");
157)   
158)   if (mysql_num_rows($result) != 1)
159)     system_failure('Interner Fehler beim Auslesen der Alias-Daten');
160)   
161)   $alias = mysql_fetch_assoc($result);
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

162)   
163)   if ($alias['domain_id'] == NULL)
164)     $alias['domain_id'] = -1;
bernd Aliases editieren

bernd authored 16 years ago

165) 
166)   /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */
167)   get_vhost_details( (int) $alias['vhost'] );
168) 
169)   return $alias;
170) }
171) 
172) 
173) function delete_alias($id)
174) {
175)   $id = (int) $id;
176)   $alias = get_alias_details($id);
177) 
178)   logger('modules/vhosts/include/vhosts.php', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
179)   db_query("DELETE FROM vhosts.alias WHERE id={$id}");
180) }
181) 
182) function save_alias($alias)
183) {
184)   if (! is_array($alias))
185)     system_failure('$alias kein array!');
186)   $id = (int) $alias['id'];
187)   $hostname = maybe_null($alias['hostname']);
188)   $domain = (int) $alias['domainid'];
189)   if ($domain == 0)
190)     system_failure('$domain == 0');
bernd domain = NULL ==> user-subd...

bernd authored 16 years ago

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

bernd authored 16 years ago

193)   $vhost = get_vhost_details( (int) $alias['vhost']);
194)   $options = mysql_real_escape_string( $alias['options'] );
195)   if ($id == 0) {
196)     logger('modules/vhosts/include/vhosts.php', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']);
197)     db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES ({$hostname}, {$domain}, {$vhost['id']}, '{$options}')");
198)   }
199)   else {
200)     logger('modules/vhosts/include/vhosts.php', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')');
201)     db_query("UPDATE vhosts.alias SET hostname={$hostname}, domain={$domain}, options='{$options}' WHERE id={$id} LIMIT 1");
202)   }
203) }
204)