forked from engineering/cloudservices
Allowed multiple domains to use the same port
parent
d918cd30bd
commit
2c528c36c9
|
@ -33,7 +33,18 @@ export default class CWG_Create extends Command {
|
||||||
if (args[3] && !args[4]) return edit.edit(`${this.client.stores.emojis.error} x509 Certificate key required`);
|
if (args[3] && !args[4]) return edit.edit(`${this.client.stores.emojis.error} x509 Certificate key required`);
|
||||||
let certs: { cert?: string, key?: string }; if (args[4]) certs = { cert: args[3], key: args[4] };
|
let certs: { cert?: string, key?: string }; if (args[4]) certs = { cert: args[3], key: args[4] };
|
||||||
if (await this.client.db.Domain.exists({ domain: args[1] })) return edit.edit(`***${this.client.stores.emojis.error} This domain already exists.***`);
|
if (await this.client.db.Domain.exists({ domain: args[1] })) return edit.edit(`***${this.client.stores.emojis.error} This domain already exists.***`);
|
||||||
if (await this.client.db.Domain.exists({ port: Number(args[2]) })) return edit.edit(`***${this.client.stores.emojis.error} This port is already binded to a domain.***`);
|
if (await this.client.db.Domain.exists({ port: Number(args[2]) })) {
|
||||||
|
// await edit.edit(`***${this.client.stores.emojis.error} This port is already binded to a domain. Do you wish to continue? (y/n)***`);
|
||||||
|
let answer: Message;
|
||||||
|
try {
|
||||||
|
answer = await this.client.util.messageCollector(message,
|
||||||
|
`***${this.client.stores.emojis.error} This port is already binded to a domain. Do you wish to continue? (y/n)***`,
|
||||||
|
30000, true, ['y', 'n'], (msg) => msg.author.id === message.author.id && msg.channel.id === message.channel.id);
|
||||||
|
} catch (error) {
|
||||||
|
return edit.edit(`***${this.client.stores.emojis.error} Bind request cancelled***`);
|
||||||
|
}
|
||||||
|
if (answer.content === 'n') return edit.edit(`***${this.client.stores.emojis.error} Bind request cancelled***`);
|
||||||
|
}
|
||||||
const domain = await this.createDomain(account, args[1], Number(args[2]), certs);
|
const domain = await this.createDomain(account, args[1], Number(args[2]), certs);
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Domain Creation');
|
embed.setTitle('Domain Creation');
|
||||||
|
@ -98,7 +109,6 @@ export default class CWG_Create extends Command {
|
||||||
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' }) {
|
||||||
try {
|
try {
|
||||||
if (port <= 1024 || port >= 65535) throw new RangeError(`Port range must be between 1024 and 65535, received ${port}.`);
|
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.`);
|
if (await this.client.db.Domain.exists({ domain })) throw new Error(`Domain ${domain} already exists in the database.`);
|
||||||
if (!await this.client.db.Account.exists({ userID: account.userID })) throw new Error(`Cannot find account ${account.userID}.`);
|
if (!await this.client.db.Account.exists({ userID: account.userID })) throw new Error(`Cannot find account ${account.userID}.`);
|
||||||
await fs.access(x509Certificate.cert, fs.constants.R_OK);
|
await fs.access(x509Certificate.cert, fs.constants.R_OK);
|
||||||
|
|
Loading…
Reference in New Issue