Backwards compatibility for global options

This commit is contained in:
MattIPv4 2020-05-27 21:15:30 +01:00
parent 5a4714cb40
commit 193b50efc7
3 changed files with 75 additions and 1 deletions

View file

@ -151,8 +151,10 @@ limitations under the License.
}, },
mounted() { mounted() {
// Import any data from the URL query params, defaulting to one domain // Import any data from the URL query params, defaulting to one domain
// Fallback to the window hash if no search query params, from the Angular version of nginxconfig
// The config file watcher will handle setting the app as ready // The config file watcher will handle setting the app as ready
importData(window.location.search, this.$data.domains, this.$data.global, this.$nextTick); const query = window.location.search || window.location.hash.slice(1);
importData(query, this.$data.domains, this.$data.global, this.$nextTick);
}, },
methods: { methods: {
changes(index) { changes(index) {

View file

@ -0,0 +1,68 @@
const oldBool = val => val === '' ? true : val;
const globalMap = {
ssl_profile: ['https', 'sslProfile'],
resolver_cloudflare: ['https', 'ocspCloudflare', oldBool],
resolver_google: ['https', 'ocspGoogle', oldBool],
resolver_opendns: ['https', 'ocspOpenDns', oldBool],
directory_letsencrypt: ['https', 'letsEncryptRoot'],
referrer_policy: ['security', 'referrerPolicy'],
content_security_policy: ['security', 'contentSecurityPolicy'],
server_tokens: ['security', 'serverTokens', oldBool],
limit_req: ['security', 'limitReq', oldBool],
php_server: ['php', 'phpServer'],
php_server_backup: ['php', 'phpBackupServer'],
python_server: ['python', 'pythonServer'],
gzip: ['performance', 'gzipCompression', oldBool],
brotli: ['performance', 'brotliCompression', oldBool],
expires_assets: ['performance', 'assetsExpiration'],
expires_media: ['performance', 'mediaExpiration'],
expires_svg: ['performance', 'svgExpiration'],
expires_fonts: ['performance', 'fontsExpiration'],
access_log: ['logging', 'accessLog'],
error_log: ['logging', 'errorLog'],
log_not_found: ['logging', 'logNotFound', oldBool],
directory_nginx: ['nginx', 'nginxConfigDirectory'],
worker_processes: ['nginx', 'workerProcesses'],
user: ['nginx', 'user'],
pid: ['nginx', 'pid'],
client_max_body_size: ['nginx', 'clientMaxBodySize'],
file_structure: ['tools', 'modularizedStructure', val => val.toLowerCase().trim() === 'modularized'],
symlink: ['tools', 'symlinkVhost', oldBool],
};
// Handle converting the old query format from nginxconfig.io-angular to our new query params
export default data => {
// Handle converting global settings & storing domains
for (const key in data) {
if (!Object.prototype.hasOwnProperty.call(data, key)) continue;
// Map old global settings to their new ones
if (key in globalMap) {
const map = globalMap[key];
data.global = data.global || {};
data.global[map[0]] = data.global[map[0]] || {};
data.global[map[0]][map[1]] = map.length < 3 ? data[key] : map[2](data[key]);
delete data[key];
continue;
}
// If not a global setting and if this is an integer
// Then, this is probably an old domain, so we'll try to convert it as such
if (!isNaN(parseInt(key))) {
data.domains = data.domains || [];
data.domains.push(data[key]);
}
}
// TODO: Handle converting domain settings
};

View file

@ -2,6 +2,7 @@ import qs from 'qs';
import clone from 'clone'; import clone from 'clone';
import Domain from '../templates/domain'; import Domain from '../templates/domain';
import isObject from './is_object'; import isObject from './is_object';
import backwardsCompatibility from './backwards_compatibility';
const applyCategories = (categories, target) => { const applyCategories = (categories, target) => {
// Work through each potential category // Work through each potential category
@ -57,6 +58,9 @@ export default (query, domains, global, nextTick) => {
}, },
}); });
// Handle converting nginxconfig.io-angular params to the current version
backwardsCompatibility(data);
// Handle domains // Handle domains
if ('domains' in data) { if ('domains' in data) {
// Check its an array or object // Check its an array or object