Changeset 5816

Show
Ignore:
Timestamp:
06/19/08 00:11:00 (5 years ago)
Author:
p_lindheimer
Message:

Merged revisions 5779 via svnmerge from
http://svn.freepbx.org/freepbx/trunk

........

r5779 | asternic | 2008-06-17 13:18:37 -0700 (Tue, 17 Jun 2008) | 1 line


#2782: FOP update to make flash player 9.0.124.0 and newer happy

........

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.4

    • Property svnmerge-integrated changed from /freepbx/branches/2.3:1-4129,4131,4133-4134,4136-4995,5088,5135,5140,5194 /freepbx/trunk:1-5453,5736,5739,5748,5750,5758,5760,5765,5771,5773,5782 to /freepbx/branches/2.3:1-4129,4131,4133-4134,4136-4995,5088,5135,5140,5194 /freepbx/trunk:1-5453,5736,5739,5748,5750,5758,5760,5765,5771,5773,5779,5782
  • freepbx/branches/2.4/amp_conf/htdocs_panel/op_server.cfg

    r2505 r5816  
    88 
    99[general] 
     10use_amportal_conf=1 
    1011; host or ip address of asterisk 
    1112manager_host=127.0.0.1       
  • freepbx/branches/2.4/amp_conf/htdocs_panel/op_server.pl

    r4993 r5816  
    1 #!/usr/bin/perl -w 
     1#!/usr/bin/perl 
    22 
    33#  Flash Operator Panel.    http://www.asternic.org 
     
    2222 
    2323use strict; 
     24use warnings; 
    2425use integer; 
    2526 
    26 use constant DEBUG         => 1
     27use constant DEBUG         => 0
    2728use constant BYTES_TO_READ => 256; 
    2829 
     
    3435use POSIX qw(setsid EWOULDBLOCK); 
    3536 
    36 my $FOP_VERSION    = "0.27"; 
     37my $FOP_VERSION    = "SVNVERSION"; 
    3738my %datos          = (); 
     39my %chanvar        = (); 
     40my %monitoring     = (); 
     41my %passvar        = (); 
    3842my %sesbot         = (); 
    3943my %linkbot        = (); 
     
    143147my %mailbox; 
    144148my %tovoicemail; 
     149my %tospy; 
    145150my %instancias; 
    146151my %agent_to_channel; 
     
    167172my $web_hostname; 
    168173my $listen_port; 
     174my $park_exten; 
     175my $parktimeout; 
    169176my $listen_addr; 
    170177my $security_code; 
     
    188195my $queue_hide; 
    189196my $enable_restart; 
     197my $passvars = ""; 
    190198my $change_led; 
    191199my $cdial_nosecure; 
     
    213221my %total_legends; 
    214222my %total_images; 
    215 my @btninclude   = (); 
    216 my @styleinclude = (); 
    217 my $command      = ""; 
    218 my $daemonized   = 0; 
    219 my $pidfile      = "/var/run/op_panel.pid"; 
    220 my $logdir       = ""; 
    221 my $confdir      = ""; 
    222 my $tab          = ""; 
     223my @serverinclude = (); 
     224my @btninclude    = (); 
     225my @styleinclude  = (); 
     226my $command       = ""; 
     227my $daemonized    = 0; 
     228my $pidfile       = "/var/run/op_panel.pid"; 
     229my $logdir        = ""; 
     230my $confdir       = ""; 
     231my $tab           = ""; 
    223232 
    224233my $PADDING = join( 
     
    393402} 
    394403 
    395 sub parse_amportal_config($)
    396     my $filename = $_[0]
     404sub parse_amportal_config
     405    my $filename = shift
    397406    my %ampconf; 
    398407 
    399     open(AMPCONF, $filename) || die "Cannot open $filename"; 
    400  
    401     while (<AMPCONF>) 
    402       { 
    403   if ($_ =~ /^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/) { 
    404              $ampconf{$1} = $2; 
    405            } 
    406       } 
     408    open( AMPCONF, $filename ) || die "Cannot open $filename"; 
     409 
     410    while (<AMPCONF>) { 
     411        if ( $_ =~ /^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/ ) { 
     412            $ampconf{$1} = $2; 
     413        } 
     414    } 
    407415 
    408416    close(AMPCONF); 
     
    412420sub read_server_config() { 
    413421    my $context = ""; 
     422    my @distinct_files; 
    414423    $counter_servers = -1; 
    415424 
    416425    $/ = "\n"; 
    417426 
    418     # get some variables from the amportal config 
    419     my %ampconf; 
    420     %ampconf = parse_amportal_config("/etc/amportal.conf"); 
    421  
    422     open( CONFIG, "<$directorio/op_server.cfg" ) 
    423       or die("Could not open op_server.cfg. Aborting..."); 
    424  
    425     while (<CONFIG>) { 
    426         chomp; 
    427         $_ =~ s/^\s+//g; 
    428         $_ =~ s/([^;]*)[;](.*)/$1/g; 
    429         $_ =~ s/\s+$//g; 
    430  
    431         if ( /^#/ || /^;/ || /^$/ ) { 
    432             next; 
    433         }    # Ignores comments and empty lines 
    434  
    435         if (/^\Q[\E/) { 
    436             s/\[(.*)\]/$1/g; 
    437             tr/a-z/A-Z/; 
    438             $context = $_; 
    439         } 
    440         else { 
    441             if ( $context ne "" ) { 
    442                 my ( $variable_name, $value ) = split( /=/, $_ ); 
    443                 $variable_name =~ tr/A-Z/a-z/; 
    444                 $variable_name =~ s/\s+//g; 
    445                 $value         =~ s/^\s+//g; 
    446                 $value         =~ s/\s+$//g; 
    447                 $value         =~ s/\"//g; 
    448                 $config->{$context}{$variable_name} = $value; 
    449  
    450                 if ( $variable_name eq "manager_host" ) { 
    451                     $counter_servers++; 
    452                     $manager_host[$counter_servers] = $value; 
    453                 } 
    454  
    455                 if ( $variable_name eq "manager_user" ) { 
    456                     $manager_user[$counter_servers] = $ampconf{"AMPMGRUSER"}; 
    457                 } 
    458  
    459                 if ( $variable_name eq "manager_secret" ) { 
    460                     $manager_secret[$counter_servers] = $ampconf{"AMPMGRPASS"}; 
    461                 } 
    462  
    463                 if ( $variable_name eq "manager_port" ) { 
    464                     $manager_port[$counter_servers] = $value; 
    465                 } 
    466  
    467                 if ( $variable_name eq "event_mask" ) { 
    468                     $event_mask[$counter_servers] = $value; 
    469                 } 
    470  
    471                 if ( $variable_name eq "astmanproxy_server" ) { 
    472                     push @astmanproxy_servers, $value; 
    473                 } 
    474  
    475             } 
    476         } 
    477     } 
    478     close(CONFIG); 
    479  
    480     # replace some config values by the corresponding ones from amportal 
    481     if ( exists $ampconf{"FOPWEBADDRESS"} ) { 
    482       $config->{"GENERAL"}{"web_hostname"} = $ampconf{"FOPWEBADDRESS"}; 
    483     } else { 
    484       $config->{"GENERAL"}{"web_hostname"} = $ampconf{"AMPWEBADDRESS"}; 
    485     } 
    486     $config->{"GENERAL"}{"security_code"} = $ampconf{"FOPPASSWORD"}; 
    487     $config->{"GENERAL"}{"flash_dir"} = $ampconf{"FOPWEBROOT"}; 
     427    @distinct_files = unique(@serverinclude); 
     428 
     429    foreach my $archivo (@distinct_files) { 
     430 
     431        open( CONFIG, "<$directorio/$archivo" ) 
     432          or die("Could not open op_server.cfg. Aborting..."); 
     433 
     434        while (<CONFIG>) { 
     435            chomp; 
     436            $_ =~ s/^\s+//g; 
     437            $_ =~ s/([^;]*)[;](.*)/$1/g; 
     438            $_ =~ s/\s+$//g; 
     439 
     440            if ( /^#/ || /^;/ || /^$/ ) { 
     441                next; 
     442            }    # Ignores comments and empty lines 
     443 
     444            if (/^\Q[\E/) { 
     445                s/\[(.*)\]/$1/g; 
     446                tr/a-z/A-Z/; 
     447                $context = $_; 
     448            } 
     449            else { 
     450                if ( $context ne "" ) { 
     451                    my ( $variable_name, $value ) = split( /=/, $_ ); 
     452                    $variable_name =~ tr/A-Z/a-z/; 
     453                    $variable_name =~ s/\s+//g; 
     454                    $value         =~ s/^\s+//g; 
     455                    $value         =~ s/\s+$//g; 
     456                    $value         =~ s/\"//g; 
     457                    $config->{$context}{$variable_name} = $value; 
     458 
     459                    if ( $variable_name eq "manager_host" ) { 
     460                        $counter_servers++; 
     461                        $manager_host[$counter_servers] = $value; 
     462                    } 
     463 
     464                    if ( $variable_name eq "manager_user" ) { 
     465                        $manager_user[$counter_servers] = $value; 
     466                    } 
     467 
     468                    if ( $variable_name eq "manager_secret" ) { 
     469                        $manager_secret[$counter_servers] = $value; 
     470                    } 
     471 
     472                    if ( $variable_name eq "manager_port" ) { 
     473                        $manager_port[$counter_servers] = $value; 
     474                    } 
     475 
     476                    if ( $variable_name eq "event_mask" ) { 
     477                        $event_mask[$counter_servers] = $value; 
     478                    } 
     479 
     480                    if ( $variable_name eq "astmanproxy_server" ) { 
     481                        push @astmanproxy_servers, $value; 
     482                    } 
     483 
     484                } 
     485            } 
     486        } 
     487        close(CONFIG); 
     488    } 
     489 
     490    if ( defined( $config->{GENERAL}{use_amportal_conf} ) ) { 
     491        if ( $config->{GENERAL}{use_amportal_conf} == 1 ) { 
     492            my $freepbx_config = "/etc/amportal.conf"; 
     493            my %ampconf; 
     494 
     495            if ( -e $freepbx_config ) { 
     496                %ampconf                              = parse_amportal_config($freepbx_config); 
     497                $config->{"GENERAL"}{"web_hostname"}  = $ampconf{"AMPWEBADDRESS"}; 
     498                $config->{"GENERAL"}{"security_code"} = $ampconf{"FOPPASSWORD"}; 
     499                $config->{"GENERAL"}{"flash_dir"}     = $ampconf{"FOPWEBROOT"}; 
     500                $manager_user[0]                      = $ampconf{"AMPMGRUSER"}; 
     501                $manager_secret[0]                    = $ampconf{"AMPMGRPASS"}; 
     502            } 
     503        } 
     504    } 
    488505 
    489506    $web_hostname     = $config->{GENERAL}{web_hostname}; 
     
    513530    $enable_restart   = $config->{GENERAL}{enable_restart}; 
    514531    $defaultlanguage  = $config->{GENERAL}{language}; 
     532    $passvars         = $config->{GENERAL}{passvars}; 
     533    $park_exten       = $config->{GENERAL}{parkexten}; 
     534    $parktimeout      = $config->{GENERAL}{parktimeout}; 
    515535 
    516536    if ( $debuglevel == -1 ) { 
     
    539559 
    540560    $clid_format = $config->{GENERAL}{clid_format}; 
    541  
     561    if ( !defined($flash_dir) ) { $flash_dir = '/var/www/html' } 
    542562    $flash_file = $flash_dir . "/variables.txt"; 
    543563    push @all_flash_files, $flash_file; 
     
    588608    } 
    589609 
     610    if ( !defined $config->{GENERAL}{monitor_filename} ) { 
     611        $config->{GENERAL}{monitor_filename} = "\${UNIQUEID}"; 
     612    } 
     613 
     614    if ( !defined $config->{GENERAL}{monitor_format} ) { 
     615        $config->{GENERAL}{monitor_format} = "wav"; 
     616    } 
     617 
    590618    if ( !defined $clid_privacy ) { 
    591619        $clid_privacy = 0; 
     
    650678    if ( !defined $clid_format ) { 
    651679        $clid_format = "(xxx) xxx-xxxx"; 
     680    } 
     681 
     682    if ( !defined $passvars ) { 
     683        $passvars = ""; 
     684    } 
     685 
     686    if ( !defined $park_exten ) { 
     687        $park_exten = "700"; 
     688    } 
     689 
     690    if ( !defined $parktimeout ) { 
     691        $parktimeout = 45000; 
     692    } 
     693    else { 
     694        $parktimeout = $parktimeout * 1000; 
    652695    } 
    653696 
     
    674717 
    675718    if ( $tipo eq "buttons" ) { 
    676         if ( !inArray( $filename, @btninclude ) ) { 
     719        if ( !grep { $filename eq $_ } @btninclude ) { 
    677720            push( @btninclude, $filename ); 
    678721        } 
     
    683726    } 
    684727    if ( $tipo eq "style" ) { 
    685         if ( !inArray( $filename, @styleinclude ) ) { 
     728        if ( !grep { $filename eq $_ } @styleinclude ) { 
    686729            push( @styleinclude, $filename ); 
     730        } 
     731        else { 
     732            log_debug( "** $filename already included", 16 ) if DEBUG; 
     733            return; 
     734        } 
     735    } 
     736    if ( $tipo eq "server" ) { 
     737        if ( !grep { $filename eq $_ } @serverinclude ) { 
     738            push( @serverinclude, $filename ); 
    687739        } 
    688740        else { 
     
    11531205            my $pos = $tmphash{position}; 
    11541206            $pos =~ s/(\d+),(\d+)/$1/g; 
    1155             $tmphash{position} = "$pos,$pos"; 
     1207            my $countpos = 2; 
     1208            $tmphash{position} = ""; 
     1209            if ( defined( $tmphash{count} ) ) { 
     1210                $countpos = $tmphash{count}; 
     1211            } 
     1212            my $a = 0; 
     1213            for ( $a = 0 ; $a < $countpos ; $a++ ) { 
     1214                $tmphash{position} .= "$pos,"; 
     1215            } 
     1216            $tmphash{position} = substr( $tmphash{position}, 0, -1 ); 
    11561217            $no_counter = 1; 
    11571218        } 
     
    12181279                $buttons{ uc("$tmphash{server}^$chan_trunk") } = $pos; 
    12191280                $textos{$indice_contexto} = $tmphash{label}; 
    1220                 if ( $no_counter == 0 ) { 
     1281                if ( !defined( $tmphash{no_label_counter} ) ) { $tmphash{no_label_counter} = 0; } 
     1282                if ( $no_counter == 0 && $tmphash{no_label_counter} == 0 ) { 
    12211283                    $textos{$indice_contexto} .= " " . $count; 
    12221284                } 
     
    13761438            $tovoicemail{$indicevm} = $tmphash{voicemailext}; 
    13771439        } 
     1440        if ( defined( $tmphash{spyext} ) ) { 
     1441            my $indicespy = $lastposition{ $tmphash{panel_context} }; 
     1442            if ( $tmphash{panel_context} ne "" ) { 
     1443                $indicespy .= "\@$tmphash{panel_context}"; 
     1444            } 
     1445            $tospy{$indicespy} = $tmphash{spyext}; 
     1446        } 
     1447 
    13781448        $/ = "\0"; 
    13791449    } 
     
    15361606            my $contextoboton = $key; 
    15371607            if ( $contextoboton =~ m/\@/ ) { 
    1538                 my @parte = split( /\@/, $contextoboton, 2 ); 
    1539                 $contextoboton = $parte[1]; 
     1608                ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    15401609                $contextoboton =~ tr/a-z/A-Z/; 
    15411610            } 
     
    15551624            my $contextoboton = $key; 
    15561625            if ( $contextoboton =~ m/\@/ ) { 
    1557                 my @parte = split( /\@/, $contextoboton, 2 ); 
    1558                 $contextoboton = $parte[1]; 
     1626                ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    15591627                $contextoboton =~ tr/a-z/A-Z/; 
    15601628            } 
     
    15741642                my $contextoboton = $key; 
    15751643                if ( $contextoboton =~ m/\@/ ) { 
    1576                     my @parte = split( /\@/, $contextoboton, 2 ); 
    1577                     $contextoboton = $parte[1]; 
     1644                    ($contextoboton) = split( /\@/, $contextoboton, 2 ); 
    15781645                    $contextoboton =~ tr/a-z/A-Z/; 
    15791646                } 
     
    15941661                my $contextoboton = $key; 
    15951662                if ( $contextoboton =~ m/\@/ ) { 
    1596                     my @parte = split( /\@/, $contextoboton, 2 ); 
    1597                     $contextoboton = $parte[1]; 
     1663                    ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    15981664                    $contextoboton =~ tr/a-z/A-Z/; 
    15991665                } 
     
    16141680                my $contextoboton = $key; 
    16151681                if ( $contextoboton =~ m/\@/ ) { 
    1616                     my @parte = split( /\@/, $contextoboton, 2 ); 
    1617                     $contextoboton = $parte[1]; 
     1682                    ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    16181683                    $contextoboton =~ tr/a-z/A-Z/; 
    16191684                } 
     
    17821847    # a trunk button. 
    17831848 
    1784     log_debug( "$heading START SUB canalid $canalid contexto $contexto server $server canalsesion $canalsesion", 16 ) if DEBUG; 
     1849    log_debug( "$heading START SUB canalid $canalid contexto $contexto server $server canalsesion $canalsesion", 16 ) 
     1850      if DEBUG; 
    17851851 
    17861852    if ( $canalid eq "" ) { 
     
    18311897        } 
    18321898        log_debug( "$heading contexto $contexto", 32 ) if DEBUG; 
    1833         my ( $nada, $ses ) = separate_session_from_channel($canalsesion); 
     1899        my ( undef, $ses ) = separate_session_from_channel($canalsesion); 
    18341900        $sesion = $ses; 
    18351901    } 
     
    18531919    } 
    18541920 
    1855     my $canalconcontextosinserver = $canalconcontexto; 
    1856     $canalconcontextosinserver =~ s/(\d+)\^(.*)/$2/g; 
    18571921    if ( $canalconcontexto !~ /\^/ ) { 
    18581922        $canalconcontexto = $server . "^" . $canalconcontexto; 
     
    19041968        } 
    19051969    } 
    1906     if ( $elemento =~ /^mISDN/i ) { 
    1907         if ( $elemento !~ /XXXY/ ) { 
    1908             $elemento .= "-XXXY"; 
    1909         } 
    1910  
    1911         #    $elemento =~ s/(.*)\/(.*)/\U$1\E\/${2}-${2}/g; 
     1970    if ( $elemento =~ /^(?i:mISDN)(?!.*XXXY)/ ) { 
     1971        $elemento .= "-XXXY"; 
    19121972    } 
    19131973    elsif ( $elemento =~ /^SRX/i ) { 
     
    19151975    } 
    19161976    elsif ( $elemento =~ /^CAPI\//i ) { 
    1917         $elemento =~ s/(CAPI\/)(.*)\/(.*)-(.*)/$1$2-$4/g; 
    1918     } 
    1919  
     1977        $elemento =~ s/(CAPI\/)(.*)\/.*-(.*)/$1$2-$3/g; 
     1978    } 
     1979 
     1980    $elemento =~ s/^asyncgoto\///gi; 
    19201981    $elemento =~ s/(.*)[-\/](.*)/$1\t$2/g; 
    19211982    log_debug( "$heading elemento2 $elemento", 32 ) if DEBUG; 
    19221983    my $canal  = $1; 
    19231984    my $sesion = $2; 
    1924     log_debug( "$heading canal $canal sesion $sesion", 32 ) if DEBUG; 
    19251985 
    19261986    if ( defined($canal) && defined($sesion) ) { 
    19271987        $canal =~ tr/a-z/A-Z/; 
    19281988        $elemento = $canal . "\t" . $sesion; 
     1989        log_debug( "$heading canal $canal sesion $sesion", 32 ) if DEBUG; 
    19291990    } 
    19301991    $elemento =~ s/IAX2\[(.*)@(.*)\]\t(.*)/IAX2\[$1\]\t$3/; 
    19311992    $elemento =~ s/IAX2\/(.*)@(.*)\t(.*)/IAX2\/$1\t$3/; 
    19321993 
    1933     my @partes = split( /\t/, $elemento ); 
    1934     return @partes; 
     1994    return split( /\t/, $elemento ); 
    19351995} 
    19361996 
     
    19572017sub erase_instances_for_trunk_buttons { 
    19582018 
    1959     my $canalid          = shift; 
    1960     my $canal            = shift; 
    1961     my $server           = shift; 
    1962     my $canalidsinserver = ""; 
     2019    my $canalid = shift; 
     2020    my $canal   = shift; 
     2021    my $server  = shift; 
    19632022    my $canalglobal; 
    1964     my $valor; 
    1965     my @new     = (); 
    19662023    my $heading = "** ERASE_INSTANCE_TRUNK"; 
    19672024 
    1968     $canalidsinserver = $canalid; 
    1969     $canalid          = "$server^$canalid"; 
     2025    my $solocanal = $canalid; 
     2026    $solocanal =~ s/[^\w]//g; 
     2027 
     2028    $canalid = "$server^$canalid"; 
    19702029    $canalid =~ s/(.*)<(.*)>/$1/g;    #discards ZOMBIE or MASQ 
    19712030 
     
    19772036    $canalglobal =~ s/IAX2\[(.*)@(.*)\]/IAX2\[$1\]/g; 
    19782037 
    1979     my ( $nada, $contexto ) = split( /\&/, $canal ); 
    1980     if ( !defined($contexto) ) { $contexto = ""; } 
    1981  
    1982     my $canalconcontexto = ""; 
    1983     if ( $contexto ne "" ) { 
    1984         $canalconcontexto = "$canalglobal&$contexto"; 
    1985         $contexto         = "&$contexto"; 
    1986     } 
    1987     else { 
    1988         $canalconcontexto = $canalglobal; 
    1989         $contexto         = ""; 
    1990     } 
     2038    my ( undef, $contexto ) = split( /\&/, $canal ); 
     2039    $contexto = $contexto ? "&$contexto" : ""; 
    19912040 
    19922041    my $sesiontemp = $canalid; 
     
    19942043    log_debug( "$heading looking for $canalid on instancias to erase it", 128 ) if DEBUG; 
    19952044 
    1996     foreach my $key1 ( sort ( keys(%instancias) ) ) { 
    1997         foreach my $key2 ( sort ( keys( %{ $instancias{$key1} } ) ) ) { 
    1998             if ( $key2 eq $canalid ) { 
    1999                 delete $instancias{$key1}{$key2}; 
    2000                 log_debug( "$heading Erasing $canalid from instanacias!", 128 ) if DEBUG; 
    2001             } 
    2002         } 
     2045    if ( $canal =~ m/^DID|^CLID/ ) { 
     2046        $canal =~ s/(.*)=.*/$1/g; 
     2047        $canalid = $server . "^" . $canal . "-" . $solocanal; 
     2048    } 
     2049    foreach my $key1 ( keys(%instancias) ) { 
     2050        delete $instancias{$key1}{$canalid}; 
     2051        log_debug( "$heading Erasing $canalid from instanacias!", 128 ) if DEBUG; 
    20032052    } 
    20042053} 
     
    20172066    } 
    20182067 
    2019     my ( $nada1, $contexto1 ) = split( /\&/, $nroboton ); 
     2068    my ( undef, $contexto1 ) = split( /\&/, $nroboton ); 
    20202069    if ( !defined($contexto1) ) { $contexto1 = ""; } 
    20212070 
     
    20332082            my @linkbotones = find_panel_buttons( $canal1, $canalsesion, $server ); 
    20342083            foreach my $cual (@linkbotones) { 
    2035                 my ( $nada2, $contexto2 ) = split( /\&/, $cual ); 
     2084                my ( undef, $contexto2 ) = split( /\&/, $cual ); 
    20362085                if ( !defined($contexto2) ) { $contexto2 = ""; } 
    20372086                if ( $contexto1 eq $contexto2 ) { 
     
    21012150    log_debug( "$heading borro cache_hit($indice_cache)", 128 ) if DEBUG; 
    21022151    delete $cache_hit{$indice_cache}; 
     2152    delete $monitoring{$canalsesion}; 
    21032153    if ( keys(%cache_hit) ) { 
    21042154        for ( keys %cache_hit ) { 
     
    21762226                        log_debug( "** Found a match $canalid=$val ($quehay) - Cleared!", 16 ) if DEBUG; 
    21772227                        delete $datos{$quehay}; 
     2228                        delete $chanvar{$quehay}; 
     2229                        delete $passvar{$quehay}; 
    21782230                    } 
    21792231                } 
     
    22012253    # Removes the context if its set 
    22022254 
    2203     my @pedazos = split( /&/, $canal ); 
    2204     $canal = $pedazos[0]; 
     2255    ($canal) = split( /&/, $canal ); 
    22052256 
    22062257    # Checks if the channel name has an equal sign 
     
    22532304    my $server  = ""; 
    22542305 
    2255     my @pedazos = split( /&/, $canal ); 
    2256     $canal = $pedazos[0]; 
     2306    ($canal) = split( /&/, $canal ); 
    22572307 
    22582308    if ( $canal =~ /\^/ ) { 
    2259         @pedazos = split( /\^/, $canal ); 
    2260         $server  = $pedazos[0]; 
    2261         $canal   = $pedazos[1]; 
     2309        ( $server, $canal ) = split( /\^/, $canal ); 
    22622310    } 
    22632311 
     
    22962344    print_datos(1); 
    22972345 
    2298     my @pedazos = split( /&/, $canal ); 
    2299     $canal = $pedazos[0]; 
     2346    ($canal) = split( /&/, $canal ); 
    23002347 
    23012348    if ( $canal =~ /\^/ ) { 
    2302         @pedazos = split( /\^/, $canal ); 
    2303         $server  = $pedazos[0]; 
    2304         $canal   = $pedazos[1]; 
     2349        ( $server, $canal ) = split( /\^/, $canal ); 
    23052350    } 
    23062351 
     
    23232368                $canalaqui = 1; 
    23242369            } 
    2325             if ( $key =~ /^Server/i && $val eq $server ) { 
     2370            if ( $key =~ /^Server/i && ( $val eq $server || $server eq "-1" ) ) { 
    23262371                $serveraqui = 1; 
    23272372                log_debug( "$heading server coincide $server = $val\n", 16 ) if DEBUG; 
     
    23642409    my $heading       = "** FIND_PANEL_BUT"; 
    23652410    my $calleridnum   = "noexiste"; 
     2411    my $didnum        = "noexiste"; 
    23662412    my %trunk_matched = (); 
    23672413 
     
    23752421 
    23762422    my $uniqueid = find_uniqueid( $canalsesion, $server ); 
    2377     if ( $uniqueid ne "" ) { 
    2378         if ( defined( $datos{$uniqueid}{"CallerID"} ) ) { 
    2379             $calleridnum = $datos{$uniqueid}{"CallerID"}; 
     2423    if ($uniqueid) { 
     2424        if ( defined( $datos{$uniqueid}{CallerID} ) ) { 
     2425            $calleridnum = $datos{$uniqueid}{CallerID}; 
     2426        } 
     2427        if (   defined( $datos{$uniqueid}{Extension} ) 
     2428            && defined( $datos{$uniqueid}{AppData} ) 
     2429            && $datos{$uniqueid}{AppData} =~ m/^FROM_DID/ ) 
     2430        { 
     2431            $didnum = $datos{$uniqueid}{"Extension"}; 
    23802432        } 
    23812433    } 
     
    24952547        # Attemp to match a button from cache 
    24962548        $indice_cache = $canalsesion . "-" . $canal . "-" . $server; 
    2497         if ( !defined( $cache_hit{$indice_cache} ) ) { 
     2549        if ( !defined( $cache_hit{$indice_cache} ) || $didnum ne "noexiste" ) { 
    24982550            log_debug( "$heading CACHE MISS $indice_cache", 32 ) if DEBUG; 
    24992551            for ( keys %buttons ) { 
    25002552                $server     = $server_original; 
    25012553                $canalfinal = ""; 
    2502                 my ( $nada, $contexto ) = split( "\&", $_ ); 
     2554                my ( undef, $contexto ) = split( "\&", $_ ); 
    25032555                if ( !defined($contexto) ) { $contexto = ""; } 
    25042556                if ( $contexto ne "" ) { $contexto = "&" . $contexto; } 
     
    25282580                    } 
    25292581                } 
     2582                elsif ( $_ =~ /^$server\^CLID\/\Q$calleridnum\E=/ ) { 
     2583                    my $solocanal = $canalsesion; 
     2584                    $solocanal =~ s/[^\w]//g; 
     2585                    my $tcanal = "CLID/" . $calleridnum . "-" . $solocanal; 
     2586                    if ( !exists( $trunk_matched{"$server^CLID/$calleridnum"} ) ) { 
     2587                        $canalfinal = get_next_trunk_button( $tcanal, $contexto, $server, $tcanal ); 
     2588                        if ( $canalfinal ne "" ) { 
     2589                            log_debug( "$heading clid match trunk ( $_ )  $canal $contexto", 32 ) if DEBUG; 
     2590                            $trunk_matched{"$server^CLID/$calleridnum"} = 1; 
     2591                            $canalfinal =~ s/(.*)\^(.*)/$2/g; 
     2592                        } 
     2593                    } 
     2594                } 
    25302595                elsif ( $_ =~ /^$server\^CLID\/\Q$calleridnum\E\&?/ ) { 
    2531  
    25322596                    log_debug( "$heading clid match ( $_ )  $canal $contexto", 32 ) if DEBUG; 
    25332597                    $canalfinal = "CLID/$calleridnum"; 
     2598                } 
     2599                elsif ( $_ =~ /^$server\^DID\/\Q$didnum\E=/ ) { 
     2600                    my $solocanal = $canalsesion; 
     2601                    $solocanal =~ s/[^\w]//g; 
     2602                    my $tcanal = "DID/" . $didnum . "-" . $solocanal; 
     2603                    if ( !exists( $trunk_matched{"$server^DID/$didnum"} ) ) { 
     2604                        $canalfinal = get_next_trunk_button( $tcanal, $contexto, $server, $tcanal ); 
     2605                        if ( $canalfinal ne "" ) { 
     2606                            log_debug( "$heading did match trunk ( $_ )  $canal $contexto", 32 ) if DEBUG; 
     2607                            $trunk_matched{"$server^DID/$didnum"} = 1; 
     2608                            $canalfinal =~ s/(.*)\^(.*)/$2/g; 
     2609                        } 
     2610                    } 
     2611                } 
     2612                elsif ( $_ =~ /^$server\^DID\/\Q$didnum\E\&?/ ) { 
     2613                    log_debug( "$heading did match ( $_ )  $canal $contexto", 32 ) if DEBUG; 
     2614                    $canalfinal = "DID/$didnum"; 
    25342615                } 
    25352616 
     
    25592640            $canalfinal = ""; 
    25602641 
    2561             my $nada1      = ""; 
    25622642            my $contextemp = ""; 
    25632643            my %contextosencontrados; 
    25642644            for my $val (@canales) { 
    2565                 ( $nada1, $contextemp ) = split( "&", $val ); 
     2645                ( undef, $contextemp ) = split( "&", $val ); 
    25662646                if ( !defined($contextemp) ) { $contextemp = ""; } 
    25672647                $contextosencontrados{"&$contextemp"} = 1; 
     
    26772757    while ( my ( $key, $val ) = each(%bloque) ) { 
    26782758        if ( defined($val) ) { 
    2679             $val =~ s/(.*)\s+$/$1/g
     2759            $val =~ s/\s+$//
    26802760        } 
    26812761        else { 
     
    26852765    } 
    26862766 
     2767    if ( defined( $hash_temporal{Application} ) ) { 
     2768 
     2769        # Chanvar hash stores the complete list of channel variables 
     2770        # that are "SET" in the dialplan for a given Uniqueid 
     2771        if ( $hash_temporal{Application} eq "Set" ) { 
     2772            my @vardata = split( /\|/, $hash_temporal{AppData} ); 
     2773            foreach my $vara (@vardata) { 
     2774                my ( $vari, $valu ) = split( /=/, $vara ); 
     2775                $vari =~ s/^_.?//g; 
     2776                $chanvar{ $hash_temporal{Uniqueid} }{$vari} = $valu; 
     2777            } 
     2778        } 
     2779    } 
    26872780    if ( defined( $hash_temporal{Channel} ) ) { 
    26882781        if ( $hash_temporal{Channel} =~ /^Agent/ ) { 
     
    27242817        while ( my ( $key, $val ) = each(%hash_temporal) ) { 
    27252818            if ( defined($val) && $val =~ /\^/ ) { 
    2726                 my @partes = split( /\^/, $val, 2 ); 
    2727                 $hash_temporal{$key} = $partes[0]; 
    2728                 my $resto_de_parametros = $partes[1]; 
    2729                 @partes = split( /\^/, $resto_de_parametros ); 
     2819 
     2820                #my @partes = split( /\^/, $val, 2 ); 
     2821                #$hash_temporal{$key} = $partes[0]; 
     2822                #my $resto_de_parametros = $partes[1]; 
     2823                ( $hash_temporal{$key}, my $resto ) = split( /\^/, $val, 2 ); 
     2824                my @partes = split( /\^/, $resto ); 
    27302825                foreach my $value (@partes) { 
    27312826                    my @partes2 = split( /: /, $value ); 
     
    27872882    if ( defined( $hash_temporal{"ActionID"} ) ) { 
    27882883        if ( $hash_temporal{"ActionID"} =~ /^timeout/i ) { 
    2789             my @partes = split( /\|/, $hash_temporal{"ActionID"} ); 
    2790             $canalid  = $partes[1]; 
    2791             $timeout  = $partes[2]; 
     2884            ( $canalid, $timeout ) = split( /\|/, $hash_temporal{"ActionID"} ); 
    27922885            $evento   = "Timeout"; 
    27932886            $unico_id = "YYYY-$server"; 
     
    28252918    } 
    28262919 
     2920    # Convert Asterisk 1.4 Originate responses to 1.2 format so attendant transfers work 
     2921    if ( $evento eq "OriginateResponse" ) { 
     2922        if ( $hash_temporal{Response} eq "Success" ) { 
     2923            $evento = "OriginateSuccess"; 
     2924        } 
     2925        else { 
     2926            $evento = "OriginateFailure"; 
     2927        } 
     2928    } 
     2929 
     2930    # Convert Asterisk 1.4 ParkedCalltimeout to UnParkedCall 
     2931    if ( $evento eq "ParkedCallTimeOut" ) { 
     2932        $evento = "UnParkedCall"; 
     2933    } 
     2934 
    28272935    $evento =~ s/UserEvent//g; 
    2828     if    ( $evento =~ /Newchannel/ )           { $evento = "newchannel"; } 
    2829     elsif ( $evento =~ /Newcallerid/ )          { $evento = "newcallerid"; } 
    2830     elsif ( $evento =~ /^Status$/ )             { $evento = "status"; } 
    2831     elsif ( $evento =~ /^StatusComplete/ )      { $evento = "statuscomplete"; } 
    2832     elsif ( $evento =~ /Newexten/ )             { $evento = "newexten"; } 
    2833     elsif ( $evento =~ /^ParkedCall$/ )         { $evento = "parkedcall"; } 
    2834     elsif ( $evento =~ /^UnParkedCall$/ )       { $evento = "unparkedcall"; } 
    2835     elsif ( $evento =~ /Newstate/ )             { $evento = "newstate"; } 
    2836     elsif ( $evento =~ /Hangup/ )               { $evento = "hangup"; } 
    2837     elsif ( $evento =~ /Rename/ )               { $evento = "rename"; } 
    2838     elsif ( $evento =~ /MessageWaiting/ )       { $evento = "voicemail"; } 
    2839     elsif ( $evento =~ /Regstatus/ )            { $evento = "regstatus"; } 
    2840     elsif ( $evento =~ /^Unlink/ )              { $evento = "unlink"; } 
    2841     elsif ( $evento =~ /QueueParams/ )          { $evento = "queueparams"; } 
    2842     elsif ( $evento =~ /PeerEntry/ )            { $evento = "peerentry"; } 
    2843     elsif ( $evento =~ /QueueEntry/ )           { $evento = "queueentry"; } 
    2844     elsif ( $evento =~ /^QueueMember$/ )        { $evento = "queuemember"; } 
    2845     elsif ( $evento =~ /^QueueMemberStatus$/ )  { $evento = "queuememberstatus"; } 
    2846     elsif ( $evento =~ /QueueMemberAdded/ )     { $evento = "queuememberadded"; } 
    2847     elsif ( $evento =~ /QueueMemberRemoved/ )   { $evento = "queuememberremoved"; } 
    2848     elsif ( $evento =~ /QueueMemberPaused/ )    { $evento = "queuememberpaused"; } 
    2849     elsif ( $evento =~ /QueueStatus$/ )         { $evento = "queuestatus"; } 
    2850     elsif ( $evento =~ /QueueStatusComplete/ )  { $evento = "queuestatuscomplete"; } 
    2851     elsif ( $evento =~ /^Link/ )                { $evento = "link"; } 
    2852     elsif ( $evento =~ /^Join/ )                { $evento = "join"; } 
    2853     elsif ( $evento =~ /^MeetmeJoin/ )          { $evento = "meetmejoin"; } 
    2854     elsif ( $evento =~ /^MeetmeLeave/ )         { $evento = "meetmeleave"; } 
    2855     elsif ( $evento =~ /^meetmemute/ )          { $evento = "meetmemute"; } 
    2856     elsif ( $evento =~ /^meetmeunmute/ )        { $evento = "meetmeunmute"; } 
    2857     elsif ( $evento =~ /^Agentlogin/ )          { $evento = "agentlogin"; } 
    2858     elsif ( $evento =~ /^RefreshQueue/ )        { $evento = "refreshqueue"; } 
    2859     elsif ( $evento =~ /^Timeout/ )             { $evento = "timeout"; } 
    2860     elsif ( $evento =~ /^AgentCalled/ )         { $evento = "agentcalled"; } 
    2861     elsif ( $evento =~ /^AgentConnect/ )        { $evento = "agentconnect"; } 
    2862     elsif ( $evento =~ /^AgentComplete/ )       { $evento = "agentcomplete"; } 
    2863     elsif ( $evento =~ /^Agentcallbacklogin/ )  { $evento = "agentcblogin"; } 
    2864     elsif ( $evento =~ /^Agentcallbacklogoff/ ) { $evento = "agentlogoff"; } 
    2865     elsif ( $evento =~ /^Agentlogoff/ )         { $evento = "agentlogoff"; } 
    2866     elsif ( $evento =~ /^IsMeetmeMember/ )      { $evento = "fakeismeetmemember"; } 
    2867     elsif ( $evento =~ /^PeerStatus/ )          { $evento = "peerstatus"; } 
    2868     elsif ( $evento =~ /^Leave/ )               { $evento = "leave"; } 
    2869     elsif ( $evento =~ /^FOP_Popup/i )          { $evento = "foppopup"; } 
    2870     elsif ( $evento =~ /^FOP_LedColor/i )       { $evento = "fopledcolor"; } 
    2871     elsif ( $evento =~ /^Dial/ )                { $evento = "dial"; } 
    2872     elsif ( $evento =~ /^ASTDB/ )               { $evento = "astdb"; } 
    2873     elsif ( $evento =~ /^DNDState/ )            { $evento = "zapdndstate"; } 
    2874     elsif ( $evento =~ /^ZapShowChannels$/ )    { $evento = "zapdndstate"; } 
    2875     elsif ( $evento =~ /^ExtensionStatus$/ )    { $evento = "extensionstatus"; } 
    2876     elsif ( $evento =~ /^OriginateSuccess$/ )   { $evento = "originatesuccess"; } 
    2877     elsif ( $evento =~ /^OriginateFailure$/ )   { $evento = "originatefailure"; } 
    2878     elsif ( $evento =~ /^ChannelReload$/ )      { $evento = "channelreload"; } 
     2936    if    ( $evento =~ /Newchannel/ )                  { $evento = "newchannel"; } 
     2937    elsif ( $evento =~ /Newcallerid/ )                 { $evento = "newcallerid"; } 
     2938    elsif ( $evento =~ /^Status$/ )                    { $evento = "status"; } 
     2939    elsif ( $evento =~ /^StatusComplete/ )             { $evento = "statuscomplete"; } 
     2940    elsif ( $evento =~ /Newexten/ )                    { $evento = "newexten"; } 
     2941    elsif ( $evento =~ /^ParkedCall$/ )                { $evento = "parkedcall"; } 
     2942    elsif ( $evento =~ /^UnParkedCall$/ )              { $evento = "unparkedcall"; } 
     2943    elsif ( $evento =~ /^virtualvaletparkedcall/i )    { $evento = "parkedcall"; } 
     2944    elsif ( $evento =~ /^virtualvaletunparkedcall$/i ) { $evento = "unparkedcall"; } 
     2945    elsif ( $evento =~ /Newstate/ )                    { $evento = "newstate"; } 
     2946    elsif ( $evento =~ /Hangup/ )                      { $evento = "hangup"; } 
     2947    elsif ( $evento =~ /Rename/ )                      { $evento = "rename"; } 
     2948    elsif ( $evento =~ /MessageWaiting/ )              { $evento = "voicemail"; } 
     2949    elsif ( $evento =~ /Regstatus/ )                   { $evento = "regstatus"; } 
     2950    elsif ( $evento =~ /^Unlink/ )                     { $evento = "unlink"; } 
     2951    elsif ( $evento =~ /QueueParams/ )                 { $evento = "queueparams"; } 
     2952    elsif ( $evento =~ /PeerEntry/ )                   { $evento = "peerentry"; } 
     2953    elsif ( $evento =~ /QueueEntry/ )                  { $evento = "queueentry"; } 
     2954    elsif ( $evento =~ /^QueueMember$/ )               { $evento = "queuemember"; } 
     2955    elsif ( $evento =~ /^QueueMemberStatus$/ )         { $evento = "queuememberstatus"; } 
     2956    elsif ( $evento =~ /QueueMemberAdded/ )            { $evento = "queuememberadded"; } 
     2957    elsif ( $evento =~ /QueueMemberRemoved/ )          { $evento = "queuememberremoved"; } 
     2958    elsif ( $evento =~ /QueueMemberPaused/ )           { $evento = "queuememberpaused"; } 
     2959    elsif ( $evento =~ /QueueStatus$/ )                { $evento = "queuestatus"; } 
     2960    elsif ( $evento =~ /QueueStatusComplete/ )         { $evento = "queuestatuscomplete"; } 
     2961    elsif ( $evento =~ /^Link/ )                       { $evento = "link"; } 
     2962    elsif ( $evento =~ /^Join/ )                       { $evento = "join"; } 
     2963    elsif ( $evento =~ /^MeetmeJoin/ )                 { $evento = "meetmejoin"; } 
     2964    elsif ( $evento =~ /^MeetmeLeave/ )                { $evento = "meetmeleave"; } 
     2965    elsif ( $evento =~ /^meetmemute/ )                 { $evento = "meetmemute"; } 
     2966    elsif ( $evento =~ /^meetmeunmute/ )               { $evento = "meetmeunmute"; } 
     2967    elsif ( $evento =~ /^Agentlogin/ )                 { $evento = "agentlogin"; } 
     2968    elsif ( $evento =~ /^Agents$/ )                    { $evento = "agents"; } 
     2969    elsif ( $evento =~ /^RefreshQueue/ )               { $evento = "refreshqueue"; } 
     2970    elsif ( $evento =~ /^Timeout/ )                    { $evento = "timeout"; } 
     2971    elsif ( $evento =~ /^AgentCalled/ )                { $evento = "agentcalled"; } 
     2972    elsif ( $evento =~ /^AgentConnect/ )               { $evento = "agentconnect"; } 
     2973    elsif ( $evento =~ /^AgentComplete/ )              { $evento = "agentcomplete"; } 
     2974    elsif ( $evento =~ /^Agentcallbacklogin/ )         { $evento = "agentcblogin"; } 
     2975    elsif ( $evento =~ /^Agentcallbacklogoff/ )        { $evento = "agentlogoff"; } 
     2976    elsif ( $evento =~ /^Agentlogoff/ )                { $evento = "agentlogoff"; } 
     2977    elsif ( $evento =~ /^IsMeetmeMember/ )             { $evento = "fakeismeetmemember"; } 
     2978    elsif ( $evento =~ /^PeerStatus/ )                 { $evento = "peerstatus"; } 
     2979    elsif ( $evento =~ /^Leave/ )                      { $evento = "leave"; } 
     2980    elsif ( $evento =~ /^FOP_Popup/i )                 { $evento = "foppopup"; } 
     2981    elsif ( $evento =~ /^FOP_LedColor/i )              { $evento = "fopledcolor"; } 
     2982    elsif ( $evento =~ /^Dial/ )                       { $evento = "dial"; } 
     2983    elsif ( $evento =~ /^ASTDB/ )                      { $evento = "astdb"; } 
     2984    elsif ( $evento =~ /^DNDState/ )                   { $evento = "zapdndstate"; } 
     2985    elsif ( $evento =~ /^ZapShowChannels$/ )           { $evento = "zapdndstate"; } 
     2986    elsif ( $evento =~ /^ExtensionStatus$/ )           { $evento = "extensionstatus"; } 
     2987    elsif ( $evento =~ /^OriginateSuccess$/ )          { $evento = "originatesuccess"; } 
     2988    elsif ( $evento =~ /^OriginateFailure$/ )          { $evento = "originatefailure"; } 
     2989    elsif ( $evento =~ /^ChannelReload$/ )             { $evento = "channelreload"; } 
     2990    elsif ( $evento =~ /^response-/ )                  { $evento = "monitor"; } 
    28792991    else { log_debug( "$heading No event match ($evento)", 32 ); } 
    28802992 
     
    28953007    } 
    28963008 
    2897     if ( $evento eq "channelreload" ) { 
     3009    if ( $evento eq "monitor" ) { 
     3010        my $botinro = ""; 
     3011        ( undef, $estado_final, undef ) = split( /-/, $hash_temporal{ActionID}, 3 ); 
     3012        ( $canal, undef ) = separate_session_from_channel( $hash_temporal{Channel} ); 
     3013        $canalid = $hash_temporal{Channel}; 
     3014        $estado_final =~ tr/A-Z/a-z/; 
     3015    } 
     3016    elsif ( $evento eq "channelreload" ) { 
    28983017 
    28993018        # Event: ChannelReload 
     
    29173036                my $indice = $hash_temporal{Uniqueid} . "-" . $hash_temporal{Server}; 
    29183037                if ( exists( $datos{"$indice"} ) ) { 
    2919                     log_debug( "** ATTENDANT we had that uniqueid before, extract the channel from there", 16 ) if DEBUG; 
     3038                    log_debug( "** ATTENDANT we had that uniqueid before, extract the channel from there", 16 ) 
     3039                      if DEBUG; 
    29203040                    if ( defined( $datos{$indice}{Extension} ) ) { 
    29213041 
     
    29303050                } 
    29313051                else { 
    2932                     log_debug( "** ATTENDANT we do not have any event with that uniqueid, save for later", 16 ) if DEBUG; 
     3052                    log_debug( "** ATTENDANT we do not have any event with that uniqueid, save for later", 16 ) 
     3053                      if DEBUG; 
    29333054                    print_datos(99); 
    29343055                    $pending_uniqueid_attendant{ $hash_temporal{Uniqueid} } = $hash_temporal{Exten} . "@" . $hash_temporal{Context}; 
     
    29723093            } 
    29733094 
    2974             while ( ( $key, $val ) = each(%mute_other) ) { 
    2975                 log_debug( "Mute other after originate failure: $key = $val", 16 ) if DEBUG; 
    2976             } 
    2977             while ( ( $key, $val ) = each(%pending_uniqueid_attendant) ) { 
    2978                 log_debug( "Pending uniqueid attendant after originate failure: $key = $val", 16 ) if DEBUG; 
    2979             } 
     3095            if (DEBUG) { 
     3096                while ( ( $key, $val ) = each(%mute_other) ) { 
     3097                    log_debug( "Mute other after originate failure: $key = $val", 16 ); 
     3098                } 
     3099                while ( ( $key, $val ) = each(%pending_uniqueid_attendant) ) { 
     3100                    log_debug( "Pending uniqueid attendant after originate failure: $key = $val", 16 ); 
     3101                } 
     3102            } 
     3103 
    29803104            my $tempval = $config->{$contexto}{'attendant_failure_redirect_to'}; 
    29813105            $tempval =~ s/\${CHANNEL}/$hash_temporal{Channel}/g; 
     
    29843108 
    29853109            if ( $tempval =~ m/\@/ ) { 
    2986                 my @partes = split( /\@/, $tempval, 2 ); 
    2987                 $dst_exten   = $partes[0]; 
    2988                 $dst_context = $partes[1]; 
     3110                ( $dst_exten, $dst_context ) = split( /\@/, $tempval, 2 ); 
    29893111            } 
    29903112            else { 
     
    30313153        #TalkTime: 557 
    30323154        #Reason: agent 
    3033         my ( $canal, $nada ) = separate_session_from_channel( $hash_temporal{Channel} ); 
     3155        my ( $canal, undef ) = separate_session_from_channel( $hash_temporal{Channel} ); 
    30343156        request_queue_status( $socket, $canal ); 
    30353157        my @respuestas = set_queueobject( $server, $canal, "status", 1 ); 
     
    31693291        $estado_final = "ringing"; 
    31703292        $canal        = $hash_temporal{"AgentCalled"}; 
    3171         $canal =~ tr/a-z/A-Z/; 
     3293        my $unique = find_uniqueid( $hash_temporal{ChannelCalling}, $server ); 
     3294        $unique =~ s/(.*)-.*/$1/g; 
     3295        $canal  =~ tr/a-z/A-Z/; 
    31723296        $canalid  = $canal . "-XXXX"; 
    31733297        $clidnum  = $hash_temporal{"CallerID"}; 
     
    31763300        my $base64_clidnum  = encode_base64( $clidnum . " " ); 
    31773301        my $base64_clidname = encode_base64( $clidname . " " ); 
     3302 
     3303        foreach my $var ( split( /\|/, $passvars ) ) { 
     3304            if ( defined( $chanvar{$unique}{$var} ) ) { 
     3305                my $base64_var = encode_base64( $chanvar{$unique}{$var} ); 
     3306                push @return, "$canal|setvar|$var=$base64_var|$canalid-$server|$canalid"; 
     3307            } 
     3308        } 
    31783309        push @return, "$canal|clidnum|$base64_clidnum|$canalid-$server|$canalid"; 
    31793310        push @return, "$canal|clidname|$base64_clidname|$canalid-$server|$canalid"; 
     
    32073338        my $dorigen  = ""; 
    32083339        my $ddestino = ""; 
    3209         my $dnada    = ""; 
    32103340        $remote_callerid{$key}      = $hash_temporal{"CallerID"}; 
    32113341        $remote_callerid_name{$key} = $hash_temporal{"CallerIDName"}; 
     3342 
     3343        foreach my $var ( split( /\|/, $passvars ) ) { 
     3344            if ( defined( $chanvar{ $hash_temporal{"SrcUniqueID"} }{$var} ) ) { 
     3345                $passvar{ $hash_temporal{"DestUniqueID"} }{$var} = $chanvar{ $hash_temporal{"SrcUniqueID"} }{$var}; 
     3346            } 
     3347        } 
    32123348 
    32133349        if ( $hash_temporal{'Source'} =~ m/^Local/i ) { 
     
    32173353            # so we can map outgoing calls to Agent buttons 
    32183354            # It will only work after the agent receives at least one call 
    3219             ( $dorigen,  $dnada ) = separate_session_from_channel( $hash_temporal{'Source'} ); 
    3220             ( $ddestino, $dnada ) = separate_session_from_channel( $hash_temporal{'Destination'} ); 
     3355            ( $dorigen,  undef ) = separate_session_from_channel( $hash_temporal{'Source'} ); 
     3356            ( $ddestino, undef ) = separate_session_from_channel( $hash_temporal{'Destination'} ); 
    32213357            if ( exists( $channel_to_agent{"$server^$dorigen"} ) ) { 
    32223358                my $agente = $channel_to_agent{"$server^$dorigen"}; 
     
    32613397        my $valor = ""; 
    32623398        $estado_final = "astdb"; 
    3263         ( $canal, my $nada ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
     3399        ( $canal, undef ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
    32643400        $canalid = $hash_temporal{"Channel"} . "-XXXX"; 
    32653401        my $clave = $hash_temporal{"Family"}; 
     
    33093445        # XXXX It will have to store this value internally in future version 
    33103446        # to avoid polling asterisk every time 
    3311         ( $canal, my $nada ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
     3447        ( $canal, undef ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
    33123448        $texto = $hash_temporal{"IP"}; 
    33133449        my $serv = $hash_temporal{"Server"}; 
     
    33253461        my $color = ""; 
    33263462        my $state = ""; 
    3327         ( $canal, my $nada ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
     3463        ( $canal, undef ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
    33283464        $color        = $hash_temporal{"Color"}; 
    33293465        $state        = $hash_temporal{"State"}; 
     
    33333469    } 
    33343470    elsif ( $evento eq "foppopup" ) { 
    3335         ( $canal, my $nada ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
     3471        ( $canal, undef ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
    33363472        my $url    = $hash_temporal{"URL"}; 
    33373473        my $target = $hash_temporal{"Target"}; 
     
    33443480    } 
    33453481    elsif ( $evento eq "refreshqueue" ) { 
    3346         ( $canal, my $nada ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
     3482        ( $canal, undef ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
    33473483 
    33483484        # Turns off led of the agent that generated the refresh 
     
    33943530            # so we populate some internal structures. If not, its a fake 
    33953531            # callbacklogin from the show agents cli command 
    3396             ( $canal, my $nada ) = separate_session_from_channel( $datos{$unico_id}{Channel} ); 
     3532            ( $canal, undef ) = separate_session_from_channel( $datos{$unico_id}{Channel} ); 
    33973533            $canal =~ tr/a-z/A-Z/; 
    33983534        } 
     
    34143550                # in op_buttons.cfg. 
    34153551                $canal = $extension_transfer_reverse{$ext_transf_key}; 
    3416                 $canal =~ s/(.*)&(.*)/$1/g
     3552                ( $canal, undef ) = split( /&/, $canal )
    34173553                if ( $canal =~ /\^/ ) { 
    3418                     my @pedacete = split( /\^/, $canal ); 
    3419                     $canal = $pedacete[1]; 
     3554                    ( undef, $canal ) = split( /\^/, $canal ); 
    34203555                } 
    34213556            } 
     
    35683703 
    35693704    } 
     3705    elsif ( $evento eq "agents" ) { 
     3706 
     3707        #Event: Agents 
     3708        #Agent: 609 
     3709        #Name: Nicolas 
     3710        #Status: AGENT_LOGGEDOFF 
     3711        #LoggedInChan: n/a 
     3712        #LoggedInTime: 0 
     3713        #TalkingTo: n/a 
     3714        my $agent_number  = $hash_temporal{Agent}; 
     3715        my $agent_name    = $hash_temporal{Name}; 
     3716        my $agent_status  = $hash_temporal{Status}; 
     3717        my $agent_logchan = $hash_temporal{LoggedInChan}; 
     3718 
     3719        $agents_name{"$server^$agent_number"} = $agent_name; 
     3720        set_queueobject( $server, "AGENT/$agent_number", "name", $agent_name ); 
     3721 
     3722        if ( $agent_status eq "AGENT_IDLE" ) { 
     3723 
     3724            # Agent callback login, idle 
     3725            my $agevent = ""; 
     3726            if ( $agent_logchan =~ /.*\/.*-.*/ ) { 
     3727                $fake_bloque[$fakecounter]{"Event"}   = "Agentlogin"; 
     3728                $fake_bloque[$fakecounter]{"Channel"} = $agent_logchan; 
     3729            } 
     3730            else { 
     3731                $fake_bloque[$fakecounter]{"Event"}     = "Agentcallbacklogin"; 
     3732                $fake_bloque[$fakecounter]{"Loginchan"} = $agent_logchan; 
     3733            } 
     3734            $fake_bloque[$fakecounter]{"Agent"}  = $agent_number; 
     3735            $fake_bloque[$fakecounter]{"Name"}   = $agent_name; 
     3736            $fake_bloque[$fakecounter]{"Server"} = "$server"; 
     3737            $fakecounter++; 
     3738        } 
     3739        elsif ( $agent_status eq "AGENT_ONCALL" ) { 
     3740 
     3741            # Agent login 
     3742            $fake_bloque[$fakecounter]{Event}   = "Agentlogin"; 
     3743            $fake_bloque[$fakecounter]{Channel} = $agent_logchan; 
     3744            $fake_bloque[$fakecounter]{Agent}   = $agent_number; 
     3745            $fake_bloque[$fakecounter]{Server}  = $server; 
     3746            $fakecounter++; 
     3747        } 
     3748        elsif ( $agent_status eq "AGENT_LOGEDOFF" ) { 
     3749            $fake_bloque[$fakecounter]{Event}  = "Agentlogoff"; 
     3750            $fake_bloque[$fakecounter]{Agent}  = $agent_number; 
     3751            $fake_bloque[$fakecounter]{Server} = $server; 
     3752            $fake_bloque[$fakecounter]{Fake}   = 1; 
     3753            $fakecounter++; 
     3754        } 
     3755 
     3756    } 
    35703757    elsif ( $evento eq "agentlogin" ) { 
    35713758 
     
    35763763 
    35773764            # This catches a live real Agentlogin event 
    3578             ( my $canalreal, my $nada ) = separate_session_from_channel( $datos{$unico_id}{Channel} ); 
     3765            ( my $canalreal, undef ) = separate_session_from_channel( $datos{$unico_id}{Channel} ); 
    35793766            $canalreal =~ tr/a-z/A-Z/; 
    35803767            $channel_to_agent{"$server^$canalreal"}   = "Agent/$texto"; 
    35813768            $agent_to_channel{"$server^Agent/$texto"} = $canalreal; 
    3582             log_debug( "channel_to_agent($server^$canalreal) = " . $channel_to_agent{"$server^$canalreal"}, 64 ) if DEBUG; 
     3769            log_debug( "channel_to_agent($server^$canalreal) = " . $channel_to_agent{"$server^$canalreal"}, 64 ) 
     3770              if DEBUG; 
    35833771            if ( !defined( $hash_temporal{Fake} ) || $hash_temporal{Fake} ne "init" ) { 
    35843772                my @respuestas = set_queueobject( $server, "AGENT/$texto", "status", 1 ); 
     
    37403928            $estado_final = "changelabel" . $change_led; 
    37413929 
    3742             if ( defined( $agent_to_channel{"$server^Agent/$canal"} ) || defined( $channel_to_agent{"$server^$canal"} ) ) { 
     3930            if (   defined( $agent_to_channel{"$server^Agent/$canal"} ) 
     3931                || defined( $channel_to_agent{"$server^$canal"} ) ) 
     3932            { 
    37433933                if ( defined( $agent_to_channel{"$server^Agent/$canal"} ) ) { 
    37443934                    $canal = $agent_to_channel{"$server^Agent/$canal"}; 
     
    38124002            if ( defined( $hash_temporal{Queue} ) ) { 
    38134003                $valor = $hash_temporal{Queue}; 
    3814                 if ( exists( $agents_available_on_queue{"$server^$valor"} ) && $agents_available_on_queue{"$server^$valor"} ne "" ) { 
     4004                if ( exists( $agents_available_on_queue{"$server^$valor"} ) 
     4005                    && $agents_available_on_queue{"$server^$valor"} ne "" ) 
     4006                { 
    38154007                    my $texto3 = ""; 
    38164008                    foreach my $qmem ( @{ $agents_available_on_queue{"$server^$valor"} } ) { 
     
    40354227    } 
    40364228    elsif ( $evento eq "meetmemute" || $evento eq "meetmeunmute" ) { 
    4037         my ( $canal, $nada ) = separate_session_from_channel($canalid); 
     4229        my ( $canal, undef ) = separate_session_from_channel($canalid); 
    40384230        $estado_final = $evento; 
    40394231        push @return, "$canal|$evento||$unico_id|$canalid"; 
     
    40664258    } 
    40674259    elsif ( $evento eq "join" ) { 
    4068         my $qclidnum  = ""; 
    4069         my $qclidname = ""; 
    40704260        $canal = "QUEUE/" . $hash_temporal{Queue}; 
    40714261        my $position = $hash_temporal{Position}; 
     
    40774267        $unico_id = "$canal-$server"; 
    40784268 
    4079         if ( defined( $hash_temporal{CallerIDName} ) ) { 
    4080             $qclidnum  = $hash_temporal{CallerID}; 
    4081             $qclidname = $hash_temporal{CallerIDName}; 
    4082         } 
    4083         elsif ( defined( $hash_temporal{CalleridName} ) ) { 
    4084             $qclidnum  = $hash_temporal{Callerid}; 
    4085             $qclidname = $hash_temporal{CalleridName}; 
    4086         } 
    4087         else { 
    4088             ( $qclidnum, $qclidname ) = split_callerid( $hash_temporal{CallerID} ); 
    4089         } 
    4090         my $texto_pos = "[$qclidname $qclidnum]"; 
    4091  
    40924269        push @return, "$canal|$estado_final|$texto|$unico_id|$canalid"; 
    4093         push @return, "$canal=$position|$estado_final|$texto_pos|$unico_id|$canalid"; 
    4094         push @return, "$canal=$position|setalpha|100|$unico_id|$canalid"; 
     4270        my @queue_events = recompute_queues_onjoin( \%hash_temporal, $server, $canalid ); 
     4271        foreach my $valor (@queue_events) { 
     4272            push @return, $valor; 
     4273        } 
    40954274        $evento = ""; 
    4096  
    4097         my $tiempo = time(); 
    4098         if ( defined( $hash_temporal{Wait} ) ) { 
    4099             $tiempo = $tiempo - $hash_temporal{Wait}; 
    4100             push @return, "$canal=$position|settimer|$hash_temporal{Wait}\@UP|$unico_id|$canalid"; 
    4101         } 
    4102         $cola->{$canalid}{POSITION} = $position; 
    4103         $cola->{$canalid}{QUEUE}    = $canal; 
    4104         $cola->{$canalid}{CLID}     = $qclidnum; 
    4105         $cola->{$canalid}{CLIDNAME} = $qclidname; 
    4106         $cola->{$canalid}{SERVER}   = $server; 
    4107         $cola->{$canalid}{TIME}     = $tiempo; 
    4108  
     4275    } 
     4276    elsif ( $evento eq "leave" ) { 
     4277        $canal = "QUEUE/" . $hash_temporal{"Queue"}; 
     4278        $canal =~ tr/a-z/A-Z/; 
     4279        $estado_final = "ocupado"; 
     4280        my $plural = ""; 
     4281        if ( $hash_temporal{"Count"} > 1 )  { $plural       = "s"; } 
     4282        if ( $hash_temporal{"Count"} == 0 ) { $estado_final = "corto"; } 
     4283        $texto    = "&waitingonqueue," . $hash_temporal{"Count"} . ",$plural&"; 
     4284        $unico_id = "$canal-$server"; 
     4285        push @return, "$canal|$estado_final|$texto|$unico_id|$canalid"; 
     4286        $evento = ""; 
     4287 
     4288        print_sesbot(1); 
     4289        my @queue_events = recompute_queues_onleave($canalid); 
     4290        foreach my $valor (@queue_events) { 
     4291            push @return, $valor; 
     4292        } 
     4293        print_sesbot(2); 
    41094294    } 
    41104295    elsif ( $evento eq "meetmejoin" ) { 
    41114296        my $originate        = "no"; 
    41124297        my $mute_other_party = "no"; 
    4113         my $nada             = ""; 
    41144298        my $contexto         = ""; 
    41154299 
     
    42894473        } 
    42904474        my $canalfin = get_meetme_pos( $server, $canal, $position ); 
     4475        my ( $ca1, $se1 ) = separate_session_from_channel( $hash_temporal{Channel} ); 
     4476        push @return, "$ca1|$estado_final|$texto_pos|YYYY-$server|$hash_temporal{Channel}"; 
    42914477        push @return, "$canalfin|$estado_final|$texto_pos|YYYY-$server|$hash_temporal{Channel}"; 
    42924478        push @return, "$canalfin|meetmeuser|$hash_temporal{Usernum},$hash_temporal{Meetme}|YYYY-$server|$hash_temporal{Channel}"; 
     
    43144500        } 
    43154501 
    4316         my ( $canal1, $nada1 ) = separate_session_from_channel($canaleja); 
     4502        my ( $canal1, undef ) = separate_session_from_channel($canaleja); 
    43174503        push @return, "$canal1|unsetlink|$canal|$unico_id|$canalid"; 
    43184504        $evento = ""; 
     
    43214507        delete $meetme_pos{"$server^$canal"}{ $hash_temporal{Usernum} }; 
    43224508        push @return, "$canalfin|corto||$hash_temporal{Uniqueid}-$server|$canaleja"; 
    4323     } 
    4324     elsif ( $evento eq "leave" ) { 
    4325         $canal = "QUEUE/" . $hash_temporal{"Queue"}; 
    4326         $canal =~ tr/a-z/A-Z/; 
    4327         $estado_final = "ocupado"; 
    4328         my $plural = ""; 
    4329         if ( $hash_temporal{"Count"} > 1 )  { $plural       = "s"; } 
    4330         if ( $hash_temporal{"Count"} == 0 ) { $estado_final = "corto"; } 
    4331         $texto    = "&waitingonqueue," . $hash_temporal{"Count"} . ",$plural&"; 
    4332         $unico_id = "$canal-$server"; 
    4333         push @return, "$canal|$estado_final|$texto|$unico_id|$canalid"; 
    4334         $evento = ""; 
    4335  
    4336         print_sesbot(1); 
    4337         my @queue_events = recompute_queues($canalid); 
    4338         foreach my $valor (@queue_events) { 
    4339             push @return, $valor; 
    4340         } 
    4341         print_sesbot(2); 
    43424509    } 
    43434510    elsif ( $evento eq "voicemail" ) { 
     
    43554522            $unico_id = $canal; 
    43564523            $canalid  = $canal . "-XXXX"; 
    4357             if ( defined( $hash_temporal{"Waiting"} ) ) { 
     4524            if ( defined( $hash_temporal{Waiting} ) ) { 
     4525 
    43584526                $estado_final = "voicemail"; 
    4359                 $texto        = $hash_temporal{"Waiting"}; 
    4360  
    4361                 #$texto        = 1; 
    4362                 if ( $texto eq "1" ) { 
    4363  
    4364                     # If it has new voicemail, ask for mailboxcount 
     4527                $texto        = $hash_temporal{Waiting}; 
     4528 
     4529                if ( $texto eq "0" ) { 
     4530 
     4531                    # If it does not have new voicemail, ask for mailboxcount to get old mails 
    43654532                    send_command_to_manager( "Action: MailboxCount\r\nMailbox: $hash_temporal{Mailbox}\r\n\r\n", 
    43664533                        $socket, 0, $astmanproxy_server ); 
    43674534                } 
     4535                else { 
     4536 
     4537                    # If it has new voicemail, look for the New and Old headers 
     4538                    if ( defined( $hash_temporal{New} ) ) { 
     4539                        my $nuevos = $hash_temporal{"New"}; 
     4540                        my $viejos = $hash_temporal{"Old"}; 
     4541                        push @return, "$canal|voicemailcount|&newold,$nuevos,$viejos|$unico_id-$server|$canal-XXXX"; 
     4542                    } 
     4543                    else { 
     4544                        send_command_to_manager( "Action: MailboxCount\r\nMailbox: $hash_temporal{Mailbox}\r\n\r\n", 
     4545                            $socket, 0, $astmanproxy_server ); 
     4546                    } 
     4547                } 
    43684548            } 
    43694549            else { 
     4550 
     4551                # This is the actual message count event 
    43704552                $estado_final = "voicemailcount"; 
    43714553                my $nuevos = $hash_temporal{"NewMessages"}; 
     
    45344716 
    45354717        if ( $nuevo_nombre =~ /<ZOMBIE>/ ) { 
    4536             log_debug( "$heading $nuevo_nombre, asterisk bug, sometimes misses the hangup, so we fake it", 64 ) if DEBUG; 
    4537             my ( $canalnuevo, $nada ) = separate_session_from_channel($nuevo_nombre); 
     4718            log_debug( "$heading $nuevo_nombre, asterisk bug, sometimes misses the hangup, so we fake it", 64 ) 
     4719              if DEBUG; 
     4720            my ( $canalnuevo, undef ) = separate_session_from_channel($nuevo_nombre); 
    45384721            push @return, "$canalnuevo|corto||$unico_id|$nuevo_nombre"; 
    45394722        } 
     
    45794762 
    45804763                    if ( defined($canalcambiado) ) { 
    4581                         my ( $canalito, $nada ) = separate_session_from_channel($canalcambiado); 
     4764                        my ( $canalito, undef ) = separate_session_from_channel($canalcambiado); 
    45824765                        push @return, "$canalito|$estado_final|$nuevo_nombre|$unico_id|$canalcambiado"; 
    4583                         ( $canalito, $nada ) = separate_session_from_channel($nuevo_nombre); 
     4766                        ( $canalito, undef ) = separate_session_from_channel($nuevo_nombre); 
    45844767                        push @return, "$canalito|$estado_final|$canalcambiado|$unico_id|$nuevo_nombre"; 
    45854768                        $canal = $canalito; 
     
    46314814            $texto        = "&unreachable,$tiempo"; 
    46324815        } 
     4816        elsif ( $state eq "Unregistered" ) { 
     4817            $estado_final = "noregistrado"; 
     4818            $texto        = "&notregistered"; 
     4819        } 
    46334820        elsif ( $state eq "Lagged" ) { 
    46344821            $estado_final = "noregistrado"; 
     
    46674854            my $hay_activos = 0; 
    46684855 
    4669             for ( keys %datos ) { 
    4670                 my $ignorame       = 0; 
    4671                 my @pedazote       = split( /-/, $_ ); 
    4672                 my $current_server = $pedazote[1]; 
     4856            foreach my $dkey ( keys %datos ) { 
     4857                my $ignorame = 0; 
     4858                my ( undef, $current_server ) = split( /-/, $dkey ); 
    46734859                if ( "$server" ne "$current_server" ) { 
    46744860                    next; 
    46754861                } 
    46764862 
    4677                 log_debug( "$heading STATUSCOMPLETE datos { $_ }", 128 ) if DEBUG; 
    4678                 push @ids, $_
     4863                log_debug( "$heading STATUSCOMPLETE datos { $dkey }", 128 ) if DEBUG; 
     4864                push @ids, $dkey
    46794865                my $myevent = "Newexten"; 
    4680                 while ( my ( $key, $val ) = each( %{ $datos{$_} } ) ) { 
     4866                while ( my ( $key, $val ) = each( %{ $datos{$dkey} } ) ) { 
    46814867                    log_debug( "$heading STATUSCOMPLETE datos { $key } = $val", 128 ) if DEBUG; 
    4682  
    46834868                    if ( defined($val) ) { 
    46844869                        $hay_activos = 1; 
     
    47564941        $estado_final = "meetmeuser"; 
    47574942        $texto        = $hash_temporal{Usernum} . "," . $hash_temporal{Meetme}; 
    4758         my ( $chan1, $nada1 ) = separate_session_from_channel( $hash_temporal{Channel} ); 
     4943        my ( $chan1, undef ) = separate_session_from_channel( $hash_temporal{Channel} ); 
    47594944        push @return, "$hash_temporal{Meetme}|setlink|$hash_temporal{Channel}||$hash_temporal{Channel}"; 
    47604945        push @return, "$chan1|setlink|$hash_temporal{Meetme}||$hash_temporal{Channel}"; 
     
    47644949    elsif ( $evento eq "newexten" ) { 
    47654950 
    4766 #        print "newexten\n"; 
    4767  
    47684951        # If its a new extension without state and priority 1, defaults to 'Up' and set setlid 
     4952        if ( !defined( $hash_temporal{'Priority'} ) ) { 
     4953            $hash_temporal{'Priority'} = 1; 
     4954        } 
    47694955        if ( !defined( $datos{$unico_id}{'State'} ) && $hash_temporal{Priority} == 1 ) { 
    47704956            $datos{$unico_id}{'State'} = "Up"; 
    47714957            log_debug( "$heading POPULATES datos($unico_id){ State } = Up", 128 ) if DEBUG; 
    47724958            ( $canal, $sesion ) = separate_session_from_channel( $hash_temporal{Channel} ); 
    4773             $texto        = $hash_temporal{Extension}; 
    4774       if($texto ne "s") { 
    4775               $estado_final = "setclid"; 
    4776       } 
    4777         } 
    4778         else { 
    4779 #            print "Newexten pero otro priority?\n"; 
     4959            $texto = $hash_temporal{Extension}; 
     4960            if ( $texto ne "s" ) { 
     4961                $estado_final = "setclid"; 
     4962            } 
    47804963        } 
    47814964 
     
    48014984            log_debug( "Save " . $hash_temporal{Channel} . " as pending", 16 ) if DEBUG; 
    48024985        } 
    4803  
    48044986 
    48054987    } 
     
    48785060    } 
    48795061    elsif ( $evento eq "parkedcall" ) { 
    4880         $texto        = "&parked," . $hash_temporal{'Exten'} . "&"; 
     5062        my $parksl = ""; 
     5063        if ( defined( $hash_temporal{LotName} ) ) { 
     5064            $parksl = $hash_temporal{LotName} . "-" . $hash_temporal{Exten}; 
     5065        } 
     5066        else { 
     5067            $parksl = $hash_temporal{Exten}; 
     5068        } 
     5069        $texto        = "&parked," . $parksl . "&"; 
    48815070        $estado_final = "ocupado3"; 
    4882         my ( $canal, $nada ) = separate_session_from_channel( $hash_temporal{'Channel'} ); 
     5071        my ( $canal, undef ) = separate_session_from_channel( $hash_temporal{'Channel'} ); 
    48835072        my $textid   = ""; 
    48845073        my $timeout  = ""; 
    48855074        my $unidchan = find_uniqueid( $hash_temporal{'Channel'}, $server ); 
    4886         $textid = $datos{$unidchan}{'Callerid'} 
    4887           if ( defined( $datos{$unidchan}{'Callerid'} ) ); 
    4888         $textid = $datos{$unidchan}{'CallerID'} 
    4889           if ( defined( $datos{$unidchan}{'CallerID'} ) ); 
    4890         $timeout = "(" . $hash_temporal{'Timeout'} . ")"; 
     5075        if ( defined( $hash_temporal{CallerID} ) ) { 
     5076            $textid = $hash_temporal{CallerID} . " " . $hash_temporal{CallerIDName}; 
     5077        } 
     5078        else { 
     5079            $textid = $datos{$unidchan}{Callerid} 
     5080              if ( defined( $datos{$unidchan}{Callerid} ) ); 
     5081            $textid = $datos{$unidchan}{CallerID} 
     5082              if ( defined( $datos{$unidchan}{CallerID} ) ); 
     5083        } 
     5084        $timeout = "(" . $hash_temporal{Timeout} . ")"; 
    48915085        $textid =~ s/\"//g; 
    48925086        $textid =~ s/\<//g; 
    48935087        $textid =~ s/\>//g; 
    48945088        push @return, "$canal|ocupado3|$texto|$unidchan|$canalid"; 
    4895         push @return, "PARK/$hash_temporal{'Exten'}|park|[$textid]$timeout|$hash_temporal{'Timeout'}-$server|$hash_temporal{'Channel'}"; 
    4896  
    4897         log_debug( "$heading pongo parked($server^$hash_temporal{'Channel'}) en $hash_temporal{'Exten'}", 64 ) if DEBUG; 
    4898         $parked{"$server^$hash_temporal{'Channel'}"} = $hash_temporal{'Exten'}
     5089        push @return, "PARK/$parksl|park|[$textid]$timeout|$hash_temporal{'Timeout'}-$server|$hash_temporal{'Channel'}"; 
     5090 
     5091        log_debug( "$heading pongo parked($server^$hash_temporal{'Channel'}) en $parksl", 64 ) if DEBUG; 
     5092        $parked{"$server^$hash_temporal{'Channel'}"} = $parksl
    48995093        $evento = "";    #NEW 
    49005094    } 
     
    49225116    # Dont check for $evento bellow this line! 
    49235117 
    4924 #    print "AFTER IF ELSE IF evento = $evento\n"; 
    4925  
    49265118    if ( $evento ne "" ) { 
    4927         log_debug( "$heading Event $evento, canal '$canal'", 32 ) if DEBUG; 
     5119        log_debug( "$heading Event $evento, canal '$canal', estadofinal $estado_final", 32 ) if DEBUG; 
    49285120 
    49295121        # De acuerdo a los datos de la extension genera 
     
    50225214            if ( $clidnum ne "" ) { 
    50235215                my $base64_clidnum = encode_base64( $clidnum . " " ); 
    5024                 $ret = "$canal|clidnum|$base64_clidnum|$unico_id|$hash_temporal{'Channel'}"; 
     5216                $ret = "$canal|clidnum|$base64_clidnum|$unico_id|$hash_temporal{Channel}"; 
    50255217                push @return, $ret; 
    50265218            } 
    50275219            if ( defined($clidname) ) { 
    50285220                my $base64_clidname = encode_base64( $clidname . " " ); 
    5029                 $ret = "$canal|clidname|$base64_clidname|$unico_id|$hash_temporal{'Channel'}"; 
     5221                $ret = "$canal|clidname|$base64_clidname|$unico_id|$hash_temporal{Channel}"; 
    50305222                push @return, $ret; 
    50315223            } 
     5224            foreach my $var ( keys %{ $passvar{ $hash_temporal{Uniqueid} } } ) { 
     5225                my $base64_var = encode_base64( $passvar{ $hash_temporal{Uniqueid} }{$var} ); 
     5226                $ret = "$canal|setvar|$var=$base64_var|$unico_id|$hash_temporal{Channel}"; 
     5227                push @return, $ret; 
     5228            } 
     5229            delete $passvar{ $hash_temporal{Uniqueid} }; 
    50325230        } 
    50335231 
     
    50375235 
    50385236        if ( $state eq "Ring" ) { 
    5039 #            print "RING $canalid $texto\n"
    5040             $texto                      = $canalid
    5041             $estado_final               = "ring"; 
    5042             $datos{$unico_id}{'Origin'} = "true"; 
    5043             log_debug( "$heading POPULATES datos($unico_id){ Origin } = true", 128 ) if DEBUG; 
     5237            $texto        = $canalid
     5238            $estado_final = "ring"
     5239 
     5240            #$datos{$unico_id}{'Origin'} = "true"; 
     5241            #log_debug( "$heading POPULATES datos($unico_id){ Origin } = true", 128 ) if DEBUG; 
    50445242        } 
    50455243 
     
    52145412 
    52155413    my $cuantos = $#return + 1; 
    5216     log_debug( "$heading returns $cuantos", 16 ) if DEBUG; 
    5217     foreach (@return) { 
    5218         log_debug( "$heading END SUB returns $_", 32 ) if DEBUG
     5414    if (DEBUG) { 
     5415        log_debug( "$heading returns $cuantos", 16 ); 
     5416        log_debug( "$heading END SUB returns $_", 32 ) foreach (@return)
    52195417    } 
    52205418    $tab = substr( $tab, 0, -1 ); 
     
    52605458    $canal =~ s/(.*)&(.*)/$1/g; 
    52615459 
    5262     # if( $canal =~ m/^CLID/ ) { 
    5263     #       my $extr = $extension_transfer{"$server^$canal"}; 
    5264     #   $extr =~ s/\d+\^(.*)/$1/g; 
    5265     #   $canal = "Local/$extr"; 
    5266     # } 
    5267  
    52685460    log_debug( "** LOCAL_CHANNELS devuelvo $server canal $canal", 32 ) if DEBUG; 
     5461 
     5462    # If channel has a pipe due to REGEXP button, replace it with something else because 
     5463    # procesa_bloque use pipes to return data to digest_event_block 
     5464    $canal =~ s/\|/~/g; 
    52695465    push @return, $server; 
    52705466    push @return, $canal; 
     
    52965492    $tab = $tab . "\t" if DEBUG; 
    52975493 
    5298     log_debug( "$heading start", 16 ) if DEBUG; 
     5494    log_debug( "$heading start", 256 ) if DEBUG; 
    52995495 
    53005496    @fake_bloque = (); 
    53015497 
    5302     # delete $datos{""}; 
    53035498    foreach my $blaque (@blique) { 
    53045499 
     
    53175512        } 
    53185513        @mensajes = procesa_bloque( $blaque, $socket, $astmanproxy_server ); 
     5514 
    53195515        foreach my $mensaje (@mensajes) { 
    53205516            if ( defined($mensaje) && $mensaje ne "" ) { 
    5321                 log_debug( "$heading GOT $mensaje", 32 ) if DEBUG; 
     5517                log_debug( "$heading GOT $mensaje", 256 ) if DEBUG; 
    53225518                delete $datos{""};    # Erase the hash with no uniqueid 
    53235519                ( $canal, $quehace, $dos, $uniqueid, $canalid ) = split( /\|/, $mensaje ); 
    53245520 
     5521                # change back newflo into pipes 
     5522                $canal   =~ s/~/\|/g; 
     5523                $canalid =~ s/~/\|/g; 
    53255524                $canalid =~ s/(.*),(\d)/$1/g;    # discard ,2 on Local channels 
    53265525 
     
    53295528 
    53305529                if ( $canal =~ /\/PSEUDO/ ) { 
    5331                     log_debug( "$heading Ignoring pseudo channel $canal", 32 ) if DEBUG; 
     5530                    log_debug( "$heading Ignoring pseudo channel $canal", 256 ) if DEBUG; 
    53325531                    next; 
    53335532                } 
    53345533 
    53355534                if ( $dos eq "skip" ) { 
    5336                     log_debug( "$heading skipping $canal $quehace (has skip)", 32 ) if DEBUG; 
     5535                    log_debug( "$heading skipping $canal $quehace (has skip)", 256 ) if DEBUG; 
    53375536                    next; 
    53385537                } 
    53395538 
    53405539                if ( $quehace eq "" ) { 
    5341                     log_debug( "$heading skipping $canal (empty quehace)", 32 ) if DEBUG; 
    5342 #         print "skip empty\n"; 
     5540                    log_debug( "$heading skipping $canal (empty quehace)", 256 ) if DEBUG; 
    53435541                    next; 
    53445542                } 
    53455543 
    5346                 log_debug( "$heading canal:    $canal",    32 ) if DEBUG; 
    5347                 log_debug( "$heading quehace:  $quehace",  32 ) if DEBUG; 
    5348                 log_debug( "$heading dos:      $dos",      32 ) if DEBUG; 
    5349                 log_debug( "$heading uniqueid: $uniqueid", 32 ) if DEBUG; 
    5350                 log_debug( "$heading canalid:  $canalid",  32 ) if DEBUG; 
    5351  
    5352                 $canalid =~ s/\s+//g;            # Removes whitespace from CHANNEL-ID 
    5353                 my $real_canal    = $canalid; 
    5354                 my $canalidzombie = $canalid;    # Removes whitespace from CHANNEL-ID 
    5355                 $canalid =~ s/(.*)<(.*)>/$1/g;   # discards ZOMBIE or MASQ 
     5544                log_debug( "$heading canal:    $canal",    256 ) if DEBUG; 
     5545                log_debug( "$heading quehace:  $quehace",  256 ) if DEBUG; 
     5546                log_debug( "$heading dos:      $dos",      256 ) if DEBUG; 
     5547                log_debug( "$heading uniqueid: $uniqueid", 256 ) if DEBUG; 
     5548                log_debug( "$heading canalid:  $canalid",  256 ) if DEBUG; 
     5549 
     5550                $canalid =~ s/\s+//g;             # Removes whitespace from CHANNEL-ID 
     5551                $canalid =~ s/(.*)<(.*)>/$1/g;    # discards ZOMBIE or MASQ 
    53565552 
    53575553                if ( $canal =~ /^vpb\//i ) { 
     
    53665562                $server =~ s/(.*)-(.*)/$2/g; 
    53675563 
    5368                 log_debug( "$heading Quehace $quehace", 64 ) if DEBUG; 
    5369  
    53705564                my $buttontext = $dos; 
    53715565                if ( $buttontext =~ /\Q[\E/ ) { 
     
    53795573                my $cuantos  = @canaleja; 
    53805574 
    5381        # Perform some pre processing... 
     5575                # Perform some pre processing... 
    53825576 
    53835577                if ( $quehace eq "corto" || $quehace eq "info" ) { 
     
    53885582                        $toda .= "$key = $val\n" 
    53895583                          if ( $key ne "E" ) && ( defined($val) ); 
    5390                         log_debug( "$heading \tAgrego $key = $val", 128 ) if DEBUG; 
     5584                        log_debug( "$heading \tAgrego $key = $val", 256 ) if DEBUG; 
    53915585                    } 
    53925586                    $toda .= " "; 
     
    53945588 
    53955589                    if ( $quehace eq "corto" ) { 
     5590                        log_debug( "$heading erasing datos{$uniqueid}", 256 ) if DEBUG; 
    53965591                        delete $datos{$uniqueid}; 
    5397                     } 
    5398  
    5399                     log_debug( "$heading erasing datos{$uniqueid}", 128 ) if DEBUG; 
    5400  
    5401                     if ( $cuantos == 0 ) { 
    5402  
    5403                         # We delete all appeareance in sesbot because the channel without 
    5404                         # a button might occupy one slot in sesbot. If we have a button 
    5405                         # match then skip this step for later 
    5406                         erase_all_sessions_from_channel( $canalid, $canal, $server ); 
    5407                     } 
    5408  
    5409                 } elsif ( $quehace eq "queueremoved" ) { 
     5592                        delete $chanvar{$uniqueid}; 
     5593                        delete $passvar{$uniqueid}; 
     5594 
     5595                        if ( $cuantos == 0 ) { 
     5596 
     5597                            # We need to call it here because a channel with no buttons defined 
     5598                            # might count for other button that exists, like meetmes, queues, etc. 
     5599                            # So we only call it when there is NO match for buttons (because 
     5600                            # we will call it again for existing matches) 
     5601                            erase_all_sessions_from_channel( $canalid, $canal, $server ); 
     5602                        } 
     5603                    } 
     5604                } 
     5605                elsif ( $quehace eq "queueremoved" ) { 
    54105606 
    54115607                    # Remove the agent from the agents_on_queue hash 
     
    54385634 
    54395635                foreach $canal (@canaleja) { 
    5440                     log_debug( "",                                       32 ) if DEBUG; 
    5441                     log_debug( "$heading canaleja LOOP; is $canal turn", 32 ) if DEBUG; 
     5636                    log_debug( "",                                       256 ) if DEBUG; 
     5637                    log_debug( "$heading canaleja LOOP; is $canal turn", 256 ) if DEBUG; 
    54425638 
    54435639                    if ( $dosoriginal ne "" ) { 
     
    54515647 
    54525648                    if ( !defined( $buttons{"$server^$canal"} ) && !defined( $buttons{"-1^$canal"} ) ) { 
    5453                         log_debug( "$heading \tThere are no buttons for $server^$canal, skipping...", 128 ) if DEBUG; 
     5649                        log_debug( "$heading \tThere are no buttons for $server^$canal, skipping...", 256 ) if DEBUG; 
    54545650                        if (DEBUG) { 
    54555651                            for ( keys %buttons ) { 
    5456                                 log_debug( "$heading \t\tKey $_", 128 ); 
     5652                                log_debug( "$heading \t\tKey $_", 256 ); 
    54575653                            } 
    54585654                        } 
     
    54635659                    # except ocupado*, corto, setlink and unsetlink 
    54645660                    if ( $canal =~ /^_/ ) { 
    5465                         log_debug( "$heading canal $canal is regexp, quehace value = $quehace", 32 ) if DEBUG; 
     5661                        log_debug( "$heading canal $canal is regexp, quehace value = $quehace", 256 ) if DEBUG; 
    54665662 
    54675663                        if (   $quehace =~ /registr/ 
     
    54695665                            || $quehace =~ /^inf/ ) 
    54705666                        { 
    5471                             log_debug( "$heading IGNORING $quehace because it is a regexp match", 32 ) if DEBUG; 
     5667                            log_debug( "$heading IGNORING $quehace because it is a regexp match", 256 ) if DEBUG; 
    54725668                            next; 
    54735669                        } 
     
    54885684                            && $quehace !~ /^unsetlink/ ) 
    54895685                        { 
    5490                             my ( $nada, $elcontexto ) = split( /\&/, $canal ); 
     5686                            my ( undef, $elcontexto ) = split( /\&/, $canal ); 
    54915687                            if ( !defined($elcontexto) ) { $elcontexto = ""; } 
    54925688                            if ( $elcontexto ne "" ) { 
     
    54955691                            my ( $canalsolo, $nrotrunk ) = split( /=/, $canal ); 
    54965692                            $canal = $canalsolo . "=1" . $elcontexto; 
    5497                             log_debug( "$heading quehace=$quehace, select 1st from trunk $canal", 32 ) if DEBUG; 
     5693                            log_debug( "$heading quehace=$quehace, select 1st from trunk $canal", 256 ) if DEBUG; 
    54985694 
    54995695                            #next; 
    55005696                        } 
    55015697 
    5502                         # If we have a wildcard button with changelabel 
     5698                        # If we have a regexp button with changelabel 
    55035699                        # and change led_color (the 1 after changelabel) 
    55045700                        # change it so to not change the led color. 
    55055701                        if ( $quehace =~ /changelabel1/ ) { 
    5506                             log_debug( "$heading el regexp tiene changelabel1, lo cambio por changelabel0!", 32
     5702                            log_debug( "$heading regexp has changelabel1, lets change it to changelabel0!", 256
    55075703                              if DEBUG; 
    55085704                            $quehace = "changelabel0"; 
     
    55135709 
    55145710                    if ( $canal eq "" ) { 
    5515             # No channel? continue... 
    5516                         log_debug( "$heading There is no command defined", 32 ) if DEBUG; 
    5517  
    5518           } else { 
     5711 
     5712                        # No channel? continue... 
     5713                        log_debug( "$heading There is no command defined", 256 ) if DEBUG; 
     5714 
     5715                    } 
     5716                    else { 
    55195717 
    55205718                        $interno = $buttons{"$server^$canal"}; 
    5521  
    55225719                        if ( !defined($interno) ) { 
    55235720                            $interno     = $buttons{"-1^$canal"}; 
     
    55385735                        } 
    55395736 
    5540            # The following block cleans internal op_server states. no matter if we 
    5541            # have a button defined or not. 
     5737                        # The following block cleans internal op_server states. no matter if we 
     5738                        # have a button defined or not. 
    55425739 
    55435740                        if ( $quehace eq 'corto' || $quehace eq 'info' ) { 
    5544  
    55455741                            my @linked = erase_all_sessions_from_channel( $canalid, $canal, $server ); 
     5742 
    55465743                            push @linked, $canal; 
    55475744                            my $btnorinum = ""; 
     
    55535750                                    $btnorinum = $buttons{"$serverindex^$canaleje"}; 
    55545751                                } 
    5555                                 log_debug( "$heading call GEN_LINKED 1", 32 ) if DEBUG; 
     5752                                log_debug( "$heading call GEN_LINKED 1", 256 ) if DEBUG; 
    55565753                                my $listabotones = generate_linked_buttons_list( $canaleje, $server ); 
    55575754                                push @respuestas, "$btnorinum|linked|$listabotones"; 
     
    55595756 
    55605757                            delete $datos{$uniqueid}; 
    5561                             log_debug( "$heading REMOVING datos { $uniqueid }", 32 ) if DEBUG; 
    5562  
    5563                         } elsif ( $quehace eq "setlink" ) { 
    5564  
    5565                             log_debug( "$heading IF quehace = SETLINK", 32 ) if DEBUG; 
    5566                             my ( $nada1, $contexto1 ) = split( /\&/, $canal ); 
     5758                            delete $chanvar{$uniqueid}; 
     5759                            delete $passvar{$uniqueid}; 
     5760                            log_debug( "$heading REMOVING datos { $uniqueid }", 256 ) if DEBUG; 
     5761 
     5762                        } 
     5763                        elsif ( $quehace eq "setlink" ) { 
     5764 
     5765                            log_debug( "$heading IF quehace = SETLINK", 256 ) if DEBUG; 
     5766                            my ( undef, $contexto1 ) = split( /\&/, $canal ); 
    55675767                            if ( !defined($contexto1) ) { $contexto1 = ""; } 
    55685768                            my $listabotones = ""; 
     
    55715771                                push @{ $linkbot{"$server^$canal"} }, ""; 
    55725772                                pop @{ $linkbot{"$server^$canal"} }; 
    5573                                 log_debug( "$heading DEFINIENDO linkbot ($server^$canal)", 32 ) if DEBUG; 
     5773                                log_debug( "$heading DEFINIENDO linkbot ($server^$canal)", 256 ) if DEBUG; 
    55745774                            } 
    55755775 
     
    55775777                            my @linkbotones = find_panel_buttons( $canal1, $dos, $server ); 
    55785778                            foreach (@linkbotones) { 
    5579                                 my ( $nada2, $contexto2 ) = split( /\&/, $_ ); 
     5779                                my ( undef, $contexto2 ) = split( /\&/, $_ ); 
    55805780                                if ( !defined($contexto2) ) { $contexto2 = ""; } 
    55815781                                if ( $contexto1 eq $contexto2 ) { 
    55825782                                    push @{ $linkbot{"$server^$canal"} }, $dos; 
    5583                                     log_debug( "$heading AGREGO a linkbot{ $server^$canal} el valor $dos", 32
     5783                                    log_debug( "$heading AGREGO a linkbot{ $server^$canal} el valor $dos", 256
    55845784                                      if DEBUG; 
    55855785                                } 
     
    55905790 
    55915791                            foreach my $valorad (@uniq) { 
    5592                                 log_debug( "$heading linkbot ($server^$canal) = $valorad", 32 ) if DEBUG; 
     5792                                log_debug( "$heading linkbot ($server^$canal) = $valorad", 256 ) if DEBUG; 
    55935793                            } 
    55945794                            my $btnorinum = $buttons{"$serverindex^$canal"}; 
    5595                             log_debug( "$heading llamo a GENERATE_LINKED", 32 ) if DEBUG; 
     5795                            log_debug( "$heading llamo a GENERATE_LINKED", 256 ) if DEBUG; 
    55965796                            $listabotones = generate_linked_buttons_list( $canal, $server ); 
    55975797                            push @respuestas, "$btnorinum|linked|$listabotones"; 
     5798                            push @respuestas, "$btnorinum|bridgepeer|$dos"; 
    55985799                            $botonlinked{$btnorinum} = $listabotones; 
    5599                             log_debug( "$heading linkeado con $listabotones", 32 ) if DEBUG; 
    5600                             log_debug( "$heading ENDIF quehace = SETLINK",    32 ) if DEBUG; 
    5601  
    5602                         } elsif ( $quehace eq "unsetlink" ) { 
    5603                             log_debug( "$heading IF quehace = UNSETLINK", 32 ) if DEBUG; 
     5800                            log_debug( "$heading linkeado con $listabotones", 256 ) if DEBUG; 
     5801                            log_debug( "$heading ENDIF quehace = SETLINK",    256 ) if DEBUG; 
     5802 
     5803                        } 
     5804                        elsif ( $quehace eq "unsetlink" ) { 
     5805                            log_debug( "$heading IF quehace = UNSETLINK", 256 ) if DEBUG; 
    56045806                            my @final = (); 
    56055807                            foreach my $msesion ( @{ $linkbot{"$server^$canal"} } ) { 
     
    56095811                            } 
    56105812                            $linkbot{"$server^$canal"} = [@final]; 
    5611                             log_debug( "$heading ENDIF quehace = UNSETLINK", 32 ) if DEBUG; 
    5612  
    5613                         } elsif ( $quehace eq "queueremoved" ) { 
     5813                            log_debug( "$heading ENDIF quehace = UNSETLINK", 256 ) if DEBUG; 
     5814 
     5815                        } 
     5816                        elsif ( $quehace eq "queueremoved" ) { 
    56145817 
    56155818                            delete $botonvoicemail{$interno}; 
     
    56275830                        } 
    56285831 
    5629            # Continue after cleaning internal state... 
     5832                        # Continue after cleaning internal state... 
    56305833                        if ( $interno eq "" ) { 
    5631                             log_debug( "$heading MISSING buttons($server^$canal), skipping...", 32 ) if DEBUG; 
     5834                            log_debug( "$heading MISSING buttons($server^$canal), skipping...", 256 ) if DEBUG; 
    56325835                            next; 
    56335836                        } 
    56345837                        else { 
    5635                             log_debug( "$heading INTERNO = $interno", 32 ) if DEBUG; 
     5838                            log_debug( "$heading INTERNO = $interno", 256 ) if DEBUG; 
    56365839                        } 
    56375840 
     
    56565859                        # 
    56575860                        if ( $canalid eq "" || $canalid =~ /zombie/i || $canalid =~ /(.*)-XXXX$/ ) { 
    5658                             log_debug( "$heading ATENTION canalid = '$canalid', skipping...", 32 ) if DEBUG; 
     5861                            log_debug( "$heading ATENTION canalid = '$canalid', skipping...", 256 ) if DEBUG; 
     5862                            if ( $quehace eq "registrado" || $quehace eq "noregistrado" || $quehace eq "unreachable" ) { 
     5863                                if ( defined( $botonregistrado{$interno} ) ) { 
     5864                                    if ( $botonregistrado{$interno} eq "$quehace|$dos" ) { 
     5865                                        $cambiaron{$interno} = 0; 
     5866                                    } 
     5867                                } 
     5868                                else { 
     5869                                    $botonregistrado{$interno} = "$quehace|$dos"; 
     5870                                    $cambiaron{$interno}       = 1; 
     5871                                } 
     5872                            } 
    56595873                        } 
    56605874                        else { 
     
    56625876                            if ( $quehace eq "corto" ) { 
    56635877 
    5664                                 log_debug( "$heading CORTO interno $interno canal $canal", 32 ) if DEBUG; 
     5878                                log_debug( "$heading CORTO interno $interno canal $canal", 256 ) if DEBUG; 
     5879                                $dos = $canalid; 
    56655880 
    56665881                                delete $botonpark{$interno}; 
     
    56895904                                if ( $cuantos == 0 ) { 
    56905905                                    log_debug( "$heading CORTO y SE DESOCUPO estadoboton($interno) = free, sesbot($interno) esta vacio", 
    5691                                         32
     5906                                        256
    56925907                                      if DEBUG; 
    56935908                                    $cambiaron{$interno}   = 1; 
     
    56965911                                else { 
    56975912                                    log_debug( "$heading CORTO y SIGUE OCUPADO estadoboton($interno) = busy, sesbot($interno) tiene algo", 
    5698                                         32
     5913                                        256
    56995914                                      if DEBUG; 
    57005915                                    &print_sesbot(3); 
     
    57095924 
    57105925                                        log_debug( 
    5711                                             "$heading Y es distinto al ultimo estado $laststatus{$interno} ne $estadoboton{$interno}", 32
     5926                                            "$heading Y es distinto al ultimo estado $laststatus{$interno} ne $estadoboton{$interno}", 256
    57125927                                          if DEBUG; 
    57135928                                    } 
     
    57305945 
    57315946                                # quehace no es "corto" 
    5732                                 # 
    57335947 
    57345948                                # MAINTAINS SESBOT HASH 
     
    57435957                                    push @{ $sesbot{$interno} }, "$canalid"; 
    57445958 
    5745                                     log_debug( "$heading AGREGO a sesbot($interno) el valor $canalid", 32 ) if DEBUG; 
     5959                                    log_debug( "$heading AGREGO a sesbot($interno) el valor $canalid", 256 ) if DEBUG; 
    57465960 
    57475961                                    my @uniq = unique( @{ $sesbot{$interno} } ); 
     
    57495963 
    57505964                                    foreach my $vavi ( @{ $sesbot{$interno} } ) { 
    5751                                         log_debug( "$heading sesbot($interno) tiene $vavi", 32 ) if DEBUG; 
    5752                                         log_debug( "$heading --------------------",         32 ) if DEBUG; 
     5965                                        log_debug( "$heading sesbot($interno) tiene $vavi", 256 ) if DEBUG; 
     5966                                        log_debug( "$heading --------------------",         256 ) if DEBUG; 
    57535967                                    } 
    57545968                                } 
    57555969 
    57565970                                if ( $canal =~ /^_/ && $quehace =~ /^ring/ ) { 
    5757                                     log_debug( "$heading TENGO UN WILDCARD ORIGINANDO LLAMADO! $canal $quehace $canalid", 32
     5971                                    log_debug( "$heading have a regexp originating a call $canal $quehace $canalid, rename label", 256
    57585972                                      if DEBUG; 
    5759                                     if ( $quehace eq "ring" ) { 
    5760  
    5761                                         # $quehace = "ocupado1"; 
    5762                                     } 
     5973 
    57635974                                    if ( $ren_wildcard == 1 ) { 
    57645975                                        push @respuestas, "$interno|changelabel0|$canalid"; 
     
    57665977                                    } 
    57675978                                } 
    5768  
    57695979                                if ( $quehace eq "ringing" ) { 
    57705980                                    if ( $laststatus{$interno} ne "ringing|${buttontext}" ) { 
     
    57885998 
    57895999                                } 
    5790                                 elsif ( $quehace =~ /^ocupado/ ) { 
     6000                                elsif ( $quehace =~ /^ocupado/ || $quehace eq 'ring' ) { 
    57916001 
    57926002                                    if ( defined( $group_count{$interno} ) ) { 
    5793                                         my $plural = ""; 
    57946003                                        if ( $group_count{$interno} == 1 ) { 
    5795                                             if ( @{ $sesbot{$interno} } > 1 ) { 
    5796                                                 $plural = "s"; 
    5797                                             } 
    5798                                             if ( @{ $sesbot{$interno} } > 0 ) { 
    5799                                                 my $cuantos = @{ $sesbot{$interno} }; 
    5800                                                 my ( $text, $textriginal, $buttontext ) = 
    5801                                                   translate( $canal, "&channels,$cuantos,$plural", "", "" ); 
    5802                                                 $buttontext = $text; 
    5803                                                 $dos        = "[" . $buttontext . "]"; 
    5804                                             } 
     6004                                            $buttontext = group_count( $interno, $canal ); 
     6005                                            push @respuestas, $buttontext; 
    58056006                                        } 
    58066007                                    } 
     
    58096010                                    } 
    58106011                                    $estadoboton{$interno} = "busy|${buttontext}"; 
    5811  
    58126012                                } 
    58136013                            } 
    58146014                        } 
    58156015 
    5816                         log_debug( "$heading Continuo proceso...", 32 ) if DEBUG; 
    5817              
     6016                        log_debug( "$heading Continuo proceso...", 256 ) if DEBUG; 
     6017 
    58186018                        if ( $quehace =~ /changelabel/ ) { 
    5819                             log_debug( "$heading quehace = changelabel", 32 ) if DEBUG; 
     6019                            log_debug( "$heading quehace = changelabel", 256 ) if DEBUG; 
    58206020 
    58216021                            # Mantains state of label and led 
     
    58566056                            } 
    58576057 
    5858                         } elsif ( $quehace eq "park" ) { 
    5859  
    5860                             log_debug( "$heading quehace = park", 32 ) if DEBUG; 
     6058                        } 
     6059                        elsif ( $quehace eq "park" ) { 
     6060 
     6061                            log_debug( "$heading quehace = park", 256 ) if DEBUG; 
    58616062                            $dos =~ m/(.*)\((.*)\)/; 
    58626063                            my $texto   = $1; 
     
    58646065                            $timeout = time() + $timeout; 
    58656066                            $botonpark{$interno} = "$texto|$timeout"; 
    5866                         } elsif ( $quehace eq "meetmeuser" ) { 
     6067                        } 
     6068                        elsif ( $quehace eq "meetmeuser" ) { 
    58676069                            $botonmeetme{$interno} = $dos; 
    5868                         } elsif ( $quehace eq "infoqstat" ) { 
     6070                        } 
     6071                        elsif ( $quehace eq "infoqstat" ) { 
    58696072                            $botonqueue{$interno} = $dos; 
    5870                         } elsif ( $quehace eq "infoqstat2" ) { 
     6073                        } 
     6074                        elsif ( $quehace eq "infoqstat2" ) { 
    58716075                            $botonqueue_count{$interno} = $dos; 
    5872                         } elsif ( $quehace =~ /info/ ) { 
     6076                        } 
     6077                        elsif ( $quehace =~ /info/ ) { 
    58736078                            my $mcola = $quehace; 
    58746079                            $mcola =~ s/^info//g; 
     
    58916096                            } 
    58926097 
    5893                         } elsif ( $quehace eq "setclid" ) { 
     6098                        } 
     6099                        elsif ( $quehace eq "setclid" ) { 
    58946100                            if ( !defined( $group_count{$interno} ) ) { 
    58956101                                push @respuestas, "$interno|settext|$dos"; 
    58966102                            } 
    5897                         } elsif ( $quehace eq "settext" ) { 
     6103                            if ( $estadoboton{$interno} eq "" ) { 
     6104                                push @respuestas, "$interno|state|busy"; 
     6105                                $estadoboton{$interno} = "busy"; 
     6106                            } 
     6107                        } 
     6108                        elsif ( $quehace eq "settext" ) { 
    58986109                            if ( !defined( $group_count{$interno} ) ) { 
    58996110                                $botonpermanenttext{$interno} = $dos; 
    5900 #                                print "vino settext a digest permanent $interno = -$dos-\n"; 
    59016111                                push @respuestas, "$interno|settext|$dos"; 
    59026112                            } 
    5903                         } elsif ( $quehace eq "fopledcolor" ) { 
     6113                        } 
     6114                        elsif ( $quehace eq "settextnopermanente" ) { 
     6115                            if ( !defined( $group_count{$interno} ) ) { 
     6116                                push @respuestas, "$interno|settext|$dos"; 
     6117                            } 
     6118                        } 
     6119                        elsif ( $quehace eq "fopledcolor" ) { 
    59046120                            $botonledcolor{$interno} = $dos; 
    5905                         } elsif ( $quehace eq "setalpha" ) { 
     6121                        } 
     6122                        elsif ( $quehace eq "setalpha" ) { 
    59066123                            $botonalpha{$interno} = $dos; 
    59076124                            push @respuestas, "$interno|setalpha|$dos"; 
    5908                         } elsif ( $quehace eq "flip" ) { 
     6125                        } 
     6126                        elsif ( $quehace eq "flip" ) { 
    59096127                            push @respuestas, "$interno|flip|$dos"; 
    5910                         } elsif ( $quehace eq "setlabel" ) { 
     6128                        } 
     6129                        elsif ( $quehace eq "setlabel" ) { 
    59116130                            if (   $dos ne "." 
    59126131                                && $dos ne "original" 
     
    59166135                                push @respuestas, "$interno|setlabel|$dos"; 
    59176136                            } 
    5918                         } elsif ( $quehace eq "voicemail" ) { 
     6137                        } 
     6138                        elsif ( $quehace eq "voicemail" ) { 
    59196139                            $botonvoicemail{$interno} = $dos; 
    5920                         } elsif ( $quehace eq "voicemailcount" ) { 
     6140                        } 
     6141                        elsif ( $quehace eq "voicemailcount" ) { 
    59216142                            $botonvoicemailcount{$interno} = $dos; 
    5922                         } elsif ( $quehace =~ "^voicemail" ) { 
     6143                        } 
     6144                        elsif ( $quehace =~ "^voicemail" ) { 
    59236145 
    59246146                            # This block is for the voicemail client 
     
    59266148                            $canalsincontexto =~ s/(.*)&(.*)/$1/g; 
    59276149                            push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|$dos"; 
    5928                         } elsif ( $quehace =~ "^ringing" ) { 
     6150                        } 
     6151                        elsif ( $quehace =~ "^ringing" ) { 
    59296152 
    59306153                            # This block is for the voicemail client, popups 
     
    59366159                            $calleridpop =~ s/\s+//g; 
    59376160                            push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|$calleridpop"; 
     6161                            if ( defined( $group_count{$interno} ) && $group_count{$interno} == 1 ) { 
     6162 
     6163                                # Ignore ringing because of groupcount 
     6164                                $quehace = ""; 
     6165                            } 
    59386166                        } 
    59396167 
     
    59466174                            && ( $quehace !~ /link/ ) ) 
    59476175                        { 
    5948                             $cambiaron{$interno} = 1; 
    5949                             log_debug( "$heading es distinto de corto,ocupado,link pongo cambiaron=1", 32 ) if DEBUG; 
     6176                            if ( !defined( $cambiaron{$interno} ) ) { 
     6177                                $cambiaron{$interno} = 1; 
     6178                                log_debug( "$heading es distinto de corto,ocupado,link pongo cambiaron=1", 256 ) 
     6179                                  if DEBUG; 
     6180                            } 
    59506181                        } 
    59516182 
     
    59566187 
    59576188                        if ( @{ $sesbot{$interno} } > 0 && $quehace eq 'corto' ) { 
    5958                             log_debug( "$heading Still busy...sesbot($interno) is not empty, ignoring hangup", 32
     6189                            log_debug( "$heading Still busy...sesbot($interno) is not empty, ignore hangup", 256
    59596190                              if DEBUG; 
     6191                            if ( defined( $group_count{$interno} ) ) { 
     6192                                if ( $group_count{$interno} == 1 ) { 
     6193                                    $buttontext = group_count( $interno, $canal ); 
     6194                                    push @respuestas, $buttontext; 
     6195                                } 
     6196                            } 
    59606197                        } 
    59616198                        else { 
     
    59646201                                my $canalsincontexto = $canal; 
    59656202                                $canalsincontexto =~ s/(.*)&(.*)/$1/g; 
    5966                                 push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|corto!"; 
     6203                                push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|$canalid"; 
     6204                                if ( defined( $group_count{$interno} ) ) { 
     6205                                    if ( $group_count{$interno} == 1 ) { 
     6206                                        $buttontext = group_count( $interno, $canal ); 
     6207                                        push @respuestas, $buttontext; 
     6208                                    } 
     6209                                } 
    59676210                            } 
    59686211 
    59696212                            my $quehace2 = $quehace; 
    5970  
    5971                             if ( $quehace2 eq "ring" ) { 
    5972  
    5973                                 #$quehace2 = "ocupado"; 
    5974                             } 
    59756213 
    59766214                            next unless ( $quehace2 ne "setlink" ); 
    59776215                            next unless ( $quehace2 ne "unsetlink" ); 
    59786216 
    5979                             log_debug( "$heading sigo quehace quehace2", 32 ) if DEBUG; 
     6217                            log_debug( "$heading sigo quehace quehace2", 256 ) if DEBUG; 
    59806218 
    59816219                            if ( $quehace2 eq "isagent" && $dos == -1 ) { 
    5982                                 log_debug( "$heading quehace2 = isagent", 32 ) if DEBUG; 
     6220                                log_debug( "$heading quehace2 = isagent", 256 ) if DEBUG; 
    59836221                                push @mensajefinal, "$interno|changelabel1|original"; 
    59846222                                push @mensajefinal, "$interno|settimer|0\@STOP"; 
    59856223                                push @mensajefinal, "$interno|settext|"; 
    5986                                 push @mensajefinal, "$interno|corto|"; 
     6224                                push @mensajefinal, "$interno|corto|$canalid"; 
    59876225                            } 
    59886226 
     
    59906228 
    59916229                                # clear the agent helper hashes. We do it here because we first need to map 
    5992                                 log_debug( "$heading quehace2 = agentlogoff", 32 ) if DEBUG; 
     6230                                log_debug( "$heading quehace2 = agentlogoff", 256 ) if DEBUG; 
    59936231                                my $canalag = $canalid; 
    59946232                                $canalag = substr( $canalag, 0, -5 ); 
     
    60016239                                    if ( $val eq $canalag ) { 
    60026240                                        delete $channel_to_agent{$key}; 
    6003                                         log_debug( "$heading borro channel_to_agent($key)", 64 ) if DEBUG; 
     6241                                        log_debug( "$heading borro channel_to_agent($key)", 256 ) if DEBUG; 
    60046242                                    } 
    60056243                                } 
     
    60086246                                if ( defined( $agent_to_channel{"$server^$canalag"} ) ) { 
    60096247                                    delete $agent_to_channel{"$server^$canalag"}; 
    6010                                     log_debug( "$heading borro agent_to_channel($server^$canalag)", 64 ) if DEBUG; 
     6248                                    log_debug( "$heading borro agent_to_channel($server^$canalag)", 256 ) if DEBUG; 
    60116249                                } 
    60126250 
     
    60236261 
    60246262                            if ( $quehace2 !~ /isagent/ && $quehace2 !~ /^agentlogoff/ && $quehace2 !~ /^setclid/ ) { 
    6025                                 log_debug( "$heading pushing respuestas $interno|$quehace2|$dos", 32 ) if DEBUG; 
    6026  
    6027                                 # Discard events that we dont want to send 
    6028                                 # to flash clients 
    6029                                 # "isagent". "agentlogoff" 
    6030                                 # everything else is pushed 
    6031                                 if ( defined( $group_count{$interno} ) && $quehace2 eq "setclid" ) { 
    6032                                     log_debug( "$heading skip settext because groupcount is set", 32 ) if DEBUG; 
    6033                                 } 
    6034                                 else { 
    6035                                     if ( $quehace2 ne "" ) { 
    6036                                         push @respuestas, "$interno|$quehace2|$dos"; 
    6037 #             print "push $quehace2 en $interno quehace2\n"; 
     6263 
     6264                                if ( defined( $cambiaron{$interno} ) && $cambiaron{$interno} == 1 ) { 
     6265 
     6266                                    # Discard events that we dont want to send 
     6267                                    # to flash clients 
     6268                                    # "isagent". "agentlogoff" 
     6269                                    # everything else is pushed 
     6270                                    if ( defined( $group_count{$interno} ) && $quehace2 eq "setclid" ) { 
     6271                                        log_debug( "$heading skip settext because groupcount is set", 256 ) if DEBUG; 
     6272                                    } 
     6273                                    else { 
     6274                                        if ( $quehace2 ne "" ) { 
     6275                                            if ( defined( $group_count{$interno} ) && $group_count{$interno} == 1 ) { 
     6276 
     6277                                                # $dos = ""; 
     6278                                            } 
     6279                                            else { 
     6280                                                push @respuestas, "$interno|$quehace2|$dos"; 
     6281                                                log_debug( "$heading pushing respuestas $interno|$quehace2|$dos", 256 ) 
     6282                                                  if DEBUG; 
     6283                                            } 
     6284                                        } 
    60386285                                    } 
    60396286                                } 
     
    60416288 
    60426289                            if ( $quehace2 =~ /ocupado/ ) { 
    6043                                 if ( $dos =~ m/(.*)?\[(.*)\].*?/ ) { 
    6044                                     my $clidtext = $2; 
    6045                                     $botonclid{$interno} = $clidtext; 
     6290                                if ( defined( $group_count{$interno} ) && $group_count{$interno} == 1 ) { 
     6291                                    $cambiaron{$interno} = 0; 
     6292                                    $quehace2 = ""; 
     6293                                    next; 
    60466294                                } 
    6047  
    6048                                 #push @mensajefinal, "$interno|state|busy"; 
    6049                                 push @mensajefinal, "$interno|settimer|0\@UP"; 
     6295                                else { 
     6296                                    if ( $dos =~ m/(.*)?\[(.*)\].*?/ ) { 
     6297                                        my $clidtext = $2; 
     6298                                        $botonclid{$interno} = $clidtext; 
     6299                                    } 
     6300 
     6301                                    #push @mensajefinal, "$interno|state|busy"; 
     6302                                    push @mensajefinal, "$interno|settimer|0\@UP"; 
     6303                                } 
    60506304                            } 
    60516305                            if ( $quehace2 eq "settimer" ) { 
    6052                                 my $tiempo = $dos; 
    6053                                 my $nada   = ""; 
     6306                                if ( !defined($dos) ) { $dos = 1; } 
     6307                                my $tiempo     = $dos; 
     6308                                my $timer_type = ""; 
    60546309                                if ( $tiempo =~ /\@/ ) { 
    6055                                     ( $tiempo, $nada ) = split( /\@/, $tiempo ); 
     6310                                    ( $tiempo, $timer_type ) = split( /\@/, $tiempo ); 
    60566311                                } 
    6057                                 if ( $nada ne "" ) { 
    6058                                     $botontimertype{$interno} = $nada; 
    6059                                     $nada = "\@" . $nada; 
     6312 
     6313                                if ( $tiempo eq "" ) { $tiempo = 0; } 
     6314 
     6315                                if ( $timer_type ne "" ) { 
     6316                                    $botontimertype{$interno} = $timer_type; 
     6317                                    $timer_type = "\@" . $timer_type; 
    60606318                                } 
    60616319                                $botontimer{$interno} = time() - $tiempo; 
    6062                                 push @mensajefinal, "$interno|settimer|$tiempo$nada"; 
     6320                                push @mensajefinal, "$interno|settimer|$tiempo$timer_type"; 
    60636321                            } 
    60646322 
     
    60776335                            } 
    60786336                            if ( $quehace2 =~ /corto/ ) { 
    6079                                 log_debug( "$heading quehace2 corto", 32 ) if DEBUG; 
     6337                                log_debug( "$heading quehace2 corto", 256 ) if DEBUG; 
    60806338 
    60816339                                my $canalsincontexto = $canal; 
     
    61016359                                        $iniagent = $channel_to_agent{"$server^$canalsincontexto"}; 
    61026360                                    } 
    6103                                     log_debug( "$heading quehace2 corto y es agente, pushing settimer y settext to idle", 1 ) if DEBUG; 
     6361                                    log_debug( "$heading quehace2 corto y es agente, pushing settimer y settext to idle", 256 ) 
     6362                                      if DEBUG; 
    61046363                                    $botontimer{$interno}     = time(); 
    61056364                                    $botontimertype{$interno} = "IDLE"; 
     
    61146373                                else { 
    61156374                                    my $valip = ""; 
    6116                                     log_debug( "$heading quehace2 corto, no es agente, pongo timer en cero", 1 ) if DEBUG; 
     6375                                    log_debug( "$heading quehace2 corto, no es agente, pongo timer en cero", 256 ) 
     6376                                      if DEBUG; 
    61176377 
    61186378                                    push @mensajefinal, "$interno|settimer|0\@STOP"; 
     
    61256385                                        if ( defined( $botonpermanenttext{$interno} ) ) { 
    61266386                                            push @mensajefinal, "$interno|settext|$botonpermanenttext{$interno}"; 
    6127 #                                            print "corto! permanent $interno = -$dos-\n"; 
    6128  
    6129                                             #$botonpermanenttext{$interno} = $dos; 
     6387                                            log_debug( "interno $interno tenia permanente $botonpermanenttext{$interno}", 128 ) 
     6388                                              if DEBUG; 
    61306389                                        } 
    61316390                                        $botonclid{$interno} = ""; 
     
    61416400                            } 
    61426401 
    6143                             if ( $quehace eq "registrado" ) { 
    6144                                 if ( defined( $botonalpha{$interno} ) ) { 
    6145                                     if ( $botonalpha{$interno} ne "" ) { 
    6146                                         push @mensajefinal, "$interno|setalpha|50"; 
     6402                            if ( $quehace eq "registrado" || $quehace eq "noregistrado" || $quehace eq "unreachable" ) { 
     6403                                if ( $botonregistrado{$interno} ne "$quehace|$dos" ) { 
     6404 
     6405                                    # changed registration state, do something 
     6406                                    if ( $quehace eq "registrado" ) { 
     6407                                        if ( defined( $botonalpha{$interno} ) ) { 
     6408                                            if ( $botonalpha{$interno} ne "" ) { 
     6409                                                push @mensajefinal, "$interno|setalpha|50"; 
     6410                                            } 
     6411                                            else { 
     6412                                                push @mensajefinal, "$interno|setalpha|100"; 
     6413                                            } 
     6414                                        } 
    61476415                                    } 
    6148                                     else { 
    6149                                         push @mensajefinal, "$interno|setalpha|100"; 
    6150                                     } 
     6416                                    $botonregistrado{$interno} = "$quehace|$dos"; 
    61516417                                } 
    6152                             } 
    6153  
    6154                             if ( $quehace eq "registrado" || $quehace eq "noregistrado" || $quehace eq "unreachable" ) { 
    6155                                 $botonregistrado{$interno} = "$quehace|$dos"; 
    61566418                            } 
    61576419 
     
    61596421                                $boton_paused{$interno} = $dos; 
    61606422                            } 
    6161                             if ( $quehace eq "agents_paused" ) { 
     6423                            elsif ( $quehace eq "agents_paused" ) { 
    61626424                                $boton_agentpaused{$interno} = $dos; 
    61636425                            } 
    6164                             if ( $quehace eq "agents_ready" ) { 
     6426                            elsif ( $quehace eq "agents_ready" ) { 
    61656427                                $boton_agentready{$interno} = $dos; 
    61666428                            } 
    6167                             if ( $quehace eq "agents_busy" ) { 
     6429                            elsif ( $quehace eq "agents_busy" ) { 
    61686430                                $boton_agentbusy{$interno} = $dos; 
    61696431                            } 
    6170                             if ( $quehace eq "agents_logedof" ) { 
     6432                            elsif ( $quehace eq "agents_logedof" ) { 
    61716433                                $boton_agentlogedof{$interno} = $dos; 
    61726434                            } 
    61736435 
    6174                             log_debug( "$heading Agrego mensaje final $interno|$quehace2|$dos", 32 ) if DEBUG; 
     6436                            log_debug( "$heading Agrego mensaje final $interno|$quehace2|$dos", 256 ) if DEBUG; 
    61756437 
    61766438                            #if (defined($mensajefinal) && $interno ne "") 
     
    61796441                                if ( exists $cambiaron{$interno} ) { 
    61806442 
    6181                                     log_debug( "$heading Existe cambiaron($interno) = $cambiaron{$interno}", 32
     6443                                    log_debug( "$heading Existe cambiaron($interno) = $cambiaron{$interno}", 256
    61826444                                      if DEBUG; 
    61836445 
    6184                                     #push(@respuestas, $mensajefinal); 
    6185                                     foreach (@mensajefinal) { 
    6186                                         push @respuestas, $_; 
     6446                                    if ( $cambiaron{$interno} == 1 ) { 
     6447                                        foreach (@mensajefinal) { 
     6448                                            log_debug( "$heading pushing respuestas $_ because cambiaron($interno)=1", 256 ) 
     6449                                              if DEBUG; 
     6450                                            push @respuestas, $_; 
     6451                                        } 
    61876452                                    } 
    61886453                                } 
    61896454                                else { 
    6190  
    6191                                     log_debug( "$heading No existe cambiaron($interno)", 32 ) if DEBUG; 
    6192                                     foreach (@mensajefinal) { 
    6193  
    6194                                         # If the last status was not modified, avoid sending info 
    6195                                         # push @respuestas, $_; 
    6196                                     } 
     6455                                    log_debug( "$heading No existe cambiaron($interno)", 256 ) if DEBUG; 
    61976456                                } 
    61986457                                if ( $toda ne "" ) { 
     
    62136472    @respuestas = unique(@respuestas); 
    62146473    $cuantas    = $#respuestas + 1; 
    6215     log_debug( "$heading end, return $cuantas", 16 ) if DEBUG; 
     6474    log_debug( "$heading end, return $cuantas", 256 ) if DEBUG; 
    62166475    foreach my $valor (@respuestas) { 
    6217         log_debug( "$heading END SUB: returns $valor", 32 ) if DEBUG; 
     6476        log_debug( "$heading END SUB: returns $valor", 256 ) if DEBUG; 
    62186477    } 
    62196478    $tab = substr( $tab, 0, -1 ) if DEBUG; 
    62206479    return @respuestas; 
     6480} 
     6481 
     6482sub group_count { 
     6483    my $interno = shift; 
     6484    my $canal   = shift; 
     6485    my $plural  = ""; 
     6486    my $return  = ""; 
     6487    if ( @{ $sesbot{$interno} } > 1 ) { 
     6488        $plural = "s"; 
     6489    } 
     6490    if ( @{ $sesbot{$interno} } > 0 ) { 
     6491        my $cuantos = @{ $sesbot{$interno} }; 
     6492        my ( $text, $textriginal, $buttontext ) = translate( $canal, "&channels,$cuantos,$plural", "", "" ); 
     6493        $return = "$interno|settext|$text"; 
     6494        $botonpermanenttext{$interno} = $text; 
     6495    } 
     6496    else { 
     6497        $botonpermanenttext{$interno} = ""; 
     6498        $return = "$interno|corto|"; 
     6499    } 
     6500    return $return; 
    62216501} 
    62226502 
     
    62746554} 
    62756555 
    6276 sub nonblock { 
    6277     my $socket = shift; 
    6278     my $flags; 
    6279  
    6280     $flags = fcntl( $socket, F_GETFL, 0 ) 
    6281       or die "Can't get flags for socket: $!\n"; 
    6282     fcntl( $socket, F_SETFL, $flags | O_NONBLOCK ) 
    6283       or die "Can't make socket nonblocking: $!\n"; 
    6284 } 
    6285  
    62866556sub clean_inmemory_state_for_server { 
    62876557 
     
    64246694 
    64256695        # The closed connections belong to an asterisk manager port 
    6426         my @partes  = split( /\|/, $manager_socket{$socket} ); 
    64276696        my @pp      = (); 
    64286697        my $counter = 0; 
     
    64616730collect_includes( "op_buttons.cfg", "buttons" ); 
    64626731collect_includes( "op_style.cfg",   "style" ); 
     6732collect_includes( "op_server.cfg",  "server" ); 
    64636733read_buttons_config(); 
    64646734read_server_config(); 
     
    64686738 
    64696739# Tries to open the listening socket 
    6470 $m = new IO::Socket::INET( Listen => 1, LocalAddr => $listen_addr, LocalPort => $listen_port, ReuseAddr => 1, Blocking => 0 ) 
     6740$m = new IO::Socket::INET( 
     6741    Listen    => 1, 
     6742    LocalAddr => $listen_addr, 
     6743    LocalPort => $listen_port, 
     6744    ReuseAddr => 1, 
     6745    Blocking  => 0 
     6746  ) 
    64716747  or die "\nCan't listen to port $listen_port\n"; 
    64726748$O = new IO::Select(); 
     
    65066782                push( @flash_clients, $C ); 
    65076783                $O->add($C); 
    6508                 nonblock($C); 
     6784                $C->blocking(0); 
    65096785            } 
    65106786            else { 
     
    66246900                                        || $bloque_final =~ /Message: Mailbox/ 
    66256901                                        || $bloque_final =~ /SIP-CanReinvite/ 
     6902                                        || $bloque_final =~ /ActionID: monitor-/ 
    66266903                                        || $bloque_final =~ /Message: Timeout/ ) 
    66276904                                    { 
     
    66346911                                                $block_count++; 
    66356912                                                $bloque[$block_count]{Event} = "sippeerentrylong"; 
     6913                                            } 
     6914                                            elsif ( $p =~ /ActionID: monitor-/ ) { 
     6915                                                my ( undef, $quemonitor, $quecana ) = split( /-/, $p, 3 ); 
     6916                                                $block_count++; 
     6917                                                $bloque[$block_count]{Event}   = "response-$quemonitor"; 
     6918                                                $bloque[$block_count]{Channel} = $quecana; 
    66366919                                            } 
    66376920                                            my $my_event = ""; 
     
    67187001                                        send_initial_status($C); 
    67197002                                    } 
     7003                                    elsif ( $bloque_final =~ /<policy-file-request\/>/ ) { 
     7004                                        send_policy_to_flash($C); 
     7005                                    } 
    67207006                                    else { 
    6721                                         log_debug( "$heading No 'Event' nor 'End'. Erasing block...", 32 ) if DEBUG; 
     7007                                        log_debug( "$heading No 'Event' nor 'End'. Erasing block...", 32 )  if DEBUG; 
     7008                                        log_debug( "$bloque_final",                                   255 ) if DEBUG; 
    67227009 
    67237010                                        # No Event in the block. Lets clear it up... 
     
    67887075    my $res   = syswrite( $socket, $encriptadofinal, $largo ); 
    67897076 
     7077    # select( undef, undef, undef, 0.01 ); 
     7078 
    67907079    if ( defined $res && $res > 0 ) { 
    67917080        if ( $res != $largo ) { 
     
    68697158        @cuales_transferir = extraer_todos_los_enlaces_de_un_canal( $origin_channel, $button_server{$datosflash} ); 
    68707159        if ( @cuales_transferir == 0 ) { 
    6871             log_debug( "** !! REVERSE TRANSFER No reverse available, using regular sesbot to find the linked channels", 16 ) if DEBUG; 
     7160            log_debug( "** !! REVERSE TRANSFER No reverse available, using regular sesbot to find the linked channels", 16 ) 
     7161              if DEBUG; 
    68727162            if ( $sesbot{$datosflash} ) { 
    68737163                if ( @{ $sesbot{$datosflash} } ) { 
     
    69577247    $elementname =~ s/\d//g; 
    69587248 
    6959     if ( $datosflash =~ /_level0\.casilla/ ) { 
    6960         $datosflash =~ s/_level0\.casilla(\d+)/$1/g; 
    6961     } 
    6962     if ( $datosflash =~ /_level0\.rectangulo/ ) { 
    6963         $datosflash =~ s/_level0\.rectangulo(\d+).*/$1/g; 
    6964     } 
     7249    $datosflash =~ s/_level0\.casilla(\d+)/$1/g; 
     7250    $datosflash =~ s/_level0\.rectangulo(\d+).*/$1/g; 
    69657251 
    69667252    log_debug( "$heading datosflash before context $datosflash", 128 ) if DEBUG; 
     
    69927278    if ( $accion =~ /^contexto\d+/ ) { 
    69937279 
    6994         my ( $nada, $contextoenviado ) = split( /\@/, $datosflash ); 
     7280        my ( undef, $contextoenviado ) = split( /\@/, $datosflash ); 
    69957281 
    69967282        if ( defined($contextoenviado) ) { 
     
    70767362                @pedazos = split( /&/, $canal ); 
    70777363                $origin_context = $pedazos[1]; 
    7078                 my @pedazos2 = split( /\^/, $pedazos[0] ); 
    7079                 $origin_server  = $pedazos2[0]; 
    7080                 $origin_channel = $pedazos2[1]; 
     7364                ( $origin_server, $origin_channel ) = split( /\^/, $pedazos[0] ); 
    70817365            } 
    70827366            else { 
    7083                 my @pedazos2 = split( /\^/, $canal ); 
    7084                 $origin_server  = $pedazos2[0]; 
    7085                 $origin_channel = $pedazos2[1]; 
     7367                ( $origin_server, $origin_channel ) = split( /\^/, $canal ); 
    70867368            } 
    70877369        } 
     
    71407422        if ( defined( $buttons{$indice} ) ) { 
    71417423            $btn_num = $buttons{$indice}; 
    7142             $btn_num =~ s/(.*)\@(.*)/$1/g; 
     7424 
     7425            # $btn_num =~ s/(.*)\@(.*)/$1/g; 
    71437426        } 
    71447427        if ( $btn_num ne "0" ) { 
     
    72447527                if ( $destino ne "0" ) { 
    72457528                    log_debug( "$heading destino es igual a $destino", 32 ) if DEBUG; 
    7246                     my @pedazos2 = split( /\^/, $destino ); 
    7247                     $destin_server = $pedazos2[0]; 
    7248                     $destino       = $pedazos2[1]; 
    7249                     ( $destino, my $nada ) = split( /\&/, $pedazos2[1] ); 
     7529                    ( $destin_server, $destino ) = split( /\^/, $destino ); 
     7530                    ($destino) = split( /\&/, $destino ); 
    72507531                    log_debug( "$heading El boton de destino es $destino en el server $destin_server", 64 ) if DEBUG; 
    72517532                } 
    72527533            } 
    72537534 
    7254             if ( $accion =~ /^tovoicemail/ ) { 
    7255  
     7535            if ( $accion =~ /^tospy/ ) { 
    72567536                my @cuales_transferir = get_transfer_channel( $origin_channel, $datosflash ); 
    72577537                my $cuantos           = @cuales_transferir; 
    72587538 
    7259                 if ( !defined( $tovoicemail{$btn_destino} ) ) { 
    7260  
    7261                     # If there is no voicemail extension defined, change it to a standard 
     7539                if ( !defined( $tospy{$btn_destino} ) ) { 
     7540 
     7541                    # If there is no spy extension defined, change it to a standard 
    72627542                    # trasnfer 
    72637543                    if ( $cuantos > 0 ) { 
     
    72697549                } 
    72707550                else { 
    7271  
    72727551                    my $keyext  = "$origin_server^$origin_channel"; 
    7273                     my $exttran = $tovoicemail{$btn_destino}; 
     7552                    my $exttran = $tospy{$btn_destino}; 
    72747553                    my ( $extx, $contextx ) = split( /\@/, $exttran, 2 ); 
    72757554 
     
    72907569                        $comando .= "Priority: 1\r\n\r\n"; 
    72917570                    } 
    7292                     send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7293                         0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7571                    if ( $button_server{$datosflash} == -1 ) { 
     7572                        send_command_to_managers($comando); 
     7573                    } 
     7574                    else { 
     7575                        send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7576                            0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7577                    } 
    72947578 
    72957579                    $tab = substr( $tab, 0, -1 ) if DEBUG; 
    72967580                    return; 
    7297                 } 
    7298             } 
    7299             if ( $accion =~ /^voicemail/ ) { 
    7300                 my $vext     = ""; 
    7301                 my $vcontext = ""; 
     7581 
     7582                } 
     7583 
     7584            } 
     7585            elsif ( $accion =~ /^tovoicemail/ ) { 
     7586 
     7587                my @cuales_transferir = get_transfer_channel( $origin_channel, $datosflash ); 
     7588                my $cuantos           = @cuales_transferir; 
     7589 
     7590                if ( !defined( $tovoicemail{$btn_destino} ) ) { 
     7591 
     7592                    # If there is no voicemail extension defined, change it to a standard 
     7593                    # trasnfer 
     7594                    if ( $cuantos > 0 ) { 
     7595                        $accion = "transferir"; 
     7596                    } 
     7597                    else { 
     7598                        $accion = "originate"; 
     7599                    } 
     7600                } 
     7601                else { 
     7602 
     7603                    my $keyext  = "$origin_server^$origin_channel"; 
     7604                    my $exttran = $tovoicemail{$btn_destino}; 
     7605                    my ( $extx, $contextx ) = split( /\@/, $exttran, 2 ); 
     7606 
     7607                    if ( $cuantos > 0 ) { 
     7608                        $comando = "Action: Redirect\r\n"; 
     7609                        $comando .= "Channel: $cuales_transferir[0]\r\n"; 
     7610                        $comando .= "Exten: $extx\r\n"; 
     7611                        $comando .= "ActionID: 1234\r\n"; 
     7612                        $comando .= "Context: $contextx\r\n"; 
     7613                        $comando .= "Priority: 1\r\n\r\n"; 
     7614                    } 
     7615                    else { 
     7616                        $comando = "Action: Originate\r\n"; 
     7617                        $comando .= "Channel: $origin_channel\r\n"; 
     7618                        $comando .= "Exten: $extx\r\n"; 
     7619                        $comando .= "ActionID: 1234\r\n"; 
     7620                        $comando .= "Context: $contextx\r\n"; 
     7621                        $comando .= "Priority: 1\r\n\r\n"; 
     7622                    } 
     7623                    if ( $button_server{$datosflash} == -1 ) { 
     7624                        send_command_to_managers($comando); 
     7625                    } 
     7626                    else { 
     7627                        send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7628                            0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7629                    } 
     7630 
     7631                    $tab = substr( $tab, 0, -1 ) if DEBUG; 
     7632                    return; 
     7633                } 
     7634            } 
     7635            elsif ( $accion =~ /^voicemail/ ) { 
     7636                my $vext       = ""; 
     7637                my $vmext      = ""; 
     7638                my $vcontext   = ""; 
     7639                my $orichannel = ""; 
    73027640 
    73037641                if ( defined( $config->{$panelcontext}{voicemail_extension} ) ) { 
    73047642                    my $voicemailext = $config->{$panelcontext}{voicemail_extension}; 
    7305                     ( $vext, $vcontext ) = split( /\@/, $voicemailext ); 
     7643                    ( $vmext, $orichannel ) = split( /\^/, $voicemailext ); 
     7644                    ( $vext,  $vcontext )   = split( /\@/, $vmext ); 
    73067645                } 
    73077646                else { 
     
    73097648                    $tab = substr( $tab, 0, -1 ) if DEBUG; 
    73107649                    return; 
     7650                } 
     7651 
     7652                if ( !defined($orichannel) ) { 
     7653                    $orichannel = $origin_channel; 
    73117654                } 
    73127655 
     
    73197662 
    73207663                $comando = "Action: Originate\r\n"; 
    7321                 $comando .= "Channel: $origin_channel\r\n"; 
     7664                $comando .= "Channel: $orichannel\r\n"; 
    73227665                $comando .= "Callerid: $vclid <$vclid>\r\n"; 
    73237666                $comando .= "Async: True\r\n"; 
     
    73297672                $comando .= "\r\n"; 
    73307673 
    7331                 send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7332                     0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7674                if ( $button_server{$datosflash} == -1 ) { 
     7675                    send_command_to_managers($comando); 
     7676                } 
     7677                else { 
     7678                    send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7679                        0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7680                } 
    73337681                $tab = substr( $tab, 0, -1 ) if DEBUG; 
    73347682                return; 
     
    73547702            } 
    73557703 
    7356             if ( $accion eq "cortar" ) { 
     7704            if ( $accion =~ /^startmonitor/ ) { 
     7705                my $buton_number = $datosflash; 
     7706                foreach my $ses ( @{ $sesbot{$buton_number} } ) { 
     7707                    my $monaction   = ""; 
     7708                    my $extracomand = ""; 
     7709                    if ( !defined( $monitoring{$ses} ) ) { 
     7710                        log_debug( "$heading START MONITOR $ses -- ($origin_server $origin_channel)", 1 ); 
     7711                        my $unique = find_uniqueid( $ses, $origin_server ); 
     7712                        my ( $filename, $format ) = compute_monitoring_filename( $unique, $panelcontext ); 
     7713                        $monaction = "Monitor"; 
     7714                        $monitoring{$ses} = 1; 
     7715                        $extracomand .= "File: $filename\r\n"; 
     7716                        $extracomand .= "Format: $format\r\n"; 
     7717                        $extracomand .= "Mix: 1\r\n"; 
     7718                    } 
     7719                    else { 
     7720                        log_debug( "$heading STOP MONITOR $ses", 1 ); 
     7721                        $monaction = "StopMonitor"; 
     7722                        delete $monitoring{$ses}; 
     7723                    } 
     7724                    $comando = "Action: $monaction\r\n"; 
     7725                    $comando .= "Channel: $ses\r\n"; 
     7726                    $comando .= "ActionID: monitor-$monaction-$ses\r\n"; 
     7727                    $comando .= $extracomand . "\r\n"; 
     7728                    if ( $button_server{$datosflash} == -1 ) { 
     7729                        send_command_to_managers($comando); 
     7730                    } 
     7731                    else { 
     7732                        send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7733                            0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7734                    } 
     7735                } 
     7736            } 
     7737            elsif ( $accion eq "cortar" ) { 
    73577738                my $buton_number = $datosflash; 
    73587739                log_debug( "$heading Will try to hangup channel para el boton $buton_number", 16 ) if DEBUG; 
     
    73637744                    $comando .= "Channel: $_\r\n\r\n"; 
    73647745                    log_debug( "-- Command received: $accion chan $_", 32 ) if DEBUG; 
    7365                     send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7366                         0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
    7367  
    7368                     # $comando = "Action: Command\r\n"; 
    7369                     # $comando .= "Command: soft hangup $_\r\n\r\n"; 
    7370                     # send_command_to_manager($comando, $p[$button_server{$datosflash}]); 
     7746 
     7747                    if ( $button_server{$datosflash} == -1 ) { 
     7748                        send_command_to_managers($comando); 
     7749                    } 
     7750                    else { 
     7751                        send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7752                            0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7753                    } 
    73717754                } 
    73727755            } 
     
    73817764                $comando .= "ActionID: meetmemute$boton_con_contexto\r\n"; 
    73827765                $comando .= "Command: meetme mute $conference $meetmemember\r\n\r\n"; 
    7383                 send_command_to_manager( $comando, $p[ $button_server{$boton_con_contexto} ], 
    7384                     0, $astmanproxy_servers[ $button_server{$boton_con_contexto} ] ); 
     7766 
     7767                if ( $button_server{$boton_con_contexto} == -1 ) { 
     7768                    send_command_to_managers($comando); 
     7769                } 
     7770                else { 
     7771                    send_command_to_manager( $comando, $p[ $button_server{$boton_con_contexto} ], 
     7772                        0, $astmanproxy_servers[ $button_server{$boton_con_contexto} ] ); 
     7773                } 
    73857774            } 
    73867775            elsif ( $accion =~ /^meetmeunmute/ ) { 
     
    73947783                $comando .= "ActionID: meetmeunmute$boton_con_contexto\r\n"; 
    73957784                $comando .= "Command: meetme unmute $conference $meetmemember\r\n\r\n"; 
    7396                 send_command_to_manager( $comando, $p[ $button_server{$boton_con_contexto} ], 
    7397                     0, $astmanproxy_servers[ $button_server{$boton_con_contexto} ] ); 
    7398             } 
    7399  
     7785 
     7786                if ( $button_server{$boton_con_contexto} == -1 ) { 
     7787                    send_command_to_managers($comando); 
     7788                } 
     7789                else { 
     7790                    send_command_to_manager( $comando, $p[ $button_server{$boton_con_contexto} ], 
     7791                        0, $astmanproxy_servers[ $button_server{$boton_con_contexto} ] ); 
     7792                } 
     7793            } 
     7794 
     7795            elsif ( $accion =~ /^atxfer/ ) { 
     7796                log_debug( "$heading ATXFER extension_transfer($origin_channel)", 1 ) if DEBUG; 
     7797                my $nro_boton_destino = $accion; 
     7798                $nro_boton_destino =~ s/^atxfer//g; 
     7799                my $contextoaagregar = ""; 
     7800                if ( $panelcontext ne "GENERAL" ) { 
     7801                    $contextoaagregar = "&$panelcontext"; 
     7802                } 
     7803                my $indice    = $origin_server . "^" . $origin_channel . $contextoaagregar; 
     7804                my $originate = $extension_transfer{$indice}; 
     7805                $originate =~ s/-?\d+\^(.*)/$1/; 
     7806                foreach ( keys(%buttons) ) { 
     7807                    log_debug( "$heading comparing $buttons{$_} with btn_destino $btn_destino", 1 ) if DEBUG; 
     7808                    if ( $buttons{$_} eq $btn_destino ) { 
     7809                        if ( $canal =~ /^_/ ) { 
     7810                            my @canalarray = @{ $sesbot{$btn_destino} }; 
     7811                            my $canalses   = $canalarray[0]; 
     7812                            my ( $newcanal, $newses ) = separate_session_from_channel($canalses); 
     7813                            $canal = $newcanal; 
     7814                        } 
     7815                        $canal =~ s/(.*)=(.*)/$1/g; 
     7816                        log_debug( "$heading match for $btn_destino the channel is $canal", 1 ) 
     7817                          if DEBUG; 
     7818                        my @links            = extraer_todos_los_enlaces_de_un_canal( $canal, $button_server{$datosflash} ); 
     7819                        my @canal_transferir = @{ $sesbot{$btn_destino} }; 
     7820 
     7821                        my $cuantos = @links; 
     7822                        if ( $cuantos <= 0 ) { 
     7823             
     7824                            $canal_destino = retrieve_extension($origin_server . "^" . $origin_channel); 
     7825                            if ( $canal_destino ne "-1" ) { 
     7826                                if ( $canal_destino =~ /\@/ ) { 
     7827                                    ( $canal_destino, $contexto ) = split( /\@/, $canal_destino ); 
     7828                                } 
     7829                            } 
     7830                            $comando = "Action: Originate\r\n"; 
     7831                            $comando .= "Channel: $destino\r\n"; 
     7832                            $comando .= "Exten: $canal_destino\r\n"; 
     7833                            $comando .= "Context: $contexto\r\n"; 
     7834                            $comando .= "Priority: 1\r\n\r\n"; 
     7835                        } 
     7836                        else { 
     7837 
     7838                            log_debug( "** $canal_transferir[0] $links[0] will be transferred to $origin_channel ($originate)", 1 ) 
     7839                              if DEBUG; 
     7840 
     7841                            my ( $vmext, $vmctx ) = split( /@/, $originate ); 
     7842                            $comando = "Action: Atxfer\r\n"; 
     7843                            $comando .= "Channel: " . $canal_transferir[0] . "\r\n"; 
     7844                            $comando .= "Exten: $vmext\r\n"; 
     7845                            $comando .= "Context: $vmctx\r\n"; 
     7846                            $comando .= "ActionID: atxfer\r\n"; 
     7847                        } 
     7848                        if ( $button_server{$nro_boton_destino} == -1 ) { 
     7849                            send_command_to_managers($comando); 
     7850                        } 
     7851                        else { 
     7852                            send_command_to_manager( $comando, $p[ $button_server{$nro_boton_destino} ], 
     7853                                0, $astmanproxy_servers[ $button_server{$nro_boton_destino} ] ); 
     7854                        } 
     7855                        last; 
     7856                    } 
     7857                } 
     7858            } 
    74007859            elsif ( $accion =~ /^conference/ ) { 
    74017860                log_debug( "$heading CONFERENCE extension_transfer($origin_channel)", 1 ) if DEBUG; 
     
    74037862                my $indice    = $origin_server . "^" . $origin_channel; 
    74047863                my $originate = $extension_transfer{$indice}; 
    7405                 $originate =~ s/\d+\^(.*)/$1/; 
     7864                $originate =~ s/-?\d+\^(.*)/$1/; 
    74067865                foreach ( keys(%buttons) ) { 
    74077866                    log_debug( "$heading comparo $buttons{$_} con btn_destino $btn_destino", 1 ) if DEBUG; 
     
    74677926                            } 
    74687927                        } 
    7469                         send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7470                             0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7928                        if ( $button_server{$datosflash} == -1 ) { 
     7929                            send_command_to_managers($comando); 
     7930                        } 
     7931                        else { 
     7932                            send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7933                                0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7934                        } 
    74717935                        last; 
    74727936                    } 
     
    74807944                    $comando .= "Command: database put clid $destino "; 
    74817945                    $comando .= "\"$clid\"\r\n\r\n"; 
    7482                     send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7483                         0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7946                    if ( $button_server{$datosflash} == -1 ) { 
     7947                        send_command_to_managers($comando); 
     7948                    } 
     7949                    else { 
     7950                        send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7951                            0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7952                    } 
    74847953                } 
    74857954 
     
    74957964                if ( $canal_destino ne "-1" ) { 
    74967965                    if ( $canal_destino =~ /\@/ ) { 
    7497                         @pedazos       = split( /\@/, $canal_destino ); 
    7498                         $canal_destino = $pedazos[0]; 
    7499                         $contexto      = $pedazos[1]; 
     7966                        ( $canal_destino, $contexto ) = split( /\@/, $canal_destino ); 
    75007967                    } 
    75017968 
    75027969                    my @cuales_transferir = get_transfer_channel( $origin_channel, $datosflash ); 
    7503  
    7504                     foreach my $valor (@cuales_transferir) { 
    7505                         log_debug( "$heading Will try to transfer $valor to extension number $canal_destino!", 16 ) 
     7970                    if ( $canal_destino eq $park_exten && $contexto eq "parkedcalls" ) { 
     7971                        log_debug( "$heading Will try to park $valor with announce and bounce to $canal_destino!", 16 ) 
    75067972                          if DEBUG; 
    7507                         $comando = "Action: Redirect\r\n"
    7508                         $comando .= "Channel: $valor\r\n"
    7509                         $comando .= "Exten: $canal_destino\r\n"; 
    7510                         if ( $contexto ne "" ) { 
    7511                             $comando .= "Context: $contexto\r\n"
     7973                        my @links
     7974                        my @canal1
     7975                        if ( $reverse_transfer == 1 ) { 
     7976                            @links = @{ $sesbot{$datosflash} }; 
     7977                            @canal1 = extraer_todos_los_enlaces_de_un_canal( $links[0], $button_server{$datosflash} )
    75127978                        } 
    7513                         $comando .= "Priority: 1\r\n\r\n"; 
    7514                         send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7515                             0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
    7516  
    7517                         if ( $calltimeout > 0 ) { 
    7518                             $comando = "Action: AbsoluteTimeout\r\n"; 
     7979                        else { 
     7980                            @canal1 = @{ $sesbot{$datosflash} }; 
     7981                            @links = extraer_todos_los_enlaces_de_un_canal( $canal1[0], $button_server{$datosflash} ); 
     7982                        } 
     7983                        $comando = "Action: Park\r\n"; 
     7984                        $comando .= "Channel: $canal1[0]\r\n"; 
     7985                        $comando .= "Channel2: $links[0]\r\n"; 
     7986                        $comando .= "Timeout: $parktimeout\r\n\r\n"; 
     7987                        if ( $button_server{$datosflash} == -1 ) { 
     7988                            send_command_to_managers($comando); 
     7989                        } 
     7990                        else { 
     7991                            send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7992                                0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7993                        } 
     7994                    } 
     7995                    else { 
     7996                        foreach my $valor (@cuales_transferir) { 
     7997                            log_debug( "$heading Will try to transfer $valor to extension number $canal_destino!", 16 ) 
     7998                              if DEBUG; 
     7999                            $comando = "Action: Redirect\r\n"; 
    75198000                            $comando .= "Channel: $valor\r\n"; 
    7520                             $comando .= "Timeout: $calltimeout\r\n"; 
    7521                             $comando .= "ActionID: timeout|$valor|$calltimeout\r\n"; 
    7522                             $comando .= "\r\n"; 
    7523                             send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7524                                 , 0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8001                            $comando .= "Exten: $canal_destino\r\n"; 
     8002                            if ( $contexto ne "" ) { 
     8003                                $comando .= "Context: $contexto\r\n"; 
     8004                            } 
     8005                            $comando .= "Priority: 1\r\n\r\n"; 
     8006                            if ( $button_server{$datosflash} == -1 ) { 
     8007                                send_command_to_managers($comando); 
     8008                            } 
     8009                            else { 
     8010                                send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     8011                                    0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8012                            } 
     8013 
     8014                            if ( $calltimeout > 0 ) { 
     8015                                $comando = "Action: AbsoluteTimeout\r\n"; 
     8016                                $comando .= "Channel: $valor\r\n"; 
     8017                                $comando .= "Timeout: $calltimeout\r\n"; 
     8018                                $comando .= "ActionID: timeout|$valor|$calltimeout\r\n"; 
     8019                                $comando .= "\r\n"; 
     8020                                if ( $button_server{$datosflash} == -1 ) { 
     8021                                    send_command_to_managers($comando); 
     8022                                } 
     8023                                else { 
     8024                                    send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     8025                                        , 0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8026                                } 
     8027                            } 
     8028 
    75258029                        } 
    7526  
    75278030                    } 
    75288031                } 
     
    75438046                    $comando .= "Command: database put clid $destino "; 
    75448047                    $comando .= "\"$clid\"\r\n\r\n"; 
    7545                     send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7546                         0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8048                    if ( $button_server{$datosflash} == -1 ) { 
     8049                        send_command_to_managers($comando); 
     8050                    } 
     8051                    else { 
     8052                        send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     8053                            0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8054                    } 
    75478055                } 
    75488056 
     
    75938101 
    75948102                    if ( $extension_destino =~ /\@/ ) { 
    7595                         @pedazos           = split( /\@/, $extension_destino ); 
    7596                         $extension_destino = $pedazos[0]; 
    7597                         $contexto          = $pedazos[1]; 
    7598                     } 
    7599  
    7600                     log_debug( "$heading Originate from $origin_channel to extension $extension_destino!", 16 ) if DEBUG; 
     8103                        ( $extension_destino, $contexto ) = split( /\@/, $extension_destino ); 
     8104                    } 
     8105 
     8106                    log_debug( "$heading Originate from $origin_channel to extension $extension_destino!", 16 ) 
     8107                      if DEBUG; 
    76018108                    my $keyext = "$origin_server^$origin_channel"; 
    76028109 
     
    76258132                    $comando .= "\r\n"; 
    76268133                } 
    7627                 send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    7628                     0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8134                if ( $button_server{$datosflash} == -1 ) { 
     8135                    send_command_to_managers($comando); 
     8136                } 
     8137                else { 
     8138                    send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     8139                        0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8140                } 
    76298141            } 
    76308142            elsif ( $accion =~ /^dial/ ) { 
     
    76468158                $comando .= "Priority: 1\r\n"; 
    76478159                $comando .= "\r\n"; 
    7648                 send_command_to_manager( $comando, $servidor_dial, 0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8160                if ( $button_server{$datosflash} == -1 ) { 
     8161                    send_command_to_managers($comando); 
     8162                } 
     8163                else { 
     8164                    send_command_to_manager( $comando, $servidor_dial, 0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     8165                } 
    76498166            } 
    76508167        } 
     
    76598176    } 
    76608177    $tab = substr( $tab, 0, -1 ) if DEBUG; 
     8178} 
     8179 
     8180sub compute_monitoring_filename { 
     8181    my $unique       = shift; 
     8182    my $panelcontext = shift; 
     8183    my $filename     = ""; 
     8184    my $format       = ""; 
     8185    my @return; 
     8186    my %hasha; 
     8187 
     8188    if ( !defined( $config->{$panelcontext}{monitor_filename} ) ) { 
     8189        $filename = $config->{GENERAL}{monitor_filename}; 
     8190    } 
     8191    else { 
     8192        $filename = $config->{$panelcontext}{monitor_filename}; 
     8193    } 
     8194    if ( !defined( $config->{$panelcontext}{monitor_format} ) ) { 
     8195        $format = $config->{GENERAL}{monitor_format}; 
     8196    } 
     8197    else { 
     8198        $format = $config->{$panelcontext}{monitor_format}; 
     8199    } 
     8200 
     8201    while ( my ( $key, $val ) = each( %{ $datos{$unique} } ) ) { 
     8202        $key =~ tr/a-z/A-Z/; 
     8203        if ( $key eq "CALLERID" ) { 
     8204            $key = "CLID"; 
     8205        } 
     8206        elsif ( $key eq "CALLERIDNUM" ) { 
     8207            $key = "CLIDNUM"; 
     8208        } 
     8209        elsif ( $key eq "CALLERIDNAME" ) { 
     8210            $key = "CLIDNAME"; 
     8211        } 
     8212        elsif ( $key eq "UNIQUEID" ) { 
     8213            my ( $realunique, undef ) = split( /-/, $val, 2 ); 
     8214            $val = $realunique; 
     8215        } 
     8216        $hasha{$key} = $val; 
     8217    } 
     8218    $filename =~ s/\${CLIDNAME}/$hasha{CLIDNAME}/gi; 
     8219    $filename =~ s/\${CLIDNUM}/$hasha{CLIDNUM}/gi; 
     8220    $filename =~ s/\${CLID}/$hasha{CLID}/gi; 
     8221    $filename =~ s/\${UNIQUEID}/$hasha{UNIQUEID}/gi; 
     8222    $filename =~ s/\${CHANNEL}/$hasha{CHANNEL}/gi; 
     8223    $filename =~ s/\${LINK}/$hasha{LINK}/gi; 
     8224    $filename = formatdate($filename); 
     8225    $filename =~ s/\//-/gi; 
     8226    push @return, $filename; 
     8227    push @return, $format; 
     8228    return @return; 
    76618229} 
    76628230 
     
    77138281    log_debug( "$heading canal_destino =  $canal_destino", 32 ) if DEBUG; 
    77148282    $canal_destino =~ s/\d+\^(.*)/$1/g; 
     8283    $canal_destino =~ s/^-//g; 
    77158284    log_debug( "$heading La extension para $param es $canal_destino", 32 ) if DEBUG; 
    77168285    return $canal_destino; 
     
    77528321    my $canalid    = shift; 
    77538322    my $member     = ""; 
    7754     my $nada       = ""; 
    77558323    my $showagents = 0; 
    77568324 
     
    77628330        } 
    77638331        else { 
    7764             ( $member, $nada ) = separate_session_from_channel($canalid); 
     8332            ( $member, undef ) = separate_session_from_channel($canalid); 
    77658333        } 
    77668334    } 
     
    77798347 
    77808348            if ( $showagents == 1 ) { 
    7781                 send_command_to_manager( "Action: Command\r\nActionId: agents\r\nCommand: show agents\r\n\r\n", $socket2 ); 
     8349 
     8350                #send_command_to_manager( "Action: Command\r\nActionId: agents\r\nCommand: show agents\r\n\r\n", $socket2 ); 
     8351                send_command_to_manager( "Action: Agents\r\n\r\n", $socket2 ); 
    77828352            } 
    77838353            if ( defined($member) ) { 
     
    79118481            for $interno ( keys %botonpermanenttext ) { 
    79128482                if ( $botonpermanenttext{$interno} ne "" ) { 
    7913                     print "permanente $interno -$botonpermanenttext{$interno}-\n"; 
    79148483                    send_status_to_flash( $socket, "$interno|settext|$botonpermanenttext{$interno}", 0 ); 
    79158484                } 
     
    80088577 
    80098578        if ( defined($socket) && $socket ne "" ) { 
    8010             my @pedazos = split( /\|/, $manager_socket{$socket} ); 
    8011             if ( $pedazos[0] eq $ip_addy{$socket} ) { 
     8579            my ($ipactual) = split( /\|/, $manager_socket{$socket} ); 
     8580            if ( $ipactual eq $ip_addy{$socket} ) { 
    80128581                my $contador = 0; 
    80138582                foreach my $valor (@manager_host) { 
    8014                     if ( $valor eq $pedazos[0] ) { 
     8583                    if ( $valor eq $ipactual ) { 
    80158584                        $nro_servidor = $contador; 
    80168585                    } 
     
    80338602            send_command_to_manager( "Action: Command\r\nActionID: parkedcalls\r\nCommand: show parkedcalls\r\n\r\n", $socket ); 
    80348603 
    8035             #        request_queue_status( $socket, "initialrequest" ); 
     8604            # request_queue_status( $socket, "initialrequest" ); 
    80368605            # Send commands to check the mailbox status for each mailbox defined 
    80378606            while ( my ( $key, $val ) = each(%mailbox) ) { 
    8038                 my @pedacitos = split( /\^/, $key ); 
    8039                 my $servidormbox = $pedacitos[0]; 
     8607                my ($servidormbox) = split( /\^/, $key ); 
    80408608                if ( "$servidormbox" eq "$nro_servidor" ) { 
    80418609                    log_debug( "$heading mailbox $ip_addy{$socket} $key $val", 32 ) if DEBUG; 
     
    80658633 
    80668634                if ( $valor =~ /\^/ ) { 
    8067                     my @pedacitos = split( /\^/, $valor ); 
    8068                     $servidormeetme = $pedacitos[0]; 
    8069                     $meetmeroom     = $pedacitos[1]; 
     8635                    ( $servidormeetme, $meetmeroom ) = split( /\^/, $valor ); 
    80708636                } 
    80718637                else { 
     
    81028668    my $interno    = ""; 
    81038669    my $estado     = ""; 
    8104     my $nada       = ""; 
    81058670    my $conference = 0; 
    81068671    my $usernum    = 0; 
     
    81588723        } 
    81598724    } 
    8160     elsif ( $texto =~ "ActionID: agents" ) { 
    8161         log_debug( "$heading process agents", 16 ) if DEBUG; 
    8162         my $agent_number; 
    8163         my $agent_state; 
    8164         my $agent_name; 
    8165  
    8166         # Show Agents CLI command, generates fake events 
    8167  
    8168         foreach (@lineas) { 
    8169             $_ =~ s/\s+/ /g; 
    8170             /(\d+) \((.*)\) (.*) (\(.*\))/; 
    8171             if ( defined($1) ) { 
    8172                 $agent_number                         = $1; 
    8173                 $agent_name                           = $2; 
    8174                 $agent_state                          = $3; 
    8175                 $agents_name{"$server^$agent_number"} = $agent_name; 
    8176                 set_queueobject( $server, "AGENT/$agent_number", "name", $agent_name ); 
    8177             } 
    8178  
    8179             if ( defined($3) ) { 
    8180                 if ( $agent_state =~ /available at/ ) { 
    8181  
    8182                     # Agent callback login 
    8183                     $agent_state =~ s/.*'(.*)'.*/$1/g; 
    8184                     $bloque[$contador]{"Event"}     = "Agentcallbacklogin"; 
    8185                     $bloque[$contador]{"Loginchan"} = $agent_state; 
    8186                     $bloque[$contador]{"Agent"}     = $agent_number; 
    8187                     $bloque[$contador]{"Server"}    = "$server"; 
    8188                     $contador++; 
    8189                 } 
    8190  
    8191                 if ( $agent_state =~ /logged in on/ ) { 
    8192  
    8193                     # Agent login 
    8194                     $agent_state =~ s/\s+/ /g; 
    8195                     $agent_state =~ s/logged in on //g; 
    8196                     $agent_state =~ s/([^ ]*).*/$1/g; 
    8197  
    8198                     $bloque[$contador]{Event}   = "Agentlogin"; 
    8199                     $bloque[$contador]{Channel} = $agent_state; 
    8200                     $bloque[$contador]{Agent}   = $agent_number; 
    8201                     $bloque[$contador]{Server}  = $server; 
    8202                     $contador++; 
    8203                 } 
    8204                 if ( $agent_state =~ /not logged in/ ) { 
    8205                     $bloque[$contador]{Event}  = "Agentlogoff"; 
    8206                     $bloque[$contador]{Agent}  = $agent_number; 
    8207                     $bloque[$contador]{Server} = $server; 
    8208                     $bloque[$contador]{Fake}   = 1; 
    8209                     $contador++; 
    8210                 } 
    8211             } 
    8212         } 
    8213     } 
     8725 
     8726    #elsif ( $texto =~ "ActionID: agents" ) { 
     8727    #    log_debug( "$heading process agents", 16 ) if DEBUG; 
     8728    #    my $agent_number; 
     8729    #    my $agent_state; 
     8730    #    my $agent_name; 
     8731    # 
     8732    #        # Show Agents CLI command, generates fake events 
     8733    # 
     8734    #        foreach (@lineas) { 
     8735    #            $_ =~ s/\s+/ /g; 
     8736    #            /(\d+) \((.*)\) (.*) (\(.*\))/; 
     8737    #            if ( defined($1) ) { 
     8738    #                $agent_number                         = $1; 
     8739    #                $agent_name                           = $2; 
     8740    #                $agent_state                          = $3; 
     8741    #                $agents_name{"$server^$agent_number"} = $agent_name; 
     8742    #                set_queueobject( $server, "AGENT/$agent_number", "name", $agent_name ); 
     8743    #            } 
     8744    # 
     8745    #            if ( defined($3) ) { 
     8746    #                if ( $agent_state =~ /available at/ ) { 
     8747    # 
     8748    #                    # Agent callback login 
     8749    #                    $agent_state =~ s/.*'(.*)'.*/$1/g; 
     8750    #                    $bloque[$contador]{"Event"}     = "Agentcallbacklogin"; 
     8751    #                    $bloque[$contador]{"Loginchan"} = $agent_state; 
     8752    #                    $bloque[$contador]{"Agent"}     = $agent_number; 
     8753    #                    $bloque[$contador]{"Server"}    = "$server"; 
     8754    #                    $contador++; 
     8755    #                } 
     8756    # 
     8757    #                if ( $agent_state =~ /logged in on/ ) { 
     8758    # 
     8759    #                    # Agent login 
     8760    #                    $agent_state =~ s/\s+/ /g; 
     8761    #                    $agent_state =~ s/logged in on //g; 
     8762    #                    $agent_state =~ s/([^ ]*).*/$1/g; 
     8763    # 
     8764    #                    $bloque[$contador]{Event}   = "Agentlogin"; 
     8765    #                    $bloque[$contador]{Channel} = $agent_state; 
     8766    #                    $bloque[$contador]{Agent}   = $agent_number; 
     8767    #                    $bloque[$contador]{Server}  = $server; 
     8768    #                    $contador++; 
     8769    #                } 
     8770    #                if ( $agent_state =~ /not logged in/ ) { 
     8771    #                    $bloque[$contador]{Event}  = "Agentlogoff"; 
     8772    #                    $bloque[$contador]{Agent}  = $agent_number; 
     8773    #                    $bloque[$contador]{Server} = $server; 
     8774    #                    $bloque[$contador]{Fake}   = 1; 
     8775    #                    $contador++; 
     8776    #                } 
     8777    #            } 
     8778    #        } 
     8779    #    } 
    82148780    elsif ( $texto =~ /ActionID: astdb-/ ) { 
    82158781        log_debug( "$heading process astdb", 16 ) if DEBUG; 
     
    82588824        } 
    82598825        my $canal_a_mutear = $buttons_reverse{$quecanal}; 
    8260         my @pedazos = split /\^/, $canal_a_mutear; 
    8261         $canal_a_mutear = $pedazos[1]; 
     8826        ( undef, $canal_a_mutear ) = split /\^/, $canal_a_mutear; 
    82628827        $canal_a_mutear =~ s/(.*)\&(.*)/$1/g; 
    82638828        $bloque[$contador]{"Event"}   = $quecomando; 
     
    82828847            my $estado = substr( $valor, $statPos ); 
    82838848            $valor =~ s/\s+/ /g; 
    8284             my @parametros = split( " ", $valor ); 
    8285             my $interno    = $parametros[0]; 
     8849            my ( $interno, $dirip ) = split( " ", $valor ); 
    82868850 
    82878851            if ( $interno =~ /\// ) { 
    8288                 my @partecitas = split( /\//, $interno ); 
    8289                 $interno = $partecitas[0]; 
    8290             } 
    8291             my $dirip = $parametros[1]; 
     8852                ($interno) = split( /\//, $interno ); 
     8853            } 
    82928854 
    82938855            if ( defined($estado) && $estado ne "" ) { 
     
    83768938            $valor =~ s/\s+/ /g; 
    83778939            if ( $valor eq "" ) { next; } 
    8378             my @parametros = split( " ", $valor ); 
    8379             my $interno    = $parametros[0]; 
    8380             my $dirip      = $parametros[1]; 
    8381             $interno =~ s/(.*)\/(.*)/$1/g; 
     8940            my ( $interno, $dirip ) = split( " ", $valor ); 
     8941            ( $interno, undef ) = split( /\//, $interno ); 
    83828942 
    83838943            if ( defined($interno) ) { 
     
    85219081                    $match++; 
    85229082                } 
    8523                 if ( $key eq "Server" && $val eq $server ) { 
     9083                if ( $key eq "Server" && ( $val eq $server || $server eq "-1" ) ) { 
    85249084                    $match++; 
    85259085                } 
     
    85889148        if ( defined($_) && $_ ne "" ) { 
    85899149            log_debug( "$heading Enviando status a " . $ip_addy{$_}, 16 ) if DEBUG; 
    8590             my @pedazos = split( /\|/, $manager_socket{$_} ); 
    8591  
    8592             if ( $pedazos[0] eq $ip_addy{$_} ) { 
     9150            my ($ip) = split( /\|/, $manager_socket{$_} ); 
     9151 
     9152            if ( $ip eq $ip_addy{$_} ) { 
    85939153                my $contador = 0; 
    85949154                foreach my $valor (@manager_host) { 
    8595                     if ( $valor eq $pedazos[0] ) { 
     9155                    if ( $valor eq $ip ) { 
    85969156                        $nro_servidor = $contador; 
    85979157                    } 
     
    86189178                # Send commands to check the mailbox status for each mailbox defined 
    86199179                while ( my ( $key, $val ) = each(%mailbox) ) { 
    8620                     my @pedacitos = split( /\^/, $key ); 
    8621                     my $servidormbox = $pedacitos[0]; 
     9180                    my ($servidormbox) = split( /\^/, $key ); 
    86229181                    if ( "$servidormbox" eq "$nro_servidor" ) { 
    86239182                        log_debug( "$heading mailbox $ip_addy{$_} $key $val", 32 ) if DEBUG; 
     
    86299188    } 
    86309189    alarm($poll_interval); 
     9190} 
     9191 
     9192sub send_policy_to_flash { 
     9193    my $socket = shift; 
     9194    if ( !defined($socket) ) { 
     9195        log_debug( "POLICY socket $socket not open!!!", 64 ) if DEBUG; 
     9196    } 
     9197    my $policy = 
     9198"<?xml version=\"1.0\"?>\r\n<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">\r\n<cross-domain-policy>\r\n<allow-access-from domain=\"*\" to-ports=\"$listen_port\" />\r\n</cross-domain-policy>\r\n\0"; 
     9199    actual_syswrite( $socket, $policy, "isclient", "policy enviado\n" ); 
    86319200} 
    86329201 
     
    86519220    if ( $encriptado =~ /key\|0/ ) { 
    86529221        $but_no = '0'; 
    8653         $encriptado =~ m/(.*)\|(.*)\|(.*)/; 
    8654         $cmd  = $2; 
    8655         $data = $1; 
    8656  
     9222        ( $data, $cmd ) = split( /\|/, $encriptado ); 
    86579223    } 
    86589224    else { 
    86599225        $but_no = $status; 
    8660         $but_no =~ s/(\d+)(.*)\|(.*)/$1/g; 
     9226        $but_no =~ s/(\d+).*\|.*/$1/g; 
    86619227        $contexto = $status; 
    86629228        $contexto =~ s/([^\|]*).*/$1/g; 
    8663         $contexto =~ m/(.*)\@(.*)/; 
    8664  
    8665         if ( defined($2) ) { 
    8666             $contexto = $2; 
    8667         } 
    8668         else { 
    8669             $contexto = ""; 
    8670         } 
    8671         $status =~ m/(.*)\|(.*)\|(.*)/; 
    8672         $cmd  = $2; 
    8673         $data = $3; 
     9229        $contexto =~ m/.*\@(.*)/; 
     9230        $contexto = $1 ? $1 : ""; 
     9231        ( undef, $cmd, $data ) = split( /\|/, $status ); 
    86749232 
    86759233        if ( $contexto ne "" && $cmd ne "restrict" ) { 
     
    87279285} 
    87289286 
     9287sub send_command_to_managers { 
     9288    my $comando = shift; 
     9289    foreach (@p) { 
     9290        send_command_to_manager( $comando, $_ ); 
     9291    } 
     9292} 
     9293 
    87299294sub send_command_to_manager { 
    87309295    my $comando            = shift; 
     
    87349299    my @todos_sockets      = (); 
    87359300 
    8736     if ( !defined($socket) && $astmanproxy_server eq "" ) { 
    8737         log_debug( "No socket defined nor astmanproxy", 32 ) if DEBUG; 
    8738         return; 
    8739    
     9301    #    if ( !defined($socket) && $astmanproxy_server eq "" ) { 
     9302    #        log_debug( "No socket defined nor astmanproxy", 32 ) if DEBUG; 
     9303    #        return; 
     9304    #   
    87409305 
    87419306    if ( !defined($noneedtoauth) ) { 
     
    87569321        return; 
    87579322    } 
    8758  
    8759     #    my @partes = split( /\|/, $manager_socket{$socket} ); 
    8760  
    8761     #    $comando = ""; 
    87629323 
    87639324    if ( $comando eq "" ) { 
     
    87849345} 
    87859346 
    8786 sub recompute_queues { 
     9347sub construct_cmd { 
     9348    my $cola    = shift; 
    87879349    my $canalid = shift; 
    8788     my @return_corto; 
    8789     my @return_ocupado; 
     9350    return $cola->{$canalid}{QUEUE} . "=" 
     9351      . $cola->{$canalid}{POSITION} 
     9352      . "|$_[0]|$_[1]|" 
     9353      . $cola->{$canalid}{QUEUE} . "-" 
     9354      . $cola->{$canalid}{SERVER} 
     9355      . "|$canalid"; 
     9356
     9357 
     9358sub recompute_queues_onjoin { 
     9359    my ( $hash_temporal, $server, $canalid ) = @_; 
     9360    my @return    = (); 
     9361    my @corto     = (); 
     9362    my @ocupado   = (); 
     9363    my $qclidnum  = ""; 
     9364    my $qclidname = ""; 
     9365 
     9366    if ( defined( $hash_temporal->{CallerIDName} ) ) { 
     9367        $qclidnum  = $hash_temporal->{CallerID}; 
     9368        $qclidname = $hash_temporal->{CallerIDName}; 
     9369    } 
     9370    elsif ( defined( $hash_temporal->{CalleridName} ) ) { 
     9371        $qclidnum  = $hash_temporal->{Callerid}; 
     9372        $qclidname = $hash_temporal->{CalleridName}; 
     9373    } 
     9374    else { 
     9375        ( $qclidnum, $qclidname ) = split_callerid( $hash_temporal->{CallerID} ); 
     9376    } 
     9377    my $texto_pos = "[$qclidname $qclidnum]"; 
     9378 
     9379    my $canal    = "QUEUE/" . $hash_temporal->{Queue}; 
     9380    my $position = $hash_temporal->{Position}; 
     9381    $canal =~ tr/a-z/A-Z/; 
     9382    my $unico_id = "$canal-$server"; 
     9383 
     9384    # Verify if the position is already taken (by means of QUEUE_PRIO) 
     9385    my $tengo = 0; 
     9386    foreach my $id ( keys %{$cola} ) { 
     9387        unless ( $cola->{$id}{QUEUE} ) { 
     9388            delete( $cola->{$id} ); 
     9389            next; 
     9390        } 
     9391 
     9392        if ( $canal eq $cola->{$id}{QUEUE} ) { 
     9393            if ( $position eq $cola->{$id}{POSITION} ) { 
     9394                $tengo = 1; 
     9395            } 
     9396        } 
     9397    } 
     9398    if ( $tengo == 1 ) { 
     9399 
     9400        # Queue prio! 
     9401        my $time = time(); 
     9402        foreach my $id ( keys %{$cola} ) { 
     9403            unless ( $cola->{$id}{QUEUE} ) { 
     9404                delete( $cola->{$id} ); 
     9405                next; 
     9406            } 
     9407 
     9408            if ( $canal eq $cola->{$id}{QUEUE} ) { 
     9409                if ( $cola->{$id}{POSITION} >= $position ) { 
     9410                    my $diftime = $time - $cola->{$id}{TIME}; 
     9411                    if ( $queue_hide == 1 ) { 
     9412                        push @corto, construct_cmd( $cola, $id, "setalpha", "000" ); 
     9413                    } 
     9414                    push @corto, construct_cmd( $cola, $id, "corto", "" ); 
     9415 
     9416                    $cola->{$id}{POSITION}++; 
     9417                    my $clidtext = $cola->{$id}{CLIDNAME} . " " . $cola->{$id}{CLID}; 
     9418                    push @ocupado, construct_cmd( $cola, $id, "settimer", $diftime ); 
     9419                    push @ocupado, construct_cmd( $cola, $id, "ocupado",  "[$clidtext]" ); 
     9420                } 
     9421            } 
     9422        } 
     9423        @ocupado = unique(@ocupado); 
     9424        @corto   = unique(@corto); 
     9425    } 
     9426 
     9427    # Normal, add new call at the end of the queue 
     9428    push @return, "$canal=$position|ocupado2|$texto_pos|$unico_id|$canalid"; 
     9429    push @return, "$canal=$position|setalpha|100|$unico_id|$canalid"; 
     9430 
     9431    my $tiempo = time(); 
     9432    if ( defined( $hash_temporal->{Wait} ) ) { 
     9433        $tiempo = $tiempo - $hash_temporal->{Wait}; 
     9434        push @return, "$canal=$position|settimer|" . $hash_temporal->{Wait} . "\@UP|$unico_id|$canalid"; 
     9435    } 
     9436    $cola->{$canalid}{POSITION} = $position; 
     9437    $cola->{$canalid}{QUEUE}    = $canal; 
     9438    $cola->{$canalid}{CLID}     = $qclidnum; 
     9439    $cola->{$canalid}{CLIDNAME} = $qclidname; 
     9440    $cola->{$canalid}{SERVER}   = $server; 
     9441    $cola->{$canalid}{TIME}     = $tiempo; 
     9442    if (@corto) { 
     9443        return ( @corto, @ocupado, @return ); 
     9444    } 
     9445    else { 
     9446        return @return; 
     9447    } 
     9448
     9449 
     9450sub recompute_queues_onleave { 
     9451    my $canalid = shift; 
     9452    my @corto; 
     9453    my @ocupado; 
    87909454    my $maxtime = 0; 
    8791  
    8792     print_recomputequeues(); 
     9455    my $save_id; 
     9456    my $time = time(); 
     9457 
     9458    #print_recomputequeues(); 
    87939459 
    87949460    my $header = "**RECOMP QUEUE"; 
     
    88019467 
    88029468    if ( $queue_hide == 1 ) { 
    8803         push @return_corto, 
    8804           $cola->{$canalid}{QUEUE} . "=" 
    8805           . $cola->{$canalid}{POSITION} 
    8806           . "|setalpha|000|" 
    8807           . $cola->{$canalid}{QUEUE} . "-" 
    8808           . $cola->{$canalid}{SERVER} 
    8809           . "|$canalid"; 
    8810     } 
    8811     push @return_corto, 
    8812       $cola->{$canalid}{QUEUE} . "=" 
    8813       . $cola->{$canalid}{POSITION} 
    8814       . "|corto||" 
    8815       . $cola->{$canalid}{QUEUE} . "-" 
    8816       . $cola->{$canalid}{SERVER} 
    8817       . "|$canalid"; 
     9469        push @corto, construct_cmd( $cola, $canalid, "setalpha", "000" ); 
     9470    } 
     9471    push @corto, construct_cmd( $cola, $canalid, "corto", "" ); 
     9472 
    88189473    delete $cola->{$canalid}; 
    8819     my $save_id; 
    88209474 
    88219475    foreach my $id ( keys %{$cola} ) { 
    8822         if ( !defined( $cola->{$id}{QUEUE} ) ) { 
     9476        unless ( $cola->{$id}{QUEUE} ) { 
    88239477            delete( $cola->{$id} ); 
    88249478            next; 
    88259479        } 
    88269480 
    8827         #foreach ( keys %{ $cola->{$id} } ) { 
    8828         #    print "key de cola $_\n"; 
    8829         #} 
    88309481        if ( $queue_to_recompute eq $cola->{$id}{QUEUE} ) { 
    88319482            $save_id = $id; 
    8832             my $diftime = time() - $cola->{$id}{TIME}; 
     9483            my $diftime = $time - $cola->{$id}{TIME}; 
    88339484            if ( $diftime > $maxtime ) { 
    88349485                $maxtime = $diftime; 
     
    88389489                my $clidtext = $cola->{$id}{CLIDNAME} . " " . $cola->{$id}{CLID}; 
    88399490                if ( $queue_hide == 1 ) { 
    8840                     push @return_corto, 
    8841                       $cola->{$id}{QUEUE} . "=" 
    8842                       . $cola->{$id}{POSITION} 
    8843                       . "|setalpha|000|" 
    8844                       . $cola->{$id}{QUEUE} . "-" 
    8845                       . $cola->{$id}{SERVER} . "|$id"; 
    8846                 } 
    8847                 push @return_corto, 
    8848                   $cola->{$id}{QUEUE} . "=" 
    8849                   . $cola->{$id}{POSITION} 
    8850                   . "|corto||" 
    8851                   . $cola->{$id}{QUEUE} . "-" 
    8852                   . $cola->{$id}{SERVER} . "|$id"; 
     9491                    push @corto, construct_cmd( $cola, $id, "setalpha", "000" ); 
     9492                } 
     9493                push @corto, construct_cmd( $cola, $id, "corto", "" ); 
    88539494                $cola->{$id}{POSITION}--; 
    8854                 push @return_ocupado, 
    8855                   $cola->{$id}{QUEUE} . "=" 
    8856                   . $cola->{$id}{POSITION} 
    8857                   . "|settimer|$diftime|" 
    8858                   . $cola->{$id}{QUEUE} . "-" 
    8859                   . $cola->{$id}{SERVER} . "|$id"; 
    8860                 push @return_ocupado, 
    8861                   $cola->{$id}{QUEUE} . "=" 
    8862                   . $cola->{$id}{POSITION} 
    8863                   . "|state|busy|" 
    8864                   . $cola->{$id}{QUEUE} . "-" 
    8865                   . $cola->{$id}{SERVER} . "|$id"; 
    8866                 push @return_ocupado, $cola->{$id}{QUEUE} . "|state|busy|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
    8867                 push @return_ocupado, 
    8868                   $cola->{$id}{QUEUE} . "|settimer|0\@STOP|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
    8869                 push @return_ocupado, 
    8870                   $cola->{$id}{QUEUE} . "=" 
    8871                   . $cola->{$id}{POSITION} 
    8872                   . "|settext|[$clidtext]|" 
    8873                   . $cola->{$id}{QUEUE} . "-" 
    8874                   . $cola->{$id}{SERVER} . "|$id"; 
     9495                push @ocupado, construct_cmd( $cola, $id, "settimer", $diftime ); 
     9496                push @ocupado, construct_cmd( $cola, $id, "ocupado",  "[$clidtext]" ); 
     9497 
     9498                #push @ocupado, $cola->{$id}{QUEUE} . "|ocupado|[$clidtext]|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
     9499                push @ocupado, $cola->{$id}{QUEUE} . "|settimer|0\@STOP|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
    88759500            } 
    88769501        } 
    88779502    } 
    88789503    if ( defined($save_id) ) { 
    8879         push @return_ocupado, 
     9504        push @ocupado, 
    88809505          $cola->{$save_id}{QUEUE} . "|settimer|$maxtime\@UP|" . $cola->{$save_id}{QUEUE} . "-" . $cola->{$save_id}{SERVER} . "|$save_id"; 
    88819506    } 
     
    88859510 
    88869511    delete $cola->{$canalid}; 
    8887     @return_ocupado = unique(@return_ocupado); 
    8888  
    8889     if (@return_corto) { 
    8890         my @todos = (); 
    8891         push @todos, @return_corto; 
    8892         push @todos, @return_ocupado; 
    8893         return @todos; 
    8894     } 
    8895  
    8896     # TEST|corto|&waitingonqueue,0,&|TEST-0|SIP/16-ea0c 
     9512    @ocupado = unique(@ocupado); 
     9513 
     9514    if (@corto) { 
     9515        return ( @corto, @ocupado ); 
     9516    } 
     9517 
    88979518} 
    88989519 
     
    89559576} 
    89569577 
    8957 sub inArray { 
    8958     my $val = shift; 
    8959     for my $elem (@_) { 
    8960         if ( $val eq $elem ) { 
    8961             return 1; 
    8962         } 
    8963     } 
    8964     return 0; 
    8965 } 
    8966  
    89679578sub encode_base64 { 
    89689579    my $res = ""; 
     
    89969607    my $devuelve     = ""; 
    89979608 
     9609    if ( !defined($name) ) { $name = "" } 
     9610 
    89989611    if ( $name eq "<unknown>" ) { $name = ""; } 
    89999612 
     
    90079620 
    90089621    @chars_number = split( //, $numero ); 
    9009     @chars_format = split( //, $format ); 
    9010  
    9011     @chars_format = reverse @chars_format; 
     9622    @chars_format = reverse split( //, $format ); 
    90129623 
    90139624    my $parate = 0; 
     
    90359646    } 
    90369647 
    9037     @result = reverse @result; 
    9038     $devuelve = join( "", @result ); 
     9648    $devuelve = join( "", reverse @result ); 
    90399649    $devuelve =~ s/\${CLIDNAME}/$name/gi; 
    90409650    return $devuelve; 
     
    91059715 
    91069716    if ( !$keys_socket{$socket} ) { 
    9107         print "nocrypt = 1\n"; 
    91089717        $nocrypt = 1; 
    91099718    } 
     
    987710486} 
    987810487 
     10488sub formatdate { 
     10489    my $format = shift; 
     10490    @_ = localtime( shift || time ); 
     10491    my $h = sprintf( "%02d", $_[2] ); 
     10492    my $i = sprintf( "%02d", $_[1] ); 
     10493    my $s = sprintf( "%02d", $_[0] ); 
     10494    my $m = sprintf( "%02d", $_[4] + 1 ); 
     10495    my $d = sprintf( "%02d", $_[3] ); 
     10496    my $y = sprintf( "%02d", ( $_[5] + 1900 ) % 100 ); 
     10497    my $Y = sprintf( "%04d", $_[5] + 1900 ); 
     10498 
     10499    $format =~ s/%Y/$Y/g; 
     10500    $format =~ s/%y/$y/g; 
     10501    $format =~ s/%h/$h/g; 
     10502    $format =~ s/%i/$i/g; 
     10503    $format =~ s/%s/$s/g; 
     10504    $format =~ s/%m/$m/g; 
     10505    $format =~ s/%d/$d/g; 
     10506    return $format; 
     10507} 
     10508 
    987910509sub add_queueobject { 
    988010510    my $server = shift; 
     
    988410514    my @return; 
    988510515 
    9886     print "add queueobject $server $queue $agent\n"; 
    988710516    $queue_object->{$server}{$queue}{$agent}{status} = 1; 
    988810517    @return = compute_queueobject($server); 
     
    989710526    my @return; 
    989810527 
    9899     print "delete queueobject $server $queue $agent\n"; 
    990010528    delete( $queue_object->{$server}{$queue}{$agent} ); 
    990110529    @return = compute_queueobject($server); 
     
    991810546                        if ( $iagent eq $agent ) { 
    991910547                            $queue_object->{$iserver}{$iqueue}{$iagent}{$property} = $value; 
    9920                             print "property set!\n"; 
    992110548                        } 
    992210549                    }