false, 'blocklist' => false, ); $licence = Licence::stored(); if ( '' === $licence['key'] ) { return $result; } // An ended or unrecognised licence is only re-checked once an hour. if ( in_array( $licence['status'], array( 'expired', 'invalid' ), true ) ) { if ( time() - (int) $licence['checkedAt'] >= HOUR_IN_SECONDS ) { Licence::refresh( false ); } if ( ! Licence::service_on() ) { return $result; } } $answer = Api_Client::request( 'POST', '/checkin', self::checkin_body(), 8 ); if ( ! $answer['ok'] || ! is_array( $answer['data'] ) ) { Licence::apply( $answer, $licence, false ); if ( ! Licence::service_on() ) { return $result; } } else { $result['checkin'] = true; // The answer is read for one thing: the state of the licence. Anything else in it is ignored. if ( isset( $answer['data']['licence'] ) && is_array( $answer['data']['licence'] ) ) { Licence::apply_info( $answer['data']['licence'] ); } } if ( Licence::service_on() ) { $result['blocklist'] = Network::sync(); } return $result; } /** * What the store tells the service about itself, for the online dashboard. * * @return array CheckinRequest. */ public static function checkin_body() { global $wp_version; $now = time(); $totals = Events::totals( $now - DAY_IN_SECONDS, $now ); $lockdown = Lockdown::to_rest(); $state = Lockdown::state(); $attack = $state['attack_id'] > 0 ? Attacks::get( $state['attack_id'] ) : null; $settings = Settings::get(); return array( 'pluginVersion' => BRICKMOAT_VERSION, 'wcVersion' => defined( 'WC_VERSION' ) ? WC_VERSION : '', 'wpVersion' => (string) $wp_version, 'storeName' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), // Where the dashboard's "Open in WordPress" link leads: this plugin's own screen. 'adminUrl' => admin_url( 'admin.php?page=brickmoat' ), 'mode' => $lockdown['on'] ? 'lockdown' : 'normal', 'lockdownReason' => $lockdown['reason'], 'totals' => array( 'attempts' => $totals['attempts'], 'allowed' => $totals['allowed'], 'challenged' => $totals['challenged'], 'blocked' => $totals['blocked'], 'declined' => $totals['declined'], ), 'openAttack' => $attack ? array( 'localId' => (int) $attack['id'], 'startedAt' => Util::iso( (int) $attack['started'] ), ) : null, 'pendingCleanup' => Cleanup::pending_count(), // Shown on the dashboard, read-only: they can only be changed on the Settings screen here. 'settings' => array( 'level' => $settings['level'], 'autoLockdown' => (bool) $settings['autoLockdown'], 'challengeGuestsInLockdown' => (bool) $settings['challengeGuestsInLockdown'], 'blockUnknownInLockdown' => (bool) $settings['blockUnknownInLockdown'], ), ); } }