From bc6e4dfe29165f484a7fb18a2e0f9b2ae3bfd809 Mon Sep 17 00:00:00 2001 From: Rafał Miłecki Date: Mon, 14 Sep 2020 18:31:07 +0200 Subject: luci-base: use actual JSON-RPC for verifying ubus RPC URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sending GET request to the main RPC base URL and expecting HTTP response code 400 had two flaws: 1. It was not verifying actual JSON-RPC interface availability 2. It did not allow implementing support for new requests Signed-off-by: Rafał Miłecki Acked-by: Jo-Philipp Wich --- modules/luci-base/htdocs/luci-static/resources/luci.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules/luci-base/htdocs/luci-static') diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 83c2807d77..faed3aa6d2 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -2553,10 +2553,16 @@ rpcBaseURL = Session.getLocalData('rpcBaseURL'); if (rpcBaseURL == null) { + var msg = { + jsonrpc: '2.0', + id: 'init', + method: 'list', + params: undefined + }; var rpcFallbackURL = this.url('admin/ubus'); - rpcBaseURL = Request.get(env.ubuspath).then(function(res) { - return (rpcBaseURL = (res.status == 400) ? env.ubuspath : rpcFallbackURL); + rpcBaseURL = Request.post(env.ubuspath, msg, { nobatch: true }).then(function(res) { + return (rpcBaseURL = res.status == 200 ? env.ubuspath : rpcFallbackURL); }, function() { return (rpcBaseURL = rpcFallbackURL); }).then(function(url) { -- cgit v1.2.3