Skip to content

Commit 075b59f

Browse files
Self-Hosting-Groupsystemcrash
authored andcommitted
luci-app-upnp: Add Expires to port map listing
Close openwrt#7481 Signed-off-by: Self-Hosting-Group <[email protected]>
1 parent 7cb2f65 commit 075b59f

File tree

40 files changed

+2628
-2473
lines changed

40 files changed

+2628
-2473
lines changed

applications/luci-app-upnp/htdocs/luci-static/resources/view/status/include/80_upnp.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
'require rpc';
55
'require uci';
66

7-
8-
97
const callUpnpGetStatus = rpc.declare({
108
object: 'luci.upnp',
119
method: 'get_status',
@@ -37,14 +35,14 @@ return baseclass.extend({
3735
},
3836

3937
render: function(data) {
40-
4138
var table = E('table', { 'class': 'table', 'id': 'upnp_status_table' }, [
4239
E('tr', { 'class': 'tr table-titles' }, [
4340
E('th', { 'class': 'th' }, _('Client Name')),
4441
E('th', { 'class': 'th' }, _('Client Address')),
4542
E('th', { 'class': 'th' }, _('Client Port')),
4643
E('th', { 'class': 'th' }, _('External Port')),
4744
E('th', { 'class': 'th' }, _('Protocol')),
45+
E('th', { 'class': 'th right' }, _('Expires')),
4846
E('th', { 'class': 'th' }, _('Description')),
4947
E('th', { 'class': 'th cbi-section-actions' }, '')
5048
])
@@ -53,12 +51,24 @@ return baseclass.extend({
5351
var rules = Array.isArray(data[0].rules) ? data[0].rules : [];
5452

5553
var rows = rules.map(function(rule) {
54+
const padnum = (num, length) => num.toString().padStart(length, "0");
55+
const expires_sec = rule?.expires || 0;
56+
const hour = Math.floor(expires_sec / 3600);
57+
const minute = Math.floor((expires_sec % 3600) / 60);
58+
const second = Math.floor(expires_sec % 60);
59+
const expires_str =
60+
hour > 0 ? `${hour}h ${padnum(minute, 2)}m ${padnum(second, 2)}s` :
61+
minute > 0 ? `${minute}m ${padnum(second, 2)}s` :
62+
expires_sec > 0 ? `${second}s` :
63+
'';
64+
5665
return [
5766
rule.host_hint || _('Unknown'),
5867
rule.intaddr,
5968
rule.intport,
6069
rule.extport,
6170
rule.proto,
71+
expires_str,
6272
rule.descr,
6373
E('button', {
6474
'class': 'btn cbi-button-remove',

applications/luci-app-upnp/htdocs/luci-static/resources/view/upnp/upnp.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
'require rpc';
77
'require form';
88

9-
10-
119
const callInitAction = rpc.declare({
1210
object: 'luci',
1311
method: 'setInitAction',
@@ -49,12 +47,24 @@ return view.extend({
4947
var rules = Array.isArray(data[0].rules) ? data[0].rules : [];
5048

5149
var rows = rules.map(function(rule) {
50+
const padnum = (num, length) => num.toString().padStart(length, "0");
51+
const expires_sec = rule?.expires || 0;
52+
const hour = Math.floor(expires_sec / 3600);
53+
const minute = Math.floor((expires_sec % 3600) / 60);
54+
const second = Math.floor(expires_sec % 60);
55+
const expires_str =
56+
hour > 0 ? `${hour}h ${padnum(minute, 2)}m ${padnum(second, 2)}s` :
57+
minute > 0 ? `${minute}m ${padnum(second, 2)}s` :
58+
expires_sec > 0 ? `${second}s` :
59+
'';
60+
5261
return [
5362
rule.host_hint || _('Unknown'),
5463
rule.intaddr,
5564
rule.intport,
5665
rule.extport,
5766
rule.proto,
67+
expires_str,
5868
rule.descr,
5969
E('button', {
6070
'class': 'btn cbi-button-remove',
@@ -64,8 +74,6 @@ return view.extend({
6474
});
6575

6676
cbi_update_table(nodes.querySelector('#upnp_status_table'), rows, E('em', _('There are no active port maps.')));
67-
68-
return;
6977
},
7078

7179
render: function(data) {
@@ -92,6 +100,7 @@ return view.extend({
92100
E('th', { 'class': 'th' }, _('Client Port')),
93101
E('th', { 'class': 'th' }, _('External Port')),
94102
E('th', { 'class': 'th' }, _('Protocol')),
103+
E('th', { 'class': 'th right' }, _('Expires')),
95104
E('th', { 'class': 'th' }, _('Description')),
96105
E('th', { 'class': 'th cbi-section-actions' }, '')
97106
])
@@ -129,9 +138,11 @@ return view.extend({
129138
_('Start autonomous port mapping service'));
130139
o.rmempty = false;
131140

132-
s.taboption('setup', form.Flag, 'enable_upnp', _('Enable UPnP IGD protocol')).default = '1';
141+
o = s.taboption('setup', form.Flag, 'enable_upnp', _('Enable UPnP IGD protocol'));
142+
o.default = '1';
133143

134-
s.taboption('setup', form.Flag, 'enable_natpmp', _('Enable PCP/NAT-PMP protocols')).default = '1';
144+
o = s.taboption('setup', form.Flag, 'enable_natpmp', _('Enable PCP/NAT-PMP protocols'));
145+
o.default = '1';
135146

136147
o = s.taboption('setup', form.Flag, 'igdv1', _('UPnP IGDv1 compatibility mode'),
137148
_('Advertise as IGDv1 (IPv4 only) device instead of IGDv2'));

0 commit comments

Comments
 (0)