#!/usr/bin/perl
#----------------------------------------------------#
# A perl script to use xitae sms service in Spain.   #
#----------------------------------------------------#
# tips to: pancake@phreaker.net                      #
# note: do not abuse, you only can send 7 sms daily. #
#       is nice to protect this kind of services.    #
# remember: DO NOT ABUSE!                            #
#----------------------------------------------------#
# 
use IO::Socket;
use Tk;

$num='';
$msg="";

$user="";
$pass="";

$s=0;

sub domsg
{
        ($nana)=@_;
        print "MSG: $nana\n";
	$wow=new MainWindow;
        $wow->Label(-textvariable => \$nana )->pack;
}

sub sendsms
{
# Send is pawah
	if ( ($user eq "") || ($pass eq "") )
	{
		print "Login and password not defined.\nRegister First.\n";
		print "And define the \$user and \$pass vars on top of script.\n";
		exit;
	}

	doconnect();
	$msg=~tr/ /+/;

	if ( length($num) != 9  )
		{
		print "Invalid phone number: '$num'.\nMust be 9digit number.\n";
                $s->close();
		}

	print "Connected.\n";
	print $s "GET /xsms.php?user=$user&pass=$pass&msg=$msg&num=$num HTTP/1.1\r\nHost: www.xitae.com\r\n\r\n";

	$flag=0;
	while(<$s>)
	{
	if ((/^1/)||(/^0/)) 
		{ 
		if ($flag == 1)
			{
			if (/^1/)
				{
				domsg( "Message sent OK :D\n");
				}
			elsif (/^0/)
				{
				domsg( "Message not sent properly :(\n" );
				} else {
				domsg( "Internal server error :/\n");
				}
			}
		$flag++;
		}	
	}

}


sub doconnect
{
	$s=IO::Socket::INET->new(
			"PeerAddr"=>"216.127.76.70", # www.xitae.com
		        "PeerPort"=>80) or
	die ("Cannot connect to remote host");
}

sub dofork
{
	if (fork())
	{
		exit 0;
	}
}

my $main = new MainWindow;

$main->Label(-text => 'xSms.pl by pancake@phreaker.net' )->pack;
$main->Label(-text => 'Telefon' )->pack;
$main->Entry(-textvariable=>\$num )->pack;
$main->Label(-text => 'Missatge' )->pack;
$main->Entry(-textvariable=>\$msg )->pack;
$main->Button(-text => "Enviar", -command => sub{sendsms} )->pack;
$main->Button(-text => 'Sortir', -command => sub{exit} )->pack;

MainLoop;


