.titleBar { margin-bottom: 5px!important; }

Perl-Script verfeinern

Dieses Thema im Forum "Asterisk Skripte" wurde erstellt von robinsonR, 14 Feb. 2012.

  1. robinsonR

    robinsonR Mitglied

    Registriert seit:
    17 Apr. 2006
    Beiträge:
    559
    Zustimmungen:
    0
    Punkte für Erfolge:
    16
    Ich habe im Internet dieses Script gefunden:
    Code:
    #!/usr/bin/perl -w
    
    # -------------------------------------------------------------------- #
    #                                                                      #
    # This script requires that you have the Dialectic Remote HTTP         #
    # server running.                                                      #
    #                                                                      #
    # Update the properties below as necessary.                            #
    #                                                                      #
    # On the Asterisk server, copy this script into:                       #
    # /var/lib/asterisk/agi-bin/                                           #
    #                                                                      #
    # Update the permissions on the AGI file:                              #
    #                                                                      #
    # cd /var/lib/asterisk/agi-bin/                                        #
    # chmod 755 dialectic-asterisk-incoming-call-monitor.agi               #
    #                                                                      #
    # To actually call the script, modify your extensions_custom.conf      #
    # file. For example:                                                   #
    #                                                                      #
    # exten => s,1,AGI,dialectic-asterisk-incoming-call-monitor.agi        #
    #                                                                      #
    # If you're using an extensions.ael file, the block for incoming       #
    # calls could look similar to this:                                    #
    #                                                                      #
    # 1 => {                                                               #
    #     AGI(dialectic-asterisk-incoming-call-monitor.agi);               #
    # }                                                                    #
    #                                                                      #
    # After modifying the extensions_custom.conf or extensions.ael file,   #
    # you'll need to reload your Asterisk server for the new               #
    # settings to take effect.                                             #
    #                                                                      #
    # Some users have reported issues when editing this file on a          #
    # Windows machine.                                                     #
    #                                                                      #
    # -------------------------------------------------------------------- #
    
    # -------------------------------------------------------------------- #
    #                                                                      #
    #              EDIT THE FOLLOWING PROPERTIES AS NECESSARY              #
    #                                                                      #
    # -------------------------------------------------------------------- #
    
    @DIALECTIC_MAC_IP_ARRAY = ('192.168.0.100');                           # The IP address(es) of the Mac(s) running Dialectic listening for incoming calls.
                                                                           # For multiple Macs, add additional single-quoted IP addresses to the array separated
                                                                           # by commas like so:
                                                                           # @DIALECTIC_MAC_IP_ARRAY = ('192.168.0.100','192.168.0.101','192.168.0.102');
    $DIALECTIC_MAC_PORT     = '58384';                                     # The port of the Mac running Dialectic as set in the Dialectic preferences
    $DIALECTIC_PASSWORD     = 'mySecretWord';                              # The password as set in the Dialectic preferences
    $MY_DEVICE_NAME         = 'My Phone';                                  # The name of the device that will be included in the Dialectic call log
    $MY_NOTE                = 'Note to include in the log.';               # Static text that will be included in the Dialectic call log
    $SHOULD_FLAG            = 'NO';                                        # 'YES' to flag the entry in the Dialectic call log
    
    # -------------------------------------------------------------------- #
    #                                                                      #
    #                        DO NOT EDIT BELOW HERE                        #
    #                                                                      #
    # -------------------------------------------------------------------- #
    
    open STDOUT, '>/dev/null';
    fork and exit;
    
    use Asterisk::AGI;
    use LWP::UserAgent;
    use URI::Escape;
    
    $AGI = new Asterisk::AGI;
    my %input = $AGI->ReadParse();
    my $caller_id = $input{'callerid'};
    my $caller_id_name = $input{'calleridname'};
    my $caller_id_e = uri_escape($caller_id);
    my $caller_id_name_e = uri_escape($caller_id_name);
    my $dialectic_password_e = uri_escape($DIALECTIC_PASSWORD);
    my $my_device_name_e = uri_escape($MY_DEVICE_NAME);
    my $my_note_e = uri_escape($MY_NOTE);
    foreach(@DIALECTIC_MAC_IP_ARRAY) {
    	my $url = "http://$_:$DIALECTIC_MAC_PORT/callDetected?password=$dialectic_password_e&number=$caller_id_e&name=$caller_id_name_e&device=$my_device_name_e&note=$my_note_e&flagged=$SHOULD_FLAG";
    	my $browser = LWP::UserAgent->new;
    	$browser->post($url);
    }
    
    exit(0);
    Leider verstehe ich zuwenig von AGI, um es meinen Bedürfnissen anpassen zu können.
    Das Problem ist, dieses Script sendet eine Meldung an jeden Computer, dessen IP-Adresse in der ersten Zeile eingegeben wurde. Ich möchte nun die Meldung nur an den Computer schicken, dessen Nebenstelle auch wirklich klingelt.
    Ich habe die Nebenstellen und die zugehörigen IP-Adressen in der Asterisk DB gespeichert und würde nun gern wissen, wie ich diese Einträge innerhalb des Scripts abrufen kann.
     
  2. rentier-s

    rentier-s Guest

    Das Skript ist so nicht wirklich brauchbar für Dein Vorhaben. Es fehlt die ganze Behandlung des STDIN Datenstroms während der Laufzeit.

    In der Theorie könnte man den Wert im AGI mittels GetVariable einlesen.

    Ich würde Dir aber dazu raten, die IP-Adresse einfach im Dialplan auszulesen und den Aufruf per
    Code:
    TrySystem(wget -O /dev/null http://...... &)
    zu machen. Dazu ist kein AGI notwendig.
     
  3. robinsonR

    robinsonR Mitglied

    Registriert seit:
    17 Apr. 2006
    Beiträge:
    559
    Zustimmungen:
    0
    Punkte für Erfolge:
    16
    Ich habe es jetzt so gelöst: In der Asterisk DB gibt es Einträge für die entsprechenden IP-Adressen. Diese werden dann im Dialplan ausgelesen und an den Script übergeben:
    Code:
    exten => s,1,Set(IP=${DB(clientip/${EXTTOCALL})})
    exten => s,n,AGI(dialectic-asterisk-incoming-call-monitor.agi,${IP})
    Das Script habe ich auch modifiziert:
    Code:
    #!/usr/bin/perl -w
    
    # -------------------------------------------------------------------- #
    #                                                                      #
    # This script requires that you have the Dialectic Remote HTTP         #
    # server running.                                                      #
    #                                                                      #
    # Update the properties below as necessary.                            #
    #                                                                      #
    # On the Asterisk server, copy this script into:                       #
    # /var/lib/asterisk/agi-bin/                                           #
    #                                                                      #
    # Update the permissions on the AGI file:                              #
    #                                                                      #
    # cd /var/lib/asterisk/agi-bin/                                        #
    # chmod 755 dialectic-asterisk-incoming-call-monitor.agi               #
    #                                                                      #
    # To actually call the script, modify your extensions_custom.conf      #
    # file. For example:                                                   #
    #                                                                      #
    # exten => s,1,AGI,dialectic-asterisk-incoming-call-monitor.agi        #
    #                                                                      #
    # If you're using an extensions.ael file, the block for incoming       #
    # calls could look similar to this:                                    #
    #                                                                      #
    # 1 => {                                                               #
    #     AGI(dialectic-asterisk-incoming-call-monitor.agi);               #
    # }                                                                    #
    #                                                                      #
    # After modifying the extensions_custom.conf or extensions.ael file,   #
    # you'll need to reload your Asterisk server for the new               #
    # settings to take effect.                                             #
    #                                                                      #
    # Some users have reported issues when editing this file on a          #
    # Windows machine.                                                     #
    #                                                                      #
    # -------------------------------------------------------------------- #
    
    # -------------------------------------------------------------------- #
    #                                                                      #
    #              EDIT THE FOLLOWING PROPERTIES AS NECESSARY              #
    #                                                                      #
    # -------------------------------------------------------------------- #
    
    @DIALECTIC_MAC_IP_ARRAY = ('192.168.0.100');                           # The IP address(es) of the Mac(s) running Dialectic listening for incoming calls.
                                                                           # For multiple Macs, add additional single-quoted IP addresses to the array separated
                                                                           # by commas like so:
                                                                           # @DIALECTIC_MAC_IP_ARRAY = ('192.168.0.100','192.168.0.101','192.168.0.102');
    $DIALECTIC_MAC_PORT     = '58384';                                     # The port of the Mac running Dialectic as set in the Dialectic preferences
    $DIALECTIC_PASSWORD     = 'mySecretWord';                              # The password as set in the Dialectic preferences
    $MY_DEVICE_NAME         = 'My Phone';                                  # The name of the device that will be included in the Dialectic call log
    $MY_NOTE                = 'Note to include in the log.';               # Static text that will be included in the Dialectic call log
    $SHOULD_FLAG            = 'NO';                                        # 'YES' to flag the entry in the Dialectic call log
    
    # -------------------------------------------------------------------- #
    #                                                                      #
    #                        DO NOT EDIT BELOW HERE                        #
    #                                                                      #
    # -------------------------------------------------------------------- #
    
    open STDOUT, '>/dev/null';
    fork and exit;
    
    use Asterisk::AGI;
    use LWP::UserAgent;
    use URI::Escape;
    
    $AGI = new Asterisk::AGI;
    my %input = $AGI->ReadParse();
    my $caller_id = $input{'callerid'};
    my $caller_id_name = $input{'calleridname'};
    my $caller_id_e = uri_escape($caller_id);
    my $caller_id_name_e = uri_escape($caller_id_name);
    my $dialectic_password_e = uri_escape($DIALECTIC_PASSWORD);
    my $my_device_name_e = uri_escape($MY_DEVICE_NAME);
    my $my_note_e = uri_escape($MY_NOTE);
    [COLOR="red"]my $my_ip = $ARGV[0];[/COLOR]
    
    [COLOR="red"]#[/COLOR]foreach(@DIALECTIC_MAC_IP_ARRAY) {
            my $url = "http://[COLOR="red"]$my_ip[/COLOR]:$DIALECTIC_MAC_PORT/callDetected?password=$dialectic_password_e&number=$caller_id_e&name=$caller_id_name_e&device=$my_device_name_e&note=$my_note_e&flagged=$SHOULD_FLAG";
            my $browser = LWP::UserAgent->new;
            $browser->post($url);
    [COLOR="red"]#[/COLOR]}
    
    exit(0);
    (Geänderte Stellen rot eingefärbt)