OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Ralf S. Engelschall
  Root:   /v/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-src                      Date:   24-Mar-2008 21:03:55
  Branch: HEAD                             Handle: 2008032420035100

  Added files:
    openpkg-src/asterisk-utils
                            asterisk-clock.pl asterisk-mail.pl
                            asterisk-utils.spec

  Log:
    new package: asterisk-utils 0 (Asterisk Addon Utilities)

  Summary:
    Revision    Changes     Path
    1.1         +99 -0      openpkg-src/asterisk-utils/asterisk-clock.pl
    1.1         +171 -0     openpkg-src/asterisk-utils/asterisk-mail.pl
    1.1         +80 -0      openpkg-src/asterisk-utils/asterisk-utils.spec
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-src/asterisk-utils/asterisk-clock.pl
  ============================================================================
  $ cvs diff -u -r0 -r1.1 asterisk-clock.pl
  --- /dev/null 2008-03-24 21:01:09 +0100
  +++ asterisk-clock.pl 2008-03-24 21:03:53 +0100
  @@ -0,0 +1,99 @@
  +#!/usr/bin/perl
  +##
  +##  asterisk-clock.pl -- Asterisk PBX Accurate Talking Clock
  +##  Copyright (c) 2007 Chris Walton
  +##  Copyright (c) 2008 Ralf S. Engelschall <[EMAIL PROTECTED]>
  +##  License: GPL (version 2 or higher)
  +##
  +##  This script will generate a 1.5s beep at 0, 15, 30, and 45 seconds
  +##  past each minute. It uses sub-second time delays in order to be as
  +##  accurate as possible. The time is annoumced in English at 11 seconds
  +##  before the beep. Warning "blips" play and 2 seconds and 1 second
  +##  before the beep.
  +##
  +##  1st PASS example... assume program starts at 5.5 seconds past the minute:
  +##  
----------------------------------------------------------------------------
  +##  0    1    2    3    4    5    6    7    8    9    10   11   12  13   14  
 15
  +##                            
->BLIP>BLIP>BLIP>BLIP>BLIP>BLIP>BLI>BLIP>BLIP>BEEP
  +##  normal operation (loop):
  +##  
----------------------------------------------------------------------------
  +##  0    1    2    3    4    5    6    7    8    9   10   11   12   13   14  
 15
  +##  
BEEP--->SILENCE----->TIME_ANNOUNCEMENT_FOLLOWED_BY_SILENCE----->BLIP>BLIP>BEEP
  +##
  +
  +use Time::HiRes qw(usleep gettimeofday);
  +
  +my $blip    = "!523/20,!0/980";  # 20ms blip followed by 980ms silence.
  +my $beep    = "!415/1500";       # 1.5s beep.
  +my $silence = "!0/500";          # 0.5s silence.
  +
  +#   turn off output buffering to stop dead lock.
  +$| = 1;
  +
  +sub status {
  +    #   AGI function status is avaialbe on STDIN
  +    my $cmd = shift;
  +    my $status = <STDIN>;
  +    if ($status !~ m/^200 result=0/) {
  +        print STDERR "$cmd returned with bad status ($status)\n";
  +        exit(-1);
  +    }
  +}
  +
  +#   STDIN will initially contain assorted channel information. Discard it 
