-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from bramanda48/develop
Add logs endpoints, authenticaton, etc
- Loading branch information
Showing
44 changed files
with
877 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
DENO_ENV="production" | ||
WEB_API_KEY="" | ||
WEB_API_WHITELISTED_IP="127.0.0.1" | ||
WEB_API_DMS_CONFIG_PATH="/tmp/docker-mailserver" | ||
WEB_API_FAIL2BAN_SQLITE_PATH="/var/lib/fail2ban/fail2ban.sqlite3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
type Environment = { | ||
Bindings: EnvironmentBindings; | ||
}; | ||
|
||
type EnvironmentBindings = { | ||
remoteAddr: () => string; | ||
|
||
// Define all environment variables | ||
DENO_ENV: string; | ||
WEB_API_KEY: string; | ||
WEB_API_WHITELISTED_IP: string; | ||
WEB_API_DMS_CONFIG_PATH: string; | ||
WEB_API_FAIL2BAN_SQLITE_PATH: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/denoland/deno/main/cli/schemas/config-file.v1.json", | ||
"tasks": { | ||
"start": "deno run --allow-all dist/main.esm.js", | ||
"dev": "deno run --allow-all --watch src/main.ts", | ||
"start": "deno run --allow-all --unstable-ffi dist/main.esm.js", | ||
"dev": "deno run --allow-all --unstable-ffi --watch src/main.ts", | ||
"deps": "deno cache --reload --lock=deno.lock --lock-write deps.ts build.ts", | ||
"build": "deno run --allow-all build.ts", | ||
"test": "deno test --allow-all" | ||
|
@@ -16,10 +16,12 @@ | |
"hono/cors": "https://deno.land/x/[email protected]/middleware/cors/index.ts", | ||
"hono/pretty-json": "https://deno.land/x/[email protected]/middleware/pretty-json/index.ts", | ||
"hono/serve-static": "https://deno.land/x/[email protected]/middleware/serve-static/index.ts", | ||
"hono/logger": "https://deno.land/x/[email protected]/middleware/logger/index.ts", | ||
"hono/swagger-ui": "https://cdn.jsdelivr.net/npm/@hono/[email protected]/+esm", | ||
"status-code": "https://deno.land/x/[email protected]/mod.ts", | ||
"zod": "https://deno.land/x/[email protected]/mod.ts", | ||
"readline": "https://deno.land/x/[email protected]/mod.ts" | ||
"readline": "https://deno.land/x/[email protected]/mod.ts", | ||
"sqlite3": "https://deno.land/x/[email protected]/mod.ts" | ||
}, | ||
"scopes": { | ||
"https://deno.land/x/[email protected]/": { | ||
|
@@ -28,9 +30,7 @@ | |
}, | ||
"compilerOptions": { | ||
"allowJs": false, | ||
"lib": [ | ||
"deno.window" | ||
], | ||
"lib": ["deno.window"], | ||
"strict": true, | ||
"strictPropertyInitialization": false, | ||
"strictNullChecks": false, | ||
|
@@ -39,16 +39,10 @@ | |
}, | ||
"lint": { | ||
"rules": { | ||
"tags": [ | ||
"recommended" | ||
], | ||
"exclude": [ | ||
"no-explicit-any" | ||
] | ||
"tags": ["recommended"], | ||
"exclude": ["no-explicit-any"] | ||
}, | ||
"include": [ | ||
"src/" | ||
] | ||
"include": ["src/"] | ||
}, | ||
"fmt": { | ||
"useTabs": false, | ||
|
@@ -57,8 +51,6 @@ | |
"semiColons": true, | ||
"singleQuote": false, | ||
"proseWrap": "preserve", | ||
"include": [ | ||
"src/" | ||
] | ||
"include": ["src/"] | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
fail2ban-client set custom banip "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
fail2ban-client set custom unbanip "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
SERVICE_NAME=$1 | ||
SERVICE_LOGS="" | ||
LIMIT=$2 | ||
|
||
case "$SERVICE_NAME" in | ||
fail2ban) | ||
SERVICE_LOGS="/var/log/mail/fail2ban.log" | ||
;; | ||
clamav) | ||
SERVICE_LOGS="/var/log/mail/clamav.log" | ||
;; | ||
rspamd) | ||
SERVICE_LOGS="/var/log/mail/rspamd.log" | ||
;; | ||
mail) | ||
SERVICE_LOGS="/var/log/mail/mail.log" | ||
;; | ||
*) | ||
echo "Invalid service name `${SERVICE_NAME}`" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
tail -"$LIMIT" "$SERVICE_LOGS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Handler, StatusCodes } from "../../../../deps.ts"; | ||
import { Fail2banService } from "../../../services/fail2ban/fail2ban.service.ts"; | ||
import { ResponseFormat } from "../../../utils/api-response.ts"; | ||
import { Fail2banValidation } from "../../../validations/V1/fail2ban/fail2ban.validation.ts"; | ||
|
||
const getJail: Handler = (c) => { | ||
const responseFormat = new ResponseFormat(c); | ||
const fail2banService = new Fail2banService(); | ||
|
||
const jail = fail2banService.getJail(); | ||
return responseFormat | ||
.withRequestData({ | ||
timestamp: new Date(), | ||
method: c.req.method, | ||
path: c.req.path, | ||
}) | ||
.json(jail, StatusCodes.OK); | ||
}; | ||
|
||
const banIpAddress: Handler = (c) => { | ||
const paramParse = c.req.param(); | ||
const { ip } = Fail2banValidation.banIpAddress.parse(paramParse); | ||
|
||
const responseFormat = new ResponseFormat(c); | ||
const fail2banService = new Fail2banService(); | ||
|
||
const banned = fail2banService.banIpAddress(ip); | ||
return responseFormat | ||
.withRequestData({ | ||
timestamp: new Date(), | ||
method: c.req.method, | ||
path: c.req.path, | ||
}) | ||
.json(banned, StatusCodes.OK); | ||
}; | ||
|
||
const unbanIpAddress: Handler = (c) => { | ||
const paramParse = c.req.param(); | ||
const { ip } = Fail2banValidation.unbanIpAddress.parse(paramParse); | ||
|
||
const responseFormat = new ResponseFormat(c); | ||
const fail2banService = new Fail2banService(); | ||
|
||
const unbanned = fail2banService.unbanIpAddress(ip); | ||
return responseFormat | ||
.withRequestData({ | ||
timestamp: new Date(), | ||
method: c.req.method, | ||
path: c.req.path, | ||
}) | ||
.json(unbanned, StatusCodes.OK); | ||
}; | ||
|
||
export const Fail2banController = { | ||
getJail, | ||
banIpAddress, | ||
unbanIpAddress, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Handler, StatusCodes } from "../../../../deps.ts"; | ||
import { RelayService } from "../../../services/relay/relay.service.ts"; | ||
import { ResponseFormat } from "../../../utils/api-response.ts"; | ||
import { RelayValidation } from "../../../validations/V1/relay/relay.validation.ts"; | ||
|
||
const addAuth: Handler = async (c) => { | ||
const bodyParse = await c.req.json(); | ||
const { domain, username, password } = | ||
RelayValidation.addAuth.parse(bodyParse); | ||
|
||
const responseFormat = new ResponseFormat(c); | ||
const relayService = new RelayService(); | ||
|
||
const auth = relayService.addAuth(domain, username, password); | ||
return responseFormat | ||
.withRequestData({ | ||
timestamp: new Date(), | ||
method: c.req.method, | ||
path: c.req.path, | ||
}) | ||
.json(auth, StatusCodes.OK); | ||
}; | ||
|
||
const addDomain: Handler = async (c) => { | ||
const bodyParse = await c.req.json(); | ||
const { domain, host, port } = RelayValidation.addDomain.parse(bodyParse); | ||
|
||
const responseFormat = new ResponseFormat(c); | ||
const relayService = new RelayService(); | ||
|
||
const domains = relayService.addDomain(domain, host, port); | ||
return responseFormat | ||
.withRequestData({ | ||
timestamp: new Date(), | ||
method: c.req.method, | ||
path: c.req.path, | ||
}) | ||
.json(domains, StatusCodes.OK); | ||
}; | ||
|
||
const excludeDomain: Handler = async (c) => { | ||
const bodyParse = await c.req.json(); | ||
const { domain } = RelayValidation.addDomain.parse(bodyParse); | ||
|
||
const responseFormat = new ResponseFormat(c); | ||
const relayService = new RelayService(); | ||
|
||
const exclude = relayService.excludeDomain(domain); | ||
return responseFormat | ||
.withRequestData({ | ||
timestamp: new Date(), | ||
method: c.req.method, | ||
path: c.req.path, | ||
}) | ||
.json(exclude, StatusCodes.OK); | ||
}; | ||
|
||
export const RelayController = { | ||
addAuth, | ||
addDomain, | ||
excludeDomain, | ||
}; |
Oops, something went wrong.