--- mailgraph	2012-06-17 10:04:34.000000000 +0200
+++ mailgraph	2014-08-08 21:53:34.000000000 +0200
@@ -4,6 +4,7 @@
 # copyright (c) 2000-2007 ETH Zurich
 # copyright (c) 2000-2007 David Schweikert <david@schweikert.ch>
 # released under the GNU General Public License
+# with dane-patch Sebastian van de Meer <kernel-error@kernel-error.de>
 
 ######## Parse::Syslog 1.09 (automatically embedded) ########
 package Parse::Syslog;
@@ -380,9 +381,10 @@
 my $rrd = "mailgraph.rrd";
 my $rrd_virus = "mailgraph_virus.rrd";
 my $rrd_greylist = "mailgraph_greylist.rrd";
+my $rrd_dane = "mailgraph_dane.rrd";
 my $year;
 my $this_minute;
-my %sum = ( sent => 0, received => 0, bounced => 0, rejected => 0, virus => 0, spam => 0, greylisted => 0, delayed => 0);
+my %sum = ( sent => 0, received => 0, bounced => 0, rejected => 0, virus => 0, spam => 0, greylisted => 0, delayed => 0, anonymoustls => 0, trustedtls => 0, untrustedtls => 0, verifiedtls => 0);
 my $rrd_inited=0;
 
 my %opt = ();
@@ -398,6 +400,10 @@
 sub event_spam($);
 sub event_greylisted($);
 sub event_delayed($);
+sub event_anonymoustls($);
+sub event_trustedtls($);
+sub event_untrustedtls($);
+sub event_verifiedtls($);
 sub init_rrd($);
 sub update($);
 
@@ -421,6 +427,7 @@
 	print "  --no-mail-rrd      no update mail rrd\n";
 	print "  --no-virus-rrd     no update virus rrd\n";
 	print "  --no-greylist-rrd  no update greylist rrd\n";
+	print "  --no-dane-rrd  no update dane rrd\n";
 	print "  --rrd-name=NAME    use NAME.rrd and NAME_virus.rrd for the rrd files\n";
 	print "  --rbl-is-spam      count rbl rejects as spam\n";
 	print "  --virbl-is-virus   count virbl rejects as viruses\n";
@@ -435,7 +442,7 @@
 		'year|y=i', 'host=s', 'verbose|v', 'daemon|d!',
 		'daemon_pid|daemon-pid=s', 'daemon_rrd|daemon-rrd=s',
 		'daemon_log|daemon-log=s', 'ignore-localhost!', 'ignore-host=s@',
-		'no-mail-rrd', 'no-virus-rrd', 'no-greylist-rrd', 'rrd_name|rrd-name=s',
+		'no-mail-rrd', 'no-virus-rrd', 'no-greylist-rrd', 'no-dane-rrd', 'rrd_name|rrd-name=s',
 		'rbl-is-spam', 'virbl-is-virus'
 		) or exit(1);
 	usage if $opt{help};
@@ -450,7 +457,8 @@
 	$daemon_rrd_dir = $opt{daemon_rrd} if defined $opt{daemon_rrd};
 	$rrd		= $opt{rrd_name}.".rrd" if defined $opt{rrd_name};
 	$rrd_virus	= $opt{rrd_name}."_virus.rrd" if defined $opt{rrd_name};
-	$rrd_virus      = $opt{rrd_name}."_greylist.rrd" if defined $opt{rrd_name};
+	$rrd_greylist	= $opt{rrd_name}."_greylist.rrd" if defined $opt{rrd_name};
+	$rrd_dane	= $opt{rrd_name}."_dane.rrd" if defined $opt{rrd_name};
 
 	# compile --ignore-host regexps
 	if(defined $opt{'ignore-host'}) {
@@ -585,6 +593,27 @@
 	elsif(-f $rrd_greylist and ! defined $rrd_greylist) {
 		$this_minute = RRDs::last($rrd_greylist) + $rrdstep;
 	}
+	# dane rrd
+	if(! -f $rrd_dane and ! $opt{'no-dane-rrd'}) {
+		RRDs::create($rrd_dane, '--start', $m, '--step', $rrdstep,
+				'DS:anonymoustls:ABSOLUTE:'.($rrdstep*2).':0:U',
+				'DS:trustedtls:ABSOLUTE:'.($rrdstep*2).':0:U',
+				'DS:untrustedtls:ABSOLUTE:'.($rrdstep*2).':0:U',
+				'DS:verifiedtls:ABSOLUTE:'.($rrdstep*2).':0:U',
+				"RRA:AVERAGE:0.5:$day_steps:$realrows",   # day
+				"RRA:AVERAGE:0.5:$week_steps:$realrows",  # week
+				"RRA:AVERAGE:0.5:$month_steps:$realrows", # month
+				"RRA:AVERAGE:0.5:$year_steps:$realrows",  # year
+				"RRA:MAX:0.5:$day_steps:$realrows",   # day
+				"RRA:MAX:0.5:$week_steps:$realrows",  # week
+				"RRA:MAX:0.5:$month_steps:$realrows", # month
+				"RRA:MAX:0.5:$year_steps:$realrows",  # year
+				);
+			$this_minute = $m;
+	}
+	elsif(-f $rrd_dane and ! defined $rrd_dane) {
+		$this_minute = RRDs::last($rrd_dane) + $rrdstep;
+	}
 
 	$rrd_inited=1;
 }
@@ -613,7 +642,20 @@
 			elsif($text =~ /\bstatus=bounced\b/) {
 				event($time, 'bounced');
 			}
+			elsif($text =~ /Anonymous TLS connection established to/) {
+				event($time, 'anonymoustls');
+			}
+			elsif($text =~ /Trusted TLS connection established to/) {
+				event($time, 'trustedtls');
+			}
+			elsif($text =~ /Untrusted TLS connection established to/) {
+				event($time, 'untrustedtls');
+			}
+			elsif($text =~ /Verified TLS connection established to/) {
+				event($time, 'verifiedtls');
+			}
 		}
+		
 		elsif($prog eq 'local') {
 			if($text =~ /\bstatus=bounced\b/) {
 				event($time, 'bounced');
@@ -918,16 +960,18 @@
 	return 1 if $m == $this_minute;
 	return 0 if $m < $this_minute;
 
-	print "update $this_minute:$sum{sent}:$sum{received}:$sum{bounced}:$sum{rejected}:$sum{virus}:$sum{spam}:$sum{greylisted}:$sum{delayed}\n" if $opt{verbose};
+	print "update $this_minute:$sum{sent}:$sum{received}:$sum{bounced}:$sum{rejected}:$sum{virus}:$sum{spam}:$sum{greylisted}:$sum{delayed}:$sum{anonymoustls}:$sum{trustedtls}:$sum{untrustedtls}:$sum{verifiedtls}\n" if $opt{verbose};
 	RRDs::update $rrd, "$this_minute:$sum{sent}:$sum{received}:$sum{bounced}:$sum{rejected}" unless $opt{'no-mail-rrd'};
 	RRDs::update $rrd_virus, "$this_minute:$sum{virus}:$sum{spam}" unless $opt{'no-virus-rrd'};
 	RRDs::update $rrd_greylist, "$this_minute:$sum{greylisted}:$sum{delayed}" unless $opt{'no-greylist-rrd'};
+	RRDs::update $rrd_dane, "$this_minute:$sum{anonymoustls}:$sum{trustedtls}:$sum{untrustedtls}:$sum{verifiedtls}" unless $opt{'no-dane-rrd'};
 	if($m > $this_minute+$rrdstep) {
 		for(my $sm=$this_minute+$rrdstep;$sm<$m;$sm+=$rrdstep) {
 			print "update $sm:0:0:0:0:0:0:0:0 (SKIP)\n" if $opt{verbose};
 			RRDs::update $rrd, "$sm:0:0:0:0" unless $opt{'no-mail-rrd'};
 			RRDs::update $rrd_virus, "$sm:0:0" unless $opt{'no-virus-rrd'};
 			RRDs::update $rrd_greylist, "$sm:0:0" unless $opt{'no-greylist-rrd'};
+			RRDs::update $rrd_dane, "$sm:0:0:0:0" unless $opt{'no-dane-rrd'};
 		}
 	}
 	$this_minute = $m;
@@ -939,6 +983,10 @@
 	$sum{spam}=0;
 	$sum{greylisted}=0;
 	$sum{delayed}=0;
+	$sum{anonymoustls}=0;
+	$sum{trustedtls}=0;
+	$sum{untrustedtls}=0;
+	$sum{verifiedtls}=0;
 	return 1;
 }
 
@@ -974,6 +1022,7 @@
  --no-mail-rrd      do not update mail rrd
  --no-virus-rrd     do not update virus rrd
  --no-greylist-rrd  do not update greylist rrd
+ --no-dane-rrd  do not update dane rrd
  --rrd-name=NAME    use NAME.rrd and NAME_virus.rrd for the rrd files
  --rbl-is-spam      count rbl rejects as spam
  --virbl-is-virus   count virbl rejects as viruses
