#!/usr/bin/perl -w
#
#    linuxsms, a linux console perl script for send short messages 
#    to gsm phones (aka sms 8-)) by z0mbie (thesumidero@yahoo.com) 
#    HOMEPAGE: http://linuxsms.sourceforge.net
#
#    Copyright (C) 2001 Alejandro Portela, <thesumidero@yahoo.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# DON'T TOUCH NOTHING AFTER HERE!... UNLESS YOU KNOW WHAT YOU ARE DOING ;-)
#
# Perl v5.005 required
require 5.005;
use IO::Socket;
use strict;
# last update 28-11-2003
my $VERSION = "0.76";
#
# global variables
my ($SERVER, $DEFAULT_SERVER, $URL);
my ($NAME, $NUMBER, $MYNUMBER, $MYPREFIX, $SMS, $SMSCHARLIMIT, $EMAIL, $ALIAS, $SIGNATURE, $SERVER_LIST, $LOG);
my $CONFIRM = "off";
my $SIG = 0;
my $FLASH = 0;
my $GET_CREDITS = 0;
my $SECURE_MODE = 1;
# default commandline is the classic long
my $CMDLINE = 1;
# COMPRESS SMS default is OFF, set to ON by '-z' commandline option
my $COMPRESS = 0;
# DEBUG default is OFF, set to ON by '-debug' commandline option
my $DEBUG = 0;
my ($LOGIN, $PASSWD, $HTTP_SOCKET, $PROXY);
my (%COOKIES);
#
# the home dir of user
my $HOME = $ENV{HOME};
# the home dir of script
$HOME   .= "/.linuxsms/";
# the homepage of script
my $LINUXSMSURL   = "linuxsms.sourceforge.net";
my $LINUXSMSEMAIL = "thesumidero\@yahoo.com";
# available server list
# format is: 
# name => [ "ACCOUNT REQUIRED ?", "HOST/IP", "URL for register account", "sms limit", "smiley rating", "country" "char limit"],
# (the last entry don't have a ',' at end)... and YES, CASE IS SENSITIVE!
my %HSERVERS = (
                everyday     => [ "Y", "eday.tele2.ee"          , "www.everyday.com"    , "3 sms / day"   , ":-)" , "SP"        , 124 ],
                everyday_fr  => [ "Y", "eday.tele2.ee"          , "www.fr.everyday.com" , "3 sms / day"   , ":-)" , "INT (!SP)" , 129 ],
                firstwap     => [ "Y", "www.1rstwap.com"        , "www.1rstwap.com"     , "15 sms / week" , ":-?" , "INT (!SP)" , 160 ],
                lycos        => [ "Y", "login.lycos.es"         , "www.lycos.es"        , "1 sms / day"   , ":-D" , "INT"       , 95  ],
                orangedk     => [ "Y", "myorange.dk"            , "myorange.dk"         , "no limit"      , ":-)" , "DK"        , 120 ],
                textamerica  => [ "Y", "www.textamerica.com"    , "www.textamerica.com" , "5 sms / day"   , ":-?" , "US"        , 120 ],
                smsac        => [ "Y", "www.sms.ac"             , "www.sms.ac"          , "2 sms /day "   , ":-D" , "INT"       , 120 ],
                ezones       => [ "Y", "www.e-zones.sk"         , "www.e-zones.sk"      , "credits"       , ":-)" , "SK"        , 480 ],
                sunrise      => [ "Y", "mymobile.sunrise.ch"    , "mymobile.sunrise.ch" , "300 sms / mon" , ":-D" , "INT"       , 130 ],
                aliceadsl    => [ "Y", "www.aliceadsl.it"       , "www.aliceadsl.it"    , "10 sms / day"  , ":-)" , "IT"        , 160 ],
                oxygen       => [ "Y", "www.oxygen.ie"          , "www.oxygen.ie"       , "20 sms / week" , ":-)" , "IE"        , 140 ]
		
               );
# the HTTP REQUEST vars
# you must put a value in this vars before
# sending a HTTP HEAD/GET/POST requests
# HOST, LOCATION & REFERER must have \r\n at end
my %HTTP_REQUEST = (
                    HEAD => "",
                    GET  => "",
                    POST => "",
                    HOST => "",
                    LOCATION => "",
                    REFERER => "",
                    DATA => "",
                   );
