Permalink
Browse files

Resolve #47 Check boot subdomains before SSL generation on user request

  • Loading branch information...
bgornicki committed Nov 25, 2018
1 parent 128b0ac commit cfad60f3d27a74ce8800febcd9cb9524aa1fd13e
Showing with 14 additions and 8 deletions.
  1. +1 −1 engrave/src/modules/SSL.ts
  2. +13 −7 engrave/src/routes/dashboard/settings.ts
@@ -99,7 +99,7 @@ export class SSLModule {
else return false;
}

private static async checkIfDomainPointsEngraveServer(domain: string) {
static async checkIfDomainPointsEngraveServer(domain: string) {
return new Promise ( (resolve, reject) => {
dns.lookup(domain, null, (error, address, family) => {
if(error) reject(error);
@@ -79,13 +79,19 @@ router.post('/settings', RoutesVlidators.isLoggedAndConfigured, async (req: IExt

router.post('/ssl', RoutesVlidators.isLoggedAndConfigured, async (req: IExtendedRequest, res: express.Response) => {
try {
console.log("Asked for SSl enable on: ", req.session.blogger.domain);
await SSLModule.generateCertificatesForDomain(req.session.blogger.domain);
let blog = await Blogs.findOne({ steem_username: req.session.steemconnect.name});
await NginxModule.generateNginxSettings(blog);
blog.ssl = true;
await blog.save();
res.json({ success: "SSL enabled!" });
const domain = req.session.blogger.domain;
if(await SSLModule.checkIfDomainPointsEngraveServer(domain) &&
await SSLModule.checkIfDomainPointsEngraveServer('www.' + domain)) {
console.log("Asked for SSl enable on: ", req.session.blogger.domain);
await SSLModule.generateCertificatesForDomain(req.session.blogger.domain);
let blog = await Blogs.findOne({ steem_username: req.session.steemconnect.name});
await NginxModule.generateNginxSettings(blog);
blog.ssl = true;
await blog.save();
res.json({ success: "SSL enabled!" });
} else {
res.json({ error: "Your domain is not pointing to our server. Edit DNS records or contact us" });
}
} catch (error) {
res.json({ error: "SSL could not be enabled. Try again or contact admin" });
}

0 comments on commit cfad60f

Please sign in to comment.