Add support of encryption and HTTP Auth r.2
This commit is contained in:
parent
4392035512
commit
c0755fe55c
@ -14,23 +14,6 @@ function logger (...p) {
|
|||||||
console.log("[DEBUG.main]:", ...p);
|
console.log("[DEBUG.main]:", ...p);
|
||||||
}
|
}
|
||||||
|
|
||||||
function auth (self, req, res, next) {
|
|
||||||
if (self.syntax.auth) {
|
|
||||||
const ACCESS = "Basic " + Buffer.from(`${self.syntax.auth.login}:${self.syntax.auth.password}`).toString('base64');
|
|
||||||
if (req.headers['authorization'] === ACCESS) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (self.syntax.auth.mode === "strict" && req.headers['authorization'] !== undefined) {
|
|
||||||
return res.status(403).send("<h1>Permission denied</h1><hr/><p>Permission denied.</p>");
|
|
||||||
}
|
|
||||||
res.set("WWW-Authenticate", "Basic");
|
|
||||||
return res.status(401).send();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
|
|
||||||
function fetchProxy (req, res, reverseTo) {
|
function fetchProxy (req, res, reverseTo) {
|
||||||
const params = { method: req.method.toUpperCase(), headers: Object.assign({}, req.headers), redirect: "follow", follow: 20, compress: false };
|
const params = { method: req.method.toUpperCase(), headers: Object.assign({}, req.headers), redirect: "follow", follow: 20, compress: false };
|
||||||
delete params.headers.host;
|
delete params.headers.host;
|
||||||
@ -70,11 +53,14 @@ module.exports = class HTTPReverse extends Component {
|
|||||||
super(adr, syntaxTree);
|
super(adr, syntaxTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
domainAction (context, domain, req, res) {
|
domainAction (context, domain, callCommand, req, res) {
|
||||||
logger("DOMAIN ACT:", this.syntax);
|
logger("DOMAIN ACT:", this.syntax);
|
||||||
if (!(context instanceof HTTPReverse))
|
if (!(context instanceof HTTPReverse))
|
||||||
throw new SyntaxError("You can't call revHTTP domain from unsupported type. Supported types: revHTTP, simpleHTTP, redirectHTTP");
|
throw new SyntaxError("You can't call revHTTP domain from unsupported type. Supported types: revHTTP, simpleHTTP, redirectHTTP");
|
||||||
fetchProxy(req, res, this.syntax.target);
|
switch (callCommand) {
|
||||||
|
case "proxy":
|
||||||
|
return fetchProxy(req, res, this.syntax.target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run () {
|
run () {
|
||||||
@ -98,7 +84,22 @@ module.exports = class HTTPReverse extends Component {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.app.use((req, res, next) => auth(this, req, res, next));
|
this.app.use((req, res, next) => {
|
||||||
|
if (this.syntax.auth) {
|
||||||
|
const ACCESS = "Basic " + Buffer.from(`${this.syntax.auth.login}:${this.syntax.auth.password}`).toString('base64');
|
||||||
|
if (req.headers['authorization'] === ACCESS) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (this.syntax.auth.mode === "strict" && req.headers['authorization'] !== undefined) {
|
||||||
|
return res.status(403).send("<h1>Permission denied</h1><hr/><p>Permission denied.</p>");
|
||||||
|
}
|
||||||
|
res.set("WWW-Authenticate", "Basic");
|
||||||
|
return res.status(401).send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
this.app.use("*", async (req, res) => {
|
this.app.use("*", async (req, res) => {
|
||||||
logger("REQ HEADERS:>", req.headers);
|
logger("REQ HEADERS:>", req.headers);
|
||||||
@ -109,7 +110,7 @@ module.exports = class HTTPReverse extends Component {
|
|||||||
if (!isNotDomained) {
|
if (!isNotDomained) {
|
||||||
return this
|
return this
|
||||||
.callDomain(currentDomain, this.syntax.domains[currentDomain])
|
.callDomain(currentDomain, this.syntax.domains[currentDomain])
|
||||||
.argv(req, res);
|
.argv("proxy", req, res);
|
||||||
}
|
}
|
||||||
return fetchProxy(req, res, reverseTo);
|
return fetchProxy(req, res, reverseTo);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user