Skip to content

Commit

Permalink
Fix reading nginx passenger vars
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Aug 16, 2023
1 parent b6e751e commit 28a2fab
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "domcloud-bridge",
"version": "0.26.1",
"version": "0.27.0",
"description": "Deployment runner for DOM Cloud",
"main": "app.js",
"engines": {
Expand Down
8 changes: 8 additions & 0 deletions src/controllers/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ export default function () {
next(error);
}
});
router.post('/ssl', checkAuth, checkGet(['domain']), checkPost(['ssl']), async function (req, res, next) {
try {
res.contentType('text/plain');
return res.send(await executor.setSsl("" + req.query.domain, req.body.ssl, req.body.http + ""));
} catch (error) {
next(error);
}
});
return router;
}
2 changes: 1 addition & 1 deletion src/controllers/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function trimPayload(payload) {
}
export async function runConfigInBackground(body, domain, sandbox, callback) {
let fullLogData = [],
chunkedLogData = ['Running runner... Please wait...\n'],
chunkedLogData = ['Running deployment script... Please wait...\n'],
delay = 5000,
startTime = Date.now();
const write = new PassThrough();
Expand Down
48 changes: 30 additions & 18 deletions src/executor/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,8 @@ class NginxExecutor {
// expand home path
vall = path.join(`/home/${info.user}`, config.passenger[key]);
break;
case "app_start_command":
// add quote strings
vall = escapeNginx(config.passenger[key]);
break;
default:
vall = config.passenger[key];
vall = escapeNginx(config.passenger[key]);
break;
}
node._add("passenger_" + key, vall);
Expand Down Expand Up @@ -159,20 +155,28 @@ class NginxExecutor {
const ke = k.slice("passenger_".length);
const ve = node[k][0]._value + '';
r.passenger = r.passenger || {};
if (ke === "document_root" || ke === "app_root") {
r.passenger[ke] = ve.slice(basepath.length);
} else if (ke === "app_start_command") {
r.passenger[ke] = unescapeNginx(ve);
} else if (ke === "env_var") {
r.passenger["env_var_list"] = r.passenger["env_var_list"] || [];
for (const env of node[k]) {
var splt = splitLimit(env._value, / /g, 2);
if (splt.length == 2) {
r.passenger["env_var_list"].push(splt[0] + '=' + unescapeNginx(splt[1]));
switch (ke) {
case "env_var":
r.passenger["env_var_list"] = r.passenger["env_var_list"] || [];
for (const env of node[k]) {
var splt = splitLimit(env._value, / /g, 2);
if (splt.length == 2) {
r.passenger["env_var_list"].push(splt[0] + '=' + unescapeNginx(splt[1]));
}
}
}
} else {
r.passenger[ke] = ve;
break;
case "document_root":
case "app_root":
case "ruby":
case "nodejs":
case "python":
case "meteor_app_settings":
// expand home path
r.passenger[ke] = ve.slice(basepath.length);
break;
default:
r.passenger[ke] = unescapeNginx(ve);
break;
}
}
if (locationKeys.includes(k)) {
Expand Down Expand Up @@ -289,6 +293,8 @@ class NginxExecutor {
spawnSudoUtil('NGINX_SET', [domain]).then(() => {
resolve("Done updated\n" + node.toString());
}).catch((err) => {
if (err && err.stderr && err.stderr.includes('nginx: [emerg]')) {
}
reject(err);
})
});
Expand Down Expand Up @@ -316,9 +322,15 @@ class NginxExecutor {
}
const info = this.extractInfo(node, domain);
if (ssl) {
if (!["off", "always", "on"].includes(ssl)) {
return reject(new Error(`Invalid ssl value ${ssl}`));
}
info.config.ssl = ssl;
}
if (http) {
if (!["1", "2"].includes(http)) {
return reject(new Error(`Invalid http value ${http}`));
}
info.config.http = http;
}
this.applyInfo(node, info);
Expand Down
2 changes: 2 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ export const unescapeNginx = function ( /** @type {string} */ str) {
try {
if (/^".*"$/.test(str)) {
return JSON.parse(str);
} else if (/'.*'/.test(str)) {
return str.substring(1, str.length - 1);
} else {
return str;
}
Expand Down
4 changes: 4 additions & 0 deletions test/nginx.d/complex.net.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ server {
passenger_enabled on;
passenger_app_start_command "python run.py --port=$PORT";
passenger_document_root /home/complex/public_html/webssh/webssh/static;
passenger_ruby /home/complex/.rvm/rubies/default/bin/ruby;
passenger_base_uri "/webssh";
passenger_app_root /home/complex/public_html/webssh;
passenger_env_var HTTP_SECURITY_AAAAA 'public';
passenger_env_var HTTP_SECURITY_BBBBB 'public';
passenger_env_var HTTP_SECURITY_LEVEL 'public';
}
location ~ \.php(/|$) {
try_files $uri =404;
Expand Down

0 comments on commit 28a2fab

Please sign in to comment.