Skip to content

Commit d0767ba

Browse files
committed
Proxy host modal basis, other improvements
1 parent abdf886 commit d0767ba

File tree

22 files changed

+667
-95
lines changed

22 files changed

+667
-95
lines changed

backend/internal/proxy-host.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ const internalProxyHost = {
422422
*/
423423
getAll: async (access, expand, searchQuery) => {
424424
const accessData = await access.can("proxy_hosts:list");
425-
426425
const query = proxyHostModel
427426
.query()
428427
.where("is_deleted", 0)
@@ -446,11 +445,9 @@ const internalProxyHost = {
446445
}
447446

448447
const rows = await query.then(utils.omitRows(omissions()));
449-
450448
if (typeof expand !== "undefined" && expand !== null && expand.indexOf("certificate") !== -1) {
451449
return internalHost.cleanAllRowsCertificateMeta(rows);
452450
}
453-
454451
return rows;
455452
},
456453

backend/lib/access.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export default function (tokenString) {
131131
const rows = await query;
132132
objects = [];
133133
_.forEach(rows, (ruleRow) => {
134-
result.push(ruleRow.id);
134+
objects.push(ruleRow.id);
135135
});
136136

137137
// enum should not have less than 1 item

frontend/src/App.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@
7070
font-family: 'Courier New', Courier, monospace !important;
7171
resize: vertical;
7272
}
73+
74+
label.row {
75+
cursor: pointer;
76+
}

frontend/src/api/backend/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface ProxyHost {
103103
modifiedOn: string;
104104
ownerUserId: number;
105105
domainNames: string[];
106+
forwardScheme: string;
106107
forwardHost: string;
107108
forwardPort: number;
108109
accessListId: number;
@@ -114,9 +115,8 @@ export interface ProxyHost {
114115
meta: Record<string, any>;
115116
allowWebsocketUpgrade: boolean;
116117
http2Support: boolean;
117-
forwardScheme: string;
118118
enabled: boolean;
119-
locations: string[]; // todo: string or object?
119+
locations?: string[]; // todo: string or object?
120120
hstsEnabled: boolean;
121121
hstsSubdomains: boolean;
122122
// Expansions:

frontend/src/components/Form/SSLOptionsFields.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ interface Props {
77
forHttp?: boolean; // the sslForced, http2Support, hstsEnabled, hstsSubdomains fields
88
forceDNSForNew?: boolean;
99
requireDomainNames?: boolean; // used for streams
10+
color?: string;
1011
}
11-
export function SSLOptionsFields({ forHttp = true, forceDNSForNew, requireDomainNames }: Props) {
12+
export function SSLOptionsFields({ forHttp = true, forceDNSForNew, requireDomainNames, color = "bg-cyan" }: Props) {
1213
const { values, setFieldValue } = useFormikContext();
1314
const v: any = values || {};
1415

@@ -31,7 +32,7 @@ export function SSLOptionsFields({ forHttp = true, forceDNSForNew, requireDomain
3132
};
3233

3334
const toggleClasses = "form-check-input";
34-
const toggleEnabled = cn(toggleClasses, "bg-cyan");
35+
const toggleEnabled = cn(toggleClasses, color);
3536

3637
const getHttpOptions = () => (
3738
<div>

frontend/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from "./useDeadHosts";
77
export * from "./useDnsProviders";
88
export * from "./useHealth";
99
export * from "./useHostReport";
10+
export * from "./useProxyHost";
1011
export * from "./useProxyHosts";
1112
export * from "./useRedirectionHost";
1213
export * from "./useRedirectionHosts";

frontend/src/hooks/useProxyHost.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2+
import { createProxyHost, getProxyHost, type ProxyHost, updateProxyHost } from "src/api/backend";
3+
4+
const fetchProxyHost = (id: number | "new") => {
5+
if (id === "new") {
6+
return Promise.resolve({
7+
id: 0,
8+
createdOn: "",
9+
modifiedOn: "",
10+
ownerUserId: 0,
11+
domainNames: [],
12+
forwardHost: "",
13+
forwardPort: 0,
14+
accessListId: 0,
15+
certificateId: 0,
16+
sslForced: false,
17+
cachingEnabled: false,
18+
blockExploits: false,
19+
advancedConfig: "",
20+
meta: {},
21+
allowWebsocketUpgrade: false,
22+
http2Support: false,
23+
forwardScheme: "",
24+
enabled: true,
25+
hstsEnabled: false,
26+
hstsSubdomains: false,
27+
} as ProxyHost);
28+
}
29+
return getProxyHost(id, ["owner"]);
30+
};
31+
32+
const useProxyHost = (id: number | "new", options = {}) => {
33+
return useQuery<ProxyHost, Error>({
34+
queryKey: ["proxy-host", id],
35+
queryFn: () => fetchProxyHost(id),
36+
staleTime: 60 * 1000, // 1 minute
37+
...options,
38+
});
39+
};
40+
41+
const useSetProxyHost = () => {
42+
const queryClient = useQueryClient();
43+
return useMutation({
44+
mutationFn: (values: ProxyHost) => (values.id ? updateProxyHost(values) : createProxyHost(values)),
45+
onMutate: (values: ProxyHost) => {
46+
if (!values.id) {
47+
return;
48+
}
49+
const previousObject = queryClient.getQueryData(["proxy-host", values.id]);
50+
queryClient.setQueryData(["proxy-host", values.id], (old: ProxyHost) => ({
51+
...old,
52+
...values,
53+
}));
54+
return () => queryClient.setQueryData(["proxy-host", values.id], previousObject);
55+
},
56+
onError: (_, __, rollback: any) => rollback(),
57+
onSuccess: async ({ id }: ProxyHost) => {
58+
queryClient.invalidateQueries({ queryKey: ["proxy-host", id] });
59+
queryClient.invalidateQueries({ queryKey: ["proxy-hosts"] });
60+
queryClient.invalidateQueries({ queryKey: ["audit-logs"] });
61+
},
62+
});
63+
};
64+
65+
export { useProxyHost, useSetProxyHost };

frontend/src/locale/lang/en.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"close": "Close",
2424
"column.access": "Access",
2525
"column.authorization": "Authorization",
26+
"column.custom-locations": "Custom Locations",
2627
"column.destination": "Destination",
2728
"column.details": "Details",
2829
"column.email": "Email",
@@ -88,9 +89,13 @@
8889
"event.updated-user": "Updated User",
8990
"footer.github-fork": "Fork me on Github",
9091
"host.flags.block-exploits": "Block Common Exploits",
92+
"host.flags.cache-assets": "Cache Assets",
9193
"host.flags.preserve-path": "Preserve Path",
9294
"host.flags.protocols": "Protocols",
9395
"host.flags.title": "Options",
96+
"host.flags.websockets-upgrade": "Websockets Support",
97+
"host.forward-port": "Forward Port",
98+
"host.forward-scheme": "Scheme",
9499
"hosts.title": "Hosts",
95100
"http-only": "HTTP Only",
96101
"lets-encrypt": "Let's Encrypt",
@@ -128,13 +133,14 @@
128133
"permissions.visibility.all": "All Items",
129134
"permissions.visibility.title": "Item Visibility",
130135
"permissions.visibility.user": "Created Items Only",
136+
"proxy-host.forward-host": "Forward Hostname / IP",
137+
"proxy-host.new": "New Proxy Host",
131138
"proxy-hosts.actions-title": "Proxy Host #{id}",
132139
"proxy-hosts.add": "Add Proxy Host",
133140
"proxy-hosts.count": "{count} Proxy Hosts",
134141
"proxy-hosts.empty": "There are no Proxy Hosts",
135142
"proxy-hosts.title": "Proxy Hosts",
136-
"redirect-host.forward-domain": "Forward Domain",
137-
"redirect-host.forward-scheme": "Scheme",
143+
"redirection-host.forward-domain": "Forward Domain",
138144
"redirection-host.new": "New Redirection Host",
139145
"redirection-hosts.actions-title": "Redirection Host #{id}",
140146
"redirection-hosts.add": "Add Redirection Host",
@@ -152,7 +158,6 @@
152158
"stream.delete.content": "Are you sure you want to delete this Stream?",
153159
"stream.delete.title": "Delete Stream",
154160
"stream.forward-host": "Forward Host",
155-
"stream.forward-port": "Forward Port",
156161
"stream.incoming-port": "Incoming Port",
157162
"stream.new": "New Stream",
158163
"streams.actions-title": "Stream #{id}",

frontend/src/locale/src/en.json

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
"column.authorization": {
7272
"defaultMessage": "Authorization"
7373
},
74+
"column.custom-locations": {
75+
"defaultMessage": "Custom Locations"
76+
},
7477
"column.destination": {
7578
"defaultMessage": "Destination"
7679
},
@@ -266,6 +269,9 @@
266269
"host.flags.block-exploits": {
267270
"defaultMessage": "Block Common Exploits"
268271
},
272+
"host.flags.cache-assets": {
273+
"defaultMessage": "Cache Assets"
274+
},
269275
"host.flags.preserve-path": {
270276
"defaultMessage": "Preserve Path"
271277
},
@@ -275,6 +281,15 @@
275281
"host.flags.title": {
276282
"defaultMessage": "Options"
277283
},
284+
"host.flags.websockets-upgrade": {
285+
"defaultMessage": "Websockets Support"
286+
},
287+
"host.forward-port": {
288+
"defaultMessage": "Forward Port"
289+
},
290+
"host.forward-scheme": {
291+
"defaultMessage": "Scheme"
292+
},
278293
"hosts.title": {
279294
"defaultMessage": "Hosts"
280295
},
@@ -386,6 +401,12 @@
386401
"permissions.visibility.user": {
387402
"defaultMessage": "Created Items Only"
388403
},
404+
"proxy-host.forward-host": {
405+
"defaultMessage": "Forward Hostname / IP"
406+
},
407+
"proxy-host.new": {
408+
"defaultMessage": "New Proxy Host"
409+
},
389410
"proxy-hosts.actions-title": {
390411
"defaultMessage": "Proxy Host #{id}"
391412
},
@@ -401,12 +422,9 @@
401422
"proxy-hosts.title": {
402423
"defaultMessage": "Proxy Hosts"
403424
},
404-
"redirect-host.forward-domain": {
425+
"redirection-host.forward-domain": {
405426
"defaultMessage": "Forward Domain"
406427
},
407-
"redirect-host.forward-scheme": {
408-
"defaultMessage": "Scheme"
409-
},
410428
"redirection-host.new": {
411429
"defaultMessage": "New Redirection Host"
412430
},
@@ -458,9 +476,6 @@
458476
"stream.forward-host": {
459477
"defaultMessage": "Forward Host"
460478
},
461-
"stream.forward-port": {
462-
"defaultMessage": "Forward Port"
463-
},
464479
"stream.incoming-port": {
465480
"defaultMessage": "Incoming Port"
466481
},

frontend/src/modals/DeadHostModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function DeadHostModal({ id, onClose }: Props) {
136136
label="ssl-certificate"
137137
allowNew
138138
/>
139-
<SSLOptionsFields />
139+
<SSLOptionsFields color="bg-red" />
140140
</div>
141141
<div className="tab-pane" id="tab-advanced" role="tabpanel">
142142
<NginxConfigField />
@@ -152,7 +152,7 @@ export function DeadHostModal({ id, onClose }: Props) {
152152
<Button
153153
type="submit"
154154
actionType="primary"
155-
className="ms-auto"
155+
className="ms-auto bg-red"
156156
data-bs-dismiss="modal"
157157
isLoading={isSubmitting}
158158
disabled={isSubmitting}

0 commit comments

Comments
 (0)