Add DNS cookbook
authorTom Hughes <tom@compton.nu>
Mon, 17 Jun 2013 20:57:12 +0000 (21:57 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 17 Jun 2013 20:57:12 +0000 (21:57 +0100)
12 files changed:
cookbooks/dns/README.rdoc [new file with mode: 0644]
cookbooks/dns/files/default/html/dns.css [new file with mode: 0644]
cookbooks/dns/files/default/html/dns.js [new file with mode: 0644]
cookbooks/dns/files/default/post-receive [new file with mode: 0644]
cookbooks/dns/metadata.rb [new file with mode: 0644]
cookbooks/dns/recipes/default.rb [new file with mode: 0644]
cookbooks/dns/templates/default/apache.erb [new file with mode: 0644]
cookbooks/dns/templates/default/cron.erb [new file with mode: 0644]
cookbooks/dns/templates/default/dns-check.erb [new file with mode: 0755]
cookbooks/dns/templates/default/dns-update.erb [new file with mode: 0755]
cookbooks/dns/templates/default/index.html.erb [new file with mode: 0644]
cookbooks/dns/templates/default/zone.html.erb [new file with mode: 0644]

diff --git a/cookbooks/dns/README.rdoc b/cookbooks/dns/README.rdoc
new file mode 100644 (file)
index 0000000..3de2ec7
--- /dev/null
@@ -0,0 +1,8 @@
+= DESCRIPTION:
+
+= REQUIREMENTS:
+
+= ATTRIBUTES:
+
+= USAGE:
+
diff --git a/cookbooks/dns/files/default/html/dns.css b/cookbooks/dns/files/default/html/dns.css
new file mode 100644 (file)
index 0000000..0a22de6
--- /dev/null
@@ -0,0 +1,7 @@
+#map {
+  position: absolute;
+  top: 0px;
+  bottom: 0px;
+  left: 0px;
+  right: 0px;
+}
diff --git a/cookbooks/dns/files/default/html/dns.js b/cookbooks/dns/files/default/html/dns.js
new file mode 100644 (file)
index 0000000..0677292
--- /dev/null
@@ -0,0 +1,35 @@
+function createMap(divName, jsonFile) {
+  // Create a map
+  var map = L.map(divName);
+
+  // Add OpenStreetMap layer
+  L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
+    attribution: "© <a target=\"_parent\" href=\"http://www.openstreetmap.org\">OpenStreetMap</a> and contributors, under an <a target=\"_parent\" href=\"http://www.openstreetmap.org/copyright\">open license</a>",
+    maxZoom: 18
+  }).addTo(map);
+
+  // Add the JSON file as an overlay
+  $.ajax({
+    url: jsonFile,
+    success: function(json) {
+      var jsonLayer = L.geoJson(json, {
+        style: function(feature) {
+          return { color: feature.properties.colour, weight: 2, opacity: 1 }
+        },
+        onEachFeature: function (feature, layer) {
+          layer.bindPopup(feature.properties.country + " via " + feature.properties.server);
+          layer.on("mouseover", function () {
+            this.setStyle({ weight: 5 });
+          });
+          layer.on("mouseout", function () {
+            this.setStyle({ weight: 2 });
+          });
+        }
+      }).addTo(map);
+
+      map.fitBounds(jsonLayer.getBounds());
+    }
+  });
+
+  return map;
+}
diff --git a/cookbooks/dns/files/default/post-receive b/cookbooks/dns/files/default/post-receive
new file mode 100644 (file)
index 0000000..0d8d82e
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/zsh
+
+# DO NOT EDIT - This file is being maintained by Chef
+
+unset GIT_DIR
+
+while read oldrev newrev refname
+do
+  if [[ "$refname" = "refs/heads/master" ]]
+  then
+    /usr/local/bin/dns-update
+  fi
+done
diff --git a/cookbooks/dns/metadata.rb b/cookbooks/dns/metadata.rb
new file mode 100644 (file)
index 0000000..d2b4f54
--- /dev/null
@@ -0,0 +1,6 @@
+maintainer        "OpenStreetMap Administrators"
+maintainer_email  "admins@openstreetmap.org"
+license           "Apache 2.0"
+description       "Configure DNS management"
+long_description  IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version           "1.0.0"
diff --git a/cookbooks/dns/recipes/default.rb b/cookbooks/dns/recipes/default.rb
new file mode 100644 (file)
index 0000000..5486014
--- /dev/null
@@ -0,0 +1,121 @@
+#
+# Cookbook Name:: dns
+# Recipe:: default
+#
+# Copyright 2011, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_recipe "git"
+include_recipe "apache"
+
+passwords = data_bag_item("dns", "passwords")
+
+package "make"
+
+package "perl"
+package "libxml-treebuilder-perl"
+package "libxml-writer-perl"
+package "libyaml-perl"
+package "libwww-perl"
+package "libjson-xs-perl"
+
+directory "/srv/dns.openstreetmap.org" do
+  owner "root"
+  group "root"
+  mode 0755
+end
+
+remote_directory "/srv/dns.openstreetmap.org/html" do
+  source "html"
+  owner "root"
+  group "root"
+  mode 0755
+  files_owner "root"
+  files_group "root"
+  files_mode 0644
+end
+
+zones = Array.new
+
+Dir.glob("/var/lib/dns/kml/*.kml").each do |kmlfile|
+  zone = File.basename(kmlfile, ".kml")
+
+  template "/srv/dns.openstreetmap.org/html/#{zone}.html" do
+    source "zone.html.erb"
+    owner "root"
+    group "root"
+    mode 0644
+    variables :zone => zone
+  end
+
+  zones.push(zone)
+end
+
+template "/srv/dns.openstreetmap.org/html/index.html" do
+  source "index.html.erb"
+  owner "root"
+  group "root"
+  mode 0644
+  variables :zones => zones
+end
+
+apache_site "dns.openstreetmap.org" do 
+  template "apache.erb"
+  directory "/srv/dns.openstreetmap.org"
+end
+
+template "/usr/local/bin/dns-update" do
+  source "dns-update.erb"
+  owner "root"
+  group "git"
+  mode 0750
+  variables :passwords => passwords
+end
+
+execute "dns-update" do
+  action :nothing
+  command "/usr/local/bin/dns-update"
+  user "git"
+  group "git"
+end
+
+directory "/var/lib/dns" do
+  owner "git"
+  group "git"
+  mode 02775
+  notifies :run, resources(:execute => "dns-update")
+end
+
+cookbook_file "#{node[:dns][:repository]}/hooks/post-receive" do
+  source "post-receive"
+  owner "git"
+  group "git"
+  mode 0750
+end
+
+template "/usr/local/bin/dns-check" do
+  source "dns-check.erb"
+  owner "root"
+  group "git"
+  mode 0750
+  variables :passwords => passwords
+end
+
+template "/etc/cron.d/dns" do
+  source "cron.erb"
+  owner "root"
+  group "root"
+  mode 0644
+end
diff --git a/cookbooks/dns/templates/default/apache.erb b/cookbooks/dns/templates/default/apache.erb
new file mode 100644 (file)
index 0000000..478ca42
--- /dev/null
@@ -0,0 +1,12 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+<VirtualHost *:80>
+       ServerName <%= @name %>
+       ServerAdmin webmaster@openstreetmap.org
+
+       CustomLog /var/log/apache2/<%= @name %>-access.log combined
+       ErrorLog /var/log/apache2/<%= @name %>-error.log
+
+       DocumentRoot <%= @directory %>/html
+       Alias /json/ /var/lib/dns/json/
+</VirtualHost>
diff --git a/cookbooks/dns/templates/default/cron.erb b/cookbooks/dns/templates/default/cron.erb
new file mode 100644 (file)
index 0000000..5ab9b3a
--- /dev/null
@@ -0,0 +1,3 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+*/3 * * * * git /usr/local/bin/dns-check
diff --git a/cookbooks/dns/templates/default/dns-check.erb b/cookbooks/dns/templates/default/dns-check.erb
new file mode 100755 (executable)
index 0000000..24fc320
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+export RSYNC_PASSWORD=<%= @passwords["rsync"] %>
+export PINGDOM_USERNAME=pingdom@openstreetmap.org
+export PINGDOM_PASSWORD=<%= @passwords["pingdom"] %>
+
+make --quiet --directory=/var/lib/dns --assume-new=lib/countries.xml update > /dev/null
diff --git a/cookbooks/dns/templates/default/dns-update.erb b/cookbooks/dns/templates/default/dns-update.erb
new file mode 100755 (executable)
index 0000000..596a4dd
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# DO NOT EDIT - This file is being maintained by Chef
+
+umask 0002
+
+export RSYNC_PASSWORD=<%= @passwords["rsync"] %>
+export PINGDOM_USERNAME=pingdom@openstreetmap.org
+export PINGDOM_PASSWORD=<%= @passwords["pingdom"] %>
+
+cd /var/lib/dns
+
+if [ ! -d .git ]
+then
+  git clone /var/lib/git/dns.git /var/lib/dns
+fi
+
+git pull -q
+
+make update
diff --git a/cookbooks/dns/templates/default/index.html.erb b/cookbooks/dns/templates/default/index.html.erb
new file mode 100644 (file)
index 0000000..3a70473
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+    <title>GeoDNS - Zones</title>
+  </head>
+  <body>
+    <h1 align="center">GeoDNS Zones</h1>
+    <% @zones.each do |zone| -%>
+    <h2 align="center"><a href="<%= zone %>.html"><%= zone %></a></h2>
+    <% end -%>
+  </body>
+</html>
diff --git a/cookbooks/dns/templates/default/zone.html.erb b/cookbooks/dns/templates/default/zone.html.erb
new file mode 100644 (file)
index 0000000..792b65c
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+    <title>GeoDNS - <%= @zone %></title>
+    <link rel="stylesheet" href="dns.css" type="text/css" media="all" />
+    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css" />
+    <!--[if lte IE 8]>
+    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.ie.css" />
+    <![endif]-->
+    <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
+    <script type="text/javascript" src="dns.js"></script>
+  </head>
+  <body onload="createMap('map', 'json/<%= @zone %>.json')">
+    <div id="map"></div>
+  </body>
+</html>