Skip to content

Commit f319d8d

Browse files
committedMar 1, 2025·
#58 add wildcard check for service, add ssl cert service run for frontend
1 parent c3923e8 commit f319d8d

File tree

5 files changed

+93
-10
lines changed

5 files changed

+93
-10
lines changed
 

‎backend/src/Routes/Main/Ssl.ts

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {DefaultRoute} from 'flyingfish_core';
33
import {SchemaSslDetailsRequest} from 'flyingfish_schemas';
44
import {Details} from './Ssl/Details.js';
55
import {Providers} from './Ssl/Providers.js';
6+
import {Run} from './Ssl/Run.js';
67

78
/**
89
* Certificate
@@ -33,6 +34,15 @@ export class Ssl extends DefaultRoute {
3334
}
3435
);
3536

37+
this._get(
38+
'/json/ssl/run/service',
39+
async(req, res) => {
40+
if (this.isUserLogin(req, res)) {
41+
res.status(200).json(await Run.rundService());
42+
}
43+
}
44+
)
45+
3646
return super.getExpressRouter();
3747
}
3848

‎backend/src/Routes/Main/Ssl/Run.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {DefaultReturn, StatusCodes} from 'flyingfish_schemas';
2+
import {SslCertService} from '../../../Service/SslCertService.js';
3+
4+
/**
5+
* Run
6+
*/
7+
export class Run {
8+
9+
/**
10+
* Run service
11+
* @returns {DefaultReturn}
12+
*/
13+
public static async rundService(): Promise<DefaultReturn> {
14+
if (SslCertService.getInstance().isInProcess()) {
15+
return {
16+
statusCode: StatusCodes.INTERNAL_ERROR,
17+
msg: 'Scheduler is currently in process.'
18+
};
19+
}
20+
21+
await SslCertService.getInstance().invokeUpdate();
22+
23+
return {
24+
statusCode: StatusCodes.OK
25+
};
26+
}
27+
28+
}

