Page MenuHomeDevCentral

D833.id2119.diff
No OneTemporary

D833.id2119.diff

diff --git a/roles/mailserver/dkim/files/bin/get-dkim-dns-entries b/roles/mailserver/dkim/files/bin/get-dkim-dns-entries
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/dkim/files/bin/get-dkim-dns-entries
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# Parses arguments
+if [ $# -eq 0 ]
+then
+ echo "Usage: `basename $0` <domain>"
+ exit 1
+fi
+
+DOMAIN=$1
+DIR=/etc/opendkim/keys/$DOMAIN
+
+if [ ! -d "$DIR" ]
+then
+ echo "Directory not found: $DIR"
+ exit 2
+fi
+
+for f in $DIR/*.txt
+do
+ get-dkim-dns-entry $f
+done
diff --git a/roles/mailserver/dkim/files/bin/get-dkim-dns-entry b/roles/mailserver/dkim/files/bin/get-dkim-dns-entry
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/dkim/files/bin/get-dkim-dns-entry
@@ -0,0 +1,57 @@
+#!/usr/bin/env php
+<?php
+
+///
+/// Parse arguments
+///
+
+if ($argc < 2) {
+ fwrite(STDERR, "Usage: $argv[0] $file\n");
+ exit(1);
+}
+
+$file = $argv[1];
+
+if (!file_exists($file)) {
+ fwrite(STDERR, "File not found: $file\n");
+ exit(2);
+}
+
+///
+/// Reads file
+///
+
+function to_one_line ($string) {
+ return str_replace(["\r", "\n"], "", trim($string));
+}
+
+function to_one_line_from_bind ($string) {
+ $toReturn = "";
+ foreach (explode('"', $string) as $fragment) {
+ if (trim($fragment) !== "") {
+ $toReturn .= $fragment;
+ }
+ }
+ return $toReturn;
+}
+
+function get_dns_record ($content) {
+ $record = to_one_line($content);
+ if (!preg_match("/(.*)\._domainkey/", $record, $matches)) {
+ throw new Exception("Can't parse file.");
+ }
+ $subdomain = $matches[0];
+
+ if (!preg_match("/\s+IN\s+TXT\s+\((.*)\)/", $record, $matches)) {
+ throw new Exception("Can't parse file.");
+ }
+ $value = to_one_line_from_bind($matches[1]);
+
+ return "$subdomain TXT $value";
+}
+
+try {
+ echo get_dns_record(file_get_contents($file)), "\n";
+} catch (Exception $ex) {
+ fwrite(STDERR, $ex->getMessage());
+}
diff --git a/roles/mailserver/dkim/files/bin/get-dkim-dns-entry.php b/roles/mailserver/dkim/files/bin/get-dkim-dns-entry.php
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/dkim/files/bin/get-dkim-dns-entry.php
@@ -0,0 +1,57 @@
+#!/usr/bin/env php
+<?php
+
+///
+/// Parse arguments
+///
+
+if ($argc < 2) {
+ fwrite(STDERR, "Usage: $argv[0] $file\n");
+ exit(1);
+}
+
+$file = $argv[1];
+
+if (!file_exists($file)) {
+ fwrite(STDERR, "File not found: $file\n");
+ exit(2);
+}
+
+///
+/// Reads file
+///
+
+function to_one_line ($string) {
+ return str_replace(["\r", "\n"], "", trim($string));
+}
+
+function to_one_line_from_bind ($string) {
+ $toReturn = "";
+ foreach (explode('"', $string) as $fragment) {
+ if (trim($fragment) !== "") {
+ $toReturn .= $fragment;
+ }
+ }
+ return $toReturn;
+}
+
+function get_dns_record ($content) {
+ $record = to_one_line($content);
+ if (!preg_match("/(.*)\._domainkey/", $record, $matches)) {
+ throw new Exception("Can't parse file.");
+ }
+ $subdomain = $matches[0];
+
+ if (!preg_match("/\s+IN\s+TXT\s+\((.*)\)/", $record, $matches)) {
+ throw new Exception("Can't parse file.");
+ }
+ $value = to_one_line_from_bind($matches[1]);
+
+ return "$subdomain TXT $value";
+}
+
+try {
+ echo get_dns_record(file_get_contents($file)), "\n";
+} catch (Exception $ex) {
+ fwrite(STDERR, $ex->getMessage());
+}
diff --git a/roles/mailserver/dkim/files/bin/get-dkim-key-table b/roles/mailserver/dkim/files/bin/get-dkim-key-table
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/dkim/files/bin/get-dkim-key-table
@@ -0,0 +1,11 @@
+#!/bin/sh
+for d in /etc/opendkim/keys/*
+do
+ DOMAIN=`basename $d`
+
+ for f in $d/*.private
+ do
+ SELECTOR=`basename $f .private`
+ echo "$SELECTOR._domainkey.$DOMAIN $DOMAIN:$SELECTOR:$f"
+ done
+done
diff --git a/roles/mailserver/dkim/files/bin/get-dkim-signing-table b/roles/mailserver/dkim/files/bin/get-dkim-signing-table
new file mode 100755
--- /dev/null
+++ b/roles/mailserver/dkim/files/bin/get-dkim-signing-table
@@ -0,0 +1,11 @@
+#!/bin/sh
+for d in /etc/opendkim/keys/*
+do
+ DOMAIN=`basename $d`
+
+ for f in $d/*.private
+ do
+ SELECTOR=`basename $f .private`
+ echo "$DOMAIN $SELECTOR._domainkey.$DOMAIN"
+ done
+done
diff --git a/roles/mailserver/dkim/files/etc/Makefile b/roles/mailserver/dkim/files/etc/Makefile
new file mode 100644
--- /dev/null
+++ b/roles/mailserver/dkim/files/etc/Makefile
@@ -0,0 +1,13 @@
+RM=rm -f
+
+all: KeyTable SigningTable
+
+clean:
+ ${RM} KeyTable SigningTable
+
+KeyTable:
+ get-dkim-key-table > KeyTable
+
+SigningTable:
+ get-dkim-signing-table > SigningTable
+
diff --git a/roles/mailserver/dkim/files/etc/TrustedHosts b/roles/mailserver/dkim/files/etc/TrustedHosts
new file mode 100644
--- /dev/null
+++ b/roles/mailserver/dkim/files/etc/TrustedHosts
@@ -0,0 +1,5 @@
+127.0.0.1
+localhost
+10.0.3.8
+dwellers.nasqueron.org
+mail.nasqueron.org
diff --git a/roles/mailserver/dkim/init.sls b/roles/mailserver/dkim/init.sls
new file mode 100644
--- /dev/null
+++ b/roles/mailserver/dkim/init.sls
@@ -0,0 +1,55 @@
+# -------------------------------------------------------------
+# Salt — OpenDKIM configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Created: 2017-01-14
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+# -------------------------------------------------------------
+# OpenDKIM configuration files
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+opendkim_config_files:
+ file.recurse:
+ {% if grains['os'] == 'FreeBSD' %}
+ - name: /usr/local/etc/opendkim
+ {% else %}
+ - name: /etc/opendkim
+ {% endif %}
+ - source: salt://roles/mailserver/dkim/files/etc
+ - include_empty: True
+ - clean: False
+ - dir_mode: 711
+ - file_mode: 644
+
+opendkim_keys_directory:
+ file.directory:
+ {% if grains['os'] == 'FreeBSD' %}
+ - name: /usr/local/etc/opendkim/keys
+ {% else %}
+ - name: /etc/opendkim/keys
+ {% endif %}
+ - dir_mode: 711
+ - user: opendkim
+ - group: opendkim
+
+# -------------------------------------------------------------
+# OpenDKIM binaries
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+opendkim_software:
+ pkg:
+ - installed
+ - pkgs:
+ - opendkim
+ {% if grains['os'] == 'Debian' or grains['os'] == 'Ubuntu' %}
+ - opendkim-tools
+ {% endif %}
+
+opendkim_extra_utilities:
+ file.recurse:
+ - name: /usr/local/bin
+ - source: salt://roles/mailserver/dkim/files/bin
+ - dir_mode: 755
+ - file_mode: 755

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 22:09 (5 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2246811
Default Alt Text
D833.id2119.diff (6 KB)

Event Timeline