Showing posts with label Asterisk. Show all posts
Showing posts with label Asterisk. Show all posts

Friday, February 24, 2017

An example of creating "personal blacklist" function in the Asterisk (Elastix)

In this example, we add a function "personal blacklist" in /etc/asterisk/extensions_custom.conf  for followme calls (in the previous post, we added a feature "out of office")

Example:
Users phones: 10XXX

Then users can use this function from phones:
*13 - add
*14 - remove

1. Add to /etc/asterisk/extensions_custom.conf enable and disable blocks

[from-internal-custom]

;personal blacklist
exten => *13,1,Goto(personal-blacklist-add,s,1)
exten => *14,1,Goto(personal-blacklist-remove,s,1)

2. Add to /etc/asterisk/extensions_custom.conf check blocks in Followme


[personal-blacklist-add]

exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Set(NumLoops=0)
exten => s,n(start),Playback(enter-num-blacklist)
exten => s,n,Set(TIMEOUT(digit)=5)
exten => s,n,Set(TIMEOUT(response)=60)
exten => s,n,Read(blacknr,then-press-pound,,,,)
exten => s,n,SayDigits(${blacknr})
exten => s,n,Playback(if-correct-press&digits/1)
exten => s,n,Noop(Waiting for input)
exten => s,n(end),WaitExten(60,)
exten => s,n,Playback(sorry-youre-having-problems&goodbye)

exten => 1,1,GotoIf($[ "${blacknr}" != ""]?:personal-blacklist-add-invalid,s,1)
exten => 1,n,Set(DB(AMPUSER/${CALLERID(num)}/blacklist/${blacknr})=1)
exten => 1,n,Playback(num-was-successfully&added)
exten => 1,n,Wait(1)
exten => 1,n,Hangup

[personal-blacklist-add-invalid]
exten => s,1,Set(NumLoops=$[${NumLoops} + 1])
exten => s,n,Playback(pm-invalid-option)
exten => s,n,GotoIf($[${NumLoops} < 3]?personal-blacklist-add,s,start)
exten => s,n,Playback(goodbye)
exten => s,n,Hangup

[personal-blacklist-remove]
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Playback(entr-num-rmv-blklist)
exten => s,n,Set(TIMEOUT(digit)=5)
exten => s,n,Set(TIMEOUT(response)=60)
exten => s,n,Read(blacknr,then-press-pound,,,,)
exten => s,n,SayDigits(${blacknr})
exten => s,n,Playback(if-correct-press&digits/1)
exten => s,n,Noop(Waiting for input)
exten => s,n(end),WaitExten(60,)
exten => s,n,Playback(sorry-youre-having-problems&goodbye)

exten => 1,1,Noop(Deleting: AMPUSER/${CALLERID(num)}/blacklist/${blacknr} ${DB_DELETE(AMPUSER/${CALLERID(num)}/blacklist/${blacknr})})
exten => 1,n,Playback(num-was-successfully&removed)
exten => 1,n,Wait(1)
exten => 1,n,Hangup

[app-blacklist-check-custom]
exten => _10XXX,1,Noop("app-blacklist-check-custom")
exten => _10XXX,n,Noop(${EXTEN})
exten => _10XXX,n,Noop(${CALLERID(num)})
exten => _10XXX,n,GotoIf($["${DB(AMPUSER/${EXTEN}/blacklist/${CALLERID(num)})}" = "1"]?app-blacklist-check,s,blacklisted)
exten => _10XXX,n,Return

