Skip to content

Commit

Permalink
+ client, querylog: Add blocked service filter support
Browse files Browse the repository at this point in the history
Close #2124

Squashed commit of the following:

commit 574726e
Merge: 3bc770f dc61744
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Wed Sep 23 19:32:38 2020 +0300

    Merge branch 'master' into feature/2124

commit 3bc770f
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Wed Sep 23 11:22:07 2020 +0300

    minor

commit 90c0d73
Merge: 5d1f264 1d36abd
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Wed Sep 23 11:17:24 2020 +0300

    Merge branch 'master' into feature/2124

commit 5d1f264
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Sep 22 17:23:08 2020 +0300

    Display elapsed if there is no service_name in blocked service

commit af86ced
Merge: b61976a 756f97e
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Sep 22 16:55:40 2020 +0300

    Merge branch 'master' into feature/2124

commit b61976a
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Sep 22 16:52:48 2020 +0300

    Rename params to blocked_services, update service name display on client

commit d5b8e5f
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Sep 22 15:59:46 2020 +0300

    Update docs, return global blocked status

commit adc9a29
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Sep 22 15:24:34 2020 +0300

    + querylog: Extract filteringStatusBlockedService

commit ee8c1dc
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Sep 22 13:54:16 2020 +0300

    + client: Add blocked service filter support
  • Loading branch information
