PDA

View Full Version : Teamspeak 2 stats script for Perl (simple)


Makull
27-08-2002, 10:23
Here is a Perl script I made to capture the stats the new 2.x server sends. I don't know where to place a second stats link in the ini file (you could in v1 but it doesn't seem to be in v2) so I altered the PostURL value in the ini file to point to my own script).

Here is the script :

#!/usr/bin/perl
#
# This file will save the statistics from TeamSpeak 2 to a local file
#

use strict;
use warnings;
use Fcntl ":flock";
use CGI;
# which path did we start from?
$0 =~ m/(.*)(\\|\/)/;
my $pathprogram = $1;
# save in @INC
push (@INC, $pathprogram);

# the filename to use for the stats
my $stats_file = 'stats.received';
# create CGI object
my $query = new CGI;
# open the stats file for writing
open(FILE, ">$pathprogram/$stats_file") || die("Couldn't open file $stats_file : $!\n");
flock(FILE, LOCK_EX);
# write all key/value pairs to the file
foreach my $item ($query->param) {
print FILE $item."=".$query->param($item)."\n";
}
flock(FILE, LOCK_UN);
close(FILE);

# in case the server requires scripts to send something back, just send a HTML header
print "Content-Type: text/html\n\n";
# Done


and here is an example of what you will get in the stats.received file :

server_adminemail=na
server_isplinkurl=na
server_ispname=Private
server_ispcountry=Earth
server_platform=Linux
server_version_major=2
server_version_minor=0
server_version_release=17
server_version_build=17
server_port=8767
server_name=Makull's BabbleBox
server_uptime=783
server_password=1
server_type1=clan
server_type2=freeware
clients_current=0
clients_maximum=10
channels_current=1
server_queryport=51234

You can then use a SSI or whatever to include this info on a webpage.

ScratchMonkey
27-08-2002, 15:21
As a rule, use -wT in the shebang line, to get Taint mode turned on. (This doesn't normally work in Windows Perl, though. See the Active State site for more info on how to deal with that.)

Also note that there's a separate forum for Webpost/scripts, as those will be common to the Linux and Windows servers.