Skip to content

Commit e36c1b9

Browse files
committed
Redirection hosts ui
1 parent 9339626 commit e36c1b9

File tree

14 files changed

+626
-71
lines changed

14 files changed

+626
-71
lines changed

frontend/src/api/backend/getRedirectionHost.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as api from "./base";
22
import type { HostExpansion } from "./expansions";
3-
import type { ProxyHost } from "./models";
3+
import type { RedirectionHost } from "./models";
44

5-
export async function getRedirectionHost(id: number, expand?: HostExpansion[], params = {}): Promise<ProxyHost> {
5+
export async function getRedirectionHost(id: number, expand?: HostExpansion[], params = {}): Promise<RedirectionHost> {
66
return await api.get({
77
url: `/nginx/redirection-hosts/${id}`,
88
params: {

frontend/src/components/Table/Formatter/EventFormatter.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IconBoltOff, IconDisc, IconUser } from "@tabler/icons-react";
1+
import { IconArrowsCross, IconBolt, IconBoltOff, IconDisc, IconUser } from "@tabler/icons-react";
22
import type { AuditLog } from "src/api/backend";
33
import { DateTimeFormat, intl } from "src/locale";
44

@@ -10,6 +10,8 @@ const getEventValue = (event: AuditLog) => {
1010
switch (event.objectType) {
1111
case "user":
1212
return event.meta?.name;
13+
case "proxy-host":
14+
case "redirection-host":
1315
case "dead-host":
1416
return event.meta?.domainNames?.join(", ") || "N/A";
1517
case "stream":
@@ -37,6 +39,12 @@ const getIcon = (row: AuditLog) => {
3739
case "user":
3840
ico = <IconUser size={16} className={c} />;
3941
break;
42+
case "proxy-host":
43+
ico = <IconBolt size={16} className={c} />;
44+
break;
45+
case "redirection-host":
46+
ico = <IconArrowsCross size={16} className={c} />;
47+
break;
4048
case "dead-host":
4149
ico = <IconBoltOff size={16} className={c} />;
4250
break;

frontend/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from "./useDnsProviders";
88
export * from "./useHealth";
99
export * from "./useHostReport";
1010
export * from "./useProxyHosts";
11+
export * from "./useRedirectionHost";
1112
export * from "./useRedirectionHosts";
1213
export * from "./useStream";
1314
export * from "./useStreams";
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2+
import {
3+
createRedirectionHost,
4+
getRedirectionHost,
5+
type RedirectionHost,
6+
updateRedirectionHost,
7+
} from "src/api/backend";
8+
9+
const fetchRedirectionHost = (id: number | "new") => {
10+
if (id === "new") {
11+
return Promise.resolve({
12+
id: 0,
13+
createdOn: "",
14+
modifiedOn: "",
15+
ownerUserId: 0,
16+
domainNames: [],
17+
forwardDomainName: "",
18+
preservePath: false,
19+
certificateId: 0,
20+
sslForced: false,
21+
advancedConfig: "",
22+
meta: {},
23+
http2Support: false,
24+
forwardScheme: "auto",
25+
forwardHttpCode: 301,
26+
blockExploits: false,
27+
enabled: true,
28+
hstsEnabled: false,
29+
hstsSubdomains: false,
30+
} as RedirectionHost);
31+
}
32+
return getRedirectionHost(id, ["owner"]);
33+
};
34+
35+
const useRedirectionHost = (id: number | "new", options = {}) => {
36+
return useQuery<RedirectionHost, Error>({
37+
queryKey: ["redirection-host", id],
38+
queryFn: () => fetchRedirectionHost(id),
39+
staleTime: 60 * 1000, // 1 minute
40+
...options,
41+
});
42+
};
43+
44+
const useSetRedirectionHost = () => {
45+
const queryClient = useQueryClient();
46+
return useMutation({
47+
mutationFn: (values: RedirectionHost) =>
48+
values.id ? updateRedirectionHost(values) : createRedirectionHost(values),
49+
onMutate: (values: RedirectionHost) => {
50+
if (!values.id) {
51+
return;
52+
}
53+
const previousObject = queryClient.getQueryData(["redirection-host", values.id]);
54+
queryClient.setQueryData(["redirection-host", values.id], (old: RedirectionHost) => ({
55+
...old,
56+
...values,
57+
}));
58+
return () => queryClient.setQueryData(["redirection-host", values.id], previousObject);
59+
},
60+
onError: (_, __, rollback: any) => rollback(),
61+
onSuccess: async ({ id }: RedirectionHost) => {
62+
queryClient.invalidateQueries({ queryKey: ["redirection-host", id] });
63+
queryClient.invalidateQueries({ queryKey: ["redirection-hosts"] });
64+
queryClient.invalidateQueries({ queryKey: ["audit-logs"] });
65+
},
66+
});
67+
};
68+
69+
export { useRedirectionHost, useSetRedirectionHost };

frontend/src/locale/lang/en.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,25 @@
7272
"error.passwords-must-match": "Passwords must match",
7373
"error.required": "This is required",
7474
"event.created-dead-host": "Created 404 Host",
75+
"event.created-redirection-host": "Created Redirection Host",
7576
"event.created-stream": "Created Stream",
7677
"event.created-user": "Created User",
7778
"event.deleted-dead-host": "Deleted 404 Host",
7879
"event.deleted-stream": "Deleted Stream",
7980
"event.deleted-user": "Deleted User",
8081
"event.disabled-dead-host": "Disabled 404 Host",
82+
"event.disabled-redirection-host": "Disabled Redirection Host",
8183
"event.disabled-stream": "Disabled Stream",
8284
"event.enabled-dead-host": "Enabled 404 Host",
85+
"event.enabled-redirection-host": "Enabled Redirection Host",
8386
"event.enabled-stream": "Enabled Stream",
87+
"event.updated-redirection-host": "Updated Redirection Host",
8488
"event.updated-user": "Updated User",
8589
"footer.github-fork": "Fork me on Github",
90+
"host.flags.block-exploits": "Block Common Exploits",
91+
"host.flags.preserve-path": "Preserve Path",
92+
"host.flags.protocols": "Protocols",
93+
"host.flags.title": "Options",
8694
"hosts.title": "Hosts",
8795
"http-only": "HTTP Only",
8896
"lets-encrypt": "Let's Encrypt",
@@ -99,6 +107,7 @@
99107
"notification.host-deleted": "Host has been deleted",
100108
"notification.host-disabled": "Host has been disabled",
101109
"notification.host-enabled": "Host has been enabled",
110+
"notification.redirection-host-saved": "Redirection Host has been saved",
102111
"notification.stream-deleted": "Stream has been deleted",
103112
"notification.stream-disabled": "Stream has been disabled",
104113
"notification.stream-enabled": "Stream has been enabled",
@@ -124,6 +133,9 @@
124133
"proxy-hosts.count": "{count} Proxy Hosts",
125134
"proxy-hosts.empty": "There are no Proxy Hosts",
126135
"proxy-hosts.title": "Proxy Hosts",
136+
"redirect-host.forward-domain": "Forward Domain",
137+
"redirect-host.forward-scheme": "Scheme",
138+
"redirection-host.new": "New Redirection Host",
127139
"redirection-hosts.actions-title": "Redirection Host #{id}",
128140
"redirection-hosts.add": "Add Redirection Host",
129141
"redirection-hosts.count": "{count} Redirection Hosts",

frontend/src/locale/src/en.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@
215215
"event.created-dead-host": {
216216
"defaultMessage": "Created 404 Host"
217217
},
218+
"event.created-redirection-host": {
219+
"defaultMessage": "Created Redirection Host"
220+
},
221+
"event.updated-redirection-host": {
222+
"defaultMessage": "Updated Redirection Host"
223+
},
224+
"event.enabled-redirection-host": {
225+
"defaultMessage": "Enabled Redirection Host"
226+
},
227+
"event.disabled-redirection-host": {
228+
"defaultMessage": "Disabled Redirection Host"
229+
},
218230
"event.created-stream": {
219231
"defaultMessage": "Created Stream"
220232
},
@@ -251,6 +263,18 @@
251263
"empty-subtitle": {
252264
"defaultMessage": "Why don't you create one?"
253265
},
266+
"host.flags.title": {
267+
"defaultMessage": "Options"
268+
},
269+
"host.flags.block-exploits": {
270+
"defaultMessage": "Block Common Exploits"
271+
},
272+
"host.flags.preserve-path": {
273+
"defaultMessage": "Preserve Path"
274+
},
275+
"host.flags.protocols": {
276+
"defaultMessage": "Protocols"
277+
},
254278
"hosts.title": {
255279
"defaultMessage": "Hosts"
256280
},
@@ -299,6 +323,9 @@
299323
"notification.host-enabled": {
300324
"defaultMessage": "Host has been enabled"
301325
},
326+
"notification.redirection-host-saved": {
327+
"defaultMessage": "Redirection Host has been saved"
328+
},
302329
"notification.stream-deleted": {
303330
"defaultMessage": "Stream has been deleted"
304331
},
@@ -374,6 +401,12 @@
374401
"proxy-hosts.title": {
375402
"defaultMessage": "Proxy Hosts"
376403
},
404+
"redirect-host.forward-scheme": {
405+
"defaultMessage": "Scheme"
406+
},
407+
"redirect-host.forward-domain": {
408+
"defaultMessage": "Forward Domain"
409+
},
377410
"redirection-hosts.actions-title": {
378411
"defaultMessage": "Redirection Host #{id}"
379412
},
@@ -386,6 +419,9 @@
386419
"redirection-hosts.empty": {
387420
"defaultMessage": "There are no Redirection Hosts"
388421
},
422+
"redirection-host.new": {
423+
"defaultMessage": "New Redirection Host"
424+
},
389425
"redirection-hosts.title": {
390426
"defaultMessage": "Redirection Hosts"
391427
},

0 commit comments

Comments
 (0)