From patchwork Tue Sep 15 07:15:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1364142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=N0lQ90UO; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=iDWW4vbl; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BrF1H5HNNz9sVM for ; Tue, 15 Sep 2020 17:17:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=zTMe9WnjbCTHQ3uqibJFKGae4oOtoIXzJdEfVVad1/A=; b=N0lQ90UOZL3y+f5n+3/2xl8iSG XKdEzBMlV+sYbtG+WNM6Q9OroI1ASo9U5gVCqSB/z5d78WoHNLzMR0zwEzorfBvQ1vk+pohl6S4iF 1i9Fra0/mV6C4MliIjlKqjGreWpc+199AloXYN7WepG8aiyZC99me4HALRLUXtLyKPxZ0IBd7GlW2 bS76WtKAF93OfT9cR+ZlI0T+6bfUIWONFj4Lb8exnOjhjaNI5LD/Q407GFFedQenRS8MmZ1L/DUOc IJoh88GXAi+jXMHWTIK4q6Ndml5IvM7mpMoQu0HUDmTbx+ka1Xh2+8n0BgfVuedfJzyg5oGDptriw FYNt+zAQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kI5CF-0007pJ-LT; Tue, 15 Sep 2020 07:16:11 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kI5CD-0007ou-8D for openwrt-devel@lists.openwrt.org; Tue, 15 Sep 2020 07:16:10 +0000 Received: by mail-lf1-x144.google.com with SMTP id y2so1946599lfy.10 for ; Tue, 15 Sep 2020 00:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9P6TDrYNzWD4JZToOtNMuaDkK2C31r52LFnBVCYnW+M=; b=iDWW4vbl71mi2h+Uz8wVc4dMAqiulC2ZCjopS5WVm4mCxKtJMLOI/nYD8dwghXQe5x FHrxUljIEGqssSt+4N0I7/3macwTwf2PIJDJs3z1wtanb/tkpS5RWECvQJMge2OBGlNg JXcVfqiWUCXA/N7M1Qel+6uIVbm8D5ZHrm1/u7V4XJKgWm0D6R3xCisGfj7EhTAsefUg odlzI6cV6CUbw/29VC0sAL3pVRg1C0bjEra6VyNO+TJ1otzv8JgTrK7Ga69gaR9dV7A5 O305pplQtI8+8FkAySMA1qLdemHFT5aBtSWw3e2ChdiwROR4mYB/KPKanapXsxvGgZ+N 7aAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9P6TDrYNzWD4JZToOtNMuaDkK2C31r52LFnBVCYnW+M=; b=mIkLP70oyRkrLGoTmn4PIfrRvkOlAsYxXBe9M0/HqX3XkkjcFHfabFZsfA8wAeOwXI et2GbfrgjXdOk/RZSblNdkR4OVgtk74tyVNo5Gx2pq3k71dqkcvxxthTiWQGSaaTJv0M LklvgWfMzMPAlnhVvJAwHW39dWFVKP/BFh8Yo0coAlbd29f20I3QA4NZ9rE8ofHgCMYV /wiCrgXbnbHVPWERvCCQgrHKgE4qnfilOSJAMZYKwZ8900SZp9bX+4oLQqMjPEtJOqc7 KuXAN/sC6ot/bYNgOCXXUDBaJts3wrwIs5WKGrbUI0xEMYZX73KMnZ10Hbb2nuI8Zb/s 2mBg== X-Gm-Message-State: AOAM530ZZ0X3qX+0W55ZfP+NAgqI/uAkIGxSB9YysEUslZ3PIzgwlFLa P9fJuDWq9i16yXoqL2eohNOWK4B0l6I= X-Google-Smtp-Source: ABdhPJzCjyqK1XhfjLlY/4XqprNnsN1jo4aL2seQkiL3x4mveBRFGYqYdOfNjujcREJrxOy2UI5zEw== X-Received: by 2002:a19:23c6:: with SMTP id j189mr6449449lfj.79.1600154167224; Tue, 15 Sep 2020 00:16:07 -0700 (PDT) Received: from localhost.localdomain (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id e9sm3785574lfn.237.2020.09.15.00.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 00:16:06 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH PROOF luci] luci-base: switch to the new ubus API Date: Tue, 15 Sep 2020 09:15:51 +0200 Message-Id: <20200915071551.7716-1-zajec5@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200915_031609_380624_6A3E09E0 X-CRM114-Status: GOOD ( 14.55 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:144 listed in] [list.dnswl.org] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Jo-Philipp Wich Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki This is proof of concept for the new uhttpd ubus API. It switches LuCI (in a bit hacky way) to the new API. Signed-off-by: Rafał Miłecki --- .../htdocs/luci-static/resources/luci.js | 5 +++ .../htdocs/luci-static/resources/rpc.js | 31 +++++-------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index e285f999e..9d2c52d77 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -739,11 +739,13 @@ if (!opt.cache) opt.url += ((/\?/).test(opt.url) ? '&' : '?') + (new Date()).getTime(); +/* if (isQueueableRequest(opt)) { requestQueue.push([opt, rejectFn, resolveFn]); requestAnimationFrame(flushRequestQueue); return; } +*/ if ('username' in opt && 'password' in opt) opt.xhr.open(opt.method, opt.url, true, opt.username, opt.password); @@ -758,6 +760,9 @@ if ('timeout' in opt) opt.xhr.timeout = +opt.timeout; + if ('authorization' in opt) + opt.xhr.setRequestHeader('Authorization', 'Bearer %s'.format(opt.authorization)); + if ('credentials' in opt) opt.xhr.withCredentials = !!opt.credentials; diff --git a/modules/luci-base/htdocs/luci-static/resources/rpc.js b/modules/luci-base/htdocs/luci-static/resources/rpc.js index 7bfc91336..5d9569d87 100644 --- a/modules/luci-base/htdocs/luci-static/resources/rpc.js +++ b/modules/luci-base/htdocs/luci-static/resources/rpc.js @@ -18,8 +18,8 @@ var rpcRequestID = 1, */ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { /* privates */ - call: function(req, cb, nobatch) { - var q = ''; + call: function(object, req, cb) { + var q = 'call/%s'.format(object); if (Array.isArray(req)) { if (req.length == 0) @@ -33,13 +33,10 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { req[i].params[2] ); } - else if (req.params) { - q += '/%s.%s'.format(req.params[1], req.params[2]); - } return request.post(rpcBaseURL + q, req, { timeout: (L.env.rpctimeout || 20) * 1000, - nobatch: nobatch, + authorization: rpcSessionID, credentials: true }).then(cb, cb); }, @@ -89,16 +86,7 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { return req.reject(e); } - if (!req.object && !req.method) { - ret = msg.result; - } - else if (Array.isArray(msg.result)) { - if (req.raise && msg.result[0] !== 0) - L.raise('RPCError', 'RPC call to %s/%s failed with ubus code %d: %s', - req.object, req.method, msg.result[0], this.getStatusText(msg.result[0])); - - ret = (msg.result.length > 1) ? msg.result[1] : msg.result[0]; - } + ret = msg.result; if (req.expect) { for (var key in req.expect) { @@ -332,17 +320,12 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { var msg = { jsonrpc: '2.0', id: rpcRequestID++, - method: 'call', - params: [ - rpcSessionID, - options.object, - options.method, - params - ] + method: options.method, + params: params }; /* call rpc */ - rpc.call(msg, rpc.parseCallReply.bind(rpc, req), options.nobatch); + rpc.call(options.object, msg, rpc.parseCallReply.bind(rpc, req)); }); }, this, this, options); },