diff options
author | Florian Eckert <fe@dev.tdt.de> | 2021-06-29 08:56:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 08:56:47 +0200 |
commit | a661d7d845a819781e3968f626e43cde8a876b9c (patch) | |
tree | 2566905b976539e8734f4e7fe393ebbdea083dc0 /applications/luci-app-frpc/htdocs/luci-static/resources/view/frpc.js | |
parent | 4314d8f3300825a9c72e249250a60da860da5a7f (diff) | |
parent | fc01bc88650ddefbcc26bbb7a2dfde2a9d143715 (diff) |
Merge pull request #5143 from msylgj/patch-1
luci-app-frpc/frps:add service status display
Diffstat (limited to 'applications/luci-app-frpc/htdocs/luci-static/resources/view/frpc.js')
-rw-r--r-- | applications/luci-app-frpc/htdocs/luci-static/resources/view/frpc.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/applications/luci-app-frpc/htdocs/luci-static/resources/view/frpc.js b/applications/luci-app-frpc/htdocs/luci-static/resources/view/frpc.js index 6c16ab800f..fb8f679b32 100644 --- a/applications/luci-app-frpc/htdocs/luci-static/resources/view/frpc.js +++ b/applications/luci-app-frpc/htdocs/luci-static/resources/view/frpc.js @@ -2,6 +2,7 @@ 'require view'; 'require ui'; 'require form'; +'require rpc'; 'require tools.widgets as widgets'; // [Widget, Option, Title, Description, {Param: 'Value'}], @@ -115,12 +116,60 @@ function defOpts(s, opts, params) { } } +var callServiceList = rpc.declare({ + object: 'service', + method: 'list', + params: ['name'], + expect: { '': {} } +}); + +function getServiceStatus() { + return L.resolveDefault(callServiceList('frpc'), {}).then(function (res) { + var isRunning = false; + try { + isRunning = res['frpc']['instances']['instance1']['running']; + } catch (e) { } + return isRunning; + }); +} + +function renderStatus(isRunning) { + var renderHTML = ""; + var spanTemp = "<span style=\"color:%s;font-weight:bold;margin-left:15px\">%s - %s</span>"; + + if (isRunning) { + renderHTML += String.format(spanTemp, 'green', _("frp Client"), _("RUNNING")); + } else { + renderHTML += String.format(spanTemp, 'red', _("frp Client"), _("NOT RUNNING")); + } + + return renderHTML; +} + return view.extend({ render: function() { var m, s, o; m = new form.Map('frpc', _('frp Client')); + s = m.section(form.NamedSection, '_status'); + s.anonymous = true; + s.render = function (section_id) { + L.Poll.add(function () { + return L.resolveDefault(getServiceStatus()).then(function(res) { + var view = document.getElementById("service_status"); + view.innerHTML = renderStatus(res); + }); + }); + + return E('div', { class: 'cbi-map' }, + E('div', { class: 'cbi-section'}, [ + E('div', { id: 'service_status' }, + _('Collecting data ...')) + ]) + ); + } + s = m.section(form.NamedSection, 'common', 'conf'); s.dynamic = true; |