fc35e6982695ba56c5da53c14ecfeb9e7b43d198
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';
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;
33)     
34)   $vhost['options'] = '';
35)   return $vhost;
36) }
37) 
38) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

140)   $logtype = maybe_null($vhost['logtype']);
141)   $options = mysql_real_escape_string( $vhost['options'] );
142) 
bernd Logging

bernd authored 16 years ago

143)   if ($id != 0) {
144)     logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Updating vhost #'.$id.' ('.$vhost['hostname'].'.'.$vhost['domain'].')');
bernd SSL auch über webinterface...

bernd authored 16 years ago

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

bernd authored 16 years ago

146)   }
147)   else {
148)     logger('modules/vhosts/include/vhosts.php', 'vhosts', 'Creating vhost '.$vhost['hostname'].'.'.$vhost['domain'].'');
bernd SSL auch über webinterface...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

151) }
152) 
153) 
bernd Aliases editieren

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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