From a7bbe35e6364b09a828f553df2ebe750b7e5a8be Mon Sep 17 00:00:00 2001 From: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com> Date: Mon, 15 May 2023 12:48:34 +0200 Subject: [PATCH] Add SSL Config Nginx --- pages/api/generate.ts | 19 ++++++++--- pages/index.tsx | 10 +++++- templates/nginx.ssl.conf | 73 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 templates/nginx.ssl.conf diff --git a/pages/api/generate.ts b/pages/api/generate.ts index 52593d6..5d2fe70 100644 --- a/pages/api/generate.ts +++ b/pages/api/generate.ts @@ -3,7 +3,7 @@ import { promises as fs } from 'fs'; import { NextApiRequest, NextApiResponse } from 'next' export default async function handler(req: NextApiRequest, res: NextApiResponse) { - var { webServer, sourcePath, domainName, includeWWW } = req.query; + var { webServer, sourcePath, domainName, includeWWW, includeSSL } = req.query; // When a parameter is defined twice, use the first one. // This keeps the variables as strings instead of arrays if they are defined more than once. @@ -18,6 +18,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) WWW = (includeWWW == 'false') ? false : true; } + if (Array.isArray(includeSSL)){ + var SSL = (includeSSL[0] == 'false') ? false : true; + } else { + SSL = (includeSSL == 'false') ? false : true; + } + + const templateDirectory = path.join(process.cwd(), 'templates'); const supportedWebServers = ['nginx']; @@ -25,10 +32,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) res.status(400).send('Invalid web server. Accepted values are: ' + supportedWebServers.join(', ')); return; } + + if(SSL){ + var template = await fs.readFile(templateDirectory + `/${webServer}.ssl.conf`, 'utf8'); + }else{ + var template = await fs.readFile(templateDirectory + `/${webServer}.conf`, 'utf8'); - // Read the template file - var template = await fs.readFile(templateDirectory + `/${webServer}.conf`, 'utf8'); - + } + // Some server-specific replacements switch (webServer) { case "nginx": diff --git a/pages/index.tsx b/pages/index.tsx index d128ee7..260a663 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -12,12 +12,14 @@ const Index = () => { const [sourcePath, setSourcePath] = useState("/var/www/fossbilling.org/src"); const [domainName, setDomainName] = useState("fossbilling.org"); const [includeWWW, setIncludeWWW] = useState(true); + const [includeSSL, setIncludeSSL] = useState(true); + const [conf, setConf] = useState(""); const [err, setErr] = useState(""); const callTheAPI = async () => { try { - const res = await fetch(`/api/generate?webServer=${webServer}&sourcePath=${sourcePath}&domainName=${domainName}&includeWWW=${includeWWW}`); + const res = await fetch(`/api/generate?webServer=${webServer}&sourcePath=${sourcePath}&domainName=${domainName}&includeWWW=${includeWWW}&includeSSL=${includeSSL}`); const data = await res.text(); if (res.ok) { setConf(data) @@ -93,6 +95,12 @@ const Index = () => { setIncludeWWW(e.target.checked)} /> + + setIncludeSSL(e.target.checked)} + /> +