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;
 }
 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)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/aws-autoloader.php';
     $credentials = new Aws\Common\Credentials\Credentials($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     $client = Aws\S3\S3Client::factory(array('credentials' => $credentials));
     $dir = $context->get('dir') ? $context->get('dir') . "/" : '';
     try {
         if (!empty($dir)) {
             $logs = $client->putObject(array('Bucket' => $context->get('bucket'), 'Key' => $dir, 'Body' => ''));
             WPAdm_Core::log('Create folder ' . $dir);
         }
         $filePath = preg_replace('#[/\\\\]+#', '/', $context->get('file'));
         $key = $dir ? $dir . '/' . basename($filePath) : basename($filePath);
         $key = ltrim(preg_replace('#[/\\\\]+#', '/', $key), '/');
         //if first will be '/', file not will be uploaded, but result will be ok
         $putRes = $client->putObject(array("Bucket" => $context->get('bucket'), 'Key' => $key, 'Body' => fopen($filePath, 'r+')));
         if ((int) $putRes == 1) {
             WPAdm_Core::log("File({$key}) Upload successfully to Amazon S3");
         }
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     } catch (S3Exception $e) {
         WPAdm_Core::log('error send file ' . $e->getMessage());
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }
 public function getResult()
 {
     global $wp_version;
     $this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
     if (!function_exists('get_plugins')) {
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
     }
     $plugin_name = array_pop(explode("/", WPAdm_Core::getPluginDir()));
     $plugin_name2 = str_replace("-", "_", $plugin_name);
     $plugin = get_plugins("/{$plugin_name}");
     $pl_version = "";
     if (isset($plugin["{$plugin_name}.php"])) {
         $pl_version = $plugin["{$plugin_name}.php"]['Version'];
     }
     if (isset($plugin["{$plugin_name2}.php"])) {
         $pl_version = $plugin["{$plugin_name2}.php"]['Version'];
     }
     $data_return = array('reply' => 'pong', 'date' => array('time_zone' => date('O'), 'time' => time()), 'system_version' => $wp_version, 'plugin_version' => $pl_version, 'system' => 'wordpress');
     //get info for minimal requirements
     $data_return['php_version'] = @phpversion();
     $data_return['php_max_execution_time'] = @intval(ini_get('max_execution_time'));
     $data_return['php_memory_limit'] = @ini_get('memory_limit');
     $data_return['php_extensions'] = @implode(',', get_loaded_extensions());
     $data_return['php_disabled_functions'] = @ini_get('disable_functions');
     $data_return['php_max_execution_time_up'] = 0;
     $data_return['php_memory_limit_up'] = 0;
     $data_return['mysql_version'] = '';
     $data_return['suhosin_functions_blacklist'] = '';
     //try set new max time
     $newMaxExecutionTime = 3000;
     @set_time_limit($newMaxExecutionTime);
     if (@intval(ini_get('max_execution_time')) == $newMaxExecutionTime) {
         $data_return['php_max_execution_time_up'] = 1;
     }
     //try set new memory limit
     $newMemoryLimit = 256;
     @ini_set('memory_limit', $newMemoryLimit . 'M');
     if (@intval(ini_get('memory_limit')) == $newMemoryLimit) {
         $data_return['php_memory_limit_up'] = 1;
     }
     //try get mysql version
     $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD);
     if (!mysqli_connect_errno()) {
         $data_return['mysql_version'] = $mysqli->server_info;
     }
     //check suhosin
     if (extension_loaded('suhosin')) {
         $data_return['suhosin_functions_blacklist'] = @ini_get('suhosin.executor.func.blacklist');
     }
     $this->result->setData($data_return);
     return $this->result;
 }
 private function unpack($f, $to)
 {
     if (strpos($to, ABSPATH) === false) {
         $to = ABSPATH . $to;
     }
     require_once WPAdm_Core::getPluginDir() . '/modules/pclzip.lib.php';
     $this->archive = new PclZip($f);
     $res = $this->archive->extract(PCLZIP_OPT_PATH, WPAdm_Core::getPluginDir(), PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_REMOVE_PATH, WPAdm_Core::$plugin_name);
     WPAdm_Core::log($this->archive->errorInfo(true));
     if ($res) {
         return true;
     }
     return false;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     //WPAdm_Core::log(print_r($context, true));
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
     $mysqldump = new WPAdm_Mysqldump();
     $mysqldump->host = $context->get('host');
     $mysqldump->user = $context->get('user');
     $mysqldump->password = $context->get('password');
     try {
         $mysqldump->optimize($context->get('db'));
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }
Example #7
0
 public static function init()
 {
     $lang_wp = self::getLanguageSystem();
     $plugin_dir = WPAdm_Core::getPluginDir();
     self::$lang_dir = $plugin_dir . '/libs/lang/';
     if (isset($lang_wp)) {
         //self::downloadLang();
         if (file_exists(self::$lang_dir . $lang_wp . '.php')) {
             require_once self::$lang_dir . $lang_wp . '.php';
             self::$lang[$lang_wp] = $languag;
             self::$lang_name = $lang_wp;
             return true;
         }
     }
     return false;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
     $af = $this->getArchiveName($context->get('to_file'));
     $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
     $archive->setRemovePath($context->get('remove_path'));
     $files = $context->get('files');
     if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
         $af = $this->getNextArchiveName($context->get('to_file'));
         unset($archive);
         $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
         $archive->setRemovePath($context->get('remove_path'));
     }
     $archive->add(implode(',', $files));
     return true;
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
     $af = $this->getArchiveName($context->get('to_file'));
     $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
     $archive->setRemovePath($context->get('remove_path'));
     $files = $context->get('files');
     // если привышен максимальный размер архива, создадим новый
     if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
         //WPAdm_Core::log(filesize($af) . ', max=' . $context->get('max_file_size'));
         $af = $this->getNextArchiveName($context->get('to_file'));
         unset($archive);
         $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
         $archive->setRemovePath($context->get('remove_path'));
     }
     //WPAdm_Core::log('Add to archive ' . $af);
     $archive->add(implode(',', $files));
     return true;
 }
 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("Decompression Archive " . 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("ERROR Archived: " . $this->archive->errorInfo(true));
             $context->setError("ERROR Archived: " . $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("File Archive Not Exist " . $context->get('zip_file'));
         WPAdm_Core::log("File Archive Not Exist " . $context->get('zip_file'));
         return false;
     }
     return true;
 }
 /**
  * @param string $com
  * @return command
  */
 static function getCommand($com = '')
 {
     if (!preg_match("|[a-zA-Z0-9_]|", $com)) {
         return null;
     }
     $com = mb_strtolower($com);
     $tmp = explode('_', $com);
     $class_file = WPAdm_Core::getPluginDir() . "/commands/class-wpadm-command-" . str_replace('_', '-', $com) . ".php";
     if (file_exists($class_file)) {
         require_once $class_file;
         foreach ($tmp as $k => $v) {
             $tmp[$k] = ucfirst($v);
         }
         $com = implode('_', $tmp);
         $class_name = "WPAdm_Command_{$com}";
         return new $class_name();
     }
     return null;
 }
 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;
 }
 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;
 }
 private function testKeys($params)
 {
     $str = 'test string';
     if (!function_exists('openssl_public_decrypt')) {
         // зашифруем строку
         openssl_private_encrypt($str, $sign, $params['private']);
         // проверим подпись
         openssl_public_decrypt($sign, $str2, $params['public']);
         $ret = $str == $str2;
     } else {
         set_include_path(get_include_path() . PATH_SEPARATOR . WPAdm_Core::getPluginDir() . '/modules/phpseclib');
         require_once 'Crypt/RSA.php';
         // зашифруем строку
         define('CRYPT_RSA_PKCS15_COMPAT', true);
         $rsa = new Crypt_RSA();
         $rsa->loadKey($params['private']);
         $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
         $ciphertext = $rsa->encrypt($str);
         // проверим подпись
         $rsa = new Crypt_RSA();
         $rsa->loadKey($params['public']);
         $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
         $ret = $str == $rsa->decrypt($ciphertext);
     }
     $this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
     $this->result->setData(array('match' => (int) $ret));
 }
 public function execute(WPAdm_Command_Context $context)
 {
     require_once WPAdm_Core::getPluginDir() . '/modules/S3.php';
     $s3 = new S3($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     //new S3Wrapper();
     //S3::setAuth($context->get('AccessKeyId'), $context->get('SecretAccessKey'));
     /*(array(
       'key'    => $context->get('AccessKeyId'),
       'secret' => $context->get('SecretAccessKey'),
       'token'  => $context->get('SessionToken')
       ));   */
     // $s3->setTimeCorrectionOffset(60);
     $dir = $context->get('dir') ? $context->get('dir') : '';
     if ($dir) {
         //$s3->mkdir('s3://' . $context->get('bucket') . '/' . $dir);
         $logs = $s3->putObject($dir, $context->get('bucket'), $dir . "/", s3::ACL_PUBLIC_READ);
         //$logs = $s3->putObjectString($dir, $context->get('bucket'), $context->get('bucket') . '/' . $dir, s3::ACL_PUBLIC_READ_WRITE);
         WPAdm_Core::log('create folder logs ' . serialize($logs));
         /*$s3->registerStreamWrapper("s3");
           @mkdir('s3://'.$context->get('bucket').'/'.$dir);*/
     }
     try {
         $filePath = preg_replace('#[/\\\\]+#', '/', $context->get('file'));
         $key = $dir ? $dir . '/' . basename($filePath) : basename($filePath);
         $key = ltrim(preg_replace('#[/\\\\]+#', '/', $key), '/');
         //if first will be '/', file not will be uploaded, but result will be ok
         $putRes = $s3->putObjectFile($filePath, $context->get('bucket'), $key, s3::ACL_PUBLIC_READ_WRITE);
         WPAdm_Core::log('putObjectFile ' . $filePath . ' == ' . $context->get('bucket') . " == " . $key . ' == ' . (int) $putRes);
     } catch (Exception $e) {
         $context->setError($e->getMessage());
         return false;
     } catch (S3Exception $e) {
         WPAdm_Core::log('error send file ' . $e->getMessage());
         $context->setError($e->getMessage());
         return false;
     }
     return true;
 }