2015-07-09 19:28:21 +02:00
< ? php
2020-04-16 18:18:56 +02:00
/**
2019-02-19 23:52:21 +07:00
* Credits
*
2020-04-16 18:18:56 +02:00
* Plugin Name : BackWPup
2019-02-19 23:52:21 +07:00
* Plugin URI : http :// backwpup . com
* Author : Inpsyde GmbH
* Author URI : http :// inpsyde . com
* License : GPLv3
* License URI : http :// www . gnu . org / licenses / gpl - 3.0
*
* The code is used for the MainWP BackWPup Extension
* Extension URL : https :// mainwp . com / extension / backwpup /
2020-04-16 18:18:56 +02:00
*/
2019-02-19 23:52:21 +07:00
2020-05-15 18:28:59 +07:00
// phpcs:disable -- third party credit.
2020-05-07 23:22:05 +07:00
2020-05-20 20:15:29 +07:00
use MainWP\Child\MainWP_Helper ;
2020-05-21 01:22:51 +07:00
use MainWP\Child\MainWP_Utility ;
2020-05-20 20:15:29 +07:00
2015-07-09 19:28:21 +02:00
if ( ! defined ( 'MAINWP_BACKWPUP_DEVELOPMENT' ) ) {
define ( 'MAINWP_BACKWPUP_DEVELOPMENT' , false );
}
2015-10-15 22:52:37 +10:00
class MainWP_Child_Back_WP_Up {
2015-07-09 19:28:21 +02:00
public $is_backwpup_installed = false ;
2020-03-26 19:45:07 +00:00
public $is_backwpup_pro = false ;
public $plugin_translate = 'mainwp-backwpup-extension' ;
public static $instance = null ;
protected $software_version = '0.1' ;
public static $information = array ();
2015-07-09 19:28:21 +02:00
protected $exclusions = array (
'cron' => array (
'cronminutes' ,
'cronhours' ,
'cronmday' ,
'cronmon' ,
'cronwday' ,
'moncronminutes' ,
'moncronhours' ,
'moncronmday' ,
'weekcronminutes' ,
'weekcronhours' ,
'weekcronwday' ,
'daycronminutes' ,
'daycronhours' ,
'hourcronminutes' ,
2015-10-15 22:52:37 +10:00
'cronbtype' ,
2015-07-09 19:28:21 +02:00
),
'dest-EMAIL' => array ( 'emailpass' ),
'dest-DBDUMP' => array ( 'dbdumpspecialsetalltables' ),
'dest-FTP' => array ( 'ftppass' ),
'dest-S3' => array ( 's3secretkey' ),
'dest-MSAZURE' => array ( 'msazurekey' ),
'dest-SUGARSYNC' => array ( 'sugaremail' , 'sugarpass' , 'sugarrefreshtoken' ),
'dest-GDRIVE' => array ( 'gdriverefreshtoken' ),
'dest-RSC' => array ( 'rscapikey' ),
2015-10-15 22:52:37 +10:00
'dest-GLACIER' => array ( 'glaciersecretkey' ),
2015-07-09 19:28:21 +02:00
);
2020-05-06 20:22:11 +07:00
public static function instance () {
2020-04-16 18:18:56 +02:00
if ( null == self :: $instance ) {
2020-05-07 01:03:56 +07:00
self :: $instance = new self ();
2015-07-09 19:28:21 +02:00
}
2020-03-26 14:05:04 +00:00
return self :: $instance ;
2015-07-09 19:28:21 +02:00
}
public function __construct () {
2020-03-26 14:11:33 +00:00
require_once ABSPATH . 'wp-admin/includes/plugin.php' ;
2018-09-27 19:52:32 +02:00
2020-03-27 15:13:11 +00:00
try {
2018-09-27 19:52:32 +02:00
2020-03-27 15:13:11 +00:00
if ( is_plugin_active ( 'backwpup-pro/backwpup.php' ) && file_exists ( plugin_dir_path ( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) {
$file_path1 = plugin_dir_path ( __FILE__ ) . '../../backwpup-pro/backwpup.php' ;
$file_path2 = plugin_dir_path ( __FILE__ ) . '../../backwpup-pro/inc/Pro/class-pro.php' ;
2020-03-26 14:05:04 +00:00
2019-11-11 23:17:10 +07:00
if ( ! file_exists ( $file_path2 ) ) {
$file_path2 = plugin_dir_path ( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php' ;
}
2020-03-26 14:05:04 +00:00
2020-05-20 20:15:29 +07:00
MainWP_Helper :: instance () -> check_files_exists ( array ( $file_path1 , $file_path2 ) );
2020-03-27 15:13:11 +00:00
require_once $file_path1 ;
require_once $file_path2 ;
$this -> is_backwpup_installed = true ;
$this -> is_backwpup_pro = true ;
} elseif ( is_plugin_active ( 'backwpup/backwpup.php' ) && file_exists ( plugin_dir_path ( __FILE__ ) . '../../backwpup/backwpup.php' ) ) {
$file_path = plugin_dir_path ( __FILE__ ) . '../../backwpup/backwpup.php' ;
2020-05-20 20:15:29 +07:00
MainWP_Helper :: instance () -> check_files_exists ( array ( $file_path ) );
2020-03-27 15:13:11 +00:00
require_once $file_path ;
$this -> is_backwpup_installed = true ;
}
if ( $this -> is_backwpup_installed ) {
2020-05-20 20:15:29 +07:00
MainWP_Helper :: instance () -> check_classes_exists ( '\BackWPup' );
MainWP_Helper :: instance () -> check_methods ( 'get_instance' );
2020-05-07 19:34:36 +07:00
\BackWPup :: get_instance ();
2020-03-27 15:13:11 +00:00
2020-03-26 14:05:04 +00:00
add_action ( 'admin_init' , array ( $this , 'init_download_backup' ) );
2020-05-07 19:34:36 +07:00
add_filter ( 'mainwp_site_sync_others_data' , array ( $this , 'sync_others_data' ), 10 , 2 );
2020-03-27 15:13:11 +00:00
}
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2020-03-27 15:13:11 +00:00
$this -> is_backwpup_installed = false ;
}
2015-07-09 19:28:21 +02:00
}
2018-09-27 19:52:32 +02:00
2015-07-09 19:28:21 +02:00
public function action () {
if ( ! $this -> is_backwpup_installed ) {
2020-05-20 20:15:29 +07:00
MainWP_Helper :: write ( array ( 'error' => __ ( 'Please install BackWPup plugin on child website' , 'mainwp-child' ) ) );
2015-07-09 19:28:21 +02:00
return ;
}
function mainwp_backwpup_handle_fatal_error () {
$error = error_get_last ();
2020-03-26 19:45:07 +00:00
$info = self :: $information ;
2015-10-15 22:52:37 +10:00
if ( isset ( $error [ 'type' ] ) && E_ERROR === $error [ 'type' ] && isset ( $error [ 'message' ] ) ) {
2020-05-20 20:15:29 +07:00
MainWP_Helper :: write ( array ( 'error' => 'MainWP_Child fatal error : ' . $error [ 'message' ] . ' Line: ' . $error [ 'line' ] . ' File: ' . $error [ 'file' ] ) );
2020-03-26 14:11:33 +00:00
} elseif ( ! empty ( $info ) ) {
2020-05-20 20:15:29 +07:00
MainWP_Helper :: write ( self :: $information );
2015-07-09 19:28:21 +02:00
} else {
2020-05-20 20:15:29 +07:00
MainWP_Helper :: write ( array ( 'error' => 'Missing information array inside fatal_error' ) );
2015-07-09 19:28:21 +02:00
}
}
2015-10-15 22:52:37 +10:00
register_shutdown_function ( 'mainwp_backwpup_handle_fatal_error' );
2015-07-09 19:28:21 +02:00
$information = array ();
if ( ! isset ( $_POST [ 'action' ] ) ) {
2020-04-16 18:18:56 +02:00
$information = array ( 'error' => __ ( 'Missing action.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
} else {
2018-11-14 21:33:36 +07:00
2015-07-09 19:28:21 +02:00
switch ( $_POST [ 'action' ] ) {
case 'backwpup_update_settings' :
$information = $this -> update_settings ();
break ;
case 'backwpup_insert_or_update_jobs' :
$information = $this -> insert_or_update_jobs ();
break ;
case 'backwpup_insert_or_update_jobs_global' :
$information = $this -> insert_or_update_jobs_global ();
break ;
case 'backwpup_get_child_tables' :
$information = $this -> get_child_tables ();
break ;
case 'backwpup_get_job_files' :
$information = $this -> get_job_files ();
break ;
case 'backwpup_destination_email_check_email' :
$information = $this -> destination_email_check_email ();
break ;
case 'backwpup_backup_now' :
$information = $this -> backup_now ();
break ;
case 'backwpup_ajax_working' :
$information = $this -> ajax_working ();
break ;
case 'backwpup_backup_abort' :
$information = $this -> backup_abort ();
break ;
case 'backwpup_tables' :
$information = $this -> tables ();
break ;
case 'backwpup_view_log' :
$information = $this -> view_log ();
break ;
case 'backwpup_delete_log' :
$information = $this -> delete_log ();
break ;
case 'backwpup_delete_job' :
$information = $this -> delete_job ();
break ;
case 'backwpup_delete_backup' :
$information = $this -> delete_backup ();
break ;
case 'backwpup_information' :
$information = $this -> information ();
break ;
case 'backwpup_wizard_system_scan' :
$information = $this -> wizard_system_scan ();
break ;
case 'backwpup_is_pro' :
$information = array ( 'is_pro' => $this -> is_backwpup_pro );
break ;
case 'backwpup_show_hide' :
$information = $this -> show_hide ();
break ;
default :
2020-04-16 18:18:56 +02:00
$information = array ( 'error' => __ ( 'Wrong action.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
}
2020-03-26 14:05:04 +00:00
self :: $information = $information ;
2015-07-09 19:28:21 +02:00
exit ();
}
2017-07-11 14:10:22 +02:00
public function init () {
2020-03-27 14:11:21 +00:00
if ( ! $this -> is_backwpup_installed ) {
2017-07-11 14:10:22 +02:00
return ;
2020-03-27 15:13:11 +00:00
}
2017-07-11 14:10:22 +02:00
add_action ( 'mainwp_child_site_stats' , array ( $this , 'do_site_stats' ) );
2016-03-15 20:54:21 +01:00
2015-10-15 22:52:37 +10:00
if ( get_option ( 'mainwp_backwpup_hide_plugin' ) === 'hide' ) {
2015-07-09 19:28:21 +02:00
add_filter ( 'all_plugins' , array ( $this , 'all_plugins' ) );
add_action ( 'admin_menu' , array ( $this , 'remove_menu' ) );
}
}
2020-04-16 18:18:56 +02:00
public function do_site_stats () {
if ( has_action ( 'mainwp_child_reports_log' ) ) {
do_action ( 'mainwp_child_reports_log' , 'backwpup' );
2017-07-11 14:10:22 +02:00
} else {
2020-04-16 18:18:56 +02:00
$this -> do_reports_log ( 'backwpup' );
2017-07-11 14:10:22 +02:00
}
}
2020-04-16 18:18:56 +02:00
2020-03-27 14:11:21 +00:00
public function do_reports_log ( $ext = '' ) {
2020-04-16 18:18:56 +02:00
if ( 'backwpup' !== $ext ) {
2020-03-26 19:51:58 +00:00
return ;
2020-03-27 15:13:11 +00:00
}
2020-03-27 14:11:21 +00:00
if ( ! $this -> is_backwpup_installed ) {
2017-07-11 14:10:22 +02:00
return ;
2020-03-27 15:13:11 +00:00
}
try {
2020-05-20 20:15:29 +07:00
MainWP_Helper :: instance () -> check_classes_exists ( array ( '\BackWPup_File' , '\BackWPup_Job' ) );
MainWP_Helper :: instance () -> check_methods ( '\BackWPup_File' , array ( 'get_absolute_path' ) );
MainWP_Helper :: instance () -> check_methods ( '\BackWPup_Job' , array ( 'read_logheader' ) );
2020-05-21 01:22:51 +07:00
$lasttime_logged = MainWP_Utility :: get_lasttime_backup ( 'backwpup' );
2020-03-27 15:13:11 +00:00
$log_folder = get_site_option ( 'backwpup_cfg_logfolder' );
2020-05-07 19:34:36 +07:00
$log_folder = \BackWPup_File :: get_absolute_path ( $log_folder );
2020-03-27 15:13:11 +00:00
$log_folder = untrailingslashit ( $log_folder );
$logfiles = array ();
2020-04-16 18:18:56 +02:00
$dir = opendir ( $log_folder );
if ( is_readable ( $log_folder ) && $dir ) {
2020-03-27 15:13:11 +00:00
while ( ( $file = readdir ( $dir ) ) !== false ) {
$log_file = $log_folder . '/' . $file ;
if ( is_file ( $log_file ) && is_readable ( $log_file ) && false !== strpos ( $file , 'backwpup_log_' ) && false !== strpos ( $file , '.html' ) ) {
$logfiles [] = $file ;
}
}
closedir ( $dir );
}
$log_items = array ();
foreach ( $logfiles as $mtime => $logfile ) {
2020-05-07 19:34:36 +07:00
$meta = \BackWPup_Job :: read_logheader ( $log_folder . '/' . $logfile );
2020-04-16 18:18:56 +02:00
if ( ! isset ( $meta [ 'logtime' ] ) || $meta [ 'logtime' ] < $lasttime_logged ) {
2020-03-27 15:13:11 +00:00
continue ;
}
2020-04-16 18:18:56 +02:00
if ( isset ( $meta [ 'errors' ] ) && ! empty ( $meta [ 'errors' ] ) ) {
continue ;
2020-03-27 15:13:11 +00:00
}
$log_items [ $mtime ] = $meta ;
$log_items [ $mtime ][ 'file' ] = $logfile ;
}
if ( ! empty ( $log_items ) ) {
$job_types = array (
2020-04-16 18:18:56 +02:00
'DBDUMP' => __ ( 'Database backup' , 'mainwp-child' ),
'FILE' => __ ( 'File backup' , 'mainwp-child' ),
'WPEXP' => __ ( 'WordPress XML export' , 'mainwp-child' ),
'WPPLUGIN' => __ ( 'Installed plugins list' , 'mainwp-child' ),
'DBCHECK' => __ ( 'Check database tables' , 'mainwp-child' ),
2020-03-27 15:13:11 +00:00
);
$new_lasttime_logged = $lasttime_logged ;
foreach ( $log_items as $log ) {
$backup_time = $log [ 'logtime' ];
if ( $backup_time < $lasttime_logged ) {
continue ;
}
2020-04-16 18:18:56 +02:00
$job_job_types = explode ( '+' , $log [ 'type' ] );
2020-03-27 15:13:11 +00:00
$backup_type = '' ;
foreach ( $job_job_types as $typeid ) {
if ( isset ( $job_types [ $typeid ] ) ) {
$backup_type .= ' + ' . $job_types [ $typeid ];
}
}
2020-04-16 18:18:56 +02:00
if ( empty ( $backup_type ) ) {
2020-03-27 15:13:11 +00:00
continue ;
} else {
2020-04-16 18:18:56 +02:00
$backup_type = ltrim ( $backup_type , ' + ' );
2020-03-27 15:13:11 +00:00
}
$message = 'BackWPup backup finished (' . $backup_type . ')' ;
do_action ( 'mainwp_reports_backwpup_backup' , $message , $backup_type , $backup_time );
if ( $new_lasttime_logged < $backup_time ) {
$new_lasttime_logged = $backup_time ;
}
}
if ( $new_lasttime_logged > $lasttime_logged ) {
2020-05-21 01:22:51 +07:00
MainWP_Utility :: update_lasttime_backup ( 'backwpup' , $new_lasttime_logged ); // to support backup before update feature.
2020-03-27 15:13:11 +00:00
}
}
2020-05-07 01:03:56 +07:00
} catch ( \Exception $ex ) {
2020-04-16 18:18:56 +02:00
// ok!
2020-03-27 15:13:11 +00:00
}
2017-07-11 14:10:22 +02:00
}
2018-09-27 19:52:32 +02:00
2020-05-06 00:47:59 +07:00
public function sync_others_data ( $information , $data = array () ) {
2020-03-26 17:03:00 +00:00
if ( isset ( $data [ 'syncBackwpupData' ] ) && $data [ 'syncBackwpupData' ] ) {
2020-03-27 15:13:11 +00:00
try {
2020-05-21 01:22:51 +07:00
$lastbackup = MainWP_Utility :: get_lasttime_backup ( 'backwpup' );
2020-03-27 15:13:11 +00:00
$information [ 'syncBackwpupData' ] = array (
'lastbackup' => $lastbackup ,
);
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2020-04-16 18:18:56 +02:00
// ok!
2020-03-27 15:13:11 +00:00
}
2018-04-17 20:33:10 +02:00
}
2020-03-27 15:13:11 +00:00
return $information ;
}
2018-09-27 19:52:32 +02:00
2020-04-16 18:18:56 +02:00
public function get_destinations_list () {
2020-05-20 20:15:29 +07:00
MainWP_Helper :: instance () -> check_classes_exists ( array ( '\BackWPup' , '\BackWPup_Option' ) );
MainWP_Helper :: instance () -> check_methods ( '\BackWPup' , array ( 'get_registered_destinations' , 'get_destination' ) );
MainWP_Helper :: instance () -> check_methods ( '\BackWPup_Option' , array ( 'get_job_ids' , 'get' ) );
2018-09-27 19:52:32 +02:00
2016-10-24 20:33:37 +02:00
$jobdest = array ();
2020-05-07 19:34:36 +07:00
$jobids = \BackWPup_Option :: get_job_ids ();
$destinations = \BackWPup :: get_registered_destinations ();
2016-10-24 20:33:37 +02:00
foreach ( $jobids as $jobid ) {
2020-05-07 19:34:36 +07:00
if ( \BackWPup_Option :: get ( $jobid , 'backuptype' ) === 'sync' ) {
2016-10-24 20:33:37 +02:00
continue ;
}
2020-05-07 19:34:36 +07:00
$dests = \BackWPup_Option :: get ( $jobid , 'destinations' );
2016-10-24 20:33:37 +02:00
foreach ( $dests as $dest ) {
2020-03-26 15:29:54 +00:00
if ( ! $destinations [ $dest ][ 'class' ] ) {
2016-03-03 20:28:07 +01:00
continue ;
}
2018-09-27 19:52:32 +02:00
2020-05-07 19:34:36 +07:00
$dest_class = \BackWPup :: get_destination ( $dest );
2020-04-16 18:18:56 +02:00
if ( $dest_class && method_exists ( $dest_class , 'file_get_list' ) ) {
2020-03-27 15:13:11 +00:00
$can_do_dest = $dest_class -> file_get_list ( $jobid . '_' . $dest );
if ( ! empty ( $can_do_dest ) ) {
$jobdest [] = $jobid . '_' . $dest ;
}
}
2016-03-03 20:28:07 +01:00
}
}
2016-10-24 20:33:37 +02:00
return $jobdest ;
}
2017-07-11 14:10:22 +02:00
2015-07-09 19:28:21 +02:00
public function all_plugins ( $plugins ) {
foreach ( $plugins as $key => $value ) {
$plugin_slug = basename ( $key , '.php' );
2015-10-15 22:52:37 +10:00
if ( 'backwpup' === $plugin_slug ) {
2015-07-09 19:28:21 +02:00
unset ( $plugins [ $key ] );
}
}
return $plugins ;
}
public function remove_menu () {
global $submenu ;
if ( isset ( $submenu [ 'backwpup' ] ) ) {
unset ( $submenu [ 'backwpup' ] );
}
remove_menu_page ( 'backwpup' );
$pos = stripos ( $_SERVER [ 'REQUEST_URI' ], 'admin.php?page=backwpup' );
2015-10-15 22:52:37 +10:00
if ( false !== $pos ) {
2020-05-05 00:56:15 +07:00
wp_safe_redirect ( get_option ( 'siteurl' ) . '/wp-admin/index.php' );
2015-07-09 19:28:21 +02:00
exit ();
}
}
protected function show_hide () {
2017-07-11 14:10:22 +02:00
2015-10-15 22:52:37 +10:00
$hide = isset ( $_POST [ 'show_hide' ] ) && ( '1' === $_POST [ 'show_hide' ] ) ? 'hide' : '' ;
2015-07-09 19:28:21 +02:00
2020-05-20 20:15:29 +07:00
MainWP_Helper :: instance () -> update_option ( 'mainwp_backwpup_hide_plugin' , $hide , 'yes' );
2015-07-09 19:28:21 +02:00
return array ( 'success' => 1 );
}
protected function information () {
global $wpdb ;
2020-04-16 18:18:56 +02:00
// Copied from BackWPup_Page_Settings.
2015-07-09 19:28:21 +02:00
ob_start ();
echo '<table class="wp-list-table widefat fixed" cellspacing="0" style="width: 85%;margin-left:auto;;margin-right:auto;">' ;
2020-04-16 18:18:56 +02:00
echo '<thead><tr><th width="35%">' . __ ( 'Setting' , 'mainwp-child' ) . '</th><th>' . __ ( 'Value' , 'mainwp-child' ) . '</th></tr></thead>' ;
echo '<tfoot><tr><th>' . __ ( 'Setting' , 'mainwp-child' ) . '</th><th>' . __ ( 'Value' , 'mainwp-child' ) . '</th></tr></tfoot>' ;
2020-05-07 19:34:36 +07:00
echo '<tr title=">=3.2"><td>' . __ ( 'WordPress version' , 'mainwp-child' ) . '</td><td>' . esc_html ( \BackWPup :: get_plugin_data ( 'wp_version' ) ) . '</td></tr>' ;
if ( ! class_exists ( '\BackWPup_Pro' , false ) ) {
echo '<tr title=""><td>' . __ ( 'BackWPup version' , 'mainwp-child' ) . '</td><td>' . esc_html ( \BackWPup :: get_plugin_data ( 'Version' ) ) . ' <a href="' . esc_url ( translate ( \BackWPup :: get_plugin_data ( 'pluginuri' ), 'backwpup' ) ) . '">' . __ ( 'Get pro.' , 'mainwp-child' ) . '</a></td></tr>' ;
2015-07-09 19:28:21 +02:00
} else {
2020-05-07 19:34:36 +07:00
echo '<tr title=""><td>' . __ ( 'BackWPup Pro version' , 'mainwp-child' ) . '</td><td>' . esc_html ( \BackWPup :: get_plugin_data ( 'Version' ) ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
}
2020-04-16 18:18:56 +02:00
echo '<tr title=">=5.3.3"><td>' . __ ( 'PHP version' , 'mainwp-child' ) . '</td><td>' . esc_html ( PHP_VERSION ) . '</td></tr>' ;
echo '<tr title=">=5.0.7"><td>' . __ ( 'MySQL version' , 'mainwp-child' ) . '</td><td>' . esc_html ( $wpdb -> get_var ( 'SELECT VERSION() AS version' ) ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
if ( function_exists ( 'curl_version' ) ) {
$curlversion = curl_version ();
2020-04-16 18:18:56 +02:00
echo '<tr title=""><td>' . __ ( 'cURL version' , 'mainwp-child' ) . '</td><td>' . esc_html ( $curlversion [ 'version' ] ) . '</td></tr>' ;
echo '<tr title=""><td>' . __ ( 'cURL SSL version' , 'mainwp-child' ) . '</td><td>' . esc_html ( $curlversion [ 'ssl_version' ] ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
} else {
2020-04-16 18:18:56 +02:00
echo '<tr title=""><td>' . __ ( 'cURL version' , 'mainwp-child' ) . '</td><td>' . __ ( 'unavailable' , 'mainwp-child' ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
}
2020-04-16 18:18:56 +02:00
echo '<tr title=""><td>' . __ ( 'WP-Cron url:' , 'mainwp-child' ) . '</td><td>' . esc_html ( site_url ( 'wp-cron.php' ) ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
2020-04-16 18:18:56 +02:00
echo '<tr><td>' . __ ( 'Server self connect:' , 'mainwp-child' ) . '</td><td>' ;
2020-05-07 12:38:30 +00:00
$raw_response = \BackWPup_Job :: get_jobrun_url ( 'test' );
2015-07-09 19:28:21 +02:00
$test_result = '' ;
if ( is_wp_error ( $raw_response ) ) {
2020-04-16 18:18:56 +02:00
$test_result .= sprintf ( __ ( 'The HTTP response test get an error "%s"' , 'mainwp-child' ), esc_html ( $raw_response -> get_error_message () ) );
2015-10-15 22:52:37 +10:00
} elseif ( 200 !== ( int ) wp_remote_retrieve_response_code ( $raw_response ) && 204 !== ( int ) wp_remote_retrieve_response_code ( $raw_response ) ) {
2020-04-16 18:18:56 +02:00
$test_result .= sprintf ( __ ( 'The HTTP response test get a false http status (%s)' , 'mainwp-child' ), esc_html ( wp_remote_retrieve_response_code ( $raw_response ) ) );
2015-07-09 19:28:21 +02:00
}
$headers = wp_remote_retrieve_headers ( $raw_response );
2020-05-07 19:34:36 +07:00
if ( isset ( $headers [ 'x-backwpup-ver' ] ) && \BackWPup :: get_plugin_data ( 'version' ) !== $headers [ 'x-backwpup-ver' ] ) {
2020-04-16 18:18:56 +02:00
$test_result .= sprintf ( __ ( 'The BackWPup HTTP response header returns a false value: "%s"' , 'mainwp-child' ), esc_html ( $headers [ 'x-backwpup-ver' ] ) );
2015-07-09 19:28:21 +02:00
}
if ( empty ( $test_result ) ) {
2020-04-16 18:18:56 +02:00
esc_html_e ( 'Response Test O.K.' , 'mainwp-child' );
2015-07-09 19:28:21 +02:00
} else {
2015-10-15 22:52:37 +10:00
echo esc_html ( $test_result );
2015-07-09 19:28:21 +02:00
}
echo '</td></tr>' ;
2020-04-16 18:18:56 +02:00
echo '<tr><td>' . __ ( 'Temp folder:' , 'mainwp-child' ) . '</td><td>' ;
2020-05-07 19:34:36 +07:00
if ( ! is_dir ( \BackWPup :: get_plugin_data ( 'TEMP' ) ) ) {
echo sprintf ( __ ( 'Temp folder %s doesn\'t exist.' , 'mainwp-child' ), esc_html ( \BackWPup :: get_plugin_data ( 'TEMP' ) ) );
} elseif ( ! is_writable ( \BackWPup :: get_plugin_data ( 'TEMP' ) ) ) {
echo sprintf ( __ ( 'Temporary folder %s is not writable.' , 'mainwp-child' ), esc_html ( \BackWPup :: get_plugin_data ( 'TEMP' ) ) );
2015-07-09 19:28:21 +02:00
} else {
2020-05-07 19:34:36 +07:00
echo esc_html ( \BackWPup :: get_plugin_data ( 'TEMP' ) );
2015-07-09 19:28:21 +02:00
}
echo '</td></tr>' ;
2020-04-16 18:18:56 +02:00
echo '<tr><td>' . __ ( 'Log folder:' , 'mainwp-child' ) . '</td><td>' ;
2018-09-27 19:52:32 +02:00
2020-05-07 19:34:36 +07:00
$log_folder = \BackWPup_File :: get_absolute_path ( get_site_option ( 'backwpup_cfg_logfolder' ) );
2018-09-27 19:52:32 +02:00
2018-01-22 20:21:06 +01:00
if ( ! is_dir ( $log_folder ) ) {
2020-04-16 18:18:56 +02:00
echo sprintf ( __ ( 'Logs folder %s not exist.' , 'mainwp-child' ), esc_html ( $log_folder ) );
2018-01-22 20:21:06 +01:00
} elseif ( ! is_writable ( $log_folder ) ) {
2020-04-16 18:18:56 +02:00
echo sprintf ( __ ( 'Log folder %s is not writable.' , 'mainwp-child' ), esc_html ( $log_folder ) );
2015-07-09 19:28:21 +02:00
} else {
2018-01-22 20:21:06 +01:00
echo esc_html ( $log_folder );
2015-07-09 19:28:21 +02:00
}
echo '</td></tr>' ;
2020-04-16 18:18:56 +02:00
echo '<tr title=""><td>' . __ ( 'Server' , 'mainwp-child' ) . '</td><td>' . esc_html ( $_SERVER [ 'SERVER_SOFTWARE' ] ) . '</td></tr>' ;
echo '<tr title=""><td>' . __ ( 'Operating System' , 'mainwp-child' ) . '</td><td>' . esc_html ( PHP_OS ) . '</td></tr>' ;
echo '<tr title=""><td>' . __ ( 'PHP SAPI' , 'mainwp-child' ) . '</td><td>' . esc_html ( PHP_SAPI ) . '</td></tr>' ;
echo '<tr title=""><td>' . __ ( 'Current PHP user' , 'mainwp-child' ) . '</td><td>' . esc_html ( get_current_user () ) . '</td></tr>' ;
$text = version_compare ( phpversion (), '5.3.0' ) < 0 && ( bool ) ini_get ( 'safe_mode' ) ? __ ( 'On' , 'mainwp-child' ) : __ ( 'Off' , 'mainwp-child' );
echo '<tr title=""><td>' . __ ( 'Safe Mode' , 'mainwp-child' ) . '</td><td>' . $text . '</td></tr>' ;
echo '<tr title=">=30"><td>' . __ ( 'Maximum execution time' , 'mainwp-child' ) . '</td><td>' . ini_get ( 'max_execution_time' ) . ' ' . __ ( 'seconds' , 'mainwp-child' ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
if ( defined ( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
2020-04-16 18:18:56 +02:00
echo '<tr title="ALTERNATE_WP_CRON"><td>' . __ ( 'Alternative WP Cron' , 'mainwp-child' ) . '</td><td>' . __ ( 'On' , 'mainwp-child' ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
} else {
2020-04-16 18:18:56 +02:00
echo '<tr title="ALTERNATE_WP_CRON"><td>' . __ ( 'Alternative WP Cron' , 'mainwp-child' ) . '</td><td>' . __ ( 'Off' , 'mainwp-child' ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
}
if ( defined ( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
2020-04-16 18:18:56 +02:00
echo '<tr title="DISABLE_WP_CRON"><td>' . __ ( 'Disabled WP Cron' , 'mainwp-child' ) . '</td><td>' . __ ( 'On' , 'mainwp-child' ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
} else {
2020-04-16 18:18:56 +02:00
echo '<tr title="DISABLE_WP_CRON"><td>' . __ ( 'Disabled WP Cron' , 'mainwp-child' ) . '</td><td>' . __ ( 'Off' , 'mainwp-child' ) . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
}
if ( defined ( 'FS_CHMOD_DIR' ) ) {
2020-04-16 18:18:56 +02:00
echo '<tr title="FS_CHMOD_DIR"><td>' . __ ( 'CHMOD Dir' , 'mainwp-child' ) . '</td><td>' . FS_CHMOD_DIR . '</td></tr>' ;
2015-07-09 19:28:21 +02:00
} else {
2020-04-16 18:18:56 +02:00
echo '<tr title="FS_CHMOD_DIR"><td>' . __ ( 'CHMOD Dir' , 'mainwp-child' ) . '</td><td>0755</td></tr>' ;
2015-07-09 19:28:21 +02:00
}
$now = localtime ( time (), true );
2020-04-16 18:18:56 +02:00
echo '<tr title=""><td>' . __ ( 'Server Time' , 'mainwp-child' ) . '</td><td>' . esc_html ( $now [ 'tm_hour' ] ) . ':' . esc_html ( $now [ 'tm_min' ] ) . '</td></tr>' ;
echo '<tr title=""><td>' . __ ( 'Blog Time' , 'mainwp-child' ) . '</td><td>' . esc_html ( date_i18n ( 'H:i' ) ) . '</td></tr>' ;
echo '<tr title=""><td>' . __ ( 'Blog Timezone' , 'mainwp-child' ) . '</td><td>' . esc_html ( get_option ( 'timezone_string' ) ) . '</td></tr>' ;
echo '<tr title=""><td>' . __ ( 'Blog Time offset' , 'mainwp-child' ) . '</td><td>' . sprintf ( __ ( '%s hours' , 'mainwp-child' ), esc_html ( get_option ( 'gmt_offset' ) ) ) . '</td></tr>' ;
echo '<tr title="WPLANG"><td>' . __ ( 'Blog language' , 'mainwp-child' ) . '</td><td>' . esc_html ( get_bloginfo ( 'language' ) ) . '</td></tr>' ;
echo '<tr title="utf8"><td>' . __ ( 'MySQL Client encoding' , 'mainwp-child' ) . '</td><td>' ;
2015-07-09 19:28:21 +02:00
echo defined ( 'DB_CHARSET' ) ? esc_html ( DB_CHARSET ) : '' ;
echo '</td></tr>' ;
2020-04-16 18:18:56 +02:00
echo '<tr title="URF-8"><td>' . __ ( 'Blog charset' , 'mainwp-child' ) . '</td><td>' . esc_html ( get_bloginfo ( 'charset' ) ) . '</td></tr>' ;
echo '<tr title=">=128M"><td>' . __ ( 'PHP Memory limit' , 'mainwp-child' ) . '</td><td>' . esc_html ( ini_get ( 'memory_limit' ) ) . '</td></tr>' ;
echo '<tr title="WP_MEMORY_LIMIT"><td>' . __ ( 'WP memory limit' , 'mainwp-child' ) . '</td><td>' . esc_html ( WP_MEMORY_LIMIT ) . '</td></tr>' ;
echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __ ( 'WP maximum memory limit' , 'mainwp-child' ) . '</td><td>' . esc_html ( WP_MAX_MEMORY_LIMIT ) . '</td></tr>' ;
2020-04-23 19:53:22 +02:00
echo '<tr title=""><td>' . __ ( 'Memory in use' , 'mainwp-child' ) . '</td><td>' . esc_html ( size_format ( memory_get_usage ( true ), 2 ) ) . '</td></tr>' ;
2020-04-16 18:18:56 +02:00
2015-07-09 19:28:21 +02:00
$disabled = ini_get ( 'disable_functions' );
if ( ! empty ( $disabled ) ) {
$disabledarry = explode ( ',' , $disabled );
2020-04-16 18:18:56 +02:00
echo '<tr title=""><td>' . __ ( 'Disabled PHP Functions:' , 'mainwp-child' ) . '</td><td>' ;
2015-07-09 19:28:21 +02:00
echo esc_html ( implode ( ', ' , $disabledarry ) );
echo '</td></tr>' ;
}
2020-04-16 18:18:56 +02:00
echo '<tr title=""><td>' . __ ( 'Loaded PHP Extensions:' , 'mainwp-child' ) . '</td><td>' ;
2015-07-09 19:28:21 +02:00
$extensions = get_loaded_extensions ();
sort ( $extensions );
echo esc_html ( implode ( ', ' , $extensions ) );
echo '</td></tr>' ;
echo '</table>' ;
$output = ob_get_contents ();
ob_end_clean ();
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $output ,
);
2015-07-09 19:28:21 +02:00
}
protected function delete_log () {
if ( ! isset ( $_POST [ 'settings' ][ 'logfile' ] ) || ! is_array ( $_POST [ 'settings' ][ 'logfile' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing logfile.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
2020-03-27 15:13:11 +00:00
$dir = get_site_option ( 'backwpup_cfg_logfolder' );
2020-05-07 19:34:36 +07:00
$dir = \BackWPup_File :: get_absolute_path ( $dir );
2018-09-27 19:52:32 +02:00
2015-07-09 19:28:21 +02:00
foreach ( $_POST [ 'settings' ][ 'logfile' ] as $logfile ) {
$logfile = basename ( $logfile );
if ( ! is_writeable ( $dir ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Directory not writable:' , 'mainwp-child' ) . $dir );
2015-07-09 19:28:21 +02:00
}
if ( ! is_file ( $dir . $logfile ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Not file:' , 'mainwp-child' ) . $dir . $logfile );
2015-07-09 19:28:21 +02:00
}
unlink ( $dir . $logfile );
}
return array ( 'success' => 1 );
}
protected function delete_job () {
if ( ! isset ( $_POST [ 'job_id' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing job_id.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
$job_id = ( int ) $_POST [ 'job_id' ];
wp_clear_scheduled_hook ( 'backwpup_cron' , array ( 'id' => $job_id ) );
2020-05-07 19:34:36 +07:00
if ( ! \BackWPup_Option :: delete_job ( $job_id ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Cannot delete job' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
return array ( 'success' => 1 );
}
protected function delete_backup () {
if ( ! isset ( $_POST [ 'settings' ][ 'backupfile' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing backupfile.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
if ( ! isset ( $_POST [ 'settings' ][ 'dest' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing dest.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
$backupfile = $_POST [ 'settings' ][ 'backupfile' ];
2015-10-15 22:52:37 +10:00
$dest = $_POST [ 'settings' ][ 'dest' ];
2015-07-09 19:28:21 +02:00
2015-10-15 22:52:37 +10:00
list ( $dest_id , $dest_name ) = explode ( '_' , $dest );
2015-07-09 19:28:21 +02:00
2020-05-07 19:34:36 +07:00
$dest_class = \BackWPup :: get_destination ( $dest_name );
2015-07-09 19:28:21 +02:00
2015-10-15 22:52:37 +10:00
if ( is_null ( $dest_class ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Invalid dest class.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
$files = $dest_class -> file_get_list ( $dest );
2015-10-15 22:52:37 +10:00
2015-07-09 19:28:21 +02:00
foreach ( $files as $file ) {
2015-10-15 22:52:37 +10:00
if ( is_array ( $file ) && $file [ 'file' ] == $backupfile ) {
2015-07-09 19:28:21 +02:00
$dest_class -> file_delete ( $dest , $backupfile );
2015-10-15 22:52:37 +10:00
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => 'DELETED' ,
);
2015-07-09 19:28:21 +02:00
}
}
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => 'Not found' ,
);
2015-07-09 19:28:21 +02:00
}
protected function view_log () {
if ( ! isset ( $_POST [ 'settings' ][ 'logfile' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing logfile.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
2020-03-27 15:13:11 +00:00
$log_folder = get_site_option ( 'backwpup_cfg_logfolder' );
2020-05-07 19:34:36 +07:00
$log_folder = \BackWPup_File :: get_absolute_path ( $log_folder );
2020-03-26 19:45:07 +00:00
$log_file = $log_folder . basename ( $_POST [ 'settings' ][ 'logfile' ] );
2015-07-09 19:28:21 +02:00
if ( ! is_readable ( $log_file ) && ! is_readable ( $log_file . '.gz' ) && ! is_readable ( $log_file . '.bz2' ) ) {
2020-04-16 18:18:56 +02:00
$output = __ ( 'Log file doesn\'t exists' , 'mainwp-child' );
2015-07-09 19:28:21 +02:00
} else {
if ( ! file_exists ( $log_file ) && file_exists ( $log_file . '.gz' ) ) {
$log_file = $log_file . '.gz' ;
}
if ( ! file_exists ( $log_file ) && file_exists ( $log_file . '.bz2' ) ) {
$log_file = $log_file . '.bz2' ;
}
2015-10-15 22:52:37 +10:00
if ( '.gz' == substr ( $log_file , - 3 ) ) {
$output = file_get_contents ( 'compress.zlib://' . $log_file , false );
} else {
$output = file_get_contents ( $log_file , false );
2015-07-09 19:28:21 +02:00
}
}
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $output ,
);
2015-07-09 19:28:21 +02:00
}
protected function tables () {
if ( ! isset ( $_POST [ 'settings' ][ 'type' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing type.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
if ( ! isset ( $_POST [ 'settings' ][ 'website_id' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing website id.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
$type = $_POST [ 'settings' ][ 'type' ];
$website_id = $_POST [ 'settings' ][ 'website_id' ];
$this -> wp_list_table_dependency ();
$array = array ();
switch ( $type ) {
case 'logs' :
2020-03-27 15:13:11 +00:00
$log_folder = get_site_option ( 'backwpup_cfg_logfolder' );
2020-05-07 19:34:36 +07:00
$log_folder = \BackWPup_File :: get_absolute_path ( $log_folder );
2020-03-27 15:13:11 +00:00
$log_folder = untrailingslashit ( $log_folder );
2018-09-27 19:52:32 +02:00
2018-01-22 20:21:06 +01:00
if ( ! is_dir ( $log_folder ) ) {
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $array ,
);
2015-07-09 19:28:21 +02:00
}
update_user_option ( get_current_user_id (), 'backwpuplogs_per_page' , 99999999 );
2020-05-07 19:34:36 +07:00
$output = new \BackWPup_Page_Logs ();
2015-07-09 19:28:21 +02:00
$output -> prepare_items ();
break ;
case 'backups' :
update_user_option ( get_current_user_id (), 'backwpupbackups_per_page' , 99999999 );
2020-05-07 19:34:36 +07:00
$output = new \BackWPup_Page_Backups ();
2015-07-09 19:28:21 +02:00
$output -> items = array ();
2020-05-07 19:34:36 +07:00
$jobids = \BackWPup_Option :: get_job_ids ();
2015-07-09 19:28:21 +02:00
if ( ! empty ( $jobids ) ) {
foreach ( $jobids as $jobid ) {
2020-05-07 19:34:36 +07:00
if ( \BackWPup_Option :: get ( $jobid , 'backuptype' ) == 'sync' ) {
2015-07-09 19:28:21 +02:00
continue ;
}
2020-05-07 19:34:36 +07:00
$dests = \Option :: get ( $jobid , 'destinations' );
2015-07-09 19:28:21 +02:00
foreach ( $dests as $dest ) {
2020-05-07 19:34:36 +07:00
$dest_class = \BackWPup :: get_destination ( $dest );
2020-04-16 18:18:56 +02:00
if ( is_null ( $dest_class ) ) {
2016-03-08 18:48:05 +01:00
continue ;
}
2020-03-26 19:45:07 +00:00
$items = $dest_class -> file_get_list ( $jobid . '_' . $dest );
2015-07-09 19:28:21 +02:00
if ( ! empty ( $items ) ) {
2015-10-15 22:52:37 +10:00
foreach ( $items as $item ) {
2020-03-26 19:45:07 +00:00
$temp_single_item = $item ;
$temp_single_item [ 'dest' ] = $jobid . '_' . $dest ;
2020-04-16 18:18:56 +02:00
$temp_single_item [ 'timeloc' ] = sprintf ( __ ( '%1$s at %2$s' , 'mainwp-child' ), date_i18n ( get_option ( 'date_format' ), $temp_single_item [ 'time' ], true ), date_i18n ( get_option ( 'time_format' ), $temp_single_item [ 'time' ], true ) );
2020-03-26 19:45:07 +00:00
$output -> items [] = $temp_single_item ;
2015-07-09 19:28:21 +02:00
}
}
}
}
}
break ;
case 'jobs' :
2020-05-07 19:34:36 +07:00
$output = new \BackWPup_Page_Jobs ();
2015-07-09 19:28:21 +02:00
$output -> prepare_items ();
break ;
}
if ( is_array ( $output -> items ) ) {
2020-04-16 18:18:56 +02:00
if ( 'jobs' == $type ) {
2015-07-09 19:28:21 +02:00
foreach ( $output -> items as $key => $val ) {
$temp_array = array ();
$temp_array [ 'id' ] = $val ;
2020-05-07 19:34:36 +07:00
$temp_array [ 'name' ] = \BackWPup_Option :: get ( $val , 'name' );
$temp_array [ 'type' ] = \BackWPup_Option :: get ( $val , 'type' );
$temp_array [ 'destinations' ] = \BackWPup_Option :: get ( $val , 'destinations' );
2015-10-15 22:52:37 +10:00
2015-07-09 19:28:21 +02:00
if ( $this -> is_backwpup_pro ) {
$temp_array [ 'export' ] = str_replace ( '&' , '&' , wp_nonce_url ( network_admin_url ( 'admin.php' ) . '?page=backwpupjobs&action=export&jobs[]=' . $val , 'bulk-jobs' ) );
}
2020-05-07 19:34:36 +07:00
if ( \BackWPup_Option :: get ( $val , 'activetype' ) == 'wpcron' ) {
2020-04-23 17:05:27 +02:00
$nextrun = wp_next_scheduled ( 'backwpup_cron' , array ( 'id' => $val ) );
if ( $nextrun + ( get_option ( 'gmt_offset' ) * 3600 ) ) {
2020-04-16 18:18:56 +02:00
$temp_array [ 'nextrun' ] = sprintf ( __ ( '%1$s at %2$s by WP-Cron' , 'mainwp-child' ), date_i18n ( get_option ( 'date_format' ), $nextrun , true ), date_i18n ( get_option ( 'time_format' ), $nextrun , true ) );
2015-10-15 22:52:37 +10:00
} else {
2020-04-16 18:18:56 +02:00
$temp_array [ 'nextrun' ] = __ ( 'Not scheduled!' , 'mainwp-child' );
2015-10-15 22:52:37 +10:00
}
} else {
2020-04-16 18:18:56 +02:00
$temp_array [ 'nextrun' ] = __ ( 'Inactive' , 'mainwp-child' );
2015-07-09 19:28:21 +02:00
}
2020-05-07 19:34:36 +07:00
if ( \BackWPup_Option :: get ( $val , 'lastrun' ) ) {
$lastrun = \BackWPup_Option :: get ( $val , 'lastrun' );
2020-04-16 18:18:56 +02:00
$temp_array [ 'lastrun' ] = sprintf ( __ ( '%1$s at %2$s' , 'mainwp-child' ), date_i18n ( get_option ( 'date_format' ), $lastrun , true ), date_i18n ( get_option ( 'time_format' ), $lastrun , true ) );
2020-05-07 19:34:36 +07:00
if ( \BackWPup_Option :: get ( $val , 'lastruntime' ) ) {
$temp_array [ 'lastrun' ] .= ' ' . sprintf ( __ ( 'Runtime: %d seconds' , 'mainwp-child' ), \BackWPup_Option :: get ( $val , 'lastruntime' ) );
2015-07-09 19:28:21 +02:00
}
2015-10-15 22:52:37 +10:00
} else {
2020-04-16 18:18:56 +02:00
$temp_array [ 'lastrun' ] = __ ( 'not yet' , 'mainwp-child' );
2015-07-09 19:28:21 +02:00
}
$temp_array [ 'website_id' ] = $website_id ;
$array [] = $temp_array ;
}
2020-04-16 18:18:56 +02:00
} elseif ( 'backups' == $type ) {
2015-07-09 19:28:21 +02:00
$without_dupes = array ();
foreach ( $output -> items as $key ) {
$temp_array = $key ;
2020-04-22 20:05:24 +02:00
$temp_array [ 'downloadurl' ] = str_replace (
array (
'&' ,
network_admin_url ( 'admin.php' ) . '?page=backwpupbackups&action=' ,
),
array (
'&' ,
admin_url ( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=' ,
),
$temp_array [ 'downloadurl' ] . '&_wpnonce=' . $this -> create_nonce_without_session ( 'mainwp_download_backup' )
);
2020-03-26 14:05:04 +00:00
2019-11-11 23:17:10 +07:00
$temp_array [ 'downloadurl_id' ] = '/wp-admin/admin.php?page=backwpupbackups' ;
2020-03-27 14:11:21 +00:00
if ( preg_match ( '/.*&jobid=([^&]+)&.*/is' , $temp_array [ 'downloadurl' ], $matches ) ) {
2020-03-26 17:03:00 +00:00
if ( ! empty ( $matches [ 1 ] ) && is_numeric ( $matches [ 1 ] ) ) {
2020-03-26 14:05:04 +00:00
$temp_array [ 'downloadurl_id' ] .= '&download_click_id=' . $matches [ 1 ];
2020-05-07 16:27:57 +00:00
}
2019-11-11 23:17:10 +07:00
}
2020-03-26 14:05:04 +00:00
2020-03-26 19:45:07 +00:00
$temp_array [ 'website_id' ] = $website_id ;
2015-10-15 22:52:37 +10:00
if ( ! isset ( $without_dupes [ $temp_array [ 'file' ] ] ) ) {
$array [] = $temp_array ;
$without_dupes [ $temp_array [ 'file' ] ] = 1 ;
2015-07-09 19:28:21 +02:00
}
}
} else {
foreach ( $output -> items as $key => $val ) {
$array [] = $val ;
}
}
}
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $array ,
);
2015-07-09 19:28:21 +02:00
}
2019-11-11 23:17:10 +07:00
public function init_download_backup () {
2020-04-16 18:18:56 +02:00
if ( ! isset ( $_GET [ 'page' ] ) || 'backwpupbackups' !== $_GET [ 'page' ] || ! isset ( $_GET [ 'download_click_id' ] ) || empty ( $_GET [ 'download_click_id' ] ) ) {
2019-11-11 23:17:10 +07:00
return ;
}
?>
< script type = " text/javascript " >
document . addEventListener ( " DOMContentLoaded " , function ( event ) {
2020-04-16 18:18:56 +02:00
var downloadLink = document . querySelector ( 'a.backup-download-link[data-jobid="<?php echo intval( $_GET[' download_click_id '] ); ?>"' );
2019-11-11 23:17:10 +07:00
if ( typeof ( downloadLink ) !== 'undefined' && downloadLink !== null ) {
2020-04-16 18:18:56 +02:00
downloadLink . click ();
2020-03-27 15:13:11 +00:00
}
2019-11-11 23:17:10 +07:00
});
</ script >
< ? php
}
2020-03-26 14:05:04 +00:00
public function download_backup () {
2015-10-15 22:52:37 +10:00
if ( ! isset ( $_GET [ 'type' ] ) || empty ( $_GET [ 'type' ] ) || ! isset ( $_GET [ '_wpnonce' ] ) || empty ( $_GET [ '_wpnonce' ] ) ) {
die ( '-1' );
2015-07-09 19:28:21 +02:00
}
if ( ! current_user_can ( 'backwpup_backups_download' ) ) {
2015-10-15 22:52:37 +10:00
die ( '-2' );
2015-07-09 19:28:21 +02:00
}
2015-10-15 22:52:37 +10:00
if ( ! $this -> verify_nonce_without_session ( $_GET [ '_wpnonce' ], 'mainwp_download_backup' ) ) {
die ( '-3' );
2015-07-09 19:28:21 +02:00
}
2020-03-26 14:05:04 +00:00
2015-07-09 19:28:21 +02:00
$dest = strtoupper ( str_replace ( 'download' , '' , $_GET [ 'type' ] ) );
2015-10-15 22:52:37 +10:00
if ( ! empty ( $dest ) && strstr ( $_GET [ 'type' ], 'download' ) ) {
2020-05-07 19:34:36 +07:00
$dest_class = \BackWPup :: get_destination ( $dest );
2015-10-15 22:52:37 +10:00
if ( is_null ( $dest_class ) ) {
die ( '-4' );
2020-03-26 14:05:04 +00:00
}
2015-07-09 19:28:21 +02:00
2015-10-15 22:52:37 +10:00
$dest_class -> file_download ( ( int ) $_GET [ 'jobid' ], $_GET [ 'file' ] );
2015-07-09 19:28:21 +02:00
} else {
2015-10-15 22:52:37 +10:00
die ( '-5' );
2020-03-26 19:51:58 +00:00
}
2015-07-09 19:28:21 +02:00
die ();
2020-03-26 19:51:58 +00:00
}
2015-07-09 19:28:21 +02:00
2015-10-15 22:52:37 +10:00
protected function create_nonce_without_session ( $action = - 1 ) {
2015-07-09 19:28:21 +02:00
$user = wp_get_current_user ();
2015-10-15 22:52:37 +10:00
$uid = ( int ) $user -> ID ;
if ( ! $uid ) {
2015-07-09 19:28:21 +02:00
$uid = apply_filters ( 'nonce_user_logged_out' , $uid , $action );
}
$i = wp_nonce_tick ();
2015-10-15 22:52:37 +10:00
return substr ( wp_hash ( $i . '|' . $action . '|' . $uid , 'nonce' ), - 12 , 10 );
2015-07-09 19:28:21 +02:00
}
2015-10-15 22:52:37 +10:00
protected function verify_nonce_without_session ( $nonce , $action = - 1 ) {
2015-07-09 19:28:21 +02:00
$nonce = ( string ) $nonce ;
2015-10-15 22:52:37 +10:00
$user = wp_get_current_user ();
$uid = ( int ) $user -> ID ;
2015-07-09 19:28:21 +02:00
if ( ! $uid ) {
$uid = apply_filters ( 'nonce_user_logged_out' , $uid , $action );
}
if ( empty ( $nonce ) ) {
return false ;
}
$i = wp_nonce_tick ();
2015-10-15 22:52:37 +10:00
$expected = substr ( wp_hash ( $i . '|' . $action . '|' . $uid , 'nonce' ), - 12 , 10 );
2015-07-09 19:28:21 +02:00
if ( hash_equals ( $expected , $nonce ) ) {
return 1 ;
}
2015-10-15 22:52:37 +10:00
$expected = substr ( wp_hash ( ( $i - 1 ) . '|' . $action . '|' . $uid , 'nonce' ), - 12 , 10 );
2015-07-09 19:28:21 +02:00
if ( hash_equals ( $expected , $nonce ) ) {
return 2 ;
}
return false ;
}
protected function ajax_working () {
if ( ! isset ( $_POST [ 'settings' ] ) || ! is_array ( $_POST [ 'settings' ] ) || ! isset ( $_POST [ 'settings' ][ 'logfile' ] ) || ! isset ( $_POST [ 'settings' ][ 'logpos' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing logfile or logpos.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
$_GET [ 'logfile' ] = $_POST [ 'settings' ][ 'logfile' ];
$_GET [ 'logpos' ] = $_POST [ 'settings' ][ 'logpos' ];
$_REQUEST [ '_wpnonce' ] = wp_create_nonce ( 'backwpupworking_ajax_nonce' );
$this -> wp_list_table_dependency ();
function mainwp_backwpup_wp_die_ajax_handler ( $message ) {
return 'mainwp_backwpup_wp_die_ajax_handler' ;
}
2020-04-16 18:18:56 +02:00
// We do this in order to not die when using wp_die.
2015-10-15 22:52:37 +10:00
if ( ! defined ( 'DOING_AJAX' ) ) {
2015-07-09 19:28:21 +02:00
define ( 'DOING_AJAX' , true );
}
add_filter ( 'wp_die_ajax_handler' , 'mainwp_backwpup_wp_die_ajax_handler' );
remove_filter ( 'wp_die_ajax_handler' , '_ajax_wp_die_handler' );
ob_start ();
2020-05-07 19:34:36 +07:00
\BackWPup_Page_Jobs :: ajax_working ();
2015-07-09 19:28:21 +02:00
$output = ob_get_contents ();
ob_end_clean ();
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $output ,
);
2015-07-09 19:28:21 +02:00
}
protected function backup_now () {
if ( ! isset ( $_POST [ 'settings' ][ 'job_id' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing job_id' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
2020-04-16 18:18:56 +02:00
// Simulate http://wp/wp-admin/admin.php?jobid=1&page=backwpupjobs&action=runnow.
2015-07-09 19:28:21 +02:00
$_GET [ 'jobid' ] = $_POST [ 'settings' ][ 'job_id' ];
$_REQUEST [ 'action' ] = 'runnow' ;
$_REQUEST [ '_wpnonce' ] = wp_create_nonce ( 'backwpup_job_run-runnowlink' );
update_site_option ( 'backwpup_messages' , array () );
$this -> wp_list_table_dependency ();
ob_start ();
2020-05-07 19:34:36 +07:00
\BackWPup_Page_Jobs :: load ();
2015-07-09 19:28:21 +02:00
ob_end_clean ();
$output = $this -> check_backwpup_messages ();
if ( isset ( $output [ 'error' ] ) ) {
2020-05-07 19:34:36 +07:00
return array ( 'error' => '\BackWPup_Page_Jobs::load fail: ' . $output [ 'error' ] );
2015-07-09 19:28:21 +02:00
} else {
2020-05-07 19:34:36 +07:00
$job_object = \BackWPup_Job :: get_working_data ();
2015-07-09 19:28:21 +02:00
if ( is_object ( $job_object ) ) {
return array (
'success' => 1 ,
'response' => $output [ 'message' ],
2015-10-15 22:52:37 +10:00
'logfile' => basename ( $job_object -> logfile ),
2015-07-09 19:28:21 +02:00
);
} else {
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $output [ 'message' ],
);
2015-07-09 19:28:21 +02:00
}
}
}
protected function backup_abort () {
$_REQUEST [ 'action' ] = 'abort' ;
$_REQUEST [ '_wpnonce' ] = wp_create_nonce ( 'abort-job' );
update_site_option ( 'backwpup_messages' , array () );
$this -> wp_list_table_dependency ();
ob_start ();
2020-05-07 19:34:36 +07:00
\BackWPup_Page_Jobs :: load ();
2015-07-09 19:28:21 +02:00
ob_end_clean ();
$output = $this -> check_backwpup_messages ();
if ( isset ( $output [ 'error' ] ) ) {
return array ( 'error' => 'Cannot abort: ' . $output [ 'error' ] );
} else {
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $output [ 'message' ],
);
2015-07-09 19:28:21 +02:00
}
}
protected function wp_list_table_dependency () {
if ( ! function_exists ( 'convert_to_screen' ) ) {
2020-04-16 18:18:56 +02:00
// We need this because BackWPup_Page_Jobs extends WP_List_Table which uses convert_to_screen.
2015-07-09 19:28:21 +02:00
function convert_to_screen ( $hook_name ) {
return new MainWP_Fake_Wp_Screen ();
}
}
if ( ! function_exists ( 'add_screen_option' ) ) {
function add_screen_option ( $option , $args = array () ) {
}
}
2020-05-07 19:34:36 +07:00
if ( ! class_exists ( '\WP_List_Table' ) ) {
2020-03-26 14:11:33 +00:00
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ;
2015-07-09 19:28:21 +02:00
}
}
protected function wizard_system_scan () {
2020-05-07 19:34:36 +07:00
if ( class_exists ( '\BackWPup_Pro_Wizard_SystemTest' ) ) {
2015-07-09 19:28:21 +02:00
ob_start ();
2020-05-07 19:34:36 +07:00
$system_test = new \BackWPup_Pro_Wizard_SystemTest ();
2015-07-09 19:28:21 +02:00
$system_test -> execute ( null );
$output = ob_get_contents ();
ob_end_clean ();
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'response' => $output ,
);
2015-07-09 19:28:21 +02:00
} else {
return array ( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' );
}
}
protected function destination_email_check_email () {
$settings = $_POST [ 'settings' ];
2015-10-15 22:52:37 +10:00
$message = '' ;
2015-07-09 19:28:21 +02:00
$emailmethod = ( isset ( $settings [ 'emailmethod' ] ) ? $settings [ 'emailmethod' ] : '' );
$emailsendmail = ( isset ( $settings [ 'emailsendmail' ] ) ? $settings [ 'emailsendmail' ] : '' );
$emailhost = ( isset ( $settings [ 'emailhost' ] ) ? $settings [ 'emailhost' ] : '' );
$emailhostport = ( isset ( $settings [ 'emailhostport' ] ) ? $settings [ 'emailhostport' ] : '' );
$emailsecure = ( isset ( $settings [ 'emailsecure' ] ) ? $settings [ 'emailsecure' ] : '' );
$emailuser = ( isset ( $settings [ 'emailuser' ] ) ? $settings [ 'emailuser' ] : '' );
$emailpass = ( isset ( $settings [ 'emailpass' ] ) ? $settings [ 'emailpass' ] : '' );
if ( ! isset ( $settings [ 'emailaddress' ] ) || strlen ( $settings [ 'emailaddress' ] ) < 2 ) {
2020-04-16 18:18:56 +02:00
$message = __ ( 'Missing email address.' , 'mainwp-child' );
2015-07-09 19:28:21 +02:00
} else {
if ( $emailmethod ) {
global $phpmailer ;
if ( ! is_object ( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) {
require_once ABSPATH . WPINC . '/class-phpmailer.php' ;
require_once ABSPATH . WPINC . '/class-smtp.php' ;
2020-05-05 00:56:15 +07:00
$phpmailer = new PHPMailer ( true ); // phpcs:ignore -- to custom init PHP mailer
2015-07-09 19:28:21 +02:00
}
if ( is_object ( $phpmailer ) ) {
do_action_ref_array ( 'phpmailer_init' , array ( & $phpmailer ) );
$emailmethod = $phpmailer -> Mailer ;
$emailsendmail = $phpmailer -> Sendmail ;
$emailhost = $phpmailer -> Host ;
$emailhostport = $phpmailer -> Port ;
$emailsecure = $phpmailer -> SMTPSecure ;
$emailuser = $phpmailer -> Username ;
$emailpass = $phpmailer -> Password ;
}
}
2020-05-07 19:34:36 +07:00
if ( ! class_exists ( '\Swift' , false ) ) {
require \BackWPup :: get_plugin_data ( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php' ;
2015-07-09 19:28:21 +02:00
}
if ( function_exists ( 'mb_internal_encoding' ) && ( ( int ) ini_get ( 'mbstring.func_overload' ) ) & 2 ) {
$mbEncoding = mb_internal_encoding ();
mb_internal_encoding ( 'ASCII' );
}
try {
2020-04-16 18:18:56 +02:00
// Create the Transport.
if ( 'smtp' == $emailmethod ) {
2015-07-09 19:28:21 +02:00
$transport = Swift_SmtpTransport :: newInstance ( $emailhost , $emailhostport );
$transport -> setUsername ( $emailuser );
$transport -> setPassword ( $emailpass );
2020-04-16 18:18:56 +02:00
if ( 'ssl' == $emailsecure ) {
2015-07-09 19:28:21 +02:00
$transport -> setEncryption ( 'ssl' );
}
2020-04-16 18:18:56 +02:00
if ( 'tls' == $emailsecure ) {
2015-07-09 19:28:21 +02:00
$transport -> setEncryption ( 'tls' );
}
2020-04-16 18:18:56 +02:00
} elseif ( 'sendmail' == $emailmethod ) {
2015-07-09 19:28:21 +02:00
$transport = Swift_SendmailTransport :: newInstance ( $emailsendmail );
} else {
$transport = Swift_MailTransport :: newInstance ();
}
$emailer = Swift_Mailer :: newInstance ( $transport );
2020-04-16 18:18:56 +02:00
$message = Swift_Message :: newInstance ( __ ( 'BackWPup archive sending TEST Message' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
$message -> setFrom ( array ( ( isset ( $settings [ 'emailsndemail' ] ) ? $settings [ 'emailsndemail' ] : 'from@example.com' ) => isset ( $settings [ 'emailsndemailname' ] ) ? $settings [ 'emailsndemailname' ] : '' ) );
$message -> setTo ( array ( $settings [ 'emailaddress' ] ) );
2020-04-16 18:18:56 +02:00
$message -> setBody ( __ ( 'If this message reaches your inbox, sending backup archives via email should work for you.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
$result = $emailer -> send ( $message );
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-07-09 19:28:21 +02:00
$message = 'Swift Mailer: ' . $e -> getMessage ();
}
if ( isset ( $mbEncoding ) ) {
mb_internal_encoding ( $mbEncoding );
}
if ( ! isset ( $result ) || ! $result ) {
2020-04-16 18:18:56 +02:00
$message = __ ( 'Error while sending email!' , 'mainwp-child' );
2015-07-09 19:28:21 +02:00
} else {
2020-04-16 18:18:56 +02:00
$message = __ ( 'Email sent.' , 'mainwp-child' );
2015-07-09 19:28:21 +02:00
}
}
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'message' => $message ,
);
2015-07-09 19:28:21 +02:00
}
protected function get_job_files () {
2020-04-16 18:18:56 +02:00
// From BackWPup_JobType_File::get_exclude_dirs.
2015-07-09 19:28:21 +02:00
function mainwp_backwpup_get_exclude_dirs ( $folder ) {
$folder = trailingslashit ( str_replace ( '\\' , '/' , realpath ( $folder ) ) );
$exclude_dir_array = array ();
if ( false !== strpos ( trailingslashit ( str_replace ( '\\' , '/' , realpath ( ABSPATH ) ) ), $folder ) && trailingslashit ( str_replace ( '\\' , '/' , realpath ( ABSPATH ) ) ) != $folder ) {
$exclude_dir_array [] = trailingslashit ( str_replace ( '\\' , '/' , realpath ( ABSPATH ) ) );
}
if ( false !== strpos ( trailingslashit ( str_replace ( '\\' , '/' , realpath ( WP_CONTENT_DIR ) ) ), $folder ) && trailingslashit ( str_replace ( '\\' , '/' , realpath ( WP_CONTENT_DIR ) ) ) != $folder ) {
$exclude_dir_array [] = trailingslashit ( str_replace ( '\\' , '/' , realpath ( WP_CONTENT_DIR ) ) );
}
if ( false !== strpos ( trailingslashit ( str_replace ( '\\' , '/' , realpath ( WP_PLUGIN_DIR ) ) ), $folder ) && trailingslashit ( str_replace ( '\\' , '/' , realpath ( WP_PLUGIN_DIR ) ) ) != $folder ) {
$exclude_dir_array [] = trailingslashit ( str_replace ( '\\' , '/' , realpath ( WP_PLUGIN_DIR ) ) );
}
if ( false !== strpos ( trailingslashit ( str_replace ( '\\' , '/' , realpath ( get_theme_root () ) ) ), $folder ) && trailingslashit ( str_replace ( '\\' , '/' , realpath ( get_theme_root () ) ) ) != $folder ) {
$exclude_dir_array [] = trailingslashit ( str_replace ( '\\' , '/' , realpath ( get_theme_root () ) ) );
}
2020-05-07 19:34:36 +07:00
if ( false !== strpos ( trailingslashit ( str_replace ( '\\' , '/' , realpath ( \BackWPup_File :: get_upload_dir () ) ) ), $folder ) && trailingslashit ( str_replace ( '\\' , '/' , realpath ( \BackWPup_File :: get_upload_dir () ) ) ) != $folder ) {
$exclude_dir_array [] = trailingslashit ( str_replace ( '\\' , '/' , realpath ( \BackWPup_File :: get_upload_dir () ) ) );
2015-07-09 19:28:21 +02:00
}
return array_unique ( $exclude_dir_array );
}
$return = array ();
$folders = array (
'abs' => ABSPATH ,
'content' => WP_CONTENT_DIR ,
'plugin' => WP_PLUGIN_DIR ,
'theme' => get_theme_root (),
2020-05-07 19:34:36 +07:00
'upload' => \BackWPup_File :: get_upload_dir (),
2015-07-09 19:28:21 +02:00
);
foreach ( $folders as $key => $folder ) {
$return_temp = array ();
$main_folder_name = realpath ( $folder );
if ( $main_folder_name ) {
$main_folder_name = untrailingslashit ( str_replace ( '\\' , '/' , $main_folder_name ) );
2020-05-07 19:34:36 +07:00
$main_folder_size = '(' . size_format ( \BackWPup_File :: get_folder_size ( $main_folder_name , false ), 2 ) . ')' ;
2015-07-09 19:28:21 +02:00
2020-04-23 19:53:22 +02:00
$dir = opendir ( $main_folder_name );
2020-04-16 18:18:56 +02:00
if ( $dir ) {
2020-04-22 20:05:24 +02:00
while ( false !== ( $file = readdir ( $dir ) ) ) {
2020-04-22 18:05:39 +00:00
if ( ! in_array ( $file , array ( '.' , '..' ) ) && is_dir ( $main_folder_name . '/' . $file ) && ! in_array ( trailingslashit ( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs ( $main_folder_name ) ) ) {
2020-05-07 19:34:36 +07:00
$folder_size = ' (' . size_format ( \BackWPup_File :: get_folder_size ( $main_folder_name . '/' . $file ), 2 ) . ')' ;
2015-07-09 19:28:21 +02:00
$return_temp [] = array (
'size' => $folder_size ,
2015-10-15 22:52:37 +10:00
'name' => $file ,
2015-07-09 19:28:21 +02:00
);
}
}
2020-04-23 19:53:22 +02:00
closedir ( $dir );
2015-07-09 19:28:21 +02:00
}
2020-03-26 15:29:54 +00:00
$return [ $key ] = array (
'size' => $main_folder_size ,
'name' => $folder ,
'folders' => $return_temp ,
);
2015-07-09 19:28:21 +02:00
}
}
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'folders' => $return ,
);
2015-07-09 19:28:21 +02:00
}
protected function get_child_tables () {
global $wpdb ;
$return = array ();
$settings = $_POST [ 'settings' ];
if ( ! empty ( $settings [ 'dbhost' ] ) && ! empty ( $settings [ 'dbuser' ] ) ) {
2020-05-08 00:51:43 +07:00
$mysqli = new mysqli ( $settings [ 'dbhost' ], $settings [ 'dbuser' ], ( isset ( $settings [ 'dbpassword' ] ) ? $settings [ 'dbpassword' ] : '' ) ); // phpcs:ignore -- third party code.
2015-07-09 19:28:21 +02:00
if ( $mysqli -> connect_error ) {
$return [ 'message' ] = $mysqli -> connect_error ;
} else {
if ( ! empty ( $settings [ 'dbname' ] ) ) {
2020-04-16 18:18:56 +02:00
$res = $mysqli -> query ( 'SHOW FULL TABLES FROM `' . $mysqli -> real_escape_string ( $settings [ 'dbname' ] ) . '`' );
if ( $res ) {
2015-07-09 19:28:21 +02:00
$tables_temp = array ();
2020-05-08 00:51:43 +07:00
while ( $table = $res -> fetch_array ( MYSQLI_NUM ) ) { // phpcs:ignore -- third party code.
2015-07-09 19:28:21 +02:00
$tables_temp [] = $table [ 0 ];
}
$res -> close ();
$return [ 'tables' ] = $tables_temp ;
}
}
if ( empty ( $settings [ 'dbname' ] ) || ! empty ( $settings [ 'first' ] ) ) {
2020-04-16 18:18:56 +02:00
$res = $mysqli -> query ( 'SHOW DATABASES' );
if ( $res ) {
2015-07-09 19:28:21 +02:00
$databases_temp = array ();
while ( $db = $res -> fetch_array () ) {
$databases_temp [] = $db [ 'Database' ];
}
$res -> close ();
$return [ 'databases' ] = $databases_temp ;
}
}
}
$mysqli -> close ();
} else {
$tables_temp = array ();
2020-05-08 00:51:43 +07:00
$tables = $wpdb -> get_results ( 'SHOW FULL TABLES FROM `' . DB_NAME . '`' , ARRAY_N ); // phpcs:ignore -- safe query.
2015-07-09 19:28:21 +02:00
foreach ( $tables as $table ) {
$tables_temp [] = $table [ 0 ];
}
$return [ 'tables' ] = $tables_temp ;
}
2017-07-11 14:10:22 +02:00
2020-04-16 18:18:56 +02:00
if ( isset ( $settings [ 'job_id' ] ) ) {
2020-05-07 19:34:36 +07:00
$return [ 'dbdumpexclude' ] = \BackWPup_Option :: get ( $settings [ 'job_id' ], 'dbdumpexclude' );
2016-08-02 19:51:22 +02:00
}
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'return' => $return ,
);
2015-07-09 19:28:21 +02:00
}
protected function insert_or_update_jobs_global () {
$settings = $_POST [ 'settings' ];
if ( ! is_array ( $settings ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing array settings' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
if ( ! isset ( $settings [ 'job_id' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing job_id' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
if ( $settings [ 'job_id' ] > 0 ) {
$new_job_id = intval ( $settings [ 'job_id' ] );
} else {
$new_job_id = null ;
}
$changes_array = array ();
$message_array = array ();
foreach ( $settings [ 'value' ] as $key => $val ) {
$temp_array = array ();
$temp_array [ 'tab' ] = $key ;
$temp_array [ 'value' ] = $val ;
if ( ! is_null ( $new_job_id ) ) {
$temp_array [ 'job_id' ] = $new_job_id ;
} else {
$temp_array [ 'job_id' ] = $settings [ 'job_id' ];
}
$_POST [ 'settings' ] = $temp_array ;
$return = $this -> insert_or_update_jobs ();
if ( is_null ( $new_job_id ) ) {
if ( ! isset ( $return [ 'job_id' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing new job_id' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
$new_job_id = $return [ 'job_id' ];
}
2020-04-16 18:18:56 +02:00
// We want to exit gracefully.
2015-07-09 19:28:21 +02:00
if ( isset ( $return [ 'error_message' ] ) ) {
$message_array [ $return [ 'error_message' ] ] = 1 ;
}
if ( isset ( $return [ 'changes' ] ) ) {
$changes_array = array_merge ( $changes_array , $return [ 'changes' ] );
}
if ( isset ( $return [ 'message' ] ) ) {
foreach ( $return [ 'message' ] as $message ) {
if ( ! isset ( $message_array [ $message ] ) ) {
$message_array [ $message ] = 1 ;
}
}
}
}
return array (
'success' => 1 ,
'job_id' => $new_job_id ,
'changes' => $changes_array ,
2015-10-15 22:52:37 +10:00
'message' => array_keys ( $message_array ),
2015-07-09 19:28:21 +02:00
);
}
2020-04-16 18:18:56 +02:00
// From BackWPup_JobType_File::edit_form_post_save with some tweaks.
2017-07-11 14:10:22 +02:00
public function edit_form_post_save ( $post_data , $id ) {
2020-04-16 18:18:56 +02:00
// Parse and save files to exclude.
2020-05-07 16:27:57 +00:00
$exclude_input = $post_data [ 'fileexclude' ];
$to_exclude_list = $exclude_input ? str_replace ( array ( " \r \n " , " \r " ), ',' , $exclude_input ) : array ();
2020-05-07 23:22:05 +07:00
if ( $to_exclude_list ) {
$to_exclude_list = sanitize_text_field ( stripslashes ( $to_exclude_list ) );
}
2020-05-07 16:27:57 +00:00
$to_exclude = $to_exclude_list ? explode ( ',' , $to_exclude_list ) : array ();
$to_exclude_parsed = array ();
2017-07-11 14:10:22 +02:00
foreach ( $to_exclude as $key => $value ) {
2020-05-07 16:27:57 +00:00
$normalized = wp_normalize_path ( trim ( $value ) );
2020-05-07 23:22:05 +07:00
if ( $normalized ) {
$to_exclude_parsed [ $key ] = $normalized ;
}
2017-07-11 14:10:22 +02:00
}
sort ( $to_exclude_parsed );
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $id , 'fileexclude' , implode ( ',' , $to_exclude_parsed ) );
2017-07-11 14:10:22 +02:00
unset ( $exclude_input , $to_exclude_list , $to_exclude , $to_exclude_parsed , $normalized );
2020-04-16 18:18:56 +02:00
// Parse and save folders to include.
2020-03-26 19:45:07 +00:00
$include_input = $post_data [ 'dirinclude' ];
$include_list = $include_input ? str_replace ( array ( " \r \n " , " \r " ), ',' , $include_input ) : array ();
$to_include = $include_list ? explode ( ',' , $include_list ) : array ();
2017-07-11 14:10:22 +02:00
$to_include_parsed = array ();
foreach ( $to_include as $key => $value ) {
2020-05-07 16:27:57 +00:00
$normalized = trailingslashit ( wp_normalize_path ( trim ( $value ) ) );
2020-05-07 23:22:05 +07:00
if ( $normalized ) {
2020-05-07 16:27:57 +00:00
$normalized = filter_var ( $normalized , FILTER_SANITIZE_URL );
2020-05-07 23:22:05 +07:00
}
2020-05-07 16:27:57 +00:00
$realpath = $normalized && '/' !== $normalized ? realpath ( $normalized ) : false ;
2020-05-07 23:22:05 +07:00
if ( $realpath ) {
$to_include_parsed [ $key ] = $realpath ;
}
2017-07-11 14:10:22 +02:00
}
sort ( $to_include_parsed );
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $id , 'dirinclude' , implode ( ',' , $to_include_parsed ) );
2020-04-22 20:05:24 +02:00
unset ( $include_input , $include_list , $to_include , $to_include_parsed , $normalized , $realpath );
2017-07-11 14:10:22 +02:00
2020-04-16 18:18:56 +02:00
// Parse and save boolean fields.
2017-07-11 14:10:22 +02:00
$boolean_fields_def = array (
'backupexcludethumbs' => FILTER_VALIDATE_BOOLEAN ,
'backupspecialfiles' => FILTER_VALIDATE_BOOLEAN ,
'backuproot' => FILTER_VALIDATE_BOOLEAN ,
'backupabsfolderup' => FILTER_VALIDATE_BOOLEAN ,
'backupcontent' => FILTER_VALIDATE_BOOLEAN ,
'backupplugins' => FILTER_VALIDATE_BOOLEAN ,
'backupthemes' => FILTER_VALIDATE_BOOLEAN ,
'backupuploads' => FILTER_VALIDATE_BOOLEAN ,
);
2020-03-26 17:03:00 +00:00
foreach ( $boolean_fields_def as $key => $value ) {
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $id , $key , ! empty ( $post_data [ $key ] ) );
2017-07-11 14:10:22 +02:00
}
2020-04-16 18:18:56 +02:00
// Parse and save directories to exclude.
2017-07-11 14:10:22 +02:00
$exclude_dirs_def = array (
2020-03-26 15:29:54 +00:00
'backuprootexcludedirs' => array (
'filter' => FILTER_SANITIZE_URL ,
'flags' => FILTER_FORCE_ARRAY ,
),
'backuppluginsexcludedirs' => array (
'filter' => FILTER_SANITIZE_URL ,
'flags' => FILTER_FORCE_ARRAY ,
),
'backupcontentexcludedirs' => array (
'filter' => FILTER_SANITIZE_URL ,
'flags' => FILTER_FORCE_ARRAY ,
),
'backupthemesexcludedirs' => array (
'filter' => FILTER_SANITIZE_URL ,
'flags' => FILTER_FORCE_ARRAY ,
),
'backupuploadsexcludedirs' => array (
'filter' => FILTER_SANITIZE_URL ,
'flags' => FILTER_FORCE_ARRAY ,
),
2017-07-11 14:10:22 +02:00
);
2020-03-26 17:03:00 +00:00
foreach ( $exclude_dirs_def as $key => $filter ) {
2020-03-26 15:29:54 +00:00
$value = ! empty ( $post_data [ $key ] ) && is_array ( $post_data [ $key ] ) ? $post_data [ $key ] : array ();
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $id , $key , $value );
2017-07-11 14:10:22 +02:00
}
}
2015-07-09 19:28:21 +02:00
protected function insert_or_update_jobs () {
2017-07-11 14:10:22 +02:00
2015-07-09 19:28:21 +02:00
$settings = $_POST [ 'settings' ];
if ( ! is_array ( $settings ) || ! isset ( $settings [ 'value' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing array settings' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
if ( ! isset ( $settings [ 'tab' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing tab' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
if ( ! isset ( $settings [ 'job_id' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing job_id' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
2020-05-07 19:34:36 +07:00
if ( ! class_exists ( '\BackWPup' ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Install BackWPup on child website' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
if ( $settings [ 'job_id' ] > 0 ) {
$job_id = intval ( $settings [ 'job_id' ] );
} else {
2020-04-16 18:18:56 +02:00
// generate jobid if not exists.
2020-05-07 19:34:36 +07:00
$newjobid = \BackWPup_Option :: get_job_ids ();
2015-07-09 19:28:21 +02:00
sort ( $newjobid );
$job_id = end ( $newjobid ) + 1 ;
}
update_site_option ( 'backwpup_messages' , array () );
2020-04-16 18:18:56 +02:00
if ( isset ( $settings [ 'value' ][ 'backupdir' ] ) && empty ( $settings [ 'value' ][ 'backupdir' ] ) ) {
2020-05-07 19:34:36 +07:00
$backupdir = \BackWPup_Option :: get ( ( int ) $job_id , 'backupdir' );
2020-04-16 18:18:56 +02:00
if ( ! empty ( $backupdir ) ) {
2017-07-11 14:10:22 +02:00
$settings [ 'value' ][ 'backupdir' ] = $backupdir ;
}
}
2017-05-11 21:07:42 +02:00
2015-07-09 19:28:21 +02:00
foreach ( $settings [ 'value' ] as $key => $val ) {
$_POST [ $key ] = $val ;
}
2020-04-16 18:18:56 +02:00
if ( 'jobtype-FILE' == $settings [ 'tab' ] ) {
$this -> edit_form_post_save ( $settings [ 'value' ], $job_id );
2020-05-07 19:34:36 +07:00
$messages = \BackWPup_Admin :: get_messages ();
2017-07-11 14:10:22 +02:00
if ( empty ( $messages [ 'error' ] ) ) {
2020-05-07 19:34:36 +07:00
$url = \BackWPup_Job :: get_jobrun_url ( 'runnowlink' , $job_id );
\BackWPup_Admin :: message ( sprintf ( __ ( 'Changes for job <i>%s</i> saved.' , 'mainwp-child' ), \BackWPup_Option :: get ( $job_id , 'name' ) ) . ' <a href="' . network_admin_url ( 'admin.php' ) . '?page=backwpupjobs">' . __ ( 'Jobs overview' , 'mainwp-child' ) . '</a> | <a href="' . $url [ 'url' ] . '">' . __ ( 'Run now' , 'mainwp-child' ) . '</a>' );
2017-07-11 14:10:22 +02:00
}
2020-04-16 18:18:56 +02:00
} elseif ( 'dest-DROPBOX' == $settings [ 'tab' ] ) {
unset ( $settings [ 'value' ] );
2020-05-07 19:34:36 +07:00
\BackWPup_Page_Editjob :: save_post_form ( $settings [ 'tab' ], $job_id );
2017-07-11 14:10:22 +02:00
} else {
2020-05-07 19:34:36 +07:00
\BackWPup_Page_Editjob :: save_post_form ( $settings [ 'tab' ], $job_id );
2017-07-11 14:10:22 +02:00
}
2015-07-09 19:28:21 +02:00
$return = $this -> check_backwpup_messages ();
if ( isset ( $return [ 'error' ] ) ) {
return array (
'success' => 1 ,
2020-04-16 18:18:56 +02:00
'error_message' => __ ( 'Cannot save jobs: ' . $return [ 'error' ], 'mainwp-child' ),
2015-07-09 19:28:21 +02:00
);
}
if ( isset ( $settings [ 'value' ][ 'sugarrefreshtoken' ] ) ) {
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $job_id , 'sugarrefreshtoken' , $settings [ 'value' ][ 'sugarrefreshtoken' ] );
2015-07-09 19:28:21 +02:00
}
if ( isset ( $settings [ 'value' ][ 'gdriverefreshtoken' ] ) ) {
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $job_id , 'gdriverefreshtoken' , $settings [ 'value' ][ 'gdriverefreshtoken' ] );
2015-07-09 19:28:21 +02:00
}
if ( isset ( $settings [ 'value' ][ 'dbdumpspecialsetalltables' ] ) && $settings [ 'value' ][ 'dbdumpspecialsetalltables' ] ) {
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $job_id , 'dbdumpexclude' , array () );
2015-07-09 19:28:21 +02:00
}
2015-10-15 22:52:37 +10:00
if ( isset ( $settings [ 'value' ][ 'dropboxtoken' ] ) && isset ( $settings [ 'value' ][ 'dropboxroot' ] ) ) {
2020-05-07 19:34:36 +07:00
\BackWPup_Option :: update ( $job_id , 'dropboxtoken' , $settings [ 'value' ][ 'dropboxtoken' ] );
\Option :: update ( $job_id , 'dropboxroot' , $settings [ 'value' ][ 'dropboxroot' ] );
2015-07-09 19:28:21 +02:00
}
$changes_array = array ();
foreach ( $settings [ 'value' ] as $key => $val ) {
2020-05-07 19:34:36 +07:00
$temp_value = \BackWPup_Option :: get ( $job_id , $key );
2015-07-09 19:28:21 +02:00
if ( is_string ( $temp_value ) ) {
if ( isset ( $this -> exclusions [ $settings [ 'tab' ] ] ) ) {
if ( ! in_array ( $key , $this -> exclusions [ $settings [ 'tab' ] ] ) && strcmp ( $temp_value , $val ) != 0 ) {
$changes_array [ $key ] = $temp_value ;
}
2020-03-26 14:11:33 +00:00
} elseif ( strcmp ( $temp_value , $val ) != 0 ) {
2015-07-09 19:28:21 +02:00
$changes_array [ $key ] = $temp_value ;
}
}
}
return array (
'success' => 1 ,
'job_id' => $job_id ,
'changes' => $changes_array ,
2015-10-15 22:52:37 +10:00
'message' => $return [ 'message' ],
2015-07-09 19:28:21 +02:00
);
}
protected function update_settings () {
$settings = $_POST [ 'settings' ];
if ( ! is_array ( $settings ) || ! isset ( $settings [ 'value' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Missing array settings' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
2020-05-07 19:34:36 +07:00
if ( ! class_exists ( '\BackWPup' ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Install BackWPup on child website' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
2020-04-16 18:18:56 +02:00
if ( isset ( $settings [ 'value' ][ 'is_premium' ] ) && 1 == $settings [ 'value' ][ 'is_premium' ] && false == $this -> is_backwpup_pro ) {
return array ( 'error' => __ ( 'You try to use pro version settings in non pro plugin version. Please install pro version on child and try again.' , 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
foreach ( $settings [ 'value' ] as $key => $val ) {
$_POST [ $key ] = $val ;
}
update_site_option ( 'backwpup_messages' , array () );
2020-03-27 15:13:11 +00:00
$settings_views = array ();
2018-12-19 17:01:08 +07:00
$settings_updaters = array ();
2020-05-07 19:34:36 +07:00
$backwpup = new \BackWPup_Page_Settings ( $settings_views , $settings_updaters );
2015-07-09 19:28:21 +02:00
$backwpup -> save_post_form ();
2020-05-07 19:34:36 +07:00
if ( class_exists ( '\BackWPup_Pro' ) ) {
$pro_settings = \BackWPup_Pro_Settings_APIKeys :: get_instance ();
2015-07-09 19:28:21 +02:00
$pro_settings -> save_form ();
}
$return = $this -> check_backwpup_messages ();
if ( isset ( $return [ 'error' ] ) ) {
2020-04-16 18:18:56 +02:00
return array ( 'error' => __ ( 'Cannot save settings: ' . $return [ 'error' ], 'mainwp-child' ) );
2015-07-09 19:28:21 +02:00
}
$exclusions = array (
'is_premium' ,
'dropboxappsecret' ,
'dropboxsandboxappsecret' ,
'sugarsyncsecret' ,
'googleclientsecret' ,
'override' ,
2015-10-15 22:52:37 +10:00
'httpauthpassword' ,
2015-07-09 19:28:21 +02:00
);
$changes_array = array ();
foreach ( $settings [ 'value' ] as $key => $val ) {
$temp_value = get_site_option ( 'backwpup_cfg_' . $key , '' );
if ( ! in_array ( $key , $exclusions ) && strcmp ( $temp_value , $val ) != 0 ) {
$changes_array [ $key ] = $temp_value ;
}
}
2020-03-26 15:29:54 +00:00
return array (
'success' => 1 ,
'changes' => $changes_array ,
'message' => $return [ 'message' ],
);
2015-07-09 19:28:21 +02:00
}
protected function check_backwpup_messages () {
$message = get_site_option ( 'backwpup_messages' , array () );
update_site_option ( 'backwpup_messages' , array () );
if ( isset ( $message [ 'error' ] ) ) {
2015-10-15 22:52:37 +10:00
return array ( 'error' => implode ( ', ' , $message [ 'error' ] ) );
2020-03-26 14:11:33 +00:00
} elseif ( isset ( $message [ 'updated' ] ) ) {
2015-07-09 19:28:21 +02:00
return array ( 'message' => $message [ 'updated' ] );
} else {
return array ( 'error' => 'Generic error' );
}
}
}
2020-05-13 18:48:37 +07:00
// phpcs:disable Generic.Files.OneObjectStructurePerFile -- fake class
2015-10-15 22:52:37 +10:00
if ( ! class_exists ( 'MainWP_Fake_Wp_Screen' ) ) {
2015-07-09 19:28:21 +02:00
class MainWP_Fake_Wp_Screen {
public $action ;
public $base ;
public $id ;
}
2015-10-15 22:52:37 +10:00
}