home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / mysqluserman.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  30.6 KB  |  859 lines

  1. MySQL User Manager by Jeff Buck 
  2.  
  3. This is an admin utility to let you manage mysql users from a web page. Fixed a number of bugs since 1.0, but it's still not very efficient code, and probably still has bugs. 
  4.  
  5.  
  6.  
  7. <html> 
  8. <head> 
  9. <title>MySQL Administration</title> 
  10. <h2><center><i>SQL User Administrator</i></center></h2> 
  11. <body> 
  12. <p> 
  13.  
  14. <? 
  15.  
  16. //------------------------------------------------------ 
  17. // 
  18. //    PHP MySQL Administrator 1.1 
  19. //    By Jeff Buck  
  20. //    (jeffb@usmicro.com) 
  21. // 
  22. //    No Rights Reserved, do whatever you want with it. 
  23. //    Just don't blame me for anything that goes wrong. 
  24. // 
  25. // 
  26. //    Set up some variables.  
  27. //    Edit these to match your configuration. 
  28. // 
  29. //------------------------------------------------------ 
  30.  
  31. $server= "your.sql.server.com"; 
  32. $pagename= "phpadmin.phtml"; 
  33. $dbdefault= "defaultdb"; 
  34. $hostdefault= "localhost"; 
  35. $mysqladmin= "/usr/local/bin/mysqladmin"; 
  36.  
  37. //------------------------------------------------------ 
  38. // 
  39. //    Reload Tables Function. 
  40. //    Asks for username and password. 
  41. // 
  42. //------------------------------------------------------ 
  43.  
  44. Function Reload_Tables () { 
  45. global $user, $password, $mysqladmin; 
  46.  
  47. exec( "$mysqladmin --user=$user --password=$password reload"); 
  48.  
  49.  
  50.  
  51. //------------------------------------------------------ 
  52. // 
  53. //    Login Function. 
  54. //    Asks for username and password. 
  55. // 
  56. //------------------------------------------------------ 
  57.  
  58. Function Login () { 
  59. global $pagename; 
  60. echo  " 
  61. <b>Please enter your login information:<p> 
  62. <FORM METHOD=POST ACTION=$pagename> 
  63. Please enter your login name: <INPUT TYPE=TEXT NAME=user><p> 
  64. Please enter your password: <INPUT TYPE=PASSWORD NAME=password><p> 
  65. <INPUT TYPE=HIDDEN NAME=mode VALUE=Menu> 
  66. <center><INPUT TYPE=SUBMIT VALUE=Login></center>"; 
  67.  
  68.  
  69. //------------------------------------------------------ 
  70. // 
  71. //    The Main Menu. 
  72. //    The main screen where all the user information 
  73. //    is entered. This is called from the login 
  74. //    screen with no values set (except defaults) or 
  75. //    from the "update" buttons using the 
  76. //    "autofill" function. 
  77. // 
  78. //------------------------------------------------------ 
  79.  
  80. Function Menu () { 
  81. global  $password,$user, 
  82.         $SCRIPT_NAME, $dbdefault, $hostdefault, $autofill, $radio_opt, 
  83.     $victim, $host, $database, 
  84.     $Select_priv, $Insert_priv, 
  85.     $Update_priv, $Delete_priv, 
  86.     $Create_priv, $Drop_priv, 
  87.     $Shutdown_priv, $Process_priv, 
  88.     $Reload_priv, $File_priv; 
  89.  
  90. $bgcolor= "#ddddff"; 
  91. $bgadmin= "#bbbbbb"; 
  92. $tbcolor= "#000080"; 
  93.  
  94. if (  "$autofill" ==  "Y" ) { 
  95.     if (  "$Select_priv" ==  "Y" ) { $Select_priv= "checked"; } else { $Select_priv= ""; } 
  96.     if (  "$Insert_priv" ==  "Y" ) { $Insert_priv= "checked"; } else { $Insert_priv= ""; } 
  97.     if (  "$Update_priv" ==  "Y" ) { $Update_priv= "checked"; } else { $Update_priv= ""; } 
  98.     if (  "$Delete_priv" ==  "Y" ) { $Delete_priv= "checked"; } else { $Delete_priv= ""; } 
  99.     if (  "$Create_priv" ==  "Y" ) { $Create_priv= "checked"; } else { $Create_priv= ""; } 
  100.     if (  "$Drop_priv" ==  "Y" ) { $Drop_priv= "checked"; } else { $Drop_priv= ""; } 
  101.         if (  "$Reload_priv" ==  "Y" ) { $Reload_priv= "checked"; } else { $Reload_priv= ""; } 
  102.         if (  "$Shutdown_priv" ==  "Y" ) { $Shutdown_priv= "checked"; } else { $Shutdown_priv= ""; } 
  103.         if (  "$Process_priv" ==  "Y" ) { $Process_priv= "checked"; } else { $Process_priv= ""; } 
  104.         if (  "$File_priv" ==  "Y" ) { $File_priv= "checked"; } else { $File_priv= ""; } 
  105.     if (  "$radio_opt" ==  "user" ) { $radio_opt_2= "checked"; } 
  106.     if (  "$radio_opt" ==  "db" ) { $radio_opt_3= "checked"; } 
  107.     $hostdefault=$host; 
  108.     $dbdefault=$database; 
  109.     } 
  110. else { 
  111.     $radio_opt_1= "checked"; 
  112.     $Select_priv= "checked"; 
  113.     $Insert_priv= "checked"; 
  114.     $Update_priv= "checked"; 
  115.     $Delete_priv= ""; 
  116.     $Create_priv= ""; 
  117.     $Drop_priv= ""; 
  118.         $Reload_priv= ""; 
  119.         $Shutdown_priv= ""; 
  120.         $Process_priv= ""; 
  121.         $File_priv= ""; 
  122.      }   
  123.  
  124.  
  125. echo  " 
  126. <FORM ACTION=\"$SCRIPT_NAME\" METHOD=POST> 
  127. <INPUT TYPE=HIDDEN NAME=password VALUE=\"$password\"> 
  128. <INPUT TYPE=HIDDEN NAME=user VALUE=\"$user\"> 
  129. <p><center> 
  130.  
  131. <table border=0 cellspacing=0 width=535> 
  132. <tr><td bgcolor=$tbcolor><font color=#ffffff><b>User Commands</font></td><td bgcolor=#009900><INPUT TYPE=RADIO NAME=mode VALUE=add $radio_opt_1><b><i>QUICK ADD USER</td></tr> 
  133. <tr><td bgcolor=#009900><INPUT TYPE=RADIO NAME=mode VALUE=g-add><b><i>ADD GLOBALLY</td> 
  134. <td bgcolor=#009900><INPUT TYPE=RADIO NAME=mode VALUE=d-add><b><i>ADD TO DATABASE</td></tr> 
  135. <tr><td bgcolor=#eeee00><INPUT TYPE=RADIO NAME=mode VALUE=g-modify $radio_opt_2><b><i> MODIFY GLOBALLY</td> 
  136. <td bgcolor=#eeee00><INPUT TYPE=RADIO NAME=mode VALUE=d-modify $radio_opt_3><b><i> MODIFY FOR DATABASE</td></tr> 
  137. <tr><td bgcolor=#dd0000><INPUT TYPE=RADIO NAME=mode VALUE=g-delete><b><i>DELETE GLOBALLY</td> 
  138. <td bgcolor=#dd0000><INPUT TYPE=RADIO NAME=mode VALUE=d-delete><b><i>DELETE FROM DATABASE</td></tr> 
  139. </b></i></table> 
  140.  
  141. <table border=1 cellspacing=0 width=535><tr><td colspan=2 bgcolor=$tbcolor><font color=#ffffff><b>User Definition</b></font></td></tr></table> 
  142. <table border=2 cellspacing=2 width=535> 
  143. <tr><td colspan=2 bgcolor=$bgcolor align=right>USER: <INPUT TYPE=text NAME=victim value=\"$victim\"></td> 
  144. <td colspan=2 bgcolor=$bgcolor align=right>PASS: <input type=password name=pw1></td></tr> 
  145. <tr><td colspan=2 bgcolor=$bgcolor align=right>HOST: <INPUT TYPE=TEXT NAME=host VALUE=\"$hostdefault\"></td> 
  146. <td colspan=2 bgcolor=$bgcolor align=right>CONFIRM: <input type=password name=pw2></td></tr> 
  147. <tr><td colspan=2 bgcolor=$bgcolor align=right>DB: <INPUT TYPE=TEXT NAME=database VALUE=\"$dbdefault\"></td><td colspan=2 bgcolor=$bgcolor align=right><i>For old password leave blank</td</tr> 
  148. </table> 
  149.  
  150. <table border=1 cellspacing=0 width=535><tr><td colspan=2 bgcolor=$tbcolor><font color=#ffffff><b>Basic User Settings</b></font></td></tr></table> 
  151. <table border=2 cellspacing=2 width=535> 
  152. <tr><td colspan=2 bgcolor=$bgcolor><table border=0 cellspacing=0><tr><td>Select:</td><td width=5%><input type=checkbox name=Select_priv value=Y $Select_priv></td></tr></table></td> 
  153.     <td colspan=2 bgcolor=$bgcolor><table border=0 cellspacing=0><tr><td>Delete:</td><td width=5%><input type=checkbox name=Delete_priv value=Y $Delete_priv></td></tr></table></td></tr> 
  154. <tr><td colspan=2 bgcolor=$bgcolor><table border=0 cellspacing=0><tr><td>Insert:</td><td width=5%><input type=checkbox name=Insert_priv value=Y $Insert_priv></td></tr></table></td> 
  155.     <td colspan=2 bgcolor=$bgcolor><table border=0 cellspacing=0><tr><td>Create:</td><td width=5%><input type=checkbox name=Create_priv value=Y $Create_priv></td></tr></table></td></tr> 
  156. <tr><td colspan=2 bgcolor=$bgcolor><table border=0 cellspacing=0><tr><td>Update:</td><td width=5%><input type=checkbox name=Update_priv value=Y $Update_priv></td></tr></table></td> 
  157.     <td colspan=2 bgcolor=$bgcolor><table border=0 cellspacing=0><tr><td>Drop:</td><td width=5%><input type=checkbox name=Drop_priv value=Y $Drop_priv></td></tr></table></td></tr> 
  158. </table> 
  159.  
  160. <table border=1 cellspacing=0 width=535><tr><td colspan=2 bgcolor=$tbcolor><font color=#ffffff><b>Administrative User Settings</b></font></td></tr></table> 
  161. <table border=2 cellspacing=2 width=535> 
  162. <tr><td colspan=2 bgcolor=$bgadmin><table border=0 cellspacing=0><tr><td>Reload:</td><td width=5%><input type=checkbox name=Reload_priv value=Y $Reload_priv></td></tr></table></td> 
  163.     <td colspan=2 bgcolor=$bgadmin><table border=0 cellspacing=0><tr><td>Shutdown:</td><td width=5%><input type=checkbox name=Shutdown_priv value=Y $Shutdown_priv></td></tr></table></td></tr> 
  164. <tr><td colspan=2 bgcolor=$bgadmin><table border=0 cellspacing=0><tr><td>Process:</td><td width=5%><input type=checkbox name=Process_priv value=Y $Process_priv></td></tr></table></td> 
  165.     <td colspan=2 bgcolor=$bgadmin><table border=0 cellspacing=0><tr><td>File:</td><td width=5%><input type=checkbox name=File_priv value=Y $File_priv></td></tr></table></td></tr> 
  166. </table> 
  167.  
  168. <input type=submit value=\"UPDATE THIS USER NOW\" width=535 color=#ffffff> 
  169. </center></form>"; 
  170.  
  171.  
  172. //------------------------------------------------------ 
  173. // 
  174. //    Basic error checking. the "pw" variable is set 
  175. //    before the functions are run to let this 
  176. //    function know if it needs to verify password 
  177. //    information or not. If a null is entered for 
  178. //    something that has a default, the default is 
  179. //    set again (user removed it from form). 
  180. // 
  181. //------------------------------------------------------ 
  182.  
  183. Function checknclean () { 
  184.  
  185. global $victim, $pw1, $pw2, $host, $database, $pw, 
  186.     $hostdefault, $dbdefault,  
  187.     $Select_priv, $Insert_priv, $Update_priv,  
  188.     $Delete_priv, $Create_priv, $Drop_priv, 
  189.     $Reload_priv, $Shutdown_priv, 
  190.     $Process_priv, $File_priv; 
  191.  
  192. if (  "$victim" ==  "" ) { die ( "Casper doesn't need an update!"); } 
  193. if (  "$database" ==  "" ) { $database =  "$dbdefault"; } 
  194. if (  "$host" ==  "" ) { $host =  "$hostdefault"; } 
  195.  
  196. if (  "$pw" ==  "1" ) { 
  197.     if (  "$pw1" !=  "$pw2" ) { die ( "Passwords don't match, try again"); } 
  198.     if (  "$pw1" ==  "" ) { die ( "If you don't want passwords, change the source code.<p> Otherwise come back when you've got one!"); } 
  199.     } 
  200.  
  201. if (  "$Select_priv" !=  "Y" ) { $Select_priv =  "N"; } 
  202. if (  "$Insert_priv" !=  "Y" ) { $Insert_priv =  "N"; } 
  203. if (  "$Update_priv" !=  "Y" ) { $Update_priv =  "N"; } 
  204. if (  "$Delete_priv" !=  "Y" ) { $Delete_priv =  "N"; } 
  205. if (  "$Create_priv" !=  "Y" ) { $Create_priv =  "N"; } 
  206. if (  "$Drop_priv" !=  "Y" ) { $Drop_priv =  "N"; } 
  207. if (  "$Reload_priv" !=  "Y" ) { $Reload_priv =  "N"; } 
  208. if (  "$Shutdown_priv" !=  "Y" ) { $Shutdown_priv =  "N"; } 
  209. if (  "$Process_priv" !=  "Y" ) { $Process_priv =  "N"; } 
  210. if (  "$File_priv" !=  "Y" ) { $File_priv =  "N"; } 
  211.  
  212.  
  213. //------------------------------------------------------ 
  214. // 
  215. //    Displays the mysql user table with 
  216. //    buttons for update and delete. 
  217. //    When feeding it user information for it's 
  218. //    query, use "%" for a wildcard. 
  219. // 
  220. //------------------------------------------------------ 
  221.  
  222. Function show_user ($victim, $host) { 
  223.  
  224. global $user, $password, $pagename; 
  225.      
  226. @mysql_select_db( "mysql"); 
  227.  
  228.  
  229. //    Determine what query to run. 
  230.  
  231. if (  "$victim" ==  "%" ) { 
  232.     if (  "$host" ==  "%" ) { $result=mysql_query( "select * from user"); } 
  233.     else { $result=mysql_query( "select * from user where host = \"$host\" "); } 
  234.     } 
  235. elseif (  "$host" ==  "%" ) { $result=mysql_query( "select * from user where user = \"$vitcim\" "); } 
  236. else { $result=mysql_query( "select * from user where user = \"$victim\" and host = \"$host\" "); } 
  237.  
  238.  
  239. //    Print out the resulting information. 
  240.  
  241. echo  "    <table  border=1><tr><th></th><th></th> 
  242.     <th width=60>Host</th><th width=60>User</th><th>Password</th> 
  243.     <th width=25>Sel</th><th width=25>Ins</th><th width=25>Upd</th> 
  244.     <th width=25>Del</th><th width=25>Crt</th><th width=25>Drp</th> 
  245.     <th width=25>Rld</th><th width=25>Sht</th><th width=25>Ps</th><th>File</th></tr>"; 
  246.  
  247. $counter=0; 
  248. while (@mysql_data_seek($result,$counter)) { 
  249.     $row=mysql_fetch_object($result); 
  250.     $counter++; 
  251.      
  252.      //-------------------------------- 
  253.      // The Update Button 
  254.      //-------------------------------- 
  255.  
  256.     echo  "<tr>     
  257.     <td><form method=post action=$pagename> 
  258.     <input type=hidden name=mode value=\"Menu\"> 
  259.     <input type=hidden name=autofill value=\"Y\"> 
  260.     <input type=hidden name=user value=\"$user\"> 
  261.     <input type=hidden name=password value=\"$password\"> 
  262.     <input type=hidden name=host value=\"$row->Host\"> 
  263.     <input type=hidden name=Select_priv value=\"$row->Select_priv\"> 
  264.     <input type=hidden name=Insert_priv value=\"$row->Insert_priv\"> 
  265.     <input type=hidden name=Update_priv value=\"$row->Update_priv\"> 
  266.     <input type=hidden name=Delete_priv value=\"$row->Delete_priv\"> 
  267.     <input type=hidden name=Create_priv value=\"$row->Create_priv\"> 
  268.     <input type=hidden name=Drop_priv value=\"$row->Drop_priv\"> 
  269.         <input type=hidden name=Reload_priv value=\"$row->Reload_priv\"> 
  270.         <input type=hidden name=Shutdown_priv value=\"$row->Shutdown_priv\"> 
  271.         <input type=hidden name=Process_priv value=\"$row->Process_priv\"> 
  272.         <input type=hidden name=File_priv value=\"$row->File_priv\"> 
  273.         <input type=hidden name=victim value=\"$row->User\"> 
  274.     <input type=hidden name=radio_opt value=\"user\"> 
  275.     <input type=submit value=UPDATE></form></td> 
  276.     "; 
  277.  
  278.      //-------------------------------- 
  279.      // The Delete Button 
  280.      //-------------------------------- 
  281.     echo " 
  282.     <td><form method=post action=$pagename> 
  283.     <input type=hidden name=mode value=\"g-delete\"> 
  284.     <input type=hidden name=user value=\"$user\"> 
  285.     <input type=hidden name=password value=\"$password\"> 
  286.     <input type=hidden name=host value=\"$row->Host\"> 
  287.     <input type=hidden name=victim value=\"$row->User\"> 
  288.     <input type=submit value=DELETE></form></td> 
  289.     "; 
  290.      
  291.      //-------------------------------- 
  292.      // Print table values 
  293.      //-------------------------------- 
  294.      
  295.     for  ($i=0;  $i<mysql_num_fields($result);  $i++)  { 
  296.         echo   "<td><center>"; 
  297.         echo   "$row[$i]"; 
  298.         echo   "</center></td>"; 
  299.         } 
  300.     echo   "</tr>"; 
  301.      } 
  302. echo  "</table>"; 
  303.  
  304.  
  305. //------------------------------------------------------ 
  306. // 
  307. //    Displays the mysql DB table with 
  308. //    buttons for update and delete. 
  309. //    When feeding it user information for it's 
  310. //    query, use "%" for a wildcard. 
  311. // 
  312. //------------------------------------------------------ 
  313.  
  314. Function show_db ($victim, $host) { 
  315.  
  316. global $user, $password, $pagename; 
  317.      
  318.  
  319. @mysql_select_db( "mysql"); 
  320.  
  321.  
  322. //    Determine what query to run. 
  323.  
  324. if ( "$victim" ==  "%") { 
  325.     if ( "$host" ==  "%") { $result=mysql_query( "select * from db"); } 
  326.     else { $result=mysql_query( "select *  from  db where host = \"$host\" "); } 
  327.     } 
  328. elseif ( "$host" ==  "%") { $result=mysql_query( "select * from db where user = \"$vitcim\" "); } 
  329. else { $result = mysql_query( "select * from db where user = \"$victim\" and host = \"$host\" "); } 
  330.  
  331.  
  332. //    Print out the resulting information. 
  333.  
  334.      
  335. echo  "    <table border=1><tr><th></th><th></th> 
  336.     <th width=60>Host</th><th width=60>Db</th><th width=130>User</th> 
  337.     <th width=25>Sel</th><th width=25>Ins</th><th width=25>Upd</th> 
  338.     <th width=25>Del</th><th width=25>Crt</th><th width=25>Drp</th></tr>"; 
  339.  
  340. $counter=0; 
  341.         while (@mysql_data_seek($result,$counter)){ 
  342.         $row=mysql_fetch_object($result); 
  343.     $counter++; 
  344.  
  345.      //-------------------------------- 
  346.      // The Update Button 
  347.      //-------------------------------- 
  348.     echo  "     
  349.     <tr> 
  350.     <td><form method=post action=$pagename> 
  351.     <input type=hidden name=mode value=\"Menu\"> 
  352.     <input type=hidden name=autofill value=\"Y\"> 
  353.     <input type=hidden name=user value=\"$user\"> 
  354.     <input type=hidden name=password value=\"$password\"> 
  355.     <input type=hidden name=host value=\"$row[0]\"> 
  356.     <input type=hidden name=Select_priv value=\"$row->Select_priv\"> 
  357.     <input type=hidden name=Insert_priv value=\"$row->Insert_priv\"> 
  358.     <input type=hidden name=Update_priv value=\"$row->Update_priv\"> 
  359.     <input type=hidden name=Delete_priv value=\"$row->Delete_priv\"> 
  360.     <input type=hidden name=Create_priv value=\"$row-Create_priv\"> 
  361.     <input type=hidden name=Drop_priv value=\"$row->Drop_priv\"> 
  362.     <input type=hidden name=victim value=\"$row->User\"> 
  363.     <input type=hidden name=database value=\"$row->Db\"> 
  364.     <input type=hidden name=radio_opt value=\"db\"> 
  365.     <input type=submit value=UPDATE></form></td> 
  366.     "; 
  367.  
  368.      //-------------------------------- 
  369.      // The Delete Button 
  370.      //-------------------------------- 
  371.     echo " 
  372.     <td><form method=post action=$pagename> 
  373.     <input type=hidden name=mode value=\"d-delete\"> 
  374.     <input type=hidden name=user value=\"$user\"> 
  375.     <input type=hidden name=password value=\"$password\"> 
  376.     <input type=hidden name=host value=\"$row->Host\"> 
  377.     <input type=hidden name=victim value=\"$row->User\"> 
  378.     <input type=hidden name=database value=\"$row->Db\"> 
  379.     <input type=submit value=DELETE></form></td> 
  380.     "; 
  381.      
  382.      //-------------------------------- 
  383.      // Print table values 
  384.      //-------------------------------- 
  385.  
  386.     echo  " 
  387.     <td><center>$row->Host</center></td> 
  388.     <td><center>$row->Db</center></td> 
  389.     <td><center>$row->User</center></td> 
  390.     <td><center>$row->Select_priv</center></td> 
  391.     <td><center>$row->Insert_priv</center></td> 
  392.     <td><center>$row->Update_priv</center></td> 
  393.     <td><center>$row->Delete_priv</center></td> 
  394.     <td><center>$row->Create_priv</center></td> 
  395.     <td><center>$row->Drop_priv</center></td> 
  396.     </tr> 
  397.     "; 
  398. //    for  ($i=0;  $i<mysql_num_fields($result);  $i++)  { 
  399. //        echo  "<td><center>"; 
  400. //        echo  "$row[$i]"; 
  401. //        echo  "</center></td>"; 
  402. //        } 
  403. //    echo  "</tr>\n"; 
  404.      } 
  405. echo  "</table>"; 
  406.  
  407.  
  408.  
  409. //------------------------------------------------------ 
  410. // 
  411. //    This function is the main add function (the  
  412. //    quick add option). It puts user information into 
  413. //    the main user table (password etc), but gives  
  414. //    the user no global rights. It then gives the 
  415. //    user rights for the specified database. 
  416. //    This is just for convenience, you could do the 
  417. //    same thing with g_add and then a d_add. 
  418. // 
  419. //------------------------------------------------------ 
  420.  
  421. Function add () { 
  422.  
  423. checknclean (); 
  424.  
  425. global $user, $password, $server,  
  426.     $victim, $pw1, $host, $database, 
  427.     $Select_priv, $Insert_priv, $Update_priv,  
  428.         $Delete_priv, $Create_priv, $Drop_priv; 
  429.  
  430.  
  431. mysql_connect($server,$user,$password); 
  432.  
  433. mysql( "mysql",     "insert into user ( user, host, password, 
  434.         Select_priv, Insert_priv, Update_priv, 
  435.         Delete_priv, Create_priv, Drop_priv ) 
  436.     values ('$victim', '$host', password(\"$pw1\"), 
  437.         'N','N','N','N','N','N')"); 
  438.  
  439. mysql( "mysql",     "insert into db ( user, host, db, 
  440.         Select_priv, Insert_priv, Update_priv, 
  441.         Delete_priv, Create_priv, Drop_priv ) 
  442.     values ('$victim', '$host', '$database', 
  443.         '$Select_priv','$Insert_priv','$Update_priv', 
  444.         '$Delete_priv','$Create_priv','$Drop_priv')"); 
  445.  
  446. Reload_Tables(); 
  447.  
  448. echo  "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>"; 
  449. show_user ( "%", "%"); 
  450.  
  451. echo   "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>"; 
  452. show_db ( "%", "%"); 
  453.  
  454. echo  "That user has been added!"; 
  455.  
  456.  
  457. //------------------------------------------------------ 
  458. // 
  459. //    Delete a user/host from every table 
  460. // 
  461. //------------------------------------------------------ 
  462.  
  463.  
  464.  
  465. Function g_delete () { 
  466.  
  467. global $user, $password, $server, $victim, $host, $database; 
  468.  
  469. checknclean (); 
  470.  
  471.  
  472. mysql_connect($server,$user,$password); 
  473.  
  474. mysql( "mysql", "delete from user where user = \"$victim\" and host = \"$host\" "); 
  475. mysql( "mysql", "delete from db where user = \"$victim\" and host = \"$host\" "); 
  476.  
  477. Reload_Tables(); 
  478.  
  479. echo  "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>"; 
  480. show_user( "%", "%"); 
  481. echo   "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>"; 
  482. show_db( "%", "%"); 
  483.  
  484. echo  "The user $victim@$host has been deleted the user"; 
  485.  
  486.  
  487.  
  488. //------------------------------------------------------ 
  489. // 
  490. //    Delete a user/host from a particular database. 
  491. // 
  492. //------------------------------------------------------ 
  493.  
  494.  
  495.  
  496. Function d_delete () { 
  497.  
  498. global $user, $password, $server, $victim, $host, $database; 
  499.  
  500. checknclean (); 
  501.  
  502.  
  503. mysql_connect($server,$user,$password); 
  504.  
  505. mysql( "mysql", "delete from db where user = \"$victim\" and host = \"$host\" "); 
  506.  
  507. Reload_Tables(); 
  508.  
  509. echo  "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>"; 
  510. show_user( "%", "%"); 
  511. echo   "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>"; 
  512. show_db( "%", "%"); 
  513.  
  514. echo  "The user $victim@$host has been deleted the user"; 
  515.  
  516.  
  517.  
  518.  
  519. //------------------------------------------------------ 
  520. // 
  521. //    Add a global user. (user table only) 
  522. // 
  523. //------------------------------------------------------ 
  524.  
  525. Function g_add () { 
  526.  
  527.  
  528. global $user, $password, $server, 
  529.         $victim, $pw1, $host, 
  530.         $Select_priv, $Insert_priv, $Update_priv,  
  531.         $Delete_priv, $Create_priv, $Drop_priv, 
  532.         $Reload_priv, $Shutdown_priv, 
  533.         $Process_priv, $File_priv; 
  534. checknclean (); 
  535.  
  536. mysql_connect($server,$user,$password); 
  537.  
  538. mysql( "mysql",     "insert into user ( user, host, password, 
  539.         Select_priv, Insert_priv, Update_priv, 
  540.                 Delete_priv, Create_priv, Drop_priv, 
  541.                 Reload_priv, Shutdown_priv, 
  542.                 Process_priv, File_priv ) 
  543.     values ('$victim', '$host', password(\"$pw1\"), 
  544.         '$Select_priv','$Insert_priv','$Update_priv', 
  545.                 '$Delete_priv','$Create_priv','$Drop_priv', 
  546.                 '$Reload_priv','$Shutdown_priv', 
  547.                 '$Process_priv','$File_priv')"); 
  548.  
  549. Reload_Tables(); 
  550.  
  551. echo  "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>"; 
  552. show_user ( "%", "%", "user"); 
  553.  
  554. echo   "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>"; 
  555. show_db ( "%", "%", "db"); 
  556.  
  557. echo  "That user has been added!"; 
  558.  
  559.  
  560. //------------------------------------------------------ 
  561. // 
  562. //    Add a user to a database. (db table only) 
  563. // 
  564. //------------------------------------------------------ 
  565.  
  566. Function d_add () { 
  567.  
  568. checknclean (); 
  569.  
  570. global $user, $password, $server,  
  571.     $victim, $host, $database, 
  572.     $Select_priv, $Insert_priv, $Update_priv,  
  573.     $Delete_priv, $Create_priv, $Drop_priv; 
  574.  
  575.  
  576. mysql_connect($server,$user,$password); 
  577.  
  578. mysql( "mysql",     "insert into db ( user, host, db, 
  579.         Select_priv, Insert_priv, Update_priv, 
  580.         Delete_priv, Create_priv, Drop_priv ) 
  581.     values ('$victim', '$host', '$database', 
  582.         '$Select_priv','$Insert_priv','$Update_priv', 
  583.         '$Delete_priv','$Create_priv','$Drop_priv')"); 
  584.  
  585. Reload_Tables(); 
  586.  
  587. echo  "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>"; 
  588. show_user ( "%", "%"); 
  589.  
  590. echo   "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>"; 
  591. show_db ( "%", "%"); 
  592.  
  593. echo  "That user has been added!"; 
  594.  
  595.  
  596. //------------------------------------------------------ 
  597. // 
  598. //    Modify a user's global settings (user table only). 
  599. // 
  600. //------------------------------------------------------ 
  601.  
  602. Function g_modify () {  
  603.  
  604. global $user, $password, $server,  
  605.     $victim, $pw1, $pw2, $host, 
  606.     $Select_priv, $Insert_priv, $Update_priv,  
  607.         $Delete_priv, $Create_priv, $Drop_priv, 
  608.         $Reload_priv, $Shutdown_priv, 
  609.         $Process_priv, $File_priv; 
  610.  
  611.  
  612. checknclean (); 
  613. if (  "$pw1" !=  "$pw2" ) { die ( "Passwords don't match, try again"); }  
  614.  
  615. mysql_connect($server,$user,$password); 
  616.  
  617. if (  "$pw1" ==  "" ) {  
  618.  
  619. mysql( "mysql",     "update user set  
  620.         user = '$victim',  
  621.         host = '$host', 
  622.         Select_priv = '$Select_priv',  
  623.         Insert_priv = '$Insert_priv', 
  624.         Update_priv = '$Update_priv', 
  625.         Delete_priv = '$Delete_priv',  
  626.         Create_priv = '$Create_priv', 
  627.                 Drop_priv = '$Drop_priv', 
  628.                 Reload_priv = '$Reload_priv', 
  629.                 Shutdown_priv = '$Shutdown_priv', 
  630.                 Process_priv = '$Process_priv', 
  631.                 File_priv = '$File_priv' 
  632.                 where user = '$victim' and host = '$host'"); 
  633.         } 
  634. else { 
  635. mysql( "mysql",     "update user set  
  636.         user = '$victim',  
  637.         host = '$host', 
  638.         password = '$pw1', 
  639.         Select_priv = '$Select_priv',  
  640.         Insert_priv = '$Insert_priv', 
  641.         Update_priv = '$Update_priv', 
  642.         Delete_priv = '$Delete_priv',  
  643.         Create_priv = '$Create_priv', 
  644.         Drop_priv = '$drop_priv' where user = '$victim' and host = '$host'"); 
  645.  
  646. Reload_Tables(); 
  647.  
  648. echo  "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>"; 
  649. show_user ( "%", "%"); 
  650.  
  651. echo   "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>"; 
  652. show_db ( "%", "%"); 
  653.  
  654. //------------------------------------------------------ 
  655. // 
  656. //    Modify a user's database settings (db table only). 
  657. // 
  658. //------------------------------------------------------ 
  659.  
  660. Function d_modify () {  
  661.  
  662. global $user, $password, $server,  
  663.     $victim, $host, $database, 
  664.     $Select_priv, $Insert_priv, $Update_priv,  
  665.     $Delete_priv, $Create_priv, $Drop_priv; 
  666.  
  667. checknclean (); 
  668.  
  669. mysql_connect($server,$user,$password); 
  670. mysql( "mysql",     "update db set  
  671.         user = '$victim',  
  672.         host = '$host', 
  673.         db = '$database', 
  674.         Select_priv = '$Select_priv',  
  675.         Insert_priv = '$Insert_priv', 
  676.         Update_priv = '$Update_priv', 
  677.         Delete_priv = '$Delete_priv',  
  678.         Create_priv = '$Create_priv', 
  679.         Drop_priv = '$Drop_priv' where user = '$victim' and host = '$host'"); 
  680.  
  681. Reload_Tables(); 
  682.  
  683. echo  "<h3><b><i><center>New Global User Settings</h3></i></b></center><p>"; 
  684. show_user ( "%", "%"); 
  685.  
  686. echo   "<p><center><h3><i><b>New Database Access Table</b></i></h3></center><p>"; 
  687. show_db ( "%", "%"); 
  688.  
  689.  
  690.  
  691. //------------------------------------------------------ 
  692. // 
  693. //    Global Display Function:  
  694. //    Display full user and db tables. 
  695. // 
  696. //------------------------------------------------------ 
  697.  
  698. Function g_display () { 
  699.  
  700. global $user, $password, $server; 
  701. mysql_connect($server,$user,$password); 
  702. show_user ( "%", "%"); 
  703. show_db ( "%", "%"); 
  704.  
  705.  
  706.  
  707.  
  708.  
  709. //------------------------------------------------------ 
  710. // 
  711. //    The footer printed at the bottem of the page 
  712. // 
  713. //------------------------------------------------------ 
  714.  
  715. Function footer() { 
  716.  
  717. global $password, $user, $pagename; 
  718.  
  719. echo  " 
  720. <hr> 
  721. <center> 
  722. <table border=1 cellspacing=2 bgcolor=#e0e0cc> 
  723. <tr> 
  724. <td><a href=\"$pagename?mode=help\">HELP</a></td> 
  725. <td><a href=\"$pagename?mode=g-display&user=$user&password=$password\">SHOW PERMISSION TABLES</a></td> 
  726. <td><a href=\"$pagename?mode=Menu&user=$user&password=$password\">Main Menu</a></td> 
  727. </tr></table> 
  728. </center> 
  729. "; 
  730.  
  731. //------------------------------------------------------ 
  732. // 
  733. //    This is the help information page. 
  734. // 
  735. //------------------------------------------------------ 
  736.  
  737. Function help () { 
  738.  
  739. echo  " 
  740. <center> 
  741. <h2><b><i>Administration Help Page</h2></b></i> 
  742. </center> 
  743. <p> 
  744. <ul><li><i>    Note: This page is not a substitute for knowing how  
  745.         mysql permissions work.<p><b>Warning: The admin utility  
  746.         doesn't include any \"Are you sure?\" prompts. Be sure  
  747.         of what you are doing before you click to submit.  
  748.         This utility was written with administrators in mind,  
  749.         and wasn't meant to be used by the average user.</b> 
  750.  
  751. </ul></li></i><p> 
  752. <hr> 
  753. <h2>User Commands:</h2><p> 
  754. <li>Quick Add User</li><p> 
  755.     <ul><ul><i>This option adds a user to both the USER table and the 
  756.     DATABASE (db) table. In the USER table, they are given absolutely 
  757.     no permissions by default, and the permissions that were checked 
  758.     on the user information page, are applied only to the  
  759.     database specified. If no database was specified, then the  
  760.     default database is used.</ul></ul></i><p> 
  761. <li>Add Globally</li><p> 
  762.     <ul><ul><i>This option adds the user to the USER table only. Any 
  763.     permissions granted here are good for *all* databases. Additional 
  764.     rights for any given database can be given with the Add for  
  765.     Database option. Every user/host pair *must* have a listing here 
  766.     since password information for the paris is stored here.</i></ul></ul><p> 
  767. <li>Add to Database</li><p> 
  768.     <ul><ul><i>This will add permissions for a user/host pair to a  
  769.     particular database.</i></ul></ul><p> 
  770. <li>Modify Globally</li><p> 
  771.     <ul><ul><i>Modifies a user's global (user table) settings. Leave the 
  772.     password boxes both blank to retain the user's previous  
  773.     password.</i></ul></ul><p> 
  774. <li>Modify for Database</li><p> 
  775.     <ul><ul>Modifies a user's permissions for a particular database.</ul></ul><p> 
  776. <li>Delete Globally</li><p> 
  777.     <ul><ul><i>Deletes the user/host pair from both the USER and 
  778.     DATABASE tables. </i></ul></ul><p> 
  779. <li>Username</li><p> 
  780.     <ul><ul><i>This is the username of the user to be added or 
  781.     modified</ul></ul></i><p> 
  782. <li>Password/Confirm</li><p> 
  783.     <ul><ul><i>This is the password and the confirmation for the user. 
  784.     If you are modifying the user, but don't want to change their 
  785.     password, then just leave both of these blank.</ul></ul></i><p> 
  786. <li>Host</li><p> 
  787.     <ul><ul><i>This is the host that the user is allowed to connect 
  788.     from. If you set this to \"%\" it is a wildcard. Use only  
  789.     \"localhost\" if you don't want users to be able to connect 
  790.     direclty to the sql server from elseware. This will allow 
  791.     scripts/programs running on the mysql server to access it 
  792.     but nothing else.</ul></ul></i><p> 
  793. <li>Database</li><p> 
  794.     <ul><ul><i>This is the database that the rights are given for.  
  795.     Note: Global rights are good for *any* database, so it may 
  796.     be easiest to set up global accounts for passwords but with 
  797.     no rights configured, and then add users to individual  
  798.     databases as needed.</ul></ul></i><p> 
  799. <li>*_priv</li><p> 
  800.     <ul><ul><i>These are the sql operations allowed for the  
  801.     database or globally for that user.</ul></ul></i><p> 
  802.  
  803.  
  804.  
  805.  
  806.  
  807. "; 
  808.  
  809.  
  810.  
  811.  
  812. // 
  813. //    Main Loop 
  814. // 
  815.  
  816. // if pw is set to 1, then the function will 
  817. // know to perform password matching verification 
  818. // and test to make sure it's not null. 
  819.  
  820. switch ($mode) { 
  821. case  ""; Login ();break; 
  822. case  "Menu"; Menu (); footer(); break; 
  823. case  "g-add"; $pw =  "1"; g_add (); footer(); break; 
  824. case  "d-add"; d_add (); footer(); break; 
  825. case  "g-delete"; g_delete (); footer(); break; 
  826. case  "d-delete"; d_delete (); footer(); break; 
  827. case  "g-modify"; g_modify (); footer(); break; 
  828. case  "d-modify"; d_modify (); footer(); break; 
  829. case  "add"; $pw =  "1"; add (); footer(); break; 
  830. case  "help"; help (); footer(); break; 
  831. case  "delete"; delete (); footer(); break; 
  832. case  "g-display"; g_display (); footer(); break; 
  833.  
  834. default; echo  "Admin utility internal error: Unknown mode: $mode"; 
  835.  
  836.  
  837. ?> 
  838. </body> 
  839. </html> 
  840.  
  841.