This commit is contained in:
Steven Tracey 2023-12-19 08:35:51 -06:00
parent b15d9adf45
commit 4107f3b5f6
7 changed files with 249 additions and 0 deletions

5
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

12
.idea/NginxInstaller.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,21 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
<option name="myValues">
<value>
<list size="7">
<item index="0" class="java.lang.String" itemvalue="nobr" />
<item index="1" class="java.lang.String" itemvalue="noembed" />
<item index="2" class="java.lang.String" itemvalue="comment" />
<item index="3" class="java.lang.String" itemvalue="noscript" />
<item index="4" class="java.lang.String" itemvalue="embed" />
<item index="5" class="java.lang.String" itemvalue="script" />
<item index="6" class="java.lang.String" itemvalue="p" />
</list>
</value>
</option>
<option name="myCustomValuesEnabled" value="true" />
</inspection_tool>
</profile>
</component>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/NginxInstaller.iml" filepath="$PROJECT_DIR$/.idea/NginxInstaller.iml" />
</modules>
</component>
</project>

82
app.js Normal file
View File

@ -0,0 +1,82 @@
document.getElementById("submit").addEventListener("click", generateQuickCmd, false);
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" +
"Wants=network-online.target\n" +
"\n" +
"[Service]\n" +
"Type=forking\n" +
"PIDFile=/var/run/nginx.pid\n" +
"ExecStartPre=/usr/sbin/nginx -t\n" +
"ExecStart=/usr/sbin/nginx\n" +
"ExecReload=/usr/sbin/nginx -s reload\n" +
"ExecStop=/bin/kill -s QUIT $MAINPID\n" +
"PrivateTmp=true\n" +
"\n" +
"[Install]\n" +
"WantedBy=multi-user.target";
function generateQuickCmd() {
fetch("https://paste.nevets.tech/api/", {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: "{'format':'url','content':'" + buildCmd() + "','expires':3600,'lexer':'bash'}"
}).then(res => res.json().then(json => {
document.getElementById("script").innerText = "curl -s " + json.url + "/raw | bash";
}));
}
function buildCmd() {
let nginxStr = document.getElementById("link").value; //https://nginx.org/download/nginx-x.xx.x.tar.gz
let script = "#!/bin/bash\n" +
"if [ \"$EUID\" -ne 0 ]\n" +
" then echo \"Please run as root (or with sudo)\"\n" +
" exit\n" +
"fi\n\n" +
"apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev\n" +
"wget " + document.getElementById("link").value + "\n" +
"tar -xzvf " + extractNginxVersion(nginxStr) + "\n";
if (document.getElementById("extMod").checked === true) {
script += "git clone https://github.com/google/ngx_brotli.git\n" +
"git clone https://github.com/openresty/headers-more-nginx-module.git\n" +
"cd ngx_brotli/ && git submodule update --init && cd ../" + extractNginxVersion(nginxStr).replace(/\.tar\.gz$/, '') + "/\n";
} else {
script += "cd " + extractNginxVersion(nginxStr).replace(/\.tar\.gz$/, '') + "\n";
}
script += "cp -r conf /etc/nginx\n" +
"mkdir /var/cache/nginx && sudo chown www-data:www-data /var/cache/nginx" +
getConfigureStr() + "\n" +
"make\n" +
"make install\n" +
"echo \"" + service + "\" >> /lib/systemd/system/nginx.service\n" +
"systemctl enable nginx.service\n" +
"systemctl start nginx.service";
return script;
}
function getConfigureStr() {
let str = "./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/etc/nginx/logs/error.log --http-log-path=/etc/nginx/logs/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=www-data --group=www-data ";
if (document.getElementById("extMod").checked === true) {
str += "--add-module=../headers-more-nginx-module --add-module=../ngx_brotli ";
}
if (document.getElementById("http3").checked === true) {
str += "--with-http_v3_module ";
}
str += "--with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_gunzip_module --with-http_gzip_static_module ";
return str;
}
function extractNginxVersion(url) {
// This regex matches 'nginx' followed by a hyphen and a version number, followed by '.tar.gz'
const regex = /nginx-\d+\.\d+\.\d+\.tar\.gz/;
// Use the regex to search the string
const match = url.match(regex);
// If a match is found, return it. Otherwise, return null or an appropriate message
return match ? match[0] : null;
}

35
index.html Normal file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Nginx Installer</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="main">
<label for="link">
<p>nginx archive <a href="https://nginx.org/download/" target=”_blank”>(copy link here)</a></p>
<input type="text" id="link">
</label>
<label for="extMod">
<p>Include recommended modules (<a href="https://github.com/openresty/headers-more-nginx-module" target="_blank">more headers</a> & <a href="https://github.com/google/ngx_brotli" target="_blank">brotli compression</a>)</p>
<input type="checkbox" id="extMod" checked>
<span class="checkmark"></span>
</label>
<label for="http3">
<p>HTTP/3:</p>
<input type="checkbox" id="http3">
<span class="checkmark"></span>
</label>
<label for="service">
<p>Run as service:</p>
<input type="checkbox" id="service">
<span class="checkmark"></span>
</label>
<button id="submit" class="centered-button">Generate Script</button>
<code lang="bash" id="script"></code>
</div>
<script src="app.js"></script>
</body>
</html>

86
style.css Normal file
View File

@ -0,0 +1,86 @@
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
font-family: "Arial Rounded MT Bold", serif;
}
.main {
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 10px;
width: fit-content; /* Adjust the width to fit the content */
}
label {
display: flex;
align-items: center; /* Align label text with checkbox */
margin: 10px 0;
position: relative;
cursor: pointer;
}
/* Adjust the spacing specifically for the first label */
label:first-child {
margin-bottom: 20px; /* Increase spacing below the first label */
width: 80%;
}
input[type="text"] {
margin-bottom: 10px; /* Adds margin below the text input */
width: 100%; /* Full width of its parent */
box-sizing: border-box; /* Include padding and border in the element's total width */
}
/* Style for checkboxes */
input[type="checkbox"] {
margin-right: 10px; /* Space between checkbox and label text */
}
/* Styling for links */
a {
color: blue;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* General button styling */
button {
padding: 10px 20px;
font-size: 16px;
color: white;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
button:active {
box-shadow:
7px 6px 28px 1px rgba(0, 0, 0, 0.24);
transform: translateY(4px);
/* Moving button 4px to y-axis */
}
/* Class to center the button in the container */
.centered-button {
display: block;
margin: 20px auto; /* Adds 20px space above and centers horizontally */
width: fit-content; /* Auto width to fit the button's content */
}