Skip to content

Commit c6ab315

Browse files
committed
Add status indicator to certificates and show active domain names
1 parent 2c15957 commit c6ab315

File tree

7 files changed

+54
-13
lines changed

7 files changed

+54
-13
lines changed

backend/internal/certificate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ const internalCertificate = {
313313
.where('is_deleted', 0)
314314
.andWhere('id', data.id)
315315
.allowGraph('[owner]')
316+
.allowGraph('[proxy_hosts]')
316317
.first();
317318

318319
if (access_data.permission_visibility !== 'all') {
@@ -464,6 +465,7 @@ const internalCertificate = {
464465
.where('is_deleted', 0)
465466
.groupBy('id')
466467
.allowGraph('[owner]')
468+
.allowGraph('[proxy_hosts]')
467469
.orderBy('nice_name', 'ASC');
468470

469471
if (access_data.permission_visibility !== 'all') {

backend/models/certificate.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const db = require('../db');
55
const helpers = require('../lib/helpers');
66
const Model = require('objection').Model;
7-
const User = require('./user');
87
const now = require('./now_helper');
98

109
Model.knex(db);
@@ -68,6 +67,8 @@ class Certificate extends Model {
6867
}
6968

7069
static get relationMappings () {
70+
const ProxyHost = require('./proxy_host');
71+
const User = require('./user');
7172
return {
7273
owner: {
7374
relation: Model.HasOneRelation,
@@ -79,6 +80,17 @@ class Certificate extends Model {
7980
modify: function (qb) {
8081
qb.where('user.is_deleted', 0);
8182
}
83+
},
84+
proxy_hosts: {
85+
relation: Model.HasManyRelation,
86+
modelClass: ProxyHost,
87+
join: {
88+
from: 'certificate.id',
89+
to: 'proxy_host.certificate_id'
90+
},
91+
modify: function (qb) {
92+
qb.where('proxy_host.is_deleted', 0);
93+
}
8294
}
8395
};
8496
}

frontend/js/app/nginx/certificates/list/item.ejs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
<td class="<%- isExpired() ? 'text-danger' : '' %>">
3434
<%- formatDbDate(expires_on, 'Do MMMM YYYY, h:mm a') %>
3535
</td>
36+
<td>
37+
<% if (proxy_hosts.length > 0) { %>
38+
<span class="status-icon bg-success"></span> <%- i18n('certificates', 'in-use') %>
39+
<% } else { %>
40+
<span class="status-icon bg-danger"></span> <%- i18n('certificates', 'inactive') %>
41+
<% } %>
42+
</td>
3643
<% if (canManage) { %>
3744
<td class="text-right">
3845
<div class="item-action dropdown">
@@ -48,6 +55,13 @@
4855
<div class="dropdown-divider"></div>
4956
<% } %>
5057
<a href="#" class="delete dropdown-item"><i class="dropdown-icon fe fe-trash-2"></i> <%- i18n('str', 'delete') %></a>
58+
<% if (proxy_hosts.length > 0) { %>
59+
<div class="dropdown-divider"></div>
60+
<span class="dropdown-header"><%- i18n('certificates', 'active-domain_names') %></span>
61+
<% proxy_hosts.forEach(function(host) { %>
62+
<a href="https://<%- host %>" class="dropdown-item" target="_blank"><%- host %></a>
63+
<% }); %>
64+
<% } %>
5165
</div>
5266
</div>
5367
</td>

frontend/js/app/nginx/certificates/list/item.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,23 @@ module.exports = Mn.View.extend({
4444
},
4545
},
4646

47-
templateContext: {
48-
canManage: App.Cache.User.canManage('certificates'),
49-
isExpired: function () {
50-
return moment(this.expires_on).isBefore(moment());
51-
},
52-
dns_providers: dns_providers
47+
templateContext: function () {
48+
return {
49+
canManage: App.Cache.User.canManage('certificates'),
50+
isExpired: function () {
51+
return moment(this.expires_on).isBefore(moment());
52+
},
53+
dns_providers: dns_providers,
54+
proxy_hosts: this.getProxyHosts()
55+
};
56+
},
57+
58+
getProxyHosts: function () {
59+
const hosts = this.model.attributes.proxy_hosts || [];
60+
return hosts.reduce((acc, host) => {
61+
acc.push(...(host.domain_names || []));
62+
return acc;
63+
}, []);
5364
},
5465

5566
initialize: function () {

frontend/js/app/nginx/certificates/list/main.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<th width="30">&nbsp;</th>
33
<th><%- i18n('str', 'name') %></th>
44
<th><%- i18n('all-hosts', 'cert-provider') %></th>
5-
<th><%- i18n('str', 'active-hosts') %></th>
65
<th><%- i18n('str', 'expires') %></th>
6+
<th><%- i18n('str', 'status') %></th>
77
<% if (canManage) { %>
88
<th>&nbsp;</th>
99
<% } %>

frontend/js/app/nginx/certificates/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = Mn.View.extend({
7474
e.preventDefault();
7575
let query = this.ui.query.val();
7676

77-
this.fetch(['owner'], query)
77+
this.fetch(['owner','proxy_hosts'], query)
7878
.then(response => this.showData(response))
7979
.catch(err => {
8080
this.showError(err);
@@ -89,7 +89,7 @@ module.exports = Mn.View.extend({
8989
onRender: function () {
9090
let view = this;
9191

92-
view.fetch(['owner'])
92+
view.fetch(['owner','proxy_hosts'])
9393
.then(response => {
9494
if (!view.isDestroyed()) {
9595
if (response && response.length) {

frontend/js/i18n/messages.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
"value": "Value",
3636
"please-wait": "Please wait...",
3737
"all": "All",
38-
"any": "Any",
39-
"active-hosts": "Active Hosts"
38+
"any": "Any"
4039
},
4140
"login": {
4241
"title": "Login to your account"
@@ -207,7 +206,10 @@
207206
"reachability-other": "There is a server found at this domain but it returned an unexpected status code {code}. Is it the NPM server? Please make sure your domain points to the IP where your NPM instance is running.",
208207
"download": "Download",
209208
"renew-title": "Renew Let's Encrypt Certificate",
210-
"search": "Search Certificate…"
209+
"search": "Search Certificate…",
210+
"in-use" : "In use",
211+
"inactive": "Inactive",
212+
"active-domain_names": "Active domain names"
211213
},
212214
"access-lists": {
213215
"title": "Access Lists",

0 commit comments

Comments
 (0)