Browse code

Neue MySQL-Verwaltung

Bernd Wurst authored on28/02/2013 15:51:12
Showing11 changed files
1 1
new file mode 100644
2 2
Binary files /dev/null and b/images/comment.png differ
... ...
@@ -243,7 +243,7 @@ function generate_form_token($form_id)
243 243
 function check_form_token($form_id, $formtoken = NULL)
244 244
 {
245 245
   if ($formtoken == NULL)
246
-    $formtoken = $_POST['formtoken'];
246
+    $formtoken = $_REQUEST['formtoken'];
247 247
   $sessid = session_id();
248 248
   if ($sessid == "") 
249 249
   {
250 250
deleted file mode 100644
... ...
@@ -1,230 +0,0 @@
1
-<?php
2
-/*
3
-This file belongs to the Webinterface of schokokeks.org Hosting
4
-
5
-Written 2008-2013 by schokokeks.org Hosting, namely
6
-  Bernd Wurst <bernd@schokokeks.org>
7
-  Hanno Böck <hanno@schokokeks.org>
8
-
9
-To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
-
11
-You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
-http://creativecommons.org/publicdomain/zero/1.0/
13
-
14
-Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
-*/
16
-
17
-require_once('session/start.php');
18
-require_once('inc/icons.php');
19
-require_role(array(ROLE_SYSTEMUSER));
20
-
21
-global $prefix;
22
-
23
-require_once('mysql.php');
24
-
25
-$output_something = true;
26
-
27
-
28
-if (isset($_GET['action']))
29
-  switch ($_GET['action'])
30
-  {
31
-    case 'delete_db':
32
-      if (! has_mysql_database($_GET['db']))
33
-        system_failure('Ungültige Datenbank');
34
-      $sure = user_is_sure();
35
-      if ($sure === NULL)
36
-      {
37
-        are_you_sure("action=delete_db&db={$_GET['db']}", "Möchten Sie die Datenbank »{$_GET['db']}« wirklich löschen?");
38
-        $output_something = false;
39
-      }
40
-      elseif ($sure === true)
41
-      {
42
-        delete_mysql_database($_GET['db']);
43
-        header("Location: ?");
44
-        $output_something = false;
45
-      }
46
-      elseif ($sure === false)
47
-      {
48
-        header("Location: ?");
49
-        $output_something = false;
50
-      }
51
-      break;
52
-    case 'delete_user':
53
-      if (! has_mysql_user($_GET['user']))
54
-        system_failure('Ungültiger Benutzer');
55
-      $sure = user_is_sure();
56
-      if ($sure === NULL)
57
-      {
58
-        are_you_sure("action=delete_user&user={$_GET['user']}", "Möchten Sie den Benutzer »{$_GET['user']}« wirklich löschen?");
59
-        $output_something = false;
60
-      }
61
-      elseif ($sure === true)
62
-      {
63
-        delete_mysql_account($_GET['user']);
64
-        header("Location: ?");
65
-        $output_something = false;
66
-      }
67
-      elseif ($sure === false)
68
-      {
69
-        header("Location: ?");
70
-        $output_something = false;
71
-      }
72
-      break;
73
-    case 'change_pw':
74
-      check_form_token('mysql_databases');
75
-      set_mysql_password($_POST['mysql_username'], $_POST['mysql_password']);
76
-      header("Location: ?");
77
-      $output_something = false;
78
-      break;
79
-    default:
80
-      system_failure("Diese Funktion scheint noch nicht eingebaut zu sein!");
81
-  }
82
-
83
-
84
-$dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
85
-$users = get_mysql_accounts($_SESSION['userinfo']['uid']);
86
-
87
-if (isset($_POST['accesseditor']))
88
-{
89
-  check_form_token('mysql_databases');
90
-  /* Eine neue Datenbank */
91
-  if ($_POST['new_db'] != '')
92
-  {
93
-    create_mysql_database($_POST['new_db']);
94
-    if (isset($_POST['access']['new']))
95
-    {
96
-      $_POST['access'][$_POST['new_db']] = array();
97
-      foreach ($users as $user) {
98
-        $user = $user['username'];
99
-        if (in_array($user, $_POST['access']['new'])) {
100
-          array_push($_POST['access'][$_POST['new_db']], $user);
101
-        }
102
-      }
103
-      if (($_POST['new_user'] != '') and (in_array('new', $_POST['access']['new'])))
104
-        array_push($_POST['access'][$_POST['new_db']], $_POST['new_user']);
105
-    }
106
-  }
107
-
108
-  /* Ein neuer Account soll angelegt werden */
109
-  if ($_POST['new_user'] != '')
110
-  {
111
-    create_mysql_account($_POST['new_user']);
112
-    foreach ($dbs as $db) {
113
-      $db = $db['name'];
114
-      if (isset($_POST['access'][$db]) and (in_array('new', $_POST['access'][$db]))) {
115
-        array_push($_POST['access'][$db], $_POST['new_user']);
116
-      }
117
-    }
118
-  }
119
-  
120
-  if (($_POST['new_user'] != '') or ($_POST['new_db'] != ''))
121
-  {
122
-    $dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
123
-    $users = get_mysql_accounts($_SESSION['userinfo']['uid']);
124
-  }
125
-
126
-  foreach ($dbs as $db)
127
-  {
128
-    $db = $db['name'];
129
-    foreach ($users as $user)
130
-    {
131
-      $user = $user['username'];
132
-      if (! isset($_POST['access'][$db]))
133
-        set_mysql_access($db, $user, false);
134
-      else
135
-        set_mysql_access($db, $user, in_array($user, $_POST['access'][$db]));
136
-    }
137
-  }
138
-  $mysql_access = NULL;
139
-}
140
-
141
-if ($output_something)
142
-{
143
-  title("MySQL-Datenbanken");
144
-  output('<p>Hier können Sie Ihre MySQL-Datenbanken verwalten. Die Einstellungen werden mit einer leichten Verzögerung (maximal 5 Minuten) in das System übertragen. Bitte beachten Sie, dass neue Zugänge also nicht umgehend funktionieren.</p>
145
-  <p><strong>Hinweis:</strong> In dieser Matrix sehen Sie links die Datenbanken und oben die Benutzer, die Sie eingerichtet haben.
146
-  In die leeren Eingabefelder können Sie den Namen eines neuen Benutzers bzw. einer neuen Datenbank eintragen. Sofern Sie noch keine Datenbank(en) oder Benutzer eingerichtet haben, erscheinen nur die Eingabefelder. Vergessen Sie nicht, nach der Erstellung eines neuen Benutzerkontos dem betreffenden Benutzer ein Passwort zu setzen (s. unten auf dieser Seite). Der Name von Datenbanken und Datenbank-Benutzern muss mit dem Namen des System-Benutzeraccounts übereinstimmen oder mit diesem und einem nachfolgenden Unterstrich beginnen. Z.B. kann der System-Benutzer <em>bernd</em> die MySQL-Accounts <em>bernd</em> und <em>bernd_2</em> erzeugen. Aufgrund einer Beschränkung des MySQL-Servers dürfen Benutzernamen allerdings zur Zeit nur 16 Zeichen lang sein.</p>');
147
-
148
-  $form = '
149
-  <table>
150
-  <tr><th>&#160;</th><th style="background-color: #729bb3; color: #fff;padding: 0.2em;" colspan="'.(count($users)+1).'">Benutzerkonten</th></tr>
151
-  <tr><th style="background-color: #729bb3; color: #fff;padding: 0.2em; text-align: left;">Datenbanken</th>';
152
-
153
-  foreach ($users as $user)
154
-  {
155
-    $username = $user["username"];
156
-    //$username = str_replace('_', '_ ', $user['username']);
157
-    $desc = ($user['description'] ? $user['description'].' (Erstellt: '.$user['created'].')' : 'Erstellt: '.$user['created']);
158
-    $form .= "<th><span title=\"{$desc}\">{$username}</span><br />".internal_link("", icon_delete("Benutzer »{$user['username']}« löschen"), "action=delete_user&user={$user['username']}")."</th>";
159
-  }
160
-  $form .= '<th><input type="text" name="new_user" size="10" value="" /><br />'.icon_add().'</th></tr>
161
-';
162
-
163
-  array_push($users, array('username' => "new", 'description' => NULL));
164
-
165
-  $servers = servers_for_databases();
166
-
167
-  foreach($dbs as $db)
168
-  {
169
-    $phpmyadmin = "https://mysql.{$servers[$db['name']]}/";
170
-    $desc = ($db['description'] ? $db['description'].' (Erstellt: '.$db['created'].')' : 'Erstellt: '.$db['created']);
171
-    $form .= "<tr><td style=\"border: 0px; font-weight: bold; text-align: right;\"><span title=\"{$desc}\">{$db['name']}</span>&#160;".internal_link("", icon_delete("Datenbank »{$db['name']}« löschen"), "action=delete_db&db={$db['name']}")."&#160;<a href=\"".$phpmyadmin."\">".other_icon("database_go.png", "Datenbank-Verwaltung über phpMyAdmin")."</a></td>";
172
-    foreach ($users as $user)
173
-      $form .= '<td style="text-align: center;"><input type="checkbox" id="'.$db['name'].'_'.$user['username'].'" name="access['.$db['name'].'][]" value="'.$user['username'].'" '.(get_mysql_access($db['name'], $user['username']) ? 'checked="checked" ' : '')." /></td>";
174
-    $form .= "</tr>\n";
175
-  }
176
-
177
-  $form .= '
178
-  <tr><td style="border: 0px; font-weight: bold; text-align: right;"><input type="text" name="new_db" size="15" value="" />'.icon_add().'</td>';
179
-  foreach ($users as $user)
180
-    $form .= '<td style="text-align: center;"><input type="checkbox" id="new_'.$user['username'].'" name="access[new][]" value="'.$user['username'].'" /></td>';
181
-  $form .= '</tr>
182
-  </table>
183
-  <p><input type="submit" name="accesseditor" value="Speichern" /></p>';
184
-
185
-  
186
-  output(html_form('mysql_databases', 'databases', '', $form));
187
-
188
-  $myservers = array();
189
-  foreach ($servers as $s) {
190
-    if (! in_array($s, $myservers)) {
191
-      $myservers[] = $s;
192
-    }
193
-  }
194
-
195
-  output("<h4>Verwaltung der Datenbanken (phpMyAdmin)</h4>
196
-  <p><img src=\"{$prefix}images/phpmyadmin.png\" style=\"width: 120px; height: 70px; float: right;\" />Zur Verwaltung der Datenbank-Inhalte stellen wir Ihnen eine stets aktualisierte Version von phpMyAdmin zur Verfügung.</p>");
197
-  if (count($myservers) == 1) {
198
-    output("<p><strong><a href=\"https://mysql.{$myservers[0]}/\">phpMyAdmin aufrufen</a></strong></p>");
199
-  }
200
-  else {
201
-    output("<p><em>Ihre Datenbanken befinden sich auf unterschiedlichen Servern, daher müssen Sie die jeweils passende Adresse für phpMyAdmin benutzen. Klicken Sie auf das Symbol ".other_icon("database_go.png", "Datenbank-Verwaltung über phpMyAdmin")." oben neben der jeweiligen Datenbank.</em></p>");
202
-  }
203
-
204
-
205
-  $users = get_mysql_accounts($_SESSION['userinfo']['uid']);
206
-
207
-
208
-
209
-  $my_users = array();
210
-  foreach ($users as $u)
211
-  {
212
-    $my_users[$u['username']] = $u['username'];
213
-  }
214
-  $form = '<div>
215
-  <label for="mysql_username">Benutzername:</label>&#160;'.html_select('mysql_username', $my_users).'
216
-  &#160;&#160;&#160;
217
-  <label for="password">Passwort:</label>&#160;<input type="password" name="mysql_password" id="password" />
218
-  &#160;&#160;<input type="submit" value="Setzen" />
219
-</div>';
220
-
221
-
222
-  output('<h4>Passwort ändern</h4>
223
-  <p>Hier können Sie das Passwort eines MySQL-Benutzeraccounts ändern bzw. neu setzen</p>
224
-
225
-  '.html_form('mysql_databases', 'databases', 'action=change_pw', $form).'<br />');
226
-
227
-}
228
-
229
-
230
-?>
231 0
new file mode 100644
... ...
@@ -0,0 +1,58 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2013 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('session/start.php');
18
+require_once('inc/icons.php');
19
+require_role(array(ROLE_SYSTEMUSER));
20
+
21
+global $prefix;
22
+
23
+require_once('mysql.php');
24
+
25
+$dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
26
+$users = get_mysql_accounts($_SESSION['userinfo']['uid']);
27
+$username = $_SESSION['userinfo']['username'];
28
+
29
+$section = 'mysql_overview';
30
+title('Beschreibung ändern');
31
+
32
+if (isset($_GET['db'])) {
33
+  $thisdb = NULL;
34
+  foreach ($dbs as $db) {
35
+    if ($db['name'] == $_GET['db']) {
36
+      $thisdb = $db;
37
+    }
38
+  }
39
+  $form = '<p>Ändern Sie hier die Beschreibung der Datenbank <strong>'.$thisdb['name'].'</strong>.</p>';
40
+  $form .= '<p><input type="text" name="description" value="'.$thisdb['description'].'" /></p>
41
+<p><input type="submit" value="Speichern" /></p>';
42
+  output(html_form('mysql_description', 'save', "action=description&db={$thisdb['name']}", $form));
43
+}
44
+if (isset($_GET['username'])) {
45
+  $thisuser = NULL;
46
+  foreach ($users as $user) {
47
+    if ($user['username'] == $_GET['username']) {
48
+      $thisuser = $user;
49
+    }
50
+  }
51
+  $form = '<p>Ändern Sie hier die Beschreibung der Datenbank <strong>'.$thisuser['username'].'</strong>.</p>';
52
+  $form .= '<p><input type="text" name="description" value="'.$thisuser['description'].'" /></p>
53
+<p><input type="submit" value="Speichern" /></p>';
54
+  output(html_form('mysql_description', 'save', "action=description&username={$thisuser['username']}", $form));
55
+}
56
+
57
+
58
+
... ...
@@ -17,7 +17,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
17 17
 function get_mysql_accounts($UID)
18 18
 {
19 19
   $UID = (int) $UID;
20
-  $result = db_query("SELECT username, description, created FROM misc.mysql_accounts WHERE useraccount=$UID ORDER BY username");
20
+  $result = db_query("SELECT id, username, description, created FROM misc.mysql_accounts WHERE useraccount=$UID ORDER BY username");
21 21
   if (mysql_num_rows($result) == 0)
22 22
     return array();
23 23
   $list = array();
... ...
@@ -42,6 +42,37 @@ function get_mysql_databases($UID)
42 42
   return $list;
43 43
 }
44 44
 
45
+function set_database_description($dbname, $description) 
46
+{
47
+  $dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
48
+  $thisdb = NULL;
49
+  foreach ($dbs as $db) {
50
+    if ($db['name'] == $dbname) {
51
+      $thisdb = $db;
52
+    }
53
+  }
54
+  if ($thisdb == NULL) {
55
+    system_failure('Ungültige Datenbank');
56
+  }
57
+  $description = maybe_null(filter_input_general($description));
58
+  db_query("UPDATE misc.mysql_database SET description={$description} WHERE id={$thisdb['id']}");
59
+}
60
+
61
+function set_dbuser_description($username, $description) 
62
+{
63
+  $users = get_mysql_accounts($_SESSION['userinfo']['uid']);
64
+  $thisuser = NULL;
65
+  foreach ($users as $user) {
66
+    if ($user['username'] == $username) {
67
+      $thisuser = $user;
68
+    }
69
+  }
70
+  if ($thisuser == NULL) {
71
+    system_failure('Ungültiger Benutzer');
72
+  }
73
+  $description = maybe_null(filter_input_general($description));
74
+  db_query("UPDATE misc.mysql_accounts SET description={$description} WHERE id={$thisuser['id']}");
75
+}
45 76
 
46 77
 function servers_for_databases()
47 78
 {
... ...
@@ -136,7 +167,7 @@ function delete_mysql_account($username)
136 167
 }
137 168
 
138 169
 
139
-function create_mysql_database($dbname, $description = '')
170
+function create_mysql_database($dbname, $description = '', $server = NULL)
140 171
 {
141 172
   if (! validate_mysql_dbname($dbname))
142 173
   {
... ...
@@ -146,9 +177,13 @@ function create_mysql_database($dbname, $description = '')
146 177
   }
147 178
   $dbname = mysql_real_escape_string($dbname);
148 179
   $uid = $_SESSION['userinfo']['uid'];
149
-  $description = maybe_null($description);
180
+  $description = maybe_null($description); 
181
+  $server = (int) $server;
182
+  if (! in_array($server, additional_servers()) || ($server == my_server_id())) {
183
+    $server = 'NULL';
184
+  }
150 185
   logger(LOG_INFO, "modules/mysql/include/mysql", "mysql", "creating database »{$dbname}«");
151
-  db_query("INSERT INTO misc.mysql_database (name, useraccount, description) VALUES ('$dbname', $uid, $description);");
186
+  db_query("INSERT INTO misc.mysql_database (name, useraccount, server, description) VALUES ('$dbname', $uid, $server, $description);");
152 187
 }
153 188
 
154 189
 
... ...
@@ -18,7 +18,7 @@ $role = $_SESSION['role'];
18 18
 
19 19
 if ($role & ROLE_SYSTEMUSER)
20 20
 {
21
-  $menu["mysql_databases"] = array("label" => "MySQL-Datenbank", "file" => "databases", "weight" => 20);
21
+  $menu["mysql_overview"] = array("label" => "MySQL-Datenbank", "file" => "overview", "weight" => 20);
22 22
     
23 23
 }
24 24
 ?>
25 25
new file mode 100644
... ...
@@ -0,0 +1,78 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2013 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('session/start.php');
18
+require_once('inc/icons.php');
19
+require_role(array(ROLE_SYSTEMUSER));
20
+
21
+global $prefix;
22
+
23
+require_once('mysql.php');
24
+
25
+$dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
26
+$users = get_mysql_accounts($_SESSION['userinfo']['uid']);
27
+$username = $_SESSION['userinfo']['username'];
28
+
29
+$section = 'mysql_overview';
30
+title('Neue MySQL-Datenbank');
31
+
32
+$dbnames = array();
33
+foreach ($dbs as $db) {
34
+  $dbnames[] = $db['name'];
35
+}
36
+
37
+$suggestion = $username.'_1';
38
+$count = 2;
39
+while (in_array($suggestion, $dbnames)) {
40
+  $suggestion = $username.'_'.$count;
41
+  $count++;
42
+}
43
+
44
+$form = '<h4>Name der neuen Datenbank</h4>
45
+<input type="text" name="newdb" value="'.$suggestion.'" />
46
+<p>Bitte nur Kleinbuchstaben, Zahlen und Unterstrich verwenden. Der Datenbankname muss mit dem Benutzernamen beginnen.</p>
47
+<p><label for="description">Optionale Beschreibung dieser Datenbank:</label> <input type="text" name="description" id="description" /></p>
48
+';
49
+if (count(additional_servers()) > 0) {
50
+  $form .= '<h4>Server</h4>';
51
+  $form .= '<p>Auf welchem Server soll diese Datenbank eingerichtet werden?</p>';
52
+  $available_servers = additional_servers();
53
+  $available_servers[] = my_server_id();
54
+  $available_servers = array_unique($available_servers);
55
+  
56
+  $selectable_servers = array();
57
+  $all_servers = server_names();
58
+  foreach ($all_servers as $id => $fqdn) {
59
+    if (in_array($id, $available_servers)) {
60
+      $selectable_servers[$id] = $fqdn;
61
+    }
62
+  }
63
+  $form .= html_select('server', $selectable_servers, my_server_id());
64
+  $form .= '<p>Alle Benutzer die auf diese Datenbank zugreifen dürfen, werden automatisch auf dem passenden Server eingerichtet</p>';
65
+}
66
+if (count($users) > 0) {
67
+  $form .= '<h4>Berechtigungen</h4>';
68
+  $form .= '<p>Welche der bisher vorhandenen Datenbank-Benutzer dürfen auf diese Datenbank zugreifen?</p>';
69
+  foreach ($users as $user) {
70
+    $form .= '<p><input type="checkbox" id="access_'.$user['username'].'" name="access[]" value="'.$user['username'].'" /> <label for="access_'.$user['username'].'">'.$user['username'].'</label></p>';
71
+  }
72
+}
73
+ 
74
+$form .= '<p><input type="submit" name="submit" value="Speichern"/><p>';
75
+
76
+
77
+output(html_form('mysql_newdb', 'save', 'action=newdb', $form));
78
+
0 79
new file mode 100644
... ...
@@ -0,0 +1,94 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2013 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('session/start.php');
18
+require_once('inc/icons.php');
19
+require_role(array(ROLE_SYSTEMUSER));
20
+
21
+global $prefix;
22
+
23
+require_once('mysql.php');
24
+
25
+$dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
26
+$users = get_mysql_accounts($_SESSION['userinfo']['uid']);
27
+$username = $_SESSION['userinfo']['username'];
28
+
29
+$section = 'mysql_overview';
30
+title('Neuer MySQL-Benutzer');
31
+
32
+
33
+html_header('
34
+<script type="text/javascript">
35
+
36
+  function makePasswd() {
37
+    var passwd = \'\';
38
+    var chars = \'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\';
39
+    for (i=0; i<15; i++) {
40
+      var c = Math.floor(Math.random()*chars.length + 1);
41
+      passwd += chars.charAt(c)
42
+    }
43
+    return passwd;
44
+  }
45
+
46
+  function setRandomPassword() 
47
+  {
48
+    pass = makePasswd();
49
+    document.getElementById(\'newpass\').value = pass;
50
+    document.getElementById(\'newpass_display\').value = pass;
51
+    document.getElementById(\'newpass_display\').parentNode.style.display = \'block\';
52
+  }
53
+</script>');
54
+
55
+
56
+$usernames = array();
57
+foreach ($users as $user) {
58
+  $usernames[] = $user['username'];
59
+}
60
+
61
+$suggestion = $username;
62
+$count = 1;
63
+while (in_array($suggestion, $usernames)) {
64
+  $suggestion = $username.'_'.$count;
65
+  $count++;
66
+}
67
+
68
+$form = '<h4>Benutzername</h4>
69
+<input type="text" name="newuser" value="'.$suggestion.'" maxlength="16" />
70
+<p>Bitte nur Kleinbuchstaben, Zahlen und Unterstrich verwenden. Der Benutzername muss mit Ihrem System-Benutzernamen beginnen.</p>
71
+<p>Aufgrund einer Einschränkung des MySQL-Servers dürfen Benutzernamen nur maximal 16 Zeichen lang sein.</p>
72
+<p><label for="description">Optionale Beschreibung dieses Benutzers:</label> <input type="text" name="description" id="description" /></p>
73
+<h4>Passwort</h4>
74
+<input onchange="document.getElementById(\'newpass_display\').parentNode.style.display=\'none\'" type="password" name="newpass" id="newpass" value="" /> <button type="button" onclick="setRandomPassword()">Passwort erzeugen</button>
75
+<p style="display: none;">Automatisch erzeugtes Passwort: <input id="newpass_display" type="text" readonly="readonly" /></p>
76
+<h4>Berechtigungen</h4>';
77
+if (count($dbs) > 0) {
78
+  $form .= '<p>Auf welche der bisher vorhandenen Datenbanken darf dieser Benutzer zugreifen?</p>';
79
+  foreach ($dbs as $db) {
80
+    $desc = '';
81
+    if ($db['description']) {
82
+      $desc = ' - <em>'.$db['description'].'</em>';
83
+    }
84
+    $form .= '<p><input type="checkbox" id="access_'.$db['name'].'" name="access[]" value="'.$db['name'].'" /> <label for="access_'.$db['name'].'">'.$db['name'].$desc.'</label></p>';
85
+  }
86
+} else {
87
+  $form .= '<p><em>Bisher gibt es noch keine Datenbanken.</em></p>';
88
+}
89
+ 
90
+$form .= '<p><input type="submit" name="submit" value="Speichern"/><p>';
91
+
92
+
93
+output(html_form('mysql_newuser', 'save', 'action=newuser', $form));
94
+
0 95
new file mode 100644
... ...
@@ -0,0 +1,129 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2013 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('session/start.php');
18
+require_once('inc/icons.php');
19
+require_role(array(ROLE_SYSTEMUSER));
20
+
21
+global $prefix;
22
+
23
+require_once('mysql.php');
24
+
25
+$dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
26
+$users = get_mysql_accounts($_SESSION['userinfo']['uid']);
27
+
28
+  title("MySQL-Datenbanken");
29
+  output('<p>Hier können Sie den Zugriff auf Ihre MySQL-Datenbanken verwalten. Die Einstellungen werden mit einer leichten Verzögerung (maximal 5 Minuten) in das System übertragen. Bitte beachten Sie, dass neue Zugänge also nicht umgehend funktionieren.</p>
30
+  <p><strong>Hinweis:</strong> In dieser Matrix sehen Sie links die Datenbanken und oben die Benutzer, die Sie eingerichtet haben. In der Übersicht ist dargestellt, welcher Benutzer auf welche Datenbank Zugriff erhält. Klicken Sie auf die Symbole um die Zugriffsrechte zu ändern.</p>');
31
+
32
+  $form = '
33
+  <table>
34
+  <tr><th>&#160;</th><th style="background-color: #729bb3; color: #fff;padding: 0.2em;" colspan="'.(count($users)+1).'">Benutzerkonten</th></tr>
35
+  <tr><th style="background-color: #729bb3; color: #fff;padding: 0.2em; text-align: left;">Datenbanken</th>';
36
+
37
+  foreach ($users as $user)
38
+  {
39
+    $username = $user["username"];
40
+    //$username = str_replace('_', '_ ', $user['username']);
41
+    $desc = '';
42
+    if ($user['description']) {
43
+      $desc = '<br /><span style="font-weight: normal; font-size: 80%; font-style: italic;">'.$user['description'].'</span>';
44
+    } 
45
+    $form .= "<th><span title=\"Erstellt: {$user['created']}\">{$username}</span>".$desc;
46
+    $form .= "<br />".internal_link('description', other_icon("comment.png", 'Beschreibung ändern'), "username={$username}")."&#160;";
47
+    $form .= internal_link("save", icon_delete("Benutzer »{$user['username']}« löschen"), "action=delete_user&user={$user['username']}")."</th>";
48
+  }
49
+
50
+  $servers = servers_for_databases();
51
+
52
+  $formtoken = generate_form_token('mysql_permchange');
53
+
54
+  foreach($dbs as $db)
55
+  {
56
+    $phpmyadmin = "https://mysql.{$servers[$db['name']]}/";
57
+    $desc = '';
58
+    if ($db['description']) {
59
+      $desc = '<br /><span style="font-weight: normal; font-size: 80%; font-style: italic;">'.$db['description'].'</span>';
60
+    } 
61
+    $form .= "<tr><td style=\"border: 0px; font-weight: bold; text-align: right;\"><span title=\"Erstellt: {$db['created']}\">{$db['name']}</span>&#160;";
62
+    $form .= internal_link('description', other_icon("comment.png", 'Datenbank-Beschreibung ändern'), "db={$db['name']}")."&#160;";
63
+    $form .= internal_link("save", icon_delete("Datenbank »{$db['name']}« löschen"), "action=delete_db&db={$db['name']}")."&#160;";
64
+    $form .= "<a href=\"".$phpmyadmin."\">".other_icon("database_go.png", "Datenbank-Verwaltung über phpMyAdmin")."</a>";
65
+    $form .= "{$desc}</td>";
66
+    foreach ($users as $user) {
67
+      $form .= '<td style="text-align: center;">';
68
+      if (get_mysql_access($db['name'], $user['username'])) {
69
+        $form .= internal_link('save', icon_enabled('Zugriff erlaubt; Anklicken zum Ändern'), "action=permchange&user={$user['username']}&db={$db['name']}&access=0&formtoken={$formtoken}");
70
+      } else {
71
+        $form .= internal_link('save', icon_disabled('Zugriff verweigern; Anklicken zum Ändern'), "action=permchange&user={$user['username']}&db={$db['name']}&access=1&formtoken={$formtoken}");
72
+      }
73
+      
74
+    }
75
+    $form .= "</tr>\n";
76
+  }
77
+
78
+  $form .= '
79
+  </table>';
80
+
81
+  
82
+  output(html_form('mysql_databases', 'databases', '', $form));
83
+
84
+  addnew('newdb', 'Neue Datenbank');
85
+  addnew('newuser', 'Neuer DB-Benutzer');
86
+
87
+
88
+  $myservers = array();
89
+  foreach ($servers as $s) {
90
+    if (! in_array($s, $myservers)) {
91
+      $myservers[] = $s;
92
+    }
93
+  }
94
+
95
+  output("<h4>Verwaltung der Datenbanken (phpMyAdmin)</h4>
96
+  <p><img src=\"{$prefix}images/phpmyadmin.png\" style=\"width: 120px; height: 70px; float: right;\" />Zur Verwaltung der Datenbank-Inhalte stellen wir Ihnen eine stets aktualisierte Version von phpMyAdmin zur Verfügung.</p>");
97
+  if (count($myservers) == 1) {
98
+    output("<p><strong><a href=\"https://mysql.{$myservers[0]}/\">phpMyAdmin aufrufen</a></strong></p>");
99
+  }
100
+  else {
101
+    output("<p><em>Ihre Datenbanken befinden sich auf unterschiedlichen Servern, daher müssen Sie die jeweils passende Adresse für phpMyAdmin benutzen. Klicken Sie auf das Symbol ".other_icon("database_go.png", "Datenbank-Verwaltung über phpMyAdmin")." oben neben der jeweiligen Datenbank.</em></p>");
102
+  }
103
+
104
+
105
+  $users = get_mysql_accounts($_SESSION['userinfo']['uid']);
106
+
107
+
108
+
109
+  $my_users = array();
110
+  foreach ($users as $u)
111
+  {
112
+    $my_users[$u['username']] = $u['username'];
113
+  }
114
+  $form = '<div>
115
+  <label for="mysql_username">Benutzername:</label>&#160;'.html_select('mysql_username', $my_users).'
116
+  &#160;&#160;&#160;
117
+  <label for="password">Passwort:</label>&#160;<input type="password" name="mysql_password" id="password" />
118
+  &#160;&#160;<input type="submit" value="Setzen" />
119
+</div>';
120
+
121
+
122
+  output('<h4>Passwort ändern</h4>
123
+  <p>Hier können Sie das Passwort eines MySQL-Benutzeraccounts ändern bzw. neu setzen</p>
124
+
125
+  '.html_form('mysql_databases', 'save', 'action=change_pw', $form).'<br />');
126
+
127
+
128
+
129
+?>
0 130
new file mode 100644
... ...
@@ -0,0 +1,151 @@
1
+<?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2013 by schokokeks.org Hosting, namely
6
+  Bernd Wurst <bernd@schokokeks.org>
7
+  Hanno Böck <hanno@schokokeks.org>
8
+
9
+To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12
+http://creativecommons.org/publicdomain/zero/1.0/
13
+
14
+Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15
+*/
16
+
17
+require_once('session/start.php');
18
+require_once('inc/icons.php');
19
+require_role(array(ROLE_SYSTEMUSER));
20
+
21
+global $prefix;
22
+
23
+require_once('mysql.php');
24
+
25
+if (isset($_GET['action']) && $_GET['action'] == 'permchange') {
26
+  check_form_token('mysql_permchange');
27
+  set_mysql_access($_GET['db'], $_GET['user'], ($_GET['access'] == 1));
28
+  redirect('overview');
29
+}
30
+
31
+if (isset($_GET['action']) && $_GET['action'] == 'newdb') {
32
+  check_form_token('mysql_newdb');
33
+  $dbname = $_POST['newdb'];
34
+  $desc = $_POST['description'];
35
+  $server = NULL;
36
+  if (isset($_POST['server'])) {
37
+    $server = $_POST['server'];
38
+  }
39
+  create_mysql_database($dbname, $desc, $server);
40
+  if (isset($_POST['access'])) {
41
+    foreach ($_POST['access'] as $user) {
42
+      set_mysql_access($dbname, $user, true);
43
+    }
44
+  }
45
+  redirect('overview');
46
+}
47
+
48
+if (isset($_GET['action']) && $_GET['action'] == 'newuser') {
49
+  check_form_token('mysql_newuser');
50
+  $username = $_POST['newuser'];
51
+  $desc = $_POST['description'];
52
+  $password = $_POST['newpass'];
53
+  create_mysql_account($username, $desc);
54
+  set_mysql_password($username, $password);
55
+  if (isset($_POST['access'])) {
56
+    foreach ($_POST['access'] as $dbname) {
57
+      set_mysql_access($dbname, $username, true);
58
+    }
59
+  }
60
+  redirect('overview');
61
+}
62
+
63
+if (isset($_GET['action']) && $_GET['action'] == 'description') {
64
+  check_form_token('mysql_description');
65
+  if (isset($_GET['db'])) {
66
+    $db = $_GET['db'];
67
+    $description = $_POST['description'];
68
+    set_database_description($db, $description);
69
+  }
70
+  if (isset($_GET['username'])) {
71
+    $user = $_GET['username'];
72
+    $description = $_POST['description'];
73
+    set_dbuser_description($user, $description);
74
+  }
75
+  redirect('overview');
76
+}
77
+
78
+
79
+if (isset($_GET['action'])) {
80
+  switch ($_GET['action'])
81
+  {
82
+    case 'delete_db':
83
+      if (! has_mysql_database($_GET['db']))
84
+        system_failure('Ungültige Datenbank');
85
+      $sure = user_is_sure();
86
+      if ($sure === NULL)
87
+      {
88
+        are_you_sure("action=delete_db&db={$_GET['db']}", "Möchten Sie die Datenbank »{$_GET['db']}« wirklich löschen?");
89
+      }
90
+      elseif ($sure === true)
91
+      {
92
+        delete_mysql_database($_GET['db']);
93
+        redirect('overview');
94
+      }
95
+      elseif ($sure === false)
96
+      {
97
+        redirect('overview');
98
+      }
99
+      break;
100
+    case 'delete_user':
101
+      if (! has_mysql_user($_GET['user']))
102
+        system_failure('Ungültiger Benutzer');
103
+      $sure = user_is_sure();
104
+      if ($sure === NULL)
105
+      {
106
+        are_you_sure("action=delete_user&user={$_GET['user']}", "Möchten Sie den Benutzer »{$_GET['user']}« wirklich löschen?");
107
+      }
108
+      elseif ($sure === true)
109
+      {
110
+        delete_mysql_account($_GET['user']);
111
+        redirect('overview');
112
+      }
113
+      elseif ($sure === false)
114
+      {
115
+        redirect('overview');
116
+      }
117
+      break;
118
+    case 'change_pw':
119
+      check_form_token('mysql_databases');
120
+      set_mysql_password($_POST['mysql_username'], $_POST['mysql_password']);
121
+      redirect('overview');
122
+      break;
123
+    default:
124
+      system_failure("Diese Funktion scheint noch nicht eingebaut zu sein!");
125
+  }
126
+}
127
+
128
+$dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
129
+$users = get_mysql_accounts($_SESSION['userinfo']['uid']);
130
+
131
+if (isset($_POST['accesseditor']))
132
+{
133
+  check_form_token('mysql_databases');
134
+  
135
+  foreach ($dbs as $db)
136
+  {
137
+    $db = $db['name'];
138
+    foreach ($users as $user)
139
+    {
140
+      $user = $user['username'];
141
+      if (! isset($_POST['access'][$db]))
142
+        set_mysql_access($db, $user, false);
143
+      else
144
+        set_mysql_access($db, $user, in_array($user, $_POST['access'][$db]));
145
+    }
146
+  }
147
+  $mysql_access = NULL;
148
+}
149
+
150
+
151
+?>
... ...
@@ -17,7 +17,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
17 17
 if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
18 18
   $shortcuts[] = array( 'section' => 'Datenbank', 
19 19
                         'weight'  => 20, 
20
-                        'file'    => 'databases', 
20
+                        'file'    => 'overview', 
21 21
                         'icon'    => 'mysql.png', 
22 22
                         'title'   => 'MySQL-Datenbanken',
23 23
                         'alert'   => NULL );