summaryrefslogtreecommitdiffhomepage
path: root/protocols/luci-proto-wireguard/htdocs/luci-static/resources
diff options
context:
space:
mode:
authorPaul Donald <newtwen+github@gmail.com>2024-05-01 18:43:51 +0200
committerPaul Donald <newtwen+github@gmail.com>2024-06-27 20:19:58 +0200
commit74f366a1e54f54079fde6e4906e7307f199127e5 (patch)
tree6524c542c3f43ec8873c6700faa8ccf3893708b6 /protocols/luci-proto-wireguard/htdocs/luci-static/resources
parentb2e7441a60e9d0fa9bda8a95fac61958a14cef85 (diff)
luci-proto-wireguard: adapt to use uqr
If for some reason luci-lib-uqr is absent, the GUI shows that the proto handler needs installing (since it now has a dep which is missing). Suitable action is to install the lib or remove/install wireguard again. Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Diffstat (limited to 'protocols/luci-proto-wireguard/htdocs/luci-static/resources')
-rw-r--r--protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js37
1 files changed, 13 insertions, 24 deletions
diff --git a/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js b/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js
index 9919687b92..05e0e275c7 100644
--- a/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js
+++ b/protocols/luci-proto-wireguard/htdocs/luci-static/resources/protocol/wireguard.js
@@ -7,6 +7,7 @@
'require form';
'require network';
'require validation';
+'require uqr';
var generateKey = rpc.declare({
object: 'luci.wireguard',
@@ -64,28 +65,16 @@ function generateDescription(name, texts) {
]);
}
-function invokeQREncode(data, code) {
- return fs.exec_direct('/usr/bin/qrencode', [
- '--inline', '--8bit', '--type=SVG',
- '--output=-', '--', data
- ]).then(function(svg) {
- code.style.opacity = '';
- dom.content(code, Object.assign(E(svg), { style: 'width:100%;height:auto' }));
- }).catch(function(error) {
- code.style.opacity = '';
-
- if (L.isObject(error) && error.name == 'NotFoundError') {
- dom.content(code, [
- Object.assign(E(qrIcon), { style: 'width:32px;height:32px;opacity:.2' }),
- E('p', _('The <em>qrencode</em> package is required for generating an QR code image of the configuration.'))
- ]);
- }
- else {
- dom.content(code, [
- _('Unable to generate QR code: %s').format(L.isObject(error) ? error.message : error)
- ]);
- }
- });
+function buildSVGQRCode(data, code) {
+ // pixel size larger than 4 clips right and bottom edges of complex configs
+ const options = {
+ pixelSize: 4,
+ whiteColor: 'white',
+ blackColor: 'black'
+ };
+ const svg = uqr.renderSVG(data, options);
+ code.style.opacity = '';
+ dom.content(code, Object.assign(E(svg), { style: 'width:100%;height:auto' }));
}
var cbiKeyPairGenerate = form.DummyValue.extend({
@@ -779,7 +768,7 @@ return network.registerProtocol('wireguard', {
conf.firstChild.data = configGenerator(endpoint.getValue(), ips.getValue(), eips.getValue(), dns.getValue());
code.style.opacity = '.5';
- invokeQREncode(conf.firstChild.data, code);
+ buildSVGQRCode(conf.firstChild.data, code);
}
};
@@ -833,7 +822,7 @@ return network.registerProtocol('wireguard', {
}, [ peer_config ])
]);
- invokeQREncode(peer_config, node.firstChild);
+ buildSVGQRCode(peer_config, node.firstChild);
return node;
};