From bf48fcbf96ee5bd4e229fd4d7333b477caadd286 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 28 Oct 2019 21:58:44 +0000 Subject: [PATCH] Fixed cert parsing --- src/commands/cwg.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/cwg.ts b/src/commands/cwg.ts index 4b1e55e..71b2b35 100644 --- a/src/commands/cwg.ts +++ b/src/commands/cwg.ts @@ -31,7 +31,9 @@ export default class CWG extends Command { const account = await this.client.db.Account.findOne({ $or: [{ account: args[1] }, { userID: args[1] }] }); if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} Cannot locate account, please try again.`); try { - const domain = await this.createDomain(account, args[2], Number(args[3]), { cert: args[4], key: args[5] }); + if (args[4] && !args[5]) return message.channel.createMessage(`${this.client.stores.emojis.error} x509 Certificate key required`); + let certs: { cert?: string, key?: string }; if (args[5]) certs = { cert: args[4], key: args[5] }; else certs = {}; + const domain = await this.createDomain(account, args[2], Number(args[3]), certs); const embed = new RichEmbed(); embed.setTitle('Domain Creation'); embed.setColor(3066993); @@ -92,7 +94,7 @@ export default class CWG extends Command { * @param x509 The paths to the certificate and key files. Must be already existant. * @example await CWG.createDomain('mydomain.cloud.libraryofcode.org', 6781); */ - public async createDomain(account: AccountInterface, domain: string, port: number, x509Certificate: { cert: string, key: string } = { cert: '/etc/nginx/ssl/cloud-org.chain.crt', key: '/etc/nginx/ssl/cloud-org.key.pem' }) { + public async createDomain(account: AccountInterface, domain: string, port: number, x509Certificate: { cert?: string, key?: string } = { cert: '/etc/nginx/ssl/cloud-org.chain.crt', key: '/etc/nginx/ssl/cloud-org.key.pem' }) { if (port <= 1024 || port >= 65535) throw new RangeError(`Port range must be between 1024 and 65535, received ${port}.`); if (await this.client.db.Domain.exists({ port })) throw new Error(`Port ${port} already exists in the database.`); if (await this.client.db.Domain.exists({ domain })) throw new Error(`Domain ${domain} already exists in the database.`);