ARGUS WordPress Defence 1.0.0 — first production release
Automatic WordPress security: local firewall, malware and file-integrity scanning, vulnerability protection, quarantine, scheduled backups, an optional page cache, and automatic global threat intelligence. See README.md for installation, update, and uninstall instructions.
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Argus_MU_Installer {
|
||||
|
||||
public static function mu_plugins_dir() {
|
||||
return WPMU_PLUGIN_DIR;
|
||||
}
|
||||
|
||||
public static function target_path() {
|
||||
return trailingslashit( self::mu_plugins_dir() ) . 'argus-mu-core.php';
|
||||
}
|
||||
|
||||
public static function source_path() {
|
||||
return ARGUS_WPD_DIR . 'mu-loader/argus-mu-core.php';
|
||||
}
|
||||
|
||||
public static function install() {
|
||||
$dir = self::mu_plugins_dir();
|
||||
|
||||
if ( ! file_exists( $dir ) ) {
|
||||
if ( ! wp_mkdir_p( $dir ) ) {
|
||||
update_option( 'argus_wpd_mu_install_status', 'failed_mkdir', false );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_writable( $dir ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions
|
||||
update_option( 'argus_wpd_mu_install_status', 'not_writable', false );
|
||||
return false;
|
||||
}
|
||||
|
||||
$copied = copy( self::source_path(), self::target_path() );
|
||||
update_option( 'argus_wpd_mu_install_status', $copied ? 'installed' : 'failed_copy', false );
|
||||
|
||||
return $copied;
|
||||
}
|
||||
|
||||
const SELF_HEAL_LOG_COOLDOWN_OPTION = 'argus_wpd_mu_self_heal_last_logged';
|
||||
const SELF_HEAL_LOG_COOLDOWN_SECS = HOUR_IN_SECONDS;
|
||||
|
||||
public static function ensure_current() {
|
||||
$target = self::target_path();
|
||||
|
||||
if ( ! file_exists( $target ) ) {
|
||||
self::maybe_log_self_heal( 'high', 'MU enforcement core was missing -- reinstalled', array( 'path' => $target ) );
|
||||
self::install();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( md5_file( $target ) !== md5_file( self::source_path() ) ) {
|
||||
self::maybe_log_self_heal( 'medium', 'MU enforcement core was out of date -- refreshed', array( 'path' => $target ) );
|
||||
self::install();
|
||||
}
|
||||
}
|
||||
|
||||
protected static function maybe_log_self_heal( $severity, $message, array $context ) {
|
||||
$last = (int) get_option( self::SELF_HEAL_LOG_COOLDOWN_OPTION, 0 );
|
||||
if ( time() - $last < self::SELF_HEAL_LOG_COOLDOWN_SECS ) {
|
||||
return;
|
||||
}
|
||||
update_option( self::SELF_HEAL_LOG_COOLDOWN_OPTION, time(), false );
|
||||
Argus_Events::record( 'self_heal', $severity, $message, $context );
|
||||
}
|
||||
|
||||
public static function status() {
|
||||
return get_option( 'argus_wpd_mu_install_status', 'unknown' );
|
||||
}
|
||||
|
||||
const HEARTBEAT_OPTION = 'argus_wpd_mu_core_heartbeat';
|
||||
const HEARTBEAT_INTERVAL_SECS = 300;
|
||||
const HEARTBEAT_STALE_AFTER_SECS = 900;
|
||||
|
||||
public static function execution_status() {
|
||||
$last = (int) get_option( self::HEARTBEAT_OPTION, 0 );
|
||||
if ( 0 === $last ) {
|
||||
|
||||
return 'never';
|
||||
}
|
||||
return ( time() - $last ) <= self::HEARTBEAT_STALE_AFTER_SECS ? 'healthy' : 'stale';
|
||||
}
|
||||
|
||||
public static function uninstall() {
|
||||
$target = self::target_path();
|
||||
if ( file_exists( $target ) ) {
|
||||
wp_delete_file( $target );
|
||||
}
|
||||
delete_option( 'argus_wpd_mu_install_status' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user