Zeige Userdomains nur noch wenn nötig.
Bernd Wurst

Bernd Wurst commited on 2015-02-18 17:05:57
Zeige 3 geänderte Dateien mit 49 Einfügungen und 21 Löschungen.

... ...
@@ -1,6 +1,7 @@
1 1
  
2 2
   function selectedDomain() {
3
-    return $('#domain option:selected').text();
3
+      dom = $('#domain option:selected').text();
4
+      return dom.match(/\S+/g)[0]
4 5
     }
5 6
   
6 7
 
... ...
@@ -130,6 +130,19 @@ function userdomain() {
130 130
   return $res;
131 131
 }
132 132
 
133
+function user_uses_userdomain()
134
+{
135
+  global $config;
136
+  $uid = (int) $_SESSION['userinfo']['uid'];
137
+  $userdomain = userdomain();
138
+  $result = db_query("SELECT id FROM vhosts.vhost WHERE domain=:domid AND user=:uid", array(":uid" => $uid, ":domid" => $userdomain['id']));
139
+  if ($result->rowCount() > 0) {
140
+    DEBUG("User hat ".$result->rowCount()." Domains *.schokokeks.net");
141
+    return True;
142
+  }
143
+  DEBUG("User hat keine Domains *.schokokeks.net");
144
+  return false;
145
+}
133 146
 
134 147
 function domainselect($selected = NULL, $selectattribute = '')
135 148
 {
... ...
@@ -150,20 +163,24 @@ function domainselect($selected = NULL, $selectattribute = '')
150 163
     }
151 164
     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->fqdn}</option>\n";
152 165
   }
