commit 6ce5a542f29cec932238df15f277af370580c13f Author: Jörg Thalheim Date: Tue Jan 13 08:19:32 2015 +0100 first commit diff --git a/registry.json b/registry.json new file mode 100644 index 0000000..7547299 --- /dev/null +++ b/registry.json @@ -0,0 +1,77 @@ +{ + "zone": { + "soa": "eve.dn42.", + "ns": "eve.dn42.", + "serial": 93, + "refresh": "1H", + "retry": "4H", + "expire": "3W", + "minimum": "1D", + "v4_subnet": "172.23.75.0/24", + "v6_subnet": "fdc0:4992:6a6d::/48" + }, + "host": { + "as": "4242420092", + "v4_tunnel": "172.23.75.1", + "start-port": 5001, + "end-port": 5020 + }, + "network": { + "hax404": { + "as": "76114", + "type": "openvpn", + "proto": "udp6", + "remote": "2a03:4000:6:145:11::1", + "v4_tunnel": "172.23.136.65", + "lport": 5001, + "rport": 5001 + }, + "chelnok": { + "as": "4242421375", + "type": "openvpn", + "proto": "udp6", + "remote": "portal.chelnok.de", + "v4_tunnel": "172.23.64.1", + "rport": 2322, + "lport": 5002 + }, + "wetu": { + "as": "64698", + "type": "openvpn", + "proto": "udp6", + "remote": "dn42.wetu.c3d2.de", + "v4_tunnel": "172.22.100.254", + "lport": 5003, + "rport": 5003 + }, + "tobee": { + "as": "4242420022", + "type": "openvpn", + "proto": "udp6", + "remote": "2001:1640:3::a", + "v4_tunnel": "172.23.67.1", + "lport": 5018, + "rport": 5018 + }, + "flatbert": { + "type": "openvpn", + "proto": "udp", + "float": true, + "v4_tunnel": "172.22.99.253", + "lport": 5002 + }, + "eve": { + "type": "local", + "ipv4": "172.23.75.1" + }, + "matchbox": { + "type": "tinc", + "ipv4": "172.23.75.2" + }, + "turingmachine": { + "type": "tinc", + "ipv4": "172.23.75.3", + "mac": "02:1f:02:a6:62:8e" + } + } +} diff --git a/scripts/dhcp b/scripts/dhcp new file mode 100755 index 0000000..4fcd8ef --- /dev/null +++ b/scripts/dhcp @@ -0,0 +1,88 @@ +#!/usr/bin/ruby +require_relative "utils" +require "optparse" + +class DhcpRegistry < Registry + def add_lease(name, macaddress, ipv4, ipv6) + data["network"][name] ||= {} + host = data["network"][name] + host["macaddress"] = macaddress + host["ipv4"] = ipv4 if ipv4 + host["ipv6"] = ipv6 if ipv6 + end + + def remove_lease(name) + if data["network"].delete(name).nil? + die "no such lease name #{name} in registry.json" + end + end + + def update_leases + template_path = Pathname.new(File.expand_path("../../templates", __FILE__)) + dhcp_template = Template.new(template_path.join("dhcp.conf.erb")) + static_leases = data["network"].select do |name, data| + data["mac"] && (data["ipv4"] || data["ipv6"]) + end.map do |name, data| + TemplateContext.new(data.merge(name: name)) + end + dhcp_path = Pathname.new(File.expand_path("../../dhcp.peers.conf", __FILE__)) + File.open(dhcp_path, "w+").write(dhcp_template.render(leases: static_leases)) + end +end + +GLOBAL_OPTIONS = OptionParser.new do |opts| + opts.banner = "Usage: dhcp [options] [subcommand [options]]" + opts.separator "" + opts.separator < + +host <%= lease.name %> { + hardware ethernet <%= lease.mac %>; +<% if lease.ipv4 -%> + fixed-address <%= lease.ipv4 %>; +<% end -%> +<% if lease.ipv6 -%> + fixed-address6 <%= lease.ipv6 %>; +<% end -%> +} +<% end -%> diff --git a/templates/dn42-zone.erb b/templates/dn42-zone.erb new file mode 100644 index 0000000..2e5eb81 --- /dev/null +++ b/templates/dn42-zone.erb @@ -0,0 +1,24 @@ +@ IN SOA <%= data["zone"]["soa"] %> hostmaster ( + <%= data["zone"]["serial"] %> ; serial + <%= data["zone"]["refresh"] %> ; refresh + <%= data["zone"]["retry"] %> ; retry + <%= data["zone"]["expire"] %> ; expire + <%= data["zone"]["minimum"] %>) ; minimum + NS <%= data["zone"]["ns"] %> + +<% data["network"].each do |name, value| %> +<% if value["cname"] -%> +<%= name %> CNAME <%= value["cname"] %> +<% end -%> +<% if value["srv"] -%> +<%= name %> SRV <%= value["srv"] %> +<% end -%> +<% if value["ipv4"] -%> +<%= name %> A <%= ip(value["ipv4"]) %> +ipv4.<%= name %> A <%= ip(value["ipv4"]) %> +<% end -%> +<% if value["ipv6"] -%> +<%= name %> AAAA <%= ip(value["ipv6"]) %> +ipv6.<%= name %> AAAA <%= ip(value["ipv6"]) %> +<% end -%> +<% end -%> diff --git a/templates/openvpn.conf.erb b/templates/openvpn.conf.erb new file mode 100644 index 0000000..052172f --- /dev/null +++ b/templates/openvpn.conf.erb @@ -0,0 +1,24 @@ +daemon +proto <%= proto %> +mode p2p +dev-type tun +comp-lzo +dev <%= name %> +persist-key +persist-tun +user nobody +group nogroup + +<% if float %> +float +port <%= lport %> +<% else %> +remote <%= remote %> +rport <%= rport %> +lport <%= lport %> +<% end %> + +ifconfig <%= own_v4_tunnel %> <%= v4_tunnel %> +secret /etc/openvpn/<%= name %>.key +script-security 2 execve +up "/etc/openvpn/scripts/ipv6.sh fd70:96c9:ef25::fe:6/124 <%= name %>" diff --git a/templates/rdns-zone.erb b/templates/rdns-zone.erb new file mode 100644 index 0000000..f7e9393 --- /dev/null +++ b/templates/rdns-zone.erb @@ -0,0 +1,11 @@ +@ IN SOA <%= data["zone"]["soa"] %> hostmaster ( + <%= data["zone"]["serial"] %> ; serial + <%= data["zone"]["refresh"] %> ; refresh + <%= data["zone"]["retry"] %> ; retry + <%= data["zone"]["expire"] %> ; expire + <%= data["zone"]["minimum"] %>) ; minimum + NS <%= data["zone"]["ns"] %> + +<% pointers do |addr, name| %> +<%= addr %> PTR <%= name %>.lxc. +<% end -%>