| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Atomic Edge Security |
| 4 |
* Plugin URI: https://atomicedge.io/wordpress |
| 5 |
* Description: Connect your WordPress site to Atomic Edge WAF/CDN for advanced security protection, analytics, and access control management. |
| 6 |
* Version: 2.9.0 |
| 7 |
* Requires at least: 5.8 |
| 8 |
* Requires PHP: 7.4 |
| 9 |
* Tested up to: 7.0 |
| 10 |
* Author: Atomic Edge |
| 11 |
* Author URI: https://atomicedge.io |
| 12 |
* License: GPL v2 or later |
| 13 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 14 |
* Text Domain: atomic-edge-security |
| 15 |
* Domain Path: /languages |
| 16 |
* |
| 17 |
* GitHub Plugin URI: https://github.com/stardothosting/atomicedge-wordpress |
| 18 |
* Primary Branch: main |
| 19 |
* @package AtomicEdge |
| 20 |
*/ |
| 21 |
|
| 22 |
// Prevent direct access. |
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; |
| 25 |
} |
| 26 |
|
| 27 |
// Plugin constants. |
| 28 |
define( 'ATOMICEDGE_VERSION', '2.9.0' ); |
| 29 |
define( 'ATOMICEDGE_PLUGIN_FILE', __FILE__ ); |
| 30 |
define( 'ATOMICEDGE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 31 |
define( 'ATOMICEDGE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 32 |
define( 'ATOMICEDGE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 33 |
|
| 34 |
// Minimum requirements. |
| 35 |
define( 'ATOMICEDGE_MIN_PHP_VERSION', '7.4' ); |
| 36 |
define( 'ATOMICEDGE_MIN_WP_VERSION', '5.8' ); |
| 37 |
|
| 38 |
define( 'ATOMICEDGE_TESTED_UP_TO', '7.0' ); |
| 39 |
|
| 40 |
/** |
| 41 |
* Check minimum requirements before loading the plugin. |
| 42 |
* |
| 43 |
* @return bool True if requirements are met, false otherwise. |
| 44 |
*/ |
| 45 |
function atomicedge_check_requirements() { |
| 46 |
$errors = array(); |
| 47 |
|
| 48 |
// Check PHP version. |
| 49 |
if ( version_compare( PHP_VERSION, ATOMICEDGE_MIN_PHP_VERSION, '<' ) ) { |
| 50 |
$errors[] = sprintf( |
| 51 |
/* translators: 1: Current PHP version, 2: Required PHP version */ |
| 52 |
esc_html__( 'Atomic Edge Security requires PHP %2$s or higher. You are running PHP %1$s.', 'atomic-edge-security' ), |
| 53 |
esc_html( PHP_VERSION ), |
| 54 |
esc_html( ATOMICEDGE_MIN_PHP_VERSION ) |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
// Check WordPress version. |
| 59 |
global $wp_version; |
| 60 |
if ( version_compare( $wp_version, ATOMICEDGE_MIN_WP_VERSION, '<' ) ) { |
| 61 |
$errors[] = sprintf( |
| 62 |
/* translators: 1: Current WordPress version, 2: Required WordPress version */ |
| 63 |
esc_html__( 'Atomic Edge Security requires WordPress %2$s or higher. You are running WordPress %1$s.', 'atomic-edge-security' ), |
| 64 |
esc_html( $wp_version ), |
| 65 |
esc_html( ATOMICEDGE_MIN_WP_VERSION ) |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
// Check for OpenSSL (required for API key encryption). |
| 70 |
if ( ! function_exists( 'openssl_encrypt' ) ) { |
| 71 |
$errors[] = esc_html__( 'Atomic Edge Security requires the OpenSSL PHP extension to be enabled.', 'atomic-edge-security' ); |
| 72 |
} |
| 73 |
|
| 74 |
if ( ! empty( $errors ) ) { |
| 75 |
add_action( |
| 76 |
'admin_notices', |
| 77 |
function () use ( $errors ) { |
| 78 |
?> |
| 79 |
<div class="notice notice-error"> |
| 80 |
<p><strong><?php esc_html_e( 'Atomic Edge Security cannot be activated:', 'atomic-edge-security' ); ?></strong></p> |
| 81 |
<ul> |
| 82 |
<?php foreach ( $errors as $error ) : ?> |
| 83 |
<li><?php echo esc_html( $error ); ?></li> |
| 84 |
<?php endforeach; ?> |
| 85 |
</ul> |
| 86 |
</div> |
| 87 |
<?php |
| 88 |
} |
| 89 |
); |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
return true; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Initialize the plugin. |
| 98 |
* |
| 99 |
* @return void |
| 100 |
*/ |
| 101 |
function atomicedge_init() { |
| 102 |
// Load plugin translations. |
| 103 |
load_plugin_textdomain( 'atomic-edge-security', false, dirname( ATOMICEDGE_PLUGIN_BASENAME ) . '/languages' ); |
| 104 |
|
| 105 |
// Check requirements. |
| 106 |
if ( ! atomicedge_check_requirements() ) { |
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
// Include required files. |
| 111 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge.php'; |
| 112 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-api.php'; |
| 113 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-dev-mode.php'; |
| 114 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-admin.php'; |
| 115 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-ajax.php'; |
| 116 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-scanner.php'; |
| 117 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-vulnerability-scanner.php'; |
| 118 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-cron.php'; |
| 119 |
|
| 120 |
// CDN classes. |
| 121 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-cdn-rules.php'; |
| 122 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-cdn-rewrite.php'; |
| 123 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-cdn.php'; |
| 124 |
|
| 125 |
// Two-Factor Authentication classes. |
| 126 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-2fa-crypto.php'; |
| 127 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-2fa-totp.php'; |
| 128 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-2fa-backup.php'; |
| 129 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-2fa-policy.php'; |
| 130 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-2fa-audit.php'; |
| 131 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-2fa.php'; |
| 132 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-2fa-login.php'; |
| 133 |
|
| 134 |
// Initialize 2FA Audit system. |
| 135 |
AtomicEdge_2FA_Audit::init(); |
| 136 |
|
| 137 |
// Load WP-CLI commands if available. |
| 138 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 139 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-cli.php'; |
| 140 |
} |
| 141 |
|
| 142 |
// Initialize main plugin class. |
| 143 |
AtomicEdge::get_instance(); |
| 144 |
} |
| 145 |
add_action( 'plugins_loaded', 'atomicedge_init' ); |
| 146 |
|
| 147 |
/** |
| 148 |
* Install/upgrade database schema used by the malware scanner. |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
function atomicedge_install_scanner_schema() { |
| 153 |
global $wpdb; |
| 154 |
|
| 155 |
$table_name = $wpdb->prefix . 'atomicedge_scan_queue'; |
| 156 |
$charset_collate = $wpdb->get_charset_collate(); |
| 157 |
|
| 158 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 159 |
|
| 160 |
$sql = "CREATE TABLE {$table_name} ( |
| 161 |
id bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
| 162 |
run_id char(36) NOT NULL, |
| 163 |
item_type varchar(10) NOT NULL, |
| 164 |
area varchar(20) NOT NULL DEFAULT '', |
| 165 |
path longtext NOT NULL, |
| 166 |
path_hash char(32) NOT NULL, |
| 167 |
status varchar(20) NOT NULL DEFAULT 'pending', |
| 168 |
meta longtext NULL, |
| 169 |
last_error longtext NULL, |
| 170 |
created_at datetime NOT NULL, |
| 171 |
updated_at datetime NOT NULL, |
| 172 |
PRIMARY KEY (id), |
| 173 |
KEY run_status (run_id,status,id), |
| 174 |
KEY run_type_status (run_id,item_type,status,id), |
| 175 |
UNIQUE KEY run_item (run_id,item_type,path_hash) |
| 176 |
) {$charset_collate};"; |
| 177 |
|
| 178 |
dbDelta( $sql ); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Plugin activation hook. |
| 183 |
* |
| 184 |
* @return void |
| 185 |
*/ |
| 186 |
function atomicedge_activate() { |
| 187 |
// Check requirements on activation. |
| 188 |
if ( ! atomicedge_check_requirements() ) { |
| 189 |
deactivate_plugins( ATOMICEDGE_PLUGIN_BASENAME ); |
| 190 |
wp_die( |
| 191 |
esc_html__( 'AtomicEdge Security cannot be activated. Please check the requirements.', 'atomic-edge-security' ), |
| 192 |
esc_html__( 'Plugin Activation Error', 'atomic-edge-security' ), |
| 193 |
array( 'back_link' => true ) |
| 194 |
); |
| 195 |
} |
| 196 |
|
| 197 |
// Set default options. |
| 198 |
$defaults = array( |
| 199 |
'api_url' => 'https://dashboard.atomicedge.io/api/v1', |
| 200 |
'connected' => false, |
| 201 |
); |
| 202 |
|
| 203 |
foreach ( $defaults as $key => $value ) { |
| 204 |
if ( false === get_option( 'atomicedge_' . $key ) ) { |
| 205 |
add_option( 'atomicedge_' . $key, $value ); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
// Ensure scanner DB schema exists. |
| 210 |
atomicedge_install_scanner_schema(); |
| 211 |
|
| 212 |
// Schedule cron events. |
| 213 |
if ( ! wp_next_scheduled( 'atomicedge_daily_scan' ) ) { |
| 214 |
wp_schedule_event( time(), 'daily', 'atomicedge_daily_scan' ); |
| 215 |
} |
| 216 |
|
| 217 |
// Schedule CDN cache cleanup. |
| 218 |
// Load Cron class if not already loaded (activation hook fires before plugins_loaded). |
| 219 |
if ( ! class_exists( 'AtomicEdge_Cron' ) ) { |
| 220 |
require_once ATOMICEDGE_PLUGIN_DIR . 'includes/class-atomicedge-cron.php'; |
| 221 |
} |
| 222 |
AtomicEdge_Cron::schedule_cdn_cleanup(); |
| 223 |
|
| 224 |
// Flush rewrite rules. |
| 225 |
flush_rewrite_rules(); |
| 226 |
} |
| 227 |
register_activation_hook( __FILE__, 'atomicedge_activate' ); |
| 228 |
|
| 229 |
/** |
| 230 |
* Plugin deactivation hook. |
| 231 |
* |
| 232 |
* @return void |
| 233 |
*/ |
| 234 |
function atomicedge_deactivate() { |
| 235 |
// Clear scheduled events. |
| 236 |
wp_clear_scheduled_hook( 'atomicedge_daily_scan' ); |
| 237 |
wp_clear_scheduled_hook( 'atomicedge_sync_settings' ); |
| 238 |
wp_clear_scheduled_hook( 'atomicedge_cdn_cache_cleanup' ); |
| 239 |
|
| 240 |
// Flush rewrite rules. |
| 241 |
flush_rewrite_rules(); |
| 242 |
} |
| 243 |
register_deactivation_hook( __FILE__, 'atomicedge_deactivate' ); |
| 244 |
|
| 245 |
/** |
| 246 |
* Add settings link to plugins page. |
| 247 |
* |
| 248 |
* @param array $links Existing plugin action links. |
| 249 |
* @return array Modified plugin action links. |
| 250 |
*/ |
| 251 |
function atomicedge_plugin_action_links( $links ) { |
| 252 |
$settings_link = sprintf( |
| 253 |
'<a href="%s">%s</a>', |
| 254 |
esc_url( admin_url( 'admin.php?page=atomicedge' ) ), |
| 255 |
esc_html__( 'Settings', 'atomic-edge-security' ) |
| 256 |
); |
| 257 |
array_unshift( $links, $settings_link ); |
| 258 |
return $links; |
| 259 |
} |
| 260 |
add_filter( 'plugin_action_links_' . ATOMICEDGE_PLUGIN_BASENAME, 'atomicedge_plugin_action_links' ); |
| 261 |
|