Skip to content

Commit

Permalink
Merge 4.4.1 from develop to master (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrcho authored Mar 23, 2022
1 parent 8c36d4b commit ce2940f
Show file tree
Hide file tree
Showing 119 changed files with 9,534 additions and 8,847 deletions.
23 changes: 17 additions & 6 deletions classes/AbstractLogger.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<?php
/**
* Abstract logger class.
*
* @package wsal
* @subpackage loggers
*/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Abstract class used in the Logger.
Expand Down Expand Up @@ -29,12 +40,12 @@ public function __construct( WpSecurityAuditLog $plugin ) {
/**
* Log alert abstract.
*
* @param integer $type - Alert code.
* @param array $data - Metadata.
* @param integer $date (Optional) - Created on.
* @param integer $type - Alert code.
* @param array $data - Metadata.
* @param integer $date (Optional) - Created on.
* @param integer $site_id (Optional) - Site id.
*/
public abstract function Log( $type, $data = array(), $date = null, $site_id = null );
abstract public function log( $type, $data = array(), $date = null, $site_id = null );

/**
* Determines what is the correct timestamp for the event.
Expand All @@ -43,8 +54,8 @@ public abstract function Log( $type, $data = array(), $date = null, $site_id = n
* action scheduler in 4.3.0. The $legacy_date attribute is only used for migration of legacy data. This should be
* removed in future releases.
*
* @param array $metadata Event metadata.
* @param int $legacy_date Legacy date only used when migrating old db event format to the new one.
* @param array $metadata Event metadata.
* @param int $legacy_date Legacy date only used when migrating old db event format to the new one.
*
* @return float GMT timestamp including microseconds.
* @since 4.3.0
Expand Down
37 changes: 19 additions & 18 deletions classes/AbstractMetaDataSensor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*
* Abstract meta data sensor file.
*
* @since 4.1.3
* @package wsal
* @since 4.1.3
* @package wsal
* @subpackage sensors
*/

// Exit if accessed directly.
Expand All @@ -16,9 +17,9 @@
/**
* Abstract sensor for meta data.
*
* @package wsal
* @package wsal
* @subpackage sensors
* @since 4.1.3
* @since 4.1.3
*/
abstract class WSAL_AbstractMetaDataSensor extends WSAL_AbstractSensor {

Expand All @@ -33,12 +34,12 @@ abstract class WSAL_AbstractMetaDataSensor extends WSAL_AbstractSensor {
* Check "Excluded Custom Fields" or meta keys starts with "_".
*
* @param string $object_type Object type - user or post.
* @param int $object_id - Object ID.
* @param string $meta_key - Meta key.
* @param int $object_id - Object ID.
* @param string $meta_key - Meta key.
*
* @return boolean can log true|false
* @return boolean Can log true|false
*/
protected function CanLogMetaKey( $object_type, $object_id, $meta_key ) {
protected function can_log_meta_key( $object_type, $object_id, $meta_key ) {
// Check if excluded meta key or starts with _.
if ( '_' === substr( $meta_key, 0, 1 ) ) {
/**
Expand All @@ -54,7 +55,7 @@ protected function CanLogMetaKey( $object_type, $object_id, $meta_key ) {
}

return false;
} elseif ( $this->IsExcludedCustomFields( $object_type, $meta_key ) ) {
} elseif ( $this->is_excluded_custom_fields( $object_type, $meta_key ) ) {
return false;
} else {
return true;
Expand All @@ -68,7 +69,7 @@ protected function CanLogMetaKey( $object_type, $object_id, $meta_key ) {
*
* @return array $editor_link - Name and value link
*/
protected function GetEditorLink( $post ) {
protected function get_editor_link( $post ) {
$post_id = is_int( $post ) ? intval( $post ) : $post->ID;
return array(
'name' => 'EditorLinkPost',
Expand All @@ -85,22 +86,22 @@ protected function GetEditorLink( $post ) {
*
* @return boolean is excluded from monitoring true|false
*/
public function IsExcludedCustomFields( $object_type, $custom ) {
$custom_fields = [];
if ('post' === $object_type) {
$custom_fields = $this->plugin->settings()->GetExcludedPostMetaFields();
} else if ('user' === $object_type) {
$custom_fields = $this->plugin->settings()->GetExcludedUserMetaFields();
public function is_excluded_custom_fields( $object_type, $custom ) {
$custom_fields = array();
if ( 'post' === $object_type ) {
$custom_fields = $this->plugin->settings()->get_excluded_post_meta_fields();
} elseif ( 'user' === $object_type ) {
$custom_fields = $this->plugin->settings()->get_excluded_user_meta_fields();
}

if ( in_array( $custom, $custom_fields ) ) {
if ( in_array( $custom, $custom_fields ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
return true;
}

foreach ( $custom_fields as $field ) {
if ( false !== strpos( $field, '*' ) ) {
// Wildcard str[any_character] when you enter (str*).
if ( substr( $field, - 1 ) == '*' ) {
if ( '*' === substr( $field, - 1 ) ) {
$field = rtrim( $field, '*' );
if ( preg_match( "/^$field/", $custom ) ) {
return true;
Expand Down
32 changes: 20 additions & 12 deletions classes/AbstractSandboxTask.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* WSAL_AbstractSandboxTask class.
*
* @package wsal
*/

/**
* Abstract Sandbox Task class.
*
Expand All @@ -20,17 +26,17 @@ public function __construct() {
}

// Set up shutdown handler.
register_shutdown_function( array( $this, 'Shutdown' ) );
register_shutdown_function( array( $this, 'shutdown' ) );

// Run event sequence.
$this->Header();
$this->header();
try {
$this->Execute();
$this->execute();
} catch ( Exception $ex ) {
$this->Message( get_class( $ex ) . ' [' . basename( $ex->getFile() ) . ':' . $ex->getLine() . ']: ' . $ex->getMessage() );
$this->Message( $ex->getTraceAsString(), true );
$this->message( get_class( $ex ) . ' [' . basename( $ex->getFile() ) . ':' . $ex->getLine() . ']: ' . $ex->getMessage() );
$this->message( $ex->getTraceAsString(), true );
}
$this->Footer();
$this->footer();

// Shutdown.
die();
Expand All @@ -39,7 +45,7 @@ public function __construct() {
/**
* Header.
*/
protected function Header() {
protected function header() {
echo '<!DOCTYPE html><html><body style="margin: 0; padding: 8px; font: 12px Arial; color: #333;">';
echo '<div style="position: fixed; top: 0; left: 0; right: 0; padding: 8px; background: #F0F0F0;">';
echo ' <div id="bar" style=" border-top: 2px solid #0AE; top: 20px; height: 0; width: 0%;"> </div>';
Expand All @@ -58,20 +64,20 @@ protected function Header() {
/**
* Footer.
*/
protected function Footer() {
protected function footer() {
echo '<div style="display: none;">';
flush();
}

/**
* Method: Execute.
*/
protected abstract function Execute();
abstract protected function execute();

/**
* Method: Shutdown.
*/
public function Shutdown() {
public function shutdown() {
echo '</div></body></html>';
flush();
}
Expand All @@ -81,7 +87,7 @@ public function Shutdown() {
*
* @param mixed $percent - Progress percentage.
*/
protected function Progress( $percent ) {
protected function progress( $percent ) {
echo '<script>bar.style.width=prg.innerHTML="' . number_format( $percent, 2 ) . '%";</script>';
flush();
}
Expand All @@ -91,8 +97,10 @@ protected function Progress( $percent ) {
*
* @param string $message - Message.
* @param bool $sticky - True if sticky.
*
* @phpcs:disable WordPress.WP.AlternativeFunctions.json_encode_json_encode
*/
protected function Message( $message, $sticky = false ) {
protected function message( $message, $sticky = false ) {
if ( $sticky ) {
echo '<script>msgs.appendChild(document.createTextNode(' . json_encode( $message . PHP_EOL ) . ')); window.scroll(0, document.body.scrollHeight);</script>';
} else {
Expand Down
57 changes: 25 additions & 32 deletions classes/AbstractSensor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*
* Abstract sensor class file.
*
* @since 1.0.0
* @package wsal
* @since 1.0.0
* @package wsal
* @subpackage sensors
*/

// Exit if accessed directly.
Expand All @@ -16,8 +17,9 @@
/**
* Abstract class used in all the sensors.
*
* @see Sensors/*.php
* @package wsal
* @see Sensors/*.php
* @package wsal
* @subpackage sensors
*/
abstract class WSAL_AbstractSensor {

Expand All @@ -42,14 +44,17 @@ public function __construct( WpSecurityAuditLog $plugin ) {
*
* @return boolean
*/
protected function IsMultisite() {
return $this->plugin->IsMultisite();
protected function is_multisite() {
return $this->plugin->is_multisite();
}

/**
* Method: Hook events related to sensor.
*/
abstract function HookEvents();
public function hook_events() {
// We call the deprecated function for backwards compatibility.
$this->HookEvents();
}

/**
* Method: Log the message for sensor.
Expand All @@ -58,13 +63,13 @@ abstract function HookEvents();
* @param string $message - Alert message.
* @param mixed $args - Message arguments.
*/
protected function Log( $type, $message, $args ) {
$this->plugin->alerts->Trigger(
protected function log( $type, $message, $args ) {
$this->plugin->alerts->trigger_event(
$type,
array(
'Message' => $message,
'Context' => $args,
'Trace' => debug_backtrace(),
'Trace' => debug_backtrace(), // phpcs:ignore
)
);
}
Expand All @@ -75,8 +80,8 @@ protected function Log( $type, $message, $args ) {
* @param string $message - Alert message.
* @param mixed $args - Message arguments.
*/
protected function LogError( $message, $args ) {
$this->Log( 0001, $message, $args );
protected function log_error( $message, $args ) {
$this->log( 0001, $message, $args );
}

/**
Expand All @@ -85,8 +90,8 @@ protected function LogError( $message, $args ) {
* @param string $message - Alert message.
* @param mixed $args - Message arguments.
*/
protected function LogWarn( $message, $args ) {
$this->Log( 0002, $message, $args );
protected function log_warn( $message, $args ) {
$this->log( 0002, $message, $args );
}

/**
Expand All @@ -95,28 +100,16 @@ protected function LogWarn( $message, $args ) {
* @param string $message - Alert message.
* @param mixed $args - Message arguments.
*/
protected function LogInfo( $message, $args ) {
$this->Log( 0003, $message, $args );
protected function log_info( $message, $args ) {
$this->log( 0003, $message, $args );
}

/**
* Check to see whether or not the specified directory is accessible.
* Deprecated placeholder function.
*
* @param string $dir_path - Directory path.
* @see WSAL_AbstractSensor::hook_events()
*
* @return boolean
* @deprecated 4.4.1 Replaced by function hook_events.
*/
protected function CheckDirectory( $dir_path ) {
if ( ! is_dir( $dir_path ) ) {
return false;
}
if ( ! is_readable( $dir_path ) ) {
return false;
}
if ( ! is_writable( $dir_path ) ) {
return false;
}

return true;
}
public function HookEvents() {}
}
Loading

0 comments on commit ce2940f

Please sign in to comment.