<%doc>
############################################################################
###    (C)opyright 2003 - 2008 RIPE NCC
###    This file is part of DNSMon
###
###    DNSMon is free software: you can redistribute it and/or modify
###    it under the terms of the GNU General Public License as published by
###    the Free Software Foundation, either version 3 of the License, or
###    (at your option) any later version.
###
###    DNSMon is distributed in the hope that it will be useful,
###    but WITHOUT ANY WARRANTY; without even the implied warranty of
###    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
###    GNU General Public License for more details.
###
###    You should have received a copy of the GNU General Public License
###    along with DNSMon.  If not, see <http://www.gnu.org/licenses/>.
############################################################################
</%doc>
<%args>
	$day => '';
	$month => '';
	$year => '';
	$hour => '';
	$period => '';
	$domain => '';
	$shift => 0;
	$tstart => 0;
	$tstop => 0;
	$af => 'ipv4';
	$refresh => '';
</%args>

<%perl>

	my $t1  = $m->comp('/lib/rrdplots:calc_t1',
		lastval=>$m->comp('/lib/rrdplots:last_val',
			srv=>'k.root-servers.net', af=>$af), %ARGS);
	my $t2  = $m->comp('/lib/rrdplots:calc_t2',
		lastval=>$m->comp('/lib/rrdplots:last_val',
			srv=>'k.root-servers.net', af=>$af), %ARGS);

	$period = $m->comp('/lib/rrdplots:calc_period',
		lastval=>$m->comp('/lib/rrdplots:last_val', srv=>'k.root-servers.net', af=>$af),
		t1=>$t1, t2=>$t2, period=>$period, shift=>$shift);

	$ARGS{'hour'}   = $t1->hour;
	$ARGS{'day'}    = $t1->mday;
	$ARGS{'month'}  = $t1->mon;
	$ARGS{'year'}   = $t1->year;
	$ARGS{'period'} = $period;

	$ARGS{'af'} = $af;
	$ARGS{'tstart'} = $t1->epoch;
	$ARGS{'tstop'} = $t2->epoch;

</%perl>

<form name="Domains" method="get" action="plot">
	<&| /lib/fillform, subs => \%ARGS &>
		<div id="fillform_domains" >
			<table summary="Parameter form to select custom plots">
				<tr>
					<td> Domain <& /lib/rrdplots:select_domain &> </td>
					<td><& /lib/rrdplots:select_af &></td>
					<td> from <& /lib/rrdplots:select_time &> </td>
					<td> for <& /lib/rrdplots:select_period &> </td>
					<td> &nbsp;<input type="submit" value="SHOW" name="plot" /> </td>
				</tr>
			</table>
		</div>
	</&>

% if ($TICKET) {
	<div id="select_select_refresh_plot"><& /lib/rrdplots:select_refresh_plot &></div>
% }
	<div id="select_shift"> Show other time frame: <& /lib/rrdplots:select_shift &> </div>
</form>

<div id="warn_long_timeframe"><& /lib/rrdplots:warn_long_timeframe, start => $t1, stop => $t2 &></div>

% $m->flush_buffer;
<div class="center"><div class="plot" id="domain_<% $domain %>"></div></div><script language="javascript" type="text/javascript" >
<& /lib/ajax, prefix => '/dns-servmon', throbber => '/images/dnsmon/throbber.gif', comp=>'SELF:plot_domain', parameters => { domain=>($domain), %ARGS, fuzzy=>0 }, update => "domain_${domain}" &>
</script>
% $m->flush_buffer;

<table id="domain_servers" summary="Overview of nameservers associated with domain">
%	my $n = 0;
%	my $afn = $af eq "ipv6" ? &AF_INET6 : &AF_INET;
%	foreach my $s (RIPE::DNSMon::RRD::domain_servers($domain,$afn)) {
% 		if ($n % 3 == 0) {
%			if ($n) {
	</tr>
%			}
	<tr>
%		}
		<td>
			<% $s %><br/>
			<& /lib/rrdplots:plot_s_drops, srv=>$s, start=>$t1, stop=>$t2, xscale=> '300', yscale => '231', fuzzy=>0, af=>$af &>
		</td>
% $m->flush_buffer;
%	$n++;
%	}
	</tr>
</table>

<%method plot_domain>
<%attr>
ajax => 1
</%attr>
<%args>
	$domain
	$period => '';
	$shift => 0;
	$af => 'ipv4';
</%args>
<%perl>

	my $t1  = $m->comp('/lib/rrdplots:calc_t1',
		lastval=>$m->comp('/lib/rrdplots:last_val',
			srv=>'k.root-servers.net', af=>$af), %ARGS);
	my $t2  = $m->comp('/lib/rrdplots:calc_t2',
		lastval=>$m->comp('/lib/rrdplots:last_val',
			srv=>'k.root-servers.net', af=>$af), %ARGS);
	my %myARGS;

	$period = $m->comp('/lib/rrdplots:calc_period',
		lastval=>$m->comp('/lib/rrdplots:last_val', srv=>'k.root-servers.net', af=>$af),
		t1=>$t1, t2=>$t2, period=>$period, shift=>$shift);

	$ARGS{'hour'}   = $t1->hour;
	$ARGS{'day'}    = $t1->mday;
	$ARGS{'month'}  = $t1->mon;
	$ARGS{'year'}   = $t1->year;
	$ARGS{'period'} = $period;
	$ARGS{'af'} = $af;

	if ($TICKET && exists($ARGS{refresh})) {
		$myARGS{'refresh'} = 'yes';
	}

</%perl>
% if ($m->comp('/lib/rrdplots:known_domain', domain => $domain, af=>$af)) {
<& /lib/rrdplots:plot_domain, domain=>($domain), start=>$t1->epoch, stop=>$t2->epoch, fuzzy=>0, af=>$af, %myARGS &>
% } else{
	<p><strong>This domain has no <% $af %> coverage by DNSMon</strong></p>
% }
</%method>
