Changeset 1810499
- Timestamp:
- 01/27/2018 04:34:00 PM (6 years ago)
- Location:
- wp-db-backup
- Files:
-
- 38 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-db-backup/trunk/README.markdown
r1366331 r1810499 �� 6 6 Tags: mysql, database, backup, cron 7 7 Requires at least: 3.6.0 8 Tested up to: 4. 4.29 Stable tag: 2.3. 18 Tested up to: 4..2 9 Stable tag: 2.3. 10 10 11 11 On-demand backup of your WordPress database. 12 12 13 Description 13 Description 14 14 ----------- 15 15 … … 21 21 NO WARRANTY. 22 22 23 Copyright (c) 201 5Austin Matzko23 Copyright (c) 201 Austin Matzko 24 24 25 25 [Source Code on GitHub](https://github.com/matzko/wp-db-backup) 26 26 27 Installation 27 Installation 28 28 ------------ 29 29 … … 105 105 When having the database backup emailed or sent to your browser for immediate download, the backup file will be _deleted_ from the server when the transfer is finished. 106 106 107 Changelog 107 Changelog 108 108 --------- 109 109 … … 117 117 * Do not attempt to delete non-existent files 118 118 119 2.2.3 119 2.2.3 120 120 ----- 121 121 * Nonce check fix for localized WP users from Sergey Biryukov … … 124 124 * Fix for JS multiple checkbox selection. 125 125 126 Upgrade Notice 126 2.3.3 127 ----- 128 * Sanitize user-supplied data 129 130 Upgrade Notice 127 131 -------------- 128 132 129 2.2.3 133 2.2.3 130 134 ----- 131 135 * Fixes problems users had when using localized WordPress installations. 132 136 * Fixes a bug that caused the size of gzipped backup files to be reported incorrectly. 133 137 134 Advanced 138 Advanced 135 139 -------- 136 140 If you are using WordPress version 2.1 or newer, you can schedule automated backups to be sent to the email address 137 141 of your choice. 138 142 139 Translators 143 Translators 140 144 ----------- 141 145 Thanks to following people for providing translation files for WP-DB-Backup: … … 174 178 * 吴曦 175 179 176 Past Contributors 180 Past Contributors 177 181 ----------------- 178 182 skippy, Firas, LaughingLizard, MtDewVirus, Podz, Ringmaster -
wp-db-backup/trunk/readme.txt
r1366331 r1810499 4 4 Tags: mysql, database, backup, cron 5 5 Requires at least: 3.6.0 6 Tested up to: 4. 4.27 Stable tag: 2.3. 16 Tested up to: 4..2 7 Stable tag: 2.3. 8 8 9 9 On-demand backup of your WordPress database. … … 18 18 NO WARRANTY. 19 19 20 Copyright (c) 201 6Austin Matzko20 Copyright (c) 201 Austin Matzko 21 21 22 22 [Source Code on GitHub](https://github.com/matzko/wp-db-backup) … … 26 26 1. Activate the plugin at your blog's Admin -> Plugins screen 27 27 1. The plugin will attempt to create a directory /wp-content/backup-*/ inside your WordPress directory. 28 1. You may need to make /wp-content writable (at least temporarily) for it to create this directory. 28 1. You may need to make /wp-content writable (at least temporarily) for it to create this directory. 29 29 For example: 30 30 `$ cd /wordpress/` … … 88 88 prefix = the table prefix for this WordPress blog, as defined in wp-config.php 89 89 date = CCYYmmdd_B format: 20050711_039 90 the "B" is the internet "Swatch" time. 90 the "B" is the internet "Swatch" time. 91 91 See the PHP date() function for details. 92 92 … … 102 102 * Do not attempt to delete non-existent files 103 103 104 = 2.2.3 = 104 = 2.2.3 = 105 105 * Nonce check fix for localized WP users from Sergey Biryukov 106 106 * Fix for gzipped files' incorrect size. … … 114 114 * Fixes a bug that caused the size of gzipped backup files to be reported incorrectly. 115 115 116 117 118 116 119 == Advanced == 117 If you are using WordPress version 2.1 or newer, you can schedule automated backups to be sent to the email address 120 If you are using WordPress version 2.1 or newer, you can schedule automated backups to be sent to the email address 118 121 of your choice. 119 122 -
wp-db-backup/trunk/wp-db-backup.php
r1366331 r1810499 4 4 Plugin URI: https://github.com/matzko/wp-db-backup 5 5 Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup">Tools → Backup</a> to get started. 6 Author: Austin Matzko 6 Author: Austin Matzko 7 7 Author URI: http://austinmatzko.com/ 8 Version: 2.3. 19 10 Copyright 201 6Austin Matzko (email : austin at pressedcode.com)8 Version: 2.3. 9 10 Copyright 201 Austin Matzko (email : austin at pressedcode.com) 11 11 12 12 This program is free software; you can redistribute it and/or modify … … 38 38 } 39 39 40 /** 41 * Set MOD_EVASIVE_OVERRIDE to true 42 * and increase MOD_EVASIVE_DELAY 40 /** 41 * Set MOD_EVASIVE_OVERRIDE to true 42 * and increase MOD_EVASIVE_DELAY 43 43 * if the backup stops prematurely. 44 44 */ … … 58 58 var $page_url; 59 59 var $referer_check_key; 60 var $version = '2. 1.5-alpha';60 var $version = '2.'; 61 61 62 62 function module_check() { … … 64 64 if ( defined( 'MOD_EVASIVE_OVERRIDE' ) && true === MOD_EVASIVE_OVERRIDE ) return true; 65 65 if ( ! defined( 'MOD_EVASIVE_OVERRIDE' ) || false === MOD_EVASIVE_OVERRIDE ) return false; 66 if ( function_exists('apache_get_modules') ) 67 foreach( (array) apache_get_modules() as $mod ) 66 if ( function_exists('apache_get_modules') ) 67 foreach( (array) apache_get_modules() as $mod ) 68 68 if ( false !== strpos($mod,'mod_evasive') || false !== strpos($mod,'mod_dosevasive') ) 69 69 return true; … … 71 71 } 72 72 73 function wpdbBackup() {73 function () { 74 74 global $table_prefix, $wpdb; 75 75 add_action('wp_ajax_save_backup_time', array(&$this, 'save_backup_time')); … … 81 81 add_filter('cron_schedules', array(&$this, 'add_sched_options')); 82 82 add_filter('wp_db_b_schedule_choices', array(&$this, 'schedule_choices')); 83 83 84 84 $table_prefix = ( isset( $table_prefix ) ) ? $table_prefix : $wpdb->prefix; 85 85 $datum = date("Ymd_B"); … … 109 109 } 110 110 } 111 112 $this->backup_dir = trailingslashit(apply_filters('wp_db_b_backup_dir', (isset($_GET['wp_db_temp_dir']) && is_writable($_GET['wp_db_temp_dir'])) ? $_GET['wp_db_temp_dir'] : get_temp_dir())); 111 112 $requested_temp_dir = sanitize_text_field($_GET['wp_db_temp_dir']); 113 $this->backup_dir = trailingslashit(apply_filters('wp_db_b_backup_dir', (isset($requested_temp_dir) && is_writable($requested_temp_dir)) ? $requested_temp_dir : get_temp_dir())); 113 114 $this->basename = 'wp-db-backup'; 114 115 115 116 $this->referer_check_key = $this->basename . '-download_' . DB_NAME; 116 117 if (isset($_POST['do_backup'])) { … … 118 119 check_admin_referer($this->referer_check_key); 119 120 $this->can_user_backup('main'); 121 120 122 // save exclude prefs 121 122 $exc_revisions = isset( $_POST['exclude-revisions'] ) ? (array) $_POST['exclude-revisions'] : array();123 $exc_spam = isset( $_POST['exclude-spam'] ) ? (array) $_POST['exclude-spam'] : array();124 update_option('wp_db_backup_excs', array('revisions' => $exc_revisions, 'spam' => $exc_spam));123 update_option('wp_db_backup_excs', array( 124 125 126 )); 125 127 switch($_POST['do_backup']) { 126 128 case 'backup': … … 129 131 case 'fragments': 130 132 add_action('admin_menu', array(&$this, 'fragment_menu')); 131 break; 133 break; 132 134 } 133 135 } elseif (isset($_GET['fragment'] )) { … … 141 143 } 142 144 } 143 145 144 146 function init() { 145 147 $this->can_user_backup(); 146 148 if (isset($_GET['backup'])) { 147 $via = isset($_GET['via']) ? $_GET['via']: 'http';148 149 $this->backup_file = $_GET['backup'];149 $via = isset($_GET['via']) ? : 'http'; 150 151 $this->backup_file = ; 150 152 $this->validate_file($this->backup_file); 151 153 … … 153 155 case 'smtp': 154 156 case 'email': 155 $success = $this->deliver_backup($this->backup_file, 'smtp', $_GET['recipient'], 'frame');157 $success = $this->deliver_backup($this->backup_file, 'smtp', , 'frame'); 156 158 $this->error_display( 'frame' ); 157 159 if ( $success ) { … … 162 164 echo ' 163 165 alert("' . __('Backup Complete!','wp-db-backup') . '"); 164 window.onbeforeunload = null; 166 window.onbeforeunload = null; 165 167 </script> 166 168 '; … … 170 172 $success = $this->deliver_backup($this->backup_file, $via); 171 173 echo $this->error_display( 'frame', false ); 172 174 173 175 if ( $success ) { 174 176 echo ' … … 182 184 } 183 185 if (isset($_GET['fragment'] )) { 184 list($table, $segment, $filename) = explode(':', $_GET['fragment']);186 list($table, $segment, $filename) = explode(':', ); 185 187 $this->validate_file($filename); 186 188 $this->backup_fragment($table, $segment, $filename); … … 207 209 function update_notice_action() { 208 210 global $pagenow; 209 if ( 211 if ( 210 212 ( 211 213 isset($_REQUEST['action']) … … 220 222 endif; 221 223 } 222 224 223 225 function update_notice($text = '') { 224 226 $pattern = '#(<a href\="' . __('http://codex.wordpress.org/WordPress_Backups') . '">.*?</p>)#'; 225 $replace = '$1' . "\n<p>" . sprintf(__('Click <a href="%s" target="_blank">here</a> to back up your database using the WordPress Database Backup plugin. <strong>Note:</strong> WordPress Database Backup does <em>not</em> back up your files, just your database.', 'wp-db-backup'), 'tools.php?page=wp-db-backup') . "</p>\n"; 227 $replace = '$1' . "\n<p>" . sprintf(__('Click <a href="%s" target="_blank">here</a> to back up your database using the WordPress Database Backup plugin. <strong>Note:</strong> WordPress Database Backup does <em>not</em> back up your files, just your database.', 'wp-db-backup'), 'tools.php?page=wp-db-backup') . "</p>\n"; 226 228 $text = preg_replace($pattern, $replace, $text); 227 229 return $text; … … 230 232 function build_backup_script() { 231 233 global $table_prefix, $wpdb; 232 234 233 235 echo "<div class='wrap'>"; 234 echo 236 echo '<fieldset class="options"><legend>' . __('Progress','wp-db-backup') . '</legend> 235 237 <p><strong>' . 236 238 __('DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:','wp-db-backup'). … … 270 272 fram.src = "' . $this->page_url . '&fragment=" + table + ":" + segment + ":' . $this->backup_filename . ':&wp_db_temp_dir=' . $this->backup_dir . '"; 271 273 } 272 274 273 275 var curStep = 0; 274 276 275 277 function nextStep() { 276 278 backupStep(curStep); 277 279 curStep++; 278 280 } 279 281 280 282 function finishBackup() { 281 var fram = document.getElementById("backuploader"); 283 var fram = document.getElementById("backuploader"); 282 284 setMeter(100); 283 285 '; … … 288 290 echo ' 289 291 setProgress("' . __('Preparing download.','wp-db-backup') . '"); 290 window.onbeforeunload = null; 292 window.onbeforeunload = null; 291 293 fram.src = "' . $download_uri . '"; 292 294 293 295 setTimeout( function() { 294 var secondFrame = document.createElement("iframe"); 296 var secondFrame = document.createElement("iframe"); 295 297 fram.parentNode.insertBefore(secondFrame, fram); 296 298 secondFrame.src = "' . $download_uri . '&download-retry=1"; … … 305 307 echo ' 306 308 setProgress("' . sprintf(__('Your backup has been emailed to %s','wp-db-backup'), $email) . '"); 307 window.onbeforeunload = null; 309 window.onbeforeunload = null; 308 310 fram.src = "' . $download_uri . '&via=email&recipient=' . $email . '"; 309 311 '; … … 312 314 echo ' 313 315 setProgress("' . __('Backup Complete!','wp-db-backup') . '"); 314 window.onbeforeunload = null; 316 window.onbeforeunload = null; 315 317 '; 316 318 } 317 319 318 320 echo ' 319 321 } 320 322 321 323 function backupStep(step) { 322 324 switch(step) { 323 325 case 0: backup("", 0); break; 324 326 '; 325 326 $also_backup = array(); 327 if (isset($_POST['other_tables'])) { 328 $also_backup = $_POST['other_tables']; 329 } else { 330 $also_backup = array(); 331 } 332 $core_tables = $_POST['core_tables']; 327 328 $also_backup = $this->get_post_data_array('other_tables'); 329 $core_tables = $this->get_post_data_array('core_tables'); 333 330 $tables = array_merge($core_tables, $also_backup); 334 331 $step_count = 1; … … 351 348 } 352 349 echo "case {$step_count}: finishBackup(); break;"; 353 350 354 351 echo ' 355 352 } … … 367 364 function backup_fragment($table, $segment, $filename) { 368 365 global $table_prefix, $wpdb; 369 366 370 367 echo "$table:$segment:$filename"; 371 368 372 369 if($table == '') { 373 370 $msg = __('Creating backup file...','wp-db-backup'); … … 379 376 } 380 377 } 381 378 382 379 if (is_writable($this->backup_dir)) { 383 380 $this->fp = $this->open($this->backup_dir . $filename, 'a'); … … 387 384 } 388 385 else { 389 if($table == '') { 386 if($table == '') { 390 387 //Begin new backup of MySql 391 388 $this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n"); … … 403 400 $this->stow("# " . sprintf(__('Table: %s','wp-db-backup'),$this->backquote($table)) . "\n"); 404 401 $this->stow("# --------------------------------------------------------\n"); 405 } 402 } 406 403 $this->backup_table($table, $segment); 407 404 } … … 412 409 413 410 if($this->fp) $this->close($this->fp); 414 411 415 412 $this->error_display('frame'); 416 413 … … 428 425 $also_backup = array(); 429 426 if (isset($_POST['other_tables'])) 430 $also_backup = $_POST['other_tables'];431 $core_tables = $_POST['core_tables'];427 $also_backup = ; 428 $core_tables = ; 432 429 $this->backup_file = $this->db_backup($core_tables, $also_backup); 433 430 if (false !== $this->backup_file) { 434 431 if ('smtp' == $_POST['deliver']) { 435 432 $email = sanitize_text_field(wp_unslash($_POST['backup_recipient'])); 436 $this->deliver_backup($this->backup_file, $_POST['deliver'], $email, 'main');433 $this->deliver_backup($this->backup_file, , $email, 'main'); 437 434 if ( get_option('wpdb_backup_recip') != $email ) { 438 435 update_option('wpdb_backup_recip', $email ); … … 441 438 } elseif ('http' == $_POST['deliver']) { 442 439 $download_uri = add_query_arg('backup',$this->backup_file,$this->page_url); 443 wp_redirect($download_uri); 440 wp_redirect($download_uri); 444 441 exit; 445 442 } … … 478 475 t[k].p[i].onkeyup = t[k].p[i].onclick = function(e) { 479 476 e = e ? e : event; 480 if ( 16 == e.keyCode ) 477 if ( 16 == e.keyCode ) 481 478 return; 482 479 var match = /([\w-]*)-table-(\d*)/.exec(this.id); … … 498 495 499 496 <?php if ( function_exists('wp_schedule_event') ) : // needs to be at least WP 2.1 for ajax ?> 500 if ( 'undefined' == typeof XMLHttpRequest ) 497 if ( 'undefined' == typeof XMLHttpRequest ) 501 498 var xml = new ActiveXObject( navigator.userAgent.indexOf('MSIE 5') >= 0 ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP' ); 502 499 else … … 507 504 var backupTime = document.getElementById('next-backup-time'); 508 505 if ( !! timeWrap && !! backupTime && ( 1 == <?php 509 echo (int) ( 'en' == strtolower( substr( get_locale(), 0, 2 ) ) ); 506 echo (int) ( 'en' == strtolower( substr( get_locale(), 0, 2 ) ) ); 510 507 ?> ) ) { 511 508 var span = document.createElement('span'); … … 529 526 saveTButton.onclick = function(e) { saveTime(backupTime, mainText); return false; }; 530 527 if ( !! mainText ) 531 mainText.onkeydown = function(e) { 528 mainText.onkeydown = function(e) { 532 529 e = e || window.event; 533 530 if ( 13 == e.keyCode ) { … … 591 588 padding: 1em; 592 589 } 593 590 594 591 fieldset.options .instructions { 595 592 font-size: smaller; … … 607 604 } 608 605 </style> 609 <?php 606 <?php 610 607 } 611 608 … … 637 634 } 638 635 639 /** 636 /** 640 637 * Add WP-DB-Backup-specific help options to the 2.7 =< WP contextual help menu 641 638 * @return string The text of the help menu. … … 673 670 else $a_string = str_replace('\\', '\\\\', $a_string); 674 671 return str_replace('\'', '\\\'', $a_string); 675 } 672 } 676 673 677 674 /** … … 684 681 $result = array(); 685 682 reset($a_name); 686 while(list($key, $val) = each($a_name)) 683 while(list($key, $val) = each($a_name)) 687 684 $result[$key] = '`' . $val . '`'; 688 685 return $result; … … 693 690 return $a_name; 694 691 } 695 } 692 } 696 693 697 694 function open($filename = '', $mode = 'w') { … … 714 711 $this->error(__('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg); 715 712 } 716 713 717 714 /** 718 715 * Logs any error messages … … 721 718 */ 722 719 function error($args = array()) { 723 if ( is_string( $args ) ) 720 if ( is_string( $args ) ) 724 721 $args = array('msg' => $args); 725 722 $args = array_merge( array('loc' => 'main', 'kind' => 'warn', 'msg' => ''), $args); … … 731 728 732 729 /** 733 * Displays error messages 730 * Displays error messages 734 731 * @param array $errs 735 732 * @param string $loc … … 747 744 $err_list[9] = __('Subsequent errors have been omitted from this log.','wp-db-backup'); 748 745 $wrap = ( 'frame' == $loc ) ? "<script type=\"text/javascript\">\n var msgList = ''; \n %1\$s \n if ( msgList ) alert(msgList); \n </script>" : '%1$s'; 749 $line = ( 'frame' == $loc ) ? 746 $line = ( 'frame' == $loc ) ? 750 747 "try{ window.parent.addError('%1\$s'); } catch(e) { msgList += ' %1\$s';}\n" : 751 748 "%1\$s<br />\n"; … … 767 764 * Alain Wolf, Zurich - Switzerland 768 765 * Website: http://restkultur.ch/personal/wolf/scripts/db_backup/ 769 770 * Modified by Scott Merrill (http://www.skippy.net/) 766 767 * Modified by Scott Merrill (http://www.skippy.net/) 771 768 * to use the WordPress $wpdb object 772 769 * @param string $table … … 782 779 return false; 783 780 } 784 781 785 782 if(($segment == 'none') || ($segment == 0)) { 786 783 // Add SQL statement to drop existing table … … 791 788 $this->stow("\n"); 792 789 $this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n"); 793 790 794 791 // Table structure 795 792 // Comment in SQL-file … … 799 796 $this->stow("#\n"); 800 797 $this->stow("\n"); 801 798 802 799 $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N); 803 800 if (false === $create_table) { … … 807 804 } 808 805 $this->stow($create_table[0][1] . ' ;'); 809 806 810 807 if (false === $table_structure) { 811 808 $err_msg = sprintf(__('Error getting table structure of %s','wp-db-backup'), $table); … … 813 810 $this->stow("#\n# $err_msg\n#\n"); 814 811 } 815 812 816 813 // Comment in SQL-file 817 814 $this->stow("\n\n"); … … 820 817 $this->stow("#\n"); 821 818 } 822 819 823 820 if(($segment == 'none') || ($segment >= 0)) { 824 821 $defs = array(); … … 834 831 } 835 832 } 836 837 833 834 838 835 // Batch by $row_inc 839 836 840 837 if($segment == 'none') { 841 838 $row_start = 0; … … 845 842 $row_inc = ROWS_PER_SEGMENT; 846 843 } 847 848 do { 844 845 do { 849 846 // don't include extra stuff, if so requested 850 847 $excs = (array) get_option('wp_db_backup_excs'); … … 855 852 $where = ' WHERE post_type != "revision"'; 856 853 } 857 854 858 855 if ( !ini_get('safe_mode')) @set_time_limit(15*60); 859 856 $table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A); 860 857 861 $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES ('; 858 $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES ('; 862 859 // \x08\\x09, not required 863 860 $search = array("\x00", "\x0a", "\x0d", "\x1a"); … … 882 879 } while((count($table_data) > 0) and ($segment=='none')); 883 880 } 884 881 885 882 if(($segment == 'none') || ($segment < 0)) { 886 883 // Create footer/closing comment in SQL-file … … 892 889 } 893 890 } // end backup_table() 894 891 895 892 function db_backup($core_tables, $other_tables) { 896 893 global $table_prefix, $wpdb; 897 894 898 895 if (is_writable($this->backup_dir)) { 899 896 $this->fp = $this->open($this->backup_dir . $this->backup_filename); … … 906 903 return false; 907 904 } 908 905 909 906 //Begin new backup of MySql 910 907 $this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n"); … … 914 911 $this->stow("# " . sprintf(__('Database: %s','wp-db-backup'),$this->backquote(DB_NAME)) . "\n"); 915 912 $this->stow("# --------------------------------------------------------\n"); 916 913 917 914 if ( (is_array($other_tables)) && (count($other_tables) > 0) ) 918 915 $tables = array_merge($core_tables, $other_tables); 919 916 else 920 917 $tables = $core_tables; 921 918 922 919 foreach ($tables as $table) { 923 920 // Increase script execution time-limit to 15 min for every table. … … 929 926 $this->backup_table($table); 930 927 } 931 928 932 929 $this->close($this->fp); 933 930 934 931 if (count($this->errors)) { 935 932 return false; … … 937 934 return $this->backup_filename; 938 935 } 939 936 940 937 } //wp_db_backup 941 938 … … 965 962 // try to use phpmailer directly (WP 2.2+) 966 963 if ( is_object( $phpmailer ) && ( strtolower(get_class( $phpmailer )) == 'phpmailer' ) ) { 967 964 968 965 // Get the site domain and get rid of www. 969 $sitename = strtolower( $_SERVER['SERVER_NAME'] ); 970 if ( substr( $sitename, 0, 4 ) == 'www.' ) { 971 $sitename = substr( $sitename, 4 ); 972 } 966 $sitename = $this->get_sitename(); 973 967 $from_email = 'wordpress@' . $sitename; 974 968 $from_name = 'WordPress'; … … 993 987 994 988 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); 995 989 996 990 $result = @$phpmailer->Send(); 997 991 … … 1001 995 $boundary = "==WPBACKUP-$randomish"; 1002 996 $fp = fopen($diskfile,"rb"); 1003 $file = fread($fp,filesize($diskfile)); 997 $file = fread($fp,filesize($diskfile)); 1004 998 $this->close($fp); 1005 999 1006 1000 $data = chunk_split(base64_encode($file)); 1007 1001 1008 1002 $headers .= "MIME-Version: 1.0\n"; 1009 $headers = 'From: wordpress@' . preg_replace('#^www\.#', '', s trtolower($_SERVER['SERVER_NAME'])) . "\n";1003 $headers = 'From: wordpress@' . preg_replace('#^www\.#', '', s)) . "\n"; 1010 1004 $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n"; 1011 1005 1012 1006 // Add a multipart boundary above the plain message 1013 1007 $message = "This is a multi-part message in MIME format.\n\n" . 1014 1008 "--{$boundary}\n" . 1015 1009 "Content-Type: text/plain; charset=\"" . get_bloginfo('charset') . "\"\n" . 1016 1010 "Content-Transfer-Encoding: 7bit\n\n" . … … 1026 1020 $data . "\n\n" . 1027 1021 "--{$boundary}--\n"; 1028 1022 1029 1023 $result = @wp_mail($to, $subject, $message, $headers); 1030 1024 } … … 1035 1029 function deliver_backup($filename = '', $delivery = 'http', $recipient = '', $location = 'main') { 1036 1030 if ('' == $filename) { return false; } 1037 1031 1038 1032 $diskfile = $this->backup_dir . $filename; 1039 1033 $gz_diskfile = "{$diskfile}.gz"; … … 1060 1054 $diskfile = $gz_diskfile; 1061 1055 $filename = "{$filename}.gz"; 1062 1056 1063 1057 /** 1064 * Try to compress to gzip, if available 1058 * Try to compress to gzip, if available 1065 1059 */ 1066 1060 } else { … … 1082 1076 } 1083 1077 /* 1084 * 1078 * 1085 1079 */ 1086 1080 } elseif ( file_exists( $gz_diskfile ) && empty( $_GET['download-retry'] ) ) { … … 1091 1085 if ('http' == $delivery) { 1092 1086 if ( ! file_exists( $diskfile ) ) { 1093 if ( empty( $_GET['download-retry'] ) ) { 1087 if ( empty( $_GET['download-retry'] ) ) { 1094 1088 $this->error(array('kind' => 'fatal', 'msg' => sprintf(__('File not found:%s','wp-db-backup'), " <strong>$filename</strong><br />") . '<br /><a href="' . $this->page_url . '">' . __('Return to Backup','wp-db-backup') . '</a>')); 1095 1089 } else { … … 1124 1118 $msg .= $err['message']; 1125 1119 } else { 1126 $msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup'); 1120 $msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup'); 1127 1121 } 1128 1122 $this->error(array('kind' => 'fatal', 'loc' => $location, 'msg' => $msg)); … … 1135 1129 return $success; 1136 1130 } 1137 1131 1138 1132 function backup_menu() { 1139 1133 global $table_prefix, $wpdb; 1140 1134 $feedback = ''; 1141 1135 $whoops = false; 1142 1136 1143 1137 // did we just do a backup? If so, let's report the status 1144 1138 if ( $this->backup_complete ) { … … 1161 1155 $feedback .= '</p></div>'; 1162 1156 } 1163 1157 1164 1158 // security check 1165 $this->wp_secure(); 1159 $this->wp_secure(); 1166 1160 1167 1161 if (count($this->errors)) { … … 1172 1166 1173 1167 // did we just save options for wp-cron? 1174 if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init')) 1168 if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init')) 1175 1169 && isset($_POST['wp_cron_backup_options']) ) : 1176 1170 do_action('wp_db_b_update_cron_options'); … … 1178 1172 wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous 1179 1173 $scheds = (array) wp_get_schedules(); 1180 $name = s trval($_POST['wp_cron_schedule']);1181 $interval = ( isset($scheds[$name]['interval']) ) ? 1174 $name = s); 1175 $interval = ( isset($scheds[$name]['interval']) ) ? 1182 1176 (int) $scheds[$name]['interval'] : 0; 1183 1177 update_option('wp_cron_backup_schedule', $name, false); … … 1189 1183 update_option('wp_cron_backup_schedule', intval($_POST['cron_schedule']), false); 1190 1184 } 1191 update_option('wp_cron_backup_tables', isset( $_POST['wp_cron_backup_tables'] ) ? $_POST['wp_cron_backup_tables'] : array());1185 update_option('wp_cron_backup_tables', ); 1192 1186 if (is_email($_POST['cron_backup_recipient'])) { 1193 update_option('wp_cron_backup_recipient', $_POST['cron_backup_recipient'], false);1187 update_option('wp_cron_backup_recipient', , false); 1194 1188 } 1195 1189 $feedback .= '<div class="updated wp-db-backup-updated"><p>' . __('Scheduled Backup Options Saved!','wp-db-backup') . '</p></div>'; 1196 1190 endif; 1197 1191 1198 1192 $other_tables = array(); 1199 1193 $also_backup = array(); 1200 1201 // Get complete db table list 1194 1195 // Get complete db table list 1202 1196 $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N); 1203 1197 $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables); … … 1206 1200 // Get list of non-WP tables 1207 1201 $other_tables = array_diff($all_tables, $wp_backup_default_tables); 1208 1202 1209 1203 if ('' != $feedback) 1210 1204 echo $feedback; 1211 1205 1212 if ( ! $this->wp_secure() ) 1206 if ( ! $this->wp_secure() ) 1213 1207 return; 1214 1208 … … 1227 1221 ?><div class="updated wp-db-backup-updated error"><p><?php _e('WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.','wp-db-backup'); ?></p> 1228 1222 <p><?php printf(__('Using your FTP client, try to set the backup directory’s write permission to %1$s or %2$s: %3$s', 'wp-db-backup'), '<code>777</code>', '<code>a+w</code>', '<code>' . $this->backup_dir . '</code>'); ?> 1229 </p></div><?php 1223 </p></div><?php 1230 1224 $whoops = true; 1231 1225 } else { 1232 1226 $this->fp = $this->open($this->backup_dir . 'test' ); 1233 if( $this->fp ) { 1227 if( $this->fp ) { 1234 1228 $this->close($this->fp); 1235 1229 @unlink($this->backup_dir . 'test' ); 1236 1230 // the directory is not writable probably due to safe mode 1237 1231 } else { 1238 ?><div class="updated wp-db-backup-updated error"><p><?php _e('WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.','wp-db-backup'); ?></p><?php 1232 ?><div class="updated wp-db-backup-updated error"><p><?php _e('WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.','wp-db-backup'); ?></p><?php 1239 1233 if( ini_get('safe_mode') ){ 1240 ?><p><?php _e('This problem seems to be caused by your server’s <code>safe_mode</code> file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup'); ?></p><?php 1234 ?><p><?php _e('This problem seems to be caused by your server’s <code>safe_mode</code> file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup'); ?></p><?php 1241 1235 } 1242 1236 ?><?php printf(__('You can try to correct this problem by using your FTP client to delete and then re-create the backup directory: %s', 'wp-db-backup'), '<code>' . $this->backup_dir . '</code>'); 1243 ?></div><?php 1237 ?></div><?php 1244 1238 $whoops = true; 1245 1239 } 1246 1240 } 1247 1241 1248 1242 1249 1243 1250 1244 if ( !file_exists($this->backup_dir . 'index.php') ) … … 1272 1266 </div> 1273 1267 <div class="tables-list extra-tables" id="extra-tables-list"> 1274 <?php 1275 if (count($other_tables) > 0) { 1268 <?php 1269 if (count($other_tables) > 0) { 1276 1270 ?> 1277 1271 <h4><?php _e('You may choose to include any of the following tables:','wp-db-backup'); ?></h4> … … 1281 1275 ?> 1282 1276 <li><label><input type="checkbox" name="other_tables[]" value="<?php echo $table; ?>" /> <code><?php echo $table; ?></code></label> 1283 <?php 1284 } 1285 ?></ul><?php 1277 <?php 1278 } 1279 ?></ul><?php 1286 1280 } 1287 1281 ?></div> 1288 1282 </fieldset> 1289 1283 1290 1284 <fieldset class="options"> 1291 1285 <legend><?php _e('Backup Options','wp-db-backup'); ?></legend> … … 1299 1293 <input type="radio" name="deliver" id="do_email" value="smtp" style="border:none;" /> 1300 1294 <?php _e('Email backup to:','wp-db-backup'); ?> 1301 <input type="text" name="backup_recipient" size="20" value="<?php 1295 <input type="text" name="backup_recipient" size="20" value="<?php 1302 1296 $backup_recip = get_option('wpdb_backup_recip'); 1303 1297 if ( empty( $backup_recip ) ) { … … 1309 1303 </ul> 1310 1304 <?php if ( ! $whoops ) : ?> 1311 <input type="hidden" name="do_backup" id="do_backup" value="backup" /> 1305 <input type="hidden" name="do_backup" id="do_backup" value="backup" /> 1312 1306 <p class="submit"> 1313 1307 <input type="submit" name="submit" onclick="document.getElementById('do_backup').value='fragments';" value="<?php _e('Backup now!','wp-db-backup'); ?>" /> … … 1319 1313 <?php do_action('wp_db_b_backup_opts'); ?> 1320 1314 </form> 1321 1315 1322 1316 <?php 1323 // this stuff only displays if some sort of wp-cron is available 1317 // this stuff only displays if some sort of wp-cron is available 1324 1318 $cron = ( function_exists('wp_schedule_event') ) ? true : false; // wp-cron in WP 2.1+ 1325 1319 $cron_old = ( function_exists('wp_cron_init') && ! $cron ) ? true : false; // wp-cron plugin by Skippy … … 1334 1328 <?php printf(__('Next Backup: %s','wp-db-backup'), '<span id="next-backup-time">' . gmdate($datetime, $next_cron + (get_option('gmt_offset') * 3600)) . '</span>'); ?> 1335 1329 </p> 1336 <?php 1330 <?php 1337 1331 endif; 1338 1332 elseif ( $cron_old ) : 1339 ?><p><?php printf(__('Last WP-Cron Daily Execution: %s','wp-db-backup'), gmdate($datetime, get_option('wp_cron_daily_lastrun') + (get_option('gmt_offset') * 3600))); ?><br /><?php 1340 printf(__('Next WP-Cron Daily Execution: %s','wp-db-backup'), gmdate($datetime, (get_option('wp_cron_daily_lastrun') + (get_option('gmt_offset') * 3600) + 86400))); ?></p><?php 1333 ?><p><?php printf(__('Last WP-Cron Daily Execution: %s','wp-db-backup'), gmdate($datetime, get_option('wp_cron_daily_lastrun') + (get_option('gmt_offset') * 3600))); ?><br /><?php 1334 printf(__('Next WP-Cron Daily Execution: %s','wp-db-backup'), gmdate($datetime, (get_option('wp_cron_daily_lastrun') + (get_option('gmt_offset') * 3600) + 86400))); ?></p><?php 1341 1335 endif; 1342 1336 ?><form method="post" action=""> … … 1344 1338 <div class="tables-list"> 1345 1339 <h4><?php _e('Schedule: ','wp-db-backup'); ?></h4> 1346 <?php 1340 <?php 1347 1341 if ( $cron_old ) : 1348 1342 $wp_cron_backup_schedule = get_option('wp_cron_backup_schedule'); … … 1385 1379 echo '</fieldset>'; 1386 1380 endif; // end of wp_cron (legacy) section 1387 1381 1388 1382 echo '</div><!-- .wrap -->'; 1389 1383 1390 1384 } // end wp_backup_menu() 1391 1385 1392 1386 function get_sched() { 1393 1387 $options = array_keys( (array) wp_get_schedules() ); 1394 $freq = get_option('wp_cron_backup_schedule'); 1388 $freq = get_option('wp_cron_backup_schedule'); 1395 1389 $freq = ( in_array( $freq , $options ) ) ? $freq : 'never'; 1396 1390 return $freq; … … 1422 1416 return $menu; 1423 1417 } // end schedule_choices() 1424 1418 1425 1419 function wp_cron_daily() { // for legacy cron plugin 1426 1420 $schedule = intval(get_option('wp_cron_backup_schedule')); … … 1429 1423 return; 1430 1424 else return $this->cron_backup(); 1431 } 1425 } 1432 1426 1433 1427 function cron_backup() { … … 1439 1433 $recipient = get_option('wp_cron_backup_recipient'); 1440 1434 $backup_file = $this->db_backup($core_tables, $other_tables); 1441 if (false !== $backup_file) 1435 if (false !== $backup_file) 1442 1436 return $this->deliver_backup($backup_file, 'smtp', $recipient, 'main'); 1443 1437 else return false; … … 1450 1444 1451 1445 /** 1452 * Checks that WordPress has sufficient security measures 1446 * Checks that WordPress has sufficient security measures 1453 1447 * @param string $kind 1454 1448 * @return bool … … 1475 1469 if ( ( $this->wp_secure('fatal', $loc) ) && current_user_can('import') ) 1476 1470 $can = $this->verify_nonce($_REQUEST['_wpnonce'], $this->referer_check_key, $loc); 1477 if ( false == $can ) 1471 if ( false == $can ) 1478 1472 $this->error(array('loc' => $loc, 'kind' => 'fatal', 'msg' => __('You are not allowed to perform backups.','wp-db-backup'))); 1479 1473 return $can; … … 1490 1484 if ( wp_verify_nonce($rec, $nonce) ) 1491 1485 return true; 1492 else 1486 else 1493 1487 $this->error(array('loc' => $loc, 'kind' => 'fatal', 'msg' => sprintf(__('There appears to be an unauthorized attempt from this site to access your database located at %1s. The attempt has been halted.','wp-db-backup'),get_option('home')))); 1494 1488 } 1495 1489 1496 1490 /** 1497 * Check whether a file to be downloaded is 1491 * Check whether a file to be downloaded is 1498 1492 * surreptitiously trying to download a non-backup file 1499 1493 * @param string $file 1500 1494 * @return null 1501 */ 1495 */ 1502 1496 function validate_file($file) { 1503 1497 if ( (false !== strpos($file, '..')) || (false !== strpos($file, './')) || (':' == substr($file, 1, 1)) ) … … 1505 1499 } 1506 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1507 1590 } 1508 1591 1509 1592 function wpdbBackup_init() { 1510 1593 global $mywpdbbackup; 1511 $mywpdbbackup = new wpdbBackup(); 1594 $mywpdbbackup = new wpdbBackup(); 1512 1595 } 1513 1596
Note: See TracChangeset
for help on using the changeset viewer.