'require form';
'require network';
'require validation';
+'require uqr';
var generateKey = rpc.declare({
object: 'luci.wireguard',
]);
}
-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({
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);
}
};
}, [ peer_config ])
]);
- invokeQREncode(peer_config, node.firstChild);
+ buildSVGQRCode(peer_config, node.firstChild);
return node;
};