VHosts können bearbeitet werden (ohne Aliases)
bernd

bernd commited on 2007-08-08 13:03:25
Zeige 5 geänderte Dateien mit 271 Einfügungen und 16 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@600 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -6,25 +6,96 @@ require_once('inc/security.php');
6 6
 require_once('vhosts.php');
7 7
 
8 8
 $title = "VHost bearbeiten";
9
+$section = 'vhosts_vhosts';
9 10
 
10 11
 require_role(ROLE_SYSTEMUSER);
11 12
 
12
-$vhost = get_vhost_details($_GET['vhost']);
13
+$id = (int) $_GET['vhost'];
14
+$vhost = empty_vhost();
15
+
16
+if ($id != 0)
17
+  $vhost = get_vhost_details($id);
13 18
 
14 19
 DEBUG($vhost);
15 20
 output("<h3>VHost bearbeiten</h3>");
16 21
 
22
+output("<script type=\"text/javascript\">
23
+  
24
+  function selectedDomain() {
25
+    var selected;
26
+    selected=document.getElementById('domain').options.selectedIndex;
27
+    return document.getElementById('domain').options.item(selected).text;
28
+    }
29
+  
30
+  function defaultDocumentRoot() {
31
+    var hostname;
32
+    if (document.getElementById('hostname').value == '') 
33
+      hostname = selectedDomain();
34
+    else
35
+      hostname = document.getElementById('hostname').value + '.' + selectedDomain();
36
+    document.getElementById('defaultdocroot').firstChild.nodeValue = 'websites/' + hostname + '/htdocs';
37
+    useDefaultDocroot();
38
+  }
39
+  
40
+  function useDefaultDocroot() {
41
+    var do_it = (document.getElementById('use_default_docroot').checked == true);
42
+    var inputfield = document.getElementById('docroot');
43
+    inputfield.disabled = do_it;
44
+    if (do_it) {
45
+      document.getElementById('docroot').value = document.getElementById('defaultdocroot').firstChild.nodeValue;
46
+    }
47
+  }
48
+  </script>");
49
+
50
+$defaultdocroot = $vhost['domain'];
51
+if ($vhost['hostname'])
52
+  $defaultdocroot = $vhost['hostname'].'.'.$defaultdocroot;
53
+
54
+$defaultdocroot = 'websites/'.$defaultdocroot.'/htdocs';
55
+
56
+$is_default_docroot = ($vhost['docroot'] == NULL) || ($vhost['homedir'].'/'.$defaultdocroot == $vhost['docroot']);
57
+
58
+$docroot = '';
59
+if ($vhost['docroot'] == '')
60
+  $docroot = $defaultdocroot;
61
+else
62
+  $docroot = substr($vhost['docroot'], strlen($vhost['homedir'])+1);
63
+
17 64
 $s = (strstr($vhost['options'], 'aliaswww') ? ' checked="checked" ' : '');
18 65
 $form = "
19 66
   <table>
20 67
     <tr><th>Einstellung</th><th>aktueller Wert</th><th>System-Standard</th></tr>
21 68
     <tr><td>Name</td>
22
-    <td><div id=\"wwwprefix\" style=\"font-weight: bold; display: inline; color: #000;\">www.</div><input type=\"text\" name=\"hostname\" size=\"10\" value=\"{$vhost['hostname']}\" />
23
-".domainselect($vhost['domain_id']);
24
-$form .= "<br /><input type=\"checkbox\" name=\"options[]\" value=\"aliaswww\" onclick=\"document.getElementById('wwwprefix').firstChild='';\" {$s}/> Ohne <strong>www</strong> davor.</td><td><em>keiner</em></td></tr>";
69
+    <td><input type=\"text\" name=\"hostname\" id=\"hostname\" size=\"10\" value=\"{$vhost['hostname']}\" onchange=\"defaultDocumentRoot()\" /><strong>.</strong>".domainselect($vhost['domain_id'], 'onchange="defaultDocumentRoot()"');
70
+$form .= "<br /><input type=\"checkbox\" name=\"options[]\" id=\"aliaswww\" value=\"aliaswww\" {$s}/> <label for=\"aliaswww\">Auch mit <strong>www</strong> davor.</label></td><td><em>keiner</em></td></tr>
71
+    <tr><td>Lokaler Pfad</td>
72
+    <td><input type=\"checkbox\" id=\"use_default_docroot\" name=\"use_default_docroot\" value=\"1\" onclick=\"useDefaultDocroot()\" ".($is_default_docroot ? 'checked="checked" ' : '')."/>&nbsp;<label for=\"use_default_docroot\">Standardeinstellung benutzen</label><br />
73
+    <strong>".$vhost['homedir']."/</strong>&nbsp;<input type=\"text\" id=\"docroot\" name=\"docroot\" size=\"30\" value=\"".$docroot."\" ".($is_default_docroot ? 'disabled="disabled" ' : '')."/>
74
+    </td>
75
+    <td id=\"defaultdocroot\">{$defaultdocroot}</td></tr>
76
+    <tr><td>PHP</td>
77
+    <td><select name=\"php\" id=\"php\">
78
+      <option value=\"none\" ".($vhost['php'] == NULL ? 'selected="selected"' : '')." >kein PHP</option>
79
+      <option value=\"mod_php\" ".($vhost['php'] == 'mod_php' ? 'selected="selected"' : '')." >als Apache-Modul</option>
80
+      <option value=\"fastcgi\" ".($vhost['php'] == 'fastcgi' ? 'selected="selected"' : '')." >FastCGI</option>
81
+    </select>
82
+    </td>
83
+    <td id=\"defaultphp\">als Apache-Modul</td></tr>
84
+    <tr>
85
+      <td>Logfiles</td>
86
+      <td><select name=\"logtype\" id=\"logtype\">
87
+      <option value=\"none\" ".($vhost['logtype'] == NULL ? 'selected="selected"' : '')." >keine Logfiles</option>
88
+      <option value=\"anonymous\" ".($vhost['logtype'] == 'anonymous' ? 'selected="selected"' : '')." >anonymisiert</option>
89
+      <option value=\"default\" ".($vhost['logtype'] == 'default' ? 'selected="selected"' : '')." >vollständige Logfile</option>
90
+    </select>
91
+    </td>
92
+    <td id=\"defaultlogtype\">keine Logfiles</td></tr>
93
+    ";
25 94
 
26
-$form .= '</table>';
27
-output(html_form('vhosts_edit_vhost', 'save.php', '', $form));
95
+$form .= '</table>
96
+  <p><input type="submit" value="Änderungen speichern" />&nbsp;&nbsp;&nbsp;&nbsp;'.internal_link('vhosts.php', 'Ohne Speichern zurück').'</p>
97
+';
98
+output(html_form('vhosts_edit_vhost', 'save.php', 'action=edit&vhost='.$vhost['id'], $form));
28 99
 
29 100
 
30 101
 ?>
... ...
@@ -9,7 +9,7 @@ require_once('class/domain.php');
9 9
 function list_vhosts()
10 10
 {
11 11
   $uid = (int) $_SESSION['userinfo']['uid'];
12
-  $result = db_query("SELECT id,fqdn,docroot,docroot_is_default,php,options FROM vhosts.v_vhost WHERE uid={$uid}");
12
+  $result = db_query("SELECT id,fqdn,docroot,docroot_is_default,php,options FROM vhosts.v_vhost WHERE uid={$uid} ORDER BY domain,hostname");
13 13
   $ret = array();
14 14
   while ($item = mysql_fetch_assoc($result))
15 15
     array_push($ret, $item);
... ...
@@ -17,7 +17,28 @@ function list_vhosts()
17 17
 }
18 18
 
19 19
 
20
-function domainselect($selected = NULL)
20
+function empty_vhost()
21
+{
22
+  $vhost['hostname'] = '';
23
+  
24
+  $domainlist = get_domain_list($_SESSION['customerinfo']['customerno'],
25
+                                $_SESSION['userinfo']['uid']);
26
+  $dom = $domainlist[0];
27
+
28
+  $vhost['domain_id'] = $dom->id;
29
+  $vhost['domain'] = $dom->fqdn;
30
+  
31
+  $vhost['homedir'] = $_SESSION['userinfo']['homedir'];
32
+  $vhost['docroot'] = NULL;
33
+  $vhost['php'] = 'mod_php';
34
+  $vhost['logtype'] = NULL;
35
+    
36
+  $vhost['options'] = '';
37
+  return $vhost;
38
+}
39
+
40
+
41
+function domainselect($selected = NULL, $selectattribute = '')
21 42
 {
22 43
   global $domainlist;
23 44
   if ($domainlist == NULL)
... ...
@@ -25,7 +46,7 @@ function domainselect($selected = NULL)
25 46
                                   $_SESSION['userinfo']['uid']);
26 47
   $selected = (int) $selected;
27 48
 
28
-  $ret = '<select name="domain" size="1">';
49
+  $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
29 50
   foreach ($domainlist as $dom)
30 51
   {
31 52
     $s = '';
... ...
@@ -62,6 +83,37 @@ function get_aliases($vhost)
62 83
   return $ret;
63 84
 }
64 85
 
86
+function delete_vhost($id)
87
+{
88
+  $id = (int) $id;
89
+  if ($id == 0)
90
+    system_failure("id == 0");
91
+  $vhost = get_vhost_details($id);
92
+  db_query("DELETE FROM vhosts.vhost WHERE id={$vhost['id']} LIMIT 1");
93
+}
94
+
95
+function save_vhost($vhost)
96
+{
97
+  if (! is_array($vhost))
98
+    system_failure('$vhost kein array!');
99
+  $id = (int) $vhost['id'];
100
+  $hostname = maybe_null($vhost['hostname']);
101
+  $domain = (int) $vhost['domainid'];
102
+  if ($domain == 0)
103
+    system_failure("Domain == 0");
104
+  $docroot = maybe_null($vhost['docroot']);
105
+  $php = maybe_null($vhost['php']);
106
+  $logtype = maybe_null($vhost['logtype']);
107
+  $options = mysql_real_escape_string( $vhost['options'] );
108
+
109
+  if ($id != 0)
110
+    db_query("UPDATE vhosts.vhost SET hostname={$hostname}, domain={$domain}, docroot={$docroot}, php={$php}, logtype={$logtype}, options='{$options}' WHERE id={$id} LIMIT 1");
111
+  else
112
+    db_query("INSERT INTO vhosts.vhost (user, hostname, domain, docroot, php, logtype, options) VALUES ({$_SESSION['userinfo']['uid']}, {$hostname}, {$domain}, {$docroot}, {$php}, {$logtype}, '{$options}')");
113
+  
114
+}
115
+
116
+
65 117
 
66 118
 
67 119
 ?>
... ...
@@ -6,7 +6,7 @@ $role = $_SESSION['role'];
6 6
 
7 7
 if ($role & ROLE_SYSTEMUSER)
8 8
 {
9
-    $menu["vhosts_vhosts"] = array("label" => "Webserver (VHosts)", "file" => "vhosts.php", "weight" => 1);
9
+    $menu["vhosts_vhosts"] = array("label" => "Subdomains", "file" => "vhosts.php", "weight" => 1);
10 10
 }
11 11
 
12 12
 if (empty($menu))
... ...
@@ -0,0 +1,130 @@
1
+<?php
2
+
3
+require_once('session/start.php');
4
+
5
+require_once('vhosts.php');
6
+
7
+require_once('inc/security.php');
8
+require_once('class/domain.php');
9
+
10
+require_role(ROLE_SYSTEMUSER);
11
+
12
+require_once("inc/debug.php");
13
+global $debugmode;
14
+
15
+
16
+if ($_GET['action'] == 'edit')
17
+{
18
+  check_form_token('vhosts_edit_vhost');
19
+  $id = (int) $_GET['vhost'];
20
+  $vhost = empty_vhost();
21
+  if ($id != 0)
22
+    $vhost = get_vhost_details( $id );
23
+  DEBUG($vhost);
24
+
25
+  $hostname = filter_input_hostname($_POST['hostname']);
26
+  $domain = new Domain( (int) $_POST['domain'] );
27
+  if ($domain->useraccount != $_SESSION['userinfo']['uid'])
28
+    system_failure('Ungültige Domain');
29
+
30
+
31
+  if (! is_array($_POST['options']))
32
+    $_POST['options'] = array();
33
+  $aliaswww = in_array('aliaswww', $_POST['options']);
34
+
35
+  $defaultdocroot = $vhost['homedir'].'/websites/'.((strlen($hostname) > 0) ? $hostname.'.' : '').($domain->fqdn).'/htdocs';
36
+
37
+  if (! check_path( $_POST['docroot'] ))
38
+    system_failure("Eingegebener Pfad enthält ungültige Angaben");
39
+  $docroot = $vhost['homedir'].'/'.$_POST['docroot'];
40
+
41
+  if (($_POST['use_default_docroot'] == '1') || ($docroot == $defaultdocroot)) {
42
+    $docroot = '';
43
+  }
44
+
45
+  DEBUG("Document-Root: ".$docroot);
46
+
47
+  $php = '';
48
+  switch ($_POST['php']) {
49
+    case 'mod_php':
50
+      $php = 'mod_php';
51
+      break;
52
+    case 'fastcgi':
53
+      $php = 'fastcgi';
54
+      break;
55
+    /* Wenn etwas anderes kommt, ist das "kein PHP". So einfach ist das. */
56
+  }
57
+
58
+  $logtype = '';
59
+  switch ($_POST['logtype']) {
60
+    case 'anonymous':
61
+      $logtype = 'anonymous';
62
+      break;
63
+    case 'default':
64
+      $logtype = 'default';
65
+      break;
66
+    /* Wenn etwas anderes kommt, ist das "kein Logging". So einfach ist das. */
67
+  }
68
+
69
+  DEBUG("PHP: {$php} / Logging: {$logtype}");
70
+
71
+  $old_options = explode(',', $vhost['options']);
72
+  $new_options = array();
73
+  foreach ($old_options AS $op)
74
+  {
75
+    if ($op != 'aliaswww')
76
+      array_push($new_options, $op);
77
+  }
78
+  if ($aliaswww)
79
+    array_push($new_options, 'aliaswww');
80
+
81
+  DEBUG($old_options);
82
+  DEBUG($new_options);
83
+  $options = implode(',', $new_options);
84
+  DEBUG('New options: '.$options);
85
+
86
+  $vhost['hostname'] = $hostname;
87
+  $vhost['domainid'] = $domain->id;
88
+  $vhost['docroot'] = $docroot;
89
+  $vhost['php'] = $php;
90
+  $vhost['logtype'] = $logtype;
91
+    
92
+  $vhost['options'] = $options;
93
+    
94
+  save_vhost($vhost);
95
+
96
+  if (! $debugmode)
97
+    header('Location: vhosts.php');
98
+
99
+}
100
+elseif ($_GET['action'] == 'delete')
101
+{
102
+  $vhost = get_vhost_details( (int) $_GET['vhost'] );
103
+  $vhost_string = ((strlen($vhost['hostname']) > 0) ? $vhost['hostname'].'.' : '').$vhost['domain'];
104
+  
105
+  $sure = user_is_sure();
106
+  if ($sure === NULL)
107
+  {
108
+    are_you_sure("action=delete&amp;vhost={$_GET['vhost']}", "Möchten Sie die Subdomain »{$vhost_string}« wirklich löschen?");
109
+  }
110
+  elseif ($sure === true)
111
+  {
112
+    delete_vhost($vhost['id']);
113
+    if (! $debugmode)
114
+      header("Location: vhosts.php");
115
+  }
116
+  elseif ($sure === false)
117
+  {
118
+    if (! $debugmode)
119
+      header("Location: vhosts.php");
120
+  }
121
+
122
+  /* TODO */
123
+}
124
+else
125
+  system_failure("Unimplemented action");
126
+
127
+output('');
128
+
129
+
130
+?>
... ...
@@ -22,12 +22,10 @@ if (count($vhosts) > 0)
22 22
   foreach ($vhosts as $vhost)
23 23
   {
24 24
     $fqdn = $vhost['fqdn'];
25
-    if (strstr($vhost['options'], 'aliaswww'))
26
-      $fqdn = 'www.'.$vhost['fqdn'];
27 25
     output("<tr><td>".internal_link('edit.php', $fqdn, "vhost={$vhost['id']}")."</td><td>");
28 26
     $aliases = get_aliases($vhost['id']);
29 27
     if (strstr($vhost['options'], 'aliaswww'))
30
-      output($vhost['fqdn'].'<br />');
28
+      output('www.'.$vhost['fqdn'].'<br />');
31 29
     foreach ($aliases as $alias)
32 30
     {
33 31
       if (strstr($alias['options'], 'aliaswww'))
... ...
@@ -36,7 +34,7 @@ if (count($vhosts) > 0)
36 34
     }
37 35
     output('</td>');
38 36
     if ($vhost['docroot_is_default'] == 1)
39
-      output("<td>{$vhost['docroot']}</td>");
37
+      output("<td><span style=\"color:#777;\">{$vhost['docroot']}</span></td>");
40 38
     else
41 39
       output("<td><strong>{$vhost['docroot']}</strong></td>");
42 40
     $php = $vhost['php'];
... ...
@@ -52,9 +50,13 @@ if (count($vhosts) > 0)
52 50
         $php = 'FastCGI';
53 51
         break;
54 52
     }
55
-    output("<td>{$php}</td></tr>");
53
+    output("<td>{$php}</td>
54
+    <td>".internal_link('save.php', 'Subdomain löschen', 'action=delete&vhost='.$vhost['id'] )."</td>
55
+    </tr>");
56 56
   }
57
-  output('</table><br />');
57
+  output('</table>
58
+<p><a href="edit.php">Neue Subdomain anlegen</a></p>
59
+  <br />');
58 60
 }
59 61
 
60 62
 
61 63