Skip to content

Commit

Permalink
feat: add version info display in status
Browse files Browse the repository at this point in the history
  • Loading branch information
yichya committed Mar 13, 2024
1 parent d8edd92 commit 16d2ca8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/root/usr/share/xray/protocol/socks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function socks_outbound(server, tag) {
address: server["server"],
port: v,
users: users
}
};
})
},
streamSettings: stream_settings_result
Expand Down
2 changes: 1 addition & 1 deletion core/root/usr/share/xray/protocol/vless.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function vless_outbound(server, tag) {
encryption: server["vless_encryption"]
}
]
}
};
})
},
streamSettings: stream_settings_result
Expand Down
3 changes: 3 additions & 0 deletions status/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define Package/$(PKG_NAME)/description
endef

define Build/Compile
echo "luci-app-xray $(PKG_VERSION)-$(PKG_RELEASE) `git rev-parse HEAD` `date +%s`" > $(PKG_BUILD_DIR)/version.txt
endef

define Package/$(PKG_NAME)/install
Expand All @@ -33,6 +34,8 @@ define Package/$(PKG_NAME)/install
$(INSTALL_DATA) ./root/usr/share/luci/menu.d/luci-app-xray-status.json $(1)/usr/share/luci/menu.d/luci-app-xray-status.json
$(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
$(INSTALL_DATA) ./root/usr/share/rpcd/acl.d/luci-app-xray-status.json $(1)/usr/share/rpcd/acl.d/luci-app-xray-status.json
$(INSTALL_DIR) $(1)/usr/share/xray
$(INSTALL_DATA) $(PKG_BUILD_DIR)/version.txt $(1)/usr/share/xray/version.txt
endef

$(eval $(call BuildPackage,$(PKG_NAME)))
23 changes: 18 additions & 5 deletions status/root/www/luci-static/resources/view/xray/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
'require view';
'require view.xray.shared as shared';

function bool_translate(v) {
if (v === "1") {
return _("available");
}
return _("unavailable");
}

function greater_than_zero(n) {
if (n < 0) {
return 0;
Expand Down Expand Up @@ -297,17 +304,24 @@ function inbound_stats(vars, config) {

return view.extend({
load: function () {
return uci.load(shared.variant);
return Promise.all([
uci.load(shared.variant),
fs.read("/usr/share/xray/version.txt")
]);
},

render: function (config) {
if (uci.get_first(config, "general", "metrics_server_enable") != "1") {
render: function (load_result) {
const config = load_result[0];
if (uci.get_first(config, "general", "metrics_server_enable") !== "1") {
return E([], [
E('h2', _('Xray (status)')),
E('p', { 'class': 'cbi-map-descr' }, _("Xray metrics server not enabled. Enable Xray metrics server to see details."))
]);
}
const info = E('p', { 'class': 'cbi-map-descr' }, _("Collecting data. If any error occurs, check if wget is installed correctly."));
const version = load_result[1].split(" ");
const stats_available = bool_translate(uci.get_first(config, "general", "stats"));
const observatory_available = bool_translate(uci.get_first(config, "general", "observatory"));
const info = E('p', { 'class': 'cbi-map-descr' }, `${version[0]} Version ${version[1]} (${version[2]}) Built ${new Date(version[3] * 1000).toLocaleString()}. Statistics: ${stats_available}. Observatory: ${observatory_available}.`);
const detail = E('div', {});
poll.add(function () {
fs.exec_direct("/usr/bin/wget", ["-O", "-", `http://127.0.0.1:${uci.get_first(config, "general", "metrics_server_port") || 18888}/debug/vars`], "json").then(function (vars) {
Expand All @@ -319,7 +333,6 @@ return view.extend({
])
]);
ui.tabs.initTabGroup(result.lastElementChild.childNodes);
dom.content(info, _("Show some statistics of Xray. If nothing here, enable statistics and / or observatory for Xray."));
dom.content(detail, result);
});
});
Expand Down

0 comments on commit 16d2ca8

Please sign in to comment.