예제 #1
0
 function parse_init()
 {
     if (isset($_REQUEST['cloneFunc'])) {
         if (!isset($_REQUEST['key'])) {
             return;
         }
         if (!isset($_REQUEST['f']) || $_REQUEST['f'] == '') {
             return;
         }
         if (!$this->isValidAuth($_REQUEST['key'])) {
             return;
         }
         if ($_REQUEST['cloneFunc'] == 'dl') {
             $this->uploadFile($_REQUEST['f']);
             exit;
         } else {
             if ($_POST['cloneFunc'] == 'deleteCloneBackup') {
                 $dirs = MainWPHelper::getMainWPDir('backup');
                 $backupdir = $dirs[0];
                 $result = glob($backupdir . $_POST['f']);
                 if (count($result) == 0) {
                     return;
                 }
                 @unlink($result[0]);
                 MainWPHelper::write(array('result' => 'ok'));
             } else {
                 if ($_POST['cloneFunc'] == 'createCloneBackupPoll') {
                     $dirs = MainWPHelper::getMainWPDir('backup');
                     $backupdir = $dirs[0];
                     $result = glob($backupdir . 'backup-' . $_POST['f'] . '-*');
                     $archiveFile = false;
                     foreach ($result as $file) {
                         if (MainWPHelper::isArchive($file, 'backup-' . $_POST['f'] . '-')) {
                             $archiveFile = $file;
                             break;
                         }
                     }
                     if ($archiveFile === false) {
                         return;
                     }
                     MainWPHelper::write(array('size' => filesize($archiveFile)));
                 } else {
                     if ($_POST['cloneFunc'] == 'createCloneBackup') {
                         MainWPHelper::endSession();
                         if (file_exists(WP_CONTENT_DIR . '/dbBackup.sql')) {
                             @unlink(WP_CONTENT_DIR . '/dbBackup.sql');
                         }
                         if (file_exists(ABSPATH . 'clone/config.txt')) {
                             @unlink(ABSPATH . 'clone/config.txt');
                         }
                         if (MainWPHelper::is_dir_empty(ABSPATH . 'clone')) {
                             @rmdir(ABSPATH . 'clone');
                         }
                         $wpversion = $_POST['wpversion'];
                         global $wp_version;
                         $includeCoreFiles = $wpversion != $wp_version;
                         $excludes = isset($_POST['exclude']) ? explode(',', $_POST['exclude']) : array();
                         $excludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/mainwp';
                         $uploadDir = MainWPHelper::getMainWPDir();
                         $uploadDir = $uploadDir[0];
                         $excludes[] = str_replace(ABSPATH, '', $uploadDir);
                         $excludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/object-cache.php';
                         if (!ini_get('safe_mode')) {
                             set_time_limit(6000);
                         }
                         $newExcludes = array();
                         foreach ($excludes as $exclude) {
                             $newExcludes[] = rtrim($exclude, '/');
                         }
                         $method = !isset($_POST['zipmethod']) ? 'tar.gz' : $_POST['zipmethod'];
                         if ($method == 'tar.gz' && !function_exists('gzopen')) {
                             $method = 'zip';
                         }
                         $res = MainWPBackup::get()->createFullBackup($newExcludes, isset($_POST['f']) ? $_POST['f'] : $_POST['file'], true, $includeCoreFiles, 0, false, false, false, false, $method);
                         if (!$res) {
                             $information['backup'] = false;
                         } else {
                             $information['backup'] = $res['file'];
                             $information['size'] = $res['filesize'];
                         }
                         //todo: RS: Remove this when the .18 is out
                         $plugins = array();
                         $dir = WP_CONTENT_DIR . '/plugins/';
                         $fh = @opendir($dir);
                         while ($entry = @readdir($fh)) {
                             if (!is_dir($dir . $entry)) {
                                 continue;
                             }
                             if ($entry == '.' || $entry == '..') {
                                 continue;
                             }
                             $plugins[] = $entry;
                         }
                         @closedir($fh);
                         $information['plugins'] = $plugins;
                         $themes = array();
                         $dir = WP_CONTENT_DIR . '/themes/';
                         $fh = @opendir($dir);
                         while ($entry = @readdir($fh)) {
                             if (!is_dir($dir . $entry)) {
                                 continue;
                             }
                             if ($entry == '.' || $entry == '..') {
                                 continue;
                             }
                             $themes[] = $entry;
                         }
                         @closedir($fh);
                         $information['themes'] = $themes;
                         MainWPHelper::write($information);
                     }
                 }
             }
         }
     }
     global $wp_rewrite;
     $snPluginDir = basename($this->plugin_dir);
     if (isset($wp_rewrite->non_wp_rules['wp-content/plugins/' . $snPluginDir . '/([^js\\/]*)$'])) {
         unset($wp_rewrite->non_wp_rules['wp-content/plugins/' . $snPluginDir . '/([^js\\/]*)$']);
     }
     if (isset($wp_rewrite->non_wp_rules['wp-content/plugins/' . $snPluginDir . '/(.*)$'])) {
         unset($wp_rewrite->non_wp_rules['wp-content/plugins/' . $snPluginDir . '/(.*)$']);
     }
     if (get_option('mainwp_child_fix_htaccess') === false) {
         include_once ABSPATH . '/wp-admin/includes/misc.php';
         $wp_rewrite->flush_rules();
         MainWPHelper::update_option('mainwp_child_fix_htaccess', 'yes', 'yes');
     }
     $this->update_htaccess();
     global $current_user;
     //wp variable
     //Login the user
     if (isset($_REQUEST['login_required']) && $_REQUEST['login_required'] == 1 && isset($_REQUEST['user'])) {
         $username = rawurldecode($_REQUEST['user']);
         if (is_user_logged_in()) {
             global $current_user;
             if ($current_user->wp_user_level != 10 && (!isset($current_user->user_level) || $current_user->user_level != 10) && !current_user_can('level_10')) {
                 do_action('wp_logout');
             }
         }
         $signature = rawurldecode(isset($_REQUEST['mainwpsignature']) ? $_REQUEST['mainwpsignature'] : '');
         $file = '';
         if (isset($_REQUEST['f'])) {
             $file = $_REQUEST['f'];
         } else {
             if (isset($_REQUEST['file'])) {
                 $file = $_REQUEST['file'];
             } else {
                 if (isset($_REQUEST['fdl'])) {
                     $file = $_REQUEST['fdl'];
                 }
             }
         }
         $auth = $this->auth($signature, rawurldecode(isset($_REQUEST['where']) ? $_REQUEST['where'] : $file), isset($_REQUEST['nonce']) ? $_REQUEST['nonce'] : '', isset($_REQUEST['nossl']) ? $_REQUEST['nossl'] : 0);
         if (!$auth) {
             return;
         }
         if (!is_user_logged_in() || $username != $current_user->user_login) {
             if (!$this->login($username)) {
                 return;
             }
             global $current_user;
             if ($current_user->wp_user_level != 10 && (!isset($current_user->user_level) || $current_user->user_level != 10) && !current_user_can('level_10')) {
                 do_action('wp_logout');
                 return;
             }
         }
         if (isset($_REQUEST['fdl'])) {
             if (stristr($_REQUEST['fdl'], '..')) {
                 return;
             }
             $this->uploadFile($_REQUEST['fdl'], isset($_REQUEST['foffset']) ? $_REQUEST['foffset'] : 0);
             exit;
         }
         $where = isset($_REQUEST['where']) ? $_REQUEST['where'] : '';
         if (isset($_POST['f']) || isset($_POST['file'])) {
             $file = '';
             if (isset($_POST['f'])) {
                 $file = $_POST['f'];
             } else {
                 if (isset($_POST['file'])) {
                     $file = $_POST['file'];
                 }
             }
             $where = 'admin.php?page=mainwp-child-restore';
             if (session_id() == '') {
                 session_start();
             }
             $_SESSION['file'] = $file;
             $_SESSION['size'] = $_POST['size'];
         }
         $open_location = isset($_REQUEST['open_location']) ? $_REQUEST['open_location'] : '';
         if (!empty($open_location)) {
             $open_location = base64_decode($open_location);
             $_vars = MainWPHelper::parse_query($open_location);
             $_path = parse_url($open_location, PHP_URL_PATH);
             if (isset($_vars['_mwpNoneName']) && isset($_vars['_mwpNoneValue'])) {
                 $_vars[$_vars['_mwpNoneName']] = wp_create_nonce($_vars['_mwpNoneValue']);
                 unset($_vars['_mwpNoneName']);
                 unset($_vars['_mwpNoneValue']);
                 $open_url = "";
                 foreach ($_vars as $key => $value) {
                     $open_url .= $key . '=' . $value . '&';
                 }
                 $open_url = rtrim($open_url, '&');
                 $open_location = "/wp-admin/" . $_path . "?" . $open_url;
             } else {
                 if (strpos($open_location, "nonce=child_temp_nonce") !== false) {
                     $open_location = str_replace("nonce=child_temp_nonce", "nonce=" . wp_create_nonce('wp-ajax'), $open_location);
                 }
             }
             wp_redirect(site_url() . $open_location);
             exit;
         }
         add_filter('the_content', array(MainWPKeywordLinks::Instance(), 'filter_content'), 100, 2);
         wp_redirect(admin_url($where));
         exit;
     }
     remove_action('admin_init', 'send_frame_options_header');
     remove_action('login_init', 'send_frame_options_header');
     // Call Heatmap
     if (get_option('heatMapExtensionLoaded') == 'yes') {
         if (get_option('heatMapsIndividualOverrideSetting') != '1' && get_option('heatMapEnabled') !== '0' || get_option('heatMapsIndividualOverrideSetting') == '1' && get_option('heatMapsIndividualDisable') != '1') {
             new MainWPHeatmapTracker();
         }
     }
     /**
      * Security
      */
     MainWPSecurity::fixAll();
     if (isset($_GET['mainwptest'])) {
         //            error_reporting(E_ALL);
         //            ini_set('display_errors', TRUE);
         //            ini_set('display_startup_errors', TRUE);
         //            echo '<pre>';
         //            $start = microtime(true);
         //            phpinfo();
         //            $_POST['type'] = 'full';
         //            $_POST['ext'] = 'tar.gz';
         //            $_POST['pid'] = time();
         //            print_r($this->backup(false));
         //            $stop = microtime(true);
         //            die(($stop - $start) . 's</pre>');
     }
     //Register does not require auth, so we register here..
     if (isset($_POST['function']) && $_POST['function'] == 'register') {
         $this->registerSite();
     }
     $auth = $this->auth(isset($_POST['mainwpsignature']) ? $_POST['mainwpsignature'] : '', isset($_POST['function']) ? $_POST['function'] : '', isset($_POST['nonce']) ? $_POST['nonce'] : '', isset($_POST['nossl']) ? $_POST['nossl'] : 0);
     if (!$auth && isset($_POST['mainwpsignature'])) {
         MainWPHelper::error(__('Authentication failed! Please deactivate and re-activate the MainWP Child plugin on this site.', 'mainwp-child'));
     }
     //Check if the user exists & is an administrator
     if (isset($_POST['function']) && isset($_POST['user'])) {
         $user = get_user_by('login', $_POST['user']);
         if (!$user) {
             MainWPHelper::error(__('No such user', 'mainwp-child'));
         }
         if ($user->wp_user_level != 10 && (!isset($user->user_level) || $user->user_level != 10) && !current_user_can('level_10')) {
             MainWPHelper::error(__('User is not an administrator', 'mainwp-child'));
         }
         $this->login($_REQUEST['user']);
     }
     if (isset($_POST['function']) && $_POST['function'] == 'visitPermalink') {
         if ($auth) {
             if ($this->login($_POST['user'], true)) {
                 return;
             } else {
                 exit;
             }
         }
     }
     //Redirect to the admin part if needed
     if ($auth && isset($_POST['admin']) && $_POST['admin'] == 1) {
         wp_redirect(get_option('siteurl') . '/wp-admin/');
         die;
     }
     new MainWPChildIThemesSecurity();
     MainWPChildUpdraftplusBackups::Instance()->updraftplus_init();
     if (version_compare(phpversion(), '5.3', '>=')) {
         MainWPChildBackUpWordPress::Instance()->init();
     }
     MainWPChildWPRocket::Instance()->init();
     MainWPChildBackWPup::Instance()->init();
     //Call the function required
     if (isset($_POST['function']) && isset($this->callableFunctions[$_POST['function']])) {
         call_user_func(array($this, $auth ? $this->callableFunctions[$_POST['function']] : $this->callableFunctionsNoAuth[$_POST['function']]));
     }
     if (get_option('mainwpKeywordLinks') == 1) {
         new MainWPKeywordLinks();
         if (!is_admin()) {
             add_filter('the_content', array(MainWPKeywordLinks::Instance(), 'filter_content'), 100);
         }
         MainWPKeywordLinks::Instance()->update_htaccess();
         // if needed
         MainWPKeywordLinks::Instance()->redirect_cloak();
     } else {
         if (get_option('mainwp_keyword_links_htaccess_set') == 'yes') {
             MainWPKeywordLinks::clear_htaccess();
             // force clear
         }
     }
     // Branding extension
     MainWPChildBranding::Instance()->branding_init();
     MainWPClientReport::Instance()->creport_init();
     MainWPChildPagespeed::Instance()->init();
     MainWPChildLinksChecker::Instance()->init();
     MainWPChildWordfence::Instance()->wordfence_init();
     MainWPChildIThemesSecurity::Instance()->ithemes_init();
 }