update bird configuration in openvpn script

This commit is contained in:
Jörg Thalheim 2015-01-16 18:47:28 +01:00
parent 50636135e4
commit bb224c163a

View File

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