public function import_settings()
 {
     $file_url = base64_decode($_POST['file_url']);
     $temporary_file = '';
     try {
         include_once ABSPATH . 'wp-admin/includes/file.php';
         //Contains download_url
         $temporary_file = download_url($file_url);
         if (is_wp_error($temporary_file)) {
             throw new Exception('Error: ' . $temporary_file->get_error_message());
         } else {
             if ($this->import_seo_settings($temporary_file)) {
                 $information['success'] = true;
             } else {
                 throw new Exception(__('Settings could not be imported:', 'wordpress-seo'));
             }
         }
     } catch (Exception $e) {
         $information['error'] = $e->getMessage();
     }
     if (file_exists($temporary_file)) {
         unlink($temporary_file);
     }
     MainWP_Helper::write($information);
 }
 function mainwp_skeleton_key_handle_fatal_error()
 {
     $error = error_get_last();
     if (isset($error['type']) && in_array($error['type'], array(1, 4, 16, 64, 256)) && isset($error['message'])) {
         MainWP_Helper::write(array('error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file']));
     } else {
         MainWP_Helper::write(MainWP_Child_Skeleton_Key::$information);
     }
 }
 public function action()
 {
     $information = array();
     if (!class_exists('WooCommerce')) {
         $information['error'] = 'NO_WOOCOMMERCE';
         MainWP_Helper::write($information);
     }
     $is_ver220 = $this->is_version_220();
     if (isset($_POST['mwp_action'])) {
         switch ($_POST['mwp_action']) {
             case 'sync_data':
                 $information = !$is_ver220 ? $this->sync_data() : $this->sync_data_two();
                 break;
             case 'report_data':
                 $information = !$is_ver220 ? $this->report_data() : $this->report_data_two();
                 break;
         }
     }
     MainWP_Helper::write($information);
 }
 function custom_login_css()
 {
     $extra_setting = $this->settings['extra_settings'];
     if (is_array($extra_setting) && isset($extra_setting['login_css']) && !empty($extra_setting['login_css'])) {
         echo '<style>' . MainWP_Helper::parse_css($extra_setting['login_css']) . '</style>';
     }
 }
 function save_settings()
 {
     global $itsec_globals;
     if (!class_exists('ITSEC_Lib')) {
         require trailingslashit($itsec_globals['plugin_dir']) . '/core/class-itsec-lib.php';
     }
     MainWP_Helper::update_option('mainwp_ithemes_ext_enabled', 'Y', 'yes');
     $settings = maybe_unserialize(base64_decode($_POST['settings']));
     $updated = false;
     $rewrites_changed = false;
     if (isset($settings['itsec_global'])) {
         //            $old_settings = get_site_option( 'itsec_global' );
         //            // keep current value
         //            $settings['itsec_global']['log_location'] = $old_settings['log_location'];
         if (update_site_option('itsec_global', $settings['itsec_global'])) {
             if (isset($settings['itsec_global']['write_files']) && true === $settings['itsec_global']['write_files']) {
                 add_site_option('itsec_rewrites_changed', true);
                 $rewrites_changed = true;
             }
             $updated = true;
         }
     }
     if (isset($settings['itsec_away_mode'])) {
         if (update_site_option('itsec_away_mode', $settings['itsec_away_mode'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_backup'])) {
         $backup = get_site_option('itsec_backup');
         if (false !== $backup && isset($backup['last_run'])) {
             $settings['itsec_backup']['last_run'] = $backup['last_run'];
         } else {
             unset($settings['itsec_backup']['last_run']);
         }
         if (update_site_option('itsec_backup', $settings['itsec_backup'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_ban_users'])) {
         $old_settings = get_site_option('itsec_ban_users');
         if (update_site_option('itsec_ban_users', $settings['itsec_ban_users'])) {
             $input = $settings['itsec_ban_users'];
             if ($input['host_list'] !== $old_settings['host_list'] || $input['enabled'] !== $old_settings['enabled'] || $input['default'] !== $old_settings['default'] || $input['agent_list'] !== $old_settings['agent_list']) {
                 if (!$rewrites_changed) {
                     add_site_option('itsec_rewrites_changed', true);
                 }
             }
             $updated = true;
         }
     }
     if (isset($settings['itsec_brute_force'])) {
         if (update_site_option('itsec_brute_force', $settings['itsec_brute_force'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_file_change'])) {
         $file_change = get_site_option('itsec_file_change');
         if (false !== $file_change && isset($file_change['last_run'])) {
             $settings['itsec_file_change']['last_run'] = $file_change['last_run'];
         } else {
             unset($settings['itsec_file_change']['last_run']);
         }
         if (false !== $file_change && isset($file_change['last_chunk'])) {
             $settings['itsec_file_change']['last_chunk'] = $file_change['last_chunk'];
         } else {
             unset($settings['itsec_file_change']['last_chunk']);
         }
         if (update_site_option('itsec_file_change', $settings['itsec_file_change'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_four_oh_four'])) {
         if (update_site_option('itsec_four_oh_four', $settings['itsec_four_oh_four'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_hide_backend'])) {
         $old_settings = get_site_option('itsec_hide_backend');
         if (update_site_option('itsec_hide_backend', $settings['itsec_hide_backend'])) {
             $input = $settings['itsec_hide_backend'];
             if ($input['slug'] !== $old_settings['slug'] || $input['register'] !== $old_settings['register'] || $input['enabled'] !== $old_settings['enabled']) {
                 if (!$rewrites_changed) {
                     add_site_option('itsec_rewrites_changed', true);
                 }
             }
             if ($input['slug'] !== $old_settings['slug'] && true === $input['enabled']) {
                 add_site_option('itsec_hide_backend_new_slug', $input['slug']);
             }
             $updated = true;
         }
     }
     if (isset($settings['itsec_ipcheck'])) {
         if (update_site_option('itsec_ipcheck', $settings['itsec_ipcheck'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_malware'])) {
         if (update_site_option('itsec_malware', $settings['itsec_malware'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_ssl'])) {
         if (update_site_option('itsec_ssl', $settings['itsec_ssl'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_strong_passwords'])) {
         if (update_site_option('itsec_strong_passwords', $settings['itsec_strong_passwords'])) {
             $updated = true;
         }
     }
     if (isset($settings['itsec_tweaks'])) {
         $old_settings = get_site_option('itsec_tweaks');
         $is_safe = ITSEC_Lib::safe_jquery_version() === true;
         $raw_version = get_site_option('itsec_jquery_version');
         if (true !== $is_safe && false !== $raw_version) {
             $enable_set_safe_jquery = true;
         }
         if (!$enable_set_safe_jquery) {
             $settings['itsec_tweaks']['safe_jquery'] = 0;
         }
         if (update_site_option('itsec_tweaks', $settings['itsec_tweaks'])) {
             if ($input['protect_files'] !== $old_settings['protect_files'] || $input['directory_browsing'] !== $old_settings['directory_browsing'] || $input['request_methods'] !== $old_settings['request_methods'] || $input['suspicious_query_strings'] !== $old_settings['suspicious_query_strings'] || $input['non_english_characters'] !== $old_settings['non_english_characters'] || $input['comment_spam'] !== $old_settings['comment_spam'] || $input['disable_xmlrpc'] !== $old_settings['disable_xmlrpc'] || $input['uploads_php'] !== $old_settings['uploads_php']) {
                 if (!$rewrites_changed) {
                     add_site_option('itsec_rewrites_changed', true);
                 }
             }
             $updated = true;
         }
     }
     $site_status = array('username_admin_exists' => username_exists('admin') ? 1 : 0, 'user_id1_exists' => ITSEC_Lib::user_id_exists(1) ? 1 : 0, 'backup' => $this->backup_status(), 'permalink_structure' => get_option('permalink_structure'), 'is_multisite' => is_multisite() ? 1 : 0, 'users_can_register' => get_site_option('users_can_register') ? 1 : 0, 'force_ssl_login' => defined('FORCE_SSL_LOGIN') && FORCE_SSL_LOGIN === true ? 1 : 0, 'force_ssl_admin' => defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN === true ? 1 : 0, 'server_nginx' => ITSEC_Lib::get_server() === 'nginx' ? 1 : 0, 'lockouts_host' => $this->get_lockouts('host', true), 'lockouts_user' => $this->get_lockouts('user', true), 'lockouts_username' => $this->get_lockouts('username', true));
     $out = array();
     if ($updated) {
         $out['result'] = 'success';
     } else {
         $out['result'] = 'noupdate';
     }
     $out['site_status'] = $site_status;
     return $out;
 }
 public function update_config()
 {
     $return = array();
     $this->config = array('replace_max' => intval($_POST['replace_max']), 'replace_max_keyword' => intval($_POST['replace_max_keyword']), 'default_link_nofollow' => intval($_POST['default_link_nofollow']), 'default_link_newtab' => intval($_POST['default_link_newtab']), 'replace_keyword_in_h_tag' => intval($_POST['replace_keyword_in_h_tag']), 'default_link_class' => sanitize_text_field($_POST['default_link_class']), 'post_match_title' => intval($_POST['post_match_title']), 'redirection_folder' => sanitize_text_field($_POST['redirection_folder']), 'enable_post_type' => $_POST['enable_post_type'], 'enable_post_type_link' => $_POST['enable_post_type_link']);
     MainWP_Helper::update_option('mainwpKeywordLinks', 1, 'yes');
     // enable extension functions
     if (MainWP_Helper::update_option('mainwp_kwl_options', $this->config)) {
         $return['status'] = 'SUCCESS';
     }
     // force update
     $this->update_htaccess(true);
     return $return;
 }
Exemplo n.º 7
0
 public static function inExcludes($excludes, $value)
 {
     if (empty($value)) {
         return false;
     }
     if (null != $excludes) {
         foreach ($excludes as $exclude) {
             if (MainWP_Helper::endsWith($exclude, '*')) {
                 if (MainWP_Helper::startsWith($value, substr($exclude, 0, strlen($exclude) - 1))) {
                     return true;
                 }
             } else {
                 if ($value == $exclude) {
                     return true;
                 } else {
                     if (MainWP_Helper::startsWith($value, $exclude . '/')) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
 function remove_notices()
 {
     $remove_hooks['all_admin_notices'] = array('UpdraftPlus' => array('show_admin_warning_unreadablelog' => 10, 'show_admin_warning_nolog' => 10, 'show_admin_warning_unreadablefile' => 10), 'UpdraftPlus_BackupModule_dropbox' => array('show_authed_admin_warning' => 10), 'UpdraftPlus_BackupModule_googledrive' => array('show_authed_admin_success' => 10));
     foreach ($remove_hooks as $hook_name => $hooks) {
         foreach ($hooks as $class_name => $methods) {
             foreach ($methods as $method => $priority) {
                 MainWP_Helper::remove_filters_for_anonymous_class($hook_name, $class_name, $method, $priority);
             }
         }
     }
 }
 function set_showhide()
 {
     MainWP_Helper::update_option('mainwp_creport_ext_branding_enabled', 'Y', 'yes');
     $hide = isset($_POST['showhide']) && 'hide' === $_POST['showhide'] ? 'hide' : '';
     MainWP_Helper::update_option('mainwp_creport_branding_stream_hide', $hide);
     $information['result'] = 'SUCCESS';
     return $information;
 }
Exemplo n.º 10
0
 public function createBackupDB($filepath_prefix, $archiveExt = false, &$archiver = null)
 {
     $timeout = 20 * 60 * 60;
     //20minutes
     // @codingStandardsIgnoreStart
     @set_time_limit($timeout);
     @ini_set('max_execution_time', $timeout);
     $mem = '512M';
     @ini_set('memory_limit', $mem);
     // @codingStandardsIgnoreEnd
     /** @var $wpdb wpdb */
     global $wpdb;
     $db_files = array();
     //Get all the tables
     $tables_db = $wpdb->get_results('SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N);
     foreach ($tables_db as $curr_table) {
         if (null !== $archiver) {
             $archiver->updatePidFile();
         }
         $table = $curr_table[0];
         $currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename($table) . '.sql';
         $db_files[] = $currentfile;
         if (file_exists($currentfile)) {
             continue;
         }
         $fh = fopen($currentfile . '.tmp', 'w');
         //or error;
         fwrite($fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';');
         //todo fix this
         //$table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N );
         $table_create = $wpdb->get_row('SHOW CREATE TABLE ' . $table, ARRAY_N);
         fwrite($fh, "\n" . $table_create[1] . ";\n\n");
         // @codingStandardsIgnoreStart
         $rows = @MainWP_Child_DB::_query('SELECT * FROM ' . $table, $wpdb->dbh);
         // @codingStandardsIgnoreEnd
         if ($rows) {
             $i = 0;
             $table_insert = 'INSERT INTO `' . $table . '` VALUES (';
             // @codingStandardsIgnoreStart
             while ($row = @MainWP_Child_DB::fetch_array($rows)) {
                 // @codingStandardsIgnoreEnd
                 $query = $table_insert;
                 foreach ($row as $value) {
                     $query .= '"' . MainWP_Child_DB::real_escape_string($value) . '", ';
                 }
                 $query = trim($query, ', ') . ');';
                 fwrite($fh, "\n" . $query);
                 $i++;
                 if ($i >= 50) {
                     fflush($fh);
                     $i = 0;
                 }
                 $query = null;
                 $row = null;
             }
         }
         $rows = null;
         fflush($fh);
         fclose($fh);
         rename($currentfile . '.tmp', $currentfile);
     }
     fclose(fopen($filepath_prefix . '.sql', 'w'));
     $db_files[] = $filepath_prefix . '.sql';
     $archivefilePath = null;
     if (false !== $archiveExt) {
         $archivefilePath = $filepath_prefix . '.sql.' . $archiveExt;
         if ('zip' === $archiveExt) {
             $this->archiver = null;
         } else {
             $this->archiver = new Tar_Archiver($this, $archiveExt);
         }
         if ($this->zipFile($db_files, $archivefilePath) && file_exists($archivefilePath)) {
             foreach ($db_files as $db_file) {
                 @unlink($db_file);
             }
         } else {
             //todo: throw exception!
         }
     }
     return false !== $archiveExt ? array('filepath' => $archivefilePath) : $db_files;
 }
Exemplo n.º 11
0
 public static function installPlugin($url, $activatePlugin = false)
 {
     $hasWPFileSystem = MainWP_Utility::getWPFilesystem();
     /** @global WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     if (file_exists(ABSPATH . '/wp-admin/includes/screen.php')) {
         include_once ABSPATH . '/wp-admin/includes/screen.php';
     }
     include_once ABSPATH . '/wp-admin/includes/template.php';
     include_once ABSPATH . '/wp-admin/includes/misc.php';
     include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . '/wp-admin/includes/plugin.php';
     $installer = new WP_Upgrader();
     $ssl_verifyhost = get_option('mainwp_sslVerifyCertificate');
     $ssl_api_verifyhost = get_option('mainwp_api_sslVerifyCertificate') === false || get_option('mainwp_api_sslVerifyCertificate') == 1 ? 1 : 0;
     if ($ssl_verifyhost === '0' || $ssl_api_verifyhost == 0) {
         add_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'noSSLFilterFunction'), 99, 2);
     }
     add_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'http_request_reject_unsafe_urls'), 99, 2);
     $result = $installer->run(array('package' => $url, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array()));
     remove_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'http_request_reject_unsafe_urls'), 99, 2);
     if ($ssl_verifyhost === '0') {
         remove_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'noSSLFilterFunction'), 99);
     }
     if (is_wp_error($result)) {
         if ($result->get_error_data() && is_string($result->get_error_data())) {
             $error = $result->get_error_data();
             MainWP_Helper::error($error);
         } else {
             $error = $result->get_error_code();
             MainWP_Helper::error(implode(', ', $error));
         }
     }
     $error = $output = $plugin_slug = null;
     if (is_wp_error($result)) {
         if ($result->get_error_data() && is_string($result->get_error_data())) {
             $error = $result->get_error_data();
         } else {
             $error = $result->get_error_code();
         }
     } else {
         $path = $result['destination'];
         foreach ($result['source_files'] as $srcFile) {
             // to fix bug
             if ($srcFile == 'readme.txt') {
                 continue;
             }
             $thePlugin = get_plugin_data($path . $srcFile);
             if ($thePlugin != null && $thePlugin != '' && $thePlugin['Name'] != '') {
                 $output .= __('Successfully installed the plugin', 'mainwp') . ' ' . $thePlugin['Name'] . ' ' . $thePlugin['Version'];
                 $plugin_slug = $result['destination_name'] . '/' . $srcFile;
                 if ($activatePlugin) {
                     activate_plugin($path . $srcFile, '', false, true);
                     do_action('mainwp_api_extension_activated', $path . $srcFile);
                 }
                 break;
             }
         }
     }
     if (!empty($error)) {
         $return['error'] = $error;
     } else {
         $return['result'] = 'SUCCESS';
         $return['output'] = $output;
         $return['slug'] = $plugin_slug;
     }
     return $return;
 }
 public function sendClick()
 {
     $url = $this->server . 'admin-ajax.php';
     $clickData = get_option('mainwp_child_click_data');
     $key = get_option('mainwp_child_pubkey');
     if (!is_array($clickData)) {
         return false;
     }
     // send 1000 record per time to fix memory bug
     $sendNow = array();
     if (count($clickData) > 1000) {
         for ($i = 0; $i < 1000; $i++) {
             $sendNow[] = $clickData[$i];
         }
     } else {
         $sendNow = $clickData;
     }
     $timestamp = time();
     $signature = $this->createSignature($key, $timestamp, $sendNow);
     $params = array('headers' => array('Referer' => site_url()), 'body' => array('timestamp' => $timestamp, 'signature' => $signature, 'data' => base64_encode(serialize($sendNow)), 'action' => 'heatmapSendClick'), 'timeout' => 30);
     if (strpos($url, 'https://') === 0) {
         $params['sslverify'] = false;
     }
     $request = wp_remote_post($url, $params);
     if (is_array($request) && isset($request['response']['code']) && 200 === (int) $request['response']['code']) {
         if (count($clickData) > 1000) {
             $saveData = array();
             $clickDataLength = count($clickData);
             for ($i = 1000; $i < $clickDataLength; $i++) {
                 $saveData[] = $clickData[$i];
             }
             MainWP_Helper::update_option('mainwp_child_click_data', $saveData);
         } else {
             delete_option('mainwp_child_click_data');
         }
     }
 }
Exemplo n.º 13
0
 public static function cloneBackupExtract()
 {
     try {
         MainWP_Helper::endSession();
         $file = isset($_POST['f']) ? $_POST['f'] : $_POST['file'];
         $testFull = false;
         if ('' === $file) {
             $dirs = MainWP_Helper::getMainWPDir('backup', false);
             $backupdir = $dirs[0];
             $files = glob($backupdir . 'download-*');
             $archiveFile = false;
             foreach ($files as $file) {
                 if (MainWP_Helper::isArchive($file, 'download-')) {
                     $archiveFile = $file;
                     break;
                 }
             }
             if (false === $archiveFile) {
                 throw new Exception(__('No download file found', 'mainwp-child'));
             }
             $file = $archiveFile;
         } else {
             if (file_exists($file)) {
                 $testFull = true;
             } else {
                 $file = ABSPATH . $file;
                 if (!file_exists($file)) {
                     throw new Exception(__('Backup file not found', 'mainwp-child'));
                 }
                 $testFull = true;
             }
         }
         //return size in kb
         $cloneInstall = new MainWP_Clone_Install($file);
         //todo: RS: refactor to get those plugins after install (after .18 release)
         $cloneInstall->readConfigurationFile();
         $plugins = get_option('mainwp_temp_clone_plugins');
         $themes = get_option('mainwp_temp_clone_themes');
         if ($testFull) {
             $cloneInstall->testDownload();
         }
         $cloneInstall->removeConfigFile();
         $cloneInstall->extractBackup();
         $pubkey = get_option('mainwp_child_pubkey');
         $uniqueId = get_option('mainwp_child_uniqueId');
         $server = get_option('mainwp_child_server');
         $nonce = get_option('mainwp_child_nonce');
         $nossl = get_option('mainwp_child_nossl');
         $nossl_key = get_option('mainwp_child_nossl_key');
         $sitesToClone = get_option('mainwp_child_clone_sites');
         $cloneInstall->install();
         $cloneInstall->updateWPConfig();
         //            $cloneInstall->update_option('mainwp_child_pubkey', $pubkey);
         //            $cloneInstall->update_option('mainwp_child_uniqueId', $uniqueId);
         //            $cloneInstall->update_option('mainwp_child_server', $server);
         //            $cloneInstall->update_option('mainwp_child_nonce', $nonce);
         //            $cloneInstall->update_option('mainwp_child_nossl', $nossl);
         //            $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key);
         //            $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone);
         //            $cloneInstall->update_option('mainwp_child_clone_permalink', true);
         MainWP_Helper::update_option('mainwp_child_pubkey', $pubkey, 'yes');
         MainWP_Helper::update_option('mainwp_child_uniqueId', $uniqueId);
         MainWP_Helper::update_option('mainwp_child_server', $server);
         MainWP_Helper::update_option('mainwp_child_nonce', $nonce);
         MainWP_Helper::update_option('mainwp_child_nossl', $nossl, 'yes');
         MainWP_Helper::update_option('mainwp_child_nossl_key', $nossl_key);
         MainWP_Helper::update_option('mainwp_child_clone_sites', $sitesToClone);
         if (!MainWP_Helper::startsWith(basename($file), 'download-backup-')) {
             MainWP_Helper::update_option('mainwp_child_restore_permalink', true, 'yes');
         } else {
             MainWP_Helper::update_option('mainwp_child_clone_permalink', true, 'yes');
         }
         $cloneInstall->clean();
         if (false !== $plugins) {
             $out = array();
             if (is_array($plugins)) {
                 $dir = WP_CONTENT_DIR . '/plugins/';
                 $fh = @opendir($dir);
                 while ($entry = @readdir($fh)) {
                     if (!is_dir($dir . $entry)) {
                         continue;
                     }
                     if ('.' === $entry || '..' === $entry) {
                         continue;
                     }
                     if (!in_array($entry, $plugins)) {
                         MainWP_Helper::delete_dir($dir . $entry);
                     }
                 }
                 @closedir($fh);
             }
             delete_option('mainwp_temp_clone_plugins');
         }
         if (false !== $themes) {
             $out = array();
             if (is_array($themes)) {
                 $dir = WP_CONTENT_DIR . '/themes/';
                 $fh = @opendir($dir);
                 while ($entry = @readdir($fh)) {
                     if (!is_dir($dir . $entry)) {
                         continue;
                     }
                     if ('.' === $entry || '..' === $entry) {
                         continue;
                     }
                     if (!in_array($entry, $themes)) {
                         MainWP_Helper::delete_dir($dir . $entry);
                     }
                 }
                 @closedir($fh);
             }
             delete_option('mainwp_temp_clone_themes');
         }
         $output = array('result' => 'ok');
         //todo: remove old tables if other prefix?
         wp_logout();
         wp_set_current_user(0);
     } catch (Exception $e) {
         $output = array('error' => $e->getMessage());
     }
     //return size in kb
     die(json_encode($output));
 }
Exemplo n.º 14
0
 public function compare($b, $a)
 {
     $pathA = $a->__toString();
     $pathB = $b->__toString();
     $dirnameA = is_file($pathA) ? dirname($pathA) : $pathA;
     $dirnameB = is_file($pathB) ? dirname($pathB) : $pathB;
     //if both are in the same folder, first show the files, then the directories
     if (dirname($pathA) == dirname($pathB)) {
         if (is_file($pathA) && !is_file($pathB)) {
             return -1;
         } else {
             if (!is_file($pathA) && is_file($pathB)) {
                 return 1;
             }
         }
         return strcmp($pathA, $pathB);
     } else {
         if ($dirnameA == $dirnameB) {
             return strcmp($pathA, $pathB);
         } else {
             if (MainWP_Helper::startsWith($dirnameA, $dirnameB)) {
                 return 1;
             } else {
                 if (MainWP_Helper::startsWith($dirnameB, $dirnameA)) {
                     return -1;
                 } else {
                     $cmp = strcmp($dirnameA, $dirnameB);
                     if (0 == $cmp) {
                         return strcmp($pathA, $pathB);
                     }
                     return $cmp;
                 }
             }
         }
     }
 }
 function set_showhide()
 {
     $hide = isset($_POST['showhide']) && 'hide' === $_POST['showhide'] ? 'hide' : '';
     MainWP_Helper::update_option('mainwp_pagespeed_hide_plugin', $hide);
     $information['result'] = 'SUCCESS';
     return $information;
 }
 public function extractWPZipBackup()
 {
     MainWP_Helper::getWPFilesystem();
     global $wp_filesystem;
     $tmpdir = ABSPATH;
     if ('ftpext' === $wp_filesystem->method && defined('FTP_BASE')) {
         $ftpBase = FTP_BASE;
         $ftpBase = trailingslashit($ftpBase);
         $tmpdir = str_replace(ABSPATH, $ftpBase, $tmpdir);
     }
     unzip_file($this->file, $tmpdir);
     return true;
 }
Exemplo n.º 17
0
 public static function remove_readme($force = false)
 {
     if ($force || self::get_security_option('readme')) {
         if (@file_exists(ABSPATH . 'readme.html')) {
             if (!@unlink(ABSPATH . 'readme.html')) {
                 MainWP_Helper::getWPFilesystem();
                 global $wp_filesystem;
                 if (!empty($wp_filesystem)) {
                     $wp_filesystem->delete(ABSPATH . 'readme.html');
                 }
             }
         }
     }
 }
 function set_showhide()
 {
     MainWP_Helper::update_option('mainwp_linkschecker_ext_enabled', 'Y', 'yes');
     $hide = isset($_POST['showhide']) && 'hide' === $_POST['showhide'] ? 'hide' : '';
     MainWP_Helper::update_option('mainwp_linkschecker_hide_plugin', $hide);
     $information['result'] = 'SUCCESS';
     return $information;
 }
Exemplo n.º 19
0
 function settings_tools()
 {
     if (isset($_POST['action'])) {
         switch ($_POST['action']) {
             case 'force_destroy_sessions':
                 if (0 === get_current_user_id()) {
                     MainWP_Helper::write(array('error' => __('Cannot get user_id', 'mainwp-child')));
                 }
                 wp_destroy_all_sessions();
                 $sessions = wp_get_all_sessions();
                 if (empty($sessions)) {
                     MainWP_Helper::write(array('success' => 1));
                 } else {
                     MainWP_Helper::write(array('error' => __('Cannot destroy sessions', 'mainwp-child')));
                 }
                 break;
             default:
                 MainWP_Helper::write(array('error' => __('Invalid action', 'mainwp-child')));
         }
     } else {
         MainWP_Helper::write(array('error' => __('Missing action', 'mainwp-child')));
     }
 }
 protected function show_hide()
 {
     MainWP_Helper::update_option('mainwp_backwpup_ext_enabled', 'Y');
     $hide = isset($_POST['show_hide']) && '1' === $_POST['show_hide'] ? 'hide' : '';
     MainWP_Helper::update_option('mainwp_backwpup_hide_plugin', $hide);
     return array('success' => 1);
 }
 function set_showhide()
 {
     $hide = isset($_POST['showhide']) && $_POST['showhide'] === 'hide' ? 'hide' : '';
     MainWP_Helper::update_option('mainwp_wordfence_hide_plugin', $hide);
     $information['result'] = 'SUCCESS';
     return $information;
 }
 protected static function checkDirectoryMainWPDirectory($write = true)
 {
     $branding_title = 'MainWP';
     if (MainWP_Child_Branding::is_branding()) {
         $branding_title = MainWP_Child_Branding::get_branding();
     }
     $branding_title .= ' upload directory';
     try {
         $dirs = MainWP_Helper::getMainWPDir(null, false);
         $path = $dirs[0];
     } catch (Exception $e) {
         return self::renderDirectoryRow($branding_title, '', 'Writable', $e->getMessage(), false);
     }
     if (!is_dir(dirname($path))) {
         if ($write) {
             return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Directory not found', false);
         } else {
             return false;
         }
     }
     $hasWPFileSystem = MainWP_Helper::getWPFilesystem();
     global $wp_filesystem;
     if ($hasWPFileSystem && !empty($wp_filesystem)) {
         if (!$wp_filesystem->is_writable($path)) {
             if ($write) {
                 return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Directory not writable', false);
             } else {
                 return false;
             }
         }
     } else {
         if (!is_writable($path)) {
             if ($write) {
                 return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Directory not writable', false);
             } else {
                 return false;
             }
         }
     }
     if ($write) {
         return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Writable', true);
     } else {
         return true;
     }
 }