diff --git a/src/blacklist/_utils/blacklist.proto b/src/blacklist/_utils/blacklist.proto index ac79870..4d5ea2c 100644 --- a/src/blacklist/_utils/blacklist.proto +++ b/src/blacklist/_utils/blacklist.proto @@ -6,6 +6,7 @@ service Blacklist { rpc PutBlackList (PutBlackListRequest) returns (PutBlackListReply) {} rpc BlockCountry (BlockCountryRequest) returns (BlockCountryReply) {} rpc GetBlackList (GetBlackListRequest) returns (stream GetBlackListReply) {} + rpc GetBlackListUnary (GetBlackListRequest) returns (GetBlackListReply) {} rpc PutWhiteList (PutWhiteListRequest) returns (PutWhiteListReply) {} } diff --git a/src/blacklist/blacklist.controller.ts b/src/blacklist/blacklist.controller.ts index b8b7a2e..1bc239f 100644 --- a/src/blacklist/blacklist.controller.ts +++ b/src/blacklist/blacklist.controller.ts @@ -12,6 +12,11 @@ import { BlockCountryRequestDto } from './_utils/dto/request/block-country-reque export class BlacklistController { constructor(private readonly blacklistService: BlacklistService) {} + @GrpcMethod('Blacklist', 'GetBlackListUnary') + getBlackListUnary() { + return this.blacklistService.getBlackListUnary(); + } + @GrpcMethod('Blacklist', 'GetBlackList') getBlacklist$(_data: unknown, _metadata: unknown, call: ServerUnaryCall) { return this.blacklistService.getBlackList$(call); diff --git a/src/blacklist/blacklist.service.ts b/src/blacklist/blacklist.service.ts index 36181f6..d964094 100644 --- a/src/blacklist/blacklist.service.ts +++ b/src/blacklist/blacklist.service.ts @@ -53,6 +53,25 @@ export class BlacklistService { }); } + async getBlackListUnary(): Promise { + const filePath = '/app/honeypot/block.conf'; + try { + const blockContent = await readFile(filePath, 'utf8'); + const regex = /deny\s+((?:\d{1,3}\.){3}\d{1,3});/g; + const matches = blockContent.match(regex) || []; + + const ips = matches.map((entry) => { + const ipRegex = /((?:\d{1,3}\.){3}\d{1,3})/; + const match = entry.match(ipRegex); + return match ? match[1] : null; + }).filter((ip) => ip !== null) as string[]; + + return { ips }; + } catch (err) { + throw new RpcException(`Error reading block.conf: ${err}`); + } + } + getBlackList$(call: ServerUnaryCall) { const subject = new Subject();