public function execute(WPAdm_Command_Context $context) { ini_set("memory_limit", "256M"); require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php'; $af = $this->getArchiveName($context->get('to_file')); ini_set("memory_limit", "256M"); $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5'); $archive->setRemovePath($context->get('remove_path')); $files = $context->get('files'); if (!file_exists($af)) { WPAdm_Core::log(langWPADM::get('Create part ', false) . basename($af)); } if (file_exists($af) && filesize($af) > $context->get('max_file_size')) { $af = $this->getNextArchiveName($context->get('to_file')); unset($archive); if (!file_exists($af)) { WPAdm_Core::log(langWPADM::get('Create part ', false) . basename($af)); } $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5'); $archive->setRemovePath($context->get('remove_path')); } $files_str = implode(',', $files); $files_archive = WPAdm_Running::getCommandResultData('archive'); if (!in_array($files_str, $files_archive)) { $archive->add($files_str); $files_archive = WPAdm_Running::getCommandResultData('archive'); $files_archive[] = $files_str; if (!empty($files_archive)) { WPAdm_Running::setCommandResultData('archive', $files_archive); } } return true; }
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 wpadm_show_backup() { require_once DRBBACKUP_BASE_DIR . "/modules/dropbox.class.php"; parent::$type = 'full'; $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting'); if ($dropbox_options) { $dropbox_options = unserialize(base64_decode($dropbox_options)); if (isset($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && isset($dropbox_options['auth_token_secret'])) { $dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']); $folder_project = self::getNameProject(); $backups = $dropbox->listing($folder_project); $n = count($backups['items']); $data['data'] = array(); for ($i = 0; $i < $n; $i++) { $backup = $dropbox->listing($folder_project . "/" . $backups['items'][$i]['name']); $data['data'][$i]['name'] = $backups['items'][$i]['name']; $data['data'][$i]['size'] = (double) $backup['size'] * 1024 * 1024; $data['data'][$i]['dt'] = parent::getDateInName($backups['items'][$i]['name']); $data['data'][$i]['count'] = count($backup['items']); $data['data'][$i]['type'] = 'dropbox'; $k = $data['data'][$i]['count']; $data['data'][$i]['files'] = '['; for ($j = 0; $j < $k; $j++) { $data['data'][$i]['files'] .= $backup['items'][$j]['name'] . ','; } } } } if (isset($_GET['pay']) && $_GET['pay'] == 'success') { if (!file_exists(WPAdm_Core::getTmpDir() . "/pay_success")) { file_put_contents(WPAdm_Core::getTmpDir() . "/pay_success", 1); parent::setMessage(langWPADM::get('', false)); } } if (isset($_GET['pay']) && $_GET['pay'] == 'cancel') { parent::setError(langWPADM::get('Checkout was canceled', false)); } $data_local = parent::read_backups(); if (isset($data['data'])) { $data['data'] = array_merge($data_local['data'], $data['data']); $data['md5'] = md5(print_r($data['data'], 1)); } else { $data = $data_local; } if (file_exists(WPAdm_Core::getTmpDir() . "/pay_success")) { $plugin_info = get_plugins("/" . parent::$plugin_name); $plugin_version = isset($plugin_info[parent::$plugin_name . '.php']['Version']) ? $plugin_info[parent::$plugin_name . '.php']['Version'] : ''; $data_server = parent::sendToServer(array('actApi' => "proBackupCheck", 'site' => home_url(), 'email' => get_option('admin_email'), 'plugin' => parent::$plugin_name, 'key' => '', 'plugin_version' => $plugin_version)); if (isset($data_server['status']) && $data_server['status'] == 'success' && isset($data_server['key'])) { update_option(PREFIX_BACKUP_ . 'pro-key', $data_server['key']); if (isset($data_server['url']) && !empty($data_server['url'])) { parent::setMessage(str_replace('&s', $data_server['url'], langWPADM::get('The "Dropbox backup & restore PRO" version can be downloaded here <a href="&s">download</a>', false))); } } } if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $stars5 = file_exists(WPAdm_Core::getTmpDir() . "/notice-star"); $plugin_data = array_values(get_plugins('/dropbox-backup')); $is_runnig = WPAdm_Running::is_running(); $show = !get_option('wpadm_pub_key') && is_super_admin(); $error = parent::getError(true); $msg = parent::getMessage(true); $base_path = DRBBACKUP_BASE_DIR; ob_start(); require_once $base_path . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show_backup.php"; echo ob_get_clean(); }
private function saveDataCommand($file) { $data_command = WPAdm_Running::getCommandResultData('command_dropbox'); $data_command[] = $file; WPAdm_Running::setCommandResultData('command_dropbox', $data_command); }
public function getResult() { $errors = array(); $this->id = uniqid('wpadm_method_send_to_dropbox_'); $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS); $this->result->setError(''); if (isset($this->params['local']) && $this->params['local']) { $params_data_cron = WPAdm_Running::getCommandResultData('local_backup'); $this->params['files'] = $params_data_cron['data']; $this->params['access_details']['dir'] = $params_data_cron['name']; WPAdm_Core::log(langWPADM::get('', false)); } $this->queue = new WPAdm_Queue($this->id); $ad = $this->params['access_details']; $this->queue->clear(); $files = $this->params['files']; //$this->getResult()->setData($files); $dir = isset($ad['dir']) ? $ad['dir'] : '/'; //$dir = trim($dir, '/') . '/' . $this->name; if (is_array($files)) { $send = false; foreach ($files as $file) { if (isset($this->params['local']) && $this->params['local']) { $data_command = WPAdm_Running::getCommandResultData('command_dropbox'); $data_error_command = WPAdm_Running::getCommandResultData('errors_sending'); if (isset($data_error_command[ABSPATH . $file]) && $data_error_command[ABSPATH . $file]['count'] > WPADM_COUNT_LIMIT_SEND_TO_DROPBOX) { $msg = langWPADM::get('Not perhaps sending file: "%file%". If you wish make upload file, increase execution time code or speed internet provider is small for upload file.', false, '%file%', $file); WPAdm_Core::log($msg); $errors[] = $msg; break; } if (!empty($data_command) && in_array(ABSPATH . $file, $data_command)) { continue; } } $commandContext = new WPAdm_Command_Context(); $commandContext->addParam('command', 'send_to_dropbox')->addParam('key', $ad['key'])->addParam('secret', $ad['secret'])->addParam('token', $ad['token'])->addParam('folder_project', $ad['folder'])->addParam('folder', $dir)->addParam('files', ABSPATH . $file); if (isset($this->params['local']) && $this->params['local']) { $commandContext->addParam('local', true); } $this->queue->add($commandContext); unset($commandContext); $send = true; } } if ($send) { WPAdm_Core::log(langWPADM::get('Start copy to Dropbox Cloud', false)); $res = $this->queue->save()->execute(); WPAdm_Core::log(langWPADM::get('End Copy Files to Dropbox', false)); } if (isset($res) && !$res) { WPAdm_Core::log(langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError()); $errors[] = langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError(); } if (count($errors) > 0) { $this->result->setError(implode("\n", $errors)); $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR); } else { if (class_exists('wpadm_wp_full_backup_dropbox') && !file_exists(WPAdm_Core::getTmpDir() . "/notice-star")) { wpadm_wp_full_backup_dropbox::setFlagToTmp('notice-star', time() . "_1d"); } if (isset($this->params['local']) && $this->params['local'] && isset($params_data_cron)) { $this->result->setData($this->params['files']); $this->result->setSize($params_data_cron['size']); $this->result->setValue('md5_data', md5(print_r($this->result->toArray(), 1))); $this->result->setValue('name', $params_data_cron['name']); $this->result->setValue('time', $params_data_cron['time']); $this->result->setValue('type', 'dropbox'); $this->result->setValue('counts', $params_data_cron['counts']); WPAdm_Core::rmdir(DROPBOX_BACKUP_DIR_BACKUP . "/{$params_data_cron['name']}"); } } return $this->result; }
/** * @param string $method * @param mixed $params * @return null|WPAdm_Method_Class */ private function getObject($method, $params) { if (!preg_match("|[a-zA-Z0-9_\\-]|", $method)) { return null; } if (function_exists('mb_strtolower')) { $method = mb_strtolower($method); } else { $method = strtolower($method); } $class_file = self::$pl_dir . "/methods/class-wpadm-method-" . str_replace('_', '-', $method) . ".php"; if (file_exists($class_file)) { require_once $class_file; $tmp = explode('_', str_replace('-', '_', $method)); foreach ($tmp as $k => $m) { $tmp[$k] = ucfirst(strtolower($m)); } $method = implode('_', $tmp); $class_name = "WPAdm_Method_{$method}"; if (!class_exists($class_name)) { $this->getResult()->setError("Class '{$class_name}' not found"); $this->getResult()->setResult(WPAdm_result::WPADM_RESULT_ERROR); return null; } if (in_array(strtolower($method), self::$cron_method) && self::$cron) { WPAdm_Running::setCommand(strtolower($this->request['method']), $params); WPAdm_Running::run(); self::$cron = true; return true; } else { return new $class_name($params); } } return null; }
static function getCommandResultData($command) { if (self::$command_result == $command) { return self::$command_result_data; } else { $path = WPAdm_Core::getTmpDir(); if (file_exists($path . "/{$command}")) { self::$command_result_data = wpadm_unpack(file_get_contents($path . "/{$command}")); return self::$command_result_data; } } return array(); }
public function getResult() { $errors = array(); $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS); $this->result->setError(''); WPAdm_Core::log(langWPADM::get('Start Backup process...', false)); # create db dump if (in_array('db', $this->params['types'])) { $mysql_dump_file = DROPBOX_BACKUP_DIR_BACKUP . '/mysqldump.sql'; if (!WPAdm_Running::getCommandResult('db')) { WPAdm_Running::setCommandResult('db'); WPAdm_Core::log(langWPADM::get('Creating Database Dump', false)); $error = WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP); if (!empty($error)) { $this->result->setError($error); $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR); return $this->result; } if (file_exists($mysql_dump_file) && !file_exists(WPAdm_Core::getTmpDir() . "/db")) { unlink($mysql_dump_file); } $wp_mysql_params = $this->getWpMysqlParams(); if (isset($this->params['optimize']) && $this->params['optimize'] == 1) { $opt_db = WPAdm_Running::getCommandResultData('db', $proc_data); if (!isset($opt_db['optimize'])) { WPAdm_Core::log(langWPADM::get('Optimize Database Tables', false)); $commandContext = new WPAdm_Command_Context(); $commandContext->addParam('command', 'mysqloptimize')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password']); $this->queue->clear()->add($commandContext); unset($commandContext); } } $commandContext = new WPAdm_Command_Context(); $commandContext->addParam('command', 'mysqldump')->addParam('host', $wp_mysql_params['host'])->addParam('db', $wp_mysql_params['db'])->addParam('user', $wp_mysql_params['user'])->addParam('password', $wp_mysql_params['password'])->addParam('tables', '')->addParam('to_file', $mysql_dump_file); $res = $this->queue->add($commandContext)->save()->execute(); if (!$res) { $log = langWPADM::get('Website "%domain" returned an error during database dump creation: \'Dump of Database wasn\'t created: "%s"\'. To solve this problem, please check your database system logs or send to us your FTP access data. You can send to us support request using "Help" button on plugin page.', false, array('%domain', '%s'), array(SITE_HOME, $this->queue->getError())); WPAdm_Core::log($log); $errors[] = $log; } elseif (0 == (int) filesize($mysql_dump_file)) { $log = langWPADM::get('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".', false, array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP)); $errors[] = $log; WPAdm_Core::log($log); } else { $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2); $log = str_replace("%size", $size_dump, langWPADM::get('Database Dump was successfully created ( %size Mb) : ', false)); WPAdm_Core::log($log . $mysql_dump_file); } unset($commandContext); WPAdm_Running::setCommandResult('db', true); } } if (count($errors) == 0) { $command_files_list = WPAdm_Running::getCommandResultData('files'); if (in_array('files', $this->params['types']) && empty($command_files_list)) { $files = $this->createListFilesForArchive(); WPAdm_Running::setCommandResultData('files', $files); } else { $files = $command_files_list; } if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) { $files[] = $mysql_dump_file; } if (empty($files)) { $errors[] = langWPADM::get('Website "%d" returned an error during creation of the list of files for a backup: list of files for a backup is empty. To solve this problem, please check files and folders permissions for website "%d".', false, array('%d'), array(SITE_HOME)); } // split the file list by 170kbayt lists, To break one big task into smaller $files2 = WPAdm_Running::getCommandResultData('files2'); if (empty($files2)) { $files2 = array(); $files2[0] = array(); $i = 0; $size = 0; foreach ($files as $f) { if ($size > 170000) { //~170kbyte $i++; $size = 0; $files2[$i] = array(); } $f_size = (int) @filesize($f); if ($f_size == 0 || $f_size > 1000000) { WPAdm_Core::log('File ' . $f . ' Size ' . $f_size); } $size += $f_size; $files2[$i][] = $f; } WPAdm_Running::setCommandResultData('files2', $files2); } WPAdm_Core::log(langWPADM::get('List of Backup-Files was successfully created', false)); $this->queue->clear(); if (!WPAdm_Running::getCommandResult('archive')) { WPAdm_Running::setCommandResult('archive'); $files_archive = WPAdm_Running::getCommandResultData('archive'); foreach ($files2 as $files) { $files_str = implode(',', $files); if (!in_array($files_str, $files_archive)) { $commandContext = new WPAdm_Command_Context(); $commandContext->addParam('command', 'archive')->addParam('files', $files)->addParam('to_file', $this->dir . '/' . $this->name)->addParam('max_file_size', 900000)->addParam('remove_path', ABSPATH); $this->queue->add($commandContext); unset($commandContext); } } WPAdm_Core::log(langWPADM::get('Backup of Files was started', false)); $this->queue->save()->execute(); WPAdm_Core::log(langWPADM::get('End of File Backup', false)); WPAdm_Running::setCommandResult('archive', true); } $files = glob($this->dir . '/' . $this->name . '*'); $urls = array(); $totalSize = 0; foreach ($files as $file) { $urls[] = str_replace(ABSPATH, '', $file); $totalSize += @intval(filesize($file)); } $this->result->setData($urls); $this->result->setSize($totalSize); $this->result->setValue('md5_data', md5(print_r($this->result->toArray(), 1))); $this->result->setValue('name', $this->name); $this->result->setValue('time', $this->time); $this->result->setValue('type', 'local'); $this->result->setValue('counts', count($urls)); $size = $totalSize / 1024 / 1024; /// MByte $size = round($size, 2); $log = str_replace("%s", $size, langWPADM::get('Backup Size %s Mb', false)); WPAdm_Core::log($log); $remove_from_server = 0; #Removing TMP-files WPAdm_Core::rmdir($mysql_dump_file); #Removind old backups(if limit the number of stored backups) if ($this->params['limit'] != 0) { WPAdm_Core::log(langWPADM::get('Limits of Backups ', false) . $this->params['limit']); WPAdm_Core::log(langWPADM::get('Removing of old Backups was started', false)); $files = glob(DROPBOX_BACKUP_DIR_BACKUP . '/*'); if (count($files) > $this->params['limit']) { $files2 = array(); foreach ($files as $f) { $fa = explode('-', $f); if (count($fa) != 3) { continue; } $files2[$fa[2]] = $f; } ksort($files2); $d = count($files2) - $this->params['limit']; $del = array_slice($files2, 0, $d); foreach ($del as $d) { WPAdm_Core::rmdir($d); } } WPAdm_Core::log(langWPADM::get('Removing of old Backups was Finished', false)); } } wpadm_class::setBackup(1); if (!empty($errors)) { $this->result->setError(implode("\n", $errors)); $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR); WPAdm_Core::rmdir($this->dir); wpadm_class::setStatus(0); wpadm_class::setErrors(implode(", ", $errors)); } else { wpadm_class::setStatus(1); WPAdm_Core::log(langWPADM::get('Backup creation was complete successfully!', false)); } wpadm_class::backupSend(); return $this->result; }
public function mysqldump($db, $filename) { $proc_data = WPAdm_Running::getCommandResultData('db'); if (!isset($proc_data['mysqldump'])) { $link = $this->connect($db); WPAdm_Core::log(langWPADM::get('MySQL of Dump was started', false)); $tables = array(); $n = $link->query('SHOW TABLES'); $result = $link->last_result; if (!empty($link->last_error)) { $this->setError($link->last_error); return false; } if ($link->last_result === null) { /* foreach($link->error->errors as $key => $errors) { if ($key == db_connect_fail) }*/ $this->setError(print_r(implode("\n", $link->error->errors), 1)); return false; } for ($i = 0; $i < $n; $i++) { $row = array_values(get_object_vars($result[$i])); $tables[] = $row[0]; } foreach ($tables as $table) { $return = ''; $proc_data = WPAdm_Running::getCommandResultData('db'); if (!isset($proc_data['mysqldump_table'][$table])) { $result = $link->last_result; if (!empty($link->last_error) && $n > 0) { $this->setError($link->last_error); } $return .= 'DROP TABLE IF EXISTS ' . $table . ';'; $ress = $link->query('SHOW CREATE TABLE ' . $table); $result2 = $link->last_result; if (!empty($link->last_error) && $n > 0) { $this->setError($link->last_error); } $row2 = array_values(get_object_vars($result2[0])); $return .= "\n\n" . $row2[1] . ";\n\n"; file_put_contents($filename, $return, FILE_APPEND); $proc_data = WPAdm_Running::getCommandResultData('db'); $proc_data['mysqldump_table'][$table] = 1; WPAdm_Running::setCommandResultData('db', $proc_data); $log = str_replace('%s', $table, langWPADM::get('Add a table "%s" in the database dump', false)); WPAdm_Core::log($log); } $while = true; while ($while) { $table_db = WPAdm_Running::getCommandResultData('tabledb'); if (isset($table_db[$table])) { if (isset($table_db[$table]['work']) && $table_db[$table]['work'] == true) { $from = $table_db[$table]['from']; // value from $to = $table_db[$table]['to']; // value to } } else { $from = 0; $to = $this->rows; } if (isset($from) && !empty($to) && $from >= 0 && $to >= 0) { unset($link); $link = $this->connect($db); $num_fields = $link->query('SELECT * FROM ' . $table . " LIMIT {$from}, {$to}"); if ($num_fields > 0) { $result2 = $link->last_result; for ($i = 0; $i < $num_fields; $i++) { $return = ''; $row = array_values(get_object_vars($result2[$i])); //WPAdm_Core::log('row' . print_r($row, 1)); $rows_num = count($row); if ($rows_num > 0) { $return .= 'INSERT INTO ' . $table . ' VALUES('; for ($j = 0; $j < $rows_num; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = str_replace("\n", "\\n", $row[$j]); if (isset($row[$j])) { $return .= '"' . $row[$j] . '"'; } else { $return .= '""'; } if ($j < $rows_num - 1) { $return .= ','; } } $return .= ");\n"; file_put_contents($filename, $return, FILE_APPEND); $from += 1; $table_db[$table]['from'] = $from; $table_db[$table]['to'] = $to; $table_db[$table]['work'] = true; WPAdm_Running::setCommandResultData('tabledb', $table_db); } } $log = str_replace(array('%s', '%from%', '%to%'), array($table, $from, $to), langWPADM::get('Add a table rows "%s" in the database dump from %from% to %to%', false)); WPAdm_Core::log($log); } else { $while = false; $table_db[$table]['work'] = false; WPAdm_Running::setCommandResultData('tabledb', $table_db); } } else { $while = false; $table_db[$table]['work'] = false; WPAdm_Running::setCommandResultData('tabledb', $table_db); } } if (!isset($proc_data['mysqldump_table'][$table])) { $return = "\n\n\n"; file_put_contents($filename, $return, FILE_APPEND); } } unset($link); WPAdm_Core::log(langWPADM::get('MySQL of Dump was finished', false)); $proc_data = WPAdm_Running::getCommandResultData('db'); $proc_data['mysqldump'] = true; WPAdm_Running::setCommandResultData('db', $proc_data); return true; } else { return false; } }