#
# ANSi color codes (default is NO colors)
# normal attributes
my $c_black = ""; my $c_red     = ""; my $c_green = ""; my $c_yellow = "";
my $c_blue  = ""; my $c_magenta = ""; my $c_cyan  = ""; my $c_white  = "";
# default attribute color
my $c_default = $c_white;
# default blink attribute
my $c_blink   = $c_default;
# default bold attribute
my $c_bold    = $c_default;
# export global vars
use vars qw ($c_black $c_red $c_green $c_yellow $c_blue $c_magenta $c_cyan $c_white);
use vars qw ($c_default $c_blink $c_bold);
use vars qw ($SERVER $DEFAULT_SERVER $URL $PROXY);
use vars qw ($NAME $NUMBER $MYNUMBER $MYPREFIX $SMS $SMSCHARLIMIT $EMAIL $ALIAS $SIGNATURE $SIG $FLASH $LOG $CONFIRM $GET_CREDITS);
use vars qw ($COMPRESS $DEBUG $CMDLINE $SECURE_MODE $SERVER_LIST);
use vars qw ($HSERVERS $HOME);
use vars qw ($LINUXSMSURL $LINUXSMSEMAIL);
use vars qw ($LOGIN $PASSWD);
use vars qw ($HTTP_SOCKET %COOKIES %HTTP_REQUEST);
#
#
# --- subroutines ---
#
#
# set ANSi colors
sub set_ansi() {
    # normal attributes
    $c_black = "\033[0;30m"; $c_red     = "\033[0;31m";
    $c_green = "\033[0;32m"; $c_yellow  = "\033[0;33m";
    $c_blue  = "\033[0;34m"; $c_magenta = "\033[0;35m";
    $c_cyan  = "\033[0;36m"; $c_white   = "\033[0;37m";
    # default attribute color
    $c_default      = $c_white;
    # blink attribute
    $c_blink        = "\033[5m";
    # bold attribute
    $c_bold         = "\033[1m";
}
#
# main starting tests (check dirs && main files)
sub main_test() {
    # test if exist home of script, else try to create
    if (! opendir(DIR, $HOME)) {
        mkdir ($HOME, 0700) or die $c_red.$c_bold.$c_blink."error\!, can\'t create ".$HOME.$c_default."\n";
        print $c_yellow.$c_bold."Creating ".$HOME.$c_default."\n";
    }
    closedir (DIR);
    #
    # test if exist config file, else try to create
    my $LINUXSMSRC = $HOME."linuxsmsrc";
    if (! open(CONFIG, $LINUXSMSRC)) {
        open(CONFIG, "> $LINUXSMSRC") or die $c_red.$c_bold.$c_blink."error\!, can\'t create ".$LINUXSMSRC.$c_default."\n";
        chmod (0600, $LINUXSMSRC) or die $c_red.$c_bold.$c_blink."error\!, can\'t change perm of ".$LINUXSMSRC.$c_default."\n";
        my $TEMP  = "####################################################\n";
        $TEMP .= "# linuxsms v".$VERSION." by z0mbie \(".$LINUXSMSEMAIL."\) #\n";
        $TEMP .= "####################################################\n";
        $TEMP .= "#\n";
        $TEMP .= "# main configuration section\n";
        $TEMP .= "# CASE IS SENSITIVE!\n";
        $TEMP .= "# lines starting with # or blank lines are ignored\n";
        $TEMP .= "# there must be a BLANK line at end (the end)\n";
        $TEMP .= "#\n";
        $TEMP .= "# write here your phone number\n";
        $TEMP .= "MYNUMBER=00000000\n";
        $TEMP .= "# default server for use if omited in commandline\n";
        $TEMP .= "SERVER=\n";
        $TEMP .= "# default prefix for international servers\n";
        $TEMP .= "PREFIX=34\n";
        $TEMP .= "# use NEW (1) || OLD (0) commandline\n";
        $TEMP .= "CMDLINE=1\n";
        $TEMP .= "# append signature at end of sms\n";
        $TEMP .= "SIGNATURE=\n";
        $TEMP .= "# set your alias here\n";
        $TEMP .= "MYALIAS=\n";
        $TEMP .= "# append always the signature (YES || NO)\n";
        $TEMP .= "ALWAYS_SIGNATURE=NO\n";
        $TEMP .= "# enable/disable ANSI colors (YES || NO)\n";
        $TEMP .= "ANSI=NO\n";
        $TEMP .= "# secure mode (if set to NO allows to run the script as root)\n";
        $TEMP .= "SECURITY=YES\n";
        $TEMP .= "# server list info (NORMAL / FULL)\n";
        $TEMP .= "SERVER_LIST=NORMAL\n";
        $TEMP .= "# PROXY support (set PROXY=HOST:PORT)\n";
        $TEMP .= "PROXY=\n";
        $TEMP .= "# sms sent log support";
        $TEMP .= "LOG=NO\n";
        $TEMP .= "#\n\n";
        print CONFIG $TEMP;
        print $c_yellow.$c_bold."Creating ".$LINUXSMSRC.$c_default."\n";
    }
    close(CONFIG);
    #
    # test if exist config file, else try to create
    my $ADDRESSBOOK = $HOME."addressbook";
    if (! open(ADDRESSBOOK, $ADDRESSBOOK)) {
        open(ADDRESSBOOK, "> $ADDRESSBOOK") or die $c_red.$c_bold.$c_blink."error\!, can\'t create ".$ADDRESSBOOK.$c_default."\n";
        chmod (0600, $ADDRESSBOOK) or die $c_red.$c_bold.$c_blink."error\!, can\'t change perm of ".$ADDRESSBOOK.$c_default."\n";
        my $TEMP  = "####################################################\n";
        $TEMP .= "# linuxsms v".$VERSION." by z0mbie \(".$LINUXSMSEMAIL."\) #\n";
        $TEMP .= "####################################################\n";
        $TEMP .= "#\n";
        $TEMP .= "# ADDRESSBOOK\n";
        $TEMP .= "# format is: name:prefix:number:default_server\n";
        $TEMP .= "# ...and YES, CASE IS SENSITIVE!\n";
        $TEMP .= "# lines starting with # or blank lines are ignored\n";
        $TEMP .= "# there must be a BLANK line at end (the end)\n";
        $TEMP .= "#\n";
        $TEMP .= "name1:1:111111111:server1\n";
        $TEMP .= "name2:22:222222222:server2\n";
        $TEMP .= "name3:333:33333333:server3\n";
        $TEMP .= "#\n\n";
        print ADDRESSBOOK $TEMP;
        print $c_yellow.$c_bold."Creating ".$ADDRESSBOOK.$c_default."\n";
    }
    close(ADDRESSBOOK);
    #
    # test if exist password file, else try to create
    my $PASSWORD = $HOME."password";
    if (! open(PASSWORD, $PASSWORD)) {
        open(PASSWORD, "> $PASSWORD") or die $c_red.$c_bold.$c_blink."error\!, can\'t create ".$PASSWORD.$c_default."\n";
        chmod (0600, $PASSWORD) or die $c_red.$c_bold.$c_blink."error\!, can\'t change perm of ".$PASSWORD.$c_default."\n";
        my $TEMP  = "####################################################\n";
        $TEMP .= "# linuxsms v".$VERSION." by z0mbie \(".$LINUXSMSEMAIL."\) #\n";
        $TEMP .= "####################################################\n";
        $TEMP .= "#\n";
        $TEMP .= "# servers PASSWORD file\n";
        $TEMP .= "# format is: server:login:pass\n";
        $TEMP .= "# ...and YES, CASE IS SENSITIVE!\n";
        $TEMP .= "# lines starting with # or blank lines are ignored\n";
        $TEMP .= "# there must be a BLANK line at end (the end)\n";
        $TEMP .= "#\n";
        $TEMP .= "server1:login1:password1\n";
        $TEMP .= "server2:login2:password2\n";
        $TEMP .= "server3:login3:password3\n";
        $TEMP .= "#\n\n";
        print PASSWORD $TEMP;
        print $c_yellow.$c_bold."Creating ".$PASSWORD.$c_default."\n";
    }
    close(PASSWORD);
    #
    # test if exist dictionary file, else try to create
    my $DICT = $HOME."dict";
    if (! open(DICT, $DICT)) {
        open(DICT, "> $DICT") or die $c_red.$c_bold.$c_blink."error\!, can\'t create ".$DICT.$c_default."\n";
        chmod (0600, $DICT) or die $c_red.$c_bold.$c_blink."error\!, can\'t change perm of ".$DICT.$c_default."\n";
        my $TEMP  = "####################################################\n";
        $TEMP .= "# linuxsms v".$VERSION." by z0mbie \(".$LINUXSMSEMAIL."\) #\n";
        $TEMP .= "####################################################\n";
        $TEMP .= "#\n";
        $TEMP .= "# dict file \(for compress\)\n";
        $TEMP .= "# format is: original_word:replace_by_this\n";
        $TEMP .= "# ...and YES, CASE IS unSENSITIVE! ;-)\n";
        $TEMP .= "# lines starting with # or blank lines are ignored\n";
        $TEMP .= "# there must be a BLANK line at end (the end)\n";
        $TEMP .= "#\n";
        $TEMP .= "one:1\n";
        $TEMP .= "two:2\n";
        $TEMP .= "tree:3\n";
        $TEMP .= "#\n\n";
        print DICT $TEMP;
        print $c_yellow.$c_bold."Creating ".$DICT.$c_default."\n";
    }
    close(DICT);
    #
    # test if exist log file, else try to create
    my $LOG = $HOME."log";
    if (! open(LOG, $LOG)) {
        open(LOG, "> $LOG") or die $c_red.$c_bold.$c_blink."error\!, can\'t create ".$LOG.$c_default."\n";
        chmod (0600, $LOG) or die $c_red.$c_bold.$c_blink."error\!, can\'t change perm of ".$LOG.$c_default."\n";
        my $TEMP  = "####################################################\n";
        $TEMP .= "# linuxsms v".$VERSION." by z0mbie \(".$LINUXSMSEMAIL."\) #\n";
        $TEMP .= "####################################################\n";
        $TEMP .= "#\n";
        print LOG $TEMP;
        print $c_yellow.$c_bold."Creating ".$LOG.$c_default."\n";
    }
    close(LOG);
    return(0);
}
# write sms in log
sub log_sms() {
    my $LOG = $HOME."log";
    open(LOG, ">> $LOG");
    print LOG "SMS sent to : ".$NAME." (".$NUMBER.")\n";
    print LOG "SMS sent on : ".`date`;
    $SMS =~ tr/\+/\ /;
    $SMS =~ s/%([A-Fa-f\d]{2})/chr hex $1/eg;
    print LOG "SMS contents: ".$SMS."\n\n";
    close(LOG);
}
#
# print some usefull help text information
sub help() {
    # the new sort commandline options
    if ($CMDLINE) {
        print $c_yellow.$c_bold."Commandline options:".$c_default."\n";
        print $c_cyan.$c_bold."-h ".$c_green."text that you are reading now \;-\)".$c_default."\n";
        print $c_cyan.$c_bold."-server ".$c_green."show available servers".$c_default."\n";
        print $c_cyan.$c_bold."-addressbook ".$c_green."list all entries in addressbook".$c_default."\n";
        print $c_cyan.$c_bold."-login:".$c_cyan."username ".$c_green."use this username to log in the server".$c_default."\n";
        print $c_cyan.$c_bold."-password:".$c_cyan."password ".$c_green."use this password to log in the server".$c_default."\n";
        print $c_cyan.$c_bold."-update ".$c_green."check for new version".$c_default."\n";
        print $c_cyan.$c_bold."-debug ".$c_green."dump debug info to STDERR".$c_default."\n";
        print $c_cyan.$c_bold."-flash ".$c_green."sms-flash ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-sig ".$c_green."add signature at end of sms".$c_default."\n";
        print $c_cyan.$c_bold."-anonymous ".$c_green."hide your number ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-confirm ".$c_green."receive confirmation of sms result ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-credits ".$c_green."only get credits, no sms will be sent ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-z ".$c_green."compress sms using internal dictionary".$c_default."\n";
    }
    # old long commandline options
    else {
        print $c_yellow.$c_bold."Commandline options:".$c_default."\n";
        print $c_cyan.$c_bold."-h ".$c_green."text that you are reading now \;-\)".$c_default."\n";
        print $c_cyan.$c_bold."-server ".$c_green."show available servers".$c_default."\n";
        print $c_cyan.$c_bold."-server:".$c_cyan."server ".$c_green."select server".$c_default."\n";
        print $c_cyan.$c_bold."-addressbook ".$c_green."list all entries in addressbook".$c_default."\n";
        print $c_cyan.$c_bold."-name:".$c_cyan."name ".$c_green."find number in addressbook using name".$c_default."\n";
        print $c_cyan.$c_bold."-number:".$c_cyan."gsm_number ".$c_green."number of phone ".$c_default."\n";
        print $c_cyan.$c_bold."-prefix:".$c_cyan."prefix_numer ".$c_green."country prefix ".$c_default."\n";
        print $c_cyan.$c_bold."-login:".$c_cyan."username ".$c_green."use this username to log in the server".$c_default."\n";
        print $c_cyan.$c_bold."-password:".$c_cyan."password ".$c_green."use this password to log in the server".$c_default."\n";
        print $c_cyan.$c_bold."-sms:".$c_cyan."\"msg\" ".$c_green."text to send ".$c_green.$c_bold."\[ if not set, read from stdin \]".$c_default."\n";
        print $c_cyan.$c_bold."-update ".$c_green."check for new version".$c_default."\n";
        print $c_cyan.$c_bold."-debug ".$c_green."dump debug info to STDERR".$c_default."\n";
        print $c_cyan.$c_bold."-flash ".$c_green."sms-flash ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-sig ".$c_green."add signature at end of sms".$c_default."\n";
        print $c_cyan.$c_bold."-anonymous ".$c_green."hide your number ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-confirm ".$c_green."receive confirmation of sms result ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-credits ".$c_green."only get credits, no sms will be sent ".$c_green.$c_bold."\[ if server has support \]".$c_default."\n";
        print $c_cyan.$c_bold."-z ".$c_green."compress sms using internal dictionary".$c_default."\n";
    }
    # ALWAYS REMEMBER THIS 8-)
    print $c_cyan."linuxsms comes with ".$c_white.$c_bold."ABSOLUTELY NO WARRANTY; This is ".$c_white.$c_bold."free software".$c_cyan.", and you are\n";
    print $c_cyan."welcome to redistribute it under certain conditions; read COPYING for details.".$c_default."\n";
    exit(0);
}
#
# print the available servers
sub print_available_servers() {
    my ($SERVER_NAME, $SERVER_IP, $SERVER_URL, $FAMILY, @VALID_ACCOUNTS, $FOUND, $TEMP);
    my $PASSWORD = $HOME."password";
    my $LINE;
    # open password file and push server accounts into @VALID_ACCOUNTS
    open (PASSWORD, $PASSWORD) or die $c_red.$c_bold.$c_blink."error\!, can\'t open ".$PASSWORD.$c_default."\n";
    while ($LINE = <PASSWORD>) {
        # we like to skip blank lines and comments
        if (($LINE !~ /^$/) && ($LINE !~ /^#/)) {
            if ($LINE =~ /^(.+)\:(.+)\:(.+)$/) {
                push (@VALID_ACCOUNTS, $1);
            }
        }
    }
    close (PASSWORD);
    print $c_yellow.$c_bold."Available servers:".$c_default."\n";
    undef $FOUND;
    foreach $FAMILY (sort(keys %HSERVERS)) {
        # server requires an account ?
        if ($HSERVERS{$FAMILY}[0] =~ /^Y$/) {
            undef $FOUND;
            # we compare with all accounts
            foreach $TEMP (@VALID_ACCOUNTS) {
                if ($TEMP =~ /^$FAMILY$/) { $FOUND = 1; }
            }
            # we have a valid account
            if ($FOUND) {
                print $c_cyan.$c_bold."- ".$c_white.$c_bold."[";
                print $c_green.$c_bold."*".$c_default;
                print $c_white.$c_bold."]".$c_cyan.$c_bold;
            }
            # sorry, more luck next time
            else {
                print $c_cyan.$c_bold."- ".$c_white.$c_bold."[";
                print $c_red.$c_bold.$c_blink."!".$c_default;
                print $c_white.$c_bold."]".$c_cyan.$c_bold;
            }
        }
        # server do not requires an account
        else { print $c_cyan.$c_bold."- ".$c_white.$c_bold."[-]".$c_cyan.$c_bold; }
        print $c_cyan.$c_bold." : ".$c_green.$FAMILY.$c_default." " x (11 - length($FAMILY));
        print $c_cyan.$c_bold." : ".$c_blue.$HSERVERS{$FAMILY}[3].$c_default. " " x (13 - length($HSERVERS{$FAMILY}[3]));
        print $c_cyan.$c_bold." : ".$c_red.$c_bold;
        if ($HSERVERS{$FAMILY}[6] > 100) { print $HSERVERS{$FAMILY}[6] }
        else { print " " . $HSERVERS{$FAMILY}[6]; }
        print " chars";
        print $c_cyan.$c_bold." : ".$c_green.$c_bold.$HSERVERS{$FAMILY}[4].$c_cyan.$c_bold." : ".$c_magenta.$c_bold.$HSERVERS{$FAMILY}[5].$c_default."\n";
        # if we do not have an account registered and we like a full server list, prints some aditional info
        if (! $FOUND && $HSERVERS{$FAMILY}[0] =~ /^Y$/ && $SERVER_LIST) {
            print $c_cyan.$c_bold."      |-> ".$c_green.$c_bold."register".$c_cyan.$c_bold."  : ".$c_blue.$c_bold."http://".$HSERVERS{$FAMILY}[2].$c_default."\n";
        }
    }
    print $c_yellow.$c_bold."Smiley Server Rating Legend:".$c_default."\n";
    print $c_green.$c_bold."  :-(".$c_cyan.$c_bold." : ".$c_blue.$c_bold."[     bad       ]".$c_default."     ";
    print $c_green.$c_bold."  :-?".$c_cyan.$c_bold." : ".$c_blue.$c_bold."[ unpredictable ]".$c_default."\n";
    print $c_green.$c_bold."  :-)".$c_cyan.$c_bold." : ".$c_blue.$c_bold."[     good      ]".$c_default."     ";
    print $c_green.$c_bold."  :-D".$c_cyan.$c_bold." : ".$c_blue.$c_bold."[     best      ]".$c_default."\n";
    print $c_yellow.$c_bold."Server Legend:".$c_default."\n";
    print $c_white.$c_bold."  [-]".$c_cyan.$c_bold." : ".$c_blue.$c_bold."no account required".$c_default."  ";
    print $c_magenta.$c_bold."   INT".$c_cyan.$c_bold." : ".$c_blue.$c_bold."International".$c_magenta.$c_bold."   US".$c_cyan.$c_bold." : ".$c_blue.$c_bold."USA only".$c_default."\n";;
    print $c_white.$c_bold."  [".$c_red.$c_bold.$c_blink."!".$c_default.$c_white.$c_bold."]".$c_cyan.$c_bold." : ".$c_blue.$c_bold."need to register".$c_default."     ";
    print $c_magenta.$c_bold."    SP".$c_cyan.$c_bold." : ".$c_blue.$c_bold."Spain only".$c_magenta.$c_bold."      SK".$c_cyan.$c_bold." : ".$c_blue.$c_bold."Slovakia only".$c_default."\n";
    print $c_white.$c_bold."  [".$c_green.$c_bold."*".$c_white.$c_bold."]".$c_cyan.$c_bold." : ".$c_blue.$c_bold."valid account found".$c_default."  ";
    print $c_magenta.$c_bold."    DK".$c_cyan.$c_bold." : ".$c_blue.$c_bold."Denmark only".$c_magenta.$c_bold."    IT".$c_cyan.$c_bold." : ".$c_blue.$c_bold."Italy only".$c_default."\n";
    print $c_magenta.$c_bold."                                 IE".$c_cyan.$c_bold." : ".$c_blue.$c_bold."Ireland only". "\n";
    
    exit(0);
}
#
# print the addressbook
sub print_addressbook() {
    my $ADDRESSBOOK = $HOME."addressbook";
    my ($LINE, @BOOK);
    # open addressbook file and push registers into @BUFFER
    open (ADDRESSBOOK, $ADDRESSBOOK) or die $c_red.$c_bold.$c_blink."error\!, can\'t open ".$ADDRESSBOOK.$c_default."\n";
    print $c_yellow.$c_bold."Available names in addressbook:".$c_default."\n";
    while ($LINE = <ADDRESSBOOK>) {
        # we like to skip blank lines and comments
        if (($LINE !~ /^$/) && ($LINE !~ /^#/)) { push @BOOK, $LINE; }
    }
    # we like an alpha sorted addressbook 8-)
    @BOOK = sort @BOOK;
    print $c_red.$c_bold."- [prefix  number]  [   name   ]  [ default server ]\n";
    foreach $LINE (@BOOK) {
        if ($LINE =~ /^(\w+)\:(\d{0,5})\:(\d{7,15})\:?(\w*)?$/) {
            # this entry has a default prefix
            if ($2) {
                print $c_cyan.$c_bold."- ".$c_blue."\[ ".$c_blue.$c_bold.$2." ".$3.$c_blue." \]".$c_cyan.$c_bold." :  ".$c_green.$1." "x(10 - length($1)).$c_cyan.$c_bold.": ".$c_magenta.$4.$c_default."\n";
            }
            # we append the default prefix
            else {
                print $c_cyan.$c_bold."- ".$c_blue."\[ ".$c_blue.$c_bold.$MYPREFIX." ".$3.$c_blue." \]".$c_cyan.$c_bold." :  ".$c_green.$1." "x(10 - length($1)).$c_cyan.$c_bold.": ".$c_magenta.$4.$c_default."\n";
            }
        }
    }
    close (ADDRESSBOOK);
    exit(0);
}
#
# find name in addressbook and returns the number
sub addressbook() {
    my $ADDRESSBOOK = $HOME."addressbook";
    my ($LINE, $N);
    # open addressbook file
    open (ADDRESSBOOK, $ADDRESSBOOK) or die $c_red.$c_bold.$c_blink."error\!, can\'t open ".$ADDRESSBOOK.$c_default."\n";
    # foreach line
    while ($LINE = <ADDRESSBOOK>) {
        # we like to skip blank lines and comments
        if (($LINE !~ /^$/) && ($LINE !~ /^#/)) {
            if ($LINE =~ /^(\w+)\:(\d{0,5})\:(\d{7,15})\:?(\w*)?$/) {
                # if we found the name
                if ($_[0] eq $1) { 
                    # we get the prefix
                    if ($2) { $MYPREFIX = $2; }
                    # and the number
                    $N = $3;
                    # and the default server
                    if ($4) { $DEFAULT_SERVER = $4; }
                }
            }
        }
    }
    close (ADDRESSBOOK);
    # hey, who are you ?
    if (! $N) { die $c_red.$c_bold.$c_blink."error\!, name ".$_[0]." was not found in ".$ADDRESSBOOK.$c_default."\n"; }
    # returns number
    return($N);
}
#
# find login && passwd of server
sub auth() {
    # don't overwrite if set login && password from commandline
    if ($LOGIN && $PASSWD) { return(0); }
    my $PASSWORD = $HOME."password";
    my $LINE;
    # open password file
    open (PASSWORD, $PASSWORD) or die $c_red.$c_bold.$c_blink."error\!, can\'t open ".$PASSWORD.$c_default."\n";
    while ($LINE = <PASSWORD>) {
        # we like to skip blank lines and comments
        if (($LINE !~ /^$/) && ($LINE !~ /^#/)) {
            if ($LINE =~ /^(.+)\:(.+)\:(.+)$/) {
                # we found a valid account for the server taken from $_[0]
                if ($_[0] eq $1) { $LOGIN = $2; $PASSWD = $3; }
            }
        }
    }
    close (PASSWORD);
    # we do not found a login && passwd for this server
    if (! ($LOGIN && $PASSWD)) {
	print $c_red.$c_bold.$c_blink."error\!, account for server ".$_[0]." was not found in ".$PASSWORD.$c_default."\n"; 
	die $c_yellow.$c_bold."Go to ".$_[0]." homepage, create an account and add it in ".$PASSWORD.$c_default."\n"; 
    }
}
#
# find the hostname (FQDN) and sms charlimit of a server
sub parse_server() {
    my $FAMILY;
    # foreach servers
    foreach $FAMILY (keys %HSERVERS) {
        # if found the server
        if ($FAMILY eq $_[0]) {
            # servername
            $SERVER = $FAMILY;
            # FQDN for open socket
            $URL = $HSERVERS{$FAMILY}[1];
            # charlimit for this server
            $SMSCHARLIMIT = $HSERVERS{$FAMILY}[6];
        }
    }
    # no server found
    if (! $URL) { die $c_red.$c_bold.$c_blink."error\!, the server ".$_[0]." was not found".$c_default."\n"; }
}
#
# check if string is a server
sub is_server() {
    my $FAMILY;
    my $FOUND = 0;
    # foreach server names
    foreach $FAMILY (keys %HSERVERS) {
        # string at $_[0] is a valid server
        if ($FAMILY eq $_[0]) { $FOUND = 1; }
    }
    return($FOUND);
}
#
# check if string is a name of addressbook
sub is_name() {
    my $ADDRESSBOOK = $HOME."addressbook";
    my $LINE;
    my $FOUND = 0;
    # open addressbook file
    open (ADDRESSBOOK, $ADDRESSBOOK) or die $c_red.$c_bold.$c_blink."error\!, can\'t open ".$ADDRESSBOOK.$c_default."\n";
    while ($LINE = <ADDRESSBOOK>) {
        # we like to skip blank lines and comments
        if (($LINE !~ /^$/) && ($LINE !~ /^#/)) {
            if ($LINE =~ /^(.*)\:(\d{0,3})\:(\d{8,15})\:?(\w*)?$/) {
                # string at $_[0] is a entry of addressbook
                if ($_[0] eq $1) { $FOUND = 1; }
            }
        }
    }
    close (ADDRESSBOOK);
    return($FOUND); 
}
#
# read options from main config file
sub config() {
    my $CONFIG = $HOME."linuxsmsrc";
    my $LINE;
    # set defaults
    $MYNUMBER = 000000000;
    $MYPREFIX = 34;  $SERVER_LIST = 1;
    $CMDLINE = 1; $SIGNATURE = ""; $SIG = 0; $SECURE_MODE = 1;
    $LOG = 0; $ALIAS = "linuxsms";
    # open configuration file
    open (CONFIG, $CONFIG) or die $c_red.$c_bold.$c_blink."error\!, can\'t open ".$CONFIG.$c_default."\n";
    while ($LINE = <CONFIG>) {
        # we like to skip blank lines and comments
        if (($LINE !~ /^$/) && ($LINE !~ /^#/)) {
            # overwrite defaults with this
            if    ($LINE =~ /^MYNUMBER\=(\d{7,15})$/) { $MYNUMBER = $1; }
            elsif ($LINE =~ /^SERVER\=(\w*)$/i) { $DEFAULT_SERVER = $1; }
            elsif ($LINE =~ /^PREFIX\=(\d{0,5})$/) { $MYPREFIX = $1; }
            elsif ($LINE =~ /^CMDLINE\=(\d)$/) { $CMDLINE = $1; }
            elsif ($LINE =~ /^SIGNATURE\=(.*)\n$/) { if ($1) { $SIGNATURE = $1; } }
            elsif ($LINE =~ /^ALWAYS_SIGNATURE\=YES$/i) { $SIG = 1; }
            elsif ($LINE =~ /^ANSI\=YES$/i) { &set_ansi(); }
            elsif ($LINE =~ /^SECURITY\=NO$/i) { $SECURE_MODE = 0; }
            elsif ($LINE =~ /^SERVER_LIST\=FULL$/i) { $SERVER_LIST = 1; }
            elsif ($LINE =~ /^PROXY\=(.*\:\d{1,5})$/i) { $PROXY = $1; }
            elsif ($LINE =~ /^LOG\=YES$/i) { $LOG = 1; }
            elsif ($LINE =~ /^MYALIAS\=(\w*)$/) { $ALIAS = $1; }
        }
    }
    close (CONFIG);
}
#
# parse long commandline options (old method)
sub parse_commandline() {
    if (@ARGV < 1) { die $c_red.$c_bold."error\!, no commandline options found, type ".$0." -h for help".$c_default."\n"; }
    foreach my $command (@ARGV) {
        if ($command =~ /^-h$/) { help(); }
        elsif ($command =~ /^-server$/) { &print_available_servers(); }
        elsif ($command =~ /^-server\:(.+)$/) { $SERVER = $1; }
        elsif ($command =~ /^-addressbook$/) { &print_addressbook(); }
        elsif ($command =~ /^-name\:(.+)$/) { $NAME = $1; }
        elsif ($command =~ /^-number\:([0-9]{7,15})$/) { $NUMBER = $1; }
        elsif ($command =~ /^-prefix\:([0-9]{0,5})$/) { $MYPREFIX = $1; }
        elsif ($command =~ /^-sms\:(.{1,})$/) { $SMS = $1; }  # ONLY ranges of 1-$MAX_SMS_LENGTH chars allowed
        elsif ($command =~ /^-update$/) { &find_new_version(); }
        elsif ($command =~ /^-debug$/) { $DEBUG = 1; }
        elsif ($command =~ /^-flash$/) { $FLASH = 1; }
        elsif ($command =~ /^-sig$/) { $SIG = 1; }
        elsif ($command =~ /^-z$/) { $COMPRESS = 1; }
        elsif ($command =~ /^-anonymous$/) { $MYNUMBER = ""; }
        elsif ($command =~ /^-login\:(\w+)$/) { $LOGIN = $1; }
        elsif ($command =~ /^-password\:(\w+)$/) { $PASSWD = $1; }
        elsif ($command =~ /^-confirm$/) { $CONFIRM = "on"; }
        elsif ($command =~ /^-credits$/) { $GET_CREDITS = 1; }
        else { die $c_red.$c_bold.$c_blink."error\!, bad options in commandline, type ".$0." -h for help".$c_default."\n"; }
    }
}
#
# parse short commandline options (new method)
sub parse_commandline_new() {
    if (@ARGV < 1) { die $c_red.$c_bold.$c_blink."error\!, no commandline options found, type ".$0." -h for help".$c_default."\n"; }
    foreach my $command (@ARGV) {
        if ($command !~ /^-(.*)/) { # is not a commandline (-xxx)
            if ($command !~ /^[0-9]{7,15}$/) { # is not a number ?
                if ($command !~ /^[0-9]{0,5}$/) { # is not a country prefix ?
                    if (! &is_name($command)) { # is not a name ?
                        if (! &is_server($command)) { # is not a server ?
                            $SMS = $command; # them, sure that it is the text for sms 8-)
                        }
                        else { $SERVER = $command; }
                    }
                    else { $NAME = $command; }
                }
                else { $MYPREFIX = $command; }
            }
            else { $NUMBER = $command; }
        }
        else {
            if ($command =~ /^-h$/) { help(); }
            elsif ($command =~ /^-server$/) { &print_available_servers(); }
            elsif ($command =~ /^-addressbook$/) { &print_addressbook(); }
            elsif ($command =~ /^-login\:(\w+)$/) { $LOGIN = $1; }
            elsif ($command =~ /^-password\:(\w+)$/) { $PASSWD = $1; }
            elsif ($command =~ /^-update$/) { &find_new_version(); }
            elsif ($command =~ /^-debug$/) { $DEBUG = 1; }
            elsif ($command =~ /^-flash$/) { $FLASH = 1; }
            elsif ($command =~ /^-sig$/) { $SIG = 1; }
            elsif ($command =~ /^-anonymous$/) { $MYNUMBER = ""; }
            elsif ($command =~ /^-z$/) { $COMPRESS = 1; }
            elsif ($command =~ /^-confirm$/) { $CONFIRM = "on"; }
            elsif ($command =~ /^-credits$/) { $GET_CREDITS = 1; }
            else { die $c_red.$c_bold.$c_blink."error\!, bad options in commandline, type ".$0." -h for help".$c_default."\n"; }
        }
    }
}
#
# compress sms
sub compress() {
    my $LENGTH = length($SMS);
    my ($SEARCH, $REPLACE);
    # strip blank spaces at begin
    $SMS =~ s/^[\s]{1,}//;
    # strip blank spaces at end
    $SMS =~ s/[\s]{1,}$//;
    # strip unwanted blank spaces repeated
    $SMS =~ s/[\s]{2,}/\ /g;
    # parse dictionary
    my $DICT = $HOME."dict";
    my ($LINE, @BUFFER);
    # open dictionary file
    open (DICT, $DICT) or die $c_red.$c_bold.$c_blink."error\!, can\'t open ".$DICT.$c_default."\n";
    while ($LINE = <DICT>) {
        # we like to skip blank lines and comments
        # and store the interesting data into @BUFFER
        if (($LINE !~ /^$/) && ($LINE !~ /^#/)) { push @BUFFER, $LINE; }
    }
    # foreach word of dictionary
    foreach (@BUFFER) {
        /(\w+):(\w+)/;
        $SEARCH = $1;
        $REPLACE = $2;
        # replace the magic word when found in SMS
        $SMS =~ s/$SEARCH/$REPLACE/ig;
    }
    my $LENGTH2 = $LENGTH - length($SMS);
    print $c_black.$c_bold."zip sms: ".$c_white.$c_bold."\"$SMS\"".$c_black.$c_bold." \[".$LENGTH2." chars saved\]".$c_default."\n";
}
#
# open a socket in remote host at remote port
# remote host is taken from $_[0]
# remote port is taken from $_[1] (if omitted uses default [80] http)
sub open_socket() {
    my $PORT = 80;
    my ($PROXY_HOST, $PROXY_PORT);
    # non standard port found in $_[1]
    if ($_[1] && $_[1] =~ /\d{1,5}/) { $PORT = $_[1]; }
    # normal connection, no proxy
    if (! $PROXY) {
        $HTTP_SOCKET = IO::Socket::INET->new(PeerAddr => $_[0], PeerPort => $PORT, Proto => "tcp");
    }
    # hello proxy, is anoybody here ?
    else {
        $PROXY =~ /(.+)\:(\d{1,5})/;
        $PROXY_HOST = $1;
        $PROXY_PORT = $2;
        if ($PROXY_HOST && $PROXY_PORT) {
            $HTTP_SOCKET = IO::Socket::INET->new(PeerAddr => $PROXY_HOST, PeerPort => $PROXY_PORT, Proto => "tcp");
        }
        else {
            print $c_black.$c_bold."\nerror  : ".$c_red.$c_bold.$c_blink."bad proxy".$c_default."\n";
            exit(3);
        }
    }
    # better luck next time
    unless ($HTTP_SOCKET) {
        if (! $PROXY) {
            print $c_black.$c_bold."\nerror  : ".$c_red.$c_bold.$c_blink."can\'t open socket at ".$_[0].$c_default."\n";
        }
        else {
            print $c_black.$c_bold."\nerror  : ".$c_red.$c_bold.$c_blink."can\'t open socket at ".$PROXY_HOST.":".$PROXY_PORT.$c_default."\n";
        }
        exit(3);
    }
}
#
# returns hexadecimal value from a char taken from $_[0]
sub char_to_hex() { 
    return sprintf '%%%02X', ord $_[0];
}
#
# elemental procedure to parse cookies
# Cookie Header must be taken from $_[0]
sub parse_cookies() {
    my (@rawcookies, $buffer, $exist);
    # LWP rules 8-)
    @rawcookies = split(/;/,$_[0]);
    foreach $buffer (@rawcookies) {
        #if($line =~ /^[ \t]*(.+)=(.*)$/) { # this was taken from LWP but wont works :-m
        if($buffer =~ /([^\s]*)=([^\s]*)/) {
            my ($name, $val) = ($1, $2);
            # skip domain, path and expires, yes, sucks, but works (I think) 8-)
            if($name !~/^(domain|path|expires)$/i && $val ne '') {
                $exist = 0;
                # foreach cookie
                foreach $buffer (keys %COOKIES) {
                    # must test if exist, and overrite with new value
                    if ($buffer eq $name) {
                        $COOKIES{$buffer} = $val;
                        $exist = 1;
                    }
                }
                # if cookie does not exist, we must store it
                if (! $exist) { $COOKIES{$name} = $val; }
                # if we have cookies, we need to know them
                $COOKIES{"check_this_for_cookies_existence"} = 1;
            }
        }
    }
    return(%COOKIES);
}
#
# construct cookie header and returns string with Cookie Header
sub write_cookies() {
    # if we have cookies to cook 8-)
    if ($COOKIES{"check_this_for_cookies_existence"}) {
        my ($c, $buffer);
        $c = "Cookie:";
        foreach $buffer (keys %COOKIES) {
            # exist is only a variable to check if we have cookies or not
            # we dont like to put them into Cookie Header
            if ($buffer ne "check_this_for_cookies_existence") {
                $c .= " ".$buffer."=".$COOKIES{$buffer}.";";
            }
        }
        # delete last separator
        $c =~ s/;$//;
        # push CR LF
        $c .= "\r\n";
        # returns Cookie Header
        return($c);
    }
    else { return(0); }
}
#
# get && parse HTTP header
# returns HTTP CODE
sub parse_http_header() {
    my $LINE;
    my $CODE = 0;
    my $HEADER = 1;
    while ($HEADER) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        # strip CR LF
        $LINE =~ s/\r//ig;
        $LINE =~ s/\n//ig;
        # HTTP header, first line (HTTP/majorversion.minorversion && response code)
        if ($LINE =~ /^HTTP\/(\d)\.(\d)\ (\d{3})\ (.*)/ ) {
            if ($1 != 1) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold.$c_blink."HTTP major version must be 1\n"; 
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
            if ($2 != 0 && $2 != 1) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold.$c_blink."HTTP minor version must be 0\|\|1\n"; 
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
        }
        if (defined $3) { $CODE = $3; }
        # Header != 2xx (OK) || 3xx (MOVED) || 4xx (NOT FOUND)
        #if ($CODE !~ /^[2-4]\d{2}$/) {
        #    print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold.$c_blink."server response unknown HTTP header: ".$c_default."\n";
        #    print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
        #    exit(2);
        #}
        while ($HEADER) {
            # next lines of HTTP header
            if (! ($LINE = <$HTTP_SOCKET>)) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
            if ($DEBUG) { print STDERR $LINE; }
            # until we no reached the end of HTTP Header, strip CR LF
            if ($LINE !~ /^\r\n$/) {
                $LINE =~ s/\r//ig;
                $LINE =~ s/\n//ig;
            }
            # get COOKIES
            if ($LINE =~ /^Set-Cookie:/i) { %COOKIES = &parse_cookies($LINE); }
            # get LOCATION
            elsif ($LINE =~ /^Location\:\ (.*)$/i) { $HTTP_REQUEST{"LOCATION"} = $1; }
            # get HOST
            elsif ($LINE =~ /^Host\:\ (.*)$/i) { $HTTP_REQUEST{"HOST"} = "Host: ".$1."\r\n"; }
            # end of HTTP header
            elsif ($LINE =~ /^\r\n$/) { undef $HEADER; }
        }
    }
    return($CODE);
}
#
# HTTP HEAD method
sub HTTP_HEAD() {
    my $BUF;
    $BUF  = "HEAD ".$HTTP_REQUEST{"HEAD"}." HTTP/1.0\r\n";
    $BUF .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)\r\n";
    if ($HTTP_REQUEST{"HOST"}) { $BUF .= $HTTP_REQUEST{"HOST"}; }
    if ($HTTP_REQUEST{"REFERER"}) { $BUF .= $HTTP_REQUEST{"REFERER"}; }
    $BUF .= "Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*\r\n";
    # we only like to send cookies if we have cookies ;)
    if ($COOKIES{"check_this_for_cookies_existence"}) { $BUF .= &write_cookies(); }
    $BUF .= "Pragma: no-cache\r\n";
    $BUF .= "Cache-Control: no-cache\r\n";
    $BUF .= "Connection: Keep-Alive\r\n";
    $BUF .= "\r\n";
    if ($DEBUG) { print STDERR "\n".$BUF; }
    print $HTTP_SOCKET $BUF;
}
#
# HTTP GET method
sub HTTP_GET() {
    my $BUF;
    $BUF  = "GET ".$HTTP_REQUEST{"GET"}." HTTP/1.0\r\n";
    $BUF .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)\r\n";
    if ($HTTP_REQUEST{"HOST"}) { $BUF .= $HTTP_REQUEST{"HOST"}; }
    if ($HTTP_REQUEST{"REFERER"}) { $BUF .= $HTTP_REQUEST{"REFERER"}; }
    $BUF .= "Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*\r\n";
    # we only like to send cookies if we have cookies ;)
    if ($COOKIES{"check_this_for_cookies_existence"}) { $BUF .= &write_cookies(); }
    $BUF .= "Pragma: no-cache\r\n";
    $BUF .= "Cache-Control: no-cache\r\n";
    $BUF .= "Connection: Keep-Alive\r\n";
    $BUF .= "\r\n";
    if ($DEBUG) { print STDERR "\n".$BUF; }
    print $HTTP_SOCKET $BUF;
}
#
# HTTP POST method
sub HTTP_POST() {
    my $BUF;
    $BUF  = "POST ".$HTTP_REQUEST{"POST"}." HTTP/1.0\r\n";
    $BUF .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)\r\n";
    if ($HTTP_REQUEST{"HOST"}) { $BUF .= $HTTP_REQUEST{"HOST"}; }
    if ($HTTP_REQUEST{"REFERER"}) { $BUF .= $HTTP_REQUEST{"REFERER"}; }
    $BUF .= "Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*\r\n";
    # we only like to send cookies if we have cookies ;)
    if ($COOKIES{"check_this_for_cookies_existence"}) { $BUF .= &write_cookies(); }
    $BUF .= "Content-type: application/x-www-form-urlencoded\r\n";
    $BUF .= "Content-length: ".length($HTTP_REQUEST{"DATA"})."\r\n";
    $BUF .= "\r\n";
    $BUF .= $HTTP_REQUEST{"DATA"};
    if ($DEBUG) { print STDERR "\n".$BUF."\n"; }
    print $HTTP_SOCKET $BUF;
}
#
# check for updates of script
sub find_new_version() {
    # vars
    $HTTP_REQUEST{"GET"} = "http://linuxsms.sourceforge.net/";
    $HTTP_REQUEST{"HOST"} = "Host: ".$LINUXSMSURL."\r\n";
    if ($VERSION =~ /pre/i) {
        print $c_cyan.$c_bold."You are using a testing-unstable version".$c_default."\n";
    }
    print $c_yellow.$c_bold."Checking for versions > ".$VERSION.$c_default."\n";
    # open connection
    &open_socket($LINUXSMSURL);
    # send GET data
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    my ($LINE);
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Last version is\:\ (.*)\,/i) {
            my $V = $1;
            if ($VERSION =~ /pre/i) {
                $VERSION =~ s/pre//i;
                if ($V >= $VERSION)
                {
                    print $c_red.$c_bold.$c_blink."New version found \(v".$V."\)".$c_default."\n";
                    print $c_cyan.$c_bold."Download it from http://".$LINUXSMSURL.$c_default."\n";
                    last;
                }
                else {
                    print $c_cyan.$c_bold."You have the latest version".$c_default."\n";
                    last;
                }
            }
            else {
                if ($V == $VERSION) { print $c_cyan.$c_bold."You have the latest version".$c_default."\n"; last; }
                elsif ($V > $VERSION) {
                    print $c_red.$c_bold.$c_blink."New version found \(v".$V."\)".$c_default."\n";
                    print $c_cyan.$c_bold."Download it from http://".$LINUXSMSURL.$c_default."\n";
                    last;
                }
            }
        }
        elsif ($LINE =~ /\<\/html\>/i) {
            print $c_red.$c_bold.$c_blink."Error parsing version".$c_default."\n";
            last;
        }
    }
    close(HTTP_SOCKET);
    exit(0);
}
#
#
# --- servers section BEGIN ---
#
# process server [everyday]
sub sms_everyday() {
    if ($MYPREFIX != 34) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." only sends to Spain (34), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    # vars
    my $CREDITS = 0;
    my $POLL = 0;
    $HTTP_REQUEST{"HEAD"} = "http://everyday.com/";
    $HTTP_REQUEST{"HOST"} = "Host: everyday.com\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://sms.everyday.com/\r\n";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_HEAD();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close($HTTP_SOCKET);
    # vars
    $HTTP_REQUEST{"GET"} = "http://sms.es.everyday.com/login.phtml?login_username=".$LOGIN."&login_password=".$PASSWD;
    $HTTP_REQUEST{"REFERER"} = "Referer: http://sms.everyday.com/\r\n";
    $HTTP_REQUEST{"HOST"} = "Host: sms.es.everyday.com\r\n";
    # we need this cookie to continue
    $COOKIES{"BrowserDetect"} = "passed";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    close ($HTTP_SOCKET);
    if ($HTTP_REQUEST{"LOCATION"} ne "http://www.es.everyday.com/") {
        print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."wrong login/passwd".$c_default."\n";
        print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
        exit(2);
    }
    print $c_black.$c_bold."\npostcrd:".$c_default;
    print $c_white.$c_bold." *".$c_default;
    # enviar postal
    $HTTP_REQUEST{"POST"} = "http://www.ecard.es.everyday.com/index.phtml";
    $HTTP_REQUEST{"HOST"} = "Host: www.ecard.es.everyday.com\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.ecard.es.everyday.com/index.phtml\r\n";
    $HTTP_REQUEST{"DATA"} = "EcardImageId=592e4641&EcardCategory=CAT_CHRISTMAS&EcardForeColor=%23000000&EcardBgColor=%23ffffff&FontStyle=apptextPlain&EcardFromName=myname&EcardFromEmail=".$LOGIN."%40everyday.com&EcardToName=yourname&EcardToEmail=".$LOGIN."%40everyday.com&EcardTitle=esto+es+el+titulo&EcardText=esto+es+el+mensaje&EcardSend=Enviar";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Tu\ postal\ ha\ sido\ enviada/i) {
            print $c_black.$c_bold."\nstatus : ".$c_white.$c_bold."postcard sent ok".$c_default."\n";
            # postcard sent ok
            last;
        }
        elsif ($LINE =~ /\<\/body\>/i) {
            print $c_black.$c_bold."\nstatus : ".$c_white.$c_bold."error sending postcard".$c_default."\n";
            # error sending postcard
            last;
        }
    }
    close ($HTTP_SOCKET);
    print $c_black.$c_bold."process:".$c_default;
    # get poll id
    $HTTP_REQUEST{"GET"} = "http://www.es.everyday.com/";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /<input\ type=\"hidden\"\ name=\"question_id\"\ value=\"(\d+)\">/i) {
            $POLL = $1;
            last;
        }
        elsif ($LINE =~ /\<\/body\>/i) {
            if (! $POLL) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t get poll id".$c_default;
            }
            last;
        }
    }
    close ($HTTP_SOCKET);
    print $c_black.$c_bold."\nvoting :".$c_default;
    print $c_white.$c_bold." *".$c_default;
    # votar encuesta
    if ($POLL) {
        $HTTP_REQUEST{"POST"} = "http://www.voting.es.everyday.com/index.phtml";
        $HTTP_REQUEST{"HOST"} = "Host: www.voting.es.everyday.com\r\n";
        $HTTP_REQUEST{"REFERER"} = "Referer: http://www.es.everyday.com/index.phtml\r\n";
        $HTTP_REQUEST{"DATA"} = "question_id=".$POLL."&static=1&voting_redirect_url=&link=&link_height=&link_width=&link_params=&variant=2&vote=%A1%A1Vota%21%21";
        # open socket
        &open_socket($URL);
        print $c_white.$c_bold." *".$c_default;
        # send POST
        &HTTP_POST();
        # get && parse HTTP header
        &parse_http_header();
        print $c_white.$c_bold." *".$c_default;
        while (1) {
            if (! ($LINE = <$HTTP_SOCKET>)) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
            if ($DEBUG) { print STDERR $LINE; }
            if ($LINE =~ /Gracias\ por\ votar/i) {
                # vote ok
                print $c_black.$c_bold."\nstatus : ".$c_white.$c_bold."vote ok".$c_default."\n";
                last;
            }
            elsif ($LINE =~ /Solo\ puedes\ votar\ una\ vez/i) {
                print $c_black.$c_bold."\nstatus : ".$c_white.$c_bold."you have voted today".$c_default."\n";
                last;
            }
            elsif ($LINE =~ /\<\/body\>/i) {
                # error sending postcard
                last;
            }
        }
        close ($HTTP_SOCKET);
    }
    else {
        print $c_black.$c_bold."\nstatus : ".$c_white.$c_bold."you have voted today".$c_default."\n";
    }
    print $c_black.$c_bold."process:".$c_default;
    # get credits
    $HTTP_REQUEST{"GET"} = "http://www.es.everyday.com/";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Mis\ Puntos/i) {
            if (! ($LINE = <$HTTP_SOCKET>)) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
            if ($LINE =~ /apptextSmall\">(\d*)/i) {
                $CREDITS = $1;
                last;
            }
        }
        elsif ($LINE =~ /\<\/body\>/i) {
            if (! $CREDITS) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t get credits".$c_default."\n";
            }
            last;
        }
    }
    close ($HTTP_SOCKET);
    print $c_black.$c_bold."\ncredits:".$c_white.$c_bold." ".$CREDITS."\n";
    if ($GET_CREDITS) {
        exit;
    }
    print $c_black.$c_bold."process:".$c_default;
    # vars
    $HTTP_REQUEST{"POST"} = "http://sms.es.everyday.com/index.phtml";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://sms.es.everyday.com/index.phtml\r\n";
    $HTTP_REQUEST{"DATA"} = "banner_id=&type_flash=&timed_at=&message=".$SMS."&gsmnumber=".$MYPREFIX.$NUMBER."&fromname=&send_sms=Enviar&show_sender_number=";
    if ($MYNUMBER) {
        $HTTP_REQUEST{"DATA"} .= "1";
    }
    else {
        $HTTP_REQUEST{"DATA"} .= "0";
    }
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /El mensaje no puede ser m.s largo de (\d*) car.cteres/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."sms char limit was changed".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        if ($LINE =~ /Has\ llegado\ a\ tu\ limite\ de\ mensajes/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(3\) in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /Para\ enviar\ sms\ necesitas\ tener\ (\d*)/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you don\'t have enought \(".$1."\) credits".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /El servicio de env\&iacute;o de SMS est\&aacute; sufriendo alg\&uacute;n problema\.\.\. Pruebe m\&aacute;s tarde/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."server exhausted".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /Tu\ mensaje\ ha\ sido\ enviado/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /Enviaste 2 mensajes hoy/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(3\) in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /El\ envio\ de\ SMS\ est.\ limitado\ a\ 3\ mensajes/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(3\) in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /\<\/body\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
}
# process server [everyday_fr]
sub sms_everyday_fr() {
    if ($MYPREFIX == 34) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." do not send to spain (34), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    # vars
    $HTTP_REQUEST{"HEAD"} = "http://fr.everyday.com/";
    $HTTP_REQUEST{"HOST"} = "Host: fr.everyday.com\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://sms.fr.everyday.com/\r\n";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_HEAD();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close($HTTP_SOCKET);
    # vars
    $HTTP_REQUEST{"GET"} = "http://sms.fr.everyday.com/login.phtml?login_username=".$LOGIN."&login_password=".$PASSWD;
    $HTTP_REQUEST{"REFERER"} = "Referer: http://sms.fr.everyday.com/\r\n";
    $HTTP_REQUEST{"HOST"} = "Host: sms.fr.everyday.com\r\n";
    # we need this cookie to continue
    $COOKIES{"BrowserDetect"} = "passed";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    close ($HTTP_SOCKET);
    if ($HTTP_REQUEST{"LOCATION"} ne "http://www.fr.everyday.com/")   	{
        print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."wrong login/passwd".$c_default."\n";
        print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
        exit(2);
    }
    # exit;
    # vars
    $HTTP_REQUEST{"POST"} = "http://sms.fr.everyday.com/index.phtml";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://sms.fr.everyday.com/index.phtml\r\n";
    $HTTP_REQUEST{"DATA"} = "banner_id=&type_flash=&timed_at=&message=".$SMS."&gsmnumber=".$MYPREFIX.$NUMBER."&fromname=&send_sms=1";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Has\ llegado\ a\ tu\ limite\ de\ mensajes/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(2\) in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /Pour\ envoyer\ un\ SMS,\ vous devez\ disposer\ d'au\ moins\ (\d*)/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you don\'t have enought \(".$1."\) points".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /Votre\ message\ est\ en\ cours\ d'envoi/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /Vous\ avez\ envoy\ 3\ message\(s\)\ aujourd'hui/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(3\) in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /\<\/body\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
}

