Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
asharirfan committed Apr 27, 2018
2 parents dea6ecd + 1b78fa2 commit 635e1d0
Show file tree
Hide file tree
Showing 19 changed files with 4,208 additions and 166 deletions.
40 changes: 40 additions & 0 deletions classes/AlertManager.php
Expand Up @@ -104,6 +104,8 @@ public function RemoveByClass( $class ) {
* @param bool $delayed - False if delayed, true if not.
*/
public function Trigger( $type, $data = array(), $delayed = false ) {
// Log temporary alerts first.
$this->log_temp_alerts();

// Get username.
$username = wp_get_current_user()->user_login;
Expand Down Expand Up @@ -529,4 +531,42 @@ private function IsDisabledIP() {
}
return $is_disabled;
}

/**
* Method: Log temporary stored alerts if DB connection
* is back.
*/
public function log_temp_alerts() {
// Get temporary alerts.
$temp_alerts = get_option( 'wsal_temp_alerts', array() );

if ( empty( $temp_alerts ) ) {
return;
}

// Get DB connector.
$db_config = WSAL_Connector_ConnectorFactory::GetConfig(); // Get DB connector configuration.
$connector = $this->plugin->getConnector( $db_config ); // Get connector for DB.
$wsal_db = $connector->getConnection(); // Get DB connection.
$connection = 0 !== (int) $wsal_db->dbh->errno ? false : true; // Database connection error check.

// Check DB connection.
if ( $connection ) { // If connected then log temporary alerts in DB.
// Log each alert.
foreach ( $temp_alerts as $timestamp => $alert ) {
$is_migrated = $alert['alert']['is_migrated'];
$created_on = $alert['alert']['created_on'];
$alert_id = $alert['alert']['alert_id'];
$site_id = $alert['alert']['site_id'];

// Loggers.
foreach ( $this->_loggers as $logger ) {
$logger->Log( $alert_id, $alert['alert_data'], $created_on, $site_id, $is_migrated );
}
}

// Delete temporary alerts.
delete_option( 'wsal_temp_alerts' );
}
}
}
40 changes: 30 additions & 10 deletions classes/AuditLogListView.php
Expand Up @@ -38,6 +38,16 @@ class WSAL_AuditLogListView extends WP_List_Table {
*/
protected $_gmt_offset_sec = 0;

/**
* Current Alert ID
*
* This class member is used to store the alert ID
* of the alert which is being rendered.
*
* @var integer
*/
private $current_alert_id = 0;

/**
* Method: Constructor.
*
Expand Down Expand Up @@ -235,9 +245,7 @@ public function get_columns() {
}
}
}
if ( $this->_plugin->settings->IsDataInspectorEnabled() ) {
$cols['data'] = '';
}
$cols['data'] = '';
return $cols;
}

Expand Down Expand Up @@ -277,6 +285,9 @@ public function column_default( $item, $column_name ) {
// Get date format.
$datetime_format = $this->_plugin->settings->GetDatetimeFormat();

// Store current alert id.
$this->current_alert_id = $item->id;

switch ( $column_name ) {
case 'read':
return '<span class="log-read log-read-'
Expand Down Expand Up @@ -436,7 +447,8 @@ public function column_default( $item, $column_name ) {
return '<div id="Event' . $item->id . '">' . $item->GetMessage( array( $this, 'meta_formatter' ) ) . '</div>';
case 'data':
$url = admin_url( 'admin-ajax.php' ) . '?action=AjaxInspector&amp;occurrence=' . $item->id;
return '<a class="more-info thickbox" title="' . __( 'Alert Data Inspector', 'wp-security-audit-log' ) . '"'
$tooltip = esc_attr__( 'View all details of this change', 'wp-security-audit-log' );
return '<a class="more-info thickbox" data-tooltip="' . $tooltip . '" title="' . __( 'Alert Data Inspector', 'wp-security-audit-log' ) . '"'
. ' href="' . $url . '&amp;TB_iframe=true&amp;width=600&amp;height=550">&hellip;</a>';
default:
return isset( $item->$column_name )
Expand Down Expand Up @@ -505,22 +517,22 @@ public function meta_formatter( $name, $value ) {
}

case '%EditorLinkPost%' == $name:
return ' <a target="_blank" href="' . esc_url( $value ) . '">View the post</a>';
return ' View the <a target="_blank" href="' . esc_url( $value ) . '">post</a>';

case '%EditorLinkPage%' == $name:
return ' <a target="_blank" href="' . esc_url( $value ) . '">View the page</a>';
return ' View the <a target="_blank" href="' . esc_url( $value ) . '">page</a>';

case '%CategoryLink%' == $name:
return ' <a target="_blank" href="' . esc_url( $value ) . '">View the category</a>';
return ' View the <a target="_blank" href="' . esc_url( $value ) . '">category</a>';

case '%TagLink%' == $name:
return ' <a target="_blank" href="' . esc_url( $value ) . '">View the tag</a>';
return ' View the <a target="_blank" href="' . esc_url( $value ) . '">tag</a>';

case '%EditorLinkForum%' == $name:
return ' <a target="_blank" href="' . esc_url( $value ) . '">View the forum</a>';
return ' View the <a target="_blank" href="' . esc_url( $value ) . '">forum</a>';

case '%EditorLinkTopic%' == $name:
return ' <a target="_blank" href="' . esc_url( $value ) . '">View the topic</a>';
return ' View the <a target="_blank" href="' . esc_url( $value ) . '">topic</a>';

case in_array( $name, array( '%MetaValue%', '%MetaValueOld%', '%MetaValueNew%' ) ):
return '<strong>' . (
Expand Down Expand Up @@ -577,6 +589,14 @@ public function meta_formatter( $name, $value ) {
}
return;

case '%ReportText%' === $name:
return;

case '%ChangeText%' === $name:
$url = admin_url( 'admin-ajax.php' ) . '?action=AjaxInspector&amp;occurrence=' . $this->current_alert_id;
return ' View the changes in <a class="thickbox" title="' . __( 'Alert Data Inspector', 'wp-security-audit-log' ) . '"'
. ' href="' . $url . '&amp;TB_iframe=true&amp;width=600&amp;height=550">data inspector.</a>';

default:
return '<strong>' . esc_html( $value ) . '</strong>';
}
Expand Down
34 changes: 30 additions & 4 deletions classes/Loggers/Database.php
Expand Up @@ -49,17 +49,43 @@ public function Log( $type, $data = array(), $date = null, $siteid = null, $migr
return;
}

// Get temporary stored alerts.
$temp_alerts = get_option( 'wsal_temp_alerts', array() );

// Create new occurrence.
$occ = new WSAL_Models_Occurrence();
$occ->is_migrated = $migrated;
$occ->created_on = $date;
$occ->created_on = is_null( $date ) ? microtime( true ) : $date;
$occ->alert_id = $type;
$occ->site_id = ! is_null( $siteid ) ? $siteid
: (function_exists( 'get_current_blog_id' ) ? get_current_blog_id() : 0);
$occ->Save();

// Set up meta data.
$occ->SetMeta( $data );
// Get DB connector.
$db_config = WSAL_Connector_ConnectorFactory::GetConfig(); // Get DB connector configuration.
$connector = $this->plugin->getConnector( $db_config ); // Get connector for DB.
$wsal_db = $connector->getConnection(); // Get DB connection.
$connection = 0 !== (int) $wsal_db->dbh->errno ? false : true; // Database connection error check.

// Check DB connection.
if ( $connection ) { // If connected then save the alert in DB.
// Save the alert occurrence.
$occ->Save();

// Set up meta data of the alert.
$occ->SetMeta( $data );
} else { // Else store the alerts in temporary option.
// Store current alert in temporary option array.
$temp_alerts[ $occ->created_on ]['alert'] = array(
'is_migrated' => $occ->is_migrated,
'created_on' => $occ->created_on,
'alert_id' => $occ->alert_id,
'site_id' => $occ->site_id,
);
$temp_alerts[ $occ->created_on ]['alert_data'] = $data;
}

// Save temporary alerts to options.
update_option( 'wsal_temp_alerts', $temp_alerts );

// Inject for promoting the paid add-ons.
$type = (int) $type;
Expand Down

0 comments on commit 635e1d0

Please sign in to comment.