From af522307e8b391d559712ae0e27cb922ffcf17ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?5gi=20=E2=98=91?= <5gi.exist@gmail.com> Date: Thu, 21 Dec 2023 14:30:24 -0500 Subject: [PATCH 1/2] Added Version checking to verify that a version of NGINX exists. Adds nginx download page to cache. Also added a few check before sending requests to the API. --- app.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index cdb2e6d..792af14 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,8 @@ document.getElementById("submit").addEventListener("click", generateQuickCmd, false); +const debug = true; // DISABLE FOR PRODUCTION +const baseURL = debug ? "http://localhost:8081/ngx" : "https://dev.nevets.tech/ngx"; + const service = "[Unit]\n" + "Description=The NGINX HTTP and reverse proxy server\n" + "After=syslog.target network-online.target remote-fs.target nss-lookup.target\n" + @@ -28,30 +31,41 @@ const service = "[Unit]\n" + // } // const sleep = ms => new Promise(r => setTimeout(r, ms)); -async function getHTML() { - return fetch("corsurl" + encodeURIComponent("https://nginx.org/download/")) - .then((response)=>response.body.toString()) - .then((responseJson)=>{return responseJson}); -} async function generateQuickCmd() { let nginxStr = document.getElementById("link").value; - // if (!st.toString().includes(extractNginxVersion(nginxStr))) { - // document.getElementById("script").innerHTML = "ERROR!? Do you have a valid verison of NGINX?" + "\nCopy to clipboard"; - // return; - // } + if (nginxStr === "") { document.getElementById("script").innerHTML = "ERROR!? Did you leave the NGINX Verison field blank?" + "\nCopy to clipboard"; return; } - let reqData = "{" + - "\"content\":\"" + encodeURI(buildCmd()) + "\"" + - "}"; + if (extractNginxVersion(nginxStr)===null || extractNginxVersion(nginxStr).includes("null")) { + document.getElementById("script").innerHTML = "ERROR!? Regex could not find the version in the input field!" + "\nCopy to clipboard"; + return; + } - fetch("https://api.nevets.tech/ngx/create", { + + let reqData = "{" + + "\"version\":\"" + encodeURIComponent(extractNginxVersion(nginxStr)) + "\"" + "}"; + let continueCycle = true; + await fetch(baseURL + "/dhv", { + method: "POST", + body: reqData, + }).then(res => res.json().then(json => { + if (json.url.includes("false")) { + document.getElementById("script").innerHTML = "ERROR!? Do you have a valid verison of NGINX?" + "\nCopy to clipboard"; + continueCycle = false; + } + })); + if (!continueCycle) { + return; + } + reqData = "{" + + "\"content\":\"" + encodeURI(buildCmd()) + "\"" + + "}"; + fetch(baseURL + "/create", { method: "POST", body: reqData, - mode: "cors" }).then(res => res.json().then(json => { document.getElementById("script").innerHTML = "curl -s " + json.url + " | bash" + "\nCopy to clipboard"; })); From 00e5c293935f20cb1cbeca995add4d2eba3ef2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?5gi=20=E2=98=91?= <5gi.exist@gmail.com> Date: Thu, 21 Dec 2023 14:32:11 -0500 Subject: [PATCH 2/2] Forgot to change it off debug. --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 792af14..d8737a1 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,6 @@ document.getElementById("submit").addEventListener("click", generateQuickCmd, false); -const debug = true; // DISABLE FOR PRODUCTION +const debug = false; // DISABLE FOR PRODUCTION const baseURL = debug ? "http://localhost:8081/ngx" : "https://dev.nevets.tech/ngx"; const service = "[Unit]\n" +