Implements a comprehensive virtual host management system for OpenWrt with
nginx reverse proxy and Let's Encrypt SSL certificate integration.
Features:
- Virtual host management with nginx reverse proxy configuration
- Backend connectivity testing before deployment
- SSL/TLS certificate provisioning via acme.sh and Let's Encrypt
- Certificate expiry monitoring with color-coded warnings
- HTTP Basic Authentication support
- WebSocket protocol support with upgrade headers
- Real-time nginx access log viewer per domain
- Automatic nginx configuration generation and reload
Components:
- RPCD backend (luci.vhost-manager): 11 ubus methods for vhost and cert management
* status, list_vhosts, get_vhost, add_vhost, update_vhost, delete_vhost
* test_backend, request_cert, list_certs, reload_nginx, get_access_logs
- 4 JavaScript views: overview, vhosts, certificates, logs
- ACL with read/write permissions for all ubus methods
- UCI config with global settings and vhost sections
- Comprehensive README with API docs, examples, and troubleshooting
Configuration:
- Nginx vhost configs generated in /etc/nginx/conf.d/vhosts/
- SSL certificates managed via ACME in /etc/acme/{domain}/
- Access logs per domain: /var/log/nginx/{domain}.access.log
- HTTP Basic Auth htpasswd files in /etc/nginx/htpasswd/
Architecture follows SecuBox standards:
- RPCD naming convention (luci. prefix)
- Menu paths match view file structure
- All JavaScript in strict mode
- Backend connectivity validation
- Comprehensive error handling
Dependencies: nginx-ssl, acme, curl
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
165 lines
4.8 KiB
JavaScript
165 lines
4.8 KiB
JavaScript
'use strict';
|
|
'require view';
|
|
'require ui';
|
|
'require vhost-manager/api as API';
|
|
|
|
return L.view.extend({
|
|
load: function() {
|
|
return Promise.all([
|
|
API.listCerts()
|
|
]);
|
|
},
|
|
|
|
render: function(data) {
|
|
var certs = data[0] || [];
|
|
|
|
var v = E('div', { 'class': 'cbi-map' }, [
|
|
E('h2', {}, _('SSL Certificates')),
|
|
E('div', { 'class': 'cbi-map-descr' }, _('Manage Let\'s Encrypt SSL certificates'))
|
|
]);
|
|
|
|
// Request new certificate section
|
|
var requestSection = E('div', { 'class': 'cbi-section' }, [
|
|
E('h3', {}, _('Request New Certificate')),
|
|
E('div', { 'class': 'cbi-section-node' }, [
|
|
E('div', { 'class': 'cbi-value' }, [
|
|
E('label', { 'class': 'cbi-value-title' }, _('Domain')),
|
|
E('div', { 'class': 'cbi-value-field' }, [
|
|
E('input', {
|
|
'type': 'text',
|
|
'class': 'cbi-input-text',
|
|
'id': 'cert-domain',
|
|
'placeholder': 'example.com'
|
|
})
|
|
])
|
|
]),
|
|
E('div', { 'class': 'cbi-value' }, [
|
|
E('label', { 'class': 'cbi-value-title' }, _('Email')),
|
|
E('div', { 'class': 'cbi-value-field' }, [
|
|
E('input', {
|
|
'type': 'email',
|
|
'class': 'cbi-input-text',
|
|
'id': 'cert-email',
|
|
'placeholder': 'admin@example.com'
|
|
})
|
|
])
|
|
]),
|
|
E('div', { 'class': 'cbi-value' }, [
|
|
E('label', { 'class': 'cbi-value-title' }, ''),
|
|
E('div', { 'class': 'cbi-value-field' }, [
|
|
E('button', {
|
|
'class': 'cbi-button cbi-button-action',
|
|
'click': function(ev) {
|
|
ev.preventDefault();
|
|
|
|
var domain = document.getElementById('cert-domain').value;
|
|
var email = document.getElementById('cert-email').value;
|
|
|
|
if (!domain || !email) {
|
|
ui.addNotification(null, E('p', _('Domain and email are required')), 'error');
|
|
return;
|
|
}
|
|
|
|
ui.addNotification(null, E('p', _('Requesting certificate... This may take a few minutes.')), 'info');
|
|
|
|
API.requestCert(domain, email).then(function(result) {
|
|
if (result.success) {
|
|
ui.addNotification(null, E('p', '✓ ' + _('Certificate obtained successfully')), 'info');
|
|
window.location.reload();
|
|
} else {
|
|
ui.addNotification(null, E('p', '✗ ' + result.message), 'error');
|
|
}
|
|
});
|
|
}
|
|
}, _('Request Certificate'))
|
|
])
|
|
])
|
|
])
|
|
]);
|
|
v.appendChild(requestSection);
|
|
|
|
// Certificates list
|
|
if (certs.length > 0) {
|
|
var certsSection = E('div', { 'class': 'cbi-section' }, [
|
|
E('h3', {}, _('Installed Certificates'))
|
|
]);
|
|
|
|
var table = E('table', { 'class': 'table' }, [
|
|
E('tr', { 'class': 'tr table-titles' }, [
|
|
E('th', { 'class': 'th' }, _('Domain')),
|
|
E('th', { 'class': 'th' }, _('Issuer')),
|
|
E('th', { 'class': 'th' }, _('Expires')),
|
|
E('th', { 'class': 'th' }, _('Actions'))
|
|
])
|
|
]);
|
|
|
|
certs.forEach(function(cert) {
|
|
var expiresDate = new Date(cert.expires);
|
|
var daysLeft = Math.floor((expiresDate - new Date()) / (1000 * 60 * 60 * 24));
|
|
var expiresColor = daysLeft < 7 ? 'red' : (daysLeft < 30 ? 'orange' : 'green');
|
|
|
|
table.appendChild(E('tr', { 'class': 'tr' }, [
|
|
E('td', { 'class': 'td' }, cert.domain),
|
|
E('td', { 'class': 'td' }, cert.issuer || 'N/A'),
|
|
E('td', { 'class': 'td' }, [
|
|
E('span', { 'style': 'color: ' + expiresColor }, cert.expires),
|
|
E('br'),
|
|
E('small', {}, daysLeft + ' ' + _('days remaining'))
|
|
]),
|
|
E('td', { 'class': 'td' }, [
|
|
E('button', {
|
|
'class': 'cbi-button cbi-button-action',
|
|
'click': function(ev) {
|
|
ui.showModal(_('Certificate Details'), [
|
|
E('div', { 'class': 'cbi-section' }, [
|
|
E('p', {}, [
|
|
E('strong', {}, _('Domain: ')),
|
|
E('span', {}, cert.domain)
|
|
]),
|
|
E('p', {}, [
|
|
E('strong', {}, _('Subject: ')),
|
|
E('span', {}, cert.subject || 'N/A')
|
|
]),
|
|
E('p', {}, [
|
|
E('strong', {}, _('Issuer: ')),
|
|
E('span', {}, cert.issuer || 'N/A')
|
|
]),
|
|
E('p', {}, [
|
|
E('strong', {}, _('Expires: ')),
|
|
E('span', {}, cert.expires)
|
|
]),
|
|
E('p', {}, [
|
|
E('strong', {}, _('File: ')),
|
|
E('code', {}, cert.cert_file)
|
|
])
|
|
]),
|
|
E('div', { 'class': 'right' }, [
|
|
E('button', {
|
|
'class': 'cbi-button cbi-button-neutral',
|
|
'click': ui.hideModal
|
|
}, _('Close'))
|
|
])
|
|
]);
|
|
}
|
|
}, _('Details'))
|
|
])
|
|
]));
|
|
});
|
|
|
|
certsSection.appendChild(table);
|
|
v.appendChild(certsSection);
|
|
} else {
|
|
v.appendChild(E('div', { 'class': 'cbi-section' }, [
|
|
E('p', { 'style': 'font-style: italic; text-align: center; padding: 20px' },
|
|
_('No SSL certificates installed'))
|
|
]));
|
|
}
|
|
|
|
return v;
|
|
},
|
|
|
|
handleSaveApply: null,
|
|
handleSave: null,
|
|
handleReset: null
|
|
});
|