Skip to content

Commit

Permalink
Merge branch 'master' into fix/1766
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemBaskal committed Jun 5, 2020
2 parents 67d62fa + 4a81abb commit 691aa0e
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 108 deletions.
35 changes: 20 additions & 15 deletions client/src/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import EncryptionTopline from '../ui/EncryptionTopline';
import Icons from '../ui/Icons';
import i18n from '../../i18n';
import Loading from '../ui/Loading';
import { FILTERS_URLS, MENU_URLS, SETTINGS_URLS } from '../../helpers/constants';
import Services from '../Filters/Services';

class App extends Component {
componentDidMount() {
Expand Down Expand Up @@ -99,26 +101,29 @@ class App extends Component {
<div className="col-lg-12">
<Status reloadPage={this.reloadPage}
message="dns_start"
/>
/>
<Loading />
</div>
</div>
)}
{!dashboard.processing && dashboard.isCoreRunning && (
<Fragment>
<Route path="/" exact component={Dashboard} />
<Route path="/settings" component={Settings} />
<Route path="/dns" component={Dns} />
<Route path="/encryption" component={Encryption} />
<Route path="/dhcp" component={Dhcp} />
<Route path="/clients" component={Clients} />
<Route path="/filters" component={DnsBlocklist} />
<Route path="/dns_allowlists" component={DnsAllowlist} />
<Route path="/dns_rewrites" component={DnsRewrites} />
<Route path="/custom_rules" component={CustomRules} />
<Route path="/logs" component={Logs} />
<Route path="/guide" component={SetupGuide} />
</Fragment>
<>
<Route path={MENU_URLS.root} exact component={Dashboard} />
<Route path={MENU_URLS.logs} component={Logs} />
<Route path={MENU_URLS.guide} component={SetupGuide} />
<Route path={SETTINGS_URLS.settings} component={Settings} />
<Route path={SETTINGS_URLS.dns} component={Dns} />
<Route path={SETTINGS_URLS.encryption} component={Encryption} />
<Route path={SETTINGS_URLS.dhcp} component={Dhcp} />
<Route path={SETTINGS_URLS.clients} component={Clients} />
<Route path={FILTERS_URLS.dns_blocklists}
component={DnsBlocklist} />
<Route path={FILTERS_URLS.dns_allowlists}
component={DnsAllowlist} />
<Route path={FILTERS_URLS.dns_rewrites} component={DnsRewrites} />
<Route path={FILTERS_URLS.custom_rules} component={CustomRules} />
<Route path={FILTERS_URLS.blocked_services} component={Services} />
</>
)}
</div>
<Footer
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Filters/DnsAllowlist.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component, Fragment } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';

Expand Down Expand Up @@ -72,7 +72,7 @@ class DnsAllowlist extends Component {
const whitelist = true;

return (
<Fragment>
<>
<PageTitle
title={t('dns_allowlists')}
subtitle={t('dns_allowlists_desc')}
Expand Down Expand Up @@ -113,7 +113,7 @@ class DnsAllowlist extends Component {
currentFilterData={currentFilterData}
whitelist={whitelist}
/>
</Fragment>
</>
);
}
}
Expand Down
64 changes: 64 additions & 0 deletions client/src/components/Filters/Services/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import { useDispatch, useSelector } from 'react-redux';
import Form from './Form';
import Card from '../../ui/Card';
import { getBlockedServices, setBlockedServices } from '../../../actions/services';
import PageTitle from '../../ui/PageTitle';

const getInitialDataForServices = (initial) => (initial ? initial.reduce(
(acc, service) => {
acc.blocked_services[service] = true;
return acc;
}, { blocked_services: {} },
) : initial);

const Services = () => {
const [t] = useTranslation();
const dispatch = useDispatch();
const services = useSelector((store) => store && store.services);

useEffect(() => {
dispatch(getBlockedServices());
}, []);

const handleSubmit = (values) => {
if (!values || !values.blocked_services) {
return;
}

const blocked_services = Object
.keys(values.blocked_services)
.filter((service) => values.blocked_services[service]);

dispatch(setBlockedServices(blocked_services));
};

const initialValues = getInitialDataForServices(services.list);

return (
<>
<PageTitle
title={t('blocked_services')}
subtitle={t('blocked_services_desc')}
/>
<Card
bodyType="card-body box-body--settings"
>
<div className="form">
<Form
initialValues={initialValues}
processing={services.processing}
processingSet={services.processingSet}
onSubmit={handleSubmit}
/>
</div>
</Card>
</>
);
};

Services.propTypes = {};

export default Services;
1 change: 1 addition & 0 deletions client/src/components/Header/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const FILTERS_ITEMS = [
{ route: FILTERS_URLS.dns_allowlists, text: 'dns_allowlists' },
{ route: FILTERS_URLS.dns_rewrites, text: 'dns_rewrites' },
{ route: FILTERS_URLS.custom_rules, text: 'custom_filtering_rules' },
{ route: FILTERS_URLS.blocked_services, text: 'blocked_services' },
];