ArtemBaskal committed Sep 23, 2020
1 parent dc61744 commit 10f67bd
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 17 deletions.
3 changes: 2 additions & 1 deletion AGHTechDoc.md
Expand Up @@ -1471,7 +1471,8 @@ Strict matching can be enabled by enclosing the value in double quotes: e.g. `"a
`response_status`:
* all
* filtered - all kinds of filtering
* blocked - blocked or blocked service
* blocked - blocked or blocked services
* blocked_services - blocked services
* blocked_safebrowsing - blocked by safebrowsing
* blocked_parental - blocked by parental control
* whitelisted - whitelisted
Expand Down
1 change: 1 addition & 0 deletions client/src/__locales/en.json
Expand Up @@ -528,6 +528,7 @@
"check_reason": "Reason: {{reason}}",
"check_rule": "Rule: {{rule}}",
"check_service": "Service name: {{service}}",
"service_name": "Service name",
"check_not_found": "Not found in your filter lists",
"client_confirm_block": "Are you sure you want to block the client \"{{ip}}\"?",
"client_confirm_unblock": "Are you sure you want to unblock the client \"{{ip}}\"?",
Expand Down
8 changes: 1 addition & 7 deletions client/src/components/Logs/Cells/DomainCell.js
Expand Up @@ -14,7 +14,6 @@ import IconTooltip from './IconTooltip';

const DomainCell = ({
answer_dnssec,
service_name,
client_proto,
domain,
time,
Expand Down Expand Up @@ -50,10 +49,6 @@ const DomainCell = ({
protocol,
};

if (service_name) {
requestDetailsObj.check_service = service_name;
}

const sourceData = getSourceData(tracker);

const knownTrackerDataObj = {
Expand Down Expand Up @@ -103,7 +98,7 @@ const DomainCell = ({
xlinkHref='privacy' contentItemClass='key-colon' renderContent={renderContent}
place='bottom' />
<div className={valueClass}>
<div className="text-truncate" title={domain}>{service_name || domain}</div>
<div className="text-truncate" title={domain}>{domain}</div>
{details && isDetailed
&& <div className="detailed-info d-none d-sm-block text-truncate"
title={details}>{details}</div>}
Expand All @@ -117,7 +112,6 @@ DomainCell.propTypes = {
domain: propTypes.string.isRequired,
time: propTypes.string.isRequired,
type: propTypes.string.isRequired,
service_name: propTypes.string,
tracker: propTypes.object,
};

Expand Down
26 changes: 23 additions & 3 deletions client/src/components/Logs/Cells/ResponseCell.js
Expand Up @@ -3,7 +3,11 @@ import { shallowEqual, useSelector } from 'react-redux';
import classNames from 'classnames';
import React from 'react';
import propTypes from 'prop-types';
import { formatElapsedMs, getFilterName } from '../../../helpers/helpers';
import {
formatElapsedMs,
getFilterName,
getServiceName,
} from '../../../helpers/helpers';
import { FILTERED_STATUS, FILTERED_STATUS_TO_META_MAP } from '../../../helpers/constants';
import IconTooltip from './IconTooltip';

Expand All @@ -16,6 +20,7 @@ const ResponseCell = ({
upstream,
rule,
filterId,
service_name,
}) => {
const { t } = useTranslation();
const filters = useSelector((state) => state.filtering.filters, shallowEqual);
Expand Down Expand Up @@ -52,7 +57,7 @@ const ResponseCell = ({
install_settings_dns: upstream,
elapsed: formattedElapsedMs,
response_code: status,
filter,
...(service_name ? { service_name: getServiceName(service_name) } : { filter }),
rule_label: rule,
response_table_header: renderResponses(response),
original_response: renderResponses(originalResponse),
Expand All @@ -64,8 +69,22 @@ const ResponseCell = ({
...COMMON_CONTENT,
filter: '',
});
const detailedInfo = isBlocked ? filter : formattedElapsedMs;

const getDetailedInfo = (reason) => {
switch (reason) {
case FILTERED_STATUS.FILTERED_BLOCKED_SERVICE:
if (!service_name) {
return formattedElapsedMs;
}
return getServiceName(service_name);
case FILTERED_STATUS.FILTERED_BLACK_LIST:
return filter;
default:
return formattedElapsedMs;
}
};

const detailedInfo = getDetailedInfo(reason);

return <div className="logs__cell logs__cell--response" role="gridcell">
<IconTooltip
Expand Down Expand Up @@ -96,6 +115,7 @@ ResponseCell.propTypes = {
upstream: propTypes.string.isRequired,
rule: propTypes.string,
filterId: propTypes.number,
service_name: propTypes.string,
};

export default ResponseCell;
5 changes: 5 additions & 0 deletions client/src/components/Logs/Cells/index.js
Expand Up @@ -11,6 +11,7 @@ import {
formatTime,
getBlockingClientName,
getFilterName,
getServiceName,
processContent,
} from '../../../helpers/helpers';
import {
Expand Down Expand Up @@ -74,6 +75,7 @@ const Row = memo(({
rule,
originalResponse,
status,
service_name,
} = rowProps;

const hasTracker = !!tracker;
Expand Down Expand Up @@ -133,6 +135,8 @@ const Row = memo(({
date: formatDateTime(time, DEFAULT_SHORT_DATE_FORMAT_OPTIONS),
encryption_status: isBlocked
? <div className="bg--danger">{requestStatus}</div> : requestStatus,
...(FILTERED_STATUS.FILTERED_BLOCKED_SERVICE && service_name
&& { service_name: getServiceName(service_name) }),
domain,
type_table_header: type,
protocol,
Expand Down Expand Up @@ -219,6 +223,7 @@ Row.propTypes = {
rule: propTypes.string,
originalResponse: propTypes.array,
status: propTypes.string.isRequired,
service_name: propTypes.string,
}).isRequired,
isSmallScreen: propTypes.bool.isRequired,
setDetailedDataCurrent: propTypes.func.isRequired,
Expand Down
11 changes: 10 additions & 1 deletion client/src/helpers/constants.js
Expand Up @@ -280,6 +280,11 @@ export const SERVICES = [
},
];

export const SERVICES_ID_NAME_MAP = SERVICES.reduce((acc, { id, name }) => {
acc[id] = name;
return acc;
}, {});

export const ENCRYPTION_SOURCE = {
PATH: 'path',
CONTENT: 'content',
Expand Down Expand Up @@ -351,6 +356,10 @@ export const RESPONSE_FILTER = {
QUERY: 'blocked',
LABEL: 'show_blocked_responses',
},
BLOCKED_SERVICES: {
QUERY: 'blocked_services',
LABEL: 'blocked_services',
},
BLOCKED_THREATS: {
QUERY: 'blocked_safebrowsing',
LABEL: 'blocked_threats',
Expand Down Expand Up @@ -397,7 +406,7 @@ export const FILTERED_STATUS_TO_META_MAP = {
COLOR: QUERY_STATUS_COLORS.WHITE,
},
[FILTERED_STATUS.FILTERED_BLOCKED_SERVICE]: {
LABEL: RESPONSE_FILTER.BLOCKED.LABEL,
LABEL: 'blocked_service',
COLOR: QUERY_STATUS_COLORS.RED,
},
[FILTERED_STATUS.FILTERED_SAFE_SEARCH]: {
Expand Down
7 changes: 7 additions & 0 deletions client/src/helpers/helpers.js
Expand Up @@ -26,6 +26,7 @@ import {
FILTERED,
FILTERED_STATUS,
IP_MATCH_LIST_STATUS,
SERVICES_ID_NAME_MAP,
STANDARD_DNS_PORT,
STANDARD_HTTPS_PORT,
STANDARD_WEB_PORT,
Expand Down Expand Up @@ -944,3 +945,9 @@ export const getBlockingClientName = (clients, ip) => {
*/
export const filterOutComments = (lines) => lines
.filter((line) => !line.startsWith(COMMENT_LINE_DEFAULT_TOKEN));

/**
* @param {string} serviceId
* @returns {string}
*/
export const getServiceName = (serviceId) => SERVICES_ID_NAME_MAP[serviceId] || serviceId;
3 changes: 2 additions & 1 deletion client/webpack.dev.js
Expand Up @@ -38,6 +38,7 @@ const getDevServerConfig = (proxyUrl = BASE_URL) => {

return {
hot: true,
open: true,
host: devServerHost,
port: devServerPort,
proxy: {
Expand All @@ -61,5 +62,5 @@ module.exports = merge(common, {
},
],
},
devServer: process.env.WEBPACK_DEV_SERVER ? getDevServerConfig(BASE_URL) : undefined,
...(process.env.WEBPACK_DEV_SERVER ? { devServer: getDevServerConfig(BASE_URL) } : undefined),
});
11 changes: 7 additions & 4 deletions querylog/search_criteria.go
Expand Up @@ -17,7 +17,8 @@ const (
filteringStatusAll = "all"
filteringStatusFiltered = "filtered" // all kinds of filtering

filteringStatusBlocked = "blocked" // blocked or blocked service
filteringStatusBlocked = "blocked" // blocked or blocked services
filteringStatusBlockedService = "blocked_services" // blocked
filteringStatusBlockedSafebrowsing = "blocked_safebrowsing" // blocked by safebrowsing
filteringStatusBlockedParental = "blocked_parental" // blocked by parental control
filteringStatusWhitelisted = "whitelisted" // whitelisted
Expand All @@ -29,7 +30,7 @@ const (
// filteringStatusValues -- array with all possible filteringStatus values
var filteringStatusValues = []string{
filteringStatusAll, filteringStatusFiltered, filteringStatusBlocked,
filteringStatusBlockedSafebrowsing, filteringStatusBlockedParental,
filteringStatusBlockedService, filteringStatusBlockedSafebrowsing, filteringStatusBlockedParental,
filteringStatusWhitelisted, filteringStatusRewritten, filteringStatusSafeSearch,
filteringStatusProcessed,
}
Expand Down Expand Up @@ -113,15 +114,17 @@ func (c *searchCriteria) match(entry *logEntry) bool {
return res.IsFiltered &&
(res.Reason == dnsfilter.FilteredBlackList ||
res.Reason == dnsfilter.FilteredBlockedService)
case filteringStatusBlockedService:
return res.IsFiltered && res.Reason == dnsfilter.FilteredBlockedService
case filteringStatusBlockedParental:
return res.IsFiltered && res.Reason == dnsfilter.FilteredParental
case filteringStatusBlockedSafebrowsing:
return res.IsFiltered && res.Reason == dnsfilter.FilteredSafeBrowsing
case filteringStatusWhitelisted:
return res.Reason == dnsfilter.NotFilteredWhiteList
case filteringStatusRewritten:
return (res.Reason == dnsfilter.ReasonRewrite ||
res.Reason == dnsfilter.RewriteEtcHosts)
return res.Reason == dnsfilter.ReasonRewrite ||
res.Reason == dnsfilter.RewriteEtcHosts
case filteringStatusSafeSearch:
return res.IsFiltered && res.Reason == dnsfilter.FilteredSafeSearch

Expand Down

0 comments on commit 10f67bd

Please sign in to comment.