Exemple #1
0
 public static function initAction()
 {
     if (wfConfig::liveTrafficEnabled() && !wfConfig::get('disableCookies', false)) {
         self::setCookie();
     }
     // This is more of a hurdle, but might stop an automated process.
     // if (current_user_can('administrator')) {
     // 	$adminUsers = new wfAdminUserMonitor();
     // 	if ($adminUsers->isEnabled() && !$adminUsers->isAdminUserLogged(get_current_user_id())) {
     // 		define('DISALLOW_FILE_MODS', true);
     // 	}
     // }
     $currentUserID = get_current_user_id();
     $role = wordfence::getCurrentUserRole();
     if (!WFWAF_SUBDIRECTORY_INSTALL) {
         try {
             $authCookie = wfWAF::getInstance()->parseAuthCookie();
             if (is_user_logged_in() && (!$authCookie || (int) $currentUserID !== (int) $authCookie['userID'] || $role !== $authCookie['role'])) {
                 $secureLoggedInCookie = is_ssl() && parse_url(get_option('home'), PHP_URL_SCHEME) === 'https';
                 wfUtils::setcookie(wfWAF::getInstance()->getAuthCookieName(), $currentUserID . '|' . $role . '|' . wfWAF::getInstance()->getAuthCookieValue($currentUserID, $role), time() + 43200, COOKIEPATH, COOKIE_DOMAIN, $secureLoggedInCookie, true);
             }
         } catch (wfWAFStorageFileException $e) {
             error_log($e->getMessage());
         }
     }
     if (wfConfig::get('other_hideWPVersion')) {
         global $wp_version;
         global $wp_styles;
         if (!$wp_styles instanceof WP_Styles) {
             $wp_styles = new WP_Styles();
         }
         if ($wp_styles->default_version === $wp_version) {
             $wp_styles->default_version = wp_hash($wp_styles->default_version);
         }
         foreach ($wp_styles->registered as $key => $val) {
             if ($wp_styles->registered[$key]->ver === $wp_version) {
                 $wp_styles->registered[$key]->ver = wp_hash($wp_styles->registered[$key]->ver);
             }
         }
         global $wp_scripts;
         if (!$wp_scripts instanceof WP_Scripts) {
             $wp_scripts = new WP_Scripts();
         }
         if ($wp_scripts->default_version === $wp_version) {
             $wp_scripts->default_version = wp_hash($wp_scripts->default_version);
         }
         foreach ($wp_scripts->registered as $key => $val) {
             if ($wp_scripts->registered[$key]->ver === $wp_version) {
                 $wp_scripts->registered[$key]->ver = wp_hash($wp_scripts->registered[$key]->ver);
             }
         }
     }
 }