From 8530232f518150141a756e7a9fe4297dcf326639 Mon Sep 17 00:00:00 2001 From: lvoegl Date: Wed, 8 Sep 2021 12:56:10 +0200 Subject: luci-proto-wireguard: client qr code generation Signed-off-by: lvoegl --- .../root/usr/libexec/rpcd/luci.wireguard | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) mode change 100644 => 100755 applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard (limited to 'applications/luci-app-wireguard') diff --git a/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard b/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard old mode 100644 new mode 100755 index 7354ad4922..fd3b4c8c44 --- a/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard +++ b/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard @@ -4,6 +4,7 @@ local json = require "luci.jsonc" local sys = require "luci.sys" local io = require "io" local uci = require "uci" +local fs = require "nixio.fs" local methods = { generateKeyPair = { @@ -14,6 +15,22 @@ local methods = { return {keys = {priv = prv, pub = pub}} end }, + generateQrCode = { + args = {privkey = "privkey"}, + call = function(args) + local qr_code + + if fs.access("/usr/bin/qrencode") then + local pubkey = sys.exec("echo '" .. args.privkey .. "' | wg pubkey 2>/dev/null"):sub(1, -2) + local client_privkey = sys.exec("wg genkey 2>/dev/null"):sub(1, -2) + local qr_enc = "[Interface]\nPrivateKey = " .. client_privkey .. "\n[Peer]\nPublicKey = " .. pubkey .. "\nAllowedIPs = 0.0.0.0/0, ::/0" + + qr_code = sys.exec("/usr/bin/qrencode --inline --8bit --type=SVG --output=- '" .. qr_enc .. "' 2>/dev/null") + end + + return {qr_code = qr_code} + end + }, getWgInstances = { call = function() local data = {} -- cgit v1.2.3