Skip to content

Commit

Permalink
Fixed Slack notification with no dashboard defined
Browse files Browse the repository at this point in the history
  • Loading branch information
riklewis committed Jul 4, 2019
1 parent 318b91a commit a465a73
Show file tree
Hide file tree
Showing 19 changed files with 1,009 additions and 49 deletions.
876 changes: 876 additions & 0 deletions svn/tags/1.3/better-detection.php

Large diffs are not rendered by default.

Binary file added svn/tags/1.3/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/icon-36x36.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/icon-white-36x36.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-bg_glass_55_fbf9ee_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-bg_glass_65_ffffff_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-bg_glass_75_dadada_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-bg_glass_75_e6e6e6_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-bg_glass_95_fef1ec_1x400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-icons_222222_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-icons_454545_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added svn/tags/1.3/images/ui-icons_888888_256x240.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions svn/tags/1.3/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
# Silence is golden.
7 changes: 7 additions & 0 deletions svn/tags/1.3/jquery-ui-tabs.min.css

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions svn/tags/1.3/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
jQuery(function() {
//initialise tab widget
jQuery("#better-detection-tabs").tabs();

//update error count
function better_detection_error_count() {
var trs = Math.max(0,jQuery("#better-detection-tabs-errors").find("tr").length-2);
jQuery("#better-detection-error-count").html(" ("+trs+")");
}
better_detection_error_count();

//handle button clicks
jQuery("#better-detection-tabs").on("click","input",function(e) {
var data = {'action':'better_detection','mode':'unknown','key':ajax_object.key};
var inp = jQuery(this);
if(inp.hasClass("action-fixed")) {
data.mode = "fixed";
data.id = inp.attr("id").replace("action-fix-","");
}
if(inp.hasClass("action-ignore")) {
data.mode = "ignore";
data.id = inp.attr("id").replace("action-ign-","");
}
if(inp.hasClass("action-test")) {
data.val = inp.siblings("input").val();
if(data.val) {
data.mode = "test";
data.id = inp.attr("id").replace("action-tst-","");
}
}
if(data.mode!=="unknown") {
inp.after("<img src='"+ajax_object.gif+"' style='height:21px'>").hide().siblings("input[type=button]").hide();
jQuery.post(ajax_object.url, data, function(response) {
if(response==="Success") {
inp.closest("tr").fadeOut("slow",function() { //remove row
jQuery(this).remove();
var trs = jQuery("#better-detection-tabs-errors").find("tr");
if(trs.length===2) {
jQuery("#better-detection-tabs-errors").html("<p>No new errors have been detected - yay!</p>"); //if only header/footer left then show message
}
better_detection_error_count();
});
}
else {
inp.siblings("img").remove(); //remove working image
inp.siblings("input").addBack().show(); //restore buttons
}
});
}
});
});
15 changes: 15 additions & 0 deletions svn/tags/1.3/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=== Better Detection ===
Contributors: bettersecurity, riklewis
Tags: better, security, detection, content, files
Requires at least: 3.5
Tested up to: 5.2
Stable tag: trunk
Requires PHP: 5.6
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Improve the security of your website by detecting unexpected changes to content

== Description ==

This plugin will create and store hashes of content (eg. posts, pages, etc.) and monitor these moving forwards in order to detect when changes occur. When changes are made outside of the normal working process, such as a direct database update, this will then be detected as the hash will get out of sync with the content.
Binary file added svn/tags/1.3/working.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 58 additions & 49 deletions svn/trunk/better-detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Plugin Name: Better Detection
Description: Improve the security of your website by detecting unexpected changes to both content
Version: 1.2
Version: 1.3
Author: Better Security
Author URI: https://bettersecurity.co
License: GPL3
Expand All @@ -18,7 +18,7 @@
--------------------------- Installation ---------------------------
*/

define('BETTER_DETECTION_VERSION','1.2');
define('BETTER_DETECTION_VERSION','1.3');

