bernd commited on 2007-08-09 19:05:07
Zeige 4 geänderte Dateien mit 177 Einfügungen und 21 Löschungen.
git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@605 87cf0b9e-d624-0410-a070-f6ee81989793
... | ... |
@@ -5,7 +5,7 @@ require_once('inc/security.php'); |
5 | 5 |
|
6 | 6 |
require_once('vhosts.php'); |
7 | 7 |
|
8 |
-$title = "VHost bearbeiten"; |
|
8 |
+$title = "Subdomain bearbeiten"; |
|
9 | 9 |
$section = 'vhosts_vhosts'; |
10 | 10 |
|
11 | 11 |
require_role(ROLE_SYSTEMUSER); |
... | ... |
@@ -17,7 +17,13 @@ if ($id != 0) |
17 | 17 |
$vhost = get_vhost_details($id); |
18 | 18 |
|
19 | 19 |
DEBUG($vhost); |
20 |
-output("<h3>VHost bearbeiten</h3>"); |
|
20 |
+if ($id == 0) { |
|
21 |
+ output("<h3>Neue Subdomain anlegen</h3>"); |
|
22 |
+ $title = "Subdomain anlegen"; |
|
23 |
+} |
|
24 |
+else { |
|
25 |
+ output("<h3>Subdomain bearbeiten</h3>"); |
|
26 |
+} |
|
21 | 27 |
|
22 | 28 |
output("<script type=\"text/javascript\"> |
23 | 29 |
|
... | ... |
@@ -93,7 +99,7 @@ $form .= "<br /><input type=\"checkbox\" name=\"options[]\" id=\"aliaswww\" valu |
93 | 99 |
"; |
94 | 100 |
|
95 | 101 |
$form .= '</table> |
96 |
- <p><input type="submit" value="Änderungen speichern" /> '.internal_link('vhosts.php', 'Ohne Speichern zurück').'</p> |
|
102 |
+ <p><input type="submit" value="Speichern" /> '.internal_link('vhosts.php', 'Abbrechen').'</p> |
|
97 | 103 |
'; |
98 | 104 |
output(html_form('vhosts_edit_vhost', 'save.php', 'action=edit&vhost='.$vhost['id'], $form)); |
99 | 105 |
|
... | ... |
@@ -38,6 +39,22 @@ function empty_vhost() |
38 | 39 |
} |
39 | 40 |
|
40 | 41 |
|
42 |
+function empty_alias() |
|
43 |
+{ |
|
44 |
+ $alias['hostname'] = ''; |
|
45 |
+ |
|
46 |
+ $domainlist = get_domain_list($_SESSION['customerinfo']['customerno'], |
|
47 |
+ $_SESSION['userinfo']['uid']); |
|
48 |
+ $dom = $domainlist[0]; |
|
49 |
+ |
|
50 |
+ $alias['domain_id'] = $dom->id; |
|
51 |
+ $alias['domain'] = $dom->fqdn; |
|
52 |
+ |
|
53 |
+ $alias['options'] = ''; |
|
54 |
+ return $alias; |
|
55 |
+} |
|
56 |
+ |
|
57 |
+ |
|
41 | 58 |
function domainselect($selected = NULL, $selectattribute = '') |
42 | 59 |
{ |
43 | 60 |
global $domainlist; |
... | ... |
@@ -49,9 +66,7 @@ function domainselect($selected = NULL, $selectattribute = '') |
49 | 66 |
$ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >'; |
50 | 67 |
foreach ($domainlist as $dom) |
51 | 68 |
{ |
52 |
- $s = ''; |
|
53 |
- if ($selected == $dom->id) |
|
54 |
- $s = ' selected="selected" '; |
|
69 |
+ $s = ($selected == $dom->id) ? ' selected="selected" ': ''; |
|
55 | 70 |
$ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n"; |
56 | 71 |
} |
57 | 72 |
$ret .= '</select>'; |
... | ... |
@@ -72,14 +87,32 @@ function get_vhost_details($id) |
72 | 87 |
} |
73 | 88 |
|
74 | 89 |
|
75 |
- |
|
76 | 90 |
function get_aliases($vhost) |
77 | 91 |
{ |
78 |
- $vhost = (int) $vhost; |
|
79 | 92 |
$result = db_query("SELECT id,fqdn,options FROM vhosts.v_alias WHERE vhost={$vhost}"); |
80 | 93 |
$ret = array(); |
81 |
- while ($item = mysql_fetch_assoc($result)) |
|
94 |
+ while ($item = mysql_fetch_assoc($result)) { |
|
82 | 95 |
array_push($ret, $item); |
96 |
+ } |
|
97 |
+ return $ret; |
|
98 |
+} |
|
99 |
+ |
|
100 |
+ |
|
101 |
+ |
|
102 |
+function get_all_aliases($vhost) |
|
103 |
+{ |
|
104 |
+ $vhost = get_vhost_details( (int) $vhost ); |
|
105 |
+ $aliases = get_aliases($vhost['id']); |
|
106 |
+ $ret = array(); |
|
107 |
+ if (strstr($vhost['options'], 'aliaswww')) { |
|
108 |
+ array_push($ret, array('id' => 'www', 'fqdn' => 'www.'.$vhost['fqdn'], 'options' => (strstr($vhost['options'], 'forwardwww') ? 'forward' : ''))); |
|
109 |
+ } |
|
110 |
+ foreach ($aliases as $item) { |
|
111 |
+ array_push($ret, $item); |
|
112 |
+ if (strstr($item['options'], 'aliaswww')) { |
|
113 |
+ array_push($ret, array('id' => 'www_'.$item['id'], 'fqdn' => 'www.'.$item['fqdn'], 'options' => (strstr($item['options'], 'forward') ? 'forward' : ''))); |
|
114 |
+ } |
|
115 |
+ } |
|
83 | 116 |
return $ret; |
84 | 117 |
} |
85 | 118 |
|
... | ... |
@@ -101,7 +136,7 @@ function save_vhost($vhost) |
101 | 136 |
$hostname = maybe_null($vhost['hostname']); |
102 | 137 |
$domain = (int) $vhost['domainid']; |
103 | 138 |
if ($domain == 0) |
104 |
- system_failure("Domain == 0"); |
|
139 |
+ system_failure('$domain == 0'); |
|
105 | 140 |
$docroot = maybe_null($vhost['docroot']); |
106 | 141 |
$php = maybe_null($vhost['php']); |
107 | 142 |
$logtype = maybe_null($vhost['logtype']); |
... | ... |
@@ -118,6 +153,54 @@ function save_vhost($vhost) |
118 | 153 |
} |
119 | 154 |
|
120 | 155 |
|
156 |
+function get_alias_details($id) |
|
157 |
+{ |
|
158 |
+ $id = (int) $id; |
|
159 |
+ $uid = (int) $_SESSION['userinfo']['uid']; |
|
160 |
+ $result = db_query("SELECT * FROM vhosts.v_alias WHERE id={$id}"); |
|
161 |
+ |
|
162 |
+ if (mysql_num_rows($result) != 1) |
|
163 |
+ system_failure('Interner Fehler beim Auslesen der Alias-Daten'); |
|
164 |
+ |
|
165 |
+ $alias = mysql_fetch_assoc($result); |
|
166 |
+ |
|
167 |
+ /* Das bewirkt, dass nur die eigenen Aliase gesehen werden können */ |
|
168 |
+ get_vhost_details( (int) $alias['vhost'] ); |
|
169 |
+ |
|
170 |
+ return $alias; |
|
171 |
+} |
|
172 |
+ |
|
173 |
+ |
|
174 |
+function delete_alias($id) |
|
175 |
+{ |
|
176 |
+ $id = (int) $id; |
|
177 |
+ $alias = get_alias_details($id); |
|
178 |
+ |
|
179 |
+ logger('modules/vhosts/include/vhosts.php', 'aliases', 'Removing alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')'); |
|
180 |
+ db_query("DELETE FROM vhosts.alias WHERE id={$id}"); |
|
181 |
+} |
|
182 |
+ |
|
183 |
+function save_alias($alias) |
|
184 |
+{ |
|
185 |
+ if (! is_array($alias)) |
|
186 |
+ system_failure('$alias kein array!'); |
|
187 |
+ $id = (int) $alias['id']; |
|
188 |
+ $hostname = maybe_null($alias['hostname']); |
|
189 |
+ $domain = (int) $alias['domainid']; |
|
190 |
+ if ($domain == 0) |
|
191 |
+ system_failure('$domain == 0'); |
|
192 |
+ $vhost = get_vhost_details( (int) $alias['vhost']); |
|
193 |
+ $options = mysql_real_escape_string( $alias['options'] ); |
|
194 |
+ if ($id == 0) { |
|
195 |
+ logger('modules/vhosts/include/vhosts.php', 'aliases', 'Creating alias '.$alias['hostname'].'.'.$alias['domain'].' for VHost '.$vhost['id']); |
|
196 |
+ db_query("INSERT INTO vhosts.alias (hostname, domain, vhost, options) VALUES ({$hostname}, {$domain}, {$vhost['id']}, '{$options}')"); |
|
197 |
+ } |
|
198 |
+ else { |
|
199 |
+ logger('modules/vhosts/include/vhosts.php', 'aliases', 'Updating alias #'.$id.' ('.$alias['hostname'].'.'.$alias['domain'].')'); |
|
200 |
+ db_query("UPDATE vhosts.alias SET hostname={$hostname}, domain={$domain}, options='{$options}' WHERE id={$id} LIMIT 1"); |
|
201 |
+ } |
|
202 |
+} |
|
203 |
+ |
|
121 | 204 |
|
122 | 205 |
|
123 | 206 |
?> |
... | ... |
@@ -97,8 +97,82 @@ if ($_GET['action'] == 'edit') |
97 | 97 |
header('Location: vhosts.php'); |
98 | 98 |
|
99 | 99 |
} |
100 |
+elseif ($_GET['action'] == 'addalias') |
|
101 |
+{ |
|
102 |
+ check_form_token('vhosts_add_alias'); |
|
103 |
+ $id = (int) $_GET['vhost']; |
|
104 |
+ $vhost = get_vhost_details( $id ); |
|
105 |
+ DEBUG($vhost); |
|
106 |
+ |
|
107 |
+ $alias = empty_alias(); |
|
108 |
+ $alias['vhost'] = $vhost['id']; |
|
109 |
+ |
|
110 |
+ |
|
111 |
+ $hostname = filter_input_hostname($_POST['hostname']); |
|
112 |
+ $domain = new Domain( (int) $_POST['domain'] ); |
|
113 |
+ if ($domain->useraccount != $_SESSION['userinfo']['uid']) |
|
114 |
+ system_failure('Ungültige Domain'); |
|
115 |
+ |
|
116 |
+ if (! is_array($_POST['options'])) |
|
117 |
+ $_POST['options'] = array(); |
|
118 |
+ $aliaswww = in_array('aliaswww', $_POST['options']); |
|
119 |
+ $forward = in_array('forward', $_POST['options']); |
|
120 |
+ |
|
121 |
+ $new_options = array(); |
|
122 |
+ if ($aliaswww) |
|
123 |
+ array_push($new_options, 'aliaswww'); |
|
124 |
+ if ($forward) |
|
125 |
+ array_push($new_options, 'forward'); |
|
126 |
+ DEBUG($new_options); |
|
127 |
+ $options = implode(',', $new_options); |
|
128 |
+ DEBUG('New options: '.$options); |
|
129 |
+ |
|
130 |
+ $alias['hostname'] = $hostname; |
|
131 |
+ $alias['domainid'] = $domain->id; |
|
132 |
+ |
|
133 |
+ $alias ['options'] = $options; |
|
134 |
+ |
|
135 |
+ save_alias($alias); |
|
136 |
+ |
|
137 |
+ if (! $debugmode) |
|
138 |
+ header('Location: aliases.php?vhost='.$vhost['id']); |
|
139 |
+ |
|
140 |
+} |
|
141 |
+elseif ($_GET['action'] == 'deletealias') |
|
142 |
+{ |
|
143 |
+ $title = "Subdomain löschen"; |
|
144 |
+ $section = 'vhosts_vhosts'; |
|
145 |
+ |
|
146 |
+ $alias = get_alias_details( (int) $_GET['alias'] ); |
|
147 |
+ DEBUG($alias); |
|
148 |
+ $alias_string = ((strlen($alias['hostname']) > 0) ? $alias['hostname'].'.' : '').$alias['domain']; |
|
149 |
+ |
|
150 |
+ $vhost = get_vhost_details( $alias['vhost'] ); |
|
151 |
+ DEBUG($vhost); |
|
152 |
+ $vhost_string = ((strlen($vhost['hostname']) > 0) ? $vhost['hostname'].'.' : '').$vhost['domain']; |
|
153 |
+ |
|
154 |
+ $sure = user_is_sure(); |
|
155 |
+ if ($sure === NULL) |
|
156 |
+ { |
|
157 |
+ are_you_sure("action=deletealias&alias={$_GET['alias']}", "Möchten Sie das Alias »{$alias_string}« für die Subdomain »{$vhost_string}« wirklich löschen?"); |
|
158 |
+ } |
|
159 |
+ elseif ($sure === true) |
|
160 |
+ { |
|
161 |
+ delete_alias($alias['id']); |
|
162 |
+ if (! $debugmode) |
|
163 |
+ header('Location: aliases.php?vhost='.$vhost['id']); |
|
164 |
+ } |
|
165 |
+ elseif ($sure === false) |
|
166 |
+ { |
|
167 |
+ if (! $debugmode) |
|
168 |
+ header('Location: aliases.php?vhost='.$vhost['id']); |
|
169 |
+ } |
|
170 |
+} |
|
100 | 171 |
elseif ($_GET['action'] == 'delete') |
101 | 172 |
{ |
173 |
+ $title = "Subdomain löschen"; |
|
174 |
+ $section = 'vhosts_vhosts'; |
|
175 |
+ |
|
102 | 176 |
$vhost = get_vhost_details( (int) $_GET['vhost'] ); |
103 | 177 |
$vhost_string = ((strlen($vhost['hostname']) > 0) ? $vhost['hostname'].'.' : '').$vhost['domain']; |
104 | 178 |
|
... | ... |
@@ -118,8 +192,6 @@ elseif ($_GET['action'] == 'delete') |
118 | 192 |
if (! $debugmode) |
119 | 193 |
header("Location: vhosts.php"); |
120 | 194 |
} |
121 |
- |
|
122 |
- /* TODO */ |
|
123 | 195 |
} |
124 | 196 |
else |
125 | 197 |
system_failure("Unimplemented action"); |
... | ... |
@@ -4,34 +4,31 @@ require_once('inc/security.php'); |
4 | 4 |
|
5 | 5 |
require_once('vhosts.php'); |
6 | 6 |
|
7 |
-$title = "Webserver VHosts"; |
|
7 |
+$title = "Subdomains"; |
|
8 | 8 |
$error = ''; |
9 | 9 |
|
10 | 10 |
require_role(ROLE_SYSTEMUSER); |
11 | 11 |
|
12 | 12 |
|
13 |
-output("<h3>Webserver (VHosts)</h3> |
|
14 |
-<p>Mit dieser Funtkion legen Sie fest, welche Domains und Subdomains verfügbar sein sollen und welches Verzeichnis die Dateien enthalten soll.</p>"); |
|
13 |
+output("<h3>Subdomains</h3> |
|
14 |
+<p>Mit dieser Funtkion legen Sie fest, welche Domains und Subdomains als Webserver-Ressource verfügbar sein sollen und welches Verzeichnis die Dateien enthalten soll.</p>"); |
|
15 | 15 |
|
16 | 16 |
$vhosts = list_vhosts(); |
17 | 17 |
|
18 | 18 |
if (count($vhosts) > 0) |
19 | 19 |
{ |
20 |
- output("<table><tr><th>(Sub-)Domain</th><th>Zusätzliche Alias-Namen</th><th>Lokaler Pfad</th><th>PHP</th></tr>"); |
|
20 |
+ output("<table><tr><th>(Sub-)Domain</th><th>Zusätzliche Alias-Namen</th><th>Lokaler Pfad<sup>*</sup></th><th>PHP</th></tr>"); |
|
21 | 21 |
|
22 | 22 |
foreach ($vhosts as $vhost) |
23 | 23 |
{ |
24 | 24 |
$fqdn = $vhost['fqdn']; |
25 | 25 |
output("<tr><td>".internal_link('edit.php', $fqdn, "vhost={$vhost['id']}")."</td><td>"); |
26 |
- $aliases = get_aliases($vhost['id']); |
|
27 |
- if (strstr($vhost['options'], 'aliaswww')) |
|
28 |
- output('www.'.$vhost['fqdn'].'<br />'); |
|
26 |
+ $aliases = get_all_aliases($vhost['id']); |
|
29 | 27 |
foreach ($aliases as $alias) |
30 | 28 |
{ |
31 |
- if (strstr($alias['options'], 'aliaswww')) |
|
32 |
- output('www.'.$alias['fqdn'].'<br />'); |
|
33 | 29 |
output($alias['fqdn'].'<br />'); |
34 | 30 |
} |
31 |
+ output(internal_link('aliases.php', 'Aliase verwalten', 'vhost='.$vhost['id'])); |
|
35 | 32 |
output('</td>'); |
36 | 33 |
if ($vhost['docroot_is_default'] == 1) |
37 | 34 |
output("<td><span style=\"color:#777;\">{$vhost['docroot']}</span></td>"); |
... | ... |
@@ -56,6 +53,7 @@ if (count($vhosts) > 0) |
56 | 53 |
} |
57 | 54 |
output('</table> |
58 | 55 |
<p><a href="edit.php">Neue Subdomain anlegen</a></p> |
56 |
+<p><sup>*</sup>) schwach geschriebene Pfadangaben bezeichnen die Standardeinstellung. Ist ein Pfad fett dargestellt, so haben Sie einen davon abweichenden Wert eingegeben.</p> |
|
59 | 57 |
<br />'); |
60 | 58 |
} |
61 | 59 |
|
62 | 60 |