[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/admin/ -> database.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Geeklog 1.4                                                               |
   6  // +---------------------------------------------------------------------------+
   7  // | database.php                                                              |
   8  // |                                                                           |
   9  // | Geeklog database backup administration page.                              |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2000-2005 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Tony Bibbs         - tony AT tonybibbs DOT com                   |
  14  // |          Blaine Lang        - langmail AT sympatico DOT ca                |
  15  // |          Dirk Haun          - dirk AT haun-online DOT de                  |
  16  // |          Alexander Schmacks - Alexander.Schmacks AT gmx DOT de            |
  17  // +---------------------------------------------------------------------------+
  18  // |                                                                           |
  19  // | This program is free software; you can redistribute it and/or             |
  20  // | modify it under the terms of the GNU General Public License               |
  21  // | as published by the Free Software Foundation; either version 2            |
  22  // | of the License, or (at your option) any later version.                    |
  23  // |                                                                           |
  24  // | This program is distributed in the hope that it will be useful,           |
  25  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  26  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  27  // | GNU General Public License for more details.                              |
  28  // |                                                                           |
  29  // | You should have received a copy of the GNU General Public License         |
  30  // | along with this program; if not, write to the Free Software Foundation,   |
  31  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  32  // |                                                                           |
  33  // +---------------------------------------------------------------------------+
  34  //
  35  // $Id: database.php,v 1.33 2006/05/15 04:10:38 vinny Exp $
  36  
  37  require_once ('../lib-common.php');
  38  require_once ('auth.inc.php');
  39  
  40  /*
  41  This page allows all Root admins to create a database backup.  This will not
  42  allow the removal of past backups.  It's pretty simple actually.  The admin
  43  clicks a button, we do a mysqldump to a file in the following format:
  44  geeklog_db_backup_YYYY_MM_DD.sql  That's it.
  45  */
  46  
  47  /**
  48  * Sort backup files with newest first, oldest last.
  49  * For use with usort() function. 
  50  * This is needed because the sort order of the backup files, coming from the
  51  * 'readdir' function, might not be that way.
  52  **/
  53  function compareBackupFiles ($pFileA, $pFileB)
  54  {
  55      global $_CONF;
  56  
  57      $lFiletimeA = filemtime ($_CONF['backup_path'] . $pFileA);
  58      $lFiletimeB = filemtime ($_CONF['backup_path'] . $pFileB);
  59      if ($lFiletimeA == $lFiletimeB) {
  60         return 0;
  61      }
  62  
  63      return ($lFiletimeA > $lFiletimeB) ? -1 : 1;
  64  }
  65  
  66  function listbackups()
  67  {
  68      global $_CONF, $_TABLES, $_IMAGE_TYPE, $LANG08, $LANG_ADMIN, $LANG_DB_BACKUP;
  69      require_once( $_CONF['path_system'] . 'lib-admin.php' );
  70      $retval = '';
  71  
  72      if (is_writable ($_CONF['backup_path'])) {
  73          $backups = array();
  74          $fd = opendir($_CONF['backup_path']);
  75          $index = 0;
  76          while ((false !== ($file = @readdir ($fd)))) {
  77              if ($file <> '.' && $file <> '..' && $file <> 'CVS' &&
  78                      preg_match ('/\.sql$/i', $file)) {
  79                  $index++;
  80                  clearstatcache();
  81                  $backups[] = $file;
  82              }
  83          }
  84          // AS, 2004-03-29 - Sort backup files by date, newest first.
  85          // Order given by 'readdir' might not be correct.
  86          usort ($backups, 'compareBackupFiles');
  87          $backups = array_slice ($backups, 0, 10);
  88          reset($backups);
  89  
  90          $data_arr = array();
  91          for ($i = 0; $i < count ($backups); $i++) {
  92              $backupfile = $_CONF['backup_path'] . $backups[$i];
  93              $backupfilesize = COM_numberFormat (filesize ($backupfile));
  94              $data_arr[$i] = array('file' => $backups[$i],
  95                                    'size' => $backupfilesize . " <b>"
  96                                              .$LANG_DB_BACKUP['bytes'] . "</b>");
  97          }
  98  
  99          $menu_arr = array (
 100                          array('url' => $_CONF['site_admin_url']
 101                                         . '/database.php?mode=' . $LANG_DB_BACKUP['do_backup'],
 102                                'text' => $LANG_ADMIN['create_new']),
 103                          array('url' => $_CONF['site_admin_url'],
 104                                'text' => $LANG_ADMIN['admin_home'])
 105          );
 106  
 107          $header_arr = array(      # dislay 'text' and use table field 'field'
 108              array('text' => $LANG_DB_BACKUP['backup_file'], 'field' => 'file'),
 109              array('text' => $LANG_DB_BACKUP['size'], 'field' => 'size')
 110          );
 111  
 112          $text_arr = array('has_menu' => true,
 113                            'instructions' => $LANG_DB_BACKUP['db_explanation']
 114                                              . "<br>" . sprintf ($LANG_DB_BACKUP['total_number'], $index),
 115                            'icon' => $_CONF['layout_url'] . '/images/icons/database.' . $_IMAGE_TYPE,
 116                            'title' => $LANG_DB_BACKUP['last_ten_backups']
 117          );
 118          $retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr, $menu_arr);
 119      } else {
 120          $retval .= COM_startBlock ($LANG08[06], '',
 121                              COM_getBlockTemplate ('_msg_block', 'header'));
 122          $retval .= $LANG_DB_BACKUP['no_access'];
 123          COM_errorLog ($_CONF['backup_path'] . ' is not writable.', 1);
 124          $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
 125      }
 126      return $retval;
 127  }
 128  
 129  
 130  $display = '';
 131  $display .= COM_siteHeader ('menu', $LANG_DB_BACKUP['last_ten_backups']);
 132  
 133  // If user isn't a root user or if the backup feature is disabled, bail.
 134  if (!SEC_inGroup ('Root') OR $_CONF['allow_mysqldump'] == 0) {
 135      $display .= COM_startBlock($MESSAGE[30], '',
 136                      COM_getBlockTemplate ('_msg_block', 'header'));
 137      $display .= $MESSAGE[46];
 138      $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
 139      $display .= COM_siteFooter ();
 140      COM_accessLog("User {$_USER['username']} tried to illegally access the database backup screen.");
 141      echo $display;
 142      exit;
 143  }
 144  
 145  // Perform the backup if asked
 146  if (isset ($_GET['mode']) &&
 147          ($_GET['mode'] == $LANG_DB_BACKUP['do_backup'])) {
 148      if (is_dir ($_CONF['backup_path'])) {
 149          $curdatetime = date ("Y_m_d_H_i_s");
 150          $backupfile = "{$_CONF['backup_path']}geeklog_db_backup_{$curdatetime}.sql";
 151          $command = $_DB_mysqldump_path . " -h$_DB_host -u$_DB_user";
 152          if (!empty ($_DB_pass)) {
 153              $command .= " -p$_DB_pass";
 154          }
 155          if (!empty ($_CONF['mysqldump_options'])) {
 156              $command .= ' ' . $_CONF['mysqldump_options'];
 157          }
 158          $command .= " $_DB_name > \"$backupfile\"";
 159  
 160          if (function_exists ('is_executable')) {
 161              $canExec = is_executable($_DB_mysqldump_path);
 162          } else {
 163              $canExec = file_exists ($_DB_mysqldump_path);
 164          }
 165          if ($canExec) {
 166              exec($command);
 167              if (file_exists ($backupfile) && filesize ($backupfile) > 0) {
 168                  @chmod($backupfile, 0644);
 169                  $timestamp = strftime ($_CONF['daytime']);
 170                  $display .= COM_startBlock ($MESSAGE[40] . ' - ' . $timestamp,
 171                                '', COM_getBlockTemplate ('_msg_block', 'header'))
 172                           . '<img src="' . $_CONF['layout_url'] . '/images/'
 173                           . 'sysmessage.' . $_IMAGE_TYPE
 174                           . '" border="0" align="top" alt="">'
 175                           . $LANG_DB_BACKUP['backup_successful'] . '<br><br>'
 176                           . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
 177              } else {
 178                  $display .= COM_startBlock ($LANG08[06], '',
 179                                  COM_getBlockTemplate ('_msg_block', 'header'));
 180                  $display .= $LANG_DB_BACKUP['zero_size'];
 181                  $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block',
 182                                                                  'footer'));
 183                  COM_errorLog ("Backup Filesize was 0 bytes", 1);    
 184                  COM_errorLog ("Command used for mysqldump: $command", 1);
 185              }
 186          } else {
 187              $display .= COM_startBlock ($LANG08[06], '',
 188                                  COM_getBlockTemplate ('_msg_block', 'header'));
 189              $display .= $LANG_DB_BACKUP['not_found'];
 190              $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block',
 191                                                              'footer'));
 192              COM_errorLog ("Backup Error: Bad path or mysqldump does not exist", 1);
 193              COM_errorLog ("Command used for mysqldump: $command", 1);
 194          }
 195      } else {
 196          $display .= COM_startBlock ($MESSAGE[30], '',
 197                              COM_getBlockTemplate ('_msg_block', 'header'));
 198          $display .= $LANG_DB_BACKUP['path_not_found'];
 199          $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
 200          COM_errorLog ("Backup directory '" . $_CONF['backup_path'] . "' does not exist or is not a directory", 1);
 201      }
 202  }
 203  
 204  // Show last ten backups
 205  
 206  $display .= listbackups();
 207  
 208  $display .= COM_siteFooter ();
 209  
 210  echo $display; 
 211  
 212  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics