sub put {
my ($self, $url, $json) = @_;
- warn "put $url ",dump($json);
if ( ! defined $json->{_rev} ) {
my $old = eval { $self->get( $url )->{_rev} };
$url =~ s/-\S+//g;
$url =~ s/\W+/-/g;
- my ( $package, undef, $line, $sub ) = caller(1);
+ my ( $package, $file, $line, $sub ) = caller(1);
( $package, undef, $line ) = caller(0) if $package eq 'main';
+ my $t = time();
+
$data->{x_meta} = {
- 'ident' => [ @_ ],
- 'time' => time(),
+ 'time' => $t,
'package' => $package,
'line' => $line,
'sub' => $sub,
};
+ $data->{'ident'} = [ @_ ] if @_;
+
+ warn 'audit ', dump($data), "at $file +$line\n";
- $audit->put( "pxelator/$package.$url", $data );
+ $audit->put( "pxelator/$t.$package.$url", $data );
}
1;
use x11;
our $pids;
-$pids = { httpd => $$ } unless defined $pids; # keep pids on refresh
+$pids = { httpd => $$, kvm => 'not started' } unless defined $pids; # keep pids on refresh
sub DESTROY {
warn "pids ",dump( $pids );
use Net::DHCP::Packet;
use Net::DHCP::Constants 0.67;
+use CouchDB;
+
use server;
my $debug = server::debug;
my $hostname = $dhcp->getOptionValue(DHO_HOST_NAME);
print "$ip ", client::conf( $ip => 'hostname', default => $hostname ), " >> /etc/hosts\n";
+ my $audit = { mac => $mac, ip => $ip, hostname => $hostname };
+ CouchDB::audit( 'request', $audit );
+
=for later
my $user_class = $dhcp->getOptionValue(DHO_USER_CLASS());
}
warn "W: options requested but missing: ",dump( @missing ),$/;
+ $audit->{requested} = [ @requested ];
+ $audit->{missing} = [ @missing ];
foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {
my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;
my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
if ($messagetype eq DHCPDISCOVER()) {
- log::mac $mac, "DHCP DISCOVER";
+ $audit->{type} = 'discover';
$packet->{Comment} = $dhcp->comment();
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER();
} elsif ($messagetype eq DHCPREQUEST()) {
my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS());
- log::mac $mac, "DHCP REQUEST $requested_ip $ip $file";
+ $audit->{type} = 'request';
if ( $ip eq $requested_ip ) {
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPACK();
$packet->{DHO_DHCP_LEASE_TIME()} = 5 * 60; # 5 min
$packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip";
}
} elsif ($messagetype eq DHCPINFORM()) {
- log::mac $mac, "DHCP INFORM ignored";
+ $audit->{type} = 'inform';
} else {
- log::mac $mac, "$messagetype igored (bootp?)";
+ $audit->{type} = sprintf('ignored %x', $messagetype);
}
warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;
+ $audit->{response} = $packet;
$packet = new Net::DHCP::Packet( %$packet );
warn "send ",$packet->toString() if $debug;
+ CouchDB::audit( 'response', $audit );
+
my $reply = IO::Socket::INET->new(
LocalAddr => $server::ip,
LocalPort => 67,
print "DHCP listen on ",$sock->sockhost,":",$sock->sockport,"\n";
+ CouchDB::audit( 'start', { 'listen' => { addr => $sock->sockhost, port => $sock->sockport } } );
+
while (1) {
process_packet $sock;
}
use Net::DNS::Nameserver;
use Net::DNS::Resolver;
use Data::Dump qw/dump/;
+use CouchDB;
use server;
our $debug = server::debug;
server->refresh;
$debug = server::debug;
- print "$qname $qclass $qtype $peerhost to ". $conn->{"sockhost"}. "\n";
+ CouchDB::audit( 'request', {
+ qname => $qname,
+ qclass => $qclass,
+ qtype => $qtype,
+ peerhost => $peerhost,
+ sockhost => $conn->{"sockhost"}
+ });
+
$query->print if $debug;
my $local = $1 if $qname =~ m{^(.+)\.\Q$server::domain_name\E$};
my $rdata;
if ( $qtype eq "A" && $local eq "server" ) {
$rdata = name_ip( $local, $server::ip );
+ CouchDB::audit('local', $rdata);
} else {
$rcode = "NXDOMAIN";
}
if ( my $rdata = $ptr_cache->{$1} ) {
$rdata .= '.' . $server::domain_name;
push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
+ CouchDB::audit('ptr', $rdata );
} else {
warn "## ",dump( $ptr_cache );
$rcode = "NXDOMAIN";
}
} elsif ( my $packet = $res->query( $qname, $qtype ) ) {
+ CouchDB::audit( 'upstream', $packet );
$packet->print;
push @ans, $_ foreach $packet->answer;
$rcode = "NOERROR";
warn "rcode: $rcode ",dump( @ans );
+ CouchDB::audit('response', { rcode => $rcode, ans => [ @ans ], auth => [ @auth ], add => [ @add ] });
+
# mark the answer as authoritive (by setting the 'aa' flag
return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
}
Verbose => $debug,
) || die "couldn't create nameserver object\n";
+ CouchDB::audit('start', { listen => { port => 53, domain_name => $server::domain_name } });
warn "DNS $server::domain_name";
$ns->main_loop;
use browser;
use network;
+use CouchDB;
sub static {
my ($client,$path) = @_;
if ( my $pid = fork ) {
# parent
close($client);
- print "http static child $pid\n";
$static_pids->{$pid} = $path;
+ CouchDB::audit('static', 'parent', { pid => $pid, path => $path });
return 1;
}
my $buff;
my $pos = 0;
- warn "static $path $type $size block: $block\n";
+ CouchDB::audit( 'static', 'child', { pid => $$, path => $path, type => $type, size => $size, block => $block });
progress_bar::start;
print STDERR "\n";
- warn "exit static child";
+ CouchDB::audit( 'static', 'child', 'exit', { pid => $$ } );
exit(0);
}
server->refresh;
- warn "get_request $path ", $param ? dump( $param ) : '', "\n";
+ CouchDB::audit( 'request', { path => $path, param => $param } );
if ( my $found = static( $client,$path ) ) {
warn "static $found" if $debug;
use autodie;
use Data::Dump qw/dump/;
+use CouchDB;
our $command;
if ( $key ) {
my $k = $cols[$key - 1];
$info->{$k} = $hash;
+ CouchDB::audit( $command, $k, $hash );
} else {
push @$info, $hash;
}
use Net::TFTPd 0.03 qw(%OPCODES);
use IO::Socket::INET;
use Data::Dump qw/dump/;
+use CouchDB;
use server;
warn 'request: ', dump( $request ) if $debug;
- config::for_ip( $request->{_REQUEST_}->{PeerAddr} );
+ my $ip = $request->{_REQUEST_}->{PeerAddr};
+ config::for_ip( $ip );
if ( $request->{RootDir} ne $dir ) {
$request->{RootDir} = $dir;
}
my $file = $request->{'_REQUEST_'}{'FileName'};
- # received request
- print $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}}, " $file\n";
+ my $opcode = $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}};
+
+ CouchDB::audit('request', {
+ ip => $ip,
+ opcode => $opcode,
+ file => $file,
+ });
progress_bar::start;
# process the request
if( $request->processRQ() ) {
- print "\nOK completed $file ", -s "$dir/$file", "\n";
+ my $size = -s "$dir/$file";
+ CouchDB::audit('completed', { file => $file, size => $size });
} else {
- print "ERROR ", Net::TFTPd->error, "\n";
+ CouchDB::audit('error', { file => $file, error => Net::TFTPd->error });
$request->processRQ();
}
warn 'listener: ',dump( $listener ) if $debug;
- printf "TFTP listen %s:%d timeout: %d dir: $dir\n",
- $listener->{LocalAddr},
- $listener->{LocalPort},
- $listener->{Timeout};
+ CouchDB::audit( 'start', {
+ addr => $listener->{LocalAddr},
+ port => $listener->{LocalPort},
+ timeout => $listener->{Timeout},
+ params => { %params },
+ });
while(1) {