/
Config.tsx
354 lines (325 loc) · 11.5 KB
/
Config.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import { Button } from "@material-ui/core";
import Box from "@material-ui/core/Box/Box";
import Step from "@material-ui/core/Step";
import StepContent from "@material-ui/core/StepContent";
import StepLabel from "@material-ui/core/StepLabel";
import Stepper from "@material-ui/core/Stepper";
import { Alert, AlertTitle } from "@material-ui/lab";
import { createCertificateAction } from "actions/certificate";
import { BasePage } from "pages/BasePage";
import { CertStatus } from "pages/Domains/CertStatus";
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { useRouteMatch } from "react-router-dom";
import { RootState } from "reducers";
import { Certificate, issuerManaged } from "types/certificate";
import { DNSConfigItems } from "widgets/ACMEServer";
import { CodeBlock } from "widgets/CodeBlock";
import { CollapseWrapper } from "widgets/CollapseWrapper";
import { KPanel } from "widgets/KPanel";
import { Body2, Subtitle1 } from "widgets/Label";
import { Loading } from "widgets/Loading";
import { TextAndCopyButton } from "widgets/TextAndCopyButton";
import { Link } from "react-router-dom";
interface StepOption {
title: string;
content: React.ReactNode;
completed: boolean;
isActive?: boolean;
}
const DomainConfigPageRaw: React.FC = () => {
const dispatch = useDispatch();
const { domains, isLoading, isFirstLoaded, certificates, acmeServer } = useSelector((state: RootState) => {
return {
isLoading: state.domains.isLoading,
isFirstLoaded: state.domains.isFirstLoaded,
domains: state.domains.domains,
certificates: state.certificates.certificates,
acmeServer: state.certificates.acmeServer,
};
});
const router = useRouteMatch<{ name: string }>();
const domain = domains.find((x) => x.name === router.params.name);
if (isLoading && !isFirstLoaded) {
return <Loading />;
}
if (!domain) {
return <Box p={2}>no such domain</Box>;
}
const isWildcard = domain.domain.startsWith("*");
let cert: Certificate | undefined;
cert = certificates.find((x) => x.domains.length === 1 && x.domains[0] === domain.domain);
if (!cert) {
cert = certificates.find((x) => !!x.domains.find((y) => y === domain.domain));
}
const renderHelper = (domain: string, type: string, target: string, proxyWarning: boolean = false) => {
return (
<CollapseWrapper title="How to check if I have configured the record correctly">
<Box mt={2}>
{proxyWarning && (
<Alert severity="info">
If you use an additional proxy when configuring domain name resolution (for example, using Cloudflare and
record proxy is turned on), the following debug steps may not get the corresponding dns resolution
results. As long as you configure it correctly, traffic can still reach your cluster.
</Alert>
)}
<p>Dig the your domain by executing following command in a terminal.</p>
<Box ml={2}>
<CodeBlock>
{type === "TXT" ? (
<TextAndCopyButton text={`dig -t txt @8.8.8.8 "${domain}"`} />
) : (
<TextAndCopyButton text={`dig @8.8.8.8 "${domain}"`} />
)}
</CodeBlock>
<p>
if you can find a <strong>{type}</strong> record in "ANSWER SECTION" with a value of{" "}
<strong>{target}</strong>, it means your DNS is added. The status will turn to "Normal" soon.
</p>
<p>
Otherwise, your record is not working yet due to cache or misconfigured. Please check your DNS provider
config.
</p>
</Box>
</Box>
</CollapseWrapper>
);
};
const step1: StepOption = {
title: "Open your domain DNS config panel",
content: <Box>Log in to your registrar account, and navigate to DNS config panel.</Box>,
completed: cert?.ready === "True",
};
const steps: StepOption[] = [step1];
const normalDomainNoCertStep = (): StepOption => {
return {
title: `Generate certificate`,
content: (
<Box mt={2}>
<Alert severity="info">Please first ensure that the DNS records above are configured correctly</Alert>
<Box mt={2}>
<Button
variant="outlined"
color="primary"
size="small"
onClick={() => {
dispatch(
createCertificateAction(
{
managedType: issuerManaged,
domains: [domain.domain],
name: "",
selfManagedCertContent: "",
selfManagedCertPrivateKey: "",
},
false,
),
);
}}
>
GENERATE CERTIFICATE
</Button>
</Box>
</Box>
),
completed: false,
};
};
const wildcardCertificateNoCertStep = (): StepOption => {
return {
title: `Generate certificate`,
content: (
<Box mt={2}>
{!acmeServer && (
<Alert severity="info">
<AlertTitle>ACME server is required</AlertTitle>
The ACME server on the cluster is not configured. This component is a necessary dependency for processing
wildcard certificates. Please go to the ACME Server page and follow the steps.
</Alert>
)}
<Box mt={2}>
<Button
variant="outlined"
color="primary"
size="small"
disabled={!acmeServer}
onClick={() => {
dispatch(
createCertificateAction(
{
managedType: issuerManaged,
domains: [domain.domain],
name: "",
selfManagedCertContent: "",
selfManagedCertPrivateKey: "",
},
false,
),
);
}}
>
GENERATE CERTIFICATE
</Button>
</Box>
</Box>
),
completed: false,
};
};
const wildcardDomainWithCertStep = (): StepOption | null => {
if (!cert!.wildcardCertDNSChallengeDomainMap) {
return null;
}
const certDomains = cert!.wildcardCertDNSChallengeDomainMap;
const firsKey = Object.keys(certDomains)[0];
const firstDomain = `_acme-challenge.${Object.keys(certDomains)[0]}`;
const firstTarget = certDomains[firsKey];
return {
title: cert!.ready ? "The domain " + cert?.domains + " is now fully configured. " : "Apply a certificate",
content: (
<Box>
{cert!.ready ? (
<Button variant="outlined" color="primary" size="small" to={`/domains/${domain.name}`} component={Link}>
Back
</Button>
) : (
<>
<Box mt={2}>Add a CNAME Record in your DNS config panel.</Box>
<Box mt={2}>
<Alert severity="warning">
<AlertTitle>
If you are using <strong>Cloudflare</strong>, Please <strong>DO NOT</strong> enable Proxy for this
record
</AlertTitle>
Using Cloudflare's CNAME proxy will cause CNAME records to fail verification.
</Alert>
</Box>
<Box mt={2}>
<DNSConfigItems
items={Object.keys(certDomains).map((domain) => ({
domain: `_acme-challenge.${domain}`,
type: "CNAME",
cnameRecord: certDomains[domain],
}))}
/>
</Box>
<Box mt={2}>
Check to make sure they’re correct, then <strong>Save the changes</strong>.
</Box>
<Box mt={2}>
Wait for changes to take effect. Generally it will take effect within a few minutes to a few hours.
</Box>
<Box mt={2}>{renderHelper(firstDomain, "CNAME", firstTarget)}</Box>
<Box mt={2} display="flex" flexDirection="row">
<Box pl={2} display="flex">
<CertStatus cert={cert!} />
</Box>
</Box>
</>
)}
</Box>
),
completed: cert!.ready === "True",
};
};
const normalDomainWithCertStep = (): StepOption | null => {
return {
title: cert!.ready ? "The domain " + cert?.domains + " is now fully configured. " : "Apply a certificate",
content: (
<Box>
{cert!.ready ? (
<Button variant="outlined" color="primary" size="small" to={`/domains/${domain.name}`} component={Link}>
Back
</Button>
) : (
<>
<Box mt={2}>
<Alert severity="info">
This step will be completed automatically, please ensure that the DNS record in the previous step is
configured correctly. Please wait.
</Alert>
</Box>
<Box mt={2} display="flex">
<CertStatus cert={cert!} />
</Box>
</>
)}
</Box>
),
completed: true,
};
};
let certStep: StepOption | null = null;
if (cert) {
if (isWildcard) {
certStep = wildcardDomainWithCertStep();
} else {
certStep = normalDomainWithCertStep();
}
} else {
if (isWildcard) {
certStep = wildcardCertificateNoCertStep();
} else {
certStep = normalDomainNoCertStep();
}
}
const trafficStep: StepOption = {
title: `Configure ${domain.recordType} record to allow traffic to enter your cluster`,
content: (
<Box>
<Box mt={2}>
Add {domain.recordType === "A" ? "an" : "a"} {domain.recordType} Record in your DNS config panel you just
open.
</Box>
<Box mt={2}>
<DNSConfigItems
items={[
{
domain: domain.domain,
type: domain.recordType,
aRecord: domain.recordType === "A" ? domain.target : undefined,
cnameRecord: domain.recordType === "CNAME" ? domain.target : undefined,
},
]}
/>
</Box>
<Box mt={2}>
Check to make sure they’re correct, then <strong>Save the changes</strong>.
</Box>
<Box mt={2}>
Wait for changes to take effect. Generally it will take effect within a few minutes to a few hours.
</Box>
<Box mt={2}>{renderHelper(domain.domain, domain.recordType, domain.target, true)}</Box>
</Box>
),
completed: !!cert && cert.ready === "True",
};
steps.push(trafficStep);
if (certStep) steps.push(certStep);
return (
<BasePage>
<Box p={2}>
<KPanel>
<Stepper orientation="vertical">
{steps.map((step, index) => (
<Step
completed={step.completed}
active={!step.completed}
expanded={!step.completed || index === 2}
key={index}
>
<StepLabel>
<Subtitle1>{step.title}</Subtitle1>
</StepLabel>
<StepContent>
<Body2>{step.content}</Body2>
</StepContent>
</Step>
))}
</Stepper>
</KPanel>
</Box>
</BasePage>
);
};
export const DomainConfigPage = DomainConfigPageRaw;