Skip to content

Commit 2aa2ab0

Browse files
leandrosansilvasuelaP
authored andcommitted
Stuff for the first iteration of 2.0
1 parent f6893db commit 2aa2ab0

File tree

233 files changed

+9403
-1661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+9403
-1661
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test:
9191
needs: []
9292
script:
9393
- make mocks
94-
- go test ./... -race -v | go run github.com/jstemmer/go-junit-report > report.xml
94+
- go test ./... -race -v -tags="sqlite_json" | go run github.com/jstemmer/go-junit-report > report.xml
9595
artifacts:
9696
reports:
9797
junit: report.xml
@@ -103,7 +103,7 @@ cover:
103103
needs: []
104104
script:
105105
- go get -u github.com/t-yuki/gocover-cobertura
106-
- ./tools/go_test.sh -coverprofile=coverinfo_with_gen.txt
106+
- ./tools/go_test.sh -tags sqlite_json -coverprofile=coverinfo_with_gen.txt
107107
- grep -v '.gen.go' < coverinfo_with_gen.txt > coverinfo.txt
108108
- go run github.com/t-yuki/gocover-cobertura < coverinfo.txt > cobertura.xml
109109
- go tool cover -html=coverinfo.txt -o coverage.html

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ run:
1313
linters:
1414
enable-all: true
1515
disable:
16+
- gomoddirectives # TODO: remove this as soon as as https://github.com/imdario/mergo/pull/198 and https://github.com/imdario/mergo/pull/197 are merged
1617
- promlinter
1718
- nolintlint
1819
- thelper

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ all:
2222
$(error Use make (dev|release|static_release) instead)
2323

2424
race:
25-
./tools/go_test.sh -race
25+
./tools/go_test.sh -race -tags="sqlite_json"
2626

