#!/usr/bin/perl -T
use strict;
use warnings;
use diagnostics;
use IO::Socket;
use CGI qw( :standard);
my $susername = "admin";
my $spasswort = "password";
my $server_adress = "127.0.0.1";
my $server_manage_port = "51234";
my $allowed_username_chars = '-a-zA-Z0-9 ';
my $allowed_password_chars = '-a-zA-Z0-9 ';
#####################################################
# PwChange V0.1b #
# #
# feel free to customize this script #
# if you think it's usefull post my #
# guestbook http://www.bk99.de #
# #
# Peter Grunert - grunert.peter [at] web [dot] de #
#####################################################
my $debug = 0;
print header("text/html");
if (param("wuser") && param("wpass") && param("wnpass") && param("wsport")) {
my $wuser = param("wuser"); my $wpass = param("wpass");
my $wnpass = param("wnpass"); my $wsport = param("wsport");
$wuser = substr($wuser,0,14); $wuser =~ s/[^$allowed_username_chars]//go;
$wpass = substr($wpass,0,14); $wpass =~ s/[^$allowed_password_chars]//go;
$wnpass = substr($wnpass,0,14); $wnpass =~ s/[^$allowed_password_chars]//go;
$wsport = substr($wsport,0,5); $wsport =~ s/[^0-9]//go;
print start_html("Statusinfo");
if ($wuser && $wpass && $wnpass && $wsport) {
&pwchange($wuser,$wpass,$wnpass,$wsport);
}
else {
&print_html("
Wrong Input in filtered fields
");
}
}
else {
print start_html("Change your Teamspeak passwort");
print startform('POST', 'pwchange.pl', 'application/x-www-form-urlencoded');
print "Username: ", textfield('wuser'), br;
print "Old password: " ,password_field('wpass'), br;
print "New password: ", password_field('wnpass'), br;
print "Serverport: ", textfield('wsport'), br;
print submit;
print end_form;
}
print end_html;
sub pwchange ($$$$) {
my ($user, $userpw, $newpass, $server_port) = @_;
my $connection = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $server_adress,
PeerPort => $server_manage_port
) or die("Cannot connect to $server_manage_port at $server_adress");
my $line = <$connection>; chomp($line);
if ($line =~ /^\[TS\]/) {
print $connection "sel $server_port\n";
$line = <$connection>; chomp($line);
print "\n\n" if ($debug);
if ($line =~ /^OK/) {
print $connection "login $user $userpw\n";
$line = <$connection>;
print "\n\n" if ($debug);
if ($line =~ /^OK/ || $line =~ /invalid permissions/) {
print $connection "slogin $susername $spasswort\n";
$line = <$connection>; chomp($line);
print "\n\n" if ($debug);
if ($line =~ /^OK/) {
print $connection "dbuserid $user\n";
$line = <$connection>;$line =~ s/\s+//g;
print "\n\n" if ($debug);
if ($line =~ /^[0-9]+$/) {
print $connection "dbuserchangepw $line $newpass $newpass\n";
$line = <$connection>;chomp($line);
print "\n\n" if ($debug);
if ($line =~ /^OK/) {
print "\n\n" if ($debug);
&print_html("Password was changed.
\n");
print $connection "logmark Password for $user has changed: $line\n";
print $connection "quit\n";
}
else {
print "\n\n" if ($debug);
&print_html("Password was NOT changed.
\n");
print $connection "logmark Password for $user has NOT changed: $line\n";
print $connection "quit\n";
}
}
else {
print "\n\n" if ($debug);
&print_html("UserID not a digit. Contact Admin, please!
\n");
print $connection "logmark USERID IS NOT A DIGIT: $user $line\n";
print $connection "quit\n";
}
}
else {
print "\n\n" if ($debug);
&print_html("SUser not known or wrong password. Can't connect to Teamspeak Server on $server_adress:$server_port
\n");
print $connection "quit\n";
}
}
else {
print "\n\n" if ($debug);
&print_html("User not known or wrong password. Can't connect to Teamspeak Server on $server_adress:$server_port
\n");
print $connection "quit\n";
}
}
else {
print "\n\n" if ($debug);
&print_html("Can't find Teamspeak server on $server_adress:$server_port
\n");
print $connection "quit\n";
};
}
else {&print_html("Can't connect to Teamspeak server managing port on $server_adress:$server_manage_port
\n")};
close($connection);
}
sub print_html ($) {
my ($html) = @_;
print "$html
";
}