Diff
6 years ago
dashboard
7 years ago
rest-api
6 years ago
.htaccess
7 years ago
Diff.php
6 years ago
GeoLite2-Country.mmdb
6 years ago
IPTraf.php
6 years ago
IPTrafList.php
7 years ago
WFLSPHP52Compatability.php
6 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
6 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
6 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
6 years ago
menu_scanner.php
6 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
6 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
6 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
6 years ago
menu_tools_twoFactor.php
7 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
noc1.key
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
6 years ago
wfActivityReport.php
6 years ago
wfAdminNoticeQueue.php
8 years ago
wfAlerts.php
6 years ago
wfArray.php
7 years ago
wfBrowscap.php
6 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
6 years ago
wfCentralAPI.php
6 years ago
wfConfig.php
6 years ago
wfCrawl.php
6 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
6 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
6 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
6 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
6 years ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
6 years ago
wfScanEngine.php
6 years ago
wfSchema.php
6 years ago
wfStyle.php
7 years ago
wfSupportController.php
6 years ago
wfUnlockMsg.php
6 years ago
wfUpdateCheck.php
6 years ago
wfUtils.php
6 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
6 years ago
wordfenceConstants.php
6 years ago
wordfenceHash.php
6 years ago
wordfenceScanner.php
6 years ago
wordfenceURLHoover.php
6 years ago
wfOnboardingController.php
197 lines
| 1 | <?php |
| 2 | |
| 3 | class wfOnboardingController { |
| 4 | const ONBOARDING_FIRST_EMAILS = 'emails'; //New install, first attempt onboarding, part 1 completed |
| 5 | const ONBOARDING_FIRST_LICENSE = 'license'; //New install, first attempt onboarding, part 2 completed |
| 6 | const ONBOARDING_FIRST_SKIPPED = 'skipped'; //New install, first attempt onboarding was skipped |
| 7 | |
| 8 | const ONBOARDING_SECOND_EMAILS = 'emails'; //New install, second attempt onboarding, part 1 completed |
| 9 | const ONBOARDING_SECOND_LICENSE = 'license'; //New install, second attempt onboarding, part 2 completed |
| 10 | const ONBOARDING_SECOND_SKIPPED = 'skipped'; //New install, second attempt onboarding was skipped |
| 11 | |
| 12 | const ONBOARDING_THIRD_EMAILS = 'emails'; //New install, third attempt onboarding, part 1 completed |
| 13 | const ONBOARDING_THIRD_LICENSE = 'license'; //New install, third attempt onboarding, part 2 completed |
| 14 | |
| 15 | const TOUR_DASHBOARD = 'dashboard'; |
| 16 | const TOUR_FIREWALL = 'firewall'; |
| 17 | const TOUR_SCAN = 'scan'; |
| 18 | const TOUR_BLOCKING = 'blocking'; |
| 19 | const TOUR_LIVE_TRAFFIC = 'livetraffic'; |
| 20 | const TOUR_LOGIN_SECURITY = 'loginsecurity'; |
| 21 | |
| 22 | /** |
| 23 | * Sets the appropriate initial settings for an existing install so it's not forced through onboarding. |
| 24 | */ |
| 25 | public static function migrateOnboarding() { |
| 26 | $alertEmails = wfConfig::getAlertEmails(); |
| 27 | $onboardingAttempt1 = wfConfig::get('onboardingAttempt1'); |
| 28 | if (!empty($alertEmails) && empty($onboardingAttempt1)) { |
| 29 | wfConfig::set('onboardingAttempt1', self::ONBOARDING_FIRST_LICENSE); //Mark onboarding as done |
| 30 | |
| 31 | $keys = array(self::TOUR_DASHBOARD, self::TOUR_FIREWALL, self::TOUR_SCAN, self::TOUR_BLOCKING, self::TOUR_LIVE_TRAFFIC); |
| 32 | foreach ($keys as $k) { |
| 33 | wfConfig::set('needsNewTour_' . $k, 0); |
| 34 | wfConfig::set('needsUpgradeTour_' . $k, 1); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Initializes the onboarding hooks. |
| 41 | * |
| 42 | * Only called if (is_admin() && wfUtils::isAdmin()) is true. |
| 43 | */ |
| 44 | public static function initialize() { |
| 45 | $willShowAnyTour = (self::shouldShowNewTour(self::TOUR_DASHBOARD) || self::shouldShowUpgradeTour(self::TOUR_DASHBOARD) || |
| 46 | self::shouldShowNewTour(self::TOUR_FIREWALL) || self::shouldShowUpgradeTour(self::TOUR_FIREWALL) || |
| 47 | self::shouldShowNewTour(self::TOUR_SCAN) || self::shouldShowUpgradeTour(self::TOUR_SCAN) || |
| 48 | self::shouldShowNewTour(self::TOUR_BLOCKING) || self::shouldShowUpgradeTour(self::TOUR_BLOCKING) || |
| 49 | self::shouldShowNewTour(self::TOUR_LIVE_TRAFFIC) || self::shouldShowUpgradeTour(self::TOUR_LIVE_TRAFFIC) || |
| 50 | self::shouldShowNewTour(self::TOUR_LOGIN_SECURITY) || self::shouldShowUpgradeTour(self::TOUR_LOGIN_SECURITY)); |
| 51 | if (!self::shouldShowAttempt1() && !self::shouldShowAttempt2() && !self::shouldShowAttempt3() && !$willShowAnyTour) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | add_action('in_admin_header', 'wfOnboardingController::_admin_header'); //Called immediately after <div id="wpcontent"> |
| 56 | add_action('pre_current_active_plugins', 'wfOnboardingController::_pre_plugins'); //Called immediately after <hr class="wp-header-end"> |
| 57 | add_action('admin_enqueue_scripts', 'wfOnboardingController::_enqueue_scripts'); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Enqueues the scripts and styles we need globally on the backend for onboarding. |
| 62 | */ |
| 63 | public static function _enqueue_scripts() { |
| 64 | $willShowAnyPluginOnboarding = (self::shouldShowAttempt1() || self::shouldShowAttempt2()); |
| 65 | $willShowAnyTour = (self::shouldShowNewTour(self::TOUR_DASHBOARD) || self::shouldShowUpgradeTour(self::TOUR_DASHBOARD) || |
| 66 | self::shouldShowNewTour(self::TOUR_FIREWALL) || self::shouldShowUpgradeTour(self::TOUR_FIREWALL) || |
| 67 | self::shouldShowNewTour(self::TOUR_SCAN) || self::shouldShowUpgradeTour(self::TOUR_SCAN) || |
| 68 | self::shouldShowNewTour(self::TOUR_BLOCKING) || self::shouldShowUpgradeTour(self::TOUR_BLOCKING) || |
| 69 | self::shouldShowNewTour(self::TOUR_LIVE_TRAFFIC) || self::shouldShowUpgradeTour(self::TOUR_LIVE_TRAFFIC) || |
| 70 | self::shouldShowNewTour(self::TOUR_LOGIN_SECURITY) || self::shouldShowUpgradeTour(self::TOUR_LOGIN_SECURITY)); |
| 71 | |
| 72 | if (wfUtils::isAdmin() && |
| 73 | (($willShowAnyPluginOnboarding && preg_match('~(?:^|/)wp-admin(?:/network)?/plugins\.php~i', $_SERVER['REQUEST_URI'])) || |
| 74 | (isset($_GET['page']) && |
| 75 | (preg_match('/^Wordfence/', @$_GET['page']) || |
| 76 | ($willShowAnyTour && preg_match('/^WFLS/', @$_GET['page'])) |
| 77 | ) |
| 78 | ) |
| 79 | ) |
| 80 | ) { |
| 81 | wp_enqueue_style('wordfence-font', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-roboto-font.css'), '', WORDFENCE_VERSION); |
| 82 | wp_enqueue_style('wordfence-ionicons-style', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-ionicons.css'), '', WORDFENCE_VERSION); |
| 83 | wp_enqueue_style('wordfenceOnboardingCSS', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-onboarding.css'), '', WORDFENCE_VERSION); |
| 84 | wp_enqueue_style('wordfence-colorbox-style', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-colorbox.css'), '', WORDFENCE_VERSION); |
| 85 | |
| 86 | wp_enqueue_script('jquery.wfcolorbox', wfUtils::getBaseURL() . wfUtils::versionedAsset('js/jquery.colorbox-min.js'), array('jquery'), WORDFENCE_VERSION); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Outputs the onboarding overlay if it needs to be shown on the plugins page. |
| 92 | */ |
| 93 | public static function _admin_header() { |
| 94 | $willShowAnyTour = (self::shouldShowNewTour(self::TOUR_DASHBOARD) || self::shouldShowUpgradeTour(self::TOUR_DASHBOARD) || |
| 95 | self::shouldShowNewTour(self::TOUR_FIREWALL) || self::shouldShowUpgradeTour(self::TOUR_FIREWALL) || |
| 96 | self::shouldShowNewTour(self::TOUR_SCAN) || self::shouldShowUpgradeTour(self::TOUR_SCAN) || |
| 97 | self::shouldShowNewTour(self::TOUR_BLOCKING) || self::shouldShowUpgradeTour(self::TOUR_BLOCKING) || |
| 98 | self::shouldShowNewTour(self::TOUR_LIVE_TRAFFIC) || self::shouldShowUpgradeTour(self::TOUR_LIVE_TRAFFIC) || |
| 99 | self::shouldShowNewTour(self::TOUR_LOGIN_SECURITY) || self::shouldShowUpgradeTour(self::TOUR_LOGIN_SECURITY)); |
| 100 | |
| 101 | $screen = get_current_screen(); |
| 102 | if ($screen->base == 'plugins' && self::shouldShowAttempt1()) { |
| 103 | register_shutdown_function('wfOnboardingController::_markAttempt1Shown'); |
| 104 | $freshInstall = wfView::create('onboarding/fresh-install')->render(); |
| 105 | |
| 106 | echo wfView::create('onboarding/overlay', array( |
| 107 | 'contentHTML' => $freshInstall, |
| 108 | ))->render(); |
| 109 | } |
| 110 | else if (preg_match('/wordfence/i', $screen->base) && $willShowAnyTour) { |
| 111 | echo wfView::create('onboarding/tour-overlay')->render(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | public static function _markAttempt1Shown() { |
| 116 | wfConfig::set('onboardingAttempt1', self::ONBOARDING_FIRST_SKIPPED); //Only show it once, default to skipped after outputting the first time |
| 117 | } |
| 118 | |
| 119 | public static function shouldShowAttempt1() { //Overlay on plugin page |
| 120 | if (wfConfig::get('onboardingAttempt3') == self::ONBOARDING_THIRD_LICENSE) { |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | switch (wfConfig::get('onboardingAttempt1')) { |
| 125 | case self::ONBOARDING_FIRST_LICENSE: |
| 126 | case self::ONBOARDING_FIRST_SKIPPED: |
| 127 | return false; |
| 128 | } |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | public static function _pre_plugins() { |
| 133 | if (self::shouldShowAttempt2()) { |
| 134 | echo wfView::create('onboarding/plugin-header')->render(); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | public static function shouldShowAttempt2() { //Header on plugin page |
| 139 | if (wfConfig::get('onboardingAttempt3') == self::ONBOARDING_THIRD_LICENSE) { |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | $alertEmails = wfConfig::getAlertEmails(); |
| 144 | $show = !wfConfig::get('onboardingAttempt2') && empty($alertEmails); //Unset defaults to true, all others false |
| 145 | return $show; |
| 146 | } |
| 147 | |
| 148 | public static function shouldShowAttempt3() { |
| 149 | if (isset($_GET['page']) && preg_match('/^Wordfence/', $_GET['page'])) { |
| 150 | $alertEmails = wfConfig::getAlertEmails(); |
| 151 | return empty($alertEmails); |
| 152 | } |
| 153 | |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Whether or not to pop up attempt 3 at page load or wait for user interaction. |
| 159 | * |
| 160 | * @return bool |
| 161 | */ |
| 162 | public static function shouldShowAttempt3Automatically() { |
| 163 | static $_shouldShowAttempt3Automatically = null; |
| 164 | if ($_shouldShowAttempt3Automatically !== null) { //We cache this so the answer remains the same for the whole request |
| 165 | return $_shouldShowAttempt3Automatically; |
| 166 | } |
| 167 | |
| 168 | if (!self::shouldShowAttempt3()) { |
| 169 | $_shouldShowAttempt3Automatically = false; |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | $_shouldShowAttempt3Automatically = (!wfConfig::get('onboardingAttempt3Initial')); |
| 174 | return (!wfConfig::get('onboardingAttempt3Initial')); |
| 175 | } |
| 176 | |
| 177 | public static function willShowNewTour($page) { |
| 178 | $key = 'needsNewTour_' . $page; |
| 179 | return wfConfig::get($key); |
| 180 | } |
| 181 | |
| 182 | public static function shouldShowNewTour($page) { |
| 183 | $key = 'needsNewTour_' . $page; |
| 184 | return (!self::shouldShowAttempt3Automatically() && !wfConfig::get('touppPromptNeeded') && wfConfig::get($key)); |
| 185 | } |
| 186 | |
| 187 | public static function willShowUpgradeTour($page) { |
| 188 | $key = 'needsUpgradeTour_' . $page; |
| 189 | return wfConfig::get($key); |
| 190 | } |
| 191 | |
| 192 | public static function shouldShowUpgradeTour($page) { |
| 193 | $key = 'needsUpgradeTour_' . $page; |
| 194 | return (!self::shouldShowAttempt3Automatically() && !wfConfig::get('touppPromptNeeded') && wfConfig::get($key)); |
| 195 | } |
| 196 | } |
| 197 |