Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luci-app-cloudflared: Overhaul tunnels.js #6943

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions applications/luci-app-cloudflared/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ LUCI_DEPENDS:=+cloudflared
LUCI_DESCRIPTION:=LuCI support for Cloudflare Zero Trust Tunnels

PKG_MAINTAINER:=Hilman Maulana <hilman0.0maulana@gmail.com>, Sergey Ponomarev <stokito@gmail.com>
PKG_VERSION:=1.1
PKG_VERSION:=1.2
PKG_LICENSE:=Apache-2.0

include ../../luci.mk

# call BuildPackage - OpenWrt buildroot signature
# call BuildPackage - OpenWrt buildroot signature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function listTunnels() {
});
}


return view.extend({
handleSaveApply: null,
handleSave: null,
Expand All @@ -34,53 +33,69 @@ return view.extend({
render: function (data) {
var tunnels = data[0];

var tunnelsElList = [];
for (var tunnel of tunnels) {
var connectionsSection = [];
var tunnelRows = tunnels.map(function (tunnel, index) {
var rowClass = index % 2 === 0 ? 'cbi-rowstyle-1' : 'cbi-rowstyle-2';
var tunneldate = new Date(tunnel.created_at).toLocaleString();
return E('tr', { 'class': 'tr ' + rowClass }, [
E('td', {'class': 'td'}, tunnel.name),
E('td', {'class': 'td'}, tunnel.id),
E('td', {'class': 'td'}, tunneldate),
E('td', {'class': 'td'}, tunnel.connections.length)
]);
});

var tunnelTable = [
E('h3', _('Tunnels Information')),
E('table', { 'class': 'table cbi-section-table' }, [
E('tr', { 'class': 'tr table-titles' }, [
E('th', {'class': 'th'}, _('Name')),
E('th', {'class': 'th'}, _('ID')),
E('th', {'class': 'th'}, _('Created At')),
E('th', {'class': 'th'}, _('Connections'))
]),
E(tunnelRows)
])
];

var connectionsTables = tunnels.map(function (tunnel) {
var connectionsTable;
if (tunnel.connections.length > 0) {
var connectionsElList = [];
for (let connection of tunnel.connections) {
var dateOpenedAt = new Date(connection.opened_at).toLocaleString();
connectionsElList.push(
E('tr', [
E('td', connection.id),
E('td', connection.origin_ip),
E('td', dateOpenedAt),
E('td', connection.colo_name)
])
);
}
var connectionRows = tunnel.connections.map(function (connection, index) {
var rowClass = index % 2 === 0 ? 'cbi-rowstyle-1' : 'cbi-rowstyle-2';
var connectiondate = new Date(connection.opened_at).toLocaleString();
return E('tr', { 'class': 'tr ' + rowClass }, [
E('td', {'class': 'td'}, connection.id),
E('td', {'class': 'td'}, connection.origin_ip),
E('td', {'class': 'td'}, connectiondate),
E('td', {'class': 'td'}, connection.colo_name)
]);
});

connectionsSection = [
E('h5', _('Connections')),
E('table', {'class': 'table cbi-section-table'}, [
E('thead', [
E('tr', {'class': 'tr table-titles'}, [
E('th', {'class': 'th'}, 'ID'),
E('th', {'class': 'th'}, _('Origin IP')),
E('th', {'class': 'th'}, _('Opened At')),
E('th', {'class': 'th'}, _('Data center')),
]),
]),
E('tbody', connectionsElList)
])
];
connectionsTable = E('table', { 'class': 'table cbi-section-table' }, [
E('tr', { 'class': 'tr table-titles' }, [
E('th', {'class': 'th'}, _('Connection ID')),
E('th', {'class': 'th'}, _('Origin IP')),
E('th', {'class': 'th'}, _('Opened At')),
E('th', {'class': 'th'}, _('Data Center'))
]),
E(connectionRows)
]);
} else {
connectionsSection = [E('em', _('No connections'))];
connectionsTable = E('div', {'class':'cbi-value center'}, [
E('em', _('No connections'))
]);
}

var tunnelEl = E('div', [
E('h4', tunnel.name),
E('span', 'ID '),
E('span', tunnel.id),
E('div', connectionsSection)
]
);
tunnelsElList.push(tunnelEl);
}
return E('div', {'class': 'cbi-section'}, [
E('h3', _('Connections') + ' ' + tunnel.name),
E(connectionsTable)
]);
});

return E([], [
E('h2', {'class': 'section-title'}, _('Tunnels')),
E('div', {'id': 'tunnels'}, tunnelsElList),
E('h2', { 'class': 'section-title' }, _('Tunnels')),
E('div', {'class': 'cbi-section'}, tunnelTable),
E(connectionsTables)
]);
}
});
});
32 changes: 26 additions & 6 deletions applications/luci-app-cloudflared/po/templates/cloudflared.pot
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,27 @@ msgstr ""
msgid "Configuration"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:55
#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:48
msgid "Tunnels Information"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:51
msgid "Name"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:52
msgid "ID"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:53
msgid "Created At"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:54
msgid "Connections"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:90
msgid "Connections"
msgstr ""

Expand All @@ -38,7 +58,7 @@ msgid ""
"dashboard."
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:62
#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:79
msgid "Data center"
msgstr ""

Expand Down Expand Up @@ -93,7 +113,7 @@ msgstr ""
msgid "Logging level"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:69
#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:85
msgid "No connections"
msgstr ""

Expand All @@ -105,11 +125,11 @@ msgstr ""
msgid "Obtain a certificate <a %s>here</a>."
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:61
#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:78
msgid "Opened At"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:60
#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:77
msgid "Origin IP"
msgstr ""

Expand Down Expand Up @@ -148,7 +168,7 @@ msgstr ""
msgid "Token"
msgstr ""

#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:82
#: applications/luci-app-cloudflared/htdocs/luci-static/resources/view/cloudflared/tunnels.js:96
#: applications/luci-app-cloudflared/root/usr/share/luci/menu.d/luci-app-cloudflared.json:22
msgid "Tunnels"
msgstr ""
Expand Down
Loading