huge update.
fix issues with failing tests (I'm just gonna fucking assume directx isn't installed on the github actions machines). Added MUCH better RBAC support and control Fixed an issue when you have over a million clients RBAC would be slow asf Add settings page with some basic settings and configs you can change.
This commit is contained in:
@@ -187,6 +187,26 @@ export function unbanIp(ip: string) {
|
||||
db.run(`DELETE FROM banned_ips WHERE ip=?`, ip);
|
||||
}
|
||||
|
||||
export type BannedIpEntry = {
|
||||
ip: string;
|
||||
reason: string | null;
|
||||
createdAt: number;
|
||||
};
|
||||
|
||||
export function listBannedIps(): BannedIpEntry[] {
|
||||
const rows = db
|
||||
.query<{ ip: string; reason: string | null; createdAt: number }>(
|
||||
`SELECT ip, reason, created_at as createdAt FROM banned_ips ORDER BY created_at DESC`,
|
||||
)
|
||||
.all();
|
||||
|
||||
return rows.map((row) => ({
|
||||
ip: row.ip,
|
||||
reason: row.reason,
|
||||
createdAt: Number(row.createdAt) || 0,
|
||||
}));
|
||||
}
|
||||
|
||||
export function isIpBanned(ip: string): boolean {
|
||||
const row = db.query<{ ip: string }>(`SELECT ip FROM banned_ips WHERE ip=?`).get(ip);
|
||||
return !!row?.ip;
|
||||
@@ -198,7 +218,16 @@ export function markAllClientsOffline() {
|
||||
}
|
||||
|
||||
export function listClients(filters: ListFilters): ListResult {
|
||||
const { page, pageSize, search, sort, statusFilter, osFilter } = filters;
|
||||
const {
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
sort,
|
||||
statusFilter,
|
||||
osFilter,
|
||||
allowedClientIds,
|
||||
deniedClientIds,
|
||||
} = filters;
|
||||
const where: string[] = [];
|
||||
const params: any[] = [];
|
||||
|
||||
@@ -221,6 +250,20 @@ export function listClients(filters: ListFilters): ListResult {
|
||||
params.push(osFilter);
|
||||
}
|
||||
|
||||
if (Array.isArray(allowedClientIds)) {
|
||||
if (allowedClientIds.length === 0) {
|
||||
where.push("1=0");
|
||||
} else {
|
||||
where.push(`id IN (${allowedClientIds.map(() => "?").join(",")})`);
|
||||
params.push(...allowedClientIds);
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(deniedClientIds) && deniedClientIds.length > 0) {
|
||||
where.push(`id NOT IN (${deniedClientIds.map(() => "?").join(",")})`);
|
||||
params.push(...deniedClientIds);
|
||||
}
|
||||
|
||||
const whereSql = where.length ? `WHERE ${where.join(" AND ")}` : "";
|
||||
|
||||
const orderBy = (() => {
|
||||
@@ -242,8 +285,10 @@ export function listClients(filters: ListFilters): ListResult {
|
||||
.query<{ c: number }>(`SELECT COUNT(*) as c FROM clients ${whereSql}`)
|
||||
.get(...params) ?? { c: 0 };
|
||||
const onlineRow = db
|
||||
.query<{ c: number }>(`SELECT COUNT(*) as c FROM clients WHERE online=1`)
|
||||
.get() ?? { c: 0 };
|
||||
.query<{ c: number }>(
|
||||
`SELECT COUNT(*) as c FROM clients ${whereSql ? `${whereSql} AND online=1` : "WHERE online=1"}`,
|
||||
)
|
||||
.get(...params) ?? { c: 0 };
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
||||
const rows = db
|
||||
|
||||
Reference in New Issue
Block a user