mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-11-21 20:36:42 +00:00
feat: rate limit auth endpoints and scope user proxy host permissions
- Add in-memory sliding window rate limiter for auth token endpoints with CI/test bypass and successful request exclusion - Add user_permission meta column migration and Objection model configuration - Support scoping allowed proxy hosts per user when in 'Created Items Only' visibility mode - Restrict advanced nginx configuration editing on hosts to admin users only - Fix user permissions route ID parsing and omit id from permission update payloads - Add allowed proxy hosts selector in permissions modal and display permissions summary badges in users table
This commit is contained in:
1 parent
cc46ce5ab6
commit
bc8bbf3562
23 files changed
+571
-104
No files matched your search
@@ -16,6 +16,11 @@ export interface UserPermissions {
|
||||
streams: string;
|
||||
accessLists: string;
|
||||
certificates: string;
|
||||
meta?: {
|
||||
proxyHostIds?: number[];
|
||||
proxy_host_ids?: number[];
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
export interface User {
|
||||
|
||||
@@ -30,8 +30,9 @@ interface Row {
|
||||
interface Props {
|
||||
initialValues: ProxyLocation[];
|
||||
name?: string;
|
||||
allowAdvanced?: boolean;
|
||||
}
|
||||
export function LocationsFields({ initialValues, name = "locations" }: Props) {
|
||||
export function LocationsFields({ initialValues, name = "locations", allowAdvanced = true }: Props) {
|
||||
const [rows, setRows] = useState<Row[]>(() => (initialValues || []).map((value, id) => ({ id, value })));
|
||||
const { setFieldValue } = useFormikContext();
|
||||
const [expanded, setExpanded] = useState<number[]>([]);
|
||||
@@ -217,7 +218,7 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
|
||||
{isOpen && (
|
||||
<div className="card-body" id={bodyId}>
|
||||
<div className="row">
|
||||
<div className="col-md-10">
|
||||
<div className={allowAdvanced ? "col-md-10" : "col-md-12"}>
|
||||
<div className="input-group mb-3">
|
||||
<span className="input-group-text">Location</span>
|
||||
<input
|
||||
@@ -230,23 +231,25 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-2 text-end">
|
||||
<button
|
||||
type="button"
|
||||
className="btn p-0"
|
||||
title="Advanced"
|
||||
aria-expanded={advVisible.includes(row.id)}
|
||||
onClick={() => toggleAdvVisible(row.id)}
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</button>
|
||||
</div>
|
||||
{allowAdvanced && (
|
||||
<div className="col-md-2 text-end">
|
||||
<button
|
||||
type="button"
|
||||
className="btn p-0"
|
||||
title="Advanced"
|
||||
aria-expanded={advVisible.includes(row.id)}
|
||||
onClick={() => toggleAdvVisible(row.id)}
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="row">
|
||||
<div className="col-md-3">
|
||||
<div className="col-sm-3 col-md-3">
|
||||
<div className="mb-3">
|
||||
<label
|
||||
className="form-label"
|
||||
className="form-label text-nowrap"
|
||||
htmlFor={`location-forwardScheme-${row.id}`}
|
||||
>
|
||||
<T id="host.forward-scheme" />
|
||||
@@ -264,10 +267,10 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<div className="col-sm-5 col-md-5">
|
||||
<div className="mb-3">
|
||||
<label
|
||||
className="form-label"
|
||||
className="form-label text-nowrap"
|
||||
htmlFor={`location-forwardHost-${row.id}`}
|
||||
>
|
||||
<T id="proxy-host.forward-host" />
|
||||
@@ -285,10 +288,10 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<div className="col-sm-4 col-md-4">
|
||||
<div className="mb-3">
|
||||
<label
|
||||
className="form-label"
|
||||
className="form-label text-nowrap"
|
||||
htmlFor={`location-forwardPort-${row.id}`}
|
||||
>
|
||||
<T id="host.forward-port" />
|
||||
@@ -316,7 +319,7 @@ export function LocationsFields({ initialValues, name = "locations" }: Props) {
|
||||
onFormChange={(value) => handleAccessListChange(row.id, value)}
|
||||
inheritHost
|
||||
/>
|
||||
{advVisible.includes(row.id) && (
|
||||
{allowAdvanced && advVisible.includes(row.id) && (
|
||||
<div className="">
|
||||
<CodeEditor
|
||||
language="nginx"
|
||||
|
||||
@@ -644,12 +644,21 @@
|
||||
"password.show": {
|
||||
"defaultMessage": "Show Password"
|
||||
},
|
||||
"permissions.allowed-proxy-hosts": {
|
||||
"defaultMessage": "Allowed Proxy Hosts"
|
||||
},
|
||||
"permissions.allowed-proxy-hosts-help": {
|
||||
"defaultMessage": "Grants additional access to selected proxy hosts created by other users (in addition to the user's own created hosts)."
|
||||
},
|
||||
"permissions.hidden": {
|
||||
"defaultMessage": "Hidden"
|
||||
},
|
||||
"permissions.manage": {
|
||||
"defaultMessage": "Manage"
|
||||
},
|
||||
"permissions.no-proxy-hosts": {
|
||||
"defaultMessage": "No proxy hosts found"
|
||||
},
|
||||
"permissions.view": {
|
||||
"defaultMessage": "View Only"
|
||||
},
|
||||
|
||||
@@ -644,12 +644,21 @@
|
||||
"password.show": {
|
||||
"defaultMessage": "Näita parooli"
|
||||
},
|
||||
"permissions.allowed-proxy-hosts": {
|
||||
"defaultMessage": "Lubatud puhverserverid"
|
||||
},
|
||||
"permissions.allowed-proxy-hosts-help": {
|
||||
"defaultMessage": "Annab täiendava ligipääsu teiste kasutajate loodud valitud puhverserveritele (lisaks kasutaja enda loodud kirjetele)."
|
||||
},
|
||||
"permissions.hidden": {
|
||||
"defaultMessage": "Peidetud"
|
||||
},
|
||||
"permissions.manage": {
|
||||
"defaultMessage": "Halda"
|
||||
},
|
||||
"permissions.no-proxy-hosts": {
|
||||
"defaultMessage": "Ühtegi puhverserverit ei leitud"
|
||||
},
|
||||
"permissions.view": {
|
||||
"defaultMessage": "Ainult vaatamine"
|
||||
},
|
||||
|
||||
@@ -437,6 +437,9 @@
|
||||
"footer.github-fork": {
|
||||
"defaultMessage": "Fork dự án này trên Github"
|
||||
},
|
||||
"form.unsaved-changes": {
|
||||
"defaultMessage": "Bạn có các thay đổi chưa được lưu. Bạn có chắc chắn muốn hủy bỏ chúng không?"
|
||||
},
|
||||
"host.flags.block-exploits": {
|
||||
"defaultMessage": "Chặn các hoạt động khai thác phổ biến"
|
||||
},
|
||||
@@ -641,12 +644,21 @@
|
||||
"password.show": {
|
||||
"defaultMessage": "Hiện mật khẩu"
|
||||
},
|
||||
"permissions.allowed-proxy-hosts": {
|
||||
"defaultMessage": "Máy chủ proxy được phép"
|
||||
},
|
||||
"permissions.allowed-proxy-hosts-help": {
|
||||
"defaultMessage": "Cấp thêm quyền truy cập vào các máy chủ proxy đã chọn do người dùng khác tạo (ngoài các mục do chính người dùng tạo)."
|
||||
},
|
||||
"permissions.hidden": {
|
||||
"defaultMessage": "Ẩn"
|
||||
},
|
||||
"permissions.manage": {
|
||||
"defaultMessage": "Quản lý"
|
||||
},
|
||||
"permissions.no-proxy-hosts": {
|
||||
"defaultMessage": "Không tìm thấy máy chủ proxy nào"
|
||||
},
|
||||
"permissions.view": {
|
||||
"defaultMessage": "Chỉ xem"
|
||||
},
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
SSLOptionsFields,
|
||||
} from "src/components";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { useDeadHost, useSetDeadHost } from "src/hooks";
|
||||
import { useDeadHost, useSetDeadHost, useUser } from "src/hooks";
|
||||
import { T } from "src/locale";
|
||||
import { showObjectSuccess } from "src/notifications";
|
||||
|
||||
@@ -25,11 +25,14 @@ interface Props extends InnerModalProps {
|
||||
id: number | "new";
|
||||
}
|
||||
const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
const { data: currentUser } = useUser("me");
|
||||
const { data, isLoading, error } = useDeadHost(id);
|
||||
const { mutate: setDeadHost } = useSetDeadHost();
|
||||
const [errorMsg, setErrorMsg] = useState<ReactNode | null>(null);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const isAdmin = currentUser?.roles?.includes("admin");
|
||||
|
||||
const onSubmit = async (values: any, { setSubmitting }: any) => {
|
||||
if (isSubmitting) return;
|
||||
setIsSubmitting(true);
|
||||
@@ -40,6 +43,11 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
...values,
|
||||
};
|
||||
|
||||
if (!isAdmin) {
|
||||
delete payload.advanced_config;
|
||||
delete payload.advancedConfig;
|
||||
}
|
||||
|
||||
setDeadHost(payload, {
|
||||
onError: (err: any) => setErrorMsg(<T id={err.message} />),
|
||||
onSuccess: () => {
|
||||
@@ -121,19 +129,21 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
<T id="column.ssl" />
|
||||
</a>
|
||||
</li>
|
||||
<li className="nav-item ms-auto" role="presentation">
|
||||
<a
|
||||
href="#tab-advanced"
|
||||
className="nav-link"
|
||||
title="Settings"
|
||||
data-bs-toggle="tab"
|
||||
aria-selected="false"
|
||||
tabIndex={-1}
|
||||
role="tab"
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</a>
|
||||
</li>
|
||||
{isAdmin && (
|
||||
<li className="nav-item ms-auto" role="presentation">
|
||||
<a
|
||||
href="#tab-advanced"
|
||||
className="nav-link"
|
||||
title="Settings"
|
||||
data-bs-toggle="tab"
|
||||
aria-selected="false"
|
||||
tabIndex={-1}
|
||||
role="tab"
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</a>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
@@ -149,9 +159,11 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
/>
|
||||
<SSLOptionsFields color="bg-red" />
|
||||
</div>
|
||||
<div className="tab-pane" id="tab-advanced" role="tabpanel">
|
||||
<NginxConfigField />
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<div className="tab-pane" id="tab-advanced" role="tabpanel">
|
||||
<NginxConfigField />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@ import Modal from "react-bootstrap/Modal";
|
||||
import { setPermissions } from "src/api/backend";
|
||||
import { Button, Loading } from "src/components";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { useUser } from "src/hooks";
|
||||
import { useProxyHosts, useUser } from "src/hooks";
|
||||
import { T } from "src/locale";
|
||||
import styles from "./PermissionsModal.module.css";
|
||||
|
||||
@@ -23,6 +23,7 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
const queryClient = useQueryClient();
|
||||
const [errorMsg, setErrorMsg] = useState<ReactNode | null>(null);
|
||||
const { data, isLoading, error } = useUser(id);
|
||||
const { data: proxyHosts } = useProxyHosts();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const onSubmit = async (values: any, { setSubmitting }: any) => {
|
||||
@@ -152,18 +153,24 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
preventHide={isSubmitting}
|
||||
initialValues={
|
||||
{
|
||||
visibility: data.permissions?.visibility,
|
||||
accessLists: data.permissions?.accessLists,
|
||||
certificates: data.permissions?.certificates,
|
||||
deadHosts: data.permissions?.deadHosts,
|
||||
proxyHosts: data.permissions?.proxyHosts,
|
||||
redirectionHosts: data.permissions?.redirectionHosts,
|
||||
streams: data.permissions?.streams,
|
||||
visibility: data.permissions?.visibility || "user",
|
||||
accessLists: data.permissions?.accessLists || "hidden",
|
||||
certificates: data.permissions?.certificates || "hidden",
|
||||
deadHosts: data.permissions?.deadHosts || "hidden",
|
||||
proxyHosts: data.permissions?.proxyHosts || "hidden",
|
||||
redirectionHosts: data.permissions?.redirectionHosts || "hidden",
|
||||
streams: data.permissions?.streams || "hidden",
|
||||
meta: {
|
||||
proxy_host_ids:
|
||||
data.permissions?.meta?.proxyHostIds ||
|
||||
data.permissions?.meta?.proxy_host_ids ||
|
||||
[],
|
||||
},
|
||||
} as any
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{({ onHide }) => (
|
||||
{({ values, setFieldValue, onHide }: any) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -227,6 +234,71 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
{({ field, form }: any) => getPermissionButtons(field, form)}
|
||||
</Field>
|
||||
</div>
|
||||
{values.visibility === "user" && values.proxyHosts !== "hidden" && (
|
||||
<div className="mb-3 ps-3 border-start border-2 border-primary">
|
||||
<label htmlFor="ignored-allowed-hosts" className="form-label mb-1">
|
||||
<T id="permissions.allowed-proxy-hosts" />
|
||||
</label>
|
||||
<div className="text-secondary small mb-2">
|
||||
<T id="permissions.allowed-proxy-hosts-help" />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "180px",
|
||||
overflowY: "auto",
|
||||
border: "1px solid var(--tblr-border-color, #e6e7e9)",
|
||||
borderRadius: "4px",
|
||||
padding: "8px",
|
||||
backgroundColor: "var(--tblr-bg-surface-secondary, #f8fafc)",
|
||||
}}
|
||||
>
|
||||
{proxyHosts && proxyHosts.length > 0 ? (
|
||||
proxyHosts.map((host) => {
|
||||
const selectedIds: number[] =
|
||||
values.meta?.proxy_host_ids || [];
|
||||
const isChecked = selectedIds.includes(host.id);
|
||||
return (
|
||||
<div key={host.id} className="form-check mb-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="form-check-input"
|
||||
id={`perm-proxy-host-${host.id}`}
|
||||
checked={isChecked}
|
||||
onChange={(e) => {
|
||||
const newIds = e.target.checked
|
||||
? [...selectedIds, host.id]
|
||||
: selectedIds.filter(
|
||||
(hId) => hId !== host.id,
|
||||
);
|
||||
setFieldValue(
|
||||
"meta.proxy_host_ids",
|
||||
newIds,
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<label
|
||||
className="form-check-label user-select-none"
|
||||
htmlFor={`perm-proxy-host-${host.id}`}
|
||||
>
|
||||
<span className="fw-semibold">
|
||||
{host.domainNames?.join(", ")}
|
||||
</span>
|
||||
<span className="text-secondary small ms-2">
|
||||
→ {host.forwardScheme}://
|
||||
{host.forwardHost}:{host.forwardPort}
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<div className="text-secondary small">
|
||||
<T id="permissions.no-proxy-hosts" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="mb-3">
|
||||
<label htmlFor="ignored" className="form-label">
|
||||
<T id="redirection-hosts" />
|
||||
|
||||
@@ -37,6 +37,8 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
const [errorMsg, setErrorMsg] = useState<ReactNode | null>(null);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const isAdmin = currentUser?.roles?.includes("admin");
|
||||
|
||||
const onSubmit = async (values: any, { setSubmitting }: any) => {
|
||||
if (isSubmitting) return;
|
||||
setIsSubmitting(true);
|
||||
@@ -48,6 +50,19 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
};
|
||||
payload.locations = (values.locations || []).filter((location: any) => location.path?.trim() !== "");
|
||||
|
||||
if (!isAdmin) {
|
||||
delete payload.advanced_config;
|
||||
delete payload.advancedConfig;
|
||||
const existingLocations = data?.locations || [];
|
||||
payload.locations = payload.locations.map((loc: any) => {
|
||||
const existingLoc = existingLocations.find((l: any) => l.path === loc.path);
|
||||
return {
|
||||
...loc,
|
||||
advancedConfig: existingLoc?.advancedConfig || "",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
setProxyHost(payload, {
|
||||
onError: (err: any) => setErrorMsg(<T id={err.message} />),
|
||||
onSuccess: () => {
|
||||
@@ -154,19 +169,21 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
<T id="column.ssl" />
|
||||
</a>
|
||||
</li>
|
||||
<li className="nav-item ms-auto" role="presentation">
|
||||
<a
|
||||
href="#tab-advanced"
|
||||
className="nav-link"
|
||||
title="Settings"
|
||||
data-bs-toggle="tab"
|
||||
aria-selected="false"
|
||||
tabIndex={-1}
|
||||
role="tab"
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</a>
|
||||
</li>
|
||||
{isAdmin && (
|
||||
<li className="nav-item ms-auto" role="presentation">
|
||||
<a
|
||||
href="#tab-advanced"
|
||||
className="nav-link"
|
||||
title="Settings"
|
||||
data-bs-toggle="tab"
|
||||
aria-selected="false"
|
||||
tabIndex={-1}
|
||||
role="tab"
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</a>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
@@ -174,12 +191,12 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
<div className="tab-pane active show" id="tab-details" role="tabpanel">
|
||||
<DomainNamesField isWildcardPermitted dnsProviderWildcardSupported />
|
||||
<div className="row">
|
||||
<div className="col-md-3">
|
||||
<div className="col-sm-3 col-md-3">
|
||||
<Field name="forwardScheme">
|
||||
{({ field, form }: any) => (
|
||||
<div className="mb-3">
|
||||
<label
|
||||
className="form-label"
|
||||
className="form-label text-nowrap"
|
||||
htmlFor="forwardScheme"
|
||||
>
|
||||
<T id="host.forward-scheme" />
|
||||
@@ -205,11 +222,14 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
</Field>
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<div className="col-sm-5 col-md-5">
|
||||
<Field name="forwardHost" validate={validateString(1, 255)}>
|
||||
{({ field, form }: any) => (
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="forwardHost">
|
||||
<label
|
||||
className="form-label text-nowrap"
|
||||
htmlFor="forwardHost"
|
||||
>
|
||||
<T id="proxy-host.forward-host" />
|
||||
</label>
|
||||
<input
|
||||
@@ -232,11 +252,14 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
</Field>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<div className="col-sm-4 col-md-4">
|
||||
<Field name="forwardPort" validate={validateNumber(1, 65535)}>
|
||||
{({ field, form }: any) => (
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="forwardPort">
|
||||
<label
|
||||
className="form-label text-nowrap"
|
||||
htmlFor="forwardPort"
|
||||
>
|
||||
<T id="host.forward-port" />
|
||||
</label>
|
||||
<input
|
||||
@@ -341,7 +364,10 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</div>
|
||||
</div>
|
||||
<div className="tab-pane" id="tab-locations" role="tabpanel">
|
||||
<LocationsFields initialValues={data?.locations || []} />
|
||||
<LocationsFields
|
||||
initialValues={data?.locations || []}
|
||||
allowAdvanced={!!isAdmin}
|
||||
/>
|
||||
</div>
|
||||
<div className="tab-pane" id="tab-ssl" role="tabpanel">
|
||||
<SSLCertificateField
|
||||
@@ -351,9 +377,11 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
/>
|
||||
<SSLOptionsFields color="bg-lime" forProxyHost={true} />
|
||||
</div>
|
||||
<div className="tab-pane" id="tab-advanced" role="tabpanel">
|
||||
<NginxConfigField />
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<div className="tab-pane" id="tab-advanced" role="tabpanel">
|
||||
<NginxConfigField />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
SSLOptionsFields,
|
||||
} from "src/components";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { useRedirectionHost, useSetRedirectionHost } from "src/hooks";
|
||||
import { useRedirectionHost, useSetRedirectionHost, useUser } from "src/hooks";
|
||||
import { T } from "src/locale";
|
||||
import { validateString } from "src/modules/Validations";
|
||||
import { showObjectSuccess } from "src/notifications";
|
||||
@@ -27,11 +27,14 @@ interface Props extends InnerModalProps {
|
||||
id: number | "new";
|
||||
}
|
||||
const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
const { data: currentUser } = useUser("me");
|
||||
const { data, isLoading, error } = useRedirectionHost(id);
|
||||
const { mutate: setRedirectionHost } = useSetRedirectionHost();
|
||||
const [errorMsg, setErrorMsg] = useState<ReactNode | null>(null);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const isAdmin = currentUser?.roles?.includes("admin");
|
||||
|
||||
const onSubmit = async (values: any, { setSubmitting }: any) => {
|
||||
if (isSubmitting) return;
|
||||
setIsSubmitting(true);
|
||||
@@ -42,6 +45,11 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
...values,
|
||||
};
|
||||
|
||||
if (!isAdmin) {
|
||||
delete payload.advanced_config;
|
||||
delete payload.advancedConfig;
|
||||
}
|
||||
|
||||
setRedirectionHost(payload, {
|
||||
onError: (err: any) => setErrorMsg(<T id={err.message} />),
|
||||
onSuccess: () => {
|
||||
@@ -134,19 +142,21 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
<T id="column.ssl" />
|
||||
</a>
|
||||
</li>
|
||||
<li className="nav-item ms-auto" role="presentation">
|
||||
<a
|
||||
href="#tab-advanced"
|
||||
className="nav-link"
|
||||
title="Settings"
|
||||
data-bs-toggle="tab"
|
||||
aria-selected="false"
|
||||
tabIndex={-1}
|
||||
role="tab"
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</a>
|
||||
</li>
|
||||
{isAdmin && (
|
||||
<li className="nav-item ms-auto" role="presentation">
|
||||
<a
|
||||
href="#tab-advanced"
|
||||
className="nav-link"
|
||||
title="Settings"
|
||||
data-bs-toggle="tab"
|
||||
aria-selected="false"
|
||||
tabIndex={-1}
|
||||
role="tab"
|
||||
>
|
||||
<IconSettings size={20} />
|
||||
</a>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
@@ -326,9 +336,11 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
/>
|
||||
<SSLOptionsFields color="bg-yellow" />
|
||||
</div>
|
||||
<div className="tab-pane" id="tab-advanced" role="tabpanel">
|
||||
<NginxConfigField />
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<div className="tab-pane" id="tab-advanced" role="tabpanel">
|
||||
<NginxConfigField />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -90,6 +90,49 @@ export default function Table({
|
||||
return <RolesFormatter roles={info.getValue()} />;
|
||||
},
|
||||
}),
|
||||
columnHelper.accessor((row: any) => row.permissions, {
|
||||
id: "permissions",
|
||||
header: intl.formatMessage({ id: "action.permissions" }),
|
||||
cell: (info: any) => {
|
||||
const permissions = info.getValue();
|
||||
const isAdminUser = info.row.original.roles?.includes("admin");
|
||||
if (isAdminUser) {
|
||||
return (
|
||||
<span className="badge bg-green-lt">
|
||||
<T id="column.satisfy-all" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (!permissions) {
|
||||
return <span className="text-muted">-</span>;
|
||||
}
|
||||
const items = [
|
||||
{ key: "proxyHosts", label: "proxy-hosts", val: permissions.proxyHosts },
|
||||
{ key: "redirectionHosts", label: "redirection-hosts", val: permissions.redirectionHosts },
|
||||
{ key: "deadHosts", label: "dead-hosts", val: permissions.deadHosts },
|
||||
{ key: "streams", label: "streams", val: permissions.streams },
|
||||
{ key: "accessLists", label: "access-lists", val: permissions.accessLists },
|
||||
{ key: "certificates", label: "certificates", val: permissions.certificates },
|
||||
];
|
||||
return (
|
||||
<div className="d-flex flex-wrap gap-1">
|
||||
{items.map((it) => {
|
||||
if (it.val === "hidden") return null;
|
||||
const isManage = it.val === "manage";
|
||||
return (
|
||||
<span
|
||||
key={it.key}
|
||||
className={`badge ${isManage ? "bg-blue-lt" : "bg-secondary-lt"}`}
|
||||
title={`${intl.formatMessage({ id: it.label })}: ${it.val}`}
|
||||
>
|
||||
<T id={it.label} />: {it.val}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
}),
|
||||
columnHelper.accessor((row: any) => row.isDisabled, {
|
||||
id: "isDisabled",
|
||||
header: intl.formatMessage({ id: "column.status" }),
|
||||
|
||||
Reference in new issue
Block a user