#
# process server [firstwap]
sub sms_firstwap() {
    if ($MYPREFIX == 34) {
        print $c_black.$c_bold."warning: ".$c_white.$c_bold.$c_blink.$SERVER." have a unstable support to Spain".$c_default."\n";
    }
    # vars
    $HTTP_REQUEST{"GET"} = "http://www.1rstwap.com/partners/go.to/1rstwap";
    $HTTP_REQUEST{"HOST"} = "Host: www.1rstwap.com\r\n";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    # vars
    $HTTP_REQUEST{"POST"} = "http://www.1rstwap.com/partners/go.php?PHPSESSID=".$COOKIES{"PHPSESSID"}."&sestime=01112001140708&pid=login";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.1rstwap.com/partners/go.php?PHPSESSID=".$COOKIES{"PHPSESSID"}."&pid=first\r\n";
    $HTTP_REQUEST{"DATA"} = "UserID=".$LOGIN."&Passwd=".$PASSWD."&submitButtonName=Sign+In&language=%2Fpartners%2Fgo.php%3FPHP_SESSID%3D%26pid%3Dfirst%26LangID%3Den%26cobid%3D1RSTWAP&cobid=1RSTWAP";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    # vars
    $HTTP_REQUEST{"GET"} = "http://www.1rstwap.com/partners/go.php?PHPSESSID=".$COOKIES{"PHPSESSID"}."&pid=home";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.1rstwap.com/partners/go.php?PHPSESSID=".$COOKIES{"PHPSESSID"}."&sestime=01112001141842&pid=login\r\n";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($SESSTIME, $LINE);
    while (1) { 
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /sestime\=(\d*)/i) {
            $SESSTIME="&sestime=".$1;
            last;
        }
        elsif ($LINE =~ /\<\/html\>/i) {
            last;
        }
    }
    close ($HTTP_SOCKET);
    # vars
    $HTTP_REQUEST{"POST"} = "http://www.1rstwap.com/partners/go.php?PHPSESSID=".$SESSTIME."&pid=addressbook&aid=smswindow&step=send";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.1rstwap.com/partners/go.php?pid=addressbook&aid=smswindow&step=openfmenu\r\n";
    if ($FLASH) {
        $HTTP_REQUEST{"DATA"}  = "hp=".$MYPREFIX.$NUMBER."&COUNTER=0&m=".$SMS."&submitButtonName=Send&SENDER=".$MYPREFIX.$MYNUMBER."&flashsms=1";
    }
    else {
        $HTTP_REQUEST{"DATA"}  = "hp=".$MYPREFIX.$NUMBER."&COUNTER=0&m=".$SMS."&submitButtonName=Send&SENDER=".$MYPREFIX.$MYNUMBER;
    }
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    while (1) { 
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Message\ has\ been\ sent/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /Quota\ Exceeded/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(25\) in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /Destination\ Number\(s\)\ is\ not\ covered\ yet/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."destination number is not supported".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /\<\/html\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
}
#
# process server [orangedk]
#
sub sms_orangedk() {
    if ($MYPREFIX != 45) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." only sends to Denmark (45), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    # vars
    $HTTP_REQUEST{"GET"} = "http://myorange.dk/smsservices/";
    $HTTP_REQUEST{"HOST"} = "Host: myorange.dk\r\n";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://myorange.dk/smsservices/";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://myorange.dk/smsservices/\r\n";
    $HTTP_REQUEST{"DATA"} = "S216_login=".$LOGIN."&S216_passw=".$PASSWD;
    # we need this cookie
    $COOKIES{"brugernavncookie"} = $LOGIN;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://myorange.dk/besked/popup/";
    $HTTP_REQUEST{"REFERER"} = "";
    $HTTP_REQUEST{"DATA"} = "S302_recipient=".$NUMBER."&S302_online=off&S302_sender=&S302_message=".$SMS."&charsLeft=102";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) { 
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /besked\/resultat/i) {
            last;
        }
        elsif ($LINE =~ /\<\/HTML\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"GET"} = "http://myorange.dk/besked/resultat/";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    print $c_white.$c_bold." *".$c_default;
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    while (1) { 
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Beskeden\ er\ afleveret\ til\ telefonen/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /Telefonen\ er\ slukket\ eller\ udenfor/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /Der\ opstod\ en\ fejl/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /\<\/HTML\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
}
# TextAmerica
# process server [textamerica]
sub sms_textamerica() {
    if ($MYPREFIX != 1) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." only sends to USA (1), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    $HTTP_REQUEST{"POST"} = "http://www.textamerica.com/login.asp";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.textamerica.com/default.asp\r\n";
    $HTTP_REQUEST{"HOST"} = "Host: www.textamerica.com\r\n";
    $HTTP_REQUEST{"DATA"} = "Login=".$LOGIN."&Password=".$PASSWD;
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://www.textamerica.com/sms.asp";
    $HTTP_REQUEST{"HOST"} = "Host: www.textamerica.com\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.textamerica.com/sms.asp\r\n";
    $HTTP_REQUEST{"DATA"} = "Phone=".$NUMBER."&Subject=\"AIM Web Server\"&Message=".$SMS;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Your\ message\ was\ delivered\ successfully/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /\Sorry/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
    }
    close ($HTTP_SOCKET);
}
# SMSAC
# process server [smsac]
sub sms_smsac() {
    if ($MYPREFIX == 34) {
        print $c_black.$c_bold."warning: ".$c_white.$c_bold.$c_blink.$SERVER." do not send to amena".$c_default."\n";
    }
    # vars
    $HTTP_REQUEST{"HEAD"} = "http://www.sms.ac/";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_HEAD();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://www.sms.ac/login.asp?Referer=Send%20SMS";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.sms.ac/\r\n";
    $HTTP_REQUEST{"HOST"} = "Host: www.sms.ac\r\n";
    $HTTP_REQUEST{"DATA"} = "loginuserid=".$LOGIN."&loginpassword=".$PASSWD."&login=Sign+In";
    # we need this cookie
    $COOKIES{"cookieteste"} = "existscookie";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://www.sms.ac/d3fault.asp";
    $HTTP_REQUEST{"HOST"} = "Host: www.sms.ac\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.sms.ac/d3fault.asp\r\n";
    $HTTP_REQUEST{"DATA"} = "mobilenumber=".$MYPREFIX.$NUMBER."&message=".$SMS."&sizebox=&SendSMS=Send+SMS";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"GET"} = "http://www.sms.ac/ShowMsgResults.asp";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /Your SMS Message has been sent to the person/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /You need additional credits to send this message/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(2\) in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /expired/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the 30 day/8 sms limit free in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /\<\/HTML\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
}
# e-zones
# process server [ezones]
sub sms_ezones() {
    if ($MYPREFIX != 421) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." only sends to Slovakia (421), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    # vars
    $COOKIES{"check_this_for_cookies_existence"} = 1;
    $COOKIES{"ETEST"} = "TEST";
    $HTTP_REQUEST{"POST"} = "http://www.e-zones.sk/pls/ezones/!e_single_sign_on.login";
    $HTTP_REQUEST{"HOST"} = "Host: www.e-zones.sk\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.e-zones.sk/pls/ezones/e_single_sign_on.reload2?id=0\r\n";
    $HTTP_REQUEST{"DATA"} = "Userme=0&page=&menu=&extrapar=&user_name=".$LOGIN."&passwd=".$PASSWD;
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    # vars
    $HTTP_REQUEST{"POST"} = "http://www.e-zones.sk/pls/ezones/!e_sms_archive.send_sms_web";
    $HTTP_REQUEST{"REFERER"} = "http://www.e-zones.sk/pls/ezones/!e_sms.send\r\n";
    if ($FLASH) {
        $HTTP_REQUEST{"DATA"} = "VERROR=No&SEND_TIME=&PERIOD=&SMSID=&FLASH=on&MSG_TEXT=".$SMS."&SMSMsgLen=480&SMScount=1&SENDER=on&ADDR=0".$NUMBER."&ODOSLAT.x=36&ODOSLAT.y=17";
    }
    else {
        $HTTP_REQUEST{"DATA"} = "VERROR=No&SEND_TIME=&PERIOD=&SMSID=&FLASH=off&MSG_TEXT=".$SMS."&SMSMsgLen=480&SMScount=1&SENDER=on&ADDR=0".$NUMBER."&ODOSLAT.x=36&ODOSLAT.y=17";
    }
    if ($CONFIRM eq "on") {
        $HTTP_REQUEST{"DATA"} .= "&saved=1&delivered=1";
    }
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($ISOK, $LINE);
    $ISOK=0;
    while (1) { 
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($LINE =~ /Tvoja spr.va bola .spe./i) {
            $ISOK=1;
        }
        elsif ($LINE =~ /Aktu.lny stav tvojich E-zones Kreditov: ([0-9]*)/i) {
            print $c_black.$c_bold."\nCredit status: ".$c_white.$c_bold.$1."\n";
        }
        elsif ($LINE =~ /\<\/html\>/i) {
            last;
        }
    }
    close ($HTTP_SOCKET);
    if ($ISOK == 1) {
        print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
    }
    else {
        print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
        print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
        exit(2);
    }
}
# sunrise
# process server [sunrise]
sub sms_sunrise() {
    # vars
    $HTTP_REQUEST{"HEAD"} = "http://mymobile.sunrise.ch/portal/res/member/";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_HEAD();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://mymobile.sunrise.ch/portal/res/guest?paf_dm=full&paf_gear_id=100001&_DARGS=/portal/sunrise/gears/templates/html/LargeLogin.jsp";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://mymobile.sunrise.ch/portal/res/guest?paf_dm=full&paf_gear_id=100001&?successURL=/portal/res/member/\r\n";
    $HTTP_REQUEST{"HOST"} = "Host: mymobile.sunrise.ch\r\n";
    $HTTP_REQUEST{"DATA"} = "_dyncharset=ASCII&_lg=".$LOGIN."&_D%3A_lg=+&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin%2FLoginFormHandler.value.password=".$PASSWD;
    $HTTP_REQUEST{"DATA"} .= "&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin%2FLoginFormHandler.value.password=+&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin";
    $HTTP_REQUEST{"DATA"} .= "%2FLoginFormHandler.cookie=+&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin%2FLoginFormHandler.nextUrl=%2Fportal%2Fres%2Fguest%3Fpaf_dm";
    $HTTP_REQUEST{"DATA"} .= "%3Dfull%26paf_gear_id%3D100001&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin%2FLoginFormHandler.nextUrl=+&%2Fch%2Fsunrise%2Fportal";
    $HTTP_REQUEST{"DATA"} .= "%2Fmobile%2Flogin%2FLoginFormHandler.errUrl=%2Fportal%2Fres%2Fguest%3Fpaf_dm%3Dfull%26paf_gear_id%3D100001&_D%3A%2Fch%2Fsunrise";
    $HTTP_REQUEST{"DATA"} .= "%2Fportal%2Fmobile%2Flogin%2FLoginFormHandler.errUrl=+&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin%2FLoginFormHandler.guestUrl=";
    $HTTP_REQUEST{"DATA"} .= "%2Fportal%2Fres%2Fguest&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin%2FLoginFormHandler.guestUrl=+&%2Fch%2Fsunrise%2Fportal";
    $HTTP_REQUEST{"DATA"} .= "%2Fmobile%2Flogin%2FLoginFormHandler.mysuccessUrl=%2Fportal%2Fres%2Fmember%2F&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Flogin";
    $HTTP_REQUEST{"DATA"} .= "%2FLoginFormHandler.mysuccessUrl=+&loginSubmitImage.x=0&loginSubmitImage.y=0&_D%3AloginSubmitImage=+&_DARGS=%2Fportal%2Fsunrise";
    $HTTP_REQUEST{"DATA"} .= "%2Fgears%2Ftemplates%2Fhtml%2FLargeLogin.jsp";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    #Location: /portal/res/member/;jsessionid=JQ5YR1NAFZILZQFIGYZXRAQ?_requestid=65543
    if ($HTTP_REQUEST{"LOCATION"} !~ /portal\/res\/member\/;jsessionid=/i) {
        print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
        print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
        exit(2);
    }
    $HTTP_REQUEST{"POST"} = "http://mymobile.sunrise.ch/portal/res/member/?_DARGS=/portal/res/member/";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://mymobile.sunrise.ch".$HTTP_REQUEST{"LOCATION"}."\r\n";
    $HTTP_REQUEST{"DATA"} = "_dyncharset=ASCII&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms%2FSmsSendFormHandler.org";
    $HTTP_REQUEST{"DATA"} .= "Number=msisdn&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms%2FSmsSendFormHandler.org";
    $HTTP_REQUEST{"DATA"} .= "Number=+&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms%2FSmsSendFormHandler.successUrl=";
    $HTTP_REQUEST{"DATA"} .= "%2Fportal%2Fres%2Fmember%2F&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.successUrl=+&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.buyUrl=%2Fportal%2Fres%2Fmember%2F%3Fpaf_dm%3Dfull";
    $HTTP_REQUEST{"DATA"} .= "%26paf_gear_id%3D500013%26site%3DloadSms&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile";
    $HTTP_REQUEST{"DATA"} .= "%2Fsms%2FSmsSendFormHandler.buyUrl=+&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.destination=%2B".$MYPREFIX.$NUMBER."&_D%3A%2Fch%2Fsunrise";
    $HTTP_REQUEST{"DATA"} .= "%2Fportal%2Fmobile%2Fsms%2FSmsSendFormHandler.destination=+&text_count=24&_D";
    $HTTP_REQUEST{"DATA"} .= "%3AMESSAGE=+&MESSAGE=".$SMS."&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.update.x=12&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.update.y=10&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.update=true&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.update=+&%2Fch%2Fsunrise%2Fportal%2Fmobile%2Fsms";
    $HTTP_REQUEST{"DATA"} .= "%2FSmsSendFormHandler.sendMessages=true&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile";
    $HTTP_REQUEST{"DATA"} .= "%2Fsms%2FSmsSendFormHandler.sendMessages=+&%2Fch%2Fsunrise%2Fportal%2Fmobile";
    $HTTP_REQUEST{"DATA"} .= "%2Fsms%2FSmsSendFormHandler.formName=SmsSend&_D%3A%2Fch%2Fsunrise%2Fportal%2Fmobile";
    $HTTP_REQUEST{"DATA"} .= "%2Fsms%2FSmsSendFormHandler.formName=+&_DARGS=%2Fportal%2Fres%2Fmember%2F";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    if ($HTTP_REQUEST{"LOCATION"} !~ /portal\/res\/member\/;jsessionid=/i) {
        print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
        print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
        exit(2);
    }
    $HTTP_REQUEST{"GET"} = "http://mymobile.sunrise.ch".$HTTP_REQUEST{"LOCATION"};
    $HTTP_REQUEST{"REFERER"} = "Referer: http://mymobile.sunrise.ch".$HTTP_REQUEST{"LOCATION"}."\r\n";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /SMS gesendet/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /\<\/HTML\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
}
# aliceadsl
# process server [aliceadsl]
sub sms_aliceadsl() {
    if ($MYPREFIX != 39) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." only sends to Italia (39), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    $NUMBER =~ /(\d{3})\d*/;
    my $NETWORK = $1;
    $NUMBER =~ s/^$NETWORK//;
    # vars
    $HTTP_REQUEST{"POST"} = "http://www.lacasadialice.it/video/noAlice/checkLoginNoAliceAction.do";
    $HTTP_REQUEST{"HOST"} = "Host: www.lacasadialice.it\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: Referer: http://www.aliceadsl.it/alice/contents/index_statica.html\r\n";
    $HTTP_REQUEST{"DATA"} = "username=".$LOGIN."&password=".$PASSWD."&service=";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close ($HTTP_SOCKET);
    # get new cookie (gx_session_id)
    $HTTP_REQUEST{"GET"} = "http://www.lacasadialice.it/video/demand/publicService.do?service=3";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.lacasadialice.it/video/jsp/demand/services/services_menu.jsp?fileArea=false\r\n";
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send GET
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /iframe src=/i) {
            last;
        }
        elsif ($LINE =~ /\<\/BODY\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
    $LINE =~ /iframe src="([^"]+)"/i;
    # vars
    $HTTP_REQUEST{"GET"} = $1;
    $HTTP_REQUEST{"HOST"} = "Host: 156.54.232.11\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.lacasadialice.it/video/demand/publicService.do?service=3\r\n";
    # open socket
    &open_socket("156.54.232.11");
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_GET();
    # get && parse HTTP header
    &parse_http_header();
    close ($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://156.54.232.11/NASApp/scu187/wond_inviaSms.do";
    $HTTP_REQUEST{"REFERER"} = "Referer: " . $HTTP_REQUEST{"GET"} . "\r\n";
    $HTTP_REQUEST{"DATA"} = "prefisso=".$NETWORK."&numDest=".$NUMBER."&destFax=&nomeDest=&cognomeDest=&invio=0&data=&ora=&minuti=&testo=".$SMS."&insNumMittente=0";
    # open socket
    &open_socket("156.54.232.11");
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    &parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    while (1) {
        if (! ($LINE = <$HTTP_SOCKET>)) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
        if ($DEBUG) { print STDERR $LINE; }
        if ($LINE =~ /<font\ class=\"white11\">OK<\/font>/i) {
            print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
            last;
        }
        elsif ($LINE =~ /Siamo spiacenti, hai esaurito il tuo credito di SMS inviabili giornalmente da/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day in this server".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(1);
        }
        elsif ($LINE =~ /\<\/HTML\>/i) {
            print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
            print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
            exit(2);
        }
    }
    close ($HTTP_SOCKET);
}

# aliceadsl
# process server [aliceadsl]
sub sms_oxygen() {
    if ($MYPREFIX != 353) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." only sends to Ireland (353), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    # vars
    $HTTP_REQUEST{"POST"} = "http://www.oxygen.ie/scripts/lrp/lrp_login.php3";
    $HTTP_REQUEST{"HOST"} = "Host: www.oxygen.ie\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.oxygen.ie/scripts/lrp/lrp_login.php3\r\n";
    $HTTP_REQUEST{"DATA"} = "username=".$LOGIN."&password=".$PASSWD."&x=0&y=0";
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_POST();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close($HTTP_SOCKET);
    # vars
    $COOKIES{"logged_in"} = "true";
    $HTTP_REQUEST{"HEAD"} = "http://www.oxygen.ie/scripts/sms/free_sms.php";
    $HTTP_REQUEST{"HOST"} = "Host: www.oxygen.ie\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://www.oxygen.ie/home.php3\r\n";
    # open socket
    &open_socket("www.oxygen.ie");
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_HEAD();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://www.oxygen.ie/scripts/sms/free_sms.php";
    $HTTP_REQUEST{"DATA"} = "done=yes&smsLEFT=140+chars+left&message=".$SMS."&phone_entry=manual&phone=".$MYPREFIX.$NUMBER."&send.x=45&send.y=9";
    # open socket
    &open_socket("www.oxygen.ie");
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    my ($LINE);
    while (1) {
	if (! ($LINE = <$HTTP_SOCKET>)) {
	    print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
	    print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
	    exit(2);
	}
	if ($LINE =~ /Message\ Sent\ Successfully/i) {
	    print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
	    last;
	}
	elsif ($LINE =~ /\<\/HTML\>/i) {
	    print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
	    print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
	    exit(2);
	}
    }
    close ($HTTP_SOCKET);
}
#
# process server [lycos]
sub sms_lycos() {
    if ($MYPREFIX != 34) {
        print $c_black.$c_bold."error  : ".$c_white.$c_bold.$SERVER." only sends to Spain (34), try another server".$c_default."\n";
        die $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
    }
    # vars
    $HTTP_REQUEST{"POST"} = "http://login.lycos.es/lsu/lsu_login.php";
    $HTTP_REQUEST{"HOST"} = "Host: login.lycos.es\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://mobile.lycos.es/mobile/personal/login.jsp?target_url=/mobile/message_center/message_center.jsp\r\n";
    $HTTP_REQUEST{"DATA"} = "service=&language=es&redirect=http%3A%2F%2Fmobile.lycos.es%2Fmobile&redir_fail=http%3A%2F%2Fmobile.lycos.es%2Fmobile%2Fpersonal%2Flogin.jsp&membername=".$LOGIN."&password=".$PASSWD;
    print $c_black.$c_bold."process:".$c_default;
    # open socket
    &open_socket($URL);
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_POST();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close($HTTP_SOCKET);
    # vars
    $COOKIES{"logged_in"} = "true";
    $HTTP_REQUEST{"HEAD"} = "http://mobile.lycos.es/mobile/message_center/message_center.jsp";
    $HTTP_REQUEST{"HOST"} = "Host: mobile.lycos.es\r\n";
    $HTTP_REQUEST{"REFERER"} = "Referer: http://mobile.lycos.es/mobile/message_center/message_center.jsp\r\n";
    # open socket
    &open_socket("mobile.lycos.es");
    print $c_white.$c_bold." *".$c_default;
    # send HEAD
    &HTTP_HEAD();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    close($HTTP_SOCKET);
    $HTTP_REQUEST{"POST"} = "http://mobile.lycos.es/mobile/message_center/message_center.jsp";
    $HTTP_REQUEST{"DATA"} = "fromUrl=message_center.jsp&myaction=send&timestamp=1057863649929&smsCost=&receivers=%2B".$MYPREFIX.$NUMBER."&body=".$SMS."&nrOfMessagesVal=1";
    # open socket
    &open_socket("mobile.lycos.es");
    print $c_white.$c_bold." *".$c_default;
    # send POST
    &HTTP_POST();
    # get && parse HTTP header
    parse_http_header();
    print $c_white.$c_bold." *".$c_default;
    if ($HTTP_REQUEST{"LOCATION"} =~ /upload_credits/) {
        print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."you have wasted the limit of sms\/day \(1\) in this server".$c_default."\n";
        print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
        exit(2);
    }
    elsif ($HTTP_REQUEST{"LOCATION"} =~ /message_delivered\.jsp/) {
        print $c_black.$c_bold."\nresult : ".$c_white.$c_bold.$c_blink."sms sent ok\!".$c_default."\n";
    }
    else {
        my ($LINE);
        while (1) {
            if (! ($LINE = <$HTTP_SOCKET>)) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."can\'t read data from socket".$c_default."\n";
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
            if ($DEBUG) { print STDERR $LINE; }
            if ($LINE =~ /El mensaje que has escrito contiene uno o varios/i) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."unsupported chars (tildes) found".$c_default."\n";
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
            elsif ($LINE =~ /\<\/HTML\>/i) {
                print $c_black.$c_bold."\nerror  : ".$c_white.$c_bold."webmasters of server change method".$c_default."\n";
                print $c_black.$c_bold."result : ".$c_white.$c_bold.$c_blink."sms NOT sent ok\!".$c_default."\n";
                exit(2);
            }
        }
    }
    close ($HTTP_SOCKET);
}

