Version Description
- Security enhancements
- Major user interface improvements
- Improvements to upload functionality
- Add Feature: Backup Email Notifications
- Add Feature: Backup Retention
- Bug fix: Create Backup & Restore folders on activation
- Updates to license activation
Download this release
Release Info
Developer | cssimmon |
Plugin | Backup and Restore WordPress – WPBackItUp Backup Plugin |
Version | 1.7.0 |
Comparing to | |
See all releases |
Code changes from version 1.6.7 to 1.7.0
- css/admin.css +22 -1
- index.php +0 -376
- js/admin.js +347 -177
- js/ajaxfileupload.js +0 -204
- lib/constants.php +0 -46
- lib/functions.php +0 -899
- lib/includes/RecursiveFilter_Iterator.php +0 -30
- lib/includes/auto_update.php +0 -141
- lib/includes/backup.php +449 -113
- lib/includes/class-backup.php +54 -0
- lib/includes/class-filesystem.php +308 -0
- lib/includes/class-logger.php +117 -0
- lib/includes/class-recursiveFilter_Iterator.php +34 -0
- lib/includes/class-restore.php +41 -0
- lib/includes/class-sql.php +387 -0
- lib/includes/class-utility.php +50 -0
- lib/includes/class-wpbackitup-admin.php +960 -0
- lib/includes/class-zip.php +1 -0
- lib/includes/recurse_zip.php +0 -1
- lib/includes/restore.php +265 -226
- lib/includes/upload.php +105 -37
- lib/includes/viewlog.php +40 -0
- readme.txt +12 -3
- views/backup.php +262 -0
- views/options.php +0 -281
- views/restore.php +177 -0
- views/settings.php +71 -0
- wp-backitup.php +79 -0
css/admin.css
CHANGED
@@ -84,7 +84,28 @@ iframe {
|
|
84 |
}
|
85 |
|
86 |
/** Status Reporting **/
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
display: none;
|
89 |
}
|
90 |
|
84 |
}
|
85 |
|
86 |
/** Status Reporting **/
|
87 |
+
.backup-status,
|
88 |
+
.backup-status span,
|
89 |
+
|
90 |
+
.backup-errors,
|
91 |
+
.backup-errors div,
|
92 |
+
.backup-unexpected-error,
|
93 |
+
|
94 |
+
.backup-success,
|
95 |
+
.backup-success div,
|
96 |
+
|
97 |
+
.restore-status,
|
98 |
+
.restore-status span,
|
99 |
+
|
100 |
+
.restore-errors,
|
101 |
+
.restore-errors div,
|
102 |
+
|
103 |
+
.restore-success,
|
104 |
+
.restore-success div,
|
105 |
+
|
106 |
+
.upload-status,
|
107 |
+
.upload-status span
|
108 |
+
{
|
109 |
display: none;
|
110 |
}
|
111 |
|
index.php
DELETED
@@ -1,376 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP Backitup
|
4 |
-
*
|
5 |
-
* @package WP Backitup
|
6 |
-
*
|
7 |
-
* @global object $wpdb
|
8 |
-
*
|
9 |
-
* @author cssimmon
|
10 |
-
* @version 1.6.7
|
11 |
-
*/
|
12 |
-
/*
|
13 |
-
Plugin Name: WP Backitup
|
14 |
-
Plugin URI: http://www.wpbackitup.com
|
15 |
-
Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
|
16 |
-
Version: 1.6.7
|
17 |
-
Author: Chris Simmons
|
18 |
-
Author URI: http://www.wpbackitup.com
|
19 |
-
License: GPL3
|
20 |
-
|
21 |
-
Copyright 2012-2014 WPBackItUp (email : support@wpbackitup.com)
|
22 |
-
|
23 |
-
This program is free software: you can redistribute it and/or modify
|
24 |
-
it under the terms of the GNU General Public License as published by
|
25 |
-
the Free Software Foundation, either version 3 of the License, or
|
26 |
-
(at your option) any later version.
|
27 |
-
|
28 |
-
This program is distributed in the hope that it will be useful,
|
29 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
-
GNU General Public License for more details.
|
32 |
-
|
33 |
-
You should have received a copy of the GNU General Public License
|
34 |
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
35 |
-
*/
|
36 |
-
// Include constants file
|
37 |
-
include_once dirname( __FILE__ ) . '/lib/constants.php';
|
38 |
-
|
39 |
-
class WPBackitup {
|
40 |
-
var $namespace = "wp-backitup";
|
41 |
-
var $friendly_name = WPBACKITUP_ITEM_NAME;
|
42 |
-
var $version = WPBACKITUP_VERSION;
|
43 |
-
|
44 |
-
// Default plugin options
|
45 |
-
var $defaults = array(
|
46 |
-
'presstrends' => "disabled",
|
47 |
-
'logging' => "disabled",
|
48 |
-
'license_key' => "",
|
49 |
-
'status' => "inactive"
|
50 |
-
);
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Instantiation construction
|
54 |
-
*
|
55 |
-
* @uses add_action()
|
56 |
-
* @uses WPBackitup::wp_register_scripts()
|
57 |
-
* @uses WPBackitup::wp_register_styles()
|
58 |
-
*/
|
59 |
-
function __construct() {
|
60 |
-
// Name of the option_value to store plugin options in
|
61 |
-
$this->option_name = '_' . $this->namespace . '--options';
|
62 |
-
|
63 |
-
// Load all library files used by this plugin
|
64 |
-
$libs = glob( WPBACKITUP_DIRNAME . '/lib/*.php' );
|
65 |
-
foreach( $libs as $lib ) {
|
66 |
-
include_once $lib;
|
67 |
-
}
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Make this plugin available for translation.
|
71 |
-
* Translations can be added to the /languages/ directory.
|
72 |
-
*/
|
73 |
-
load_theme_textdomain( $this->namespace, WPBACKITUP_DIRNAME . '/languages' );
|
74 |
-
|
75 |
-
// Add all action, filter and shortcode hooks
|
76 |
-
$this->_add_hooks();
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Add in various hooks
|
81 |
-
*/
|
82 |
-
private function _add_hooks() {
|
83 |
-
// Options page for configuration
|
84 |
-
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
85 |
-
// Route requests for form processing
|
86 |
-
add_action( 'init', array( &$this, 'route' ) );
|
87 |
-
|
88 |
-
// Add a settings link next to the "Deactivate" link on the plugin listing page
|
89 |
-
add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
|
90 |
-
|
91 |
-
// Register all JavaScripts for this plugin
|
92 |
-
add_action( 'init', array( &$this, 'wp_register_scripts' ), 1 );
|
93 |
-
// Register all Stylesheets for this plugin
|
94 |
-
add_action( 'init', array( &$this, 'wp_register_styles' ), 1 );
|
95 |
-
}
|
96 |
-
|
97 |
-
/**
|
98 |
-
* Process update page form submissions and validate license key
|
99 |
-
*
|
100 |
-
* @uses WPBackitup::sanitize()
|
101 |
-
* @uses wp_redirect()
|
102 |
-
* @uses wp_verify_nonce()
|
103 |
-
* @uses wp_remote_get()
|
104 |
-
* @uses add_query_arg()
|
105 |
-
* @uses is_wp_error()
|
106 |
-
* @uses wp_remote_retrieve_body()
|
107 |
-
* @uses update_option()
|
108 |
-
* @uses wp_safe_redirect()
|
109 |
-
*/
|
110 |
-
private function _admin_options_update() {
|
111 |
-
|
112 |
-
// Verify submission for processing using wp_nonce
|
113 |
-
if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-update-options" ) ) {
|
114 |
-
//create data array
|
115 |
-
$data = array();
|
116 |
-
|
117 |
-
/**
|
118 |
-
* Loop through each POSTed value and sanitize it to protect against malicious code. Please
|
119 |
-
* note that rich text (or full HTML fields) should not be processed by this function and
|
120 |
-
* dealt with directly.
|
121 |
-
*/
|
122 |
-
foreach( $_POST['data'] as $key => $val ) {
|
123 |
-
$data[$key] = $this->_sanitize( $val );
|
124 |
-
}
|
125 |
-
|
126 |
-
//check license status and try to activate if invalid
|
127 |
-
$license = trim ( $data['license_key'] );
|
128 |
-
|
129 |
-
// Check license
|
130 |
-
$api_params = array(
|
131 |
-
'edd_action' => 'check_license',
|
132 |
-
'license' => $license,
|
133 |
-
'item_name' => urlencode( WPBACKITUP_ITEM_NAME )
|
134 |
-
);
|
135 |
-
|
136 |
-
// Call the custom API
|
137 |
-
$response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP_SITE_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
|
138 |
-
|
139 |
-
// make sure the response came back okay
|
140 |
-
if ( is_wp_error( $response ) )
|
141 |
-
return false;
|
142 |
-
|
143 |
-
// decode the license data
|
144 |
-
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
145 |
-
|
146 |
-
if( $license_data->license != 'valid' ) {
|
147 |
-
// Try to activate license (process is almost identical to check_license)
|
148 |
-
$api_params = array(
|
149 |
-
'edd_action'=> 'activate_license',
|
150 |
-
'license' => $license,
|
151 |
-
'item_name' => urlencode( WPBACKITUP_ITEM_NAME ) // the name of our product in EDD
|
152 |
-
);
|
153 |
-
$response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP_SITE_URL ) );
|
154 |
-
if ( is_wp_error( $response ) )
|
155 |
-
return false;
|
156 |
-
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
157 |
-
}
|
158 |
-
|
159 |
-
/* Manually define status value */
|
160 |
-
$data['status'] = $license_data->license;
|
161 |
-
|
162 |
-
// Update the options value with the data submitted
|
163 |
-
update_option( $this->option_name, $data );
|
164 |
-
|
165 |
-
// Redirect back to the options page with the message flag to show the saved message
|
166 |
-
wp_safe_redirect( $_REQUEST['_wp_http_referer'] . '&update=1' );
|
167 |
-
exit;
|
168 |
-
}
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* Sanitize data
|
173 |
-
*
|
174 |
-
* @param mixed $str The data to be sanitized
|
175 |
-
*
|
176 |
-
* @uses wp_kses()
|
177 |
-
*
|
178 |
-
* @return mixed The sanitized version of the data
|
179 |
-
*/
|
180 |
-
private function _sanitize( $str ) {
|
181 |
-
if ( !function_exists( 'wp_kses' ) ) {
|
182 |
-
include_once ABSPATH . 'wp-includes/kses.php';
|
183 |
-
}
|
184 |
-
global $allowedposttags;
|
185 |
-
global $allowedprotocols;
|
186 |
-
|
187 |
-
if ( is_string( $str ) ) {
|
188 |
-
$str = wp_kses( $str, $allowedposttags, $allowedprotocols );
|
189 |
-
} elseif( is_array( $str ) ) {
|
190 |
-
$arr = array();
|
191 |
-
foreach( (array) $str as $key => $val ) {
|
192 |
-
$arr[$key] = $this->_sanitize( $val );
|
193 |
-
}
|
194 |
-
$str = $arr;
|
195 |
-
}
|
196 |
-
|
197 |
-
return $str;
|
198 |
-
}
|
199 |
-
|
200 |
-
/**
|
201 |
-
* Hook into register_activation_hook action
|
202 |
-
*/
|
203 |
-
static function activate() {
|
204 |
-
// Do activation actions
|
205 |
-
}
|
206 |
-
|
207 |
-
/**
|
208 |
-
* Define the admin menu options for this plugin
|
209 |
-
*
|
210 |
-
* @uses add_action()
|
211 |
-
* @uses add_options_page()
|
212 |
-
*/
|
213 |
-
function admin_menu() {
|
214 |
-
$page_hook = add_menu_page( $this->friendly_name, $this->friendly_name, 'administrator', $this->namespace, array( &$this, 'admin_options_page' ), WPBACKITUP_URLPATH .'/images/icon.png', 77);
|
215 |
-
|
216 |
-
// Add print scripts and styles action based off the option page hook
|
217 |
-
add_action( 'admin_print_scripts-' . $page_hook, array( &$this, 'admin_print_scripts' ) );
|
218 |
-
add_action( 'admin_print_styles-' . $page_hook, array( &$this, 'admin_print_styles' ) );
|
219 |
-
}
|
220 |
-
|
221 |
-
|
222 |
-
/**
|
223 |
-
* The admin section options page rendering method
|
224 |
-
*
|
225 |
-
* @uses current_user_can()
|
226 |
-
* @uses wp_die()
|
227 |
-
*/
|
228 |
-
function admin_options_page() {
|
229 |
-
if( !current_user_can( 'manage_options' ) ) {
|
230 |
-
wp_die( 'You do not have sufficient permissions to access this page' );
|
231 |
-
}
|
232 |
-
|
233 |
-
$page_title = $this->friendly_name . ' Options';
|
234 |
-
$namespace = $this->namespace;
|
235 |
-
|
236 |
-
include WPBACKITUP_DIRNAME . "/views/options.php";
|
237 |
-
}
|
238 |
-
|
239 |
-
/**
|
240 |
-
* Load JavaScript for the admin options page
|
241 |
-
*
|
242 |
-
* @uses wp_enqueue_script()
|
243 |
-
*/
|
244 |
-
function admin_print_scripts() {
|
245 |
-
wp_enqueue_script( "{$this->namespace}-admin" );
|
246 |
-
//wp_enqueue_script( "{$this->namespace}-ajaxfileupload" );
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* Load Stylesheet for the admin options page
|
251 |
-
*
|
252 |
-
* @uses wp_enqueue_style()
|
253 |
-
*/
|
254 |
-
function admin_print_styles() {
|
255 |
-
wp_enqueue_style( "{$this->namespace}-admin" );
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* Hook into register_deactivation_hook action
|
260 |
-
*
|
261 |
-
* Put code here that needs to happen when your plugin is deactivated
|
262 |
-
*/
|
263 |
-
static function deactivate() {
|
264 |
-
// Do deactivation actions
|
265 |
-
}
|
266 |
-
|
267 |
-
/**
|
268 |
-
* Retrieve the stored plugin option or the default if no user specified value is defined
|
269 |
-
*
|
270 |
-
* @param string $option_name The name of the TrialAccount option you wish to retrieve
|
271 |
-
*
|
272 |
-
* @uses get_option()
|
273 |
-
*
|
274 |
-
* @return mixed Returns the option value or false(boolean) if the option is not found
|
275 |
-
*/
|
276 |
-
function get_option( $option_name ) {
|
277 |
-
// Load option values if they haven't been loaded already
|
278 |
-
if( !isset( $this->options ) || empty( $this->options ) ) {
|
279 |
-
$this->options = get_option( $this->option_name, $this->defaults );
|
280 |
-
}
|
281 |
-
|
282 |
-
if( isset( $this->options[$option_name] ) ) {
|
283 |
-
return $this->options[$option_name]; // Return user's specified option value
|
284 |
-
} elseif( isset( $this->defaults[$option_name] ) ) {
|
285 |
-
return $this->defaults[$option_name]; // Return default option value
|
286 |
-
}
|
287 |
-
return false;
|
288 |
-
}
|
289 |
-
|
290 |
-
/**
|
291 |
-
* Initialization function to hook into the WordPress init action
|
292 |
-
*
|
293 |
-
* Instantiates the class on a global variable and sets the class, actions
|
294 |
-
* etc. up for use.
|
295 |
-
*/
|
296 |
-
static function instance() {
|
297 |
-
global $WPBackitup;
|
298 |
-
|
299 |
-
// Only instantiate the Class if it hasn't been already
|
300 |
-
if( !isset( $WPBackitup ) ) $WPBackitup = new WPBackitup();
|
301 |
-
}
|
302 |
-
|
303 |
-
/**
|
304 |
-
* Hook into plugin_action_links filter
|
305 |
-
*
|
306 |
-
* @param object $links An array of the links to show, this will be the modified variable
|
307 |
-
* @param string $file The name of the file being processed in the filter
|
308 |
-
*/
|
309 |
-
function plugin_action_links( $links, $file ) {
|
310 |
-
if( $file == plugin_basename( WPBACKITUP_DIRNAME . '/' . basename( __FILE__ ) ) ) {
|
311 |
-
$old_links = $links;
|
312 |
-
$new_links = array(
|
313 |
-
"settings" => '<a href="admin.php?page=' . $this->namespace . '">' . __( 'Manage' ) . '</a>'
|
314 |
-
);
|
315 |
-
$links = array_merge( $new_links, $old_links );
|
316 |
-
}
|
317 |
-
|
318 |
-
return $links;
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
* Route the user based off of environment conditions
|
323 |
-
*
|
324 |
-
* @uses WPBackitup::_admin_options_update()
|
325 |
-
*/
|
326 |
-
function route() {
|
327 |
-
$uri = $_SERVER['REQUEST_URI'];
|
328 |
-
$protocol = isset( $_SERVER['HTTPS'] ) ? 'https' : 'http';
|
329 |
-
$hostname = $_SERVER['HTTP_HOST'];
|
330 |
-
$url = "{$protocol}://{$hostname}{$uri}";
|
331 |
-
$is_post = (bool) ( strtoupper( $_SERVER['REQUEST_METHOD'] ) == "POST" );
|
332 |
-
|
333 |
-
// Check if a nonce was passed in the request
|
334 |
-
if( isset( $_REQUEST['_wpnonce'] ) ) {
|
335 |
-
$nonce = $_REQUEST['_wpnonce'];
|
336 |
-
|
337 |
-
// Handle POST requests
|
338 |
-
if( $is_post ) {
|
339 |
-
if( wp_verify_nonce( $nonce, "{$this->namespace}-update-options" ) ) {
|
340 |
-
$this->_admin_options_update();
|
341 |
-
}
|
342 |
-
}
|
343 |
-
// Handle GET requests
|
344 |
-
else {
|
345 |
-
|
346 |
-
}
|
347 |
-
}
|
348 |
-
}
|
349 |
-
|
350 |
-
/**
|
351 |
-
* Register scripts used by this plugin for enqueuing elsewhere
|
352 |
-
*
|
353 |
-
* @uses wp_register_script()
|
354 |
-
*/
|
355 |
-
function wp_register_scripts() {
|
356 |
-
// Admin JavaScript
|
357 |
-
wp_register_script( "{$this->namespace}-admin", WPBACKITUP_URLPATH . "/js/admin.js", array( 'jquery' ), $this->version, true );
|
358 |
-
//wp_register_script( "{$this->namespace}-ajaxfileupload", WPBACKITUP_URLPATH . "/js/ajaxfileupload.js", array( 'jquery' ), $this->version, true );
|
359 |
-
}
|
360 |
-
|
361 |
-
/**
|
362 |
-
* Register styles used by this plugin for enqueuing elsewhere
|
363 |
-
*
|
364 |
-
* @uses wp_register_style()
|
365 |
-
*/
|
366 |
-
function wp_register_styles() {
|
367 |
-
// Admin Stylesheet
|
368 |
-
wp_register_style( "{$this->namespace}-admin", WPBACKITUP_URLPATH . "/css/admin.css", array(), $this->version, 'screen' );
|
369 |
-
}
|
370 |
-
}
|
371 |
-
if( !isset( $WPBackitup ) ) {
|
372 |
-
WPBackitup::instance();
|
373 |
-
}
|
374 |
-
|
375 |
-
register_activation_hook( __FILE__, array( 'WPBackitup', 'activate' ) );
|
376 |
-
register_deactivation_hook( __FILE__, array( 'WPBackitup', 'deactivate' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js/admin.js
CHANGED
@@ -6,82 +6,54 @@
|
|
6 |
*/
|
7 |
|
8 |
(function($){
|
9 |
-
/* define backup variables */
|
10 |
-
var backup = {
|
11 |
-
action: 'backup',
|
12 |
-
beforeSend: function () {
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
$('.backup-icon').show();
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
var logreader = {
|
34 |
-
action: 'logreader'
|
35 |
-
};
|
36 |
-
|
37 |
-
/* define logreader variables */
|
38 |
-
var statusreader = {
|
39 |
-
action: 'statusreader'
|
40 |
-
};
|
41 |
-
|
42 |
-
/* define logreader function */
|
43 |
-
function display_log() {
|
44 |
-
$.post(ajaxurl, logreader, function(response) {
|
45 |
-
|
46 |
-
/* Get response from log reader */
|
47 |
-
var xmlObj = $(response);
|
48 |
-
|
49 |
-
/* For each response */
|
50 |
-
xmlObj.each(function() {
|
51 |
-
|
52 |
-
/* Select correct status */
|
53 |
-
var attributename = "." + $(this).attr('class');
|
54 |
-
|
55 |
-
/* Select correct status */
|
56 |
-
if ($(this).html() == 0) {
|
57 |
-
|
58 |
-
/* If status returns 0, display 'Failed' */
|
59 |
-
$('.backup-icon').fadeOut(200);
|
60 |
-
$(attributename).find(".fail").fadeIn(1500);
|
61 |
-
clearInterval(window.intervalDefine);
|
62 |
-
|
63 |
-
} else {
|
64 |
-
|
65 |
-
/* If status returns 1, display 'Done' or show detailed message */
|
66 |
-
$(attributename).find(".status").fadeIn(500);
|
67 |
-
|
68 |
-
}
|
69 |
-
|
70 |
-
/* If is final or error */
|
71 |
-
if (attributename == ".finalinfo") {
|
72 |
-
/* Stop logreader */
|
73 |
-
clearInterval(window.intervalDefine);
|
74 |
-
}
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
/* define display status function */
|
81 |
function display_status() {
|
82 |
-
$.post(ajaxurl,
|
83 |
-
|
84 |
-
/* Get response from log reader */
|
85 |
var xmlObj = $(response);
|
86 |
|
87 |
/* For each response */
|
@@ -91,12 +63,11 @@
|
|
91 |
var attributename = "." + $(this).attr('class');
|
92 |
var icon_attributename = "." + $(this).attr('class') + '-icon';
|
93 |
|
94 |
-
|
95 |
//Hide all
|
96 |
if ( $(this).html() == 0 ) {
|
97 |
|
98 |
$(attributename).find(".status").hide();
|
99 |
-
$(attributename).find(".status-icon").hide();
|
100 |
|
101 |
}
|
102 |
|
@@ -151,44 +122,245 @@
|
|
151 |
});
|
152 |
}
|
153 |
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
$(".backup-button").click(function(e) {
|
156 |
e.preventDefault();
|
157 |
|
158 |
-
$("#backup-button").attr('disabled', 'disabled'); //Disable button
|
159 |
-
|
160 |
-
$.post(ajaxurl, backup, function(response) {
|
161 |
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
});
|
174 |
|
|
|
|
|
|
|
175 |
|
176 |
-
|
177 |
-
|
178 |
-
e.preventDefault();
|
179 |
-
if (confirm('Are you sure you want to restore your site?'))
|
180 |
-
{
|
181 |
-
var filename = this.title;
|
182 |
-
var row = this.id.replace('restoreRow', 'row');
|
183 |
-
$('#is_selected').val(1);
|
184 |
-
$('#selected_file').val(filename);
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
});
|
190 |
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
$('#datatable').on('click', 'a.deleteRow', function(e) {
|
193 |
|
194 |
e.preventDefault();
|
@@ -199,7 +371,7 @@
|
|
199 |
$.ajax({
|
200 |
url: ajaxurl,
|
201 |
type: 'post',
|
202 |
-
data: {action: "
|
203 |
success: function(data) {
|
204 |
if (data === 'deleted')
|
205 |
{
|
@@ -218,7 +390,8 @@
|
|
218 |
}
|
219 |
});
|
220 |
|
221 |
-
|
|
|
222 |
{
|
223 |
// decide class of row to be inserted dynamically
|
224 |
var css_class;
|
@@ -236,94 +409,91 @@
|
|
236 |
if (data != undefined)
|
237 |
{
|
238 |
var restoreColumn = '<td><a href="#" title="' + data.file + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n';
|
239 |
-
var newRow = '<tr ' + css_class + ' id="row' + cur_row + '">\n\
|
240 |
-
<td>' + data.file +'</td>\n\
|
241 |
-
<td><a href="' + data.link + '">Download</a></td>\n\
|
242 |
-
<td><a href="#" title="' + data.file + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n';
|
243 |
-
|
244 |
-
if (true==data.license)
|
245 |
-
newRow +=restoreColumn;
|
246 |
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
if ($('#nofiles'))
|
250 |
$('#nofiles').remove();
|
251 |
|
|
|
252 |
$('#datatable').prepend(newRow);
|
253 |
-
$('#datatable tr:
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
/* execute restore on button click */
|
258 |
-
$("#restore-form").submit(function() {
|
259 |
-
/* display processing icon */
|
260 |
-
$('.restore-icon').css('visibility', 'visible');
|
261 |
-
|
262 |
-
/* hide default message, backup status and backup errors */
|
263 |
-
$('.default-status, .backup-status, .backup-errors').hide();
|
264 |
-
|
265 |
-
/* show restore status messages */
|
266 |
-
$('.restore-status, .restore-errors, .restore-success').show();
|
267 |
-
$('.preparing-icon').css('visibility', 'visible');
|
268 |
-
$('.preparing').find(".status-icon").fadeIn(1500);
|
269 |
-
|
270 |
|
271 |
-
|
272 |
-
$("#restore-form").attr("target", "upload_target");
|
273 |
-
$("#upload_target").load(function() {
|
274 |
-
upload_file();
|
275 |
-
});
|
276 |
-
});
|
277 |
|
278 |
-
|
279 |
-
function upload_file() {
|
280 |
-
|
281 |
-
/* process upload */
|
282 |
-
var ret = frames['upload_target'].document.getElementsByTagName("body")[0].innerHTML;
|
283 |
-
|
284 |
-
/* Return PHP messages, used for development */
|
285 |
-
$("#php").html(ret);
|
286 |
-
clearInterval(display_log);
|
287 |
-
$('.upload-icon').fadeOut(1000);
|
288 |
-
return ret;
|
289 |
}
|
290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
try{
|
311 |
-
var data = $.parseJSON(response);
|
312 |
-
processRow(data);
|
313 |
-
status_message=data.file + ' was uploaded successfully...';
|
314 |
-
}
|
315 |
-
catch(err)
|
316 |
-
{
|
317 |
-
status_message=response;
|
318 |
-
}
|
319 |
-
|
320 |
-
//Update the status and disable the button
|
321 |
-
$("#wpbackitup-zip").attr("disabled", "disabled"); //Disable upload
|
322 |
-
$("#upload-button").attr("disabled", "disabled"); //Disable upload
|
323 |
-
$('.upload-status').show();
|
324 |
-
$('.upload-status').html(status_message);
|
325 |
-
|
326 |
-
});
|
327 |
-
});
|
328 |
|
329 |
})(jQuery);
|
6 |
*/
|
7 |
|
8 |
(function($){
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
//Add View Log Click event to backup page
|
11 |
+
add_viewlog_onclick();
|
|
|
12 |
|
13 |
+
//binds to onchange event of the upload file input field
|
14 |
+
$('#wpbackitup-zip').bind('change', function() {
|
15 |
|
16 |
+
//this.files[0].size gets the size of your file.
|
17 |
+
var upload_file_size = this.files[0].size;
|
18 |
+
var max_file_size = $('#maxfilesize').val();
|
19 |
|
20 |
+
//IF Not supported by browser just check on server
|
21 |
+
if (upload_file_size == 'undefined' ||
|
22 |
+
max_file_size == 'undefined' ||
|
23 |
+
upload_file_size == '' ||
|
24 |
+
max_file_size =='')
|
25 |
+
{
|
26 |
+
return;
|
27 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
if (upload_file_size > max_file_size){
|
30 |
+
alert('The backup you have selected exceeds what your host allows you to upload.');
|
31 |
+
$("#wpbackitup-zip").val("");
|
32 |
+
}
|
33 |
+
});
|
34 |
|
35 |
+
/* define logreader variables */
|
36 |
+
var response_reader = {
|
37 |
+
action: 'response_reader'
|
38 |
+
};
|
39 |
+
|
40 |
+
/* define logreader variables */
|
41 |
+
var status_reader = {
|
42 |
+
action: 'status_reader'
|
43 |
+
};
|
44 |
+
|
45 |
+
function add_viewlog_onclick(){
|
46 |
+
$(".viewloglink").click(function(){
|
47 |
+
var href = $(this).attr("href");
|
48 |
+
$("#viewlog_log").val(href);
|
49 |
+
$("#viewlog").submit();
|
50 |
+
return false;
|
51 |
+
});
|
52 |
+
}
|
53 |
/* define display status function */
|
54 |
function display_status() {
|
55 |
+
$.post(ajaxurl, status_reader, function(response) {
|
56 |
+
/* Get response from log reader */
|
|
|
57 |
var xmlObj = $(response);
|
58 |
|
59 |
/* For each response */
|
63 |
var attributename = "." + $(this).attr('class');
|
64 |
var icon_attributename = "." + $(this).attr('class') + '-icon';
|
65 |
|
|
|
66 |
//Hide all
|
67 |
if ( $(this).html() == 0 ) {
|
68 |
|
69 |
$(attributename).find(".status").hide();
|
70 |
+
$(attributename).find(".status-icon").hide();
|
71 |
|
72 |
}
|
73 |
|
122 |
});
|
123 |
}
|
124 |
|
125 |
+
/* define backup response_reader function */
|
126 |
+
function get_backup_response() {
|
127 |
+
//This function is required because of 504 gateway timeouts
|
128 |
+
|
129 |
+
var jqxhr = $.ajax({
|
130 |
+
url: ajaxurl,
|
131 |
+
type: 'POST',
|
132 |
+
data: {action: "response_reader"},
|
133 |
+
dataType: "json"
|
134 |
+
});
|
135 |
+
|
136 |
+
jqxhr.always(function(jsonData, textStatus, errorThrown) {
|
137 |
+
console.log("Backup Response:" + JSON.stringify(errorThrown));
|
138 |
+
console.log("Backup Response text status:" + textStatus);
|
139 |
+
|
140 |
+
if (jsonData) {
|
141 |
+
if (jsonData.message=='success') {
|
142 |
+
console.log("JSON response received.");
|
143 |
+
processRow_backup(jsonData);
|
144 |
+
$('.backup-success').show();
|
145 |
+
|
146 |
+
} else { //Error
|
147 |
+
console.log("JSON error response received.");
|
148 |
+
status_message='An unexpected error has occurred: ' + jsonData.message;
|
149 |
+
|
150 |
+
$('.backup-status').hide();
|
151 |
+
|
152 |
+
var unexpected_error= $('.backup-unexpected-error');
|
153 |
+
unexpected_error.html(status_message);
|
154 |
+
unexpected_error.addClass("isa_error");
|
155 |
+
unexpected_error.show();
|
156 |
+
|
157 |
+
}
|
158 |
+
|
159 |
+
} else { //Didnt get any json back
|
160 |
+
console.log("NON JSON response received.");
|
161 |
+
status_message='An unexpected error has occurred: ' + textStatus + ':' + JSON.stringify(errorThrown);
|
162 |
+
|
163 |
+
$('.backup-status').hide();
|
164 |
+
|
165 |
+
var unexpected_error= $('.backup-unexpected-error');
|
166 |
+
unexpected_error.html(status_message);
|
167 |
+
unexpected_error.addClass("isa_error");
|
168 |
+
unexpected_error.show();
|
169 |
+
}
|
170 |
+
});
|
171 |
+
}
|
172 |
+
|
173 |
+
/*BACKUP button click */
|
174 |
$(".backup-button").click(function(e) {
|
175 |
e.preventDefault();
|
176 |
|
177 |
+
$("#backup-button").attr('disabled', 'disabled'); //Disable button
|
|
|
|
|
178 |
|
179 |
+
var jqxhr = $.ajax({
|
180 |
+
url: ajaxurl,
|
181 |
+
type: 'POST',
|
182 |
+
data: {action: "backup"},
|
183 |
+
cache: false,
|
184 |
+
dataType: "json",
|
185 |
|
186 |
+
beforeSend: function(jqXHR, settings) {
|
187 |
+
console.log("BeforeSend:Nothing to report.");
|
188 |
+
|
189 |
+
/* display processing icon */
|
190 |
+
$('.backup-icon').css('visibility', 'visible');
|
191 |
+
$('.backup-icon').show();
|
192 |
+
|
193 |
+
/* hide default message, restore status and restore errors */
|
194 |
+
$('.backup-success').hide();
|
195 |
+
$('.default-status').hide();
|
196 |
+
$('.backup-unexpected-error').hide();
|
197 |
+
|
198 |
+
/* hide the status just incase this is the second run */
|
199 |
+
$("ul.backup-status").children().children().hide();
|
200 |
+
$(".backup-errors").children().children().hide();
|
201 |
+
$(".backup-success").children().children().hide();
|
202 |
+
|
203 |
+
/* show backup status, backup errors */
|
204 |
+
$('.backup-status').show();
|
205 |
+
window.intervalDefine = setInterval(display_status, 3000);
|
206 |
+
}
|
207 |
});
|
208 |
+
|
209 |
+
//Fetch the JSON response file if it exists
|
210 |
+
jqxhr.always(function(data, textStatus, errorThrown) {
|
211 |
+
console.log("Backup Button Click - Always");
|
212 |
+
clearInterval(window.intervalDefine);
|
213 |
+
display_status(); //Fetch status one last time manually
|
214 |
+
get_backup_response(); //fetch the response too
|
215 |
+
$('.backup-icon').fadeOut(1000);
|
216 |
+
$("#backup-button").removeAttr("disabled"); //enable button
|
217 |
+
});
|
218 |
+
|
219 |
});
|
220 |
|
221 |
+
/* RESTORE button click */
|
222 |
+
$('#datatable').on('click', 'a.restoreRow', function(e) {
|
223 |
+
e.preventDefault();
|
224 |
|
225 |
+
if (confirm('Are you sure you want to restore your site?'))
|
226 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
+
var filename = this.title;
|
229 |
+
var row = this.id.replace('restoreRow', 'row');
|
230 |
+
userid = $('input[name=user_id]').val();
|
|
|
231 |
|
232 |
+
$.ajax({
|
233 |
+
url: ajaxurl,
|
234 |
+
type: 'post',
|
235 |
+
data: {action: "restore", selected_file: filename,user_id: userid},
|
236 |
+
success: function(response) {
|
237 |
+
/* Return PHP messages, used for development */
|
238 |
+
$("#php").html(response);
|
239 |
+
|
240 |
+
//clearInterval(window.intervalDefine);
|
241 |
+
var data = $.parseJSON(response);
|
242 |
+
|
243 |
+
},
|
244 |
+
beforeSend: function () {
|
245 |
+
/* display processing icon */
|
246 |
+
$('.restore-icon').css('visibility', 'visible');
|
247 |
+
|
248 |
+
/* hide default message, backup status and backup errors */
|
249 |
+
$('.default-status, .upload-status').hide();
|
250 |
+
|
251 |
+
$("ul.restore-status").children().children().hide();
|
252 |
+
$(".restore-errors").children().children().hide();
|
253 |
+
$(".restore-success").children().children().hide();
|
254 |
+
|
255 |
+
/* show restore status messages */
|
256 |
+
$('.restore-status, .restore-errors, .restore-success').show();
|
257 |
+
$('.preparing-icon').css('visibility', 'visible');
|
258 |
+
$('.preparing').find(".status-icon").fadeIn(1500);
|
259 |
+
|
260 |
+
window.intervalDefine = setInterval(display_status, 3000);
|
261 |
+
}
|
262 |
+
});
|
263 |
+
}
|
264 |
+
});
|
265 |
+
|
266 |
+
/*Upload form button*/
|
267 |
+
$("#upload-form").submit(function() {
|
268 |
+
|
269 |
+
//e.preventDefault();
|
270 |
+
|
271 |
+
//CHECK ERRORS ON USER SIDE, IF TRUE, END OPERATIONS.
|
272 |
+
if (upload_errors()){
|
273 |
+
return false;
|
274 |
+
}
|
275 |
+
|
276 |
+
var formData = new FormData();
|
277 |
+
jQuery.each($('#wpbackitup-zip')[0].files, function(i, file) {
|
278 |
+
formData.append('uploadFile-'+i, file);
|
279 |
+
});
|
280 |
+
formData.append('action', 'upload');
|
281 |
+
formData.append('_wpnonce', $('#_wpnonce').val());
|
282 |
+
formData.append('_wp_http_referer',$("[name='_wp_http_referer']").val());
|
283 |
+
|
284 |
+
jQuery.ajax({
|
285 |
+
url: ajaxurl,
|
286 |
+
type: 'POST',
|
287 |
+
cache: false,
|
288 |
+
contentType: false,
|
289 |
+
processData: false,
|
290 |
+
dataType: "json",
|
291 |
+
|
292 |
+
//MODIFIED - From ajaxData to formData
|
293 |
+
data: formData,
|
294 |
+
|
295 |
+
beforeSend: function(jqXHR, settings){
|
296 |
+
//console.log("Haven't entered server side yet.");
|
297 |
+
/* display processing icon */
|
298 |
+
$('.upload-icon').css('visibility', 'visible');
|
299 |
+
|
300 |
+
/* hide default message, backup status and backup errors */
|
301 |
+
$('.default-status, .restore-status, .restore-errors').hide();
|
302 |
+
$("ul.restore-status").children().children().hide();
|
303 |
+
$(".restore-errors").children().children().hide();
|
304 |
+
$(".restore-success").children().children().hide();
|
305 |
+
|
306 |
+
/* show restore status messages */
|
307 |
+
$('.upload-status').toggle();
|
308 |
+
|
309 |
+
$("#wpbackitup-zip").attr("disabled", "disabled"); //Disable upload
|
310 |
+
$("#upload-button").attr("disabled", "disabled"); //Disable upload
|
311 |
+
|
312 |
+
},
|
313 |
+
dataFilter: function(data, type){
|
314 |
+
//Check the response before sending to success
|
315 |
+
//Possible that is isnt json so just forward it to success in a json object
|
316 |
+
try {
|
317 |
+
$("#php").html(data);
|
318 |
+
var response = $.parseJSON(data);
|
319 |
+
console.log("JSON string echoed back from server side:" + response);
|
320 |
+
return data;
|
321 |
+
} catch (e) {
|
322 |
+
console.log("NON JSON string echoed back from server side:" + type + ':' + data);
|
323 |
+
var rtnData = new Object();
|
324 |
+
rtnData.success = "";
|
325 |
+
rtnData.error = data;
|
326 |
+
return JSON.stringify(rtnData)
|
327 |
+
}
|
328 |
+
|
329 |
+
|
330 |
+
},
|
331 |
+
success: function(data, textStatus, jqXHR){
|
332 |
+
console.log("Back from server-side:" + data);
|
333 |
+
//Checking errors that may have been caught on the server side that
|
334 |
+
// normally wouldn't display in the error Ajax function.
|
335 |
+
|
336 |
+
if (data.msg == 'success')
|
337 |
+
{
|
338 |
+
status_message=data.file + ' file was uploaded successfully...';
|
339 |
+
processRow_restore(data);
|
340 |
+
$('.upload-status').addClass("isa_success");
|
341 |
+
}else{
|
342 |
+
status_message='Error: ' + data.error;
|
343 |
+
$('.upload-status').addClass("isa_error");
|
344 |
+
}
|
345 |
+
|
346 |
+
$('.upload-icon').fadeOut(1000);
|
347 |
+
$('.upload-status').show();
|
348 |
+
$('.upload-status').html(status_message);
|
349 |
+
|
350 |
+
},
|
351 |
+
error: function(jqXHR, textStatus, errorThrown){
|
352 |
+
console.log("A JS error has occurred." + textStatus +':' +errorThrown);
|
353 |
+
},
|
354 |
+
complete: function(jqXHR, textStatus){
|
355 |
+
console.log("Ajax is finished.");
|
356 |
+
}
|
357 |
+
});
|
358 |
+
|
359 |
+
return false;
|
360 |
+
});
|
361 |
+
|
362 |
+
|
363 |
+
// DELETE file action
|
364 |
$('#datatable').on('click', 'a.deleteRow', function(e) {
|
365 |
|
366 |
e.preventDefault();
|
371 |
$.ajax({
|
372 |
url: ajaxurl,
|
373 |
type: 'post',
|
374 |
+
data: {action: "delete_file", filed: filename},
|
375 |
success: function(data) {
|
376 |
if (data === 'deleted')
|
377 |
{
|
390 |
}
|
391 |
});
|
392 |
|
393 |
+
|
394 |
+
function processRow_backup(data)
|
395 |
{
|
396 |
// decide class of row to be inserted dynamically
|
397 |
var css_class;
|
409 |
if (data != undefined)
|
410 |
{
|
411 |
var restoreColumn = '<td><a href="#" title="' + data.file + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
|
413 |
+
var viewColumn = '<td> </td>\n';
|
414 |
+
if (typeof data.log_link !== 'undefined') {
|
415 |
+
viewColumn = '<td><a class="viewloglink" href="' + data.log_link + '">View Log</a></td>\n';
|
416 |
+
}
|
417 |
+
|
418 |
+
var newRow =
|
419 |
+
'<tr ' + css_class + ' id="row' + cur_row + '">\n\
|
420 |
+
<td>New Backup!</td>\n\
|
421 |
+
<td><i class="fa fa-long-arrow-right"></i>' + data.file +'</td>\n\
|
422 |
+
<td><a href="' + data.zip_link + '">Download</a></td>\n';
|
423 |
+
newRow +=viewColumn;
|
424 |
+
newRow +='<td><a href="#" title="' + data.file + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n';
|
425 |
+
newRow +='</tr>';
|
426 |
|
427 |
if ($('#nofiles'))
|
428 |
$('#nofiles').remove();
|
429 |
|
430 |
+
var total_rows = $('#datatable tr').length;
|
431 |
$('#datatable').prepend(newRow);
|
432 |
+
$('#datatable tr:first').hide().show('slow'); // just an animation to show newly added row
|
433 |
+
|
434 |
+
if(total_rows >= data.retained)
|
435 |
+
$('#datatable tr:last').hide();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
|
437 |
+
add_viewlog_onclick();
|
|
|
|
|
|
|
|
|
|
|
438 |
|
439 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
}
|
441 |
|
442 |
+
function processRow_restore(data)
|
443 |
+
{
|
444 |
+
// decide class of row to be inserted dynamically
|
445 |
+
var css_class;
|
446 |
+
css_class = '';
|
447 |
+
|
448 |
+
if (!$('#datatable tr').first().hasClass('alternate'))
|
449 |
+
css_class = 'class="alternate"';
|
450 |
+
// decided class of row to be inserted dynamically
|
451 |
+
|
452 |
+
// build id of the row to be inserted dynamically
|
453 |
+
var cur_row = ($('#datatable tr:last')[0].id.replace('row', ''));
|
454 |
+
cur_row++;
|
455 |
+
|
456 |
+
// built id of the row to be inserted dynamically
|
457 |
+
if (data != undefined)
|
458 |
+
{
|
459 |
+
var restoreColumn = '<td><a href="#" title="' + data.file + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n';
|
460 |
+
var newRow =
|
461 |
+
'<tr ' + css_class + ' id="row' + cur_row + '">\n\
|
462 |
+
<td>Uploaded Backup<i class="fa fa-long-arrow-right"></i>' + data.file +'</td>\n\
|
463 |
+
<td><a href="' + data.zip_link + '">Download</a></td>\n\
|
464 |
+
<td><a href="#" title="' + data.file + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n\
|
465 |
+
<td><a href="#" title="' + data.file + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n\
|
466 |
+
</tr>';
|
467 |
+
|
468 |
+
if ($('#nofiles'))
|
469 |
+
$('#nofiles').remove();
|
470 |
+
|
471 |
+
var total_rows = $('#datatable tr').length;
|
472 |
+
$('#datatable').prepend(newRow);
|
473 |
+
$('#datatable tr:first').hide().show('slow'); // just an animation to show newly added row
|
474 |
+
|
475 |
+
if(total_rows >= data.retained)
|
476 |
+
$('#datatable tr:last').hide();
|
477 |
+
}
|
478 |
+
}
|
479 |
|
480 |
+
function upload_errors()
|
481 |
+
{
|
482 |
+
if ($('#wpbackitup-zip').val() == '')
|
483 |
+
{
|
484 |
+
alert('No file(s) selected. Please choose a backup file to upload.');
|
485 |
+
return true;
|
486 |
+
}
|
487 |
+
if ($('#wpbackitup-zip').val() != '')
|
488 |
+
{
|
489 |
+
var ext = $('#wpbackitup-zip').val().split('.').pop().toLowerCase();
|
490 |
+
if($.inArray(ext, ['zip']) == -1)
|
491 |
+
{
|
492 |
+
alert('Invalid file type. Please choose a ZIP file to upload.');
|
493 |
+
return true;
|
494 |
+
}
|
495 |
+
}
|
496 |
+
return false;
|
497 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
|
499 |
})(jQuery);
|
js/ajaxfileupload.js
DELETED
@@ -1,204 +0,0 @@
|
|
1 |
-
/**
|
2 |
-
* WP Backitup Ajax File Upload
|
3 |
-
*
|
4 |
-
* @version 1.4.0
|
5 |
-
* @since 1.0.1
|
6 |
-
*/
|
7 |
-
|
8 |
-
jQuery.extend({
|
9 |
-
createUploadIframe: function(id, uri)
|
10 |
-
{
|
11 |
-
//create frame
|
12 |
-
var frameId = 'jUploadFrame' + id;
|
13 |
-
var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"';
|
14 |
-
if(window.ActiveXObject)
|
15 |
-
{
|
16 |
-
if(typeof uri== 'boolean'){
|
17 |
-
iframeHtml += ' src="' + 'javascript:false' + '"';
|
18 |
-
|
19 |
-
}
|
20 |
-
else if(typeof uri== 'string'){
|
21 |
-
iframeHtml += ' src="' + uri + '"';
|
22 |
-
|
23 |
-
}
|
24 |
-
}
|
25 |
-
iframeHtml += ' />';
|
26 |
-
jQuery(iframeHtml).appendTo(document.body);
|
27 |
-
|
28 |
-
return jQuery('#' + frameId).get(0);
|
29 |
-
},
|
30 |
-
createUploadForm: function(id, fileElementId, data)
|
31 |
-
{
|
32 |
-
//create form
|
33 |
-
var formId = 'jUploadForm' + id;
|
34 |
-
var fileId = 'jUploadFile' + id;
|
35 |
-
var form = jQuery('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
|
36 |
-
if(data)
|
37 |
-
{
|
38 |
-
for(var i in data)
|
39 |
-
{
|
40 |
-
jQuery('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form);
|
41 |
-
}
|
42 |
-
}
|
43 |
-
var oldElement = jQuery('#' + fileElementId);
|
44 |
-
var newElement = jQuery(oldElement).clone();
|
45 |
-
jQuery(oldElement).attr('id', fileId);
|
46 |
-
jQuery(oldElement).before(newElement);
|
47 |
-
jQuery(oldElement).appendTo(form);
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
//set attributes
|
52 |
-
jQuery(form).css('position', 'absolute');
|
53 |
-
jQuery(form).css('top', '-1200px');
|
54 |
-
jQuery(form).css('left', '-1200px');
|
55 |
-
jQuery(form).appendTo('body');
|
56 |
-
return form;
|
57 |
-
},
|
58 |
-
|
59 |
-
ajaxFileUpload: function(s) {
|
60 |
-
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
|
61 |
-
s = jQuery.extend({}, jQuery.ajaxSettings, s);
|
62 |
-
var id = new Date().getTime()
|
63 |
-
var form = jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false:s.data));
|
64 |
-
var io = jQuery.createUploadIframe(id, s.secureuri);
|
65 |
-
var frameId = 'jUploadFrame' + id;
|
66 |
-
var formId = 'jUploadForm' + id;
|
67 |
-
// Watch for a new set of requests
|
68 |
-
if ( s.global && ! jQuery.active++ )
|
69 |
-
{
|
70 |
-
jQuery.event.trigger( "ajaxStart" );
|
71 |
-
}
|
72 |
-
var requestDone = false;
|
73 |
-
// Create the request object
|
74 |
-
var xml = {}
|
75 |
-
if ( s.global )
|
76 |
-
jQuery.event.trigger("ajaxSend", [xml, s]);
|
77 |
-
// Wait for a response to come back
|
78 |
-
var uploadCallback = function(isTimeout)
|
79 |
-
{
|
80 |
-
var io = document.getElementById(frameId);
|
81 |
-
try
|
82 |
-
{
|
83 |
-
if(io.contentWindow)
|
84 |
-
{
|
85 |
-
xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
|
86 |
-
xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
|
87 |
-
|
88 |
-
}else if(io.contentDocument)
|
89 |
-
{
|
90 |
-
xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
|
91 |
-
xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
|
92 |
-
}
|
93 |
-
}catch(e)
|
94 |
-
{
|
95 |
-
jQuery.handleError(s, xml, null, e);
|
96 |
-
}
|
97 |
-
if ( xml || isTimeout == "timeout")
|
98 |
-
{
|
99 |
-
requestDone = true;
|
100 |
-
var status;
|
101 |
-
try {
|
102 |
-
status = isTimeout != "timeout" ? "success" : "error";
|
103 |
-
// Make sure that the request was successful or notmodified
|
104 |
-
if ( status != "error" )
|
105 |
-
{
|
106 |
-
// process the data (runs the xml through httpData regardless of callback)
|
107 |
-
var data = jQuery.uploadHttpData( xml, s.dataType );
|
108 |
-
// If a local callback was specified, fire it and pass it the data
|
109 |
-
if ( s.success )
|
110 |
-
s.success( data, status );
|
111 |
-
|
112 |
-
// Fire the global callback
|
113 |
-
if( s.global )
|
114 |
-
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
|
115 |
-
} else
|
116 |
-
jQuery.handleError(s, xml, status);
|
117 |
-
} catch(e)
|
118 |
-
{
|
119 |
-
status = "error";
|
120 |
-
jQuery.handleError(s, xml, status, e);
|
121 |
-
}
|
122 |
-
|
123 |
-
// The request was completed
|
124 |
-
if( s.global )
|
125 |
-
jQuery.event.trigger( "ajaxComplete", [xml, s] );
|
126 |
-
|
127 |
-
// Handle the global AJAX counter
|
128 |
-
if ( s.global && ! --jQuery.active )
|
129 |
-
jQuery.event.trigger( "ajaxStop" );
|
130 |
-
|
131 |
-
// Process result
|
132 |
-
if ( s.complete )
|
133 |
-
s.complete(xml, status);
|
134 |
-
|
135 |
-
jQuery(io).unbind()
|
136 |
-
|
137 |
-
setTimeout(function()
|
138 |
-
{ try
|
139 |
-
{
|
140 |
-
jQuery(io).remove();
|
141 |
-
jQuery(form).remove();
|
142 |
-
|
143 |
-
} catch(e)
|
144 |
-
{
|
145 |
-
jQuery.handleError(s, xml, null, e);
|
146 |
-
}
|
147 |
-
|
148 |
-
}, 100)
|
149 |
-
|
150 |
-
xml = null
|
151 |
-
|
152 |
-
}
|
153 |
-
}
|
154 |
-
// Timeout checker
|
155 |
-
if ( s.timeout > 0 )
|
156 |
-
{
|
157 |
-
setTimeout(function(){
|
158 |
-
// Check to see if the request is still happening
|
159 |
-
if( !requestDone ) uploadCallback( "timeout" );
|
160 |
-
}, s.timeout);
|
161 |
-
}
|
162 |
-
try
|
163 |
-
{
|
164 |
-
|
165 |
-
var form = jQuery('#' + formId);
|
166 |
-
jQuery(form).attr('action', s.url);
|
167 |
-
jQuery(form).attr('method', 'POST');
|
168 |
-
jQuery(form).attr('target', frameId);
|
169 |
-
if(form.encoding)
|
170 |
-
{
|
171 |
-
jQuery(form).attr('encoding', 'multipart/form-data');
|
172 |
-
}
|
173 |
-
else
|
174 |
-
{
|
175 |
-
jQuery(form).attr('enctype', 'multipart/form-data');
|
176 |
-
}
|
177 |
-
jQuery(form).submit();
|
178 |
-
|
179 |
-
} catch(e)
|
180 |
-
{
|
181 |
-
jQuery.handleError(s, xml, null, e);
|
182 |
-
}
|
183 |
-
|
184 |
-
jQuery('#' + frameId).load(uploadCallback );
|
185 |
-
return {abort: function () {}};
|
186 |
-
|
187 |
-
},
|
188 |
-
|
189 |
-
uploadHttpData: function( r, type ) {
|
190 |
-
var data = !type;
|
191 |
-
data = type == "xml" || data ? r.responseXML : r.responseText;
|
192 |
-
// If the type is "script", eval it in global context
|
193 |
-
if ( type == "script" )
|
194 |
-
jQuery.globalEval( data );
|
195 |
-
// Get the JavaScript object, if JSON is used.
|
196 |
-
if ( type == "json" )
|
197 |
-
eval( "data = " + data );
|
198 |
-
// evaluate scripts within html
|
199 |
-
if ( type == "html" )
|
200 |
-
jQuery("<div>").html(data).evalScripts();
|
201 |
-
|
202 |
-
return data;
|
203 |
-
}
|
204 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/constants.php
DELETED
@@ -1,46 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Constants used by this plugin
|
4 |
-
*
|
5 |
-
* @package WP Backitup
|
6 |
-
*
|
7 |
-
* @author jcpeden
|
8 |
-
* @version 1.5.5
|
9 |
-
* @since 1.0.1
|
10 |
-
*/
|
11 |
-
|
12 |
-
if( !defined( 'WPBACKITUP_VERSION' ) ) define( 'WPBACKITUP_VERSION', '1.6.7' );
|
13 |
-
|
14 |
-
if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', dirname( dirname( __FILE__ ) ) );
|
15 |
-
|
16 |
-
if( !defined( 'WPBACKITUP_DIR_PATH' ) ) define( 'WPBACKITUP_DIR_PATH', dirname( dirname( dirname( __FILE__ ) ) ) );
|
17 |
-
|
18 |
-
if( !defined( 'WPBACKITUP_CONTENT_PATH' ) ) define( 'WPBACKITUP_CONTENT_PATH', dirname(dirname(dirname(dirname(__FILE__)))) .'/' );
|
19 |
-
|
20 |
-
if( !defined( 'WPBACKITUP_BACKUP_FOLDER' ) ) define( 'WPBACKITUP_BACKUP_FOLDER', 'wpbackitup_backups' );
|
21 |
-
|
22 |
-
if( !defined( 'WPBACKITUP_RESTORE_FOLDER' ) ) define( 'WPBACKITUP_RESTORE_FOLDER', 'wpbackitup_restore' );
|
23 |
-
|
24 |
-
if( !defined( 'WPBACKITUP_URLPATH' ) ) define( 'WPBACKITUP_URLPATH', WP_PLUGIN_URL . "/" . plugin_basename( WPBACKITUP_DIRNAME ) );
|
25 |
-
|
26 |
-
if( !defined( 'WPBACKITUP_BACKUPFILE_URLPATH' ) ) define( 'WPBACKITUP_BACKUPFILE_URLPATH', content_url() . "/" .WPBACKITUP_BACKUP_FOLDER);
|
27 |
-
|
28 |
-
if( !defined( 'IS_AJAX_REQUEST' ) ) define( 'IS_AJAX_REQUEST', ( !empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) );
|
29 |
-
|
30 |
-
if( !defined( 'WPBACKITUP_SITE_URL' ) ) define( 'WPBACKITUP_SITE_URL', 'http://www.wpbackitup.com' );
|
31 |
-
|
32 |
-
if( !defined( 'WPBACKITUP_ITEM_NAME' ) ) define( 'WPBACKITUP_ITEM_NAME', 'WP Backitup' );
|
33 |
-
|
34 |
-
if( !defined( 'WPBACKITUP_PLUGIN_FOLDER' ) ) define( 'WPBACKITUP_PLUGIN_FOLDER', plugin_basename( WPBACKITUP_DIRNAME ));
|
35 |
-
|
36 |
-
if( !defined( 'WPBACKITUP_SQL_DBBACKUP_FILENAME' ) ) define( 'WPBACKITUP_SQL_DBBACKUP_FILENAME', 'db-backup.sql');
|
37 |
-
|
38 |
-
if( !defined( 'WPBACKITUP_SQL_TABLE_RENAME_FILENAME' ) ) define( 'WPBACKITUP_SQL_TABLE_RENAME_FILENAME', 'db-rename-tables.sql');
|
39 |
-
|
40 |
-
if( !defined( 'WPBACKITUP_PLUGINS_PATH' ) ) define( 'WPBACKITUP_PLUGINS_PATH', dirname(dirname(__DIR__)));
|
41 |
-
|
42 |
-
if( !defined( 'WPBACKITUP_PLUGINS_FOLDER' ) ) define( 'WPBACKITUP_PLUGINS_FOLDER', basename(WPBACKITUP_PLUGINS_PATH));
|
43 |
-
|
44 |
-
if( !defined( 'WPBACKITUP_THEMES_PATH' ) ) define( 'WPBACKITUP_THEMES_PATH', dirname(get_bloginfo('template_directory')));
|
45 |
-
|
46 |
-
if( !defined( 'WPBACKITUP_THEMES_FOLDER' ) ) define( 'WPBACKITUP_THEMES_FOLDER', basename(WPBACKITUP_THEMES_PATH));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/functions.php
DELETED
@@ -1,899 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP Backitup Functions
|
4 |
-
*
|
5 |
-
* @package WP Backitup
|
6 |
-
*
|
7 |
-
* @author jcpeden
|
8 |
-
* @version 1.4.2
|
9 |
-
* @since 1.0.2
|
10 |
-
*/
|
11 |
-
|
12 |
-
// localize the plugin
|
13 |
-
function lang_setup() {
|
14 |
-
global $WPBackitup;
|
15 |
-
load_plugin_textdomain($WPBackitup->namespace, false, dirname(plugin_basename(__FILE__)) . '/lang/');
|
16 |
-
}
|
17 |
-
add_action('after_setup_theme', 'lang_setup');
|
18 |
-
|
19 |
-
// include recurseZip class
|
20 |
-
if( !class_exists( 'recurseZip' ) ) {
|
21 |
-
include_once 'includes/recurse_zip.php';
|
22 |
-
}
|
23 |
-
|
24 |
-
// include recursive iterator
|
25 |
-
if( !class_exists( 'RecursiveFilter_Iterator' ) ) {
|
26 |
-
include_once 'includes/RecursiveFilter_Iterator.php';
|
27 |
-
}
|
28 |
-
// retrieve our license key from the DB
|
29 |
-
$license_key = trim( $this->get_option( 'license_key' ) );
|
30 |
-
|
31 |
-
|
32 |
-
//Feth the debug status and set
|
33 |
-
global $WPBACKITUP_DEBUG;
|
34 |
-
$WPBACKITUP_DEBUG=false;
|
35 |
-
if ('enabled'==$this->get_option( 'logging' )){
|
36 |
-
$WPBACKITUP_DEBUG= true;
|
37 |
-
}
|
38 |
-
|
39 |
-
//Check the license key
|
40 |
-
function license_active(){
|
41 |
-
global $WPBackitup;
|
42 |
-
$license_key = $WPBackitup->get_option( 'license_key' );
|
43 |
-
$license_status = $WPBackitup->get_option( 'status' );
|
44 |
-
|
45 |
-
if(false !== $license_key && false !== $license_status && 'valid'== $license_status)
|
46 |
-
{
|
47 |
-
return true;
|
48 |
-
}
|
49 |
-
return false;
|
50 |
-
}
|
51 |
-
|
52 |
-
//define dbSize function
|
53 |
-
function dbSize($dbname) {
|
54 |
-
mysqli_select_db($dbname);
|
55 |
-
$result = mysqli_query("SHOW TABLE STATUS");
|
56 |
-
$dbsize = 0;
|
57 |
-
while($row = mysqli_fetch_array($result)) {
|
58 |
-
$dbsize += $row["Data_length"] + $row["Index_length"];
|
59 |
-
}
|
60 |
-
return $dbsize;
|
61 |
-
}
|
62 |
-
|
63 |
-
//define formatFileSize function
|
64 |
-
function formatFileSize($bytes)
|
65 |
-
{
|
66 |
-
if ($bytes >= 1073741824)
|
67 |
-
{
|
68 |
-
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
|
69 |
-
}
|
70 |
-
elseif ($bytes >= 1048576)
|
71 |
-
{
|
72 |
-
$bytes = number_format($bytes / 1048576, 2) . ' MB';
|
73 |
-
}
|
74 |
-
elseif ($bytes >= 1024)
|
75 |
-
{
|
76 |
-
$bytes = number_format($bytes / 1024, 2) . ' KB';
|
77 |
-
}
|
78 |
-
elseif ($bytes > 1)
|
79 |
-
{
|
80 |
-
$bytes = $bytes . ' bytes';
|
81 |
-
}
|
82 |
-
elseif ($bytes == 1)
|
83 |
-
{
|
84 |
-
$bytes = $bytes . ' byte';
|
85 |
-
}
|
86 |
-
else
|
87 |
-
{
|
88 |
-
$bytes = '0 bytes';
|
89 |
-
}
|
90 |
-
|
91 |
-
return $bytes;
|
92 |
-
}
|
93 |
-
|
94 |
-
//define dirSize function
|
95 |
-
function dirSize($directory) {
|
96 |
-
$size = 0;
|
97 |
-
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
|
98 |
-
$size+=$file->getSize();
|
99 |
-
}
|
100 |
-
return $size;
|
101 |
-
}
|
102 |
-
|
103 |
-
//load backup function
|
104 |
-
function backup() {
|
105 |
-
include_once 'includes/backup.php';
|
106 |
-
}
|
107 |
-
add_action('wp_ajax_backup', 'backup');
|
108 |
-
|
109 |
-
function deletefile()
|
110 |
-
{
|
111 |
-
$fileToDel = str_replace('deleteRow', '', $_POST['filed']);
|
112 |
-
$restore_path = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/' . $fileToDel;
|
113 |
-
_log('(functions.deletefile) Delete File:' . $restore_path);
|
114 |
-
if (unlink($restore_path))
|
115 |
-
echo 'deleted';
|
116 |
-
else
|
117 |
-
echo 'problem';
|
118 |
-
exit(0);
|
119 |
-
}
|
120 |
-
|
121 |
-
add_action('wp_ajax_deletefile', 'deletefile');
|
122 |
-
|
123 |
-
|
124 |
-
//load restore_path function
|
125 |
-
function restore_path() {
|
126 |
-
include_once 'includes/restore_from_path.php';
|
127 |
-
}
|
128 |
-
add_action('wp_ajax_restore_path', 'restore_path');
|
129 |
-
|
130 |
-
//load download function
|
131 |
-
//function download() {
|
132 |
-
// if(glob(WPBACKITUP_DIRNAME . "/backups/*.zip")) {
|
133 |
-
// foreach (glob(WPBACKITUP_DIRNAME . "/backups/*.zip") as $file) {
|
134 |
-
// $filename = basename($file);
|
135 |
-
// echo 'Download your last backup:</br><a href="' .WPBACKITUP_URLPATH. '/backups/' .$filename .'">' .$filename .'</a>';
|
136 |
-
// }
|
137 |
-
// } else {
|
138 |
-
// echo 'No export file available for download. Please create one.';
|
139 |
-
// }
|
140 |
-
// die();
|
141 |
-
//}
|
142 |
-
//add_action('wp_ajax_download', 'download');
|
143 |
-
|
144 |
-
//Get Status Log
|
145 |
-
function getStatusLog() {
|
146 |
-
$log = WPBACKITUP_DIRNAME .'/logs/status.log';
|
147 |
-
if (file_exists($log)){
|
148 |
-
unlink($log);
|
149 |
-
}
|
150 |
-
$fh = fopen($log, 'w') or die( "Can't write to log file" );
|
151 |
-
return $fh;
|
152 |
-
}
|
153 |
-
|
154 |
-
//load logreader function
|
155 |
-
function logreader() {
|
156 |
-
$log = WPBACKITUP_DIRNAME .'/logs/status.log';
|
157 |
-
if(file_exists($log) ) {
|
158 |
-
readfile($log);
|
159 |
-
}
|
160 |
-
die();
|
161 |
-
}
|
162 |
-
add_action('wp_ajax_logreader', 'logreader');
|
163 |
-
|
164 |
-
//load status check function
|
165 |
-
function statusreader() {
|
166 |
-
$log = WPBACKITUP_DIRNAME .'/logs/restore_status.log';
|
167 |
-
if(file_exists($log) ) {
|
168 |
-
readfile($log);
|
169 |
-
}
|
170 |
-
die();
|
171 |
-
}
|
172 |
-
add_action('wp_ajax_statusreader', 'statusreader');
|
173 |
-
|
174 |
-
//define create_dir function
|
175 |
-
if(!function_exists('create_dir')) {
|
176 |
-
function create_dir($dir) {
|
177 |
-
if( !is_dir($dir) ) {
|
178 |
-
@mkdir($dir, 0755);
|
179 |
-
}
|
180 |
-
_log('(functions.create_dir) Directory created: ' .$dir);
|
181 |
-
return true;
|
182 |
-
}
|
183 |
-
}
|
184 |
-
|
185 |
-
//Define recusive_copy function
|
186 |
-
if(!function_exists('recursive_copy')) {
|
187 |
-
function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
|
188 |
-
_log('(functions.recursive_copy) IGNORE:');
|
189 |
-
_log($ignore);
|
190 |
-
if( is_dir($dir) ) { //If the directory exists
|
191 |
-
if ($dh = opendir($dir) ) {
|
192 |
-
while(($file = readdir($dh)) !== false) { //While there are files in the directory
|
193 |
-
if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
|
194 |
-
if (!is_dir( $dir.$file ) ) {
|
195 |
-
$fsrc = fopen($dir .$file,'r');
|
196 |
-
$fdest = fopen($target_path .$file,'w+');
|
197 |
-
$len = stream_copy_to_stream($fsrc,$fdest);
|
198 |
-
fclose($fsrc);
|
199 |
-
fclose($fdest);
|
200 |
-
} else { //If $file is a directory
|
201 |
-
$destdir = $target_path .$file; //Modify the destination dir
|
202 |
-
if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
|
203 |
-
_log('(functions.recursive_copy) Create Folder: ' .$destdir);
|
204 |
-
@mkdir($destdir, 0755);
|
205 |
-
}
|
206 |
-
recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
|
207 |
-
}
|
208 |
-
}
|
209 |
-
}
|
210 |
-
closedir($dh);
|
211 |
-
}
|
212 |
-
}
|
213 |
-
_log('(functions.recursive_copy) Recursive FROM: ' .$dir);
|
214 |
-
_log('(functions.recursive_copy) Recursive Copy TO: '.$target_path);
|
215 |
-
return true;
|
216 |
-
}
|
217 |
-
}
|
218 |
-
|
219 |
-
//Generate SQL to rename existing WP tables.
|
220 |
-
if(!function_exists('db_rename_wptables')) {
|
221 |
-
function db_rename_wptables($sql_file_path,$table_prefix) {
|
222 |
-
_log('(db_rename_wptables)Manually Create SQL Backup File:'.$sql_file_path);
|
223 |
-
|
224 |
-
$mysqli = db_get_sqlconnection();
|
225 |
-
if (false===$mysqli) {
|
226 |
-
return false;
|
227 |
-
}
|
228 |
-
|
229 |
-
$tables = array() ;
|
230 |
-
|
231 |
-
// Exploring what tables this database has
|
232 |
-
$sql = "SHOW TABLES WHERE `Tables_in_" .DB_NAME ."` NOT LIKE 'save_%'";
|
233 |
-
$result = $mysqli->query($sql);
|
234 |
-
|
235 |
-
// Cycle through "$result" and put content into an array
|
236 |
-
while ($row = $result->fetch_row()) {
|
237 |
-
$tables[] = $row[0] ;
|
238 |
-
}
|
239 |
-
|
240 |
-
// Close the connection
|
241 |
-
$mysqli->close() ;
|
242 |
-
|
243 |
-
// Cycle through each table
|
244 |
-
$firstPass=true;
|
245 |
-
foreach($tables as $table) {
|
246 |
-
$source_table=$table;
|
247 |
-
$target_table='save_'. $source_table;
|
248 |
-
|
249 |
-
if($firstPass){
|
250 |
-
$firstPass=false;
|
251 |
-
|
252 |
-
// Script Header Information
|
253 |
-
$return = '';
|
254 |
-
$return .= "--\n";
|
255 |
-
$return .= "-- WP Backitup Rename WP Tables \n";
|
256 |
-
$return .= "--\n";
|
257 |
-
$return .= '-- Created: ' . date("Y/m/d") . "\n";
|
258 |
-
$return .= "--\n";
|
259 |
-
$return .= "-- Database : " . DB_NAME . "\n";
|
260 |
-
$return .= "--\n";
|
261 |
-
$return .= "-- --------------------------------------------------\n";
|
262 |
-
$return .= "-- ---------------------------------------------------\n";
|
263 |
-
$return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ;
|
264 |
-
$return .= "--\n" ;
|
265 |
-
$return .= 'RENAME TABLE '. "\n";
|
266 |
-
}
|
267 |
-
else{
|
268 |
-
$return .= "\n" . ',';
|
269 |
-
}
|
270 |
-
|
271 |
-
$return .= '`'.$source_table.'` TO `' . $target_table . '` ';
|
272 |
-
}
|
273 |
-
|
274 |
-
$return .=';' . "\n" ;
|
275 |
-
$return .= 'COMMIT ; ' . "\n" ;
|
276 |
-
$return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
|
277 |
-
|
278 |
-
//save file if there were any tables in the database
|
279 |
-
if (count($tables)>0){
|
280 |
-
$handle = fopen($sql_file_path,'w+');
|
281 |
-
fwrite($handle,$return);
|
282 |
-
fclose($handle);
|
283 |
-
_log('(db_rename_wptables)SQL Backup File Created:' .$sql_file_path);
|
284 |
-
}
|
285 |
-
|
286 |
-
if (!file_exists($sql_file_path)){
|
287 |
-
_log('(db_rename_wptables) SQL file doesnt exist: ' .$sql_file_path);
|
288 |
-
return false;
|
289 |
-
}
|
290 |
-
|
291 |
-
return true;
|
292 |
-
}
|
293 |
-
}
|
294 |
-
|
295 |
-
if(!function_exists('db_get_hostonly')) {
|
296 |
-
function db_get_hostonly($db_host) {
|
297 |
-
//Check for port
|
298 |
-
$host_array = explode(':',$db_host);
|
299 |
-
if (is_array($host_array)){
|
300 |
-
return $host_array[0];
|
301 |
-
}
|
302 |
-
return $db_host;
|
303 |
-
}
|
304 |
-
}
|
305 |
-
//Get rid of the port if its in the hostname
|
306 |
-
if(!function_exists('db_get_portonly')) {
|
307 |
-
function db_get_portonly($db_host) {
|
308 |
-
//Check for port
|
309 |
-
$host_array = explode(':',$db_host);
|
310 |
-
if (is_array($host_array) && count($host_array)>1){
|
311 |
-
return $host_array[1];
|
312 |
-
}
|
313 |
-
|
314 |
-
return false;
|
315 |
-
}
|
316 |
-
}
|
317 |
-
|
318 |
-
//Get SQL connection
|
319 |
-
if(!function_exists('db_get_sqlconnection')) {
|
320 |
-
function db_get_sqlconnection() {
|
321 |
-
_log('(functions.db_get_sqlconnection)Get SQL connection to database.');
|
322 |
-
$db_name = DB_NAME;
|
323 |
-
$db_user = DB_USER;
|
324 |
-
$db_pass = DB_PASSWORD;
|
325 |
-
$db_host = db_get_hostonly(DB_HOST);
|
326 |
-
$db_port = db_get_portonly(DB_HOST);
|
327 |
-
|
328 |
-
_log('(functions.db_get_sqlconnection)Host:' . $db_host);
|
329 |
-
_log('(functions.db_get_sqlconnection)Port:' . $db_port);
|
330 |
-
|
331 |
-
if (false===$db_port){
|
332 |
-
$mysqli = new mysqli($db_host , $db_user , $db_pass , $db_name);
|
333 |
-
}
|
334 |
-
else {
|
335 |
-
$mysqli = new mysqli($db_host , $db_user , $db_pass , $db_name,$db_port);
|
336 |
-
}
|
337 |
-
|
338 |
-
if ($mysqli->connect_errno) {
|
339 |
-
_log('(functions.db_get_sqlconnection)Cannot connect to database.' . $mysqli->connect_error);
|
340 |
-
return false;
|
341 |
-
}
|
342 |
-
return $mysqli;
|
343 |
-
}
|
344 |
-
}
|
345 |
-
|
346 |
-
//Define DB backup function
|
347 |
-
if(!function_exists('db_backup')) {
|
348 |
-
function db_backup($sql_file_path) {
|
349 |
-
_log('(functions.db_backup)Manually Create SQL Backup File:'.$sql_file_path);
|
350 |
-
|
351 |
-
$mysqli = db_get_sqlconnection();
|
352 |
-
$mysqli->set_charset('utf8');
|
353 |
-
|
354 |
-
if (false===$mysqli) {
|
355 |
-
return false;
|
356 |
-
}
|
357 |
-
|
358 |
-
// Script Header Information
|
359 |
-
$return = '';
|
360 |
-
$return .= "-- ------------------------------------------------------\n";
|
361 |
-
$return .= "-- ------------------------------------------------------\n";
|
362 |
-
$return .= "--\n";
|
363 |
-
$return .= "-- WP BackItUp Manual Database Backup \n";
|
364 |
-
$return .= "--\n";
|
365 |
-
$return .= '-- Created: ' . date("Y/m/d") . ' on ' . date("h:i") . "\n";
|
366 |
-
$return .= "--\n";
|
367 |
-
$return .= "-- Database : " . DB_NAME . "\n";
|
368 |
-
$return .= "--\n";
|
369 |
-
$return .= "-- ------------------------------------------------------\n";
|
370 |
-
$return .= "-- ------------------------------------------------------\n";
|
371 |
-
$return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ;
|
372 |
-
$return .= 'SET FOREIGN_KEY_CHECKS=0 ;' ."\n" ;
|
373 |
-
$return .= "\n";
|
374 |
-
|
375 |
-
$return .= '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' ."\n" ;
|
376 |
-
$return .= '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' ."\n" ;
|
377 |
-
$return .= '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;' ."\n" ;
|
378 |
-
$return .= '/*!40101 SET NAMES utf8 */;' ."\n" ;
|
379 |
-
|
380 |
-
$tables = array() ;
|
381 |
-
|
382 |
-
// Exploring what tables this database has
|
383 |
-
$result = $mysqli->query('SHOW TABLES' ) ;
|
384 |
-
|
385 |
-
// Cycle through "$result" and put content into an array
|
386 |
-
while ($row = $result->fetch_row()) {
|
387 |
-
$tables[] = $row[0] ;
|
388 |
-
}
|
389 |
-
|
390 |
-
// Cycle through each table
|
391 |
-
foreach($tables as $table) {
|
392 |
-
// Get content of each table
|
393 |
-
$result = $mysqli->query('SELECT * FROM '. $table) ;
|
394 |
-
|
395 |
-
// Get number of fields (columns) of each table
|
396 |
-
$num_fields = $mysqli->field_count ;
|
397 |
-
|
398 |
-
// Add table information
|
399 |
-
$return .= "--\n" ;
|
400 |
-
$return .= '-- Table structure for table `' . $table . '`' . "\n" ;
|
401 |
-
$return .= "--\n" ;
|
402 |
-
$return.= 'DROP TABLE IF EXISTS `'.$table.'`;' . "\n" ;
|
403 |
-
|
404 |
-
// Get the table-shema
|
405 |
-
$shema = $mysqli->query('SHOW CREATE TABLE '.$table) ;
|
406 |
-
|
407 |
-
// Extract table shema
|
408 |
-
$tableshema = $shema->fetch_row() ;
|
409 |
-
|
410 |
-
// Append table-shema into code
|
411 |
-
$return.= $tableshema[1].";" . "\n\n" ;
|
412 |
-
|
413 |
-
// Cycle through each table-row
|
414 |
-
while($rowdata = $result->fetch_row()) {
|
415 |
-
|
416 |
-
// Prepare code that will insert data into table
|
417 |
-
/*Script to take the backup of complete wordpress database tables with there strucutre and data
|
418 |
-
* @author - rajeev sharma @ matrix
|
419 |
-
*/
|
420 |
-
$return.= 'INSERT INTO '.$table.' VALUES(';
|
421 |
-
for($j=0; $j<$num_fields; $j++){
|
422 |
-
$rowdata[$j] = addslashes($rowdata[$j]);
|
423 |
-
$rowdata[$j] = str_replace("\n","\\n",$rowdata[$j]);
|
424 |
-
|
425 |
-
if (isset($rowdata[$j])) {
|
426 |
-
$return.= '"'.$rowdata[$j].'"' ;
|
427 |
-
} else {
|
428 |
-
if (is_null($rowdata[$j])) {
|
429 |
-
$return.= 'NULL';//Dont think this is working but not causing issues
|
430 |
-
} else {
|
431 |
-
$return.= '""';
|
432 |
-
}
|
433 |
-
}
|
434 |
-
|
435 |
-
if ($j<($num_fields-1)) { $return.= ','; }
|
436 |
-
}
|
437 |
-
$return.= ");\n";
|
438 |
-
}
|
439 |
-
$return .= "\n\n" ;
|
440 |
-
}
|
441 |
-
|
442 |
-
// Close the connection
|
443 |
-
$mysqli->close() ;
|
444 |
-
$return .= 'SET FOREIGN_KEY_CHECKS = 1 ; ' . "\n" ;
|
445 |
-
$return .= 'COMMIT ; ' . "\n" ;
|
446 |
-
$return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
|
447 |
-
|
448 |
-
//save file
|
449 |
-
$handle = fopen($sql_file_path,'w+');
|
450 |
-
fwrite($handle,$return);
|
451 |
-
fclose($handle);
|
452 |
-
clearstatcache();
|
453 |
-
|
454 |
-
//Did the export work
|
455 |
-
if (!file_exists($sql_file_path) || filesize($sql_file_path)<=0) {
|
456 |
-
_log('(functions.db_backup) Failure: SQL Export file was empty or didnt exist.');
|
457 |
-
return false;
|
458 |
-
}
|
459 |
-
|
460 |
-
_log('(functions.db_backup)SQL Backup File Created:'.$sql_file_path);
|
461 |
-
return true;
|
462 |
-
}
|
463 |
-
}
|
464 |
-
|
465 |
-
if(!function_exists('db_SQLDump')) {
|
466 |
-
function db_SQLDump($sql_file_path) {
|
467 |
-
|
468 |
-
_log('(functions.db_SQLDump) SQL Dump: ' .$sql_file_path);
|
469 |
-
|
470 |
-
$db_name = DB_NAME;
|
471 |
-
$db_user = DB_USER;
|
472 |
-
$db_pass = DB_PASSWORD;
|
473 |
-
$db_host = db_get_hostonly(DB_HOST);
|
474 |
-
$db_port = db_get_portonly(DB_HOST);
|
475 |
-
|
476 |
-
//This is to ensure that exec() is enabled on the server
|
477 |
-
if(exec('echo EXEC') == 'EXEC') {
|
478 |
-
try {
|
479 |
-
$process = 'mysqldump';
|
480 |
-
|
481 |
-
$command = $process
|
482 |
-
. ' --host=' . $db_host;
|
483 |
-
|
484 |
-
//Check for port
|
485 |
-
if (false!==$db_port){
|
486 |
-
$command .=' --port=' . $db_port;
|
487 |
-
}
|
488 |
-
|
489 |
-
$command .=
|
490 |
-
' --user=' . $db_user
|
491 |
-
. ' --password=' . $db_pass
|
492 |
-
.=' ' . $db_name
|
493 |
-
. ' > "' . $sql_file_path .'"';
|
494 |
-
|
495 |
-
//_log('(functions.db_SQLDump)Execute command:' . $command);
|
496 |
-
|
497 |
-
exec($command,$output,$rtn_var);
|
498 |
-
_log('(functions.db_SQLDump)Execute output:');
|
499 |
-
_log($output);
|
500 |
-
_log('Return Value:' .$rtn_var);
|
501 |
-
|
502 |
-
//0 is success
|
503 |
-
if ($rtn_var>0){
|
504 |
-
return false;
|
505 |
-
}
|
506 |
-
|
507 |
-
//Did the export work
|
508 |
-
clearstatcache();
|
509 |
-
if (!file_exists($sql_file_path) || filesize($sql_file_path)<=0) {
|
510 |
-
_log('(functions.db_SQLDump) Failure: Dump was empty or missing.');
|
511 |
-
return false;
|
512 |
-
}
|
513 |
-
} catch(Exception $e) {
|
514 |
-
_log('(functions.db_SQLDump) Exception: ' .$e);
|
515 |
-
return false;
|
516 |
-
}
|
517 |
-
}
|
518 |
-
else
|
519 |
-
{
|
520 |
-
_log('(functions.db_SQLDump) Failure: Exec() disabled.');
|
521 |
-
return false;
|
522 |
-
}
|
523 |
-
|
524 |
-
_log('(functions.db_SQLDump) SQL Dump completed.');
|
525 |
-
return true;
|
526 |
-
}
|
527 |
-
}
|
528 |
-
//define db_import function
|
529 |
-
if(!function_exists('db_run_sql')) {
|
530 |
-
function db_run_sql($sql_file) {
|
531 |
-
_log('(functions.db_run_sql)SQL Execute:' .$sql_file);
|
532 |
-
|
533 |
-
//Is the backup sql file empty
|
534 |
-
if (!file_exists($sql_file) || filesize($sql_file)<=0) {
|
535 |
-
_log('(functions.db_run_sql) Failure: SQL File was empty:' .$sql_file);
|
536 |
-
return false;
|
537 |
-
}
|
538 |
-
|
539 |
-
//This is to ensure that exec() is enabled on the server
|
540 |
-
if(exec('echo EXEC') != 'EXEC') {
|
541 |
-
_log('(functions.db_run_sql) Failure: Exec() disabled.');
|
542 |
-
return false;
|
543 |
-
}
|
544 |
-
|
545 |
-
try {
|
546 |
-
|
547 |
-
$db_name = DB_NAME;
|
548 |
-
$db_user = DB_USER;
|
549 |
-
$db_pass = DB_PASSWORD;
|
550 |
-
$db_host = db_get_hostonly(DB_HOST);
|
551 |
-
$db_port = db_get_portonly(DB_HOST);
|
552 |
-
|
553 |
-
$process = 'mysql';
|
554 |
-
$command = $process
|
555 |
-
. ' --host=' . $db_host
|
556 |
-
. ' --user=' . $db_user
|
557 |
-
. ' --password=' . $db_pass
|
558 |
-
. ' --database=' . $db_name
|
559 |
-
. ' --execute="SOURCE ' . $sql_file .'"';
|
560 |
-
|
561 |
-
_log('(functions.db_run_sql)Execute command:' . $command);
|
562 |
-
|
563 |
-
$output = shell_exec($command);
|
564 |
-
exec($command,$output,$rtn_var);
|
565 |
-
_log('(functions.db_run_sql)Execute output:');
|
566 |
-
_log($output);
|
567 |
-
_log('Return Value:' .$rtn_var);
|
568 |
-
|
569 |
-
//0 is success
|
570 |
-
if ($rtn_var>0){
|
571 |
-
return false;
|
572 |
-
}
|
573 |
-
|
574 |
-
}catch(Exception $e) {
|
575 |
-
_log('(functions.db_run_sql) Exception: ' .$e);
|
576 |
-
return false;
|
577 |
-
}
|
578 |
-
|
579 |
-
//Success
|
580 |
-
_log('(functions.db_run_sql)SQL Executed successfully:' .$sql_file);
|
581 |
-
return true;
|
582 |
-
}
|
583 |
-
}
|
584 |
-
|
585 |
-
//Define the create_siteinfo function
|
586 |
-
if(!function_exists('create_siteinfo')) {
|
587 |
-
function create_siteinfo($path, $table_prefix) {
|
588 |
-
$siteinfo = $path ."backupsiteinfo.txt";
|
589 |
-
$handle = fopen($siteinfo, 'w+');
|
590 |
-
$entry = site_url( '/' ) ."\n$table_prefix";
|
591 |
-
fwrite($handle, $entry);
|
592 |
-
fclose($handle);
|
593 |
-
_log('(funtions.create_siteinfo) Site Info created:'.$siteinfo);
|
594 |
-
return true;
|
595 |
-
}
|
596 |
-
}
|
597 |
-
|
598 |
-
if(!function_exists('delete_allbutzips')){
|
599 |
-
function delete_allbutzips($dir){
|
600 |
-
$ignore = array('cgi-bin','.','..','._');
|
601 |
-
if( is_dir($dir) ){
|
602 |
-
if($dh = opendir($dir)) {
|
603 |
-
while( ($file = readdir($dh)) !== false ) {
|
604 |
-
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
605 |
-
if (!in_array($file, $ignore) && substr($file, 0, 1) != '.' && $ext!="zip") { //Check the file is not in the ignore array
|
606 |
-
if(!is_dir($dir .'/'. $file)) {
|
607 |
-
unlink($dir .'/'. $file);
|
608 |
-
} else {
|
609 |
-
recursive_delete($dir.'/'. $file, $ignore);
|
610 |
-
}
|
611 |
-
}
|
612 |
-
}
|
613 |
-
}
|
614 |
-
@rmdir($dir);
|
615 |
-
closedir($dh);
|
616 |
-
}
|
617 |
-
_log('(funtions.delete_allbutzips) Delete all but zips completed:'.$dir);
|
618 |
-
return true;
|
619 |
-
}
|
620 |
-
}
|
621 |
-
|
622 |
-
|
623 |
-
//Recursively delete all children
|
624 |
-
if(!function_exists('delete_children_recursive')){
|
625 |
-
function delete_children_recursive($path, $ignore = array('cgi-bin','._'))
|
626 |
-
{
|
627 |
-
if (is_dir($path))
|
628 |
-
{
|
629 |
-
_log('(delete_children_recursive) Ignore:');
|
630 |
-
_log($ignore);
|
631 |
-
$iterator = new RecursiveDirectoryIterator($path);
|
632 |
-
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
|
633 |
-
$filter = new RecursiveFilter_Iterator($iterator);
|
634 |
-
$filter->set_filter($ignore);
|
635 |
-
|
636 |
-
$all_files = new RecursiveIteratorIterator($filter,RecursiveIteratorIterator::CHILD_FIRST);
|
637 |
-
|
638 |
-
foreach ($all_files as $file)
|
639 |
-
{
|
640 |
-
if ($file->isDir())
|
641 |
-
{
|
642 |
-
_log('(delete_recursive_new) delete folder:'.$file);
|
643 |
-
rmdir($file->getPathname());
|
644 |
-
}
|
645 |
-
else
|
646 |
-
{
|
647 |
-
_log('(delete_recursive_new) delete file:'.$file);
|
648 |
-
unlink($file->getPathname());
|
649 |
-
}
|
650 |
-
}
|
651 |
-
}
|
652 |
-
return true;
|
653 |
-
}
|
654 |
-
}
|
655 |
-
|
656 |
-
//Define recursive_delete function
|
657 |
-
if(!function_exists('recursive_delete')){
|
658 |
-
function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
|
659 |
-
if( is_dir($dir) ){
|
660 |
-
if($dh = opendir($dir)) {
|
661 |
-
while( ($file = readdir($dh)) !== false ) {
|
662 |
-
if (!in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
|
663 |
-
if(!is_dir($dir .'/'. $file)) {
|
664 |
-
unlink($dir .'/'. $file);
|
665 |
-
} else {
|
666 |
-
recursive_delete($dir.'/'. $file, $ignore);
|
667 |
-
}
|
668 |
-
}
|
669 |
-
}
|
670 |
-
}
|
671 |
-
_log('(functions.recursive_delete) Folder Deleted:' .$dir);
|
672 |
-
@rmdir($dir);
|
673 |
-
closedir($dh);
|
674 |
-
}
|
675 |
-
return true;
|
676 |
-
}
|
677 |
-
}
|
678 |
-
|
679 |
-
//Define zip function
|
680 |
-
function zip($source, $destination, $ignore) {
|
681 |
-
if (is_string($source)) $source_arr = array($source); // convert it to array
|
682 |
-
if (!extension_loaded('zip')) {
|
683 |
-
return false;
|
684 |
-
}
|
685 |
-
$zip = new ZipArchive();
|
686 |
-
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
|
687 |
-
return false;
|
688 |
-
}
|
689 |
-
foreach ($source_arr as $source) {
|
690 |
-
if (!file_exists($source)) continue;
|
691 |
-
$source = str_replace('\\', '/', realpath($source));
|
692 |
-
if (is_dir($source) === true) {
|
693 |
-
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
|
694 |
-
foreach ($files as $file) {
|
695 |
-
if (!preg_match($ignore, $file)) {
|
696 |
-
$file = str_replace('\\', '/', realpath($file));
|
697 |
-
if (is_dir($file) === true) {
|
698 |
-
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
|
699 |
-
} else if (is_file($file) === true) {
|
700 |
-
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
|
701 |
-
}
|
702 |
-
}
|
703 |
-
}
|
704 |
-
} else if (is_file($source) === true) {
|
705 |
-
$zip->addFromString(basename($source), file_get_contents($source));
|
706 |
-
}
|
707 |
-
}
|
708 |
-
return $zip->close();
|
709 |
-
}
|
710 |
-
|
711 |
-
|
712 |
-
//Disable presstrends v 1.6.1
|
713 |
-
function load_presstrends() {
|
714 |
-
// global $WPBackitup;
|
715 |
-
// _log('Load Presstrends');
|
716 |
-
// if($WPBackitup->get_option( 'presstrends' ) == 'enabled') {
|
717 |
-
// _log('Presstrends enabled');
|
718 |
-
// // PressTrends Account API Key
|
719 |
-
// $api_key = '7s4lfc8du5we4cjcdcw7wv3bedn596gjxmgy';
|
720 |
-
// $auth = 'uu8dz66bqreltwdq66hjculnyqkkwofy5';
|
721 |
-
|
722 |
-
// // Start of Metrics
|
723 |
-
// global $wpdb;
|
724 |
-
// $data = get_transient( 'presstrends_cache_data' );
|
725 |
-
// if ( !$data || $data == '' ) {
|
726 |
-
// _log('Presstrends cached data:' . $data);
|
727 |
-
// $api_base = 'http://api.presstrends.io/index.php/api/pluginsites/update/auth/';
|
728 |
-
// $url = $api_base . $auth . '/api/' . $api_key . '/';
|
729 |
-
|
730 |
-
// $count_posts = wp_count_posts();
|
731 |
-
// $count_pages = wp_count_posts( 'page' );
|
732 |
-
// $comments_count = wp_count_comments();
|
733 |
-
|
734 |
-
// // wp_get_theme was introduced in 3.4, for compatibility with older versions, let's do a workaround for now.
|
735 |
-
// if ( function_exists( 'wp_get_theme' ) ) {
|
736 |
-
// $theme_data = wp_get_theme();
|
737 |
-
// $theme_name = urlencode( $theme_data->Name );
|
738 |
-
// } else {
|
739 |
-
// $theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
|
740 |
-
// $theme_name = $theme_data['Name'];
|
741 |
-
// }
|
742 |
-
|
743 |
-
// $plugin_name = '&';
|
744 |
-
// foreach ( get_plugins() as $plugin_info ) {
|
745 |
-
// $plugin_name .= $plugin_info['Name'] . '&';
|
746 |
-
// }
|
747 |
-
// // CHANGE __FILE__ PATH IF LOCATED OUTSIDE MAIN PLUGIN FILE
|
748 |
-
// $plugin_data = get_plugin_data( __FILE__ );
|
749 |
-
// $posts_with_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0" );
|
750 |
-
// $data = array(
|
751 |
-
// 'url' => stripslashes( str_replace( array( 'http://', '/', ':' ), '', site_url() ) ),
|
752 |
-
// 'posts' => $count_posts->publish,
|
753 |
-
// 'pages' => $count_pages->publish,
|
754 |
-
// 'comments' => $comments_count->total_comments,
|
755 |
-
// 'approved' => $comments_count->approved,
|
756 |
-
// 'spam' => $comments_count->spam,
|
757 |
-
// 'pingbacks' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
|
758 |
-
// 'post_conversion' => ( $count_posts->publish > 0 && $posts_with_comments > 0 ) ? number_format( ( $posts_with_comments / $count_posts->publish ) * 100, 0, '.', '' ) : 0,
|
759 |
-
// 'theme_version' => $plugin_data['Version'],
|
760 |
-
// 'theme_name' => $theme_name,
|
761 |
-
// 'site_name' => str_replace( ' ', '', get_bloginfo( 'name' ) ),
|
762 |
-
// 'plugins' => count( get_option( 'active_plugins' ) ),
|
763 |
-
// 'plugin' => urlencode( $plugin_name ),
|
764 |
-
// 'wpversion' => get_bloginfo( 'version' ),
|
765 |
-
// );
|
766 |
-
|
767 |
-
// foreach ( $data as $k => $v ) {
|
768 |
-
// $url .= $k . '/' . $v . '/';
|
769 |
-
// }
|
770 |
-
// _log('Prestrends URL' . $url);
|
771 |
-
// //wp_remote_get( $url ); - disable usage tracking
|
772 |
-
// set_transient( 'presstrends_cache_data', $data, 60 * 60 * 24 );
|
773 |
-
// }
|
774 |
-
// }
|
775 |
-
}
|
776 |
-
|
777 |
-
// PressTrends WordPress Action
|
778 |
-
add_action('admin_init', 'load_presstrends');
|
779 |
-
|
780 |
-
//Get Status Log
|
781 |
-
if(!function_exists('deleteDebugLog')){
|
782 |
-
function deleteDebugLog() {
|
783 |
-
global $WPBACKITUP_DEBUG;
|
784 |
-
if ($WPBACKITUP_DEBUG===true){
|
785 |
-
$date = date_i18n('Y-m-d',current_time( 'timestamp' ));
|
786 |
-
$mydebugLog = WPBACKITUP_DIRNAME ."/logs/debug_" .$date .".log";
|
787 |
-
if (file_exists($mydebugLog)){
|
788 |
-
try{
|
789 |
-
unlink($mydebugLog);
|
790 |
-
} catch(Exception $e) {
|
791 |
-
//Dont do anything
|
792 |
-
}
|
793 |
-
}
|
794 |
-
|
795 |
-
$debugLog = WPBACKITUP_CONTENT_PATH ."debug.log";
|
796 |
-
if (file_exists($debugLog)){
|
797 |
-
try{
|
798 |
-
unlink($debugLog);
|
799 |
-
} catch(Exception $e) {
|
800 |
-
//Dont do anything
|
801 |
-
}
|
802 |
-
}
|
803 |
-
}
|
804 |
-
}
|
805 |
-
}
|
806 |
-
|
807 |
-
//Get debug Log
|
808 |
-
if(!function_exists('getDebugLogFile')){
|
809 |
-
function getDebugLogFile() {
|
810 |
-
try {
|
811 |
-
global $WPBACKITUP_DEBUG;
|
812 |
-
if ($WPBACKITUP_DEBUG===true){
|
813 |
-
//Check to see if File exists
|
814 |
-
$date = date_i18n('Y-m-d',current_time( 'timestamp' ));
|
815 |
-
$debugLog = WPBACKITUP_DIRNAME ."/logs/debug_" .$date .".log";
|
816 |
-
$dfh = fopen($debugLog, 'a');
|
817 |
-
return $dfh;
|
818 |
-
}
|
819 |
-
} catch(Exception $e) {
|
820 |
-
//Dont do anything
|
821 |
-
}
|
822 |
-
}
|
823 |
-
}
|
824 |
-
|
825 |
-
// //load logWriter function
|
826 |
-
if(!function_exists('_log')){
|
827 |
-
function _log($message) {
|
828 |
-
//Is debug ON
|
829 |
-
global $WPBACKITUP_DEBUG;
|
830 |
-
try{
|
831 |
-
if ($WPBACKITUP_DEBUG===true){
|
832 |
-
$dfh = getDebugLogFile(); //Get File
|
833 |
-
if (!is_null($dfh)){
|
834 |
-
$date = date_i18n('Y-m-d Hi:i:s',current_time( 'timestamp' ));
|
835 |
-
if( is_array( $message ) || is_object( $message ) ){
|
836 |
-
fwrite($dfh, $date ." " .print_r( $message, true ) . PHP_EOL);
|
837 |
-
} else {
|
838 |
-
fwrite($dfh, $date ." " .$message . PHP_EOL);
|
839 |
-
}
|
840 |
-
fclose($dfh);
|
841 |
-
}
|
842 |
-
}
|
843 |
-
} catch(Exception $e) {
|
844 |
-
//Dont do anything
|
845 |
-
}
|
846 |
-
}
|
847 |
-
}
|
848 |
-
|
849 |
-
//Log all the constants
|
850 |
-
if(!function_exists('_log_constants')){
|
851 |
-
function _log_constants() {
|
852 |
-
_log("**SYSTEM CONSTANTS**");
|
853 |
-
_log("WPBackItUp License Active: " . (license_active() ? 'true' : 'false'));
|
854 |
-
_log("Wordpress Version:" . get_bloginfo( 'version'));
|
855 |
-
_log("PHP Version:" . phpversion());
|
856 |
-
_log("Operating System:" . php_uname());
|
857 |
-
|
858 |
-
_log("**CONSTANTS**");
|
859 |
-
_log("WPBACKITUP_VERSION:" . WPBACKITUP_VERSION);
|
860 |
-
_log("WPBACKITUP_DIRNAME:" . WPBACKITUP_DIRNAME);
|
861 |
-
_log("WPBACKITUP_DIR_PATH:" . WPBACKITUP_DIRNAME);
|
862 |
-
_log("WPBACKITUP_CONTENT_PATH:" . WPBACKITUP_CONTENT_PATH);
|
863 |
-
_log("WPBACKITUP_BACKUP_FOLDER:" . WPBACKITUP_BACKUP_FOLDER);
|
864 |
-
_log("WPBACKITUP_RESTORE_FOLDER:" . WPBACKITUP_RESTORE_FOLDER);
|
865 |
-
_log("WPBACKITUP_URLPATH:" . WPBACKITUP_URLPATH);
|
866 |
-
_log("WPBACKITUP_BACKUPFILE_URLPATH:" . WPBACKITUP_BACKUPFILE_URLPATH );
|
867 |
-
_log("IS_AJAX_REQUEST:" . IS_AJAX_REQUEST );
|
868 |
-
_log("WPBACKITUP_SITE_URL:" . WPBACKITUP_SITE_URL );
|
869 |
-
_log("WPBACKITUP_ITEM_NAME:" . WPBACKITUP_ITEM_NAME );
|
870 |
-
_log("WPBACKITUP_PLUGIN_FOLDER:" . WPBACKITUP_PLUGIN_FOLDER );
|
871 |
-
_log("WPBACKITUP_SQL_DBBACKUP_FILENAME:" . WPBACKITUP_SQL_DBBACKUP_FILENAME);
|
872 |
-
_log("WPBACKITUP_SQL_TABLE_RENAME_FILENAME:" . WPBACKITUP_SQL_TABLE_RENAME_FILENAME);
|
873 |
-
_log("WPBACKITUP_PLUGINS_PATH:" . WPBACKITUP_PLUGINS_PATH);
|
874 |
-
_log("WPBACKITUP_PLUGINS_FOLDER:" . WPBACKITUP_PLUGINS_FOLDER);
|
875 |
-
_log("WPBACKITUP_THEMES_PATH:" . WPBACKITUP_THEMES_PATH);
|
876 |
-
_log("WPBACKITUP_THEMES_FOLDER:" . WPBACKITUP_THEMES_FOLDER);
|
877 |
-
_log("** END CONSTANTS**");
|
878 |
-
}
|
879 |
-
}
|
880 |
-
|
881 |
-
// if(!function_exists('redo_to_checkpoint')) {
|
882 |
-
// function redo_to_checkpoint($checkpoint) {
|
883 |
-
|
884 |
-
// if($checkpoint == "db")
|
885 |
-
// {
|
886 |
-
// if( glob($restoration_dir_path . "*.cur") ) {
|
887 |
-
// //collect connection information from form
|
888 |
-
// fwrite($fh, '<div class="database">In Progress</div>');
|
889 |
-
// include_once WP_DIR_PATH .'/wp-config.php';
|
890 |
-
// //Add user to DB in v1.0.5
|
891 |
-
// $user_id = $_POST['user_id'];
|
892 |
-
// //Connect to DB
|
893 |
-
// $output = db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc);
|
894 |
-
// }
|
895 |
-
|
896 |
-
// }
|
897 |
-
|
898 |
-
// }
|
899 |
-
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/includes/RecursiveFilter_Iterator.php
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* WP Backitup Recurse Iterator
|
4 |
-
*
|
5 |
-
* @package WP Backitup
|
6 |
-
*
|
7 |
-
* @author cssimmon
|
8 |
-
* @version 1.4.0
|
9 |
-
* @since 1.0.1
|
10 |
-
*/
|
11 |
-
|
12 |
-
|
13 |
-
class RecursiveFilter_Iterator extends RecursiveFilterIterator {
|
14 |
-
|
15 |
-
private $filters=array();
|
16 |
-
|
17 |
-
//Set the ignore list
|
18 |
-
function set_filter ($ignore) {
|
19 |
-
$this->filters = $ignore;
|
20 |
-
}
|
21 |
-
|
22 |
-
public function accept() {
|
23 |
-
return !in_array(
|
24 |
-
$this->current()->getFilename(),
|
25 |
-
$this->filters,
|
26 |
-
true
|
27 |
-
);
|
28 |
-
}
|
29 |
-
|
30 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/includes/auto_update.php
DELETED
@@ -1,141 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* WP Backitup Auto Update
|
5 |
-
*
|
6 |
-
* @package WP Backitup
|
7 |
-
*
|
8 |
-
* @author jcpeden
|
9 |
-
* @version 1.4.0
|
10 |
-
* @since 1.0.1
|
11 |
-
*/
|
12 |
-
|
13 |
-
class EDD_SL_Plugin_Updater {
|
14 |
-
private $api_url = '';
|
15 |
-
private $api_data = array();
|
16 |
-
private $name = '';
|
17 |
-
private $slug = '';
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Class constructor.
|
21 |
-
*
|
22 |
-
* @uses plugin_basename()
|
23 |
-
* @uses hook()
|
24 |
-
*
|
25 |
-
* @param string $_api_url The URL pointing to the custom API endpoint.
|
26 |
-
* @param string $_plugin_file Path to the plugin file.
|
27 |
-
* @param array $_api_data Optional data to send with API calls.
|
28 |
-
* @return void
|
29 |
-
*/
|
30 |
-
function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
|
31 |
-
$this->api_url = trailingslashit( $_api_url );
|
32 |
-
$this->api_data = urlencode_deep( $_api_data );
|
33 |
-
$this->name = plugin_basename( $_plugin_file );
|
34 |
-
$this->slug = basename( $_plugin_file, '.php');
|
35 |
-
$this->version = $_api_data['version'];
|
36 |
-
|
37 |
-
// Set up hooks.
|
38 |
-
$this->hook();
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Set up Wordpress filters to hook into WP's update process.
|
43 |
-
*
|
44 |
-
* @uses add_filter()
|
45 |
-
*
|
46 |
-
* @return void
|
47 |
-
*/
|
48 |
-
private function hook() {
|
49 |
-
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'pre_set_site_transient_update_plugins_filter' ) );
|
50 |
-
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
|
51 |
-
}
|
52 |
-
|
53 |
-
/**
|
54 |
-
* Check for Updates at the defined API endpoint and modify the update array.
|
55 |
-
*
|
56 |
-
* This function dives into the update api just when Wordpress creates its update array,
|
57 |
-
* then adds a custom API call and injects the custom plugin data retrieved from the API.
|
58 |
-
* It is reassembled from parts of the native Wordpress plugin update code.
|
59 |
-
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
|
60 |
-
*
|
61 |
-
* @uses api_request()
|
62 |
-
*
|
63 |
-
* @param array $_transient_data Update array build by Wordpress.
|
64 |
-
* @return array Modified update array with custom plugin data.
|
65 |
-
*/
|
66 |
-
function pre_set_site_transient_update_plugins_filter( $_transient_data ) {
|
67 |
-
|
68 |
-
|
69 |
-
if( empty( $_transient_data ) ) return $_transient_data;
|
70 |
-
|
71 |
-
$to_send = array( 'slug' => $this->slug );
|
72 |
-
|
73 |
-
$api_response = $this->api_request( 'plugin_latest_version', $to_send );
|
74 |
-
|
75 |
-
if( false !== $api_response && is_object( $api_response ) ) {
|
76 |
-
if( version_compare( $this->version, $api_response->new_version, '<' ) )
|
77 |
-
$_transient_data->response[$this->name] = $api_response;
|
78 |
-
}
|
79 |
-
return $_transient_data;
|
80 |
-
}
|
81 |
-
|
82 |
-
|
83 |
-
/**
|
84 |
-
* Updates information on the "View version x.x details" page with custom data.
|
85 |
-
*
|
86 |
-
* @uses api_request()
|
87 |
-
*
|
88 |
-
* @param mixed $_data
|
89 |
-
* @param string $_action
|
90 |
-
* @param object $_args
|
91 |
-
* @return object $_data
|
92 |
-
*/
|
93 |
-
function plugins_api_filter( $_data, $_action = '', $_args = null ) {
|
94 |
-
if ( ( $_action != 'plugin_information' ) || !isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) return $_data;
|
95 |
-
|
96 |
-
$to_send = array( 'slug' => $this->slug );
|
97 |
-
|
98 |
-
$api_response = $this->api_request( 'plugin_information', $to_send );
|
99 |
-
if ( false !== $api_response ) $_data = $api_response;
|
100 |
-
|
101 |
-
return $_data;
|
102 |
-
}
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Calls the API and, if successfull, returns the object delivered by the API.
|
106 |
-
*
|
107 |
-
* @uses get_bloginfo()
|
108 |
-
* @uses wp_remote_post()
|
109 |
-
* @uses is_wp_error()
|
110 |
-
*
|
111 |
-
* @param string $_action The requested action.
|
112 |
-
* @param array $_data Parameters for the API action.
|
113 |
-
* @return false||object
|
114 |
-
*/
|
115 |
-
private function api_request( $_action, $_data ) {
|
116 |
-
|
117 |
-
global $wp_version;
|
118 |
-
|
119 |
-
$data = array_merge( $this->api_data, $_data );
|
120 |
-
if( $data['slug'] != $this->slug )
|
121 |
-
return;
|
122 |
-
|
123 |
-
$api_params = array(
|
124 |
-
'edd_action' => 'get_version',
|
125 |
-
'license' => $data['license'],
|
126 |
-
'name' => $data['item_name'],
|
127 |
-
'slug' => $this->slug,
|
128 |
-
'author' => $data['author']
|
129 |
-
);
|
130 |
-
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
|
131 |
-
|
132 |
-
if ( !is_wp_error( $request ) ):
|
133 |
-
$request = json_decode( wp_remote_retrieve_body( $request ) );
|
134 |
-
if( $request )
|
135 |
-
$request->sections = maybe_unserialize( $request->sections );
|
136 |
-
return $request;
|
137 |
-
else:
|
138 |
-
return false;
|
139 |
-
endif;
|
140 |
-
}
|
141 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/includes/backup.php
CHANGED
@@ -1,160 +1,496 @@
|
|
1 |
-
<?php
|
2 |
//limit process to 15 minutes
|
3 |
@set_time_limit(900);
|
4 |
|
5 |
/**
|
6 |
-
* WP Backitup Backup
|
7 |
*
|
8 |
-
* @package WP Backitup
|
9 |
*
|
10 |
* @author cssimmon
|
11 |
-
*
|
12 |
-
* @since 1.0.1
|
13 |
*/
|
|
|
14 |
/*** Includes ***/
|
15 |
-
|
16 |
-
if
|
17 |
-
include_once
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
/*** Globals ***/
|
21 |
global $WPBackitup;
|
|
|
|
|
|
|
|
|
|
|
22 |
$fileUTCDateTime=current_time( 'timestamp' );
|
23 |
-
$localDateTime = date_i18n('Y-m-d-
|
24 |
-
$
|
25 |
-
|
26 |
-
$
|
27 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
//*****************//
|
31 |
//*** MAIN CODE ***//
|
32 |
//*****************//
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
//
|
38 |
-
$
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
//
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
-
//
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
|
53 |
-
//
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
}
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
die();
|
84 |
}
|
|
|
85 |
}
|
86 |
|
87 |
-
|
|
|
|
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
}
|
103 |
|
104 |
-
|
105 |
-
global $
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
die();
|
112 |
-
} else {
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
}
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
$
|
119 |
-
|
120 |
-
$
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
}
|
132 |
|
133 |
-
//close log file
|
134 |
-
fwrite($fh, '<div class="finalinfo">1</div>');
|
135 |
-
fclose($fh);
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
-
|
142 |
-
|
|
|
|
|
143 |
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
-
|
147 |
-
|
|
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
/******************/
|
152 |
-
function cleanup_on_failure($backup_project_path){
|
153 |
-
global $WPBACKITUP_DEBUG;
|
154 |
-
if ($WPBACKITUP_DEBUG===true){
|
155 |
-
_log('Cleanup On Fail suspended: debug on.');
|
156 |
}
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
}
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
//limit process to 15 minutes
|
3 |
@set_time_limit(900);
|
4 |
|
5 |
/**
|
6 |
+
* WP Backitup Backup
|
7 |
*
|
8 |
+
* @package WP Backitup
|
9 |
*
|
10 |
* @author cssimmon
|
11 |
+
*
|
|
|
12 |
*/
|
13 |
+
|
14 |
/*** Includes ***/
|
15 |
+
|
16 |
+
if( !class_exists( 'WPBackItUp_Logger' ) ) {
|
17 |
+
include_once 'class-logger.php';
|
18 |
+
}
|
19 |
+
|
20 |
+
if( !class_exists( 'WPBackItUp_Utility' ) ) {
|
21 |
+
include_once 'class-utility.php';
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
if( !class_exists( 'WPBackItUp_SQL' ) ) {
|
26 |
+
include_once 'class-sql.php';
|
27 |
+
}
|
28 |
+
|
29 |
+
// include backup class
|
30 |
+
if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
31 |
+
include_once 'class-backup.php';
|
32 |
+
}
|
33 |
+
|
34 |
+
// include logger class
|
35 |
+
if( !class_exists( 'WPBackItUp_Zip' ) ) {
|
36 |
+
include_once 'class-zip.php';
|
37 |
+
}
|
38 |
+
|
39 |
+
// include file system class
|
40 |
+
if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
|
41 |
+
include_once 'class-filesystem.php';
|
42 |
+
}
|
43 |
|
44 |
/*** Globals ***/
|
45 |
global $WPBackitup;
|
46 |
+
global $backup_start_time;
|
47 |
+
|
48 |
+
//Get root
|
49 |
+
$url = str_replace('http://','',home_url());
|
50 |
+
$url = str_replace('/','-',$url);
|
51 |
$fileUTCDateTime=current_time( 'timestamp' );
|
52 |
+
$localDateTime = date_i18n('Y-m-d-His',$fileUTCDateTime);
|
53 |
+
$backup_name = 'Backup_' . $url .'_' .$localDateTime;
|
54 |
+
|
55 |
+
global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
|
56 |
+
$inactive=0;
|
57 |
+
$active=1;
|
58 |
+
$complete=2;
|
59 |
+
$failure=-1;
|
60 |
+
$warning=-2;
|
61 |
+
$success=99;
|
62 |
+
|
63 |
+
//setup the status array
|
64 |
+
global $status_array;
|
65 |
+
$status_array = array(
|
66 |
+
'preparing' =>$inactive,
|
67 |
+
'backupdb' =>$inactive ,
|
68 |
+
'infofile'=>$inactive,
|
69 |
+
'backupfiles'=>$inactive,
|
70 |
+
'zipfile'=>$inactive,
|
71 |
+
'cleanup'=>$inactive
|
72 |
+
);
|
73 |
|
74 |
+
global $logger;
|
75 |
+
$log_path = WPBACKITUP__BACKUP_PATH;
|
76 |
+
//echo "</br>Log Path:" .$log_path ;
|
77 |
+
$logger = new WPBackItUp_Logger(false,$log_path,$backup_name);
|
78 |
+
|
79 |
+
global $wp_backup; //Eventually everything will be migrated to this class
|
80 |
+
$wp_backup = new WPBackItUp_Backup($logger,$backup_name);
|
81 |
|
82 |
//*****************//
|
83 |
//*** MAIN CODE ***//
|
84 |
//*****************//
|
85 |
+
$logger->log('***BEGIN BACKUP***');
|
86 |
+
$logger->logConstants();
|
87 |
+
$backup_start_time = current_time( 'timestamp');
|
88 |
+
|
89 |
+
$WPBackitup->increment_backup_count();
|
90 |
+
|
91 |
+
|
92 |
+
//Dont do anything with this now, just post date time
|
93 |
+
$jsonResponse = new stdClass();
|
94 |
+
$jsonResponse->message = 'processing';
|
95 |
+
$jsonResponse->server_time=$backup_start_time;
|
96 |
+
write_response_file($jsonResponse);
|
97 |
+
|
98 |
+
//Cleanup & Validate the backup folded is ready
|
99 |
+
set_status('preparing',$active,true);
|
100 |
+
sleep(3);//For UI only
|
101 |
+
|
102 |
+
//TESTS GO HERE
|
103 |
+
|
104 |
+
//$response['message'] ='success';
|
105 |
+
//$response['filedate'] = $localDateTime;
|
106 |
+
//$response['file'] = $wp_backup->backup_filename;
|
107 |
+
//$response['zip_link'] = WPBACKITUP__BACKUP_URL . '/' . $wp_backup->backup_filename;
|
108 |
+
//$response['license'] = $this->license_active();
|
109 |
+
//$response['retained'] = $wp_backup->backup_retained_number;
|
110 |
+
//echo json_encode($response);
|
111 |
+
//die();
|
112 |
+
//TEST END HERE
|
113 |
+
|
114 |
+
$logger->log('CLEANUP');
|
115 |
+
cleanup_BackupFolder($wp_backup->backup_folder_root);
|
116 |
+
create_BackupFolder($wp_backup->backup_project_path);
|
117 |
+
check_BackupFolder($wp_backup->backup_project_path);
|
118 |
+
set_status('preparing',$complete,false);
|
119 |
+
|
120 |
+
//Backup the database
|
121 |
+
$logger->log('SQL EXPORT');
|
122 |
+
set_status('backupdb',$active,true);
|
123 |
+
sleep(3);//For UI only
|
124 |
+
$sqlFileName=$wp_backup->backup_project_path . WPBACKITUP__SQL_DBBACKUP_FILENAME;
|
125 |
+
export_Database($sqlFileName);
|
126 |
+
set_status('backupdb',$complete,false);
|
127 |
|
128 |
+
//Extract the site info
|
129 |
+
$logger->log('SITE INFO');
|
130 |
+
set_status('infofile',$active,true);
|
131 |
+
sleep(3);//For UI only
|
132 |
+
create_SiteInfoFile($wp_backup->backup_project_path);
|
133 |
+
set_status('infofile',$complete,false);
|
134 |
|
135 |
+
//Backup the WP-Content
|
136 |
+
$logger->log('WP CONTENT');
|
137 |
+
set_status('backupfiles',$active,true);
|
138 |
+
sleep(3);//For UI only
|
139 |
+
backup_wpcontent();
|
140 |
+
set_status('backupfiles',$complete,false);
|
141 |
|
142 |
+
//Zip up the backup folder
|
143 |
+
$logger->log('ZIP');
|
144 |
+
set_status('zipfile',$active,true);
|
145 |
+
sleep(3);//For UI only
|
146 |
+
$logger->log('Zip Up the Backup Folder:'.$wp_backup->backup_project_path);
|
147 |
+
$zip = new WPBackItUp_Zip($logger);
|
148 |
+
$zip->compress($wp_backup->backup_project_path, $wp_backup->backup_folder_root);
|
149 |
+
set_status('zipfile',$complete,false);
|
150 |
+
|
151 |
+
//Send JSON response
|
152 |
+
$jsonResponse = new stdClass();
|
153 |
+
$jsonResponse->message = 'success';
|
154 |
+
$jsonResponse->filedate = $localDateTime;
|
155 |
+
$jsonResponse->file = $wp_backup->backup_filename;
|
156 |
+
$jsonResponse->zip_link = WPBACKITUP__BACKUP_URL . '/' . $wp_backup->backup_filename;
|
157 |
+
$jsonResponse->license = $this->license_active();
|
158 |
+
$jsonResponse->retained = $wp_backup->backup_retained_number;
|
159 |
+
|
160 |
+
if (file_exists($logger->logFilePath)) {
|
161 |
+
$jsonResponse->log_link = basename($logger->logFileName,'.log');
|
162 |
}
|
163 |
|
164 |
+
//Cleanup
|
165 |
+
$logger->log('CLEANUP');
|
166 |
+
set_status('cleanup',$active,true);
|
167 |
+
cleanup($wp_backup->backup_project_path);
|
168 |
+
set_status('cleanup',$complete,false);
|
169 |
+
|
170 |
+
//Send success Email to user before cleanup
|
171 |
+
send_backup_notification_email(null,true);
|
172 |
+
|
173 |
+
//DONE!
|
174 |
+
set_status_success();
|
175 |
+
write_response_file($jsonResponse);
|
176 |
+
|
177 |
+
$WPBackitup->increment_successful_backup_count();
|
178 |
+
|
179 |
+
$logger->log("Backup completed successfully");
|
180 |
+
$logger->log("*** END BACKUP ***");
|
181 |
+
die();
|
182 |
+
|
183 |
+
/******************/
|
184 |
+
/*** Functions ***/
|
185 |
+
/******************/
|
186 |
+
function cleanup($path){
|
187 |
+
global $logger,$wp_backup;
|
188 |
+
$logger->log('Delete Backup Folder:'.$path);
|
189 |
+
$fileSystem = new WPBackItUp_FileSystem($logger);
|
190 |
+
if(!$fileSystem ->recursive_delete($path)) {
|
191 |
+
write_warning_status('error106');
|
192 |
}
|
193 |
+
else
|
194 |
+
{
|
195 |
+
$logger->log('Backup Folder Deleted');
|
196 |
+
}
|
197 |
+
|
198 |
+
//Check the retention
|
199 |
+
$fileSystem->purge_FilesByDate($wp_backup->backup_retained_number,$wp_backup->backup_folder_root);
|
200 |
+
|
201 |
+
//Purge logs older than 5 days
|
202 |
+
$fileSystem->purge_files(WPBACKITUP__BACKUP_PATH .'/','log',5);
|
203 |
+
|
204 |
+
}
|
205 |
+
|
206 |
+
function backup_wpcontent(){
|
207 |
+
global $logger,$wp_backup;
|
208 |
+
|
209 |
+
$fromFolder = WPBACKITUP__CONTENT_PATH . '/';
|
210 |
+
$ignore = array( WPBACKITUP__BACKUP_FOLDER,$wp_backup->backup_name,$wp_backup->restore_folder_root,'backupbuddy_backups','*.zip','cache' );
|
211 |
+
|
212 |
+
$logger->log('Recursive Copy FROM:'.$fromFolder);
|
213 |
+
$logger->log('Recursive Copy TO:'.$wp_backup->backup_project_path);
|
214 |
+
$logger->log('Ignore Array:');
|
215 |
+
$logger->log($ignore);
|
216 |
+
|
217 |
+
$fileSystem = new WPBackItUp_FileSystem($logger);
|
218 |
+
if(!$fileSystem->recursive_copy($fromFolder, $wp_backup->backup_project_path, $ignore) ) {
|
219 |
+
write_fatal_error_status('error103');
|
220 |
+
cleanup_on_failure($wp_backup->backup_project_path);
|
221 |
+
send_backup_notification_email(103,false);
|
222 |
die();
|
223 |
}
|
224 |
+
$logger->log('Recursive Copy completed');
|
225 |
}
|
226 |
|
227 |
+
//Create siteinfo in project dir
|
228 |
+
function create_SiteInfoFile($path){
|
229 |
+
global $wpdb,$logger;
|
230 |
|
231 |
+
$logger->log('Create Site Info File:'.$path);
|
232 |
+
if (!create_siteinfo($path, $wpdb->prefix) ) {
|
233 |
+
write_fatal_error_status('error105');
|
234 |
+
cleanup_on_failure($path);
|
235 |
+
send_backup_notification_email(105,false);
|
236 |
+
die();
|
237 |
+
}
|
238 |
+
$logger->log('Site Info File Created.');
|
239 |
+
}
|
240 |
|
241 |
+
function create_siteinfo($path, $table_prefix) {
|
242 |
+
$siteinfo = $path ."backupsiteinfo.txt";
|
243 |
+
$handle = fopen($siteinfo, 'w+');
|
244 |
+
$entry = site_url( '/' ) ."\n$table_prefix";
|
245 |
+
fwrite($handle, $entry);
|
246 |
+
fclose($handle);
|
247 |
+
return true;
|
248 |
}
|
249 |
|
250 |
+
function export_Database($sqlFileName){
|
251 |
+
global $wp_backup,$logger;
|
252 |
+
|
253 |
+
$SQL = new WPBackItUp_SQL($logger);
|
254 |
+
|
255 |
+
//Try SQLDump First
|
256 |
+
$logger->log('Create the SQL Backup File:'.$sqlFileName);
|
257 |
+
if(!$SQL->mysqldump_export($sqlFileName) ) {
|
258 |
+
//Try manual extract if sqldump isnt working
|
259 |
+
if(!$SQL->manual_export($sqlFileName) ) {
|
260 |
+
write_fatal_error_status('error104');
|
261 |
+
cleanup_on_failure($wp_backup->backup_project_path);
|
262 |
+
send_backup_notification_email(104,false);
|
263 |
+
die();
|
264 |
+
}
|
265 |
+
}
|
266 |
+
$logger->log('Created the SQL Backup File:'.$sqlFileName);
|
267 |
+
}
|
268 |
+
//Check to see if the directory is writeable
|
269 |
+
function check_BackupFolder($path){
|
270 |
+
global $wp_backup,$logger;
|
271 |
+
$logger->log("Is folder writeable: " .$path);
|
272 |
+
if(!is_writeable($path)) {
|
273 |
+
write_fatal_error_status('error102');
|
274 |
+
send_backup_notification_email(102,false);
|
275 |
die();
|
276 |
+
} else {
|
277 |
+
//If the directory is writeable, create the backup folder if it doesn't exist
|
278 |
+
$logger->log("Folder IS writeable: " .$path);
|
279 |
+
if(!is_dir($path) ) {
|
280 |
+
$logger->log("Create Backup Content Folder: " .$path);
|
281 |
+
@mkdir($wp_backup->backup_project_path, 0755);
|
282 |
+
$logger->log('Backup Content Folder Created:'.$path);
|
283 |
+
}
|
284 |
+
}
|
285 |
}
|
286 |
|
287 |
+
function create_BackupFolder($path){
|
288 |
+
global $logger;
|
289 |
+
$fileSystem = new WPBackItUp_FileSystem($logger);
|
290 |
+
|
291 |
+
$logger->log("Create Backup Folder: " .$path);
|
292 |
+
if(!$fileSystem->create_dir($path)) {
|
293 |
+
$logger->log('Error: Cant create backup folder :'. $path);
|
294 |
+
write_fatal_error_status('error101');
|
295 |
+
send_backup_notification_email(101, false);
|
296 |
+
die();
|
297 |
+
}
|
298 |
+
$logger->log("Backup Folder Created");
|
299 |
+
}
|
300 |
+
|
301 |
+
function send_backup_notification_email($err, $status)
|
302 |
+
{
|
303 |
+
global $WPBackitup, $logger, $backup_start_time,$status_array;
|
304 |
+
$utility = new WPBackItUp_Utility($logger);
|
305 |
+
|
306 |
+
$start_date = new DateTime(date( 'Y-m-d H:i:s',$backup_start_time));
|
307 |
+
$backup_end_time = current_time( 'timestamp' );
|
308 |
+
$interval = $start_date->diff(new DateTime(date( 'Y-m-d H:i:s',$backup_end_time)));
|
309 |
+
|
310 |
+
$logger->log('Script Processing Time:' .$interval->format('%i Minutes %s Seconds'));
|
311 |
+
|
312 |
+
$status_description = array(
|
313 |
+
'preparing'=>'Preparing for backup...Done',
|
314 |
+
'backupdb'=>'Backing-up database...Done',
|
315 |
+
'infofile'=>'Creating backup information file...Done',
|
316 |
+
'backupfiles'=>'Backing up plugins, themes, and uploads...Done',
|
317 |
+
'zipfile'=>'Zipping backup directory...Done',
|
318 |
+
'cleanup'=>'Cleaning up...Done'
|
319 |
+
);
|
320 |
+
|
321 |
+
$error_description = array(
|
322 |
+
'101' =>'Error 101: Unable to create a new directory for backup. Please check your CHMOD settings of your wp-backitup backup directory',
|
323 |
+
'102'=> 'Error 102: Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory',
|
324 |
+
'103'=> 'Error 103: Unable to backup your files. Please try again',
|
325 |
+
'104'=> 'Error 104: Unable to backup your database. Please try again',
|
326 |
+
'105'=> 'Error 105: Unable to create site information file. Please try again',
|
327 |
+
'106'=> 'Warning 106: Unable to cleanup your backup directory',
|
328 |
+
'114'=> 'Error 114: Your database was accessible but an export could not be created. Please contact support by clicking the get support link on the right. Please let us know who your host is when you submit the request'
|
329 |
+
);
|
330 |
+
|
331 |
+
if($status)
|
332 |
+
{
|
333 |
+
$subject = 'WP BackItUp - Backup completed successfully.';
|
334 |
+
$message = '<b>Your backup completed successfully.</b><br/><br/>';
|
335 |
|
336 |
+
} else {
|
337 |
+
$subject = 'WP BackItUp - Backup did not complete successfully.';
|
338 |
+
$message = '<b>Your backup did not complete successfully.</b><br/><br/>';
|
339 |
+
}
|
340 |
+
|
341 |
+
$message .= 'Backup started: ' . date( 'Y-m-d H:i:s',$backup_start_time) . '<br/>';
|
342 |
+
$message .= 'Backup ended: ' . date( 'Y-m-d H:i:s',$backup_end_time) . '<br/>';
|
343 |
+
$message .= 'Processing Time: ' . $interval->format('%i Minutes %s Seconds') . '<br/>';
|
344 |
+
|
345 |
+
$message .= '<br/>';
|
346 |
+
|
347 |
+
$message .='<b>Steps Completed</b><br/>';
|
348 |
+
|
349 |
+
//Add the completed statuses
|
350 |
+
foreach ($status_array as $status_key => $status_value) {
|
351 |
+
// echo($status_key. ':' .$status_value);
|
352 |
+
if ($status_value==2) {
|
353 |
+
foreach ($status_description as $msg_key => $msg_value) {
|
354 |
+
// echo($status_key. ':' .$msg_key);
|
355 |
+
if ($status_key==$msg_key) {
|
356 |
+
$message .= $msg_value . '<br/>';
|
357 |
+
break;
|
358 |
+
}
|
359 |
+
}
|
360 |
+
}
|
361 |
+
}
|
362 |
+
|
363 |
+
//Add the errors
|
364 |
+
if(!$status)
|
365 |
+
{
|
366 |
+
$message .= '<br/>';
|
367 |
+
$message .= 'Errors:<br/>';
|
368 |
+
|
369 |
+
foreach ($error_description as $key => $value) {
|
370 |
+
if ($err==$key){
|
371 |
+
$message .=$error_description[$key];
|
372 |
+
}
|
373 |
+
}
|
374 |
+
}
|
375 |
+
|
376 |
+
$message .='<br/><br/>Checkout <a href="https://www.wpbackitup.com">www.wpbackitup.com</a> for info about WP BackItUp and our other products.<br/>';
|
377 |
+
|
378 |
+
$notification_email = $WPBackitup->get_option('notification_email');
|
379 |
+
if($notification_email)
|
380 |
+
$utility->send_email($notification_email,$subject,$message);
|
381 |
+
}
|
382 |
+
|
383 |
+
function cleanup_on_failure($path){
|
384 |
+
global $logger;
|
385 |
+
if (WPBACKITUP__DEBUG===true){
|
386 |
+
$logger->log('Cleanup On Fail suspended: debug on.');
|
387 |
+
}
|
388 |
+
else{
|
389 |
+
cleanup_backupFolder($path);
|
390 |
+
}
|
391 |
+
}
|
392 |
|
393 |
+
function cleanup_BackupFolder($dir){
|
394 |
+
global $logger;
|
395 |
+
$logger->log('Cleanup Backup Folder:'.$dir);
|
396 |
+
$ignore = array('cgi-bin','.','..','._');
|
397 |
+
if( is_dir($dir) ){
|
398 |
+
if($dh = opendir($dir)) {
|
399 |
+
while( ($file = readdir($dh)) !== false ) {
|
400 |
+
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
401 |
+
if (!in_array($file, $ignore) && substr($file, 0, 1) != '.' && $ext!="zip" && $ext!="log") { //Check the file is not in the ignore array
|
402 |
+
if(!is_dir($dir .'/'. $file)) {
|
403 |
+
unlink($dir .'/'. $file);
|
404 |
+
} else {
|
405 |
+
$fileSystem = new WPBackItUp_FileSystem($logger);
|
406 |
+
$fileSystem->recursive_delete($dir.'/'. $file, $ignore);
|
407 |
+
}
|
408 |
+
}
|
409 |
+
}
|
410 |
+
}
|
411 |
+
@rmdir($dir);
|
412 |
+
closedir($dh);
|
413 |
+
}
|
414 |
+
$logger->log('Cleanup Backup Folder completed:'.$dir);
|
415 |
+
return true;
|
416 |
}
|
417 |
|
|
|
|
|
|
|
418 |
|
419 |
+
function write_fatal_error_status($status_code) {
|
420 |
+
global $status_array,$active,$failure;
|
421 |
+
|
422 |
+
//Find the active status and set to failure
|
423 |
+
foreach ($status_array as $key => $value) {
|
424 |
+
if ($value==$active){
|
425 |
+
$status_array[$key]=$failure;
|
426 |
+
}
|
427 |
+
}
|
428 |
|
429 |
+
//Add failure to array
|
430 |
+
$status_array[$status_code]=$failure;
|
431 |
+
write_status();
|
432 |
+
}
|
433 |
|
434 |
+
function write_warning_status($status_code) {
|
435 |
+
global $status_array,$warning;
|
436 |
+
|
437 |
+
//Add warning to array
|
438 |
+
$status_array[$status_code]=$warning;
|
439 |
+
write_status();
|
440 |
+
}
|
441 |
|
442 |
+
function write_status() {
|
443 |
+
global $status_array;
|
444 |
+
$fh=getStatusLog();
|
445 |
|
446 |
+
foreach ($status_array as $key => $value) {
|
447 |
+
fwrite($fh, '<div class="' . $key . '">' . $value .'</div>');
|
|
|
|
|
|
|
|
|
|
|
448 |
}
|
449 |
+
fclose($fh);
|
450 |
+
}
|
451 |
+
|
452 |
+
function set_status($process,$status,$flush){
|
453 |
+
global $status_array;
|
454 |
+
$status_array[$process]=$status;
|
455 |
+
|
456 |
+
if ($flush) write_status();
|
457 |
+
}
|
458 |
+
|
459 |
+
function set_status_success(){
|
460 |
+
global $status_array,$success;
|
461 |
+
|
462 |
+
$status_array['finalinfo']=$success;
|
463 |
+
write_status();
|
464 |
+
}
|
465 |
+
|
466 |
+
//Get Status Log
|
467 |
+
function getStatusLog() {
|
468 |
+
$log = WPBACKITUP__PLUGIN_PATH .'/logs/status.log';
|
469 |
+
if (file_exists($log)){
|
470 |
+
unlink($log);
|
471 |
}
|
472 |
+
$fh = fopen($log, 'w') or die( "Can't write to log file" );
|
473 |
+
return $fh;
|
474 |
+
}
|
475 |
+
|
476 |
+
//write Response Log
|
477 |
+
function write_response_file($object) {
|
478 |
+
global $logger;
|
479 |
+
$json_response = json_encode($object);
|
480 |
+
$logger->log('Write response file:' . $json_response);
|
481 |
+
|
482 |
+
$fh=get_response_file();
|
483 |
+
fwrite($fh, $json_response);
|
484 |
+
fclose($fh);
|
485 |
+
}
|
486 |
+
|
487 |
+
//Get Response Log
|
488 |
+
function get_response_file() {
|
489 |
+
global $logger;
|
490 |
+
$response_file_path = WPBACKITUP__PLUGIN_PATH .'/logs/response.log';
|
491 |
+
$filesytem = new WPBackItUp_FileSystem($logger);
|
492 |
+
return $filesytem->get_file_handle($response_file_path,true);
|
493 |
}
|
494 |
+
|
495 |
+
|
496 |
+
|
lib/includes/class-backup.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
/**
|
3 |
+
* WP Backitup Backup Class
|
4 |
+
*
|
5 |
+
* @package WP Backitup
|
6 |
+
*
|
7 |
+
* @author cssimmon
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
class WPBackItUp_Backup {
|
11 |
+
|
12 |
+
private $logger;
|
13 |
+
|
14 |
+
//Public Properties
|
15 |
+
public $backup_name;
|
16 |
+
public $backup_filename;
|
17 |
+
public $backup_project_path;
|
18 |
+
public $backup_folder_root;
|
19 |
+
public $restore_folder_root;
|
20 |
+
public $backup_retained_number;
|
21 |
+
|
22 |
+
function __construct($logger,$backup_name) {
|
23 |
+
global $WPBackitup;
|
24 |
+
try {
|
25 |
+
$this->logger = $logger;
|
26 |
+
$this->backup_name=$backup_name;
|
27 |
+
$this->backup_filename=$backup_name . '.zip';
|
28 |
+
|
29 |
+
$backup_project_path = WPBACKITUP__BACKUP_PATH .'/'. $backup_name .'/';
|
30 |
+
//echo('</br>Backup Proj Path:' .$backup_project_path);
|
31 |
+
|
32 |
+
$backup_folder_root =WPBACKITUP__BACKUP_PATH .'/';
|
33 |
+
$restore_folder_root = WPBACKITUP__RESTORE_FOLDER;
|
34 |
+
|
35 |
+
$this->backup_project_path=$backup_project_path;
|
36 |
+
$this->backup_folder_root=$backup_folder_root;
|
37 |
+
$this->restore_folder_root=$restore_folder_root;
|
38 |
+
|
39 |
+
$this->backup_retained_number = $WPBackitup->backup_retained_number();
|
40 |
+
|
41 |
+
} catch(Exception $e) {
|
42 |
+
//Dont do anything
|
43 |
+
print $e;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
function __destruct() {
|
48 |
+
|
49 |
+
}
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
}
|
lib/includes/class-filesystem.php
ADDED
@@ -0,0 +1,308 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WP Backitup Utility Class
|
5 |
+
*
|
6 |
+
* @package WP Backitup
|
7 |
+
*
|
8 |
+
* @author cssimmon
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
/*** Includes ***/
|
12 |
+
// include backup class
|
13 |
+
if( !class_exists( 'WPBackItUp_RecursiveFilter_Iterator' ) ) {
|
14 |
+
include_once 'class-recursiveFilter_Iterator.php';
|
15 |
+
}
|
16 |
+
|
17 |
+
class WPBackItUp_FileSystem {
|
18 |
+
|
19 |
+
private $logger;
|
20 |
+
|
21 |
+
function __construct($logger) {
|
22 |
+
try {
|
23 |
+
$this->logger = $logger;
|
24 |
+
} catch(Exception $e) {
|
25 |
+
//Dont do anything
|
26 |
+
print $e;
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
function __destruct() {
|
31 |
+
|
32 |
+
}
|
33 |
+
|
34 |
+
public function create_dir($dir) {
|
35 |
+
$this->logger->log('(FileSytem.create_dir) Create Directory: ' .$dir);
|
36 |
+
if( !is_dir($dir) ) {
|
37 |
+
@mkdir($dir, 0755);
|
38 |
+
}
|
39 |
+
$this->logger->log('(FileSytem.create_dir) Directory created: ' .$dir);
|
40 |
+
return true;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function recursive_delete($dir, $ignore = array('') ){
|
44 |
+
$this->logger->log('(FileSystem.recursive_delete) Recursively Delete: ' .$dir);
|
45 |
+
|
46 |
+
$this->logger->log('(FileSystem.recursive_delete) Ignore:');
|
47 |
+
$this->logger->log($ignore);
|
48 |
+
|
49 |
+
if( is_dir($dir) ){
|
50 |
+
//Make sure the folder is not in the ignore array
|
51 |
+
if (!$this->ignore($dir,$ignore)){
|
52 |
+
if($dh = opendir($dir)) {
|
53 |
+
while( ($file = readdir($dh)) !== false ) {
|
54 |
+
if (!$this->ignore($file,$ignore)) { //Check the file is not in the ignore array
|
55 |
+
if(!is_dir($dir .'/'. $file)) {
|
56 |
+
unlink($dir .'/'. $file); //delete the file
|
57 |
+
$this->logger->log('(FileSytem.recursive_delete) File Deleted:' .$dir .'/'. $file);
|
58 |
+
} else {
|
59 |
+
//This is a dir so delete the files first
|
60 |
+
$this->recursive_delete($dir.'/'. $file, $ignore);
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
}
|
65 |
+
//Remove the directory
|
66 |
+
@rmdir($dir);
|
67 |
+
$this->logger->log('(FileSystem.recursive_delete) Folder Deleted:' .$dir);
|
68 |
+
closedir($dh);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
$this->logger->log('(FileSystem.recursive_delete) Recursive Delete Completed.');
|
72 |
+
return true;
|
73 |
+
}
|
74 |
+
|
75 |
+
public function recursive_copy($dir, $target_path, $ignore = array('') ) {
|
76 |
+
$this->logger->log('(FileSystem.recursive_copy) Recursive copy FROM: ' .$dir);
|
77 |
+
$this->logger->log('(FileSystem.recursive_copy) Recursive Copy TO: '.$target_path);
|
78 |
+
$this->logger->log('(FileSystem.recursive_copy) IGNORE:');
|
79 |
+
$this->logger->log($ignore);
|
80 |
+
|
81 |
+
if( is_dir($dir) ) { //If the directory exists
|
82 |
+
if (!$this->ignore($dir,$ignore)){
|
83 |
+
if ($dh = opendir($dir) ) {
|
84 |
+
while(($file = readdir($dh)) !== false) { //While there are files in the directory
|
85 |
+
if ( !$this->ignore($file,$ignore)) { //Check the file is not in the ignore array
|
86 |
+
if (!is_dir( $dir.$file ) ) {
|
87 |
+
try {
|
88 |
+
$fsrc = fopen($dir .$file,'r');
|
89 |
+
$fdest = fopen($target_path .$file,'w+');
|
90 |
+
stream_copy_to_stream($fsrc,$fdest);
|
91 |
+
fclose($fsrc);
|
92 |
+
fclose($fdest);
|
93 |
+
} catch(Exception $e) {
|
94 |
+
$this->logger->log('(FileSystem.recursive_copy) Exception: ' .$e);
|
95 |
+
return false;
|
96 |
+
}
|
97 |
+
} else { //If $file is a directory
|
98 |
+
$destdir = $target_path .$file; //Modify the destination dir
|
99 |
+
if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
|
100 |
+
$this->logger->log('(FileSytem.recursive_copy) Create Folder: ' .$destdir);
|
101 |
+
@mkdir($destdir, 0755);
|
102 |
+
}
|
103 |
+
$this->recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
closedir($dh);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
$this->logger->log('(FileSystem.recursive_copy) Completed');
|
113 |
+
return true;
|
114 |
+
}
|
115 |
+
|
116 |
+
public function recursive_validate($source_path, $target_path, $ignore = array('') ) {
|
117 |
+
$this->logger->log('(FileSystem.recursive_validate) Recursive validate FROM: ' .$source_path);
|
118 |
+
$this->logger->log('(FileSystem.recursive_validate) Recursive validate TO: '.$target_path);
|
119 |
+
$this->logger->log('(FileSystem.recursive_validate) IGNORE:');
|
120 |
+
$this->logger->log($ignore);
|
121 |
+
|
122 |
+
$rtnVal=true;
|
123 |
+
if( is_dir($source_path) ) { //If the directory exists
|
124 |
+
if (!$this->ignore($source_path,$ignore)){
|
125 |
+
if ($dh = opendir($source_path) ) {
|
126 |
+
while(($file = readdir($dh)) !== false) { //While there are files in the directory
|
127 |
+
if ( !$this->ignore($file,$ignore)) { //Check the file is not in the ignore array
|
128 |
+
if (!is_dir( $source_path.$file ) ) {
|
129 |
+
try {
|
130 |
+
$source_file = $source_path .$file;
|
131 |
+
$target_file = $target_path .$file;
|
132 |
+
|
133 |
+
if (!file_exists($target_file)) {
|
134 |
+
$this->logger->log('(FileSystem.recursive_validate) Files DIFF - Target file doesnt exist:' . $target_file);
|
135 |
+
$rtnVal=false;
|
136 |
+
continue;
|
137 |
+
}
|
138 |
+
|
139 |
+
$source_file_size = filesize ($source_file);
|
140 |
+
$target_file_size = filesize ($target_file);
|
141 |
+
|
142 |
+
if ($source_file_size != $target_file_size){
|
143 |
+
$this->logger->log('(FileSystem.recursive_validate) Files DIFF Source:' . $source_file);
|
144 |
+
$this->logger->log('(FileSystem.recursive_validate) Files DIFF Target:' . $target_file);
|
145 |
+
$this->logger->log('(FileSystem.recursive_validate) Files DIFF Size:' . $source_file_size .':' . $target_file_size);
|
146 |
+
$rtnVal=false;
|
147 |
+
continue;
|
148 |
+
}
|
149 |
+
|
150 |
+
} catch(Exception $e) {
|
151 |
+
$this->logger->log('(FileSystem.recursive_validate) Exception: ' .$e);
|
152 |
+
return false;
|
153 |
+
}
|
154 |
+
} else { //If $file is a directory
|
155 |
+
$destdir = $target_path .$file; //Modify the destination dir
|
156 |
+
if(!is_dir($destdir)) {
|
157 |
+
$this->logger->log('(FileSytem.recursive_validate) DIFF Folder doesnt exist: ' .$destdir);
|
158 |
+
$rtnVal= false;
|
159 |
+
}else{
|
160 |
+
$dir_rtnVal=$this->recursive_validate($source_path .$file .'/', $target_path .$file .'/', $ignore);
|
161 |
+
//Don't want to set to true as its the default on all calls
|
162 |
+
if (!$dir_rtnVal) $rtnVal = false;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
closedir($dh);
|
168 |
+
}
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
$this->logger->log('(FileSystem.recursive_validate) Completed:' . ($rtnVal ? 'true' : 'false'));
|
173 |
+
return $rtnVal;
|
174 |
+
}
|
175 |
+
|
176 |
+
private function ignore($file, $ignoreList){
|
177 |
+
$ignore = false;
|
178 |
+
|
179 |
+
//Exclude these files and folders from the delete
|
180 |
+
if (in_array(basename($file), $ignoreList) ||
|
181 |
+
substr($file, 0, 1) == '.' ||
|
182 |
+
($file == "." ) ||
|
183 |
+
($file == ".." ) ||
|
184 |
+
($file == "._" ) ||
|
185 |
+
($file == "cgi-bin" )) {
|
186 |
+
$ignore = true;
|
187 |
+
|
188 |
+
$this->logger->log('(FileSystem.recursive_delete) IGNORE:'.$file);
|
189 |
+
}
|
190 |
+
|
191 |
+
return $ignore;
|
192 |
+
}
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
// function delete_children_recursive($path, $ignore = array('cgi-bin','._'))
|
197 |
+
// { //The filters are not working on this method
|
198 |
+
// return false;
|
199 |
+
// if (is_dir($path))
|
200 |
+
// {
|
201 |
+
// $this->logger->log('(FileSystem_delete_children_recursive) Ignore:');
|
202 |
+
// $this->logger->log($ignore);
|
203 |
+
//
|
204 |
+
// $iterator = new RecursiveDirectoryIterator($path);
|
205 |
+
// $iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
|
206 |
+
// $filter = new WPBackItUp_RecursiveFilter_Iterator($iterator);
|
207 |
+
// $filter->set_filter($ignore);
|
208 |
+
//
|
209 |
+
// $all_files = new RecursiveIteratorIterator($filter,RecursiveIteratorIterator::CHILD_FIRST);
|
210 |
+
//
|
211 |
+
// foreach ($all_files as $file)
|
212 |
+
// {
|
213 |
+
// if ($file->isDir())
|
214 |
+
// {
|
215 |
+
// $this->logger->log('(delete_recursive_new) delete folder:'.$file);
|
216 |
+
// rmdir($file->getPathname());
|
217 |
+
// }
|
218 |
+
// else
|
219 |
+
// {
|
220 |
+
// $this->logger->log('(delete_recursive_new) delete file:'.$file);
|
221 |
+
// unlink($file->getPathname());
|
222 |
+
//
|
223 |
+
// }
|
224 |
+
//
|
225 |
+
// $this->logger->log('(FileSystem_delete_children_recursive) Deleted:' . $file);
|
226 |
+
// }
|
227 |
+
// }
|
228 |
+
// return true;
|
229 |
+
// }
|
230 |
+
|
231 |
+
|
232 |
+
public function purge_FilesByDate($number_Files_Allowed,$path)
|
233 |
+
{
|
234 |
+
$this->logger->log('(FileSytem.purge_FilesByDate) Purge files by date:' .$number_Files_Allowed .':'.$path);
|
235 |
+
|
236 |
+
if (is_numeric($number_Files_Allowed) && $number_Files_Allowed> 0){
|
237 |
+
$FileList = glob($path . "*.zip");
|
238 |
+
|
239 |
+
//Sort by Date Time
|
240 |
+
usort($FileList, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
|
241 |
+
|
242 |
+
$i = 1;
|
243 |
+
foreach ($FileList as $key => $val)
|
244 |
+
{
|
245 |
+
if($i <= $number_Files_Allowed)
|
246 |
+
{
|
247 |
+
$i++;
|
248 |
+
continue;
|
249 |
+
}
|
250 |
+
else{
|
251 |
+
$log_file_path = str_replace('.zip','.log',$val);
|
252 |
+
unlink($val);
|
253 |
+
unlink($log_file_path);
|
254 |
+
$this->logger->log('(FileSytem.purge_FilesByDate) Delete File:)' .$val);
|
255 |
+
|
256 |
+
}
|
257 |
+
}
|
258 |
+
}
|
259 |
+
$this->logger->log('(FileSytem.purge_FilesByDate) Completed.)');
|
260 |
+
}
|
261 |
+
|
262 |
+
public function purge_files($path, $file_extension, $days)
|
263 |
+
{
|
264 |
+
$this->logger->log('(FileSytem.purge_files) Purge files days:' . $days);
|
265 |
+
$this->logger->log('(FileSytem.purge_files) Purge files path:' . $path);
|
266 |
+
$this->logger->log('(FileSytem.purge_files) Purge files extension:' . $file_extension);
|
267 |
+
|
268 |
+
//Check Parms
|
269 |
+
if (empty($path) || empty($file_extension) || !is_numeric($days)){
|
270 |
+
$this->logger->log('(FileSytem.purge_files) Invalid Parm values');
|
271 |
+
return false;
|
272 |
+
}
|
273 |
+
|
274 |
+
$FileList = glob($path . '*.' . $file_extension);
|
275 |
+
//Sort by Date Time
|
276 |
+
usort($FileList, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
|
277 |
+
|
278 |
+
foreach ($FileList as $key => $file)
|
279 |
+
{
|
280 |
+
$current_date = new DateTime('now');
|
281 |
+
$file_mod_date = new DateTime(date('Y-m-d',filemtime($file)));
|
282 |
+
$date_diff = $current_date->diff($file_mod_date);
|
283 |
+
|
284 |
+
if($date_diff->days>=$days){
|
285 |
+
unlink($file);
|
286 |
+
$this->logger->log('Delete:' . $file);
|
287 |
+
}
|
288 |
+
else{
|
289 |
+
break; //Exit for
|
290 |
+
}
|
291 |
+
}
|
292 |
+
$this->logger->log('(FileSytem.purge_files) Completed.');
|
293 |
+
return true;
|
294 |
+
}
|
295 |
+
|
296 |
+
function get_file_handle($path,$newFile) {
|
297 |
+
$this->logger->log('(FileSytem.get_file_handle) Path:' . $path);
|
298 |
+
|
299 |
+
if ($newFile && file_exists($path)){
|
300 |
+
unlink($path);
|
301 |
+
$this->logger->log('(FileSytem.get_file_handle) Deleted:' . $path);
|
302 |
+
}
|
303 |
+
|
304 |
+
return fopen($path, 'w');
|
305 |
+
}
|
306 |
+
|
307 |
+
|
308 |
+
}
|
lib/includes/class-logger.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed (logger)');
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WP Backitup Logging Class
|
5 |
+
*
|
6 |
+
* @package WP Backitup
|
7 |
+
*
|
8 |
+
* @author cssimmon
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
class WPBackItUp_Logger {
|
13 |
+
|
14 |
+
private $dfh;
|
15 |
+
private $logging;
|
16 |
+
|
17 |
+
public $logFileName;
|
18 |
+
public $logFilePath;
|
19 |
+
|
20 |
+
public function __construct($delete_log, $path=null, $file_name=null) {
|
21 |
+
global $WPBackitup;
|
22 |
+
|
23 |
+
$this->logging = $WPBackitup->logging();
|
24 |
+
|
25 |
+
//check for optional parms
|
26 |
+
if (!is_string($path)){
|
27 |
+
$path = WPBACKITUP__PLUGIN_PATH .'/logs';
|
28 |
+
}
|
29 |
+
|
30 |
+
if (!is_string($file_name)){
|
31 |
+
$file_name='debug';
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
$this->logFileName=$file_name .'.log';
|
36 |
+
$this->logFilePath= $path .'/'. $this->logFileName;
|
37 |
+
|
38 |
+
try {
|
39 |
+
//If debug then open the file handle
|
40 |
+
if (true===$this->logging){
|
41 |
+
|
42 |
+
//Delete log first
|
43 |
+
if ($delete_log && file_exists($this->logFilePath)) {
|
44 |
+
unlink($this->logFilePath);
|
45 |
+
}
|
46 |
+
|
47 |
+
$this->dfh = fopen($this->logFilePath, 'a');
|
48 |
+
fwrite($this->dfh, "** Open LOG File ** ". PHP_EOL);
|
49 |
+
}
|
50 |
+
} catch(Exception $e) {
|
51 |
+
//Dont do anything
|
52 |
+
print $e;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
|
56 |
+
function __destruct() {
|
57 |
+
try {
|
58 |
+
//fwrite($this->dfh,"***file closed***" .PHP_EOL);
|
59 |
+
if (!is_null($this->dfh) && is_resource($this->dfh)){
|
60 |
+
fwrite($this->dfh, "** Close LOG File ** ". PHP_EOL);
|
61 |
+
fclose($this->dfh);
|
62 |
+
}
|
63 |
+
} catch(Exception $e) {
|
64 |
+
//Dont do anything
|
65 |
+
print $e;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
function log($message) {
|
71 |
+
try{
|
72 |
+
if (true===$this->logging){
|
73 |
+
if (!is_null($this->dfh) && is_resource($this->dfh)){
|
74 |
+
$date = date_i18n('Y-m-d Hi:i:s',current_time( 'timestamp' ));
|
75 |
+
if( is_array( $message ) || is_object( $message ) ){
|
76 |
+
fwrite($this->dfh, $date ." " .print_r( $message, true ) . PHP_EOL);
|
77 |
+
} else {
|
78 |
+
fwrite($this->dfh, $date ." " .$message . PHP_EOL);
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
} catch(Exception $e) {
|
83 |
+
//Dont do anything
|
84 |
+
print $e;
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
function logConstants() {
|
89 |
+
global $WPBackitup;
|
90 |
+
try{
|
91 |
+
if (true===$this->logging){
|
92 |
+
$this->log("**SYSTEM CONSTANTS**");
|
93 |
+
|
94 |
+
$this->log("Wordpress Version:" . get_bloginfo( 'version'));
|
95 |
+
$this->log("PHP Version:" . phpversion());
|
96 |
+
$this->log("Operating System:" . php_uname());
|
97 |
+
$this->log("Safe Mode:" . (ini_get('safe_mode') ? 'true' : 'false'));
|
98 |
+
$this->log("Script Max Execution Time:" . ini_get('max_execution_time'));
|
99 |
+
$this->log("WPBackItUp License Active: " . ($WPBackitup->license_active() ? 'true' : 'false'));
|
100 |
+
|
101 |
+
$this->log("**WPBACKITUP CONSTANTS**");
|
102 |
+
|
103 |
+
$prefix='WPBACKITUP';
|
104 |
+
foreach (get_defined_constants() as $key=>$value)
|
105 |
+
{
|
106 |
+
if (substr($key,0,strlen($prefix))==$prefix) {
|
107 |
+
$this->log($key . ':' . $value);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
$this->log("**END CONSTANTS**");
|
111 |
+
}
|
112 |
+
} catch(Exception $e) {
|
113 |
+
//Dont do anything
|
114 |
+
print $e;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
lib/includes/class-recursiveFilter_Iterator.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WP Backitup Recurse Iterator
|
5 |
+
*
|
6 |
+
* @package WP Backitup
|
7 |
+
*
|
8 |
+
* @author cssimmon
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
|
12 |
+
|
13 |
+
class WPBackItUp_RecursiveFilter_Iterator extends RecursiveFilterIterator {
|
14 |
+
|
15 |
+
private $filters=array();
|
16 |
+
private $logger;
|
17 |
+
|
18 |
+
//Set the ignore list
|
19 |
+
function set_filter ($ignore) {
|
20 |
+
$this->filters = $ignore;
|
21 |
+
}
|
22 |
+
|
23 |
+
public function accept() {
|
24 |
+
$logger = new WPBackItUp_Logger(false);
|
25 |
+
$accept = !in_array(
|
26 |
+
$this->current()->getFilename(),
|
27 |
+
$this->filters,
|
28 |
+
true);
|
29 |
+
|
30 |
+
$logger->log('(WPBackItUp_RecursiveFilter_Iterator) accept:' . $this->current()->getFilename() . ":" .$accept);
|
31 |
+
return $accept;
|
32 |
+
}
|
33 |
+
|
34 |
+
}
|
lib/includes/class-restore.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
/**
|
3 |
+
* WP Backitup Backup Class
|
4 |
+
*
|
5 |
+
* @package WP Backitup
|
6 |
+
*
|
7 |
+
* @author cssimmon
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
class WPBackItUp_Restore {
|
11 |
+
|
12 |
+
private $logger;
|
13 |
+
|
14 |
+
//Public Properties
|
15 |
+
public $backup_folder_path;
|
16 |
+
public $restore_folder_path;
|
17 |
+
|
18 |
+
function __construct($logger) {
|
19 |
+
global $WPBackitup;
|
20 |
+
|
21 |
+
try {
|
22 |
+
$this->logger = $logger;
|
23 |
+
|
24 |
+
$this->backup_folder_path = WPBACKITUP__BACKUP_PATH .'/';
|
25 |
+
$this->restore_folder_path = WPBACKITUP__RESTORE_PATH .'/';
|
26 |
+
|
27 |
+
|
28 |
+
} catch(Exception $e) {
|
29 |
+
$this->logger->log($e);
|
30 |
+
print $e;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
function __destruct() {
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
}
|
lib/includes/class-sql.php
ADDED
@@ -0,0 +1,387 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WP Backitup SQL Class
|
5 |
+
*
|
6 |
+
* @package WP Backitup
|
7 |
+
*
|
8 |
+
* @author cssimmon
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
class WPBackItUp_SQL {
|
12 |
+
|
13 |
+
private $logger;
|
14 |
+
private $connection;
|
15 |
+
|
16 |
+
function __construct($logger) {
|
17 |
+
try {
|
18 |
+
$this->logger = $logger;
|
19 |
+
$this->connection = $this->get_sqlconnection();
|
20 |
+
|
21 |
+
} catch(Exception $e) {
|
22 |
+
//Dont do anything
|
23 |
+
print $e;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
function __destruct() {
|
28 |
+
// Close the connection
|
29 |
+
$this->connection->close() ;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function mysqldump_export($sql_file_path) {
|
33 |
+
|
34 |
+
$this->logger->log('(SQL.mysqldump_export) SQL Dump: ' .$sql_file_path);
|
35 |
+
|
36 |
+
$db_name = DB_NAME;
|
37 |
+
$db_user = DB_USER;
|
38 |
+
$db_pass = DB_PASSWORD;
|
39 |
+
$db_host = $this->get_hostonly(DB_HOST);
|
40 |
+
$db_port = $this->get_portonly(DB_HOST);
|
41 |
+
|
42 |
+
//This is to ensure that exec() is enabled on the server
|
43 |
+
if(exec('echo EXEC') == 'EXEC') {
|
44 |
+
try {
|
45 |
+
$process = 'mysqldump';
|
46 |
+
|
47 |
+
$command = $process
|
48 |
+
. ' --host=' . $db_host;
|
49 |
+
|
50 |
+
//Check for port
|
51 |
+
if (false!==$db_port){
|
52 |
+
$command .=' --port=' . $db_port;
|
53 |
+
}
|
54 |
+
|
55 |
+
$command .=
|
56 |
+
' --user=' . $db_user
|
57 |
+
. ' --password=' . $db_pass
|
58 |
+
.=' ' . $db_name
|
59 |
+
. ' > "' . $sql_file_path .'"';
|
60 |
+
|
61 |
+
//$this->logger->log('(SQL.db_SQLDump)Execute command:' . $command);
|
62 |
+
|
63 |
+
exec($command,$output,$rtn_var);
|
64 |
+
$this->logger->log('(SQL.mysqldump_export)Execute output:');
|
65 |
+
$this->logger->log($output);
|
66 |
+
$this->logger->log('Return Value:' .$rtn_var);
|
67 |
+
|
68 |
+
//0 is success
|
69 |
+
if ($rtn_var>0){
|
70 |
+
return false;
|
71 |
+
}
|
72 |
+
|
73 |
+
//Did the export work
|
74 |
+
clearstatcache();
|
75 |
+
if (!file_exists($sql_file_path) || filesize($sql_file_path)<=0) {
|
76 |
+
$this->logger->log('(SQL.mysqldump_export) Failure: Dump was empty or missing.');
|
77 |
+
return false;
|
78 |
+
}
|
79 |
+
} catch(Exception $e) {
|
80 |
+
$this->logger->log('(SQL.mysqldump_export) Exception: ' .$e);
|
81 |
+
return false;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
else
|
85 |
+
{
|
86 |
+
$this->logger->log('(SQL.mysqldump_export) Failure: Exec() disabled.');
|
87 |
+
return false;
|
88 |
+
}
|
89 |
+
|
90 |
+
$this->logger->log('(SQL.mysqldump_export) SQL Dump completed.');
|
91 |
+
return true;
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
public function manual_export($sql_file_path) {
|
96 |
+
$this->logger->log('(SQL.manual_export)Manually Create SQL Backup File:'.$sql_file_path);
|
97 |
+
|
98 |
+
$mysqli = $this->connection;
|
99 |
+
$mysqli->set_charset('utf8');
|
100 |
+
|
101 |
+
if (false===$mysqli) {
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
|
105 |
+
// Script Header Information
|
106 |
+
$return = '';
|
107 |
+
$return .= "-- ------------------------------------------------------\n";
|
108 |
+
$return .= "-- ------------------------------------------------------\n";
|
109 |
+
$return .= "--\n";
|
110 |
+
$return .= "-- WP BackItUp Manual Database Backup \n";
|
111 |
+
$return .= "--\n";
|
112 |
+
$return .= '-- Created: ' . date("Y/m/d") . ' on ' . date("h:i") . "\n";
|
113 |
+
$return .= "--\n";
|
114 |
+
$return .= "-- Database : " . DB_NAME . "\n";
|
115 |
+
$return .= "--\n";
|
116 |
+
$return .= "-- ------------------------------------------------------\n";
|
117 |
+
$return .= "-- ------------------------------------------------------\n";
|
118 |
+
$return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ;
|
119 |
+
$return .= 'SET FOREIGN_KEY_CHECKS=0 ;' ."\n" ;
|
120 |
+
$return .= "\n";
|
121 |
+
$return .= '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' ."\n" ;
|
122 |
+
$return .= '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' ."\n" ;
|
123 |
+
$return .= '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;' ."\n" ;
|
124 |
+
$return .= '/*!40101 SET NAMES utf8 */;' ."\n" ;
|
125 |
+
|
126 |
+
$tables = array() ;
|
127 |
+
|
128 |
+
// Exploring what tables this database has
|
129 |
+
$result = $mysqli->query('SHOW TABLES' ) ;
|
130 |
+
|
131 |
+
// Cycle through "$result" and put content into an array
|
132 |
+
while ($row = $result->fetch_row()) {
|
133 |
+
$tables[] = $row[0] ;
|
134 |
+
}
|
135 |
+
|
136 |
+
// Cycle through each table
|
137 |
+
foreach($tables as $table) {
|
138 |
+
// Get content of each table
|
139 |
+
$result = $mysqli->query('SELECT * FROM '. $table) ;
|
140 |
+
|
141 |
+
// Get number of fields (columns) of each table
|
142 |
+
$num_fields = $mysqli->field_count ;
|
143 |
+
|
144 |
+
// Add table information
|
145 |
+
$return .= "--\n" ;
|
146 |
+
$return .= '-- Table structure for table `' . $table . '`' . "\n" ;
|
147 |
+
$return .= "--\n" ;
|
148 |
+
$return.= 'DROP TABLE IF EXISTS `'.$table.'`;' . "\n" ;
|
149 |
+
|
150 |
+
// Get the table-shema
|
151 |
+
$shema = $mysqli->query('SHOW CREATE TABLE '.$table) ;
|
152 |
+
|
153 |
+
// Extract table shema
|
154 |
+
$tableshema = $shema->fetch_row() ;
|
155 |
+
|
156 |
+
// Append table-shema into code
|
157 |
+
$return.= $tableshema[1].";" . "\n\n" ;
|
158 |
+
|
159 |
+
// Cycle through each table-row
|
160 |
+
while($rowdata = $result->fetch_row()) {
|
161 |
+
|
162 |
+
$return.= 'INSERT INTO '.$table.' VALUES(';
|
163 |
+
for($j=0; $j<$num_fields; $j++){
|
164 |
+
$rowdata[$j] = addslashes($rowdata[$j]);
|
165 |
+
$rowdata[$j] = str_replace("\n","\\n",$rowdata[$j]);
|
166 |
+
|
167 |
+
if (isset($rowdata[$j])) {
|
168 |
+
$return.= '"'.$rowdata[$j].'"' ;
|
169 |
+
} else {
|
170 |
+
if (is_null($rowdata[$j])) {
|
171 |
+
$return.= 'NULL';//Dont think this is working but not causing issues
|
172 |
+
} else {
|
173 |
+
$return.= '""';
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
if ($j<($num_fields-1)) { $return.= ','; }
|
178 |
+
}
|
179 |
+
$return.= ");\n";
|
180 |
+
}
|
181 |
+
$return .= "\n\n" ;
|
182 |
+
}
|
183 |
+
|
184 |
+
$return .= 'SET FOREIGN_KEY_CHECKS = 1 ; ' . "\n" ;
|
185 |
+
$return .= 'COMMIT ; ' . "\n" ;
|
186 |
+
$return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
|
187 |
+
|
188 |
+
//save file
|
189 |
+
$handle = fopen($sql_file_path,'w+');
|
190 |
+
fwrite($handle,$return);
|
191 |
+
fclose($handle);
|
192 |
+
clearstatcache();
|
193 |
+
|
194 |
+
//Did the export work
|
195 |
+
if (!file_exists($sql_file_path) || filesize($sql_file_path)<=0) {
|
196 |
+
$this->logger->log('(SQL.manual_export) Failure: SQL Export file was empty or didnt exist.');
|
197 |
+
return false;
|
198 |
+
}
|
199 |
+
|
200 |
+
$this->logger->log('(SQL.manual_export)SQL Backup File Created:'.$sql_file_path);
|
201 |
+
return true;
|
202 |
+
}
|
203 |
+
|
204 |
+
public function run_sql_exec($sql_file) {
|
205 |
+
$this->logger->log('(SQL.run_sql_exec)SQL Execute:' .$sql_file);
|
206 |
+
|
207 |
+
//Is the backup sql file empty
|
208 |
+
if (!file_exists($sql_file) || filesize($sql_file)<=0) {
|
209 |
+
$this->logger->log('(SQL.run_sql_exec) Failure: SQL File was empty:' .$sql_file);
|
210 |
+
return false;
|
211 |
+
}
|
212 |
+
|
213 |
+
//This is to ensure that exec() is enabled on the server
|
214 |
+
if(exec('echo EXEC') != 'EXEC') {
|
215 |
+
$this->logger->log('(SQL.run_sql_exec) Failure: Exec() disabled.');
|
216 |
+
return false;
|
217 |
+
}
|
218 |
+
|
219 |
+
try {
|
220 |
+
|
221 |
+
$db_name = DB_NAME;
|
222 |
+
$db_user = DB_USER;
|
223 |
+
$db_pass = DB_PASSWORD;
|
224 |
+
$db_host = $this->get_hostonly(DB_HOST);
|
225 |
+
$db_port = $this->get_portonly(DB_HOST);
|
226 |
+
|
227 |
+
$process = 'mysql';
|
228 |
+
$command = $process
|
229 |
+
. ' --host=' . $db_host
|
230 |
+
. ' --user=' . $db_user
|
231 |
+
. ' --password=' . $db_pass
|
232 |
+
. ' --database=' . $db_name
|
233 |
+
. ' --execute="SOURCE ' . $sql_file .'"';
|
234 |
+
|
235 |
+
//$this->logger->log('(SQL.db_run_sql)Execute command:' . $command);
|
236 |
+
|
237 |
+
//$output = shell_exec($command);
|
238 |
+
exec($command,$output,$rtn_var);
|
239 |
+
$this->logger->log('(SQL.run_sql_exec)Execute output:');
|
240 |
+
$this->logger->log($output);
|
241 |
+
$this->logger->log('Return Value:' .$rtn_var);
|
242 |
+
|
243 |
+
//0 is success
|
244 |
+
if ($rtn_var!=0){
|
245 |
+
return false;
|
246 |
+
}
|
247 |
+
|
248 |
+
}catch(Exception $e) {
|
249 |
+
$this->logger->log('(SQL.run_sql_exec) Exception: ' .$e);
|
250 |
+
return false;
|
251 |
+
}
|
252 |
+
|
253 |
+
//Success
|
254 |
+
$this->logger->log('(SQL.run_sql_exec)SQL Executed successfully:' .$sql_file);
|
255 |
+
return true;
|
256 |
+
}
|
257 |
+
|
258 |
+
public function run_sql_manual($sql_file) {
|
259 |
+
$this->logger->log('(SQL.run_sql_manual)SQL Execute:' .$sql_file);
|
260 |
+
|
261 |
+
//Is the backup sql file empty
|
262 |
+
if (!file_exists($sql_file) || filesize($sql_file)<=0) {
|
263 |
+
$this->logger->log('(SQL.run_sql_manual) Failure: SQL File was empty:' .$sql_file);
|
264 |
+
return false;
|
265 |
+
}
|
266 |
+
|
267 |
+
$query = file_get_contents($sql_file);
|
268 |
+
if (empty($query)) return false;
|
269 |
+
|
270 |
+
try {
|
271 |
+
|
272 |
+
$mysqli = $this->get_sqlconnection();
|
273 |
+
$mysqli->set_charset('utf8');
|
274 |
+
|
275 |
+
if (false===$mysqli) {
|
276 |
+
return false;
|
277 |
+
}
|
278 |
+
|
279 |
+
if($mysqli->multi_query($query))
|
280 |
+
{
|
281 |
+
do {
|
282 |
+
/* store first result set */
|
283 |
+
if($resultSet = $mysqli->store_result())
|
284 |
+
{
|
285 |
+
while($row = $resultSet->fetch_row())
|
286 |
+
{
|
287 |
+
|
288 |
+
}
|
289 |
+
$resultSet->free();
|
290 |
+
}
|
291 |
+
|
292 |
+
if (!$mysqli->more_results()) break; //All done
|
293 |
+
|
294 |
+
} while ($mysqli->next_result());
|
295 |
+
|
296 |
+
$mysqli->close();
|
297 |
+
}
|
298 |
+
|
299 |
+
}catch(Exception $e) {
|
300 |
+
$this->logger->log('(SQL.run_sql_manual) Exception: ' .$e);
|
301 |
+
return false;
|
302 |
+
}
|
303 |
+
|
304 |
+
//Success
|
305 |
+
$this->logger->log('(SQL.run_sql_manual)SQL Executed successfully:' .$sql_file);
|
306 |
+
return true;
|
307 |
+
}
|
308 |
+
|
309 |
+
private function get_sqlconnection() {
|
310 |
+
$this->logger->log('(SQL.get_sqlconnection)Get SQL connection to database.');
|
311 |
+
$db_name = DB_NAME;
|
312 |
+
$db_user = DB_USER;
|
313 |
+
$db_pass = DB_PASSWORD;
|
314 |
+
$db_host = $this->get_hostonly(DB_HOST);
|
315 |
+
$db_port = $this->get_portonly(DB_HOST);
|
316 |
+
|
317 |
+
$this->logger->log('(SQL.get_sqlconnection)Host:' . $db_host);
|
318 |
+
$this->logger->log('(SQL.get_sqlconnection)Port:' . $db_port);
|
319 |
+
|
320 |
+
if (false===$db_port){
|
321 |
+
$mysqli = new mysqli($db_host , $db_user , $db_pass , $db_name);
|
322 |
+
}
|
323 |
+
else {
|
324 |
+
$mysqli = new mysqli($db_host , $db_user , $db_pass , $db_name,$db_port);
|
325 |
+
}
|
326 |
+
|
327 |
+
if ($mysqli->connect_errno) {
|
328 |
+
$this->logger->log('(SQL.get_sqlconnection)Cannot connect to database.' . $mysqli->connect_error);
|
329 |
+
return false;
|
330 |
+
}
|
331 |
+
return $mysqli;
|
332 |
+
}
|
333 |
+
|
334 |
+
private function get_hostonly($db_host) {
|
335 |
+
//Check for port
|
336 |
+
$host_array = explode(':',$db_host);
|
337 |
+
if (is_array($host_array)){
|
338 |
+
return $host_array[0];
|
339 |
+
}
|
340 |
+
return $db_host;
|
341 |
+
}
|
342 |
+
|
343 |
+
private function get_portonly($db_host) {
|
344 |
+
//Check for port
|
345 |
+
$host_array = explode(':',$db_host);
|
346 |
+
if (is_array($host_array) && count($host_array)>1){
|
347 |
+
return $host_array[1];
|
348 |
+
}
|
349 |
+
|
350 |
+
return false;
|
351 |
+
}
|
352 |
+
|
353 |
+
//Get SQL scalar value
|
354 |
+
public function get_sql_scalar($sql){
|
355 |
+
global $logger;
|
356 |
+
$value='';
|
357 |
+
if ($result = mysqli_query($this->connection, $sql)) {
|
358 |
+
while ($row = mysqli_fetch_row($result)) {
|
359 |
+
$value = $row[0];
|
360 |
+
}
|
361 |
+
mysqli_free_result($result);
|
362 |
+
}
|
363 |
+
return $value;
|
364 |
+
}
|
365 |
+
|
366 |
+
//Run SQL command
|
367 |
+
public function run_sql_command($sql){
|
368 |
+
global $logger;
|
369 |
+
if(!mysqli_query($this->connection, $sql) ) {
|
370 |
+
$logger->log('Error:SQL Command Failed:' .$sql);
|
371 |
+
return false;
|
372 |
+
}
|
373 |
+
return true;
|
374 |
+
}
|
375 |
+
|
376 |
+
//This function is untested
|
377 |
+
// function get_database_size($dbname) {
|
378 |
+
// mysqli_select_db($dbname);
|
379 |
+
// $result = mysqli_query("SHOW TABLE STATUS");
|
380 |
+
// $dbsize = 0;
|
381 |
+
// while($row = mysqli_fetch_array($result)) {
|
382 |
+
// $dbsize += $row["Data_length"] + $row["Index_length"];
|
383 |
+
// }
|
384 |
+
// return $dbsize;
|
385 |
+
// }
|
386 |
+
|
387 |
+
}
|
lib/includes/class-utility.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
/**
|
3 |
+
* WP Backitup Utility Class
|
4 |
+
*
|
5 |
+
* @package WP Backitup
|
6 |
+
*
|
7 |
+
* @author cssimmon
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
class WPBackItUp_Utility {
|
11 |
+
|
12 |
+
private $logger;
|
13 |
+
|
14 |
+
function __construct($logger) {
|
15 |
+
try {
|
16 |
+
$this->logger = $logger;
|
17 |
+
} catch(Exception $e) {
|
18 |
+
//Dont do anything
|
19 |
+
print $e;
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
function __destruct() {
|
24 |
+
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
function send_email($to,$subject,$message)
|
29 |
+
{
|
30 |
+
try {
|
31 |
+
//global $WPBackitup;
|
32 |
+
if($to) {
|
33 |
+
$from_email = get_bloginfo('admin_email');
|
34 |
+
$headers[] = 'Content-type: text/html';
|
35 |
+
$headers[] = 'From: WP BackItUp '. '<'. $from_email .'>';
|
36 |
+
|
37 |
+
wp_mail($to, $subject, $message, $headers);
|
38 |
+
$this->logger->log('(send_email)EMail Sent from:' .$from_email);
|
39 |
+
$this->logger->log('(send_email)EMail Sent to:' .$to);
|
40 |
+
}
|
41 |
+
|
42 |
+
} catch(Exception $e) {
|
43 |
+
//Dont do anything
|
44 |
+
$this->logger->log('(send_email)Send Email Exception:'.$e);
|
45 |
+
}
|
46 |
+
|
47 |
+
}
|
48 |
+
|
49 |
+
}
|
50 |
+
|
lib/includes/class-wpbackitup-admin.php
ADDED
@@ -0,0 +1,960 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
/**
|
3 |
+
* WP Backitup Admin Class
|
4 |
+
*
|
5 |
+
* @package WP Backitup
|
6 |
+
*
|
7 |
+
* @author cssimmon
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
|
11 |
+
|
12 |
+
class WPBackitup_Admin {
|
13 |
+
|
14 |
+
public $namespace = WPBACKITUP__NAMESPACE;
|
15 |
+
public $friendly_name = WPBACKITUP__FRIENDLY_NAME;
|
16 |
+
public $version = WPBACKITUP__VERSION;
|
17 |
+
|
18 |
+
private static $instance = false;
|
19 |
+
|
20 |
+
//Use Getters
|
21 |
+
private $license_key;//Loaded in getter
|
22 |
+
private $license_type; //Loaded in getter
|
23 |
+
private $license_expires;
|
24 |
+
|
25 |
+
private $license_active;//Loaded in getter
|
26 |
+
private $license_status;//Loaded in getter
|
27 |
+
private $license_status_message;//Loaded in getter
|
28 |
+
private $license_type_description; //Getter will load
|
29 |
+
|
30 |
+
private $backup_retained_number; //Getter will load
|
31 |
+
private $notification_email;//Getter will load
|
32 |
+
private $logging;//Getter will load
|
33 |
+
|
34 |
+
private $backup_count; //getter will load
|
35 |
+
private $successful_backup_count;
|
36 |
+
|
37 |
+
// Default plugin options
|
38 |
+
public $defaults = array(
|
39 |
+
'logging' => false,
|
40 |
+
'license_key' => "lite",
|
41 |
+
'license_last_check_date'=> "1970-01-01 00:00:00",
|
42 |
+
'license_status' => "",
|
43 |
+
'license_status_message'=> "",
|
44 |
+
'license_type' => "0",
|
45 |
+
'license_expires'=> "1970-01-01 00:00:00",
|
46 |
+
'license_limit'=> "1",
|
47 |
+
'license_sitecount'=> "",
|
48 |
+
'notification_email' => "",
|
49 |
+
'backup_retained_number' => "3",
|
50 |
+
'lite_backup_retained_number' => "1",
|
51 |
+
'backup_count'=>0,
|
52 |
+
'successful_backup_count'=>0,
|
53 |
+
'stats_last_check_date'=> "1970-01-01 00:00:00",
|
54 |
+
);
|
55 |
+
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Retrieve the current WP backItUp instance.
|
59 |
+
*/
|
60 |
+
public static function get_instance() {
|
61 |
+
if ( ! self::$instance ) {
|
62 |
+
// echo('new instance');
|
63 |
+
self::$instance = new self();
|
64 |
+
}
|
65 |
+
|
66 |
+
return self::$instance;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Instantiation construction
|
71 |
+
*
|
72 |
+
*/
|
73 |
+
private function __construct() {
|
74 |
+
/**
|
75 |
+
* Make this plugin available for translation.
|
76 |
+
* Translations can be added to the /languages/ directory.
|
77 |
+
*/
|
78 |
+
|
79 |
+
//TODO: Add multi Language Support back
|
80 |
+
//load_theme_textdomain( $this->namespace, WPBACKITUP__PLUGIN_DIR . '/languages' );
|
81 |
+
|
82 |
+
// Add all action, filter and shortcode hooks
|
83 |
+
$this->_add_hooks();
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Add in various hooks
|
88 |
+
*/
|
89 |
+
private function _add_hooks() {
|
90 |
+
|
91 |
+
// Options page for configuration
|
92 |
+
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
93 |
+
|
94 |
+
// Route requests for form processing
|
95 |
+
add_action( 'admin_init', array( &$this, 'route' ) );
|
96 |
+
|
97 |
+
// Add a settings link next to the "Deactivate" link on the plugin listing page
|
98 |
+
add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
|
99 |
+
|
100 |
+
//Load all the resources
|
101 |
+
add_action( 'admin_enqueue_scripts', array( &$this, 'load_resources' ) );
|
102 |
+
|
103 |
+
//Load the backup action
|
104 |
+
add_action('wp_ajax_backup', array( &$this, 'ajax_backup' ));
|
105 |
+
|
106 |
+
//Load the restore action
|
107 |
+
add_action('wp_ajax_restore', array( &$this, 'ajax_restore' ));
|
108 |
+
|
109 |
+
//Load the upload action
|
110 |
+
add_action('wp_ajax_upload', array( &$this, 'ajax_upload' ));
|
111 |
+
|
112 |
+
//Status reader for UI
|
113 |
+
add_action('wp_ajax_status_reader', array( &$this,'ajax_status_reader'));
|
114 |
+
|
115 |
+
add_action('wp_ajax_response_reader', array( &$this,'ajax_response_reader'));
|
116 |
+
|
117 |
+
//Delete File Action
|
118 |
+
add_action('wp_ajax_delete_file', array( &$this,'ajax_delete_file'));
|
119 |
+
|
120 |
+
//View Log Action
|
121 |
+
add_action('admin_post_viewlog', array( &$this,'admin_viewlog'));
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
/**
|
126 |
+
*
|
127 |
+
* Define the admin menu options for this plugin
|
128 |
+
*
|
129 |
+
*/
|
130 |
+
public function admin_menu() {
|
131 |
+
|
132 |
+
// add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
|
133 |
+
add_menu_page( $this->friendly_name, $this->friendly_name, 'administrator', $this->namespace, array( &$this, 'admin_backup_page' ), WPBACKITUP__PLUGIN_URL .'/images/icon.png', 77);
|
134 |
+
|
135 |
+
//Add Backup Menu Nav
|
136 |
+
add_submenu_page( $this->namespace, 'Backup', 'Backup', 'administrator', $this->namespace.'-backup', array( &$this, 'admin_backup_page' ) );
|
137 |
+
|
138 |
+
//Add Restore Menu Nav IF licensed
|
139 |
+
if ($this->license_type()!=0) {
|
140 |
+
add_submenu_page( $this->namespace, 'Restore', 'Restore', 'administrator', $this->namespace.'-restore', array( &$this, 'admin_restore_page' ) );
|
141 |
+
}
|
142 |
+
|
143 |
+
//Add Settings Menu Nav
|
144 |
+
add_submenu_page( $this->namespace, 'Settings', 'Settings', 'administrator', $this->namespace.'-settings', array( &$this, 'admin_settings_page' ) );
|
145 |
+
|
146 |
+
//add_submenu_page( $this->namespace, 'Test', 'Test', 'administrator', $this->namespace.'-test', array( &$this, 'admin_test_page' ) );
|
147 |
+
|
148 |
+
// remove duplicate submenu page. wp limitations //
|
149 |
+
// http://wordpress.stackexchange.com/questions/16401/remove-duplicate-main-submenu-in-admin
|
150 |
+
remove_submenu_page($this->namespace,$this->namespace);
|
151 |
+
|
152 |
+
// Add print scripts and styles action based off the option page hook
|
153 |
+
add_action( 'admin_print_scripts', array( &$this, 'admin_print_scripts' ) );
|
154 |
+
add_action( 'admin_print_styles', array( &$this, 'admin_print_styles' ) );
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Load JavaScript for the admin options page
|
159 |
+
*
|
160 |
+
* @uses wp_enqueue_script()
|
161 |
+
*/
|
162 |
+
public function admin_print_scripts() {
|
163 |
+
wp_enqueue_script( "{$this->namespace}-admin" );
|
164 |
+
wp_enqueue_script( "{$this->namespace}-admin-viewlog" );
|
165 |
+
|
166 |
+
}
|
167 |
+
|
168 |
+
public function load_resources() {
|
169 |
+
// Admin JavaScript
|
170 |
+
wp_register_script( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "/js/admin.js", array( 'jquery' ), $this->version, true );
|
171 |
+
//wp_register_script( "{$this->namespace}-admin-viewlog", WPBACKITUP__PLUGIN_URL . "/js/admin_test.js", array( 'jquery' ), $this->version, true );
|
172 |
+
|
173 |
+
// Admin Stylesheet
|
174 |
+
wp_register_style( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "/css/admin.css", array(), $this->version, 'screen' );
|
175 |
+
|
176 |
+
wp_register_style( 'google-fonts', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
|
177 |
+
wp_enqueue_style( 'google-fonts' );
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Load Stylesheet for the admin options page
|
182 |
+
*
|
183 |
+
* @uses wp_enqueue_style()
|
184 |
+
*/
|
185 |
+
public function admin_print_styles() {
|
186 |
+
wp_enqueue_style( "{$this->namespace}-admin" );
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* The admin section backup page rendering method
|
191 |
+
*
|
192 |
+
*/
|
193 |
+
public function admin_backup_page()
|
194 |
+
{
|
195 |
+
if( !current_user_can( 'manage_options' ) ) {
|
196 |
+
wp_die( 'You do not have sufficient permissions to access this page' );
|
197 |
+
}
|
198 |
+
|
199 |
+
include WPBACKITUP__PLUGIN_PATH . "/views/backup.php";
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* The admin section restore page rendering method
|
204 |
+
*
|
205 |
+
*/
|
206 |
+
public function admin_restore_page()
|
207 |
+
{
|
208 |
+
if( !current_user_can( 'manage_options' ) ) {
|
209 |
+
wp_die( 'You do not have sufficient permissions to access this page.' );
|
210 |
+
}
|
211 |
+
|
212 |
+
include WPBACKITUP__PLUGIN_PATH . "/views/restore.php";
|
213 |
+
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* The admin section settings page rendering method
|
217 |
+
*
|
218 |
+
*/
|
219 |
+
public function admin_settings_page()
|
220 |
+
{
|
221 |
+
|
222 |
+
if( !current_user_can( 'manage_options' ) ) {
|
223 |
+
wp_die( 'You do not have sufficient permissions to access this page.' );
|
224 |
+
}
|
225 |
+
|
226 |
+
include WPBACKITUP__PLUGIN_PATH . "/views/settings.php";
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* The admin section backup page rendering method
|
231 |
+
*
|
232 |
+
*/
|
233 |
+
// public function admin_test_page()
|
234 |
+
// {
|
235 |
+
// if( !current_user_can( 'manage_options' ) ) {
|
236 |
+
// wp_die( 'You do not have sufficient permissions to access this page' );
|
237 |
+
// }
|
238 |
+
//
|
239 |
+
// include WPBACKITUP__PLUGIN_PATH . "/views/test.php";
|
240 |
+
// }
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Route the user based off of environment conditions
|
244 |
+
*
|
245 |
+
* @uses WPBackitup::_admin_options_update()
|
246 |
+
*/
|
247 |
+
public function route() {
|
248 |
+
$uri = $_SERVER['REQUEST_URI'];
|
249 |
+
$protocol = isset( $_SERVER['HTTPS'] ) ? 'https' : 'http';
|
250 |
+
$hostname = $_SERVER['HTTP_HOST'];
|
251 |
+
$url = "{$protocol}://{$hostname}{$uri}";
|
252 |
+
$is_post = (bool) ( strtoupper( $_SERVER['REQUEST_METHOD'] ) == "POST" );
|
253 |
+
|
254 |
+
// Check if a nonce was passed in the request
|
255 |
+
if( isset( $_REQUEST['_wpnonce'] ) ) {
|
256 |
+
$nonce = $_REQUEST['_wpnonce'];
|
257 |
+
// $logger->log('NONCE:' .$nonce);
|
258 |
+
|
259 |
+
// Handle POST requests
|
260 |
+
if( $is_post ) {
|
261 |
+
|
262 |
+
if( wp_verify_nonce( $nonce, "{$this->namespace}-update-options" ) ) {
|
263 |
+
$this->_admin_options_update();
|
264 |
+
}
|
265 |
+
}
|
266 |
+
// Handle GET requests
|
267 |
+
else {
|
268 |
+
|
269 |
+
}
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
public function initialize(){
|
274 |
+
$this->check_license();
|
275 |
+
}
|
276 |
+
//load backup
|
277 |
+
public function ajax_backup() {
|
278 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/backup.php' );
|
279 |
+
}
|
280 |
+
|
281 |
+
//load restore
|
282 |
+
public function ajax_restore() {
|
283 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/restore.php' );
|
284 |
+
}
|
285 |
+
|
286 |
+
//load upload
|
287 |
+
public function ajax_upload() {
|
288 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/upload.php' );
|
289 |
+
}
|
290 |
+
|
291 |
+
public function ajax_status_reader() {
|
292 |
+
$log = WPBACKITUP__PLUGIN_PATH .'/logs/status.log';
|
293 |
+
if(file_exists($log) ) {
|
294 |
+
readfile($log);
|
295 |
+
}
|
296 |
+
die();
|
297 |
+
}
|
298 |
+
|
299 |
+
public function ajax_response_reader() {
|
300 |
+
$log = WPBACKITUP__PLUGIN_PATH .'/logs/response.log';
|
301 |
+
if(file_exists($log) ) {
|
302 |
+
readfile($log);
|
303 |
+
}else{
|
304 |
+
$rtnData = new stdClass();
|
305 |
+
$rtnData->message = 'No response log found.';
|
306 |
+
echo json_encode($rtnData);
|
307 |
+
}
|
308 |
+
die();
|
309 |
+
}
|
310 |
+
|
311 |
+
public function ajax_delete_file()
|
312 |
+
{
|
313 |
+
$backup_file_name = str_replace('deleteRow', '', $_POST['filed']);
|
314 |
+
$backup_file_path = WPBACKITUP__BACKUP_PATH .'/' . $backup_file_name;
|
315 |
+
$log_file_path = str_replace('.zip','.log',$backup_file_path);
|
316 |
+
|
317 |
+
if (unlink($backup_file_path)) {
|
318 |
+
echo 'deleted';
|
319 |
+
//Delete the log
|
320 |
+
unlink($log_file_path);
|
321 |
+
}
|
322 |
+
else{
|
323 |
+
echo 'error';
|
324 |
+
}
|
325 |
+
|
326 |
+
exit(0);
|
327 |
+
}
|
328 |
+
|
329 |
+
function admin_viewlog(){
|
330 |
+
include_once( WPBACKITUP__PLUGIN_PATH.'/lib/includes/viewlog.php' );
|
331 |
+
}
|
332 |
+
|
333 |
+
|
334 |
+
/**
|
335 |
+
* Process update page form submissions and validate license key
|
336 |
+
*
|
337 |
+
*/
|
338 |
+
public function _admin_options_update() {
|
339 |
+
// Verify submission for processing using wp_nonce
|
340 |
+
if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-update-options" ) ) {
|
341 |
+
|
342 |
+
/**
|
343 |
+
* Loop through each POSTed value and sanitize it to protect against malicious code. Please
|
344 |
+
* note that rich text (or full HTML fields) should not be processed by this function and
|
345 |
+
* dealt with directly.
|
346 |
+
*/
|
347 |
+
|
348 |
+
$logger = new WPBackItUp_Logger(false);
|
349 |
+
$logger->log("Posted Fields");
|
350 |
+
$logger->log($_POST['data']); //License will not be in this array
|
351 |
+
|
352 |
+
foreach( $_POST['data'] as $key => $val ) {
|
353 |
+
$posted_value = $this->_sanitize($val);
|
354 |
+
//If license updated then validate
|
355 |
+
if (!empty($key) && $key=='license_key') {
|
356 |
+
$logger->log('License Posted:' .$posted_value);
|
357 |
+
$this->update_license_options($posted_value);
|
358 |
+
}
|
359 |
+
else {
|
360 |
+
$data[$key] =$posted_value;
|
361 |
+
}
|
362 |
+
}
|
363 |
+
|
364 |
+
$license_description = $this->license_type_description();
|
365 |
+
|
366 |
+
//Could have just been a license update
|
367 |
+
if(!empty($data)) {
|
368 |
+
|
369 |
+
//Set back to original settings if value not changed
|
370 |
+
if(!empty($data['backup_retained_number']) && !is_numeric($data['backup_retained_number']))
|
371 |
+
{
|
372 |
+
$data['backup_retained_number'] = $this->defaults['backup_retained_number'];
|
373 |
+
set_transient('settings-error-number', __('Please enter a number', $this->namespace), 60);
|
374 |
+
}
|
375 |
+
else{ //Empty OR not NUMERIC
|
376 |
+
|
377 |
+
//Empty
|
378 |
+
if ( empty($data['backup_retained_number']) ){
|
379 |
+
set_transient('settings-error-number', __('Please enter a number', $this->namespace), 60);
|
380 |
+
}
|
381 |
+
|
382 |
+
//exceeds lite threshold
|
383 |
+
if ( !empty($data['backup_retained_number']) && ($this->license_type()==0) && ($data['backup_retained_number'] > 1) ){
|
384 |
+
$data['backup_retained_number'] = $this->defaults['lite_backup_retained_number'];
|
385 |
+
set_transient('settings-license-error', __(ucfirst($license_description) .' license holders may only save 1 backup archive.', $this->namespace), 60);
|
386 |
+
}
|
387 |
+
|
388 |
+
//exceeds pro threshold
|
389 |
+
if (!empty($data['backup_retained_number']) && ($this->license_type()==1) && ($data['backup_retained_number'] > 3)){
|
390 |
+
$data['backup_retained_number'] = $this->defaults['backup_retained_number'];
|
391 |
+
set_transient('settings-license-error', __(ucfirst($license_description) .' license holders may only save up to 3 backup archives.', $this->namespace), 60);
|
392 |
+
}
|
393 |
+
|
394 |
+
}
|
395 |
+
|
396 |
+
if(!empty($data['notification_email']) && !is_email($data['notification_email']))
|
397 |
+
{
|
398 |
+
$data['notification_email'] = $this->defaults['notification_email'];
|
399 |
+
set_transient('settings-error-email', __('Please enter a a valid email', $this->namespace), 60);
|
400 |
+
}
|
401 |
+
|
402 |
+
// Update the options value with the data submitted
|
403 |
+
foreach( $data as $key => $val ) {
|
404 |
+
$this->set_option($key, $val);
|
405 |
+
$logger->log('Updated Option: ' .$key .':' .$val);
|
406 |
+
}
|
407 |
+
}
|
408 |
+
|
409 |
+
// Redirect back to the options page with the message flag to show the saved message
|
410 |
+
wp_safe_redirect( $_REQUEST['_wp_http_referer'] . '&update=1' );
|
411 |
+
exit;
|
412 |
+
}
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Hook into plugin_action_links filter
|
417 |
+
*
|
418 |
+
* @param object $links An array of the links to show, this will be the modified variable
|
419 |
+
* @param string $file The name of the file being processed in the filter
|
420 |
+
*
|
421 |
+
*/
|
422 |
+
public function plugin_action_links( $links, $file ) {
|
423 |
+
|
424 |
+
// Add links to plugin
|
425 |
+
if ( $file == plugin_basename( WPBACKITUP__PLUGIN_PATH . '/wp-backitup.php' ) ) {
|
426 |
+
$settings_link = '<a href="' . esc_url( self::get_settings_page_url() ) . '">'.esc_html__( 'Settings' , 'wp-backitup').'</a>';
|
427 |
+
array_unshift($links, $settings_link);
|
428 |
+
}
|
429 |
+
|
430 |
+
return $links;
|
431 |
+
}
|
432 |
+
|
433 |
+
/**
|
434 |
+
*
|
435 |
+
* GETTERS
|
436 |
+
*
|
437 |
+
**/
|
438 |
+
|
439 |
+
/**
|
440 |
+
* Generic Getter
|
441 |
+
*/
|
442 |
+
public function get($property) {
|
443 |
+
|
444 |
+
if (empty($this->$property)) {
|
445 |
+
$this->$property = $this->get_option($property);
|
446 |
+
|
447 |
+
//If not set then use the defaults
|
448 |
+
if (empty($this->$property)) {
|
449 |
+
$this->$property=$this->defaults[$property];
|
450 |
+
}
|
451 |
+
}
|
452 |
+
|
453 |
+
return $this->$property;
|
454 |
+
|
455 |
+
}
|
456 |
+
|
457 |
+
|
458 |
+
/**
|
459 |
+
* Getter - license key
|
460 |
+
*/
|
461 |
+
public function license_key(){
|
462 |
+
return $this->get('license_key');
|
463 |
+
}
|
464 |
+
|
465 |
+
/**
|
466 |
+
* Getter - license status message
|
467 |
+
*/
|
468 |
+
public function license_status_message(){
|
469 |
+
return $this->get('license_status_message');
|
470 |
+
}
|
471 |
+
|
472 |
+
/**
|
473 |
+
* Getter - license expires
|
474 |
+
*/
|
475 |
+
public function license_expires(){
|
476 |
+
return $this->get('license_expires');
|
477 |
+
}
|
478 |
+
|
479 |
+
/**
|
480 |
+
* Getter - notification email
|
481 |
+
*/
|
482 |
+
public function notification_email(){
|
483 |
+
return $this->get('notification_email');
|
484 |
+
}
|
485 |
+
|
486 |
+
/**
|
487 |
+
* Getter - logging
|
488 |
+
*/
|
489 |
+
public function logging(){
|
490 |
+
$logging = $this->get('logging');
|
491 |
+
return $logging === 'true'? true: false;
|
492 |
+
}
|
493 |
+
|
494 |
+
/**
|
495 |
+
* Getter - license active - derived property
|
496 |
+
*/
|
497 |
+
public function license_active(){
|
498 |
+
//echo('</br>license Active Value1:' .$this->license_active);
|
499 |
+
|
500 |
+
if (empty($this->license_active)) {
|
501 |
+
//echo('</br>SET PROP');
|
502 |
+
|
503 |
+
$this->license_active = false;//default
|
504 |
+
|
505 |
+
$license_key = $this->license_key();
|
506 |
+
$license_status = $this->license_status();
|
507 |
+
|
508 |
+
//Allow expired licenses to be active for now
|
509 |
+
if(false !== $license_key && false !== $license_status) {
|
510 |
+
if ('valid'== $license_status || 'expired'== $license_status) {
|
511 |
+
$this->license_active= true;
|
512 |
+
}
|
513 |
+
}
|
514 |
+
}
|
515 |
+
|
516 |
+
//echo('</br>license Active Value2:' .$this->license_active);
|
517 |
+
return $this->license_active;
|
518 |
+
}
|
519 |
+
|
520 |
+
/**
|
521 |
+
* Getter - license status
|
522 |
+
*/
|
523 |
+
public function license_status(){
|
524 |
+
return $this->get('license_status');
|
525 |
+
}
|
526 |
+
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Getter: Get license type or default
|
530 |
+
*/
|
531 |
+
public function license_type(){
|
532 |
+
return $this->get('license_type');
|
533 |
+
}
|
534 |
+
|
535 |
+
/**
|
536 |
+
* Getter - license type description - derived property
|
537 |
+
*/
|
538 |
+
public function license_type_description(){
|
539 |
+
|
540 |
+
if (empty($this->license_type_description)) {
|
541 |
+
|
542 |
+
switch ($this->license_type()) {
|
543 |
+
case 0:
|
544 |
+
$this->license_type_description = 'lite';
|
545 |
+
break;
|
546 |
+
case 1:
|
547 |
+
$this->license_type_description = 'personal';
|
548 |
+
break;
|
549 |
+
|
550 |
+
case 2:
|
551 |
+
$this->license_type_description = 'business';
|
552 |
+
break;
|
553 |
+
|
554 |
+
case 3:
|
555 |
+
$this->license_type_description = 'professional';
|
556 |
+
break;
|
557 |
+
}
|
558 |
+
}
|
559 |
+
|
560 |
+
return $this->license_type_description;
|
561 |
+
}
|
562 |
+
|
563 |
+
/**
|
564 |
+
* Getter - backup retained number - derived property
|
565 |
+
*/
|
566 |
+
public function backup_retained_number(){
|
567 |
+
if (empty($this->backup_retained_number)) {
|
568 |
+
$this->backup_retained_number = $this->get_option('backup_retained_number');
|
569 |
+
|
570 |
+
//If not set then use the defaults
|
571 |
+
if (empty($this->backup_retained_number)) {
|
572 |
+
|
573 |
+
switch ($this->license_type()) {
|
574 |
+
case 0: //Lite
|
575 |
+
$this->backup_retained_number=1;
|
576 |
+
break;
|
577 |
+
case 1: //Personal
|
578 |
+
$this->backup_retained_number=3;
|
579 |
+
break;
|
580 |
+
|
581 |
+
case 2: //Business
|
582 |
+
$this->backup_retained_number=3;
|
583 |
+
break;
|
584 |
+
|
585 |
+
case 3: //Pro
|
586 |
+
$this->backup_retained_number=3;
|
587 |
+
break;
|
588 |
+
}
|
589 |
+
|
590 |
+
$this->set_option('backup_retained_number',$this->backup_retained_number);
|
591 |
+
}
|
592 |
+
|
593 |
+
}
|
594 |
+
|
595 |
+
return $this->backup_retained_number;
|
596 |
+
|
597 |
+
}
|
598 |
+
|
599 |
+
function backup_count(){
|
600 |
+
return $this->get('backup_count');
|
601 |
+
}
|
602 |
+
|
603 |
+
function successful_backup_count(){
|
604 |
+
return $this->get('successful_backup_count');
|
605 |
+
}
|
606 |
+
|
607 |
+
/**---------- END GETTERS --------------- **/
|
608 |
+
|
609 |
+
/**---------- SETTERS --------------- **/
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Generic Setter
|
613 |
+
*/
|
614 |
+
private function set($property,$value) {
|
615 |
+
|
616 |
+
$this->set_option($property, $value);
|
617 |
+
$this->$property = $value;
|
618 |
+
|
619 |
+
//If not set then use the defaults
|
620 |
+
if (empty($this->$property)) {
|
621 |
+
$this->$property=$this->defaults[$property];
|
622 |
+
}
|
623 |
+
|
624 |
+
}
|
625 |
+
|
626 |
+
function set_backup_count($value){
|
627 |
+
$this->set('backup_count', $value);
|
628 |
+
}
|
629 |
+
|
630 |
+
function set_successful_backup_count($value){
|
631 |
+
$this->set('successful_backup_count', $value);
|
632 |
+
}
|
633 |
+
|
634 |
+
/**---------- END SETTERS --------------- **/
|
635 |
+
|
636 |
+
|
637 |
+
/**-------------- LICENSE FUNCTIONS ---------------**/
|
638 |
+
|
639 |
+
/**
|
640 |
+
* Validate License Info Once per day
|
641 |
+
*/
|
642 |
+
public function check_license(){
|
643 |
+
$license_key=$this->license_key();
|
644 |
+
//echo "</br>License Key:" .$license_key;
|
645 |
+
|
646 |
+
$license_last_check_date=$this->get_option('license_last_check_date');
|
647 |
+
|
648 |
+
//Validate License once per day
|
649 |
+
$license_last_check_date = new DateTime($license_last_check_date);
|
650 |
+
//echo($license_last_check_date->format('Y-m-d H:i:s') .'</br>');
|
651 |
+
|
652 |
+
$now = new DateTime('now');//Get NOW
|
653 |
+
$yesterday = $now->sub(new DateInterval('P1D'));//subtract a day
|
654 |
+
//echo($yesterday->format('Y-m-d H:i:s') .'</br>');
|
655 |
+
|
656 |
+
//Validate License
|
657 |
+
if ($license_last_check_date<$yesterday)
|
658 |
+
{
|
659 |
+
//echo "Validate License";
|
660 |
+
$this->update_license_options($license_key);
|
661 |
+
//$this->update_stats($license_key);
|
662 |
+
}
|
663 |
+
}
|
664 |
+
|
665 |
+
/**
|
666 |
+
* Update ALL the license options
|
667 |
+
*/
|
668 |
+
private function update_license_options($license)
|
669 |
+
{
|
670 |
+
$logger = new WPBackItUp_Logger(false);
|
671 |
+
$logger->log('Update License Options:' .$license);
|
672 |
+
|
673 |
+
$license=trim($license);
|
674 |
+
|
675 |
+
//Load the defaults
|
676 |
+
$data['license_key'] = $this->defaults['license_key'];
|
677 |
+
$dt = new DateTime('now');
|
678 |
+
$data['license_last_check_date'] = $dt->format('Y-m-d H:i:s');
|
679 |
+
|
680 |
+
$data['license_status'] = $this->defaults['license_status'];
|
681 |
+
$data['license_status_message']= $this->defaults['license_status_message'];
|
682 |
+
$data['license_expires']= $this->defaults['license_expires'];
|
683 |
+
$data['license_limit']= $this->defaults['license_limit'];
|
684 |
+
$data['license_sitecount']= $this->defaults['license_sitecount'];
|
685 |
+
$data['license_type']= $this->defaults['license_type'];
|
686 |
+
|
687 |
+
//If no value then default to lite
|
688 |
+
if (empty($license) || 'lite'== $license ){
|
689 |
+
$data['license_status'] = 'free';
|
690 |
+
$data['license_expires']= $this->defaults['license_expires'];
|
691 |
+
$data['license_limit']= 1;
|
692 |
+
$data['license_sitecount']= 1;
|
693 |
+
$data['license_type']= 0;
|
694 |
+
} else {
|
695 |
+
//CALL EDD_ACTIVATE_LICENSE to get activation information
|
696 |
+
$api_params = array(
|
697 |
+
'edd_action'=> 'activate_license',
|
698 |
+
'license' => $license,
|
699 |
+
'item_name' => urlencode( WPBACKITUP__ITEM_NAME ) // the name of our product in EDD
|
700 |
+
);
|
701 |
+
|
702 |
+
$response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP__SECURESITE_URL ), array( 'timeout' => 15, 'sslverify' => true ) );
|
703 |
+
$logger->log('Validation Response:');
|
704 |
+
$logger->log($response);
|
705 |
+
|
706 |
+
if ( is_wp_error( $response ) )
|
707 |
+
return false; //Exit and don't update
|
708 |
+
|
709 |
+
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
710 |
+
$logger->log('License Object Info');
|
711 |
+
$logger->log($license_data);
|
712 |
+
|
713 |
+
$data['license_key'] = $license;
|
714 |
+
$data['license_status'] = $license_data->license;
|
715 |
+
$data['license_limit'] = $license_data->license_limit;
|
716 |
+
$data['license_sitecount'] = $license_data->site_count;
|
717 |
+
$data['license_expires'] = $license_data->expires;
|
718 |
+
|
719 |
+
//This is how we determine the type of license because
|
720 |
+
//there is no difference in EDD
|
721 |
+
if (is_numeric($license_data->license_limit)){
|
722 |
+
|
723 |
+
//Personal
|
724 |
+
if ($license_data->license_limit<5) {
|
725 |
+
$data['license_type'] = 1;
|
726 |
+
}
|
727 |
+
|
728 |
+
//Business
|
729 |
+
if ($license_data->license_limit>=5 && $license_data->license_limit<20) {
|
730 |
+
$data['license_type'] = 2;
|
731 |
+
}
|
732 |
+
|
733 |
+
//Professional
|
734 |
+
if ($license_data->license_limit>=20) {
|
735 |
+
$data['license_type'] = 3;
|
736 |
+
}
|
737 |
+
|
738 |
+
//EDD sends back expired in the error
|
739 |
+
if (($license_data->license=='invalid') && ($license_data->error=='expired')){
|
740 |
+
|
741 |
+
//Default to valid for now
|
742 |
+
$data['license_status'] ='valid';
|
743 |
+
$data['license_status_message'] ='';
|
744 |
+
|
745 |
+
//Only expire license in current month
|
746 |
+
$license_expire_date = $license_data->expires;
|
747 |
+
$expire_date_array = date_parse($license_expire_date);
|
748 |
+
$logger->log('Expire Date Array');
|
749 |
+
$logger->log($expire_date_array);
|
750 |
+
$logger->log('Expire Month: ' .$expire_date_array[month]);
|
751 |
+
$logger->log('Current Month: ' .date('m'));
|
752 |
+
|
753 |
+
//only EXPIRE current month
|
754 |
+
if ($expire_date_array[month]==date('m')) {
|
755 |
+
$data['license_status'] ='expired';
|
756 |
+
$data['license_status_message'] ='License has expired.';
|
757 |
+
$logger->log('Expire License.');
|
758 |
+
}
|
759 |
+
}
|
760 |
+
|
761 |
+
if (($license_data->license=='invalid') && ($license_data->error=='no_activations_left')){
|
762 |
+
$data['license_status_message'] ='Activation limit has been reached.';
|
763 |
+
}
|
764 |
+
}
|
765 |
+
}
|
766 |
+
|
767 |
+
$logger->log('Updating License Options');
|
768 |
+
foreach($data as $key => $val ) {
|
769 |
+
$this->set_option($key, $val);
|
770 |
+
$logger->log('Updated Option: ' .$key .':' .$val);
|
771 |
+
}
|
772 |
+
return true;
|
773 |
+
}
|
774 |
+
|
775 |
+
/**-------------- END LICENSE FUNCTIONS ---------------**/
|
776 |
+
|
777 |
+
/**
|
778 |
+
* Retrieve the stored plugin option or the default if no user specified value is defined
|
779 |
+
*
|
780 |
+
* @param string $option_name
|
781 |
+
*
|
782 |
+
* @uses get_option()
|
783 |
+
*
|
784 |
+
* @return mixed Returns the option value or false(boolean) if the option is not found
|
785 |
+
*/
|
786 |
+
public function get_option( $option_name ) {
|
787 |
+
// Load option values if they haven't been loaded already
|
788 |
+
$wp_option_name = $this->namespace .'_' .$option_name;
|
789 |
+
|
790 |
+
//Use this after migration
|
791 |
+
//$option_value = get_option($wp_option_name,$this->defaults[$option_name]);
|
792 |
+
|
793 |
+
$option_value = get_option($wp_option_name);
|
794 |
+
|
795 |
+
//return the value
|
796 |
+
if(isset( $option_value ) && !empty( $option_value )) return $option_value;
|
797 |
+
|
798 |
+
//Should only happen once
|
799 |
+
//Can take this out in next release
|
800 |
+
//If looking for license then migrate the old settings
|
801 |
+
if ('license_key'==$option_name) {
|
802 |
+
$options = get_option('_' . $this->namespace . '--options');
|
803 |
+
$license = $options[$option_name];
|
804 |
+
if( isset( $license ) || !empty( $license ) ) {
|
805 |
+
//migrate to new option setting
|
806 |
+
$this->set_option($option_name, $license);
|
807 |
+
$this->update_license_options($license);
|
808 |
+
|
809 |
+
//Delete the old options
|
810 |
+
delete_option('_' . $this->namespace . '--options');
|
811 |
+
|
812 |
+
return $license;
|
813 |
+
}
|
814 |
+
|
815 |
+
}
|
816 |
+
//Return the default
|
817 |
+
return $this->defaults[$option_name];
|
818 |
+
}
|
819 |
+
|
820 |
+
//Prefix options with namespace & save
|
821 |
+
public function set_option($option_name, $value) {
|
822 |
+
$option_name = $this->namespace .'_' .$option_name;
|
823 |
+
update_option($option_name,$value);
|
824 |
+
|
825 |
+
//Check class variables
|
826 |
+
if($option_name=='license_type')
|
827 |
+
$this->license_type= $value;
|
828 |
+
}
|
829 |
+
|
830 |
+
public function increment_backup_count(){
|
831 |
+
$backup_count = $this->backup_count();
|
832 |
+
$backup_count=$backup_count+1;
|
833 |
+
$this->set_backup_count($backup_count);
|
834 |
+
}
|
835 |
+
|
836 |
+
public function increment_successful_backup_count(){
|
837 |
+
$successful_backup_count = $this->successful_backup_count();
|
838 |
+
$successful_backup_count=$successful_backup_count+1;
|
839 |
+
$this->set_successful_backup_count($successful_backup_count);
|
840 |
+
}
|
841 |
+
|
842 |
+
/**
|
843 |
+
* Sanitize data
|
844 |
+
*
|
845 |
+
* @param mixed $str The data to be sanitized
|
846 |
+
*
|
847 |
+
* @uses wp_kses()
|
848 |
+
*
|
849 |
+
* @return mixed The sanitized version of the data
|
850 |
+
*/
|
851 |
+
private function _sanitize( $str ) {
|
852 |
+
if ( !function_exists( 'wp_kses' ) ) {
|
853 |
+
include_once ABSPATH . 'wp-includes/kses.php';
|
854 |
+
}
|
855 |
+
global $allowedposttags;
|
856 |
+
global $allowedprotocols;
|
857 |
+
|
858 |
+
if ( is_string( $str ) ) {
|
859 |
+
$str = wp_kses( $str, $allowedposttags, $allowedprotocols );
|
860 |
+
} elseif( is_array( $str ) ) {
|
861 |
+
$arr = array();
|
862 |
+
foreach( (array) $str as $key => $val ) {
|
863 |
+
$arr[$key] = $this->_sanitize( $val );
|
864 |
+
}
|
865 |
+
$str = $arr;
|
866 |
+
}
|
867 |
+
|
868 |
+
return $str;
|
869 |
+
}
|
870 |
+
|
871 |
+
/**STATIC FUNCTIONS**/
|
872 |
+
|
873 |
+
private static function get_settings_page_url( $page = 'config' ) {
|
874 |
+
|
875 |
+
$args = array( 'page' => 'wp-backitup-settings' );
|
876 |
+
$url = add_query_arg( $args, admin_url( 'admin.php' ));
|
877 |
+
|
878 |
+
return $url;
|
879 |
+
}
|
880 |
+
|
881 |
+
|
882 |
+
/**
|
883 |
+
* Activation action
|
884 |
+
*/
|
885 |
+
public static function activate() {
|
886 |
+
$logger = new WPBackItUp_Logger(true);
|
887 |
+
|
888 |
+
try{
|
889 |
+
//Check backup folder folders
|
890 |
+
$backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
|
891 |
+
if( !is_dir($backup_dir) ) {
|
892 |
+
@mkdir($backup_dir, 0755);
|
893 |
+
$logger->log('Backup Folder Created:' . $backup_dir);
|
894 |
+
}
|
895 |
+
|
896 |
+
//Check restore folder folders
|
897 |
+
$restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
|
898 |
+
if( !is_dir($restore_dir) ) {
|
899 |
+
@mkdir($restore_dir, 0755);
|
900 |
+
$logger->log('Restore Folder Created:' . $backup_dir);
|
901 |
+
}
|
902 |
+
|
903 |
+
//Make sure they exist now
|
904 |
+
if( !is_dir($backup_dir) || !is_dir($restore_dir)) {
|
905 |
+
exit ('WP BackItUp was not able to create the required backup and restore folders.');
|
906 |
+
}
|
907 |
+
|
908 |
+
} catch (Exception $e) {
|
909 |
+
$logger->log(' Activation Exception:' . $e->getMessage());
|
910 |
+
exit ('WP BackItUp encountered an error during activation.</br>' .$e->getMessage());
|
911 |
+
}
|
912 |
+
|
913 |
+
|
914 |
+
}
|
915 |
+
|
916 |
+
/**
|
917 |
+
* Deactivation action
|
918 |
+
*/
|
919 |
+
public static function deactivate() {
|
920 |
+
// Do deactivation actions
|
921 |
+
|
922 |
+
}
|
923 |
+
|
924 |
+
/* --------------------- PRIVATES -----------------------------------------*/
|
925 |
+
|
926 |
+
/**
|
927 |
+
* Update statistics
|
928 |
+
*/
|
929 |
+
private function update_stats($license)
|
930 |
+
{
|
931 |
+
$logger = new WPBackItUp_Logger(true);
|
932 |
+
$logger->log('Update Stats:' .$license);
|
933 |
+
|
934 |
+
$license=trim($license);
|
935 |
+
|
936 |
+
//Get stats here
|
937 |
+
|
938 |
+
//Setup API call
|
939 |
+
$api_params = array(
|
940 |
+
'wpb_action'=> 'update_stats',
|
941 |
+
'license' => $license
|
942 |
+
);
|
943 |
+
|
944 |
+
$url = WPBACKITUP__SECURESITE_URL .'/stats-update-test';
|
945 |
+
$response = wp_remote_get( add_query_arg( $api_params, $url ), array( 'timeout' => 15, 'sslverify' => true ) );
|
946 |
+
$logger->log('Stats Response:');
|
947 |
+
$logger->log($response);
|
948 |
+
|
949 |
+
if ( is_wp_error( $response ) )
|
950 |
+
return false; //Exit and don't update
|
951 |
+
|
952 |
+
//$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
953 |
+
|
954 |
+
return true;
|
955 |
+
}
|
956 |
+
|
957 |
+
/* --------------------- END PRIVATES -----------------------------------------*/
|
958 |
+
|
959 |
+
|
960 |
+
}
|
lib/includes/class-zip.php
ADDED
@@ -0,0 +1 @@
|
|
|
|
0 |
* WP Backitup Zip Function
|
1 |
*
|
2 |
* @package WP Backitup
|
3 |
*
|
4 |
* @author cssimmon
|
5 |
*
|
6 |
*/
|
7 |
private $zip_file_count;
|
8 |
private $max_file_count=1000;
|
9 |
$this->zip_file_count=0;
|
10 |
}
|
11 |
function __destruct() {
|
12 |
|
13 |
}
|
14 |
}
|
15 |
$zip->addFile($src,substr($src,$path));
|
16 |
}
|
17 |
if(!is_dir($src)){
|
18 |
$zip->close();
|
19 |
@unlink($dst);
|
20 |
$this->logger->log('(Zip.compress) File not found:' . $dst);
|
21 |
echo 'Error: File not found';
|
22 |
exit;
|
23 |
}
|
24 |
$this->recurse_zip($src,$dst,$zip,$path);}
|
25 |
//Reopen the zip when you get to max file count
|
26 |
if($this->zip_file_count>=$this->max_file_count){
|
27 |
$zip->close();
|
28 |
$this->zip_file_count=0;
|
29 |
$zip = new ZipArchive;
|
30 |
$res = $zip->open($dst,ZIPARCHIVE::CREATE);
|
31 |
//Check for error
|
32 |
if($res !== TRUE){
|
33 |
$this->logger->log('(Zip.recurse_zip) Zip open cant be opened:' .$res);
|
34 |
exit('Zip open cant be opened');
|
35 |
}
|
36 |
}
|
37 |
$zipFilePath = substr($src . '/' . $file,$path);
|
38 |
$zip->addEmptyDir($zipFilePath);
|
39 |
$this->zip_file_count++;
|
40 |
$this->recurse_zip($src . '/' . $file,$dst,$zip,$path);
|
41 |
$this->zip_file_count++;
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
* WP Backitup Zip Function
|
3 |
*
|
4 |
* @package WP Backitup
|
5 |
*
|
6 |
* @author cssimmon
|
7 |
*
|
8 |
*/
|
9 |
private $zip_file_count;
|
10 |
private $max_file_count=1000;
|
11 |
$this->zip_file_count=0;
|
12 |
}
|
13 |
function __destruct() {
|
14 |
|
15 |
}
|
16 |
}
|
17 |
$zip->addFile($src,substr($src,$path));
|
18 |
}
|
19 |
if(!is_dir($src)){
|
20 |
$zip->close();
|
21 |
@unlink($dst);
|
22 |
$this->logger->log('(Zip.compress) File not found:' . $dst);
|
23 |
echo 'Error: File not found';
|
24 |
exit;
|
25 |
}
|
26 |
$this->recurse_zip($src,$dst,$zip,$path);}
|
27 |
//Reopen the zip when you get to max file count
|
28 |
if($this->zip_file_count>=$this->max_file_count){
|
29 |
$zip->close();
|
30 |
$this->zip_file_count=0;
|
31 |
$zip = new ZipArchive;
|
32 |
$res = $zip->open($dst,ZIPARCHIVE::CREATE);
|
33 |
//Check for error
|
34 |
if($res !== TRUE){
|
35 |
$this->logger->log('(Zip.recurse_zip) Zip open cant be opened:' .$res);
|
36 |
exit('Zip open cant be opened');
|
37 |
}
|
38 |
}
|
39 |
$zipFilePath = substr($src . '/' . $file,$path);
|
40 |
$zip->addEmptyDir($zipFilePath);
|
41 |
$this->zip_file_count++;
|
42 |
$this->recurse_zip($src . '/' . $file,$dst,$zip,$path);
|
43 |
$this->zip_file_count++;
|
lib/includes/recurse_zip.php
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
<?php
|
2 |
* WP Backitup Recurse Zip Function
|
3 |
*
|
4 |
* @package WP Backitup
|
5 |
*
|
6 |
* @author jcpeden
|
7 |
* @version 1.4.0
|
8 |
* @since 1.0.1
|
9 |
*/
|
|
|
0 |
* WP Backitup Recurse Zip Function
|
1 |
*
|
2 |
* @package WP Backitup
|
3 |
*
|
4 |
* @author jcpeden
|
5 |
* @version 1.4.0
|
6 |
* @since 1.0.1
|
7 |
*/
|
lib/includes/restore.php
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<?php
|
2 |
@set_time_limit(900);// 15 minutes per image should be PLENTY
|
3 |
|
4 |
/**
|
@@ -7,22 +7,33 @@
|
|
7 |
* @package WP Backitup Pro
|
8 |
*
|
9 |
* @author cssimmon
|
10 |
-
*
|
11 |
-
* @since 1.0.1
|
12 |
*/
|
13 |
|
14 |
/*** Includes ***/
|
15 |
-
//
|
16 |
-
if
|
17 |
-
include_once
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
/*** Globals ***/
|
21 |
-
$
|
22 |
-
$
|
23 |
-
|
24 |
-
$
|
|
|
25 |
|
|
|
26 |
$inactive=0;
|
27 |
$active=1;
|
28 |
$complete=2;
|
@@ -31,6 +42,7 @@ $warning=-2;
|
|
31 |
$success=99;
|
32 |
|
33 |
//setup the status array
|
|
|
34 |
$status_array = array(
|
35 |
'preparing' =>$inactive ,
|
36 |
'unzipping' =>$inactive ,
|
@@ -39,80 +51,88 @@ $status_array = array(
|
|
39 |
'database'=>$inactive,
|
40 |
'wpcontent'=>$inactive,
|
41 |
'cleanup'=>$inactive
|
42 |
-
);
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
//*****************//
|
46 |
//*** MAIN CODE ***//
|
47 |
//*****************//
|
48 |
-
|
49 |
-
|
50 |
-
_log_constants();
|
51 |
|
52 |
-
if (
|
53 |
-
|
54 |
write_fatal_error_status('error225');
|
55 |
die();
|
56 |
}
|
57 |
|
58 |
-
//--Get form post values
|
59 |
$backup_file_name = $_POST['selected_file'];//Get the backup file name
|
60 |
-
if( $backup_file_name
|
61 |
write_fatal_error_status('error201');
|
62 |
die();
|
63 |
}
|
64 |
|
65 |
//Get user ID
|
66 |
$user_id = $_POST['user_id'];
|
67 |
-
if( $user_id
|
68 |
write_fatal_error_status('error201');
|
69 |
die();
|
70 |
}
|
71 |
|
|
|
|
|
|
|
|
|
|
|
72 |
set_status('preparing',$active,true);
|
73 |
|
74 |
//set path to backup file
|
75 |
-
$backup_file_path = $
|
76 |
|
77 |
delete_restore_folder();
|
78 |
|
79 |
-
create_restore_folder($
|
80 |
set_status('preparing',$complete,false);
|
81 |
|
82 |
set_status('unzipping',$active,true);
|
83 |
-
unzip_backup($backup_file_path,$
|
84 |
set_status('unzipping',$complete,false);
|
85 |
|
86 |
set_status('validation',$active,true);
|
87 |
-
$restoration_dir_path=validate_restore_folder($
|
88 |
-
|
89 |
-
$backupSQLFile = $restoration_dir_path . WPBACKITUP_SQL_DBBACKUP_FILENAME;
|
90 |
|
91 |
-
|
92 |
|
93 |
-
|
94 |
|
95 |
-
$siteurl = get_siteurl(
|
96 |
|
97 |
-
$homeurl = get_homeurl(
|
98 |
|
99 |
-
$user_login = get_user_login($
|
100 |
|
101 |
-
$user_pass = get_user_pass($
|
102 |
|
103 |
-
$user_email = get_user_email($
|
104 |
|
105 |
//Collect previous backup site url start
|
106 |
-
|
107 |
$import_siteinfo_lines = file($restoration_dir_path .'backupsiteinfo.txt');
|
108 |
$import_siteurl = trim($import_siteinfo_lines[0]);
|
109 |
$current_siteurl = trim($siteurl ,'/');
|
110 |
$import_table_prefix = $import_siteinfo_lines[1];
|
111 |
-
|
112 |
|
113 |
//Check table prefix values FATAL
|
114 |
if($table_prefix !=$import_table_prefix) {
|
115 |
-
|
116 |
write_warning_status('error221');
|
117 |
}
|
118 |
|
@@ -120,12 +140,7 @@ if($table_prefix !=$import_table_prefix) {
|
|
120 |
//Create restore point for DB
|
121 |
set_status('validation',$complete,false);
|
122 |
set_status('restore_point',$active,true);
|
123 |
-
$RestorePoint_SQL = backup_database($
|
124 |
-
|
125 |
-
//create_table_rename_sql($restore_folder_root,$table_prefix);
|
126 |
-
//Rename the old tables - not sure i want to do this anymore
|
127 |
-
//$renameSQLFile = $restore_folder_root.WPBACKITUP_SQL_TABLE_RENAME_FILENAME;
|
128 |
-
//rename_SQL_tables($renameSQLFile);
|
129 |
|
130 |
set_status('restore_point',$complete,false);
|
131 |
|
@@ -134,37 +149,38 @@ set_status('database',$active,true);
|
|
134 |
import_backedup_database($backupSQLFile);
|
135 |
|
136 |
//FAILURES AFTER THIS POINT SHOULD REQUIRE ROLLBACK OF DB
|
137 |
-
update_user_credentials($
|
138 |
|
139 |
-
update_siteurl($
|
140 |
|
141 |
-
update_homeurl($
|
142 |
|
143 |
//Done with DB restore
|
144 |
set_status('database',$complete,false);
|
145 |
|
146 |
-
//Disconnect database
|
147 |
-
mysqli_close($dbc);
|
148 |
-
|
149 |
//***DEAL WITH WPCONTENT NOW ***
|
150 |
set_status('wpcontent',$active,true);
|
151 |
-
delete_plugins_content(
|
152 |
-
|
153 |
-
delete_themes_content(WPBACKITUP_THEMES_PATH,$restoration_dir_path);
|
154 |
|
155 |
//delete whatever is left
|
156 |
-
$wpcontent_folder=
|
157 |
-
delete_wpcontent_content($wpcontent_folder
|
158 |
|
159 |
restore_wpcontent($restoration_dir_path);
|
160 |
set_status('wpcontent',$complete,false);
|
|
|
|
|
|
|
161 |
|
162 |
set_status('cleanup',$active,true);
|
163 |
cleanup_restore_folder($restoration_dir_path);
|
164 |
set_status('cleanup',$complete,false);
|
165 |
set_status_success();
|
166 |
|
167 |
-
|
|
|
|
|
168 |
die();
|
169 |
|
170 |
/******************/
|
@@ -173,7 +189,7 @@ die();
|
|
173 |
|
174 |
//Get Status Log
|
175 |
function get_restore_Log() {
|
176 |
-
$log =
|
177 |
if (file_exists($log)){
|
178 |
unlink($log);
|
179 |
}
|
@@ -231,370 +247,393 @@ function set_status_success(){
|
|
231 |
|
232 |
//Create an empty restore folder
|
233 |
function create_restore_folder($path) {
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
237 |
write_fatal_error_status('error222');
|
238 |
die();
|
239 |
}
|
240 |
-
|
241 |
}
|
242 |
|
243 |
//Delete restore folder and contents
|
244 |
function delete_restore_folder() {
|
245 |
-
|
|
|
246 |
//Delete the existing restore directory
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
}
|
251 |
|
252 |
//Unzip the backup to the restore folder
|
253 |
-
function unzip_backup($backup_file_path,$restore_folder_root){
|
|
|
254 |
//unzip the upload
|
255 |
-
|
256 |
-
|
257 |
$zip = new ZipArchive;
|
258 |
$res = $zip->open($backup_file_path);
|
259 |
if ($res === TRUE) {
|
260 |
$zip->extractTo($restore_folder_root);
|
261 |
$zip->close();
|
262 |
} else {
|
263 |
-
|
264 |
write_fatal_error_status('error203');
|
265 |
delete_restore_folder();
|
266 |
die();
|
267 |
}
|
268 |
-
|
269 |
}
|
270 |
|
271 |
//Validate the restore folder
|
272 |
function validate_restore_folder($restore_folder_root){
|
|
|
273 |
$restoration_dir_path='';
|
274 |
|
275 |
-
|
276 |
if ( count( glob( $restore_folder_root.'*', GLOB_ONLYDIR ) ) == 1 ) {
|
277 |
foreach( glob($restore_folder_root .'*', GLOB_ONLYDIR ) as $dir) {
|
278 |
$restoration_dir_path = $dir .'/';
|
|
|
279 |
}
|
280 |
}
|
281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
|
283 |
//Validate the restoration
|
284 |
-
|
285 |
if(!glob($restoration_dir_path .'backupsiteinfo.txt') ){
|
286 |
-
|
287 |
write_fatal_error_status('error204');
|
288 |
delete_restore_folder(); //delete the restore folder if bad
|
289 |
die();
|
290 |
}
|
291 |
-
|
292 |
return $restoration_dir_path;
|
293 |
}
|
294 |
|
295 |
// Backup the current database try dump first
|
296 |
function backup_database($restore_folder_root){
|
|
|
297 |
$date = date_i18n('Y-m-d-Hi',current_time( 'timestamp' ));
|
298 |
$backup_file = $restore_folder_root . 'db-backup-' . $date .'.cur';
|
299 |
-
|
300 |
-
|
|
|
|
|
301 |
//Try a manual restore since dump didnt work
|
302 |
-
if(
|
303 |
-
|
304 |
write_fatal_error_status('error205');
|
305 |
delete_restore_folder();
|
306 |
die();
|
307 |
}
|
308 |
}
|
309 |
-
|
310 |
return $backup_file;
|
311 |
}
|
312 |
|
313 |
-
//Generate a script to rename the tables
|
314 |
-
function create_table_rename_sql($restore_folder_root,$table_prefix){
|
315 |
-
$sql_file_path= $restore_folder_root .'db-rename-tables.sql';
|
316 |
-
_log('Generate a script to rename the tables.' .$sql_file_path);
|
317 |
-
if(!db_rename_wptables($sql_file_path,$table_prefix)) {
|
318 |
-
_log('Error: Cant generate rename script:'.$sql_file_path);
|
319 |
-
write_fatal_error_status('error205');
|
320 |
-
delete_restore_folder();
|
321 |
-
die();
|
322 |
-
}
|
323 |
-
_log('SQL Script to rename tables generated.' .$sql_file_path);
|
324 |
-
}
|
325 |
-
|
326 |
//Make sure there IS a backup to restore
|
327 |
-
function validate_SQL_exists($
|
328 |
-
|
|
|
329 |
|
330 |
if(!file_exists($backupSQLFile) && !empty($backupSQLFile)) {
|
331 |
-
|
332 |
write_fatal_error_status('error216');
|
333 |
delete_restore_folder();
|
334 |
die();
|
335 |
}
|
336 |
-
|
337 |
-
}
|
338 |
-
|
339 |
-
//Get SQL Connection
|
340 |
-
function get_sql_connection($restoration_dir_path){
|
341 |
-
//Connect to DB
|
342 |
-
$dbc = db_get_sqlconnection();
|
343 |
-
if ( !$dbc ) {
|
344 |
-
_log('Error: Cant connect to database.');
|
345 |
-
write_fatal_error_status('error206');
|
346 |
-
delete_restore_folder();
|
347 |
-
die();
|
348 |
-
}
|
349 |
-
return $dbc;
|
350 |
-
}
|
351 |
-
|
352 |
-
//Get SQL scalar value
|
353 |
-
function get_sql_scalar($dbc,$sql){
|
354 |
-
$value='';
|
355 |
-
if ($result = mysqli_query($dbc, $sql)) {
|
356 |
-
while ($row = mysqli_fetch_row($result)) {
|
357 |
-
$value = $row[0];
|
358 |
-
}
|
359 |
-
mysqli_free_result($result);
|
360 |
-
}
|
361 |
-
return $value;
|
362 |
-
}
|
363 |
-
|
364 |
-
//Run SQL command
|
365 |
-
function run_SQL_command($dbc, $sql){
|
366 |
-
if(!mysqli_query($dbc, $sql) ) {
|
367 |
-
_log('Error:SQL Command Failed:' .$sql);
|
368 |
-
return false;
|
369 |
-
}
|
370 |
-
return true;
|
371 |
-
}
|
372 |
-
|
373 |
-
//Rename the existing tables to have the save_ prefix
|
374 |
-
function rename_SQL_tables($renameSQLFile){
|
375 |
-
_log('Rename existing tables to contain save_ prefix:' .$renameSQLFile);
|
376 |
-
if(!db_run_sql($renameSQLFile)) {
|
377 |
-
_log('Error: Table rename error.');
|
378 |
-
write_fatal_error_status('error205');
|
379 |
-
delete_restore_folder();
|
380 |
-
die();
|
381 |
-
}
|
382 |
-
_log('Tables renamed to contain save_ prefix.');
|
383 |
}
|
384 |
|
385 |
//Restore DB
|
386 |
function restore_database(){
|
|
|
387 |
global $RestorePoint_SQL;
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
|
|
|
|
|
|
|
|
|
|
394 |
}
|
395 |
write_fatal_error_status('error224');
|
396 |
-
|
397 |
}
|
398 |
|
399 |
//Run DB restore
|
400 |
function import_backedup_database($backupSQLFile){
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
}
|
408 |
-
|
409 |
}
|
410 |
|
411 |
//get siteurl
|
412 |
-
function get_siteurl(
|
|
|
413 |
global $table_prefix;
|
414 |
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
|
415 |
-
|
|
|
|
|
416 |
if (empty($siteurl)) {
|
417 |
-
|
418 |
write_fatal_error_status('error207');
|
419 |
-
mysqli_close($dbc);
|
420 |
delete_restore_folder();
|
421 |
die();
|
422 |
}
|
423 |
-
|
424 |
return $siteurl;
|
425 |
}
|
426 |
|
427 |
//get homeurl
|
428 |
-
function get_homeurl(
|
|
|
429 |
global $table_prefix;
|
430 |
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
|
431 |
-
|
|
|
432 |
if (empty($homeurl)) {
|
433 |
-
|
434 |
write_fatal_error_status('error208');
|
435 |
-
mysqli_close($dbc);
|
436 |
delete_restore_folder();
|
437 |
die();
|
438 |
}
|
439 |
-
|
440 |
return $homeurl;
|
441 |
}
|
442 |
|
443 |
//get user login
|
444 |
-
function get_user_login($
|
|
|
445 |
global $table_prefix;
|
446 |
$sql = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
447 |
-
|
|
|
|
|
448 |
if (empty($user_login)) {
|
449 |
-
|
450 |
write_fatal_error_status('error209');
|
451 |
-
mysqli_close($dbc);
|
452 |
delete_restore_folder();
|
453 |
die();
|
454 |
}
|
455 |
-
|
456 |
return $user_login;
|
457 |
}
|
458 |
|
459 |
//get user pass
|
460 |
-
function get_user_pass($
|
|
|
461 |
global $table_prefix;
|
462 |
$sql = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
463 |
-
|
|
|
|
|
464 |
if (empty($user_pass)) {
|
465 |
-
|
466 |
write_fatal_error_status('error210');
|
467 |
-
|
468 |
-
delete_restore_folder();
|
469 |
die();
|
470 |
}
|
471 |
-
|
472 |
return $user_pass;
|
473 |
}
|
474 |
|
475 |
//get user email
|
476 |
-
function get_user_email($
|
|
|
477 |
global $table_prefix;
|
478 |
$sql = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
|
479 |
-
|
|
|
|
|
480 |
if (empty($user_email)) {
|
481 |
-
|
482 |
write_fatal_error_status('error211');
|
483 |
-
mysqli_close($dbc);
|
484 |
delete_restore_folder();
|
485 |
die();
|
486 |
}
|
487 |
-
|
488 |
return $user_email;
|
489 |
}
|
490 |
|
491 |
-
//Update user
|
492 |
-
function update_user_credentials($
|
|
|
493 |
$sql = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
|
494 |
-
|
495 |
-
|
|
|
|
|
496 |
write_warning_status('error215');
|
497 |
-
mysqli_close($dbc);
|
498 |
restore_database();
|
499 |
delete_restore_folder();
|
500 |
die();
|
501 |
}
|
502 |
-
|
503 |
}
|
504 |
|
505 |
//update the site URL in the restored database
|
506 |
-
function update_siteurl($
|
507 |
-
|
508 |
-
|
509 |
-
|
|
|
|
|
|
|
510 |
write_warning_status('error213');
|
511 |
-
mysqli_close($dbc);
|
512 |
restore_database();
|
513 |
delete_restore_folder();
|
514 |
die();
|
515 |
}
|
516 |
-
|
517 |
}
|
518 |
|
519 |
//Update homeURL
|
520 |
-
function update_homeurl($
|
521 |
-
|
522 |
-
|
523 |
-
|
|
|
|
|
524 |
write_warning_status('error214');
|
525 |
-
mysqli_close($dbc);
|
526 |
restore_database();
|
527 |
delete_restore_folder();
|
528 |
die();
|
529 |
}
|
530 |
-
|
531 |
}
|
532 |
|
533 |
//Delete wp-content content
|
534 |
-
function delete_wpcontent_content($root_folder
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
|
|
|
|
539 |
write_warning_status('error217');
|
540 |
restore_database();
|
541 |
delete_restore_folder();
|
542 |
die();
|
543 |
}
|
544 |
-
|
545 |
}
|
546 |
|
547 |
//Delete plugins content
|
548 |
-
function delete_plugins_content(
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
|
|
|
|
|
|
553 |
write_warning_status('error217');
|
554 |
restore_database();
|
555 |
delete_restore_folder();
|
556 |
die();
|
557 |
}
|
558 |
-
|
559 |
}
|
560 |
|
561 |
|
562 |
//Delete themes content
|
563 |
-
function delete_themes_content(
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
|
|
|
|
568 |
write_warning_status('error217');
|
569 |
restore_database();
|
570 |
delete_restore_folder();
|
571 |
die();
|
572 |
}
|
573 |
-
|
574 |
}
|
575 |
|
576 |
//Restore all wp content from zip
|
577 |
function restore_wpcontent($restoration_dir_path){
|
578 |
-
|
579 |
-
|
580 |
-
$
|
581 |
-
|
582 |
-
|
|
|
|
|
583 |
write_warning_status('error219');
|
584 |
restore_database();
|
585 |
delete_restore_folder();
|
586 |
die();
|
587 |
}
|
588 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
589 |
}
|
590 |
|
591 |
//Delete the restoration directory
|
592 |
function cleanup_restore_folder($restoration_dir_path){
|
593 |
-
|
|
|
594 |
if(!delete_restore_folder()) {
|
595 |
-
|
596 |
write_warning_status('error220'); //NOT fatal
|
597 |
} else {
|
598 |
-
|
599 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
}
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed (restore)');
|
2 |
@set_time_limit(900);// 15 minutes per image should be PLENTY
|
3 |
|
4 |
/**
|
7 |
* @package WP Backitup Pro
|
8 |
*
|
9 |
* @author cssimmon
|
10 |
+
*
|
|
|
11 |
*/
|
12 |
|
13 |
/*** Includes ***/
|
14 |
+
// include backup class
|
15 |
+
if( !class_exists( 'WPBackItUp_Restore' ) ) {
|
16 |
+
include_once 'class-restore.php';
|
17 |
+
}
|
18 |
+
|
19 |
+
// include file system class
|
20 |
+
if( !class_exists( 'WPBackItUp_Filesystem' ) ) {
|
21 |
+
include_once 'class-filesystem.php';
|
22 |
+
}
|
23 |
+
|
24 |
+
// include SQL class
|
25 |
+
if( !class_exists( 'WPBackItUp_SQL' ) ) {
|
26 |
+
include_once 'class-sql.php';
|
27 |
+
}
|
28 |
|
29 |
/*** Globals ***/
|
30 |
+
global $WPBackitup;
|
31 |
+
global $table_prefix; //this is from wp-config
|
32 |
+
|
33 |
+
global $backup_file_name; //name of the backup file
|
34 |
+
global $backup_file_path; //full path to zip file on server
|
35 |
|
36 |
+
global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
|
37 |
$inactive=0;
|
38 |
$active=1;
|
39 |
$complete=2;
|
42 |
$success=99;
|
43 |
|
44 |
//setup the status array
|
45 |
+
global $status_array;
|
46 |
$status_array = array(
|
47 |
'preparing' =>$inactive ,
|
48 |
'unzipping' =>$inactive ,
|
51 |
'database'=>$inactive,
|
52 |
'wpcontent'=>$inactive,
|
53 |
'cleanup'=>$inactive
|
54 |
+
);
|
55 |
+
|
56 |
+
global $logger;
|
57 |
+
$logger = new WPBackItUp_Logger(true,null,'restore');
|
58 |
+
|
59 |
+
global $wp_restore; //Eventually everything will be migrated to this class
|
60 |
+
$wp_restore = new WPBackItUp_Restore($logger);
|
61 |
|
62 |
|
63 |
//*****************//
|
64 |
//*** MAIN CODE ***//
|
65 |
//*****************//
|
66 |
+
$logger->log('***BEGIN RESTORE***');
|
67 |
+
$logger->logConstants();
|
|
|
68 |
|
69 |
+
if (!$this->license_active()){
|
70 |
+
$logger->log('Restore is not available because license is not active.');
|
71 |
write_fatal_error_status('error225');
|
72 |
die();
|
73 |
}
|
74 |
|
75 |
+
//--Get form post values
|
76 |
$backup_file_name = $_POST['selected_file'];//Get the backup file name
|
77 |
+
if( empty($backup_file_name)) {
|
78 |
write_fatal_error_status('error201');
|
79 |
die();
|
80 |
}
|
81 |
|
82 |
//Get user ID
|
83 |
$user_id = $_POST['user_id'];
|
84 |
+
if( empty($user_id)) {
|
85 |
write_fatal_error_status('error201');
|
86 |
die();
|
87 |
}
|
88 |
|
89 |
+
|
90 |
+
//TEST
|
91 |
+
|
92 |
+
//END TEST
|
93 |
+
|
94 |
set_status('preparing',$active,true);
|
95 |
|
96 |
//set path to backup file
|
97 |
+
$backup_file_path = $wp_restore->backup_folder_path .$backup_file_name ;
|
98 |
|
99 |
delete_restore_folder();
|
100 |
|
101 |
+
create_restore_folder($wp_restore->restore_folder_path);
|
102 |
set_status('preparing',$complete,false);
|
103 |
|
104 |
set_status('unzipping',$active,true);
|
105 |
+
unzip_backup($backup_file_path,$wp_restore->restore_folder_path);
|
106 |
set_status('unzipping',$complete,false);
|
107 |
|
108 |
set_status('validation',$active,true);
|
109 |
+
$restoration_dir_path=validate_restore_folder($wp_restore->restore_folder_path);
|
|
|
|
|
110 |
|
111 |
+
$backupSQLFile = $restoration_dir_path . WPBACKITUP__SQL_DBBACKUP_FILENAME;
|
112 |
|
113 |
+
validate_SQL_exists($backupSQLFile);
|
114 |
|
115 |
+
$siteurl = get_siteurl();
|
116 |
|
117 |
+
$homeurl = get_homeurl();
|
118 |
|
119 |
+
$user_login = get_user_login($user_id);
|
120 |
|
121 |
+
$user_pass = get_user_pass($user_id);
|
122 |
|
123 |
+
$user_email = get_user_email($user_id);
|
124 |
|
125 |
//Collect previous backup site url start
|
126 |
+
$logger->log('Get backupsiteinfo.txt values...');
|
127 |
$import_siteinfo_lines = file($restoration_dir_path .'backupsiteinfo.txt');
|
128 |
$import_siteurl = trim($import_siteinfo_lines[0]);
|
129 |
$current_siteurl = trim($siteurl ,'/');
|
130 |
$import_table_prefix = $import_siteinfo_lines[1];
|
131 |
+
$logger->log($import_siteinfo_lines);
|
132 |
|
133 |
//Check table prefix values FATAL
|
134 |
if($table_prefix !=$import_table_prefix) {
|
135 |
+
$logger->log('Error: Table prefix different from restore.');
|
136 |
write_warning_status('error221');
|
137 |
}
|
138 |
|
140 |
//Create restore point for DB
|
141 |
set_status('validation',$complete,false);
|
142 |
set_status('restore_point',$active,true);
|
143 |
+
$RestorePoint_SQL = backup_database($wp_restore->backup_folder_path); //Save in backup folder
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
set_status('restore_point',$complete,false);
|
146 |
|
149 |
import_backedup_database($backupSQLFile);
|
150 |
|
151 |
//FAILURES AFTER THIS POINT SHOULD REQUIRE ROLLBACK OF DB
|
152 |
+
update_user_credentials($import_table_prefix, $user_login, $user_pass, $user_email, $user_id);
|
153 |
|
154 |
+
update_siteurl($import_table_prefix, $current_siteurl);
|
155 |
|
156 |
+
update_homeurl($import_table_prefix, $homeurl);
|
157 |
|
158 |
//Done with DB restore
|
159 |
set_status('database',$complete,false);
|
160 |
|
|
|
|
|
|
|
161 |
//***DEAL WITH WPCONTENT NOW ***
|
162 |
set_status('wpcontent',$active,true);
|
163 |
+
delete_plugins_content();
|
164 |
+
delete_themes_content();
|
|
|
165 |
|
166 |
//delete whatever is left
|
167 |
+
$wpcontent_folder=WPBACKITUP__CONTENT_PATH;
|
168 |
+
delete_wpcontent_content($wpcontent_folder);
|
169 |
|
170 |
restore_wpcontent($restoration_dir_path);
|
171 |
set_status('wpcontent',$complete,false);
|
172 |
+
validate_wpcontent($restoration_dir_path,$wpcontent_folder);
|
173 |
+
|
174 |
+
update_permalinks();
|
175 |
|
176 |
set_status('cleanup',$active,true);
|
177 |
cleanup_restore_folder($restoration_dir_path);
|
178 |
set_status('cleanup',$complete,false);
|
179 |
set_status_success();
|
180 |
|
181 |
+
$logger->log('Restore completed successfully');
|
182 |
+
|
183 |
+
$logger->log('***END RESTORE***');
|
184 |
die();
|
185 |
|
186 |
/******************/
|
189 |
|
190 |
//Get Status Log
|
191 |
function get_restore_Log() {
|
192 |
+
$log = WPBACKITUP__PLUGIN_PATH .'/logs/status.log';
|
193 |
if (file_exists($log)){
|
194 |
unlink($log);
|
195 |
}
|
247 |
|
248 |
//Create an empty restore folder
|
249 |
function create_restore_folder($path) {
|
250 |
+
global $logger;
|
251 |
+
$logger->log('Create restore folder:' .$path);
|
252 |
+
|
253 |
+
$fileSystem = new WPBackItUp_FileSystem($logger);
|
254 |
+
if(!$fileSystem->create_dir($path)) {
|
255 |
+
$logger->log('Error: Cant create restore folder :'. $path);
|
256 |
write_fatal_error_status('error222');
|
257 |
die();
|
258 |
}
|
259 |
+
$logger->log('Restore folder created:' .$path);
|
260 |
}
|
261 |
|
262 |
//Delete restore folder and contents
|
263 |
function delete_restore_folder() {
|
264 |
+
global $logger;
|
265 |
+
global $wp_restore;
|
266 |
//Delete the existing restore directory
|
267 |
+
$logger->log('Delete existing restore folder:' .$wp_restore->restore_folder_path);
|
268 |
+
$fileSystem = new WPBackItUp_FileSystem($logger);
|
269 |
+
return $fileSystem->recursive_delete($wp_restore->restore_folder_path);
|
270 |
}
|
271 |
|
272 |
//Unzip the backup to the restore folder
|
273 |
+
function unzip_backup($backup_file_path,$restore_folder_root){
|
274 |
+
global $logger;
|
275 |
//unzip the upload
|
276 |
+
$logger->log('Unzip the backup file source:' .$backup_file_path);
|
277 |
+
$logger->log('Unzip the backup file target:' .$restore_folder_root);
|
278 |
$zip = new ZipArchive;
|
279 |
$res = $zip->open($backup_file_path);
|
280 |
if ($res === TRUE) {
|
281 |
$zip->extractTo($restore_folder_root);
|
282 |
$zip->close();
|
283 |
} else {
|
284 |
+
$logger->log('Error: Cant unzip backup:'.$backup_file_path);
|
285 |
write_fatal_error_status('error203');
|
286 |
delete_restore_folder();
|
287 |
die();
|
288 |
}
|
289 |
+
$logger->log('Backup file unzipped: ' .$restore_folder_root);
|
290 |
}
|
291 |
|
292 |
//Validate the restore folder
|
293 |
function validate_restore_folder($restore_folder_root){
|
294 |
+
global $logger;
|
295 |
$restoration_dir_path='';
|
296 |
|
297 |
+
$logger->log('Identify the restoration directory in restore folder: ' .$restore_folder_root.'*');
|
298 |
if ( count( glob( $restore_folder_root.'*', GLOB_ONLYDIR ) ) == 1 ) {
|
299 |
foreach( glob($restore_folder_root .'*', GLOB_ONLYDIR ) as $dir) {
|
300 |
$restoration_dir_path = $dir .'/';
|
301 |
+
$logger->log('Restoration directory Set to: ' .$restoration_dir_path);
|
302 |
}
|
303 |
}
|
304 |
+
|
305 |
+
if (empty($restoration_dir_path)) {
|
306 |
+
$logger->log('Error: Restore directory INVALID: ' .$restore_folder_root);
|
307 |
+
write_fatal_error_status('error204');
|
308 |
+
delete_restore_folder(); //delete the restore folder if bad
|
309 |
+
die();
|
310 |
+
}
|
311 |
|
312 |
//Validate the restoration
|
313 |
+
$logger->log('Validate restoration directory: ' . $restoration_dir_path .'backupsiteinfo.txt');
|
314 |
if(!glob($restoration_dir_path .'backupsiteinfo.txt') ){
|
315 |
+
$logger->log('Error: backupsiteinfo.txt missing from restore folder: ' .$restoration_dir_path);
|
316 |
write_fatal_error_status('error204');
|
317 |
delete_restore_folder(); //delete the restore folder if bad
|
318 |
die();
|
319 |
}
|
320 |
+
$logger->log('Restoration directory validated: ' .$restoration_dir_path);
|
321 |
return $restoration_dir_path;
|
322 |
}
|
323 |
|
324 |
// Backup the current database try dump first
|
325 |
function backup_database($restore_folder_root){
|
326 |
+
global $logger;
|
327 |
$date = date_i18n('Y-m-d-Hi',current_time( 'timestamp' ));
|
328 |
$backup_file = $restore_folder_root . 'db-backup-' . $date .'.cur';
|
329 |
+
$logger->log('Backup the current database: ' .$backup_file);
|
330 |
+
|
331 |
+
$dbc = new WPBackItUp_SQL($logger);
|
332 |
+
if(!$dbc->mysqldump_export($backup_file)) {
|
333 |
//Try a manual restore since dump didnt work
|
334 |
+
if(!$dbc->manual_export($backup_file)) {
|
335 |
+
$logger->log('Error: Cant backup database:'.$backup_file);
|
336 |
write_fatal_error_status('error205');
|
337 |
delete_restore_folder();
|
338 |
die();
|
339 |
}
|
340 |
}
|
341 |
+
$logger->log('Current database backed up: ' .$backup_file);
|
342 |
return $backup_file;
|
343 |
}
|
344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
//Make sure there IS a backup to restore
|
346 |
+
function validate_SQL_exists($backupSQLFile){
|
347 |
+
global $logger;
|
348 |
+
$logger->log('Check for database backup file:' . $backupSQLFile);
|
349 |
|
350 |
if(!file_exists($backupSQLFile) && !empty($backupSQLFile)) {
|
351 |
+
$logger->log('Error: NO Database backups in backup.');
|
352 |
write_fatal_error_status('error216');
|
353 |
delete_restore_folder();
|
354 |
die();
|
355 |
}
|
356 |
+
$logger->log('Database backup file exist:' . $backupSQLFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
}
|
358 |
|
359 |
//Restore DB
|
360 |
function restore_database(){
|
361 |
+
global $logger;
|
362 |
global $RestorePoint_SQL;
|
363 |
+
$logger->log('Restore the DB to previous state.' . $RestorePoint_SQL);
|
364 |
+
|
365 |
+
$dbc = new WPBackItUp_SQL($logger);
|
366 |
+
if(!$dbc->run_sql_exec($RestorePoint_SQL)) {
|
367 |
+
//Do it manually if the import doesnt work
|
368 |
+
if(!$dbc->run_sql_manual($RestorePoint_SQL)) {
|
369 |
+
$logger->log('Error: Database could not be restored.' .$RestorePoint_SQL);
|
370 |
+
write_fatal_error_status('error223');
|
371 |
+
delete_restore_folder();
|
372 |
+
die();
|
373 |
+
}
|
374 |
}
|
375 |
write_fatal_error_status('error224');
|
376 |
+
$logger->log('Database restored to previous state.');
|
377 |
}
|
378 |
|
379 |
//Run DB restore
|
380 |
function import_backedup_database($backupSQLFile){
|
381 |
+
global $logger;
|
382 |
+
$logger->log('Import the backed up database.');
|
383 |
+
//Try SQL Import first
|
384 |
+
|
385 |
+
$dbc = new WPBackItUp_SQL($logger);
|
386 |
+
if(!$dbc->run_sql_exec($backupSQLFile)) {
|
387 |
+
//Do it manually if the import doesnt work
|
388 |
+
if(!$dbc->run_sql_manual($backupSQLFile)) {
|
389 |
+
$logger->log('Error: Database import error.');
|
390 |
+
write_fatal_error_status('error212');
|
391 |
+
delete_restore_folder();
|
392 |
+
die();
|
393 |
+
}
|
394 |
}
|
395 |
+
$logger->log('Backed up database imported.');
|
396 |
}
|
397 |
|
398 |
//get siteurl
|
399 |
+
function get_siteurl(){
|
400 |
+
global $logger;
|
401 |
global $table_prefix;
|
402 |
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
|
403 |
+
|
404 |
+
$dbc = new WPBackItUp_SQL($logger);
|
405 |
+
$siteurl = $dbc->get_sql_scalar($sql);
|
406 |
if (empty($siteurl)) {
|
407 |
+
$logger->log('Error: Siteurl not found');
|
408 |
write_fatal_error_status('error207');
|
|
|
409 |
delete_restore_folder();
|
410 |
die();
|
411 |
}
|
412 |
+
$logger->log('Siteurl found:' .$siteurl);
|
413 |
return $siteurl;
|
414 |
}
|
415 |
|
416 |
//get homeurl
|
417 |
+
function get_homeurl(){
|
418 |
+
global $logger;
|
419 |
global $table_prefix;
|
420 |
$sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
|
421 |
+
$dbc = new WPBackItUp_SQL($logger);
|
422 |
+
$homeurl = $dbc->get_sql_scalar($sql);
|
423 |
if (empty($homeurl)) {
|
424 |
+
$logger->log('Error: Homeurl not found.');
|
425 |
write_fatal_error_status('error208');
|
|
|
426 |
delete_restore_folder();
|
427 |
die();
|
428 |
}
|
429 |
+
$logger->log('homeurl found:' . $homeurl);
|
430 |
return $homeurl;
|
431 |
}
|
432 |
|
433 |
//get user login
|
434 |
+
function get_user_login($user_id){
|
435 |
+
global $logger;
|
436 |
global $table_prefix;
|
437 |
$sql = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
438 |
+
|
439 |
+
$dbc = new WPBackItUp_SQL($logger);
|
440 |
+
$user_login = $dbc->get_sql_scalar($sql);
|
441 |
if (empty($user_login)) {
|
442 |
+
$logger->log('Error: user_login not found.');
|
443 |
write_fatal_error_status('error209');
|
|
|
444 |
delete_restore_folder();
|
445 |
die();
|
446 |
}
|
447 |
+
$logger->log('user_login found.');
|
448 |
return $user_login;
|
449 |
}
|
450 |
|
451 |
//get user pass
|
452 |
+
function get_user_pass($user_id){
|
453 |
+
global $logger;
|
454 |
global $table_prefix;
|
455 |
$sql = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
|
456 |
+
|
457 |
+
$dbc = new WPBackItUp_SQL($logger);
|
458 |
+
$user_pass = $dbc->get_sql_scalar($sql);
|
459 |
if (empty($user_pass)) {
|
460 |
+
$logger->log('Error: user_pass not found.');
|
461 |
write_fatal_error_status('error210');
|
462 |
+
delete_restore_folder();
|
|
|
463 |
die();
|
464 |
}
|
465 |
+
$logger->log('user_pass found.');
|
466 |
return $user_pass;
|
467 |
}
|
468 |
|
469 |
//get user email
|
470 |
+
function get_user_email($user_id){
|
471 |
+
global $logger;
|
472 |
global $table_prefix;
|
473 |
$sql = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
|
474 |
+
|
475 |
+
$dbc = new WPBackItUp_SQL($logger);
|
476 |
+
$user_email = $dbc->get_sql_scalar($sql);
|
477 |
if (empty($user_email)) {
|
478 |
+
$logger->log('Error: user_email not found.');
|
479 |
write_fatal_error_status('error211');
|
|
|
480 |
delete_restore_folder();
|
481 |
die();
|
482 |
}
|
483 |
+
$logger->log('user_email found.' . $user_email);
|
484 |
return $user_email;
|
485 |
}
|
486 |
|
487 |
+
//Update user credentials
|
488 |
+
function update_user_credentials($table_prefix, $user_login, $user_pass, $user_email, $user_id){
|
489 |
+
global $logger;
|
490 |
$sql = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
|
491 |
+
|
492 |
+
$dbc = new WPBackItUp_SQL($logger);
|
493 |
+
if (!$dbc->run_sql_command($sql)){
|
494 |
+
$logger->log('Error: User Credential database update failed..');
|
495 |
write_warning_status('error215');
|
|
|
496 |
restore_database();
|
497 |
delete_restore_folder();
|
498 |
die();
|
499 |
}
|
500 |
+
$logger->log('User Credential updated in database.');
|
501 |
}
|
502 |
|
503 |
//update the site URL in the restored database
|
504 |
+
function update_siteurl($table_prefix, $current_siteurl){
|
505 |
+
global $logger;
|
506 |
+
$sql = "UPDATE ". $table_prefix ."options SET option_value='" .$current_siteurl ."' WHERE option_name='siteurl'";
|
507 |
+
|
508 |
+
$dbc = new WPBackItUp_SQL($logger);
|
509 |
+
if (!$dbc->run_sql_command($sql)){
|
510 |
+
$logger->log('Error: SiteURL updated failed.');
|
511 |
write_warning_status('error213');
|
|
|
512 |
restore_database();
|
513 |
delete_restore_folder();
|
514 |
die();
|
515 |
}
|
516 |
+
$logger->log('SiteURL updated in database.');
|
517 |
}
|
518 |
|
519 |
//Update homeURL
|
520 |
+
function update_homeurl($table_prefix, $homeurl){
|
521 |
+
global $logger;
|
522 |
+
$sql = "UPDATE ". $table_prefix ."options SET option_value='" .$homeurl ."' WHERE option_name='home'";
|
523 |
+
$dbc = new WPBackItUp_SQL($logger);
|
524 |
+
if (!$dbc->run_sql_command($sql)){
|
525 |
+
$logger->log('Error: HomeURL database update failed..');
|
526 |
write_warning_status('error214');
|
|
|
527 |
restore_database();
|
528 |
delete_restore_folder();
|
529 |
die();
|
530 |
}
|
531 |
+
$logger->log('HomeURL updated in database.');
|
532 |
}
|
533 |
|
534 |
//Delete wp-content content
|
535 |
+
function delete_wpcontent_content($root_folder){
|
536 |
+
global $logger;
|
537 |
+
$logger->log('Delete the wp_content contents:' .$root_folder);
|
538 |
+
$ignore = array(WPBACKITUP__PLUGIN_FOLDER,WPBACKITUP__RESTORE_FOLDER,WPBACKITUP__BACKUP_FOLDER,'debug.log');
|
539 |
+
$filesystem = new WPBackItUp_FileSystem($logger);
|
540 |
+
if(!$filesystem->recursive_delete($root_folder,$ignore)) {
|
541 |
+
$logger->log('Error: Cant delete WPContent:' .$root_folder);
|
542 |
write_warning_status('error217');
|
543 |
restore_database();
|
544 |
delete_restore_folder();
|
545 |
die();
|
546 |
}
|
547 |
+
$logger->log('wp-content has been deleted:' .$root_folder);
|
548 |
}
|
549 |
|
550 |
//Delete plugins content
|
551 |
+
function delete_plugins_content(){
|
552 |
+
global $logger;
|
553 |
+
$plugins_folder=WPBACKITUP__PLUGINS_ROOT_PATH;
|
554 |
+
$logger->log('Delete the plugins contents:' .$plugins_folder);
|
555 |
+
$ignore = array(WPBACKITUP__PLUGIN_FOLDER);
|
556 |
+
$filesystem = new WPBackItUp_FileSystem($logger);
|
557 |
+
if(!$filesystem->recursive_delete($plugins_folder,$ignore)) {
|
558 |
+
$logger->log('Error: Cant delete old WPContent:' .$plugins_folder );
|
559 |
write_warning_status('error217');
|
560 |
restore_database();
|
561 |
delete_restore_folder();
|
562 |
die();
|
563 |
}
|
564 |
+
$logger->log('Plugins content deleted:' .$plugins_folder);
|
565 |
}
|
566 |
|
567 |
|
568 |
//Delete themes content
|
569 |
+
function delete_themes_content(){
|
570 |
+
global $logger;
|
571 |
+
$themes_folder=WPBACKITUP__THEMES_ROOT_PATH ;
|
572 |
+
$logger->log('Delete the themes contents:' .$themes_folder);
|
573 |
+
$filesystem = new WPBackItUp_FileSystem($logger);
|
574 |
+
if(!$filesystem->recursive_delete($themes_folder)) {
|
575 |
+
$logger->log('Error: Cant delete old WPContent:' .$themes_folder );
|
576 |
write_warning_status('error217');
|
577 |
restore_database();
|
578 |
delete_restore_folder();
|
579 |
die();
|
580 |
}
|
581 |
+
$logger->log('Themes content deleted:' .$themes_folder);
|
582 |
}
|
583 |
|
584 |
//Restore all wp content from zip
|
585 |
function restore_wpcontent($restoration_dir_path){
|
586 |
+
global $logger;
|
587 |
+
$logger->log('Copy content folder from:' .$restoration_dir_path);
|
588 |
+
$logger->log('Copy content folder to:' .WPBACKITUP__CONTENT_PATH);
|
589 |
+
$ignore = array(WPBACKITUP__PLUGIN_FOLDER, WPBACKITUP__BACKUP_FOLDER,WPBACKITUP__RESTORE_FOLDER, 'status.log','debug.log', WPBACKITUP__SQL_DBBACKUP_FILENAME, 'backupsiteinfo.txt');
|
590 |
+
$filesystem = new WPBackItUp_FileSystem($logger);
|
591 |
+
if(!$filesystem->recursive_copy($restoration_dir_path,WPBACKITUP__CONTENT_PATH. '/',$ignore)) {
|
592 |
+
$logger->log('Error: Content folder was not copied successfully');
|
593 |
write_warning_status('error219');
|
594 |
restore_database();
|
595 |
delete_restore_folder();
|
596 |
die();
|
597 |
}
|
598 |
+
$logger->log('Content folder copied successfully');
|
599 |
+
}
|
600 |
+
|
601 |
+
//Restore all wp content from zip
|
602 |
+
function validate_wpcontent($source_dir_path,$target_dir_path){
|
603 |
+
global $logger;
|
604 |
+
$logger->log('Validate content folder TO:' .$source_dir_path);
|
605 |
+
$logger->log('Validate content folder FROM:' .$target_dir_path);
|
606 |
+
|
607 |
+
$ignore = array(WPBACKITUP__PLUGIN_FOLDER,'debug.log','backupsiteinfo.txt','db-backup.sql');
|
608 |
+
$filesystem = new WPBackItUp_FileSystem($logger);
|
609 |
+
if(!$filesystem->recursive_validate($source_dir_path. '/', $target_dir_path . '/',$ignore)) {
|
610 |
+
$logger->log('Error: Content folder is not the same as backup.');
|
611 |
+
}
|
612 |
+
|
613 |
+
$logger->log('Content folder validation complete.');
|
614 |
}
|
615 |
|
616 |
//Delete the restoration directory
|
617 |
function cleanup_restore_folder($restoration_dir_path){
|
618 |
+
global $logger;
|
619 |
+
$logger->log('Cleanup the restore folder: ' .$restoration_dir_path);
|
620 |
if(!delete_restore_folder()) {
|
621 |
+
$logger->log('Error: Cleanup restore folder failed: ' .$restoration_dir_path);
|
622 |
write_warning_status('error220'); //NOT fatal
|
623 |
} else {
|
624 |
+
$logger->log('Restore folder cleaned successfully: ' .$restoration_dir_path);
|
625 |
}
|
626 |
+
}
|
627 |
+
function update_permalinks(){
|
628 |
+
global $wp_rewrite, $logger;
|
629 |
+
try {
|
630 |
+
$old_permalink_structure = $wp_rewrite->permalink_structure;
|
631 |
+
$wp_rewrite->set_permalink_structure($old_permalink_structure);
|
632 |
+
$wp_rewrite->flush_rules( true );//Update permalinks - hard flush
|
633 |
+
}catch(Exception $e) {
|
634 |
+
$logger->log('(restore.update_permalinks) Exception: ' .$e);
|
635 |
+
return false;
|
636 |
+
}
|
637 |
+
$logger->log('(restore.update_permalinks) Permalinks updated.');
|
638 |
+
return true;
|
639 |
}
|
lib/includes/upload.php
CHANGED
@@ -1,45 +1,113 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
/**
|
4 |
* WP BackItUp File Upload Handler
|
5 |
*
|
6 |
* @package WP BackItUp Pro
|
7 |
*
|
8 |
* @author cssimmon
|
9 |
-
*
|
10 |
-
* @since 1.0.1
|
11 |
-
*
|
12 |
*/
|
13 |
|
14 |
-
/*** Includes ***/
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed (upload)');
|
|
|
2 |
/**
|
3 |
* WP BackItUp File Upload Handler
|
4 |
*
|
5 |
* @package WP BackItUp Pro
|
6 |
*
|
7 |
* @author cssimmon
|
8 |
+
*
|
|
|
|
|
9 |
*/
|
10 |
|
11 |
+
/*** Includes ***/
|
12 |
+
|
13 |
+
|
14 |
+
/*** Globals ***/
|
15 |
+
global $logger;
|
16 |
+
$logger = new WPBackItUp_Logger(true,null,'upload');
|
17 |
+
$backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
|
18 |
+
|
19 |
+
//*****************//
|
20 |
+
//*** MAIN CODE ***//
|
21 |
+
//*****************//
|
22 |
+
$logger->log('***BEGIN UPLOAD***');
|
23 |
+
|
24 |
+
//Initialize return class
|
25 |
+
$rtnData = new stdClass();
|
26 |
+
$rtnData->file = '';
|
27 |
+
$rtnData->zip_link = '';
|
28 |
+
$rtnData->msg = '';
|
29 |
+
$rtnData->error = '';
|
30 |
+
|
31 |
+
|
32 |
+
if ( !wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-upload-file') || !check_admin_referer( WPBACKITUP__NAMESPACE .'-upload-file', '_wpnonce' )) {
|
33 |
+
$rtnData->error ='Invalid Nonce';
|
34 |
+
|
35 |
+
}else{
|
36 |
+
foreach ($_FILES as $key => $value)
|
37 |
+
{
|
38 |
+
//GET FILE CONTENT
|
39 |
+
$logger->log("File Uploaded Key: " . $key);
|
40 |
+
$logger->log("File Uploaded Value");
|
41 |
+
$logger->log($value);
|
42 |
+
|
43 |
+
$temp_file_path= $value['tmp_name'];
|
44 |
+
$original_file_name = $value['name'];
|
45 |
+
$save_to_file_path = $backup_folder_root . $original_file_name;
|
46 |
+
$error = $value['error'];
|
47 |
+
$size = $value['size'];
|
48 |
+
$error_message = get_error_message($error);
|
49 |
+
|
50 |
+
$logger->log("Temp File Uploaded: " . $temp_file_path);
|
51 |
+
$logger->log("Original File Name: " .$original_file_name);
|
52 |
+
$logger->log("Save to File path: " .$save_to_file_path);
|
53 |
+
$logger->log("Error: " .$error);
|
54 |
+
$logger->log("Size: " .$size);
|
55 |
+
$logger->log("Error Message:" . $error_message);
|
56 |
+
|
57 |
+
//Handle the file upload
|
58 |
+
if (is_uploaded_file($value['tmp_name'])) {
|
59 |
+
if (move_uploaded_file($value['tmp_name'], $save_to_file_path)) {
|
60 |
+
$rtnData->msg = 'success';
|
61 |
+
$rtnData->file = $original_file_name;
|
62 |
+
$rtnData->zip_link = WPBACKITUP__BACKUP_URL .'/' .$original_file_name;
|
63 |
+
} else {
|
64 |
+
$error_message='File could not be saved to backup folder.';
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
$rtnData->error = $error_message;
|
69 |
+
break; //Only one file is ever uploaded
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
echo json_encode($rtnData);
|
74 |
+
|
75 |
+
$logger->log('Upload completed successfully');
|
76 |
+
$logger->log('***END UPLOAD***');
|
77 |
+
die();
|
78 |
+
|
79 |
+
/******************/
|
80 |
+
/*** Functions ***/
|
81 |
+
/******************/
|
82 |
+
function get_error_message($code)
|
83 |
+
{
|
84 |
+
if (0==$code) return '';
|
85 |
+
|
86 |
+
switch ($code) {
|
87 |
+
case UPLOAD_ERR_INI_SIZE:
|
88 |
+
$message = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
|
89 |
+
break;
|
90 |
+
case UPLOAD_ERR_FORM_SIZE:
|
91 |
+
$message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
|
92 |
+
break;
|
93 |
+
case UPLOAD_ERR_PARTIAL:
|
94 |
+
$message = "The uploaded file was only partially uploaded";
|
95 |
+
break;
|
96 |
+
case UPLOAD_ERR_NO_FILE:
|
97 |
+
$message = "No file was uploaded";
|
98 |
+
break;
|
99 |
+
case UPLOAD_ERR_NO_TMP_DIR:
|
100 |
+
$message = "Missing a temporary folder";
|
101 |
+
break;
|
102 |
+
case UPLOAD_ERR_CANT_WRITE:
|
103 |
+
$message = "Failed to write file to disk";
|
104 |
+
break;
|
105 |
+
case UPLOAD_ERR_EXTENSION:
|
106 |
+
$message = "File upload stopped by extension";
|
107 |
+
break;
|
108 |
+
default:
|
109 |
+
$message = "Unknown upload error";
|
110 |
+
break;
|
111 |
+
}
|
112 |
+
return $message;
|
113 |
+
}
|
lib/includes/viewlog.php
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed (viewlog)');
|
2 |
+
|
3 |
+
|
4 |
+
if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
5 |
+
&& isset($_REQUEST['viewlog_log']) && !empty($_REQUEST['viewlog_log']) ){
|
6 |
+
|
7 |
+
if ( wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-viewlog')) {
|
8 |
+
|
9 |
+
$log_filename = $_REQUEST['viewlog_log']. '.log';
|
10 |
+
$log_path = WPBACKITUP__BACKUP_PATH .'/' .$log_filename ;
|
11 |
+
|
12 |
+
if(file_exists($log_path) ) {
|
13 |
+
header ('Content-type: octet/stream');
|
14 |
+
header("Content-Disposition: attachment; filename=$log_filename");
|
15 |
+
header("Content-Length: ".filesize($log_path));
|
16 |
+
ob_get_clean();
|
17 |
+
readfile($log_path);
|
18 |
+
if (ob_get_level()>1) ob_end_flush();
|
19 |
+
die();
|
20 |
+
}
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
//Return empty file
|
25 |
+
header ('Content-type: octet/stream');
|
26 |
+
header("Content-Disposition: attachment; filename=empty.log");
|
27 |
+
header("Content-Length: 100");
|
28 |
+
ob_get_clean();
|
29 |
+
echo('No log file found.'. PHP_EOL);
|
30 |
+
//echo($_REQUEST['_wpnonce']. PHP_EOL);
|
31 |
+
//echo($_REQUEST['viewlog_log']. PHP_EOL);
|
32 |
+
if (ob_get_level()>1) ob_end_flush();
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.wpbackitup.com
|
|
4 |
Tags: backup wordpress, database backup, backup database, download database, backup and restore, restoring wordpress, restore wordpress, restore wordpress backup
|
5 |
Requires at least: 3.4.2
|
6 |
Tested up to: 3.9.1
|
7 |
-
Stable tag: 1.6.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -23,7 +23,7 @@ Tired of messing around in PHPMyAdmin and with FTP trying to restore you backups
|
|
23 |
Simply install the plugin directly to Wordpress and browse to the new menu 'WP Backitup'. From there, just follow the on-screen instructions and watch as WP Backitup creates a backup of you site's plugins, themes and uploads as well as you content and settings (including all custom widgets and settings for any additional plugins).
|
24 |
|
25 |
= Where can I purchase a license? =
|
26 |
-
You can <a href="http://www.wpbackitup.com
|
27 |
|
28 |
= More questions? =
|
29 |
Please ask them in the <a href="http://wordpress.org/support/plugin/wp-backitup">support forum</a>.
|
@@ -44,7 +44,7 @@ Installation of the plugin is straightforward:
|
|
44 |
Sure! The backup zips generated by WP Backitup contain a database dump and a copy of your wp-content directory. Simply upload your files and import your database.
|
45 |
|
46 |
= Is there an easier way to restore my backup zips? =
|
47 |
-
Yes, purchase and download <a href="http://www.wpbackitup.com
|
48 |
|
49 |
= Will the plugin work on shared hosting/sub domains/webhost xxx? =
|
50 |
Yes.
|
@@ -91,6 +91,15 @@ Yes.
|
|
91 |
3. When the backup has been created, click the download link to access a zipped backup of your site.
|
92 |
|
93 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
= 1.6.7 =
|
95 |
* Wordpress 3.9.1 support
|
96 |
* Unicode fix to support utf8 content
|
4 |
Tags: backup wordpress, database backup, backup database, download database, backup and restore, restoring wordpress, restore wordpress, restore wordpress backup
|
5 |
Requires at least: 3.4.2
|
6 |
Tested up to: 3.9.1
|
7 |
+
Stable tag: 1.6.7
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
23 |
Simply install the plugin directly to Wordpress and browse to the new menu 'WP Backitup'. From there, just follow the on-screen instructions and watch as WP Backitup creates a backup of you site's plugins, themes and uploads as well as you content and settings (including all custom widgets and settings for any additional plugins).
|
24 |
|
25 |
= Where can I purchase a license? =
|
26 |
+
You can <a href="http://www.wpbackitup.com">purchase a no-risk WP Backitup license</a> from the WP Backitup site. This will allow you to restore your backups from the Wordpress dashboard in minutes or get a full money-back refund.
|
27 |
|
28 |
= More questions? =
|
29 |
Please ask them in the <a href="http://wordpress.org/support/plugin/wp-backitup">support forum</a>.
|
44 |
Sure! The backup zips generated by WP Backitup contain a database dump and a copy of your wp-content directory. Simply upload your files and import your database.
|
45 |
|
46 |
= Is there an easier way to restore my backup zips? =
|
47 |
+
Yes, purchase and download <a href="http://www.wpbackitup.com" title="WP Backitup">WP Backitup</a>. Once installed, you'll be able to restore you backup zips without FTP or MySQL.
|
48 |
|
49 |
= Will the plugin work on shared hosting/sub domains/webhost xxx? =
|
50 |
Yes.
|
91 |
3. When the backup has been created, click the download link to access a zipped backup of your site.
|
92 |
|
93 |
== Changelog ==
|
94 |
+
= 1.7.0 =
|
95 |
+
* Security enhancements
|
96 |
+
* Major user interface improvements
|
97 |
+
* Improvements to upload functionality
|
98 |
+
* Add Feature: Backup Email Notifications
|
99 |
+
* Add Feature: Backup Retention
|
100 |
+
* Bug fix: Create Backup & Restore folders on activation
|
101 |
+
* Updates to license activation
|
102 |
+
|
103 |
= 1.6.7 =
|
104 |
* Wordpress 3.9.1 support
|
105 |
* Unicode fix to support utf8 content
|
views/backup.php
ADDED
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
|
4 |
+
$page_title = $this->friendly_name . ' Backup';
|
5 |
+
$namespace = $this->namespace;
|
6 |
+
|
7 |
+
//Path Variables
|
8 |
+
$backup_folder_root = WPBACKITUP__BACKUP_PATH;
|
9 |
+
|
10 |
+
//Get license info
|
11 |
+
$version = $this->version;
|
12 |
+
$license_key = $this->license_key();
|
13 |
+
$license_active = $this->license_active();
|
14 |
+
|
15 |
+
$license_type = $this->license_type();
|
16 |
+
$license_type_description = $this->license_type_description();
|
17 |
+
if (!empty($license_type_description)){
|
18 |
+
$license_type_description = ucfirst($license_type_description);
|
19 |
+
}
|
20 |
+
|
21 |
+
$license_status = $this->license_status();
|
22 |
+
$license_status_message = $this->license_status_message();
|
23 |
+
|
24 |
+
$license_Expires = $this->license_expires();
|
25 |
+
$formatted_expired_date = date('F j, Y',strtotime($license_Expires));
|
26 |
+
|
27 |
+
// get retention number set
|
28 |
+
$retain_archives = $this->backup_retained_number();
|
29 |
+
|
30 |
+
?>
|
31 |
+
<script type="text/javascript">var __namespace = "<?php echo($namespace); ?>";</script>
|
32 |
+
<div class="wrap">
|
33 |
+
<h2><?php echo $page_title; ?></h2>
|
34 |
+
<div id="content">
|
35 |
+
<div class="widget">
|
36 |
+
<h3><i class="fa fa-cogs"></i> <?php _e('Backup', $namespace); ?></h3>
|
37 |
+
<p><b>Click the backup button to create a zipped backup file of this site's database, plugins, themes and settings.</b></p>
|
38 |
+
<p>Once your backup file has been created it will appear in the available backups section below. This file can remain on your hosting providers server but we recommend that you download and save it somewhere safe.</p>
|
39 |
+
<p> Licensed WP BackItUp users can use these backup files to perform an automated restore of their site.</p>
|
40 |
+
<p><input type="submit" id="backup-button" class="backup-button button-primary" value="<?php _e("Backup", $namespace) ?>"/><img class="backup-icon status-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></p>
|
41 |
+
<?php
|
42 |
+
//Display a note for lite customers
|
43 |
+
if (!$license_active)
|
44 |
+
echo '<p> * WP BackItUp Lite customers may use these backup files to manually restore their site. Please visit <a href="'.WPBACKITUP__SITE_URL .'" target="_blank">' .WPBACKITUP__SITE_URL .'</a> for manual restore instructions.</p>';
|
45 |
+
?>
|
46 |
+
</div>
|
47 |
+
|
48 |
+
<!--Available Backups section-->
|
49 |
+
<div class="widget">
|
50 |
+
<h3><i class="fa fa-cloud-download"></i> <?php _e('Available Backups', $namespace); ?></h3>
|
51 |
+
|
52 |
+
<!--View Log Form-->
|
53 |
+
<form id = "viewlog" name = "viewlog" action="admin-post.php" method="post">
|
54 |
+
<input type="hidden" name="action" value="viewlog">
|
55 |
+
<input type="hidden" id="viewlog_log" name="viewlog_log" value="test">
|
56 |
+
<?php wp_nonce_field($this->namespace . "-viewlog"); ?>
|
57 |
+
</form>
|
58 |
+
|
59 |
+
<table class="widefat" id="datatable">
|
60 |
+
<?php
|
61 |
+
|
62 |
+
//Get Zip File List
|
63 |
+
$zip_filelist = glob($backup_folder_root . "/*.zip");
|
64 |
+
$log_filelist = glob($backup_folder_root . "/*.log");
|
65 |
+
|
66 |
+
if (glob($backup_folder_root . "/*.zip"))
|
67 |
+
{
|
68 |
+
//Sort by Date Time
|
69 |
+
usort($zip_filelist, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
|
70 |
+
|
71 |
+
$i = 0;
|
72 |
+
foreach ($zip_filelist as $zip_file)
|
73 |
+
{
|
74 |
+
if( $retain_archives && $retain_archives == $i)
|
75 |
+
break;
|
76 |
+
|
77 |
+
$zip_filename = basename($zip_file);
|
78 |
+
//Local Date Time
|
79 |
+
$zip_datetime = get_date_from_gmt(date('Y-m-d H:i:s', filemtime($zip_file)), 'Y-m-d g:i a');
|
80 |
+
|
81 |
+
//Check for log
|
82 |
+
$log_file = str_replace('.zip','.log',$zip_file);
|
83 |
+
$log_filename = basename($log_file);
|
84 |
+
|
85 |
+
$logExists=false;
|
86 |
+
if (in_array($log_file,$log_filelist)) $logExists=true;
|
87 |
+
|
88 |
+
|
89 |
+
$class = $i % 2 == 0 ? 'class="alternate"' : '';
|
90 |
+
?>
|
91 |
+
|
92 |
+
<tr <?php echo $class ?> id="row<?php echo $i; ?>">
|
93 |
+
<td><?php echo $zip_datetime ?></td>
|
94 |
+
<td><?php echo $zip_filename ?></td>
|
95 |
+
<td><a href="<?php echo WPBACKITUP__BACKUP_URL ?>/<?php echo $zip_filename; ?>">Download</a></td>
|
96 |
+
<?php if ($logExists) :?>
|
97 |
+
<td><a class='viewloglink' href="<?php echo basename($log_filename, ".log") ?>">View Log</a></td>
|
98 |
+
<?php else: ?>
|
99 |
+
<td> </td>
|
100 |
+
<?php endif; ?>
|
101 |
+
<td><a href="#" title="<?php echo $zip_filename; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
|
102 |
+
|
103 |
+
</tr>
|
104 |
+
|
105 |
+
<?php
|
106 |
+
$i++;
|
107 |
+
}
|
108 |
+
}
|
109 |
+
else
|
110 |
+
{
|
111 |
+
echo '<tr id="nofiles"><td colspan="3">No backup archives available for download.</td></tr>';
|
112 |
+
}
|
113 |
+
?>
|
114 |
+
</table>
|
115 |
+
|
116 |
+
<?php
|
117 |
+
//Display restore note for lite customers
|
118 |
+
if (!$license_active)
|
119 |
+
echo '<p>* The automated restore feature is only available to licensed WP BackItUp customers. Please visit <a href="'.WPBACKITUP__SITE_URL .'" target="_blank">' .WPBACKITUP__SITE_URL .'</a> to get WP BackItUp risk free for 30 days.</p>';
|
120 |
+
?>
|
121 |
+
</div>
|
122 |
+
|
123 |
+
<div id="status" class="widget">
|
124 |
+
<h3><i class="fa fa-check-square-o"></i> <?php _e('Status', $namespace); ?></h3>
|
125 |
+
|
126 |
+
<!--default status message-->
|
127 |
+
<ul class="default-status">
|
128 |
+
<li><?php _e('Nothing to report', $namespace); ?></li>
|
129 |
+
</ul>
|
130 |
+
|
131 |
+
|
132 |
+
<!--backup status messages-->
|
133 |
+
<ul class="backup-status">
|
134 |
+
<li class="preparing"><?php _e('Preparing for backup', $namespace); ?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
135 |
+
<li class='backupdb'><?php _e('Backing-up database', $namespace); ?>...<span class='status-icon'><img class="backupdb-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
136 |
+
<li class='infofile'><?php _e('Creating backup information file', $namespace); ?>...<span class='status-icon'><img class="infofile-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
137 |
+
<li class='backupfiles'><?php _e('Backing up plugins, themes, and uploads', $namespace); ?>...<span class='status-icon'><img class="backupfiles-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
138 |
+
<li class='zipfile'><?php _e('Zipping backup directory', $namespace); ?>...<span class='status-icon'><img class="zipfile-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
139 |
+
<li class='cleanup'><?php _e('Cleaning up', $namespace); ?>...<span class='status-icon'><img class="cleanup-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
140 |
+
</ul>
|
141 |
+
|
142 |
+
<!--backup error messages-->
|
143 |
+
<div class="backup-errors">
|
144 |
+
<span class="error101"><div class='isa_error'><?php _e('Error 101: Unable to create a new directory for backup. Please check your CHMOD settings of your wp-backitup backup directory', $namespace); ?>.</div></span>
|
145 |
+
<span class="error102"><div class='isa_error'><?php _e('Error 102: Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory', $namespace); ?>.</div></span>
|
146 |
+
<span class="error103"><div class='isa_error'><?php _e('Error 103: Unable to backup your files. Please try again', $namespace); ?>.</div></span>
|
147 |
+
<span class="error104"><div class='isa_error'><?php _e('Error 104: Unable to backup your database. Please try again', $namespace); ?>.</div></span>
|
148 |
+
<span class="error105"><div class='isa_error'><?php _e('Error 105: Unable to create site information file. Please try again', $namespace); ?>.</div></span>
|
149 |
+
<span class="error106"><div class='isa_warning'><?php _e('Warning 106: Unable to cleanup your backup directory', $namespace); ?>.</div></span>
|
150 |
+
|
151 |
+
<span class="error114"><div class='isa_error'><?php _e('Error 114: Your database was accessible but an export could not be created. Please contact support by clicking the get support link on the right. Please let us know who your host is when you submit the request', $namespace); ?>.</div></span>
|
152 |
+
</div>
|
153 |
+
|
154 |
+
<!--Upload status messages-->
|
155 |
+
<ul class="backup-unexpected-error">
|
156 |
+
<span class='error999'><div class='isa_error'><?php _e('An unexpected error has occurred. ', $namespace); ?></div></span>
|
157 |
+
</ul>
|
158 |
+
|
159 |
+
<!--success messages-->
|
160 |
+
<div class="backup-success">
|
161 |
+
<span class='finalinfo'><div class='isa_success'><?php _e('Backup completed successfully. ', $namespace); ?></div></span>
|
162 |
+
</div>
|
163 |
+
|
164 |
+
</div>
|
165 |
+
|
166 |
+
<!--Debug Widget-->
|
167 |
+
<?php if (WP_DEBUG===true) :?>
|
168 |
+
<div class="widget">
|
169 |
+
<h3><i class="fa fa-wrench"></i> <?php _e('Debug', $namespace); ?></h3>
|
170 |
+
<div id="php"><p>Debugging is turned on in your wp-config.php file and should only be used when troubleshooting issues on your site.</p></div>
|
171 |
+
</div>
|
172 |
+
<?php endif; ?>
|
173 |
+
|
174 |
+
</div>
|
175 |
+
|
176 |
+
|
177 |
+
|
178 |
+
<div id="sidebar">
|
179 |
+
<!-- Display opt-in form if the user is unregistered -->
|
180 |
+
<?php if (!$license_active) : ?>
|
181 |
+
<div class="widget">
|
182 |
+
<h3 class="promo"><?php _e('Get a license', $namespace); ?></h3>
|
183 |
+
<p><?php _e('Tired of messing with FTP, MySQL and PHPMyAdmin? Restore your backups from this page in minutes or your money back', $namespace); ?>.</p>
|
184 |
+
<a href="<?php _e(WPBACKITUP__SITE_URL, $namespace); ?>" target="blank"><?php _e('Purchase a license for WP BackItUp', $namespace); ?></a>
|
185 |
+
</div>
|
186 |
+
<?php endif; ?>
|
187 |
+
|
188 |
+
|
189 |
+
<!-- Display license key widget -->
|
190 |
+
<form action="" method="post" id="<?php echo $namespace; ?>-form">
|
191 |
+
<?php wp_nonce_field($namespace . "-update-options"); ?>
|
192 |
+
<div class="widget">
|
193 |
+
<h3 class="promo"><?php _e('License v ' . $version, $namespace); ?></h3>
|
194 |
+
<?php
|
195 |
+
|
196 |
+
$fontColor='green';
|
197 |
+
if ($license_status=='valid')
|
198 |
+
$fontColor='green';
|
199 |
+
|
200 |
+
if ($license_status=='invalid')
|
201 |
+
$fontColor='red';
|
202 |
+
|
203 |
+
if ($license_status=='expired')
|
204 |
+
$fontColor='orange';
|
205 |
+
|
206 |
+
$license_message='';
|
207 |
+
if (!empty($license_status)) {
|
208 |
+
$license_message=' License Status: ' . $license_status;
|
209 |
+
}
|
210 |
+
|
211 |
+
if($license_active)
|
212 |
+
echo '<p>' . $license_type_description .' License Key</p>';
|
213 |
+
else
|
214 |
+
echo '<p>Enter your license key to activate features.</p>';
|
215 |
+
?>
|
216 |
+
|
217 |
+
<input type="text" name="data[license_key]" id="license_key" value="<?php _e($license_key, $namespace); ?>" />
|
218 |
+
<div style="color:<?php _e($fontColor); ?>"><?php _e($license_message, $namespace); ?></div>
|
219 |
+
<div style="color:<?php _e($fontColor); ?>"><?php _e($license_status_message, $namespace); ?></div>
|
220 |
+
|
221 |
+
<?php if ($license_status=='expired'): ?>
|
222 |
+
<div>License expired: <span style="color:red"><?php _e($formatted_expired_date, $namespace); ?></span></div>
|
223 |
+
<?php endif; ?>
|
224 |
+
|
225 |
+
<?php if ($license_active) : ?>
|
226 |
+
<div class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e("Update", $namespace) ?>" /></div>
|
227 |
+
<?php endif; ?>
|
228 |
+
|
229 |
+
<?php if (!$license_active) : ?>
|
230 |
+
<p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e("Activate", $namespace) ?>" /></p>
|
231 |
+
<?php endif; ?>
|
232 |
+
|
233 |
+
<?php if ($license_status=='invalid' || $license_status==''): ?>
|
234 |
+
<p><?php _e('Purchase a <a href="'. WPBACKITUP__SITE_URL .'" target="blank">no-risk </a>license using the purchase link above', $namespace); ?>.</p>
|
235 |
+
<?php endif; ?>
|
236 |
+
|
237 |
+
<?php if ($license_status=='expired'): ?>
|
238 |
+
<div>License expired? <?php _e('Click <a href="'. WPBACKITUP__SITE_URL .'/expired-license" target="blank">here </a>for more info.', $namespace); ?> </div>
|
239 |
+
<?php endif; ?>
|
240 |
+
|
241 |
+
|
242 |
+
</div>
|
243 |
+
|
244 |
+
<!-- Display links widget -->
|
245 |
+
<div class="widget">
|
246 |
+
<h3 class="promo"><?php _e('Useful Links', $namespace); ?></h3>
|
247 |
+
<ul>
|
248 |
+
<?php if ($license_active) : ?>
|
249 |
+
<li><a href="<?php _e(WPBACKITUP__SITE_URL, $namespace); ?>/your-account/" target="_blank"><?php _e('Your account', $namespace); ?></a></li>
|
250 |
+
<li><a href="<?php _e(WPBACKITUP__SITE_URL, $namespace); ?>" target="_blank"><?php _e('Upgrade your license', $namespace); ?></a></li>
|
251 |
+
<?php endif; ?>
|
252 |
+
<li><a href="<?php _e(WPBACKITUP__SITE_URL, $namespace); ?>/help" target="_blank"><?php _e('Help', $namespace); ?></a></li>
|
253 |
+
<li><a href="<?php _e(WPBACKITUP__SITE_URL, $namespace); ?>/support" target="_blank"><?php _e('Get support', $namespace); ?></a></li>
|
254 |
+
<li><a href="<?php _e(WPBACKITUP__SITE_URL, $namespace); ?>/feature-request" target="_blank"><?php _e('Feature Request', $namespace); ?></a></li>
|
255 |
+
<li>Have a suggestion? Why not submit a feature request.</li>
|
256 |
+
</ul>
|
257 |
+
</div>
|
258 |
+
</form>
|
259 |
+
|
260 |
+
</div>
|
261 |
+
</div>
|
262 |
+
|
views/options.php
DELETED
@@ -1,281 +0,0 @@
|
|
1 |
-
<script type="text/javascript">var __namespace = '<?php echo $namespace; ?>';</script>
|
2 |
-
<div class="wrap">
|
3 |
-
<div id="wp-backitup-icon" class="icon32"><img src="<?php echo plugin_dir_url(dirname(__FILE__) ); ?>images/icon32.png" alt="WP Backitup Icon" height="32" width="32" /></div>
|
4 |
-
<h2>WPBackItUp Options</h2>
|
5 |
-
<div id="content">
|
6 |
-
|
7 |
-
<!--Backup section-->
|
8 |
-
<div class="widget">
|
9 |
-
<h3><?php _e('Backup', $namespace );?></h3>
|
10 |
-
<p><?php _e('Click the backup button to create a zipped backup file of this site\'s database, plugins, themes and settings.', $namespace ) ;?></p>
|
11 |
-
<p>
|
12 |
-
Once your backup file has been created it will appear in the available backups section below. This file can remain on your hosting providers server but we recommend that you download and save it somewhere safe.
|
13 |
-
</p>
|
14 |
-
<p> WPBackitUp Pro users can use these backup files to perform an automated restore of their site.</p>
|
15 |
-
<p><input type="submit" id="backup-button" class="backup-button button-primary" value="<?php _e( "Backup", $namespace ) ?>"</><img class="backup-icon status-icon" src="<?php echo WPBACKITUP_URLPATH. "/images/loader.gif"; ?>" height="16" width="16" /></p>
|
16 |
-
|
17 |
-
<?php
|
18 |
-
//Display a note for lite customers
|
19 |
-
if(!license_active())
|
20 |
-
{
|
21 |
-
echo '<p> * WPBackItUp Lite customers may use these backup files to manually restore their site. Please visit <a href="http://www.wpbackitup.com/wp-backitup-pro/" target="_blank">www.wpbackitup.com</a> for manual restore instructions.</p>';
|
22 |
-
}
|
23 |
-
?>
|
24 |
-
</div>
|
25 |
-
|
26 |
-
<!--Available Backups section-->
|
27 |
-
<div class="widget">
|
28 |
-
<h3><?php _e('Available Backups', $namespace); ?></h3>
|
29 |
-
<table class="widefat" id="datatable">
|
30 |
-
<?php
|
31 |
-
|
32 |
-
//Get Zip File List
|
33 |
-
$backup_folder_root = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/';
|
34 |
-
$zipFileList = glob($backup_folder_root ."*.zip");
|
35 |
-
|
36 |
-
//Sort by Date Time
|
37 |
-
usort($zipFileList, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
|
38 |
-
|
39 |
-
if (glob($backup_folder_root ."*.zip"))
|
40 |
-
{
|
41 |
-
$i = 0;
|
42 |
-
foreach ($zipFileList as $file)
|
43 |
-
{
|
44 |
-
$filename = basename($file);
|
45 |
-
$fileDateTime=get_date_from_gmt(date( 'Y-m-d H:i:s', filemtime($file)), 'Y-m-d g:i a' ); //Local Date Time
|
46 |
-
$class = $i % 2 == 0 ? 'class="alternate"' : '';
|
47 |
-
?>
|
48 |
-
<tr <?php echo $class ?> id="row<?php echo $i; ?>">
|
49 |
-
<td><?php echo $filename?></td>
|
50 |
-
<td><a href="<?php echo WPBACKITUP_BACKUPFILE_URLPATH ?>/<?php echo $filename; ?>">Download</a></td>
|
51 |
-
<td><a href="#" title="<?php echo $filename; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
|
52 |
-
<?php
|
53 |
-
if (license_active()) {
|
54 |
-
echo '<td><a href="#" title="' . $filename . '" class="restoreRow" id="restoreRow' . $i . '">Restore</a></td>';
|
55 |
-
}
|
56 |
-
?>
|
57 |
-
</tr>
|
58 |
-
<?php
|
59 |
-
$i++;
|
60 |
-
}
|
61 |
-
}
|
62 |
-
else
|
63 |
-
{
|
64 |
-
echo '<tr id="nofiles"><td colspan="3">No export file available for download. Please create one.</td></tr>';
|
65 |
-
}
|
66 |
-
?>
|
67 |
-
</table>
|
68 |
-
|
69 |
-
<form id="restore-form" method="post" action="<?php echo WPBACKITUP_URLPATH . '/lib/includes/restore.php'; ?>">
|
70 |
-
<?php global $current_user; ?>
|
71 |
-
<input type="hidden" name="user_id" value="<?php echo $current_user->ID; ?>" />
|
72 |
-
<input type="hidden" name="is_selected" id="is_selected" value="0" />
|
73 |
-
<input type="hidden" name="selected_file" id="selected_file" value="" />
|
74 |
-
</form>
|
75 |
-
|
76 |
-
<?php
|
77 |
-
//Display restore note for lite customers
|
78 |
-
if (!license_active()) {
|
79 |
-
echo '<p>* The automated restore feature is only available to Pro customers. Please visit <a href="http://www.wpbackitup.com/wp-backitup-pro/" target="_blank">www.wpbackitup.com</a> to get WPBackItUp Pro risk free for 30 days.</p>' ;
|
80 |
-
}
|
81 |
-
?>
|
82 |
-
</div>
|
83 |
-
|
84 |
-
<!--Disable upload form if the user has not activated-->
|
85 |
-
<?php
|
86 |
-
if( license_active())
|
87 |
-
{ ?>
|
88 |
-
<div class="widget">
|
89 |
-
<h3>
|
90 |
-
<?php _e('Upload', $namespace );?>
|
91 |
-
</h3>
|
92 |
-
<iframe id="upload_target" name="upload_target" src=""></iframe>
|
93 |
-
<p>
|
94 |
-
<?php _e('Upload a WP BackItUp zip file to add it to your list of available backups.', $namespace );?>
|
95 |
-
</p>
|
96 |
-
<?php
|
97 |
-
$max_upload = (int)(ini_get('upload_max_filesize'));
|
98 |
-
$max_post = (int)(ini_get('post_max_size'));
|
99 |
-
$memory_limit = (int)(ini_get('memory_limit'));
|
100 |
-
$upload_mb = min($max_upload, $max_post, $memory_limit);
|
101 |
-
?>
|
102 |
-
<p>
|
103 |
-
<?php _e( 'The maximum file size your hosting provider allows you to upload is ', $namespace );
|
104 |
-
echo $upload_mb .'MB.'; ?>
|
105 |
-
</p>
|
106 |
-
<form id="upload-form" method="post" enctype="multipart/form-data" action="<?php echo WPBACKITUP_URLPATH . '/lib/includes/upload.php'; ?>">
|
107 |
-
<p><input name="uploaded-zip" id="wpbackitup-zip" type="file" /></p>
|
108 |
-
<p><input type="submit" class="restore-button button-primary" name="Upload" id="upload-button" value="<?php _e("Upload", $namespace) ?>" /><img class="upload-icon status-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></p>
|
109 |
-
</form>
|
110 |
-
</div>
|
111 |
-
<?php } ?>
|
112 |
-
<!--End of Upload form-->
|
113 |
-
|
114 |
-
|
115 |
-
<div id="status" class="widget">
|
116 |
-
<h3><?php _e('Status', $namespace );?></h3>
|
117 |
-
|
118 |
-
<!--default status message-->
|
119 |
-
<ul class="default-status">
|
120 |
-
<li><?php _e('Nothing to report', $namespace );?></li>
|
121 |
-
</ul>
|
122 |
-
|
123 |
-
|
124 |
-
<!--backup status messages-->
|
125 |
-
<ul class="backup-status">
|
126 |
-
<li class='prerequisites'><?php _e('Preparing to backup', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
127 |
-
<li class='backupdb'><?php _e('Backing-up database', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
128 |
-
<li class='backupfiles'><?php _e('Backing-up /wp-content/', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
129 |
-
<li class='infofile'><?php _e('Creating backup information file', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
130 |
-
<li class='zipfile'><?php _e('Zipping backup directory', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
131 |
-
<li class='cleanup'><?php _e('Cleaning up', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
132 |
-
<li class='finalinfo'><span class='status'><?php _e('Backup file created successfully. You can download your backup file using the link above', $namespace ); ?></span></li>
|
133 |
-
</ul>
|
134 |
-
|
135 |
-
<!--backup error messages-->
|
136 |
-
<ul class="backup-errors">
|
137 |
-
<li class="error101"><span class='status error'><?php _e('Error: Unable to create new directory for backup. Please check your CHMOD settings of your wp-backitup plugin directory' , $namespace ); ?>.</span></li>
|
138 |
-
<li class="error102"><span class='status error'><?php _e('Error: Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory', $namespace ); ?>.</span></li>
|
139 |
-
<li class="error103"><span class='status error'><?php _e('Error: Unable to backup your files. Please try again', $namespace ); ?>.</span></li>
|
140 |
-
<li class="error104"><span class='status error'><?php _e('Error: Unable to backup your database. Please try again', $namespace ); ?>.</span></li>
|
141 |
-
<li class="error114"><span class='status error'><?php _e('Error: Your database was accesible but a dump could not be created. Please contact support by clicking the link on the right, stating your web host when you submit the form.', $namespace ); ?>.</span></li>
|
142 |
-
<li class="error105"><span class='status error'><?php _e('Error: Unable to create site information file. Please try again', $namespace ); ?>.</span></li>
|
143 |
-
<li class="error106"><span class='status error'><?php _e('Warning: Unable to cleanup your backup directory', $namespace ); ?>.</span></li>
|
144 |
-
</ul>
|
145 |
-
|
146 |
-
<!--Upload status messages-->
|
147 |
-
<ul class="upload-status">
|
148 |
-
<li><span class='upload-status'></span></li>
|
149 |
-
</ul>
|
150 |
-
|
151 |
-
<!--restore status messages-->
|
152 |
-
<ul class="restore-status">
|
153 |
-
<li class="preparing"><?php _e('Preparing for restore', $namespace );?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
154 |
-
<li class="unzipping"><?php _e('Unzipping backup file', $namespace );?>...<span class='status-icon'><img class="unzipping-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
155 |
-
<li class="validation"><?php _e('Validating backup file', $namespace );?>...<span class='status-icon'><img class="validation-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
156 |
-
<li class="restore_point"><?php _e('Creating checkpoint', $namespace );?>...<span class='status-icon'><img class="restore_point-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
157 |
-
<li class="database"><?php _e('Restoring database', $namespace );?>...<span class='status-icon'><img class="database-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
158 |
-
<li class="wpcontent"><?php _e('Restoring /wp-content/ directory', $namespace );?>...<span class='status-icon'><img class="wpcontent-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
159 |
-
<li class="cleanup"><?php _e('Cleaning up restore files', $namespace );?>...<span class='status-icon'><img class="cleanup-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
|
160 |
-
</ul>
|
161 |
-
<p>
|
162 |
-
|
163 |
-
<!--restore error messages-->
|
164 |
-
<div class="restore-errors">
|
165 |
-
<span class="error201"><div class='isa_error'><?php _e('Error: No file selected', $namespace ); ?>.</div></span>
|
166 |
-
<span class="error202"><div class='isa_error'><?php _e('Error: Your file could not be uploaded', $namespace ); ?>.</div></span>
|
167 |
-
<span class="error203"><div class='isa_error'><?php _e('Error: Your backup zip file could not be unzipped', $namespace ); ?>.</div></span>
|
168 |
-
<span class="error204"><div class='isa_error'><?php _e('Error: Your backup zip file appears to be invalid. Please ensure you selected a valid backup zip file', $namespace ); ?>.</div></span>
|
169 |
-
<span class="error205"><div class='isa_error'><?php _e('Error: Cannot create restore point', $namespace ); ?>.</div></span>
|
170 |
-
<span class="error206"><div class='isa_error'><?php _e('Error: Unable to connect to your database', $namespace ); ?>.</div></span>
|
171 |
-
<span class="error207"><div class='isa_error'><?php _e('Error: Unable to get current site URL from database. Please try again', $namespace ); ?>.</div></span>
|
172 |
-
<span class="error208"><div class='isa_error'><?php _e('Error: Unable to get current home URL from database. Please try again', $namespace ); ?>.</div></span>
|
173 |
-
<span class="error209"><div class='isa_error'><?php _e('Error: Unable to get current user ID from database. Please try again', $namespace ); ?>.</div></span>
|
174 |
-
<span class="error210"><div class='isa_error'><?php _e('Error: Unable to get current user password from database. Please try again', $namespace ); ?>.</div></span>
|
175 |
-
<span class="error211"><div class='isa_error'><?php _e('Error: Unable to get current user email from database. Please try again', $namespace ); ?>.</div></span>
|
176 |
-
<span class="error212"><div class='isa_error'><?php _e('Error: Unable to import your database. This may require importing the file manually', $namespace ); ?>.</div></span>
|
177 |
-
<span class="error213"><div class='isa_warning'><?php _e('Error: Unable to update your current site URL value. This may require importing the file manually', $namespace ); ?>.</div></span>
|
178 |
-
<span class="error214"><div class='isa_warning'><?php _e('Error: Unable to update your current home URL value. This may require importing the file manually', $namespace ); ?>.</div></span>
|
179 |
-
<span class="error215"><div class='isa_warning'><?php _e('Error: Unable to update your user information. This may require importing the file manually', $namespace ); ?>.</div></span>
|
180 |
-
<span class="error216"><div class='isa_error'><?php _e('Error: Database not detected in import file', $namespace ); ?>.</div></span>
|
181 |
-
<span class="error217"><div class='isa_warning'><?php _e('Error: Unable to remove existing wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</div></span>
|
182 |
-
<span class="error218"><div class='isa_error'><?php _e('Error: Unable to create new wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</div></span>
|
183 |
-
<span class="error219"><div class='isa_warning'><?php _e('Error: Unable to import wp-content. Please try again', $namespace ); ?>.</div></span>
|
184 |
-
<span class="error220"><div class='isa_warning'><?php _e('Warning: Unable to cleanup import directory. No action is required.', $namespace ); ?>.</div></span>
|
185 |
-
<span class="error221"><div class='isa_warning'><?php _e('Warning: Table prefix value in wp-config.php is different from backup. This MUST be corrected in your wp-config.php file before your site will function', $namespace ); ?>.</div></span>
|
186 |
-
<span class='error222'><div class='isa_error'><?php _e('Error: Unable to create restore folder', $namespace ); ?>.</div></span>
|
187 |
-
<span class='error223'><div class='isa_error'><?php _e('Error: An error occurred during the restore. We attempted to restore the database to its previous state but were unsuccessful. Please contact wpbackitup customer support and do not attempt to perform any further restores', $namespace ); ?>.</div></span>
|
188 |
-
<span class='error224'><div class='isa_error'><?php _e('Error: An error occurred during the restore, however, we have successfully restored your database to the previous state', $namespace ); ?>.</div></span>
|
189 |
-
<span class='error225'><div class='isa_error'><?php _e('Error: Restore option is only available to WP BackItUp Pro users', $namespace ); ?>.</div></span>
|
190 |
-
</div>
|
191 |
-
|
192 |
-
<!--restore success messages-->
|
193 |
-
<div class="restore-success">
|
194 |
-
<span class='finalinfo'><div class='isa_success'><?php _e('Restore completed successfully. Please refresh the page and login to the site again (with your current username and password)', $namespace ); ?></div></span>
|
195 |
-
</div>
|
196 |
-
|
197 |
-
</div>
|
198 |
-
<?php
|
199 |
-
global $WPBACKITUP_DEBUG;
|
200 |
-
if ($WPBACKITUP_DEBUG===true) {
|
201 |
-
echo '<p><div id="php">Logging messages</p></div>';
|
202 |
-
} ?>
|
203 |
-
</div>
|
204 |
-
|
205 |
-
<div id="sidebar">
|
206 |
-
|
207 |
-
<!-- Display opt-in form if the user is unregistered -->
|
208 |
-
<?php
|
209 |
-
if(!license_active()) { ?>
|
210 |
-
<div class="widget">
|
211 |
-
<h3 class="promo"><?php _e('Get a license key', $namespace ); ?></h3>
|
212 |
-
<p><?php _e('Tired of messing with FTP, MySQL and PHPMyAdmin? Restore your backups from this page in minutes or your money back', $namespace ); ?>.</p>
|
213 |
-
<a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/" target="blank"><?php _e('Purchase a license key for WP Backitup Pro', $namespace ); ?></a>
|
214 |
-
</div>
|
215 |
-
<?php } ?>
|
216 |
-
|
217 |
-
<?php /*<div class="widget">
|
218 |
-
<h3 class="promo"><?php _e('Site Information', $namespace ); ?></h3>
|
219 |
-
<p>Backup Size: <?php echo formatFileSize(totalSize(WPBACKITUP_CONTENT_PATH) ); ?></p>
|
220 |
-
<p>WP Backitup is not recommended for sites larger than 50MB.</p>
|
221 |
-
</div> */ ?>
|
222 |
-
|
223 |
-
<!-- Display license key widget -->
|
224 |
-
<form action="" method="post" id="<?php echo $namespace; ?>-form">
|
225 |
-
<?php wp_nonce_field( $namespace . "-update-options" ); ?>
|
226 |
-
<div class="widget">
|
227 |
-
<h3 class="promo"><?php _e('License Key v '.WPBACKITUP_VERSION, $namespace); ?></h3>
|
228 |
-
<?php
|
229 |
-
$license = $this->get_option( 'license_key' );
|
230 |
-
if(!license_active()) { ?>
|
231 |
-
<p><?php _e('Enter your license key to activate Pro features.', $namespace ); ?>.</p>
|
232 |
-
<?php } ?>
|
233 |
-
<p><input type="text" name="data[license_key]" id="license_key" value="<?php echo $license; ?>" />
|
234 |
-
<?php
|
235 |
-
if(license_active() ) { ?>
|
236 |
-
<span style="color:green;"><?php _e('Pro License Active', $namespace); ?></span></p>
|
237 |
-
<p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Update", $namespace ) ?>" /></p>
|
238 |
-
<?php } else { ?>
|
239 |
-
<span style="color:red;"><?php _e('Pro License Inactive', $namespace); ?></span></p>
|
240 |
-
<p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Activate", $namespace ) ?>" /></p>
|
241 |
-
<p><?php _e('Purchase a <a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/" target="blank">no-risk </a>license using the purchase link above',$namespace); ?>.</p>
|
242 |
-
<?php }
|
243 |
-
?>
|
244 |
-
</div>
|
245 |
-
|
246 |
-
<!-- Display links widget -->
|
247 |
-
<div class="widget">
|
248 |
-
<h3 class="promo"><?php _e('Useful Links', $namespace ); ?></h3>
|
249 |
-
<ul>
|
250 |
-
<?php
|
251 |
-
if(license_active()) { ?>
|
252 |
-
<li><a href="http://www.wpbackitup.com/your-account/" target="_blank"><?php _e('Your account',$namespace); ?></a></li>
|
253 |
-
<li><a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/" target="_blank"><?php _e('Upgrade your license',$namespace); ?></a></li>
|
254 |
-
<?php }
|
255 |
-
?>
|
256 |
-
<li><a href="http://www.wpbackitup.com/support" target="_blank"><?php _e('Get support',$namespace); ?></a></li>
|
257 |
-
<li><a href="http://www.wpbackitup.com/feature-request" target="_blank"><?php _e('Feature Request',$namespace); ?></a></li>
|
258 |
-
<li>Have a suggestion? Why not submit a feature request.</li>
|
259 |
-
</ul>
|
260 |
-
</div>
|
261 |
-
|
262 |
-
<div class="widget">
|
263 |
-
<h3 class="promo">Turn on logging?</h3>
|
264 |
-
<p><input type="radio" name="data[logging]" value="enabled" <?php if($this->get_option( 'logging' ) == 'enabled') echo 'checked'; ?>> <label><?php _e('Yes', $namespace ); ?></label></p>
|
265 |
-
<p><input type="radio" name="data[logging]" value="disabled" <?php if($this->get_option( 'logging' ) == 'disabled') echo 'checked'; ?>> <label><?php _e('No', $namespace ); ?></label></p>
|
266 |
-
<p><?php _e('This option should only be turned on when troubleshooting issues with WPBackItUp support.', $namespace ); ?></p>
|
267 |
-
<p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Save", $namespace ) ?>" /></p>
|
268 |
-
</div>
|
269 |
-
|
270 |
-
<!--
|
271 |
-
<div class="widget">
|
272 |
-
<h3 class="promo">Allow Usage Tracking?</h3>
|
273 |
-
<p><input type="radio" name="data[presstrends]" value="enabled" <?php if($this->get_option( 'presstrends' ) == 'enabled') echo 'checked'; ?>> <label><?php _e('Yes', $namespace ); ?></label></p>
|
274 |
-
<p><input type="radio" name="data[presstrends]" value="disabled" <?php if($this->get_option( 'presstrends' ) == 'disabled') echo 'checked'; ?>> <label><?php _e('No', $namespace ); ?></label></p>
|
275 |
-
<p><?php _e('Allow WPBackItUp to track how this plugin is used so we can make it better. We only track usage data related to this plugin and will never share this data.', $namespace ); ?></p>
|
276 |
-
<p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Save", $namespace ) ?>" /></p>
|
277 |
-
</div>
|
278 |
-
-->
|
279 |
-
</form>
|
280 |
-
</div>
|
281 |
-
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
views/restore.php
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
$page_title = $this->friendly_name . ' Restore';
|
4 |
+
$namespace = $this->namespace;
|
5 |
+
|
6 |
+
//Path Variables
|
7 |
+
$backup_folder_root = WPBACKITUP__BACKUP_PATH .'/';
|
8 |
+
|
9 |
+
?>
|
10 |
+
|
11 |
+
<script type="text/javascript">var __namespace = '<?php echo $namespace; ?>';</script>
|
12 |
+
<div class="wrap">
|
13 |
+
<div id="wp-backitup-icon" class="icon32"><img src="<?php echo plugin_dir_url(dirname(__FILE__)); ?>images/icon32.png" alt="WP Backitup Icon" height="32" width="32" /></div>
|
14 |
+
<h2><?php echo $page_title; ?></h2>
|
15 |
+
<div id="content">
|
16 |
+
|
17 |
+
<!--Available Backups section-->
|
18 |
+
<div class="widget">
|
19 |
+
<h3><i class="fa fa-cloud-download"></i> <?php _e('Available Backups', $namespace); ?></h3>
|
20 |
+
<table class="widefat" id="datatable">
|
21 |
+
<?php
|
22 |
+
//Get Zip File List
|
23 |
+
$zipFileList = glob($backup_folder_root . "*.zip");
|
24 |
+
|
25 |
+
//Sort by Date Time
|
26 |
+
usort($zipFileList, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
|
27 |
+
|
28 |
+
if (glob($backup_folder_root . "*.zip"))
|
29 |
+
{
|
30 |
+
$i = 0;
|
31 |
+
foreach ($zipFileList as $file)
|
32 |
+
{
|
33 |
+
$filename = basename($file);
|
34 |
+
$fileDateTime = get_date_from_gmt(date('Y-m-d H:i:s', filemtime($file)), 'Y-m-d g:i a'); //Local Date Time
|
35 |
+
$class = $i % 2 == 0 ? 'class="alternate"' : '';
|
36 |
+
?>
|
37 |
+
<tr <?php echo $class ?> id="row<?php echo $i; ?>">
|
38 |
+
<td><?php echo $filename ?></td>
|
39 |
+
<td><a href="<?php echo WPBACKITUP__BACKUP_URL ?>/<?php echo $filename; ?>">Download</a></td>
|
40 |
+
<td><a href="#" title="<?php echo $filename; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
|
41 |
+
<?php
|
42 |
+
if ($this->license_active())
|
43 |
+
{
|
44 |
+
echo '<td><a href="#" title="' . $filename . '" class="restoreRow" id="restoreRow' . $i . '">Restore</a></td>';
|
45 |
+
}
|
46 |
+
?>
|
47 |
+
</tr>
|
48 |
+
<?php
|
49 |
+
$i++;
|
50 |
+
}
|
51 |
+
}
|
52 |
+
else
|
53 |
+
{
|
54 |
+
echo '<tr id="nofiles"><td colspan="3">No export file available for download. Please create one.</td></tr>';
|
55 |
+
}
|
56 |
+
?>
|
57 |
+
</table>
|
58 |
+
|
59 |
+
<form id="restore-form" method="post" action="admin-post.php">
|
60 |
+
<?php global $current_user; ?>
|
61 |
+
<input type="hidden" name="user_id" value="<?php echo $current_user->ID; ?>" />
|
62 |
+
<input type="hidden" name="is_selected" id="is_selected" value="0" />
|
63 |
+
<input type="hidden" name="selected_file" id="selected_file" value="" />
|
64 |
+
</form>
|
65 |
+
|
66 |
+
<?php
|
67 |
+
//Display restore note for lite customers
|
68 |
+
if (!$this->license_active())
|
69 |
+
{
|
70 |
+
echo '<p>* The automated restore feature is only available to licensed customers. Please visit <a href="' . WPBACKITUP__SITE_URL .'" target="_blank">'. WPBACKITUP__SITE_URL .'</a> to get license WP BackItUp risk free for 30 days.</p>';
|
71 |
+
}
|
72 |
+
?>
|
73 |
+
</div>
|
74 |
+
|
75 |
+
<!--Disable upload form if the user has not activated-->
|
76 |
+
<?php
|
77 |
+
if ($this->license_active())
|
78 |
+
{
|
79 |
+
?>
|
80 |
+
<div class="widget">
|
81 |
+
<h3><i class="fa fa-upload"></i> <?php _e('Upload', $namespace); ?></h3>
|
82 |
+
<iframe id="upload_target" name="upload_target" src="">
|
83 |
+
</iframe>
|
84 |
+
<p><b><?php _e('Upload a WP BackItUp zip file to add it to your list of available backups.', $namespace); ?></b></p>
|
85 |
+
<?php
|
86 |
+
$max_upload = (int) (ini_get('upload_max_filesize'));
|
87 |
+
$max_post = (int) (ini_get('post_max_size'));
|
88 |
+
$memory_limit = (int) (ini_get('memory_limit'));
|
89 |
+
$upload_mb = min($max_upload, $max_post, $memory_limit);
|
90 |
+
$upload_bytes = $upload_mb * 1048576;
|
91 |
+
?>
|
92 |
+
<p>
|
93 |
+
<?php _e('The maximum file size your hosting provider allows you to upload is ', $namespace);?>
|
94 |
+
<span style="color:green"><?php echo $upload_mb . 'MB.'; ?></span>
|
95 |
+
</p>
|
96 |
+
<form id="upload-form" name="upload-form" method="post" enctype="multipart/form-data">
|
97 |
+
<?php wp_nonce_field($namespace . "-upload-file"); ?>
|
98 |
+
<input type="hidden" id="maxfilesize" value="<?php echo $upload_bytes; ?>"/>
|
99 |
+
<p><input name="uploaded-zip" id="wpbackitup-zip" type="file" /></p>
|
100 |
+
<p><input type="submit" class="restore-button button-primary" name="Upload" id="upload-button" value="<?php _e("Upload", $namespace) ?>" /><img class="upload-icon status-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></p>
|
101 |
+
</form>
|
102 |
+
</div>
|
103 |
+
<?php } ?>
|
104 |
+
<!--End of Upload form-->
|
105 |
+
|
106 |
+
|
107 |
+
<div id="status" class="widget">
|
108 |
+
<h3><i class="fa fa-check-square-o"></i> <?php _e('Status', $namespace); ?></h3>
|
109 |
+
|
110 |
+
<!--default status message-->
|
111 |
+
<ul class="default-status">
|
112 |
+
<li><?php _e('Nothing to report', $namespace); ?></li>
|
113 |
+
</ul>
|
114 |
+
|
115 |
+
<!--Upload status messages-->
|
116 |
+
<ul class="upload-status">
|
117 |
+
<li><span class='upload-status'></span></li>
|
118 |
+
</ul>
|
119 |
+
|
120 |
+
<!--restore status messages-->
|
121 |
+
<ul class="restore-status">
|
122 |
+
<li class="preparing"><?php _e('Preparing for restore', $namespace); ?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
123 |
+
<li class="unzipping"><?php _e('Unzipping backup file', $namespace); ?>...<span class='status-icon'><img class="unzipping-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
124 |
+
<li class="validation"><?php _e('Validating backup file', $namespace); ?>...<span class='status-icon'><img class="validation-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
125 |
+
<li class="restore_point"><?php _e('Creating checkpoint', $namespace); ?>...<span class='status-icon'><img class="restore_point-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
126 |
+
<li class="database"><?php _e('Restoring database', $namespace); ?>...<span class='status-icon'><img class="database-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
127 |
+
<li class="wpcontent"><?php _e('Restoring plugins, themes and uploads', $namespace); ?>...<span class='status-icon'><img class="wpcontent-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
128 |
+
<li class="cleanup"><?php _e('Cleaning up restore files', $namespace); ?>...<span class='status-icon'><img class="cleanup-icon" src="<?php echo WPBACKITUP__PLUGIN_URL . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace); ?></span><span class='fail error'><?php _e('Failed', $namespace); ?></span></li>
|
129 |
+
</ul>
|
130 |
+
<p>
|
131 |
+
|
132 |
+
<!--restore error messages-->
|
133 |
+
<div class="restore-errors">
|
134 |
+
<span class="error201"><div class='isa_error'><?php _e('Error 201: No file selected', $namespace); ?>.</div></span>
|
135 |
+
<span class="error202"><div class='isa_error'><?php _e('Error 202: Your file could not be uploaded', $namespace); ?>.</div></span>
|
136 |
+
<span class="error203"><div class='isa_error'><?php _e('Error 203: Your backup zip file could not be unzipped', $namespace); ?>.</div></span>
|
137 |
+
<span class="error204"><div class='isa_error'><?php _e('Error 204: Your backup zip file appears to be invalid. Please ensure you selected a valid backup zip file', $namespace); ?>.</div></span>
|
138 |
+
<span class="error205"><div class='isa_error'><?php _e('Error 205: Cannot create restore point', $namespace); ?>.</div></span>
|
139 |
+
<span class="error206"><div class='isa_error'><?php _e('Error 206: Unable to connect to your database', $namespace); ?>.</div></span>
|
140 |
+
<span class="error207"><div class='isa_error'><?php _e('Error 207: Unable to get current site URL from database. Please try again', $namespace); ?>.</div></span>
|
141 |
+
<span class="error208"><div class='isa_error'><?php _e('Error 208: Unable to get current home URL from database. Please try again', $namespace); ?>.</div></span>
|
142 |
+
<span class="error209"><div class='isa_error'><?php _e('Error 209: Unable to get current user ID from database. Please try again', $namespace); ?>.</div></span>
|
143 |
+
<span class="error210"><div class='isa_error'><?php _e('Error 210: Unable to get current user password from database. Please try again', $namespace); ?>.</div></span>
|
144 |
+
<span class="error211"><div class='isa_error'><?php _e('Error 211: Unable to get current user email from database. Please try again', $namespace); ?>.</div></span>
|
145 |
+
<span class="error212"><div class='isa_error'><?php _e('Error 212: Unable to import your database. This may require importing the file manually', $namespace); ?>.</div></span>
|
146 |
+
<span class="error213"><div class='isa_warning'><?php _e('Error 213: Unable to update your current site URL value. This may require importing the file manually', $namespace); ?>.</div></span>
|
147 |
+
<span class="error214"><div class='isa_warning'><?php _e('Error 214: Unable to update your current home URL value. This may require importing the file manually', $namespace); ?>.</div></span>
|
148 |
+
<span class="error215"><div class='isa_warning'><?php _e('Error 215: Unable to update your user information. This may require importing the file manually', $namespace); ?>.</div></span>
|
149 |
+
<span class="error216"><div class='isa_error'><?php _e('Error 216: Database not detected in import file', $namespace); ?>.</div></span>
|
150 |
+
<span class="error217"><div class='isa_warning'><?php _e('Error 217: Unable to remove existing wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace); ?>.</div></span>
|
151 |
+
<span class="error218"><div class='isa_error'><?php _e('Error 218: Unable to create new wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace); ?>.</div></span>
|
152 |
+
<span class="error219"><div class='isa_warning'><?php _e('Error 219: Unable to import wp-content. Please try again', $namespace); ?>.</div></span>
|
153 |
+
<span class="error220"><div class='isa_warning'><?php _e('Warning 220: Unable to cleanup import directory. No action is required.', $namespace); ?>.</div></span>
|
154 |
+
<span class="error221"><div class='isa_warning'><?php _e('Warning 221: Table prefix value in wp-config.php is different from backup. This MUST be corrected in your wp-config.php file before your site will function', $namespace); ?>.</div></span>
|
155 |
+
<span class='error222'><div class='isa_error'><?php _e('Error 222: Unable to create restore folder', $namespace); ?>.</div></span>
|
156 |
+
<span class='error223'><div class='isa_error'><?php _e('Error 223: An error occurred during the restore. We attempted to restore the database to its previous state but were unsuccessful. Please contact WP BackItUp customer support and do not attempt to perform any further restores', $namespace); ?>.</div></span>
|
157 |
+
<span class='error224'><div class='isa_error'><?php _e('Error 224: An error occurred during the restore, however, we have successfully restored your database to the previous state', $namespace); ?>.</div></span>
|
158 |
+
<span class='error225'><div class='isa_error'><?php _e('Error 225: Restore option is only available to licensed WP BackItUp users', $namespace); ?>.</div></span>
|
159 |
+
</div>
|
160 |
+
|
161 |
+
<!--restore success messages-->
|
162 |
+
<div class="restore-success">
|
163 |
+
<span class='finalinfo'><div class='isa_success'><?php _e('Restore completed successfully. Please refresh the page and login to the site again (with your current username and password)', $namespace); ?></div></span>
|
164 |
+
</div>
|
165 |
+
|
166 |
+
</div>
|
167 |
+
|
168 |
+
<!--Debug Widget-->
|
169 |
+
<?php if (WP_DEBUG===true) :?>
|
170 |
+
<div class="widget">
|
171 |
+
<h3><i class="fa fa-wrench"></i> <?php _e('Debug', $namespace); ?></h3>
|
172 |
+
<div id="php"><p>Debugging is turned on in your wp-config.php file and should only be used when troubleshooting issues on your site.</p></div>
|
173 |
+
</div>
|
174 |
+
<?php endif; ?>
|
175 |
+
</div>
|
176 |
+
|
177 |
+
</div>
|
views/settings.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
$page_title = $this->friendly_name . ' Settings';
|
4 |
+
$namespace = $this->namespace;
|
5 |
+
|
6 |
+
?>
|
7 |
+
|
8 |
+
<div class="wrap">
|
9 |
+
<h2><?php echo $page_title; ?></h2>
|
10 |
+
<div id="content">
|
11 |
+
|
12 |
+
<!-- Display Settings widget -->
|
13 |
+
<form action="admin-post.php" method="post" id="<?php echo $namespace; ?>-form">
|
14 |
+
<?php wp_nonce_field($namespace . "-update-options"); ?>
|
15 |
+
<div class="widget">
|
16 |
+
<h3 class="promo"><i class="fa fa-envelope"></i> Email Notifications</h3>
|
17 |
+
<p><b>Please enter your email address if you would like to receive backup email notifications.</b></p>
|
18 |
+
<p><?php _e('Backup email notifications will be sent for every backup and will contain status information related to the backup.', $namespace); ?></p>
|
19 |
+
<p><input type="text" name="data[notification_email]" value="<?php echo $this->notification_email(); ?>" size="30"></p>
|
20 |
+
<div class="submit"><input type="submit" name="Save_Email" class="button-primary" value="<?php _e("Save", $namespace) ?>" /></div>
|
21 |
+
<?php
|
22 |
+
if ( false !== ( $msg = get_transient('settings-error-email') ) && $msg)
|
23 |
+
{
|
24 |
+
echo '<p class="error">'.$msg.'</p>';
|
25 |
+
delete_transient('settings-error-email');
|
26 |
+
}
|
27 |
+
?>
|
28 |
+
</div>
|
29 |
+
|
30 |
+
<div class="widget">
|
31 |
+
<h3 class="promo"><i class="fa fa-trash-o"></i> Backup Retention</h3>
|
32 |
+
<p><b>Enter the number of backup archives that you would like to remain on the server.</b></p>
|
33 |
+
<p>Many hosts limit the amount of space that you can take up on their servers. This option tells
|
34 |
+
WP BackItUp the maximum number of backup archives that should remain on your hosts server. Don't worry, we will
|
35 |
+
always remove the oldest backup archives first.</p>
|
36 |
+
<p><input type="text" name="data[backup_retained_number]" value="<?php echo $this->backup_retained_number(); ?>" size="4"></p>
|
37 |
+
<div class="submit"><input type="submit" name="Save_Retention" class="button-primary" value="<?php _e("Save", $namespace) ?>" /></div>
|
38 |
+
<?php
|
39 |
+
if ( false !== ( $msg = get_transient('settings-error-number') ) && $msg)
|
40 |
+
{
|
41 |
+
echo '<p class="error">'.$msg.'</p>';
|
42 |
+
delete_transient('settings-error-number');
|
43 |
+
}
|
44 |
+
|
45 |
+
if ( false !== ( $msg = get_transient('settings-license-error') ) && $msg)
|
46 |
+
{
|
47 |
+
echo '<p class="error">'.$msg.'</p>';
|
48 |
+
delete_transient('settings-license-error');
|
49 |
+
}
|
50 |
+
?>
|
51 |
+
</div>
|
52 |
+
|
53 |
+
<div class="widget">
|
54 |
+
<h3 class="promo"><i class="fa fa-file-text-o"></i> Turn on logging?</h3>
|
55 |
+
<p><input type="radio" name="data[logging]" value="true" <?php if ($this->logging()) echo 'checked'; ?>> <label><?php _e('Yes', $namespace); ?></label></p>
|
56 |
+
<p><input type="radio" name="data[logging]" value="false" <?php if (!$this->logging()) echo 'checked'; ?>> <label><?php _e('No', $namespace); ?></label></p>
|
57 |
+
<p><?php _e('This option should only be turned on when troubleshooting issues with WPBackItUp support.', $namespace); ?></p>
|
58 |
+
<p class="submit"><input type="submit" name="Save_Logging" class="button-primary" value="<?php _e("Save", $namespace) ?>" /></p>
|
59 |
+
</div>
|
60 |
+
|
61 |
+
<!--Debug Widget-->
|
62 |
+
<?php if (WP_DEBUG===true) :?>
|
63 |
+
<div class="widget">
|
64 |
+
<h3><i class="fa fa-wrench"></i> <?php _e('Debug', $namespace); ?></h3>
|
65 |
+
<div id="php"><p>Debugging is turned on in your wp-config.php file and should only be used when troubleshooting issues on your site.</p></div>
|
66 |
+
</div>
|
67 |
+
<?php endif; ?>
|
68 |
+
|
69 |
+
</form>
|
70 |
+
</div>
|
71 |
+
</div>
|
wp-backitup.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WP Backitup
|
5 |
+
*
|
6 |
+
* @package WP Backitup
|
7 |
+
*
|
8 |
+
* @author cssimmon
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
/*
|
12 |
+
Plugin Name: WP Backitup
|
13 |
+
Plugin URI: http://www.wpbackitup.com
|
14 |
+
Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
|
15 |
+
Version: 1.7.0
|
16 |
+
Author: Chris Simmons
|
17 |
+
Author URI: http://www.wpbackitup.com
|
18 |
+
License: GPL3
|
19 |
+
|
20 |
+
Copyright 2012-2014 WPBackItUp (email : support@wpbackitup.com)
|
21 |
+
|
22 |
+
This program is free software: you can redistribute it and/or modify
|
23 |
+
it under the terms of the GNU General Public License as published by
|
24 |
+
the Free Software Foundation, either version 3 of the License, or
|
25 |
+
(at your option) any later version.
|
26 |
+
|
27 |
+
This program is distributed in the hope that it will be useful,
|
28 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
+
GNU General Public License for more details.
|
31 |
+
|
32 |
+
You should have received a copy of the GNU General Public License
|
33 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
34 |
+
*/
|
35 |
+
|
36 |
+
define( 'WPBACKITUP__NAMESPACE', 'wp-backitup' );
|
37 |
+
define( 'WPBACKITUP__VERSION', '1.7.0');
|
38 |
+
define( 'WPBACKITUP__DEBUG', false );
|
39 |
+
define( 'WPBACKITUP__MINIMUM_WP_VERSION', '3.0' );
|
40 |
+
define( 'WPBACKITUP__ITEM_NAME', 'WP Backitup' );
|
41 |
+
define( 'WPBACKITUP__FRIENDLY_NAME', 'WP BackItUp' );
|
42 |
+
|
43 |
+
define( 'WPBACKITUP__CONTENT_PATH', WP_CONTENT_DIR );
|
44 |
+
|
45 |
+
define( 'WPBACKITUP__SITE_URL', 'http://www.wpbackitup.com');
|
46 |
+
define( 'WPBACKITUP__SECURESITE_URL', 'https://www.wpbackitup.com' );
|
47 |
+
|
48 |
+
define( 'WPBACKITUP__PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
49 |
+
define( 'WPBACKITUP__PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
|
50 |
+
define( 'WPBACKITUP__PLUGIN_FOLDER',basename(dirname(__FILE__)));
|
51 |
+
|
52 |
+
define( 'WPBACKITUP__BACKUP_FOLDER', 'wpbackitup_backups' );
|
53 |
+
define( 'WPBACKITUP__BACKUP_URL', content_url() . "/" .WPBACKITUP__BACKUP_FOLDER);
|
54 |
+
define( 'WPBACKITUP__BACKUP_PATH',WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER);
|
55 |
+
|
56 |
+
define( 'WPBACKITUP__RESTORE_FOLDER', 'wpbackitup_restore' );
|
57 |
+
define( 'WPBACKITUP__RESTORE_PATH',WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER);
|
58 |
+
|
59 |
+
define( 'WPBACKITUP__PLUGINS_ROOT_PATH',WP_PLUGIN_DIR );
|
60 |
+
define( 'WPBACKITUP__THEMES_ROOT_PATH',get_theme_root() );
|
61 |
+
|
62 |
+
define( 'WPBACKITUP__SQL_DBBACKUP_FILENAME', 'db-backup.sql');
|
63 |
+
|
64 |
+
register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
|
65 |
+
register_deactivation_hook( __FILE__, array( 'WPBackitup_Admin', 'deactivate' ) );
|
66 |
+
|
67 |
+
|
68 |
+
//Only add hook when admin
|
69 |
+
if ( is_admin() && ! class_exists( 'WPBackitup_Admin' )) {
|
70 |
+
//include_once dirname( __FILE__ ) . '/lib/constants.php';
|
71 |
+
require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-wpbackitup-admin.php' );
|
72 |
+
require_once( WPBACKITUP__PLUGIN_PATH .'/lib/includes/class-logger.php' );
|
73 |
+
|
74 |
+
global $WPBackitup;
|
75 |
+
$WPBackitup = WPBackitup_Admin::get_instance();
|
76 |
+
$WPBackitup->initialize();
|
77 |
+
}
|
78 |
+
|
79 |
+
|