mirror of
				https://github.com/NginxProxyManager/nginx-proxy-manager.git
				synced 2025-11-04 01:15:14 +00:00 
			
		
		
		
	Adds buttons to test availability of server from public internet
This commit is contained in:
		@@ -685,6 +685,16 @@ module.exports = {
 | 
			
		||||
                return fetch('post', 'nginx/certificates/' + id + '/renew', undefined, {timeout});
 | 
			
		||||
            },
 | 
			
		||||
 | 
			
		||||
            /**
 | 
			
		||||
             * @param  {Number}  id
 | 
			
		||||
             * @returns {Promise}
 | 
			
		||||
             */
 | 
			
		||||
            testHttpChallenge: function (domains) {
 | 
			
		||||
                return fetch('get', 'nginx/certificates/test-http?' + new URLSearchParams({
 | 
			
		||||
                    domains: JSON.stringify(domains),
 | 
			
		||||
                }));
 | 
			
		||||
            },
 | 
			
		||||
 | 
			
		||||
            /**
 | 
			
		||||
             * @param   {Number}  id
 | 
			
		||||
             * @returns {Promise}
 | 
			
		||||
 
 | 
			
		||||
@@ -366,6 +366,19 @@ module.exports = {
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Certificate Test Reachability
 | 
			
		||||
     *
 | 
			
		||||
     * @param model
 | 
			
		||||
     */
 | 
			
		||||
    showNginxCertificateTestReachability: function (model) {
 | 
			
		||||
      if (Cache.User.isAdmin() || Cache.User.canManage('certificates')) {
 | 
			
		||||
        require(['./main', './nginx/certificates/test'], function (App, View) {
 | 
			
		||||
          App.UI.showModalDialog(new View({model: model}));
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Audit Log
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,14 @@
 | 
			
		||||
                            <input type="text" name="domain_names" class="form-control" id="input-domains" value="<%- domain_names.join(',') %>" required>
 | 
			
		||||
                            <div class="text-blue"><i class="fe fe-alert-triangle"></i> <%- i18n('ssl', 'hosts-warning') %></div>
 | 
			
		||||
                        </div>
 | 
			
		||||
 | 
			
		||||
                        <div class="mb-3 test-domains-container">
 | 
			
		||||
                            <button type="button" class="btn btn-secondary test-domains col-sm-12"><%- i18n('certificates', 'test-reachability') %></button>
 | 
			
		||||
                            <div class="text-secondary small">
 | 
			
		||||
                                <i class="fe fe-info"></i> 
 | 
			
		||||
                                <%- i18n('certificates', 'reachability-info') %>
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="col-sm-12 col-md-12">
 | 
			
		||||
                        <div class="form-group">
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,8 @@ module.exports = Mn.View.extend({
 | 
			
		||||
        non_loader_content:                   '.non-loader-content',
 | 
			
		||||
        le_error_info:                        '#le-error-info',
 | 
			
		||||
        domain_names:                         'input[name="domain_names"]',
 | 
			
		||||
        test_domains_container:               '.test-domains-container',
 | 
			
		||||
        test_domains_button:                  '.test-domains',
 | 
			
		||||
        buttons:                              '.modal-footer button',
 | 
			
		||||
        cancel:                               'button.cancel',
 | 
			
		||||
        save:                                 'button.save',
 | 
			
		||||
@@ -56,10 +58,12 @@ module.exports = Mn.View.extend({
 | 
			
		||||
                    this.ui.dns_provider_credentials.prop('required', 'required');
 | 
			
		||||
                }
 | 
			
		||||
                this.ui.dns_challenge_content.show();
 | 
			
		||||
                this.ui.test_domains_container.hide();
 | 
			
		||||
            } else {
 | 
			
		||||
                this.ui.dns_provider.prop('required', false);
 | 
			
		||||
                this.ui.dns_provider_credentials.prop('required', false);
 | 
			
		||||
                this.ui.dns_challenge_content.hide();                
 | 
			
		||||
                this.ui.dns_challenge_content.hide();
 | 
			
		||||
                this.ui.test_domains_container.show();            
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
@@ -205,6 +209,23 @@ module.exports = Mn.View.extend({
 | 
			
		||||
                    this.ui.non_loader_content.show();
 | 
			
		||||
                });
 | 
			
		||||
        },
 | 
			
		||||
        'click @ui.test_domains_button': function (e) {
 | 
			
		||||
            e.preventDefault();
 | 
			
		||||
            const domainNames = this.ui.domain_names[0].value.split(',');
 | 
			
		||||
            if (domainNames && domainNames.length > 0) {
 | 
			
		||||
                this.model.set('domain_names', domainNames);
 | 
			
		||||
                this.model.set('back_to_add', true);
 | 
			
		||||
                App.Controller.showNginxCertificateTestReachability(this.model);
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        'change @ui.domain_names': function(e){
 | 
			
		||||
            const domainNames = e.target.value.split(',');
 | 
			
		||||
            if (domainNames && domainNames.length > 0) {
 | 
			
		||||
                this.ui.test_domains_button.prop('disabled', false);
 | 
			
		||||
            } else {
 | 
			
		||||
                this.ui.test_domains_button.prop('disabled', true);
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        'change @ui.other_certificate_key': function(e){
 | 
			
		||||
            this.setFileName("other_certificate_key_label", e)
 | 
			
		||||
        },
 | 
			
		||||
@@ -257,6 +278,10 @@ module.exports = Mn.View.extend({
 | 
			
		||||
        this.ui.credentials_file_content.hide(); 
 | 
			
		||||
        this.ui.loader_content.hide();
 | 
			
		||||
        this.ui.le_error_info.hide();
 | 
			
		||||
        const domainNames = this.ui.domain_names[0].value.split(',');
 | 
			
		||||
        if (!domainNames || domainNames.length === 0 || (domainNames.length === 1 && domainNames[0] === "")) {
 | 
			
		||||
            this.ui.test_domains_button.prop('disabled', true);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    initialize: function (options) {
 | 
			
		||||
 
 | 
			
		||||
@@ -42,6 +42,9 @@
 | 
			
		||||
            <% if (provider === 'letsencrypt') { %>
 | 
			
		||||
                <a href="#" class="renew dropdown-item"><i class="dropdown-icon fe fe-refresh-cw"></i> <%- i18n('certificates', 'force-renew') %></a>
 | 
			
		||||
                <a href="#" class="download dropdown-item"><i class="dropdown-icon fe fe-download"></i> <%- i18n('certificates', 'download') %></a>
 | 
			
		||||
                <% if (meta.dns_challenge === false) { %>
 | 
			
		||||
                    <a href="#" class="test dropdown-item"><i class="dropdown-icon fe fe-globe"></i> <%- i18n('certificates', 'test-reachability') %></a>
 | 
			
		||||
                <% } %>
 | 
			
		||||
                <div class="dropdown-divider"></div>
 | 
			
		||||
            <% } %>
 | 
			
		||||
            <a href="#" class="delete dropdown-item"><i class="dropdown-icon fe fe-trash-2"></i> <%- i18n('str', 'delete') %></a>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ const Mn            = require('backbone.marionette');
 | 
			
		||||
const moment        = require('moment');
 | 
			
		||||
const App           = require('../../../main');
 | 
			
		||||
const template      = require('./item.ejs');
 | 
			
		||||
const dns_providers = require('../../../../../../global/certbot-dns-plugins')
 | 
			
		||||
const dns_providers = require('../../../../../../global/certbot-dns-plugins');
 | 
			
		||||
 | 
			
		||||
module.exports = Mn.View.extend({
 | 
			
		||||
    template: template,
 | 
			
		||||
@@ -12,7 +12,8 @@ module.exports = Mn.View.extend({
 | 
			
		||||
        host_link: '.host-link',
 | 
			
		||||
        renew:     'a.renew',
 | 
			
		||||
        delete:    'a.delete',
 | 
			
		||||
        download:  'a.download'
 | 
			
		||||
        download:  'a.download',
 | 
			
		||||
        test:      'a.test'
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    events: {
 | 
			
		||||
@@ -31,11 +32,16 @@ module.exports = Mn.View.extend({
 | 
			
		||||
            let win = window.open($(e.currentTarget).attr('rel'), '_blank');
 | 
			
		||||
            win.focus();
 | 
			
		||||
        },
 | 
			
		||||
        
 | 
			
		||||
                
 | 
			
		||||
        'click @ui.download': function (e) {
 | 
			
		||||
            e.preventDefault();
 | 
			
		||||
            App.Api.Nginx.Certificates.download(this.model.get('id'))
 | 
			
		||||
        }
 | 
			
		||||
            App.Api.Nginx.Certificates.download(this.model.get('id'));
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        'click @ui.test': function (e) {
 | 
			
		||||
            e.preventDefault();
 | 
			
		||||
            App.Controller.showNginxCertificateTestReachability(this.model);
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    templateContext: {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								frontend/js/app/nginx/certificates/test.ejs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								frontend/js/app/nginx/certificates/test.ejs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
<div class="modal-content">
 | 
			
		||||
    <div class="modal-header">
 | 
			
		||||
        <h5 class="modal-title"><%- i18n('certificates', 'reachability-title') %></h5>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="modal-body">
 | 
			
		||||
        <div class="waiting text-center">
 | 
			
		||||
            <%= i18n('str', 'please-wait') %>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="alert alert-danger error" role="alert"></div>
 | 
			
		||||
        <div class="alert alert-danger success" role="alert"></div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="modal-footer">
 | 
			
		||||
        <button type="button" class="btn btn-secondary cancel" disabled><%- i18n('str', 'close') %></button>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										73
									
								
								frontend/js/app/nginx/certificates/test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								frontend/js/app/nginx/certificates/test.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,73 @@
 | 
			
		||||
const Mn       = require('backbone.marionette');
 | 
			
		||||
const App      = require('../../main');
 | 
			
		||||
const template = require('./test.ejs');
 | 
			
		||||
 | 
			
		||||
module.exports = Mn.View.extend({
 | 
			
		||||
	template:  template,
 | 
			
		||||
	className: 'modal-dialog',
 | 
			
		||||
 | 
			
		||||
	ui: {
 | 
			
		||||
		waiting: '.waiting',
 | 
			
		||||
		error:   '.error',
 | 
			
		||||
		success: '.success',
 | 
			
		||||
		close:   'button.cancel'
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
    events: {
 | 
			
		||||
        'click @ui.close': function (e) {
 | 
			
		||||
            e.preventDefault();
 | 
			
		||||
            if (this.model.get('back_to_add')) {
 | 
			
		||||
                App.Controller.showNginxCertificateForm(this.model);
 | 
			
		||||
            } else {
 | 
			
		||||
                App.UI.closeModal();
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
	onRender: function () {
 | 
			
		||||
		this.ui.error.hide();
 | 
			
		||||
		this.ui.success.hide();
 | 
			
		||||
 | 
			
		||||
		App.Api.Nginx.Certificates.testHttpChallenge(this.model.get('domain_names'))
 | 
			
		||||
			.then((result) => {
 | 
			
		||||
				let allOk = true;
 | 
			
		||||
				let text  = '';
 | 
			
		||||
 | 
			
		||||
				for (const domain in result) {
 | 
			
		||||
					const status = result[domain];
 | 
			
		||||
					if (status === 'ok') {
 | 
			
		||||
						text += `<p><strong>${domain}:</strong> ${App.i18n('certificates', 'reachability-ok')}</p>`;
 | 
			
		||||
					} else {
 | 
			
		||||
						allOk = false;
 | 
			
		||||
						if (status === 'no-host') {
 | 
			
		||||
							text += `<p><strong>${domain}:</strong> ${App.i18n('certificates', 'reachability-not-resolved')}</p>`;
 | 
			
		||||
						} else if (status === 'failed') {
 | 
			
		||||
							text += `<p><strong>${domain}:</strong> ${App.i18n('certificates', 'reachability-failed-to-check')}</p>`;
 | 
			
		||||
						} else if (status === '404') {
 | 
			
		||||
							text += `<p><strong>${domain}:</strong> ${App.i18n('certificates', 'reachability-404')}</p>`;
 | 
			
		||||
						} else if (status.startsWith('other:')) {
 | 
			
		||||
							const code = status.substring(6);
 | 
			
		||||
							text      += `<p><strong>${domain}:</strong> ${App.i18n('certificates', 'reachability-other', {code})}</p>`;
 | 
			
		||||
						} else {
 | 
			
		||||
							// This should never happen
 | 
			
		||||
							text += `<p><strong>${domain}:</strong> ?</p>`;
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				this.ui.waiting.hide();
 | 
			
		||||
				if (allOk) {
 | 
			
		||||
					this.ui.success.html(text).show();
 | 
			
		||||
				} else {
 | 
			
		||||
					this.ui.error.html(text).show();
 | 
			
		||||
				}
 | 
			
		||||
				this.ui.close.prop('disabled', false);
 | 
			
		||||
			})
 | 
			
		||||
			.catch((e) => {
 | 
			
		||||
				console.error(e);
 | 
			
		||||
				this.ui.waiting.hide();
 | 
			
		||||
				this.ui.error.text(App.i18n('certificates', 'reachability-failed-to-reach-api')).show();
 | 
			
		||||
				this.ui.close.prop('disabled', false);
 | 
			
		||||
			});
 | 
			
		||||
	}
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user