Commit 40fc904e authored by nanahira's avatar nanahira

add htpasswd

parent 949133ec
Pipeline #22640 passed with stages
in 24 minutes and 43 seconds
......@@ -10,7 +10,8 @@
"license": "MIT",
"dependencies": {
"lodash": "^4.17.21",
"mustache": "^4.2.0"
"mustache": "^4.2.0",
"nano-md5": "^1.0.5"
},
"devDependencies": {
"@types/jest": "^28.1.6",
......@@ -3657,6 +3658,11 @@
"mustache": "bin/mustache"
}
},
"node_modules/nano-md5": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/nano-md5/-/nano-md5-1.0.5.tgz",
"integrity": "sha512-1VAOX0EiuwAdCMGpnglxp9r6ylm+gXwQi+UPAnc/Oj1tLLJ8D1I8rLZeiO4MWsUAqH8tuBAHweT1LYSrDfJlPg=="
},
"node_modules/natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
......@@ -7537,6 +7543,11 @@
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
},
"nano-md5": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/nano-md5/-/nano-md5-1.0.5.tgz",
"integrity": "sha512-1VAOX0EiuwAdCMGpnglxp9r6ylm+gXwQi+UPAnc/Oj1tLLJ8D1I8rLZeiO4MWsUAqH8tuBAHweT1LYSrDfJlPg=="
},
"natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
......
......@@ -57,6 +57,7 @@
},
"dependencies": {
"lodash": "^4.17.21",
"mustache": "^4.2.0"
"mustache": "^4.2.0",
"nano-md5": "^1.0.5"
}
}
import { pickCert } from './check-cert';
import { Parser } from './parser';
import { getSiteNames } from './utility';
import md5 from 'nano-md5';
import fs from 'fs';
export interface SiteHttps {
ports: number[];
......@@ -23,6 +25,7 @@ export interface SiteRenderData {
disableTop?: boolean;
serverExtra?: string[];
locationExtra?: string[];
htpasswd?: string;
}
export interface ProxyRenderData extends SiteRenderData {
......@@ -145,6 +148,17 @@ async function getSiteData(
} as ProxyRenderData;
}
const basicPasswords = Object.entries(parser.getDict('HTPASSWD'));
if (basicPasswords.length) {
const htpasswd = basicPasswords
.map(([user, pass]) => `${user}:${md5.crypt(pass)}`)
.join('\n');
await fs.promises.writeFile(
`/etc/nginx/generated/htpasswd-${domain}`,
htpasswd,
);
}
return {
domains: domains,
ports: parser.getArrayNumber('PORT') || [80],
......@@ -157,6 +171,9 @@ async function getSiteData(
disableTop: parser.getBoolean('DISABLE_TOP'),
serverExtra: parser.getArray('SERVER_EXTRA'),
locationExtra: parser.getArray('LOCATION_EXTRA'),
htpasswd: basicPasswords.length
? `/etc/nginx/generated/htpasswd-${domain}`
: undefined,
...specificRenderData,
};
}
......
......@@ -195,6 +195,11 @@ http {
}
{{/disableTop}}
{{#htpasswd}}
auth_basic "Please enter your username and password";
auth_basic_user_file {{htpasswd}};
{{/htpasswd}}
{{#serverExtra}}
{{.}}
{{/serverExtra}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment