From f46bdaf4c168c9c21e7fefb07ce2f60d7ff84afc Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 21 Jan 2002 09:37:42 +0000 Subject: [PATCH] initial import --- README | 18 +++++++++++++++ icesnap | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ icesnap.conf | 16 +++++++++++++ snap.tmpl | 18 +++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 README create mode 100755 icesnap create mode 100644 icesnap.conf create mode 100644 snap.tmpl diff --git a/README b/README new file mode 100644 index 0000000..025f499 --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +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 + diff --git a/icesnap b/icesnap new file mode 100755 index 0000000..b56aa3b --- /dev/null +++ b/icesnap @@ -0,0 +1,75 @@ +#!/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; + +} + diff --git a/icesnap.conf b/icesnap.conf new file mode 100644 index 0000000..0f9bf31 --- /dev/null +++ b/icesnap.conf @@ -0,0 +1,16 @@ + +# 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'; + diff --git a/snap.tmpl b/snap.tmpl new file mode 100644 index 0000000..ba12e8a --- /dev/null +++ b/snap.tmpl @@ -0,0 +1,18 @@ + + + icecast snapshot + + +

icecast snapshot

+ Mountpoint: <%= $main::mount %>

+ + +<% $total = 0; + foreach my $user_agent ( keys %{$main::mount{$main::mount}} ) { + $total += $main::mount{$main::mount}{$user_agent}; +%> + +<% } %> +
User Agent#
<%= $user_agent %><%= $main::mount{$main::mount}{$user_agent} %>
+
Total: <%= $total %>
+ -- 2.11.0