Version Description
- Improvement of backup process: Duplicated files are removed from backing up for better backup process
- Improvement of Dropbox: During authentication refresh token has been added
- Bug fixed related to import issues connected to server timeout
Download this release
Release Info
Developer | BackupGuard |
Plugin | WordPress Backup and Migrate Plugin – Backup Guard |
Version | 1.6.9 |
Comparing to | |
See all releases |
Code changes from version 1.6.8.8 to 1.6.9
- README.txt +10 -2
- backup.php +2 -2
- com/config/config.wordpress.php +189 -158
- com/core/functions.php +1101 -1100
- com/core/storage/SGDropboxStorage.php +462 -405
- com/lib/Dropbox/WebAuth.php +32 -20
- com/lib/Dropbox/WebAuthBase.php +45 -64
- public/ajax/cloudDropbox.php +16 -15
- public/backups.php +292 -292
- public/js/sgbackup.js +1017 -1013
README.txt
CHANGED
@@ -4,9 +4,9 @@ Contributors: Backup Guard, Backup Guard Support
|
|
4 |
Author: Backup Guard
|
5 |
Donate link: https://backup-guard.com/products/backup-wordpress
|
6 |
Tags: backup, wordpress backup plugin, backup plugin, database backup, migrate, back up
|
7 |
-
Requires at least: 3
|
8 |
Tested up to: 6.0
|
9 |
-
Stable tag: 1.6.
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
@@ -168,6 +168,14 @@ When you are facing an issue of any kind with any of our products, the first thi
|
|
168 |
|
169 |
== Changelog ==
|
170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
= 1.6.8.8 =
|
172 |
* Improvement of "Destination folder" in Cloud settings: Validation has been added
|
173 |
* Bug fixed related to deprecated warnings in functions.php file
|
4 |
Author: Backup Guard
|
5 |
Donate link: https://backup-guard.com/products/backup-wordpress
|
6 |
Tags: backup, wordpress backup plugin, backup plugin, database backup, migrate, back up
|
7 |
+
Requires at least: 5.3
|
8 |
Tested up to: 6.0
|
9 |
+
Stable tag: 1.6.9
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
168 |
|
169 |
== Changelog ==
|
170 |
|
171 |
+
= 1.6.9 =
|
172 |
+
* Improvement of backup process: Duplicated files are removed from backing up for better backup process
|
173 |
+
* Improvement of Dropbox: During authentication refresh token has been added
|
174 |
+
* Bug fixed related to import issues connected to server timeout
|
175 |
+
|
176 |
+
= 1.6.8.9 =
|
177 |
+
* Fix deprecated functions for php8.1
|
178 |
+
|
179 |
= 1.6.8.8 =
|
180 |
* Improvement of "Destination folder" in Cloud settings: Validation has been added
|
181 |
* Bug fixed related to deprecated warnings in functions.php file
|
backup.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Backup
|
5 |
* Plugin URI: https://backup-guard.com/products/backup-wordpress
|
6 |
* Description: Backup Guard is the most complete site backup and restore plugin. We offer the easiest way to backup, restore or migrate your site. You can backup your files, database or both.
|
7 |
-
* Version: 1.6.
|
8 |
* Author: BackupGuard
|
9 |
* Author URI: https://backup-guard.com/products/backup-wordpress
|
10 |
* License: GPL-2.0+
|
@@ -16,7 +16,7 @@ if (function_exists('activate_backup_guard')) {
|
|
16 |
}
|
17 |
|
18 |
if (!defined('SG_BACKUP_GUARD_VERSION')) {
|
19 |
-
define('SG_BACKUP_GUARD_VERSION', '1.6.
|
20 |
}
|
21 |
|
22 |
if (!defined('SG_BACKUP_GUARD_MAIN_FILE')) {
|
4 |
* Plugin Name: Backup
|
5 |
* Plugin URI: https://backup-guard.com/products/backup-wordpress
|
6 |
* Description: Backup Guard is the most complete site backup and restore plugin. We offer the easiest way to backup, restore or migrate your site. You can backup your files, database or both.
|
7 |
+
* Version: 1.6.9
|
8 |
* Author: BackupGuard
|
9 |
* Author URI: https://backup-guard.com/products/backup-wordpress
|
10 |
* License: GPL-2.0+
|
16 |
}
|
17 |
|
18 |
if (!defined('SG_BACKUP_GUARD_VERSION')) {
|
19 |
+
define('SG_BACKUP_GUARD_VERSION', '1.6.9');
|
20 |
}
|
21 |
|
22 |
if (!defined('SG_BACKUP_GUARD_MAIN_FILE')) {
|
com/config/config.wordpress.php
CHANGED
@@ -1,158 +1,189 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
global $wp_version, $wpdb; // phpcs:ignore
|
4 |
-
if (!defined('SG_ENV_WORDPRESS')) {
|
5 |
-
define('SG_ENV_WORDPRESS', 'Wordpress');
|
6 |
-
}
|
7 |
-
define('SG_ENV_MAGENTO', 'Magento');
|
8 |
-
define('SG_ENV_VERSION', $wp_version); // phpcs:ignore
|
9 |
-
if (!defined('SG_ENV_ADAPTER')) {
|
10 |
-
define('SG_ENV_ADAPTER', SG_ENV_WORDPRESS);
|
11 |
-
}
|
12 |
-
if (!defined('SG_ENV_DB_PREFIX')) {
|
13 |
-
define('SG_ENV_DB_PREFIX', $wpdb->prefix);
|
14 |
-
}
|
15 |
-
require_once(dirname(__FILE__) . '/config.php');
|
16 |
-
|
17 |
-
define('SG_ENV_CORE_TABLE', SG_WORDPRESS_CORE_TABLE);
|
18 |
-
//Database
|
19 |
-
if (!defined('SG_DB_ADAPTER')) {
|
20 |
-
define('SG_DB_ADAPTER', SG_ENV_ADAPTER);
|
21 |
-
}
|
22 |
-
if (!defined('SG_DB_NAME')) {
|
23 |
-
define('SG_DB_NAME', $wpdb->dbname);
|
24 |
-
}
|
25 |
-
if (!defined('SG_BACKUP_DATABASE_EXCLUDE')) {
|
26 |
-
define('SG_BACKUP_DATABASE_EXCLUDE', SG_ACTION_TABLE_NAME . ',' . SG_CONFIG_TABLE_NAME . ',' . SG_SCHEDULE_TABLE_NAME);
|
27 |
-
}
|
28 |
-
|
29 |
-
//Templates
|
30 |
-
define('SG_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates') . '/');
|
31 |
-
|
32 |
-
//Mail
|
33 |
-
define('SG_MAIL_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates/mails') . '/');
|
34 |
-
define('SG_MAIL_BACKUP_TEMPLATE', 'mail_backup.php');
|
35 |
-
define('SG_MAIL_RESTORE_TEMPLATE', 'mail_restore.php');
|
36 |
-
define('SG_MAIL_UPLOAD_TEMPLATE', 'mail_upload.php');
|
37 |
-
|
38 |
-
//Notice
|
39 |
-
define('SG_NOTICE_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates/notices') . '/');
|
40 |
-
|
41 |
-
//Htaccess
|
42 |
-
define('SG_HTACCESS_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates/htaccess') . '/');
|
43 |
-
|
44 |
-
//BackupGuard SDK
|
45 |
-
define('SG_BACKUPGUARD_CLIENT_ID', 'wordpress');
|
46 |
-
define('SG_BACKUPGUARD_CLIENT_SECRET', 'AAPQEgsyQrt6wqDBk7fpa24NP6W43evtayxXmUqS');
|
47 |
-
|
48 |
-
define('SG_BACKUPGUARD_UPLOAD_CLIENT_ID', 'backupguard');
|
49 |
-
define('SG_BACKUPGUARD_UPLOAD_CLIENT_SECRET', 'e9503d56b06b95241abf68eaa0d13194aae9503e');
|
50 |
-
|
51 |
-
define('SG_BACKUPGUARD_UPLOAD_SCOPE', 'create_backups');
|
52 |
-
|
53 |
-
//Backup
|
54 |
-
$wpContent = basename(WP_CONTENT_DIR);
|
55 |
-
$wpPlugins = basename(WP_PLUGIN_DIR);
|
56 |
-
$wpThemes
|
57 |
-
|
58 |
-
$uploadDir = wp_upload_dir();
|
59 |
-
$wpUploads = basename($uploadDir['basedir']); // phpcs:ignore
|
60 |
-
|
61 |
-
$dbCharset = 'utf8';
|
62 |
-
if (@constant("DB_CHARSET")) {
|
63 |
-
$dbCharset = DB_CHARSET;
|
64 |
-
}
|
65 |
-
|
66 |
-
//
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
}
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
define('
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
$
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
$
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
$
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
$wpContent . '/
|
119 |
-
$wpContent . '/' . $
|
120 |
-
$wpContent . '/
|
121 |
-
$wpContent . '/
|
122 |
-
$wpContent . '/' . $
|
123 |
-
$wpContent . '/' . $wpUploads . '/
|
124 |
-
$wpContent . '/
|
125 |
-
$wpContent . '/
|
126 |
-
$wpContent . '/
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
global $wp_version, $wpdb; // phpcs:ignore
|
4 |
+
if (!defined('SG_ENV_WORDPRESS')) {
|
5 |
+
define('SG_ENV_WORDPRESS', 'Wordpress');
|
6 |
+
}
|
7 |
+
define('SG_ENV_MAGENTO', 'Magento');
|
8 |
+
define('SG_ENV_VERSION', $wp_version); // phpcs:ignore
|
9 |
+
if (!defined('SG_ENV_ADAPTER')) {
|
10 |
+
define('SG_ENV_ADAPTER', SG_ENV_WORDPRESS);
|
11 |
+
}
|
12 |
+
if (!defined('SG_ENV_DB_PREFIX')) {
|
13 |
+
define('SG_ENV_DB_PREFIX', $wpdb->prefix);
|
14 |
+
}
|
15 |
+
require_once(dirname(__FILE__) . '/config.php');
|
16 |
+
|
17 |
+
define('SG_ENV_CORE_TABLE', SG_WORDPRESS_CORE_TABLE);
|
18 |
+
//Database
|
19 |
+
if (!defined('SG_DB_ADAPTER')) {
|
20 |
+
define('SG_DB_ADAPTER', SG_ENV_ADAPTER);
|
21 |
+
}
|
22 |
+
if (!defined('SG_DB_NAME')) {
|
23 |
+
define('SG_DB_NAME', $wpdb->dbname);
|
24 |
+
}
|
25 |
+
if (!defined('SG_BACKUP_DATABASE_EXCLUDE')) {
|
26 |
+
define('SG_BACKUP_DATABASE_EXCLUDE', SG_ACTION_TABLE_NAME . ',' . SG_CONFIG_TABLE_NAME . ',' . SG_SCHEDULE_TABLE_NAME);
|
27 |
+
}
|
28 |
+
|
29 |
+
//Templates
|
30 |
+
define('SG_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates') . '/');
|
31 |
+
|
32 |
+
//Mail
|
33 |
+
define('SG_MAIL_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates/mails') . '/');
|
34 |
+
define('SG_MAIL_BACKUP_TEMPLATE', 'mail_backup.php');
|
35 |
+
define('SG_MAIL_RESTORE_TEMPLATE', 'mail_restore.php');
|
36 |
+
define('SG_MAIL_UPLOAD_TEMPLATE', 'mail_upload.php');
|
37 |
+
|
38 |
+
//Notice
|
39 |
+
define('SG_NOTICE_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates/notices') . '/');
|
40 |
+
|
41 |
+
//Htaccess
|
42 |
+
define('SG_HTACCESS_TEMPLATES_PATH', realpath(SG_APP_PATH . '../public/templates/htaccess') . '/');
|
43 |
+
|
44 |
+
//BackupGuard SDK
|
45 |
+
define('SG_BACKUPGUARD_CLIENT_ID', 'wordpress');
|
46 |
+
define('SG_BACKUPGUARD_CLIENT_SECRET', 'AAPQEgsyQrt6wqDBk7fpa24NP6W43evtayxXmUqS');
|
47 |
+
|
48 |
+
define('SG_BACKUPGUARD_UPLOAD_CLIENT_ID', 'backupguard');
|
49 |
+
define('SG_BACKUPGUARD_UPLOAD_CLIENT_SECRET', 'e9503d56b06b95241abf68eaa0d13194aae9503e');
|
50 |
+
|
51 |
+
define('SG_BACKUPGUARD_UPLOAD_SCOPE', 'create_backups');
|
52 |
+
|
53 |
+
//Backup
|
54 |
+
$wpContent = basename(WP_CONTENT_DIR);
|
55 |
+
$wpPlugins = basename(WP_PLUGIN_DIR);
|
56 |
+
$wpThemes = basename(get_theme_root());
|
57 |
+
|
58 |
+
$uploadDir = wp_upload_dir(); // phpcs:ignore
|
59 |
+
$wpUploads = basename($uploadDir['basedir']); // phpcs:ignore
|
60 |
+
|
61 |
+
$dbCharset = 'utf8';
|
62 |
+
if (@constant("DB_CHARSET")) {
|
63 |
+
$dbCharset = DB_CHARSET;
|
64 |
+
}
|
65 |
+
|
66 |
+
//Exclude others plugin dirs
|
67 |
+
function backupGuardFindExcludesDirs()
|
68 |
+
{
|
69 |
+
$callback = function ($value) {
|
70 |
+
return mb_substr($value, 19);
|
71 |
+
};
|
72 |
+
|
73 |
+
$mergedArray = array_merge(
|
74 |
+
glob(WP_CONTENT_DIR . '/*backup*', GLOB_ONLYDIR),
|
75 |
+
glob(WP_CONTENT_DIR . '/*tmp*', GLOB_ONLYDIR),
|
76 |
+
glob(WP_CONTENT_DIR . '/*log*', GLOB_ONLYDIR),
|
77 |
+
glob(WP_CONTENT_DIR . '/uploads/*backup*', GLOB_ONLYDIR),
|
78 |
+
glob(WP_CONTENT_DIR . '/uploads/*log*', GLOB_ONLYDIR),
|
79 |
+
glob(WP_CONTENT_DIR . '/uploads/*temp*', GLOB_ONLYDIR)
|
80 |
+
);
|
81 |
+
|
82 |
+
return array_values(array_map($callback, $mergedArray));
|
83 |
+
}
|
84 |
+
|
85 |
+
$findExcludesDirs = backupGuardFindExcludesDirs();
|
86 |
+
|
87 |
+
//Define same constants in magento config file
|
88 |
+
define('SG_UPLOAD_PATH', $uploadDir['basedir']);
|
89 |
+
define('SG_UPLOAD_URL', $uploadDir['baseurl']);
|
90 |
+
if (!defined('SG_SITE_URL')) {
|
91 |
+
define('SG_SITE_URL', get_site_url());
|
92 |
+
}
|
93 |
+
define('SG_HOME_URL', get_home_url());
|
94 |
+
define('SG_DB_CHARSET', $dbCharset);
|
95 |
+
if (!defined('SG_MYSQL_VERSION')) {
|
96 |
+
define('SG_MYSQL_VERSION', $wpdb->db_version());
|
97 |
+
}
|
98 |
+
$type = "standard";
|
99 |
+
|
100 |
+
if (is_multisite()) {
|
101 |
+
$type = "multisite";
|
102 |
+
}
|
103 |
+
|
104 |
+
define('SG_SITE_TYPE', $type);
|
105 |
+
|
106 |
+
if (!defined('SG_PING_FILE_PATH')) {
|
107 |
+
define('SG_PING_FILE_PATH', $uploadDir['basedir'] . '/backup-guard/ping.json');
|
108 |
+
}
|
109 |
+
//Symlink download
|
110 |
+
define('SG_SYMLINK_PATH', $uploadDir['basedir'] . '/sg_symlinks/');
|
111 |
+
define('SG_SYMLINK_URL', $uploadDir['baseurl'] . '/sg_symlinks/');
|
112 |
+
|
113 |
+
if (!defined('SG_APP_ROOT_DIRECTORY')) {
|
114 |
+
define('SG_APP_ROOT_DIRECTORY', realpath(dirname(WP_CONTENT_DIR) . "/")); //Wordpress Define
|
115 |
+
}
|
116 |
+
|
117 |
+
$sgBackupFilePathsExclude = array(
|
118 |
+
$wpContent . '/' . $wpPlugins . '/backup/',
|
119 |
+
$wpContent . '/' . $wpPlugins . '/backup-guard-pro/',
|
120 |
+
$wpContent . '/' . $wpPlugins . '/backup-guard-silver/',
|
121 |
+
$wpContent . '/' . $wpPlugins . '/backup-guard-gold/',
|
122 |
+
$wpContent . '/' . $wpPlugins . '/backup-guard-platinum/',
|
123 |
+
$wpContent . '/' . $wpUploads . '/sg_symlinks/',
|
124 |
+
$wpContent . '/Dropbox_Backup/',
|
125 |
+
$wpContent . '/updraft/',
|
126 |
+
$wpContent . '/upsupsystic/',
|
127 |
+
$wpContent . '/wpbackitup_backups/',
|
128 |
+
$wpContent . '/wpbackitup_restore/',
|
129 |
+
$wpContent . '/backups/',
|
130 |
+
$wpContent . '/cache/',
|
131 |
+
$wpContent . '/et-cache/',
|
132 |
+
$wpContent . '/litespeed/',
|
133 |
+
$wpContent . '/w3tc-config/',
|
134 |
+
$wpContent . '/wflogs/',
|
135 |
+
$wpContent . '/wp-rocket-config/',
|
136 |
+
$wpContent . '/et-temp/',
|
137 |
+
$wpContent . '/' . $wpUploads . '/wp-clone/',
|
138 |
+
$wpContent . '/' . $wpUploads . '/wp-staging/',
|
139 |
+
$wpContent . '/' . $wpUploads . '/wp-migrate-db/',
|
140 |
+
$wpContent . '/' . $wpUploads . '/db-backup/',
|
141 |
+
$wpContent . '/' . $wpPlugins . '/wordpress-move/backup/',
|
142 |
+
$wpContent . '/as3b_backups/',
|
143 |
+
$wpContent . '/' . $wpUploads . '/backupbuddy_backups/',
|
144 |
+
$wpContent . '/backups-dup-pro/',
|
145 |
+
$wpContent . '/managewp/backups/',
|
146 |
+
$wpContent . '/' . $wpUploads . '/backupbuddy_temp/',
|
147 |
+
$wpContent . '/' . $wpUploads . '/pb_backupbuddy/',
|
148 |
+
$wpContent . '/' . $wpUploads . '/snapshots/',
|
149 |
+
$wpContent . '/debug.log',
|
150 |
+
$wpContent . '/backup-db/',
|
151 |
+
$wpContent . '/' . $wpUploads . '/prime-mover-export-files/',
|
152 |
+
$wpContent . '/' . $wpUploads . '/prime-mover-lock-files/',
|
153 |
+
$wpContent . '/' . $wpUploads . '/prime-mover-tmp-downloads/',
|
154 |
+
$wpContent . '/' . $wpUploads . '/wpo/',
|
155 |
+
$wpContent . '/webtoffee_migrations/',
|
156 |
+
$wpContent . '/WPvivid_Uploads/',
|
157 |
+
$wpContent . '/wpvivid_staging/'
|
158 |
+
);
|
159 |
+
|
160 |
+
define('SG_BACKUP_FILE_PATHS_EXCLUDE', implode(',', array_merge($findExcludesDirs, $sgBackupFilePathsExclude)));
|
161 |
+
if (!defined('SG_BACKUP_DIRECTORY')) {
|
162 |
+
define('SG_BACKUP_DIRECTORY', $uploadDir['basedir'] . '/backup-guard/'); //backups will be stored here
|
163 |
+
}
|
164 |
+
define('SG_BACKUP_DIRECTORY_URL', SG_UPLOAD_URL . '/backup-guard/');
|
165 |
+
|
166 |
+
//Storage
|
167 |
+
define('SG_STORAGE_UPLOAD_CRON', '');
|
168 |
+
|
169 |
+
define('SG_BACKUP_FILE_PATHS', $wpContent . ',' . $wpContent . '/' . $wpPlugins . ',' . $wpContent . '/' . $wpThemes . ',' . $wpContent . '/' . $wpUploads);
|
170 |
+
|
171 |
+
if (!defined('SG_WP_OPTIONS_MIGRATABLE_VALUES')) {
|
172 |
+
define('SG_WP_OPTIONS_MIGRATABLE_VALUES', 'user_roles');
|
173 |
+
}
|
174 |
+
if (!defined('SG_WP_USERMETA_MIGRATABLE_VALUES')) {
|
175 |
+
define('SG_WP_USERMETA_MIGRATABLE_VALUES', 'capabilities,user_level,dashboard_quick_press_last_post_id,user-settings,user-settings-time');
|
176 |
+
}
|
177 |
+
if (!defined('SG_MISC_MIGRATABLE_TABLES')) {
|
178 |
+
define('SG_MISC_MIGRATABLE_TABLES', SG_ENV_DB_PREFIX . 'options,' . SG_ENV_DB_PREFIX . 'usermeta');
|
179 |
+
}
|
180 |
+
if (!defined('SG_MULTISITE_TABLES_TO_MIGRATE')) {
|
181 |
+
define('SG_MULTISITE_TABLES_TO_MIGRATE', SG_ENV_DB_PREFIX . 'blogs,' . SG_ENV_DB_PREFIX . 'site');
|
182 |
+
}
|
183 |
+
if (!defined('SG_SUBDOMAIN_INSTALL')) {
|
184 |
+
define('SG_SUBDOMAIN_INSTALL', defined('SUBDOMAIN_INSTALL') ? SUBDOMAIN_INSTALL : false);
|
185 |
+
}
|
186 |
+
|
187 |
+
define('SG_BACKUP_PRODUCTS_URL', 'https://backup-guard.com/admin/products/view');
|
188 |
+
|
189 |
+
define('SG_BACKUP_GUARD_SECURITY_EXTENSION', 'backup-guard-security');
|
com/core/functions.php
CHANGED
@@ -1,1100 +1,1101 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function backupGuardGetSiteUrl()
|
4 |
-
{
|
5 |
-
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
6 |
-
return get_site_url();
|
7 |
-
} else {
|
8 |
-
return sprintf(
|
9 |
-
"%s://%s%s",
|
10 |
-
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
|
11 |
-
$_SERVER['SERVER_NAME'],
|
12 |
-
$_SERVER['REQUEST_URI']
|
13 |
-
);
|
14 |
-
}
|
15 |
-
}
|
16 |
-
|
17 |
-
function backupGuardGetCapabilities()
|
18 |
-
{
|
19 |
-
switch (SG_PRODUCT_IDENTIFIER) {
|
20 |
-
case 'backup-guard-en':
|
21 |
-
case 'backup-guard-wp-platinum':
|
22 |
-
case 'backup-guard-en-regular':
|
23 |
-
case 'backup-guard-en-extended':
|
24 |
-
return BACKUP_GUARD_CAPABILITIES_PLATINUM;
|
25 |
-
case 'backup-guard-wp-gold':
|
26 |
-
return BACKUP_GUARD_CAPABILITIES_GOLD;
|
27 |
-
case 'backup-guard-wp-silver':
|
28 |
-
return BACKUP_GUARD_CAPABILITIES_SILVER;
|
29 |
-
case 'backup-guard-wp-free':
|
30 |
-
return BACKUP_GUARD_CAPABILITIES_FREE;
|
31 |
-
}
|
32 |
-
}
|
33 |
-
|
34 |
-
function convertToReadableSize($size)
|
35 |
-
{
|
36 |
-
if (!$size) {
|
37 |
-
return '0';
|
38 |
-
}
|
39 |
-
|
40 |
-
$base
|
41 |
-
$suffix = array("", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
|
42 |
-
$fBase
|
43 |
-
|
44 |
-
return round(pow(1000, $base - floor($base)), 1) . $suffix[$fBase];
|
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 |
-
sg1.
|
74 |
-
sg1
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
{
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
$newDateTime
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
$getCurrentTimezone
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
$newDateTime
|
122 |
-
$newDateTime->
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
{
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
{
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
{
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
$
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
$opt
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
$
|
224 |
-
$
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
$path
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
'
|
251 |
-
'
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
$
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
$backupOptions['
|
278 |
-
$backupOptions['
|
279 |
-
$backupOptions['
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
$
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
$
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
$
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
$
|
309 |
-
$
|
310 |
-
$backupOptions['
|
311 |
-
|
312 |
-
|
313 |
-
$backupOptions['
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
{
|
323 |
-
|
324 |
-
$
|
325 |
-
$
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
{
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
$state
|
347 |
-
$
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
$
|
360 |
-
$
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
{
|
378 |
-
|
379 |
-
$objects
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
$
|
402 |
-
$
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
$
|
407 |
-
$step
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
$
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
$days
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
$seconds
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
$
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
$
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
$
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
@
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
{
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
header('Content-
|
528 |
-
header('Content-
|
529 |
-
header('
|
530 |
-
header('
|
531 |
-
header('
|
532 |
-
header('
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
$str
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
header('
|
550 |
-
header('
|
551 |
-
header('Cache-Control:
|
552 |
-
header('
|
553 |
-
header('Content-
|
554 |
-
header('Content-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
$
|
565 |
-
|
566 |
-
|
567 |
-
$
|
568 |
-
|
569 |
-
|
570 |
-
$
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
$
|
575 |
-
|
576 |
-
|
577 |
-
$
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
header('Content-
|
583 |
-
header('Content-
|
584 |
-
header('Content-
|
585 |
-
header(
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
$
|
596 |
-
|
597 |
-
|
598 |
-
$
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
header('Content-
|
604 |
-
header('Content-
|
605 |
-
header('Content-
|
606 |
-
header(
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
$
|
617 |
-
|
618 |
-
|
619 |
-
$
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
header('Content-
|
625 |
-
header('Content-
|
626 |
-
header('Content-
|
627 |
-
header(
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
{
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
$pluginCapabilities
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
$ts
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
$
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
SGConfig::set('
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
$
|
709 |
-
$
|
710 |
-
$
|
711 |
-
$
|
712 |
-
$
|
713 |
-
|
714 |
-
|
715 |
-
$tableName
|
716 |
-
|
717 |
-
|
718 |
-
$
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
case 'backup-guard-en
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
$
|
853 |
-
$
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
}
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
$
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
$
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
$
|
920 |
-
$
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
}
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
$
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
$
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
$
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
$
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
DateTimeZone::
|
1048 |
-
DateTimeZone::
|
1049 |
-
DateTimeZone::
|
1050 |
-
DateTimeZone::
|
1051 |
-
DateTimeZone::
|
1052 |
-
DateTimeZone::
|
1053 |
-
DateTimeZone::
|
1054 |
-
DateTimeZone::
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
$
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
$
|
1074 |
-
$
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function backupGuardGetSiteUrl()
|
4 |
+
{
|
5 |
+
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
6 |
+
return get_site_url();
|
7 |
+
} else {
|
8 |
+
return sprintf(
|
9 |
+
"%s://%s%s",
|
10 |
+
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
|
11 |
+
$_SERVER['SERVER_NAME'],
|
12 |
+
$_SERVER['REQUEST_URI']
|
13 |
+
);
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
function backupGuardGetCapabilities()
|
18 |
+
{
|
19 |
+
switch (SG_PRODUCT_IDENTIFIER) {
|
20 |
+
case 'backup-guard-en':
|
21 |
+
case 'backup-guard-wp-platinum':
|
22 |
+
case 'backup-guard-en-regular':
|
23 |
+
case 'backup-guard-en-extended':
|
24 |
+
return BACKUP_GUARD_CAPABILITIES_PLATINUM;
|
25 |
+
case 'backup-guard-wp-gold':
|
26 |
+
return BACKUP_GUARD_CAPABILITIES_GOLD;
|
27 |
+
case 'backup-guard-wp-silver':
|
28 |
+
return BACKUP_GUARD_CAPABILITIES_SILVER;
|
29 |
+
case 'backup-guard-wp-free':
|
30 |
+
return BACKUP_GUARD_CAPABILITIES_FREE;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
function convertToReadableSize($size)
|
35 |
+
{
|
36 |
+
if (!$size) {
|
37 |
+
return '0';
|
38 |
+
}
|
39 |
+
|
40 |
+
$base = log($size) / log(1000);
|
41 |
+
$suffix = array("", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
|
42 |
+
$fBase = floor($base);
|
43 |
+
|
44 |
+
return round(pow(1000, $base - floor($base)), 1) . $suffix[$fBase];
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
function backupGuardgetSealPopup()
|
49 |
+
{
|
50 |
+
$currentDate = time();
|
51 |
+
$sgShouldShowPopup = SGConfig::get('SG_SHOULD_SHOW_POPUP') == null ? true : SGConfig::get('SG_SHOULD_SHOW_POPUP');
|
52 |
+
$sgPluginInstallUpdateDate = SGConfig::get('SG_PLUGIN_INSTALL_UPDATE_DATE') == null ? time() : SGConfig::get('SG_PLUGIN_INSTALL_UPDATE_DATE');
|
53 |
+
|
54 |
+
// check ig plugin is active for free days show poup
|
55 |
+
if (($currentDate - $sgPluginInstallUpdateDate >= SG_PLUGIN_ACTIVE_INTERVAL) && $sgShouldShowPopup) {
|
56 |
+
?>
|
57 |
+
<script>
|
58 |
+
window.SGPMPopupLoader = window.SGPMPopupLoader || {
|
59 |
+
ids: [], popups: {}, call: function (w, d, s, l, id) {
|
60 |
+
w['sgp'] = w['sgp'] || function () {
|
61 |
+
(w['sgp'].q = w['sgp'].q || []).push(arguments[0]);
|
62 |
+
};
|
63 |
+
var sg1 = d.createElement(s), sg0 = d.getElementsByTagName(s)[0];
|
64 |
+
if (SGPMPopupLoader && SGPMPopupLoader.ids && SGPMPopupLoader.ids.length > 0) {
|
65 |
+
SGPMPopupLoader.ids.push(id);
|
66 |
+
return;
|
67 |
+
}
|
68 |
+
SGPMPopupLoader.ids.push(id);
|
69 |
+
sg1.onload = function () {
|
70 |
+
SGPMPopup.openSGPMPopup();
|
71 |
+
};
|
72 |
+
sg1.async = true;
|
73 |
+
sg1.src = l;
|
74 |
+
sg0.parentNode.insertBefore(sg1, sg0);
|
75 |
+
return {};
|
76 |
+
}
|
77 |
+
};
|
78 |
+
SGPMPopupLoader.call(window, document, 'script', 'https://popupmaker.com/assets/lib/SGPMPopup.min.js', '7c685e17');
|
79 |
+
</script>
|
80 |
+
<?php
|
81 |
+
SGConfig::set('SG_SHOULD_SHOW_POPUP', 0);
|
82 |
+
}
|
83 |
+
|
84 |
+
return;
|
85 |
+
}
|
86 |
+
|
87 |
+
function backupGuardConvertDateTimezone($dateTime, $currentTimezone = false, $dateFormat = "Y-m-d H:i:s", $timeZone = SG_DEFAULT_TIMEZONE)
|
88 |
+
{
|
89 |
+
if ($currentTimezone) {
|
90 |
+
$getCurrentTimezone = SGConfig::get('SG_TIMEZONE', true);
|
91 |
+
|
92 |
+
if ($getCurrentTimezone) {
|
93 |
+
$timeZone = $getCurrentTimezone;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
$newDateTime = new DateTime($dateTime);
|
98 |
+
$newDateTime->setTimezone(new DateTimeZone($timeZone));
|
99 |
+
|
100 |
+
return $newDateTime->format($dateFormat);
|
101 |
+
}
|
102 |
+
|
103 |
+
function backupGuardCeliDateTimezone($time)
|
104 |
+
{
|
105 |
+
|
106 |
+
$currentDateTime = date('Y-m-d H', $time);
|
107 |
+
|
108 |
+
$celiCurrentDateTime = $currentDateTime . ':00:00';
|
109 |
+
|
110 |
+
return date('Y-m-d H:i:s', strtotime($celiCurrentDateTime));
|
111 |
+
}
|
112 |
+
|
113 |
+
function backupGuardConvertDateTimezoneToUTC($dateTime, $timezone = 'UTC')
|
114 |
+
{
|
115 |
+
$getCurrentTimezone = SGConfig::get('SG_TIMEZONE', true);
|
116 |
+
if ($getCurrentTimezone) {
|
117 |
+
$timezone = $getCurrentTimezone;
|
118 |
+
}
|
119 |
+
|
120 |
+
$newDateTime = new DateTime($dateTime, new DateTimeZone($timezone));
|
121 |
+
$newDateTime->setTimezone(new DateTimeZone("UTC"));
|
122 |
+
$dateTimeUTC = $newDateTime->format("Y-m-d H:i:s");
|
123 |
+
|
124 |
+
return $dateTimeUTC;
|
125 |
+
}
|
126 |
+
|
127 |
+
function backupGuardRemoveSlashes($value)
|
128 |
+
{
|
129 |
+
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
130 |
+
return wp_unslash($value);
|
131 |
+
} else {
|
132 |
+
if (is_array($value)) {
|
133 |
+
return array_map('stripslashes', $value);
|
134 |
+
}
|
135 |
+
|
136 |
+
return stripslashes($value);
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
function backupGuardSanitizeTextField($value)
|
141 |
+
{
|
142 |
+
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
143 |
+
if (is_array($value)) {
|
144 |
+
return array_map('sanitize_text_field', $value);
|
145 |
+
}
|
146 |
+
|
147 |
+
return sanitize_text_field($value);
|
148 |
+
} else {
|
149 |
+
if (is_array($value)) {
|
150 |
+
return array_map('strip_tags', $value);
|
151 |
+
}
|
152 |
+
|
153 |
+
return strip_tags($value);
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
function backupGuardIsMultisite()
|
158 |
+
{
|
159 |
+
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
160 |
+
return defined('BG_IS_MULTISITE') ? BG_IS_MULTISITE : is_multisite();
|
161 |
+
} else {
|
162 |
+
return false;
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
function backupGuardGetBanner($env, $type = "plugin", $userType = null)
|
167 |
+
{
|
168 |
+
include_once SG_LIB_PATH . 'BackupGuard/Client.php';
|
169 |
+
$client = new BackupGuard\Client();
|
170 |
+
|
171 |
+
return $client->getBanner(strtolower($env), $type, $userType);
|
172 |
+
}
|
173 |
+
|
174 |
+
function backupGuardGetFilenameOptions($options)
|
175 |
+
{
|
176 |
+
$selectedPaths = explode(',', $options['SG_BACKUP_FILE_PATHS']);
|
177 |
+
$pathsToExclude = explode(',', $options['SG_BACKUP_FILE_PATHS_EXCLUDE']);
|
178 |
+
|
179 |
+
$opt = '';
|
180 |
+
|
181 |
+
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
182 |
+
$opt .= 'opt(';
|
183 |
+
|
184 |
+
if ($options['SG_BACKUP_TYPE'] == SG_BACKUP_TYPE_CUSTOM) {
|
185 |
+
if ($options['SG_ACTION_BACKUP_DATABASE_AVAILABLE']) {
|
186 |
+
$opt .= 'db_';
|
187 |
+
}
|
188 |
+
|
189 |
+
if ($options['SG_ACTION_BACKUP_FILES_AVAILABLE']) {
|
190 |
+
if (in_array('wp-content', $selectedPaths)) {
|
191 |
+
$opt .= 'wpc_';
|
192 |
+
}
|
193 |
+
if (!in_array('wp-content/plugins', $pathsToExclude)) {
|
194 |
+
$opt .= 'plg_';
|
195 |
+
}
|
196 |
+
if (!in_array('wp-content/themes', $pathsToExclude)) {
|
197 |
+
$opt .= 'thm_';
|
198 |
+
}
|
199 |
+
if (!in_array('wp-content/uploads', $pathsToExclude)) {
|
200 |
+
$opt .= 'upl_';
|
201 |
+
}
|
202 |
+
}
|
203 |
+
} else {
|
204 |
+
$opt .= 'full';
|
205 |
+
}
|
206 |
+
|
207 |
+
$opt = trim($opt, "_");
|
208 |
+
$opt .= ')_';
|
209 |
+
}
|
210 |
+
|
211 |
+
return $opt;
|
212 |
+
}
|
213 |
+
|
214 |
+
function backupGuardGenerateToken()
|
215 |
+
{
|
216 |
+
return md5(time());
|
217 |
+
}
|
218 |
+
|
219 |
+
// Parse a URL and return its components
|
220 |
+
function backupGuardParseUrl($url)
|
221 |
+
{
|
222 |
+
$urlComponents = parse_url($url);
|
223 |
+
$domain = $urlComponents['host'];
|
224 |
+
$port = '';
|
225 |
+
|
226 |
+
if (isset($urlComponents['port']) && strlen($urlComponents['port'])) {
|
227 |
+
$port = ":" . $urlComponents['port'];
|
228 |
+
}
|
229 |
+
|
230 |
+
$domain = preg_replace("/(www|\dww|w\dw|ww\d)\./", "", $domain);
|
231 |
+
|
232 |
+
$path = "";
|
233 |
+
if (isset($urlComponents['path'])) {
|
234 |
+
$path = $urlComponents['path'];
|
235 |
+
}
|
236 |
+
|
237 |
+
return $domain . $port . $path;
|
238 |
+
}
|
239 |
+
|
240 |
+
function backupGuardIsReloadEnabled()
|
241 |
+
{
|
242 |
+
// Check if reloads option is turned on
|
243 |
+
return SGConfig::get('SG_BACKUP_WITH_RELOADINGS') ? true : false;
|
244 |
+
}
|
245 |
+
|
246 |
+
function backupGuardGetBackupOptions($options)
|
247 |
+
{
|
248 |
+
$backupOptions = array(
|
249 |
+
'SG_BACKUP_UPLOAD_TO_STORAGES' => '',
|
250 |
+
'SG_BACKUP_FILE_PATHS_EXCLUDE' => '',
|
251 |
+
'SG_BACKUP_FILE_PATHS' => ''
|
252 |
+
);
|
253 |
+
|
254 |
+
if (isset($options['sg-custom-backup-name']) && $options['sg-custom-backup-name']) {
|
255 |
+
SGConfig::set("SG_CUSTOM_BACKUP_NAME", $options['sg-custom-backup-name']);
|
256 |
+
} else {
|
257 |
+
SGConfig::set("SG_CUSTOM_BACKUP_NAME", '');
|
258 |
+
}
|
259 |
+
|
260 |
+
//If background mode
|
261 |
+
$isBackgroundMode = !empty($options['backgroundMode']) ? 1 : 0;
|
262 |
+
|
263 |
+
if ($isBackgroundMode) {
|
264 |
+
$backupOptions['SG_BACKUP_IN_BACKGROUND_MODE'] = $isBackgroundMode;
|
265 |
+
}
|
266 |
+
|
267 |
+
//If cloud backup
|
268 |
+
if (!empty($options['backupCloud']) && count($options['backupStorages'])) {
|
269 |
+
$clouds = $options['backupStorages'];
|
270 |
+
$backupOptions['SG_BACKUP_UPLOAD_TO_STORAGES'] = implode(',', $clouds);
|
271 |
+
}
|
272 |
+
|
273 |
+
$backupOptions['SG_BACKUP_TYPE'] = $options['backupType'];
|
274 |
+
|
275 |
+
if ($options['backupType'] == SG_BACKUP_TYPE_FULL) {
|
276 |
+
$backupOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE'] = 1;
|
277 |
+
$backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 1;
|
278 |
+
$backupOptions['SG_BACKUP_FILE_PATHS_EXCLUDE'] = SG_BACKUP_FILE_PATHS_EXCLUDE;
|
279 |
+
$backupOptions['SG_BACKUP_FILE_PATHS'] = 'wp-content';
|
280 |
+
} else if ($options['backupType'] == SG_BACKUP_TYPE_CUSTOM) {
|
281 |
+
//If database backup
|
282 |
+
$isDatabaseBackup = !empty($options['backupDatabase']) ? 1 : 0;
|
283 |
+
$backupOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE'] = $isDatabaseBackup;
|
284 |
+
|
285 |
+
//If db backup
|
286 |
+
if ($options['backupDBType']) {
|
287 |
+
$tablesToBackup = implode(',', $options['table']);
|
288 |
+
$backupOptions['SG_BACKUP_TABLES_TO_BACKUP'] = $tablesToBackup;
|
289 |
+
}
|
290 |
+
|
291 |
+
//If files backup
|
292 |
+
if (!empty($options['backupFiles']) && count($options['directory'])) {
|
293 |
+
$backupFiles = explode(',', SG_BACKUP_FILE_PATHS);
|
294 |
+
$filesToExclude = @array_diff($backupFiles, $options['directory']);
|
295 |
+
|
296 |
+
if (in_array('wp-content', $options['directory'])) {
|
297 |
+
$options['directory'] = array('wp-content');
|
298 |
+
} else {
|
299 |
+
$filesToExclude = array_diff($filesToExclude, array('wp-content'));
|
300 |
+
}
|
301 |
+
|
302 |
+
$filesToExclude = implode(',', $filesToExclude);
|
303 |
+
if (strlen($filesToExclude)) {
|
304 |
+
$filesToExclude = ',' . $filesToExclude;
|
305 |
+
}
|
306 |
+
|
307 |
+
$backupOptions['SG_BACKUP_FILE_PATHS_EXCLUDE'] = SG_BACKUP_FILE_PATHS_EXCLUDE . $filesToExclude;
|
308 |
+
$options['directory'] = backupGuardSanitizeTextField($options['directory']);
|
309 |
+
$backupOptions['SG_BACKUP_FILE_PATHS'] = implode(',', $options['directory']);
|
310 |
+
$backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 1;
|
311 |
+
} else {
|
312 |
+
$backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] = 0;
|
313 |
+
$backupOptions['SG_BACKUP_FILE_PATHS'] = 0;
|
314 |
+
}
|
315 |
+
}
|
316 |
+
|
317 |
+
return $backupOptions;
|
318 |
+
}
|
319 |
+
|
320 |
+
function backupGuardLoadStateData()
|
321 |
+
{
|
322 |
+
if (file_exists(SG_BACKUP_DIRECTORY . SG_STATE_FILE_NAME)) {
|
323 |
+
$sgState = new SGState();
|
324 |
+
$stateFile = file_get_contents(SG_BACKUP_DIRECTORY . SG_STATE_FILE_NAME);
|
325 |
+
$sgState = $sgState->factory($stateFile);
|
326 |
+
|
327 |
+
return $sgState;
|
328 |
+
}
|
329 |
+
|
330 |
+
return false;
|
331 |
+
}
|
332 |
+
|
333 |
+
function backupGuardValidateApiCall($token)
|
334 |
+
{
|
335 |
+
if (!strlen($token)) {
|
336 |
+
exit();
|
337 |
+
}
|
338 |
+
|
339 |
+
$statePath = SG_BACKUP_DIRECTORY . SG_STATE_FILE_NAME;
|
340 |
+
|
341 |
+
if (!file_exists($statePath)) {
|
342 |
+
exit();
|
343 |
+
}
|
344 |
+
|
345 |
+
$state = file_get_contents($statePath);
|
346 |
+
$state = json_decode($state, true);
|
347 |
+
$stateToken = $state['token'];
|
348 |
+
|
349 |
+
if ($stateToken != $token) {
|
350 |
+
exit();
|
351 |
+
}
|
352 |
+
|
353 |
+
return true;
|
354 |
+
}
|
355 |
+
|
356 |
+
function backupGuardScanBackupsDirectory($path)
|
357 |
+
{
|
358 |
+
$backups = scandir($path);
|
359 |
+
$backupFolders = array();
|
360 |
+
foreach ($backups as $backup) {
|
361 |
+
if ($backup == "." || $backup == "..") {
|
362 |
+
continue;
|
363 |
+
}
|
364 |
+
|
365 |
+
if (is_dir($path . $backup)) {
|
366 |
+
$backupFolders[$backup] = filemtime($path . $backup);
|
367 |
+
}
|
368 |
+
}
|
369 |
+
// Sort(from low to high) backups by creation date
|
370 |
+
asort($backupFolders);
|
371 |
+
|
372 |
+
return $backupFolders;
|
373 |
+
}
|
374 |
+
|
375 |
+
function backupGuardSymlinksCleanup($dir)
|
376 |
+
{
|
377 |
+
if (is_dir($dir)) {
|
378 |
+
$objects = scandir($dir);
|
379 |
+
foreach ($objects as $object) {
|
380 |
+
if ($object == "." || $object == "..") {
|
381 |
+
continue;
|
382 |
+
}
|
383 |
+
|
384 |
+
if (filetype($dir . $object) != "dir") {
|
385 |
+
@unlink($dir . $object);
|
386 |
+
} else {
|
387 |
+
backupGuardSymlinksCleanup($dir . $object . '/');
|
388 |
+
@rmdir($dir . $object);
|
389 |
+
}
|
390 |
+
}
|
391 |
+
} else if (file_exists($dir)) {
|
392 |
+
@unlink($dir);
|
393 |
+
}
|
394 |
+
|
395 |
+
return;
|
396 |
+
}
|
397 |
+
|
398 |
+
function backupGuardRealFilesize($filename)
|
399 |
+
{
|
400 |
+
$fp = fopen($filename, 'r');
|
401 |
+
$return = false;
|
402 |
+
if (is_resource($fp)) {
|
403 |
+
if (PHP_INT_SIZE < 8) { // 32 bit
|
404 |
+
if (0 === fseek($fp, 0, SEEK_END)) {
|
405 |
+
$return = 0.0;
|
406 |
+
$step = 0x7FFFFFFF;
|
407 |
+
while ($step > 0) {
|
408 |
+
if (0 === fseek($fp, -$step, SEEK_CUR)) {
|
409 |
+
$return += floatval($step);
|
410 |
+
} else {
|
411 |
+
$step >>= 1;
|
412 |
+
}
|
413 |
+
}
|
414 |
+
}
|
415 |
+
} else if (0 === fseek($fp, 0, SEEK_END)) { // 64 bit
|
416 |
+
$return = ftell($fp);
|
417 |
+
}
|
418 |
+
}
|
419 |
+
|
420 |
+
return $return;
|
421 |
+
}
|
422 |
+
|
423 |
+
function backupGuardFormattedDuration($startTs, $endTs)
|
424 |
+
{
|
425 |
+
$result = '';
|
426 |
+
$seconds = $endTs - $startTs;
|
427 |
+
|
428 |
+
if ($seconds < 1) {
|
429 |
+
return '0 seconds';
|
430 |
+
}
|
431 |
+
|
432 |
+
$days = intval(intval($seconds) / (3600 * 24));
|
433 |
+
if ($days > 0) {
|
434 |
+
$result .= $days . (($days > 1) ? ' days ' : ' day ');
|
435 |
+
}
|
436 |
+
|
437 |
+
$hours = intval(intval($seconds) / 3600) % 24;
|
438 |
+
if ($hours > 0) {
|
439 |
+
$result .= $hours . (($hours > 1) ? ' hours ' : ' hour ');
|
440 |
+
}
|
441 |
+
|
442 |
+
$minutes = intval(intval($seconds) / 60) % 60;
|
443 |
+
if ($minutes > 0) {
|
444 |
+
$result .= $minutes . (($minutes > 1) ? ' minutes ' : ' minute ');
|
445 |
+
}
|
446 |
+
|
447 |
+
$seconds = intval($seconds) % 60;
|
448 |
+
if ($seconds > 0) {
|
449 |
+
$result .= $seconds . (($seconds > 1) ? ' seconds' : ' second');
|
450 |
+
}
|
451 |
+
|
452 |
+
return $result;
|
453 |
+
}
|
454 |
+
|
455 |
+
function backupGuardDeleteDirectory($dirName)
|
456 |
+
{
|
457 |
+
$dirHandle = null;
|
458 |
+
if (is_dir($dirName)) {
|
459 |
+
$dirHandle = opendir($dirName);
|
460 |
+
}
|
461 |
+
|
462 |
+
if (!$dirHandle) {
|
463 |
+
return false;
|
464 |
+
}
|
465 |
+
|
466 |
+
while ($file = readdir($dirHandle)) {
|
467 |
+
if ($file != "." && $file != "..") {
|
468 |
+
if (!is_dir($dirName . "/" . $file)) {
|
469 |
+
@unlink($dirName . "/" . $file);
|
470 |
+
} else {
|
471 |
+
backupGuardDeleteDirectory($dirName . '/' . $file);
|
472 |
+
}
|
473 |
+
}
|
474 |
+
}
|
475 |
+
|
476 |
+
closedir($dirHandle);
|
477 |
+
|
478 |
+
return @rmdir($dirName);
|
479 |
+
}
|
480 |
+
|
481 |
+
function backupGuardMakeSymlinkFolder($filename)
|
482 |
+
{
|
483 |
+
$filename = backupGuardRemoveSlashes($filename);
|
484 |
+
|
485 |
+
$downloaddir = SG_SYMLINK_PATH;
|
486 |
+
|
487 |
+
if (!file_exists($downloaddir)) {
|
488 |
+
mkdir($downloaddir, 0777);
|
489 |
+
}
|
490 |
+
|
491 |
+
$letters = 'abcdefghijklmnopqrstuvwxyz';
|
492 |
+
srand((double)microtime() * 1000000);
|
493 |
+
$string = '';
|
494 |
+
|
495 |
+
for ($i = 1; $i <= rand(4, 12); $i++) {
|
496 |
+
$q = rand(1, 24);
|
497 |
+
$string = $string . $letters[$q];
|
498 |
+
}
|
499 |
+
|
500 |
+
$handle = opendir($downloaddir);
|
501 |
+
while ($dir = readdir($handle)) {
|
502 |
+
if ($dir == "." || $dir == "..") {
|
503 |
+
continue;
|
504 |
+
}
|
505 |
+
|
506 |
+
if (is_dir($downloaddir . $dir)) {
|
507 |
+
@unlink($downloaddir . $dir . "/" . $filename);
|
508 |
+
@rmdir($downloaddir . $dir);
|
509 |
+
}
|
510 |
+
}
|
511 |
+
|
512 |
+
closedir($handle);
|
513 |
+
mkdir($downloaddir . $string, 0777);
|
514 |
+
|
515 |
+
return $string;
|
516 |
+
}
|
517 |
+
|
518 |
+
function backupGuardDownloadFile($file, $type = 'application/octet-stream')
|
519 |
+
{
|
520 |
+
if (ob_get_level()) {
|
521 |
+
ob_end_clean();
|
522 |
+
}
|
523 |
+
|
524 |
+
$file = backupGuardRemoveSlashes($file);
|
525 |
+
if (file_exists($file)) {
|
526 |
+
header('Content-Description: File Transfer');
|
527 |
+
header('Content-Type: ' . $type);
|
528 |
+
header('Content-Disposition: attachment; filename="' . basename($file) . '";');
|
529 |
+
header('Expires: 0');
|
530 |
+
header('Cache-Control: must-revalidate');
|
531 |
+
header('Pragma: public');
|
532 |
+
header('Content-Length: ' . filesize($file));
|
533 |
+
readfile($file);
|
534 |
+
}
|
535 |
+
|
536 |
+
exit;
|
537 |
+
}
|
538 |
+
|
539 |
+
function backupGuardDownloadViaPhp($backupName, $fileName)
|
540 |
+
{
|
541 |
+
$str = backupGuardMakeSymlinkFolder($fileName);
|
542 |
+
@copy(SG_BACKUP_DIRECTORY . $backupName . '/' . $fileName, SG_SYMLINK_PATH . $str . '/' . $fileName);
|
543 |
+
|
544 |
+
if (file_exists(SG_SYMLINK_PATH . $str . '/' . $fileName)) {
|
545 |
+
$remoteGet = wp_remote_get(SG_SYMLINK_URL . $str . '/' . $fileName);
|
546 |
+
if (!is_wp_error($remoteGet)) {
|
547 |
+
$content = wp_remote_retrieve_body($remoteGet);
|
548 |
+
header('Pragma: public');
|
549 |
+
header('Expires: 0');
|
550 |
+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
551 |
+
header('Cache-Control: private', false);
|
552 |
+
header('Content-Type: application/octet-stream');
|
553 |
+
header('Content-Disposition: attachment; filename=' . $fileName . ';');
|
554 |
+
header('Content-Transfer-Encoding: binary');
|
555 |
+
echo $content;
|
556 |
+
exit;
|
557 |
+
}
|
558 |
+
}
|
559 |
+
}
|
560 |
+
|
561 |
+
function backupGuardDownloadFileViaFunction($safeDir, $fileName, $type)
|
562 |
+
{
|
563 |
+
$downloadDir = SG_SYMLINK_PATH;
|
564 |
+
$downloadURL = SG_SYMLINK_URL;
|
565 |
+
|
566 |
+
$safeDir = backupGuardRemoveSlashes($safeDir);
|
567 |
+
$string = backupGuardMakeSymlinkFolder($fileName);
|
568 |
+
|
569 |
+
$target = $safeDir . $fileName;
|
570 |
+
$link = $downloadDir . $string . '/' . $fileName;
|
571 |
+
|
572 |
+
if ($type == BACKUP_GUARD_DOWNLOAD_MODE_LINK) {
|
573 |
+
$res = @link($target, $link);
|
574 |
+
$name = 'link';
|
575 |
+
} else {
|
576 |
+
$res = @symlink($target, $link);
|
577 |
+
$name = 'symlink';
|
578 |
+
}
|
579 |
+
|
580 |
+
if ($res) {
|
581 |
+
header('Content-Description: File Transfer');
|
582 |
+
header('Content-Type: application/octet-stream');
|
583 |
+
header('Content-Disposition: attachment;filename="' . $fileName . '"');
|
584 |
+
header('Content-Transfer-Encoding: binary');
|
585 |
+
header("Location: " . $downloadURL . $string . "/" . $fileName);
|
586 |
+
} else {
|
587 |
+
wp_die(_backupGuardT(ucfirst($name) . " / shortcut creation failed! Seems your server configurations don't allow $name creation, so we're unable to provide you the direct download url. You can download your backup using any FTP client. All backups and related stuff we locate '/wp-content/uploads/backup-guard' directory. If you need this functionality, you should check out your server configurations and make sure you don't have any limitation related to $name creation.", true));
|
588 |
+
}
|
589 |
+
exit;
|
590 |
+
}
|
591 |
+
|
592 |
+
function backupGuardDownloadFileSymlink($safedir, $filename)
|
593 |
+
{
|
594 |
+
$downloaddir = SG_SYMLINK_PATH;
|
595 |
+
$downloadURL = SG_SYMLINK_URL;
|
596 |
+
|
597 |
+
$safedir = backupGuardRemoveSlashes($safedir);
|
598 |
+
$string = backupGuardMakeSymlinkFolder($filename);
|
599 |
+
|
600 |
+
$res = @symlink($safedir . $filename, $downloaddir . $string . "/" . $filename);
|
601 |
+
if ($res) {
|
602 |
+
header('Content-Description: File Transfer');
|
603 |
+
header('Content-Type: application/octet-stream');
|
604 |
+
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
605 |
+
header('Content-Transfer-Encoding: binary');
|
606 |
+
header("Location: " . $downloadURL . $string . "/" . $filename);
|
607 |
+
} else {
|
608 |
+
wp_die(_backupGuardT("Symlink / shortcut creation failed! Seems your server configurations don't allow symlink creation, so we're unable to provide you the direct download url. You can download your backup using any FTP client. All backups and related stuff we locate '/wp-content/uploads/backup-guard' directory. If you need this functionality, you should check out your server configurations and make sure you don't have any limitation related to symlink creation.", true));
|
609 |
+
}
|
610 |
+
exit;
|
611 |
+
}
|
612 |
+
|
613 |
+
function backupGuardDownloadFileLink($safedir, $filename)
|
614 |
+
{
|
615 |
+
$downloaddir = SG_SYMLINK_PATH;
|
616 |
+
$downloadURL = SG_SYMLINK_URL;
|
617 |
+
|
618 |
+
$safedir = backupGuardRemoveSlashes($safedir);
|
619 |
+
$string = backupGuardMakeSymlinkFolder($filename);
|
620 |
+
|
621 |
+
$res = @link($safedir . $filename, $downloaddir . $string . "/" . $filename);
|
622 |
+
if ($res) {
|
623 |
+
header('Content-Description: File Transfer');
|
624 |
+
header('Content-Type: application/octet-stream');
|
625 |
+
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
626 |
+
header('Content-Transfer-Encoding: binary');
|
627 |
+
header("Location: " . $downloadURL . $string . "/" . $filename);
|
628 |
+
} else {
|
629 |
+
wp_die(_backupGuardT("Link / shortcut creation failed! Seems your server configurations don't allow link creation, so we're unable to provide you the direct download url. You can download your backup using any FTP client. All backups and related stuff we locate '/wp-content/uploads/backup-guard' directory. If you need this functionality, you should check out your server configurations and make sure you don't have any limitation related to link creation.", true));
|
630 |
+
}
|
631 |
+
exit;
|
632 |
+
}
|
633 |
+
|
634 |
+
function backupGuardGetCurrentUrlScheme()
|
635 |
+
{
|
636 |
+
return (is_ssl()) ? 'https' : 'http';
|
637 |
+
}
|
638 |
+
|
639 |
+
function backupGuardGetCurrentUrlHost()
|
640 |
+
{
|
641 |
+
if (defined('SG_SITE_URL')) {
|
642 |
+
$url = SG_SITE_URL;
|
643 |
+
} else {
|
644 |
+
$url = get_site_url();
|
645 |
+
}
|
646 |
+
|
647 |
+
$parseUrl = parse_url($url);
|
648 |
+
|
649 |
+
return $parseUrl['host'];
|
650 |
+
}
|
651 |
+
|
652 |
+
function backupGuardValidateLicense()
|
653 |
+
{
|
654 |
+
$pluginCapabilities = backupGuardGetCapabilities();
|
655 |
+
if ($pluginCapabilities == BACKUP_GUARD_CAPABILITIES_FREE) {
|
656 |
+
return true;
|
657 |
+
}
|
658 |
+
|
659 |
+
//only check once per day
|
660 |
+
$ts = (int)SGConfig::get('SG_LICENSE_CHECK_TS');
|
661 |
+
if (time() - $ts < SG_LICENSE_CHECK_TIMEOUT) {
|
662 |
+
return true;
|
663 |
+
}
|
664 |
+
|
665 |
+
include_once SG_LIB_PATH . 'SGAuthClient.php';
|
666 |
+
|
667 |
+
$url = site_url();
|
668 |
+
|
669 |
+
$auth = SGAuthClient::getInstance();
|
670 |
+
$res = $auth->validateUrl($url);
|
671 |
+
|
672 |
+
if ($res === -1) { //login is required
|
673 |
+
backup_guard_login_page();
|
674 |
+
|
675 |
+
return false;
|
676 |
+
} else if ($res === false) { //invalid license
|
677 |
+
backup_guard_link_license_page();
|
678 |
+
|
679 |
+
return false;
|
680 |
+
} else {
|
681 |
+
SGConfig::set('SG_LICENSE_CHECK_TS', time(), true);
|
682 |
+
SGConfig::set('SG_LICENSE_KEY', $res, true);
|
683 |
+
}
|
684 |
+
|
685 |
+
return true;
|
686 |
+
}
|
687 |
+
|
688 |
+
//returns true if string $haystack ends with string $needle or $needle is an empty string
|
689 |
+
function backupGuardStringEndsWith($haystack, $needle)
|
690 |
+
{
|
691 |
+
$length = strlen($needle);
|
692 |
+
|
693 |
+
return $length === 0 ||
|
694 |
+
(substr($haystack, -$length) === $needle);
|
695 |
+
}
|
696 |
+
|
697 |
+
//returns true if string $haystack starts with string $needle
|
698 |
+
function backupGuardStringStartsWith($haystack, $needle)
|
699 |
+
{
|
700 |
+
$length = strlen($needle);
|
701 |
+
|
702 |
+
return (substr($haystack, 0, $length) === $needle);
|
703 |
+
}
|
704 |
+
|
705 |
+
function backupGuardGetDbTables()
|
706 |
+
{
|
707 |
+
$sgdb = SGDatabase::getInstance();
|
708 |
+
$tables = $sgdb->query("SHOW TABLES");
|
709 |
+
$tablesKey = 'Tables_in_' . SG_DB_NAME;
|
710 |
+
$tableNames = array();
|
711 |
+
$customTablesToExclude = str_replace(' ', '', SGConfig::get('SG_TABLES_TO_EXCLUDE'));
|
712 |
+
$tablesToExclude = explode(',', $customTablesToExclude);
|
713 |
+
foreach ($tables as $table) :
|
714 |
+
$tableName = $table[$tablesKey];
|
715 |
+
if ($tableName != SG_ACTION_TABLE_NAME && $tableName != SG_CONFIG_TABLE_NAME && $tableName != SG_SCHEDULE_TABLE_NAME) {
|
716 |
+
array_push(
|
717 |
+
$tableNames,
|
718 |
+
array('name' => $tableName,
|
719 |
+
'current' => backupGuardStringStartsWith($tableName, SG_ENV_DB_PREFIX) ? 'true' : 'false',
|
720 |
+
'disabled' => in_array($tableName, $tablesToExclude) ? 'disabled' : '')
|
721 |
+
);
|
722 |
+
}
|
723 |
+
endforeach;
|
724 |
+
usort(
|
725 |
+
$tableNames,
|
726 |
+
function ($name1, $name2) {
|
727 |
+
if (backupGuardStringStartsWith($name1['name'], SG_ENV_DB_PREFIX)) {
|
728 |
+
if (backupGuardStringStartsWith($name2['name'], SG_ENV_DB_PREFIX)) {
|
729 |
+
return 0;
|
730 |
+
}
|
731 |
+
|
732 |
+
return -1;
|
733 |
+
}
|
734 |
+
|
735 |
+
return 1;
|
736 |
+
}
|
737 |
+
);
|
738 |
+
|
739 |
+
return $tableNames;
|
740 |
+
}
|
741 |
+
|
742 |
+
function backupGuardGetBackupTablesHTML($defaultChecked = false)
|
743 |
+
{
|
744 |
+
$tables = backupGuardGetDbTables();
|
745 |
+
?>
|
746 |
+
|
747 |
+
<div class="checkbox">
|
748 |
+
<label for="custom-backupdb-chbx">
|
749 |
+
<input type="checkbox" class="sg-custom-option" name="backupDatabase"
|
750 |
+
id="custom-backupdb-chbx" <?php echo $defaultChecked ? 'checked' : '' ?>>
|
751 |
+
<span class="sg-checkbox-label-text"><?php _backupGuardT('Backup database'); ?></span>
|
752 |
+
</label>
|
753 |
+
<div class="col-md-12 sg-checkbox sg-backup-db-options">
|
754 |
+
<div class="checkbox">
|
755 |
+
<label for="custombackupdbfull-radio" class="sg-backup-db-mode"
|
756 |
+
title="<?php _backupGuardT('Backup all tables found in the database') ?>">
|
757 |
+
<input type="radio" name="backupDBType" id="custombackupdbfull-radio" value="0" checked>
|
758 |
+
<?php _backupGuardT('Full'); ?>
|
759 |
+
</label>
|
760 |
+
<label for="custombackupdbcurent-radio" class="sg-backup-db-mode"
|
761 |
+
title="<?php echo _backupGuardT('Backup tables related to the current WordPress installation. Only tables with', true) . ' ' . SG_ENV_DB_PREFIX . ' ' . _backupGuardT('will be backed up', true) ?>">
|
762 |
+
<input type="radio" name="backupDBType" id="custombackupdbcurent-radio" value="1">
|
763 |
+
<?php _backupGuardT('Only WordPress'); ?>
|
764 |
+
</label>
|
765 |
+
<label for="custombackupdbcustom-radio" class="sg-backup-db-mode"
|
766 |
+
title="<?php _backupGuardT('Select tables you want to include in your backup') ?>">
|
767 |
+
<input type="radio" name="backupDBType" id="custombackupdbcustom-radio" value="2">
|
768 |
+
<?php _backupGuardT('Custom'); ?>
|
769 |
+
</label>
|
770 |
+
<!--Tables-->
|
771 |
+
<div class="col-md-12 sg-custom-backup-tables">
|
772 |
+
<?php foreach ($tables as $table) : ?>
|
773 |
+
<div class="checkbox">
|
774 |
+
<label for="<?php echo $table['name'] ?>">
|
775 |
+
<input type="checkbox" name="table[]"
|
776 |
+
current="<?php echo $table['current'] ?>" <?php echo $table['disabled'] ?>
|
777 |
+
id="<?php echo $table['name'] ?>" value="<?php echo $table['name']; ?>">
|
778 |
+
<span class="sg-checkbox-label-text"><?php echo basename($table['name']); ?></span>
|
779 |
+
<?php if ($table['disabled']) { ?>
|
780 |
+
<span class="sg-disableText"><?php _backupGuardT('(excluded from settings)') ?></span>
|
781 |
+
<?php } ?>
|
782 |
+
</label>
|
783 |
+
</div>
|
784 |
+
<?php endforeach; ?>
|
785 |
+
</div>
|
786 |
+
</div>
|
787 |
+
</div>
|
788 |
+
|
789 |
+
</div>
|
790 |
+
|
791 |
+
<?php
|
792 |
+
}
|
793 |
+
|
794 |
+
function backupGuardIsAccountGold()
|
795 |
+
{
|
796 |
+
return strpos("gold", SG_PRODUCT_IDENTIFIER) !== false;
|
797 |
+
}
|
798 |
+
|
799 |
+
function backupGuardGetProductName()
|
800 |
+
{
|
801 |
+
$name = '';
|
802 |
+
switch (SG_PRODUCT_IDENTIFIER) {
|
803 |
+
case 'backup-guard-wp-silver':
|
804 |
+
$name = 'Silver';
|
805 |
+
break;
|
806 |
+
case 'backup-guard-wp-platinum':
|
807 |
+
$name = 'Platinum';
|
808 |
+
break;
|
809 |
+
case 'backup-guard-en':
|
810 |
+
case 'backup-guard-en-regular':
|
811 |
+
$name = 'Regular';
|
812 |
+
break;
|
813 |
+
case 'backup-guard-en-extended':
|
814 |
+
$name = 'Extended';
|
815 |
+
break;
|
816 |
+
case 'backup-guard-wp-gold':
|
817 |
+
$name = 'Gold';
|
818 |
+
break;
|
819 |
+
case 'backup-guard-wp-free':
|
820 |
+
$name = 'Free';
|
821 |
+
break;
|
822 |
+
}
|
823 |
+
|
824 |
+
return $name;
|
825 |
+
}
|
826 |
+
|
827 |
+
function backupGuardGetFileSelectiveRestore()
|
828 |
+
{
|
829 |
+
?>
|
830 |
+
<div class="col-md-12 sg-checkbox sg-restore-files-options">
|
831 |
+
<div class="checkbox">
|
832 |
+
<label for="restorefilesfull-radio" class="sg-restore-files-mode">
|
833 |
+
<input type="radio" name="restoreFilesType" checked id="restorefilesfull-radio" value="0">
|
834 |
+
<?php _backupGuardT('Full'); ?>
|
835 |
+
</label>
|
836 |
+
|
837 |
+
<label for="restorefilescustom-radio" class="sg-restore-files-mode">
|
838 |
+
<input type="radio" name="restoreFilesType" id="restorefilescustom-radio" value="1">
|
839 |
+
<?php _backupGuardT('Custom'); ?>
|
840 |
+
</label>
|
841 |
+
<!--Files-->
|
842 |
+
<div class="col-md-12 sg-file-selective-restore">
|
843 |
+
<div id="fileSystemTreeContainer"></div>
|
844 |
+
</div>
|
845 |
+
</div>
|
846 |
+
</div>
|
847 |
+
<?php
|
848 |
+
}
|
849 |
+
|
850 |
+
function checkAllMissedTables()
|
851 |
+
{
|
852 |
+
$sgdb = SGDatabase::getInstance();
|
853 |
+
$allTables = array(SG_CONFIG_TABLE_NAME, SG_SCHEDULE_TABLE_NAME, SG_ACTION_TABLE_NAME);
|
854 |
+
$status = true;
|
855 |
+
|
856 |
+
foreach ($allTables as $table) {
|
857 |
+
$query = $sgdb->query(
|
858 |
+
"SELECT count(*) as isExists
|
859 |
+
FROM information_schema.TABLES
|
860 |
+
WHERE (TABLE_SCHEMA = '" . DB_NAME . "') AND (TABLE_NAME = '$table')"
|
861 |
+
);
|
862 |
+
|
863 |
+
if (empty($query[0]['isExists'])) {
|
864 |
+
$status = false;
|
865 |
+
}
|
866 |
+
}
|
867 |
+
|
868 |
+
return $status;
|
869 |
+
}
|
870 |
+
|
871 |
+
function backupGuardIncludeFile($filePath)
|
872 |
+
{
|
873 |
+
if (file_exists($filePath)) {
|
874 |
+
include_once $filePath;
|
875 |
+
}
|
876 |
+
}
|
877 |
+
|
878 |
+
function getCloudUploadDefaultMaxChunkSize()
|
879 |
+
{
|
880 |
+
$memory = (int)SGBoot::$memoryLimit;
|
881 |
+
$uploadSize = 1;
|
882 |
+
|
883 |
+
if ($memory <= 128) {
|
884 |
+
$uploadSize = 4;
|
885 |
+
} else if ($memory > 128 && $memory <= 256) {
|
886 |
+
$uploadSize = 8;
|
887 |
+
} else if ($memory > 256 && $memory <= 512) {
|
888 |
+
$uploadSize = 16;
|
889 |
+
} else if ($memory > 512) {
|
890 |
+
$uploadSize = 32;
|
891 |
+
}
|
892 |
+
|
893 |
+
return $uploadSize;
|
894 |
+
}
|
895 |
+
|
896 |
+
function getCloudUploadChunkSize()
|
897 |
+
{
|
898 |
+
$cloudUploadDefaultChunkSize = (int)getCloudUploadDefaultMaxChunkSize();
|
899 |
+
$savedCloudUploadChunkSize = (int)SGConfig::get('SG_BACKUP_CLOUD_UPLOAD_CHUNK_SIZE');
|
900 |
+
|
901 |
+
return ($savedCloudUploadChunkSize ? $savedCloudUploadChunkSize : $cloudUploadDefaultChunkSize);
|
902 |
+
}
|
903 |
+
|
904 |
+
function backupGuardCheckOS()
|
905 |
+
{
|
906 |
+
$os = strtoupper(substr(PHP_OS, 0, 3));
|
907 |
+
|
908 |
+
if ($os === 'WIN') {
|
909 |
+
return 'windows';
|
910 |
+
} else if ($os === 'LIN') {
|
911 |
+
return 'linux';
|
912 |
+
}
|
913 |
+
|
914 |
+
return 'other';
|
915 |
+
}
|
916 |
+
|
917 |
+
function backupGuardCheckDownloadMode()
|
918 |
+
{
|
919 |
+
$system = backupGuardCheckOS();
|
920 |
+
$link = false;
|
921 |
+
$symlink = false;
|
922 |
+
|
923 |
+
if (!file_exists(SG_SYMLINK_PATH)) {
|
924 |
+
mkdir(SG_SYMLINK_PATH);
|
925 |
+
}
|
926 |
+
|
927 |
+
backupGuardRemoveDownloadTmpFiles();
|
928 |
+
|
929 |
+
$testFile = fopen(SG_SYMLINK_PATH . 'test.log', 'w');
|
930 |
+
|
931 |
+
if (!$testFile) {
|
932 |
+
return BACKUP_GUARD_DOWNLOAD_MODE_PHP;
|
933 |
+
}
|
934 |
+
|
935 |
+
if (function_exists('link')) {
|
936 |
+
$link = @link(SG_SYMLINK_PATH . 'test.log', SG_SYMLINK_PATH . 'link.log');
|
937 |
+
}
|
938 |
+
|
939 |
+
if (function_exists('symlink')) {
|
940 |
+
$symlink = @symlink(SG_SYMLINK_PATH . 'test.log', SG_SYMLINK_PATH . 'symlink.log');
|
941 |
+
}
|
942 |
+
|
943 |
+
backupGuardRemoveDownloadTmpFiles();
|
944 |
+
|
945 |
+
if ($system == 'windows') {
|
946 |
+
if ($symlink) {
|
947 |
+
return BACKUP_GUARD_DOWNLOAD_MODE_SYMLINK;
|
948 |
+
}
|
949 |
+
} else {
|
950 |
+
if ($link) {
|
951 |
+
return BACKUP_GUARD_DOWNLOAD_MODE_LINK;
|
952 |
+
} elseif ($symlink) {
|
953 |
+
return BACKUP_GUARD_DOWNLOAD_MODE_SYMLINK;
|
954 |
+
}
|
955 |
+
}
|
956 |
+
|
957 |
+
return BACKUP_GUARD_DOWNLOAD_MODE_PHP;
|
958 |
+
}
|
959 |
+
|
960 |
+
function backupGuardRemoveDownloadTmpFiles()
|
961 |
+
{
|
962 |
+
if (file_exists(SG_SYMLINK_PATH . 'test.log')) {
|
963 |
+
@unlink(SG_SYMLINK_PATH . 'test.log');
|
964 |
+
}
|
965 |
+
|
966 |
+
if (file_exists(SG_SYMLINK_PATH . 'link.log')) {
|
967 |
+
@unlink(SG_SYMLINK_PATH . 'link.log');
|
968 |
+
}
|
969 |
+
|
970 |
+
if (file_exists(SG_SYMLINK_PATH . 'symlink.log') || is_link(SG_SYMLINK_PATH . 'symlink.log')) {
|
971 |
+
@unlink(SG_SYMLINK_PATH . 'symlink.log');
|
972 |
+
}
|
973 |
+
}
|
974 |
+
|
975 |
+
function backupGuardMigrateDownloadMode()
|
976 |
+
{
|
977 |
+
$downloadModeRow = SGConfig::get('SG_DOWNLOAD_MODE', true);
|
978 |
+
|
979 |
+
if (!is_null($downloadModeRow)) {
|
980 |
+
return true;
|
981 |
+
}
|
982 |
+
|
983 |
+
$downloadMode = BACKUP_GUARD_DOWNLOAD_MODE_PHP;
|
984 |
+
$downloadViaPhp = SGConfig::get('SG_DOWNLOAD_VIA_PHP', true);
|
985 |
+
|
986 |
+
if ($downloadViaPhp != BACKUP_GUARD_DOWNLOAD_MODE_PHP) {
|
987 |
+
$downloadMode = backupGuardCheckDownloadMode();
|
988 |
+
}
|
989 |
+
|
990 |
+
SGConfig::set('SG_DOWNLOAD_MODE', $downloadMode);
|
991 |
+
|
992 |
+
return true;
|
993 |
+
}
|
994 |
+
|
995 |
+
function addLiteSpeedHtaccessModule()
|
996 |
+
{
|
997 |
+
$server = '';
|
998 |
+
if (isset($_SERVER['SERVER_SOFTWARE'])) {
|
999 |
+
$server = strtolower($_SERVER['SERVER_SOFTWARE']);
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
if (strpos($server, 'litespeed') !== false) {
|
1003 |
+
$htaccessFile = ABSPATH . '.htaccess';
|
1004 |
+
$htaccessContent = '';
|
1005 |
+
|
1006 |
+
if (is_readable($htaccessFile)) {
|
1007 |
+
$htaccessContent = @file_get_contents($htaccessFile);
|
1008 |
+
if (!$htaccessContent) {
|
1009 |
+
$htaccessContent = '';
|
1010 |
+
}
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
if (!$htaccessContent || !preg_match('/noabort/i', $htaccessContent)) {
|
1014 |
+
$liteSpeedTemplate = file_get_contents(SG_HTACCESS_TEMPLATES_PATH . 'liteSpeed.php');
|
1015 |
+
$result = file_put_contents($htaccessFile, "\n" . $liteSpeedTemplate, FILE_APPEND);
|
1016 |
+
|
1017 |
+
if ($result) {
|
1018 |
+
return true;
|
1019 |
+
}
|
1020 |
+
}
|
1021 |
+
}
|
1022 |
+
|
1023 |
+
return false;
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
function removeLiteSpeedHtaccessModule()
|
1027 |
+
{
|
1028 |
+
$htaccessFile = ABSPATH . '.htaccess';
|
1029 |
+
$htaccessContent = file_get_contents($htaccessFile);
|
1030 |
+
|
1031 |
+
$result = preg_replace('/(# LITESPEED START[\s\S]+?# LITESPEED END)/', '', $htaccessContent);
|
1032 |
+
|
1033 |
+
if ($result) {
|
1034 |
+
$change = file_put_contents($htaccessFile, $result);
|
1035 |
+
|
1036 |
+
if ($change) {
|
1037 |
+
return true;
|
1038 |
+
}
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
return false;
|
1042 |
+
}
|
1043 |
+
|
1044 |
+
function getAllTimezones()
|
1045 |
+
{
|
1046 |
+
static $regions = array(
|
1047 |
+
DateTimeZone::AFRICA,
|
1048 |
+
DateTimeZone::AMERICA,
|
1049 |
+
DateTimeZone::ANTARCTICA,
|
1050 |
+
DateTimeZone::ASIA,
|
1051 |
+
DateTimeZone::ATLANTIC,
|
1052 |
+
DateTimeZone::AUSTRALIA,
|
1053 |
+
DateTimeZone::EUROPE,
|
1054 |
+
DateTimeZone::INDIAN,
|
1055 |
+
DateTimeZone::PACIFIC,
|
1056 |
+
);
|
1057 |
+
|
1058 |
+
$timezones = array();
|
1059 |
+
foreach ($regions as $region) {
|
1060 |
+
$timezones = array_merge($timezones, DateTimeZone::listIdentifiers($region));
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
$timezoneOffsets = array();
|
1064 |
+
foreach ($timezones as $timezone) {
|
1065 |
+
$tz = new DateTimeZone($timezone);
|
1066 |
+
$timezoneOffsets[$timezone] = $tz->getOffset(new DateTime());
|
1067 |
+
}
|
1068 |
+
|
1069 |
+
asort($timezoneOffsets);
|
1070 |
+
|
1071 |
+
$timezoneList = array();
|
1072 |
+
foreach ($timezoneOffsets as $timezone => $offset) {
|
1073 |
+
$offsetPrefix = $offset < 0 ? '-' : '+';
|
1074 |
+
$offsetFormatted = gmdate('H:i', abs($offset));
|
1075 |
+
$offsetFormattedOnlyHour = gmdate('H', abs($offset));
|
1076 |
+
|
1077 |
+
$prettyOffset = "UTC${offsetPrefix}${offsetFormatted}";
|
1078 |
+
|
1079 |
+
$timezoneList[$timezone] = ["(${prettyOffset}) $timezone", "${offsetPrefix}${offsetFormattedOnlyHour}"];
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
return $timezoneList;
|
1083 |
+
}
|
1084 |
+
|
1085 |
+
function backupGuardIsMaintenanceMode()
|
1086 |
+
{
|
1087 |
+
if (file_exists(ABSPATH . '.maintenance')) {
|
1088 |
+
return true;
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
return false;
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
function backupGuardDiskFreeSize($dir)
|
1095 |
+
{
|
1096 |
+
if (function_exists('disk_free_space')) {
|
1097 |
+
return convertToReadableSize(@disk_free_space($dir));
|
1098 |
+
}
|
1099 |
+
|
1100 |
+
return 0;
|
1101 |
+
}
|
com/core/storage/SGDropboxStorage.php
CHANGED
@@ -1,405 +1,462 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once SG_STORAGE_PATH . 'SGStorage.php';
|
4 |
-
|
5 |
-
use Dropbox as dbx;
|
6 |
-
|
7 |
-
class SGDropboxStorage extends SGStorage
|
8 |
-
{
|
9 |
-
private $_client
|
10 |
-
private $_fd
|
11 |
-
private $_filePath = '';
|
12 |
-
|
13 |
-
public function init()
|
14 |
-
{
|
15 |
-
//check if curl extension is loaded
|
16 |
-
SGBoot::checkRequirement('curl');
|
17 |
-
|
18 |
-
// Dropbox api 2
|
19 |
-
$this->setActiveDirectory('');
|
20 |
-
|
21 |
-
@set_exception_handler(array('SGDropboxStorage', 'exceptionHandler'));
|
22 |
-
include_once SG_STORAGE_PATH . 'SGDropbox.php';
|
23 |
-
}
|
24 |
-
|
25 |
-
public static function exceptionHandler($exception)
|
26 |
-
{
|
27 |
-
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
28 |
-
wp_die($exception->getMessage());
|
29 |
-
} elseif (SG_ENV_ADAPTER == SG_ENV_MAGENTO) {
|
30 |
-
die($exception->getMessage());
|
31 |
-
}
|
32 |
-
}
|
33 |
-
|
34 |
-
public function connect()
|
35 |
-
{
|
36 |
-
if ($this->isConnected()) {
|
37 |
-
return;
|
38 |
-
}
|
39 |
-
|
40 |
-
// phpcs:disable
|
41 |
-
$authCode = $this->getAuthCodeFromURL($cancel);
|
42 |
-
|
43 |
-
if ($cancel) {
|
44 |
-
throw new SGExceptionMethodNotAllowed('User did not allow access');
|
45 |
-
}
|
46 |
-
// phpcs:enable
|
47 |
-
|
48 |
-
$this->auth($authCode);
|
49 |
-
}
|
50 |
-
|
51 |
-
private function auth($authCode = '')
|
52 |
-
{
|
53 |
-
if ($authCode) {
|
54 |
-
try {
|
55 |
-
//exchange authorization code for access token
|
56 |
-
parse_str($_SERVER['QUERY_STRING'], $arr);
|
57 |
-
list($accessToken) = $this->getWebAuth()->finish($arr);
|
58 |
-
|
59 |
-
$this->setAccessToken($accessToken);
|
60 |
-
$
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
}
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
$
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
$
|
108 |
-
|
109 |
-
$
|
110 |
-
|
111 |
-
|
112 |
-
'
|
113 |
-
'
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
$
|
143 |
-
|
144 |
-
$
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
$
|
152 |
-
$
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
$curl->
|
167 |
-
$curl->
|
168 |
-
$curl->
|
169 |
-
|
170 |
-
$
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
$
|
205 |
-
$
|
206 |
-
$
|
207 |
-
|
208 |
-
$this->
|
209 |
-
|
210 |
-
$this->state->
|
211 |
-
$this->state->
|
212 |
-
$this->state->
|
213 |
-
$this->state->
|
214 |
-
$this->state->
|
215 |
-
$this->state->
|
216 |
-
$this->state->
|
217 |
-
$this->state->
|
218 |
-
$this->state->
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
$
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
$
|
240 |
-
|
241 |
-
$
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
$
|
249 |
-
|
250 |
-
$
|
251 |
-
}
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
$
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
$this->
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
$
|
278 |
-
|
279 |
-
$
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
}
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
$
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
$
|
354 |
-
$
|
355 |
-
$
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
$
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
$
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
if (!$
|
376 |
-
$
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once SG_STORAGE_PATH . 'SGStorage.php';
|
4 |
+
|
5 |
+
use Dropbox as dbx;
|
6 |
+
|
7 |
+
class SGDropboxStorage extends SGStorage
|
8 |
+
{
|
9 |
+
private $_client = null;
|
10 |
+
private $_fd = null;
|
11 |
+
private $_filePath = '';
|
12 |
+
|
13 |
+
public function init()
|
14 |
+
{
|
15 |
+
//check if curl extension is loaded
|
16 |
+
SGBoot::checkRequirement('curl');
|
17 |
+
|
18 |
+
// Dropbox api 2
|
19 |
+
$this->setActiveDirectory('');
|
20 |
+
|
21 |
+
@set_exception_handler(array('SGDropboxStorage', 'exceptionHandler'));
|
22 |
+
include_once SG_STORAGE_PATH . 'SGDropbox.php';
|
23 |
+
}
|
24 |
+
|
25 |
+
public static function exceptionHandler($exception)
|
26 |
+
{
|
27 |
+
if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
|
28 |
+
wp_die($exception->getMessage());
|
29 |
+
} elseif (SG_ENV_ADAPTER == SG_ENV_MAGENTO) {
|
30 |
+
die($exception->getMessage());
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
public function connect()
|
35 |
+
{
|
36 |
+
if ($this->isConnected()) {
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
|
40 |
+
// phpcs:disable
|
41 |
+
$authCode = $this->getAuthCodeFromURL($cancel);
|
42 |
+
|
43 |
+
if ($cancel) {
|
44 |
+
throw new SGExceptionMethodNotAllowed('User did not allow access');
|
45 |
+
}
|
46 |
+
// phpcs:enable
|
47 |
+
|
48 |
+
$this->auth($authCode);
|
49 |
+
}
|
50 |
+
|
51 |
+
private function auth($authCode = '')
|
52 |
+
{
|
53 |
+
if ($authCode) {
|
54 |
+
try {
|
55 |
+
//exchange authorization code for access token
|
56 |
+
parse_str($_SERVER['QUERY_STRING'], $arr);
|
57 |
+
list($accessToken, $refreshToken) = $this->getWebAuth()->finish($arr);
|
58 |
+
|
59 |
+
$this->setAccessToken($accessToken);
|
60 |
+
$this->setRefreshToken($refreshToken);
|
61 |
+
$accountInfo = $this->getClient()->getAccountInfo();
|
62 |
+
SGConfig::set('SG_DROPBOX_CONNECTION_STRING', $accountInfo['email']);
|
63 |
+
|
64 |
+
$this->connected = true;
|
65 |
+
return;
|
66 |
+
} catch (Exception $ex) {
|
67 |
+
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
$refUrl = base64_encode($this->getRefURL());
|
72 |
+
$authorizeUrl = $this->getWebAuth()->start($refUrl);
|
73 |
+
header("Location: $authorizeUrl");
|
74 |
+
exit;
|
75 |
+
}
|
76 |
+
|
77 |
+
public function connectOffline()
|
78 |
+
{
|
79 |
+
if ($this->isConnected()) {
|
80 |
+
return;
|
81 |
+
}
|
82 |
+
|
83 |
+
if (!$this->getClient()) {
|
84 |
+
throw new SGExceptionNotFound('Access token not found');
|
85 |
+
}
|
86 |
+
|
87 |
+
$this->connected = true;
|
88 |
+
}
|
89 |
+
|
90 |
+
public function checkConnected()
|
91 |
+
{
|
92 |
+
$accessToken = $this->getAccessToken();
|
93 |
+
$this->connected = $accessToken ? true : false;
|
94 |
+
}
|
95 |
+
|
96 |
+
public function getListOfFiles()
|
97 |
+
{
|
98 |
+
if (!$this->isConnected()) {
|
99 |
+
throw new SGExceptionForbidden('Permission denied. Authentication required.');
|
100 |
+
}
|
101 |
+
|
102 |
+
$listOfFiles = array();
|
103 |
+
$activeDirectory = rtrim($this->getActiveDirectory()) . '/';
|
104 |
+
$metaData = $this->getClient()->getMetadataWithChildren($activeDirectory . SGConfig::get('SG_STORAGE_BACKUPS_FOLDER_NAME'));
|
105 |
+
|
106 |
+
foreach ($metaData['entries'] as $file) {
|
107 |
+
$size = $file['size'];
|
108 |
+
$date = $this->standardizeFileCreationDate($file['client_modified']);
|
109 |
+
$name = basename($file['path_display']);
|
110 |
+
|
111 |
+
$listOfFiles[$name] = array(
|
112 |
+
'name' => $name,
|
113 |
+
'size' => $size,
|
114 |
+
'date' => $date,
|
115 |
+
'path' => $file['path_display'],
|
116 |
+
);
|
117 |
+
}
|
118 |
+
|
119 |
+
krsort($listOfFiles);
|
120 |
+
return $listOfFiles;
|
121 |
+
}
|
122 |
+
|
123 |
+
public function createFolder($folderName)
|
124 |
+
{
|
125 |
+
if (!$this->isConnected()) {
|
126 |
+
throw new SGExceptionForbidden('Permission denied. Authentication required.');
|
127 |
+
}
|
128 |
+
|
129 |
+
$path = rtrim($this->getActiveDirectory(), '/') . '/' . $folderName;
|
130 |
+
$this->getClient()->createFolder($path);
|
131 |
+
|
132 |
+
return $path;
|
133 |
+
}
|
134 |
+
|
135 |
+
public function downloadFile($file, $size, $backupId = null)
|
136 |
+
{
|
137 |
+
if (!$file) {
|
138 |
+
return false;
|
139 |
+
}
|
140 |
+
|
141 |
+
$this->_filePath = SG_BACKUP_DIRECTORY . basename($file);
|
142 |
+
$this->_fd = fopen(SG_BACKUP_DIRECTORY . basename($file), "w");
|
143 |
+
|
144 |
+
$client = $this->getClient();
|
145 |
+
|
146 |
+
$url = "https://content.dropboxapi.com/2/files/download";
|
147 |
+
$params = array(
|
148 |
+
"path" => $file
|
149 |
+
);
|
150 |
+
|
151 |
+
$chunk = 1.0 * 1024 * 1024;
|
152 |
+
$start = 0;
|
153 |
+
$end = $chunk;
|
154 |
+
$result = true;
|
155 |
+
|
156 |
+
while (true) {
|
157 |
+
if ($end > $size) {
|
158 |
+
$end = $size;
|
159 |
+
}
|
160 |
+
|
161 |
+
if ($start >= $size) {
|
162 |
+
$result = true;
|
163 |
+
break;
|
164 |
+
}
|
165 |
+
|
166 |
+
$curl = $client->mkCurl($url);
|
167 |
+
$curl->set(CURLOPT_CUSTOMREQUEST, "POST");
|
168 |
+
$curl->set(CURLOPT_WRITEFUNCTION, array($this, 'writer'));
|
169 |
+
$curl->addHeader("Dropbox-API-Arg: " . json_encode($params));
|
170 |
+
$curl->addHeader("Range: bytes=$start-$end");
|
171 |
+
|
172 |
+
$response = $curl->exec();
|
173 |
+
|
174 |
+
if ($response->statusCode !== 206) {
|
175 |
+
$result = false;
|
176 |
+
break;
|
177 |
+
}
|
178 |
+
|
179 |
+
$start = $end + 1;
|
180 |
+
$end += $chunk;
|
181 |
+
}
|
182 |
+
|
183 |
+
fclose($this->_fd);
|
184 |
+
|
185 |
+
if (!$result) {
|
186 |
+
@unlink(SG_BACKUP_DIRECTORY . basename($file));
|
187 |
+
}
|
188 |
+
|
189 |
+
return $result;
|
190 |
+
}
|
191 |
+
|
192 |
+
public function writer($ch, $data)
|
193 |
+
{
|
194 |
+
if (!file_exists($this->_filePath)) {
|
195 |
+
return -1;
|
196 |
+
}
|
197 |
+
|
198 |
+
fwrite($this->_fd, $data);
|
199 |
+
return strlen($data);
|
200 |
+
}
|
201 |
+
|
202 |
+
private function saveStateData($uploadId, $offset)
|
203 |
+
{
|
204 |
+
$token = $this->delegate->getToken();
|
205 |
+
$actionId = $this->delegate->getActionId();
|
206 |
+
$pendingStorageUploads = $this->delegate->getPendingStorageUploads();
|
207 |
+
$currentUploadChunksCount = $this->delegate->getCurrentUploadChunksCount();
|
208 |
+
$progress = $this->delegate->getProgress();
|
209 |
+
|
210 |
+
$this->state->setProgress($progress);
|
211 |
+
$this->state->setCurrentUploadChunksCount($currentUploadChunksCount);
|
212 |
+
$this->state->setStorageType(SG_STORAGE_DROPBOX);
|
213 |
+
$this->state->setPendingStorageUploads($pendingStorageUploads);
|
214 |
+
$this->state->setToken($token);
|
215 |
+
$this->state->setUploadId($uploadId);
|
216 |
+
$this->state->setOffset($offset);
|
217 |
+
$this->state->setAction(SG_STATE_ACTION_UPLOADING_BACKUP);
|
218 |
+
$this->state->setActiveDirectory($this->getActiveDirectory());
|
219 |
+
$this->state->setActionId($actionId);
|
220 |
+
$this->state->save();
|
221 |
+
}
|
222 |
+
|
223 |
+
public function uploadFile($filePath)
|
224 |
+
{
|
225 |
+
if (!$this->isConnected()) {
|
226 |
+
throw new SGExceptionForbidden('Permission denied. Authentication required.');
|
227 |
+
}
|
228 |
+
|
229 |
+
if (!file_exists($filePath) || !is_readable($filePath)) {
|
230 |
+
throw new SGExceptionNotFound('File does not exist or is not readable: ' . $filePath);
|
231 |
+
}
|
232 |
+
|
233 |
+
$client = $this->getClient();
|
234 |
+
//$chunkSizeBytes = 2.0 * 1024 * 1024;
|
235 |
+
$chunkSizeBytes = (int)getCloudUploadChunkSize() * 1024 * 1024;
|
236 |
+
|
237 |
+
//Note: Because PHP's integer type is signed and many platforms use 32bit integers,
|
238 |
+
//some filesystem functions may return unexpected results for files which are larger than 2GB.
|
239 |
+
$fileSize = backupGuardRealFilesize($filePath);
|
240 |
+
|
241 |
+
$this->delegate->willStartUpload((int)ceil($fileSize / $chunkSizeBytes));
|
242 |
+
|
243 |
+
$handle = fopen($filePath, "rb");
|
244 |
+
$byteOffset = $this->state->getOffset();
|
245 |
+
fseek($handle, $byteOffset);
|
246 |
+
|
247 |
+
if ($this->state->getAction() == SG_STATE_ACTION_PREPARING_STATE_FILE) {
|
248 |
+
$data = fread($handle, $chunkSizeBytes);
|
249 |
+
$uploadId = $client->chunkedUploadStart($data);
|
250 |
+
$byteOffset += strlen($data);
|
251 |
+
} else {
|
252 |
+
$uploadId = $this->state->getUploadId();
|
253 |
+
}
|
254 |
+
|
255 |
+
SGPing::update();
|
256 |
+
|
257 |
+
while ($byteOffset < $fileSize) {
|
258 |
+
$data = fread($handle, $chunkSizeBytes);
|
259 |
+
$client->chunkedUploadContinue($uploadId, $byteOffset, $data);
|
260 |
+
$byteOffset += strlen($data);
|
261 |
+
|
262 |
+
if (!$this->delegate->shouldUploadNextChunk()) {
|
263 |
+
fclose($handle);
|
264 |
+
return;
|
265 |
+
}
|
266 |
+
|
267 |
+
SGPing::update();
|
268 |
+
|
269 |
+
$shouldReload = $this->shouldReload();
|
270 |
+
if ($shouldReload && backupGuardIsReloadEnabled()) {
|
271 |
+
$this->saveStateData($uploadId, $byteOffset);
|
272 |
+
@fclose($handle);
|
273 |
+
$this->reload();
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
$activeDirectory = $this->getActiveDirectory();
|
278 |
+
|
279 |
+
$path = rtrim($activeDirectory, '/') . '/' . basename($filePath);
|
280 |
+
|
281 |
+
$result = $client->chunkedUploadFinish($uploadId, $path, $byteOffset);
|
282 |
+
fclose($handle);
|
283 |
+
|
284 |
+
return $result;
|
285 |
+
}
|
286 |
+
|
287 |
+
public function fileExists($path)
|
288 |
+
{
|
289 |
+
$this->connectOffline();
|
290 |
+
if (!$this->isConnected()) {
|
291 |
+
throw new SGExceptionForbidden('Permission denied. Authentication required.');
|
292 |
+
}
|
293 |
+
|
294 |
+
$client = $this->getClient();
|
295 |
+
try {
|
296 |
+
$result = $client->searchFileNames(dirname($path), basename($path));
|
297 |
+
} catch (Exception $e) {
|
298 |
+
return false;
|
299 |
+
}
|
300 |
+
|
301 |
+
return $result;
|
302 |
+
}
|
303 |
+
|
304 |
+
public function deleteFile($path)
|
305 |
+
{
|
306 |
+
$this->connectOffline();
|
307 |
+
if (!$this->isConnected()) {
|
308 |
+
throw new SGExceptionForbidden('Permission denied. Authentication required.');
|
309 |
+
}
|
310 |
+
|
311 |
+
return $this->getClient()->delete($path);
|
312 |
+
}
|
313 |
+
|
314 |
+
public function deleteFolder($folderName)
|
315 |
+
{
|
316 |
+
return $this->deleteFile($folderName);
|
317 |
+
}
|
318 |
+
|
319 |
+
private function getAppInfo()
|
320 |
+
{
|
321 |
+
$key = SG_STORAGE_DROPBOX_KEY;
|
322 |
+
$secret = SG_STORAGE_DROPBOX_SECRET;
|
323 |
+
|
324 |
+
$appInfo = new dbx\AppInfo($key, $secret);
|
325 |
+
|
326 |
+
return $appInfo;
|
327 |
+
}
|
328 |
+
|
329 |
+
private function getAccessToken()
|
330 |
+
{
|
331 |
+
return SGConfig::get('SG_DROPBOX_ACCESS_TOKEN');
|
332 |
+
}
|
333 |
+
|
334 |
+
private function setAccessToken($accessToken)
|
335 |
+
{
|
336 |
+
SGConfig::set('SG_DROPBOX_ACCESS_TOKEN', $accessToken, true);
|
337 |
+
}
|
338 |
+
|
339 |
+
private function getRefreshToken()
|
340 |
+
{
|
341 |
+
return SGConfig::get('SG_DROPBOX_REFRESH_TOKEN');
|
342 |
+
}
|
343 |
+
|
344 |
+
private function setRefreshToken($refreshToken)
|
345 |
+
{
|
346 |
+
SGConfig::set('SG_DROPBOX_REFRESH_TOKEN', $refreshToken, true);
|
347 |
+
}
|
348 |
+
|
349 |
+
// private function getRefreshedAccessToken()
|
350 |
+
// {
|
351 |
+
// $array = array();
|
352 |
+
// $ch = curl_init();
|
353 |
+
// curl_setopt($ch, CURLOPT_URL, 'https://api.dropbox.com/oauth2/token');
|
354 |
+
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
355 |
+
// curl_setopt($ch, CURLOPT_POST, 1);
|
356 |
+
// curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=refresh_token&refresh_token=" . $this->getRefreshToken());
|
357 |
+
// curl_setopt($ch, CURLOPT_USERPWD, SG_STORAGE_DROPBOX_KEY . ':' . SG_STORAGE_DROPBOX_SECRET);
|
358 |
+
// $headers = array();
|
359 |
+
// $headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
360 |
+
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
361 |
+
// $response = json_decode(curl_exec($ch), true);
|
362 |
+
//
|
363 |
+
// if (curl_errno($ch)) {
|
364 |
+
// $array = ['status' => 400, 'access_token' => null];
|
365 |
+
// } elseif (isset($response['access_token'])) {
|
366 |
+
// $array = ['status' => 200, 'access_token' => $response['access_token']];
|
367 |
+
// }
|
368 |
+
// curl_close($ch);
|
369 |
+
//
|
370 |
+
// return $array;
|
371 |
+
// }
|
372 |
+
|
373 |
+
private function getClient()
|
374 |
+
{
|
375 |
+
if (!$this->_client) {
|
376 |
+
$accessToken = $this->getAccessToken();
|
377 |
+
if (!$accessToken) {
|
378 |
+
return false;
|
379 |
+
}
|
380 |
+
|
381 |
+
try {
|
382 |
+
return $this->getNewClient($accessToken);
|
383 |
+
} catch (dbx\Exception_InvalidAccessToken $error) {
|
384 |
+
$response = $this->getWebAuth()->getRefreshedAccessToken(SG_STORAGE_DROPBOX_KEY, SG_STORAGE_DROPBOX_SECRET, $this->getRefreshToken());
|
385 |
+
|
386 |
+
if ($response['status'] === 200) {
|
387 |
+
SGConfig::set('SG_DROPBOX_ACCESS_TOKEN', $response['access_token'], true);
|
388 |
+
return $this->getNewClient($response['access_token']);
|
389 |
+
}
|
390 |
+
|
391 |
+
return false;
|
392 |
+
}
|
393 |
+
}
|
394 |
+
|
395 |
+
return $this->_client;
|
396 |
+
}
|
397 |
+
|
398 |
+
private function getNewClient($accessToken)
|
399 |
+
{
|
400 |
+
$appInfo = $this->getAppInfo();
|
401 |
+
$client = new dbx\Client($accessToken, SG_STORAGE_DROPBOX_CLIENT_ID, null, $appInfo->getHost());
|
402 |
+
|
403 |
+
$client->getAccountInfo();
|
404 |
+
|
405 |
+
return $client;
|
406 |
+
}
|
407 |
+
|
408 |
+
private function getWebAuth()
|
409 |
+
{
|
410 |
+
$appInfo = $this->getAppInfo();
|
411 |
+
$redirectUri = SG_STORAGE_DROPBOX_REDIRECT_URI;
|
412 |
+
$savedCSRFToken = SGConfig::get('SG_DROPBOX_CONNECTION_CSRF_TOKEN');
|
413 |
+
if (!empty($savedCSRFToken)) {
|
414 |
+
$_SESSION['dropbox-auth-csrf-token'] = $savedCSRFToken;
|
415 |
+
SGConfig::set('SG_DROPBOX_CONNECTION_CSRF_TOKEN', false);
|
416 |
+
}
|
417 |
+
|
418 |
+
$csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
|
419 |
+
return new dbx\WebAuth($appInfo, SG_STORAGE_DROPBOX_CLIENT_ID, $redirectUri, $csrfTokenStore, null);
|
420 |
+
}
|
421 |
+
|
422 |
+
private function getCurrentURL()
|
423 |
+
{
|
424 |
+
$http = backupGuardGetCurrentUrlScheme();
|
425 |
+
$url = $http . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
426 |
+
return $url;
|
427 |
+
}
|
428 |
+
|
429 |
+
private function getRefURL()
|
430 |
+
{
|
431 |
+
$refUrl = $this->getCurrentURL();
|
432 |
+
if (!$_SERVER['QUERY_STRING']) {
|
433 |
+
$refUrl .= '?';
|
434 |
+
} else {
|
435 |
+
$refUrl .= '&';
|
436 |
+
}
|
437 |
+
|
438 |
+
return $refUrl;
|
439 |
+
}
|
440 |
+
|
441 |
+
private function getAuthCodeFromURL(&$cancel = false)
|
442 |
+
{
|
443 |
+
$query = $_SERVER['QUERY_STRING'];
|
444 |
+
if (!$query) {
|
445 |
+
return '';
|
446 |
+
}
|
447 |
+
|
448 |
+
$query = explode('&', $query);
|
449 |
+
$code = '';
|
450 |
+
foreach ($query as $q) {
|
451 |
+
$q = explode('=', $q);
|
452 |
+
if ($q[0] == 'code') {
|
453 |
+
$code = $q[1];
|
454 |
+
} else if ($q[0] == 'cancel' && $q[1] == '1') {
|
455 |
+
$cancel = true;
|
456 |
+
break;
|
457 |
+
}
|
458 |
+
}
|
459 |
+
|
460 |
+
return $code;
|
461 |
+
}
|
462 |
+
}
|
com/lib/Dropbox/WebAuth.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<?php
|
|
|
2 |
namespace Dropbox;
|
3 |
|
4 |
/**
|
@@ -74,10 +75,13 @@ class WebAuth extends WebAuthBase
|
|
74 |
*
|
75 |
* @return string
|
76 |
*/
|
77 |
-
function getRedirectUri()
|
|
|
|
|
|
|
78 |
|
79 |
/** @var string */
|
80 |
-
private $
|
81 |
|
82 |
/**
|
83 |
* A object that lets us save CSRF token string to the user's session. If you're using the
|
@@ -90,10 +94,13 @@ class WebAuth extends WebAuthBase
|
|
90 |
*
|
91 |
* @return ValueStore
|
92 |
*/
|
93 |
-
function getCsrfTokenStore()
|
|
|
|
|
|
|
94 |
|
95 |
/** @var object */
|
96 |
-
private $
|
97 |
|
98 |
/**
|
99 |
* Constructor.
|
@@ -109,14 +116,14 @@ class WebAuth extends WebAuthBase
|
|
109 |
* @param null|string $userLocale
|
110 |
* See {@link getUserLocale()}
|
111 |
*/
|
112 |
-
function __construct($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore, $userLocale = null)
|
113 |
{
|
114 |
parent::__construct($appInfo, $clientIdentifier, $userLocale);
|
115 |
|
116 |
Checker::argStringNonEmpty("redirectUri", $redirectUri);
|
117 |
|
118 |
-
$this->
|
119 |
-
$this->
|
120 |
}
|
121 |
|
122 |
/**
|
@@ -141,20 +148,20 @@ class WebAuth extends WebAuthBase
|
|
141 |
*
|
142 |
* @throws Exception
|
143 |
*/
|
144 |
-
function start($urlState = null)
|
145 |
{
|
146 |
Checker::argStringOrNull("urlState", $urlState);
|
147 |
|
148 |
$csrfToken = self::encodeCsrfToken(Security::getRandomBytes(16));
|
149 |
-
|
150 |
$state = $csrfToken;
|
151 |
if ($urlState !== null) {
|
152 |
$state .= "|";
|
153 |
$state .= $urlState;
|
154 |
}
|
155 |
-
$this->
|
156 |
|
157 |
-
return $this->_getAuthorizeUrl($this->
|
158 |
}
|
159 |
|
160 |
private static function encodeCsrfToken($string)
|
@@ -185,12 +192,12 @@ class WebAuth extends WebAuthBase
|
|
185 |
* @throws WebAuthException_NotApproved
|
186 |
* @throws WebAuthException_Provider
|
187 |
*/
|
188 |
-
function finish($queryParams)
|
189 |
{
|
190 |
Checker::argArray("queryParams", $queryParams);
|
191 |
|
192 |
-
$csrfTokenFromSession = $this->
|
193 |
-
Checker::argStringOrNull("this->
|
194 |
|
195 |
// Check well-formedness of request.
|
196 |
|
@@ -218,8 +225,8 @@ class WebAuth extends WebAuthBase
|
|
218 |
}
|
219 |
|
220 |
if ($code !== null && $error !== null) {
|
221 |
-
throw new WebAuthException_BadRequest("Query parameters 'code' and 'error' are both set;".
|
222 |
-
|
223 |
}
|
224 |
if ($code === null && $error === null) {
|
225 |
throw new WebAuthException_BadRequest("Neither query parameter 'code' or 'error' is set.");
|
@@ -240,10 +247,10 @@ class WebAuth extends WebAuthBase
|
|
240 |
$urlState = substr($state, $splitPos + 1);
|
241 |
}
|
242 |
if (!Security::stringEquals($csrfTokenFromSession, $givenCsrfToken)) {
|
243 |
-
throw new WebAuthException_Csrf("Expected ".Util::q($csrfTokenFromSession) .
|
244 |
-
|
245 |
}
|
246 |
-
$this->
|
247 |
|
248 |
// Check for error identifier
|
249 |
|
@@ -268,7 +275,12 @@ class WebAuth extends WebAuthBase
|
|
268 |
|
269 |
// If everything went ok, make the network call to get an access token.
|
270 |
|
271 |
-
list($accessToken, $userId) = $this->_finish($code, $this->
|
272 |
return array($accessToken, $userId, $urlState);
|
273 |
}
|
|
|
|
|
|
|
|
|
|
|
274 |
}
|
1 |
<?php
|
2 |
+
|
3 |
namespace Dropbox;
|
4 |
|
5 |
/**
|
75 |
*
|
76 |
* @return string
|
77 |
*/
|
78 |
+
public function getRedirectUri()
|
79 |
+
{
|
80 |
+
return $this->_redirectUri;
|
81 |
+
}
|
82 |
|
83 |
/** @var string */
|
84 |
+
private $_redirectUri;
|
85 |
|
86 |
/**
|
87 |
* A object that lets us save CSRF token string to the user's session. If you're using the
|
94 |
*
|
95 |
* @return ValueStore
|
96 |
*/
|
97 |
+
public function getCsrfTokenStore()
|
98 |
+
{
|
99 |
+
return $this->_csrfTokenStore;
|
100 |
+
}
|
101 |
|
102 |
/** @var object */
|
103 |
+
private $_csrfTokenStore;
|
104 |
|
105 |
/**
|
106 |
* Constructor.
|
116 |
* @param null|string $userLocale
|
117 |
* See {@link getUserLocale()}
|
118 |
*/
|
119 |
+
public function __construct($appInfo, $clientIdentifier, $redirectUri, $csrfTokenStore, $userLocale = null)
|
120 |
{
|
121 |
parent::__construct($appInfo, $clientIdentifier, $userLocale);
|
122 |
|
123 |
Checker::argStringNonEmpty("redirectUri", $redirectUri);
|
124 |
|
125 |
+
$this->_csrfTokenStore = $csrfTokenStore;
|
126 |
+
$this->_redirectUri = $redirectUri;
|
127 |
}
|
128 |
|
129 |
/**
|
148 |
*
|
149 |
* @throws Exception
|
150 |
*/
|
151 |
+
public function start($urlState = null)
|
152 |
{
|
153 |
Checker::argStringOrNull("urlState", $urlState);
|
154 |
|
155 |
$csrfToken = self::encodeCsrfToken(Security::getRandomBytes(16));
|
156 |
+
\SGConfig::set('SG_DROPBOX_CONNECTION_CSRF_TOKEN', $csrfToken);
|
157 |
$state = $csrfToken;
|
158 |
if ($urlState !== null) {
|
159 |
$state .= "|";
|
160 |
$state .= $urlState;
|
161 |
}
|
162 |
+
$this->_csrfTokenStore->set($csrfToken);
|
163 |
|
164 |
+
return $this->_getAuthorizeUrl($this->_redirectUri, $state);
|
165 |
}
|
166 |
|
167 |
private static function encodeCsrfToken($string)
|
192 |
* @throws WebAuthException_NotApproved
|
193 |
* @throws WebAuthException_Provider
|
194 |
*/
|
195 |
+
public function finish($queryParams)
|
196 |
{
|
197 |
Checker::argArray("queryParams", $queryParams);
|
198 |
|
199 |
+
$csrfTokenFromSession = $this->_csrfTokenStore->get();
|
200 |
+
Checker::argStringOrNull("this->_csrfTokenStore->get()", $csrfTokenFromSession);
|
201 |
|
202 |
// Check well-formedness of request.
|
203 |
|
225 |
}
|
226 |
|
227 |
if ($code !== null && $error !== null) {
|
228 |
+
throw new WebAuthException_BadRequest("Query parameters 'code' and 'error' are both set;" .
|
229 |
+
" only one must be set.");
|
230 |
}
|
231 |
if ($code === null && $error === null) {
|
232 |
throw new WebAuthException_BadRequest("Neither query parameter 'code' or 'error' is set.");
|
247 |
$urlState = substr($state, $splitPos + 1);
|
248 |
}
|
249 |
if (!Security::stringEquals($csrfTokenFromSession, $givenCsrfToken)) {
|
250 |
+
throw new WebAuthException_Csrf("Expected " . Util::q($csrfTokenFromSession) .
|
251 |
+
", got " . Util::q($givenCsrfToken) . ".");
|
252 |
}
|
253 |
+
$this->_csrfTokenStore->clear();
|
254 |
|
255 |
// Check for error identifier
|
256 |
|
275 |
|
276 |
// If everything went ok, make the network call to get an access token.
|
277 |
|
278 |
+
list($accessToken, $userId) = $this->_finish($code, $this->_redirectUri);
|
279 |
return array($accessToken, $userId, $urlState);
|
280 |
}
|
281 |
+
|
282 |
+
public function getRefreshedAccessToken($key, $secrect, $refreshToken)
|
283 |
+
{
|
284 |
+
return $this->_getRefreshedAccessToken($key, $secrect, $refreshToken);
|
285 |
+
}
|
286 |
}
|
com/lib/Dropbox/WebAuthBase.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<?php
|
|
|
2 |
namespace Dropbox;
|
3 |
|
4 |
/**
|
@@ -6,52 +7,69 @@ namespace Dropbox;
|
|
6 |
*/
|
7 |
class WebAuthBase extends AuthBase
|
8 |
{
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
/* Dropbox api 2*/
|
24 |
-
protected function _getAuthorizeUrl($redirectUri, $state)
|
25 |
{
|
26 |
return RequestUtil::buildUrlForGetOrPut(
|
27 |
$this->userLocale,
|
28 |
$this->appInfo->getHost()->getWeb(),
|
29 |
"oauth2/authorize",
|
30 |
array(
|
|
|
31 |
"client_id" => $this->appInfo->getKey(),
|
32 |
"response_type" => "code",
|
33 |
"redirect_uri" => $redirectUri,
|
34 |
"state" => $state,
|
35 |
-
)
|
|
|
36 |
}
|
37 |
|
38 |
-
protected function _finish($code, $originalRedirectUri)
|
39 |
{
|
40 |
// This endpoint requires "Basic" auth.
|
41 |
-
$clientCredentials = $this->appInfo->getKey().":"
|
42 |
-
$authHeaderValue = "Basic ".base64_encode($clientCredentials);
|
43 |
|
44 |
$response = RequestUtil::doPostWithSpecificAuth(
|
45 |
-
$this->clientIdentifier,
|
|
|
|
|
46 |
$this->appInfo->getHost()->getApi(),
|
47 |
"oauth2/token",
|
48 |
array(
|
49 |
"grant_type" => "authorization_code",
|
50 |
"code" => $code,
|
51 |
"redirect_uri" => $originalRedirectUri,
|
52 |
-
)
|
|
|
53 |
|
54 |
-
if ($response->statusCode !== 200)
|
|
|
|
|
55 |
|
56 |
$parts = RequestUtil::parseResponseJson($response->body);
|
57 |
|
@@ -66,54 +84,17 @@ class WebAuthBase extends AuthBase
|
|
66 |
if (!array_key_exists('uid', $parts) || !is_string($parts['uid'])) {
|
67 |
throw new Exception_BadResponse("Missing \"uid\" string field.");
|
68 |
}
|
|
|
|
|
|
|
|
|
69 |
$userId = $parts['uid'];
|
70 |
|
71 |
if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
|
72 |
throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got "
|
73 |
-
.Util::q($tokenType));
|
74 |
}
|
75 |
|
76 |
-
return array($accessToken, $userId);
|
77 |
}
|
78 |
-
|
79 |
-
// protected function _finish($code, $originalRedirectUri)
|
80 |
-
// {
|
81 |
-
// // This endpoint requires "Basic" auth.
|
82 |
-
// $clientCredentials = $this->appInfo->getKey().":".$this->appInfo->getSecret();
|
83 |
-
// $authHeaderValue = "Basic ".base64_encode($clientCredentials);
|
84 |
-
|
85 |
-
// $response = RequestUtil::doPostWithSpecificAuth(
|
86 |
-
// $this->clientIdentifier, $authHeaderValue, $this->userLocale,
|
87 |
-
// $this->appInfo->getHost()->getApi(),
|
88 |
-
// "1/oauth2/token",
|
89 |
-
// array(
|
90 |
-
// "grant_type" => "authorization_code",
|
91 |
-
// "code" => $code,
|
92 |
-
// "redirect_uri" => $originalRedirectUri,
|
93 |
-
// ));
|
94 |
-
|
95 |
-
// if ($response->statusCode !== 200) throw RequestUtil::unexpectedStatus($response);
|
96 |
-
|
97 |
-
// $parts = RequestUtil::parseResponseJson($response->body);
|
98 |
-
|
99 |
-
// if (!array_key_exists('token_type', $parts) || !is_string($parts['token_type'])) {
|
100 |
-
// throw new Exception_BadResponse("Missing \"token_type\" field.");
|
101 |
-
// }
|
102 |
-
// $tokenType = $parts['token_type'];
|
103 |
-
// if (!array_key_exists('access_token', $parts) || !is_string($parts['access_token'])) {
|
104 |
-
// throw new Exception_BadResponse("Missing \"access_token\" field.");
|
105 |
-
// }
|
106 |
-
// $accessToken = $parts['access_token'];
|
107 |
-
// if (!array_key_exists('uid', $parts) || !is_string($parts['uid'])) {
|
108 |
-
// throw new Exception_BadResponse("Missing \"uid\" string field.");
|
109 |
-
// }
|
110 |
-
// $userId = $parts['uid'];
|
111 |
-
|
112 |
-
// if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
|
113 |
-
// throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got "
|
114 |
-
// .Util::q($tokenType));
|
115 |
-
// }
|
116 |
-
|
117 |
-
// return array($accessToken, $userId);
|
118 |
-
// }
|
119 |
}
|
1 |
<?php
|
2 |
+
|
3 |
namespace Dropbox;
|
4 |
|
5 |
/**
|
7 |
*/
|
8 |
class WebAuthBase extends AuthBase
|
9 |
{
|
10 |
+
protected function _getRefreshedAccessToken($key, $secrect, $refreshToken) // phpcs:ignore
|
11 |
+
{
|
12 |
+
$array = array();
|
13 |
+
$ch = curl_init();
|
14 |
+
curl_setopt($ch, CURLOPT_URL, 'https://api.dropbox.com/oauth2/token');
|
15 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
16 |
+
curl_setopt($ch, CURLOPT_POST, 1);
|
17 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=refresh_token&refresh_token=" . $refreshToken);
|
18 |
+
curl_setopt($ch, CURLOPT_USERPWD, $key . ':' . $secrect);
|
19 |
+
$headers = array();
|
20 |
+
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
21 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
22 |
+
$response = json_decode(curl_exec($ch), true);
|
23 |
+
|
24 |
+
if (curl_errno($ch)) {
|
25 |
+
$array = ['status' => 400, 'access_token' => null];
|
26 |
+
} elseif (isset($response['access_token'])) {
|
27 |
+
$array = ['status' => 200, 'access_token' => $response['access_token']];
|
28 |
+
}
|
29 |
+
curl_close($ch);
|
30 |
+
|
31 |
+
return $array;
|
32 |
+
}
|
33 |
|
34 |
/* Dropbox api 2*/
|
35 |
+
protected function _getAuthorizeUrl($redirectUri, $state) // phpcs:ignore
|
36 |
{
|
37 |
return RequestUtil::buildUrlForGetOrPut(
|
38 |
$this->userLocale,
|
39 |
$this->appInfo->getHost()->getWeb(),
|
40 |
"oauth2/authorize",
|
41 |
array(
|
42 |
+
"token_access_type" => "offline",
|
43 |
"client_id" => $this->appInfo->getKey(),
|
44 |
"response_type" => "code",
|
45 |
"redirect_uri" => $redirectUri,
|
46 |
"state" => $state,
|
47 |
+
)
|
48 |
+
);
|
49 |
}
|
50 |
|
51 |
+
protected function _finish($code, $originalRedirectUri) // phpcs:ignore
|
52 |
{
|
53 |
// This endpoint requires "Basic" auth.
|
54 |
+
$clientCredentials = $this->appInfo->getKey() . ":" . $this->appInfo->getSecret();
|
55 |
+
$authHeaderValue = "Basic " . base64_encode($clientCredentials);
|
56 |
|
57 |
$response = RequestUtil::doPostWithSpecificAuth(
|
58 |
+
$this->clientIdentifier,
|
59 |
+
$authHeaderValue,
|
60 |
+
$this->userLocale,
|
61 |
$this->appInfo->getHost()->getApi(),
|
62 |
"oauth2/token",
|
63 |
array(
|
64 |
"grant_type" => "authorization_code",
|
65 |
"code" => $code,
|
66 |
"redirect_uri" => $originalRedirectUri,
|
67 |
+
)
|
68 |
+
);
|
69 |
|
70 |
+
if ($response->statusCode !== 200) {
|
71 |
+
throw RequestUtil::unexpectedStatus($response);
|
72 |
+
}
|
73 |
|
74 |
$parts = RequestUtil::parseResponseJson($response->body);
|
75 |
|
84 |
if (!array_key_exists('uid', $parts) || !is_string($parts['uid'])) {
|
85 |
throw new Exception_BadResponse("Missing \"uid\" string field.");
|
86 |
}
|
87 |
+
$refreshToken = $parts['refresh_token'];
|
88 |
+
if (!array_key_exists('refresh_token', $parts) || !is_string($parts['refresh_token'])) {
|
89 |
+
throw new Exception_BadResponse("Missing \"refresh_token\" string field.");
|
90 |
+
}
|
91 |
$userId = $parts['uid'];
|
92 |
|
93 |
if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
|
94 |
throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got "
|
95 |
+
. Util::q($tokenType));
|
96 |
}
|
97 |
|
98 |
+
return array($accessToken, $refreshToken, $userId);
|
99 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
}
|
public/ajax/cloudDropbox.php
CHANGED
@@ -1,25 +1,26 @@
|
|
1 |
<?php
|
2 |
-
require_once(dirname(__FILE__).'/../boot.php');
|
3 |
-
require_once(SG_STORAGE_PATH.'SGDropboxStorage.php');
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
SGConfig::set('SG_DROPBOX_CONNECTION_STRING','');
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
13 |
|
14 |
$dp = new SGDropboxStorage();
|
15 |
try {
|
16 |
-
|
17 |
-
}
|
18 |
-
|
19 |
-
header("Location: ".SG_PUBLIC_CLOUD_URL);
|
20 |
}
|
21 |
|
22 |
-
if($dp->isConnected()) {
|
23 |
-
|
24 |
-
|
25 |
}
|
1 |
<?php
|
|
|
|
|
2 |
|
3 |
+
require_once(dirname(__FILE__) . '/../boot.php');
|
4 |
+
require_once(SG_STORAGE_PATH . 'SGDropboxStorage.php');
|
|
|
5 |
|
6 |
+
if (backupGuardIsAjax()) {
|
7 |
+
SGConfig::set('SG_DROPBOX_ACCESS_TOKEN', '');
|
8 |
+
SGConfig::set('SG_DROPBOX_CONNECTION_STRING', '');
|
9 |
+
SGConfig::set('SG_DROPBOX_REFRESH_TOKEN', '');
|
10 |
+
|
11 |
+
if (isset($_POST['cancel'])) {
|
12 |
+
die('{"success":1}');
|
13 |
+
}
|
14 |
}
|
15 |
|
16 |
$dp = new SGDropboxStorage();
|
17 |
try {
|
18 |
+
$dp->connect();
|
19 |
+
} catch (Exception $e) {
|
20 |
+
header("Location: " . SG_PUBLIC_CLOUD_URL);
|
|
|
21 |
}
|
22 |
|
23 |
+
if ($dp->isConnected()) {
|
24 |
+
header("Location: " . SG_PUBLIC_CLOUD_URL);
|
25 |
+
exit();
|
26 |
}
|
public/backups.php
CHANGED
@@ -1,292 +1,292 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
$backups
|
4 |
-
$downloadUrl
|
5 |
-
$contentClassName
|
6 |
-
$allowDataCollection = SGConfig::get('SG_BACKUP_SEND_USAGE_STATUS');
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
<?php
|
14 |
-
|
15 |
-
|
16 |
-
<div class="bg-verify-user-info-
|
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 |
-
|
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 |
-
<option value="
|
74 |
-
<option value="
|
75 |
-
<option value="
|
76 |
-
<option value="
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
<span class="sg-backup-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
<span class="sg-backup-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
<span class="sg-backup-
|
142 |
-
|
143 |
-
|
144 |
-
<?php
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
<span class="sg-backup-
|
157 |
-
|
158 |
-
|
159 |
-
<
|
160 |
-
<
|
161 |
-
|
162 |
-
<
|
163 |
-
|
164 |
-
<th
|
165 |
-
<th><?php _backupGuardT('
|
166 |
-
<th><?php _backupGuardT('
|
167 |
-
<th><?php _backupGuardT('
|
168 |
-
<th><?php _backupGuardT('
|
169 |
-
|
170 |
-
</
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
<?php
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
<td><?php echo
|
184 |
-
<td><?php echo
|
185 |
-
<td
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
<?php
|
200 |
-
if ($backup['status'] == SG_ACTION_STATUS_FINISHED_WARNINGS) : ?>
|
201 |
-
<span class="btn-xs text-warning" data-toggle="tooltip" data-placement="top"
|
202 |
-
data-original-title="
|
203 |
-
<?php if ($backup['type'] == SG_ACTION_TYPE_BACKUP) :
|
204 |
-
|
205 |
-
elseif ($backup['type'] == SG_ACTION_TYPE_RESTORE) :
|
206 |
-
|
207 |
-
else :
|
208 |
-
|
209 |
-
endif; ?>
|
210 |
-
" data-container="#sg-wrapper"><?php _backupGuardT('Warning') ?></span>
|
211 |
-
<?php elseif ($backup['status'] == SG_ACTION_STATUS_ERROR) : ?>
|
212 |
-
<span class="btn-xs text-danger" data-toggle="tooltip" data-placement="top"
|
213 |
-
data-original-title="
|
214 |
-
<?php if ($backup['type'] == SG_ACTION_TYPE_BACKUP) :
|
215 |
-
|
216 |
-
elseif ($backup['type'] == SG_ACTION_TYPE_RESTORE) :
|
217 |
-
echo _backupGuardT('Errors found during restore', true);
|
218 |
-
else :
|
219 |
-
echo _backupGuardT('Errors found during upload', true);
|
220 |
-
endif; ?>
|
221 |
-
" data-container="#sg-wrapper"><?php _backupGuardT('Failed') ?></span>
|
222 |
-
<?php else : ?>
|
223 |
-
<span class="btn-xs sg-text-success"><?php _backupGuardT('Success') ?></span>
|
224 |
-
<?php endif; ?>
|
225 |
-
|
226 |
-
</td>
|
227 |
-
<td class="sg-backup-actions-td">
|
228 |
-
<?php if ($backup['active']) : ?>
|
229 |
-
<?php if ($backup['type'] != SG_ACTION_TYPE_RESTORE) : ?>
|
230 |
-
<a class="btn-xs sg-cancel-backup" sg-data-backup-id="<?php echo $backup['id'] ?>"
|
231 |
-
href="javascript:void(0)" title="<?php _backupGuardT('Stop') ?>"> </a>
|
232 |
-
<?php endif; ?>
|
233 |
-
<?php else : ?>
|
234 |
-
<a href="javascript:void(0)"
|
235 |
-
data-sgbackup-name="<?php echo htmlspecialchars($backup['name']); ?>"
|
236 |
-
data-remote="deleteBackup" class="sg-remove-backup btn-xs"
|
237 |
-
title="<?php _backupGuardT('Delete') ?>"> </a>
|
238 |
-
<div class="btn-group">
|
239 |
-
<a href="javascript:void(0)" class="sg-bg-download-button btn-xs"
|
240 |
-
data-toggle="dropdown1" aria-expanded="false"
|
241 |
-
title="<?php _backupGuardT('Download') ?>">
|
242 |
-
|
243 |
-
</a>
|
244 |
-
<ul class="dropdown-menu">
|
245 |
-
<?php if ($backup['files']) : ?>
|
246 |
-
<li>
|
247 |
-
<a href="<?php echo $downloadUrl . 'backupName=' . htmlspecialchars(@$backup['name']) . '&downloadType=' . SG_BACKUP_DOWNLOAD_TYPE_SGBP ?>">
|
248 |
-
<i class="glyphicon glyphicon-hdd"
|
249 |
-
aria-hidden="true"></i> <?php _backupGuardT('Backup') ?>
|
250 |
-
</a>
|
251 |
-
</li>
|
252 |
-
<?php endif; ?>
|
253 |
-
<?php if ($backup['backup_log']) : ?>
|
254 |
-
<li>
|
255 |
-
<a href="<?php echo $downloadUrl . 'backupName=' . htmlspecialchars(@$backup['name']) . '&downloadType=' . SG_BACKUP_DOWNLOAD_TYPE_BACKUP_LOG ?>">
|
256 |
-
<i class="glyphicon glyphicon-list-alt"
|
257 |
-
aria-hidden="true"></i> <?php _backupGuardT('Backup log') ?>
|
258 |
-
</a>
|
259 |
-
</li>
|
260 |
-
<?php endif; ?>
|
261 |
-
<?php if ($backup['restore_log']) : ?>
|
262 |
-
<li>
|
263 |
-
<a href="<?php echo $downloadUrl . 'backupName=' . @$backup['name'] . '&downloadType=' . SG_BACKUP_DOWNLOAD_TYPE_RESTORE_LOG ?>">
|
264 |
-
<i class="glyphicon glyphicon-th-list"
|
265 |
-
aria-hidden="true"></i> <?php _backupGuardT('Restore log') ?>
|
266 |
-
</a>
|
267 |
-
</li>
|
268 |
-
<?php endif; ?>
|
269 |
-
</ul>
|
270 |
-
</div>
|
271 |
-
<?php
|
272 |
-
$path = SG_BACKUP_DIRECTORY . $backup['name'] . '/' . $backup['name'] . '.sgbp';
|
273 |
-
?>
|
274 |
-
<?php if (file_exists($path) && ($backup['status'] != SG_ACTION_STATUS_ERROR) && (filesize($path) > SG_BACKUP_VALID_ARCHIVE_SIZE)) : ?>
|
275 |
-
<a href="javascript:void(0)" title="<?php _backupGuardT('Restore') ?>"
|
276 |
-
class="sg-restore-button btn-xs" data-toggle="modal" data-modal-name="manual-restore"
|
277 |
-
data-remote="modalManualRestore"
|
278 |
-
data-sgbp-params="<?php echo htmlspecialchars($backup['name']) ?>">
|
279 |
-
</a>
|
280 |
-
<?php endif; ?>
|
281 |
-
<?php endif; ?>
|
282 |
-
</td>
|
283 |
-
</tr>
|
284 |
-
<?php endforeach; ?>
|
285 |
-
</tbody>
|
286 |
-
</table>
|
287 |
-
<div class="text-right sg-backups">
|
288 |
-
<ul class="pagination"></ul>
|
289 |
-
</div>
|
290 |
-
</fieldset>
|
291 |
-
<div class="clearfix"></div>
|
292 |
-
</div>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$backups = SGBackup::getAllBackups();
|
4 |
+
$downloadUrl = admin_url('admin-post.php?action=backup_guard_downloadBackup&');
|
5 |
+
$contentClassName = getBackupPageContentClassName('backups');
|
6 |
+
$allowDataCollection = SGConfig::get('SG_BACKUP_SEND_USAGE_STATUS');
|
7 |
+
|
8 |
+
?>
|
9 |
+
<div id="sg-backup-page-content-backups" class="sg-backup-page-content <?php echo $contentClassName; ?>">
|
10 |
+
<?php if (SGConfig::get('SG_REVIEW_POPUP_STATE') == SG_SHOW_REVIEW_POPUP) : ?>
|
11 |
+
<!-- Review Box -->
|
12 |
+
<script type="text/javascript">sgShowReview = 1;</script>
|
13 |
+
<?php endif; ?>
|
14 |
+
<?php if (!SGConfig::get('SG_HIDE_VERIFICATION_POPUP_STATE') && ($pluginCapabilities == BACKUP_GUARD_CAPABILITIES_FREE)) : ?>
|
15 |
+
<div id="bg-verify-user-info-container" class="bg-verify-user-info-container">
|
16 |
+
<div class="bg-verify-user-info-overlay"></div>
|
17 |
+
<div class="bg-verify-user-info-popup-tbl">
|
18 |
+
<div class="bg-verify-user-info-popup-cel">
|
19 |
+
<div class="bg-verify-user-info-popup-content">
|
20 |
+
<a href="javascript:void(0)" class="bg-verify-user-info-cancel"><img
|
21 |
+
src="<?php echo SG_IMAGE_URL . 'popupClose.png' ?>" class="wp_fm_loader"/></a>
|
22 |
+
<div class="bg-verify-user-info-popup-inner-content">
|
23 |
+
<?php
|
24 |
+
$displayName = 'Admin';
|
25 |
+
if (function_exists('wp_get_current_user')) {
|
26 |
+
$currentUser = wp_get_current_user();
|
27 |
+
}
|
28 |
+
if (!empty($currentUser)) {
|
29 |
+
// phpcs:disable
|
30 |
+
$displayName = $currentUser->display_name;
|
31 |
+
// phpcs:enable
|
32 |
+
$displayName = ucfirst($displayName);
|
33 |
+
}
|
34 |
+
?>
|
35 |
+
<h3 class="sgbg-welcome-title"><?php _backupGuardT('Hey');
|
36 |
+
echo " " . $displayName; ?>!</h3>
|
37 |
+
<p class="bg-verify-user-info-desc">
|
38 |
+
<?php _backupGuardT(
|
39 |
+
'Thank you for choosing BackupGuard - the greatest WordPress backup plugin.
|
40 |
+
We recommend filling in the form below before starting to use the plugin.
|
41 |
+
This will provide us with an opportunity to make the experience so much better for you!'
|
42 |
+
); ?>
|
43 |
+
</p>
|
44 |
+
<form>
|
45 |
+
<div class="bg-verify-user-info-form-group">
|
46 |
+
<div class="bg-verify-user-info-form-twocol">
|
47 |
+
<input name="bg-verify-user-info-name" id="bg-verify-user-info-name"
|
48 |
+
class="regular-text sg-backup-input" type="text" value=""
|
49 |
+
placeholder="First Name"/>
|
50 |
+
<span id="bg-verify-user-info-name-error"
|
51 |
+
class="bg-verify-user-info-error-message"><?php _backupGuardT('Please Enter First Name.'); ?></span>
|
52 |
+
</div>
|
53 |
+
<div class="bg-verify-user-info-form-twocol">
|
54 |
+
<input name="bg-verify-user-info-last-name" id="bg-verify-user-info-last-name"
|
55 |
+
class="regular-text sg-backup-input" type="text" value=""
|
56 |
+
placeholder="Last Name"/>
|
57 |
+
<span id="bg-verify-user-info-last-name-error"
|
58 |
+
class="bg-verify-user-info-error-message"><?php _backupGuardT('Please Enter Last Name.'); ?></span>
|
59 |
+
</div>
|
60 |
+
</div>
|
61 |
+
<div class="bg-verify-user-info-form-group">
|
62 |
+
<div class="bg-verify-user-info-form-onecol">
|
63 |
+
<input name="bg-verify-user-info-email" id="bg-verify-user-info-email"
|
64 |
+
class="regular-text sg-backup-input" type="text" value=""
|
65 |
+
placeholder="Email Address"/>
|
66 |
+
<span id="bg-verify-user-info-email-error"
|
67 |
+
class="bg-verify-user-info-error-message"><?php _backupGuardT('Please Enter Valid Email Address.'); ?></span>
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
<div class="bg-verify-user-info-form-group">
|
71 |
+
<div class="bg-verify-user-info-form-onecol">
|
72 |
+
<select name="bg-verify-user-prioraty" id="bg-verify-user-prioraty">
|
73 |
+
<option value=""><?php _backupGuardT('What will you use the plugin for?') ?></option>
|
74 |
+
<option value="local backup"><?php _backupGuardT('Local Backup') ?></option>
|
75 |
+
<option value="cloud backup"><?php _backupGuardT('Cloud Backup') ?></option>
|
76 |
+
<option value="migration"><?php _backupGuardT('Migration') ?></option>
|
77 |
+
<option value="other"><?php _backupGuardT('Other Feature(s)') ?></option>
|
78 |
+
</select>
|
79 |
+
<span id="bg-verify-user-info-priority-error"
|
80 |
+
class="bg-verify-user-info-error-message"><?php _backupGuardT('Please Select Your Priority.'); ?></span>
|
81 |
+
</div>
|
82 |
+
</div>
|
83 |
+
<div class="bg-verify-user-info-form-group">
|
84 |
+
<div class="bg-verify-user-info-form-onecol">
|
85 |
+
<input name="bg-verify-user-priorati-custom" id="bg-verify-user-priorati-custom"
|
86 |
+
class="regular-text sg-backup-input" type="text"
|
87 |
+
placeholder="<?php _backupGuardT('Feature(s)') ?>" hidden>
|
88 |
+
<span id="bg-verify-user-info-priority-custom-error"
|
89 |
+
class="bg-verify-user-info-error-message"><?php _backupGuardT('Please Enter Your Priority.'); ?></span>
|
90 |
+
</div>
|
91 |
+
</div>
|
92 |
+
<div class="bg-verify-user-info-control-buttons-container">
|
93 |
+
<button class="bg-verify-user-info-verify-email button button-primary"><?php _backupGuardT("Subscribe") ?></button>
|
94 |
+
</div>
|
95 |
+
</form>
|
96 |
+
<div class="row sgbg-send-usage-data-wrapper">
|
97 |
+
<div class="sg-data-collection-label">
|
98 |
+
<label class="sg-control-label"><?php _backupGuardT('Automatically send anonymous diagnostic and usage data') ?></label>
|
99 |
+
</div>
|
100 |
+
<div class="backup-send-usage-data-status-wrapper">
|
101 |
+
<label class="sg-switch-container">
|
102 |
+
<input type="checkbox" name="backup-send-usage-data-status"
|
103 |
+
class="sg-switch backup-send-usage-data-status" checked="checked">
|
104 |
+
</label>
|
105 |
+
</div>
|
106 |
+
</div>
|
107 |
+
</div>
|
108 |
+
<div class="bg-initial-privacy-links-container">
|
109 |
+
<a href="<?php echo BACKUP_GUARD_TERMS_OF_SERVICE_URL ?>"
|
110 |
+
target="_blank"><?php _backupGuardT('Terms of Service'); ?></a>
|
111 |
+
<a href="<?php echo BACKUP_GUARD_PRIVACY_POLICY_URL ?>"
|
112 |
+
target="_blank"><?php _backupGuardT('Privacy Policy'); ?></a>
|
113 |
+
</div>
|
114 |
+
</div>
|
115 |
+
</div>
|
116 |
+
</div>
|
117 |
+
</div>
|
118 |
+
|
119 |
+
<?php endif; ?>
|
120 |
+
<fieldset>
|
121 |
+
<div><h1 class="sg-backup-page-title"><?php _backupGuardT('Backups') ?></h1></div>
|
122 |
+
|
123 |
+
<a href="javascript:void(0)" id="sg-manual-backup" class="pull-left btn btn-success sg-backup-action-buttons"
|
124 |
+
data-toggle="modal" data-modal-name="manual-backup" data-remote="modalManualBackup"
|
125 |
+
sg-data-backup-type="<?php echo SG_BACKUP_METHOD_STANDARD ?>">
|
126 |
+
<span class="sg-backup-start sg-backup-buttons-content"></span>
|
127 |
+
<span class="sg-backup-buttons-content sg-backup-buttons-text"><?php _backupGuardT('Backup') ?></span>
|
128 |
+
</a>
|
129 |
+
|
130 |
+
<a href="javascript:void(0)" id="sg-backup-with-migration"
|
131 |
+
class="pull-left btn btn-primary sg-backup-action-buttons" data-toggle="modal"
|
132 |
+
data-modal-name="manual-backup" data-remote="modalManualBackup"
|
133 |
+
sg-data-backup-type="<?php echo SG_BACKUP_METHOD_MIGRATE ?>"<?php echo SGBoot::isFeatureAvailable('BACKUP_WITH_MIGRATION') ? '' : 'disabled' ?>>
|
134 |
+
<span class="sg-backup-migrate sg-backup-buttons-content"></span>
|
135 |
+
<span class="sg-backup-buttons-text sg-backup-buttons-content"><?php _backupGuardT('Migrate') ?></span>
|
136 |
+
</a>
|
137 |
+
<?php if (!(defined('SG_USER_MODE') && SG_USER_MODE)) : ?>
|
138 |
+
<a href="javascript:void(0)" id="sg-import"
|
139 |
+
class="btn btn-primary sg-margin-left-12 pull-left sg-backup-action-buttons" data-toggle="modal"
|
140 |
+
data-modal-name="import" data-remote="modalImport">
|
141 |
+
<span class="sg-backup-import sg-backup-buttons-content"></span>
|
142 |
+
<span class="sg-backup-buttons-text sg-backup-buttons-content"><?php _backupGuardT('Import') ?><span>
|
143 |
+
</a>
|
144 |
+
<?php endif; ?>
|
145 |
+
<?php if ($pluginCapabilities == BACKUP_GUARD_CAPABILITIES_FREE) : ?>
|
146 |
+
<a href="<?php echo BACKUP_GUARD_WORDPRESS_SUPPORT_URL; ?>" target="_blank">
|
147 |
+
<button type="button" id="sg-report-problem-button"
|
148 |
+
class="btn btn btn-primary sg-margin-left-12 pull-right sg-backup-action-buttons sg-button-red pull-right">
|
149 |
+
<span class="sg-backup-report"></span>
|
150 |
+
|
151 |
+
<span class="sg-backup-buttons-text sg-backup-buttons-content"><?php _backupGuardT('Report issue') ?></span>
|
152 |
+
</button>
|
153 |
+
</a>
|
154 |
+
<?php endif; ?>
|
155 |
+
<a id="sg-delete-multi-backups" class="pull-right btn btn-danger sg-margin-left-12 sg-backup-action-buttons">
|
156 |
+
<span class="sg-backup-delete sg-backup-buttons-content"></span>
|
157 |
+
<span class="sg-backup-buttons-text sg-backup-buttons-content"><?php _backupGuardT('Delete') ?></span>
|
158 |
+
</a>
|
159 |
+
<div class="clearfix"></div>
|
160 |
+
<br/>
|
161 |
+
<table class="table table-striped paginated sg-backup-table sg-backups">
|
162 |
+
<thead>
|
163 |
+
<tr>
|
164 |
+
<th><input type="checkbox" id="sg-checkbox-select-all" autocomplete="off"></th>
|
165 |
+
<th><?php _backupGuardT('Filename') ?></th>
|
166 |
+
<th><?php _backupGuardT('Size') ?></th>
|
167 |
+
<th><?php _backupGuardT('Date') ?></th>
|
168 |
+
<th><?php _backupGuardT('Status') ?></th>
|
169 |
+
<th><?php _backupGuardT('Actions') ?></th>
|
170 |
+
</tr>
|
171 |
+
</thead>
|
172 |
+
<tbody>
|
173 |
+
<?php if (empty($backups)) : ?>
|
174 |
+
<tr>
|
175 |
+
<td colspan="6"><?php _backupGuardT('No backups found.') ?></td>
|
176 |
+
</tr>
|
177 |
+
<?php endif; ?>
|
178 |
+
<?php foreach ($backups as $backup) : ?>
|
179 |
+
<tr>
|
180 |
+
<td><input type="checkbox" autocomplete="off"
|
181 |
+
value="<?php echo $backup['name'] ?>" <?php echo $backup['active'] ? 'disabled' : '' ?>>
|
182 |
+
</td>
|
183 |
+
<td><?php echo $backup['name'] ?></td>
|
184 |
+
<td><?php echo !$backup['active'] ? $backup['size'] : '' ?></td>
|
185 |
+
<td><?php echo backupGuardConvertDateTimezone($backup['date'], true) ?></td>
|
186 |
+
<td id="sg-status-tabe-data-<?php echo $backup['id'] ?>" <?php echo $backup['active'] ? 'data-toggle="tooltip" data-placement="top" data-original-title="" data-container="#sg-wrapper"' : '' ?>>
|
187 |
+
<?php
|
188 |
+
if ($backup['active']) :
|
189 |
+
$filteredStatuses = backupGuardFilterStatusesByActionType($backup, $backup['options']);
|
190 |
+
?>
|
191 |
+
<input type="hidden" class="sg-active-action-id" value="<?php echo $backup['id']; ?>"/>
|
192 |
+
<?php foreach ($filteredStatuses as $statusCode) : ?>
|
193 |
+
<span class="btn-xs sg-status-icon sg-status-<?php echo $statusCode; ?>"> </span>
|
194 |
+
<?php endforeach; ?>
|
195 |
+
<div class="sg-progress progress">
|
196 |
+
<div class="progress-bar"></div>
|
197 |
+
</div>
|
198 |
+
<?php else : ?>
|
199 |
+
<?php
|
200 |
+
if ($backup['status'] == SG_ACTION_STATUS_FINISHED_WARNINGS) : ?>
|
201 |
+
<span class="btn-xs text-warning" data-toggle="tooltip" data-placement="top"
|
202 |
+
data-original-title="
|
203 |
+
<?php if ($backup['type'] == SG_ACTION_TYPE_BACKUP) :
|
204 |
+
echo _backupGuardT('Warnings found during backup', true);
|
205 |
+
elseif ($backup['type'] == SG_ACTION_TYPE_RESTORE) :
|
206 |
+
echo _backupGuardT('Warnings found during restore', true);
|
207 |
+
else :
|
208 |
+
echo _backupGuardT('Warnings found during upload', true);
|
209 |
+
endif; ?>
|
210 |
+
" data-container="#sg-wrapper"><?php _backupGuardT('Warning') ?></span>
|
211 |
+
<?php elseif ($backup['status'] == SG_ACTION_STATUS_ERROR) : ?>
|
212 |
+
<span class="btn-xs text-danger" data-toggle="tooltip" data-placement="top"
|
213 |
+
data-original-title="
|
214 |
+
<?php if ($backup['type'] == SG_ACTION_TYPE_BACKUP) :
|
215 |
+
echo _backupGuardT('Errors found during backup', true);
|
216 |
+
elseif ($backup['type'] == SG_ACTION_TYPE_RESTORE) :
|
217 |
+
echo _backupGuardT('Errors found during restore', true);
|
218 |
+
else :
|
219 |
+
echo _backupGuardT('Errors found during upload', true);
|
220 |
+
endif; ?>
|
221 |
+
" data-container="#sg-wrapper"><?php _backupGuardT('Failed') ?></span>
|
222 |
+
<?php else : ?>
|
223 |
+
<span class="btn-xs sg-text-success"><?php _backupGuardT('Success') ?></span>
|
224 |
+
<?php endif; ?>
|
225 |
+
<?php endif; ?>
|
226 |
+
</td>
|
227 |
+
<td class="sg-backup-actions-td">
|
228 |
+
<?php if ($backup['active']) : ?>
|
229 |
+
<?php if ($backup['type'] != SG_ACTION_TYPE_RESTORE) : ?>
|
230 |
+
<a class="btn-xs sg-cancel-backup" sg-data-backup-id="<?php echo $backup['id'] ?>"
|
231 |
+
href="javascript:void(0)" title="<?php _backupGuardT('Stop') ?>"> </a>
|
232 |
+
<?php endif; ?>
|
233 |
+
<?php else : ?>
|
234 |
+
<a href="javascript:void(0)"
|
235 |
+
data-sgbackup-name="<?php echo htmlspecialchars($backup['name']); ?>"
|
236 |
+
data-remote="deleteBackup" class="sg-remove-backup btn-xs"
|
237 |
+
title="<?php _backupGuardT('Delete') ?>"> </a>
|
238 |
+
<div class="btn-group">
|
239 |
+
<a href="javascript:void(0)" class="sg-bg-download-button btn-xs"
|
240 |
+
data-toggle="dropdown1" aria-expanded="false"
|
241 |
+
title="<?php _backupGuardT('Download') ?>">
|
242 |
+
|
243 |
+
</a>
|
244 |
+
<ul class="dropdown-menu">
|
245 |
+
<?php if ($backup['files']) : ?>
|
246 |
+
<li>
|
247 |
+
<a href="<?php echo $downloadUrl . 'backupName=' . htmlspecialchars(@$backup['name']) . '&downloadType=' . SG_BACKUP_DOWNLOAD_TYPE_SGBP ?>">
|
248 |
+
<i class="glyphicon glyphicon-hdd"
|
249 |
+
aria-hidden="true"></i> <?php _backupGuardT('Backup') ?>
|
250 |
+
</a>
|
251 |
+
</li>
|
252 |
+
<?php endif; ?>
|
253 |
+
<?php if ($backup['backup_log']) : ?>
|
254 |
+
<li>
|
255 |
+
<a href="<?php echo $downloadUrl . 'backupName=' . htmlspecialchars(@$backup['name']) . '&downloadType=' . SG_BACKUP_DOWNLOAD_TYPE_BACKUP_LOG ?>">
|
256 |
+
<i class="glyphicon glyphicon-list-alt"
|
257 |
+
aria-hidden="true"></i> <?php _backupGuardT('Backup log') ?>
|
258 |
+
</a>
|
259 |
+
</li>
|
260 |
+
<?php endif; ?>
|
261 |
+
<?php if ($backup['restore_log']) : ?>
|
262 |
+
<li>
|
263 |
+
<a href="<?php echo $downloadUrl . 'backupName=' . @$backup['name'] . '&downloadType=' . SG_BACKUP_DOWNLOAD_TYPE_RESTORE_LOG ?>">
|
264 |
+
<i class="glyphicon glyphicon-th-list"
|
265 |
+
aria-hidden="true"></i> <?php _backupGuardT('Restore log') ?>
|
266 |
+
</a>
|
267 |
+
</li>
|
268 |
+
<?php endif; ?>
|
269 |
+
</ul>
|
270 |
+
</div>
|
271 |
+
<?php
|
272 |
+
$path = SG_BACKUP_DIRECTORY . $backup['name'] . '/' . $backup['name'] . '.sgbp';
|
273 |
+
?>
|
274 |
+
<?php if (file_exists($path) && ($backup['status'] != SG_ACTION_STATUS_ERROR) && (filesize($path) > SG_BACKUP_VALID_ARCHIVE_SIZE)) : ?>
|
275 |
+
<a href="javascript:void(0)" title="<?php _backupGuardT('Restore') ?>"
|
276 |
+
class="sg-restore-button btn-xs" data-toggle="modal" data-modal-name="manual-restore"
|
277 |
+
data-remote="modalManualRestore"
|
278 |
+
data-sgbp-params="<?php echo htmlspecialchars($backup['name']) ?>">
|
279 |
+
</a>
|
280 |
+
<?php endif; ?>
|
281 |
+
<?php endif; ?>
|
282 |
+
</td>
|
283 |
+
</tr>
|
284 |
+
<?php endforeach; ?>
|
285 |
+
</tbody>
|
286 |
+
</table>
|
287 |
+
<div class="text-right sg-backups">
|
288 |
+
<ul class="pagination"></ul>
|
289 |
+
</div>
|
290 |
+
</fieldset>
|
291 |
+
<div class="clearfix"></div>
|
292 |
+
</div>
|
public/js/sgbackup.js
CHANGED
@@ -1,1013 +1,1017 @@
|
|
1 |
-
/* phpcs:disable */
|
2 |
-
|
3 |
-
BG_BACKUP_STRINGS_DEACTIVATE = [];
|
4 |
-
SG_DOWNLOAD_PROGRESS = '';
|
5 |
-
SG_ACTIVE_DOWNLOAD_AJAX = '';
|
6 |
-
SG_CHECK_ACTION_STATUS_REQUEST_FREQUENCY = 10000;
|
7 |
-
|
8 |
-
SG_STORAGE_FTP = 1;
|
9 |
-
SG_STORAGE_DROPBOX = 2;
|
10 |
-
SG_STORAGE_GOOGLE_DRIVE = 3;
|
11 |
-
SG_STORAGE_AMAZON = 4;
|
12 |
-
SG_STORAGE_ONE_DRIVE = 5;
|
13 |
-
SG_STORAGE_BACKUP_GUARD = 6;
|
14 |
-
SG_STORAGE_P_CLOUD = 7;
|
15 |
-
SG_STORAGE_BOX = 8;
|
16 |
-
|
17 |
-
BG_BACKUP_STRINGS_DEACTIVATE.areYouSure = "Are you sure?";
|
18 |
-
|
19 |
-
|
20 |
-
jQuery(document).on(
|
21 |
-
'change',
|
22 |
-
'.btn-file :file',
|
23 |
-
function () {
|
24 |
-
var input = jQuery(this);
|
25 |
-
|
26 |
-
if (input.get(0).files) {
|
27 |
-
var numFile = input.get(0).files.length
|
28 |
-
} else {
|
29 |
-
var numFiles = 1;
|
30 |
-
}
|
31 |
-
|
32 |
-
var label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
|
33 |
-
input.trigger('fileselect', [numFiles, label]);
|
34 |
-
}
|
35 |
-
);
|
36 |
-
|
37 |
-
jQuery(document).ready(
|
38 |
-
function () {
|
39 |
-
sgBackup.initTablePagination('sg-backups');
|
40 |
-
sgBackup.initActiveAction();
|
41 |
-
sgBackup.initBackupDeletion();
|
42 |
-
sgBackup.toggleMultiDeleteButton();
|
43 |
-
sgBackup.closeFreeBanner();
|
44 |
-
|
45 |
-
jQuery('span[data-toggle=tooltip]').tooltip();
|
46 |
-
|
47 |
-
jQuery('#sg-checkbox-select-all').on(
|
48 |
-
'change',
|
49 |
-
function () {
|
50 |
-
var checkAll = jQuery('#sg-checkbox-select-all');
|
51 |
-
jQuery('tbody input[type="checkbox"]:not(:disabled):visible').prop('checked', checkAll.prop('checked'));
|
52 |
-
sgBackup.toggleMultiDeleteButton();
|
53 |
-
}
|
54 |
-
);
|
55 |
-
|
56 |
-
jQuery('#sg-delete-multi-backups').on(
|
57 |
-
'click',
|
58 |
-
function () {
|
59 |
-
if (!confirm(BG_BACKUP_STRINGS_DEACTIVATE.areYouSure)) {
|
60 |
-
return false;
|
61 |
-
}
|
62 |
-
|
63 |
-
var backups = jQuery('tbody input[type="checkbox"]:checked');
|
64 |
-
var backupNames = [];
|
65 |
-
backups.each(
|
66 |
-
function (i) {
|
67 |
-
backupNames[i] = jQuery(this).val();
|
68 |
-
}
|
69 |
-
);
|
70 |
-
|
71 |
-
if (backupNames.length) {
|
72 |
-
sgBackup.deleteMultiBackups(backupNames);
|
73 |
-
}
|
74 |
-
}
|
75 |
-
);
|
76 |
-
|
77 |
-
jQuery('tbody input[type="checkbox"]').on(
|
78 |
-
'change',
|
79 |
-
function () {
|
80 |
-
var numberOfBackups = jQuery('tbody input[type="checkbox"]').length;
|
81 |
-
var numberOfChoosenBackups = sgBackup.getSelectedBackupsNumber();
|
82 |
-
var isCheked = jQuery(this).is(':checked');
|
83 |
-
sgBackup.toggleMultiDeleteButton();
|
84 |
-
|
85 |
-
if (!isCheked) {
|
86 |
-
jQuery('#sg-checkbox-select-all').prop('checked', false);
|
87 |
-
} else {
|
88 |
-
if (numberOfBackups === numberOfChoosenBackups) {
|
89 |
-
jQuery('#sg-checkbox-select-all').prop('checked', true);
|
90 |
-
}
|
91 |
-
}
|
92 |
-
}
|
93 |
-
);
|
94 |
-
|
95 |
-
var surveyClose = function (e) {
|
96 |
-
e.preventDefault();
|
97 |
-
|
98 |
-
jQuery('.bg-verify-user-info-container').slideUp();
|
99 |
-
jQuery('.bg-verify-user-info-overlay').hide();
|
100 |
-
|
101 |
-
var ajaxHandler = new sgRequestHandler('setUserInfoVerificationPopupState', {token: BG_BACKUP_STRINGS.nonce});
|
102 |
-
ajaxHandler.run();
|
103 |
-
};
|
104 |
-
|
105 |
-
jQuery('.bg-verify-user-info-overlay').bind('click', surveyClose);
|
106 |
-
|
107 |
-
jQuery('.bg-verify-user-info-cancel').click(surveyClose);
|
108 |
-
|
109 |
-
jQuery('#bg-verify-user-prioraty').on(
|
110 |
-
'change',
|
111 |
-
function () {
|
112 |
-
if (jQuery(this).val() === "other") {
|
113 |
-
jQuery('#bg-verify-user-priorati-custom').show();
|
114 |
-
} else {
|
115 |
-
jQuery('#bg-verify-user-priorati-custom').hide();
|
116 |
-
}
|
117 |
-
}
|
118 |
-
);
|
119 |
-
|
120 |
-
jQuery('.bg-verify-user-info-verify-email').click(
|
121 |
-
function (e) {
|
122 |
-
e.preventDefault();
|
123 |
-
|
124 |
-
var email = jQuery('#bg-verify-user-info-email').val();
|
125 |
-
var fname = jQuery('#bg-verify-user-info-name').val();
|
126 |
-
var lname = jQuery('#bg-verify-user-info-last-name').val();
|
127 |
-
var priority = jQuery('#bg-verify-user-prioraty').val();
|
128 |
-
|
129 |
-
var sendData = true;
|
130 |
-
jQuery('.bg-verify-user-info-error-message').hide();
|
131 |
-
|
132 |
-
if (priority === "other") {
|
133 |
-
priority = jQuery('#bg-verify-user-priorati-custom').val();
|
134 |
-
|
135 |
-
if (!priority) {
|
136 |
-
jQuery('#bg-verify-user-info-priority-custom-error').show()
|
137 |
-
sendData = false;
|
138 |
-
}
|
139 |
-
} else if (!priority) {
|
140 |
-
jQuery('#bg-verify-user-info-priority-error').show()
|
141 |
-
sendData = false;
|
142 |
-
}
|
143 |
-
|
144 |
-
if (fname === '') {
|
145 |
-
jQuery('#bg-verify-user-info-name-error').show();
|
146 |
-
sendData = false;
|
147 |
-
}
|
148 |
-
|
149 |
-
if (lname === '') {
|
150 |
-
jQuery('#bg-verify-user-info-last-name-error').show();
|
151 |
-
sendData = false;
|
152 |
-
}
|
153 |
-
|
154 |
-
if (!sgBackup.isValidEmailAddress(email)) {
|
155 |
-
jQuery('#bg-verify-user-info-email-error').show();
|
156 |
-
sendData = false;
|
157 |
-
}
|
158 |
-
|
159 |
-
if (sendData) {
|
160 |
-
jQuery('.bg-verify-user-info-container').slideUp();
|
161 |
-
jQuery('.bg-verify-user-info-overlay').hide();
|
162 |
-
var currentStatus = jQuery('.backup-send-usage-data-status').is(':checked');
|
163 |
-
|
164 |
-
var ajaxHandler = new sgRequestHandler(
|
165 |
-
'storeSubscriberInfo',
|
166 |
-
{
|
167 |
-
email: email,
|
168 |
-
fname: fname,
|
169 |
-
lname: lname,
|
170 |
-
priority: priority,
|
171 |
-
currentStatus: currentStatus,
|
172 |
-
token: BG_BACKUP_STRINGS.nonce
|
173 |
-
}
|
174 |
-
);
|
175 |
-
|
176 |
-
ajaxHandler.run();
|
177 |
-
}
|
178 |
-
}
|
179 |
-
);
|
180 |
-
}
|
181 |
-
);
|
182 |
-
|
183 |
-
sgBackup.isValidEmailAddress = function (emailAddress) {
|
184 |
-
var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,10}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
|
185 |
-
return pattern.test(emailAddress);
|
186 |
-
|
187 |
-
};
|
188 |
-
|
189 |
-
sgBackup.getSelectedBackupsNumber = function () {
|
190 |
-
return jQuery('tbody input[type="checkbox"]:checked').length
|
191 |
-
|
192 |
-
};
|
193 |
-
|
194 |
-
sgBackup.toggleMultiDeleteButton = function () {
|
195 |
-
var numberOfChoosenBackups = sgBackup.getSelectedBackupsNumber();
|
196 |
-
var target = jQuery('#sg-delete-multi-backups');
|
197 |
-
if (numberOfChoosenBackups > 0) {
|
198 |
-
target.removeAttr('disabled');
|
199 |
-
} else {
|
200 |
-
target.attr('disabled', 'disabled');
|
201 |
-
}
|
202 |
-
|
203 |
-
};
|
204 |
-
|
205 |
-
sgBackup.closeFreeBanner = function () {
|
206 |
-
jQuery('.sg-close-free-banner').bind(
|
207 |
-
'click',
|
208 |
-
function () {
|
209 |
-
var ajaxHandler = new sgRequestHandler(
|
210 |
-
'closeFreeBanner',
|
211 |
-
{
|
212 |
-
token: BG_BACKUP_STRINGS.nonce
|
213 |
-
}
|
214 |
-
);
|
215 |
-
ajaxHandler.callback = function (response, error) {
|
216 |
-
jQuery('#sg-banner').remove();
|
217 |
-
};
|
218 |
-
ajaxHandler.run();
|
219 |
-
}
|
220 |
-
);
|
221 |
-
};
|
222 |
-
|
223 |
-
sgBackup.deleteMultiBackups = function (backupNames) {
|
224 |
-
var ajaxHandler = new sgRequestHandler('deleteBackup', {backupName: backupNames, token: BG_BACKUP_STRINGS.nonce});
|
225 |
-
ajaxHandler.callback = function (response) {
|
226 |
-
location.reload();
|
227 |
-
};
|
228 |
-
ajaxHandler.run();
|
229 |
-
|
230 |
-
};
|
231 |
-
|
232 |
-
// SGManual Backup AJAX callback.
|
233 |
-
sgBackup.manualBackup = function (checkedStatus) {
|
234 |
-
var error = [];
|
235 |
-
// Validation.
|
236 |
-
jQuery('.alert').remove();
|
237 |
-
if (jQuery('input[type=radio][name=backupType]:checked').val() === 2) {
|
238 |
-
if (jQuery('.sg-custom-option:checked').length <= 0) {
|
239 |
-
error.push(BG_BACKUP_STRINGS.invalidBackupOption);
|
240 |
-
}
|
241 |
-
|
242 |
-
// Check if any file is selected.
|
243 |
-
if (jQuery('input[type=checkbox][name=backupFiles]:checked').length > 0) {
|
244 |
-
if (jQuery('.sg-custom-backup-files input:checkbox:checked').length <= 0) {
|
245 |
-
error.push(BG_BACKUP_STRINGS.invalidDirectorySelected);
|
246 |
-
}
|
247 |
-
}
|
248 |
-
}
|
249 |
-
|
250 |
-
// Check if any cloud is selected.
|
251 |
-
if (jQuery('input[type=checkbox][name=backupCloud]:checked').length > 0) {
|
252 |
-
if (jQuery('.sg-custom-backup-cloud input:checkbox:checked').length <= 0) {
|
253 |
-
error.push(BG_BACKUP_STRINGS.invalidCloud);
|
254 |
-
}
|
255 |
-
}
|
256 |
-
|
257 |
-
// If any error show it and abort ajax.
|
258 |
-
if (error.length) {
|
259 |
-
var sgAlert = sgBackup.alertGenerator(error, 'alert-danger');
|
260 |
-
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
261 |
-
return false;
|
262 |
-
}
|
263 |
-
|
264 |
-
if (!checkedStatus) {
|
265 |
-
sgBackup.checkBackupCreation();
|
266 |
-
}
|
267 |
-
|
268 |
-
// Before all disable buttons.
|
269 |
-
jQuery('.alert').remove();
|
270 |
-
jQuery('.modal-footer .btn-primary').attr('disabled', 'disabled');
|
271 |
-
jQuery('.modal-footer .btn-primary').html(BG_BACKUP_STRINGS.backupInProgress);
|
272 |
-
|
273 |
-
// Reset Status!
|
274 |
-
var backupName = jQuery("#sg-custom-backup-name").val();
|
275 |
-
var resetStatusHandler = new sgRequestHandler(
|
276 |
-
'resetStatus',
|
277 |
-
{
|
278 |
-
backupName: backupName,
|
279 |
-
token: BG_BACKUP_STRINGS.nonce
|
280 |
-
}
|
281 |
-
);
|
282 |
-
resetStatusHandler.callback = function (response, error) {
|
283 |
-
var manualBackupForm = jQuery('#manualBackup');
|
284 |
-
var manualBackupHandler = new sgRequestHandler('manualBackup', manualBackupForm.serialize() + '&token=' + BG_BACKUP_STRINGS.nonce);
|
285 |
-
|
286 |
-
manualBackupHandler.dataIsObject = false;
|
287 |
-
// If error!
|
288 |
-
if (typeof response.success === 'undefined') {
|
289 |
-
var sgAlert = sgBackup.alertGenerator(response, 'alert-danger');
|
290 |
-
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
291 |
-
|
292 |
-
if (response === 0 || response === false || response === '0' || response === 'false') {
|
293 |
-
response = BG_BACKUP_STRINGS.errorMessage;
|
294 |
-
}
|
295 |
-
|
296 |
-
sgBackup.restManualBackupModal();
|
297 |
-
return false;
|
298 |
-
}
|
299 |
-
|
300 |
-
if (checkedStatus) {
|
301 |
-
sgBackup.hideAndReload();
|
302 |
-
}
|
303 |
-
|
304 |
-
manualBackupHandler.run();
|
305 |
-
};
|
306 |
-
resetStatusHandler.run();
|
307 |
-
|
308 |
-
};
|
309 |
-
|
310 |
-
sgBackup.hideAndReload = function () {
|
311 |
-
jQuery('#sg-modal').modal('hide');
|
312 |
-
location.reload();
|
313 |
-
|
314 |
-
};
|
315 |
-
|
316 |
-
sgBackup.restManualBackupModal = function () {
|
317 |
-
jQuery('.modal-footer .btn-primary').removeAttr('disabled');
|
318 |
-
jQuery('.modal-footer .btn-primary').html('Backup');
|
319 |
-
|
320 |
-
};
|
321 |
-
|
322 |
-
sgBackup.cancelDonwload = function (name) {
|
323 |
-
var cancelDonwloadHandler = new sgRequestHandler('cancelDownload', {name: name, token: BG_BACKUP_STRINGS.nonce});
|
324 |
-
cancelDonwloadHandler.callback = function (response) {
|
325 |
-
sgBackup.hideAjaxSpinner();
|
326 |
-
location.reload();
|
327 |
-
};
|
328 |
-
cancelDonwloadHandler.run();
|
329 |
-
|
330 |
-
};
|
331 |
-
|
332 |
-
sgBackup.listStorage = function (importFrom) {
|
333 |
-
var listStorage = new sgRequestHandler('listStorage', {storage: importFrom, token: BG_BACKUP_STRINGS.nonce});
|
334 |
-
sgBackup.showAjaxSpinner('#sg-modal-inport-from');
|
335 |
-
jQuery('#sg-archive-list-table tbody').empty();
|
336 |
-
|
337 |
-
jQuery('#sg-modal').off('hide.bs.modal').on(
|
338 |
-
'hide.bs.modal',
|
339 |
-
function (e) {
|
340 |
-
if (SG_ACTIVE_DOWNLOAD_AJAX) {
|
341 |
-
if (!confirm(BG_BACKUP_STRINGS.confirm)) {
|
342 |
-
e.preventDefault();
|
343 |
-
return false;
|
344 |
-
}
|
345 |
-
|
346 |
-
var target = jQuery('input[name="select-archive-to-download"]:checked');
|
347 |
-
var name = target.attr('file-name');
|
348 |
-
|
349 |
-
sgBackup.cancelDonwload(name);
|
350 |
-
}
|
351 |
-
}
|
352 |
-
);
|
353 |
-
|
354 |
-
listStorage.callback = function (response, error) {
|
355 |
-
var cloudName = '';
|
356 |
-
var cloudId = parseInt(importFrom, 10);
|
357 |
-
|
358 |
-
switch (cloudId) {
|
359 |
-
case SG_STORAGE_AMAZON:
|
360 |
-
cloudName = "S3";
|
361 |
-
break;
|
362 |
-
|
363 |
-
case SG_STORAGE_DROPBOX:
|
364 |
-
cloudName = "Dropbox";
|
365 |
-
break;
|
366 |
-
|
367 |
-
case SG_STORAGE_GOOGLE_DRIVE:
|
368 |
-
cloudName = "Google Drive";
|
369 |
-
break;
|
370 |
-
|
371 |
-
case SG_STORAGE_FTP:
|
372 |
-
cloudName = "FTP";
|
373 |
-
break;
|
374 |
-
|
375 |
-
case SG_STORAGE_ONE_DRIVE:
|
376 |
-
cloudName = "OneDrive";
|
377 |
-
break;
|
378 |
-
|
379 |
-
case SG_STORAGE_P_CLOUD:
|
380 |
-
cloudName = "pCloud";
|
381 |
-
break;
|
382 |
-
|
383 |
-
case SG_STORAGE_BOX:
|
384 |
-
cloudName = "box.com";
|
385 |
-
break;
|
386 |
-
|
387 |
-
case SG_STORAGE_BACKUP_GUARD:
|
388 |
-
cloudName = "BackupGuard";
|
389 |
-
break;
|
390 |
-
|
391 |
-
default:
|
392 |
-
cloudName = '';
|
393 |
-
break;
|
394 |
-
}//end switch
|
395 |
-
|
396 |
-
jQuery('.modal-title').html('Import from ' + cloudName);
|
397 |
-
|
398 |
-
sgBackup.hideAjaxSpinner();
|
399 |
-
var content = '';
|
400 |
-
if ((typeof response.error !== "undefined") || response.length === 0 || response === undefined) {
|
401 |
-
content = '<tr><td colspan="4">' + BG_BACKUP_STRINGS.noBackupsAvailable + '</td></tr>';
|
402 |
-
} else {
|
403 |
-
jQuery.each(
|
404 |
-
response,
|
405 |
-
function (key, value) {
|
406 |
-
var backupId = 0;
|
407 |
-
|
408 |
-
if (typeof value.id !== 'undefined') {
|
409 |
-
backupId = value.id;
|
410 |
-
value.path = value.name;
|
411 |
-
}
|
412 |
-
|
413 |
-
content += '<tr>';
|
414 |
-
content += '<td class="file-select-radio"><input type="radio" file-name="' + value.name + '" name="select-archive-to-download" size="' + value.size + '" backup-id="' + backupId + '" storage="' + importFrom + '" value="' + value.path + '"></td>';
|
415 |
-
content += '<td>' + value.name + '</td>';
|
416 |
-
content += '<td>' + sgBackup.convertBytesToMegabytes(value.size) + '</td>';
|
417 |
-
content += '<td>' + value.date + '</td>';
|
418 |
-
content += '</tr>';
|
419 |
-
}
|
420 |
-
);
|
421 |
-
}//end if
|
422 |
-
|
423 |
-
jQuery('#sg-archive-list-table tbody').append(content);
|
424 |
-
sgBackup.toggleDownloadFromCloudPage();
|
425 |
-
};
|
426 |
-
|
427 |
-
listStorage.run();
|
428 |
-
|
429 |
-
};
|
430 |
-
|
431 |
-
|
432 |
-
sgBackup.convertBytesToMegabytes = function ($bytes) {
|
433 |
-
return ($bytes / (1024 * 1024)).toFixed(2);
|
434 |
-
|
435 |
-
};
|
436 |
-
|
437 |
-
// Init file upload!
|
438 |
-
sgBackup.initFileUpload = function () {
|
439 |
-
sgBackup.downloadFromPC();
|
440 |
-
|
441 |
-
jQuery('#uploadSgbpFile').click(
|
442 |
-
function () {
|
443 |
-
if (jQuery('#modal-import-3').is(":visible")) {
|
444 |
-
var target = jQuery('input[name="select-archive-to-download"]:checked');
|
445 |
-
var path = target.val();
|
446 |
-
var name = target.attr('file-name');
|
447 |
-
var storage = target.attr('storage');
|
448 |
-
var size = target.attr('size');
|
449 |
-
var backupId = target.attr('backup-id');
|
450 |
-
sgBackup.downloadFromCloud(path, name, storage, size, backupId);
|
451 |
-
}
|
452 |
-
}
|
453 |
-
);
|
454 |
-
|
455 |
-
};
|
456 |
-
|
457 |
-
sgBackup.nextPage = function () {
|
458 |
-
var importFrom = jQuery('input[name="storage-radio"]:checked').val();
|
459 |
-
jQuery('.alert').remove();
|
460 |
-
|
461 |
-
if (!importFrom) {
|
462 |
-
var alert = sgBackup.alertGenerator(BG_BACKUP_STRINGS.invalidImportOption, 'alert-danger');
|
463 |
-
jQuery('#sg-modal .modal-header').prepend(alert);
|
464 |
-
} else {
|
465 |
-
if (importFrom === 'local-pc') {
|
466 |
-
sgBackup.toggleDownloadFromPCPage();
|
467 |
-
} else {
|
468 |
-
var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: "DOWNLOAD_FROM_CLOUD"});
|
469 |
-
isFeatureAvailable.callback = function (response) {
|
470 |
-
if (typeof response.success !== 'undefined') {
|
471 |
-
sgBackup.listStorage(importFrom);
|
472 |
-
} else {
|
473 |
-
var alert = sgBackup.alertGenerator(response.error, 'alert-danger');
|
474 |
-
jQuery('#sg-modal .modal-header').prepend(alert);
|
475 |
-
}
|
476 |
-
};
|
477 |
-
|
478 |
-
isFeatureAvailable.run();
|
479 |
-
}
|
480 |
-
}
|
481 |
-
|
482 |
-
};
|
483 |
-
|
484 |
-
sgBackup.previousPage = function () {
|
485 |
-
if (jQuery('#modal-import-2').is(":visible")) {
|
486 |
-
jQuery('#modal-import-2').hide();
|
487 |
-
} else {
|
488 |
-
jQuery('#modal-import-3').hide();
|
489 |
-
}
|
490 |
-
|
491 |
-
sgBackup.toggleNavigationButtons();
|
492 |
-
|
493 |
-
jQuery('#modal-import-1').show();
|
494 |
-
jQuery('#uploadSgbpFile').hide();
|
495 |
-
|
496 |
-
jQuery('.modal-title').html('Import from');
|
497 |
-
|
498 |
-
};
|
499 |
-
|
500 |
-
sgBackup.toggleNavigationButtons = function () {
|
501 |
-
jQuery('#switch-modal-import-pages-next').toggle();
|
502 |
-
jQuery('#switch-modal-import-pages-back').toggle();
|
503 |
-
|
504 |
-
};
|
505 |
-
|
506 |
-
sgBackup.toggleDownloadFromPCPage = function () {
|
507 |
-
sgBackup.toggleNavigationButtons();
|
508 |
-
jQuery('#modal-import-1').toggle();
|
509 |
-
jQuery('#modal-import-2').toggle();
|
510 |
-
jQuery('#uploadSgbpFile').toggle();
|
511 |
-
|
512 |
-
};
|
513 |
-
|
514 |
-
sgBackup.toggleDownloadFromCloudPage = function () {
|
515 |
-
sgBackup.toggleNavigationButtons();
|
516 |
-
jQuery('#modal-import-1').toggle();
|
517 |
-
jQuery('#modal-import-3').toggle();
|
518 |
-
jQuery('#uploadSgbpFile').toggle();
|
519 |
-
|
520 |
-
};
|
521 |
-
|
522 |
-
sgBackup.downloadFromCloud = function (path, name, storage, size, backupId) {
|
523 |
-
sgBackup.showAjaxSpinner('.modal-dialog');
|
524 |
-
var error = [];
|
525 |
-
if (!path) {
|
526 |
-
error.push(BG_BACKUP_STRINGS.invalidDownloadFile);
|
527 |
-
}
|
528 |
-
|
529 |
-
jQuery('.alert').remove();
|
530 |
-
|
531 |
-
if (error.length) {
|
532 |
-
sgBackup.hideAjaxSpinner();
|
533 |
-
var sgAlert = sgBackup.alertGenerator(error, 'alert-danger');
|
534 |
-
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
535 |
-
return false;
|
536 |
-
}
|
537 |
-
|
538 |
-
var downloadFromCloudHandler = new sgRequestHandler(
|
539 |
-
'downloadFromCloud',
|
540 |
-
{
|
541 |
-
path: path,
|
542 |
-
storage: storage,
|
543 |
-
size: size,
|
544 |
-
backupId: backupId,
|
545 |
-
token: BG_BACKUP_STRINGS.nonce
|
546 |
-
}
|
547 |
-
);
|
548 |
-
|
549 |
-
jQuery('#switch-modal-import-pages-back').hide();
|
550 |
-
jQuery('#uploadSgbpFile').attr('disabled', 'disabled');
|
551 |
-
|
552 |
-
downloadFromCloudHandler.callback = function (response, error) {
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
jQuery('#uploadSgbpFile').html(BG_BACKUP_STRINGS.import);
|
562 |
-
|
563 |
-
var sgAlert = sgBackup.alertGenerator(response.error, 'alert-danger');
|
564 |
-
|
565 |
-
jQuery('#uploadSgbpFile').attr('disabled', false);
|
566 |
-
jQuery('#switch-modal-import-pages-back').toggle();
|
567 |
-
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
568 |
-
SG_ACTIVE_DOWNLOAD_AJAX = false;
|
569 |
-
|
570 |
-
return false;
|
571 |
-
}
|
572 |
-
};
|
573 |
-
|
574 |
-
SG_ACTIVE_DOWNLOAD_AJAX = true;
|
575 |
-
downloadFromCloudHandler.run();
|
576 |
-
sgBackup.fileDownloadProgress(name, size);
|
577 |
-
|
578 |
-
};
|
579 |
-
|
580 |
-
sgBackup.downloadFromPC = function () {
|
581 |
-
var sgData = null;
|
582 |
-
jQuery('#sg-modal').off('hide.bs.modal').on(
|
583 |
-
'hide.bs.modal',
|
584 |
-
function (e) {
|
585 |
-
if (SG_ACTIVE_DOWNLOAD_AJAX) {
|
586 |
-
if (!confirm(BG_BACKUP_STRINGS.confirm)) {
|
587 |
-
e.preventDefault();
|
588 |
-
return false;
|
589 |
-
}
|
590 |
-
|
591 |
-
sgData.abort();
|
592 |
-
sgBackup.cancelDonwload(sgData.files[0].name);
|
593 |
-
}
|
594 |
-
}
|
595 |
-
);
|
596 |
-
|
597 |
-
jQuery('.sg-backup-upload-input').fileupload(
|
598 |
-
{
|
599 |
-
dataType: 'json',
|
600 |
-
maxChunkSize: 2000000,
|
601 |
-
add: function (e, data) {
|
602 |
-
if (data.originalFiles.length) {
|
603 |
-
var fileName = data.originalFiles[0].name;
|
604 |
-
jQuery('#sg-import-file-name').val(fileName);
|
605 |
-
}
|
606 |
-
|
607 |
-
jQuery('#uploadSgbpFile').click(
|
608 |
-
function () {
|
609 |
-
if (jQuery('#modal-import-2').is(":visible")) {
|
610 |
-
sgData = data;
|
611 |
-
SG_ACTIVE_DOWNLOAD_AJAX = true;
|
612 |
-
jQuery('#uploadSgbpFile').attr('disabled', 'disabled');
|
613 |
-
jQuery('#switch-modal-import-pages-back').hide();
|
614 |
-
jQuery('#uploadSgbpFile').html(BG_BACKUP_STRINGS.importInProgress);
|
615 |
-
data.submit();
|
616 |
-
}
|
617 |
-
}
|
618 |
-
);
|
619 |
-
},
|
620 |
-
done: function (e, data) {
|
621 |
-
location.reload();
|
622 |
-
},
|
623 |
-
progress: function (e, data) {
|
624 |
-
var progress = parseInt(((data.loaded / data.total) * 100), 10);
|
625 |
-
jQuery('#uploadSgbpFile').html('Importing (' + Math.round(progress) + '%)');
|
626 |
-
}
|
627 |
-
}
|
628 |
-
).on(
|
629 |
-
'fileuploadfail',
|
630 |
-
function (e, data) {
|
631 |
-
var alert = sgBackup.alertGenerator(BG_BACKUP_STRINGS.fileUploadFailed, 'alert-danger');
|
632 |
-
jQuery('#sg-modal .modal-header').prepend(alert);
|
633 |
-
}
|
634 |
-
);
|
635 |
-
|
636 |
-
};
|
637 |
-
|
638 |
-
sgBackup.fileDownloadProgress = function (file, size) {
|
639 |
-
var getFileDownloadProgress = new sgRequestHandler(
|
640 |
-
'getFileDownloadProgress',
|
641 |
-
{
|
642 |
-
file: file,
|
643 |
-
size: size,
|
644 |
-
token: BG_BACKUP_STRINGS.nonce
|
645 |
-
}
|
646 |
-
);
|
647 |
-
|
648 |
-
getFileDownloadProgress.callback = function (response) {
|
649 |
-
if (
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
};
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
}
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
location.
|
705 |
-
}
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
}
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
sgCheckBoxWrapper.find('input[type=checkbox]
|
756 |
-
sgCheckBoxWrapper.
|
757 |
-
}
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
}
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
jQuery('[for=cloud-
|
774 |
-
jQuery('[for=cloud-
|
775 |
-
jQuery('[for=cloud-
|
776 |
-
jQuery('[for=cloud-
|
777 |
-
|
778 |
-
jQuery('
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
};
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
}
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
}
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
}
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
)
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
var
|
906 |
-
|
907 |
-
sgActionHandler
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
}
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
tooltipText = 'Uploading to
|
958 |
-
} else if (response.subtype ===
|
959 |
-
tooltipText = 'Uploading to
|
960 |
-
} else if (response.subtype ===
|
961 |
-
tooltipText = 'Uploading to
|
962 |
-
} else if (response.subtype ===
|
963 |
-
tooltipText = 'Uploading to
|
964 |
-
} else if (response.subtype ===
|
965 |
-
tooltipText = 'Uploading to
|
966 |
-
} else if (response.subtype ===
|
967 |
-
tooltipText = 'Uploading to
|
968 |
-
}
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
}
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
jQuery('
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
jQuery('
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
ajaxHandler.
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
}
|
1012 |
-
|
1013 |
-
|
|
|
|
|
|
|
|
1 |
+
/* phpcs:disable */
|
2 |
+
|
3 |
+
BG_BACKUP_STRINGS_DEACTIVATE = [];
|
4 |
+
SG_DOWNLOAD_PROGRESS = '';
|
5 |
+
SG_ACTIVE_DOWNLOAD_AJAX = '';
|
6 |
+
SG_CHECK_ACTION_STATUS_REQUEST_FREQUENCY = 10000;
|
7 |
+
|
8 |
+
SG_STORAGE_FTP = 1;
|
9 |
+
SG_STORAGE_DROPBOX = 2;
|
10 |
+
SG_STORAGE_GOOGLE_DRIVE = 3;
|
11 |
+
SG_STORAGE_AMAZON = 4;
|
12 |
+
SG_STORAGE_ONE_DRIVE = 5;
|
13 |
+
SG_STORAGE_BACKUP_GUARD = 6;
|
14 |
+
SG_STORAGE_P_CLOUD = 7;
|
15 |
+
SG_STORAGE_BOX = 8;
|
16 |
+
|
17 |
+
BG_BACKUP_STRINGS_DEACTIVATE.areYouSure = "Are you sure?";
|
18 |
+
|
19 |
+
|
20 |
+
jQuery(document).on(
|
21 |
+
'change',
|
22 |
+
'.btn-file :file',
|
23 |
+
function () {
|
24 |
+
var input = jQuery(this);
|
25 |
+
|
26 |
+
if (input.get(0).files) {
|
27 |
+
var numFile = input.get(0).files.length
|
28 |
+
} else {
|
29 |
+
var numFiles = 1;
|
30 |
+
}
|
31 |
+
|
32 |
+
var label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
|
33 |
+
input.trigger('fileselect', [numFiles, label]);
|
34 |
+
}
|
35 |
+
);
|
36 |
+
|
37 |
+
jQuery(document).ready(
|
38 |
+
function () {
|
39 |
+
sgBackup.initTablePagination('sg-backups');
|
40 |
+
sgBackup.initActiveAction();
|
41 |
+
sgBackup.initBackupDeletion();
|
42 |
+
sgBackup.toggleMultiDeleteButton();
|
43 |
+
sgBackup.closeFreeBanner();
|
44 |
+
|
45 |
+
jQuery('span[data-toggle=tooltip]').tooltip();
|
46 |
+
|
47 |
+
jQuery('#sg-checkbox-select-all').on(
|
48 |
+
'change',
|
49 |
+
function () {
|
50 |
+
var checkAll = jQuery('#sg-checkbox-select-all');
|
51 |
+
jQuery('tbody input[type="checkbox"]:not(:disabled):visible').prop('checked', checkAll.prop('checked'));
|
52 |
+
sgBackup.toggleMultiDeleteButton();
|
53 |
+
}
|
54 |
+
);
|
55 |
+
|
56 |
+
jQuery('#sg-delete-multi-backups').on(
|
57 |
+
'click',
|
58 |
+
function () {
|
59 |
+
if (!confirm(BG_BACKUP_STRINGS_DEACTIVATE.areYouSure)) {
|
60 |
+
return false;
|
61 |
+
}
|
62 |
+
|
63 |
+
var backups = jQuery('tbody input[type="checkbox"]:checked');
|
64 |
+
var backupNames = [];
|
65 |
+
backups.each(
|
66 |
+
function (i) {
|
67 |
+
backupNames[i] = jQuery(this).val();
|
68 |
+
}
|
69 |
+
);
|
70 |
+
|
71 |
+
if (backupNames.length) {
|
72 |
+
sgBackup.deleteMultiBackups(backupNames);
|
73 |
+
}
|
74 |
+
}
|
75 |
+
);
|
76 |
+
|
77 |
+
jQuery('tbody input[type="checkbox"]').on(
|
78 |
+
'change',
|
79 |
+
function () {
|
80 |
+
var numberOfBackups = jQuery('tbody input[type="checkbox"]').length;
|
81 |
+
var numberOfChoosenBackups = sgBackup.getSelectedBackupsNumber();
|
82 |
+
var isCheked = jQuery(this).is(':checked');
|
83 |
+
sgBackup.toggleMultiDeleteButton();
|
84 |
+
|
85 |
+
if (!isCheked) {
|
86 |
+
jQuery('#sg-checkbox-select-all').prop('checked', false);
|
87 |
+
} else {
|
88 |
+
if (numberOfBackups === numberOfChoosenBackups) {
|
89 |
+
jQuery('#sg-checkbox-select-all').prop('checked', true);
|
90 |
+
}
|
91 |
+
}
|
92 |
+
}
|
93 |
+
);
|
94 |
+
|
95 |
+
var surveyClose = function (e) {
|
96 |
+
e.preventDefault();
|
97 |
+
|
98 |
+
jQuery('.bg-verify-user-info-container').slideUp();
|
99 |
+
jQuery('.bg-verify-user-info-overlay').hide();
|
100 |
+
|
101 |
+
var ajaxHandler = new sgRequestHandler('setUserInfoVerificationPopupState', {token: BG_BACKUP_STRINGS.nonce});
|
102 |
+
ajaxHandler.run();
|
103 |
+
};
|
104 |
+
|
105 |
+
jQuery('.bg-verify-user-info-overlay').bind('click', surveyClose);
|
106 |
+
|
107 |
+
jQuery('.bg-verify-user-info-cancel').click(surveyClose);
|
108 |
+
|
109 |
+
jQuery('#bg-verify-user-prioraty').on(
|
110 |
+
'change',
|
111 |
+
function () {
|
112 |
+
if (jQuery(this).val() === "other") {
|
113 |
+
jQuery('#bg-verify-user-priorati-custom').show();
|
114 |
+
} else {
|
115 |
+
jQuery('#bg-verify-user-priorati-custom').hide();
|
116 |
+
}
|
117 |
+
}
|
118 |
+
);
|
119 |
+
|
120 |
+
jQuery('.bg-verify-user-info-verify-email').click(
|
121 |
+
function (e) {
|
122 |
+
e.preventDefault();
|
123 |
+
|
124 |
+
var email = jQuery('#bg-verify-user-info-email').val();
|
125 |
+
var fname = jQuery('#bg-verify-user-info-name').val();
|
126 |
+
var lname = jQuery('#bg-verify-user-info-last-name').val();
|
127 |
+
var priority = jQuery('#bg-verify-user-prioraty').val();
|
128 |
+
|
129 |
+
var sendData = true;
|
130 |
+
jQuery('.bg-verify-user-info-error-message').hide();
|
131 |
+
|
132 |
+
if (priority === "other") {
|
133 |
+
priority = jQuery('#bg-verify-user-priorati-custom').val();
|
134 |
+
|
135 |
+
if (!priority) {
|
136 |
+
jQuery('#bg-verify-user-info-priority-custom-error').show()
|
137 |
+
sendData = false;
|
138 |
+
}
|
139 |
+
} else if (!priority) {
|
140 |
+
jQuery('#bg-verify-user-info-priority-error').show()
|
141 |
+
sendData = false;
|
142 |
+
}
|
143 |
+
|
144 |
+
if (fname === '') {
|
145 |
+
jQuery('#bg-verify-user-info-name-error').show();
|
146 |
+
sendData = false;
|
147 |
+
}
|
148 |
+
|
149 |
+
if (lname === '') {
|
150 |
+
jQuery('#bg-verify-user-info-last-name-error').show();
|
151 |
+
sendData = false;
|
152 |
+
}
|
153 |
+
|
154 |
+
if (!sgBackup.isValidEmailAddress(email)) {
|
155 |
+
jQuery('#bg-verify-user-info-email-error').show();
|
156 |
+
sendData = false;
|
157 |
+
}
|
158 |
+
|
159 |
+
if (sendData) {
|
160 |
+
jQuery('.bg-verify-user-info-container').slideUp();
|
161 |
+
jQuery('.bg-verify-user-info-overlay').hide();
|
162 |
+
var currentStatus = jQuery('.backup-send-usage-data-status').is(':checked');
|
163 |
+
|
164 |
+
var ajaxHandler = new sgRequestHandler(
|
165 |
+
'storeSubscriberInfo',
|
166 |
+
{
|
167 |
+
email: email,
|
168 |
+
fname: fname,
|
169 |
+
lname: lname,
|
170 |
+
priority: priority,
|
171 |
+
currentStatus: currentStatus,
|
172 |
+
token: BG_BACKUP_STRINGS.nonce
|
173 |
+
}
|
174 |
+
);
|
175 |
+
|
176 |
+
ajaxHandler.run();
|
177 |
+
}
|
178 |
+
}
|
179 |
+
);
|
180 |
+
}
|
181 |
+
);
|
182 |
+
|
183 |
+
sgBackup.isValidEmailAddress = function (emailAddress) {
|
184 |
+
var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,10}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
|
185 |
+
return pattern.test(emailAddress);
|
186 |
+
|
187 |
+
};
|
188 |
+
|
189 |
+
sgBackup.getSelectedBackupsNumber = function () {
|
190 |
+
return jQuery('tbody input[type="checkbox"]:checked').length
|
191 |
+
|
192 |
+
};
|
193 |
+
|
194 |
+
sgBackup.toggleMultiDeleteButton = function () {
|
195 |
+
var numberOfChoosenBackups = sgBackup.getSelectedBackupsNumber();
|
196 |
+
var target = jQuery('#sg-delete-multi-backups');
|
197 |
+
if (numberOfChoosenBackups > 0) {
|
198 |
+
target.removeAttr('disabled');
|
199 |
+
} else {
|
200 |
+
target.attr('disabled', 'disabled');
|
201 |
+
}
|
202 |
+
|
203 |
+
};
|
204 |
+
|
205 |
+
sgBackup.closeFreeBanner = function () {
|
206 |
+
jQuery('.sg-close-free-banner').bind(
|
207 |
+
'click',
|
208 |
+
function () {
|
209 |
+
var ajaxHandler = new sgRequestHandler(
|
210 |
+
'closeFreeBanner',
|
211 |
+
{
|
212 |
+
token: BG_BACKUP_STRINGS.nonce
|
213 |
+
}
|
214 |
+
);
|
215 |
+
ajaxHandler.callback = function (response, error) {
|
216 |
+
jQuery('#sg-banner').remove();
|
217 |
+
};
|
218 |
+
ajaxHandler.run();
|
219 |
+
}
|
220 |
+
);
|
221 |
+
};
|
222 |
+
|
223 |
+
sgBackup.deleteMultiBackups = function (backupNames) {
|
224 |
+
var ajaxHandler = new sgRequestHandler('deleteBackup', {backupName: backupNames, token: BG_BACKUP_STRINGS.nonce});
|
225 |
+
ajaxHandler.callback = function (response) {
|
226 |
+
location.reload();
|
227 |
+
};
|
228 |
+
ajaxHandler.run();
|
229 |
+
|
230 |
+
};
|
231 |
+
|
232 |
+
// SGManual Backup AJAX callback.
|
233 |
+
sgBackup.manualBackup = function (checkedStatus) {
|
234 |
+
var error = [];
|
235 |
+
// Validation.
|
236 |
+
jQuery('.alert').remove();
|
237 |
+
if (jQuery('input[type=radio][name=backupType]:checked').val() === 2) {
|
238 |
+
if (jQuery('.sg-custom-option:checked').length <= 0) {
|
239 |
+
error.push(BG_BACKUP_STRINGS.invalidBackupOption);
|
240 |
+
}
|
241 |
+
|
242 |
+
// Check if any file is selected.
|
243 |
+
if (jQuery('input[type=checkbox][name=backupFiles]:checked').length > 0) {
|
244 |
+
if (jQuery('.sg-custom-backup-files input:checkbox:checked').length <= 0) {
|
245 |
+
error.push(BG_BACKUP_STRINGS.invalidDirectorySelected);
|
246 |
+
}
|
247 |
+
}
|
248 |
+
}
|
249 |
+
|
250 |
+
// Check if any cloud is selected.
|
251 |
+
if (jQuery('input[type=checkbox][name=backupCloud]:checked').length > 0) {
|
252 |
+
if (jQuery('.sg-custom-backup-cloud input:checkbox:checked').length <= 0) {
|
253 |
+
error.push(BG_BACKUP_STRINGS.invalidCloud);
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
// If any error show it and abort ajax.
|
258 |
+
if (error.length) {
|
259 |
+
var sgAlert = sgBackup.alertGenerator(error, 'alert-danger');
|
260 |
+
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
261 |
+
return false;
|
262 |
+
}
|
263 |
+
|
264 |
+
if (!checkedStatus) {
|
265 |
+
sgBackup.checkBackupCreation();
|
266 |
+
}
|
267 |
+
|
268 |
+
// Before all disable buttons.
|
269 |
+
jQuery('.alert').remove();
|
270 |
+
jQuery('.modal-footer .btn-primary').attr('disabled', 'disabled');
|
271 |
+
jQuery('.modal-footer .btn-primary').html(BG_BACKUP_STRINGS.backupInProgress);
|
272 |
+
|
273 |
+
// Reset Status!
|
274 |
+
var backupName = jQuery("#sg-custom-backup-name").val();
|
275 |
+
var resetStatusHandler = new sgRequestHandler(
|
276 |
+
'resetStatus',
|
277 |
+
{
|
278 |
+
backupName: backupName,
|
279 |
+
token: BG_BACKUP_STRINGS.nonce
|
280 |
+
}
|
281 |
+
);
|
282 |
+
resetStatusHandler.callback = function (response, error) {
|
283 |
+
var manualBackupForm = jQuery('#manualBackup');
|
284 |
+
var manualBackupHandler = new sgRequestHandler('manualBackup', manualBackupForm.serialize() + '&token=' + BG_BACKUP_STRINGS.nonce);
|
285 |
+
|
286 |
+
manualBackupHandler.dataIsObject = false;
|
287 |
+
// If error!
|
288 |
+
if (typeof response.success === 'undefined') {
|
289 |
+
var sgAlert = sgBackup.alertGenerator(response, 'alert-danger');
|
290 |
+
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
291 |
+
|
292 |
+
if (response === 0 || response === false || response === '0' || response === 'false') {
|
293 |
+
response = BG_BACKUP_STRINGS.errorMessage;
|
294 |
+
}
|
295 |
+
|
296 |
+
sgBackup.restManualBackupModal();
|
297 |
+
return false;
|
298 |
+
}
|
299 |
+
|
300 |
+
if (checkedStatus) {
|
301 |
+
sgBackup.hideAndReload();
|
302 |
+
}
|
303 |
+
|
304 |
+
manualBackupHandler.run();
|
305 |
+
};
|
306 |
+
resetStatusHandler.run();
|
307 |
+
|
308 |
+
};
|
309 |
+
|
310 |
+
sgBackup.hideAndReload = function () {
|
311 |
+
jQuery('#sg-modal').modal('hide');
|
312 |
+
location.reload();
|
313 |
+
|
314 |
+
};
|
315 |
+
|
316 |
+
sgBackup.restManualBackupModal = function () {
|
317 |
+
jQuery('.modal-footer .btn-primary').removeAttr('disabled');
|
318 |
+
jQuery('.modal-footer .btn-primary').html('Backup');
|
319 |
+
|
320 |
+
};
|
321 |
+
|
322 |
+
sgBackup.cancelDonwload = function (name) {
|
323 |
+
var cancelDonwloadHandler = new sgRequestHandler('cancelDownload', {name: name, token: BG_BACKUP_STRINGS.nonce});
|
324 |
+
cancelDonwloadHandler.callback = function (response) {
|
325 |
+
sgBackup.hideAjaxSpinner();
|
326 |
+
location.reload();
|
327 |
+
};
|
328 |
+
cancelDonwloadHandler.run();
|
329 |
+
|
330 |
+
};
|
331 |
+
|
332 |
+
sgBackup.listStorage = function (importFrom) {
|
333 |
+
var listStorage = new sgRequestHandler('listStorage', {storage: importFrom, token: BG_BACKUP_STRINGS.nonce});
|
334 |
+
sgBackup.showAjaxSpinner('#sg-modal-inport-from');
|
335 |
+
jQuery('#sg-archive-list-table tbody').empty();
|
336 |
+
|
337 |
+
jQuery('#sg-modal').off('hide.bs.modal').on(
|
338 |
+
'hide.bs.modal',
|
339 |
+
function (e) {
|
340 |
+
if (SG_ACTIVE_DOWNLOAD_AJAX) {
|
341 |
+
if (!confirm(BG_BACKUP_STRINGS.confirm)) {
|
342 |
+
e.preventDefault();
|
343 |
+
return false;
|
344 |
+
}
|
345 |
+
|
346 |
+
var target = jQuery('input[name="select-archive-to-download"]:checked');
|
347 |
+
var name = target.attr('file-name');
|
348 |
+
|
349 |
+
sgBackup.cancelDonwload(name);
|
350 |
+
}
|
351 |
+
}
|
352 |
+
);
|
353 |
+
|
354 |
+
listStorage.callback = function (response, error) {
|
355 |
+
var cloudName = '';
|
356 |
+
var cloudId = parseInt(importFrom, 10);
|
357 |
+
|
358 |
+
switch (cloudId) {
|
359 |
+
case SG_STORAGE_AMAZON:
|
360 |
+
cloudName = "S3";
|
361 |
+
break;
|
362 |
+
|
363 |
+
case SG_STORAGE_DROPBOX:
|
364 |
+
cloudName = "Dropbox";
|
365 |
+
break;
|
366 |
+
|
367 |
+
case SG_STORAGE_GOOGLE_DRIVE:
|
368 |
+
cloudName = "Google Drive";
|
369 |
+
break;
|
370 |
+
|
371 |
+
case SG_STORAGE_FTP:
|
372 |
+
cloudName = "FTP";
|
373 |
+
break;
|
374 |
+
|
375 |
+
case SG_STORAGE_ONE_DRIVE:
|
376 |
+
cloudName = "OneDrive";
|
377 |
+
break;
|
378 |
+
|
379 |
+
case SG_STORAGE_P_CLOUD:
|
380 |
+
cloudName = "pCloud";
|
381 |
+
break;
|
382 |
+
|
383 |
+
case SG_STORAGE_BOX:
|
384 |
+
cloudName = "box.com";
|
385 |
+
break;
|
386 |
+
|
387 |
+
case SG_STORAGE_BACKUP_GUARD:
|
388 |
+
cloudName = "BackupGuard";
|
389 |
+
break;
|
390 |
+
|
391 |
+
default:
|
392 |
+
cloudName = '';
|
393 |
+
break;
|
394 |
+
}//end switch
|
395 |
+
|
396 |
+
jQuery('.modal-title').html('Import from ' + cloudName);
|
397 |
+
|
398 |
+
sgBackup.hideAjaxSpinner();
|
399 |
+
var content = '';
|
400 |
+
if ((typeof response.error !== "undefined") || response.length === 0 || response === undefined) {
|
401 |
+
content = '<tr><td colspan="4">' + BG_BACKUP_STRINGS.noBackupsAvailable + '</td></tr>';
|
402 |
+
} else {
|
403 |
+
jQuery.each(
|
404 |
+
response,
|
405 |
+
function (key, value) {
|
406 |
+
var backupId = 0;
|
407 |
+
|
408 |
+
if (typeof value.id !== 'undefined') {
|
409 |
+
backupId = value.id;
|
410 |
+
value.path = value.name;
|
411 |
+
}
|
412 |
+
|
413 |
+
content += '<tr>';
|
414 |
+
content += '<td class="file-select-radio"><input type="radio" file-name="' + value.name + '" name="select-archive-to-download" size="' + value.size + '" backup-id="' + backupId + '" storage="' + importFrom + '" value="' + value.path + '"></td>';
|
415 |
+
content += '<td>' + value.name + '</td>';
|
416 |
+
content += '<td>' + sgBackup.convertBytesToMegabytes(value.size) + '</td>';
|
417 |
+
content += '<td>' + value.date + '</td>';
|
418 |
+
content += '</tr>';
|
419 |
+
}
|
420 |
+
);
|
421 |
+
}//end if
|
422 |
+
|
423 |
+
jQuery('#sg-archive-list-table tbody').append(content);
|
424 |
+
sgBackup.toggleDownloadFromCloudPage();
|
425 |
+
};
|
426 |
+
|
427 |
+
listStorage.run();
|
428 |
+
|
429 |
+
};
|
430 |
+
|
431 |
+
|
432 |
+
sgBackup.convertBytesToMegabytes = function ($bytes) {
|
433 |
+
return ($bytes / (1024 * 1024)).toFixed(2);
|
434 |
+
|
435 |
+
};
|
436 |
+
|
437 |
+
// Init file upload!
|
438 |
+
sgBackup.initFileUpload = function () {
|
439 |
+
sgBackup.downloadFromPC();
|
440 |
+
|
441 |
+
jQuery('#uploadSgbpFile').click(
|
442 |
+
function () {
|
443 |
+
if (jQuery('#modal-import-3').is(":visible")) {
|
444 |
+
var target = jQuery('input[name="select-archive-to-download"]:checked');
|
445 |
+
var path = target.val();
|
446 |
+
var name = target.attr('file-name');
|
447 |
+
var storage = target.attr('storage');
|
448 |
+
var size = target.attr('size');
|
449 |
+
var backupId = target.attr('backup-id');
|
450 |
+
sgBackup.downloadFromCloud(path, name, storage, size, backupId);
|
451 |
+
}
|
452 |
+
}
|
453 |
+
);
|
454 |
+
|
455 |
+
};
|
456 |
+
|
457 |
+
sgBackup.nextPage = function () {
|
458 |
+
var importFrom = jQuery('input[name="storage-radio"]:checked').val();
|
459 |
+
jQuery('.alert').remove();
|
460 |
+
|
461 |
+
if (!importFrom) {
|
462 |
+
var alert = sgBackup.alertGenerator(BG_BACKUP_STRINGS.invalidImportOption, 'alert-danger');
|
463 |
+
jQuery('#sg-modal .modal-header').prepend(alert);
|
464 |
+
} else {
|
465 |
+
if (importFrom === 'local-pc') {
|
466 |
+
sgBackup.toggleDownloadFromPCPage();
|
467 |
+
} else {
|
468 |
+
var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: "DOWNLOAD_FROM_CLOUD"});
|
469 |
+
isFeatureAvailable.callback = function (response) {
|
470 |
+
if (typeof response.success !== 'undefined') {
|
471 |
+
sgBackup.listStorage(importFrom);
|
472 |
+
} else {
|
473 |
+
var alert = sgBackup.alertGenerator(response.error, 'alert-danger');
|
474 |
+
jQuery('#sg-modal .modal-header').prepend(alert);
|
475 |
+
}
|
476 |
+
};
|
477 |
+
|
478 |
+
isFeatureAvailable.run();
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
};
|
483 |
+
|
484 |
+
sgBackup.previousPage = function () {
|
485 |
+
if (jQuery('#modal-import-2').is(":visible")) {
|
486 |
+
jQuery('#modal-import-2').hide();
|
487 |
+
} else {
|
488 |
+
jQuery('#modal-import-3').hide();
|
489 |
+
}
|
490 |
+
|
491 |
+
sgBackup.toggleNavigationButtons();
|
492 |
+
|
493 |
+
jQuery('#modal-import-1').show();
|
494 |
+
jQuery('#uploadSgbpFile').hide();
|
495 |
+
|
496 |
+
jQuery('.modal-title').html('Import from');
|
497 |
+
|
498 |
+
};
|
499 |
+
|
500 |
+
sgBackup.toggleNavigationButtons = function () {
|
501 |
+
jQuery('#switch-modal-import-pages-next').toggle();
|
502 |
+
jQuery('#switch-modal-import-pages-back').toggle();
|
503 |
+
|
504 |
+
};
|
505 |
+
|
506 |
+
sgBackup.toggleDownloadFromPCPage = function () {
|
507 |
+
sgBackup.toggleNavigationButtons();
|
508 |
+
jQuery('#modal-import-1').toggle();
|
509 |
+
jQuery('#modal-import-2').toggle();
|
510 |
+
jQuery('#uploadSgbpFile').toggle();
|
511 |
+
|
512 |
+
};
|
513 |
+
|
514 |
+
sgBackup.toggleDownloadFromCloudPage = function () {
|
515 |
+
sgBackup.toggleNavigationButtons();
|
516 |
+
jQuery('#modal-import-1').toggle();
|
517 |
+
jQuery('#modal-import-3').toggle();
|
518 |
+
jQuery('#uploadSgbpFile').toggle();
|
519 |
+
|
520 |
+
};
|
521 |
+
|
522 |
+
sgBackup.downloadFromCloud = function (path, name, storage, size, backupId) {
|
523 |
+
sgBackup.showAjaxSpinner('.modal-dialog');
|
524 |
+
var error = [];
|
525 |
+
if (!path) {
|
526 |
+
error.push(BG_BACKUP_STRINGS.invalidDownloadFile);
|
527 |
+
}
|
528 |
+
|
529 |
+
jQuery('.alert').remove();
|
530 |
+
|
531 |
+
if (error.length) {
|
532 |
+
sgBackup.hideAjaxSpinner();
|
533 |
+
var sgAlert = sgBackup.alertGenerator(error, 'alert-danger');
|
534 |
+
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
535 |
+
return false;
|
536 |
+
}
|
537 |
+
|
538 |
+
var downloadFromCloudHandler = new sgRequestHandler(
|
539 |
+
'downloadFromCloud',
|
540 |
+
{
|
541 |
+
path: path,
|
542 |
+
storage: storage,
|
543 |
+
size: size,
|
544 |
+
backupId: backupId,
|
545 |
+
token: BG_BACKUP_STRINGS.nonce
|
546 |
+
}
|
547 |
+
);
|
548 |
+
|
549 |
+
jQuery('#switch-modal-import-pages-back').hide();
|
550 |
+
jQuery('#uploadSgbpFile').attr('disabled', 'disabled');
|
551 |
+
|
552 |
+
downloadFromCloudHandler.callback = function (response, error) {
|
553 |
+
if (typeof response.success !== 'undefined') {
|
554 |
+
location.reload();
|
555 |
+
} else if (typeof response.error !== 'undefined') {
|
556 |
+
sgBackup.hideAjaxSpinner();
|
557 |
+
jQuery('.alert').remove();
|
558 |
+
|
559 |
+
clearTimeout(SG_DOWNLOAD_PROGRESS);
|
560 |
+
|
561 |
+
jQuery('#uploadSgbpFile').html(BG_BACKUP_STRINGS.import);
|
562 |
+
|
563 |
+
var sgAlert = sgBackup.alertGenerator(response.error, 'alert-danger');
|
564 |
+
|
565 |
+
jQuery('#uploadSgbpFile').attr('disabled', false);
|
566 |
+
jQuery('#switch-modal-import-pages-back').toggle();
|
567 |
+
jQuery('#sg-modal .modal-header').prepend(sgAlert);
|
568 |
+
SG_ACTIVE_DOWNLOAD_AJAX = false;
|
569 |
+
|
570 |
+
return false;
|
571 |
+
}
|
572 |
+
};
|
573 |
+
|
574 |
+
SG_ACTIVE_DOWNLOAD_AJAX = true;
|
575 |
+
downloadFromCloudHandler.run();
|
576 |
+
sgBackup.fileDownloadProgress(name, size);
|
577 |
+
|
578 |
+
};
|
579 |
+
|
580 |
+
sgBackup.downloadFromPC = function () {
|
581 |
+
var sgData = null;
|
582 |
+
jQuery('#sg-modal').off('hide.bs.modal').on(
|
583 |
+
'hide.bs.modal',
|
584 |
+
function (e) {
|
585 |
+
if (SG_ACTIVE_DOWNLOAD_AJAX) {
|
586 |
+
if (!confirm(BG_BACKUP_STRINGS.confirm)) {
|
587 |
+
e.preventDefault();
|
588 |
+
return false;
|
589 |
+
}
|
590 |
+
|
591 |
+
sgData.abort();
|
592 |
+
sgBackup.cancelDonwload(sgData.files[0].name);
|
593 |
+
}
|
594 |
+
}
|
595 |
+
);
|
596 |
+
|
597 |
+
jQuery('.sg-backup-upload-input').fileupload(
|
598 |
+
{
|
599 |
+
dataType: 'json',
|
600 |
+
maxChunkSize: 2000000,
|
601 |
+
add: function (e, data) {
|
602 |
+
if (data.originalFiles.length) {
|
603 |
+
var fileName = data.originalFiles[0].name;
|
604 |
+
jQuery('#sg-import-file-name').val(fileName);
|
605 |
+
}
|
606 |
+
|
607 |
+
jQuery('#uploadSgbpFile').click(
|
608 |
+
function () {
|
609 |
+
if (jQuery('#modal-import-2').is(":visible")) {
|
610 |
+
sgData = data;
|
611 |
+
SG_ACTIVE_DOWNLOAD_AJAX = true;
|
612 |
+
jQuery('#uploadSgbpFile').attr('disabled', 'disabled');
|
613 |
+
jQuery('#switch-modal-import-pages-back').hide();
|
614 |
+
jQuery('#uploadSgbpFile').html(BG_BACKUP_STRINGS.importInProgress);
|
615 |
+
data.submit();
|
616 |
+
}
|
617 |
+
}
|
618 |
+
);
|
619 |
+
},
|
620 |
+
done: function (e, data) {
|
621 |
+
location.reload();
|
622 |
+
},
|
623 |
+
progress: function (e, data) {
|
624 |
+
var progress = parseInt(((data.loaded / data.total) * 100), 10);
|
625 |
+
jQuery('#uploadSgbpFile').html('Importing (' + Math.round(progress) + '%)');
|
626 |
+
}
|
627 |
+
}
|
628 |
+
).on(
|
629 |
+
'fileuploadfail',
|
630 |
+
function (e, data) {
|
631 |
+
var alert = sgBackup.alertGenerator(BG_BACKUP_STRINGS.fileUploadFailed, 'alert-danger');
|
632 |
+
jQuery('#sg-modal .modal-header').prepend(alert);
|
633 |
+
}
|
634 |
+
);
|
635 |
+
|
636 |
+
};
|
637 |
+
|
638 |
+
sgBackup.fileDownloadProgress = function (file, size) {
|
639 |
+
var getFileDownloadProgress = new sgRequestHandler(
|
640 |
+
'getFileDownloadProgress',
|
641 |
+
{
|
642 |
+
file: file,
|
643 |
+
size: size,
|
644 |
+
token: BG_BACKUP_STRINGS.nonce
|
645 |
+
}
|
646 |
+
);
|
647 |
+
|
648 |
+
getFileDownloadProgress.callback = function (response) {
|
649 |
+
if (response.progress === 100) {
|
650 |
+
location.reload();
|
651 |
+
}
|
652 |
+
|
653 |
+
if (typeof response.progress !== 'undefined') {
|
654 |
+
jQuery('#uploadSgbpFile').html('Importing (' + Math.round(response.progress) + '%)');
|
655 |
+
SG_DOWNLOAD_PROGRESS = setTimeout(
|
656 |
+
function () {
|
657 |
+
getFileDownloadProgress.run();
|
658 |
+
},
|
659 |
+
SG_AJAX_REQUEST_FREQUENCY
|
660 |
+
);
|
661 |
+
}
|
662 |
+
};
|
663 |
+
|
664 |
+
getFileDownloadProgress.run();
|
665 |
+
|
666 |
+
};
|
667 |
+
|
668 |
+
sgBackup.fileUploadProgress = function (e) {
|
669 |
+
if (e.lengthComputable) {
|
670 |
+
jQuery('#uploadSgbpFile').html('Importing (' + Math.round((e.loaded * 100.0) / e.total) + '%)');
|
671 |
+
}
|
672 |
+
|
673 |
+
};
|
674 |
+
|
675 |
+
sgBackup.checkBackupCreation = function () {
|
676 |
+
jQuery('#manualBackup .btn-success').attr('disabled', true);
|
677 |
+
var sgBackupCreationHandler = new sgRequestHandler('checkBackupCreation', {token: BG_BACKUP_STRINGS.nonce});
|
678 |
+
sgBackupCreationHandler.dataType = 'html';
|
679 |
+
sgBackupCreationHandler.callback = function (response) {
|
680 |
+
var hideAndReload = function () {
|
681 |
+
jQuery('#sg-modal').modal('hide');
|
682 |
+
location.reload();
|
683 |
+
};
|
684 |
+
if (response.length) {
|
685 |
+
var result = jQuery.parseJSON(response);
|
686 |
+
if (result && result.status === 'cleaned') {
|
687 |
+
sgBackup.manualBackup('cleaned');
|
688 |
+
} else {
|
689 |
+
hideAndReload();
|
690 |
+
}
|
691 |
+
} else {
|
692 |
+
hideAndReload();
|
693 |
+
}
|
694 |
+
};
|
695 |
+
sgBackupCreationHandler.run();
|
696 |
+
|
697 |
+
};
|
698 |
+
|
699 |
+
sgBackup.checkRestoreCreation = function () {
|
700 |
+
jQuery('#manualBackup .btn-success').attr('disabled', true);
|
701 |
+
var sgRestoreCreationHandler = new sgRequestHandler('checkRestoreCreation', {token: BG_BACKUP_STRINGS.nonce});
|
702 |
+
sgRestoreCreationHandler.callback = function (response) {
|
703 |
+
if (response.status === 0 && response.external_enabled === 1) {
|
704 |
+
location.href = response.external_url;
|
705 |
+
} else if (response.status === 'cleaned') {
|
706 |
+
jQuery('#manualBackup .btn-success').click();
|
707 |
+
} else {
|
708 |
+
location.reload();
|
709 |
+
}
|
710 |
+
};
|
711 |
+
sgRestoreCreationHandler.run();
|
712 |
+
|
713 |
+
};
|
714 |
+
|
715 |
+
sgBackup.initManulBackupRadioInputs = function () {
|
716 |
+
jQuery('input[type=radio][name=backupType]').off('change').on(
|
717 |
+
'change',
|
718 |
+
function () {
|
719 |
+
jQuery('.sg-custom-backup').fadeToggle();
|
720 |
+
}
|
721 |
+
);
|
722 |
+
jQuery('input[type=radio][name=restoreType]').off('change').on(
|
723 |
+
'change',
|
724 |
+
function () {
|
725 |
+
if (jQuery('input[type=radio][name=restoreType]:checked').val() === "files") {
|
726 |
+
jQuery('.sg-restore-files-options').fadeIn();
|
727 |
+
} else {
|
728 |
+
jQuery('.sg-restore-files-options').fadeOut();
|
729 |
+
}
|
730 |
+
}
|
731 |
+
);
|
732 |
+
|
733 |
+
jQuery('input[type=radio][name=restoreFilesType]').off('change').on(
|
734 |
+
'change',
|
735 |
+
function () {
|
736 |
+
jQuery('.sg-file-selective-restore').fadeToggle();
|
737 |
+
}
|
738 |
+
);
|
739 |
+
|
740 |
+
jQuery('input[type=checkbox][name=backupFiles], input[type=checkbox][name=backupDatabase], input[type=checkbox][name=backupCloud]').off('change').on(
|
741 |
+
'change',
|
742 |
+
function () {
|
743 |
+
var sgCheckBoxWrapper = jQuery(this).closest('.checkbox').find('.sg-checkbox');
|
744 |
+
sgCheckBoxWrapper.fadeToggle();
|
745 |
+
if (jQuery(this).attr('name') === 'backupFiles') {
|
746 |
+
sgCheckBoxWrapper.find('input[type=checkbox]').attr('checked', 'checked');
|
747 |
+
}
|
748 |
+
}
|
749 |
+
);
|
750 |
+
jQuery('input[type=radio][name=backupDBType]').off('change').on(
|
751 |
+
'change',
|
752 |
+
function () {
|
753 |
+
var sgCheckBoxWrapper = jQuery(this).closest('.checkbox').find('.sg-custom-backup-tables');
|
754 |
+
if (jQuery('input[type=radio][name=backupDBType]:checked').val() === '2') {
|
755 |
+
sgCheckBoxWrapper.find('input[type=checkbox]').not("[disabled]").prop('checked', true)
|
756 |
+
sgCheckBoxWrapper.fadeIn();
|
757 |
+
} else {
|
758 |
+
sgCheckBoxWrapper.fadeOut();
|
759 |
+
sgCheckBoxWrapper.find('input[type=checkbox][current="true"]').not("[disabled]").prop('checked', true)
|
760 |
+
sgCheckBoxWrapper.find('input[type=checkbox][current="false"]').prop('checked', false)
|
761 |
+
}
|
762 |
+
}
|
763 |
+
)
|
764 |
+
|
765 |
+
};
|
766 |
+
|
767 |
+
sgBackup.initImportTooltips = function () {
|
768 |
+
jQuery('a[data-toggle=tooltip]').tooltip();
|
769 |
+
|
770 |
+
};
|
771 |
+
|
772 |
+
sgBackup.initManualBackupTooltips = function () {
|
773 |
+
jQuery('[for=cloud-ftp]').tooltip();
|
774 |
+
jQuery('[for=cloud-dropbox]').tooltip();
|
775 |
+
jQuery('[for=cloud-gdrive]').tooltip();
|
776 |
+
jQuery('[for=cloud-one-drive]').tooltip();
|
777 |
+
jQuery('[for=cloud-p-cloud]').tooltip();
|
778 |
+
jQuery('[for=cloud-box]').tooltip();
|
779 |
+
jQuery('[for=cloud-amazon]').tooltip();
|
780 |
+
jQuery('[for=cloud-backup-guard]').tooltip();
|
781 |
+
|
782 |
+
jQuery('a[data-toggle=tooltip]').tooltip();
|
783 |
+
|
784 |
+
};
|
785 |
+
|
786 |
+
sgBackup.startRestore = function (bname) {
|
787 |
+
var checkIsItMigration = new sgRequestHandler('checkFreeMigration', {bname: bname, token: BG_BACKUP_STRINGS.nonce});
|
788 |
+
|
789 |
+
checkIsItMigration.callback = function (response) {
|
790 |
+
if (response) {
|
791 |
+
jQuery('.modal-body.sg-modal-body').html(response);
|
792 |
+
return false;
|
793 |
+
}
|
794 |
+
|
795 |
+
sgBackup.startRestoreAction(bname);
|
796 |
+
};
|
797 |
+
checkIsItMigration.dataType = '';
|
798 |
+
checkIsItMigration.run();
|
799 |
+
|
800 |
+
};
|
801 |
+
|
802 |
+
sgBackup.startRestoreAction = function (bname) {
|
803 |
+
jQuery('.alert').remove();
|
804 |
+
var type = jQuery('input[type=radio][name=restoreType]:checked').val();
|
805 |
+
var restoreFilesType = jQuery('input[type=radio][name=restoreFilesType]:checked').val() || "0";
|
806 |
+
|
807 |
+
if (restoreFilesType === "0") {
|
808 |
+
var paths = "/";
|
809 |
+
} else {
|
810 |
+
var paths = jQuery("#fileSystemTreeContainer").jstree("get_selected");
|
811 |
+
}
|
812 |
+
|
813 |
+
var checkPHPVersionCompatibility = new sgRequestHandler(
|
814 |
+
'checkPHPVersionCompatibility',
|
815 |
+
{
|
816 |
+
bname: bname,
|
817 |
+
token: BG_BACKUP_STRINGS.nonce
|
818 |
+
}
|
819 |
+
);
|
820 |
+
|
821 |
+
checkPHPVersionCompatibility.callback = function (response) {
|
822 |
+
if (typeof response.error !== 'undefined') {
|
823 |
+
alert(response.error);
|
824 |
+
return false;
|
825 |
+
} else if (typeof response.warning !== 'undefined') {
|
826 |
+
if (!confirm(response.warning)) {
|
827 |
+
return false;
|
828 |
+
}
|
829 |
+
}
|
830 |
+
|
831 |
+
sgBackup.showAjaxSpinner('#sg-content-wrapper');
|
832 |
+
var resetStatusHandler = new sgRequestHandler('resetStatus', {token: BG_BACKUP_STRINGS.nonce});
|
833 |
+
resetStatusHandler.callback = function (response) {
|
834 |
+
// If error!
|
835 |
+
if (typeof response.success === 'undefined') {
|
836 |
+
alert(response);
|
837 |
+
location.reload();
|
838 |
+
return false;
|
839 |
+
}
|
840 |
+
|
841 |
+
var restoreHandler = new sgRequestHandler('restore', {bname: bname, type: type, paths: paths});
|
842 |
+
restoreHandler.run();
|
843 |
+
sgBackup.checkRestoreCreation();
|
844 |
+
};
|
845 |
+
resetStatusHandler.run();
|
846 |
+
};
|
847 |
+
|
848 |
+
if (type === "files" && restoreFilesType === 1) {
|
849 |
+
var isFeatureAvailable = new sgRequestHandler('isFeatureAvailable', {sgFeature: "SLECTIVE_RESTORE"});
|
850 |
+
isFeatureAvailable.callback = function (response) {
|
851 |
+
if (typeof response.success !== 'undefined') {
|
852 |
+
checkPHPVersionCompatibility.run();
|
853 |
+
} else {
|
854 |
+
var alert = sgBackup.alertGenerator(response.error, 'alert-warning');
|
855 |
+
jQuery('#sg-modal .modal-header').prepend(alert);
|
856 |
+
return false;
|
857 |
+
}
|
858 |
+
};
|
859 |
+
|
860 |
+
isFeatureAvailable.run();
|
861 |
+
} else {
|
862 |
+
checkPHPVersionCompatibility.run();
|
863 |
+
}
|
864 |
+
|
865 |
+
};
|
866 |
+
|
867 |
+
sgBackup.initActiveAction = function () {
|
868 |
+
if (jQuery('.sg-active-action-id').length <= 0) {
|
869 |
+
return;
|
870 |
+
}
|
871 |
+
|
872 |
+
var activeActionsIds = [];
|
873 |
+
jQuery('.sg-active-action-id').each(
|
874 |
+
function () {
|
875 |
+
activeActionsIds.push(jQuery(this).val());
|
876 |
+
}
|
877 |
+
);
|
878 |
+
|
879 |
+
// Cancel Button!
|
880 |
+
jQuery('.sg-cancel-backup').click(
|
881 |
+
function () {
|
882 |
+
if (confirm('Are you sure?')) {
|
883 |
+
var actionId = jQuery(this).attr('sg-data-backup-id');
|
884 |
+
var sgCancelHandler = new sgRequestHandler(
|
885 |
+
'cancelBackup',
|
886 |
+
{
|
887 |
+
actionId: actionId,
|
888 |
+
token: BG_BACKUP_STRINGS.nonce
|
889 |
+
}
|
890 |
+
);
|
891 |
+
sgCancelHandler.run();
|
892 |
+
}
|
893 |
+
}
|
894 |
+
);
|
895 |
+
|
896 |
+
var activeActionsIdsLength = activeActionsIds.length;
|
897 |
+
for (var i = 0; i < activeActionsIdsLength; i++) {
|
898 |
+
// GetProgress!
|
899 |
+
sgBackup.getActionProgress(activeActionsIds[i]);
|
900 |
+
}
|
901 |
+
|
902 |
+
};
|
903 |
+
|
904 |
+
sgBackup.getActionProgress = function (actionId) {
|
905 |
+
var progressBar = jQuery('.sg-progress .progress-bar', '#sg-status-tabe-data-' + actionId);
|
906 |
+
|
907 |
+
var sgActionHandler = new sgRequestHandler('getAction', {actionId: actionId, token: BG_BACKUP_STRINGS.nonce});
|
908 |
+
// Init tooltip!
|
909 |
+
var statusTooltip = jQuery('#sg-status-tabe-data-' + actionId + '[data-toggle=tooltip]').tooltip();
|
910 |
+
|
911 |
+
sgActionHandler.callback = function (response) {
|
912 |
+
if (response) {
|
913 |
+
sgBackup.disableUi();
|
914 |
+
var progressInPercents = response.progress + '%';
|
915 |
+
progressBar.width(progressInPercents);
|
916 |
+
sgBackup.statusUpdate(statusTooltip, response, progressInPercents);
|
917 |
+
setTimeout(
|
918 |
+
function () {
|
919 |
+
sgActionHandler.run();
|
920 |
+
},
|
921 |
+
SG_CHECK_ACTION_STATUS_REQUEST_FREQUENCY
|
922 |
+
);
|
923 |
+
} else {
|
924 |
+
jQuery('[class*=sg-status]').addClass('active');
|
925 |
+
jQuery('.sg-progress').remove();
|
926 |
+
jQuery('.sg-active-action-id').remove();
|
927 |
+
location.reload();
|
928 |
+
}
|
929 |
+
};
|
930 |
+
sgActionHandler.run();
|
931 |
+
|
932 |
+
};
|
933 |
+
|
934 |
+
sgBackup.statusUpdate = function (tooltip, response, progressInPercents) {
|
935 |
+
var tooltipText = '';
|
936 |
+
if (response.type === '1') {
|
937 |
+
var currentAction = 'Backup';
|
938 |
+
if (response.status === '1') {
|
939 |
+
tooltipText = currentAction + ' database - ' + progressInPercents;
|
940 |
+
} else if (response.status === '2') {
|
941 |
+
tooltipText = currentAction + ' files - ' + progressInPercents;
|
942 |
+
}
|
943 |
+
|
944 |
+
jQuery('.sg-status-' + response.status).prevAll('[class*=sg-status]').addClass('active');
|
945 |
+
} else if (response.type === '2') {
|
946 |
+
var currentAction = 'Restore';
|
947 |
+
if (response.status === '1') {
|
948 |
+
tooltipText = currentAction + ' database - ' + progressInPercents;
|
949 |
+
} else if (response.status === '2') {
|
950 |
+
tooltipText = currentAction + ' files - ' + progressInPercents;
|
951 |
+
}
|
952 |
+
|
953 |
+
jQuery('.sg-status-' + response.type + response.status).prevAll('[class*=sg-status]').addClass('active');
|
954 |
+
} else if (response.type === '3') {
|
955 |
+
var cloudIcon = jQuery('.sg-status-' + response.type + response.subtype);
|
956 |
+
if (response.subtype === SG_STORAGE_FTP) {
|
957 |
+
tooltipText = 'Uploading to FTP - ' + progressInPercents;
|
958 |
+
} else if (response.subtype === SG_STORAGE_DROPBOX) {
|
959 |
+
tooltipText = 'Uploading to Dropbox - ' + progressInPercents;
|
960 |
+
} else if (response.subtype === SG_STORAGE_GOOGLE_DRIVE) {
|
961 |
+
tooltipText = 'Uploading to Google Drive - ' + progressInPercents;
|
962 |
+
} else if (response.subtype === SG_STORAGE_AMAZON) {
|
963 |
+
tooltipText = 'Uploading to Amazon S3 - ' + progressInPercents;
|
964 |
+
} else if (response.subtype === SG_STORAGE_ONE_DRIVE) {
|
965 |
+
tooltipText = 'Uploading to OneDrive - ' + progressInPercents;
|
966 |
+
} else if (response.subtype === SG_STORAGE_P_CLOUD) {
|
967 |
+
tooltipText = 'Uploading to pCloud - ' + progressInPercents;
|
968 |
+
} else if (response.subtype === SG_STORAGE_BOX) {
|
969 |
+
tooltipText = 'Uploading to box.com - ' + progressInPercents;
|
970 |
+
} else if (response.subtype === SG_STORAGE_BACKUP_GUARD) {
|
971 |
+
tooltipText = 'Uploading to BackupGuard - ' + progressInPercents;
|
972 |
+
}
|
973 |
+
|
974 |
+
cloudIcon.prevAll('[class*=sg-status]').addClass('active');
|
975 |
+
}//end if
|
976 |
+
|
977 |
+
tooltip.attr('data-original-title', tooltipText);
|
978 |
+
|
979 |
+
};
|
980 |
+
|
981 |
+
sgBackup.disableUi = function () {
|
982 |
+
jQuery('#sg-manual-backup').attr('disabled', 'disabled');
|
983 |
+
jQuery('#sg-backup-with-migration').attr('disabled', 'disabled');
|
984 |
+
jQuery('#sg-import').attr('disabled', 'disabled');
|
985 |
+
jQuery('.sg-restore').attr('disabled', 'disabled');
|
986 |
+
jQuery('.sg-restore-button').attr('disabled', 'disabled');
|
987 |
+
|
988 |
+
};
|
989 |
+
|
990 |
+
sgBackup.enableUi = function () {
|
991 |
+
jQuery('#sg-manual-backup').removeAttr('disabled');
|
992 |
+
jQuery('#sg-backup-with-migration').removeAttr('disabled');
|
993 |
+
jQuery('#sg-import').removeAttr('disabled');
|
994 |
+
jQuery('.sg-restore').removeAttr('disabled');
|
995 |
+
jQuery('.sg-restore-button').removeAttr('disabled');
|
996 |
+
|
997 |
+
};
|
998 |
+
|
999 |
+
sgBackup.initBackupDeletion = function () {
|
1000 |
+
jQuery('.sg-remove-backup').click(
|
1001 |
+
function () {
|
1002 |
+
var btn = jQuery(this),
|
1003 |
+
url = btn.attr('data-remote'),
|
1004 |
+
backupName = [btn.attr('data-sgbackup-name')];
|
1005 |
+
if (confirm('Are you sure?')) {
|
1006 |
+
var ajaxHandler = new sgRequestHandler(url, {backupName: backupName, token: BG_BACKUP_STRINGS.nonce});
|
1007 |
+
ajaxHandler.callback = function (response) {
|
1008 |
+
location.reload();
|
1009 |
+
};
|
1010 |
+
ajaxHandler.run();
|
1011 |
+
}
|
1012 |
+
}
|
1013 |
+
);
|
1014 |
+
|
1015 |
+
};
|
1016 |
+
|
1017 |
+
/* phpcs:enable */
|