#
#
# --- servers section END ---
#
#
# --- main() ---
#
#
# main starting tests (check dirs && main files)
&main_test();
# read options from main config file
&config();
print $c_white.$c_bold."linuxsms ".$c_black.$c_bold."v".$VERSION.$c_blue.$c_bold." by z0mbie ".$c_blue."<".$LINUXSMSEMAIL.">".$c_default."\n";
# check if we are run this script as root
if ($> == 0 && $SECURE_MODE == 1 ) {
    print $c_red.$c_bold.$c_blink."hello root, your privileges are not required for run this script \;\)".$c_default."\n"; 
    print $c_red.$c_bold.$c_blink."if you like to use it as root, change to SECURITY=NO in main config".$c_default."\n";
    exit(1);
}
# I am not responsible of your acts ;-)
elsif ($> == 0) { print $c_red.$c_bold.$c_blink."WARNING!!!".$c_default.$c_white.$c_bold." : runing script as root, use at your own risk.".$c_default."\n"; }
# parse commandline options
if ($CMDLINE) { &parse_commandline_new(); }
else { &parse_commandline(); }
# find name in addressbook
if ($NAME) { $NUMBER = &addressbook($NAME); }
if (! $NAME) { $NAME = "unknown"; }
# some checks 8-)
if (! $SERVER) { $SERVER = $DEFAULT_SERVER; }
if (! $SERVER) { die $c_red.$c_bold.$c_blink."error\!, server not selected".$c_default."\n"; }
# for getting credits, we do not need name || number
if (! $GET_CREDITS) {
    if (! $NUMBER) { die $c_red.$c_bold.$c_blink."error\!, name || number is incorrect or not found".$c_default."\n"; }
    # if sms text not found, read sms from standard input
    # this patch can read until EOF from STDIN, until CRTL+D
    if (! $SMS) { $SMS = join("", <STDIN>); chop($SMS); }
    # add signature
    if ($SIGNATURE && $SIG) { $SMS .= $SIGNATURE; }
}
else {
    $NAME ="none";
    $NUMBER = "000000000";
    $SMS ="a hack for getting credits, no sms will be sent";
}
# get info from server (hostname, ip, sms char-limit...)
&parse_server($SERVER);
# print status
print $c_black.$c_bold."calling: ".$c_white.$c_bold."+".$MYPREFIX." ".$NUMBER."... (".$NAME.")".$c_default."\n";
print $c_black.$c_bold."server : ".$c_white.$c_bold.$SERVER.$c_default."\n";
print $c_black.$c_bold."sms    : ".$c_white.$c_bold."\"".$SMS."\"".$c_default."\n";
if ($PROXY) { print $c_black.$c_bold."proxy  : ".$c_white.$c_bold.$PROXY.$c_default."\n"; }
# compress sms
if ($COMPRESS) { &compress(); }
# check sms char limit
if (length($SMS) > $SMSCHARLIMIT and $SERVER ne "amena3") {
    print $c_black.$c_bold."error  : ";
    print $c_red.$c_bold.$c_blink."sms is too large \(".(length($SMS)-$SMSCHARLIMIT)." chars exceed, limit is ".$SMSCHARLIMIT.")".$c_default."\n";
    exit(1);
}
# parse symbol chars to hexadecimal values
$SMS =~ s/([^\s\w()'*~!.])/&char_to_hex($1)/eg;
# convert spaces into '+'
$SMS =~ tr/[\ ]/+/;
# flush buffer after print
$|=1;
# send sms
if    ($SERVER eq "everyday") { &auth($SERVER); &sms_everyday(); }
elsif ($SERVER eq "firstwap") { &auth($SERVER); &sms_firstwap(); }
elsif ($SERVER eq "orangedk") { &auth($SERVER); &sms_orangedk(); }
elsif ($SERVER eq "textamerica") { &auth($SERVER); &sms_textamerica(); }
elsif ($SERVER eq "lycos") { &auth($SERVER); &sms_lycos(); }
elsif ($SERVER eq "smsac") { &auth($SERVER); &sms_smsac(); }
elsif ($SERVER eq "ezones") { &auth($SERVER); &sms_ezones(); }
elsif ($SERVER eq "sunrise") { &auth($SERVER); &sms_sunrise(); }
elsif ($SERVER eq "aliceadsl") { &auth($SERVER); &sms_aliceadsl(); }
elsif ($SERVER eq "everyday_fr") { &auth($SERVER); &sms_everyday_fr(); }
elsif ($SERVER eq "oxygen") { &auth($SERVER); &sms_oxygen(); }
# set line buffered (default)
$|=0;
if ($LOG) {
    &log_sms();
}
# yeah!, few hours reading hundreds of lines and finally the END! 8-)
exit(0);