all.
  +while (<STDIN>) {
  +    chomp;
  +    last unless ($_);
  +}
  +
  +#   Answer the channel
  +print "ANSWER\n";
  +status("Exec Answer");
  +
  +while (1) {
  +    my ($seconds, $microseconds) = gettimeofday();
  +
  +    #   sleep until the next second rolls around.
  +    usleep(1000000 - $microseconds);
  +
  +    #   calculate number of seconds left before the beep.
  +    my $time_til_beep = 14 - ($seconds % 15);
  +
  +    if ($time_til_beep < 11 ) {
  +        #   Insufficient time to announce the time; just play blips.
  +        #   This should only occur on first pass.
  +        print "EXEC PlayTones ", ("$blip," x $time_til_beep), $beep, "\n";
  +        status("Exec PlayTones");
  +
  +        #   Sleep while the blips and beep are playing.
  +        usleep($time_til_beep * 1000000 + 1500000);
  +    } else {
  +        #   We have sufficient time to announce what the time will be at the 
beep.
  +        my $time_at_beep = $seconds + $time_til_beep + 1;
  +
  +        #   Sleep until 11 seconds before the beep and then announce the 
time.
  +        usleep(($time_til_beep - 11) * 1000000);
  +        print qq{STREAM FILE at-tone-time-exactly ""\n};
  +        status("Stream File");
  +        print qq{SAY DATETIME $time_at_beep "#" "IM'vm-and'S'seconds'\n};
  +        status("Say DateTime");
  +
  +        #   We need to get the time again because we don't know how long
  +        #   the announcement took to play.
  +        ($seconds, $microseconds) = gettimeofday();
  +
  +        #   Now sleep until 2.5 seconds before the beep.
  +        my $delay = 12500000 - $microseconds - (($seconds % 15) * 1000000);
  +        next if ($delay < 0); # abort if annoucment took too long to play.
  +        usleep($delay);
  +
  +        #   Now play two warning blips followed by the beep.
  +        #   Preceeding the blips with .5s silence ensures the 1st blip is 
heard.
  +        print "EXEC PlayTones $silence,$blip,$blip,$beep\n";
  +        status("Exec PlayTones");
  +
  +        #   Sleep while the blips and beep are playing.
  +        usleep(4000000);
  +    }
  +}
  +
  @@ .
  patch -p0 <<'@@ .'
  Index: openpkg-src/asterisk-utils/asterisk-mail.pl
  ============================================================================
  $ cvs diff -u -r0 -r1.1 asterisk-mail.pl
  --- /dev/null 2008-03-24 21:01:09 +0100
  +++ asterisk-mail.pl  2008-03-24 21:03:55 +0100
  @@ -0,0 +1,171 @@
  +#!/usr/bin/perl
  +##
  +##  asterisk-mail.pl -- Asterisk Mail User Agent
  +##  Copyright (c) 2008 Ralf S. Engelschall <[EMAIL PROTECTED]>
  +##  License: GPL (version 2 or higher)
  +##  Usage: asterisk-mail.pl <src> <dst> <name> <file>
  +##
  +
  +require 5.008;
  +use IO::File;
  +use IO::All;
  +use Asterisk::Manager;
  +use Data::Dumper;
  +use MIME::Entity;
  +
  +#   local configuration
  +my $my = {
  +    -prog_name       => "asterisk-mail",
  +    -prog_version    => "0.9.0",
  +    -asterisk_name   => "OpenPKG Asterisk PBX",
  +    -asterisk_host   => "127.0.0.1",
  +    -asterisk_port   => "5038",
  +    -asterisk_user   => "asterisk",
  +    -asterisk_secret => "asterisk",
  +    -sendmail        => "/usr/sbin/sendmail",
  +};
  +
  +##
  +##  use Asterisk Manager Interface (AMI)
  +##  to retrieve information about users
  +##
  +
  +my $cfg = {
  +    -extension2realname => {},
  +    -realname2extension => {},
  +    -extension2mailaddr => {},
  +    -mailaddr2extension => {},
  +    -extension2sipuser  => {},
  +    -sipuser2extension  => {}
  +};
  +my $astman = new Asterisk::Manager;
  +$astman->host($my->{-asterisk_host});
  +$astman->port($my->{-asterisk_port});
  +$astman->user($my->{-asterisk_user});
  +$astman->secret($my->{-asterisk_secret});
  +$astman->connect() or die sprintf(
  +    "Could not connect to Asterisk Manager Interface (AMI) at %s:%s\n",
  +    $astman->host(), $astman->port()
  +);
  +my %response = $astman->action("VoicemailUsersList", 1);
  +if ($response{"Response"} eq "Success") {
  +    while (1) {
  +        %response = map { 
  +            Asterisk::Manager::splitresult($_);
  +        } $astman->read_response();
  +        if ($response{"Event"} eq "VoicemailUserEntry") {
  +            $cfg->{-extension2mailaddr}->{$response{"VoiceMailbox"}} = 
$response{"Email"};
  +            $cfg->{-mailaddr2extension}->{$response{"Email"}} = 
$response{"VoiceMailbox"};
  +            $cfg->{-extension2realname}->{$response{"VoiceMailbox"}} = 
$response{"Fullname"};
  +            $cfg->{-realname2extension}->{$response{"Fullname"}} = 
$response{"VoiceMailbox"};
  +        }
  +        else {
  +            last;
  +        }
  +    }
  +}
  +my $response = $astman->sendcommand("Action" => "Command", "Command" => "sip 
show users", 1);
  +$response =~ s/^.+Username\s+.+?NAT\r?\n//si;
  +my @sipusers = map { s/^(\S+).*$/$1/; $_ } split(/\r?\n/, $response);
  +foreach my $sipuser (@sipusers) {
  +    $response = $astman->sendcommand("Action" => "Command", "Command" => 
"sip show user $sipuser", 1);
  +    if ($response =~ m/^.*?Callerid\s*:\s*(.+?)\r?\n.*$/si) {
  +        $response = $1;
  +        if ($response =~ m/<(\d+)>/s) {
  +            $cfg->{-extension2sipuser}->{$1} = $sipuser;
  +            $cfg->{-sipuser2extension}->{$sipuser} = $1;
  +        }
  +        if ($response =~ m/"(.+?)"/s) {
  +            
$cfg->{-extension2realname}->{$cfg->{-sipuser2extension}->{$sipuser}} = $1
  +                if (        defined $cfg->{-sipuser2extension}->{$sipuser}
  +                    and not defined 
$cfg->{-extension2realname}->{$cfg->{-sipuser2extension}->{$sipuser}});
  +            $cfg->{-realname2extension}->{$1} = 
$cfg->{-sipuser2extension}->{$sipuser} 
  +                if (        defined $cfg->{-sipuser2extension}->{$sipuser}
  +                    and not defined $cfg->{-realname2extension}->{$1});
  +        }
  +    }
  +}
  +$astman->disconnect();
  +
  +##
  +##  resolve user information
  +##
  +
  +my ($src, $dst, $name, $wavfile) = @ARGV;
  +$src = &resolve_user($src);
  +$dst = &resolve_user($dst);
  +sub resolve_user ($) {
  +    my ($id) = @_;
  +    my $user = {
  +        -extension => ''
  +        -sipuser   => ''
  +        -realname  => ''
  +        -mailaddr  => ''
  +    };
  +    if ($id =~ m/[EMAIL PROTECTED]/) {
  +        $user->{-mailaddr}  = $id;
  +        $user->{-extension} = 
$cfg->{-mailaddr2extension}->{$user->{-mailaddr}};
  +        $user->{-sipuser}   = 
$cfg->{-extension2sipuser}->{$user->{-extension}};
  +        $user->{-realname}  = 
$cfg->{-extension2realname}->{$user->{-extension}};
  +    }
  +    elsif ($id =~ m/^\S+\s+\S+.*$/) {
  +        $user->{-realname}  = $id;
  +        $user->{-extension} = 
$cfg->{-realname2extension}->{$user->{-realname}};
  +        $user->{-sipuser}   = 
$cfg->{-extension2sipuser}->{$user->{-extension}};
  +        $user->{-mailaddr}  = 
$cfg->{-extension2mailaddr}->{$user->{-extension}};
  +    }
  +    elsif ($id =~ m/^\d+$/) {
  +        $user->{-extension} = $id;
  +        $user->{-sipuser}   = 
$cfg->{-extension2sipuser}->{$user->{-extension}};
  +        $user->{-mailaddr}  = 
$cfg->{-extension2mailaddr}->{$user->{-extension}};
  +        $user->{-realname}  = 
$cfg->{-extension2realname}->{$user->{-extension}};
  +    }
  +    else {
  +        $user->{-sipuser}   = $id;
  +        $user->{-extension} = 
$cfg->{-sipuser2extension}->{$user->{-sipuser}};
  +        $user->{-mailaddr}  = 
$cfg->{-extension2mailaddr}->{$user->{-extension}};
  +        $user->{-realname}  = 
$cfg->{-extension2realname}->{$user->{-extension}};
  +    }
  +    $user->{-extension} = "0"               if (not defined 
$user->{-extension});
  +    $user->{-sipuser}   = "unknown"         if (not defined 
$user->{-sipuser});
  +    $user->{-realname}  = ""                if (not defined 
$user->{-realname});
  +    $user->{-mailaddr}  = "[EMAIL PROTECTED]" if (not defined 
$user->{-mailaddr});
  +    return $user;
  +}
  +
  +##
  +##  send file as a mail
  +##
  +
  +my $text =
  +    "Dear " . $dst->{-realname} . ",\n" .
  +    "\n" .
  +    "here is your audio recording of\n" .
  +    "$name.\n" .
  +    "\n" .
  +    "Yours,\n" .
  +    "\n" .
  +    "-- \n" .
  +    $my->{-asterisk_name} . "\n";
  +
  +my $mail = MIME::Entity->build(
  +    From       => sprintf("%s <%s>", $src->{-realname} || 
$my->{-asterisk_name}, $src->{-mailaddr}),
  +    To         => sprintf("%s <%s>", $dst->{-realname} || 
$my->{-asterisk_name}, $dst->{-mailaddr}),
  +    'X-Mailer' => sprintf("%s/%s", $my->{-prog_name}, $my->{-prog_version}),
  +    Subject    => sprintf("[%s] Your audio recording of %s", 
$my->{-asterisk_name}, $name),
  +    Data       => $text,
  +);
  +
  +if (-f $wavfile) {
  +    my $data = io($wavfile)->slurp();
  +    $mail->attach(Data => $data, Type => "audio/x-wav");
  +}
  +else {
  +    my $data = "ERROR: WAV file \"$wavfile\" not found\n";
  +    $mail->attach(Data => $data, Type => "text/plain");
  +}
  +
  +my $io = new IO::File sprintf("|%s -oi -oem -f '%s' -t", $my->{-sendmail}, 
$dst->{-mailaddr}) or die;
  +$io->printf($mail->stringify);
  +$io->close();
  +
  @@ .
  patch -p0 <<'@@ .'
  Index: openpkg-src/asterisk-utils/asterisk-utils.spec
  ============================================================================
  $ cvs diff -u -r0 -r1.1 asterisk-utils.spec
  --- /dev/null 2008-03-24 21:01:09 +0100
  +++ asterisk-utils.spec       2008-03-24 21:03:55 +0100
  @@ -0,0 +1,80 @@
  +##
  +##  asterisk-utils.spec -- OpenPKG RPM Package Specification
  +##  Copyright (c) 2000-2008 OpenPKG Foundation e.V. <http://openpkg.net/>
  +##
  +##  Permission to use, copy, modify, and distribute this software for
  +##  any purpose with or without fee is hereby granted, provided that
  +##  the above copyright notice and this permission notice appear in all
  +##  copies.
  +##
  +##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  +##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  +##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  +##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  +##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  +##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  +##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  +##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  +##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  +##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  +##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  +##  SUCH DAMAGE.
  +##
  +
  +#   package information
  +Name:         asterisk-utils
  +Summary:      Asterisk Addon Utilities
  +URL:          http://www.asterisk.org/
  +Vendor:       Ralf S. Engelschall et al.
  +Packager:     OpenPKG Foundation e.V.
  +Distribution: OpenPKG Community
  +Class:        EVAL
  +Group:        VoIP
  +License:      GPL
  +Version:      0
  +Release:      20080324
  +
  +#   list of sources
  +Source0:      asterisk-mail.pl
  +Source1:      asterisk-clock.pl
  +
  +#   build information
  +Prefix:       %{l_prefix}
  +BuildRoot:    %{l_buildroot}
  +BuildPreReq:  OpenPKG, openpkg >= 20060823
  +PreReq:       OpenPKG, openpkg >= 20060823
  +PreReq:       asterisk, perl-asterisk, perl, perl-time, perl-mail
  +AutoReq:      no
  +AutoReqProv:  no
  +
  +%description
  +    This is a small set of addon utilities for the Asterisk PBX.
  +
  +%track
  +
  +%prep
  +    %setup -q -T -c
  +
  +%build
  +
  +%install
  +    rm -rf $RPM_BUILD_ROOT
  +    %{l_shtool} mkdir -f -p -m 755 \
  +        $RPM_BUILD_ROOT%{l_prefix}/sbin \
  +        $RPM_BUILD_ROOT%{l_prefix}/lib/asterisk/agi-bin
  +    %{l_shtool} install -c -m 755 \
  +        -e 's;/usr/bin/perl;%{l_prefix}/bin/perl;' \
  +        %{SOURCE asterisk-mail.pl} \
  +        $RPM_BUILD_ROOT%{l_prefix}/sbin/asterisk-mail
  +    %{l_shtool} install -c -m 755 \
  +        -e 's;/usr/bin/perl;%{l_prefix}/bin/perl;' \
  +        -e 's;/usr/sbin/sendmail;%{l_prefix}/sbin/sendmail;' \
  +        %{SOURCE asterisk-clock.pl} \
  +        $RPM_BUILD_ROOT%{l_prefix}/lib/asterisk/agi-bin/asterisk-clock
  +    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}
  +
  +%files -f files
  +
  +%clean
  +    rm -rf $RPM_BUILD_ROOT
  +
  @@ .
______________________________________________________________________
OpenPKG                                             http://openpkg.org
CVS Repository Commit List                     [email protected]

Reply via email to