}
function check_db($dbcheck)
{
$select = "SELECT host, user FROM mysql.user ORDER BY host, user";
$result = mysql_query($select);
$rows = @mysql_num_rows($result);
# Errors
if (!isset($rows)) return -1;
if ($rows == 0) return 0;
table_grants_header($dbcheck);
while ($row = mysql_fetch_array($result))
table_grants($row{"host"}, $row{"user"}, $dbcheck);
table_grants_tail();
}
function normal_operations()
{
global $server, $lang, $self;
global $strReloadMySQL, $strGo;
global $strHostEmpty, $strUserEmpty, $strPasswordEmpty;
global $strPasswordNotSame, $strAddUserMessage, $strRememberReload;
global $strDatabase, $strHost, $strAnyHost, $strUserName;
global $strAnyUser, $strPassword, $strNoPassword, $strReType;
global $strPrivileges, $strAddUser, $strCheckDbPriv;
?>
}
function grant_operations()
{
global $server, $lang, $user, $host;
global $dbgrant, $tablegrant;
global $self;
global $strBack, $strGo;
global $strDbEmpty, $strTableEmpty;
global $strAddPriv, $strAddPrivMessage;
global $strDatabase, $strAnyDatabase;
global $strTable, $strAnyTable;
global $strColumn, $strAnyColumn, $strColumnEmpty;
?>
}
function table_grants_header($dbcheck = false) {
global $cfgBorder;
global $strAction;
global $strHost, $strUser, $strDatabase, $strColumn;
global $strTable, $strPrivileges, $strGrantOption;
echo "
\n
";
if ($dbcheck) {
echo "
$strAction";
echo "
$strHost
";
echo "
$strUser
";
} else {
echo "
$strAction";
}
echo "
$strDatabase
";
echo "
$strTable
";
echo "
$strPrivileges
";
if (!$dbcheck) echo "
$strGrantOption
";
echo "
\n";
}
function table_grants_tail() {
echo "
\n";
}
function table_grants($host, $user, $dbcheck = false)
{
global $cfgBgcolorOne, $cfgBgcolorTwo;
global $server, $lang, $db, $table;
global $self;
global $strEdit, $strDelete, $strAny, $strAll, $strYes, $strNo;
global $strRevoke, $strRevokePriv, $strRevokeGrant;
global $strRevokeMessage, $strRevokeGrantMessage;
global $strNoPrivileges;
$select = "SHOW GRANTS FOR '$user'@'$host'";
$result = mysql_query($select);
$rows = @mysql_num_rows($result);
# Errors
if (!isset($rows)) return -1;
if ($rows == 0) return 0;
$i = 0;
while ($row = mysql_fetch_row($result)) {
if (preg_match("/GRANT (.*) ON ([^\.]+).([^\.]+) TO .*$/i", $row[0], $parts)) {
$priv = $parts[1];
$db = $parts[2];
$table = trim($parts[3]);
$grantopt = eregi("WITH GRANT OPTION$", $row[0]);
} else {
$db = " ";
$table = " ";
$column = " ";
$priv = "";
$grantopt = false;
}
if ($priv == "USAGE") $priv = "";
# Checking the database ...
if ($dbcheck)
if (!eregi($dbcheck . "|\*", $db) || (trim($priv) == "")) continue;
# Password Line
if ((trim($priv) == "") && !$grantopt) continue;
if (!$dbcheck && !($show_header++)) table_grants_header();
$bgcolor = $cfgBgcolorOne;
$i % 2 ? 0: $bgcolor = $cfgBgcolorTwo;
# Revoke
$query = "server=$server&lang=$lang&db=mysql&table=user";
$revoke_url = "sql.php3";
$revoke_url .= "?sql_query=".urlencode("REVOKE $priv ON $db.$table FROM '$user'@'$host'");
$revoke_url .= "&$query";
$revoke_url .= "&zero_rows=" . urlencode("$strRevokeMessage $user@$host");
$revoke_url .= "&goto=$self";
# Revoke GRANT OPTION
$revoke_grant_url = "sql.php3";
$revoke_grant_url .= "?sql_query=".urlencode("REVOKE GRANT OPTION ON $db.$table FROM '$user'@'$host'");
$revoke_grant_url .= "&$query";
$revoke_grant_url .= "&zero_rows=" . urlencode("$strRevokeGrantMessage $user@$host");
$revoke_grant_url .= "&goto=$self";
?>
}
function edit_operations($host, $user)
{
global $server, $lang;
global $self;
global $strBack, $strGo;
global $strDelPassMessage, $strRememberReload, $strUpdatePassMessage;
global $strUpdatePrivMessage, $strRememberReload;
global $strPasswordEmpty, $strPasswordNotSame;
global $strDeletePassword, $strUpdatePassword, $strEditPrivileges;
global $strPassword, $strReType;
$result = mysql_query("SELECT * FROM mysql.user WHERE user = '$user' and host = '$host'");
$rows = @mysql_num_rows($result);
# Errors
if (!isset($rows)) return -1;
if ($rows == 0) return 0;
$row = mysql_fetch_array($result);
#Delete Password
$del_url = "sql.php3";
$del_url .= "?sql_query=" . urlencode("UPDATE user SET password = '' WHERE user = '$user' and host = '$host'");
$del_url .= "&zero_rows=" . urlencode("$strDelPassMessage $user@$host $strRememberReload");
$del_url .= "&server=$server&lang=$lang&db=mysql&table=user";
$del_url .= "&goto=$self";
?>