3 # Copyright (c) 2002 Ivan Kohler
5 # This program is free software; you can redistribute it and/or modify it under
6 # the same terms as Perl itself.
11 use vars qw( $Debug $dsn $username $password );
14 use Net::SSH qw(sshopen2);
18 my $machine = shift or die &usage;
19 my $logfile = shift || '/var/log/icecast/access.log';
22 require "/etc/icelog.conf";
24 my $dbh = DBI->connect($dsn, $username, $password)
25 or die "Can't connect to $dsn: ". $DBI::errstr;
27 my $iceaccessd = '/usr/local/bin/iceaccessd';
29 my $me = "[iceaccess_server]";
34 my($reader, $writer) = (new IO::Handle, new IO::Handle);
35 $writer->autoflush(1);
36 warn "$me Connecting to $machine\n" if $Debug;
37 sshopen2($machine,$reader,$writer,$iceaccessd, $logfile, $pos);
38 warn "$me Entering main loop\n" if $Debug;
40 warn "$me Reading (waiting for) data\n" if $Debug;
41 my $line = scalar(<$reader>);
42 die "No response from remote iceaccessd process" unless defined($line);
45 ( $pos, %hash ) = split(/\t/, $line);
46 if ( $pos eq 'EOF' ) { ; #re-open iceacceed process on new logfile
53 my $customer = $hash{mountpoint};
54 $hash{mountpoint} =~ /^\/([^\/]*)/
55 or die "weird mountpoint $hash{mountpoint}";
58 #$hash{mountpoint} =~ /\/|^([^\/]+)$/;
62 if ( $hash{mountpoint} =~ /\/0+(\.\w+)?$/ ) {
68 #switch to prepare_cached?
69 my $sth = $dbh->prepare(<<END) or die $dbh->errstr;
70 INSERT INTO icelog ( logdate, logmachine, logpos, customer, liveflag,
71 hostname, start, mountpoint, bytes, useragent,
73 ) VALUES ( NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
81 $hash{hostname}, #hostname
83 $hash{mountpoint}, #mountpoint
85 $hash{useragent}, #useragent,
86 $hash{seconds}, #seconds
87 ) or die $sth->errstr;
93 warn "connection to $machine lost!\n";
95 warn "reconnecting...\n";
102 die "Usage:\n\n iceaccess_server machine logfile position\n";