This is an admin utility to let you manage mysql users from a web page. It works for me.. I've fixed a number of bugs since 1.0, but it's still not very efficient code, and probably still has bugs.
<html>
<head>
<title>MySQL Administration</title>
<h2><center><i>SQL User Administrator</i></center></h2>
<body>
<p>
<?
//------------------------------------------------------
//
// PHP MySQL Administrator 1.1
// By Jeff Buck
// (jeffb@usmicro.com)
//
// No Rights Reserved, do whatever you want with it.
// Just don't blame me for anything that goes wrong.
//
//
// Set up some variables.
// Edit these to match your configuration.
//
//------------------------------------------------------
//------------------------------------------------------
//
// Login Function.
// Asks for username and password.
//
//------------------------------------------------------
Function Login () {
global $pagename;
echo "
<b>Please enter your login information:<p>
<FORM METHOD=POST ACTION=$pagename>
Please enter your login name: <INPUT TYPE=TEXT NAME=user><p>
Please enter your password: <INPUT TYPE=PASSWORD NAME=password><p>
<INPUT TYPE=HIDDEN NAME=mode VALUE=Menu>
<center><INPUT TYPE=SUBMIT VALUE=Login></center>";
}
//------------------------------------------------------
//
// The Main Menu.
// The main screen where all the user information
// is entered. This is called from the login
// screen with no values set (except defaults) or
// from the "update" buttons using the
// "autofill" function.
//
//------------------------------------------------------
Function Menu () {
global $password,$user,
$SCRIPT_NAME, $dbdefault, $hostdefault, $autofill, $radio_opt,
$victim, $host, $database,
$Select_priv, $Insert_priv,
$Update_priv, $Delete_priv,
$Create_priv, $Drop_priv,
$Shutdown_priv, $Process_priv,
$Reload_priv, $File_priv;
<input type=submit value=\"UPDATE THIS USER NOW\" width=535 color=#ffffff>
</center></form>";
}
//------------------------------------------------------
//
// Basic error checking. the "pw" variable is set
// before the functions are run to let this
// function know if it needs to verify password
// information or not. If a null is entered for
// something that has a default, the default is
// set again (user removed it from form).
//
//------------------------------------------------------
if ( "$victim" == "" ) { die ( "Casper doesn't need an update!"); }
if ( "$database" == "" ) { $database = "$dbdefault"; }
if ( "$host" == "" ) { $host = "$hostdefault"; }
if ( "$pw" == "1" ) {
if ( "$pw1" != "$pw2" ) { die ( "Passwords don't match, try again"); }
if ( "$pw1" == "" ) { die ( "If you don't want passwords, change the source code.<p>
Otherwise come back when you've got one!"); }
}
//------------------------------------------------------
//
// Displays the mysql user table with
// buttons for update and delete.
// When feeding it user information for it's
// query, use "%" for a wildcard.
//
//------------------------------------------------------
Function show_user ($victim, $host) {
global $user, $password, $pagename;
@mysql_select_db( "mysql");
// Determine what query to run.
if ( "$victim" == "%" ) {
if ( "$host" == "%" ) { $result=mysql_query( "select * from user"); }
else { $result=mysql_query( "select * from user where host = \"$host\" "); }
}
elseif ( "$host" == "%" ) { $result=mysql_query( "select * from user where user = \"$vitcim\" "); }
else { $result=mysql_query( "select * from user where user = \"$victim\" and host = \"$host\" "); }
//------------------------------------------------------
//
// Displays the mysql DB table with
// buttons for update and delete.
// When feeding it user information for it's
// query, use "%" for a wildcard.
//
//------------------------------------------------------
Function show_db ($victim, $host) {
global $user, $password, $pagename;
@mysql_select_db( "mysql");
// Determine what query to run.
if ( "$victim" == "%") {
if ( "$host" == "%") { $result=mysql_query( "select * from db"); }
else { $result=mysql_query( "select * from db where host = \"$host\" "); }
}
elseif ( "$host" == "%") { $result=mysql_query( "select * from db where user = \"$vitcim\" "); }
else { $result = mysql_query( "select * from db where user = \"$victim\" and host = \"$host\" "); }
//------------------------------------------------------
//
// This function is the main add function (the
// quick add option). It puts user information into
// the main user table (password etc), but gives
// the user no global rights. It then gives the
// user rights for the specified database.
// This is just for convenience, you could do the
// same thing with g_add and then a d_add.
//
//------------------------------------------------------
//------------------------------------------------------
//
// Delete a user/host from every table
//
//------------------------------------------------------
Function g_delete () {
global $user, $password, $server, $victim, $host, $database;
checknclean ();
mysql_connect($server,$user,$password);
mysql( "mysql", "delete from user where user = \"$victim\" and host = \"$host\" ");
mysql( "mysql", "delete from db where user = \"$victim\" and host = \"$host\" ");
Reload_Tables();
echo "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>";
show_user( "%", "%");
echo "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>";
show_db( "%", "%");
echo "The user $victim@$host has been deleted the user";
}
//------------------------------------------------------
//
// Delete a user/host from a particular database.
//
//------------------------------------------------------
Function d_delete () {
global $user, $password, $server, $victim, $host, $database;
checknclean ();
mysql_connect($server,$user,$password);
mysql( "mysql", "delete from db where user = \"$victim\" and host = \"$host\" ");
Reload_Tables();
echo "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>";
show_user( "%", "%");
echo "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>";
show_db( "%", "%");
echo "The user $victim@$host has been deleted the user";
}
//------------------------------------------------------
//
// Add a global user. (user table only)
//
//------------------------------------------------------
//------------------------------------------------------
//
// Add a user to a database. (db table only)
//
//------------------------------------------------------
//------------------------------------------------------
//
// Global Display Function:
// Display full user and db tables.
//
//------------------------------------------------------
//------------------------------------------------------
//
// The footer printed at the bottem of the page
//
//------------------------------------------------------
//------------------------------------------------------
//
// This is the help information page.
//
//------------------------------------------------------
Function help () {
echo "
<center>
<h2><b><i>Administration Help Page</h2></b></i>
</center>
<p>
<ul><li><i> Note: This page is not a substitute for knowing how
mysql permissions work.<p><b>Warning: The admin utility
doesn't include any \"Are you sure?\" prompts. Be sure
of what you are doing before you click to submit.
This utility was written with administrators in mind,
and wasn't meant to be used by the average user.</b>
</ul></li></i><p>
<hr>
<h2>User Commands:</h2><p>
<li>Quick Add User</li><p>
<ul><ul><i>This option adds a user to both the USER table and the
DATABASE (db) table. In the USER table, they are given absolutely
no permissions by default, and the permissions that were checked
on the user information page, are applied only to the
database specified. If no database was specified, then the
default database is used.</ul></ul></i><p>
<li>Add Globally</li><p>
<ul><ul><i>This option adds the user to the USER table only. Any
permissions granted here are good for *all* databases. Additional
rights for any given database can be given with the Add for
Database option. Every user/host pair *must* have a listing here
since password information for the paris is stored here.</i></ul></ul><p>
<li>Add to Database</li><p>
<ul><ul><i>This will add permissions for a user/host pair to a
particular database.</i></ul></ul><p>
<li>Modify Globally</li><p>
<ul><ul><i>Modifies a user's global (user table) settings. Leave the
password boxes both blank to retain the user's previous
password.</i></ul></ul><p>
<li>Modify for Database</li><p>
<ul><ul>Modifies a user's permissions for a particular database.</ul></ul><p>
<li>Delete Globally</li><p>
<ul><ul><i>Deletes the user/host pair from both the USER and
DATABASE tables. </i></ul></ul><p>
<li>Username</li><p>
<ul><ul><i>This is the username of the user to be added or
modified</ul></ul></i><p>
<li>Password/Confirm</li><p>
<ul><ul><i>This is the password and the confirmation for the user.
If you are modifying the user, but don't want to change their
password, then just leave both of these blank.</ul></ul></i><p>
<li>Host</li><p>
<ul><ul><i>This is the host that the user is allowed to connect
from. If you set this to \"%\" it is a wildcard. Use only
\"localhost\" if you don't want users to be able to connect
direclty to the sql server from elseware. This will allow
scripts/programs running on the mysql server to access it
but nothing else.</ul></ul></i><p>
<li>Database</li><p>
<ul><ul><i>This is the database that the rights are given for.
Note: Global rights are good for *any* database, so it may
be easiest to set up global accounts for passwords but with
no rights configured, and then add users to individual
databases as needed.</ul></ul></i><p>
<li>*_priv</li><p>
<ul><ul><i>These are the sql operations allowed for the
database or globally for that user.</ul></ul></i><p>
";
}
//
// Main Loop
//
// if pw is set to 1, then the function will
// know to perform password matching verification
// and test to make sure it's not null.
switch ($mode) {
case ""; Login ();break;
case "Menu"; Menu (); footer(); break;
case "g-add"; $pw = "1"; g_add (); footer(); break;
case "d-add"; d_add (); footer(); break;
case "g-delete"; g_delete (); footer(); break;
case "d-delete"; d_delete (); footer(); break;
case "g-modify"; g_modify (); footer(); break;
case "d-modify"; d_modify (); footer(); break;
case "add"; $pw = "1"; add (); footer(); break;
case "help"; help (); footer(); break;
case "delete"; delete (); footer(); break;
case "g-display"; g_display (); footer(); break;