diff --git a/src/webserv/FaucetWebApi.ts b/src/webserv/FaucetWebApi.ts index 1d525be9a..c0b50d049 100644 --- a/src/webserv/FaucetWebApi.ts +++ b/src/webserv/FaucetWebApi.ts @@ -11,6 +11,7 @@ import { IFaucetResultSharingConfig } from "../config/ConfigShared"; import { FaucetError } from "../common/FaucetError"; import { EthClaimInfo, EthClaimManager } from "../eth/EthClaimManager"; import { buildFaucetStatus, buildQueueStatus, buildSessionStatus } from "./api/faucetStatus"; +import { sha256 } from "../utils/CryptoUtils"; export interface IFaucetApiUrl { path: string[]; @@ -90,7 +91,7 @@ export class FaucetWebApi { case "getQueueStatus".toLowerCase(): return this.onGetQueueStatus(); case "getFaucetStatus".toLowerCase(): - return this.onGetFaucetStatus(); + return this.onGetFaucetStatus(apiUrl.query['key'] as string); default: let handler: (req: IncomingMessage, url: IFaucetApiUrl, body: Buffer) => Promise; if((handler = this.apiEndpoints[apiUrl.path[0].toLowerCase()])) @@ -340,7 +341,17 @@ export class FaucetWebApi { return cachedRsp.data; } - public async onGetFaucetStatus(): Promise { + public async onGetFaucetStatus(key: string): Promise { + if(key) { + if(key !== sha256(faucetConfig.faucetSecret + "-unmasked")) + return new FaucetHttpResponse(403, "Access denied"); + return Object.assign( + await buildFaucetStatus(), + buildQueueStatus(true), + await buildSessionStatus(true) + ); + } + let now = Math.floor(new Date().getTime() / 1000); let cachedRsp, cacheKey = "faucet"; if(!(cachedRsp = this.cachedStatusData[cacheKey]) || cachedRsp.time < now - FAUCETSTATUS_CACHE_TIME) { diff --git a/src/webserv/api/faucetStatus.ts b/src/webserv/api/faucetStatus.ts index f3c9e915d..795a57256 100644 --- a/src/webserv/api/faucetStatus.ts +++ b/src/webserv/api/faucetStatus.ts @@ -101,7 +101,7 @@ export async function buildFaucetStatus(): Promise { return statusRsp; } -export async function buildSessionStatus(): Promise { +export async function buildSessionStatus(unmasked?: boolean): Promise { let sessionsRsp: IClientSessionsStatus = { sessions: null, }; @@ -111,10 +111,10 @@ export async function buildSessionStatus(): Promise { sessionsRsp.sessions = sessions.map((session) => { let runningSession = sessionManager.getSession(session.sessionId); return { - id: getHashedSessionId(session.sessionId, faucetConfig.faucetSecret), + id: unmasked ? session.sessionId : getHashedSessionId(session.sessionId, faucetConfig.faucetSecret), start: session.startTime, target: session.targetAddr, - ip: getHashedIp(session.remoteIP, faucetConfig.faucetSecret), + ip: unmasked ? session.remoteIP : getHashedIp(session.remoteIP, faucetConfig.faucetSecret), ipInfo: session.data["ipinfo.data"], balance: session.dropAmount, nonce: session.data["pow.lastNonce"], @@ -131,12 +131,12 @@ export async function buildSessionStatus(): Promise { return sessionsRsp; } -export function buildQueueStatus(): IClientQueueStatus { +export function buildQueueStatus(unmasked?: boolean): IClientQueueStatus { let claims = ServiceManager.GetService(EthClaimManager).getTransactionQueue(); let rspClaims = claims.map((claimTx) => { return { time: claimTx.claim.claimTime, - session: getHashedSessionId(claimTx.session, faucetConfig.faucetSecret), + session: unmasked ? claimTx.session : getHashedSessionId(claimTx.session, faucetConfig.faucetSecret), target: claimTx.target, amount: claimTx.amount.toString(), status: claimTx.claim.claimStatus,