feat: per-path access lists, host logs modal, PostgreSQL support

- Per-path access lists: assign different access lists to individual
  locations on the same proxy host
- Host logs modal: view access/error logs from proxy host dropdown
- PostgreSQL JSON containment query (@>) for location regeneration
- Locale keys: action.logs, column.error
This commit is contained in:
Dimas R. Wisnu committed 2026-08-07 16:40:32 +07:00
1 parent a62c2a6dc3
commit 4a0f212289
16 files changed
+434 -78

No files matched your search

@@ -0,0 +1,8 @@
import * as api from "./base";
export async function getProxyHostLogs(id: number, type: "access" | "error" = "access"): Promise<{ logs: string }> {
return await api.get({
url: `/nginx/proxy-hosts/${id}/logs`,
params: { type },
});
}
+1
View File
@@ -27,6 +27,7 @@ export * from "./getDeadHosts";
export * from "./getHealth";
export * from "./getHostsReport";
export * from "./getProxyHost";
export * from "./getProxyHostLogs";
export * from "./getProxyHosts";
export * from "./getRedirectionHost";
export * from "./getRedirectionHosts";
+2
View File
@@ -103,6 +103,8 @@ export interface ProxyLocation {
forwardScheme: string;
forwardHost: string;
forwardPort: number;
accessListId?: number;
accessList?: AccessList;
}
export interface ProxyHost {
+5 -1
View File
@@ -31,14 +31,18 @@ interface Props {
id?: string;
name?: string;
label?: string;
onFormChange?: (value: number) => void;
}
export function AccessField({ name = "accessListId", label = "access-list", id = "accessListId" }: Props) {
export function AccessField({ name = "accessListId", label = "access-list", id = "accessListId", onFormChange }: Props) {
const { locale } = useLocaleState();
const { isLoading, isError, error, data } = useAccessLists(["owner", "items", "clients"]);
const { setFieldValue } = useFormikContext();
const handleChange = (newValue: any, _actionMeta: ActionMeta<AccessOption>) => {
setFieldValue(name, newValue?.value);
if (onFormChange) {
onFormChange(newValue?.value ?? 0);
}
};
const options: AccessOption[] =
@@ -5,6 +5,7 @@ import { useFormikContext } from "formik";
import { useState } from "react";
import type { ProxyLocation } from "src/api/backend";
import { intl, T } from "src/locale";
import { AccessField } from "./AccessField";
import styles from "./LocationsFields.module.css";
interface Props {
@@ -22,6 +23,7 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
forwardScheme: "http",
forwardHost: "",
forwardPort: 80,
accessListId: 0,
};
const toggleAdvVisible = (idx: number) => {
@@ -44,6 +46,12 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
setFormField(newValues);
};
const handleAccessListChange = (idx: number, accessListId: number) => {
const newValues = values.map((v: ProxyLocation, i: number) => (i === idx ? { ...v, accessListId } : v));
setValues(newValues);
setFormField(newValues);
};
const setFormField = (newValues: ProxyLocation[]) => {
const filtered = newValues.filter((v: ProxyLocation) => v?.path?.trim() !== "");
setFieldValue(name, filtered);
@@ -141,6 +149,12 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
</div>
</div>
</div>
<AccessField
name={`locations[${idx}].accessListId`}
label="access-list"
id={`locations-access-list-${idx}`}
onFormChange={(value) => handleAccessListChange(idx, value)}
/>
{advVisible.includes(idx) && (
<div className="">
<CodeEditor
+1
View File
@@ -11,6 +11,7 @@ export * from "./useDnsProviders";
export * from "./useHealth";
export * from "./useHostReport";
export * from "./useProxyHost";
export * from "./useProxyHostLogs";
export * from "./useProxyHosts";
export * from "./useRedirectionHost";
export * from "./useRedirectionHosts";
+12
View File
@@ -0,0 +1,12 @@
import { useQuery } from "@tanstack/react-query";
import { getProxyHostLogs } from "src/api/backend";
const useProxyHostLogs = (id: number, type: "access" | "error" = "access") => {
return useQuery<{ logs: string }, Error>({
queryKey: ["proxy-host-logs", id, type],
queryFn: () => getProxyHostLogs(id, type),
staleTime: 10_000,
});
};
export { useProxyHostLogs };
+6
View File
@@ -122,6 +122,9 @@
"action.enable": {
"defaultMessage": "Enable"
},
"action.logs": {
"defaultMessage": "Logs"
},
"action.permissions": {
"defaultMessage": "Permissions"
},
@@ -248,6 +251,9 @@
"column.access": {
"defaultMessage": "Access"
},
"column.error": {
"defaultMessage": "Error"
},
"column.authorization": {
"defaultMessage": "Authorization"
},
+93
View File
@@ -0,0 +1,93 @@
import CodeEditor from "@uiw/react-textarea-code-editor";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
import { useState } from "react";
import { Alert } from "react-bootstrap";
import Modal from "react-bootstrap/Modal";
import { Button, Loading } from "src/components";
import { useProxyHostLogs } from "src/hooks";
import { T } from "src/locale";
const showHostLogsModal = (id: number) => {
EasyModal.show(HostLogsModal, { id });
};
interface Props extends InnerModalProps {
id: number;
}
const HostLogsModal = EasyModal.create(({ id, visible, remove }: Props) => {
const [logType, setLogType] = useState<"access" | "error">("access");
const { data, isLoading, error } = useProxyHostLogs(id, logType);
return (
<Modal show={visible} onHide={remove} size="lg" scrollable>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
)}
<Modal.Header closeButton>
<Modal.Title>
<T id="action.logs" />
</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className="mb-3">
<ul className="nav nav-tabs">
<li className="nav-item">
<a
href="#"
className={`nav-link ${logType === "access" ? "active" : ""}`}
onClick={(e) => {
e.preventDefault();
setLogType("access");
}}
>
<T id="column.access" />
</a>
</li>
<li className="nav-item">
<a
href="#"
className={`nav-link ${logType === "error" ? "active" : ""}`}
onClick={(e) => {
e.preventDefault();
setLogType("error");
}}
>
<T id="column.error" />
</a>
</li>
</ul>
</div>
{isLoading ? (
<Loading noLogo />
) : (
<div style={{ maxHeight: "60vh", overflow: "auto" }}>
<CodeEditor
language="text"
padding={15}
data-color-mode="dark"
indentWidth={2}
style={{
fontFamily:
"ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace",
borderRadius: "0.3rem",
backgroundColor: "var(--tblr-bg-surface-dark)",
fontSize: "12px",
}}
readOnly
value={data?.logs || ""}
/>
</div>
)}
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={remove}>
<T id="action.close" />
</Button>
</Modal.Footer>
</Modal>
);
});
export { showHostLogsModal };
+1
View File
@@ -6,6 +6,7 @@ export * from "./DeleteConfirmModal";
export * from "./DNSCertificateModal";
export * from "./EventDetailsModal";
export * from "./HelpModal";
export * from "./HostLogsModal";
export * from "./HTTPCertificateModal";
export * from "./PermissionsModal";
export * from "./ProxyHostModal";
+20 -8
View File
@@ -1,4 +1,4 @@
import { IconDotsVertical, IconEdit, IconPower, IconTrash } from "@tabler/icons-react";
import { IconDotsVertical, IconEdit, IconFileText, IconPower, IconTrash } from "@tabler/icons-react";
import {
createColumnHelper,
getCoreRowModel,
@@ -28,9 +28,10 @@ interface Props {
onEdit?: (id: number) => void;
onDelete?: (id: number) => void;
onDisableToggle?: (id: number, enabled: boolean) => void;
onLogs?: (id: number) => void;
onNew?: () => void;
}
export default function Table({ data, isFetching, onEdit, onDelete, onDisableToggle, onNew, isFiltered }: Props) {
export default function Table({ data, isFetching, onEdit, onDelete, onDisableToggle, onLogs, onNew, isFiltered }: Props) {
const columnHelper = createColumnHelper<ProxyHost>();
const columns = useMemo(
() => [
@@ -115,19 +116,30 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
data={{ id: info.row.original.id }}
/>
</span>
<a
className="dropdown-item"
href="#"
onClick={(e) => {
e.preventDefault();
onEdit?.(info.row.original.id);
}}
>
<IconEdit size={16} />
<T id="action.edit" />
</a>
<HasPermission section={PROXY_HOSTS} permission={MANAGE} hideError>
<a
className="dropdown-item"
href="#"
onClick={(e) => {
e.preventDefault();
onEdit?.(info.row.original.id);
onLogs?.(info.row.original.id);
}}
>
<IconEdit size={16} />
<T id="action.edit" />
<IconFileText size={16} />
<T id="action.logs" />
</a>
<HasPermission section={PROXY_HOSTS} permission={MANAGE} hideError>
<a
<a
className="dropdown-item"
href="#"
onClick={(e) => {
@@ -160,7 +172,7 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
},
}),
],
[columnHelper, onEdit, onDisableToggle, onDelete],
[columnHelper, onEdit, onDisableToggle, onDelete, onLogs],
);
const [sorting, setSorting] = useState<SortingState>([]);
@@ -6,7 +6,7 @@ import { deleteProxyHost, toggleProxyHost } from "src/api/backend";
import { Button, HasPermission, LoadingPage } from "src/components";
import { useProxyHosts } from "src/hooks";
import { T } from "src/locale";
import { showDeleteConfirmModal, showHelpModal, showProxyHostModal } from "src/modals";
import { showDeleteConfirmModal, showHelpModal, showHostLogsModal, showProxyHostModal } from "src/modals";
import { MANAGE, PROXY_HOSTS } from "src/modules/Permissions";
import { showObjectSuccess } from "src/notifications";
import Table from "./Table";
@@ -99,6 +99,7 @@ export default function TableWrapper() {
isFiltered={!!search}
isFetching={isFetching}
onEdit={(id: number) => showProxyHostModal(id)}
onLogs={(id: number) => showHostLogsModal(id)}
onDelete={(id: number) => {
const host = data?.find((h) => h.id === id);
showDeleteConfirmModal({