PluginProbe
Two Factor Authentication / 1.14.3
Two Factor Authentication v1.14.3
1.12.2 1.13.0 1.14.10 1.14.11 1.14.14 1.14.15 1.14.16 1.14.17 1.14.23 1.14.24 1.14.26 1.14.27 1.14.3 1.14.4 1.14.5 1.14.7 1.14.8 1.15.5 1.16.0 1.2.10 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 All 98 releases
two-factor-authentication / two-factor-login.php

two-factor-login.php in Two Factor Authentication 1.14.3, at two-factor-login.php

169 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Two Factor Authentication
4 Plugin URI: https://www.simbahosting.co.uk/s3/product/two-factor-authentication/
5 Description: Secure your WordPress login forms with two factor authentication - including WooCommerce login forms
6 Author: David Anderson, original plugin by Oskar Hane and enhanced by Dee Nutbourne
7 Author URI: https://www.simbahosting.co.uk
8 Version: 1.14.3
9 Text Domain: two-factor-authentication
10 Domain Path: /languages
11 License: GPLv2 or later
12 */
13
14 // N.B. We don't use __DIR__ (PHP 5.4+) because we want to show a clean error on earlier versions - i.e. this file still supports earlier versions.
15 if (!empty($GLOBALS['simba_two_factor_authentication']) && file_exists(dirname(__FILE__).'/simba-tfa/premium/loader.php')) {
16 throw new Exception('To activate Two Factor Authentication Premium, first de-activate the free version (only one can be active at once).');
17 }
18
19 if (!defined('SIMBA_TFA_TEXT_DOMAIN')) define('SIMBA_TFA_TEXT_DOMAIN', 'two-factor-authentication');
20 if (!class_exists('Simba_Two_Factor_Authentication')) require dirname(__FILE__).'/simba-tfa/simba-tfa.php';
21
22 /**
23 * This parent-child relationship enables the two to be split without affecting backwards compatibility for developers making direct calls
24 *
25 * This class is for the plugin encapsulation.
26 */
27 class Simba_Two_Factor_Authentication_Plugin extends Simba_Two_Factor_Authentication {
28
29 public $version = '1.14.3';
30
31 const PHP_REQUIRED = '5.6';
32
33 /**
34 * Constructor, run upon plugin initiation
35 *
36 * @uses __FILE__
37 */
38 public function __construct() {
39
40 add_action('plugins_loaded', array($this, 'plugins_loaded_load_textdomain'));
41
42 if (version_compare(PHP_VERSION, self::PHP_REQUIRED, '<' )) {
43 add_action('all_admin_notices', array($this, 'admin_notice_insufficient_php'));
44 $abort = true;
45 }
46
47 if (!function_exists('mcrypt_get_iv_size') && !function_exists('openssl_cipher_iv_length')) {
48 add_action('all_admin_notices', array($this, 'admin_notice_missing_mcrypt_and_openssl'));
49 $abort = true;
50 }
51
52 if (!empty($abort)) return;
53
54 // Menu entries
55 add_action('admin_menu', array($this, 'menu_entry_for_admin'));
56 add_action('admin_menu', array($this, 'menu_entry_for_user'));
57 add_action('network_admin_menu', array($this, 'menu_entry_for_user'));
58
59 // Add settings link in plugin list
60 $plugin = plugin_basename(__FILE__);
61 add_filter("plugin_action_links_$plugin", array($this, 'add_plugin_settings_link'));
62 add_filter("network_admin_plugin_action_links_$plugin", array($this, 'add_plugin_settings_link'));
63
64 parent::__construct();
65
66 }
67
68 /**
69 * Give the filesystem path to the plugin's vendor directory
70 *
71 * @return String
72 */
73 public function vendor_dir() {
74 return __DIR__.'/vendor';
75 }
76
77 /**
78 * Runs upon the WP filters plugin_action_links_(plugin) and network_plugin_action_links_(plugin)
79 *
80 * @param Array $links
81 *
82 * @return Array
83 */
84 public function add_plugin_settings_link($links) {
85 if (!is_network_admin()) {
86 $link = '<a href="options-general.php?page=two-factor-auth">'.__('Plugin settings', 'two-factor-authentication').'</a>';
87 array_unshift($links, $link);
88 } else {
89 switch_to_blog(1);
90 $link = '<a href="'.admin_url('options-general.php').'?page=two-factor-auth">'.__('Plugin settings', 'two-factor-authentication').'</a>';
91 restore_current_blog();
92 array_unshift($links, $link);
93 }
94
95 $link2 = '<a href="admin.php?page=two-factor-auth-user">'.__('User settings', 'two-factor-authentication').'</a>';
96 array_unshift($links, $link2);
97
98 return $links;
99 }
100
101 /**
102 * Runs upon the WP actions admin_menu and network_admin_menu
103 */
104 public function menu_entry_for_user() {
105
106 $this->get_totp_controller()->potentially_port_private_keys();
107
108 global $current_user;
109 if ($this->is_activated_for_user($current_user->ID)) {
110 add_menu_page(__('Two Factor Authentication', 'two-factor-authentication'), __('Two Factor Auth', 'two-factor-authentication'), 'read', 'two-factor-auth-user', array($this, 'show_dashboard_user_settings_page'), $this->includes_url().'/tfa_admin_icon_16x16.png', 72);
111 }
112 }
113
114 /**
115 * Runs upon the WP action admin_menu
116 */
117 public function menu_entry_for_admin() {
118
119 $this->get_totp_controller()->potentially_port_private_keys();
120
121 if (is_multisite() && (!is_super_admin() || !is_main_site())) return;
122
123 add_options_page(
124 __('Two Factor Authentication', 'two-factor-authentication'),
125 __('Two Factor Authentication', 'two-factor-authentication'),
126 $this->get_management_capability(),
127 'two-factor-auth',
128 array($this, 'show_admin_settings_page')
129 );
130 }
131
132 /**
133 * Include the admin settings page code
134 */
135 public function show_admin_settings_page() {
136 $totp_controller = $this->get_totp_controller();
137 $totp_controller->setUserHMACTypes();
138 if (!is_admin() || !current_user_can($this->get_management_capability())) return;
139 $this->include_template('admin-settings.php', array('totp_controller' => $totp_controller));
140 }
141
142 /**
143 * Runs conditionally on the WP action all_admin_notices
144 */
145 public function admin_notice_insufficient_php() {
146 $this->show_admin_warning('<strong>'.__('Higher PHP version required', 'two-factor-authentication').'</strong><br> '.sprintf(__('The Two Factor Authentication plugin requires PHP version %s or higher - your current version is only %s.', 'two-factor-authentication'), self::PHP_REQUIRED, PHP_VERSION), 'error');
147 }
148
149 /**
150 * Runs conditionally on the WP action all_admin_notices
151 */
152 public function admin_notice_missing_mcrypt_and_openssl() {
153 $this->show_admin_warning('<strong>'.__('PHP OpenSSL or mcrypt module required', 'two-factor-authentication').'</strong><br> '.__('The Two Factor Authentication plugin requires either the PHP openssl (preferred) or mcrypt module to be installed. Please ask your web hosting company to install one of them.', 'two-factor-authentication'), 'error');
154 }
155
156 /**
157 * Run upon the WP plugins_loaded action. This method is called even if main loading aborts - so don't put anything else in it (use a separate method).
158 */
159 public function plugins_loaded_load_textdomain() {
160 load_plugin_textdomain(
161 'two-factor-authentication',
162 false,
163 dirname(plugin_basename(__FILE__)).'/languages/'
164 );
165 }
166 }
167
168 $GLOBALS['simba_two_factor_authentication'] = new Simba_Two_Factor_Authentication_Plugin();
169