PCCS MySQLDatabase Admin Tool version 1.3.4


/ -> mysqldb_admin.php

1  <?
2  /////////////////////////////////////////////////////////////////////////////////////
3  // coder: cthorn
4  // mysqldb_admin.php
5  //
6  /************************************************************************
7  PCCS MySQLDatabase Admin Tool
8  Copyright (C) Chauncey Thorn
9 
10  This program is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 2
13  of the License, or (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA , USA.
23  **************************************************************************/
24  // updated 10-09-2000
25  // -- added changelog to this file
26  // -- moved refresh_meta() and log_this()
27  // -- now including logging_function.php
28  // updated 10-23-2000
29  // -- moving to a single file for global include files
30    
31  require('mysqldb_app_includes.php');
32     
33     common_header($_title);
34     pageTop("PCCS MySQLAdmin Tool: DATABASE MANAGEMENT","600");
35 
36  $link_array = array(
37  "$str_mainMenu" => "./",
38  "$str_installscriptlink" => "installscript/mysqldb_installscript.php",
39  "$str_createwebacct" => "mysqldb_create_webuser.php",
40  "LOGOUT" => "logout.php"
41  );
42 
43   print "<BR>";
44   print "<CENTER>";
45   navBar($link_array);
46   print "</CENTER>";
47   print "<BR>";
48 
49 
50 
51    // Display Text based on action
52     print "<p>";
53     if ($argv[0] == ""):
54      $menu = "$str_mainMenu";
55          endif;
56     if ($action == "dbschema"):
57          $menu = "$str_mysqlschemadump";
58          endif;
59     // heading();
60     print "<P> <CENTER><FONT SIZE=+2 >";
61     print "</FONT></CENTER>";
62     print "<P>";
63 
64     // Display Process list
65 
66     $qry = "SHOW PROCESSLIST";
67     $res = mysql($db_name,$qry);
68          $ps = mysql_numrows($res);
69     print "<CENTER>";
70     print "$str_processesrunningon $db_server: ";
71     print "<A HREF=$PHP_SELF?action=processlist CLASS=noul> $ps </A>&nbsp;";
72     print " $str_usingmysqldbver $display_mysql_version &nbsp;";
73     print "<A HREF=$PHP_SELF?action=status CLASS=noul> $str_sysstatus </A>&nbsp;";
74     print "</CENTER>";
75     print "<p>";
76 
77  if ($argv[0] == ""):
78  print "<CENTER>";
79  print "<FORM ACTION=mysqldb_runcmd.php?action=createdb METHOD=post>\n";
80  print " <INPUT TYPE=text NAME=thisdatabase> &nbsp; <INPUT
81  TYPE=submit VALUE=\"CREATE DATABASE\">";
82  print "</FORM><P>";
83  print "</center>";
84       // Display Databases
85 
86       // $result = mysqlquery("mysql","SHOW DATABASES");
87  print "
88        <CENTER>
89        <TABLE BORDER=0 CELLSPACING=3 CELLPADDING=0>
90              <TR>
91           <TH></TH>
92              </TR>
93           <TR>
94              <TH ALIGN=left CLASS=uline>$str_database</TH>
95           <TH ALIGN=left CLASS=uline>OPTIMIZE DB</TH>
96           <TH CLASS=uline>$str_restordb</TH>
97           <TH CLASS=uline>$str_dropdb</TH>
98           <TH CLASS=uline>$str_backupdb</TH>
99           <TH ALIGN=left CLASS=uline>CREATE DUMP</TH>
100 
101           <TH CLASS=uline>$str_numtbls</TH>
102              </TR>
103  ";
104          // updated
105          // moved SQL query to PHP function
106          
107          $db_list = mysql_list_dbs() or die("List DB Failed");
108          $num = mysql_numrows($db_list);
109           for ($i =0 ;$i < $num; $i++):
110              if ($c == $c1):
111                 $c = $c2;
112              else:
113                 $c = $c1;
114              endif;
115 
116  while ($row = mysql_fetch_array($db_list)) {
117              print "<TR BGCOLOR=$c>";
118 
119           $db = $row["Database"];
120 
121           print "<TD ALIGN=left>";
122           print "<A HREF=\"mysqldb_info.php?action=tables&dbname=$db\" CLASS=noul
123           onMouseOver=\"window.status='$str_viewtbl'; return
124  true;\" onMouseOut=\"window.status=' '; return true;\">" . strtoupper("$db"). "</A>";
125           print "</TD>";
126 
127 
128           print "<TD ALIGN=center>";
129           print "<A HREF=\"mysqldb_optimize.php?action=optimizedb&dbname=$db\" CLASS=noul onMouseOver=\"window.status='$str_restoredb'; return
130  true;\" onMouseOut=\"window.status=' '; return true;\">$str_optimize</A>";
131           print "</TD>";
132 
133 
134           print "<TD ALIGN=center>";
135           print "<A HREF=\"dumpfiles/?dbname=$db\" CLASS=noul onMouseOver=\"window.status='$str_restoredb'; return
136  true;\" onMouseOut=\"window.status=' '; return true;\">$str_restordb</A>";
137           print "</TD>";
138 
139           print "<TD ALIGN=center>";
140           print "<A HREF=\"$PHP_SELF?action=warn_dropdb&dbname=$db\" CLASS=noul onMouseOver=\"window.status='$str_dropdb'; return
141  true;\" onMouseOut=\"window.status=' '; return true;\">$str_dropdb</A>";
142           print "</TD>";
143          
144           print "<TD ALIGN=center>";
145           print "<A HREF=\"mysqldb_backup.php?action=backup&dbname=$db\" CLASS=noul
146           onMouseOver=\"window.status='$str_backupdb'; return
147  true;\" onMouseOut=\"window.status=' '; return true;\">$str_backupdb</A>";
148           print "</TD>";
149          
150           print "<TD ALIGN=center>";
151           print "<A HREF=\"mysqldb_admin.php?action=typeofdump&dbname=$db\" CLASS=noul
152           onMouseOver=\"window.status='$str_createdump'; return
153  true;\" onMouseOut=\"window.status=' '; return true;\">CREATE DUMP</A>";
154           print "</TD>";
155 
156 
157           print "<TD ALIGN=right>";
158 
159           // Show tables in database
160    $res = @mysql_list_tables($db);
161          
162           // Changed SQL --> PHP function
163           // updated
164           // $qry = "SHOW TABLES FROM $db";
165           // $res = @mysql($db,$qry);
166          
167           $records = @mysql_numrows($res);
168           if($records <= 0 ) {
169           echo "&nbsp;";
170              } else {
171           echo $records;
172           }
173           print "</TD>";
174          
175  }
176 
177 
178           print "</TR>";
179           endfor;
180           print "</TABLE></CENTER>";
181  endif;
182 
183  if($action == "typeofdump"):
184  // section added
185  // give choice on type of dump
186  // with data or without it
187 
188  print "
189  <center>\n
190  <FORM ACTION=$PHP_SELF?action=dumpdb METHOD=post>\n
191  <INPUT TYPE=hidden NAME=dbname VALUE=$dbname>\n
192  <table><tr><th colspan=2>What Type of Dump ?</th></tr>\n
193  <tr>\n
194  <td>With DATA</td><td><INPUT type=radio name=dumptype value=with></td>\n
195  <td>Without DATA</td><td><INPUT type=radio name=dumptype value=without></td>\n
196  </tr>\n
197  <tr><td colspan=2 align=center><INPUT type=submit value=\"CREATE DUMP\"></td>\n
198  </table>\n
199  </form>\n
200  </center>\n
201  ";
202 
203  endif;
204 
205  if($action =="dumpdb"):
206   // updated
207   // extended function to dump with or without data
208   // --opt or --opt -d
209   // moved function to global.vars.php
210   
211          dumpdb($dbname,$dumptype);
212 
213  endif;
214 
215  if($action =="warn_dropdb"):
216  // Do you really want to delete database YES or NO
217  //
218          print "<CENTER>";
219          print "<FONT COLOR=red>ARE You Sure you want to DROP DATABASE $dbname</FONT>";
220          print "<P>";
221          print "<A HREF=$PHP_SELF>&lt;&lt;&lt; NO :</A>";
222          print "<A HREF=$PHP_SELF?action=dropdb&db=$dbname>: YES &gt;&gt;&gt;</A>";
223          print "</CENTER>";
224  endif;
225 
226  if($action == "dropdb"):
227  // Drop Database
228  // You said delete database
229  //
230  // Using PHP function to drop table
231  // updated
232  // $qry = "DROP DATABASE $db";
233  // $result = mysqlquery("mysql", $qry);
234          
235  $result = mysql_drop_db($db);
236          if(!empty($result)) {
237                  log_this("DATABASE: $db WAS DROPPED","dblog.txt");
238                  print "Database $db Was dropped<BR>";
239                  print "<A HREF=mysqldb_admin.php>Back to Databases</A>";
240          } else {
241                  
242                  log_this("DATABASE ERROR: Unable to Drop $db ","dblog.txt");
243                  print "Unable to Drop $db <BR>";
244                  print "<A HREF=mysqldb_admin.php>Back to Databases</A>";
245          }
246  endif;
247 
248  // print "<A HREF=javascript:history.back()>BACK</A>";
249 
250  if($action =="processlist"):
251  // Display Process List
252  // URL: action=processlist
253 
254     $result = mysqlquery("mysql","SHOW PROCESSLIST ");
255     $num = mysql_numrows($result);
256        $c1 = "#CCCCCC";
257        $c2 = "#CCCCCC";
258     print "
259        <CENTER>
260        <TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>
261              <TR>
262           <TH ALIGN=left>Kill</TH>
263              <TH ALIGN=left>Id</TH>
264           <TH ALIGN=left>User</TH>
265           <TH ALIGN=left>Host</TH>
266           <TH ALIGN=left>DB</TH>
267           <TH ALIGN=left>Command</TH>
268           <TH ALIGN=left>Time</TH>
269           <TH ALIGN=left>State</TH>
270           <TH ALIGN=left>Info</TH>
271              </TR>
272          ";
273          
274            for ($i =0 ;$i < $num; $i++):
275              if ($c == $c1):
276                 $c = $c2;
277              else:
278                 $c = $c1;
279              endif;
280          
281  ?>
282              <TR BGCOLOR=<? echo $c ?>>
283           <TD ALIGN=left><A HREF=<? echo $PHP_SELF
284           ?>?action=killprocess&par=<?echo
285           mysql_result($result,$i,"Id")?>>****</TD>
286           <TD ALIGN=left><?echo mysql_result($result,$i,"Id")?></TD>
287           <TD ALIGN=left><?echo mysql_result($result,$i,"User")?></TD>
288           <TD ALIGN=left><?echo mysql_result($result,$i,"Host")?></TD>
289           <TD ALIGN=left><?echo mysql_result($result,$i,"db")?></TD>
290           <TD ALIGN=left><?echo mysql_result($result,$i,"Command")?></TD>
291           <TD ALIGN=left><?echo mysql_result($result,$i,"Time")?></TD>
292           <TD ALIGN=left><?echo mysql_result($result,$i,"State")?></TD>
293           <TD ALIGN=left><?echo mysql_result($result,$i,"Info")?></TD>
294 
295              </TR>
296           <? endfor ?>
297        </TABLE>
298          <P><P>
299 
300  <? endif ?>
301 
302  <?
303 
304  if($action =="status"):
305  // Display database status
306  // URL: action=status
307 
308        $result = mysqlquery("mysql","SHOW STATUS");
309        $num = mysql_numrows($result);
310        $c1 = "#CCCCCC";
311        $c2 = "#CCCCCC";
312     print "
313        <CENTER>
314        <TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>
315              <TR>
316              <TH ALIGN=left>Status Variable</TH>
317           <TH ALIGN=center>Value</TH>
318              </TR>
319      ";
320     
321           for ($i =0 ;$i < $num; $i++):
322              if ($c == $c1):
323                 $c = $c2;
324              else:
325                 $c = $c1;
326              endif;
327      print "<TR BGCOLOR=$c>";
328      
329  ?>
330           <TD ALIGN=left><?echo mysql_result($result,$i,"Variable_name")?></TD>
331    <TD ALIGN=center><?echo mysql_result($result,$i,"Value")?></TD>
332              </TR>
333           <? endfor ?>
334        </TABLE>
335  <? endif ?>
336 
337  <?
338  ///////////////////////////////////////////////////////////////////////
339  // Display System Information
340  //
341  // Displays databases
342  // Main display for this script
343  /*
344  if ($argv[0] == ""):
345          print "<P>";
346          print "<CENTER>";
347          print "<FONT SIZE=+2 COLOR=blue>$str_sysinfobanner</FONT>";
348          print "<P>";
349 
350           for ($i =0 ;$i < $num; $i++):
351        $result = mysqlquery("mysql","SHOW STATUS");
352        $num = mysql_numrows($result);
353        $var1 = mysql_result($result,$i,"Variable_name");
354        $var2 = mysql_result($result,$i,"Value");
355        $var2 = "<FONT COLOR=red>$var2</FONT>";
356        
357          if ($var1 == "Questions"):
358          print ("$str_questions : $var2 &nbsp;");
359          endif;
360 
361          if ($var1 == "Uptime"):
362          print "<BR>";
363          print ("$str_systemuptime : $var2 &nbsp;");
364          endif;
365 
366          if ($var1 == "tables"):
367          print ("$str_ables : $var2 &nbsp;");
368          endif;
369 
370          if ($var1 == "files"):
371          print ("$str_iles : $var2 &nbsp;");
372          endif;
373 
374          if ($var1 == "d_tables"):
375          print ("$str_dtables : $var2 <BR>&nbsp;");
376          endif;
377                          
378          if ($var1 == "Running_threads"):
379          print ("$str_runningthreads : $var2 &nbsp;");
380          print "<BR>";
381          endif;
382 
383        endfor;
384          print "</CENTER>";
385  endif;
386  */
387  if($action == "killprocess"):
388          $qry ="KILL $par";
389          $result = mysqlquery($db_name,$qry);
390                  if (!empty($result)) {
391           log_this("DATABASE ACTION: $qry","dblog.txt");
392                  //
393                  } else {
394                  echo mysql_error()."<BR>\n";
395                  echo "$qry";
396          }
397 
398 
399          
400           refresh_meta("action=processlist");
401  endif;
402 
403 
404  pageBottom();
405  footer();
406  ?>


Generated: Sat Jan 27 15:40:36 2001 Generated by PHPXref 0.1.2
PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002