current_time( 'mysql' ), 'summary' => sanitize_text_field( $summary ), ) ); update_option( 'syslock_events', array_slice( $events, 0, 5 ), false ); // Rate-limit emails: max 1 email per 60 minutes per event type. $lock_transient = 'syslock_mail_' . md5( $event_key ); if ( get_transient( $lock_transient ) ) { return; } set_transient( $lock_transient, 1, HOUR_IN_SECONDS ); $admin_email = get_option( 'admin_email' ); if ( ! is_email( $admin_email ) ) { return; } $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $site_url = home_url(); $body = "SysLock Security Alert on {$site_name} ({$site_url})\n"; $body .= str_repeat( '-', 55 ) . "\n\n"; $body .= "Blocked action: {$summary}\n"; if ( '' !== $details ) { $body .= "Details: {$details}\n"; } $body .= 'Time (server): ' . current_time( 'Y-m-d H:i:s' ) . "\n\n"; $body .= "If this action was intentional, temporarily deactivate SysLock under Plugins (or define SYSLOCK_UNLOCK in wp-config.php) and reactivate it once finished.\n"; wp_mail( $admin_email, sprintf( '[SysLock] Blocked: %s (%s)', $summary, $site_name ), $body ); } /** * Send reminder email if the plugin is deactivated so the admin remembers to re-enable it. * Note: Stored quarantine timestamps and logs are preserved across temporary deactivations. */ register_deactivation_hook( __FILE__, function (): void { $admin_email = get_option( 'admin_email' ); if ( ! is_email( $admin_email ) ) { return; } $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); $body = "SysLock has been deactivated on {$site_name} (" . home_url() . ").\n\n"; $body .= "Identity lock and 72-hour update quarantine are currently paused.\n"; $body .= "Remember to reactivate SysLock from Plugins once you finish your administrative changes.\n"; wp_mail( $admin_email, sprintf( '[SysLock] Plugin deactivated on %s', $site_name ), $body ); } ); // Bootstrap modules. add_action( 'plugins_loaded', function (): void { ( new SysLock_Hardening() )->init(); ( new SysLock_Quarantine() )->init(); if ( is_admin() ) { ( new SysLock_Admin() )->init(); } if ( defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::add_command( 'syslock audit', function (): void { $results = SysLock_Auditor::run_audit(); if ( empty( $results['issues'] ) ) { WP_CLI::success( 'No integrity, permission, or exposure issues detected.' ); return; } foreach ( $results['issues'] as $issue ) { WP_CLI::warning( sprintf( '[%s] %s — %s', $issue['category'], $issue['target'], $issue['message'] ) ); } } ); } } );