diff --git a/scripts/openvpn b/scripts/openvpn index eacdc04..d5be0ba 100755 --- a/scripts/openvpn +++ b/scripts/openvpn @@ -1,5 +1,6 @@ #!/usr/bin/env ruby require_relative "utils" +require_relative "bird" require "netaddr" require "optparse" require "set" @@ -8,12 +9,12 @@ class OpenvpnRegistry < Registry def initialize super @host = data["host"] - @v4_tunnel_ip = @host["v4_tunnel"] + @v4_tunnel_ip = @host["v4_tunnel"] or die("v4_tunnel not set for host") + @start_port = @host["start_port"].to_i @end_port = @host["end_port"].to_i @openvpn_path = Pathname.new(File.expand_path("../../openvpn", __FILE__)) - die("v4_tunnel not set for host") unless @v4_tunnel_ip end def add_peer(name, peer) @@ -71,9 +72,9 @@ class OpenvpnRegistry < Registry params["lport"] = peer["rport"] end params["remote"] = if peer["proto"] == "udp6" - data["host"]["v6_public"] + @host["v6_public"] else - data["host"]["v4_public"] + @host["v4_public"] end params end @@ -138,6 +139,7 @@ class Application @registry.save @registry.update_configurations + BgpRegistry.new.update_configs end def add_command(args) options = {} @@ -176,6 +178,7 @@ class Application options["proto"] = proto @registry.add_peer(name, options) end + def remove_command(args) parser = OptionParser.new do |opts| opts.banner = "Usage: openvpn remove NAME"