‎backend/src/Service/SslCertService.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,14 @@ export class SslCertService {
275275
let isCreate = false;
276276

277277
let isExist = false;
278+
let useWildcard = false;
279+
280+
if (provider.isSupportWildcard()) {
281+
useWildcard = http.cert_wildcard;
282+
}
278283

279284
try {
280-
// TODO Wildcard
281-
isExist = await provider.existCertificate(domain.domainname, {wildcard: false});
285+
isExist = await provider.existCertificate(domain.domainname, {wildcard: useWildcard});
282286
} catch (eExist) {
283287
Logger.getLogger().error(
284288
'\'%s\' (http_id: %d), cert is exist is except: %s',
@@ -297,8 +301,7 @@ export class SslCertService {
297301
let sslBundel = null;
298302

299303
try {
300-
// TODO Wildcard
301-
sslBundel = await provider.getCertificationBundel(domain.domainname, {wildcard: false});
304+
sslBundel = await provider.getCertificationBundel(domain.domainname, {wildcard: useWildcard});
302305
} catch (eBundel) {
303306
Logger.getLogger().error(
304307
'\'%s\' (http_id: %d), cert bundle is except: %s',
@@ -372,8 +375,7 @@ export class SslCertService {
372375
isCertCreated = await provider.createCertificate({
373376
domainName: domain.domainname,
374377
email: http.cert_email,
375-
// TODO wildcard
376-
wildcard: false,
378+
wildcard: useWildcard,
377379
webRootPath: NginxServer.getInstance().getWebRootPath()
378380
}, {
379381
dnsServer: Dns2Server.getInstance()
@@ -453,8 +455,7 @@ export class SslCertService {
453455
isCertCreated = await provider.createCertificate({
454456
domainName: domain.domainname,
455457
email: http.cert_email,
456-
// TODO wildcard
457-
wildcard: false,
458+
wildcard: useWildcard,
458459
webRootPath: NginxServer.getInstance().getWebRootPath()
459460
}, {
460461
dnsServer: Dns2Server.getInstance()
@@ -568,4 +569,12 @@ export class SslCertService {
568569
}
569570
}
570571

572+
/**
573+
* Is the scheduler in a process
574+
* @returns {boolean}
575+
*/
576+
public isInProcess(): boolean {
577+
return this._inProcess;
578+
}
579+
571580
}

‎frontend/src/inc/Api/Ssl.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
SchemaDefaultReturn,
23
SchemaSslDetailsResponse,
34
SchemaSslProvidersResponse,
45
SslDetails,
@@ -15,6 +16,7 @@ export class Ssl {
1516

1617
/**
1718
* getList
19+
* @return {SslProvidersResponse}
1820
* @throws
1921
*/
2022
public static async getProviders(): Promise<SslProvidersResponse> {
@@ -23,7 +25,7 @@ export class Ssl {
2325

2426
/**
2527
* getCertDetails
26-
* @param httpid
28+
* @param {number} httpid
2729
*/
2830
public static async getCertDetails(httpid: number): Promise<SslDetails> {
2931
const resultContent = await NetFetch.postData('/json/ssl/cert/details', {httpid}, SchemaSslDetailsResponse);
@@ -35,4 +37,13 @@ export class Ssl {
3537
return resultContent.details;
3638
}
3739

40+
/**
41+
* Run Service
42+
* @return {boolean}
43+
*/
44+
public static async runService(): Promise<boolean> {
45+
await NetFetch.getData('/json/ssl/run/service', SchemaDefaultReturn);
46+
return true;
47+
}
48+
3849
}

‎frontend/src/inc/Pages/Routes.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from 'bambooo';
2424
import {ListenData, RouteHttpSave, RouteStreamSave} from 'flyingfish_schemas';
2525
import {Vts} from 'vts';
26+
import {UnauthorizedError} from '../Api/Error/UnauthorizedError.js';
2627
import {Listen as ListenAPI, ListenCategory} from '../Api/Listen.js';
2728
import {Nginx as NginxAPI} from '../Api/Nginx.js';
2829
import {
@@ -34,6 +35,7 @@ import {
3435
import {Ssh as SshAPI} from '../Api/Ssh.js';
3536
import {Ssl as SslAPI} from '../Api/Ssl.js';
3637
import {Lang} from '../Lang.js';
38+
import {UtilRedirect} from '../Utils/UtilRedirect.js';
3739
import {BasePage} from './BasePage.js';
3840
import {RouteHttpEditModal} from './Routes/RouteHttpEditModal.js';
3941
import {RouteStreamEditModal} from './Routes/RouteStreamEditModal.js';
@@ -88,9 +90,10 @@ export class Routes extends BasePage {
8890
// Navbar Left -------------------------------------------------------------------------------------------------
8991

9092
const toast = this._toast;
93+
const leftNavbar = this._wrapper.getNavbar().getLeftNavbar();
9194

9295
// eslint-disable-next-line no-new
93-
new LeftNavbarLink(this._wrapper.getNavbar().getLeftNavbar(), 'Reload Config', async() => {
96+
new LeftNavbarLink(leftNavbar, 'Reload Config', async() => {
9497
if (await NginxAPI.reload()) {
9598
toast.fire({
9699
icon: 'success',
@@ -106,6 +109,28 @@ export class Routes extends BasePage {
106109
return false;
107110
}, 'btn btn-block btn-default btn-sm', IconFa.redo);
108111

112+
leftNavbar.getElement().append('&nbsp;');
113+
114+
// eslint-disable-next-line no-new
115+
new LeftNavbarLink(leftNavbar, 'Run SSL-Cert Service', async() => {
116+
try {
117+
await SslAPI.runService();
118+
119+
if (this._onLoadTable) {
120+
this._onLoadTable();
121+
}
122+
} catch (e) {
123+
if (e instanceof UnauthorizedError) {
124+
UtilRedirect.toLogin();
125+
}
126+
}
127+
128+
return false;
129+
}, 'btn btn-block btn-default btn-sm', 'fas fa-play');
130+
131+
leftNavbar.getElement().append('&nbsp;');
132+
133+
109134
// -------------------------------------------------------------------------------------------------------------
110135

111136
this._routeStreamDialog.setOnSave(async(): Promise<void> => {

0 commit comments

Comments
 (0)
Please sign in to comment.