PCCS MySQLDatabase Admin Tool version 1.3.4


/dumpfiles/ -> index.php

1  <?php
2  // Found on freshmeat.net in the fm.zip archive
3  // Modified by: Chauncey Thorn
4  // Filename: index.php
5  // Function: Handle the restores of Databases and restore to new database
6  //
7  // updated 10-07-2000
8  // -- made heavy modifications
9  // -- added restore support and create new database to restore to
10  // -- created a link to this file from mysqldb_admin.php
11  // .. no error checking yet... working on my setup
12     require('../mysqldb_app_includes.php');
13     
14     common_header($_title);
15     
16  ///////////////////////////////////////////////////////////////////////////////
17  ?>
18      <P>
19    
20      <CENTER>
21      <TABLE BGCOLOR=#000000 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER
22       BORDER=0 VALIGN=MIDDLE ><TR><TD BGCOLOR=#000000>
23 
24      <TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER
25       VALIGN=CENTER BGCOLOR=#dddddd WIDTH=100%><TR><TD>
26    
27        <TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER
28         VALIGN=TOP BORDER=0><TR BGCOLOR=#0022cf>
29         <TD BGCOLOR=#ffffff>
30         <CENTER><FONT FACE="Arial, Helvetica, Verdana"
31          SIZE=+1 ><B><?php heading() ?></B></FONT></CENTER>
32        </TD>
33        <TD BGCOLOR=#ffffff ALIGN=RIGHT WIDTH=32>
34        &nbsp;
35        </TD></TR></TABLE>
36      
37  <P>
38 
39  <?php
40  $dir_ext="_db";
41  $dbbackupdir="/home/www/htdocs/pccs_mysqladm/dumpfiles/$dbname$dir_ext";
42  $webshare = "$dbbackupdir";
43 
44  ?>
45 
46  <script language=javascript>
47  <!--
48  function submit(form) {
49          form.submit()
50  }
51  //-->
52  </script>
53 
54  <?php
55 
56  if (isset($exit)) { unset($edit); unset($upload); }
57 
58  if (empty($pwd)) $pwd = "/";
59 
60  if ($action == "upload") exec("cp $userfile $webshare$pwd$userfile_name");
61 
62  $file = $webshare.$pwd.$fn;
63 
64  function read_file($file) {
65 
66          if (!($fp = fopen($file, 'r' ))) return false;
67 
68          $contents = fread($fp, filesize($file));
69 
70          fclose($fp);
71 
72          return $contents;
73  }
74 
75  function write_file($file, $contents) {
76 
77          if ($fp = fopen($file, "w")) {
78 
79                  fputs($fp, $contents, strlen($contents));
80 
81                  fclose($fp);
82 
83                  return 1;
84 
85          } else {
86 
87                  return 0;
88          }
89  }
90 
91  //-------------------------------------------------------------------------------------------------
92 
93  if ($copy) {
94 
95          if ($action == "copy") {
96 
97                  exec("cp -R ".$webshare.$oldname." ".$webshare.$newname);
98                  
99          } else {
100 
101  ?>
102  <table align=center border=2 cellspacing=0 cellpadding=3>
103          <tr>
104                  <form name=copy method=post action=<?php echo $PHP_SELF; ?>?dbname=<?php echo $dbname ?> >
105                          <td>
106                          <input type=hidden name=oldname value="<?php echo $pwd.$fn; ?>">
107                          <input type=hidden name=action value=copy>
108                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
109                          <font face=Verdana><small>Clipboard Contents: <?php echo $pwd.$fn; ?></small></font><br>
110                          <input type=submit name="copy" value="Copy as:">
111                          <input type=text size="56" name="newname" value="<?php echo $pwd.$fn; ?>"><br>
112                          <input type=submit name="exit" value="Cancel"></td>
113                  </form>
114          </tr>
115  </table><br><br>
116  <?php
117 
118          }
119  }
120 
121  //-------------------------------------------------------------------------------------------------
122 
123  if ($move) {
124 
125          if ($action == "move") {
126 
127                  exec("mv ".$webshare.$oldname." ".$webshare.$newname);
128                  
129          } else {
130 
131  ?>
132  <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
133          <tr>
134                  <td>
135                  <form name=move method=post action=<?php echo $PHP_SELF; ?>>
136                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
137                          <font face=Verdana><small>Clipboard Contents: <?php echo $pwd.$fn; ?></small></font><br>
138                          <input type=submit name="move" value="Move to:">
139                          <input type=text size="56" name="newname" value="<?php echo $pwd.$fn; ?>"><br>
140                          <input type=hidden name=oldname value="<?php echo $pwd.$fn; ?>">
141                          <input type=hidden name=action value=move>
142                          <input type=submit name="exit" value="Cancel"></td></form>
143          </tr>
144  </table><br><br>
145  <?php
146 
147          }
148  }
149 
150  //-------------------------------------------------------------------------------------------------
151 
152  if ($rename) {
153 
154          if ($action == "rename") {
155 
156                  exec("mv ".$webshare.$oldname." ".$webshare.$newname);
157                  
158          } else {
159 
160  ?>
161  <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
162          <tr>
163                  <td>
164                  <form name=move method=post action=<?php echo $PHP_SELF; ?>>
165                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
166                          <font face=Verdana><small>Clipboard Contents: <?php echo $pwd.$fn; ?></small></font><br>
167                          <input type=submit name="rename" value="Rename to:">
168                          <input type=text size="56" name="newname" value="<?php echo $pwd.$fn; ?>"><br>
169                          <input type=hidden name=oldname value="<?php echo $pwd.$fn; ?>">
170                          <input type=hidden name=action value=rename>
171                          <input type=submit name="exit" value="Cancel"></td></form>
172          </tr>
173  </table><br><br>
174  <?php
175 
176          }
177  }
178 
179  //-------------------------------------------------------------------------------------------------
180 
181  if ($newfile) {
182 
183          if (isset($fn)) {
184 
185                  write_file($file, "");
186 
187                  $edit = 1;
188 
189          } else {
190 
191                  echo "You must specify a name for the file you wish to create.";
192          }
193 
194          echo $result;
195 
196  }
197 
198  //-------------------------------------------------------------------------------------------------
199 
200  if ($newdir) {
201 
202          if (isset($newdirname)) {
203 
204                  exec("mkdir ".$webshare.$pwd.$newdirname);
205 
206          } else {
207 
208                  echo "You must specify a name for the directory you wish to create.";
209          }
210 
211          echo $result;
212  }
213 
214  //-------------------------------------------------------------------------------------------------
215 
216  if ($delete) {
217 
218          if ($action == "delete") {
219 
220                  exec("rm -R $file");
221                  
222          } else {
223 
224  ?>
225  <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
226          <tr>
227                  <td>
228                  <form name=delete method=post action=<?php echo $PHP_SELF; ?>>
229                          <font face=Verdana><small>Delete <?php echo $pwd.$fn; ?>?</small></font>
230                          <input type=submit name="delete" value="Yes">
231                          <input type=submit name="exit" value="No">
232                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
233                          <input type=hidden name="fn" value="<?php echo $fn; ?>">
234                          &nbsp;<input type=hidden name=action value=delete></td></form>
235          </tr>
236  </table><br><br>
237  <?php
238 
239          }
240  }
241 
242  //-------------------------------------------------------------------------------------------------
243 
244  if (isset($edit)) {
245 
246          if (!(isset($fn))) echo "No filename was specified.";
247 
248          else {
249 
250                  if ($save) {
251 
252                          if ((isset($file)) && (isset($contents))) {
253 
254                                  $contents = stripslashes($contents);
255 
256                                  write_file($file, $contents);
257 
258                          } else {
259 
260                                  echo "Error saving file to disk";
261                          }
262                  }
263  ?>
264  <table bgcolor="#999999" border=2 cellspacing=0 cellpadding=3 align=center>
265          <tr>
266                  <td>BACKUP File: <?php echo $fn; ?></td>
267          </tr>
268          <tr>
269                  <td align=center>
270                  <form method="post" action="<?php echo $PHP_SELF; ?>?dbname=<?php echo $dbname ?>">
271                          <textarea name="contents" cols=60 rows=20><?php $contents = read_file($webshare.$pwd.$fn); echo htmlentities($contents); ?></textarea><br>
272                          <!-- <input type=submit name="save" value="Save"> Really don't need to save -->
273                          <input type=submit name="exit" value="Exit">
274                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
275                          <input type=hidden name="fn" value="<?php echo $fn; ?>">
276                          <input type=hidden name="edit" value="Edit"></td></form>
277          </tr>
278  </table></form><br>
279  <?php
280 
281          }
282  }
283 
284  //-------------------------------------------------------------------------------------------------
285 
286  exec("ls -l ".$webshare.$pwd, $result, $id);
287 
288  $up_pwd = eregi_replace("/$", "", $pwd);
289 
290  $up_pwd = eregi_replace("[_a-z0-9\.-]+$", "", $up_pwd);
291 
292  echo "
293  <table align=center bgcolor=#FFFFFF border=2 cellspacing=1 cellpadding=3>
294          <tr>
295                  <td><a href=../mysqldb_admin.php>Back to Databases</a> : MySQLDatabase Admin DB Restore Tool: ".$pwd."</td>
296          </tr>
297          <tr>
298                  <td>
299                          <table>
300                                  <tr>
301                                          <td colspan=2><font face=Verdana><small>BACKUP Files for Database : $dbname</small></font><td>
302                                  </tr>
303                                  <tr>
304                                          <td colspan=2>
305                                          <img src=../images/dbfolder.gif border=0 alt=$dbname>&nbsp;</td>
306                                  </tr>
307 
308 
309                          </table></td>
310          </tr>
311          <tr>
312                  <td>
313  ";
314  ?>
315                          <form method=post action="<?php echo $PHP_SELF; ?>?dbname=<?php echo $dbname ?>" name="files">
316                          <font face=Verdana><small>BACKUP Files:</small></font><br>
317                          <select name=fn>
318  <?php
319 
320  $i = 1;
321 
322  while (isset($result[$i])) {
323 
324          $result[$i] = eregi_replace(" +", ",", $result[$i]);
325 
326          $line = explode(",", $result[$i]);
327 
328          if (!(ereg("^d", $line[0]))) {
329 
330                  echo "<option value=\"".$line[8]."\">".$line[8]."\n";
331          }
332 
333          $i++;
334  }
335  ?>
336                          </select>
337                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
338                          <input type=submit name="edit" value="View Backup">
339                          <input type=submit name="restore" value="Restore">
340                          <input type=submit name="copy" value="Copy">
341                          <input type=submit name="delete" value="Delete">
342                          <input type=submit name="rename" value="Rename">
343                          </form></td>
344          </tr>
345          <tr>
346                  <td>
347                          <form method=post action=<?php echo $PHP_SELF; ?>?action=createnewdb&dbname=<?php echo $dbname ?>>
348                          <font face=Verdana><small>Restore to another Database:</small></font><br>
349                          <input type=hidden name="pwd" value=<?php echo $pwd; ?>>
350                          <input type=text name=databasename size=40>
351                          <select name=fn>
352  <?php
353                  
354  $i = 1;
355                                  
356  while (isset($result[$i])) {
357                                  
358          $result[$i] = eregi_replace(" +", ",", $result[$i]);
359                                          
360          $line = explode(",", $result[$i]);
361                                  
362          if (!(ereg("^d", $line[0]))) {
363 
364                  echo "<option value=\"".$line[8]."\">".$line[8]."\n";
365          }
366          
367          $i++;
368  }
369  ?>
370                          </select>
371 
372                          <input name=createnewdb value=" Create New Database " type=submit>
373                          </form></td>
374          </tr>
375  </table>
376  <br>
377  <br>
378  <?
379 
380  if ($restore) {
381 
382          if ($action == "dorestore") {
383                  $cmd = "mysql -u$db_user -p$db_passwd $dbname < " .$webshare.$pwd.$fn;
384                  exec("$cmd") or die("Error Executing: $cmd$fn ");
385                  
386          } else {
387 
388  ?>
389  <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
390          <tr>
391                  <td>
392                  <form name=move method=post action=<?php echo $PHP_SELF; ?>?dbname=<?php echo $dbname ?>>
393                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
394                          <input type=hidden name="dbname" value="<?php echo $dbname; ?>">
395                          <font face=Verdana><small>Clipboard Contents: <?php echo $fn; ?></small></font><br>
396                          <input type=submit name="restore" value="Restore to: <?php echo $dbname ?>">
397                          <input type=text size="56" name="fn" value="<?php echo $fn; ?>">
398                          <br>
399                          
400                          <input type=hidden name=action value=restoretonewdb>
401                          <input type=submit name="exit" value="Cancel"></td></form>
402          </tr>
403  </table><br><br>
404  <? }
405  } ?>
406 
407 
408  <?
409 
410  if ($createnewdb) {
411 
412          if ($action == "restoretonewdb") {
413                  $cmd1 = "mysqladmin -u$db_user -p$db_passwd create $databasename";
414                  $cmd2 = "mysql -u$db_user -p$db_passwd $databasename < $webshare$pwd$fn" ;
415                  exec("$cmd1") or die("Error Executing: $cmd1 ");
416                  exec("$cmd2") or die("Error Executing: $cmd2$fn ");
417          echo $database .": was created ...";
418          echo "<br> Click Back to Database";
419          } else {
420 
421  ?>
422  <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
423          <tr>
424                  <td>
425                  <form name=move method=post action=<?php echo $PHP_SELF; ?>?action=restoretonewdb&dbname=<?php echo $dbname ?>>
426                          <input type=hidden name="webshare" value="<?php echo $webshare; ?>">
427                          <input type=hidden name="fn" value="<?php echo $fn; ?>">
428                          <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
429                          <input type=hidden name="databasename" value="<?php echo $databasename; ?>">
430                          <font face=Verdana><small>Restore This BACKUP: <?php echo $fn; ?></small></font><br>
431                          <input type=submit name="createnewdb" value="Restore to:">
432                          <input type=text size="56" name="databasename" value="<?php echo $databasename; ?>">
433                          <br>
434                          
435                          <input type=submit name="exit" value="Cancel"></td></form>
436          </tr>
437  </table><br><br>
438  <? }
439  } ?>
440 
441 
442 
443 
444  </TD>
445  </TR>
446  </TABLE>
447 
448 
449 
450  </TD></TR></TABLE>
451  </TD></TR></TABLE>
452  </CENTER>


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