[ext-findmefollow-custom]
exten => _FMPR-10XXX,1,Noop("CUSTOM-FOLLOWME")
exten => _FMPR-10XXX,n,Gosub(app-blacklist-check-custom,${EXTEN:5},1)
exten => _FMPR-10XXX,n,GotoIf($["${DB(AMPUSER/${EXTEN:5}/followme/announ_custom)}" != "1"]?NOANNOUN)
exten => _FMPR-10XXX,n,Answer
exten => _FMPR-10XXX,n,Wait(1)
exten => _FMPR-10XXX,n,Playback(custom/Hi_subscriber_you_are_calling_is_out_of_office)
exten => _FMPR-10XXX,n,Goto(ext-findmefollow,${EXTEN:5},DIALGRP)
exten => _FMPR-10XXX,n(NOANNOUN),Noop("NO ANNOUNCMENT")
exten => _FMPR-10XXX,n,Macro(dial-one,${RT},${DIAL_OPTIONS},${EXTEN:5})

Wednesday, February 22, 2017

An example of creating "out of office" function in the Asterisk (Elastix)

In this example, we create a function "out of office" in /etc/asterisk/extensions_custom.conf  for followme calls

Example:
Users phones: 10XXX

Then users can use this function from phones:
*11 - enable
*12 - disable


1. We have to record WAV files (PCM Encoded, 16 Bits, at 8000Hz) and add to Asterisk:
Sorry, subscriber out office
Hello, you set autoreply
Hello, you disable autoreply

2. Add to /etc/asterisk/extensions_custom.conf enable and disable blocks

[from-internal-custom]

;out of office enable
exten => *11,1,Answer
exten => *11,n,Wait(1)
exten => *11,n,Noop(${CALLERID(num)})
exten => *11,n,Set(DB(AMPUSER/${CALLERID(num)}/followme/announ_custom1)=1)
exten => *11,n,Playback(custom/Hi_you_enable_auto_reply_for_forwarding_call)
exten => *11,n,Hangup

;out of office disable
exten => *12,1,Answer
exten => *12,n,Wait(1)
exten => *12,n,Noop(${CALLERID(num)})
exten => *12,n,Set(DB(AMPUSER/${CALLERID(num)}/followme/announ_custom1)=0)
exten => *12,n,Playback(custom/Hi_you_disable_auto_reply_for_forwarding_call)
exten => *12,n,Hangup

3. Add to /etc/asterisk/extensions_custom.conf check blocks in Followme
[ext-findmefollow-custom]

;forward call, check out of office
exten => _FMPR-10XXX,1,Noop("CUSTOM-FOLLOWME")
exten => _FMPR-10XXX,n,GotoIf($["${DB(AMPUSER/${EXTEN:5}/followme/announ_custom1)}" != "1"]?NOANNOUN)
exten => _FMPR-10XXX,n,Answer
exten => _FMPR-10XXX,n,Wait(1)
exten => _FMPR-10XXX,n,Playback(custom/Hi_subscriber_you_are_calling_is_out_of_office)
exten => _FMPR-10XXX,n,Goto(ext-findmefollow,${EXTEN:5},DIALGRP)
exten => _FMPR-10XXX,n(NOANNOUN),Noop("NO ANNOUNCMENT")
exten => _FMPR-10XXX,n,Macro(dial-one,${RT},${DIAL_OPTIONS},${EXTEN:5})

Sunday, January 22, 2017

An example of creating the array with a list of phone numbers in the Asterisk

In this example, we create a variable and assign a list of numbers in /etc/asterisk/globals_custom.conf file.
Then we can use this variable in the dialplan /etc/asterisk/extensions_custom.conf.

1. Create a variable in /etc/asterisk/globals_custom.conf
TELS1 = "(18005532447|14085267209|18005536387)"
2. Example of use dialplan /etc/asterisk/extensions_custom.conf
exten = _1XXXXXXXXXX,1,GotoIf($["${CALLERID(num)}" : ${TELS1}]?eq)

...
exten = _1XXXXXXXXXX,n(eq),Noop("equal")


Thursday, May 26, 2016

Example perl script parse hylafax errors

In this article I share a script errors parse in the log Hylafax.
This script can be useful to those who are move faxes to Asterisk/Elastix. The script will be sent by e-mail failure fax, missed calls for monitoring.

