Skip to content

Commit

Permalink
#58 add wildcard check for service, add ssl cert service run for fron…
Browse files Browse the repository at this point in the history
…tend
  • Loading branch information
stefanwerfling committed Mar 1, 2025
1 parent c3923e8 commit f319d8d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 10 deletions.
10 changes: 10 additions & 0 deletions backend/src/Routes/Main/Ssl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DefaultRoute} from 'flyingfish_core';
import {SchemaSslDetailsRequest} from 'flyingfish_schemas';
import {Details} from './Ssl/Details.js';
import {Providers} from './Ssl/Providers.js';
import {Run} from './Ssl/Run.js';

/**
* Certificate
Expand Down Expand Up @@ -33,6 +34,15 @@ export class Ssl extends DefaultRoute {
}
);

this._get(
'/json/ssl/run/service',
async(req, res) => {
if (this.isUserLogin(req, res)) {
res.status(200).json(await Run.rundService());
}
}
)

return super.getExpressRouter();
}

Expand Down
28 changes: 28 additions & 0 deletions backend/src/Routes/Main/Ssl/Run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {DefaultReturn, StatusCodes} from 'flyingfish_schemas';
import {SslCertService} from '../../../Service/SslCertService.js';

/**
* Run
*/
export class Run {

/**
* Run service
* @returns {DefaultReturn}
*/
public static async rundService(): Promise<DefaultReturn> {
if (SslCertService.getInstance().isInProcess()) {
return {
statusCode: StatusCodes.INTERNAL_ERROR,
msg: 'Scheduler is currently in process.'
};
}

await SslCertService.getInstance().invokeUpdate();

return {
statusCode: StatusCodes.OK
};
}

}
25 changes: 17 additions & 8 deletions backend/src/Service/SslCertService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,14 @@ export class SslCertService {
let isCreate = false;

let isExist = false;
let useWildcard = false;

if (provider.isSupportWildcard()) {
useWildcard = http.cert_wildcard;
}

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

try {
// TODO Wildcard
sslBundel = await provider.getCertificationBundel(domain.domainname, {wildcard: false});
sslBundel = await provider.getCertificationBundel(domain.domainname, {wildcard: useWildcard});
} catch (eBundel) {
Logger.getLogger().error(
'\'%s\' (http_id: %d), cert bundle is except: %s',
Expand Down Expand Up @@ -372,8 +375,7 @@ export class SslCertService {
isCertCreated = await provider.createCertificate({
domainName: domain.domainname,
email: http.cert_email,
// TODO wildcard
wildcard: false,
wildcard: useWildcard,
webRootPath: NginxServer.getInstance().getWebRootPath()
}, {
dnsServer: Dns2Server.getInstance()
Expand Down Expand Up @@ -453,8 +455,7 @@ export class SslCertService {
isCertCreated = await provider.createCertificate({
domainName: domain.domainname,
email: http.cert_email,
// TODO wildcard
wildcard: false,
wildcard: useWildcard,
webRootPath: NginxServer.getInstance().getWebRootPath()
}, {
dnsServer: Dns2Server.getInstance()
Expand Down Expand Up @@ -568,4 +569,12 @@ export class SslCertService {
}
}

/**
* Is the scheduler in a process
* @returns {boolean}
*/
public isInProcess(): boolean {
return this._inProcess;
}

}
13 changes: 12 additions & 1 deletion frontend/src/inc/Api/Ssl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
SchemaDefaultReturn,
SchemaSslDetailsResponse,
SchemaSslProvidersResponse,
SslDetails,
Expand All @@ -15,6 +16,7 @@ export class Ssl {

/**
* getList
* @return {SslProvidersResponse}
* @throws
*/
public static async getProviders(): Promise<SslProvidersResponse> {
Expand All @@ -23,7 +25,7 @@ export class Ssl {

/**
* getCertDetails
* @param httpid
* @param {number} httpid
*/
public static async getCertDetails(httpid: number): Promise<SslDetails> {
const resultContent = await NetFetch.postData('/json/ssl/cert/details', {httpid}, SchemaSslDetailsResponse);
Expand All @@ -35,4 +37,13 @@ export class Ssl {
return resultContent.details;
}

/**
* Run Service
* @return {boolean}
*/
public static async runService(): Promise<boolean> {
await NetFetch.getData('/json/ssl/run/service', SchemaDefaultReturn);
return true;
}

}
27 changes: 26 additions & 1 deletion frontend/src/inc/Pages/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from 'bambooo';
import {ListenData, RouteHttpSave, RouteStreamSave} from 'flyingfish_schemas';
import {Vts} from 'vts';
import {UnauthorizedError} from '../Api/Error/UnauthorizedError.js';
import {Listen as ListenAPI, ListenCategory} from '../Api/Listen.js';
import {Nginx as NginxAPI} from '../Api/Nginx.js';
import {
Expand All @@ -34,6 +35,7 @@ import {
import {Ssh as SshAPI} from '../Api/Ssh.js';
import {Ssl as SslAPI} from '../Api/Ssl.js';
import {Lang} from '../Lang.js';
import {UtilRedirect} from '../Utils/UtilRedirect.js';
import {BasePage} from './BasePage.js';
import {RouteHttpEditModal} from './Routes/RouteHttpEditModal.js';
import {RouteStreamEditModal} from './Routes/RouteStreamEditModal.js';
Expand Down Expand Up @@ -88,9 +90,10 @@ export class Routes extends BasePage {
// Navbar Left -------------------------------------------------------------------------------------------------

const toast = this._toast;
const leftNavbar = this._wrapper.getNavbar().getLeftNavbar();

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

leftNavbar.getElement().append('&nbsp;');

// eslint-disable-next-line no-new
new LeftNavbarLink(leftNavbar, 'Run SSL-Cert Service', async() => {
try {
await SslAPI.runService();

if (this._onLoadTable) {
this._onLoadTable();
}
} catch (e) {
if (e instanceof UnauthorizedError) {
UtilRedirect.toLogin();
}
}

return false;
}, 'btn btn-block btn-default btn-sm', 'fas fa-play');

leftNavbar.getElement().append('&nbsp;');


// -------------------------------------------------------------------------------------------------------------

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

0 comments on commit f319d8d

Please sign in to comment.