summaryrefslogtreecommitdiffhomepage
path: root/applications
diff options
context:
space:
mode:
authorlvoegl <lvoegl@tdt.de>2021-09-08 12:56:10 +0200
committerLukas Voegl <lvoegl@tdt.de>2021-09-17 14:15:56 +0200
commit8530232f518150141a756e7a9fe4297dcf326639 (patch)
treec384683892b83e4dd750f3b118d54038ae7c71f9 /applications
parentd98935c45b7affde6b5323d87473ea82736a1335 (diff)
luci-proto-wireguard: client qr code generation
Signed-off-by: lvoegl <lvoegl@tdt.de>
Diffstat (limited to 'applications')
-rwxr-xr-x[-rw-r--r--]applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard17
1 files changed, 17 insertions, 0 deletions
diff --git a/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard b/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard
index 7354ad4922..fd3b4c8c44 100644..100755
--- 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 = {}