class Menu extends Component {
Expand Down
69 changes: 0 additions & 69 deletions client/src/components/Settings/Services/index.js

This file was deleted.

16 changes: 0 additions & 16 deletions client/src/components/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';

import Services from './Services';
import StatsConfig from './StatsConfig';
import LogsConfig from './LogsConfig';
import FiltersConfig from './FiltersConfig';
Expand Down Expand Up @@ -35,7 +34,6 @@ class Settings extends Component {

componentDidMount() {
this.props.initSettings(this.settings);
this.props.getBlockedServices();
this.props.getStatsConfig();
this.props.getLogsConfig();
this.props.getFilteringStatus();
Expand Down Expand Up @@ -63,8 +61,6 @@ class Settings extends Component {
render() {
const {
settings,
services,
setBlockedServices,
setStatsConfig,
resetStats,
stats,
Expand All @@ -77,7 +73,6 @@ class Settings extends Component {
} = this.props;

const isDataReady = !settings.processing
&& !services.processing
&& !stats.processingGetConfig
&& !queryLogs.processingGetConfig;

Expand Down Expand Up @@ -123,12 +118,6 @@ class Settings extends Component {
resetStats={resetStats}
/>
</div>
<div className="col-md-12">
<Services
services={services}
setBlockedServices={setBlockedServices}
/>
</div>
</div>
</div>
)}
Expand All @@ -147,14 +136,9 @@ Settings.propTypes = {
setFiltersConfig: PropTypes.func.isRequired,
getFilteringStatus: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
getBlockedServices: PropTypes.func,
getLogsConfig: PropTypes.func,
setBlockedServices: PropTypes.func,
setLogsConfig: PropTypes.func,
clearLogs: PropTypes.func,
services: PropTypes.shape({
processing: PropTypes.bool,
}),
stats: PropTypes.shape({
processingGetConfig: PropTypes.bool,
interval: PropTypes.number,
Expand Down
1 change: 1 addition & 0 deletions client/src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const FILTERS_URLS = {
dns_allowlists: '/dns_allowlists',
dns_rewrites: '/dns_rewrites',
custom_rules: '/custom_rules',
blocked_services: '/blocked_services',
};

export const SERVICES = [
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ require (
golang.org/x/crypto v0.0.0-20200403201458-baeed622b8d8
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.2.8
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
16 changes: 14 additions & 2 deletions home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ const (

// logSettings
type logSettings struct {
LogFile string `yaml:"log_file"` // Path to the log file. If empty, write to stdout. If "syslog", writes to syslog
Verbose bool `yaml:"verbose"` // If true, verbose logging is enabled
LogCompress bool `yaml:"log_compress"` // Compress determines if the rotated log files should be compressed using gzip (default: false)
LogLocalTime bool `yaml:"log_localtime"` // If the time used for formatting the timestamps in is the computer's local time (default: false [UTC])
LogMaxBackups int `yaml:"log_max_backups"` // Maximum number of old log files to retain (MaxAge may still cause them to get deleted)
LogMaxSize int `yaml:"log_max_size"` // Maximum size in megabytes of the log file before it gets rotated (default 100 MB)
LogMaxAge int `yaml:"log_max_age"` // MaxAge is the maximum number of days to retain old log files
LogFile string `yaml:"log_file"` // Path to the log file. If empty, write to stdout. If "syslog", writes to syslog
Verbose bool `yaml:"verbose"` // If true, verbose logging is enabled
}

// configuration is loaded from YAML
Expand Down Expand Up @@ -131,6 +136,13 @@ var config = configuration{
LeaseDuration: 86400,
ICMPTimeout: 1000,
},
logSettings: logSettings{
LogCompress: false,
LogLocalTime: false,
LogMaxBackups: 0,
LogMaxSize: 100,
LogMaxAge: 0,
},
SchemaVersion: currentSchemaVersion,
}

Expand Down
26 changes: 23 additions & 3 deletions home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"syscall"
"time"

"gopkg.in/natefinch/lumberjack.v2"

"github.com/AdguardTeam/AdGuardHome/util"

"github.com/joomcode/errorx"
Expand Down Expand Up @@ -396,13 +398,22 @@ func configureLogger(args options) {
ls := getLogSettings()

// command-line arguments can override config settings
if args.verbose {
if args.verbose || config.Verbose {
ls.Verbose = true
}
if args.logFile != "" {
ls.LogFile = args.logFile
} else if config.LogFile != "" {
ls.LogFile = config.LogFile
}

// Handle default log settings overrides
ls.LogCompress = config.LogCompress
ls.LogLocalTime = config.LogLocalTime
ls.LogMaxBackups = config.LogMaxBackups
ls.LogMaxSize = config.LogMaxSize
ls.LogMaxAge = config.LogMaxAge

// log.SetLevel(log.INFO) - default
if ls.Verbose {
log.SetLevel(log.DEBUG)
Expand All @@ -414,6 +425,7 @@ func configureLogger(args options) {
ls.LogFile = configSyslog
}

// logs are written to stdout (default)
if ls.LogFile == "" {
return
}
Expand All @@ -430,11 +442,19 @@ func configureLogger(args options) {
logFilePath = ls.LogFile
}

file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
_, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("cannot create a log file: %s", err)
}
log.SetOutput(file)

log.SetOutput(&lumberjack.Logger{
Filename: logFilePath,
Compress: ls.LogCompress, // disabled by default
LocalTime: ls.LogLocalTime,
MaxBackups: ls.LogMaxBackups,
MaxSize: ls.LogMaxSize, // megabytes
MaxAge: ls.LogMaxAge, //days
})
}
}

Expand Down

0 comments on commit 691aa0e

Please sign in to comment.