diff --git a/connect.inc.php b/connect.inc.php
index ded979f1..66126524 100644
--- a/connect.inc.php
+++ b/connect.inc.php
@@ -1,5 +1,5 @@
select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]))) {
+if (!(strlen($_GET["db"]) ? $mysql->select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]) || isset($_GET["privileges"]))) {
if (strlen($_GET["db"])) {
unset($_SESSION["databases"][$_GET["server"]]);
}
@@ -9,6 +9,7 @@ if (!(strlen($_GET["db"]) ? $mysql->select_db($_GET["db"]) : isset($_GET["sql"])
} else {
page_header(lang('Select database'), null);
echo '
' . lang('Create new database') . "
\n";
+ echo '' . lang('Privileges') . "
\n";
echo '' . lang('Process list') . "
\n";
echo "" . lang('MySQL version') . ": $mysql->server_info " . lang('through PHP extension') . " " . (extension_loaded("mysqli") ? "MySQLi" : (extension_loaded("mysql") ? "MySQL" : "PDO")) . "
\n";
}
diff --git a/design.inc.php b/design.inc.php
index 95662ee4..354ccd0c 100644
--- a/design.inc.php
+++ b/design.inc.php
@@ -9,7 +9,7 @@ function page_header($title, $breadcrumb = array(), $title2 = "") {
-
+
@@ -32,7 +32,7 @@ function page_header($title, $breadcrumb = array(), $title2 = "") {
}
foreach ($breadcrumb as $key => $val) {
if (strlen($val)) {
- echo '' . htmlspecialchars($val) . ' > ';
+ echo '' . htmlspecialchars($val) . ' > ';
}
}
}
diff --git a/index.php b/index.php
index 53cc465b..9dd63f12 100644
--- a/index.php
+++ b/index.php
@@ -83,6 +83,8 @@ if (isset($_GET["dump"])) {
include "./procedure.inc.php";
} elseif (isset($_GET["trigger"])) {
include "./trigger.inc.php";
+ } elseif (isset($_GET["privileges"])) {
+ include "./privileges.inc.php";
} elseif (isset($_GET["processlist"])) {
include "./processlist.inc.php";
} else {
diff --git a/privileges.inc.php b/privileges.inc.php
new file mode 100644
index 00000000..22918a6a
--- /dev/null
+++ b/privileges.inc.php
@@ -0,0 +1,90 @@
+ lang('Privileges')));
+ $privileges = array();
+ $result = $mysql->query("SHOW PRIVILEGES");
+ while ($row = $result->fetch_assoc()) {
+ foreach (explode(",", $row["Context"]) as $context) {
+ $privileges[$context][$row["Privilege"]] = $row["Comment"]; //! translation
+ }
+ }
+ $result->free();
+ $privileges["Server Admin"] += $privileges["File access on server"];
+ $privileges["Databases"]["Create routine"] = $privileges["Procedures"]["Create routine"];
+ $privileges["Columns"] = array();
+ foreach (array("Select", "Insert", "Update", "References") as $val) {
+ $privileges["Columns"][$val] = $privileges["Tables"][$val];
+ }
+ unset($privileges["Server Admin"]["Usage"]);
+ unset($privileges["Procedures"]["Create routine"]);
+ unset($privileges["Functions"]["Create routine"]);
+ $grants = array();
+ if (strlen($_GET["privileges"]) && ($result = $mysql->query("SHOW GRANTS FOR '" . $mysql->escape_string($_GET["name"]) . "'@'" . $mysql->escape_string($_GET["privileges"]) . "'"))) { //! Use information_schema for MySQL 5 - column names in column privileges are not escaped
+ while ($row = $result->fetch_row()) {
+ if (preg_match('~GRANT (.*) ON (.*) TO ~', $row[0], $match)) { //! escape part between ON and TO
+ preg_match_all('~ *([^(,]*[^ ,(])( *\\([^)]+\\))?~', $match[1], $matches, PREG_SET_ORDER);
+ foreach ($matches as $val) {
+ $grants["$match[2]$val[2]"][$val[1]] = true;
+ }
+ }
+ if (preg_match('~ WITH GRANT OPTION~', $row[0])) { //! don't check inside strings and identifiers
+ $grants[$match[2]]["GRANT OPTION"] = true;
+ }
+ }
+ $result->free();
+ }
+ $grants[""] = true;
+
+ foreach (array(
+ "Server Admin" => lang('Server'),
+ "Databases" => lang('Database'),
+ "Tables" => lang('Table'),
+ "Columns" => lang('Column'),
+ "Procedures" => lang('Procedure'),
+ "Functions" => lang('Function'),
+ ) as $key => $val) {
+ if ($privileges[$key]) {
+ echo "\n";
+ }
+ }
+ //! DROP USER, name, server, password
+} else {
+ page_header(lang('Privileges'));
+ echo '' . lang('Create user') . "
\n";
+ //! use mysql database if possible (GRANTEE not properly escaped) or CURRENT_USER in MySQL 4 in case of insufficient privileges
+ $result = $mysql->query("SELECT DISTINCT GRANTEE FROM information_schema.USER_PRIVILEGES");
+ echo "\n";
+ echo " " . lang('Username') . " " . lang('Server') . " \n";
+ while ($row = $result->fetch_row()) {
+ preg_match("~'((?:[^']+|'')*)'@'((?:[^']+|'')+)'~", $row[0], $match);
+ echo '' . lang('edit') . ' ' . htmlspecialchars(str_replace("''", "'", $match[1])) . " " . htmlspecialchars(str_replace("''", "'", $match[2])) . " \n";
+ }
+ echo "
\n";
+ $result->free();
+}