From bcabe10a83dd82adc44ef4bbe13d34d42f967cbc Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 8 May 2024 10:55:40 +0200 Subject: [PATCH] Fix var names --- appliances/VRouter/WireGuard/main.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/appliances/VRouter/WireGuard/main.rb b/appliances/VRouter/WireGuard/main.rb index 82e05bdc..05d5eff3 100644 --- a/appliances/VRouter/WireGuard/main.rb +++ b/appliances/VRouter/WireGuard/main.rb @@ -37,7 +37,7 @@ def initialize(conf) #------------------------------------------------------------------- @wgpeer[:shared] = bash('wg genpsk', chomp: true) @wgpeer[:private] = bash('wg genkey', chomp: true) - @wgpeer[:public] = bash("wg pubkey <<< '#{private_k}'", chomp: true) + @wgpeer[:public] = bash("wg pubkey <<< '#{@wgpeer[:private]}'", chomp: true) @wgpeer[:allowedips] = conf[:allowedips] @@ -180,8 +180,11 @@ def wg_environment conf[:listenport] = ONEAPP_VNF_WG_LISTEN_PORT conf[:subnet] = IPAddr.new(ONEAPP_VNF_WG_SUBNET) conf[:dev] = ONEAPP_VNF_WG_DEVICE - conf[:num_peers] = ONEAPP_VNF_WG_PEERS - + conf[:num_peers] = begin + Integer(ONEAPP_VNF_WG_PEERS) + rescue + 5 + end #----------------------------------------------------------------------- # Return configuration # TODO Support multiple devices @@ -270,7 +273,7 @@ def execute # ------------------------------------------------------------------ msg :info, "[WireGuard::execute] Using configuration found in VM #{vm64}" - file "#{ETC_DIR}/#{conf[:dev]}.conf", + file "#{ETC_DIR}/#{opts[:dev]}.conf", Base64.strict_decode64(conf64), mode: 'u=rw,g=r,o=', overwrite: true @@ -292,15 +295,15 @@ def execute conf = ERB.new(<<~CONF, trim_mode: '-').result(binding) [Interface] - Address = <%= "#{conf[:subnet].succ}/#{conf[:subnet].prefix}" %> - ListenPort = <%= conf[:listenport] %> - PrivateKey = <%= conf[:server_private] %> + Address = <%= "#{opts[:subnet].succ}/#{opts[:subnet].prefix}" %> + ListenPort = <%= opts[:listenport] %> + PrivateKey = <%= opts[:server_private] %> <% peers.each do |p| %> <%= p.to_s_server %> <% end %> CONF - file "#{ETC_DIR}/#{conf[:dev]}.conf", + file "#{ETC_DIR}/#{opts[:dev]}.conf", conf, mode: 'u=rw,g=r,o=', overwrite: true @@ -329,11 +332,11 @@ def execute end end - msg :info, "[WireGuard::execute] bringing up #{conf[:dev]}" + msg :info, "[WireGuard::execute] bringing up #{opts[:dev]}" bash <<~BASH - wg-quick up '#{conf[:dev]}' - echo 1 > '/proc/sys/net/ipv4/conf/#{conf[:dev]}/forwarding' + wg-quick up '#{opts[:dev]}' + echo 1 > '/proc/sys/net/ipv4/conf/#{opts[:dev]}/forwarding' BASH end