-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathauthpress.php
More file actions
184 lines (145 loc) · 4.97 KB
/
authpress.php
File metadata and controls
184 lines (145 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* Plugin Name: AuthPress
* Plugin URI: https://www.authpress.dev
* Description: Advanced WordPress 2FA plugin with multiple authentication providers: Telegram, Email, Authenticator Apps, and extensible custom providers.
* Version: 4.0.2
* Requires at least: 6.0
* Tested up to: 6.8
* Requires PHP: 7.0
* Author: dueclic
* Author URI: https://www.dueclic.com
* Text Domain: two-factor-login-telegram
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
error_reporting(E_ERROR);
if (!defined('ABSPATH')) {
die;
}
define('AUTHPRESS_PLUGIN_VERSION', '4.0.2');
if (!function_exists('get_auth_token_duration')) {
function get_auth_token_duration() {
$providers = authpress_providers();
$duration = $providers['email']['token_duration'] ?? 20;
return absint($duration) * 60;
}
}
/**
*
* Full path to the AuthPress File
*
*/
define('AUTHPRESS_PLUGIN_FILE', __FILE__);
define('AUTHPRESS_TG_GETME_TRANSIENT', 'authpress_provider_telegram_valid_bot');
/**
*
* The main plugin class
*
*/
// Load PhpQrCode PHP lib
if (file_exists(dirname(__FILE__) . '/lib/phpqrcode/qrlib.php')) {
require_once(dirname(__FILE__) . '/lib/phpqrcode/qrlib.php');
}
require_once(dirname(__FILE__) . "/includes/class-authpress-plugin.php");
function authpress_provider_categories(
$available_providers = array()
)
{
$provider_categories = [
'messaging' => [
'title' => __("Messaging Providers", "two-factor-login-telegram"),
'description' => __("Receive authentication codes directly via messaging platforms.", "two-factor-login-telegram"),
'providers' => ['telegram', 'email']
],
'authenticator' => [
'title' => __("Authenticator Apps", "two-factor-login-telegram"),
'description' => __("Time-based One-Time Password apps that generate codes offline.", "two-factor-login-telegram"),
'providers' => ['authenticator']
]
];
$provider_categories = apply_filters('authpress_provider_categories', $provider_categories);
$categorized_providers = [];
foreach ($provider_categories as $category) {
$categorized_providers = array_merge($categorized_providers, $category['providers']);
}
$uncategorized_providers = array_diff(array_keys($available_providers), $categorized_providers);
// Exclude recovery_codes from being shown in admin interface - it's a backend-only provider
$uncategorized_providers = array_diff($uncategorized_providers, ['recovery_codes']);
if (!empty($uncategorized_providers)) {
$provider_categories['other'] = [
'title' => __("Other Providers", "two-factor-login-telegram"),
'description' => __("Additional 2FA methods provided by plugins.", "two-factor-login-telegram"),
'providers' => $uncategorized_providers
];
}
return $provider_categories;
}
function authpress_providers()
{
$authpress_providers = get_option('authpress_providers', array(
'authenticator' => array('enabled' => false),
'telegram' => array('enabled' => false, 'bot_token' => '', 'failed_login_reports' => false),
'email' => array('enabled' => false)
));
return apply_filters('authpress_providers', $authpress_providers);
}
function authpress_provider_config(
$provider_name
)
{
$providers = authpress_providers();
if (isset($providers[$provider_name])) {
return $providers[$provider_name];
}
return null;
}
/**
* @param $category
* @return bool
*/
function authpress_category_has_providers(
$category,
$available_providers
){
$has_available_providers = false;
foreach ($category['providers'] as $provider_key) {
$provider = $available_providers[$provider_key] ?? null;
if ($provider) {
$has_available_providers = true;
break;
}
}
return apply_filters('authpress_category_has_providers', $has_available_providers, $category, $available_providers);
}
function authpress_logo()
{
$plugin_logo = plugins_url('assets/images/plugin_logo.png', AUTHPRESS_PLUGIN_FILE);
$plugin_logo = apply_filters_deprecated(
'two_factor_login_telegram_logo',
array($plugin_logo),
'4.0.0',
'authpress_logo',
__('two_factor_login_telegram_logo filter is deprecated. Use authpress_logo instead.', 'two-factor-login-telegram')
);
return apply_filters('authpress_logo', $plugin_logo);
}
function authpress_get_template($template_path, $context = array(), $full_path = false)
{
$full_path = $full_path ? $template_path : plugin_dir_path(AUTHPRESS_PLUGIN_FILE) . $template_path;
if (!file_exists($full_path)) {
return '';
}
// Extract context variables
if (!empty($context)) {
extract($context, EXTR_SKIP);
}
ob_start();
include $full_path;
return ob_get_clean();
}
function authpress_init()
{
return \Authpress\AuthPress_Plugin::get_instance();
}
authpress_init();