summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-frps/htdocs/luci-static/resources
diff options
context:
space:
mode:
authorSiYao Mo <msylgj@vip.qq.com>2021-06-24 00:55:28 +0800
committerSiYao Mo <msylgj@vip.qq.com>2021-06-24 17:56:32 +0800
commitfc01bc88650ddefbcc26bbb7a2dfde2a9d143715 (patch)
tree30f04bcfe0dbf928ab65a89df370dccd50ac6942 /applications/luci-app-frps/htdocs/luci-static/resources
parent665bbb014bbe05a40ca0422d028fe358a1f33694 (diff)
luci-app-frpc/frps:add service status display
reference from luci-app-smartdns Special thanks to Nick Peng <pymumu@gmail.com> Signed-off-by: SiYao Mo <msylgj@vip.qq.com>
Diffstat (limited to 'applications/luci-app-frps/htdocs/luci-static/resources')
-rw-r--r--applications/luci-app-frps/htdocs/luci-static/resources/view/frps.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/applications/luci-app-frps/htdocs/luci-static/resources/view/frps.js b/applications/luci-app-frps/htdocs/luci-static/resources/view/frps.js
index cb092ce6bb..25f0714d83 100644
--- a/applications/luci-app-frps/htdocs/luci-static/resources/view/frps.js
+++ b/applications/luci-app-frps/htdocs/luci-static/resources/view/frps.js
@@ -1,6 +1,7 @@
'use strict';
'require view';
'require form';
+'require rpc';
'require tools.widgets as widgets';
// [Widget, Option, Title, Description, {Param: 'Value'}],
@@ -90,12 +91,60 @@ function defOpts(s, opts, params) {
}
}
+var callServiceList = rpc.declare({
+ object: 'service',
+ method: 'list',
+ params: ['name'],
+ expect: { '': {} }
+});
+
+function getServiceStatus() {
+ return L.resolveDefault(callServiceList('frps'), {}).then(function (res) {
+ var isRunning = false;
+ try {
+ isRunning = res['frps']['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 Server"), _("RUNNING"));
+ } else {
+ renderHTML += String.format(spanTemp, 'red', _("frp Server"), _("NOT RUNNING"));
+ }
+
+ return renderHTML;
+}
+
return view.extend({
render: function() {
var m, s, o;
m = new form.Map('frps', _('frp Server'));
+ 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;