static function init() { $command = self::getCommand(); if ($command) { WPAdm_Core::$cron = false; wpadm_class::$type = 'full'; //$time_load = ini_get("max_execution_time"); //WPAdm_Core::log('proccess is work ' . $time_load . 'sec'); /*if ($time_load != 0) { self::run($time_load - 5); } else { self::run(90); } */ self::run(30); if (self::checkLock()) { $core = new WPAdm_Core($command, 'full_backup_dropbox', DRBBACKUP_BASE_DIR); if ($result = $core->getResult()->toArray(true)) { if ($result['result'] == 'success') { self::delCommand($command['method']); self::stop(); self::setCommandResultData($command['method'], $result); self::init(); } elseif ($result['result'] == 'error') { self::setCommandResultData($command['method'], $result); self::stop(); self::init_params_default(); } } } } }
function wpadm_run($pl, $dir) { require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-method-class.php'; $request_name = $pl . '_request'; if (isset($_POST[$request_name]) && !empty($_POST[$request_name])) { require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-core.php'; $wpadm = new WPAdm_Core(wpadm_unpack($_POST[$request_name]), $pl, $dir); echo '<wpadm>' . wpadm_pack($wpadm->getResult()->toArray()) . '</wpadm>'; exit; } }
function wpadm_run($pl, $dir) { @set_time_limit(0); require_once dirname(__FILE__) . '/class-wpadm-method-class.php'; $request_name = 'wpadm_' . $pl . '_request'; if (isset($_POST[$request_name]) && !empty($_POST[$request_name])) { require_once dirname(__FILE__) . '/class-wpadm-core.php'; $wpadm = new WPAdm_Core(wpadm_unpack($_POST[$request_name]), $pl, $dir); echo '<wpadm>' . wpadm_pack($wpadm->getResult()->toArray()) . '</wpadm>'; exit; } }
function wpadm_run($pl, $dir) { require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-method-class.php'; $request_name = $pl . '_request'; if (isset($_POST[$request_name]) && !empty($_POST[$request_name])) { require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-core.php'; WPAdm_Core::$cron = false; $user_ip = wpadm_getIp(); if ($_SERVER['SERVER_ADDR'] != $user_ip && $_SERVER['HTTP_USER_AGENT'] != 'dropbox-backup user-agent') { WPAdm_Running::init_params_default(false); } $wpadm = new WPAdm_Core(wpadm_unpack($_POST[$request_name]), $pl, $dir); echo '<wpadm>' . wpadm_pack($wpadm->getResult()->toArray()) . '</wpadm>'; exit; } }
public static function dropbox_backup_create() { require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php"; @session_write_close(); $log = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir); if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) { @unlink(WPAdm_Core::getTmpDir() . "/logs2"); } if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) { file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", ''); } if (WPAdm_Core::dir_writeble(DROPBOX_BACKUP_DIR_BACKUP) && !file_exists(WPAdm_Core::getTmpDir() . "/create-backup")) { file_put_contents(WPAdm_Core::getTmpDir() . "/create-backup", 1); $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting'); $send_to_dropbox = true; if ($dropbox_options) { $dropbox_options = unserialize(base64_decode($dropbox_options)); if (!isset($dropbox_options['app_key'])) { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "App Key" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME)); $send_to_dropbox = false; } if (!isset($dropbox_options['app_secret'])) { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "App Secret" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME)); $send_to_dropbox = false; } if (!isset($dropbox_options['oauth_token'])) { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during file sending to Dropbox: "Auth Token not exist. Files cannot be sent to Dropbox cloud. Please, check your Dropbox settings."', false, '%d', SITE_HOME)); $send_to_dropbox = false; } } else { WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during connection to Dropbox: "app key" and "app secret" wasn\'t found. Please, check your Dropbox settings.', false, '%d', SITE_HOME)); $res['type'] = 'local'; $send_to_dropbox = false; } if ($send_to_dropbox) { parent::$type = 'full'; WPAdm_Running::init_params_default(); WPAdm_Running::delCommandResultData("local_backup"); $dropbox_options = self::getSettings(); $optimization = isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1 || !isset($dropbox_options['is_optimization']) ? 1 : 0; $backup_local = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files'))), 'full_backup_dropbox', WPAdm_Core::$pl_dir); $res = array(); if (WPAdm_Core::$cron === false) { $res = $backup->getResult()->toArray(); $res['md5_data'] = md5(print_r($res, 1)); $res['name'] = $backup->name; $res['time'] = $backup->time; $res['type'] = 'dropbox'; $res['counts'] = count($res['data']); } unset($backup_local); $folder_project = self::getNameProject(); WPAdm_Running::delCommandResultData("send-to-dropbox"); $backup = new WPAdm_Core(array('method' => "send-to-dropbox", 'params' => array('files' => isset($res['data']) ? $res['data'] : '', 'local' => true, 'access_details' => array('key' => $dropbox_options['app_key'], 'secret' => $dropbox_options['app_secret'], 'token' => $dropbox_options['auth_token_secret'], 'dir' => isset($res['name']) ? $res['name'] : '', 'folder' => $folder_project))), 'full_backup_dropbox', WPAdm_Core::$pl_dir); if (WPAdm_Core::$cron === false) { $result_send = $backup->getResult()->toArray(); if ($result_send['result'] == 'error') { $res = array(); $res['error'] = $result_send['error']; $res['result'] = 'error'; @rename(WPAdm_Core::getTmpDir() . "/logs2", WPAdm_Core::getTmpDir() . "/logs_error_" . $backup_local->time); } WPAdm_Core::rmdir(DROPBOX_BACKUP_DIR_BACKUP . "/{$res['name']}"); } else { set_transient('running_command', 'send-to-dropbox', 0); $res['result'] = 'work'; $res['error'] = ''; $res['data'] = array(); $res['size'] = 0; } if (file_exists(WPAdm_Core::getTmpDir() . "/create-backup")) { @unlink(WPAdm_Core::getTmpDir() . "/create-backup"); } } } else { $res['result'] = 'error'; $res['error'] = langWPADM::get('Website "%domain" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir-backup".', false, array('%domain', '%dir-backup'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP)); $res['data'] = array(); $res['size'] = 0; } @session_start(); echo json_encode($res); wp_die(); }
public static function restore_backup() { require_once dirname(__FILE__) . "/class-wpadm-core.php"; @session_write_close(); $log = new WPAdm_Core(array('method' => "local"), 'db_backup_s3', dirname(__FILE__)); if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) { unlink(WPAdm_Core::getTmpDir() . "/logs2"); } if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) { unlink(WPAdm_Core::getTmpDir() . "/log.log"); } $res['error'] = 'Error'; $res['result'] = 'error'; parent::$type = 'db'; if (isset($_POST['type'])) { $name_backup = isset($_POST['name']) ? trim($_POST['name']) : ""; $dir = ABSPATH . 'wpadm_backups/' . $name_backup; if ($_POST['type'] == 'local') { $backup = new WPAdm_Core(array('method' => "local_restore", 'params' => array('types' => array('db'), 'name_backup' => $name_backup)), 'db_backup_s3', dirname(__FILE__)); $res = $backup->getResult()->toArray(); } elseif ($_POST['type'] == 's3') { $amazon_option = self::getAmazonOptions(); if ($amazon_option) { require_once dirname(__FILE__) . '/modules/aws-autoloader.php'; try { $credentials = new Aws\Common\Credentials\Credentials($amazon_option['access_key_id'], $amazon_option['secret_access_key']); $client = Aws\S3\S3Client::factory(array('credentials' => $credentials)); $project = self::getNameProject(); WPAdm_Core::log("Get Files for Resore Backup"); $keys = $client->listObjects(array('Bucket' => $amazon_option['bucket'], 'Prefix' => $name_backup))->getIterator(); //->getPath('Contents/*/Key'); if (isset($keys['Contents'])) { $n = count($keys['Contents']); WPAdm_Core::mkdir($dir); WPAdm_Core::log("Start Downloads files with Amazon S3"); for ($i = 0; $i < $n; $i++) { $path = explode("/", $keys['Contents'][$i]['Key']); if (isset($path[0]) && isset($path[1]) && !empty($path[1])) { $result = $client->getObject(array('Bucket' => $amazon_option['bucket'], 'Key' => $keys['Contents'][$i]['Key'], 'SaveAs' => ABSPATH . 'wpadm_backups/' . $keys['Contents'][$i]['Key'])); WPAdm_Core::log("Download file - {$keys['Contents'][$i]['Key']}"); } } WPAdm_Core::log("End downloads files with Amazon S3"); $restore = new WPAdm_Core(array('method' => "local_restore", 'params' => array('log-delete' => 0, 'types' => array('db'), 'name_backup' => $name_backup)), 'db_backup_s3', dirname(__FILE__)); $res = $restore->getResult()->toArray(); if (is_dir($dir)) { WPAdm_Core::rmdir($dir); } } else { $res['error'] = "Error, in downloads with Amazon S3"; $res['result'] = 'error'; } } catch (Exception $e) { $res['error'] = $e->getMessage(); $res['result'] = 'error'; } catch (S3Exception $e) { $res['error'] = $e->getMessage(); $res['result'] = 'error'; } } else { $res['error'] = 'Error: Data is not exist for send backup files to Amazon S3. Please type your Data in the Settings form'; $res['result'] = 'error'; } } } @session_start(); echo json_encode($res); wp_die(); }