153
-  if (count($domainlist) > 0) {
166
+  $userdomain = userdomain();
167
+  $user_needs_userdomain = $userdomain && (count($domainlist) == 0 || user_uses_userdomain());
168
+  $user_needs_userdomain = $user_needs_userdomain || ($selected == -2);
169
+  if (count($domainlist) > 0 && $user_needs_userdomain) {
154 170
     $ret .= ' <option value="" disabled="disabled">--------------------------------</option>';
155 171
   }
156
-  $userdomain = userdomain();
157
-  if ($userdomain) {
172
+  if ($userdomain && (count($domainlist) == 0 || user_uses_userdomain())) {
158 173
     $s = ($selected == -1 ? ' selected="selected"' : '');
159 174
     $ret .= ' <option value="-1"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.$userdomain['name'].'</option>';
160 175
   }
176
+  if ($selected == -2) {
161 177
     $s = ($selected == -2 ? ' selected="selected"' : '');
162
-  $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').'</option>';
163
-  $ret .= '</select>';
178
+    $ret .= ' <option value="-2"'.$s.'>'.$_SESSION['userinfo']['username'].'.'.config('masterdomain').' (Bitte nicht mehr benutzen!)</option>';
164 179
     if ($selected > 0 and ! $found) {
165 180
       system_failure("Hier wird eine Domain benutzt, die nicht zu diesem Benutzeraccount gehört. Bearbeiten würde Daten zerstören!");
166 181
     }
182
+  }
183
+  $ret .= '</select>';
167 184
   return $ret;
168 185
 }
169 186
 
... ...
@@ -171,6 +188,7 @@ function domainselect($selected = NULL, $selectattribute = '')
171 188
 
172 189
 function get_vhost_details($id)
173 190
 {
191
+  DEBUG("Lese #{$id}...");
174 192
   $id = (int) $id;
175 193
   $uid = (int) $_SESSION['userinfo']['uid'];
176 194
   $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", array(":uid" => $uid, ":id" => $id));
... ...
@@ -307,30 +325,32 @@ function check_hostname_collision($hostname, $domain)
307 325
 {
308 326
   $uid = (int) $_SESSION['userinfo']['uid'];
309 327
   # Neuer vhost => Prüfe Duplikat
310
-  $args = array(":hostname" => $hostname, ":domain" => $domain);
311
-  $hostnamecheck = "hostname=:hostname";
312
-  if (! $hostname) {
313
-    $hostnamecheck = "hostname IS NULL";
314
-    unset($args[":hostname"]);
315
-  }
328
+  $args = array(":hostname" => $hostname, ":domain" => $domain, ":uid" => $uid);
316 329
   $domaincheck = "domain=:domain";
317 330
   if ($domain == -1) {
318
-    $args[":uid"] = $uid;
319
-    $domaincheck = "domain=-1 AND user=:uid";
331
+    $userdomain = userdomain();
332
+    if ($hostname) {
333
+      $hostname .= ".".$_SESSION['userinfo']['username'];
334
+    }
335
+    $args[":domain"] = $userdomain['id'];
320 336
   }
321 337
   if ($domain == -2) {
322
-    $args[":uid"] = $uid;
323 338
     unset($args[":domain"]);
324
-    $domaincheck = "domain IS NULL AND user=:uid";
339
+    $domaincheck = "domain IS NULL";
325 340
   }
326
-  $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck}", $args);
341
+  $hostnamecheck = "hostname=:hostname";
342
+  if (! $hostname) {
343
+    $hostnamecheck = "hostname IS NULL";
344
+    unset($args[":hostname"]);
345
+  }
346
+  $result = db_query("SELECT id FROM vhosts.vhost WHERE {$hostnamecheck} AND {$domaincheck} AND user=:uid", $args);
327 347
   if ($result->rowCount() > 0) {
328 348
     system_failure('Eine Konfiguration mit diesem Namen gibt es bereits.');
329 349
   }
330
-  if ($domain == -1) {
350
+  if ($domain <= -1) {
331 351
     return ;
332 352
   }
333
-  $result = db_query("SELECT id, vhost FROM vhosts.alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
353
+  $result = db_query("SELECT id, vhost FROM vhosts.v_alias WHERE {$hostnamecheck} AND {$domaincheck}", $args);
334 354
   if ($result->rowCount() > 0) {
335 355
     $data = $result->fetch();
336 356
     $vh = get_vhost_details($data['vhost']);
... ...
@@ -39,20 +39,27 @@ if ($_GET['action'] == 'edit')
39 39
 
40 40
   $hostname = filter_input_hostname($_POST['hostname'], true);
41 41
 
42
+  $domainname = NULL;
42 43
   $domain_id = (int) $_POST['domain'];
43 44
   if ($domain_id >= 0) {
44 45
     $domain = new Domain( (int) $_POST['domain'] );
45 46
     $domain->ensure_userdomain();
46 47
     $domain_id = $domain->id;
48
+    $domainname = $domain->fqdn;
47 49
   }
48
-  if ($domain_id == -1) {
50
+  elseif ($domain_id == -1) {
49 51
     # use configured user_vhosts_domain
50 52
     $userdomain = userdomain();
51 53
     $domain = new Domain( (int) $userdomain['id'] );
52 54
     $domain_id = $domain->id;
55
+    $domainname = $domain->fqdn;
53 56
     $hostname = $hostname.'.'.$_SESSION['userinfo']['username'];
54 57
     $hostname = trim($hostname, " .-");
55 58
   }
59
+  elseif ($domain_id == -2) {
60
+    # use system masterdomain
61
+    $domainname = $_SESSION['userinfo']['username'].".".config('masterdomain');
62
+  }
56 63
 
57 64
   if (! (isset($_POST['options']) && is_array($_POST['options'])))
58 65
     $_POST['options'] = array();
... ...
@@ -61,7 +68,7 @@ if ($_GET['action'] == 'edit')
61 68
   $docroot = '';
62 69
   if ($_POST['vhost_type'] == 'regular' || $_POST['vhost_type'] == 'dav')
63 70
   {
64
-    $defaultdocroot = $vhost['homedir'].'/websites/'.((strlen($hostname) > 0) ? $hostname.'.' : '').($domain->fqdn).'/htdocs';
71
+    $defaultdocroot = $vhost['homedir'].'/websites/'.((strlen($hostname) > 0) ? $hostname.'.' : '').($domainname).'/htdocs';
65 72
   
66 73
     $docroot = '';
67 74
     if (isset($_POST['docroot']))
68 75