luci-base: use actual JSON-RPC for verifying ubus RPC URL
authorRafał Miłecki <rafal@milecki.pl>
Mon, 14 Sep 2020 16:31:07 +0000 (18:31 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 15 Sep 2020 08:34:39 +0000 (10:34 +0200)
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 <rafal@milecki.pl>
Acked-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 83c2807d77250212377abd76d95b38c078b7687f..faed3aa6d2c7e76a6b0c47aa5a3eb86a48d23d9b 100644 (file)
                                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) {