summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-wireguard/root/usr
diff options
context:
space:
mode:
authorlvoegl <lvoegl@tdt.de>2021-09-10 14:01:53 +0200
committerLukas Voegl <lvoegl@tdt.de>2021-09-17 14:22:54 +0200
commit03d615f62c83cf3c8aba01e0abcb1b3f93409133 (patch)
tree514eedfffccd6affd3e8420dc38897634636c695 /applications/luci-app-wireguard/root/usr
parent8530232f518150141a756e7a9fe4297dcf326639 (diff)
luci-proto-wireguard: add more options to qr code
Signed-off-by: lvoegl <lvoegl@tdt.de>
Diffstat (limited to 'applications/luci-app-wireguard/root/usr')
-rwxr-xr-xapplications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard27
1 files changed, 25 insertions, 2 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 fd3b4c8c44..94374b07d7 100755
--- a/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard
+++ b/applications/luci-app-wireguard/root/usr/libexec/rpcd/luci.wireguard
@@ -16,15 +16,38 @@ local methods = {
end
},
generateQrCode = {
- args = {privkey = "privkey"},
+ args = {privkey = "privkey", psk = "psk", allowed_ips = {"allowed_ips"}},
call = function(args)
local qr_code
if fs.access("/usr/bin/qrencode") then
+ local psk = args.psk
+ local listen_port = args.listen_port
+ local allowed_ips = args.allowed_ips
+
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"
+ local iface_qr = {
+ "[Interface]",
+ "PrivateKey = " .. client_privkey,
+ }
+
+ local peer_qr = {
+ "[Peer]",
+ "PublicKey = " .. pubkey,
+ }
+
+ if not allowed_ips or next(allowed_ips) == nil then
+ allowed_ips = {"0.0.0.0/0", "::/0"}
+ end
+ table.insert(peer_qr, "AllowedIPs = " .. table.concat(allowed_ips, ", "))
+
+ if psk then
+ table.insert(peer_qr, "PresharedKey = " .. psk)
+ end
+
+ qr_enc = table.concat(iface_qr, "\n") .. "\n\n" .. table.concat(peer_qr, "\n")
qr_code = sys.exec("/usr/bin/qrencode --inline --8bit --type=SVG --output=- '" .. qr_enc .. "' 2>/dev/null")
end