download hylafax_parse_error.pl

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
#!/usr/bin/perl -w

use warnings;
use MIME::Entity;

my $file = "";
my $tr = 0;
my $CID = "";
my $FaxModem = "";
my $FaxErr = "";
my $PATH_TO_SENDMAIL = "/usr/lib/sendmail";
my @arr_for_tmp = "";
my $cfile_name = "";
my $var = "";
my $count_filename = '/home/Scripts/error_get_count';

open(my $fh, '<', $count_filenameor die "cant open count file";
{
  local $/;
  $content = <$fh>;
}

@cfiles = </var/spool/hylafax/log/c*>;
foreach $cfile (@cfiles) {
  @arr_for_tmp=split /\//,$cfile;
  $cfile_name=$arr_for_tmp[(scalar(@arr_for_tmp))-1];
  $cfile_name =~ s/c//;
  if ($cfile_name > $content) {
   check_processing_jobs($cfile);
  }
}

close $fh;
open($fh, '>', $count_filenameor die "cant open count file";
close $fh;

sub check_processing_jobs
{
 $tr = 0
 $file = $_[0];
 open my $info, $file or die "Could not open $file: $!";

 whilemy $line = <$info>)  { 
if ($line =~ /CallID/) {
 $CID = $line;     
}
if ($line =~ /FAX CONNECTION  DEVICE/) {
 $FaxModem = $line;     
}
if ($line =~ /error|invalid/) {
 $FaxErr = $line;
 $tr = 1;     
}
}

if ($tr == 1) {
$CID =~ m/^"\d+"\s$/gi;

if ($FaxModem =~ "ttyIAX2") {
   $to_email = "fax_user2\@blogspot.com";
   $data_email = "fax for user2 123456789 ";
}

if ($FaxModem =~ "ttyIAX1") {
   $to_email = "fax_user1\@blogspot.com";
   $data_email = "fax for user1 987654321 ";
}

    $top = MIME::Entity->build(Type    => "multipart/mixed; charset=UTF-8",
       Charset    => "UTF-8",
       From    => "fax\@blogspot.com",
       To      => $to_email,
       Subject => 'fax');
    local $data = "Error " . $data_email . "\n\t" . $CID . "\n\t" . $FaxModem . "\n\t" . $FaxErr;
    $data =~ s/\n+/\n/gi;
    $top->attach(Data => $data);
    open MAIL, "| " . $PATH_TO_SENDMAIL . " -t -oi -oem" or die "open: $!";
    $top->print(\*MAIL);
    close MAIL;
}

close $info;
}

Tuesday, March 29, 2016

Elastix multiple external ip

In this article I want to share the experience to add multiple addresses for Elastix/Asterisk server. This can be used in the following scenarios:
1. A cluster of two Elastix servers (http://www.elastix.com/en/elastix-high-availability-in-detail-2/)
2. Single Elastix server and two voip-provider
3. A cluster of two Elastix servers and two voip-provider

'extrnip' parameter can specify only one IP address in the file sip.conf. Therefore 'externip' in this case is not needed. To use a different address just add routes such as

Server1: internal 192.168.0.1 external_1 192.168.1.1 external_2 192.168.1.2
Server2: internal 192.168.0.2 external_1 192.168.1.5 external_2 192.168.1.5
Virtual IP: external_1 192.168.1.3, isp_1 192.168.1.4, external_2 192.168.1.6, isp_2 192.168.1.7

001
002
ip route add 192.168.1.4/32 via 192.168.1.3 dev eth1 src 192.168.1.3
ip route add 192.168.1.7/32 via 192.168.1.6 dev eth1 src 192.168.1.6

to routes added during the event HA
- create script "/etc/ha.d/resource.d/IProute"

001
002
003
004
005
006
007
008
009
010
#!/bin/bash

args=("$@")

if [ ${args[0]} == "start" ]then
        ip route add 192.168.1.4/32 via 192.168.1.3 dev eth1 src 192.168.1.3
        ip route add 192.168.1.7/32 via 192.168.1.6 dev eth1 src 192.168.1.6
fi

exit 0

- add script "IProute" to config HA "/etc/ha.d/haresources"

001
voipserver.drbd drbddisk::r0 Filesystem::/dev/drbd0::/replica::ext3 IPaddr::192.168.0.3/24/eth0/192.168.0.255 IPaddr::192.168.1.3/27/eth1/192.168.1.31 IPaddr::192.168.1.6/27/eth1/192.168.1.31 IProute mysqld asterisk httpd elastix-updaterd

Sunday, February 21, 2016

Elastix PBX - Batch Configuration error: Secret weak

I want to share a way of import of unsafe passwords in Elastix. We need to comment out the line in the file "/var/www/html/modules/extensions_batch/libs/paloSantoExtensionsBatch.class.php":

001
002
003
004
    //    if (!isset($extension['secret']|| !$this->_valida_password($extension['secret'])) {
    //        $this->errMsg = _tr("Secret weak. Line").": $numLinea";
    //        return FALSE;
    //    }

Sunday, June 29, 2014

Instructions for creating Dial-in conference in Lync

This manual describes how to setup your server Lync 2013 to prepare for the conference with analog abonent. Are also briefly Asterisk server setup. For a conference on the Lync 2013 and an Asterisk reserved extension 2000.
  1. Open Lync Topology Builder, download config, create a PSTN gateways



  2. Edit poll property, mark checkbox Dial-in (PSTN) conferencing
  3. Publish Topology and run “Lync Server Deployment Wizard – Install or Update lync Server System – Setup or Remove Lync Server Components” on servers
  4. Run Microsoft Lync Server 2013 Control Panel, go to conferencing – Dial-in Access Number and create New number

    Define ext number
  5. Go to Voice Routing – Dial Plan and configure Normalization rule for Global dial plan – name Local Extensions
  6. Edit Site dial plan – select Normalization rule Local Extensions, and press commit all
  7. Next edit Voice Routing – Voice Policy, create New Associated PSTN Usage
  8. Create Route, add Associated trunks

  9. Go to Asterisk to configure incoming calls:
               sip.conf:
    [general]
    context=incoming                 ; Default context for incoming calls
    allowguest=no                  ; Allow or reject guest calls (default is yes)
    allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
    allowtransfer=no               ; Disable all transfers (unless enabled in peers or users)
    bindport=5060                   ; UDP Port to bind to (SIP standard port is 5060)
    bindaddr=0.0.0.0                ; IP address to bind to (0.0.0.0 binds to all)
    srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
    disallow=all
    allow=ulaw
    allow=alaw
    localnet=x.x.x.x/x.x.x.x
    externalip=x.x.x.x
    canreinvite => no                                                                   

    [Lync_Trunk]                   ; Our Lync trunk
    type=friend
    port=5068                      ; This is the default Lync Server TCP listening port
    host=x.x.x.x             ; This should be the IP address of your Lync Server
    dtmfmode=rfc2833
    context=from-lync
    nat=yes
    qualify=yes
    transport=tcp

    extensions.conf:                                                                 
    [incoming]
    exten => s,1,Answer
    exten => s,n,Background(ent-target-attendant)
    exten => s,n,WaitExten(5)
    exten => s,n,Background(conf-placeintoconf)
    exten => s,n,Dial(SIP/Lync_Trunk/2000,20)
    exten => _200X,1,Dial(SIP/Lync_Trunk/${EXTEN},20)
    exten => i,1,Playback(pbx-invalid)
    exten => i,n,Goto(incoming,s,1)

    [from-lync]
    exten=>_.,1,Dial(${OUTBOUNDTRUNK}/${EXTEN},tT)
    exten=>_.,n,Congestion()
    exten=>_.,n,hangup()