From 9145937a9f4f315c2b1316f09cb6da7fcfa34b32 Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Fri, 3 Aug 2001 13:16:59 +0000 Subject: [PATCH] Added gzip compression for downloadable file git-svn-id: file:///svn/phpbb/trunk@805 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/admin/admin_db_utilities.php | 106 +++++++++++++----- phpBB/language/lang_english.php | 1 + .../PSO/admin/db_utils_backup_body.tpl | 22 ++-- 3 files changed, 90 insertions(+), 39 deletions(-) diff --git a/phpBB/admin/admin_db_utilities.php b/phpBB/admin/admin_db_utilities.php index 350012cca0..f8ce716673 100644 --- a/phpBB/admin/admin_db_utilities.php +++ b/phpBB/admin/admin_db_utilities.php @@ -28,10 +28,6 @@ * adapted from the unoficial phpMyAdmin 2.2.0. ***************************************************************************/ -// -// Do the setmodules stuff for the admin control panel. -// - if($setmodules == 1) { $filename = basename(__FILE__); @@ -41,12 +37,36 @@ if($setmodules == 1) return; } +$phpbb_root_path = "./../"; +include($phpbb_root_path . 'extension.inc'); +include($phpbb_root_path . 'common.'.$phpEx); + +// +// Start session management +// +$userdata = session_pagestart($user_ip, PAGE_INDEX, $session_length); +init_userprefs($userdata); +// +// End session management +// + +// +// Is user logged in? If yes are they an admin? +// +if( !$userdata['session_logged_in'] ) +{ + header("Location: ../login.$phpEx?forward_page=admin/"); +} +else if( $userdata['user_level'] != ADMIN ) +{ + message_die(GENERAL_MESSAGE, $lang['Not_admin']); +} + // // Set VERBOSE to 1 for debugging info.. // define("VERBOSE", 0); - // // Increase maximum execution time, but don't complain about it if it isn't // allowed. @@ -727,21 +747,6 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) { $perform = (isset($HTTP_POST_VARS['perform'])) ? $HTTP_POST_VARS['perform'] : $HTTP_GET_VARS['perform']; - if( $perform == 'backup' - && ( isset($HTTP_POST_VARS['backupstart']) || isset($HTTP_GET_VARS['backupstart']) ) - && !isset($HTTP_POST_VARS['startdownload']) && !isset($HTTP_GET_VARS['startdownload']) - ) - { - // We want to warn the user before the download starts.. This part of the script - // needs a META header so we can't include the header yet. - $no_page_header = TRUE; - } - // - // Include required files, get $phpEx and check permissions - // - require('pagestart.inc'); - - switch($perform) { case 'backup': @@ -753,7 +758,7 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) case 'oracle': $db_type = "Oracle"; break; - case 'ofbc': + case 'odbc': $db_type = "ODBC"; break; case 'mssql': @@ -761,6 +766,8 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) break; } + include('page_header_admin.'.$phpEx); + $template->set_filenames(array( "body" => "admin/admin_message_body.tpl") ); @@ -775,11 +782,14 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) break; } - $tables = array('auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'session', 'smilies', 'themes', 'themes_name', 'topics', 'user_group', 'users', 'words'); + $tables = array('auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'session', 'smilies', 'themes', 'themes_name', 'topics', 'user_group', 'users', 'words'); $additional_tables = (isset($HTTP_POST_VARS['additional_tables'])) ? $HTTP_POST_VARS['additional_tables'] : ( (isset($HTTP_GET_VARS['additional_tables'])) ? $HTTP_GET_VARS['additional_tables'] : "" ); + $backup_type = (isset($HTTP_POST_VARS['backup_type'])) ? $HTTP_POST_VARS['backup_type'] : ( (isset($HTTP_GET_VARS['backup_type'])) ? $HTTP_GET_VARS['backup_type'] : "" ); + $gzipcompress = (!empty($HTTP_POST_VARS['gzipcompress'])) ? $HTTP_POST_VARS['gzipcompress'] : ( (!empty($HTTP_GET_VARS['gzipcompress'])) ? $HTTP_GET_VARS['gzipcompress'] : 0 ); + if(!empty($additional_tables)) { if(ereg(",", $additional_tables)) @@ -800,11 +810,13 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) if( !isset($HTTP_POST_VARS['backupstart']) && !isset($HTTP_GET_VARS['backupstart'])) { + include('page_header_admin.'.$phpEx); + $template->set_filenames(array( "body" => "admin/db_utils_backup_body.tpl") ); - $s_hidden_fields = ""; + $s_hidden_fields = ""; $template->assign_vars(array( "L_DATABASE_BACKUP" => $lang['Database_Utilities'] . " : " . $lang['Backup'], @@ -814,7 +826,10 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) "L_DATA_BACKUP" => $lang['Data_backup'], "L_ADDITIONAL_TABLES" => $lang['Additional_tables'], "L_START_BACKUP" => $lang['Start_backup'], - "L_BACKUP_OPTIONS" => $lang['Backup_options'], + "L_BACKUP_OPTIONS" => $lang['Backup_options'], + "L_GZIP_COMPRESS" => $lang['Gzip_compress'], + "L_NO" => $lang['No'], + "L_YES" => $lang['Yes'], "S_HIDDEN_FIELDS" => $s_hidden_fields, "S_DBUTILS_ACTION" => append_sid("admin_db_utilities.$phpEx")) @@ -826,13 +841,12 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) } else if( !isset($HTTP_POST_VARS['startdownload']) && !isset($HTTP_GET_VARS['startdownload']) ) { - $template->set_filenames(array( "body" => "admin/admin_message_body.tpl") ); $template->assign_vars(array( - "META" => "", + "META" => "", "MESSAGE_TITLE" => $lang['Database_Utilities'] . " : " . $lang['Backup'], "MESSAGE_TEXT" => $lang['Backup_download']) @@ -881,11 +895,36 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) // // move forward with sending the file across... // - header("Content-Type: text/x-delimtext; name=\"phpbb_db_backup.sql\""); - header("Content-disposition: attachment; filename=phpbb_db_backup.sql"); header("Pragma: no-cache"); - echo $backup_sql; + $do_gzip_compress = FALSE; + if( $gzipcompress ) + { + $phpver = phpversion(); + + if($phpver >= "4.0") + { + if(extension_loaded("zlib")) + { + $do_gzip_compress = TRUE; + } + } + } + + if($do_gzip_compress) + { + header("Content-Type: text/x-delimtext; name=\"phpbb_db_backup.sql.gz\""); + header("Content-disposition: attachment; filename=phpbb_db_backup.sql.gz"); + + echo gzencode($backup_sql); + } + else + { + header("Content-Type: text/x-delimtext; name=\"phpbb_db_backup.sql\""); + header("Content-disposition: attachment; filename=phpbb_db_backup.sql"); + + echo $backup_sql; + } exit; @@ -897,6 +936,8 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) // // Define Template files... // + include('page_header_admin.'.$phpEx); + $template->set_filenames(array( "body" => "admin/db_utils_restore_body.tpl") ); @@ -925,6 +966,7 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) // if($backup_file == "none") { + include('page_header_admin.'.$phpEx); message_die(GENERAL_ERROR, "Backup file upload failed"); } // @@ -943,6 +985,7 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) } else { + include('page_header_admin.'.$phpEx); message_die(GENERAL_ERROR, "Trouble Accessing uploaded file"); } @@ -970,12 +1013,15 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) if(!$result && ( !(SQL_LAYER == 'postgres' && eregi("drop table", $sql) ) ) ) { + include('page_header_admin.'.$phpEx); message_die(GENERAL_ERROR, "Error importing backup file", "", __LINE__, __FILE__, mysql_error() ."
". $sql); } } } } + include('page_header_admin.'.$phpEx); + $template->set_filenames(array( "body" => "admin/admin_message_body.tpl") ); @@ -996,4 +1042,4 @@ if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) ) include('page_footer_admin.'.$phpEx); -?> +?> \ No newline at end of file diff --git a/phpBB/language/lang_english.php b/phpBB/language/lang_english.php index 0f76e40a93..09921689e6 100755 --- a/phpBB/language/lang_english.php +++ b/phpBB/language/lang_english.php @@ -679,6 +679,7 @@ $lang['Full_backup'] = "Full backup"; $lang['Structure_backup'] = "Structure Only backup"; $lang['Data_backup'] = "Data only backup"; $lang['Additional_tables'] = "Additional tables"; +$lang['Gzip_compress'] = "Gzip compress file"; $lang['Select_file'] = "Select a file"; $lang['Start_Restore'] = "Start Restore"; $lang['Restore_success'] = "The Database has been successfully restored.

Your board should be back to the state it was when the backup was made."; diff --git a/phpBB/templates/PSO/admin/db_utils_backup_body.tpl b/phpBB/templates/PSO/admin/db_utils_backup_body.tpl index 73a65ad016..c34d3c9958 100644 --- a/phpBB/templates/PSO/admin/db_utils_backup_body.tpl +++ b/phpBB/templates/PSO/admin/db_utils_backup_body.tpl @@ -5,29 +5,33 @@

{L_BACKUP_EXPLAIN}

- - +
+ - + - + - + - + - - -
{L_BACKUP_OPTIONS}
{L_FULL_BACKUP}
{L_STRUCTURE_BACKUP}
{L_DATA_BACKUP}
{L_ADDITIONAL_TABLES}
{S_HIDDEN_FIELDS}
+ {L_GZIP_COMPRESS} + {L_NO}  {L_YES} + + + {S_HIDDEN_FIELDS} + +