Skip to content

Commit

Permalink
luci-app-upnp: Add Expires to port map listing
Browse files Browse the repository at this point in the history
Close #7481

Signed-off-by: Self-Hosting-Group <selfhostinggroup-git+openwrt@shost.ing>
  • Loading branch information
Self-Hosting-Group committed Dec 18, 2024
1 parent 8b3c13f commit f3c2377
Show file tree
Hide file tree
Showing 40 changed files with 2,646 additions and 2,473 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
'require rpc';
'require uci';



const callUpnpGetStatus = rpc.declare({
object: 'luci.upnp',
method: 'get_status',
Expand All @@ -27,6 +25,12 @@ function handleDelRule(num, ev) {
callUpnpDeleteRule(num);
}

function padnum(num, length) {
num = num.toString();
while (num.length < length) num = "0" + num;
return num;
}

return baseclass.extend({
title: _('Active UPnP IGD & PCP/NAT-PMP Port Maps'),

Expand All @@ -37,14 +41,14 @@ return baseclass.extend({
},

render: function(data) {

var table = E('table', { 'class': 'table', 'id': 'upnp_status_table' }, [
E('tr', { 'class': 'tr table-titles' }, [
E('th', { 'class': 'th' }, _('Client Name')),
E('th', { 'class': 'th' }, _('Client Address')),
E('th', { 'class': 'th' }, _('Client Port')),
E('th', { 'class': 'th' }, _('External Port')),
E('th', { 'class': 'th' }, _('Protocol')),
E('th', { 'class': 'th' }, _('Expires')),
E('th', { 'class': 'th' }, _('Description')),
E('th', { 'class': 'th cbi-section-actions' }, '')
])
Expand All @@ -53,12 +57,27 @@ return baseclass.extend({
var rules = Array.isArray(data[0].rules) ? data[0].rules : [];

var rows = rules.map(function(rule) {
var expires_sec, hour, minute, second, expires_str = '';
expires_sec = (new Date(rule.expires * 1000) - new Date().getTime()) / 1000;
hour = Math.floor(expires_sec / 3600);
minute = Math.floor(expires_sec % 3600 / 60);
second = Math.floor(expires_sec % 60);
if (hour >= 1) {
expires_str += hour + 'h ';
expires_str += padnum(minute, 2) + 'm ';
expires_str += padnum(second, 2) + 's';
} else if (minute >= 1) {
expires_str += minute + 'm ';
expires_str += padnum(second, 2) + 's';
} else if (expires_sec >= 1) expires_str += second + 's';

return [
rule.host_hint || _('Unknown'),
rule.intaddr,
rule.intport,
rule.extport,
rule.proto,
expires_str,
rule.descr,
E('button', {
'class': 'btn cbi-button-remove',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
'require rpc';
'require form';



const callInitAction = rpc.declare({
object: 'luci',
method: 'setInitAction',
Expand Down Expand Up @@ -36,6 +34,12 @@ function handleDelRule(num, ev) {
callUpnpDeleteRule(num);
}

function padnum(num, length) {
num = num.toString();
while (num.length < length) num = "0" + num;
return num;
}

return view.extend({
load: function() {
return Promise.all([
Expand All @@ -49,12 +53,27 @@ return view.extend({
var rules = Array.isArray(data[0].rules) ? data[0].rules : [];

var rows = rules.map(function(rule) {
var expires_sec, hour, minute, second, expires_str = '';
expires_sec = (new Date(rule.expires * 1000) - new Date().getTime()) / 1000;
hour = Math.floor(expires_sec / 3600);
minute = Math.floor(expires_sec % 3600 / 60);
second = Math.floor(expires_sec % 60);
if (hour >= 1) {
expires_str += hour + 'h ';
expires_str += padnum(minute, 2) + 'm ';
expires_str += padnum(second, 2) + 's';
} else if (minute >= 1) {
expires_str += minute + 'm ';
expires_str += padnum(second, 2) + 's';
} else if (expires_sec >= 1) expires_str += second + 's';

return [
rule.host_hint || _('Unknown'),
rule.intaddr,
rule.intport,
rule.extport,
rule.proto,
expires_str,
rule.descr,
E('button', {
'class': 'btn cbi-button-remove',
Expand All @@ -64,8 +83,6 @@ return view.extend({
});

cbi_update_table(nodes.querySelector('#upnp_status_table'), rows, E('em', _('There are no active port maps.')));

return;
},

render: function(data) {
Expand All @@ -92,6 +109,7 @@ return view.extend({
E('th', { 'class': 'th' }, _('Client Port')),
E('th', { 'class': 'th' }, _('External Port')),
E('th', { 'class': 'th' }, _('Protocol')),
E('th', { 'class': 'th' }, _('Expires')),
E('th', { 'class': 'th' }, _('Description')),
E('th', { 'class': 'th cbi-section-actions' }, '')
])
Expand Down Expand Up @@ -129,9 +147,11 @@ return view.extend({
_('Start autonomous port mapping service'));
o.rmempty = false;

s.taboption('setup', form.Flag, 'enable_upnp', _('Enable UPnP IGD protocol')).default = '1';
o = s.taboption('setup', form.Flag, 'enable_upnp', _('Enable UPnP IGD protocol'));
o.default = '1';

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

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

0 comments on commit f3c2377

Please sign in to comment.