-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinit_global.php
230 lines (180 loc) · 10.1 KB
/
init_global.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php // This code runs everywhere. pb_backupbuddy::$options preloaded.
/***** BEGIN Solid Backups Stash Live Init *****/
foreach( pb_backupbuddy::$options['remote_destinations'] as $destination ) { // See if we have Live activated.
if ( 'live' == $destination['type'] ) {
include( 'destinations/live/live_continuous.php' );
backupbuddy_live_continuous::init();
break;
}
}
/***** END Solid Backups Stash Live Init *****/
include( 'classes/constants.php' );
include( 'classes/api.php' );
require_once( pb_backupbuddy::plugin_path() . '/vendor/woocommerce/action-scheduler/action-scheduler.php' );
// Handle API calls if backupbuddy_api_key is posted. If anything fails security checks pretend nothing at all happened.
if ( isset( $_SERVER['HTTP_BACKUPBUDDY_API_KEY' ] ) && ( '' != $_SERVER['HTTP_BACKUPBUDDY_API_KEY' ] ) ) { // Although the header is passed with dashes PHP changes these to underscores after they are received. However, if you send the header with underscores it will silently be dropped.
if ( pb_backupbuddy::full_logging() ) {
pb_backupbuddy::status( 'details', 'Deployment incoming call: HTTP_BACKUPBUDDY-API-KEY header set' );
}
if ( defined( 'BACKUPBUDDY_API_ENABLE' ) && ( TRUE == BACKUPBUDDY_API_ENABLE ) ) {
if ( pb_backupbuddy::full_logging() ) {
pb_backupbuddy::status( 'details', 'Deployment incoming call: API enabled via wp-config.' );
}
if ( ( isset( pb_backupbuddy::$options['remote_api'] ) ) && ( count( pb_backupbuddy::$options['remote_api']['keys'] ) > 0 ) ) { // Verify API is enabled. && defined( 'BACKUPBUDDY_API_SALT' ) && ( 'CHANGEME' != BACKUPBUDDY_API_SALT ) && ( strlen( BACKUPBUDDY_API_SALT ) >= 5 )
if ( pb_backupbuddy::full_logging() ) {
pb_backupbuddy::status( 'details', 'Deployment incoming call: API keys are defined / turned on.' );
}
include( 'classes/remote_api.php' );
pb_backupbuddy::set_status_serial( 'remote_api' ); // Log all incoming remote API calls.
backupbuddy_remote_api::localCall( $keySet = true );
die();
}
}
}
// Make localization happen.
if ( ( ! defined( 'PB_STANDALONE' ) ) && ( '1' != pb_backupbuddy::$options['disable_localization'] ) ) {
load_plugin_textdomain( 'it-l10n-backupbuddy', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
}
/********** ACTIONS (global) **********/
/**
* Iterating edits since last updates dashboard widget.
*/
// Post Tracking.
pb_backupbuddy::add_action( array( 'save_post', 'save_post_iterate_edits_since_last' ), 10, 3 );
pb_backupbuddy::add_action( array( 'post_updated', 'post_updated_iterate_edits_since_last' ), 10, 3 );
pb_backupbuddy::add_action( array( 'wp_insert_post', 'insert_post_iterate_edits_since_last' ), 10, 3 );
pb_backupbuddy::add_action( array( 'wp_trash_post', 'trash_post_iterate_edits_since_last' ), 10 );
// Option Tracking.
pb_backupbuddy::add_action( array( 'update_option', 'update_option_iterate_edits_since_last' ), 10, 3 );
pb_backupbuddy::add_action( array( 'delete_option', 'delete_option_iterate_edits_since_last' ), 10 );
// Plugin Tracking.
pb_backupbuddy::add_action( array( 'activated_plugin', 'activate_plugin_iterate_edits_since_last' ), 10, 2 );
pb_backupbuddy::add_action( array( 'deactivated_plugin', 'deactivate_plugin_iterate_edits_since_last' ), 10, 2 );
pb_backupbuddy::add_action( array( 'upgrader_process_complete', 'update_plugin_iterate_edits_since_last' ), 10, 2 );
/********** AJAX (global) **********/
/********** CRON (global) **********/
pb_backupbuddy::add_cron( 'cron', backupbuddy_constants::DEFAULT_CRON_PRIORITY, 3 ); // Master CRON handler as of v6.4.0.9. Pass all cron functionality through this. Params: cron_method, args, reschedulecount(optional).
/********** FILTERS (global) **********/
pb_backupbuddy::add_filter( 'cron_schedules' ); // Add schedule periods such as bimonthly, etc into cron. By default passes 1 param at priority 10.
if ( '1' == pb_backupbuddy::$options['disable_https_local_ssl_verify'] ) {
add_filter( 'https_local_ssl_verify', '__return_false', 100 );
}
/********** OTHER (global) **********/
// WP-CLI tool support for command line access to BackupBuddy. http://wp-cli.org/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
include( pb_backupbuddy::plugin_path() . '/classes/wp-cli.php' );
}
/*
add_filter( 'cron_request', 'backupbuddy_spoof_cron_agent' );
function backupbuddy_spoof_cron_agent( $cron ) {
$cron['args']['user-agent'] = 'Mozilla';
return $cron;
}
*/
// Jetpack Security Report. As of Jan 2015.
function backupbuddy_jetpack_security_report() {
$maxTimeWithoutBackupBeforeWarn = 60*60*24*32; // After this amount of time (default 32 days) we will warn the user that they have not completed a backup in too long.
// Default arguments.
$args = array(
'status' => 'ok',
'message' => '',
);
// Determine last completed backup.
$lastRun = pb_backupbuddy::$options['last_backup_finish'];
if ( 0 === $lastRun ) { // never made a backup.
$args['status'] = 'warning';
$args['message'] = __( 'You have not completed your first Solid Backups backup.', 'it-l10n-backupbuddy' );
} else { // have made a backup.
$args['last'] = $lastRun;
// If the last backup was too long ago then change status to warning. Only calculate a backup was ever made.
if ( ( time() - $lastRun ) > $maxTimeWithoutBackupBeforeWarn ) {
$args['status'] = 'warning';
$args['message'] .= ' ' . __( 'It has been over a month since your last Solid Backups backup completed.', 'it-l10n-backupbuddy' );
}
}
// Determine next run.
$nextRun = 0;
foreach ( pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule ) { // Find soonest schedule to run next.
$thisRun = backupbuddy_core::next_scheduled( 'run_scheduled_backup', array( (int)$schedule_id ) );
if ( false !== $thisRun ) {
if ( ( 0 === $nextRun ) || ( $thisRun < $nextRun ) ) { // Set next run if $thisRun is going to run sooner than schedule in $nextRun.
$nextRun = $thisRun;
}
}
}
if ( 0 === $nextRun ) {
$args['status'] = 'warning';
$args['message'] .= ' ' . __( 'You do not currently have any backup schedules in Solid Backups.', 'it-l10n-backupbuddy' );
} else {
$args['next'] = $nextRun;
}
// Cleanup.
$args['message'] = trim( $args['message'] );
if ( '' == $args['message'] ) {
unset( $args['message'] );
}
// Call security report.
Jetpack::submit_security_report(
'backup',
dirname( __FILE__ ) . '/backupbuddy.php',
$args
);
} // End backupbuddy_jetpack_security_report().
add_action( 'jetpack_security_report', 'backupbuddy_jetpack_security_report' );
if ( isset( pb_backupbuddy::$options['cron_request_timeout_override'] ) && ( '' != pb_backupbuddy::$options['cron_request_timeout_override'] ) && ( pb_backupbuddy::$options['cron_request_timeout_override'] > 0 ) ) {
add_filter( 'cron_request', 'backupbuddy_cron_request_adjust' );
function backupbuddy_cron_request_adjust( $cron ) {
$cron['args']['timeout'] = pb_backupbuddy::$options['cron_request_timeout_override'];
return $cron;
}
}
// Inform PHP Compatibility Checking plugin that we are always compatible with the latest PHP version(s).
function itbub_phpcompat_declaration( $ignored ) {
array_push( $ignored, '*/backupbuddy/*');
return $ignored;
}
add_filter( 'phpcompat_whitelist', 'itbub_phpcompat_declaration' );
// WP 4.9+ Now requires an action to be specified on an ajax call so we must register a nopriv action
// for the http loopback test to invoke to get the expected '0 200 OK' response. It has to be nopriv
// because the this is a loopback access and so the site itsefl is not a logged in user.
function itbub_ajax_nopriv_itbub_http_loop_back_test() {
// Default WordPress response will be die('0') or wp_die('0') which will return '0 200 OK'
if ( ( '' == pb_backupbuddy::_GET( 'serial' ) ) || ( pb_backupbuddy::_GET( 'serial' ) != pb_backupbuddy::$options['log_serial'] ) ) {
status_header(400);
die();
}
// If we made it here, we're good.
wp_die('-1');
}
add_action( 'wp_ajax_nopriv_itbub_http_loop_back_test', 'itbub_ajax_nopriv_itbub_http_loop_back_test' );
// Solid Sync Verb Support
function backupbuddy_register_sync_verbs( $api ) {
$verbs = array(
'backupbuddy-run-backup' => 'Ithemes_Sync_Verb_Backupbuddy_Run_Backup',
'backupbuddy-add-profile' => 'Ithemes_Sync_Verb_Backupbuddy_Add_Profile',
'backupbuddy-list-profiles' => 'Ithemes_Sync_Verb_Backupbuddy_List_Profiles',
'backupbuddy-list-schedules' => 'Ithemes_Sync_Verb_Backupbuddy_List_Schedules',
'backupbuddy-list-destinations' => 'Ithemes_Sync_Verb_Backupbuddy_List_Destinations',
'backupbuddy-list-destinationTypes' => 'Ithemes_Sync_Verb_Backupbuddy_List_DestinationTypes',
'backupbuddy-get-overview' => 'Ithemes_Sync_Verb_Backupbuddy_Get_Overview',
'backupbuddy-get-latestBackupProcess' => 'Ithemes_Sync_Verb_Backupbuddy_Get_LatestBackupProcess',
'backupbuddy-get-everything' => 'Ithemes_Sync_Verb_Backupbuddy_Get_Everything',
'backupbuddy-get-importbuddy' => 'Ithemes_Sync_Verb_Backupbuddy_Get_Importbuddy',
'backupbuddy-add-schedule' => 'Ithemes_Sync_Verb_Backupbuddy_Add_Schedule',
'backupbuddy-edit-schedule' => 'Ithemes_Sync_Verb_Backupbuddy_Edit_Schedule',
'backupbuddy-test-destination' => 'Ithemes_Sync_Verb_Backupbuddy_Test_Destination',
'backupbuddy-delete-destination' => 'Ithemes_Sync_Verb_Backupbuddy_Delete_Destination',
'backupbuddy-delete-schedule' => 'Ithemes_Sync_Verb_Backupbuddy_Delete_Schedule',
'backupbuddy-get-destinationSettings' => 'Ithemes_Sync_Verb_Backupbuddy_Get_DestinationSettings',
'backupbuddy-add-destination' => 'Ithemes_Sync_Verb_Backupbuddy_Add_Destination',
'backupbuddy-edit-destination' => 'Ithemes_Sync_Verb_Backupbuddy_Edit_Destination',
'backupbuddy-get-backupStatus' => 'Ithemes_Sync_Verb_Backupbuddy_Get_BackupStatus',
'backupbuddy-get-liveStats' => 'Ithemes_Sync_Verb_Backupbuddy_Get_LiveStats',
'backupbuddy-set-liveStatus' => 'Ithemes_Sync_Verb_Backupbuddy_Set_LiveStatus',
'backupbuddy-run-liveSnapshot' => 'Ithemes_Sync_Verb_Backupbuddy_Run_LiveSnapshot',
);
foreach( $verbs as $name => $class ) {
$api->register( $name, $class, pb_backupbuddy::plugin_path() . "/classes/ithemes-sync/$name.php" );
}
}
add_action( 'ithemes_sync_register_verbs', 'backupbuddy_register_sync_verbs' );