Changeset 4263

Show
Ignore:
Timestamp:
06/28/07 14:41:22 (6 years ago)
Author:
p_lindheimer
Message:

#2022: bring fop up to version 0.27

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.3/amp_conf/htdocs_panel/op_server.pl

    r2505 r4263  
    3434use POSIX qw(setsid EWOULDBLOCK); 
    3535 
    36 my $FOP_VERSION                = "026.001"; 
    37 my %datos                      = (); 
    38 my %sesbot                     = (); 
    39 my %linkbot                    = (); 
    40 my %cache_hit                  = (); 
    41 my %estadoboton                = (); 
     36my $FOP_VERSION    = "0.27"; 
     37my %datos          = (); 
     38my %sesbot         = (); 
     39my %linkbot        = (); 
     40my %cache_hit      = (); 
     41my %estadoboton    = (); 
     42my %preestadoboton = (); 
     43 
     44my %boton_paused               = (); 
     45my %boton_agentready           = (); 
     46my %boton_agentpaused          = (); 
     47my %boton_agentbusy            = (); 
     48my %boton_agentlogedof         = (); 
    4249my %botonled                   = (); 
    4350my %botonalpha                 = (); 
     51my %botonledcolor              = (); 
    4452my %botonregistrado            = (); 
    4553my %boton_ip                   = (); 
     
    5260my %botonmeetme                = (); 
    5361my %botonclid                  = (); 
     62my %botonpermanenttext         = (); 
    5463my %botonqueue                 = (); 
    5564my %botonqueue_count           = (); 
     
    6372my %autenticado                = (); 
    6473my %auto_conference            = (); 
     74my %attendant_transfer         = (); 
     75my %attendant_pending          = (); 
     76my %pending_uniqueid_attendant = (); 
     77my %mute_other                 = (); 
     78my %autosip                    = (); 
     79my %cnt_auto_pos               = (); 
     80my $cnt_autosip                = 0; 
     81my %autosip_detail             = (); 
    6582my %buttons                    = (); 
    6683my %buttons_queue              = (); 
    6784my %buttons_queue_reverse      = (); 
    6885my %buttons_preserve_case      = (); 
     86my %buttons_astdbkey           = (); 
    6987my %button_server              = (); 
    7088my %buttons_reverse            = (); 
     
    7290my %iconos                     = (); 
    7391my %urls                       = (); 
     92my %alarms                     = (); 
    7493my %targets                    = (); 
    7594my %remote_callerid            = (); 
     
    92111my %client_queue_nocrypt       = (); 
    93112my %ip_addy                    = (); 
    94 my %count_queue                = (); 
     113my %agents_available_on_queue  = (); 
     114my $queue_object               = {}; 
    95115my %is_agent                   = (); 
    96116my %agents_on_queue            = (); 
     
    107127my $bloque_final; 
    108128my $todo; 
     129my $reload_pending     = 0; 
    109130my $regexp_buttons     = 0; 
     131my $auto_buttons       = 0; 
     132my @auto_config        = (); 
    110133my $queueagent_buttons = 0; 
    111134my $defaultlanguage; 
     
    161184my $clid_privacy; 
    162185my %clid_private; 
     186my %group_count; 
    163187my $show_ip; 
    164188my $queue_hide; 
     
    175199my $first_room; 
    176200my $last_room; 
    177 my $meetme_context; 
    178201my $clid_format; 
    179202my $directorio       = ""; 
     
    185208my %shapes; 
    186209my %legends; 
     210my %images; 
    187211my %no_encryption = (); 
    188212my %total_shapes; 
    189213my %total_legends; 
     214my %total_images; 
    190215my @btninclude   = (); 
    191216my @styleinclude = (); 
     
    309334} 
    310335 
    311 open STDIN, '/dev/null'   or die "Can't read /dev/null: $!"; 
    312  
    313336if ( $logdir ne "" ) { 
    314337    open( STDOUT, ">>$logdir/output.log" ) 
     
    316339    open( STDERR, ">>$logdir/error.log" ) 
    317340      or die "Can't open output log $logdir/error.log"; 
    318 } else { 
    319     open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; 
    320     open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!"; 
    321341} 
    322342 
     
    325345    exit if $pid; 
    326346    setsid or die "Can't start a new session: $!"; 
    327     open MYPIDFILE, ">$pidfile"; 
     347    open MYPIDFILE, ">$pidfile" 
     348      or die "Failed to open PID file $pidfile for writing."; 
    328349    print MYPIDFILE $$; 
    329350    close MYPIDFILE; 
     
    513534    %barge_rooms = map { $todos_los_rooms[$_], 0 } 0 .. $#todos_los_rooms; 
    514535 
    515     $meetme_context = $config->{GENERAL}{conference_context}; 
    516     $clid_format    = $config->{GENERAL}{clid_format}; 
     536    $clid_format = $config->{GENERAL}{clid_format}; 
    517537 
    518538    $flash_file = $flash_dir . "/variables.txt"; 
     
    761781                next unless ( $contador >= 0 ); 
    762782                my ( $key, $val ) = split( /=/, $_, 2 ); 
     783                if ( !defined($val) ) { $val = ""; } 
    763784                $key =~ tr/A-Z/a-z/; 
    764785                $key =~ s/^\s+//g; 
     
    781802 
    782803        close(CONFIG); 
     804    } 
     805 
     806    # Read now the auto_sip button config files 
     807    foreach my $papi ( sort keys %autosip ) { 
     808        if ( !defined( $autosip{$papi}{channel} ) ) { next; } 
     809 
     810        $contador++; 
     811        log_debug( "-----", 16 ) if DEBUG; 
     812        $btn_cfg[$contador]{'channel_preserve_case'} = $autosip{$papi}{channel}; 
     813        $btn_cfg[$contador]{'channel'}               = $autosip{$papi}{channel}; 
     814        if ( defined( $cnt_auto_pos{ $autosip{$papi}{autonumber} } ) ) { 
     815            $cnt_auto_pos{ $autosip{$papi}{autonumber} }++; 
     816        } 
     817        else { 
     818            $cnt_auto_pos{ $autosip{$papi}{autonumber} } = 0; 
     819        } 
     820 
     821        my $pos = $autosip{$papi}{starting_position} + $cnt_auto_pos{ $autosip{$papi}{autonumber} }; 
     822        $btn_cfg[$contador]{'position'} = $pos; 
     823        $btn_cfg[$contador]{'channel'}  = $autosip{$papi}{channel}; 
     824        my $logblock = "\n[" . $autosip{$papi}{channel} . "]\n"; 
     825        log_debug( $autosip{$papi}{channel} . " at position $pos", 16 ) if DEBUG; 
     826 
     827        while ( my ( $key, $val ) = each( %{ $autosip{$papi} } ) ) { 
     828            if ( $val eq "" ) { 
     829                log_debug( "** Empty value for autosip for key $key, button $papi", 1 ) if DEBUG; 
     830                next; 
     831            } 
     832            $btn_cfg[$contador]{$key} = $val; 
     833            $logblock .= "$key=$val\n"; 
     834            if ( $key eq "panel_context" ) { 
     835                push @contextos, $val; 
     836            } 
     837        } 
     838        log_debug( "$logblock", 1 ) if DEBUG; 
    783839    } 
    784840 
     
    817873    my %rectangles_counter; 
    818874    my %legends_counter; 
    819  
     875    my %images_counter; 
     876 
     877    my $cont_auto = 0; 
    820878  CONFIG: 
    821879    foreach (@btn_cfg) { 
     
    831889            } 
    832890        } 
     891        if ( $tmphash{channel} =~ /^AUTO/i ) { 
     892            $auto_buttons = 1; 
     893            while ( my ( $key, $val ) = each(%tmphash) ) { 
     894                $auto_config[$cont_auto]{$key} = $val; 
     895            } 
     896            $cont_auto++; 
     897            next CONFIG; 
     898        } 
     899 
    833900        if ( $tmphash{channel} =~ /^_/ ) { 
    834901            $regexp_buttons = 1; 
     
    836903        elsif ( $tmphash{channel} =~ /^QUEUEAGENT\//i ) { 
    837904            $queueagent_buttons = 1; 
     905        } 
     906        elsif ( $tmphash{channel} =~ /^image$/i ) { 
     907 
     908            # Image config primitive 
     909 
     910            if ( defined( $tmphash{panel_context} ) ) { 
     911                $tmphash{panel_context} =~ tr/a-z/A-Z/; 
     912                $tmphash{panel_context} =~ s/^DEFAULT$//xms; 
     913            } 
     914            else { 
     915                $tmphash{panel_context} = ""; 
     916            } 
     917            my $conttemp = $tmphash{panel_context}; 
     918            if ( $conttemp eq "" ) { $conttemp = "GENERAL"; } 
     919 
     920            if ( !defined( $tmphash{src} ) ) { 
     921                next CONFIG; 
     922            } 
     923            if ( !defined( $tmphash{url} ) ) { 
     924                $tmphash{url} = "no"; 
     925            } 
     926            if ( !defined( $tmphash{target} ) ) { 
     927                $tmphash{target} = "NONTARFOP"; 
     928            } 
     929            $images_counter{$conttemp}++; 
     930            if ( $images_counter{$conttemp} > 1 ) { 
     931                $images{$conttemp} .= "&"; 
     932            } 
     933            $total_images{$conttemp}++; 
     934            $images{$conttemp} .= "image_$images_counter{$conttemp}=" . $tmphash{x} . ","; 
     935            $images{$conttemp} .= $tmphash{y} . ","; 
     936            $images{$conttemp} .= $tmphash{src} . ","; 
     937            $images{$conttemp} .= $tmphash{url} . ","; 
     938            $images{$conttemp} .= $tmphash{target}; 
     939            next CONFIG; 
     940 
    838941        } 
    839942        elsif ( $tmphash{channel} =~ /^legend$/i ) { 
     
    9721075        } 
    9731076 
     1077        if ( !defined( $tmphash{alarm} ) ) { 
     1078            $tmphash{alarm} = "0"; 
     1079 
     1080        } 
    9741081        if ( !defined( $tmphash{url} ) ) { 
    9751082            $tmphash{url} = "0"; 
     
    9841091        } 
    9851092        else { 
     1093            if ( $tmphash{server} eq "*" ) { $tmphash{server} = 0; } 
    9861094            $tmphash{server} = $tmphash{server} - 1; 
    9871095        } 
     
    11011209                } 
    11021210                $buttons_preserve_case{"$tmphash{server}^$chan_trunk_case"} = $pos; 
    1103                 $buttons{ uc("$tmphash{server}^$chan_trunk") }              = $pos; 
    1104                 $textos{$indice_contexto}                                   = $tmphash{label}; 
     1211                if ( defined( $tmphash{astdbkey} ) ) { 
     1212                    $buttons_astdbkey{"$tmphash{server}^$chan_trunk_case"} = $tmphash{astdbkey}; 
     1213                } 
     1214                $buttons{ uc("$tmphash{server}^$chan_trunk") } = $pos; 
     1215                $textos{$indice_contexto} = $tmphash{label}; 
    11051216                if ( $no_counter == 0 ) { 
    11061217                    $textos{$indice_contexto} .= " " . $count; 
     
    11081219                $iconos{$indice_contexto}  = $tmphash{icon}; 
    11091220                $urls{$indice_contexto}    = $tmphash{url}; 
     1221                $alarms{$indice_contexto}  = $tmphash{alarm}; 
    11101222                $targets{$indice_contexto} = $tmphash{target}; 
    11111223                $button_server{$pos}       = $tmphash{server}; 
     
    11401252                $buttons{"$tmphash{server}^$canal_key"}                    = $lastpos . "\@" . $tmphash{panel_context}; 
    11411253                $buttons_preserve_case{"$tmphash{server}^$canal_key_case"} = $lastpos . "\@" . $tmphash{panel_context}; 
     1254                if ( defined( $tmphash{astdbkey} ) ) { 
     1255                    $buttons_astdbkey{"$tmphash{server}^$canal_key_case"} = $tmphash{astdbkey}; 
     1256                } 
    11421257 
    11431258                $textos{"$lastpos\@$tmphash{panel_context}"}              = $tmphash{label}; 
    11441259                $iconos{"$lastpos\@$tmphash{panel_context}"}              = $tmphash{icon}; 
    11451260                $urls{"$lastpos\@$tmphash{panel_context}"}                = $tmphash{url}; 
     1261                $alarms{"$lastpos\@$tmphash{panel_context}"}              = $tmphash{alarm}; 
    11461262                $targets{"$lastpos\@$tmphash{panel_context}"}             = $tmphash{target}; 
    11471263                $button_server{ $buttons{"$tmphash{server}^$canal_key"} } = $tmphash{server}; 
     
    11571273                $buttons{"$tmphash{server}^$canal_key"}                    = $lastpos; 
    11581274                $buttons_preserve_case{"$tmphash{server}^$canal_key_case"} = $lastpos; 
    1159                 $textos{$lastpos}                                          = $tmphash{label}; 
    1160                 $iconos{$lastpos}                                          = $tmphash{icon}; 
    1161                 $urls{$lastpos}                                            = $tmphash{url}; 
    1162                 $targets{$lastpos}                                         = $tmphash{target}; 
    1163                 $button_server{ $buttons{"$tmphash{server}^$canal_key"} }  = $tmphash{server}; 
     1275                if ( defined( $tmphash{astdbkey} ) ) { 
     1276                    $buttons_astdbkey{"$tmphash{server}^$canal_key_case"} = $tmphash{astdbkey}; 
     1277                } 
     1278                $textos{$lastpos}                                         = $tmphash{label}; 
     1279                $iconos{$lastpos}                                         = $tmphash{icon}; 
     1280                $urls{$lastpos}                                           = $tmphash{url}; 
     1281                $alarms{$lastpos}                                         = $tmphash{alarm}; 
     1282                $targets{$lastpos}                                        = $tmphash{target}; 
     1283                $button_server{ $buttons{"$tmphash{server}^$canal_key"} } = $tmphash{server}; 
    11641284            } 
    11651285        } 
    11661286 
    11671287        @positions = unique(@positions); 
     1288 
     1289        if ( defined( $tmphash{groupcount} ) ) { 
     1290            my $count = @positions; 
     1291            if ( $count == 0 ) { 
     1292                push @positions, $lastposition{ $tmphash{panel_context} }; 
     1293            } 
     1294            if ( $tmphash{groupcount} eq "true" || $tmphash{groupcount} eq "1" ) { 
     1295                my $agre_context = ""; 
     1296                if ( $tmphash{panel_context} ne "" ) { 
     1297                    $agre_context = "\@" . $tmphash{panel_context}; 
     1298                } 
     1299                foreach my $pos (@positions) { 
     1300                    $group_count{"$pos$agre_context"} = 1; 
     1301                } 
     1302            } 
     1303        } 
    11681304 
    11691305        if ( defined( $tmphash{privacy} ) ) { 
     
    13301466        my $flash_context_file = $directorio . "/variables" . $append_filename . ".txt"; 
    13311467        push @all_flash_files, $flash_context_file; 
     1468        no warnings "io"; 
    13321469        open( VARIABLES, ">$flash_context_file" ) 
    13331470          or die("Could not write configuration data $flash_context_file.\nCheck your file permissions\n"); 
     
    13811518        } 
    13821519        while ( my ( $key, $val ) = each(%legends) ) { 
     1520            if ( $key eq $contexto_iterate ) { 
     1521                print VARIABLES "&$val"; 
     1522            } 
     1523        } 
     1524        while ( my ( $key, $val ) = each(%images) ) { 
    13831525            if ( $key eq $contexto_iterate ) { 
    13841526                print VARIABLES "&$val"; 
     
    14621604            } 
    14631605        } 
     1606        while ( my ( $key, $val ) = each(%alarms) ) { 
     1607            $val =~ s/\"(.*)\"/$1/g; 
     1608            if ( $val ne "0" ) { 
     1609                my $base64_url    = encode_base64($val); 
     1610                my $contextoboton = $key; 
     1611                if ( $contextoboton =~ m/\@/ ) { 
     1612                    my @parte = split( /\@/, $contextoboton, 2 ); 
     1613                    $contextoboton = $parte[1]; 
     1614                    $contextoboton =~ tr/a-z/A-Z/; 
     1615                } 
     1616                else { 
     1617                    $contextoboton = "GENERAL"; 
     1618                } 
     1619 
     1620                if ( $contextoboton eq $contexto_iterate ) { 
     1621                    $key =~ s/(\d+)\@.+/$1/g; 
     1622                    print VARIABLES "&alarm$key=$base64_url\n"; 
     1623                } 
     1624            } 
     1625        } 
     1626 
    14641627        if ( !defined( $style_variables{$contextlower} ) ) { 
    14651628            $style_variables{$contextlower} = $style_variables{"general"}; 
     
    14731636            $total_legends{$contexto_iterate} = 0; 
    14741637        } 
     1638        if ( !defined( $total_images{$contexto_iterate} ) ) { 
     1639            $total_images{$contexto_iterate} = 0; 
     1640        } 
     1641 
    14751642        print VARIABLES "&total_legends=" . $total_legends{$contexto_iterate}; 
     1643        print VARIABLES "&total_images=" . $total_images{$contexto_iterate}; 
    14761644 
    14771645        foreach my $val (@textsclients) { 
     
    14881656    } 
    14891657    $/ = "\0"; 
     1658 
     1659} 
     1660 
     1661sub send_reload_to_flash() { 
     1662    if ( $reload_pending == 1 ) { 
     1663        log_debug( "Pending Reload!", 32 ) if DEBUG; 
     1664        foreach my $socket ( keys %keys_socket ) { 
     1665            &sends_reload($socket); 
     1666        } 
     1667        $reload_pending = 0; 
     1668    } 
    14901669} 
    14911670 
     
    15331712 
    15341713sub generate_configs_onhup { 
     1714 
     1715    %autosip        = (); 
     1716    %autosip_detail = (); 
     1717    %cnt_auto_pos   = (); 
     1718    $cnt_autosip    = 0; 
     1719 
    15351720    %buttons            = (); 
    15361721    %background         = (); 
     
    15551740    %botonvoicemailcount = (); 
    15561741    %botonalpha          = (); 
     1742    %botonledcolor       = (); 
    15571743    %botonqueue          = (); 
    15581744    %botonqueuemember    = (); 
     
    17151901    } 
    17161902    if ( $elemento =~ /^mISDN/i ) { 
    1717         $elemento .= "-XXXX"; 
     1903        if ( $elemento !~ /XXXY/ ) { 
     1904            $elemento .= "-XXXY"; 
     1905        } 
    17181906 
    17191907        #    $elemento =~ s/(.*)\/(.*)/\U$1\E\/${2}-${2}/g; 
    17201908    } 
    1721     if ( $elemento =~ /^SRX/i ) { 
     1909    elsif ( $elemento =~ /^SRX/i ) { 
    17221910        $elemento =~ s/(.*)\/(.*)/\U$1\E\/${2}-1/g; 
    17231911    } 
     1912    elsif ( $elemento =~ /^CAPI\//i ) { 
     1913        $elemento =~ s/(CAPI\/)(.*)\/(.*)-(.*)/$1$2-$4/g; 
     1914    } 
     1915 
    17241916    $elemento =~ s/(.*)[-\/](.*)/$1\t$2/g; 
    17251917    log_debug( "$heading elemento2 $elemento", 32 ) if DEBUG; 
     
    17601952 
    17611953sub erase_instances_for_trunk_buttons { 
     1954 
    17621955    my $canalid          = shift; 
    17631956    my $canal            = shift; 
     
    17941987 
    17951988    my $sesiontemp = $canalid; 
    1796     if ( $canalid =~ /^Zap/i && $canal =~ /\*/ ) { 
    1797  
    1798         # Si es un Zap y ademas wildcard, cambio el canalid para 
    1799         # que tenga la sesion modificada 
    1800         # $sesiontemp =~ s/Zap/ZAP/g; 
    1801         $sesiontemp =~ s/(.*)\/(.*)-(.*)/\U$1\/$2-${2}\E${3}/g; 
    1802     } 
    1803     if ( $canalid =~ /^MGCP/i && $canal =~ /\*/ ) { 
    1804  
    1805         # Si es un MGCP y ademas wildcard, cambio el canalid para 
    1806         # que tenga la sesion modificada 
    1807         my $sesiontemp2 = $sesiontemp; 
    1808         $sesiontemp2 =~ s/(.*)\@(.*)-(.*)/$2/g; 
    1809         $sesiontemp2 = substr( $sesiontemp2, -3 ); 
    1810         $sesiontemp =~ s/(.*)\/(.*)-(.*)/\U$1\E\/${2}-${sesiontemp2}${3}/g; 
    1811     } 
    18121989 
    18131990    log_debug( "$heading looking for $canalid on instancias to erase it", 128 ) if DEBUG; 
     
    19152092    my @return; 
    19162093    my $heading = "** ERASE_ALL_SESS_FROM"; 
    1917     log_debug( "$heading canal $canal canalid $canalid", 16 ) if DEBUG; 
     2094    log_debug( "$heading canal $canal canalid $canalid server $server", 16 ) if DEBUG; 
    19182095 
    19192096    my $indice_cache = $canalid . "-" . $canal . "-" . $server; 
     
    21382315            $todo .= "$key = $val\n"; 
    21392316            log_debug( "$heading buscando $canal en $key=$val", 128 ) if DEBUG; 
    2140             if ( ( $val =~ /^$canal-/i || $val =~ /^$canal$/ ) && $key =~ /^Chan/i ) { 
     2317            if ( ( $val =~ /^$canal-/i || $val =~ /^$canal$/i ) && $key =~ /^Chan/i ) { 
    21412318                log_debug( "$heading canal coincide $canal = $val\n", 16 ) if DEBUG; 
    21422319                $canalaqui = 1; 
     
    22852462                @multicanal = ($canal); 
    22862463            } 
    2287             print_agents(); 
    22882464        } 
    22892465    } 
     
    23092485    my $indice_cache = ""; 
    23102486    @multicanal = unique(@multicanal); 
     2487    my $server_original = $server; 
    23112488 
    23122489    foreach my $canal (@multicanal) { 
     
    23172494            log_debug( "$heading CACHE MISS $indice_cache", 32 ) if DEBUG; 
    23182495            for ( keys %buttons ) { 
     2496                $server     = $server_original; 
    23192497                $canalfinal = ""; 
    23202498                my ( $nada, $contexto ) = split( "\&", $_ ); 
    23212499                if ( !defined($contexto) ) { $contexto = ""; } 
    23222500                if ( $contexto ne "" ) { $contexto = "&" . $contexto; } 
     2501                log_debug( "$heading trying $_", 32 ) if DEBUG; 
     2502                if ( $_ =~ /^\Q-1^\E/ ) { 
     2503                    log_debug( "$heading IGNORE SERVER! $_", 32 ) if DEBUG; 
     2504                    $server = "-1"; 
     2505                } 
    23232506                if ( $_ =~ /^\Q$server^$canal\E$/i ) { 
    23242507 
     
    25252708    if ( $hash_temporal{"Event"} =~ /^UserEvent/ ) { 
    25262709 
     2710        if ( $hash_temporal{"Event"} eq "UserEvent" ) { 
     2711 
     2712            # Asterisk 1.4 Issues a separate header for UserEvent, merge it 
     2713            # to make it compatible with the way older versions worked 
     2714            $hash_temporal{"Event"} = "UserEvent" . $hash_temporal{UserEvent}; 
     2715        } 
     2716 
    25272717        # This blocks checks if we have an UserEvent 
    25282718        # and splits every key value pair if it haves 
     
    25532743 
    25542744    if ( defined( $hash_temporal{"Uniqueid"} ) ) { 
    2555         $unico_id   = $hash_temporal{"Uniqueid"}; 
    2556         $fill_datos = 1; 
     2745        $unico_id = $hash_temporal{"Uniqueid"}; 
     2746        if ( $hash_temporal{Event} !~ /^Originate/ ) { 
     2747            $fill_datos = 1; 
     2748        } 
    25572749    } 
    25582750    else { 
     
    26192811                        $val = ""; 
    26202812                    } 
    2621                     $datos{$unico_id}{"$key"} = $val; 
     2813                    $datos{$unico_id}{$key} = $val; 
    26222814                    log_debug( "$heading POPULATES datos($unico_id){ $key } = $val", 128 ) if DEBUG; 
    26232815                } 
     
    26442836    elsif ( $evento =~ /^Unlink/ )              { $evento = "unlink"; } 
    26452837    elsif ( $evento =~ /QueueParams/ )          { $evento = "queueparams"; } 
     2838    elsif ( $evento =~ /PeerEntry/ )            { $evento = "peerentry"; } 
    26462839    elsif ( $evento =~ /QueueEntry/ )           { $evento = "queueentry"; } 
    26472840    elsif ( $evento =~ /^QueueMember$/ )        { $evento = "queuemember"; } 
     
    26772870    elsif ( $evento =~ /^ZapShowChannels$/ )    { $evento = "zapdndstate"; } 
    26782871    elsif ( $evento =~ /^ExtensionStatus$/ )    { $evento = "extensionstatus"; } 
     2872    elsif ( $evento =~ /^OriginateSuccess$/ )   { $evento = "originatesuccess"; } 
     2873    elsif ( $evento =~ /^OriginateFailure$/ )   { $evento = "originatefailure"; } 
     2874    elsif ( $evento =~ /^ChannelReload$/ )      { $evento = "channelreload"; } 
    26792875    else { log_debug( "$heading No event match ($evento)", 32 ); } 
    26802876 
     
    26952891    } 
    26962892 
    2697     if ( $evento eq "agentcomplete" ) { 
     2893    if ( $evento eq "channelreload" ) { 
     2894 
     2895        # Event: ChannelReload 
     2896        # Privilege: system,all 
     2897        # Channel: SIP 
     2898        # ReloadReason: RELOAD (Channel module reload) 
     2899        # Registry_Count: 1 
     2900        # Peer_Count: 19 
     2901        # User_Count: 7 
     2902        $reload_pending = 1; 
     2903        &generate_configs_onhup; 
     2904 
     2905    } 
     2906    elsif ( $evento eq "originatesuccess" ) { 
     2907        if ( defined( $hash_temporal{ActionID} ) ) { 
     2908            if ( $hash_temporal{ActionID} =~ /^attendant/ ) { 
     2909 
     2910                # Store the uniqueid for OriginateSuccess for attendant transfers 
     2911                # we need it to find the channel in the next newexten event with 
     2912                # the same uniqueid 
     2913                my $indice = $hash_temporal{Uniqueid} . "-" . $hash_temporal{Server}; 
     2914                if ( exists( $datos{"$indice"} ) ) { 
     2915                    log_debug( "** ATTENDANT we had that uniqueid before, extract the channel from there", 16 ) if DEBUG; 
     2916                    if ( defined( $datos{$indice}{Extension} ) ) { 
     2917 
     2918                        # if Extension is defined we received the Newexten event before the OriginateSuccess 
     2919                        # if not, then we only had a Ringing state without extension/context, so use the one from 
     2920                        # this event. 
     2921                        $attendant_pending{ $datos{$indice}{Channel} } = $datos{$indice}{Extension} . "@" . $datos{$indice}{Context}; 
     2922                    } 
     2923                    else { 
     2924                        $attendant_pending{ $datos{$indice}{Channel} } = $hash_temporal{Exten} . "@" . $hash_temporal{Context}; 
     2925                    } 
     2926                } 
     2927                else { 
     2928                    log_debug( "** ATTENDANT we do not have any event with that uniqueid, save for later", 16 ) if DEBUG; 
     2929                    print_datos(99); 
     2930                    $pending_uniqueid_attendant{ $hash_temporal{Uniqueid} } = $hash_temporal{Exten} . "@" . $hash_temporal{Context}; 
     2931                } 
     2932            } 
     2933        } 
     2934        $evento = ""; 
     2935    } 
     2936    elsif ( $evento eq "originatefailure" ) { 
     2937 
     2938        my $contexto = $hash_temporal{ActionID}; 
     2939 
     2940        $contexto =~ s/(.*)-(.*)/$2/g; 
     2941        $contexto = uc($contexto); 
     2942        $canal    = $hash_temporal{Channel}; 
     2943 
     2944        my $ext_transf = $extension_transfer{"$server^$canal"}; 
     2945        $ext_transf =~ s/\d+\^(.*)/$1/g; 
     2946        my @part_ext = split( /\@/, $ext_transf ); 
     2947 
     2948        my $dst_exten   = $hash_temporal{Exten}; 
     2949        my $dst_context = $hash_temporal{Context}; 
     2950 
     2951        if ( defined( $config->{$contexto}{'attendant_failure_redirect_to'} ) ) { 
     2952 
     2953            # If we define a new extension/context, then disengage the originating button 
     2954            # from the conference 
     2955 
     2956            my @borrar = (); 
     2957            while ( ( $key, $val ) = each(%attendant_pending) ) { 
     2958                if ( $val eq "$dst_exten\@$dst_context" ) { 
     2959                    push @borrar, $key; 
     2960                    log_debug( "Hangup pending attendant channel $key on originate failure", 16 ) if DEBUG; 
     2961                    my $comando = "Action: Hangup\r\n"; 
     2962                    $comando .= "Channel: $key\r\n\r\n"; 
     2963                    send_command_to_manager( $comando, $socket, 0, $astmanproxy_server ); 
     2964                } 
     2965            } 
     2966            foreach (@borrar) { 
     2967                delete $attendant_pending{$_}; 
     2968            } 
     2969 
     2970            while ( ( $key, $val ) = each(%mute_other) ) { 
     2971                log_debug( "Mute other after originate failure: $key = $val", 16 ) if DEBUG; 
     2972            } 
     2973            while ( ( $key, $val ) = each(%pending_uniqueid_attendant) ) { 
     2974                log_debug( "Pending uniqueid attendant after originate failure: $key = $val", 16 ) if DEBUG; 
     2975            } 
     2976            my $tempval = $config->{$contexto}{'attendant_failure_redirect_to'}; 
     2977            $tempval =~ s/\${CHANNEL}/$hash_temporal{Channel}/g; 
     2978            $tempval =~ s/\${EXTEN}/$part_ext[0]/g; 
     2979            $tempval =~ s/\${CONTEXT}/$part_ext[1]/g; 
     2980 
     2981            if ( $tempval =~ m/\@/ ) { 
     2982                my @partes = split( /\@/, $tempval, 2 ); 
     2983                $dst_exten   = $partes[0]; 
     2984                $dst_context = $partes[1]; 
     2985            } 
     2986            else { 
     2987                $dst_exten   = $tempval; 
     2988                $dst_context = "default"; 
     2989            } 
     2990        } 
     2991 
     2992        log_debug( "Transfer to $dst_exten @ $dst_context after originate failure", 16 ) if DEBUG; 
     2993 
     2994        # Event: OriginateFailure 
     2995        # Privilege: call,all 
     2996        # ActionID: attendant-general 
     2997        # Channel: SIP/17 
     2998        # Context: conferences 
     2999        # Exten: 901 
     3000        # Reason: 5 
     3001        # Uniqueid: <null> 
     3002        # Server: 0 
     3003 
     3004        if ( $hash_temporal{ActionID} =~ /^attendant/ ) { 
     3005            my $room = $hash_temporal{Exten} . "@" . $hash_temporal{Context}; 
     3006            print "Failure pero tengo mute_other($room) = " . $mute_other{$room} . "\n"; 
     3007            my $comando = "Action: Redirect\r\n"; 
     3008            $comando .= "Channel: " . $mute_other{$room} . "\r\n"; 
     3009            $comando .= "Exten: " . $dst_exten . "\r\n"; 
     3010            $comando .= "Context: " . $dst_context . "\r\n"; 
     3011            $comando .= "ActionID: 1234attendant\r\n"; 
     3012            $comando .= "Priority: 1\r\n\r\n"; 
     3013            send_command_to_manager( $comando, $socket, 0, $astmanproxy_server ); 
     3014        } 
     3015        $evento = ""; 
     3016 
     3017    } 
     3018    elsif ( $evento eq "agentcomplete" ) { 
    26983019 
    26993020        # Hook for queue statistics? 
     
    27083029        my ( $canal, $nada ) = separate_session_from_channel( $hash_temporal{Channel} ); 
    27093030        request_queue_status( $socket, $canal ); 
    2710     } 
    2711  
    2712     if ( $evento eq "agentcalled" ) { 
     3031        my @respuestas = set_queueobject( $server, $canal, "status", 1 ); 
     3032        foreach (@respuestas) { 
     3033            push @return, $_; 
     3034        } 
     3035    } 
     3036    elsif ( $evento eq "PeerlistComplete" ) { 
     3037 
     3038        foreach (@auto_config) { 
     3039            my %tmphash = %$_; 
     3040            my $srv     = 1; 
     3041            if ( defined( $tmphash{server} ) ) { 
     3042                $srv = $tmphash{server}; 
     3043            } 
     3044            $srv--; 
     3045 
     3046            if ( $srv == $hash_temporal{Server} ) { 
     3047                my $match = $tmphash{channel_preserve_case}; 
     3048                $match =~ s/^AUTO\///g; 
     3049                while ( ( $key, $val ) = each(%autosip) ) { 
     3050                    my ( $server, $sipp ) = split( /\^/, $key, 2 ); 
     3051                    if ( "SIP/$sipp" =~ m/$match/ && $server == $srv ) { 
     3052                        $cnt_autosip++; 
     3053                        log_debug( "AUTO sip de server $srv $key coincide con $match, envio query detallado autosipentry-$cnt_autosip", 16 ) 
     3054                          if DEBUG; 
     3055                        my $comando = "Action: SIPShowPeer\r\nPeer: $sipp\r\nActionID: autosipentry-$cnt_autosip\r\n\r\n"; 
     3056                        send_command_to_manager( $comando, $socket, 0, $server ); 
     3057                    } 
     3058                    else { 
     3059                        log_debug( "No autosip match $srv $key con $match", 32 ) if DEBUG; 
     3060                    } 
     3061                } 
     3062            } 
     3063        } 
     3064        $autosip_detail{"autosipentry-$cnt_autosip"} = 1; 
     3065        send_reload_to_flash(); 
     3066    } 
     3067    elsif ( $evento eq "sippeerentrylong" ) { 
     3068 
     3069        if ( defined( $hash_temporal{ObjectName} ) ) { 
     3070 
     3071            my $calid               = $hash_temporal{Callerid}; 
     3072            my $ctx                 = $hash_temporal{Context}; 
     3073            my $chan_name           = $hash_temporal{ObjectName}; 
     3074            my $acid                = $hash_temporal{ActionID}; 
     3075            my $voicemailbox        = $hash_temporal{VoiceMailbox} ? $hash_temporal{VoiceMailbox} : ""; 
     3076            my $accode              = $hash_temporal{Accountcode} ? $hash_temporal{Accountcode} : ""; 
     3077            my $voicemailboxnum     = ""; 
     3078            my $voicemailboxcontext = ""; 
     3079 
     3080            my $calidnum  = $calid; 
     3081            my $calidname = $calid; 
     3082 
     3083            $calidnum  =~ s/([^<]*)<([^>]*)>/$2/g; 
     3084            $calidname =~ s/([^<]*)<([^>]*)>/$1/g; 
     3085 
     3086            if ( $voicemailbox =~ m/\@/ ) { 
     3087                ( $voicemailboxnum, $voicemailboxcontext ) = split( /\@/, $voicemailbox, 2 ); 
     3088            } 
     3089            else { 
     3090                $voicemailboxnum     = $voicemailbox; 
     3091                $voicemailboxcontext = ""; 
     3092            } 
     3093            my $cnt = 0; 
     3094 
     3095            foreach my $auto (@auto_config) { 
     3096                my %tmphash = %$auto; 
     3097                if ( !defined( $tmphash{server} ) ) { $tmphash{server} = 1; } 
     3098                my $srv = $tmphash{server}; 
     3099                $srv--; 
     3100                my $match = $tmphash{channel_preserve_case}; 
     3101                $match =~ s/^AUTO\///g; 
     3102                if ( !defined( $hash_temporal{Server} ) ) { 
     3103                    $hash_temporal{Server} = 1; 
     3104                } 
     3105 
     3106                if ( $srv == $hash_temporal{Server} && "SIP/$chan_name" =~ m/$match/ ) { 
     3107                    while ( ( $key, $val ) = each(%tmphash) ) { 
     3108                        $val =~ s/\${CONTEXT}/$ctx/g; 
     3109                        $val =~ s/\${CALLERID}/$calid/g; 
     3110                        $val =~ s/\${CLIDNUM}/$calidnum/g; 
     3111                        $val =~ s/\${CLIDNAME}/$calidname/g; 
     3112                        $val =~ s/\${VOICEMAILBOX}/$voicemailbox/g; 
     3113                        $val =~ s/\${VOICEMAILBOXNUM}/$voicemailboxnum/g; 
     3114                        $val =~ s/\${VOICEMAILBOXCONTEXT}/$voicemailboxcontext/g; 
     3115                        $val =~ s/\${ACCOUNTCODE}/$accode/g; 
     3116                        $val =~ s/\${CHANNEL}/$chan_name/g; 
     3117                        $autosip{"$server^$chan_name"}{$key} = $val; 
     3118                    } 
     3119                    $autosip{"$server^$chan_name"}{channel}    = "SIP/$chan_name"; 
     3120                    $autosip{"$server^$chan_name"}{autonumber} = $cnt; 
     3121                    delete( $autosip{"$server^$chan_name"}{channel_preserve_case} ); 
     3122 
     3123                    delete( $autosip_detail{$acid} ); 
     3124                    my @quedan = keys(%autosip_detail); 
     3125 
     3126                    # AUTOSIP SUTOSIP 
     3127                    my $cuantos_quedan = @quedan; 
     3128                    if ( $cuantos_quedan == 0 ) { 
     3129 
     3130                        # Last autosip for each server, it is time to write variables 
     3131                        # for this kind 
     3132                        read_buttons_config(); 
     3133                        genera_config(); 
     3134                        send_initial_status( '', 1 ); 
     3135                    } 
     3136 
     3137                } 
     3138                $cnt++; 
     3139            } 
     3140        } 
     3141 
     3142    } 
     3143    elsif ( $evento eq "peerentry" ) { 
     3144 
     3145        #Event: PeerEntry 
     3146        #ActionID: autosip 
     3147        #Channeltype: SIP 
     3148        #ObjectName: nicocasa 
     3149        #ChanObjectType: peer 
     3150        #IPaddress: 1.2.3.4 
     3151        #IPport: 15540 
     3152        #Dynamic: yes 
     3153        #Natsupport: yes 
     3154        #ACL: no 
     3155        #Status: UNREACHABLE 
     3156 
     3157        if ( $hash_temporal{ActionID} eq "autosip" ) { 
     3158            my $peer = $hash_temporal{ObjectName}; 
     3159            $autosip{"$server^$peer"}{server} = $server; 
     3160        } 
     3161    } 
     3162    elsif ( $evento eq "agentcalled" ) { 
    27133163 
    27143164        # We use this event to send the ringing state for an Agent 
     
    27193169        $clidnum  = $hash_temporal{"CallerID"}; 
    27203170        $clidname = $hash_temporal{"CallerIDName"}; 
    2721         $texto    = "&incoming,[" . format_clid( $clidnum, $clid_format ) . "]"; 
     3171        $texto    = "&incoming,[" . format_clid( $clidnum, $clidname, $clid_format ) . "]"; 
    27223172        my $base64_clidnum  = encode_base64( $clidnum . " " ); 
    27233173        my $base64_clidname = encode_base64( $clidname . " " ); 
     
    27273177        $evento = ""; 
    27283178    } 
    2729  
    2730     if ( $evento eq "agentconnect" ) { 
     3179    elsif ( $evento eq "agentconnect" ) { 
    27313180 
    27323181        # We use this event to fake the ringing state 
    27333182        $estado_final = "ocupado"; 
    2734         $texto        = "Taking call from $hash_temporal{\"Queue\"}"
     3183        $texto        = "Taking call from " . $hash_temporal{Queue}
    27353184        $canal        = $hash_temporal{"Channel"}; 
    27363185        $canal =~ tr/a-z/A-Z/; 
    27373186        $canalid = $canal . "-XXXX"; 
    2738         push @return, "$canal|$estado_final|$texto|$canalid-$server|$canalid";    #NEW 
     3187        push @return, "$canal|$estado_final|$texto|$canalid-$server|$canalid";                     #NEW 
     3188        push @return, "$canal|agentconnect|$hash_temporal{Uniqueid}|$canalid-$server|$canalid";    #NEW 
     3189 
     3190        my $member     = $hash_temporal{Member}; 
     3191        my $queue      = $hash_temporal{Queue}; 
     3192        my @respuestas = set_queueobject( $server, $member, "status", 2 ); 
     3193        foreach (@respuestas) { 
     3194            push @return, $_; 
     3195        } 
     3196 
    27393197        $evento = ""; 
    27403198    } 
    2741  
    2742     if ( $evento eq "dial" ) { 
     3199    elsif ( $evento eq "dial" ) { 
    27433200 
    27443201        # We use this hashes to store the remote callerid for CVS-HEAD 
     
    27503207        $remote_callerid_name{$key} = $hash_temporal{"CallerIDName"}; 
    27513208 
    2752         # We also look for Dial from Local/XX@context to TECH/XX for 
    2753         # matching agentcallbacklogins exten@context to real channels 
    2754         # so we can map outgoing calls to Agent buttons 
    2755         # It will only work after the agent receives at least one call 
    2756         ( $dorigen,  $dnada ) = separate_session_from_channel( $hash_temporal{'Source'} ); 
    2757         ( $ddestino, $dnada ) = separate_session_from_channel( $hash_temporal{'Destination'} ); 
    2758         if ( exists( $channel_to_agent{"$server^$dorigen"} ) ) { 
    2759             my $agente = $channel_to_agent{"$server^$dorigen"}; 
    2760  
    2761             # delete $channel_to_agent{$dorigen}; 
    2762             $channel_to_agent{"$server^$ddestino"} = $agente; 
    2763         } 
    2764     } 
    2765  
    2766     if ( $evento eq "zapdndstate" ) { 
     3209        if ( $hash_temporal{'Source'} =~ m/^Local/i ) { 
     3210 
     3211            # We also look for Dial from Local/XX@context to TECH/XX for 
     3212            # matching agentcallbacklogins exten@context to real channels 
     3213            # so we can map outgoing calls to Agent buttons 
     3214            # It will only work after the agent receives at least one call 
     3215            ( $dorigen,  $dnada ) = separate_session_from_channel( $hash_temporal{'Source'} ); 
     3216            ( $ddestino, $dnada ) = separate_session_from_channel( $hash_temporal{'Destination'} ); 
     3217            if ( exists( $channel_to_agent{"$server^$dorigen"} ) ) { 
     3218                my $agente = $channel_to_agent{"$server^$dorigen"}; 
     3219 
     3220                # delete $channel_to_agent{$dorigen}; 
     3221                $channel_to_agent{"$server^$ddestino"} = $agente; 
     3222            } 
     3223        } 
     3224    } 
     3225    elsif ( $evento eq "zapdndstate" ) { 
     3226 
    27673227        $canal = $hash_temporal{"Channel"}; 
    27683228        my $zstatus = ""; 
     
    27913251 
    27923252        $evento = ""; 
    2793     } 
    2794  
    2795     if ( $evento eq "astdb" ) { 
     3253 
     3254    } 
     3255    elsif ( $evento eq "astdb" ) { 
     3256 
    27963257        my $valor = ""; 
    27973258        $estado_final = "astdb"; 
     
    27993260        $canalid = $hash_temporal{"Channel"} . "-XXXX"; 
    28003261        my $clave = $hash_temporal{"Family"}; 
    2801         if ( !defined( $hash_temporal{"State"} ) ) { 
     3262        if ( !defined( $hash_temporal{"Value"} ) ) { 
    28023263            $valor = ""; 
    28033264        } 
    28043265        else { 
    2805             $valor = $hash_temporal{"State"}; 
     3266            $valor = $hash_temporal{"Value"}; 
    28063267        } 
    28073268 
    28083269        foreach my $item ( @{ $astdbcommands{$clave} } ) { 
    28093270            my $item_temp = $item; 
     3271            my $datoon    = ""; 
     3272            my $datooff   = ""; 
    28103273            $item_temp =~ s/\${value}/$valor/g; 
    28113274            my ( $comando, $datos ) = split( /=/, $item_temp ); 
     3275            if ( $datos =~ /\|/ ) { 
     3276                ( $datoon, $datooff ) = split( /\|/, $datos ); 
     3277            } 
     3278            else { 
     3279                $datoon  = $datos; 
     3280                $datooff = ""; 
     3281            } 
     3282 
    28123283            if ( $valor ne "" ) { 
    2813                 push @return, "$canal|$comando|$datos|$canalid-$server|$canalid"; 
     3284                push @return, "$canal|$comando|$datoon|$canalid-$server|$canalid"; 
    28143285            } 
    28153286            else { 
    2816                 push @return, "$canal|$comando||$canalid-$server|$canalid"; 
     3287                push @return, "$canal|$comando|$datooff|$canalid-$server|$canalid"; 
    28173288            } 
    28183289        } 
    28193290        $evento = ""; 
    28203291    } 
    2821  
    2822     if ( $evento eq "timeout" ) { 
     3292    elsif ( $evento eq "timeout" ) { 
    28233293        $estado_final = "timeout"; 
    28243294        $texto        = $timeout; 
     
    28303300        $evento = ""; 
    28313301    } 
    2832  
    2833     if ( $evento eq "regstatus" ) { 
     3302    elsif ( $evento eq "regstatus" ) { 
    28343303 
    28353304        # Sends the IP address of the peer to the flash client 
     
    28493318        } 
    28503319    } 
    2851  
    2852     if ( $evento eq "fopledcolor" ) { 
     3320    elsif ( $evento eq "fopledcolor" ) { 
    28533321        my $color = ""; 
    28543322        my $state = ""; 
     
    28603328        $evento = ""; 
    28613329    } 
    2862  
    2863     if ( $evento eq "foppopup" ) { 
     3330    elsif ( $evento eq "foppopup" ) { 
    28643331        ( $canal, my $nada ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
    28653332        my $url    = $hash_temporal{"URL"}; 
     
    28723339        $evento = ""; 
    28733340    } 
    2874  
    2875     if ( $evento eq "refreshqueue" ) { 
     3341    elsif ( $evento eq "refreshqueue" ) { 
    28763342        ( $canal, my $nada ) = separate_session_from_channel( $hash_temporal{"Channel"} ); 
    28773343 
     
    28843350        $evento = ""; 
    28853351    } 
    2886  
    2887     if ( $evento eq "agentcblogin" ) { 
     3352    elsif ( $evento eq "agentcblogin" ) { 
    28883353        my $canal      = ""; 
    28893354        my $canallocal = ""; 
     
    28933358        if ( $canalid eq "" ) { 
    28943359            $canalid = "Agent/$texto-XXXX"; 
     3360        } 
     3361        my @respuestas = set_queueobject( $server, "AGENT/$texto", "status", 1 ); 
     3362        foreach (@respuestas) { 
     3363            push @return, $_; 
    28953364        } 
    28963365 
     
    29643433            $agent_to_channel{"$server^Agent/$texto"} = $canal; 
    29653434 
    2966             print_agents(); 
    2967  
    29683435            $estado_final = "changelabel" . $change_led; 
    29693436            if ( $ren_cbacklogin == 1 ) { 
     
    30003467        $evento = ""; 
    30013468    } 
    3002  
    3003     if ( $evento eq "queuememberpaused" && $agent_status == 1 ) { 
     3469    elsif ( $evento eq "queuememberpaused" && $agent_status == 1 ) { 
    30043470        my $canal   = $hash_temporal{Location}; 
    3005         my $cola    = $hash_temporal{Queue}; 
    30063471        my $canalid = $canal . "-XXXX"; 
    30073472 
     
    30233488 
    30243489        my $color = ""; 
    3025         if ( $hash_temporal{Paused} eq "1" ) { 
     3490        if ( $hash_temporal{Paused} ne "0" ) { 
    30263491            my ( $text, $textriginal, $buttontext ) = translate( $canal, "&paused", "", "" ); 
    30273492            $texto = $text; 
     
    30343499            $texto = "&idle"; 
    30353500            $color = "ledcolor_agent"; 
     3501        } 
     3502        my $canset = ""; 
     3503        $canset = uc($canal); 
     3504        my @respuestas = set_queueobject( $server, $canset, "paused", $hash_temporal{Paused} ); 
     3505        foreach my $item (@respuestas) { 
     3506            push @return, $item; 
    30363507        } 
    30373508        $boton_ip{$canalid} = $texto; 
     
    30413512        push @return, "$canal|fopledcolor|$color^2|$unico_id|$canalid"; 
    30423513        push @return, "$canal|state|free|$unico_id|$canalid"; 
     3514        push @return, "$canal|paused|$hash_temporal{Paused}|$unico_id|$canalid"; 
    30433515        $evento = ""; 
    30443516 
    30453517    } 
    3046  
    3047     if ( $evento eq "queuememberremoved" ) { 
    3048         my $cola  = $hash_temporal{Queue}; 
    3049         my $canal = $hash_temporal{Location}; 
     3518    elsif ( $evento eq "queuememberremoved" ) { 
     3519        my $colar      = $hash_temporal{Queue}; 
     3520        my $canal      = $hash_temporal{Location}; 
     3521        my @respuestas = delete_queueobject( $server, $colar, $canal ); 
     3522        foreach (@respuestas) { 
     3523            push @return, $_; 
     3524        } 
     3525 
    30503526        $fake_bloque[$fakecounter]{Event}   = "Agentlogoff"; 
    30513527        $fake_bloque[$fakecounter]{Channel} = $canal . "-XXXX"; 
    30523528        $fake_bloque[$fakecounter]{Agent}   = $canal; 
    3053         $fake_bloque[$fakecounter]{Queue}   = $cola
     3529        $fake_bloque[$fakecounter]{Queue}   = $colar
    30543530        $fake_bloque[$fakecounter]{Fake}    = "removed"; 
    30553531        $fake_bloque[$fakecounter]{Server}  = $hash_temporal{Server}; 
     
    30573533        $evento = ""; 
    30583534    } 
    3059  
    3060     if ( $evento eq "queuememberadded" ) { 
    3061  
    3062         my $cola  = $hash_temporal{Queue}; 
    3063         my $canal = $hash_temporal{Location}; 
     3535    elsif ( $evento eq "queuememberadded" ) { 
     3536 
     3537        my $colar      = $hash_temporal{Queue}; 
     3538        my $canal      = $hash_temporal{Location}; 
     3539        my @respuestas = add_queueobject( $server, $colar, $canal ); 
     3540        foreach (@respuestas) { 
     3541            push @return, $_; 
     3542        } 
    30643543 
    30653544        $fake_bloque[$fakecounter]{Event}   = "Agentlogin"; 
    30663545        $fake_bloque[$fakecounter]{Channel} = $canal . "-XXXX"; 
    30673546        $fake_bloque[$fakecounter]{Agent}   = $canal; 
    3068         $fake_bloque[$fakecounter]{Queue}   = $cola
     3547        $fake_bloque[$fakecounter]{Queue}   = $colar
    30693548        $fake_bloque[$fakecounter]{Server}  = $hash_temporal{Server}; 
    30703549        $fake_bloque[$fakecounter]{Addhash} = 1; 
     
    30853564 
    30863565    } 
    3087  
    3088     if ( $evento eq "agentlogin" ) { 
     3566    elsif ( $evento eq "agentlogin" ) { 
    30893567 
    30903568        my $labeltext = "."; 
     
    30993577            $agent_to_channel{"$server^Agent/$texto"} = $canalreal; 
    31003578            log_debug( "channel_to_agent($server^$canalreal) = " . $channel_to_agent{"$server^$canalreal"}, 64 ) if DEBUG; 
     3579            if ( !defined( $hash_temporal{Fake} ) || $hash_temporal{Fake} ne "init" ) { 
     3580                my @respuestas = set_queueobject( $server, "AGENT/$texto", "status", 1 ); 
     3581                foreach (@respuestas) { 
     3582                    push @return, $_; 
     3583                } 
     3584            } 
    31013585        } 
    31023586 
     
    32073691 
    32083692        if ( defined( $hash_temporal{Queue} ) ) { 
    3209             if ( keys(%count_queue) ) { 
     3693            if ( keys(%agents_available_on_queue) ) { 
    32103694                my $contaconta = 0; 
    32113695                my %temp_queue = (); 
    32123696                my $valor      = "$server^$hash_temporal{Queue}"; 
    32133697 
    3214                 push @{ $count_queue{$valor} }, "$server^$texto"; 
     3698                push @{ $agents_available_on_queue{$valor} }, "$server^$texto"; 
    32153699 
    32163700                my %count; 
    3217                 my @unique_queues = grep { ++$count{$_} < 2 } @{ $count_queue{$valor} }; 
    3218                 @{ $count_queue{$valor} } = @unique_queues; 
    3219  
    3220                 if ( exists( $count_queue{$valor} ) && $count_queue{$valor} ne "" ) { 
     3701                my @unique_queues = grep { ++$count{$_} < 2 } @{ $agents_available_on_queue{$valor} }; 
     3702                @{ $agents_available_on_queue{$valor} } = @unique_queues; 
     3703 
     3704                if ( exists( $agents_available_on_queue{$valor} ) && $agents_available_on_queue{$valor} ne "" ) { 
    32213705                    my $texto3 = ""; 
    3222                     foreach my $qmem ( @{ $count_queue{$valor} } ) { 
     3706                    foreach my $qmem ( @{ $agents_available_on_queue{$valor} } ) { 
    32233707                        $texto3 .= "$qmem\n"; 
    32243708                    } 
    3225                     $contaconta = @{ $count_queue{$valor} }; 
     3709                    $contaconta = @{ $agents_available_on_queue{$valor} }; 
    32263710                    my $texto2 = "Agents Logged: $contaconta\n" . $texto3 . "  "; 
    32273711                    $texto2 = encode_base64($texto2); 
     
    32323716        } 
    32333717    } 
    3234  
    3235     if ( $evento eq "agentlogoff" ) { 
     3718    elsif ( $evento eq "agentlogoff" ) { 
    32363719 
    32373720        $canal = "Agent/" . $hash_temporal{Agent}; 
     
    32403723        } 
    32413724 
     3725        if ( !defined( $hash_temporal{Fake} ) || $hash_temporal{Fake} ne "init" ) { 
     3726            my @respuestas = set_queueobject( $server, "AGENT/$canal", "status", 5 ); 
     3727            foreach (@respuestas) { 
     3728                push @return, $_; 
     3729            } 
     3730        } 
     3731 
    32423732        my $texto = $hash_temporal{Agent}; 
    32433733        $canalid = $canal . "-XXXX"; 
     
    32483738            if ( defined( $agent_to_channel{"$server^Agent/$canal"} ) || defined( $channel_to_agent{"$server^$canal"} ) ) { 
    32493739                if ( defined( $agent_to_channel{"$server^Agent/$canal"} ) ) { 
    3250  
    3251                     #                    ( $canal, my $nada ) = separate_session_from_channel( $agent_to_channel{"$server^Agent/$canal"} ); 
    32523740                    $canal = $agent_to_channel{"$server^Agent/$canal"}; 
    32533741                } 
    32543742                else { 
    3255  
    3256                     #                    ( $canal, my $nada ) = separate_session_from_channel( $channel_to_agent{"$server^$canal"} ); 
    32573743                    $canal = $channel_to_agent{"$server^$canal"}; 
    32583744                } 
     
    32663752                } 
    32673753 
    3268                 #delete $agent_to_channel{"$server^$canal"}; 
    3269                 #delete $agent_to_channel{"$server^$agente"}; 
    32703754                delete $reverse_agents{$texto}; 
    32713755                delete $reverse_agents{$canal}; 
     
    33063790        delete( $is_agent{ uc("$server^$texto") } ); 
    33073791 
    3308         if ( keys(%count_queue) ) { 
    3309             print_countqueue("agentlogoff principio count_queue"); 
     3792        if ( keys(%agents_available_on_queue) ) { 
     3793            print_countqueue("agentlogoff principio agents_available_on_queue"); 
    33103794            my $contaconta = 0; 
    33113795            my %temp_queue = (); 
    33123796            my $valor      = ""; 
    3313             foreach $valor ( sort ( keys(%count_queue) ) ) { 
    3314                 foreach my $vvalor ( @{ $count_queue{$valor} } ) { 
     3797            foreach $valor ( sort ( keys(%agents_available_on_queue) ) ) { 
     3798                foreach my $vvalor ( @{ $agents_available_on_queue{$valor} } ) { 
    33153799                    if ( $vvalor !~ /^$server\^$canal$/i && $vvalor !~ /^$server\^AGENT\/$texto$/i ) { 
    33163800                        push @{ $temp_queue{$valor} }, $vvalor; 
     
    33213805                } 
    33223806            } 
    3323             %count_queue = %temp_queue; 
     3807            %agents_available_on_queue = %temp_queue; 
    33243808            if ( defined( $hash_temporal{Queue} ) ) { 
    33253809                $valor = $hash_temporal{Queue}; 
    3326                 if ( exists( $count_queue{"$server^$valor"} ) && $count_queue{"$server^$valor"} ne "" ) { 
     3810                if ( exists( $agents_available_on_queue{"$server^$valor"} ) && $agents_available_on_queue{"$server^$valor"} ne "" ) { 
    33273811                    my $texto3 = ""; 
    3328                     foreach my $qmem ( @{ $count_queue{"$server^$valor"} } ) { 
     3812                    foreach my $qmem ( @{ $agents_available_on_queue{"$server^$valor"} } ) { 
    33293813                        $texto3 .= "$qmem\n"; 
    33303814                    } 
    3331                     $contaconta = @{ $count_queue{"$server^$valor"} }; 
     3815                    $contaconta = @{ $agents_available_on_queue{"$server^$valor"} }; 
    33323816                    my $texto2 = "Agents Logged: $contaconta\n" . $texto3 . "  "; 
    33333817                    $texto2 = encode_base64($texto2); 
     
    33393823 
    33403824    } 
    3341  
    3342     if ( $evento eq "queueentry" ) { 
     3825    elsif ( $evento eq "queueentry" ) { 
    33433826 
    33443827        if ( defined( $max_queue_waiting_time_for{"$hash_temporal{Queue}-$hash_temporal{Server}"} ) ) { 
     
    33643847        $fakecounter++; 
    33653848    } 
    3366  
    3367     if ( $evento eq "queuestatuscomplete" ) { 
     3849    elsif ( $evento eq "queuestatuscomplete" ) { 
    33683850        for my $cola_server ( keys %max_queue_waiting_time_for ) { 
    33693851            my ( $cola, $server ) = ( $cola_server =~ m/(.*)-(.*)/ ); 
     
    33773859        } 
    33783860        $evento = ""; 
    3379     } 
    3380  
    3381     if ( $evento eq "queuemember" || $evento eq "queuememberstatus" ) { 
     3861        my @respuestas = compute_queueobject($server); 
     3862        foreach (@respuestas) { 
     3863            push @return, $_; 
     3864        } 
     3865    } 
     3866    elsif ( $evento eq "queuemember" || $evento eq "queuememberstatus" ) { 
    33823867 
    33833868        my $canalag = $hash_temporal{"Location"}; 
     
    33873872        $canal = $hash_temporal{"Location"}; 
    33883873 
     3874        # $agent_status{$hash_temporal{Queue}}{$canalag}=$hash_temporal{Status}; XXXXXXXX NUEVO 
     3875 
    33893876        ( $server, $canal ) = local_channels_are_driving_me_mad( $server, $canal ); 
    33903877 
     
    34003887                    $fake_bloque[$fakecounter]{Agent}  = $temp; 
    34013888                    $fake_bloque[$fakecounter]{Server} = $server; 
    3402                     $fake_bloque[$fakecounter]{Fake}   = "1"; 
     3889                    $fake_bloque[$fakecounter]{Fake}   = "init"; 
    34033890                    $fakecounter++; 
    34043891 
     
    34113898                    $fake_bloque[$fakecounter]{Channel} = $canal . "-XXXX"; 
    34123899                    $fake_bloque[$fakecounter]{Agent}   = $canal; 
    3413                     $fake_bloque[$fakecounter]{Fake}    = "1"; 
     3900                    $fake_bloque[$fakecounter]{Fake}    = "init"; 
    34143901                    $fake_bloque[$fakecounter]{Server}  = $server; 
    34153902                    $fakecounter++; 
     
    34183905                } 
    34193906            } 
     3907 
     3908            if ( defined( $hash_temporal{Paused} ) ) { 
     3909                if ( $evento eq "queuemember" ) { 
     3910                    push @return, "$canalag|paused|$hash_temporal{Paused}|$unicoag_id|$canal-XXXX"; 
     3911                } 
     3912            } 
     3913 
    34203914        } 
    34213915 
     
    34263920            reserve_next_available_agent_button( $server, $canal, $hash_temporal{Queue} ); 
    34273921            $is_agent{ uc("$server^$canalag") } = 1; 
    3428  
    3429             #if ( $agent_status == 1 ) { 
    3430             #    if ( $hash_temporal{Paused} eq "1" ) { 
    3431             #        push @return, "$canal|settext|&paused|$unico_id|$canalid"; 
    3432             #        push @return, "$canal|settimer|0\@IDLE|$unico_id|$canalid"; 
    3433             #    } 
    3434             #    else { 
    3435             #        push @return, "$canal|settext|&idle|$unico_id|$canalid"; 
    3436             #        push @return, "$canal|settimer|0\@IDLE|$unico_id|$canalid"; 
    3437             #    } 
    3438             #} 
    3439  
    34403922        } 
    34413923        if ( $canal !~ /^Local/ ) { 
     
    34513933        while ( ( $key, $val ) = each(%hash_temporal) ) { 
    34523934            if ( !defined($val) ) { $val = " "; } 
    3453             $texto .= "$key = $val\n"; 
     3935 
     3936            # Status line changes from 1 to 0 on each ring and not taken call, generating 
     3937            # an event that we do not really need 
     3938            $texto .= "$key = $val\n" if ( $key ne "Status" ); 
    34543939            if ( $key eq "Status" && $val != 5 ) { 
    34553940                $estado_final .= $vval; 
    3456                 push @{ $count_queue{"$server^$vval"} }, "$server^$canal"; 
     3941                push @{ $agents_available_on_queue{"$server^$vval"} }, "$server^$canal"; 
    34573942                $has_status_ast_12 = 1; 
     3943            } 
     3944            if ( $key eq "Status" ) { 
     3945                $queue_object->{$server}->{$vval}->{$canal}->{status} = $val; 
     3946            } 
     3947            if ( $key eq "Paused" ) { 
     3948                $queue_object->{$server}->{$vval}->{$canal}->{paused} = $val; 
    34583949            } 
    34593950        } 
     
    34623953            # If there is no status on the events, is asterisk stable, count the agent in 
    34633954            $estado_final .= $vval; 
    3464             push @{ $count_queue{"$server^$vval"} }, "$server^$canal"; 
     3955            push @{ $agents_available_on_queue{"$server^$vval"} }, "$server^$canal"; 
    34653956        } 
    34663957        my %count; 
    3467         my @unique_queues = grep { ++$count{$_} < 2 } @{ $count_queue{"$server^$vval"} }; 
    3468         @{ $count_queue{"$server^$vval"} } = @unique_queues; 
    3469         $contaconta = @{ $count_queue{"$server^$vval"} }; 
     3958        my @unique_queues = grep { ++$count{$_} < 2 } @{ $agents_available_on_queue{"$server^$vval"} }; 
     3959        @{ $agents_available_on_queue{"$server^$vval"} } = @unique_queues; 
     3960        $contaconta = @{ $agents_available_on_queue{"$server^$vval"} }; 
    34703961 
    34713962        my $texto3 = ""; 
    3472         foreach my $qmem ( @{ $count_queue{"$server^$vval"} } ) { 
     3963        foreach my $qmem ( @{ $agents_available_on_queue{"$server^$vval"} } ) { 
    34733964            $texto3 .= "$qmem\n"; 
    34743965        } 
     
    34853976            push @return, "$canalag|$estado_final|$texto|$unicoag_id|$canalagid"; 
    34863977        } 
    3487         push @return, "QUEUE/" . uc( $hash_temporal{Queue} ) . "|infoqstat2|$texto2|$unico_id|$canalid"; 
     3978        if ( $evento eq "queuememberstatus" ) { 
     3979 
     3980            # for each member we sent a message to the queue, on initial status it would make 
     3981            # more sense to send the status at the end and not for  every queue member 
     3982            push @return, "QUEUE/" . uc( $hash_temporal{Queue} ) . "|infoqstat2|$texto2|$unico_id|$canalid"; 
     3983 
     3984            # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 
     3985        } 
    34883986 
    34893987        if ( $canal !~ /^Local/i && $canal !~ /^Agent/i && $evento eq "queuemember" ) { 
     
    35154013        $evento = ""; 
    35164014    } 
    3517  
    3518     if ( $evento eq "queuestatus" ) { 
     4015    elsif ( $evento eq "queuestatus" ) { 
    35194016        $canal   = $hash_temporal{Queue}; 
    35204017        $canalid = $canal . "-XXXX"; 
     
    35334030        $evento = ""; 
    35344031    } 
    3535  
    3536     if ( $evento eq "meetmemute" || $evento eq "meetmeunmute" ) { 
     4032    elsif ( $evento eq "meetmemute" || $evento eq "meetmeunmute" ) { 
    35374033        my ( $canal, $nada ) = separate_session_from_channel($canalid); 
    35384034        $estado_final = $evento; 
     
    35404036        $evento = ""; 
    35414037    } 
    3542  
    3543     if ( $evento eq "queueparams" ) { 
     4038    elsif ( $evento eq "queueparams" ) { 
    35444039        $canal = $hash_temporal{Queue}; 
    35454040        $canal =~ tr/a-z/A-Z/; 
     
    35664061        $evento = ""; 
    35674062    } 
    3568  
    3569     if ( $evento eq "join" ) { 
     4063    elsif ( $evento eq "join" ) { 
    35704064        my $qclidnum  = ""; 
    35714065        my $qclidname = ""; 
     
    36104104 
    36114105    } 
    3612  
    3613     if ( $evento eq "meetmejoin" ) { 
    3614         my $originate = "no"; 
    3615         my $nada      = ""; 
    3616         my $contexto  = ""; 
     4106    elsif ( $evento eq "meetmejoin" ) { 
     4107        my $originate        = "no"; 
     4108        my $mute_other_party = "no"; 
     4109        my $nada             = ""; 
     4110        my $contexto         = ""; 
    36174111 
    36184112        if ( $hash_temporal{Channel} =~ /^Local/ ) { 
     
    36324126 
    36334127        for $quehay ( keys %auto_conference ) { 
    3634  
    36354128            if ( $quehay eq $hash_temporal{Channel} ) { 
    36364129                $originate = $auto_conference{"$quehay"}; 
    36374130                $contexto  = $barge_context{$canal}; 
    36384131            } 
     4132        } 
     4133 
     4134        for $quehay ( keys %attendant_transfer ) { 
     4135            if ( $quehay eq $hash_temporal{Channel} ) { 
     4136                $originate        = $attendant_transfer{$quehay}; 
     4137                $mute_other_party = $mute_other{$quehay}; 
     4138                $contexto         = $barge_context{$canal}; 
     4139 
     4140                # delete mute_other($channel) and set it to mute_other(room) 
     4141                # so we can use that for redirecting when attendant_pending 
     4142                # hangs up. 
     4143                delete $mute_other{$quehay}; 
     4144                my $indice = $canal . "@" . $config->{$contexto}{'conference_context'}; 
     4145                $mute_other{$indice} = $mute_other_party; 
     4146            } 
     4147        } 
     4148 
     4149        my $callerid_attendant   = ""; 
     4150        my $callerid_attendant_n = ""; 
     4151        if ( $mute_other_party ne "no" ) { 
     4152            my $extendest = $canal; 
     4153            my $contedest = $config->{$contexto}{'conference_context'}; 
     4154 
     4155            if ( defined( $config->{$contexto}{'attendant_hold_extension'} ) ) { 
     4156                $extendest = $config->{$contexto}{'attendant_hold_extension'}; 
     4157            } 
     4158 
     4159            if ( defined( $config->{$contexto}{'attendant_hold_context'} ) ) { 
     4160                $contedest = $config->{$contexto}{'attendant_hold_context'}; 
     4161            } 
     4162 
     4163            log_debug( "** ATTENDANT Redirect $mute_other_party to MUSIC on HOLD extension", 16 ) if DEBUG; 
     4164            for $quehay ( keys %datos ) { 
     4165                if ( defined( $datos{$quehay}{Channel} ) ) { 
     4166                    if ( $datos{$quehay}{Channel} eq $mute_other_party ) { 
     4167                        $callerid_attendant   = $datos{$quehay}{CallerID}; 
     4168                        $callerid_attendant_n = $datos{$quehay}{CallerIDName}; 
     4169                    } 
     4170                } 
     4171            } 
     4172            my $comando = "Action: Redirect\r\n"; 
     4173            $comando .= "Channel: $mute_other_party\r\n"; 
     4174            $comando .= "Exten: " . $extendest . "\r\n"; 
     4175            $comando .= "Context: " . $contedest . "\r\n"; 
     4176            $comando .= "ActionID: 1234attendant\r\n"; 
     4177            $comando .= "Priority: 1\r\n\r\n"; 
     4178            send_command_to_manager( $comando, $socket, 0, $astmanproxy_server ); 
    36394179        } 
    36404180 
     
    36464186            $comando .= "Context: " . $config->{$contexto}{'conference_context'} . "\r\n"; 
    36474187            $comando .= "Priority: 1\r\n"; 
     4188            if ( $callerid_attendant ne "" ) { 
     4189                $comando .= "CallerID: $callerid_attendant_n <$callerid_attendant>\r\n"; 
     4190            } 
     4191            if ( $mute_other_party ne "no" ) { 
     4192                $comando .= "Async: True\r\n"; 
     4193                $comando .= "ActionID: attendant-$contexto\r\n"; 
     4194            } 
    36484195            $comando .= "\r\n"; 
    36494196            send_command_to_manager( $comando, $socket, 0, $astmanproxy_server ); 
    3650  
    3651             if ($barge_muted) { 
     4197            if ( $config->{$contexto}{barge_muted} && $mute_other_party eq "no" ) { 
    36524198                $start_muted{"$server^$originate"} = 1; 
    36534199            } 
     
    37264272        else { 
    37274273            print_datos(99); 
    3728             ( $qclidnum, $qclidname ) = split_callerid( $datos{$realunique}{CallerID} ); 
     4274            if ( defined( $datos{$realunique}{CallerID} ) ) { 
     4275                ( $qclidnum, $qclidname ) = split_callerid( $datos{$realunique}{CallerID} ); 
     4276            } 
     4277            else { 
     4278                $qclidnum  = ""; 
     4279                $qclidname = ""; 
     4280            } 
    37294281        } 
    37304282        my $texto_pos = "[$qclidnum]"; 
     
    37364288        push @return, "$canalfin|meetmeuser|$hash_temporal{Usernum},$hash_temporal{Meetme}|YYYY-$server|$hash_temporal{Channel}"; 
    37374289    } 
    3738  
    3739     if ( $evento eq "meetmeleave" ) { 
     4290    elsif ( $evento eq "meetmeleave" ) { 
    37404291        $canal = $hash_temporal{Meetme}; 
    37414292        $canal =~ tr/a-z/A-Z/; 
     
    37674318        push @return, "$canalfin|corto||$hash_temporal{Uniqueid}-$server|$canaleja"; 
    37684319    } 
    3769  
    3770     if ( $evento eq "leave" ) { 
     4320    elsif ( $evento eq "leave" ) { 
    37714321        $canal = "QUEUE/" . $hash_temporal{"Queue"}; 
    37724322        $canal =~ tr/a-z/A-Z/; 
     
    37874337        print_sesbot(2); 
    37884338    } 
    3789  
    3790     if ( $evento eq "voicemail" ) { 
     4339    elsif ( $evento eq "voicemail" ) { 
    37914340        my @canalesvoicemail = (); 
    37924341 
     
    38254374        $evento = ""; 
    38264375    } 
    3827  
    3828     if ( $evento eq "link" ) { 
     4376    elsif ( $evento eq "link" ) { 
    38294377        my $uniqueid1 = $hash_temporal{"Uniqueid1"}; 
    38304378        my $uniqueid2 = $hash_temporal{"Uniqueid2"}; 
     
    38464394 
    38474395        my $channel1conses = $channel1; 
    3848         if ( $channel1 !~ /${sesion1}$/ ) { 
     4396        if ( $channel1 !~ /${sesion1}$/ && $channel1 !~ /^mISDN/i ) { 
    38494397            $channel1conses = "$canal1-$sesion1"; 
    38504398        } 
    38514399 
    38524400        my $channel2conses = $channel2; 
    3853         if ( $channel2 !~ /${sesion2}$/ ) { 
     4401        if ( $channel2 !~ /${sesion2}$/ && $channel2 !~ /^mISDN/i ) { 
    38544402            my $channel2conses = "$canal2-$sesion2"; 
    38554403        } 
     
    38994447            $clid2 = $datos{$uniqueid1}{"CallerID"}; 
    39004448        } 
    3901         if ( $clid1 ne "" && $channel2 ne "" ) { 
    3902             my $clid_with_format = format_clid( $clid1, $clid_format ); 
    3903             push @return, "$canal1|settext|[$clid_with_format]|$uniqueid1|$channel1conses"; 
    3904         } 
    3905         if ( $clid2 ne "" && $channel1 ne "" ) { 
    3906             my $clid_with_format = format_clid( $clid2, $clid_format ); 
    3907             push @return, "$canal2|settext|[$clid_with_format]|$uniqueid2|$channel2conses"; 
    3908         } 
     4449        my $sclidname1 = ""; 
     4450        my $sclidname2 = ""; 
     4451 
     4452        if ( defined( $hash_temporal{Privilege} ) ) { 
     4453 
     4454            # Fake events do not have the Privilege set, so, do not send the settext 
     4455            # with callerid on fake link events. 
     4456            if ( $clid1 ne "" && $channel2 ne "" ) { 
     4457                $sclidname1 = $saved_clidname{"$server^$channel2"}; 
     4458                my $clid_with_format = format_clid( $clid1, $sclidname1, $clid_format ); 
     4459                push @return, "$canal1|setclid|$clid_with_format|$uniqueid1|$channel1conses"; 
     4460            } 
     4461            if ( $clid2 ne "" && $channel1 ne "" ) { 
     4462                $sclidname2 = $saved_clidname{"$server^$channel1"}; 
     4463                my $clid_with_format = format_clid( $clid2, $sclidname2, $clid_format ); 
     4464                push @return, "$canal2|setclid|$clid_with_format|$uniqueid2|$channel2conses"; 
     4465            } 
     4466        } 
     4467 
    39094468        push @return, "$canal1|setlink|$channel2|$uniqueid1|$channel1conses"; 
    39104469        push @return, "$canal2|setlink|$channel1|$uniqueid2|$channel2conses"; 
    39114470        $evento = "";    #NEW 
    39124471    } 
    3913  
    3914     if ( $evento eq "unlink" ) { 
     4472    elsif ( $evento eq "unlink" ) { 
    39154473        my $uniqueid1 = $hash_temporal{Uniqueid1}; 
    39164474        my $uniqueid2 = $hash_temporal{Uniqueid2}; 
     
    39564514        $evento = "";    #NEW 
    39574515    } 
    3958  
    3959     if ( $evento eq "rename" ) { 
     4516    elsif ( $evento eq "rename" ) { 
    39604517        my $nuevo_nombre = ""; 
    39614518        my $viejo_nombre = ""; 
     
    39784535        } 
    39794536 
    3980         # Directamente borra la sesion que se debe renombrar 
    3981         #if ( ( $nuevo_nombre !~ /</ ) && ( $viejo_nombre !~ /</ ) ) { 
    39824537        my @final = (); 
    39834538 
     
    40504605        $evento = "";    #NEW 
    40514606    } 
    4052  
    4053     if ( $evento eq "peerstatus" ) { 
     4607    elsif ( $evento eq "peerstatus" ) { 
    40544608        my $tiempo = 0; 
    40554609        $canal = $hash_temporal{Peer}; 
     
    40814635        $evento = ""; 
    40824636    } 
    4083  
    4084     if ( $evento eq "extensionstatus" ) { 
     4637    elsif ( $evento eq "extensionstatus" ) { 
    40854638        $canal = $hash_temporal{"Exten"}; 
    40864639        $canal =~ s/(\d+)/SCCP\/$1/g; 
     
    40974650        $evento = ""; 
    40984651    } 
    4099  
    4100     if ( $evento eq "status" ) { 
     4652    elsif ( $evento eq "status" ) { 
    41014653        $evento = ""; 
    41024654    } 
    4103  
    4104     if ( $evento eq "statuscomplete" ) { 
     4655    elsif ( $evento eq "statuscomplete" ) { 
    41054656 
    41064657        # When done with the status retrieval, generate events to send to 
     
    41964747        $evento = "";    #NEW (estaba comentado) 
    41974748    } 
    4198  
    4199     if ( $evento eq "fakeismeetmemember" ) { 
     4749    elsif ( $evento eq "fakeismeetmemember" ) { 
    42004750        my @bot1 = (); 
    42014751        my $bot2 = 0; 
    42024752        $estado_final = "meetmeuser"; 
    4203         $texto        = $hash_temporal{"Usernum"} . "," . $hash_temporal{"Meetme"}; 
    4204         my ( $chan1, $nada1 ) = separate_session_from_channel( $hash_temporal{'Channel'} ); 
    4205         push @return, "$hash_temporal{'Meetme'}|setlink|$hash_temporal{'Channel'}||$hash_temporal{'Channel'}"; 
    4206         push @return, "$chan1|setlink|$hash_temporal{'Meetme'}||$hash_temporal{'Channel'}"; 
    4207         $evento = "";    #NEW 
    4208     } 
    4209  
    4210     if ( $evento eq "newexten" ) { 
    4211  
    4212         # If its a new extension without state, defaults to 'Up' 
    4213         if ( !defined( $datos{$unico_id}{'State'} ) && $fill_datos ) { 
     4753        $texto        = $hash_temporal{Usernum} . "," . $hash_temporal{Meetme}; 
     4754        my ( $chan1, $nada1 ) = separate_session_from_channel( $hash_temporal{Channel} ); 
     4755        push @return, "$hash_temporal{Meetme}|setlink|$hash_temporal{Channel}||$hash_temporal{Channel}"; 
     4756        push @return, "$chan1|setlink|$hash_temporal{Meetme}||$hash_temporal{Channel}"; 
     4757        $evento = ""; 
     4758 
     4759    } 
     4760    elsif ( $evento eq "newexten" ) { 
     4761 
     4762        print "newexten\n"; 
     4763 
     4764        # If its a new extension without state and priority 1, defaults to 'Up' and set setlid 
     4765        if ( !defined( $datos{$unico_id}{'State'} ) && $hash_temporal{Priority} == 1 ) { 
    42144766            $datos{$unico_id}{'State'} = "Up"; 
    42154767            log_debug( "$heading POPULATES datos($unico_id){ State } = Up", 128 ) if DEBUG; 
     4768            ( $canal, $sesion ) = separate_session_from_channel( $hash_temporal{Channel} ); 
     4769            $texto        = $hash_temporal{Extension}; 
     4770      if($texto ne "s") { 
     4771              $estado_final = "setclid"; 
     4772      } 
     4773        } 
     4774        else { 
     4775            print "Newexten pero otro priority?\n"; 
    42164776        } 
    42174777 
     
    42264786            log_debug( "$heading NO EXISTE parked{$server^$canalid}", 128 ) if DEBUG; 
    42274787        } 
    4228     } 
    4229  
    4230     if ( $evento eq "hangup" ) { 
     4788 
     4789        if ( exists( $pending_uniqueid_attendant{ $hash_temporal{Uniqueid} } ) ) { 
     4790 
     4791            # This was from an originatesuccess for attendant transfers 
     4792            # so remove the hash element and add it to attendant_pending hash 
     4793            # that is used for look for hangups and perform redirects 
     4794 
     4795            $attendant_pending{ $hash_temporal{Channel} } = $pending_uniqueid_attendant{ $hash_temporal{Uniqueid} }; 
     4796            delete $pending_uniqueid_attendant{ $hash_temporal{Uniqueid} }; 
     4797            log_debug( "Save " . $hash_temporal{Channel} . " as pending", 16 ) if DEBUG; 
     4798        } 
     4799 
     4800 
     4801    } 
     4802    elsif ( $evento eq "hangup" ) { 
     4803 
     4804        # Look for attendant_pending and perform a redirect of the 
     4805        # hold channel to the same meetme room to complete the transfer 
     4806        my $canalid = $hash_temporal{Channel}; 
     4807        my $room    = ""; 
     4808        my @aborrar = (); 
     4809        foreach my $key ( keys %attendant_pending ) { 
     4810            if ( $canalid eq $key ) { 
     4811                $room = $attendant_pending{$key}; 
     4812                log_debug( "** ATTENDANT corto y pending coincide con $canalid! es = $room", 16 ) if DEBUG; 
     4813                last; 
     4814            } 
     4815        } 
     4816        if ( $room ne "" ) { 
     4817            push @aborrar, $canalid; 
     4818            while ( my ( $key, $val ) = each(%attendant_pending) ) { 
     4819                if ( $val eq $room ) { 
     4820                    push @aborrar, $key; 
     4821                } 
     4822            } 
     4823            foreach my $item (@aborrar) { 
     4824                log_debug( "** ATTENDANT borrando pending $item", 32 ) if DEBUG; 
     4825                delete $attendant_pending{$item}; 
     4826            } 
     4827            log_debug( "transfer " . $mute_other{$room} . " to meetme $room", 32 ) if DEBUG; 
     4828            my $eext = $room; 
     4829            my $ccnt = $room; 
     4830            $eext =~ s/(.*)\@(.*)/$1/g; 
     4831            $ccnt =~ s/(.*)\@(.*)/$2/g; 
     4832            my $comando = "Action: Redirect\r\n"; 
     4833            $comando .= "Channel: $mute_other{$room}\r\n"; 
     4834            $comando .= "Exten: $eext\r\n"; 
     4835            $comando .= "Context: $ccnt\r\n"; 
     4836            $comando .= "Priority: 10\r\n\r\n"; 
     4837            send_command_to_manager( $comando, $socket, 0, $astmanproxy_server ); 
     4838        } 
     4839        else { 
     4840            log_debug( "** ATTENDANT no room for pending", 32 ) if DEBUG; 
     4841        } 
     4842 
     4843        # End block for attendant pending 
     4844 
    42314845        if ( exists( $datos{$unico_id} ) ) { 
    42324846            $datos{$unico_id}{'State'} = "Down"; 
     4847            $hash_temporal{'State'} = "Down"; 
    42334848            log_debug( "$heading POPULATES datos($unico_id){ State } = down", 128 ) if DEBUG; 
    4234         } 
    4235         else { 
    4236             $hash_temporal{'State'} = "Down"; 
    42374849        } 
    42384850 
     
    42484860        } 
    42494861    } 
    4250  
    4251     if ( $evento eq "unparkedcall" ) { 
     4862    elsif ( $evento eq "unparkedcall" ) { 
    42524863        my $channel1 = $hash_temporal{"Channel"}; 
    42534864 
     
    42624873        } 
    42634874    } 
    4264  
    4265     if ( $evento eq "parkedcall" ) { 
     4875    elsif ( $evento eq "parkedcall" ) { 
    42664876        $texto        = "&parked," . $hash_temporal{'Exten'} . "&"; 
    42674877        $estado_final = "ocupado3"; 
     
    42854895        $evento = "";    #NEW 
    42864896    } 
    4287  
    4288     if ( $evento eq "newcallerid" ) { 
     4897    elsif ( $evento eq "newcallerid" ) { 
    42894898        $estado_final = "setstatus"; 
    42904899        $state        = "Newcallerid"; 
     
    43094918    # Dont check for $evento bellow this line! 
    43104919 
     4920    print "AFTER IF ELSE IF evento = $evento\n"; 
     4921 
    43114922    if ( $evento ne "" ) { 
    43124923        log_debug( "$heading Event $evento, canal '$canal'", 32 ) if DEBUG; 
     
    43634974            } 
    43644975 
    4365             if ( exists( $datos{$unico_id}{'State'} ) ) { 
    4366                 log_debug( "$heading EXISTE datos($unico_id){state}", 32 ) if DEBUG; 
    4367                 $state = $datos{$unico_id}{'State'}; 
    4368             } 
    4369  
    43704976            if ( exists( $datos{$unico_id}{'Callerid'} ) ) { 
    43714977                $clid = $datos{$unico_id}{'Callerid'}; 
     
    43955001        } 
    43965002 
     5003        # print "clidnum $clidnum clidname $clidname\n"; 
     5004 
    43975005        if ( $state eq "" ) { 
    43985006            if ( defined( $hash_temporal{'State'} ) ) { 
     
    44045012        } 
    44055013 
    4406         my $clid_with_format = format_clid( $clidnum, $clid_format ); 
     5014        my $clid_with_format = format_clid( $clidnum, $clidname, $clid_format ); 
    44075015 
    44085016        if ( $state eq "Ringing" ) { 
     
    44255033 
    44265034        if ( $state eq "Ring" ) { 
    4427             $texto                      = "&calling"; 
     5035            print "RING $canalid $texto\n"; 
     5036            $texto                      = $canalid; 
    44285037            $estado_final               = "ring"; 
    44295038            $datos{$unico_id}{'Origin'} = "true"; 
     
    45215130        my $exten_clid = ""; 
    45225131        if ( $state eq "Up" ) { 
     5132 
     5133            if ( defined( $hash_temporal{CallerIDName} ) ) { 
     5134                $saved_clidname{"$server^$hash_temporal{'Channel'}"} = $hash_temporal{CallerIDName}; 
     5135            } 
     5136 
    45235137            if ( $exten ne "" ) { 
    45245138                if ( is_number($exten) ) { 
    4525                     $exten_clid = format_clid( $exten, $clid_format ); 
     5139                    $exten_clid = format_clid( $exten, '', $clid_format ); 
    45265140                    if ( defined( $saved_clidnum{"$server^$canalid"} ) ) { 
    4527                         $exten_clid = format_clid( $saved_clidnum{"$server^$canalid"}, $clid_format ); 
     5141                        $exten_clid = format_clid( $saved_clidnum{"$server^$canalid"}, $saved_clidname{"$server^$canalid"}, $clid_format ); 
    45285142                    } 
    45295143                    if ($clid_privacy) { 
     
    45335147                } 
    45345148                else { 
    4535                     if ( length($exten) == 1 ) { 
    4536                         $conquien = $exten; 
    4537                         $exclude  = 1;        # We ignore events that have letter extensions 's', 'h', etc 
    4538                         $exclude  = 0;        # Do we? UserEvent fake events dont work if we ignore them 
    4539                         log_debug( "$heading CLID is not a number! $exten", 32 ) if DEBUG; 
     5149                    if ( defined( $saved_clidname{"$server^$hash_temporal{Channel}"} ) ) { 
     5150                        $clidname = $saved_clidname{"$server^$hash_temporal{Channel}"}; 
    45405151                    } 
    4541                     else
    4542                         $conquien = $exten
     5152                    if ( defined( $saved_clidnum{"$server^$hash_temporal{Channel}"} ) )
     5153                        $clidnum = $saved_clidnum{"$server^$hash_temporal{Channel}"}
    45435154                    } 
     5155                    $conquien = format_clid( $clidnum, $clidname, $clid_format ); 
     5156 
     5157                    #if ( length($exten) == 1 ) { 
     5158                    #    $conquien = $exten; 
     5159                    #    $exclude  = 1;        # We ignore events that have letter extensions 's', 'h', etc 
     5160                    #    $exclude  = 0;        # Do we? UserEvent fake events dont work if we ignore them 
     5161                    #    log_debug( "$heading CLID is not a number! $exten", 32 ) if DEBUG; 
     5162                    #} 
     5163                    #else { 
     5164                    #    $conquien = $exten; 
     5165                    #} 
    45445166                } 
    45455167            } 
     
    45625184                    } 
    45635185                    else { 
     5186                        if ( $exten_clid eq "" ) { $exten_clid = $conquien; } 
    45645187                        $texto = "&calling,[$exten_clid]"; 
    45655188                    } 
     
    46105233        my $local_channel = $canal; 
    46115234        $local_channel =~ s/Local\///gi; 
     5235        if ( $local_channel =~ m/\/n$/ ) { 
     5236            $local_channel = substr( $local_channel, 0, -2 ); 
     5237        } 
     5238 
    46125239        if ( defined( $extension_transfer_reverse{"$server^$local_channel"} ) ) { 
    46135240            if ( $extension_transfer_reverse{"$server^$local_channel"} !~ /\d+\^CLID/ ) { 
     
    46565283    my @mensajes           = (); 
    46575284    my $interno            = ""; 
    4658     my $todo               = ""; 
     5285    my $toda               = ""; 
    46595286    my @mensajefinal; 
    46605287    my $cuantas; 
     
    46685295 
    46695296    @fake_bloque = (); 
    4670     delete $datos{""}; 
     5297 
     5298    # delete $datos{""}; 
    46715299    foreach my $blaque (@blique) { 
    46725300 
     
    46895317                log_debug( "$heading GOT $mensaje", 32 ) if DEBUG; 
    46905318                delete $datos{""};    # Erase the hash with no uniqueid 
    4691                 ( $canal, $quehace, $dos, $uniqueid, $canalid ) = 
    4692                   split( /\|/, $mensaje ); 
     5319                ( $canal, $quehace, $dos, $uniqueid, $canalid ) = split( /\|/, $mensaje ); 
     5320 
     5321                $canalid =~ s/(.*),(\d)/$1/g;    # discard ,2 on Local channels 
    46935322 
    46945323                if ( !defined($dos) )     { $dos     = ""; } 
     
    47015330 
    47025331                if ( $dos eq "skip" ) { 
    4703                     log_debug( "$heading SALTEO $canal tiene skip", 32 ) if DEBUG; 
     5332                    log_debug( "$heading skipping $canal $quehace (has skip)", 32 ) if DEBUG; 
    47045333                    next; 
    47055334                } 
     5335 
    47065336                if ( $quehace eq "" ) { 
    4707                     log_debug( "$heading SALTEO $canal no tiene quehace", 32 ) if DEBUG; 
     5337                    log_debug( "$heading skipping $canal (empty quehace)", 32 ) if DEBUG; 
     5338          print "skip empty\n"; 
    47085339                    next; 
    47095340                } 
     
    47155346                log_debug( "$heading canalid:  $canalid",  32 ) if DEBUG; 
    47165347 
    4717                 #                if ( !defined($canal) )   { $canal   = ""; } 
    4718                 #                if ( !defined($quehace) ) { $quehace = ""; } 
    4719                 #                if ( !defined($dos) )     { $dos     = ""; } 
    4720  
    4721                 $canalid =~ s/\s+//g;    # Removes whitespace from CHANNEL-ID 
     5348                $canalid =~ s/\s+//g;            # Removes whitespace from CHANNEL-ID 
     5349                my $real_canal    = $canalid; 
    47225350                my $canalidzombie = $canalid;    # Removes whitespace from CHANNEL-ID 
    47235351                $canalid =~ s/(.*)<(.*)>/$1/g;   # discards ZOMBIE or MASQ 
     
    47475375                my $cuantos  = @canaleja; 
    47485376 
     5377        # Perform some pre processing... 
     5378 
    47495379                if ( $quehace eq "corto" || $quehace eq "info" ) { 
    47505380 
    47515381                    # We collect the last state of the channel on hangup 
     5382                    $toda = ""; 
    47525383                    while ( my ( $key, $val ) = each( %{ $datos{$uniqueid} } ) ) { 
    4753                         $todo .= "$key = $val\n" 
     5384                        $toda .= "$key = $val\n" 
    47545385                          if ( $key ne "E" ) && ( defined($val) ); 
    47555386                        log_debug( "$heading \tAgrego $key = $val", 128 ) if DEBUG; 
    47565387                    } 
    4757                     $todo .= " "; 
    4758                     $todo = encode_base64($todo); 
    4759  
    4760                     delete $datos{$uniqueid}; 
    4761                     delete $cola->{$canalidzombie}; 
     5388                    $toda .= " "; 
     5389                    $toda = encode_base64($toda); 
     5390 
     5391                    if ( $quehace eq "corto" ) { 
     5392                        delete $datos{$uniqueid}; 
     5393                    } 
     5394 
    47625395                    log_debug( "$heading erasing datos{$uniqueid}", 128 ) if DEBUG; 
    47635396 
     
    47695402                        erase_all_sessions_from_channel( $canalid, $canal, $server ); 
    47705403                    } 
    4771                 } 
    4772  
    4773                 if ( $quehace eq "queueremoved" ) { 
     5404 
     5405                } elsif ( $quehace eq "queueremoved" ) { 
    47745406 
    47755407                    # Remove the agent from the agents_on_queue hash 
     
    48145446                    } 
    48155447 
    4816                     if ( !defined( $buttons{"$server^$canal"} ) ) { 
    4817                         log_debug( "$heading \tNo tengo botones para $server^$canal, END FUNCTION", 128 ) if DEBUG; 
    4818                         for ( keys %buttons ) { 
    4819                             log_debug( "$heading \t\tKey $_", 128 ) if DEBUG; 
     5448                    if ( !defined( $buttons{"$server^$canal"} ) && !defined( $buttons{"-1^$canal"} ) ) { 
     5449                        log_debug( "$heading \tThere are no buttons for $server^$canal, skipping...", 128 ) if DEBUG; 
     5450                        if (DEBUG) { 
     5451                            for ( keys %buttons ) { 
     5452                                log_debug( "$heading \t\tKey $_", 128 ); 
     5453                            } 
    48205454                        } 
    48215455                        next; 
     
    48255459                    # except ocupado*, corto, setlink and unsetlink 
    48265460                    if ( $canal =~ /^_/ ) { 
    4827                         log_debug( "$heading canal $canal es un WILD y quehace vale $quehace", 32 ) if DEBUG; 
     5461                        log_debug( "$heading canal $canal is regexp, quehace value = $quehace", 32 ) if DEBUG; 
    48285462 
    48295463                        if (   $quehace =~ /registr/ 
     
    48315465                            || $quehace =~ /^inf/ ) 
    48325466                        { 
    4833                             log_debug( "$heading IGNORO $quehace porque es un wildcard", 32 ) if DEBUG; 
     5467                            log_debug( "$heading IGNORING $quehace because it is a regexp match", 32 ) if DEBUG; 
    48345468                            next; 
    48355469                        } 
     
    48395473                            && $quehace !~ /^state/ 
    48405474                            && $quehace !~ /^settext/ 
     5475                            && $quehace !~ /^setclid/ 
    48415476                            && $quehace !~ /^setlabel/ 
    48425477                            && $quehace !~ /^setlink/ 
     
    48565491                            my ( $canalsolo, $nrotrunk ) = split( /=/, $canal ); 
    48575492                            $canal = $canalsolo . "=1" . $elcontexto; 
    4858                             log_debug( "$heading quehace=$quehace, elijo el 1ero del trunk $canal", 32 ) if DEBUG; 
     5493                            log_debug( "$heading quehace=$quehace, select 1st from trunk $canal", 32 ) if DEBUG; 
    48595494 
    48605495                            #next; 
     
    48655500                        # change it so to not change the led color. 
    48665501                        if ( $quehace =~ /changelabel1/ ) { 
    4867                             log_debug( "$heading el wildcard tiene changelabel1, lo cambio por changelabel0!", 32 ) 
     5502                            log_debug( "$heading el regexp tiene changelabel1, lo cambio por changelabel0!", 32 ) 
    48685503                              if DEBUG; 
    48695504                            $quehace = "changelabel0"; 
     
    48715506                    } 
    48725507 
    4873                     if ( $canal ne "" ) { 
     5508                    my $serverindex = $server;    # Save the server in another var 
     5509 
     5510                    if ( $canal eq "" ) { 
     5511            # No channel? continue... 
     5512                        log_debug( "$heading There is no command defined", 32 ) if DEBUG; 
     5513 
     5514          } else { 
     5515 
     5516                        $interno = $buttons{"$server^$canal"}; 
     5517 
     5518                        if ( !defined($interno) ) { 
     5519                            $interno     = $buttons{"-1^$canal"}; 
     5520                            $serverindex = -1; 
     5521                            if ( $quehace !~ /regist/ ) { 
     5522                                $button_server{$interno} = $server; 
     5523                            } 
     5524                        } 
     5525 
     5526                        $interno = "" if ( !defined($interno) ); 
     5527 
     5528                        if ( $interno ne "" ) { 
     5529                            if ( defined( $clid_private{$interno} ) && $clid_private{$interno} == 1 ) { 
     5530                                if ( $dos =~ m/\[/ ) { 
     5531                                    $dos =~ s/([^\[]*)?(\[.*\])/$1 \[n\/a\]/g; 
     5532                                } 
     5533                            } 
     5534                        } 
     5535 
     5536            # The following block cleans internal op_server states. no matter if we 
     5537            # have a button defined or not. 
    48745538 
    48755539                        if ( $quehace eq 'corto' || $quehace eq 'info' ) { 
     
    48835547                                } 
    48845548                                else { 
    4885                                     $btnorinum = $buttons{"$server^$canaleje"}; 
     5549                                    $btnorinum = $buttons{"$serverindex^$canaleje"}; 
    48865550                                } 
    48875551                                log_debug( "$heading call GEN_LINKED 1", 32 ) if DEBUG; 
     
    48925556                            delete $datos{$uniqueid}; 
    48935557                            log_debug( "$heading REMOVING datos { $uniqueid }", 32 ) if DEBUG; 
    4894                         } 
    4895  
    4896                         if ( $quehace eq "setlink" ) { 
     5558 
     5559                        } elsif ( $quehace eq "setlink" ) { 
     5560 
    48975561                            log_debug( "$heading IF quehace = SETLINK", 32 ) if DEBUG; 
    48985562                            my ( $nada1, $contexto1 ) = split( /\&/, $canal ); 
     
    49185582                            } 
    49195583 
    4920                             #my %seen = (); 
    4921                             #my @uniq = 
    4922                             #  grep { !$seen{$_}++ } @{ $linkbot{"$server^$canal"} }; 
    4923                             #$linkbot{"$server^$canal"} = \@uniq; 
    49245584                            my @uniq = unique( @{ $linkbot{"$server^$canal"} } ); 
    49255585                            $linkbot{"$server^$canal"} = \@uniq; 
     
    49285588                                log_debug( "$heading linkbot ($server^$canal) = $valorad", 32 ) if DEBUG; 
    49295589                            } 
    4930                             my $btnorinum = $buttons{"$server^$canal"}; 
     5590                            my $btnorinum = $buttons{"$serverindex^$canal"}; 
    49315591                            log_debug( "$heading llamo a GENERATE_LINKED", 32 ) if DEBUG; 
    49325592                            $listabotones = generate_linked_buttons_list( $canal, $server ); 
     
    49355595                            log_debug( "$heading linkeado con $listabotones", 32 ) if DEBUG; 
    49365596                            log_debug( "$heading ENDIF quehace = SETLINK",    32 ) if DEBUG; 
    4937                         } 
    4938  
    4939                         if ( $quehace eq "unsetlink" ) { 
     5597 
     5598                        } elsif ( $quehace eq "unsetlink" ) { 
    49405599                            log_debug( "$heading IF quehace = UNSETLINK", 32 ) if DEBUG; 
    49415600                            my @final = (); 
     
    49475606                            $linkbot{"$server^$canal"} = [@final]; 
    49485607                            log_debug( "$heading ENDIF quehace = UNSETLINK", 32 ) if DEBUG; 
    4949                         } 
    4950  
    4951                         $interno = $buttons{"$server^$canal"}; 
    4952                         $interno = "" if ( !defined($interno) ); 
    4953  
    4954                         if ( $interno ne "" ) { 
    4955                             if ( defined( $clid_private{$interno} ) && $clid_private{$interno} == 1 ) { 
    4956                                 if ( $dos =~ m/\[/ ) { 
    4957                                     $dos =~ s/([^\[]*)?(\[.*\])/$1 \[n\/a\]/g; 
    4958                                 } 
    4959                             } 
    4960                         } 
    4961  
    4962                         if ( $quehace eq "queueremoved" ) { 
     5608 
     5609                        } elsif ( $quehace eq "queueremoved" ) { 
     5610 
    49635611                            delete $botonvoicemail{$interno}; 
    49645612                            delete $botonvoicemailcount{$interno}; 
     
    49755623                        } 
    49765624 
     5625            # Continue after cleaning internal state... 
    49775626                        if ( $interno eq "" ) { 
    4978                             log_debug( "$heading NO HAY INTERNO buttons($server^$canal), ABORTO", 32 ) if DEBUG; 
     5627                            log_debug( "$heading MISSING buttons($server^$canal), skipping...", 32 ) if DEBUG; 
    49795628                            next; 
    49805629                        } 
    4981                         log_debug( "$heading EL INTERNO es $interno", 32 ) if DEBUG; 
     5630                        else { 
     5631                            log_debug( "$heading INTERNO = $interno", 32 ) if DEBUG; 
     5632                        } 
    49825633 
    49835634                        if ( !defined( $laststatus{$interno} ) ) { 
     
    50015652                        # 
    50025653                        if ( $canalid eq "" || $canalid =~ /zombie/i || $canalid =~ /(.*)-XXXX$/ ) { 
    5003                             log_debug( "$heading ATENCION canalid es $canalid, NO PROCESAR?", 32 ) if DEBUG; 
     5654                            log_debug( "$heading ATENTION canalid = '$canalid', skipping...", 32 ) if DEBUG; 
    50045655                        } 
    50055656                        else { 
     
    50445695                                      if DEBUG; 
    50455696                                    &print_sesbot(3); 
     5697                                    &print_datos(1); 
     5698 
    50465699                                    if ( $laststatus{$interno} ne "busy|${buttontext}" ) { 
    50475700                                        $cambiaron{$interno} = 1; 
     
    50495702                                        push @respuestas, "$interno|state|busy"; 
    50505703 
    5051                                         # Justin from Fry's has prolems with callerid being cleared while a call is connected 
    5052                                         # from a queue using Local channels, so commnet these out 
    5053                                         #push @respuestas, "$interno|settext|"; 
    5054                                         #push @respuestas, "$interno|setstatus|"; 
    50555704                                        $laststatus{$interno} = "busy|${buttontext}"; 
    50565705 
     
    50595708                                          if DEBUG; 
    50605709                                    } 
    5061                                     $estadoboton{$interno} = "busy|${buttontext}"; 
     5710 
     5711                                    # Conserva el callerid anterior 
     5712                                    if ( defined( $preestadoboton{$interno} ) ) { 
     5713                                        $estadoboton{$interno} = $preestadoboton{$interno}; 
     5714                                        delete $preestadoboton{$interno}; 
     5715                                    } 
     5716                                    else { 
     5717                                        $estadoboton{$interno} = "busy|${buttontext}"; 
     5718                                    } 
     5719                                    my $stringy = $estadoboton{$interno}; 
     5720                                    $stringy =~ s/(.*)\|(.*)/$2/g; 
     5721                                    push @respuestas, "$interno|settext|$stringy"; 
    50625722                                } 
    50635723 
     
    51075767                                        $cambiaron{$interno} = 1; 
    51085768                                    } 
     5769                                    if ( $estadoboton{$interno} =~ /^busy/ ) { 
     5770 
     5771                                        # If we were busy before the ringing, save the callerid so we can restore it 
     5772                                        # if this call is not answered, discarded, or whatever. 
     5773                                        $preestadoboton{$interno} = $estadoboton{$interno}; 
     5774                                    } 
    51095775                                    $estadoboton{$interno} = "ringing|${buttontext}"; 
    51105776                                    if ( $dos =~ m/(.*)?\[(.*)\].*?/ ) { 
     
    51155781                                    # We dont want a timer when ringing - Local channels 
    51165782                                    # generate a previous state and timer 
    5117                                     push @mensajefinal, "$interno|settimer|0\@STOP"; 
     5783                                    ## push @mensajefinal, "$interno|settimer|0\@STOP"; 
    51185784 
    51195785                                } 
    51205786                                elsif ( $quehace =~ /^ocupado/ ) { 
     5787 
     5788                                    if ( defined( $group_count{$interno} ) ) { 
     5789                                        my $plural = ""; 
     5790                                        if ( $group_count{$interno} == 1 ) { 
     5791                                            if ( @{ $sesbot{$interno} } > 1 ) { 
     5792                                                $plural = "s"; 
     5793                                            } 
     5794                                            if ( @{ $sesbot{$interno} } > 0 ) { 
     5795                                                my $cuantos = @{ $sesbot{$interno} }; 
     5796                                                my ( $text, $textriginal, $buttontext ) = 
     5797                                                  translate( $canal, "&channels,$cuantos,$plural", "", "" ); 
     5798                                                $buttontext = $text; 
     5799                                                $dos        = "[" . $buttontext . "]"; 
     5800                                            } 
     5801                                        } 
     5802                                    } 
    51215803                                    if ( $laststatus{$interno} ne "busy|${buttontext}" ) { 
    51225804                                        $cambiaron{$interno} = 1; 
    51235805                                    } 
    51245806                                    $estadoboton{$interno} = "busy|${buttontext}"; 
     5807 
    51255808                                } 
    51265809                            } 
     
    51285811 
    51295812                        log_debug( "$heading Continuo proceso...", 32 ) if DEBUG; 
     5813             
    51305814                        if ( $quehace =~ /changelabel/ ) { 
    51315815                            log_debug( "$heading quehace = changelabel", 32 ) if DEBUG; 
     
    51575841                            } 
    51585842                            else { 
    5159                                 $botonled{$interno}   = $cambia_el_led; 
    5160                                 $botonlabel{$interno} = $dos; 
    5161                                 $agent_label{$canal}  = $dos; 
     5843                                $botonled{$interno} = $cambia_el_led; 
     5844                                if ( $ren_agentlogin || $ren_cbacklogin ) { 
     5845                                    $botonlabel{$interno} = $dos; 
     5846                                } 
     5847                                else { 
     5848                                    $botonlabel{$interno} = "."; 
     5849                                } 
     5850 
     5851                                $agent_label{$canal} = $dos; 
    51625852                            } 
    51635853 
    5164                         } 
    5165                         if ( $quehace eq "park" ) { 
     5854                        } elsif ( $quehace eq "park" ) { 
     5855 
    51665856                            log_debug( "$heading quehace = park", 32 ) if DEBUG; 
    51675857                            $dos =~ m/(.*)\((.*)\)/; 
     
    51705860                            $timeout = time() + $timeout; 
    51715861                            $botonpark{$interno} = "$texto|$timeout"; 
    5172                         } 
    5173                         if ( $quehace eq "meetmeuser" ) { 
     5862                        } elsif ( $quehace eq "meetmeuser" ) { 
    51745863                            $botonmeetme{$interno} = $dos; 
    5175                         } 
    5176  
    5177                         if ( $quehace eq "infoqstat" ) { 
     5864                        } elsif ( $quehace eq "infoqstat" ) { 
    51785865                            $botonqueue{$interno} = $dos; 
    5179                         } 
    5180                         elsif ( $quehace eq "infoqstat2" ) { 
     5866                        } elsif ( $quehace eq "infoqstat2" ) { 
    51815867                            $botonqueue_count{$interno} = $dos; 
    5182                         } 
    5183                         elsif ( $quehace =~ /info/ ) { 
     5868                        } elsif ( $quehace =~ /info/ ) { 
    51845869                            my $mcola = $quehace; 
    51855870                            $mcola =~ s/^info//g; 
    5186                             push @{ $botonqueuemember{$interno} }, "$mcola|$dos"; 
    5187                         } 
    5188  
    5189                         if ( $quehace eq "settext" ) { 
    5190                             $botonclid{$interno} = $dos; 
    5191                             push @respuestas, "$interno|settext|$dos"; 
    5192                         } 
    5193                         if ( $quehace eq "setalpha" ) { 
     5871                            my $estaba   = 0; 
     5872                            my @newarray = (); 
     5873                            foreach my $val ( @{ $botonqueuemember{$interno} } ) { 
     5874                                if ( $val =~ /^$mcola\|/ ) { 
     5875                                    if ( $val eq "$mcola|$dos" ) { 
     5876                                        $estaba  = 1; 
     5877                                        $quehace = ""; 
     5878                                    } 
     5879                                } 
     5880                                else { 
     5881                                    push @newarray, $val; 
     5882                                } 
     5883                            } 
     5884                            @{ $botonqueuemember{$interno} } = @newarray; 
     5885                            if ( $estaba == 0 ) { 
     5886                                push @{ $botonqueuemember{$interno} }, "$mcola|$dos"; 
     5887                            } 
     5888 
     5889                        } elsif ( $quehace eq "setclid" ) { 
     5890                            if ( !defined( $group_count{$interno} ) ) { 
     5891                                push @respuestas, "$interno|settext|$dos"; 
     5892                            } 
     5893                        } elsif ( $quehace eq "settext" ) { 
     5894                            if ( !defined( $group_count{$interno} ) ) { 
     5895                                $botonpermanenttext{$interno} = $dos; 
     5896                                print "vino settext a digest permanent $interno = -$dos-\n"; 
     5897                                push @respuestas, "$interno|settext|$dos"; 
     5898                            } 
     5899                        } elsif ( $quehace eq "fopledcolor" ) { 
     5900                            $botonledcolor{$interno} = $dos; 
     5901                        } elsif ( $quehace eq "setalpha" ) { 
    51945902                            $botonalpha{$interno} = $dos; 
    51955903                            push @respuestas, "$interno|setalpha|$dos"; 
    5196                         } 
    5197                         if ( $quehace eq "flip" ) { 
     5904                        } elsif ( $quehace eq "flip" ) { 
    51985905                            push @respuestas, "$interno|flip|$dos"; 
    5199                         } 
    5200                         if ( $quehace eq "setlabel" ) { 
     5906                        } elsif ( $quehace eq "setlabel" ) { 
    52015907                            if (   $dos ne "." 
    52025908                                && $dos ne "original" 
     
    52065912                                push @respuestas, "$interno|setlabel|$dos"; 
    52075913                            } 
    5208                         } 
    5209                         if ( $quehace eq "voicemail" ) { 
     5914                        } elsif ( $quehace eq "voicemail" ) { 
    52105915                            $botonvoicemail{$interno} = $dos; 
    5211                         } 
    5212                         if ( $quehace eq "voicemailcount" ) { 
     5916                        } elsif ( $quehace eq "voicemailcount" ) { 
    52135917                            $botonvoicemailcount{$interno} = $dos; 
     5918                        } elsif ( $quehace =~ "^voicemail" ) { 
     5919 
     5920                            # This block is for the voicemail client 
     5921                            my $canalsincontexto = $canal; 
     5922                            $canalsincontexto =~ s/(.*)&(.*)/$1/g; 
     5923                            push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|$dos"; 
     5924                        } elsif ( $quehace =~ "^ringing" ) { 
     5925 
     5926                            # This block is for the voicemail client, popups 
     5927                            my $canalsincontexto = $canal; 
     5928                            $canalsincontexto =~ s/(.*)&(.*)/$1/g; 
     5929                            my $calleridpop = $dos; 
     5930                            $calleridpop =~ s/(.*)\Q[\E(.*)/$2/g; 
     5931                            $calleridpop =~ s/\]//g; 
     5932                            $calleridpop =~ s/\s+//g; 
     5933                            push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|$calleridpop"; 
    52145934                        } 
    52155935 
     
    52375957                        else { 
    52385958 
    5239                             # This block is for the voicemail client 
    5240                             if ( $quehace =~ "^voicemail" ) { 
    5241                                 my $canalsincontexto = $canal; 
    5242                                 $canalsincontexto =~ s/(.*)&(.*)/$1/g; 
    5243                                 push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|$dos"; 
    5244                             } 
    5245  
    5246                             # This block is for the voicemail client, popups 
    5247                             if ( $quehace =~ "^ringing" ) { 
    5248                                 my $canalsincontexto = $canal; 
    5249                                 $canalsincontexto =~ s/(.*)&(.*)/$1/g; 
    5250                                 my $calleridpop = $dos; 
    5251                                 $calleridpop =~ s/(.*)\Q[\E(.*)/$2/g; 
    5252                                 $calleridpop =~ s/\]//g; 
    5253                                 $calleridpop =~ s/\s+//g; 
    5254                                 push @mensajefinal, "$canalsincontexto\@$canalsincontexto|$quehace|$calleridpop"; 
    5255                             } 
    52565959                            if ( $quehace eq "corto" ) { 
    52575960                                my $canalsincontexto = $canal; 
     
    52895992                                    $canalag = "Agent/" . $canalag; 
    52905993                                } 
    5291                                 print_agents(); 
    52925994 
    52935995                                my %temp_channel_to_agent = %channel_to_agent; 
     
    53136015                                delete $botontimer{$interno}; 
    53146016                                delete $botontimertype{$interno}; 
     6017                                delete $sesbot{$interno};    # Delete all sessions for agentlogoff XXXXXXX ???? 
    53156018                            } 
    53166019 
    5317                             if ( $quehace2 !~ /isagent/ && $quehace2 !~ /^agentlogoff/ ) { 
     6020                            if ( $quehace2 !~ /isagent/ && $quehace2 !~ /^agentlogoff/ && $quehace2 !~ /^setclid/ ) { 
    53186021                                log_debug( "$heading pushing respuestas $interno|$quehace2|$dos", 32 ) if DEBUG; 
    53196022 
     
    53226025                                # "isagent". "agentlogoff" 
    53236026                                # everything else is pushed 
    5324                                 push @respuestas, "$interno|$quehace2|$dos"; 
     6027                                if ( defined( $group_count{$interno} ) && $quehace2 eq "setclid" ) { 
     6028                                    log_debug( "$heading skip settext because groupcount is set", 32 ) if DEBUG; 
     6029                                } 
     6030                                else { 
     6031                                    if ( $quehace2 ne "" ) { 
     6032                                        push @respuestas, "$interno|$quehace2|$dos"; 
     6033                    print "push $quehace2 en $interno quehace2\n"; 
     6034                                    } 
     6035                                } 
    53256036                            } 
    53266037 
     
    53556066                                } 
    53566067                            } 
     6068                            if ( $quehace eq "ocupado1" ) { 
     6069                                push @mensajefinal, "$interno|channel|$canalid"; 
     6070                            } 
    53576071                            if ( $quehace2 eq "ring" ) { 
    53586072                                push @mensajefinal, "$interno|state|busy"; 
    5359  
    5360                                 #push @mensajefinal, "$interno|settext|$dos"; 
    53616073                            } 
    53626074                            if ( $quehace2 =~ /corto/ ) { 
     
    53996111                                    my $valip = ""; 
    54006112                                    log_debug( "$heading quehace2 corto, no es agente, pongo timer en cero", 1 ) if DEBUG; 
    5401                                     print_agents(); 
    54026113 
    54036114                                    push @mensajefinal, "$interno|settimer|0\@STOP"; 
     
    54086119                                    } 
    54096120                                    else { 
     6121                                        if ( defined( $botonpermanenttext{$interno} ) ) { 
     6122                                            push @mensajefinal, "$interno|settext|$botonpermanenttext{$interno}"; 
     6123                                            print "corto! permanent $interno = -$dos-\n"; 
     6124 
     6125                                            #$botonpermanenttext{$interno} = $dos; 
     6126                                        } 
    54106127                                        $botonclid{$interno} = ""; 
     6128 
    54116129                                    } 
    54126130 
     
    54346152                            } 
    54356153 
     6154                            if ( $quehace eq "paused" ) { 
     6155                                $boton_paused{$interno} = $dos; 
     6156                            } 
     6157                            if ( $quehace eq "agents_paused" ) { 
     6158                                $boton_agentpaused{$interno} = $dos; 
     6159                            } 
     6160                            if ( $quehace eq "agents_ready" ) { 
     6161                                $boton_agentready{$interno} = $dos; 
     6162                            } 
     6163                            if ( $quehace eq "agents_busy" ) { 
     6164                                $boton_agentbusy{$interno} = $dos; 
     6165                            } 
     6166                            if ( $quehace eq "agents_logedof" ) { 
     6167                                $boton_agentlogedof{$interno} = $dos; 
     6168                            } 
     6169 
    54366170                            log_debug( "$heading Agrego mensaje final $interno|$quehace2|$dos", 32 ) if DEBUG; 
    54376171 
     
    54586192                                    } 
    54596193                                } 
    5460                                 if ( $todo ne "" ) { 
    5461                                     my $otromensajefinal = "$interno|info|$todo"; 
     6194                                if ( $toda ne "" ) { 
     6195                                    my $otromensajefinal = "$interno|info|$toda"; 
    54626196                                    push( @respuestas, $otromensajefinal ); 
     6197                                    $toda = ""; 
    54636198                                } 
    54646199                            } 
     
    54666201 
    54676202                        $laststatus{$interno} = $estadoboton{$interno}; 
    5468                     } 
    5469                     else {    # endif canal distinto de nada 
    5470                         log_debug( "$heading There is no command defined", 32 ) if DEBUG; 
    54716203                    } 
    54726204                } 
     
    55496281 
    55506282sub clean_inmemory_state_for_server { 
     6283 
    55516284    my $server = shift; 
    55526285    my @botones_a_limpiar; 
     
    55676300        delete $botonvoicemailcount{$_}; 
    55686301        delete $botonalpha{$_}; 
     6302        delete $botonledcolor{$_}; 
    55696303        delete $botonqueue{$_}; 
    55706304        delete $botonqueuemember{$_}; 
     
    56566390    } 
    56576391 
    5658     # Adds AMI handles into IO::Select 
     6392    # Add AMI handles into IO::Select 
    56596393    foreach (@p) { 
    56606394        if ( defined($_) ) { 
     
    58856619                                    if (   $bloque_final =~ /Event:/ 
    58866620                                        || $bloque_final =~ /Message: Mailbox/ 
     6621                                        || $bloque_final =~ /SIP-CanReinvite/ 
    58876622                                        || $bloque_final =~ /Message: Timeout/ ) 
    58886623                                    { 
     
    58926627                                        my $block_count = -1; 
    58936628                                        foreach my $p (@lineas) { 
     6629                                            if ( $p =~ /ActionID: autosipentry/ ) { 
     6630                                                $block_count++; 
     6631                                                $bloque[$block_count]{Event} = "sippeerentrylong"; 
     6632                                            } 
    58946633                                            my $my_event = ""; 
    5895                                             if ( $p =~ /Event:/ ) { 
     6634                                            if ( $p =~ /^Event:/ ) { 
    58966635                                                $block_count++; 
    58976636                                                log_debug( "$heading Event detected block_count = $block_count", 128 ) 
     
    61176856    if ( $origin_channel =~ m/^PARK/i || $origin_channel =~ m/^QUEUE/i || $origin_channel =~ m/^\d/ ) { 
    61186857        $local_reverse = 0; 
    6119         log_debug("** GET TRANSFER Disable reverse transfer for $origin_channel!",16) if DEBUG; 
     6858        log_debug( "** GET TRANSFER Disable reverse transfer for $origin_channel!", 16 ) if DEBUG; 
    61206859    } 
    61216860 
     
    61256864        # Transfer the session from the *other* button 
    61266865        @cuales_transferir = extraer_todos_los_enlaces_de_un_canal( $origin_channel, $button_server{$datosflash} ); 
    6127     if (@cuales_transferir == 0) { 
    6128           log_debug( "** !! REVERSE TRANSFER No reverse available, using regular sesbot", 16 ) if DEBUG; 
    6129           if ( @{ $sesbot{$datosflash} } ) { 
    6130               @cuales_transferir = @{ $sesbot{$datosflash} }; 
    6131           } 
    6132     } 
     6866        if ( @cuales_transferir == 0 ) { 
     6867            log_debug( "** !! REVERSE TRANSFER No reverse available, using regular sesbot to find the linked channels", 16 ) if DEBUG; 
     6868            if ( $sesbot{$datosflash} ) { 
     6869                if ( @{ $sesbot{$datosflash} } ) { 
     6870                    @cuales_transferir = extraer_todos_los_enlaces_de_un_canal( $cuales_transferir[0], $button_server{$datosflash} ); 
     6871                } 
     6872            } 
     6873        } 
    61336874    } 
    61346875    else { 
     
    61366877 
    61376878        # Transfer the session from the same button 
    6138         if ( @{ $sesbot{$datosflash} } ) { 
    6139             @cuales_transferir = @{ $sesbot{$datosflash} }; 
     6879        if ( $sesbot{$datosflash} ) { 
     6880            if ( @{ $sesbot{$datosflash} } ) { 
     6881                @cuales_transferir = @{ $sesbot{$datosflash} }; 
     6882            } 
     6883            else { 
     6884                @cuales_transferir = (); 
     6885            } 
    61406886        } 
    61416887        else { 
     
    62607006        sends_version($socket); 
    62617007 
    6262         # send_initial_status(); 
    62637008        first_client_status($socket); 
    62647009        $tab = substr( $tab, 0, -1 ) if DEBUG; 
     
    64087153        log_debug( "$heading origin_channel = $origin_channel", 64 ) if DEBUG; 
    64097154 
     7155        my $no_security_code = ""; 
    64107156        if ( defined( $config->{$panelcontext}{security_code} ) ) { 
    64117157            $myclave = $config->{$panelcontext}{security_code} . $keys_socket{$socket}; 
    64127158            log_debug( "$heading usando key " . $keys_socket{$socket}, 16 ) if DEBUG; 
     7159            $no_security_code = $config->{$panelcontext}{security_code}; 
    64137160        } 
    64147161        else { 
     
    64167163            $myclave = $config->{GENERAL}{security_code} . $keys_socket{$socket}; 
    64177164            log_debug( "$heading usando key " . $keys_socket{$socket}, 16 ) if DEBUG; 
     7165            $no_security_code = $config->{GENERAL}{security_code}; 
    64187166        } 
    64197167 
     
    64237171 
    64247172        if (   ( "$password" eq "$md5clave" ) 
    6425             || ( $accion =~ /^dial/ && $cdial_nosecure == 1 ) ) 
     7173            || ( $accion =~ /^dial/ && $cdial_nosecure == 1 ) 
     7174            || ( $no_security_code eq "" ) ) 
    64267175        { 
    64277176            sends_correct($socket); 
     
    65017250            if ( $accion =~ /^tovoicemail/ ) { 
    65027251 
    6503                 my $keyext = "$origin_server^$origin_channel"; 
    6504                 my $exttran = $tovoicemail{$btn_destino}; 
    6505                 my ( $extx, $contextx ) = split( /\@/, $exttran, 2 ); 
    6506  
    65077252                my @cuales_transferir = get_transfer_channel( $origin_channel, $datosflash ); 
    6508                 my $cuantos = @cuales_transferir; 
    6509  
    6510                 if ( $cuantos > 0 ) { 
    6511                     $comando = "Action: Redirect\r\n"; 
    6512                     $comando .= "Channel: $cuales_transferir[0]\r\n"; 
    6513                     $comando .= "Exten: $extx\r\n"; 
    6514                     $comando .= "ActionID: 1234\r\n"; 
    6515                     $comando .= "Context: $contextx\r\n"; 
    6516                     $comando .= "Priority: 1\r\n\r\n"; 
     7253                my $cuantos           = @cuales_transferir; 
     7254 
     7255                if ( !defined( $tovoicemail{$btn_destino} ) ) { 
     7256 
     7257                    # If there is no voicemail extension defined, change it to a standard 
     7258                    # trasnfer 
     7259                    if ( $cuantos > 0 ) { 
     7260                        $accion = "transferir"; 
     7261                    } 
     7262                    else { 
     7263                        $accion = "originate"; 
     7264                    } 
    65177265                } 
    65187266                else { 
    6519                     $comando = "Action: Originate\r\n"; 
    6520                     $comando .= "Channel: $origin_channel\r\n"; 
    6521                     $comando .= "Exten: $extx\r\n"; 
    6522                     $comando .= "ActionID: 1234\r\n"; 
    6523                     $comando .= "Context: $contextx\r\n"; 
    6524                     $comando .= "Priority: 1\r\n\r\n"; 
    6525                 } 
    6526                 send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
    6527                     0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
    6528  
    6529                 return; 
     7267 
     7268                    my $keyext  = "$origin_server^$origin_channel"; 
     7269                    my $exttran = $tovoicemail{$btn_destino}; 
     7270                    my ( $extx, $contextx ) = split( /\@/, $exttran, 2 ); 
     7271 
     7272                    if ( $cuantos > 0 ) { 
     7273                        $comando = "Action: Redirect\r\n"; 
     7274                        $comando .= "Channel: $cuales_transferir[0]\r\n"; 
     7275                        $comando .= "Exten: $extx\r\n"; 
     7276                        $comando .= "ActionID: 1234\r\n"; 
     7277                        $comando .= "Context: $contextx\r\n"; 
     7278                        $comando .= "Priority: 1\r\n\r\n"; 
     7279                    } 
     7280                    else { 
     7281                        $comando = "Action: Originate\r\n"; 
     7282                        $comando .= "Channel: $origin_channel\r\n"; 
     7283                        $comando .= "Exten: $extx\r\n"; 
     7284                        $comando .= "ActionID: 1234\r\n"; 
     7285                        $comando .= "Context: $contextx\r\n"; 
     7286                        $comando .= "Priority: 1\r\n\r\n"; 
     7287                    } 
     7288                    send_command_to_manager( $comando, $p[ $button_server{$datosflash} ], 
     7289                        0, $astmanproxy_servers[ $button_server{$datosflash} ] ); 
     7290 
     7291                    $tab = substr( $tab, 0, -1 ) if DEBUG; 
     7292                    return; 
     7293                } 
    65307294            } 
    65317295            if ( $accion =~ /^voicemail/ ) { 
     
    66297393                    0, $astmanproxy_servers[ $button_server{$boton_con_contexto} ] ); 
    66307394            } 
     7395 
    66317396            elsif ( $accion =~ /^conference/ ) { 
    66327397                log_debug( "$heading CONFERENCE extension_transfer($origin_channel)", 1 ) if DEBUG; 
     
    66477412                        log_debug( "$heading coincidencia para btn_destino $btn_destino el canal es $canal", 1 ) 
    66487413                          if DEBUG; 
    6649                         my @links = extraer_todos_los_enlaces_de_un_canal( $canal, $button_server{$datosflash} ); 
    6650  
     7414                        my @links            = extraer_todos_los_enlaces_de_un_canal( $canal, $button_server{$datosflash} ); 
    66517415                        my @canal_transferir = @{ $sesbot{$btn_destino} }; 
    66527416 
     
    66847448                                $comando .= "Context: $conference_context\r\n"; 
    66857449                                $comando .= "Priority: 1\r\n\r\n"; 
    6686                                 $auto_conference{ $canal_transferir[0] } = $origin_channel; 
     7450 
     7451                                if ( defined( $config->{$panelcontext}{'attendant_hold_extension'} ) ) { 
     7452                                    $attendant_transfer{ $canal_transferir[0] } = $origin_channel; 
     7453                                    $mute_other{ $canal_transferir[0] }         = $links[0]; 
     7454                                    $attendant_pending{ $canal_transferir[0] }  = $empty_room . "@" . $conference_context; 
     7455                                } 
     7456                                else { 
     7457                                    $auto_conference{ $canal_transferir[0] } = $origin_channel; 
     7458                                } 
    66877459                            } 
    66887460                            else { 
     
    66987470            } 
    66997471            elsif ( $accion =~ /transferir/ ) { 
    6700  
    67017472                if ( $accion =~ /^ctransferir/ ) { 
    67027473 
     
    67907561 
    67917562                    my $member = 0; 
    6792                     while ( my ( $key, $val ) = each(%count_queue) ) { 
     7563                    while ( my ( $key, $val ) = each(%agents_available_on_queue) ) { 
    67937564                        if ( $key eq "$button_server{$datosflash}^$destino" ) { 
    67947565                            foreach my $qmember (@$val) { 
     
    69547725                    my $canalito = $2; 
    69557726                    if ( $canalito !~ m/^_/ && $nro_servidor == $servidor && $canalito !~ m/=/ ) { 
    6956                         my $comando = "Action: Command\r\n"; 
    6957                         $comando .= "ActionID: astdb-$key-$canalito\r\n"; 
    6958                         $comando .= "Command: database get $key $canalito\r\n\r\n"; 
    6959                         if ( defined( $autenticado{$socket} ) ) { 
    6960                             if ( $autenticado{$socket} == 1 ) { 
    6961                                 send_command_to_manager( $comando, $socket ); 
     7727                        if ( defined( $buttons_astdbkey{$canal} ) ) { 
     7728                            my $astdbkey = $buttons_astdbkey{$canal}; 
     7729                            my $comando  = "Action: Command\r\n"; 
     7730                            $comando .= "ActionID: astdb-$key-$canalito\r\n"; 
     7731                            $comando .= "Command: database get $key $astdbkey\r\n\r\n"; 
     7732                            if ( defined( $autenticado{$socket} ) ) { 
     7733                                if ( $autenticado{$socket} == 1 ) { 
     7734                                    send_command_to_manager( $comando, $socket ); 
     7735                                } 
    69627736                            } 
    69637737                        } 
     
    69997773    foreach my $socket2 (@todos) { 
    70007774        if ( defined($socket2) && $socket2 ne "" ) { 
     7775 
    70017776            if ( $showagents == 1 ) { 
    70027777                send_command_to_manager( "Action: Command\r\nActionId: agents\r\nCommand: show agents\r\n\r\n", $socket2 ); 
     
    70167791                send_command_to_manager( "Action: QueueStatus\r\nActionID: QueueStatus\r\n", $socket2 ); 
    70177792            } 
    7018  
    7019             #   if($showagents==1) { 
    7020             #           send_command_to_manager( "Action: Command\r\nActionId: agents\r\nCommand: show agents\r\n\r\n", $socket2 ); 
    7021             #   } 
    70227793        } 
    70237794    } 
     
    70477818            if ( $botonled{$interno} == 1 ) { 
    70487819                send_status_to_flash( $socket, "$interno|changelabel1|$botonlabel{$interno}", 0 ); 
     7820            } 
     7821        } 
     7822        for $interno ( keys %botonledcolor ) { 
     7823            if ( $botonledcolor{$interno} ne "" ) { 
     7824                send_status_to_flash( $socket, "$interno|fopledcolor|$botonledcolor{$interno}", 0 ); 
     7825                if ( $estadoboton{$interno} =~ /^free/ || $estadoboton{$interno} eq "" ) { 
     7826                    send_status_to_flash( $socket, "$interno|state|free", 0 ); 
     7827                } 
    70497828            } 
    70507829        } 
     
    70877866            } 
    70887867        } 
     7868 
     7869        if ( keys(%boton_paused) ) { 
     7870            for $interno ( keys %boton_paused ) { 
     7871                send_status_to_flash( $socket, "$interno|paused|$boton_paused{$interno}", 0 ); 
     7872            } 
     7873        } 
     7874        if ( keys(%boton_agentpaused) ) { 
     7875            for $interno ( keys %boton_agentready ) { 
     7876                send_status_to_flash( $socket, "$interno|agents_paused|$boton_agentpaused{$interno}", 0 ); 
     7877            } 
     7878        } 
     7879        if ( keys(%boton_agentready) ) { 
     7880            for $interno ( keys %boton_agentready ) { 
     7881                send_status_to_flash( $socket, "$interno|agents_ready|$boton_agentready{$interno}", 0 ); 
     7882            } 
     7883        } 
     7884        if ( keys(%boton_agentbusy) ) { 
     7885            for $interno ( keys %boton_agentbusy ) { 
     7886                send_status_to_flash( $socket, "$interno|agents_busy|$boton_agentbusy{$interno}", 0 ); 
     7887            } 
     7888        } 
     7889        if ( keys(%boton_agentlogedof) ) { 
     7890            for $interno ( keys %boton_agentlogedof ) { 
     7891                send_status_to_flash( $socket, "$interno|agents_logedof|$boton_agentlogedof{$interno}", 0 ); 
     7892            } 
     7893        } 
     7894 
    70897895        if ( keys(%botonpark) ) { 
    70907896            for $interno ( keys %botonpark ) { 
     
    70987904            } 
    70997905        } 
     7906        if ( keys(%botonpermanenttext) ) { 
     7907            for $interno ( keys %botonpermanenttext ) { 
     7908                if ( $botonpermanenttext{$interno} ne "" ) { 
     7909                    print "permanente $interno -$botonpermanenttext{$interno}-\n"; 
     7910                    send_status_to_flash( $socket, "$interno|settext|$botonpermanenttext{$interno}", 0 ); 
     7911                } 
     7912            } 
     7913        } 
    71007914        for $interno ( keys %estadoboton ) { 
    71017915 
    7102             #if ( $estadoboton{$interno} !~ /^free/ ) { 
    71037916            if ( $estadoboton{$interno} =~ /^busy/ ) { 
    71047917                send_status_to_flash( $socket, "$interno|state|busy", 0 ); 
     
    71117924            } 
    71127925            if ( defined( $botonclid{$interno} ) ) { 
     7926                my $texti = ""; 
    71137927                if ( $botonclid{$interno} ne "" ) { 
    71147928                    send_status_to_flash( $socket, "$interno|settext|$botonclid{$interno}", 0 ); 
     
    71167930            } 
    71177931 
    7118             #} 
    71197932        } 
    71207933        if ( keys(%botonlinked) ) { 
     
    71747987    my $heading      = "** SEND INITIAL STATUS"; 
    71757988    my $cual         = shift; 
     7989    my $skip_autosip = shift; 
    71767990    my @socket_manager; 
    71777991 
    7178     if ( defined($cual) ) { 
     7992    if ( !defined($skip_autosip) ) { $skip_autosip = 0; } 
     7993 
     7994    if ( defined($cual) && $cual ne "" ) { 
    71797995        push @socket_manager, $cual; 
    71807996    } 
     
    71848000 
    71858001    log_debug( "$heading START SUB", 16 ) if DEBUG; 
    7186  
    7187     request_astdb_status(); 
    71888002 
    71898003    foreach my $socket (@socket_manager) { 
     
    72098023            send_command_to_manager( "Action: ZapShowChannels\r\n\r\n", $socket ); 
    72108024 
     8025            if ( $skip_autosip == 0 ) { 
     8026                send_command_to_manager( "Action: SIPPeers\r\nActionID: autosip\r\n\r\n", $socket ); 
     8027            } 
     8028 
    72118029            send_command_to_manager( "Action: Command\r\nActionID: parkedcalls\r\nCommand: show parkedcalls\r\n\r\n", $socket ); 
    72128030 
     
    72658083        } 
    72668084    } 
     8085    request_astdb_status(); 
    72678086    alarm(2); 
    72688087} 
     
    73518170                $agent_state                          = $3; 
    73528171                $agents_name{"$server^$agent_number"} = $agent_name; 
     8172                set_queueobject( $server, "AGENT/$agent_number", "name", $agent_name ); 
    73538173            } 
    73548174 
     
    79668786    my $maxtime = 0; 
    79678787 
     8788    print_recomputequeues(); 
     8789 
    79688790    my $header = "**RECOMP QUEUE"; 
    79698791    log_debug( "$header canalid $canalid", 1 ) if DEBUG; 
     
    79948816 
    79958817    foreach my $id ( keys %{$cola} ) { 
     8818        if ( !defined( $cola->{$id}{QUEUE} ) ) { 
     8819            delete( $cola->{$id} ); 
     8820            next; 
     8821        } 
     8822 
     8823        #foreach ( keys %{ $cola->{$id} } ) { 
     8824        #    print "key de cola $_\n"; 
     8825        #} 
    79968826        if ( $queue_to_recompute eq $cola->{$id}{QUEUE} ) { 
    79978827            $save_id = $id; 
     
    80478877    } 
    80488878 
     8879    # Remove the item from the hash, recompute_queues is only called 
     8880    # from the Leave event 
     8881 
     8882    delete $cola->{$canalid}; 
    80498883    @return_ocupado = unique(@return_ocupado); 
    80508884 
     
    81518985 
    81528986    my $numero       = shift; 
     8987    my $name         = shift; 
    81538988    my $format       = shift; 
    81548989    my @chars_number = (); 
     
    81578992    my $devuelve     = ""; 
    81588993 
     8994    if ( $name eq "<unknown>" ) { $name = ""; } 
     8995 
    81598996    if ( !is_number($numero) ) { 
    81608997        return $numero; 
     
    81969033    @result = reverse @result; 
    81979034    $devuelve = join( "", @result ); 
     9035    $devuelve =~ s/\${CLIDNAME}/$name/gi; 
    81989036    return $devuelve; 
    81999037} 
     
    82449082    my $randomkey = generate_random_password($keylen); 
    82459083    my $mandakey  = "$randomkey|key|0"; 
    8246     if ( !$keys_socket{"$socket"} ) { 
     9084    if ( !$keys_socket{$socket} ) { 
    82479085        $nocrypt = 1; 
    82489086    } 
     
    82519089    } 
    82529090    send_status_to_flash( $socket, $mandakey, $nocrypt ); 
     9091} 
     9092 
     9093sub sends_reload { 
     9094    my $socket   = shift; 
     9095    my $nocrypt  = 0; 
     9096    my $contexto = $flash_contexto{$socket}; 
     9097    my $boton    = "0"; 
     9098    if ( $contexto ne "" ) { 
     9099        $boton .= "\@$contexto"; 
     9100    } 
     9101 
     9102    if ( !$keys_socket{$socket} ) { 
     9103        print "nocrypt = 1\n"; 
     9104        $nocrypt = 1; 
     9105    } 
     9106    my $mensaje = "<response btn=\"0\" cmd=\"reload\" data=\"0\"/>\0"; 
     9107    log_debug( "Sending reload to flash client at " . $ip_addy{$socket}, 1 ) if DEBUG; 
     9108    push( @{ $client_queue_nocrypt{$socket} }, $mensaje ); 
     9109    push( @{ $client_queue{$socket} },         $mensaje ); 
    82539110} 
    82549111 
     
    88609717# End TEA 
    88619718 
     9719sub print_recomputequeues { 
     9720 
     9721    foreach my $paso1 ( keys %{$cola} ) { 
     9722        print "-----------------\n"; 
     9723        foreach my $it ( keys %{ $cola->{$paso1} } ) { 
     9724            print "cola($paso1)($it) = " . $cola->{$paso1}{$it} . "\n"; 
     9725        } 
     9726    } 
     9727} 
     9728 
    88629729sub print_agentonqueue { 
    88639730    my $valor = shift; 
     
    88749741sub print_countqueue { 
    88759742    my $valor = shift; 
    8876     if ( keys(%count_queue) ) { 
    8877         foreach my $valor ( sort ( keys(%count_queue) ) ) { 
    8878             foreach my $vvalor ( @{ $count_queue{$valor} } ) { 
    8879                 log_debug( "\t| count_queue{$valor} = $vvalor", 32 ) if DEBUG; 
     9743    if ( keys(%agents_available_on_queue) ) { 
     9744        foreach my $valor ( sort ( keys(%agents_available_on_queue) ) ) { 
     9745            foreach my $vvalor ( @{ $agents_available_on_queue{$valor} } ) { 
     9746                log_debug( "\t| agents_available_on_queue{$valor} = $vvalor", 32 ) if DEBUG; 
    88809747            } 
    88819748        } 
     
    90069873} 
    90079874 
     9875sub add_queueobject { 
     9876    my $server = shift; 
     9877    my $queue  = shift; 
     9878    my $agent  = shift; 
     9879 
     9880    my @return; 
     9881 
     9882    print "add queueobject $server $queue $agent\n"; 
     9883    $queue_object->{$server}{$queue}{$agent}{status} = 1; 
     9884    @return = compute_queueobject($server); 
     9885    return @return; 
     9886} 
     9887 
     9888sub delete_queueobject { 
     9889    my $server = shift; 
     9890    my $queue  = shift; 
     9891    my $agent  = shift; 
     9892 
     9893    my @return; 
     9894 
     9895    print "delete queueobject $server $queue $agent\n"; 
     9896    delete( $queue_object->{$server}{$queue}{$agent} ); 
     9897    @return = compute_queueobject($server); 
     9898    return @return; 
     9899} 
     9900 
     9901sub set_queueobject { 
     9902    my $server   = shift; 
     9903    my $agent    = shift; 
     9904    my $property = shift; 
     9905    my $value    = shift; 
     9906 
     9907    my @return; 
     9908 
     9909    foreach my $val ($queue_object) { 
     9910        foreach my $iserver ( keys %{$val} ) { 
     9911            if ( $server eq $iserver ) { 
     9912                foreach my $iqueue ( keys %{ $queue_object->{$iserver} } ) { 
     9913                    foreach my $iagent ( keys %{ $queue_object->{$iserver}{$iqueue} } ) { 
     9914                        if ( $iagent eq $agent ) { 
     9915                            $queue_object->{$iserver}{$iqueue}{$iagent}{$property} = $value; 
     9916                            print "property set!\n"; 
     9917                        } 
     9918                    } 
     9919                } 
     9920            } 
     9921        } 
     9922    } 
     9923    @return = compute_queueobject($server); 
     9924    return @return; 
     9925} 
     9926 
     9927sub compute_queueobject { 
     9928    my $server = shift; 
     9929 
     9930    my $head = "** compute queueboject: "; 
     9931    log_debug( "$head", 16 ); 
     9932 
     9933    my $queueagent_counter = {}; 
     9934    my @return; 
     9935    my $canalid; 
     9936    my $ready; 
     9937    my $busy; 
     9938    my $logedof; 
     9939    my $paused; 
     9940 
     9941    if ( !defined($server) ) { $server = -1; } 
     9942    foreach my $val ($queue_object) { 
     9943        foreach my $iserver ( keys %{$val} ) { 
     9944            if ( $server eq $iserver || $server == -1 ) { 
     9945                foreach my $iqueue ( keys %{ $queue_object->{$iserver} } ) { 
     9946                    $queueagent_counter->{$iserver}->{$iqueue}->{ready}   = 0; 
     9947                    $queueagent_counter->{$iserver}->{$iqueue}->{logedof} = 0; 
     9948                    $queueagent_counter->{$iserver}->{$iqueue}->{busy}    = 0; 
     9949                    $queueagent_counter->{$iserver}->{$iqueue}->{paused}  = 0; 
     9950                    foreach my $iagent ( keys %{ $queue_object->{$iserver}{$iqueue} } ) { 
     9951                        if ( $queue_object->{$iserver}{$iqueue}{$iagent}{paused} > 0 ) { 
     9952                            $queueagent_counter->{$iserver}->{$iqueue}->{paused}++; 
     9953                        } 
     9954                        if ( $queue_object->{$iserver}{$iqueue}{$iagent}{status} == 1 ) { 
     9955                            $queueagent_counter->{$iserver}->{$iqueue}->{ready}++; 
     9956                        } 
     9957                        elsif ( $queue_object->{$iserver}{$iqueue}{$iagent}{status} == 5 ) { 
     9958                            $queueagent_counter->{$iserver}->{$iqueue}->{logedof}++; 
     9959                        } 
     9960                        elsif ($queue_object->{$iserver}{$iqueue}{$iagent}{status} == 2 
     9961                            || $queue_object->{$iserver}{$iqueue}{$iagent}{status} == 3 
     9962                            || $queue_object->{$iserver}{$iqueue}{$iagent}{status} == 6 ) 
     9963                        { 
     9964                            $queueagent_counter->{$iserver}->{$iqueue}->{busy}++; 
     9965                        } 
     9966                    } 
     9967                    $canalid = "QUEUE/$iqueue-XXXX"; 
     9968                    $ready   = $queueagent_counter->{$server}->{$iqueue}{ready}; 
     9969                    $busy    = $queueagent_counter->{$server}->{$iqueue}{busy}; 
     9970                    $logedof = $queueagent_counter->{$server}->{$iqueue}{logedof}; 
     9971                    $paused  = $queueagent_counter->{$server}->{$iqueue}{paused}; 
     9972 
     9973                    push @return, "QUEUE/$iqueue|agents_ready|$ready|$canalid-$server|$canalid"; 
     9974                    push @return, "QUEUE/$iqueue|agents_busy|$busy|$canalid-$server|$canalid"; 
     9975                    push @return, "QUEUE/$iqueue|agents_logedof|$logedof|$canalid-$server|$canalid"; 
     9976                    push @return, "QUEUE/$iqueue|agents_paused|$paused|$canalid-$server|$canalid"; 
     9977 
     9978                } 
     9979            } 
     9980        } 
     9981    } 
     9982    return @return; 
     9983} 
     9984 
    90089985sub print_cola_write { 
    90099986    my $socket = shift; 
     
    90139990            foreach my $val ( @{ $client_queue{$_} } ) { 
    90149991                $contame++; 
    9015                 print "cola $contame $_ comando $val\n"; 
    90169992            } 
    90179993        } 
     
    90219997        foreach my $val ( @{ $client_queue{$socket} } ) { 
    90229998            $contame++; 
    9023             print "cola $contame $socket comando $val\n"; 
    90249999        } 
    902510000    } 
     
    908810063            } 
    908910064        } 
    9090         if ( keys(%count_queue) ) { 
     10065        if ( keys(%agents_available_on_queue) ) { 
    909110066            print "Count on queue: \n"; 
    9092             foreach my $valor ( sort ( keys(%count_queue) ) ) { 
    9093                 print "count_queue{$valor} = $count_queue{$valor}\n"; 
     10067            foreach my $valor ( sort ( keys(%agents_available_on_queue) ) ) { 
     10068                foreach ( @{ $agents_available_on_queue{$valor} } ) { 
     10069                    print "agents_available_on_queue{$valor} = $_\n"; 
     10070                } 
    909410071            } 
    909510072        } 
     
    918310160=head1 DESCRIPTION 
    918410161 
    9185 B<This program> will read the given input file(s) and do someting useful with the contents thereof. 
     10162B<This program> is a proxy server for the Flash Operator Panel. It reads configuration files and updates the data to display on the panel. 
     10163 
     10164=head1 FILES 
     10165 
     10166=over 8 
     10167 
     10168=item B</etc/op-panel> 
     10169 
     10170The configuration files of the operator panel daemon reside in that directory 
     10171(may differ on other distributions). Those include: 
     10172 
     10173=item B<op_server.cfg> 
     10174 
     10175The server's configuration file. See remarks in file for documentation. 
     10176 
     10177=item B<op_buttons.cfg> 
     10178 
     10179Defines the layout of the operator panel, and also which phones to track. 
     10180 
     10181=item B</var/log/op-panel/output.log> 
     10182 
     10183The standard output of the daemon, including debugging prints and dumps. 
     10184 
     10185=item B</var/log/op-panel/error.log> 
     10186 
     10187The standard error of the daemon. Should normally be empty. 
    918610188 
    918710189=cut