public function subscribeToNewsletter($email) { if (RublonHelper::isSiteRegistered()) { require_once dirname(__FILE__) . '/libs/RublonImplemented/RublonAPINewsletterSignup.php'; $signup = new RublonAPINewsletterSignup($this->rublon, $email); try { $signup->perform(); $result = $signup->subscribedSuccessfully(); } catch (RublonException $e) { if ($e instanceof RublonAPIException) { $response = $e->getClient()->getResponse(); if (!empty($response[RublonAPINewsletterSignup::FIELD_RESULT]) && !empty($response[RublonAPINewsletterSignup::FIELD_RESULT]['exception']) && $response[RublonAPINewsletterSignup::FIELD_RESULT]['exception'] == 'AlreadySubscribed_NewsletterException') { $result = self::ERROR_ALREADY_SUBSCRIBED; } else { $result = self::ERROR_NL_API; } } else { $result = self::ERROR_NL_RUBLON_API; } } return $result !== false ? $result : self::ERROR_NL_RUBLON_API; } else { return self::ERROR_RUBLON_NOT_CONFIGURED; } }
/** * Create Trusted Devices Widget container for WP Dashboard * * @return string */ public function getTDMWidget() { $result = ''; if (RublonHelper::isSiteRegistered()) { if (RublonHelper::canShowTDMWidget()) { $current_user = wp_get_current_user(); $protection_type = RublonHelper::YES; RublonHelper::isUserProtected($current_user, $protection_type); switch ($protection_type) { case RublonHelper::PROTECTION_TYPE_MOBILE: $result .= '<p>' . sprintf(__('Your account is protected by <a href="%s" target="_blank">Rublon</a>.', 'rublon'), RublonHelper::rubloncomUrl()) . '</p>'; break; case RublonHelper::PROTECTION_TYPE_EMAIL: $result .= '<p>' . sprintf(__('Your account is protected by <a href="%s" target="_blank">Rublon</a>.', 'rublon'), RublonHelper::rubloncomUrl()) . ' ' . sprintf(__('Get the <a href="%s/get" target="_blank">Rublon mobile app</a> for more security.', 'rublon'), RublonHelper::rubloncomUrl()) . '</p>'; break; case RublonHelper::PROTECTION_TYPE_NONE: $lang = RublonHelper::getBlogLanguage(); $result .= '<p>' . sprintf('<span style="color: red; font-weight: bold;">' . __('Warning!', 'rublon') . '</span>' . ' ' . __('Your account is not protected. Go to <a href="%s">your profile page</a> to enable account protection.', 'rublon'), admin_url(RublonHelper::WP_PROFILE_PAGE . RublonHelper::WP_PROFILE_EMAIL2FA_SECTION)) . '</p>'; break; } $result .= $this->getDeviceWidget(); } else { $result = '<p>' . __('Your account isn\'t protected by Rublon and thus vulnerable to password theft and brute force attacks. Please contact your administrator. ') . '</p>'; } } return $result; }
private function __construct() { if (current_user_can('manage_options')) { if (!RublonHelper::isSiteRegistered() || RublonHelper::isTrackingAllowed() === null) { wp_enqueue_style('wp-pointer'); wp_enqueue_script('jquery-ui'); wp_enqueue_script('wp-pointer'); wp_enqueue_script('utils'); if (RublonHelper::isTrackingAllowed() === null) { add_action('admin_print_footer_scripts', array($this, 'anonymousStats')); } elseif (!RublonHelper::isSiteRegistered()) { try { $consumer_registration = new RublonConsumerRegistrationWordPress(); $this->_apireg_form = $consumer_registration->retrieveRegistrationForm(); add_action('admin_print_footer_scripts', array($this, 'apiRegistration')); } catch (Exception $e) { RublonHelper::handleRegistrationException($e, $no_redirect = true); } } } } }
static function pluginsLoaded() { if (RublonHelper::isSiteRegistered()) { foreach (self::$strategies as $action) { if ($strategy = RublonConfirmStrategy::getStrategyInstance($action)) { $strategy->pluginsLoaded(); } } } }
public function canUserActivate() { return !RublonHelper::isSiteRegistered() && current_user_can('manage_options'); }
function rublon2factor_add_dashboard_device_widget() { if (RublonHelper::isSiteRegistered()) { wp_add_dashboard_widget('rublon_dashboard_device_widget', __('Account Protection', 'rublon'), 'RublonHelper::createDashboardDeviceWidget'); } global $wp_meta_boxes; $normal_core = $wp_meta_boxes['dashboard']['normal']['core']; $side_core = $wp_meta_boxes['dashboard']['side']['core']; if (!empty($normal_core['rublon_dashboard_device_widget']) && !empty($side_core['dashboard_quick_press'])) { $rublon_widget = $normal_core['rublon_dashboard_device_widget']; unset($normal_core['rublon_dashboard_device_widget']); $new_side_core = array(); foreach ($side_core as $widget_name => $widget) { $new_side_core[$widget_name] = $widget; if ($widget_name == 'dashboard_quick_press') { $new_side_core['rublon_dashboard_device_widget'] = $rublon_widget; } } $side_core = $new_side_core; } $wp_meta_boxes['dashboard']['normal']['core'] = $normal_core; $wp_meta_boxes['dashboard']['side']['core'] = $side_core; }
/** * Add the Rublon icon and menu to the toolbar * */ function rublon2factor_modify_admin_toolbar() { global $wp_admin_bar; $current_user = wp_get_current_user(); if (RublonHelper::isSiteRegistered() && RublonHelper::isUserAuthenticated($current_user) && is_object($wp_admin_bar)) { // add a Rublon icon to the my-account node $my_account = $wp_admin_bar->get_node('my-account'); if (is_object($my_account) && property_exists($my_account, 'title')) { $my_account->title = $my_account->title . '<img id="rublon-toolbar-logo" class="rublon-image" src="' . RUBLON2FACTOR_PLUGIN_URL . '/assets/images/rublon_logo_32x32.png' . '" />'; $wp_admin_bar->remove_node('my-account'); $wp_admin_bar->add_node($my_account); } // remove all my-account subnodes except user-info $nodes = $wp_admin_bar->get_nodes(); if (is_array($nodes)) { $removed_nodes = array(); foreach ($nodes as $node) { if (!empty($node->title) && !empty($node->parent) && !empty($node->id) && $node->parent == 'user-actions' && $node->id != 'user-info') { array_push($removed_nodes, $node); $wp_admin_bar->remove_node($node->id); } } // add Rublon node $wp_admin_bar->add_node(array('id' => 'rublon', 'title' => __('Protected by Rublon', 'rublon'), 'href' => admin_url(RublonHelper::WP_RUBLON_PAGE), 'parent' => 'user-actions')); // restore all removed nodes foreach ($removed_nodes as $node) { $wp_admin_bar->add_node($node); } } } }
/** * Check if a single site registration is needed. * * If the multisite network has been registered * in Rublon, perform a single site registration. * * @param WP_User|null $user (optional) WordPress user * @return void */ public static function checkSubprojectRegistration($user = null) { if (self::isNetworkRegistered() && !is_main_site() && !RublonHelper::isSiteRegistered()) { if (!empty($user) && $user instanceof WP_User) { $current_user = $user; $user_can_register_subproject = true; } else { $current_user = wp_get_current_user(); $user_can_register_subproject = is_user_logged_in(); } if ($current_user instanceof WP_User && $user_can_register_subproject) { self::performSiteRegistration(); } } }
/** * Get the features list from Rublon server. * * @return NULL|array */ static function getFeaturesFromServer() { if (!RublonHelper::isSiteRegistered()) { return null; } try { $client = new RublonAPIGetAvailableFeatures(RublonHelper::getRublon()); $client->perform(); return $client->getFeatures(); } catch (RublonException $e) { return null; } }