--- /dev/null
+icesnap
+
+Copyright (c) 2002 Ivan Kohler
+All rights reserved.
+This program is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+ivan-icesnap@420.am
+
+icesnap takes a snapshot of the current state of an icecast server, then
+creates (from a template) HTML pages for each mountpoint listing the number
+of listeners, total and broken down by User-Agent (i.e. xmms, WinAMP,
+Realplayer, etc.).
+
+To use, set the parameters in icesnap.conf and copy it to /etc/icesnap.conf,
+then run icesnap as desired (perhaps from cron) to generate the HTML output.
+A sample template file is included in snap.tmpl
+
--- /dev/null
+#!/usr/bin/perl -w
+#
+# Copyright (c) 2002 Ivan Kohler
+# All rights reserved.
+# This program is free software; you can redistribute it and/or modify it under
+# the same terms as Perl itself.
+#
+# ivan-icelog@420.am
+
+use strict;
+use Net::Icecast;
+use Apache::ASP;
+
+require "/etc/icesnap.conf";
+
+unless ( -e $outdir) {
+ mkdir($outdir, 0755) or die "can't mkdir $outdir: $!";
+}
+
+my $c = Net::Icecast->new($host, $port, $admin_password)
+ or die "can't connect";
+
+my %hash = $c->listeners;
+
+#my %mount;
+use vars qw( %mount );
+
+#produce blank pages
+foreach my $mount (qw( / /24 ) ) {
+ $mount{$mount} = {};
+}
+
+foreach my $listener ( keys %hash ) {
+# print "$listener => \n";
+ my %lhash = %{$hash{$listener}};
+ foreach my $key ( keys %lhash ) {
+# print " $key => $lhash{$key}\n";
+ }
+
+ $mount{$lhash{mountpoint}}{$lhash{user_agent}}++;
+}
+
+#print "\n\n";
+
+use vars qw($mount);
+foreach $mount ( keys %mount ) {
+ my $total = 0;
+ &writepage();
+# print "$mount => \n";
+# foreach my $user_agent ( keys %{$mount{$mount}} ) {
+# $total += $mount{$mount}{$user_agent};
+# print " $user_agent => $mount{$mount}{$user_agent}\n";
+# }
+# print " TOTAL $total\n\n";
+}
+
+sub writepage {
+ #my $mount = shift;
+# my %mount = %{shift()};
+ #my $mref = shift;
+
+ open(STDOUT,">$outdir/$mount.html") or die "can't open $outdir/$mount.html: $!";
+
+ #nicked from cgi/asp in the Apache::ASP disribution
+
+ my $r = &Apache::ASP::CGI::init($template);
+
+ $r->dir_config('NoHeaders', 1);
+
+ &Apache::ASP::handler($r);
+
+ close STDOUT;
+
+}
+
--- /dev/null
+
+# icecast server host
+my $host = 'server.name';
+
+# icecast server port number
+my $port = 8000;
+
+# icecast server admin password
+my $admin_password = 'adminpw';
+
+# template file
+my $template = '/path/to/snap.tmpl';
+
+# html output directory
+my $outdir = '/path/to/htmlout';
+
--- /dev/null
+<html>
+ <head>
+ <title>icecast snapshot</title>
+ </head>
+ <body bgcolor="#e8e8e8">
+ <h2>icecast snapshot</h2>
+ Mountpoint: <%= $main::mount %><br><br>
+ <table border>
+ <tr><th>User Agent</th><th>#</th></tr>
+<% $total = 0;
+ foreach my $user_agent ( keys %{$main::mount{$main::mount}} ) {
+ $total += $main::mount{$main::mount}{$user_agent};
+%>
+ <tr><td><%= $user_agent %></td><td><%= $main::mount{$main::mount}{$user_agent} %></td></tr>
+<% } %>
+ </table>
+ <br>Total: <%= $total %><br>
+</html>