mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-28 15:56:39 +00:00
Access logs working
This commit is contained in:
@@ -1915,7 +1915,7 @@
|
|||||||
"droppedByRule": "Dropped by Rule",
|
"droppedByRule": "Dropped by Rule",
|
||||||
"noSessions": "No Sessions",
|
"noSessions": "No Sessions",
|
||||||
"temporaryRequestToken": "Temporary Request Token",
|
"temporaryRequestToken": "Temporary Request Token",
|
||||||
"noMoreAuthMethods": "No More Auth Methods",
|
"noMoreAuthMethods": "No Valid Auth",
|
||||||
"ip": "IP Address",
|
"ip": "IP Address",
|
||||||
"reason": "Reason",
|
"reason": "Reason",
|
||||||
"requestLogs": "Request Logs",
|
"requestLogs": "Request Logs",
|
||||||
|
|||||||
@@ -230,23 +230,22 @@ export const actionAuditLog = pgTable("actionAuditLog", {
|
|||||||
index("idx_actionAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
index("idx_actionAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
export const identityAuditLog = pgTable("identityAuditLog", {
|
export const accessAuditLog = pgTable("accessAuditLog", {
|
||||||
id: serial("id").primaryKey(),
|
id: serial("id").primaryKey(),
|
||||||
timestamp: bigint("timestamp", { mode: "number" }).notNull(), // this is EPOCH time in seconds
|
timestamp: bigint("timestamp", { mode: "number" }).notNull(), // this is EPOCH time in seconds
|
||||||
orgId: varchar("orgId")
|
orgId: varchar("orgId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
||||||
actorType: varchar("actorType", { length: 50 }).notNull(),
|
actorType: varchar("actorType", { length: 50 }),
|
||||||
actor: varchar("actor", { length: 255 }).notNull(),
|
actor: varchar("actor", { length: 255 }),
|
||||||
actorId: varchar("actorId", { length: 255 }).notNull(),
|
actorId: varchar("actorId", { length: 255 }),
|
||||||
resourceId: integer("resourceId"),
|
resourceId: integer("resourceId"),
|
||||||
ip: varchar("ip", { length: 45 }).notNull(),
|
ip: varchar("ip", { length: 45 }),
|
||||||
type: varchar("type", { length: 100 }).notNull(),
|
type: varchar("type", { length: 100 }).notNull(),
|
||||||
action: varchar("action", { length: 100 }).notNull(),
|
action: boolean("action").notNull(),
|
||||||
location: text("location"),
|
location: text("location"),
|
||||||
path: text("path"),
|
|
||||||
userAgent: text("userAgent"),
|
userAgent: text("userAgent"),
|
||||||
metadata: text("details")
|
metadata: text("metadata")
|
||||||
}, (table) => ([
|
}, (table) => ([
|
||||||
index("idx_identityAuditLog_timestamp").on(table.timestamp),
|
index("idx_identityAuditLog_timestamp").on(table.timestamp),
|
||||||
index("idx_identityAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
index("idx_identityAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
||||||
@@ -270,4 +269,4 @@ export type RemoteExitNodeSession = InferSelectModel<
|
|||||||
export type ExitNodeOrg = InferSelectModel<typeof exitNodeOrgs>;
|
export type ExitNodeOrg = InferSelectModel<typeof exitNodeOrgs>;
|
||||||
export type LoginPage = InferSelectModel<typeof loginPage>;
|
export type LoginPage = InferSelectModel<typeof loginPage>;
|
||||||
export type ActionAuditLog = InferSelectModel<typeof actionAuditLog>;
|
export type ActionAuditLog = InferSelectModel<typeof actionAuditLog>;
|
||||||
export type IdentityAuditLog = InferSelectModel<typeof identityAuditLog>;
|
export type AccessAuditLog = InferSelectModel<typeof accessAuditLog>;
|
||||||
@@ -688,7 +688,7 @@ export const requestAuditLog = pgTable(
|
|||||||
ip: text("ip"),
|
ip: text("ip"),
|
||||||
location: text("location"),
|
location: text("location"),
|
||||||
userAgent: text("userAgent"),
|
userAgent: text("userAgent"),
|
||||||
metadata: text("details"),
|
metadata: text("metadata"),
|
||||||
headers: text("headers"), // JSON blob
|
headers: text("headers"), // JSON blob
|
||||||
query: text("query"), // JSON blob
|
query: text("query"), // JSON blob
|
||||||
originalRequestURL: text("originalRequestURL"),
|
originalRequestURL: text("originalRequestURL"),
|
||||||
|
|||||||
@@ -225,23 +225,22 @@ export const actionAuditLog = sqliteTable("actionAuditLog", {
|
|||||||
index("idx_actionAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
index("idx_actionAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
export const identityAuditLog = sqliteTable("identityAuditLog", {
|
export const accessAuditLog = sqliteTable("accessAuditLog", {
|
||||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||||
timestamp: integer("timestamp").notNull(), // this is EPOCH time in seconds
|
timestamp: integer("timestamp").notNull(), // this is EPOCH time in seconds
|
||||||
orgId: text("orgId")
|
orgId: text("orgId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
||||||
actorType: text("actorType").notNull(),
|
actorType: text("actorType"),
|
||||||
actor: text("actor").notNull(),
|
actor: text("actor"),
|
||||||
actorId: text("actorId").notNull(),
|
actorId: text("actorId"),
|
||||||
resourceId: integer("resourceId"),
|
resourceId: integer("resourceId"),
|
||||||
ip: text("ip").notNull(),
|
ip: text("ip"),
|
||||||
type: text("type").notNull(),
|
|
||||||
action: text("action").notNull(),
|
|
||||||
location: text("location"),
|
location: text("location"),
|
||||||
path: text("path"),
|
type: text("type").notNull(),
|
||||||
|
action: integer("action", { mode: "boolean" }).notNull(),
|
||||||
userAgent: text("userAgent"),
|
userAgent: text("userAgent"),
|
||||||
metadata: text("details")
|
metadata: text("metadata")
|
||||||
}, (table) => ([
|
}, (table) => ([
|
||||||
index("idx_identityAuditLog_timestamp").on(table.timestamp),
|
index("idx_identityAuditLog_timestamp").on(table.timestamp),
|
||||||
index("idx_identityAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
index("idx_identityAuditLog_org_timestamp").on(table.orgId, table.timestamp)
|
||||||
@@ -265,3 +264,4 @@ export type RemoteExitNodeSession = InferSelectModel<
|
|||||||
export type ExitNodeOrg = InferSelectModel<typeof exitNodeOrgs>;
|
export type ExitNodeOrg = InferSelectModel<typeof exitNodeOrgs>;
|
||||||
export type LoginPage = InferSelectModel<typeof loginPage>;
|
export type LoginPage = InferSelectModel<typeof loginPage>;
|
||||||
export type ActionAuditLog = InferSelectModel<typeof actionAuditLog>;
|
export type ActionAuditLog = InferSelectModel<typeof actionAuditLog>;
|
||||||
|
export type AccessAuditLog = InferSelectModel<typeof accessAuditLog>;
|
||||||
@@ -733,7 +733,7 @@ export const requestAuditLog = sqliteTable(
|
|||||||
ip: text("ip"),
|
ip: text("ip"),
|
||||||
location: text("location"),
|
location: text("location"),
|
||||||
userAgent: text("userAgent"),
|
userAgent: text("userAgent"),
|
||||||
metadata: text("details"),
|
metadata: text("metadata"),
|
||||||
headers: text("headers"), // JSON blob
|
headers: text("headers"), // JSON blob
|
||||||
query: text("query"), // JSON blob
|
query: text("query"), // JSON blob
|
||||||
originalRequestURL: text("originalRequestURL"),
|
originalRequestURL: text("originalRequestURL"),
|
||||||
|
|||||||
102
server/private/lib/logAccessAudit.ts
Normal file
102
server/private/lib/logAccessAudit.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import { accessAuditLog, db } from "@server/db";
|
||||||
|
import { getCountryCodeForIp } from "@server/lib/geoip";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import NodeCache from "node-cache";
|
||||||
|
|
||||||
|
const cache = new NodeCache({
|
||||||
|
stdTTL: 5 // seconds
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function logAccessAudit(data: {
|
||||||
|
action: boolean;
|
||||||
|
type: string;
|
||||||
|
orgId: string;
|
||||||
|
resourceId?: number;
|
||||||
|
user?: { username: string; userId: string };
|
||||||
|
apiKey?: { name: string | null; apiKeyId: string };
|
||||||
|
metadata?: any;
|
||||||
|
userAgent?: string;
|
||||||
|
requestIp?: string;
|
||||||
|
}) {
|
||||||
|
try {
|
||||||
|
let actorType: string | undefined;
|
||||||
|
let actor: string | undefined;
|
||||||
|
let actorId: string | undefined;
|
||||||
|
|
||||||
|
const user = data.user;
|
||||||
|
if (user) {
|
||||||
|
actorType = "user";
|
||||||
|
actor = user.username;
|
||||||
|
actorId = user.userId;
|
||||||
|
}
|
||||||
|
const apiKey = data.apiKey;
|
||||||
|
if (apiKey) {
|
||||||
|
actorType = "apiKey";
|
||||||
|
actor = apiKey.name || apiKey.apiKeyId;
|
||||||
|
actorId = apiKey.apiKeyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (!actorType || !actor || !actorId) {
|
||||||
|
// logger.warn("logRequestAudit: Incomplete actor information");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
const timestamp = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
|
let metadata = null;
|
||||||
|
if (metadata) {
|
||||||
|
metadata = JSON.stringify(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientIp = data.requestIp
|
||||||
|
? (() => {
|
||||||
|
if (
|
||||||
|
data.requestIp.startsWith("[") &&
|
||||||
|
data.requestIp.includes("]")
|
||||||
|
) {
|
||||||
|
// if brackets are found, extract the IPv6 address from between the brackets
|
||||||
|
const ipv6Match = data.requestIp.match(/\[(.*?)\]/);
|
||||||
|
if (ipv6Match) {
|
||||||
|
return ipv6Match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data.requestIp;
|
||||||
|
})()
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const countryCode = data.requestIp
|
||||||
|
? await getCountryCodeFromIp(data.requestIp)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
await db.insert(accessAuditLog).values({
|
||||||
|
timestamp: timestamp,
|
||||||
|
orgId: data.orgId,
|
||||||
|
actorType,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
action: data.action,
|
||||||
|
type: data.type,
|
||||||
|
metadata,
|
||||||
|
resourceId: data.resourceId,
|
||||||
|
userAgent: data.userAgent,
|
||||||
|
ip: clientIp,
|
||||||
|
location: countryCode
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCountryCodeFromIp(ip: string): Promise<string | undefined> {
|
||||||
|
const geoIpCacheKey = `geoip_access:${ip}`;
|
||||||
|
|
||||||
|
let cachedCountryCode: string | undefined = cache.get(geoIpCacheKey);
|
||||||
|
|
||||||
|
if (!cachedCountryCode) {
|
||||||
|
cachedCountryCode = await getCountryCodeForIp(ip); // do it locally
|
||||||
|
// Cache for longer since IP geolocation doesn't change frequently
|
||||||
|
cache.set(geoIpCacheKey, cachedCountryCode, 300); // 5 minutes
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachedCountryCode;
|
||||||
|
}
|
||||||
81
server/private/routers/auditLogs/exportAccessAuditLog.ts
Normal file
81
server/private/routers/auditLogs/exportAccessAuditLog.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { registry } from "@server/openApi";
|
||||||
|
import { NextFunction } from "express";
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
import { OpenAPITags } from "@server/openApi";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { queryAccessAuditLogsParams, queryAccessAuditLogsQuery, queryAccess } from "./queryAccessAuditLog";
|
||||||
|
import { generateCSV } from "@server/routers/auditLogs/generateCSV";
|
||||||
|
|
||||||
|
registry.registerPath({
|
||||||
|
method: "get",
|
||||||
|
path: "/org/{orgId}/logs/access/export",
|
||||||
|
description: "Export the access audit log for an organization as CSV",
|
||||||
|
tags: [OpenAPITags.Org],
|
||||||
|
request: {
|
||||||
|
query: queryAccessAuditLogsQuery,
|
||||||
|
params: queryAccessAuditLogsParams
|
||||||
|
},
|
||||||
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function exportAccessAuditLogs(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedQuery = queryAccessAuditLogsQuery.safeParse(req.query);
|
||||||
|
if (!parsedQuery.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedQuery.error)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { timeStart, timeEnd, limit, offset } = parsedQuery.data;
|
||||||
|
|
||||||
|
const parsedParams = queryAccessAuditLogsParams.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
|
const baseQuery = queryAccess(timeStart, timeEnd, orgId);
|
||||||
|
|
||||||
|
const log = await baseQuery.limit(limit).offset(offset);
|
||||||
|
|
||||||
|
const csvData = generateCSV(log);
|
||||||
|
|
||||||
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
|
res.setHeader('Content-Disposition', `attachment; filename="access-audit-logs-${orgId}-${Date.now()}.csv"`);
|
||||||
|
|
||||||
|
return res.send(csvData);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,25 +11,20 @@
|
|||||||
* This file is not licensed under the AGPLv3.
|
* This file is not licensed under the AGPLv3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { actionAuditLog, db } from "@server/db";
|
|
||||||
import { registry } from "@server/openApi";
|
import { registry } from "@server/openApi";
|
||||||
import { NextFunction } from "express";
|
import { NextFunction } from "express";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { eq, gt, lt, and, count } from "drizzle-orm";
|
|
||||||
import { OpenAPITags } from "@server/openApi";
|
import { OpenAPITags } from "@server/openApi";
|
||||||
import { z } from "zod";
|
|
||||||
import createHttpError from "http-errors";
|
import createHttpError from "http-errors";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import { QueryActionAuditLogResponse } from "@server/routers/auditLogs/types";
|
|
||||||
import response from "@server/lib/response";
|
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { queryActionAuditLogsParams, queryActionAuditLogsQuery, querySites } from "./queryActionAuditLog";
|
import { queryActionAuditLogsParams, queryActionAuditLogsQuery, queryAction } from "./queryActionAuditLog";
|
||||||
import { generateCSV } from "@server/routers/auditLogs/generateCSV";
|
import { generateCSV } from "@server/routers/auditLogs/generateCSV";
|
||||||
|
|
||||||
registry.registerPath({
|
registry.registerPath({
|
||||||
method: "get",
|
method: "get",
|
||||||
path: "/org/{orgId}/logs/actionk/export",
|
path: "/org/{orgId}/logs/action/export",
|
||||||
description: "Export the action audit log for an organization as CSV",
|
description: "Export the action audit log for an organization as CSV",
|
||||||
tags: [OpenAPITags.Org],
|
tags: [OpenAPITags.Org],
|
||||||
request: {
|
request: {
|
||||||
@@ -67,7 +62,7 @@ export async function exportActionAuditLogs(
|
|||||||
}
|
}
|
||||||
const { orgId } = parsedParams.data;
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
const baseQuery = querySites(timeStart, timeEnd, orgId);
|
const baseQuery = queryAction(timeStart, timeEnd, orgId);
|
||||||
|
|
||||||
const log = await baseQuery.limit(limit).offset(offset);
|
const log = await baseQuery.limit(limit).offset(offset);
|
||||||
|
|
||||||
|
|||||||
@@ -13,3 +13,5 @@
|
|||||||
|
|
||||||
export * from "./queryActionAuditLog";
|
export * from "./queryActionAuditLog";
|
||||||
export * from "./exportActionAuditLog";
|
export * from "./exportActionAuditLog";
|
||||||
|
export * from "./queryAccessAuditLog";
|
||||||
|
export * from "./exportAccessAuditLog";
|
||||||
173
server/private/routers/auditLogs/queryAccessAuditLog.ts
Normal file
173
server/private/routers/auditLogs/queryAccessAuditLog.ts
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { accessAuditLog, db, resources } from "@server/db";
|
||||||
|
import { registry } from "@server/openApi";
|
||||||
|
import { NextFunction } from "express";
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
import { eq, gt, lt, and, count } from "drizzle-orm";
|
||||||
|
import { OpenAPITags } from "@server/openApi";
|
||||||
|
import { z } from "zod";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { QueryAccessAuditLogResponse } from "@server/routers/auditLogs/types";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
|
||||||
|
export const queryAccessAuditLogsQuery = z.object({
|
||||||
|
// iso string just validate its a parseable date
|
||||||
|
timeStart: z
|
||||||
|
.string()
|
||||||
|
.refine((val) => !isNaN(Date.parse(val)), {
|
||||||
|
message: "timeStart must be a valid ISO date string"
|
||||||
|
})
|
||||||
|
.transform((val) => Math.floor(new Date(val).getTime() / 1000)),
|
||||||
|
timeEnd: z
|
||||||
|
.string()
|
||||||
|
.refine((val) => !isNaN(Date.parse(val)), {
|
||||||
|
message: "timeEnd must be a valid ISO date string"
|
||||||
|
})
|
||||||
|
.transform((val) => Math.floor(new Date(val).getTime() / 1000))
|
||||||
|
.optional()
|
||||||
|
.default(new Date().toISOString()),
|
||||||
|
limit: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.default("1000")
|
||||||
|
.transform(Number)
|
||||||
|
.pipe(z.number().int().positive()),
|
||||||
|
offset: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.default("0")
|
||||||
|
.transform(Number)
|
||||||
|
.pipe(z.number().int().nonnegative())
|
||||||
|
});
|
||||||
|
|
||||||
|
export const queryAccessAuditLogsParams = z.object({
|
||||||
|
orgId: z.string()
|
||||||
|
});
|
||||||
|
|
||||||
|
export function queryAccess(timeStart: number, timeEnd: number, orgId: string) {
|
||||||
|
return db
|
||||||
|
.select({
|
||||||
|
orgId: accessAuditLog.orgId,
|
||||||
|
action: accessAuditLog.action,
|
||||||
|
actorType: accessAuditLog.actorType,
|
||||||
|
actorId: accessAuditLog.actorId,
|
||||||
|
resourceId: accessAuditLog.resourceId,
|
||||||
|
resourceName: resources.name,
|
||||||
|
resourceNiceId: resources.niceId,
|
||||||
|
ip: accessAuditLog.ip,
|
||||||
|
location: accessAuditLog.location,
|
||||||
|
userAgent: accessAuditLog.userAgent,
|
||||||
|
metadata: accessAuditLog.metadata,
|
||||||
|
type: accessAuditLog.type,
|
||||||
|
timestamp: accessAuditLog.timestamp,
|
||||||
|
actor: accessAuditLog.actor
|
||||||
|
})
|
||||||
|
.from(accessAuditLog)
|
||||||
|
.leftJoin(resources, eq(accessAuditLog.resourceId, resources.resourceId))
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
gt(accessAuditLog.timestamp, timeStart),
|
||||||
|
lt(accessAuditLog.timestamp, timeEnd),
|
||||||
|
eq(accessAuditLog.orgId, orgId)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.orderBy(accessAuditLog.timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function countAccessQuery(timeStart: number, timeEnd: number, orgId: string) {
|
||||||
|
const countQuery = db
|
||||||
|
.select({ count: count() })
|
||||||
|
.from(accessAuditLog)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
gt(accessAuditLog.timestamp, timeStart),
|
||||||
|
lt(accessAuditLog.timestamp, timeEnd),
|
||||||
|
eq(accessAuditLog.orgId, orgId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return countQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
registry.registerPath({
|
||||||
|
method: "get",
|
||||||
|
path: "/org/{orgId}/logs/access",
|
||||||
|
description: "Query the access audit log for an organization",
|
||||||
|
tags: [OpenAPITags.Org],
|
||||||
|
request: {
|
||||||
|
query: queryAccessAuditLogsQuery,
|
||||||
|
params: queryAccessAuditLogsParams
|
||||||
|
},
|
||||||
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function queryAccessAuditLogs(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedQuery = queryAccessAuditLogsQuery.safeParse(req.query);
|
||||||
|
if (!parsedQuery.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedQuery.error)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { timeStart, timeEnd, limit, offset } = parsedQuery.data;
|
||||||
|
|
||||||
|
const parsedParams = queryAccessAuditLogsParams.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
|
const baseQuery = queryAccess(timeStart, timeEnd, orgId);
|
||||||
|
|
||||||
|
const log = await baseQuery.limit(limit).offset(offset);
|
||||||
|
|
||||||
|
const totalCountResult = await countAccessQuery(timeStart, timeEnd, orgId);
|
||||||
|
const totalCount = totalCountResult[0].count;
|
||||||
|
|
||||||
|
return response<QueryAccessAuditLogResponse>(res, {
|
||||||
|
data: {
|
||||||
|
log: log,
|
||||||
|
pagination: {
|
||||||
|
total: totalCount,
|
||||||
|
limit,
|
||||||
|
offset
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Access audit logs retrieved successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ export const queryActionAuditLogsParams = z.object({
|
|||||||
orgId: z.string()
|
orgId: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
export function querySites(timeStart: number, timeEnd: number, orgId: string) {
|
export function queryAction(timeStart: number, timeEnd: number, orgId: string) {
|
||||||
return db
|
return db
|
||||||
.select({
|
.select({
|
||||||
orgId: actionAuditLog.orgId,
|
orgId: actionAuditLog.orgId,
|
||||||
@@ -80,7 +80,7 @@ export function querySites(timeStart: number, timeEnd: number, orgId: string) {
|
|||||||
.orderBy(actionAuditLog.timestamp);
|
.orderBy(actionAuditLog.timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function countQuery(timeStart: number, timeEnd: number, orgId: string) {
|
export function countActionQuery(timeStart: number, timeEnd: number, orgId: string) {
|
||||||
const countQuery = db
|
const countQuery = db
|
||||||
.select({ count: count() })
|
.select({ count: count() })
|
||||||
.from(actionAuditLog)
|
.from(actionAuditLog)
|
||||||
@@ -134,11 +134,11 @@ export async function queryActionAuditLogs(
|
|||||||
}
|
}
|
||||||
const { orgId } = parsedParams.data;
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
const baseQuery = querySites(timeStart, timeEnd, orgId);
|
const baseQuery = queryAction(timeStart, timeEnd, orgId);
|
||||||
|
|
||||||
const log = await baseQuery.limit(limit).offset(offset);
|
const log = await baseQuery.limit(limit).offset(offset);
|
||||||
|
|
||||||
const totalCountResult = await countQuery(timeStart, timeEnd, orgId);
|
const totalCountResult = await countActionQuery(timeStart, timeEnd, orgId);
|
||||||
const totalCount = totalCountResult[0].count;
|
const totalCount = totalCountResult[0].count;
|
||||||
|
|
||||||
return response<QueryActionAuditLogResponse>(res, {
|
return response<QueryActionAuditLogResponse>(res, {
|
||||||
|
|||||||
@@ -351,8 +351,17 @@ authenticated.get(
|
|||||||
logs.queryActionAuditLogs
|
logs.queryActionAuditLogs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
authenticated.get(
|
authenticated.get(
|
||||||
"/org/:orgId/logs/action/export",
|
"/org/:orgId/logs/action/export",
|
||||||
logs.exportActionAuditLogs
|
logs.exportActionAuditLogs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
authenticated.get(
|
||||||
|
"/org/:orgId/logs/access",
|
||||||
|
logs.queryAccessAuditLogs
|
||||||
|
)
|
||||||
|
|
||||||
|
authenticated.get(
|
||||||
|
"/org/:orgId/logs/access/export",
|
||||||
|
logs.exportAccessAuditLogs
|
||||||
|
)
|
||||||
@@ -11,7 +11,7 @@ import { fromError } from "zod-validation-error";
|
|||||||
import { QueryRequestAuditLogResponse } from "@server/routers/auditLogs/types";
|
import { QueryRequestAuditLogResponse } from "@server/routers/auditLogs/types";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { queryAccessAuditLogsQuery, queryRequestAuditLogsParams, querySites } from "./queryRequstAuditLog";
|
import { queryAccessAuditLogsQuery, queryRequestAuditLogsParams, queryRequest } from "./queryRequstAuditLog";
|
||||||
import { generateCSV } from "./generateCSV";
|
import { generateCSV } from "./generateCSV";
|
||||||
|
|
||||||
registry.registerPath({
|
registry.registerPath({
|
||||||
@@ -54,7 +54,7 @@ export async function exportRequestAuditLogs(
|
|||||||
}
|
}
|
||||||
const { orgId } = parsedParams.data;
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
const baseQuery = querySites(timeStart, timeEnd, orgId);
|
const baseQuery = queryRequest(timeStart, timeEnd, orgId);
|
||||||
|
|
||||||
const log = await baseQuery.limit(limit).offset(offset);
|
const log = await baseQuery.limit(limit).offset(offset);
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export const queryRequestAuditLogsParams = z.object({
|
|||||||
orgId: z.string()
|
orgId: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
export function querySites(timeStart: number, timeEnd: number, orgId: string) {
|
export function queryRequest(timeStart: number, timeEnd: number, orgId: string) {
|
||||||
return db
|
return db
|
||||||
.select({
|
.select({
|
||||||
timestamp: requestAuditLog.timestamp,
|
timestamp: requestAuditLog.timestamp,
|
||||||
@@ -84,7 +84,7 @@ export function querySites(timeStart: number, timeEnd: number, orgId: string) {
|
|||||||
.orderBy(requestAuditLog.timestamp);
|
.orderBy(requestAuditLog.timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function countQuery(timeStart: number, timeEnd: number, orgId: string) {
|
export function countRequestQuery(timeStart: number, timeEnd: number, orgId: string) {
|
||||||
const countQuery = db
|
const countQuery = db
|
||||||
.select({ count: count() })
|
.select({ count: count() })
|
||||||
.from(requestAuditLog)
|
.from(requestAuditLog)
|
||||||
@@ -138,11 +138,11 @@ export async function queryRequestAuditLogs(
|
|||||||
}
|
}
|
||||||
const { orgId } = parsedParams.data;
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
const baseQuery = querySites(timeStart, timeEnd, orgId);
|
const baseQuery = queryRequest(timeStart, timeEnd, orgId);
|
||||||
|
|
||||||
const log = await baseQuery.limit(limit).offset(offset);
|
const log = await baseQuery.limit(limit).offset(offset);
|
||||||
|
|
||||||
const totalCountResult = await countQuery(timeStart, timeEnd, orgId);
|
const totalCountResult = await countRequestQuery(timeStart, timeEnd, orgId);
|
||||||
const totalCount = totalCountResult[0].count;
|
const totalCount = totalCountResult[0].count;
|
||||||
|
|
||||||
return response<QueryRequestAuditLogResponse>(res, {
|
return response<QueryRequestAuditLogResponse>(res, {
|
||||||
|
|||||||
@@ -45,3 +45,27 @@ export type QueryRequestAuditLogResponse = {
|
|||||||
offset: number;
|
offset: number;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type QueryAccessAuditLogResponse = {
|
||||||
|
log: {
|
||||||
|
orgId: string;
|
||||||
|
action: string;
|
||||||
|
type: string;
|
||||||
|
resourceId: number | null;
|
||||||
|
resourceName: string | null;
|
||||||
|
resourceNiceId: string | null;
|
||||||
|
ip: string | null;
|
||||||
|
location: string | null;
|
||||||
|
userAgent: string | null;
|
||||||
|
metadata: string | null;
|
||||||
|
actorType: string;
|
||||||
|
actorId: string;
|
||||||
|
timestamp: number;
|
||||||
|
actor: string;
|
||||||
|
}[];
|
||||||
|
pagination: {
|
||||||
|
total: number;
|
||||||
|
limit: number;
|
||||||
|
offset: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateSessionToken,
|
generateSessionToken,
|
||||||
serializeSessionCookie
|
serializeSessionCookie
|
||||||
} from "@server/auth/sessions/app";
|
} from "@server/auth/sessions/app";
|
||||||
import { db } from "@server/db";
|
import { db, resources } from "@server/db";
|
||||||
import { users, securityKeys } from "@server/db";
|
import { users, securityKeys } from "@server/db";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
@@ -18,12 +18,14 @@ import logger from "@server/logger";
|
|||||||
import { verifyPassword } from "@server/auth/password";
|
import { verifyPassword } from "@server/auth/password";
|
||||||
import { verifySession } from "@server/auth/sessions/verifySession";
|
import { verifySession } from "@server/auth/sessions/verifySession";
|
||||||
import { UserType } from "@server/types/UserTypes";
|
import { UserType } from "@server/types/UserTypes";
|
||||||
|
import { logAccessAudit } from "@server/private/lib/logAccessAudit";
|
||||||
|
|
||||||
export const loginBodySchema = z
|
export const loginBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
email: z.string().toLowerCase().email(),
|
email: z.string().toLowerCase().email(),
|
||||||
password: z.string(),
|
password: z.string(),
|
||||||
code: z.string().optional()
|
code: z.string().optional(),
|
||||||
|
resourceGuid: z.string().optional()
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ export async function login(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { email, password, code } = parsedBody.data;
|
const { email, password, code, resourceGuid } = parsedBody.data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { session: existingSession } = await verifySession(req);
|
const { session: existingSession } = await verifySession(req);
|
||||||
@@ -66,6 +68,28 @@ export async function login(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let resourceId: number | null = null;
|
||||||
|
let orgId: string | null = null;
|
||||||
|
if (resourceGuid) {
|
||||||
|
const [resource] = await db
|
||||||
|
.select()
|
||||||
|
.from(resources)
|
||||||
|
.where(eq(resources.resourceGuid, resourceGuid))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!resource) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Resource with GUID ${resourceGuid} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceId = resource.resourceId;
|
||||||
|
orgId = resource.orgId;
|
||||||
|
}
|
||||||
|
|
||||||
const existingUserRes = await db
|
const existingUserRes = await db
|
||||||
.select()
|
.select()
|
||||||
.from(users)
|
.from(users)
|
||||||
@@ -78,6 +102,18 @@ export async function login(
|
|||||||
`Username or password incorrect. Email: ${email}. IP: ${req.ip}.`
|
`Username or password incorrect. Email: ${email}. IP: ${req.ip}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resourceId && orgId) {
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: orgId,
|
||||||
|
resourceId: resourceId,
|
||||||
|
action: false,
|
||||||
|
type: "login",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.UNAUTHORIZED,
|
HttpCode.UNAUTHORIZED,
|
||||||
@@ -98,6 +134,18 @@ export async function login(
|
|||||||
`Username or password incorrect. Email: ${email}. IP: ${req.ip}.`
|
`Username or password incorrect. Email: ${email}. IP: ${req.ip}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resourceId && orgId) {
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: orgId,
|
||||||
|
resourceId: resourceId,
|
||||||
|
action: false,
|
||||||
|
type: "login",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.UNAUTHORIZED,
|
HttpCode.UNAUTHORIZED,
|
||||||
@@ -158,6 +206,18 @@ export async function login(
|
|||||||
`Two-factor code incorrect. Email: ${email}. IP: ${req.ip}.`
|
`Two-factor code incorrect. Email: ${email}. IP: ${req.ip}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resourceId && orgId) {
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: orgId,
|
||||||
|
resourceId: resourceId,
|
||||||
|
action: false,
|
||||||
|
type: "login",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.UNAUTHORIZED,
|
HttpCode.UNAUTHORIZED,
|
||||||
|
|||||||
@@ -10,11 +10,10 @@ import { z } from "zod";
|
|||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import { createResourceSession } from "@server/auth/sessions/resource";
|
import { createResourceSession } from "@server/auth/sessions/resource";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import {
|
import { verifyResourceAccessToken } from "@server/auth/verifyResourceAccessToken";
|
||||||
verifyResourceAccessToken
|
|
||||||
} from "@server/auth/verifyResourceAccessToken";
|
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import stoi from "@server/lib/stoi";
|
import stoi from "@server/lib/stoi";
|
||||||
|
import { logAccessAudit } from "@server/private/lib/logAccessAudit";
|
||||||
|
|
||||||
const authWithAccessTokenBodySchema = z
|
const authWithAccessTokenBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -131,6 +130,16 @@ export async function authWithAccessToken(
|
|||||||
`Resource access token invalid. Resource ID: ${resource.resourceId}. IP: ${req.ip}.`
|
`Resource access token invalid. Resource ID: ${resource.resourceId}. IP: ${req.ip}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: resource.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: false,
|
||||||
|
type: "accessToken",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.UNAUTHORIZED,
|
HttpCode.UNAUTHORIZED,
|
||||||
@@ -150,6 +159,15 @@ export async function authWithAccessToken(
|
|||||||
doNotExtend: true
|
doNotExtend: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: resource.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: true,
|
||||||
|
type: "accessToken",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
|
||||||
return response<AuthWithAccessTokenResponse>(res, {
|
return response<AuthWithAccessTokenResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
session: token,
|
session: token,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { createResourceSession } from "@server/auth/sessions/resource";
|
|||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { verifyPassword } from "@server/auth/password";
|
import { verifyPassword } from "@server/auth/password";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
|
import { logAccessAudit } from "@server/private/lib/logAccessAudit";
|
||||||
|
|
||||||
export const authWithPasswordBodySchema = z
|
export const authWithPasswordBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -113,6 +114,16 @@ export async function authWithPassword(
|
|||||||
`Resource password incorrect. Resource ID: ${resource.resourceId}. IP: ${req.ip}.`
|
`Resource password incorrect. Resource ID: ${resource.resourceId}. IP: ${req.ip}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: org.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: false,
|
||||||
|
type: "password",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
createHttpError(HttpCode.UNAUTHORIZED, "Incorrect password")
|
createHttpError(HttpCode.UNAUTHORIZED, "Incorrect password")
|
||||||
);
|
);
|
||||||
@@ -129,6 +140,15 @@ export async function authWithPassword(
|
|||||||
doNotExtend: true
|
doNotExtend: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: org.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: true,
|
||||||
|
type: "password",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
|
||||||
return response<AuthWithPasswordResponse>(res, {
|
return response<AuthWithPasswordResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
session: token
|
session: token
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { createResourceSession } from "@server/auth/sessions/resource";
|
|||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { verifyPassword } from "@server/auth/password";
|
import { verifyPassword } from "@server/auth/password";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
|
import { logAccessAudit } from "@server/private/lib/logAccessAudit";
|
||||||
|
|
||||||
export const authWithPincodeBodySchema = z
|
export const authWithPincodeBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
@@ -112,6 +113,16 @@ export async function authWithPincode(
|
|||||||
`Resource pin code incorrect. Resource ID: ${resource.resourceId}. IP: ${req.ip}.`
|
`Resource pin code incorrect. Resource ID: ${resource.resourceId}. IP: ${req.ip}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: org.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: false,
|
||||||
|
type: "pincode",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
createHttpError(HttpCode.UNAUTHORIZED, "Incorrect PIN")
|
createHttpError(HttpCode.UNAUTHORIZED, "Incorrect PIN")
|
||||||
);
|
);
|
||||||
@@ -128,6 +139,15 @@ export async function authWithPincode(
|
|||||||
doNotExtend: true
|
doNotExtend: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: org.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: true,
|
||||||
|
type: "pincode",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
|
||||||
return response<AuthWithPincodeResponse>(res, {
|
return response<AuthWithPincodeResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
session: token
|
session: token
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import { generateSessionToken } from "@server/auth/sessions/app";
|
import { generateSessionToken } from "@server/auth/sessions/app";
|
||||||
import { db } from "@server/db";
|
import { db } from "@server/db";
|
||||||
import {
|
import { orgs, resourceOtp, resources, resourceWhitelist } from "@server/db";
|
||||||
orgs,
|
|
||||||
resourceOtp,
|
|
||||||
resources,
|
|
||||||
resourceWhitelist
|
|
||||||
} from "@server/db";
|
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import { eq, and } from "drizzle-orm";
|
import { eq, and } from "drizzle-orm";
|
||||||
@@ -17,13 +12,11 @@ import { createResourceSession } from "@server/auth/sessions/resource";
|
|||||||
import { isValidOtp, sendResourceOtpEmail } from "@server/auth/resourceOtp";
|
import { isValidOtp, sendResourceOtpEmail } from "@server/auth/resourceOtp";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
|
import { logAccessAudit } from "@server/private/lib/logAccessAudit";
|
||||||
|
|
||||||
const authWithWhitelistBodySchema = z
|
const authWithWhitelistBodySchema = z
|
||||||
.object({
|
.object({
|
||||||
email: z
|
email: z.string().toLowerCase().email(),
|
||||||
.string()
|
|
||||||
.toLowerCase()
|
|
||||||
.email(),
|
|
||||||
otp: z.string().optional()
|
otp: z.string().optional()
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
@@ -126,6 +119,19 @@ export async function authWithWhitelist(
|
|||||||
`Email is not whitelisted. Email: ${email}. IP: ${req.ip}.`
|
`Email is not whitelisted. Email: ${email}. IP: ${req.ip}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (org && resource) {
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: org.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: false,
|
||||||
|
type: "whitelistedEmail",
|
||||||
|
metadata: { email },
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.UNAUTHORIZED,
|
HttpCode.UNAUTHORIZED,
|
||||||
@@ -219,6 +225,16 @@ export async function authWithWhitelist(
|
|||||||
doNotExtend: true
|
doNotExtend: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: org.orgId,
|
||||||
|
resourceId: resource.resourceId,
|
||||||
|
action: true,
|
||||||
|
metadata: { email },
|
||||||
|
type: "whitelistedEmail",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
|
||||||
return response<AuthWithWhitelistResponse>(res, {
|
return response<AuthWithWhitelistResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
session: token
|
session: token
|
||||||
|
|||||||
@@ -10,11 +10,10 @@ import { fromError } from "zod-validation-error";
|
|||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { generateSessionToken } from "@server/auth/sessions/app";
|
import { generateSessionToken } from "@server/auth/sessions/app";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import {
|
import { encodeHexLowerCase } from "@oslojs/encoding";
|
||||||
encodeHexLowerCase
|
|
||||||
} from "@oslojs/encoding";
|
|
||||||
import { sha256 } from "@oslojs/crypto/sha2";
|
import { sha256 } from "@oslojs/crypto/sha2";
|
||||||
import { response } from "@server/lib/response";
|
import { response } from "@server/lib/response";
|
||||||
|
import { logAccessAudit } from "@server/private/lib/logAccessAudit";
|
||||||
|
|
||||||
const getExchangeTokenParams = z
|
const getExchangeTokenParams = z
|
||||||
.object({
|
.object({
|
||||||
@@ -47,13 +46,13 @@ export async function getExchangeToken(
|
|||||||
|
|
||||||
const { resourceId } = parsedParams.data;
|
const { resourceId } = parsedParams.data;
|
||||||
|
|
||||||
const resource = await db
|
const [resource] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(resources)
|
.from(resources)
|
||||||
.where(eq(resources.resourceId, resourceId))
|
.where(eq(resources.resourceId, resourceId))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (resource.length === 0) {
|
if (!resource) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.NOT_FOUND,
|
HttpCode.NOT_FOUND,
|
||||||
@@ -89,6 +88,21 @@ export async function getExchangeToken(
|
|||||||
doNotExtend: true
|
doNotExtend: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (req.user) {
|
||||||
|
logAccessAudit({
|
||||||
|
orgId: resource.orgId,
|
||||||
|
resourceId: resourceId,
|
||||||
|
user: {
|
||||||
|
username: req.user.username,
|
||||||
|
userId: req.user.userId
|
||||||
|
},
|
||||||
|
action: true,
|
||||||
|
type: "login",
|
||||||
|
userAgent: req.headers["user-agent"],
|
||||||
|
requestIp: req.ip
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
logger.debug("Request token created successfully");
|
logger.debug("Request token created successfully");
|
||||||
|
|
||||||
return response<GetExchangeTokenResponse>(res, {
|
return response<GetExchangeTokenResponse>(res, {
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ export type LoginRequest = {
|
|||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
|
resourceGuid?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LoginResponse = {
|
export type LoginResponse = {
|
||||||
|
|||||||
375
src/app/[orgId]/settings/logs/access/page.tsx
Normal file
375
src/app/[orgId]/settings/logs/access/page.tsx
Normal file
@@ -0,0 +1,375 @@
|
|||||||
|
"use client";
|
||||||
|
import { Button } from "@app/components/ui/button";
|
||||||
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { useState, useRef, useEffect } from "react";
|
||||||
|
import { createApiClient } from "@app/lib/api";
|
||||||
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import { LogDataTable } from "@app/components/LogDataTable";
|
||||||
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
|
import { DateTimeValue } from "@app/components/DateTimePicker";
|
||||||
|
import { ArrowUpRight, Key, User } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export default function GeneralPage() {
|
||||||
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const router = useRouter();
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
const t = useTranslations();
|
||||||
|
const { env } = useEnvContext();
|
||||||
|
const { orgId } = useParams();
|
||||||
|
|
||||||
|
const [rows, setRows] = useState<any[]>([]);
|
||||||
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||||
|
const [isExporting, setIsExporting] = useState(false);
|
||||||
|
|
||||||
|
// Pagination state
|
||||||
|
const [totalCount, setTotalCount] = useState<number>(0);
|
||||||
|
const [currentPage, setCurrentPage] = useState<number>(0);
|
||||||
|
const [pageSize, setPageSize] = useState<number>(20);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
// Set default date range to last 24 hours
|
||||||
|
const getDefaultDateRange = () => {
|
||||||
|
const now = new Date();
|
||||||
|
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
|
||||||
|
|
||||||
|
return {
|
||||||
|
startDate: {
|
||||||
|
date: yesterday
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
date: now
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const [dateRange, setDateRange] = useState<{
|
||||||
|
startDate: DateTimeValue;
|
||||||
|
endDate: DateTimeValue;
|
||||||
|
}>(getDefaultDateRange());
|
||||||
|
|
||||||
|
// Trigger search with default values on component mount
|
||||||
|
useEffect(() => {
|
||||||
|
const defaultRange = getDefaultDateRange();
|
||||||
|
queryDateTime(defaultRange.startDate, defaultRange.endDate);
|
||||||
|
}, [orgId]); // Re-run if orgId changes
|
||||||
|
|
||||||
|
const handleDateRangeChange = (
|
||||||
|
startDate: DateTimeValue,
|
||||||
|
endDate: DateTimeValue
|
||||||
|
) => {
|
||||||
|
setDateRange({ startDate, endDate });
|
||||||
|
setCurrentPage(0); // Reset to first page when filtering
|
||||||
|
queryDateTime(startDate, endDate, 0, pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle page changes
|
||||||
|
const handlePageChange = (newPage: number) => {
|
||||||
|
setCurrentPage(newPage);
|
||||||
|
queryDateTime(
|
||||||
|
dateRange.startDate,
|
||||||
|
dateRange.endDate,
|
||||||
|
newPage,
|
||||||
|
pageSize
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle page size changes
|
||||||
|
const handlePageSizeChange = (newPageSize: number) => {
|
||||||
|
setPageSize(newPageSize);
|
||||||
|
setCurrentPage(0); // Reset to first page when changing page size
|
||||||
|
queryDateTime(dateRange.startDate, dateRange.endDate, 0, newPageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const queryDateTime = async (
|
||||||
|
startDate: DateTimeValue,
|
||||||
|
endDate: DateTimeValue,
|
||||||
|
page: number = currentPage,
|
||||||
|
size: number = pageSize
|
||||||
|
) => {
|
||||||
|
console.log("Date range changed:", { startDate, endDate, page, size });
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Convert the date/time values to API parameters
|
||||||
|
let params: any = {
|
||||||
|
limit: size,
|
||||||
|
offset: page * size
|
||||||
|
};
|
||||||
|
|
||||||
|
if (startDate?.date) {
|
||||||
|
const startDateTime = new Date(startDate.date);
|
||||||
|
if (startDate.time) {
|
||||||
|
const [hours, minutes, seconds] = startDate.time
|
||||||
|
.split(":")
|
||||||
|
.map(Number);
|
||||||
|
startDateTime.setHours(hours, minutes, seconds || 0);
|
||||||
|
}
|
||||||
|
params.timeStart = startDateTime.toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endDate?.date) {
|
||||||
|
const endDateTime = new Date(endDate.date);
|
||||||
|
if (endDate.time) {
|
||||||
|
const [hours, minutes, seconds] = endDate.time
|
||||||
|
.split(":")
|
||||||
|
.map(Number);
|
||||||
|
endDateTime.setHours(hours, minutes, seconds || 0);
|
||||||
|
} else {
|
||||||
|
// If no time is specified, set to NOW
|
||||||
|
const now = new Date();
|
||||||
|
endDateTime.setHours(
|
||||||
|
now.getHours(),
|
||||||
|
now.getMinutes(),
|
||||||
|
now.getSeconds(),
|
||||||
|
now.getMilliseconds()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
params.timeEnd = endDateTime.toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await api.get(`/org/${orgId}/logs/access`, { params });
|
||||||
|
if (res.status === 200) {
|
||||||
|
setRows(res.data.data.log || []);
|
||||||
|
setTotalCount(res.data.data.pagination?.total || 0);
|
||||||
|
console.log("Fetched logs:", res.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: t("Failed to filter logs"),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const refreshData = async () => {
|
||||||
|
console.log("Data refreshed");
|
||||||
|
setIsRefreshing(true);
|
||||||
|
try {
|
||||||
|
// Refresh data with current date range and pagination
|
||||||
|
await queryDateTime(
|
||||||
|
dateRange.startDate,
|
||||||
|
dateRange.endDate,
|
||||||
|
currentPage,
|
||||||
|
pageSize
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: t("refreshError"),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsRefreshing(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const exportData = async () => {
|
||||||
|
try {
|
||||||
|
setIsExporting(true);
|
||||||
|
const response = await api.get(`/org/${orgId}/logs/access/export`, {
|
||||||
|
responseType: "blob",
|
||||||
|
params: {
|
||||||
|
timeStart: dateRange.startDate?.date
|
||||||
|
? new Date(dateRange.startDate.date).toISOString()
|
||||||
|
: undefined,
|
||||||
|
timeEnd: dateRange.endDate?.date
|
||||||
|
? new Date(dateRange.endDate.date).toISOString()
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a URL for the blob and trigger a download
|
||||||
|
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
const epoch = Math.floor(Date.now() / 1000);
|
||||||
|
link.setAttribute(
|
||||||
|
"download",
|
||||||
|
`access-audit-logs-${orgId}-${epoch}.csv`
|
||||||
|
);
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.parentNode?.removeChild(link);
|
||||||
|
setIsExporting(false);
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: t("exportError"),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ColumnDef<any>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: "timestamp",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("timestamp");
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div className="whitespace-nowrap">
|
||||||
|
{new Date(
|
||||||
|
row.original.timestamp * 1000
|
||||||
|
).toLocaleString()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "action",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("action");
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
{row.original.action ? <>Allowed</> : <>Denied</>}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "ip",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("ip");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "location",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("location");
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
{row.original.location ? (
|
||||||
|
<span className="text-muted-foreground text-xs">
|
||||||
|
({row.original.location})
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-muted-foreground text-xs">
|
||||||
|
-
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "resourceName",
|
||||||
|
header: t("resource"),
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
href={`/${row.original.orgId}/settings/resources/${row.original.resourceNiceId}`}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="text-xs h-6"
|
||||||
|
>
|
||||||
|
{row.original.resourceName}
|
||||||
|
<ArrowUpRight className="ml-2 h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "type",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("type");
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
{/* {row.original.type == "pincode" ? (
|
||||||
|
<User className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<Key className="h-4 w-4" />
|
||||||
|
)} */}
|
||||||
|
{row.original.type.charAt(0).toUpperCase() +
|
||||||
|
row.original.type.slice(1)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "actor",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("actor");
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
{row.original.actor ? (
|
||||||
|
<>
|
||||||
|
{row.original.actorType == "user" ? (
|
||||||
|
<User className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<Key className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
{row.original.actor}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>-</>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "actorId",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("actorId");
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
{row.original.actorId || "-"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<LogDataTable
|
||||||
|
columns={columns}
|
||||||
|
data={rows}
|
||||||
|
persistPageSize="access-logs-table"
|
||||||
|
title={t("accessLogs")}
|
||||||
|
searchPlaceholder={t("searchLogs")}
|
||||||
|
searchColumn="type"
|
||||||
|
onRefresh={refreshData}
|
||||||
|
isRefreshing={isRefreshing}
|
||||||
|
onExport={exportData}
|
||||||
|
isExporting={isExporting}
|
||||||
|
onDateRangeChange={handleDateRangeChange}
|
||||||
|
dateRange={{
|
||||||
|
start: dateRange.startDate,
|
||||||
|
end: dateRange.endDate
|
||||||
|
}}
|
||||||
|
defaultSort={{
|
||||||
|
id: "timestamp",
|
||||||
|
desc: false
|
||||||
|
}}
|
||||||
|
// Server-side pagination props
|
||||||
|
totalCount={totalCount}
|
||||||
|
currentPage={currentPage}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
onPageSizeChange={handlePageSizeChange}
|
||||||
|
isLoading={isLoading}
|
||||||
|
defaultPageSize={pageSize}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -190,7 +190,7 @@ export default function GeneralPage() {
|
|||||||
const epoch = Math.floor(Date.now() / 1000);
|
const epoch = Math.floor(Date.now() / 1000);
|
||||||
link.setAttribute(
|
link.setAttribute(
|
||||||
"download",
|
"download",
|
||||||
`access-audit-logs-${orgId}-${epoch}.csv`
|
`action-audit-logs-${orgId}-${epoch}.csv`
|
||||||
);
|
);
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
import { internal } from "@app/lib/api";
|
|
||||||
import { authCookieHeader } from "@app/lib/api/cookies";
|
|
||||||
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
||||||
import { HorizontalTabs } from "@app/components/HorizontalTabs";
|
import { HorizontalTabs } from "@app/components/HorizontalTabs";
|
||||||
import { verifySession } from "@app/lib/auth/verifySession";
|
import { verifySession } from "@app/lib/auth/verifySession";
|
||||||
import OrgProvider from "@app/providers/OrgProvider";
|
|
||||||
import OrgUserProvider from "@app/providers/OrgUserProvider";
|
|
||||||
import { GetOrgResponse } from "@server/routers/org";
|
|
||||||
import { GetOrgUserResponse } from "@server/routers/user";
|
|
||||||
import { AxiosResponse } from "axios";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { cache } from "react";
|
import { cache } from "react";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
@@ -37,6 +30,10 @@ export default async function GeneralSettingsPage({
|
|||||||
title: t("request"),
|
title: t("request"),
|
||||||
href: `/{orgId}/settings/logs/request`
|
href: `/{orgId}/settings/logs/request`
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: t("access"),
|
||||||
|
href: `/{orgId}/settings/logs/access`
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: t("action"),
|
title: t("action"),
|
||||||
href: `/{orgId}/settings/logs/action`
|
href: `/{orgId}/settings/logs/action`
|
||||||
|
|||||||
@@ -266,14 +266,25 @@ export default function GeneralPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "action",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return t("action");
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
{row.original.action ? <>Allowed</> : <>Denied</>}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "ip",
|
accessorKey: "ip",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
return t("ip");
|
return t("ip");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
accessorKey: "location",
|
accessorKey: "location",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
@@ -303,7 +314,11 @@ export default function GeneralPage() {
|
|||||||
<Link
|
<Link
|
||||||
href={`/${row.original.orgId}/settings/resources/${row.original.resourceNiceId}`}
|
href={`/${row.original.orgId}/settings/resources/${row.original.resourceNiceId}`}
|
||||||
>
|
>
|
||||||
<Button variant="outline" size="sm" className="text-xs h-6">
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="text-xs h-6"
|
||||||
|
>
|
||||||
{row.original.resourceName}
|
{row.original.resourceName}
|
||||||
<ArrowUpRight className="ml-2 h-3 w-3" />
|
<ArrowUpRight className="ml-2 h-3 w-3" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -373,8 +373,8 @@ export function LogDataTable<TData, TValue>({
|
|||||||
typeof actionValue === "boolean"
|
typeof actionValue === "boolean"
|
||||||
) {
|
) {
|
||||||
className = actionValue
|
className = actionValue
|
||||||
? "bg-green-100 dark:bg-green-900"
|
? "bg-green-100 dark:bg-green-900/50"
|
||||||
: "bg-red-100 dark:bg-red-900";
|
: "bg-red-100 dark:bg-red-900/50";
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
CardTitle
|
CardTitle
|
||||||
} from "@app/components/ui/card";
|
} from "@app/components/ui/card";
|
||||||
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
||||||
import { useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { LockIcon, FingerprintIcon } from "lucide-react";
|
import { LockIcon, FingerprintIcon } from "lucide-react";
|
||||||
import { createApiClient } from "@app/lib/api";
|
import { createApiClient } from "@app/lib/api";
|
||||||
import {
|
import {
|
||||||
@@ -74,6 +74,8 @@ export default function LoginForm({
|
|||||||
const { env } = useEnvContext();
|
const { env } = useEnvContext();
|
||||||
const api = createApiClient({ env });
|
const api = createApiClient({ env });
|
||||||
|
|
||||||
|
const { resourceGuid } = useParams();
|
||||||
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const hasIdp = idps && idps.length > 0;
|
const hasIdp = idps && idps.length > 0;
|
||||||
@@ -235,7 +237,8 @@ export default function LoginForm({
|
|||||||
const response = await loginProxy({
|
const response = await loginProxy({
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
code
|
code,
|
||||||
|
resourceGuid: resourceGuid as string
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user