function better_detection_activation() {
global $wpdb;
Expand Down Expand Up @@ -264,40 +264,43 @@ function better_detection_do_notify($type,$item_id) {
case "post":
$item = get_post($item_id);
$text = $item->post_type;
$flds = array(
[
'title' => __('ID', 'better-detect-text'),
'value' => $item->ID,
'short' => true
],
[
'title' => __('Post Date', 'better-detect-text'),
'value' => date($frmt, strtotime($item->post_date)),
'short' => true
],
[
'title' => __('Status', 'better-detect-text'),
'value' => ucwords($item->post_status),
'short' => true
],
[
'title' => __('Last Modified', 'better-detect-text'),
'value' => date($frmt, strtotime($item->post_modified)),
'short' => true
]
);
if($auto!=="") {
$flds[] = [
'title' => __('Dashboard Link', 'better-detect-text'),
'value' => '<' . $auto . '|' . __('Click here to automatically log in to the dashboard', 'better-detect-text') . '>',
'short' => false
];
}
$atts = array([
'fallback' => __('ALERT from', 'better-detect-text') . ' <' . $home . '|' . $link . '> - ' . __('change detected to', 'better-detect-text') . ' ' . $item->post_type . ' <' . get_permalink($item_id) . '|' . $item->post_title . '>',
'color' => '#000000',
'title' => $item->post_title,
'title_link' => get_permalink($item_id),
'footer' => 'Better Security',
'footer_icon' => 'https://bettersecurity.co/images/icon-48x48.png',
'fields' => array(
[
'title' => __('ID', 'better-detect-text'),
'value' => $item->ID,
'short' => true
],
[
'title' => __('Post Date', 'better-detect-text'),
'value' => date($frmt, strtotime($item->post_date)),
'short' => true
],
[
'title' => __('Status', 'better-detect-text'),
'value' => ucwords($item->post_status),
'short' => true
],
[
'title' => __('Last Modified', 'better-detect-text'),
'value' => date($frmt, strtotime($item->post_modified)),
'short' => true
],
[
'title' => __('Dashboard Link', 'better-detect-text'),
'value' => '<' . $auto . '|' . __('Click here to automatically log in to the dashboard', 'better-detect-text') . '>',
'short' => false
]
)
'fields' => $flds
]);
$used = true;
break;
Expand Down Expand Up @@ -356,7 +359,7 @@ function better_detection_do_test($type,$value) {
}

//check for email address
if($type=="email" && $value!=="") {
if($type==="email" && $value!=="") {
//create email body
$body = ' <div style="background-color:white;margin:24px 0;">';
$body .= ' <a href="https://bettersecurity.co" target="_blank" style="display:inline-block;width:100%;">';
Expand All @@ -383,32 +386,38 @@ function better_detection_do_test($type,$value) {
}

//check for Slack webhook
if($type=="slack" && $value!=="") {
if($type==="slack" && $value!=="") {
//create message attachments
$flds = array(
[
'title' => __('Test Date', 'better-detect-text'),
'value' => current_time($frmt),
'short' => true
]
);
if($auto!=="") {
$flds[] = [
'title' => __('Dashboard Link', 'better-detect-text'),
'value' => '<' . $auto . '|' . __('Click here to automatically log in to the dashboard', 'better-detect-text') . '>',
'short' => false
];
}
$atts = array([
'fallback' => __('ALERT from', 'better-detect-text') . ' <' . $home . '|' . $link . '> - ' . __('test notification. Has it worked?', 'better-detect-text'),
'color' => '#000000',
'footer' => 'Better Security',
'footer_icon' => 'https://bettersecurity.co/images/icon-48x48.png',
'fields' => $flds
]);

//post message to Slack
wp_remote_post($value,array(
'blocking' => false,
'body' => json_encode(array(
'text' => __('ALERT from', 'better-detect-text') . ' <' . $home . '|' . $link . '> - ' . __('test notification. Has it worked?', 'better-detect-text'),
'username' => 'Better Detection',
'icon_url' => 'https://bettersecurity.co/images/icon-48x48.png',
'attachments' => array([
'fallback' => __('ALERT from', 'better-detect-text') . ' <' . $home . '|' . $link . '> - ' . __('test notification. Has it worked?', 'better-detect-text'),
'color' => '#000000',
'footer' => 'Better Security',
'footer_icon' => 'https://bettersecurity.co/images/icon-48x48.png',
'fields' => array(
[
'title' => __('Test Date', 'better-detect-text'),
'value' => current_time($frmt),
'short' => true
],
[
'title' => __('Dashboard Link', 'better-detect-text'),
'value' => '<' . $auto . '|' . __('Click here to automatically log in to the dashboard', 'better-detect-text') . '>',
'short' => false
]
)
])
'attachments' => $atts
))
));
return true;
Expand Down

0 comments on commit a465a73

Please sign in to comment.