2727
BUILD_DEPENDENCIES = go gcc ragel npm vue
2828
$(foreach exec,$(BUILD_DEPENDENCIES),\
@@ -37,16 +37,16 @@ pre_build: npminstall translations frontend_root static_www postfix_parser domai
3737
pre_release: pre_build recommendation_release
3838

3939
dev_bin: dev_pre_build recommendation_dev
40-
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
40+
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
4141

4242
dev_headless_bin: dev_headless_pre_build recommendation_dev
43-
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
43+
go build -tags="dev include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
4444

4545
release_bin: pre_release
46-
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
46+
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags "${BUILD_INFO_FLAGS}"
4747

4848
static_release_bin: pre_release
49-
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql" -o "lightmeter" -ldflags \
49+
go build -tags="release include no_postgres no_mysql no_clickhouse no_mssql sqlite_json" -o "lightmeter" -ldflags \
5050
"${BUILD_INFO_FLAGS} -linkmode external -extldflags '-static' -s -w" -a -v
5151

5252
static_www:
@@ -66,16 +66,19 @@ recommendation_dev:
6666
recommendation_release:
6767
go generate -tags="release" gitlab.com/lightmeter/controlcenter/recommendation
6868

69-
mocks: postfix_parser dashboard_mock insights_mock detective_mock
69+
mocks: postfix_parser dashboard_mock insights_mock detective_mock intel_mock
7070

7171
dashboard_mock:
7272
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/dashboard
7373

7474
insights_mock:
7575
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/insights/core
7676

77+
intel_mock:
78+
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/intel/receptor
79+
7780
detective_mock:
78-
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/detective
81+
go generate -tags="dev sqlite_json" gitlab.com/lightmeter/controlcenter/detective
7982

8083
po2go:
8184
go generate -tags="dev" gitlab.com/lightmeter/controlcenter/po

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Running headless mode requires building ControlCenter for this purpose:
200200

201201
```
202202
make devheadless # Build ControlCenter
203-
./lightmeter -stdin -verbose --listen :8003 # Example command to start ControlCenter quickly (same as running a normal build)
203+
./lightmeter -stdin -log-level DEBUG --listen :8003 # Example command to start ControlCenter quickly (same as running a normal build)
204204
```
205205

206206
### Authentication
@@ -235,7 +235,22 @@ For detailed information, check [Usage](cli_usage.md).
235235
(even if compressed with gzip or bzip2) and waiting new log files that happen after such import.
236236
To use it, start lightmeter with the argument `-watch_dir /path/to/dir`, which is likely to be `/var/log/mail`.
237237
Lightmeter won't import such logs again if they have already been imported, in case of a process restart.
238-
- You can run it behind a reverse http proxy such as Apache httpd or nginx, even on a different path. No extra configuration is needed.
238+
239+
### Reverse proxy and securing the user interface
240+
241+
Control Center has a web based user interface, provided over a ***plain*** HTTP server. It does not ship a HTTP server.
242+
It's up to you to deploy it behind a HTTP reverse proxy, such as NGINX, Apache HTTPD, H2 or Traefik.
243+
244+
Running behind a reverse proxy does not require any extra configuration, even if Control Center user interface is available
245+
in a path different from `/`, for instance, on `https://example.com/lightmeter/`.
246+
247+
Control Center assumes that it's running behind a reverse proxy to obtain the user's IP (used for rate limiting requests and prevent some sorts of DOS attacks).
248+
249+
In case you are running Control Center in a private network and do not need to run it behind a reverse proxy, using plain HTTP, you should pass
250+
an extra argument in the command line `-i_know_what_am_doing_not_using_a_reverse_proxy` or set the environment variable
251+
`LIGHTMETER_I_KNOW_WHAT_I_AM_DOING_NOT_USING_A_REVERSE_PROXY=true`.
252+
253+
###
239254

240255
Currently the following patterns for log files are "watched":
241256
- mail.log
@@ -253,13 +268,14 @@ For cloud installations of Lightmeter, it may be necessary to set parameters via
253268
Here are all parameters you can set through environment variables, and their respective command-line equivalents:
254269
- `LIGHTMETER_WORKSPACE=/path/to/workspace` (`-workspace`)
255270
- `LIGHTMETER_WATCH_DIR=/var/log` (`-watch_dir`)
256-
- `LIGHTMETER_VERBOSE=true` (`-verbose`)
271+
- `LIGHTMETER_LOG_LEVEL=DEBUG` (`-log-level DEBUG`)
257272
- `LIGHTMETER_LISTEN=localhost:9999` (`-listen`)
258273
- `LIGHTMETER_LOGS_SOCKET=unix;/path/to/socket.sock` (`-logs_socket`)
259274
- `LIGHTMETER_LOGS_USE_RSYNC=true` (`-logs_use_rsync`)
260275
- `LIGHTMETER_LOGS_STARTING_YEAR=2019` (`-log_starting_year`)
261276
- `LIGHTMETER_LOG_FORMAT=prepend-rfc3339` (`-log_format`)
262277
- `LIGHTMETER_LOG_FILE_PATTERNS=mail.log:mail.err:mail.warn:zimbra.log:maillog` (`-log_file_patterns`)
278+
- `LIGHTMETER_I_KNOW_WHAT_I_AM_DOING_NOT_USING_A_REVERSE_PROXY=true` (`-i_know_what_am_doing_not_using_a_reverse_proxy`)
263279

264280
### Rotated files
265281

acceptance_tests/specs/1_1_registration.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Tags: failure
77
* Focus on field with placeholder "Name"
88
* Type "User Complete Name"
99
* Focus on field with placeholder "Email"
10-
10+
1111
* Focus on field with placeholder "Password"
1212
* Type "54353%#%#54354353gffgdgdfg"
1313
* Expect registration to fail
@@ -20,7 +20,7 @@ Tags: success
2020
* Focus on field with placeholder "Name"
2121
* Type "User Complete Name"
2222
* Focus on field with placeholder "Email"
23-
23+
2424
* Focus on field with placeholder "Password"
2525
* Type "54353%#%#54354353gffgdgdfg"
2626
* Select option "direct" from menu "Most of my mail is…"

acceptance_tests/specs/3_login.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: success
55

66
* Go to login page
77
* Focus on field with placeholder "Email"
8-
8+
99
* Focus on field with placeholder "Password"
1010
* Type "54353%#%#54354353gffgdgdfg"
1111
* Click on "Login"

acceptance_tests/tests/step_implementation.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ const headless = process.env.headless_chrome.toLowerCase() === 'true';
3838

3939
var lightmeterProcess = null
4040

41-
var tmpDir = tmp.dirSync()
41+
var workspaceDir = tmp.dirSync()
4242

4343
beforeSuite(async () => {
44-
lightmeterProcess = child_process.execFile('../lightmeter', ['-workspace', tmpDir.name, '-stdin', '-listen', ':8080'])
44+
let callback = function(error, stdout, stderr) {
45+
if (error) {
46+
console.warn(stdout)
47+
console.error(stderr)
48+
throw error
49+
}
50+
}
51+
52+
lightmeterProcess = child_process.execFile('../lightmeter', ['-workspace', workspaceDir.name, '-stdin', '-listen', ':8080'], callback)
4553

4654
return new Promise((r) => setTimeout(r, 2000)).then(async () => {
4755
await openBrowser({ headless: headless, args: ["--no-sandbox", "--no-first-run"] })

api/connectionstats.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import (
1414
"time"
1515
)
1616

17-
type smtpAuthAttemptsHandler struct {
17+
type authAttemptsHandler struct {
1818
accessor *connectionstats.Accessor
1919
}
2020

21-
// @Summary Information Fetch SMTP authentication attempts
21+
// @Summary Information Fetch authentication attempts
2222
// @Param from query string true "Initial date in the format 1999-12-23"
2323
// @Param to query string true "Final date in the format 1999-12-23"
2424
// @Produce json
2525
// @Success 200 {object} connectionstats.Stats "desc"
2626
// @Failure 422 {string} string "desc"
27-
// @Router /api/v0/fetchSmtpAuthAttempts [get]
28-
func (handler smtpAuthAttemptsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
27+
// @Router /api/v0/fetchAuthAttempts [get]
28+
func (handler authAttemptsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
2929
interval := httpmiddleware.GetIntervalFromContext(r)
3030

3131
result, err := handler.accessor.FetchAuthAttempts(r.Context(), interval)
@@ -38,5 +38,5 @@ func (handler smtpAuthAttemptsHandler) ServeHTTP(w http.ResponseWriter, r *http.
3838

3939
func HttpConnectionsDashboard(auth *auth.Authenticator, mux *http.ServeMux, timezone *time.Location, accessor *connectionstats.Accessor) {
4040
authenticated := httpmiddleware.WithDefaultStack(auth, httpmiddleware.RequestWithInterval(timezone))
41-
mux.Handle("/api/v0/fetchSmtpAuthAttempts", authenticated.WithEndpoint(smtpAuthAttemptsHandler{accessor: accessor}))
41+
mux.Handle("/api/v0/fetchAuthAttempts", authenticated.WithEndpoint(authAttemptsHandler{accessor: accessor}))
4242
}

api/detective.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"time"
2323
)
2424

25-
func requireDetectiveAuth(auth *httpauth.Authenticator, settingsReader *metadata.Reader) httpmiddleware.Middleware {
25+
func requireDetectiveAuth(auth *httpauth.Authenticator, settingsReader metadata.Reader) httpmiddleware.Middleware {
2626
return func(h httpmiddleware.CustomHTTPHandler) httpmiddleware.CustomHTTPHandler {
2727
return httpmiddleware.CustomHTTPHandler(func(w http.ResponseWriter, r *http.Request) error {
2828
/* The detective handler can be accessed if authenticated
@@ -128,8 +128,13 @@ func (h oldestAvailableTimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
128128
return httputil.WriteJson(w, OldestAvailableTimeResponse{Time: &time}, http.StatusOK)
129129
}
130130

131-
func HttpDetective(auth *auth.Authenticator, mux *http.ServeMux, timezone *time.Location, detective detective.Detective, escalator escalator.Requester, settingsReader *metadata.Reader) {
132-
publicIfEnabled := httpmiddleware.New(httpmiddleware.RequestWithTimeout(httpmiddleware.DefaultTimeout), requireDetectiveAuth(auth, settingsReader))
131+
func HttpDetective(auth *auth.Authenticator, mux *http.ServeMux, timezone *time.Location, detective detective.Detective, escalator escalator.Requester, settingsReader metadata.Reader, isBehindReverseProxy bool) {
132+
publicIfEnabled := httpmiddleware.New(
133+
httpmiddleware.RequestWithRateLimit(10*time.Minute, 20, isBehindReverseProxy, httpmiddleware.BlockQuery),
134+
httpmiddleware.RequestWithTimeout(httpmiddleware.DefaultTimeout),
135+
requireDetectiveAuth(auth, settingsReader),
136+
)
137+
133138
mux.Handle("/api/v0/checkMessageDeliveryStatus", publicIfEnabled.WithEndpoint(checkMessageDeliveryHandler{detective}))
134139
mux.Handle("/api/v0/escalateMessage", publicIfEnabled.WithEndpoint(detectiveEscalatorHandler{requester: escalator, detective: detective}))
135140
mux.Handle("/api/v0/oldestAvailableTimeForMessageDetective", publicIfEnabled.WithEndpoint(oldestAvailableTimeHandler{detective: detective}))

api/detective_auth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ func buildTestEnv(t *testing.T) (*httptest.Server, *mock_detective.MockDetective
6464
settingsWriter := writeRunner.Writer()
6565
settingsReader := handler.Reader
6666

67-
HttpDetective(auth, mux, time.UTC, detective, &fakeEscalateRequester{}, settingsReader)
67+
HttpDetective(auth, mux, time.UTC, detective, &fakeEscalateRequester{}, settingsReader, true)
6868

69-
httpauth.HttpAuthenticator(mux, auth, settingsReader)
69+
httpauth.HttpAuthenticator(mux, auth, settingsReader, true)
7070

7171
s := httptest.NewServer(mux)
7272

api/rate_limit_test.go

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)