From e8596c155460199e508c71b86e273dc31b8e58e7 Mon Sep 17 00:00:00 2001 From: Jaap-Jan de Wit Date: Mon, 24 Aug 2020 09:00:00 +0000 Subject: [PATCH] cloudflare DNS also possible while adding proxy, redirection and 404 --- frontend/js/app/nginx/dead/form.ejs | 17 ++++++++++ frontend/js/app/nginx/dead/form.js | 38 ++++++++++++++++----- frontend/js/app/nginx/proxy/form.ejs | 17 ++++++++++ frontend/js/app/nginx/proxy/form.js | 39 +++++++++++++++++----- frontend/js/app/nginx/redirection/form.ejs | 17 ++++++++++ frontend/js/app/nginx/redirection/form.js | 37 +++++++++++++++----- 6 files changed, 140 insertions(+), 25 deletions(-) diff --git a/frontend/js/app/nginx/dead/form.ejs b/frontend/js/app/nginx/dead/form.ejs index f94d2cc8..d48820f6 100644 --- a/frontend/js/app/nginx/dead/form.ejs +++ b/frontend/js/app/nginx/dead/form.ejs @@ -73,6 +73,23 @@ + +
+
+ +
+
+
+
+ + +
+
+
diff --git a/frontend/js/app/nginx/dead/form.js b/frontend/js/app/nginx/dead/form.js index 4d7ef6b7..aca367a5 100644 --- a/frontend/js/app/nginx/dead/form.js +++ b/frontend/js/app/nginx/dead/form.js @@ -23,6 +23,9 @@ module.exports = Mn.View.extend({ hsts_enabled: 'input[name="hsts_enabled"]', hsts_subdomains: 'input[name="hsts_subdomains"]', http2_support: 'input[name="http2_support"]', + cloudflare_switch: 'input[name="meta[cloudflare_use]"]', + cloudflare_token: 'input[name="meta[cloudflare_token]"', + cloudflare: '.cloudflare', letsencrypt: '.letsencrypt' }, @@ -31,10 +34,12 @@ module.exports = Mn.View.extend({ let id = this.ui.certificate_select.val(); if (id === 'new') { this.ui.letsencrypt.show().find('input').prop('disabled', false); + this.ui.cloudflare.hide(); } else { this.ui.letsencrypt.hide().find('input').prop('disabled', true); } + let enabled = id === 'new' || parseInt(id, 10) > 0; let inputs = this.ui.ssl_forced.add(this.ui.http2_support); @@ -76,6 +81,17 @@ module.exports = Mn.View.extend({ } }, + 'change @ui.cloudflare_switch': function() { + let checked = this.ui.cloudflare_switch.prop('checked'); + if (checked) { + this.ui.cloudflare_token.prop('required', 'required'); + this.ui.cloudflare.show(); + } else { + this.ui.cloudflare_token.prop('required', false); + this.ui.cloudflare.hide(); + } + }, + 'click @ui.save': function (e) { e.preventDefault(); @@ -98,20 +114,23 @@ module.exports = Mn.View.extend({ } // Check for any domain names containing wildcards, which are not allowed with letsencrypt - if (data.certificate_id === 'new') { + if (data.certificate_id === 'new') { let domain_err = false; - data.domain_names.map(function (name) { - if (name.match(/\*/im)) { - domain_err = true; - } - }); + if (!data.meta.cloudflare_use) { + data.domain_names.map(function (name) { + if (name.match(/\*/im)) { + domain_err = true; + } + }); + } if (domain_err) { - alert('Cannot request Let\'s Encrypt Certificate for wildcard domains'); + alert('Cannot request Let\'s Encrypt Certificate for wildcard domains without CloudFlare DNS.'); return; } - data.meta.letsencrypt_agree = data.meta.letsencrypt_agree === '1'; + data.meta.cloudflare_use = data.meta.cloudflare_use === '1'; + data.meta.letsencrypt_agree = data.meta.letsencrypt_agree === '1'; } else { data.certificate_id = parseInt(data.certificate_id, 10); } @@ -127,6 +146,8 @@ module.exports = Mn.View.extend({ } this.ui.buttons.prop('disabled', true).addClass('btn-disabled'); + this.ui.save.addClass('btn-loading'); + method(data) .then(result => { view.model.set(result); @@ -140,6 +161,7 @@ module.exports = Mn.View.extend({ .catch(err => { alert(err.message); this.ui.buttons.prop('disabled', false).removeClass('btn-disabled'); + this.ui.save.removeClass('btn-loading'); }); } }, diff --git a/frontend/js/app/nginx/proxy/form.ejs b/frontend/js/app/nginx/proxy/form.ejs index 0cc0d543..e0035977 100644 --- a/frontend/js/app/nginx/proxy/form.ejs +++ b/frontend/js/app/nginx/proxy/form.ejs @@ -141,6 +141,23 @@
+ +
+
+ +
+
+
+
+ + +
+
+
diff --git a/frontend/js/app/nginx/proxy/form.js b/frontend/js/app/nginx/proxy/form.js index eb93bc8f..0f642814 100644 --- a/frontend/js/app/nginx/proxy/form.js +++ b/frontend/js/app/nginx/proxy/form.js @@ -33,6 +33,9 @@ module.exports = Mn.View.extend({ hsts_enabled: 'input[name="hsts_enabled"]', hsts_subdomains: 'input[name="hsts_subdomains"]', http2_support: 'input[name="http2_support"]', + cloudflare_switch: 'input[name="meta[cloudflare_use]"]', + cloudflare_token: 'input[name="meta[cloudflare_token]"', + cloudflare: '.cloudflare', forward_scheme: 'select[name="forward_scheme"]', letsencrypt: '.letsencrypt' }, @@ -46,6 +49,7 @@ module.exports = Mn.View.extend({ let id = this.ui.certificate_select.val(); if (id === 'new') { this.ui.letsencrypt.show().find('input').prop('disabled', false); + this.ui.cloudflare.hide(); } else { this.ui.letsencrypt.hide().find('input').prop('disabled', true); } @@ -91,6 +95,17 @@ module.exports = Mn.View.extend({ } }, + 'change @ui.cloudflare_switch': function() { + let checked = this.ui.cloudflare_switch.prop('checked'); + if (checked) { + this.ui.cloudflare_token.prop('required', 'required'); + this.ui.cloudflare.show(); + } else { + this.ui.cloudflare_token.prop('required', false); + this.ui.cloudflare.hide(); + } + }, + 'click @ui.add_location_btn': function (e) { e.preventDefault(); @@ -134,20 +149,23 @@ module.exports = Mn.View.extend({ } // Check for any domain names containing wildcards, which are not allowed with letsencrypt - if (data.certificate_id === 'new') { + if (data.certificate_id === 'new') { let domain_err = false; - data.domain_names.map(function (name) { - if (name.match(/\*/im)) { - domain_err = true; - } - }); + if (!data.meta.cloudflare_use) { + data.domain_names.map(function (name) { + if (name.match(/\*/im)) { + domain_err = true; + } + }); + } if (domain_err) { - alert('Cannot request Let\'s Encrypt Certificate for wildcard domains'); + alert('Cannot request Let\'s Encrypt Certificate for wildcard domains without CloudFlare DNS.'); return; } - data.meta.letsencrypt_agree = data.meta.letsencrypt_agree === '1'; + data.meta.cloudflare_use = data.meta.cloudflare_use === '1'; + data.meta.letsencrypt_agree = data.meta.letsencrypt_agree === '1'; } else { data.certificate_id = parseInt(data.certificate_id, 10); } @@ -163,6 +181,8 @@ module.exports = Mn.View.extend({ } this.ui.buttons.prop('disabled', true).addClass('btn-disabled'); + this.ui.save.addClass('btn-loading'); + method(data) .then(result => { view.model.set(result); @@ -176,6 +196,7 @@ module.exports = Mn.View.extend({ .catch(err => { alert(err.message); this.ui.buttons.prop('disabled', false).removeClass('btn-disabled'); + this.ui.save.removeClass('btn-loading'); }); } }, @@ -203,7 +224,7 @@ module.exports = Mn.View.extend({ text: input }; }, - createFilter: /^(?:\*\.)?(?:[^.*]+\.?)+[^.]$/ + createFilter: /^(?:\.)?(?:[^.*]+\.?)+[^.]$/ }); // Access Lists diff --git a/frontend/js/app/nginx/redirection/form.ejs b/frontend/js/app/nginx/redirection/form.ejs index 7cdb8a3c..7d497699 100644 --- a/frontend/js/app/nginx/redirection/form.ejs +++ b/frontend/js/app/nginx/redirection/form.ejs @@ -97,6 +97,23 @@
+ +
+
+ +
+
+
+
+ + +
+
+
diff --git a/frontend/js/app/nginx/redirection/form.js b/frontend/js/app/nginx/redirection/form.js index 0cef1a3d..4e5b168c 100644 --- a/frontend/js/app/nginx/redirection/form.js +++ b/frontend/js/app/nginx/redirection/form.js @@ -23,6 +23,9 @@ module.exports = Mn.View.extend({ hsts_enabled: 'input[name="hsts_enabled"]', hsts_subdomains: 'input[name="hsts_subdomains"]', http2_support: 'input[name="http2_support"]', + cloudflare_switch: 'input[name="meta[cloudflare_use]"]', + cloudflare_token: 'input[name="meta[cloudflare_token]"', + cloudflare: '.cloudflare', letsencrypt: '.letsencrypt' }, @@ -31,6 +34,7 @@ module.exports = Mn.View.extend({ let id = this.ui.certificate_select.val(); if (id === 'new') { this.ui.letsencrypt.show().find('input').prop('disabled', false); + this.ui.cloudflare.hide(); } else { this.ui.letsencrypt.hide().find('input').prop('disabled', true); } @@ -76,6 +80,17 @@ module.exports = Mn.View.extend({ } }, + 'change @ui.cloudflare_switch': function() { + let checked = this.ui.cloudflare_switch.prop('checked'); + if (checked) { + this.ui.cloudflare_token.prop('required', 'required'); + this.ui.cloudflare.show(); + } else { + this.ui.cloudflare_token.prop('required', false); + this.ui.cloudflare.hide(); + } + }, + 'click @ui.save': function (e) { e.preventDefault(); @@ -100,20 +115,23 @@ module.exports = Mn.View.extend({ } // Check for any domain names containing wildcards, which are not allowed with letsencrypt - if (data.certificate_id === 'new') { + if (data.certificate_id === 'new') { let domain_err = false; - data.domain_names.map(function (name) { - if (name.match(/\*/im)) { - domain_err = true; - } - }); + if (!data.meta.cloudflare_use) { + data.domain_names.map(function (name) { + if (name.match(/\*/im)) { + domain_err = true; + } + }); + } if (domain_err) { - alert('Cannot request Let\'s Encrypt Certificate for wildcard domains'); + alert('Cannot request Let\'s Encrypt Certificate for wildcard domains without CloudFlare DNS.'); return; } - data.meta.letsencrypt_agree = data.meta.letsencrypt_agree === '1'; + data.meta.cloudflare_use = data.meta.cloudflare_use === '1'; + data.meta.letsencrypt_agree = data.meta.letsencrypt_agree === '1'; } else { data.certificate_id = parseInt(data.certificate_id, 10); } @@ -129,6 +147,8 @@ module.exports = Mn.View.extend({ } this.ui.buttons.prop('disabled', true).addClass('btn-disabled'); + this.ui.save.addClass('btn-loading'); + method(data) .then(result => { view.model.set(result); @@ -142,6 +162,7 @@ module.exports = Mn.View.extend({ .catch(err => { alert(err.message); this.ui.buttons.prop('disabled', false).removeClass('btn-disabled'); + this.ui.save.removeClass('btn-loading'); }); } },