From 088a3785ccaa91c94d645119a9ee666090c08a31 Mon Sep 17 00:00:00 2001 From: mrfry Date: Tue, 11 Apr 2023 11:17:07 +0200 Subject: [PATCH] reading https files path from json --- README.md | 1 + src/types/basicTypes.ts | 6 ++++++ src/types/typeSchemas.ts | 10 ++++++++++ src/utils/files.ts | 23 ++++++++++++++++++++--- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce553e8..2f609b2 100755 --- a/README.md +++ b/README.md @@ -212,6 +212,7 @@ https://gitlab.com/MrFry/moodle-test-userscript . ├── data/ server specific data files not tracked by git │ ├── admins.json forum admins. should be removed and should use admin column from user db +│ ├── httpsfiles.json file including privkeyFile, fullchainFile, chainFile for https functionality │ ├── apiRootRedirectTo url where domain/api should redirect to │ ├── dbs/ directory for databases, and for their backups │ ├── domain the domain the server is hosted on. Used when `DOMAIN` env var is empty diff --git a/src/types/basicTypes.ts b/src/types/basicTypes.ts index c164caf..64973fc 100644 --- a/src/types/basicTypes.ts +++ b/src/types/basicTypes.ts @@ -180,3 +180,9 @@ export interface PeerInfo { note?: string http?: boolean } + +export interface HttpsFiles { + privkeyFile: string + fullchainFile: string + chainFile: string +} diff --git a/src/types/typeSchemas.ts b/src/types/typeSchemas.ts index 4b07b67..b17e240 100644 --- a/src/types/typeSchemas.ts +++ b/src/types/typeSchemas.ts @@ -156,3 +156,13 @@ export const ModulesSchema: Schema = { '.*': ModuleSchema, }, } + +export const HttpsFilesSchema: Schema = { + type: 'object', + patternProperties: { + privkeyFile: { type: 'string' }, + fullchainFile: { type: 'string' }, + chainFile: { type: 'string' }, + }, + required: ['privkeyFile', 'fullchainFile', 'chainFile'], +} diff --git a/src/utils/files.ts b/src/utils/files.ts index 64e412d..2466371 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -6,9 +6,11 @@ import { ModulesSchema, SelfInfoSchema, LinksSchema, + HttpsFilesSchema, } from '../types/typeSchemas' import logger from './logger' import utils from './utils' +import { HttpsFiles } from '../types/basicTypes' // FIXME: remove all file exists checks from everywhere for files that are created / checked here @@ -75,7 +77,22 @@ export const readAndValidateFile = (file: FileDescriptor): T => { return parsedContent } +const filesFiles = { + httpsFiles: { + path: 'data/httpsfiles.json', + description: + 'file paths for https functionality (privkey, chain files). Optional if https server is not used', + schema: HttpsFilesSchema, + warningIfMissing: true, + }, +} as const satisfies Record + +const httpsFiles: HttpsFiles = utils.FileExists(filesFiles.httpsFiles.path) + ? utils.ReadJSON(filesFiles.httpsFiles.path) + : null + export const files = { + ...filesFiles, // -------------------------------------------------------------------------------- // server / modules files // -------------------------------------------------------------------------------- @@ -155,15 +172,15 @@ export const files = { // https files // -------------------------------------------------------------------------------- privkeyFile: { - path: '/etc/letsencrypt/live/frylabs.net/privkey.pem', + path: httpsFiles?.privkeyFile, description: 'private key file for https', }, fullchainFile: { - path: '/etc/letsencrypt/live/frylabs.net/fullchain.pem', + path: httpsFiles?.fullchainFile, description: 'full chain key file for https', }, chainFile: { - path: '/etc/letsencrypt/live/frylabs.net/chain.pem', + path: httpsFiles?.chainFile, description: 'chain key file for https', },