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); } MainWPHelper::write($information); }
public function action() { $information = array(); if (!class_exists('WooCommerce')) { $information['error'] = 'NO_WOOCOMMERCE'; MainWPHelper::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; } } MainWPHelper::write($information); }
function set_showhide() { MainWPHelper::update_option('mainwp_creport_ext_branding_enabled', "Y", 'yes'); $hide = isset($_POST['showhide']) && $_POST['showhide'] === "hide" ? 'hide' : ""; MainWPHelper::update_option('mainwp_creport_branding_stream_hide', $hide); $information['result'] = 'SUCCESS'; return $information; }
function save_settings() { MainWPHelper::update_option('mainwp_pagespeed_ext_enabled', "Y", 'yes'); $current_values = get_option('gpagespeedi_options'); if (is_array($current_values) && $current_values['last_run_finished'] == false) { return array('result' => 'RUNNING'); } $settings = $_POST['settings']; $settings = unserialize(base64_decode($settings)); if (is_array($settings)) { if (isset($settings['api_key']) && !empty($settings['api_key'])) { $current_values['google_developer_key'] = $settings['api_key']; } if (isset($settings['response_language'])) { $current_values['response_language'] = $settings['response_language']; } if (isset($_POST['strategy'])) { $current_values['strategy'] = $_POST['strategy']; } if (isset($settings['max_execution_time'])) { $current_values['max_execution_time'] = $settings['max_execution_time']; } if (isset($settings['delay_time'])) { $current_values['sleep_time'] = $settings['delay_time']; } if (isset($settings['log_exception'])) { $current_values['log_api_errors'] = $settings['log_exception'] ? true : false; } if (isset($settings['scan_technical'])) { $current_values['scan_method'] = $settings['scan_technical']; } if (isset($settings['report_expiration'])) { $current_values['recheck_interval'] = $settings['report_expiration']; } if (isset($settings['check_report'])) { if (is_array($settings['check_report'])) { $current_values['check_pages'] = in_array('page', $settings['check_report']) ? true : false; $current_values['check_posts'] = in_array('post', $settings['check_report']) ? true : false; $current_values['check_categories'] = in_array('category', $settings['check_report']) ? true : false; } else { $current_values['check_pages'] = $current_values['check_posts'] = $current_values['check_categories'] = false; } } if (isset($settings['delete_data']) && !empty($settings['delete_data'])) { $this->delete_data($settings['delete_data']); } if (update_option('gpagespeedi_options', $current_values)) { $information['result'] = 'SUCCESS'; } else { $information['result'] = 'NOTCHANGE'; } } $strategy = $current_values['strategy']; $result = $this->sync_data($strategy); $information['data'] = $result['data']; return $information; }
function set_showhide() { MainWPHelper::update_option('mainwp_backupwordpress_ext_enabled', "Y"); $hide = isset($_POST['showhide']) && $_POST['showhide'] === "hide" ? 'hide' : ""; MainWPHelper::update_option('mainwp_backupwordpress_hide_plugin', $hide); $information['result'] = 'SUCCESS'; return $information; }
function set_showhide() { MainWPHelper::update_option('mainwp_linkschecker_ext_enabled', "Y", 'yes'); $hide = isset($_POST['showhide']) && $_POST['showhide'] === "hide" ? 'hide' : ""; MainWPHelper::update_option('mainwp_linkschecker_hide_plugin', $hide); $information['result'] = 'SUCCESS'; return $information; }
function save_settings() { global $itsec_globals; if (!class_exists('ITSEC_Lib')) { require trailingslashit($itsec_globals['plugin_dir']) . 'core/class-itsec-lib.php'; } MainWPHelper::update_option('mainwp_ithemes_ext_enabled', "Y", 'yes'); $settings = 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']) && $settings['itsec_global']['write_files'] === true) { 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 ($backup !== false && 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 ($file_change !== false && isset($file_change['last_run'])) { $settings['itsec_file_change']['last_run'] = $file_change['last_run']; } else { unset($settings['itsec_file_change']['last_run']); } if ($file_change !== false && 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'] && $input['enabled'] === true) { 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 ($is_safe !== true && $raw_version !== false) { $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 extractWPZipBackup() { MainWPHelper::getWPFilesystem(); global $wp_filesystem; //First check if there is a database backup in the zip file, these can be very large and the wordpress unzip_file can not handle these! // if ($this->checkZipSupport()) // { // return $this->extractZipBackup(); // $zip = new ZipArchive(); // $zipRes = $zip->open($this->file); // if ($zipRes) // { // $stats = $zip->statName('wp-content/dbBackup.sql'); // // @$zip->extractTo(ABSPATH); // // $zip->deleteName('wp-content/dbBackup.sql'); // $zip->deleteName('clone'); // $zip->close(); // // $zip->close(); // } // } // else // { // return $this->extractZipPclBackup(); // } $tmpdir = ABSPATH; if ($wp_filesystem->method == 'ftpext' && defined('FTP_BASE')) { $ftpBase = FTP_BASE; $ftpBase = trailingslashit($ftpBase); $tmpdir = str_replace(ABSPATH, $ftpBase, $tmpdir); } unzip_file($this->file, $tmpdir); return true; }
public static function cloneBackupExtract() { try { MainWPHelper::endSession(); $file = isset($_POST['f']) ? $_POST['f'] : $_POST['file']; $testFull = false; if ($file == '') { $dirs = MainWPHelper::getMainWPDir('backup', false); $backupdir = $dirs[0]; $files = glob($backupdir . 'download-*'); $archiveFile = false; foreach ($files as $file) { if (MainWPHelper::isArchive($file, 'download-')) { $archiveFile = $file; break; } } if ($archiveFile === false) { 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 MainWPCloneInstall($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); MainWPHelper::update_option('mainwp_child_pubkey', $pubkey, 'yes'); MainWPHelper::update_option('mainwp_child_uniqueId', $uniqueId); MainWPHelper::update_option('mainwp_child_server', $server); MainWPHelper::update_option('mainwp_child_nonce', $nonce); MainWPHelper::update_option('mainwp_child_nossl', $nossl, 'yes'); MainWPHelper::update_option('mainwp_child_nossl_key', $nossl_key); MainWPHelper::update_option('mainwp_child_clone_sites', $sitesToClone); if (!MainWPHelper::startsWith(basename($file), 'download-backup-')) { MainWPHelper::update_option('mainwp_child_restore_permalink', true, 'yes'); } else { MainWPHelper::update_option('mainwp_child_clone_permalink', true, 'yes'); } $cloneInstall->clean(); if ($plugins !== false) { $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)) { MainWPHelper::delete_dir($dir . $entry); } } @closedir($fh); } delete_option('mainwp_temp_clone_plugins'); } if ($themes !== false) { $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)) { MainWPHelper::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)); }
function uploadFile($file, $offset = 0) { $dirs = MainWPHelper::getMainWPDir('backup'); $backupdir = $dirs[0]; header('Content-Description: File Transfer'); header('Content-Description: File Transfer'); if (MainWPHelper::endsWith($file, '.tar.gz')) { header('Content-Type: application/x-gzip'); header("Content-Encoding: gzip'"); } else { header('Content-Type: application/octet-stream'); } header('Content-Disposition: attachment; filename="' . basename($file) . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($backupdir . $file)); while (@ob_end_flush()) { } $this->readfile_chunked($backupdir . $file, $offset); }
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')) { MainWPHelper::getWPFilesystem(); global $wp_filesystem; if (!empty($wp_filesystem)) { $wp_filesystem->delete(ABSPATH . 'readme.html'); } } } } }
function settings_tools() { if (isset($_POST['action'])) { switch ($_POST['action']) { case 'force_destroy_sessions': if (get_current_user_id() == 0) { MainWPHelper::write(array('error' => __('Cannot get user_id', 'mainwp-child'))); } wp_destroy_all_sessions(); $sessions = wp_get_all_sessions(); if (empty($sessions)) { MainWPHelper::write(array('success' => 1)); } else { MainWPHelper::write(array('error' => __('Cannot destroy sessions', 'mainwp-child'))); } break; default: MainWPHelper::write(array('error' => __('Invalid action', 'mainwp-child'))); } } else { MainWPHelper::write(array('error' => __('Missing action', 'mainwp-child'))); } }
public function update_branding() { $information = array(); $settings = unserialize(base64_decode($_POST['settings'])); if (!is_array($settings)) { return $information; } $current_extra_setting = $this->settings['extra_settings']; MainWPHelper::update_option('mainwp_branding_ext_enabled', "Y", 'yes'); $header = array('name' => $settings['child_plugin_name'], 'description' => $settings['child_plugin_desc'], 'author' => $settings['child_plugin_author'], 'authoruri' => $settings['child_plugin_author_uri'], 'pluginuri' => $settings['child_plugin_uri']); MainWPHelper::update_option('mainwp_branding_preserve_branding', $settings['child_preserve_branding']); MainWPHelper::update_option('mainwp_branding_plugin_header', $header, 'yes'); MainWPHelper::update_option('mainwp_branding_support_email', $settings['child_support_email']); MainWPHelper::update_option('mainwp_branding_support_message', $settings['child_support_message']); MainWPHelper::update_option('mainwp_branding_remove_restore', $settings['child_remove_restore']); MainWPHelper::update_option('mainwp_branding_remove_setting', $settings['child_remove_setting']); MainWPHelper::update_option('mainwp_branding_remove_server_info', $settings['child_remove_server_info']); MainWPHelper::update_option('mainwp_branding_remove_wp_tools', $settings['child_remove_wp_tools']); MainWPHelper::update_option('mainwp_branding_remove_wp_setting', $settings['child_remove_wp_setting']); MainWPHelper::update_option('mainwp_branding_remove_permalink', $settings['child_remove_permalink']); MainWPHelper::update_option('mainwp_branding_button_contact_label', $settings['child_button_contact_label'], 'yes'); MainWPHelper::update_option('mainwp_branding_send_email_message', $settings['child_send_email_message']); MainWPHelper::update_option('mainwp_branding_message_return_sender', $settings['child_message_return_sender']); MainWPHelper::update_option('mainwp_branding_submit_button_title', $settings['child_submit_button_title']); if (isset($settings['child_disable_wp_branding']) && ($settings['child_disable_wp_branding'] === "Y" || $settings['child_disable_wp_branding'] === "N")) { MainWPHelper::update_option('mainwp_branding_disable_wp_branding', $settings['child_disable_wp_branding']); } $extra_setting = array('show_button_in' => $settings['child_show_support_button_in'], 'global_footer' => $settings['child_global_footer'], 'dashboard_footer' => $settings['child_dashboard_footer'], 'remove_widget_welcome' => $settings['child_remove_widget_welcome'], 'remove_widget_glance' => $settings['child_remove_widget_glance'], 'remove_widget_activity' => $settings['child_remove_widget_activity'], 'remove_widget_quick' => $settings['child_remove_widget_quick'], 'remove_widget_news' => $settings['child_remove_widget_news'], 'site_generator' => $settings['child_site_generator'], 'generator_link' => $settings['child_generator_link'], 'admin_css' => $settings['child_admin_css'], 'login_css' => $settings['child_login_css'], 'texts_replace' => $settings['child_texts_replace'], 'hide_nag' => $settings['child_hide_nag'], 'hide_screen_opts' => $settings['child_hide_screen_opts'], 'hide_help_box' => $settings['child_hide_help_box'], 'hide_metabox_post_excerpt' => $settings['child_hide_metabox_post_excerpt'], 'hide_metabox_post_slug' => $settings['child_hide_metabox_post_slug'], 'hide_metabox_post_tags' => $settings['child_hide_metabox_post_tags'], 'hide_metabox_post_author' => $settings['child_hide_metabox_post_author'], 'hide_metabox_post_comments' => $settings['child_hide_metabox_post_comments'], 'hide_metabox_post_revisions' => $settings['child_hide_metabox_post_revisions'], 'hide_metabox_post_discussion' => $settings['child_hide_metabox_post_discussion'], 'hide_metabox_post_categories' => $settings['child_hide_metabox_post_categories'], 'hide_metabox_post_custom_fields' => $settings['child_hide_metabox_post_custom_fields'], 'hide_metabox_post_trackbacks' => $settings['child_hide_metabox_post_trackbacks'], 'hide_metabox_page_custom_fields' => $settings['child_hide_metabox_page_custom_fields'], 'hide_metabox_page_author' => $settings['child_hide_metabox_page_author'], 'hide_metabox_page_discussion' => $settings['child_hide_metabox_page_discussion'], 'hide_metabox_page_revisions' => $settings['child_hide_metabox_page_revisions'], 'hide_metabox_page_attributes' => $settings['child_hide_metabox_page_attributes'], 'hide_metabox_page_slug' => $settings['child_hide_metabox_page_slug']); if (isset($settings['child_login_image_url'])) { if (empty($settings['child_login_image_url'])) { $extra_setting['login_image'] = array(); } else { try { $upload = $this->uploadImage($settings['child_login_image_url']); //Upload image to WP if ($upload != null) { $extra_setting['login_image'] = array("path" => $upload["path"], "url" => $upload["url"]); if (isset($current_extra_setting['login_image']['path'])) { $old_file = $current_extra_setting['login_image']['path']; if (!empty($old_file) && file_exists($old_file)) { @unlink($old_file); } } } } catch (Exception $e) { $information['error']['login_image'] = $e->getMessage(); } } } else { if (isset($current_extra_setting['login_image'])) { $extra_setting['login_image'] = $current_extra_setting['login_image']; } } if (isset($settings['child_favico_image_url'])) { if (empty($settings['child_favico_image_url'])) { $extra_setting['favico_image'] = array(); } else { try { $upload = $this->uploadImage($settings['child_favico_image_url']); //Upload image to WP if ($upload != null) { $extra_setting['favico_image'] = array("path" => $upload["path"], "url" => $upload["url"]); if (isset($current_extra_setting['favico_image']['path'])) { $old_file = $current_extra_setting['favico_image']['path']; if (!empty($old_file) && file_exists($old_file)) { @unlink($old_file); } } } } catch (Exception $e) { $information['error']['favico_image'] = $e->getMessage(); } } } else { if (isset($current_extra_setting['favico_image'])) { $extra_setting['favico_image'] = $current_extra_setting['favico_image']; } } MainWPHelper::update_option('mainwp_branding_extra_settings', $extra_setting, 'yes'); if ($settings['child_plugin_hide']) { MainWPHelper::update_option('mainwp_branding_child_hide', 'T'); } else { MainWPHelper::update_option('mainwp_branding_child_hide', ''); } if ($settings['child_show_support_button'] && !empty($settings['child_support_email'])) { MainWPHelper::update_option('mainwp_branding_show_support', 'T'); } else { MainWPHelper::update_option('mainwp_branding_show_support', ''); } if ($settings['child_disable_change']) { MainWPHelper::update_option('mainwp_branding_disable_change', 'T'); } else { MainWPHelper::update_option('mainwp_branding_disable_change', ''); } $information['result'] = 'SUCCESS'; return $information; }
function addFileToZip($path, $zipEntryName) { if (time() - $this->lastRun > 20) { @set_time_limit($this->timeout); $this->lastRun = time(); } if ($this->excludeZip && MainWPHelper::endsWith($path, '.zip')) { return false; } // this would fail with status ZIPARCHIVE::ER_OPEN // after certain number of files is added since // ZipArchive internally stores the file descriptors of all the // added files and only on close writes the contents to the ZIP file // see: http://bugs.php.net/bug.php?id=40494 // and: http://pecl.php.net/bugs/bug.php?id=9443 // return $zip->addFile( $path, $zipEntryName ); $this->zipArchiveSizeCount += filesize($path); $this->gcCnt++; //5 mb limit! if (!$this->loadFilesBeforeZip || filesize($path) > 5 * 1024 * 1024) { $this->zipArchiveFileCount++; $added = $this->zip->addFile($path, $zipEntryName); } else { $this->zipArchiveFileCount++; $this->testContent = file_get_contents($path); if ($this->testContent === false) { return false; } $added = $this->zip->addFromString($zipEntryName, $this->testContent); } if ($this->gcCnt > 20) { if (function_exists('gc_enable')) { @gc_enable(); } if (function_exists('gc_collect_cycles')) { @gc_collect_cycles(); } $this->gcCnt = 0; } //Over limits? if ($this->file_descriptors > 0 && $this->zipArchiveFileCount > $this->file_descriptors) { $this->zip->close(); $this->zip = null; unset($this->zip); if (function_exists('gc_enable')) { @gc_enable(); } if (function_exists('gc_collect_cycles')) { @gc_collect_cycles(); } $this->zip = new ZipArchive(); $this->zip->open($this->zipArchiveFileName); $this->zipArchiveFileCount = 0; $this->zipArchiveSizeCount = 0; } return $added; }
function remove_notices() { $remove_hooks['all_admin_notices'] = array('UpdraftPlus' => array('show_admin_warning_unreadablelog' => 10, 'show_admin_warning_nolog' => 10, 'show_admin_warning_unreadablelog' => 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) { MainWPHelper::remove_filters_for_anonymous_class($hook_name, $class_name, $method, $priority); } } } }
public static function inExcludes($excludes, $value) { if (empty($value)) { return false; } if ($excludes != null) { foreach ($excludes as $exclude) { if (MainWPHelper::endsWith($exclude, '*')) { if (MainWPHelper::startsWith($value, substr($exclude, 0, strlen($exclude) - 1))) { return true; } } else { if ($value == $exclude) { return true; } else { if (MainWPHelper::startsWith($value, $exclude . '/')) { return true; } } } } } return false; }
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[$i] = $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')); if (strpos($url, "https://") === 0) { $params['sslverify'] = FALSE; } $request = wp_remote_post($url, $params); if (is_array($request) && intval($request['body']) > 0) { if (count($clickData) > 1000) { $saveData = array(); for ($i = 1000; $i < count($clickData); $i++) { $saveData[$i] = $clickData[$i]; } MainWPHelper::update_option('mainwp_child_click_data', $saveData); } else { delete_option('mainwp_child_click_data'); } } }
protected function show_hide() { MainWPHelper::update_option('mainwp_backwpup_ext_enabled', "Y"); $hide = isset($_POST['show_hide']) && $_POST['show_hide'] == "1" ? 'hide' : ""; MainWPHelper::update_option('mainwp_backwpup_hide_plugin', $hide); return array('success' => 1); }
protected static function checkDirectoryMainWPDirectory($write = true) { $branding_title = "MainWP"; if (MainWPChildBranding::is_branding()) { $branding_title = MainWPChildBranding::get_branding(); } $branding_title .= " upload directory"; try { $dirs = MainWPHelper::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 = MainWPHelper::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; } }
function set_showhide() { $hide = isset($_POST['showhide']) && $_POST['showhide'] === "hide" ? 'hide' : ""; MainWPHelper::update_option('mainwp_wprocket_hide_plugin', $hide); $information['result'] = 'SUCCESS'; return $information; }
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 (MainWPHelper::startsWith($dirnameA, $dirnameB)) { return 1; } else { if (MainWPHelper::startsWith($dirnameB, $dirnameA)) { return -1; } else { $cmp = strcmp($dirnameA, $dirnameB); if ($cmp == 0) { return strcmp($pathA, $pathB); } return $cmp; } } } } }
function save_setting() { MainWPHelper::update_option('mainwp_wordfence_ext_enabled', "Y", 'yes'); $settings = unserialize(base64_decode($_POST['settings'])); if (is_array($settings) && count($settings) > 0) { $result = array(); $reload = ''; $opts = $settings; $validUsers = array(); $invalidUsers = array(); foreach (explode(',', $opts['liveTraf_ignoreUsers']) as $val) { $val = trim($val); if (strlen($val) > 0) { if (get_user_by('login', $val)) { $validUsers[] = $val; } else { $invalidUsers[] = $val; } } } if (sizeof($invalidUsers) > 0) { // return array('errorMsg' => "The following users you selected to ignore in live traffic reports are not valid on this system: " . htmlentities(implode(', ', $invalidUsers)) ); $result['invalid_users'] = htmlentities(implode(', ', $invalidUsers)); } if (sizeof($validUsers) > 0) { $opts['liveTraf_ignoreUsers'] = implode(',', $validUsers); } else { $opts['liveTraf_ignoreUsers'] = ''; } if (!$opts['other_WFNet']) { $wfdb = new wfDB(); global $wpdb; $p = $wpdb->base_prefix; $wfdb->queryWrite("delete from {$p}" . "wfBlocks where wfsn=1 and permanent=0"); } $regenerateHtaccess = false; if (wfConfig::get('bannedURLs', false) != $opts['bannedURLs']) { $regenerateHtaccess = true; } foreach ($opts as $key => $val) { if (in_array($key, self::$options_filter)) { if ($key != 'apiKey') { //Don't save API key yet wfConfig::set($key, $val); } } } if ($regenerateHtaccess) { wfCache::addHtaccessCode('add'); } if ($opts['autoUpdate'] == '1') { wfConfig::enableAutoUpdate(); } else { if ($opts['autoUpdate'] == '0') { wfConfig::disableAutoUpdate(); } } $sch = isset($opts['scheduleScan']) ? $opts['scheduleScan'] : ""; if ($sch != get_option('mainwp_child_wordfence_cron_time')) { update_option('mainwp_child_wordfence_cron_time', $sch); $sched = wp_next_scheduled('mainwp_child_wordfence_cron_scan'); if ($sched != false) { wp_unschedule_event($sched, 'mainwp_child_wordfence_cron_scan'); } } $result['cacheType'] = wfConfig::get('cacheType'); $result['paidKeyMsg'] = false; $apiKey = trim($_POST['apiKey']); if (!$apiKey) { //Empty API key (after trim above), then try to get one. $api = new wfAPI('', wfUtils::getWPVersion()); try { $keyData = $api->call('get_anon_api_key'); if ($keyData['ok'] && $keyData['apiKey']) { wfConfig::set('apiKey', $keyData['apiKey']); wfConfig::set('isPaid', 0); $result['apiKey'] = $keyData['apiKey']; $result['isPaid'] = 0; $reload = 'reload'; } else { throw new Exception("We could not understand the Wordfence server's response because it did not contain an 'ok' and 'apiKey' element."); } } catch (Exception $e) { $result['error'] = "Your options have been saved, but we encountered a problem. You left your API key blank, so we tried to get you a free API key from the Wordfence servers. However we encountered a problem fetching the free key: " . htmlentities($e->getMessage()); return $result; } } else { if ($apiKey != wfConfig::get('apiKey')) { $api = new wfAPI($apiKey, wfUtils::getWPVersion()); try { $res = $api->call('check_api_key', array(), array()); if ($res['ok'] && isset($res['isPaid'])) { wfConfig::set('apiKey', $apiKey); wfConfig::set('isPaid', $res['isPaid']); //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools. $result['apiKey'] = $apiKey; $result['isPaid'] = $res['isPaid']; if ($res['isPaid']) { $result['paidKeyMsg'] = true; } $reload = 'reload'; } else { throw new Exception("We could not understand the Wordfence API server reply when updating your API key."); } } catch (Exception $e) { $result['error'] = "Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: " . htmlentities($e->getMessage()); return $result; } } else { try { $api = new wfAPI($apiKey, wfUtils::getWPVersion()); $res = $api->call('ping_api_key', array(), array()); } catch (Exception $e) { $result['error'] = "Your options have been saved. However we noticed you do not change your API key and we tried to verify it with the Wordfence servers and received an error: " . htmlentities($e->getMessage()); return $result; } } } $result['ok'] = 1; $result['reload'] = $reload; return $result; } }