|
PCCS MySQLDatabase Admin Tool version 1.3.4
|
/ -> mysqldb_gr_perms.php
1 <?php
2 // Hacked by: Chauncey Thorn 3 /************************************************************************
4 PCCS MySQLDatabase Admin Tool
5 Copyright (C) 1999 Chauncey Thorn
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA , USA.
20 **************************************************************************/
21 // updated 10-23-2000 22 // -- moving to a single file for global include files 23
24 require('mysqldb_app_includes.php');
25
26 common_header($_title);
27
28 pageTop("PCCS MySQLAdmin Tool: GRANT/REVOKE USER ACCESS TO DB","600");
29
30
31 $across = "6";
32 $start_script = "mysqldb_gr_perms.php";
33 if($argv[0] ==""):
34
35 // heading();
36 print "
37
38 <font face=\"arial, heveltica\" size=\"2\" color=\"Red\" style=\"font-size: 12;
39 font-weight: normal;\">";
40 $cur_date = date("l M d, Y H:i:s");
41 print " $cur_date";
42 print "<p>";
43 print "<center>Choose Database to grant/revoke permissions</center>";
44 print "</font>";
45 print "<HR>";
46
47
48 function displayDatabases() {
49 global $across, $start_script;
50
51 $content .="<table width=100% border=0 cellpadding=3><tr>";
52 $result_1 = mysql_query("SHOW DATABASES");
53
54 while ($info = mysql_fetch_array($result_1))
55 {
56
57 $a++;
58
59 $content .="<td><small><a
60 href=\"$start_script?action=list_tbls&db=$info[Database]\"
61 CLASS=noul><b>$info[Database]
62 </b></a>";
63 $content .= "$info[User]</small></td>\n";
64 if ($a == $across) {$content .="</tr>"; $a=0;}
65 }
66
67 $content .= "</tr></table>";
68
69 echo $content;
70 }
71
72 displayDatabases();
73 print "<HR>";
74 print "<CENTER>";
75 print "<font color=blue>";
76 print " You can also Modify Permissions via one of the mysql.* tables";
77 print "</font>";
78 print "<p>";
79 print "[ <A HREF=mysqldb_host.php>mysql.host</A> ";
80 print "| <A HREF=mysqldb_user.php>mysql.user</A> ";
81 print "| <A HREF=mysqldb_db.php>mysql.db</A> ]";
82 print "</CENTER>";
83 print "<p>";
84 print "<<<<a href=./>back...</a>";
85 print "<p>";
86
87 endif;
88 ?>
89 <?
90
91 if($action =="list_tbls"):
92 print "Set GRANT and/or REVOKE on a Table";
93 print "<p>";
94 $res = mysql_list_tables("$db") or die("Query Failed");
95 while ($row = mysql_fetch_row($res))
96
97 print "[ <a
98 href=$start_script?action=perms&db=$db&tbl=$row[0]>Grant/Revoke</a> |
99
100 $row[0] ]<br>\n";
101 print "<br><a href=$start_script>Back</a>";
102 endif;
103
104 if($action =="perms"):
105
106 print "<small>";
107 print "Example <br>";
108 print "<font color=red>";
109 print "GRANT SELECT on $db.$tbl TO cthorn@'%'";
110 PRINT "<BR>";
111 print "REVOKE SELECT on $db.$tbl FROM cthorn@'%'";
112 print "</font>";
113 print "</small>";
114 print "<form action=$start_script?action=setperms method=post>";
115 print "<select name=opts1>";
116 print "<option value=GRANT> GRANT </option>";
117 print "<option value=REVOKE> REVOKE </option>";
118 print "</select>";
119 print " ";
120 print "<input type=text name=perm>";
121 print " ON $db.$tbl ";
122 print " ";
123 print "<select name=opts2>";
124 print "<option value=TO> TO </option>";
125 print "<option value=FROM> FROM </option>";
126 print "</select>";
127
128 print "
129 <SELECT NAME=dbuser SINGLE>";
130 $qry = "SELECT User,host FROM user ORDER BY User";
131 $res = mysqlquery("mysql",$qry) or die("Error running query");
132 for ($i = 0; $i < mysql_numrows($res); $i++):
133 $user_output = mysql_result($res,$i,"User");
134 $host_output = mysql_result($res,$i,"Host");
135 if($host_output == "%"):
136 print "<OPTION VALUE=\"$user_output@'$host_output'\">$user_output@'$host_output'</OPTION>";
137 else:
138 print "<OPTION VALUE=\"$user_output@$host_output\">$user_output@$host_output</OPTION>";
139 endif;
140 endfor;
141 print " </SELECT>";
142 print "<br>";
143 print "<input type=hidden name=on value=\"$db.$tbl\">";
144 print "<input type=hidden name=db value=$db>\n";
145 print "<input type=submit value=\"Apply Permissions\"></form>";
146 endif;
147
148 if($action =="setperms"):
149 $qry = "$opts1 $perm ON $on $opts2 $dbuser ";
150 // $qry = stripslashes($qry);
151 $result = mysqlquery("mysql",$qry);
152 if (!empty($result)) {
153 //
154 log_this($qry,"dblog.txt");
155 // modifed by Chauncey Thorn
156 // - added link and displaying what happen
157 // no conformation )+:
158 echo "Permissions changed<br>\n";
159 echo "<a href=$PHP_SELF?action=list_tbls&db=$db>Back to $db
160 Tables</a>";
161 } else {
162 echo mysql_error()."<BR>\n";
163 }
164 endif;
165
166 // footer();
167
168 pageBottom();
169 ?>
| |