Skip to content

Ignore default location when defined in advanced config #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/backend/internal/nginx.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const _ = require('lodash');
const fs = require('fs');
const Liquid = require('liquidjs');
Expand Down Expand Up @@ -92,7 +90,7 @@ const internalNginx = {
})
.then(() => {
return combined_meta;
})
});
},

/**
Expand Down Expand Up @@ -146,13 +144,20 @@ const internalNginx = {
return new Promise((resolve, reject) => {
let template = null;
let filename = internalNginx.getConfigName(host_type, host.id);

try {
template = fs.readFileSync(__dirname + '/../templates/' + host_type + '.conf', {encoding: 'utf8'});
} catch (err) {
reject(new error.ConfigurationError(err.message));
return;
}

// Manipulate the data a bit before sending it to the template
host.use_default_location = true;
if (typeof host.advanced_config !== 'undefined' && host.advanced_config) {
host.use_default_location = !internalNginx.advancedConfigHasDefaultLocation(host.advanced_config);
}

renderEngine
.parseAndRender(template, host)
.then(config_text => {
Expand Down Expand Up @@ -312,6 +317,14 @@ const internalNginx = {
});

return Promise.all(promises);
},

/**
* @param {string} config
* @returns {boolean}
*/
advancedConfigHasDefaultLocation: function (config) {
return !!config.match(/^(?:.*;)?\s*?location\s*?\/\s*?{/im);
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/backend/templates/dead_host.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ server {

{{ advanced_config }}

{% if use_default_location %}
location / {
{% include "_forced_ssl.conf" %}
{% include "_hsts.conf" %}
return 404;
}
{% endif %}

}
{% endif %}
3 changes: 3 additions & 0 deletions src/backend/templates/proxy_host.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ server {

{{ advanced_config }}

{% if use_default_location %}
location / {
{%- if access_list_id > 0 -%}
# Access List
Expand All @@ -35,5 +36,7 @@ server {
# Proxy!
include conf.d/include/proxy.conf;
}
{% endif %}

}
{% endif %}
3 changes: 3 additions & 0 deletions src/backend/templates/redirection_host.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ server {

{{ advanced_config }}

{% if use_default_location %}
location / {
{% include "_forced_ssl.conf" %}
{% include "_hsts.conf" %}
Expand All @@ -22,5 +23,7 @@ server {
return 301 $scheme://{{ forward_domain_name }};
{% endif %}
}
{% endif %}

}
{% endif %}
6 changes: 6 additions & 0 deletions src/frontend/js/app/nginx/proxy/form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<div role="tabpanel" class="tab-pane" id="advanced">
<div class="row">
<div class="col-md-12">
<p>Nginx variables available to you are:</p>
<ul class="text-monospace">
<li>$server # Host/IP</li>
<li>$port # Port Number</li>
<li>$forward_scheme # http or https</li>
</ul>
<div class="form-group mb-0">
<label class="form-label"><%- i18n('all-hosts', 'advanced-config') %></label>
<textarea name="advanced_config" rows="8" class="form-control text-monospace" placeholder="# <%- i18n('all-hosts', 'advanced-warning') %>"><%- advanced_config %></textarea>
Expand Down