Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

jueves, 23 de abril de 2020

Asterisk Realtime Centos 7






Asterisk realtime centos 7

yum install epel-release

Install dependencies

yum install unixODBC-devel

yum install unixODBC

yum install python-devel

yum install python-pip

yum install MySQL-python

yum install mysql-connector-odbc

yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel




Install LAMP
https://hostadvice.com/how-to/how-to-install-lamp-stack-on-centos-7/

Install Asterisk


sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/sysconfig/selinux
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config
reboot
MAKE SURE SELINUX IS DISABLED running the next command
sestatus
yum -y update
yum -y groupinstall core base "Development Tools"
yum install -y make wget openssl-devel ncurses-devel newt-devel libxml2-devel kernel-devel gcc gcc-c++ sqlite-devel
cd /usr/src/
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz
tar zxvf asterisk*
cd /usr/src/asterisk*
contrib/scripts/install_prereq install

./configure --libdir=/usr/lib64 --with-pjproject-bundled --with-jansson-bundled && make menuselect && make && make install
make samples
make config
ldconfig
service asterisk start
asterisk -rvvvvvvvvvvvvv

Install Realtime 

Create the DB

# mysqladmin -u root -p create asterisk

First, install Alembic:
# pip install alembic
Then, move to the Asterisk source directory containing the Alembic scripts:
# cd contrib/ast-db-manage/
Next, edit the config.ini.sample file and change the sqlalchemy.url option, e.g.
sqlalchemy.url = mysql://root:password@localhost/asterisk
such that the URL matches the username and password required to access your database.
Then rename the config.ini.sample file to config.ini
# cp config.ini.sample config.ini
Finally, use Alembic to setup the database tables:
# alembic -c config.ini upgrade head
You'll see something similar to:
# alembic -c config.ini upgrade head
INFO  [alembic.migration] Context impl MySQLImpl.
INFO  [alembic.migration] Will assume non-transactional DDL.
INFO  [alembic.migration] Running upgrade None -> 4da0c5f79a9c, Create tables
INFO  [alembic.migration] Running upgrade 4da0c5f79a9c -> 43956d550a44, Add tables for pjsip
#
You can then connect to MySQL to see that the tables were created:
# mysql -u root -p -D asterisk

mysql> show tables;
+--------------------+
| Tables_in_asterisk |
+--------------------+
| alembic_version    |
| iaxfriends         |
| meetme             |
| musiconhold        |
| ps_aors            |
| ps_auths           |
| ps_contacts        |
| ps_domain_aliases  |
| ps_endpoint_id_ips |
| ps_endpoints       |
| sippeers           |
| voicemail          |
+--------------------+
12 rows in set (0.00 sec)
mysql> quit



/etc/odbc.ini
[asterisk-mysql]
Description = MySQL connection to 'asterisk' database
Driver = MySQL
Database = asterisk
Server = localhost
UserName = root
Password = 7891
Port = 3306
Socket = /var/lib/mysql/mysql.sock
/etc/odbcinst.ini
# Example driver definitions
# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
/etc/asterisk/res_odbc.conf
[asterisk-mysql]
enabled => yes
dsn => asterisk-mysql
username => root
password => 7891
pre-connect => yes
/etc/asterisk/cdr_adaptive_odbc.conf
[asterisk-mysql]
connection=asterisk-mysql
table=cdr
alias start => calldate
----------------------------
Load on asterisk
module reload res_odbc.so

Check connection

asterisk_realtime*CLI> odbc show all

ODBC DSN Settings
-----------------

  Name:   asterisk
  DSN:    asterisk
    Number of active connections: 1 (out of 1)
    Logging: Disabled



Connecting PJSIP Sorcery to the Realtime Database


nano  /etc/asterisk/sorcery.conf

[res_pjsip] ; Realtime PJSIP configuration wizard
endpoint=realtime,ps_endpoints
auth=realtime,ps_auths
aor=realtime,ps_aors
domain_alias=realtime,ps_domain_aliases
contact=realtime,ps_contacts

[res_pjsip_endpoint_identifier_ip]
identify=realtime,ps_endpoint_id_ips

Realtime Configuration

/etc/asterisk/extconfig.conf
ps_endpoints => odbc,asterisk
ps_auths => odbc,asterisk
ps_aors => odbc,asterisk
ps_domain_aliases => odbc,asterisk
ps_endpoint_id_ips => odbc,asterisk
ps_contacts => odbc,asterisk


/etc/asterisk/modules.conf
preload => res_odbc.so
preload => res_config_odbc.so
noload => chan_sip.so 


/etc/asterisk/pjsip.conf
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0

Create endpoints

insert into ps_aors (id, max_contacts) values (103, 1); insert into ps_auths (id, auth_type, password, username) values (103, 'userpass', 103, 103); insert into ps_endpoints (id, transport, aors, auth, context, disallow, allow, direct_media) values (103, 'transport-udp', '103', '103', 'testing', 'all', 'g722', 'no');

                      pjsip show endpoint 103

https://gist.github.com/ambiorixg12/8cea6702d8c2b5afef31690c0f5d72e0

https://wiki.asterisk.org/wiki/display/AST/Setting+up+PJSIP+Realtime



----------------------------php code----
php /home/ambiorix/insert_device.php 2222

<?php
$link = mysqli_connect("localhost", "root", "mypass", "asterisk");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$sip_device ="$argv[1]";

$query1 = "INSERT INTO `ps_aors` (`id`, `max_contacts`) VALUES ($sip_device, 1)";
if (mysqli_query($link, $query1)) {
    printf("Query 1 executed successfully.\n");
} else {
    printf("Error executing query 1: %s\n", mysqli_error($link));
}

$query2 = "INSERT INTO `ps_auths` (`id`, `auth_type`, `password`, `username`) VALUES ($sip_device, 'userpass', $sip_device, $sip_device)";
if (mysqli_query($link, $query2)) {
    printf("Query 2 executed successfully.\n");
} else {
    printf("Error executing query 2: %s\n", mysqli_error($link));
}

$query3 = "INSERT INTO `ps_endpoints` (`id`, `transport`, `aors`, `auth`, `context`, `disallow`, `allow`, `direct_media`) 
VALUES ($sip_device, 'transport-udp', '$sip_device', '$sip_device', 'testing', 'all', 'g722', 'no')";
if (mysqli_query($link, $query3)) {
    printf("Query 3 executed successfully.\n");
} else {
    printf("Error executing query 3: %s\n", mysqli_error($link));
}

/* close connection */
mysqli_close($link);
?>

lunes, 20 de abril de 2020

SIP Media Flow Attribute Support

Show 
Home > Product Description > VoIP > SIP Media Flow Attribute Support

Overview:

The IMG supports the media flow direction attributes sendrecv, recvonly, sendonly, and inactive. These attributes, which are interpreted from the senders perspective, set the direction of the media stream to be established in the SIP protocol. The flow attributes present in the SDP portion of the SIP messaging will be used to support the call hold/resume scenario which is explained in RFC 3264 section 6.1 and still be backwards compatible with the call hold feature of RFC 2543 section B5. Up until software version 10.5.2 the IMG supported the Call Hold scenario using the "c=0.0.0.0" line  in the SDP message to put a call on hold. With the addition of the Media Flow direction Attributes a call can now be put on hold and then the call can be resumed by sending a Re-INVITE message with both the c=0.0.0.0 and one of the Flow attributes displayed above.


Call Flow Attributes:

The following attributes are supported on the IMG. These attributes are coded in the IMG and do not need to be configured. The attributes were added to support the call hold/resume feature and are supported in the Re-INVITE message only. Below is some background information on the Media Call Flow attributes added.

sendrecv - Used to establish a 2-way media stream.
recvonly - The SIP endpoint would only receive (listen mode) and not send media.
sendonly - The SIP endpoint would only send and not receive media.
inactive -  The SIP endpoint would neither send nor receive media.

Table 1 below shows the response the IMG will use when it receives a Media Flow Attribute on the incoming side.
Table 1:
Attribute in incoming Re-INVITE
Attribute in 200 OK response
IMG Connection Mode
a=sendrecv
a=sendrecv
2-Way Connection
a=sendonly
a=recvonly
Listen Mode (recv)
a=recvonly
a=sendonly
Transmit Mode (send)
c=0.0.0.0
c=0.0.0.0
Hold
a=inactive
a=inactive
Hold
c=0.0.0.0 and a=inactive
c=0.0.0.0 and a=inactive
Hold



Call Flow Information:

Call Flow: Call Hold/Resume

cf_flowdirectionattribute_f1454.png

The Call flow diagram above explains the Call Hold/Resume feature implemented with the Call Flow Direction Attributes.

  1. A 2-way call is established from GW-A to GW-B through the IMG using normal call messaging procedures.
  2. GW-A wants to put the call on hold. GW-A sends a Re-INVITE message to the IMG with the a=sendonly line in the SDP. This tells the IMG that GW-A is in a send-only mode and will not receive RTP/RTCP data.
  3. The IMG then sends a 200 OK response with the a=recvonly line indicating that it will only receive RTP/RTCP data and not transmit RTP/RTCP data packets to GW-A. At this point, GW-A can only transmit to IMG.
  4. The IMG then sends a Re-INVITE message to GW-B with the c=0.0.0.0 and a=inactive in the SDP. By sending these two messages, the IMG effectively puts the call on hold.
  5. GW-B responds with a 200 OK telling the IMG it is now on hold. There is no voice path between IMG and GW-B.
  6. GW-A then wants to take the call off hold and resume the call. It sends a Re-INVITE to the IMG with the line a=sendrecv telling the IMG it is now in a send/receive mode and the call can resume.
  7. The IMG responds with 200 OK message with the a=sendrecv line in its SDP.
  8. The IMG then sends a Re-INVITE to GW-B with the same a=sendrecv message in its SDP. GW-A responds with 200 OK and a=sendrecv in the SDP.
  9. At this point the call resumes and RTP/RTCP data begin flowing again.


Additional Information:

  • Support of the Media Call Flow Attributes is limited to the Re-INVITE method only. If a gateway sends a different method such as the UPDATE method with Media Call Flow attributes set for call hold or resume,IMG will honor the UPDATE method but not put call on hold or off hold/resume.
  • Absence of a Call Flow Attribute in the Re-INVITE shall default to sendrecv.
  • Call Flow attributes within an INVITE message will be ignored.
  • IMG by default will use c=0.0.0.0 and a=inactive in the Re-INVITE to propagate the call hold to outgoing SIP leg.
  • RTP as well as RTCP will be stopped when media is put "On Hold".
  • IMG honors 'recvonly' attribute in re-invite SDP, and responds with 'sendonly' in the 200 OK SDP.
  • Sample SDP messages shown below:

SDP with Flow Direction at session level:
v=0
o=Dialogic_SDP 0 1 IN IP4 10.10.1.253
s=Dialogic-SIP
c=IN IP4 10.10.1.100
t=0.0
a=sendonly
m=audio 8004 RTP/AVP 0
a=rtpmap:0 PCMU/8000
a=silenceSupp:off

SDP with flow direction attribute at media level:
v=0
o=Dialogic_SDP 0 1 IN IP4 10.10.1.253
s=Dialogic-SIP
c=IN IP4 10.10.1.100
t=0.0
m=audio 8004 RTP/AVP 0
a=rtpmap:0 PCMU/8000
a=silenceSupp:off
a=sendonly

sábado, 28 de marzo de 2020

phpagi spoof

//wait a minute to give everything a chance to settle
sleep(2);


//I had it set up to check the callerid against a set of valid peeps - but i decided i was tired of that. and it made it too complex.
//get caller id. 
$cid = $agi->parse_callerid();
$cid= $cid[username];

//streamfile that says "Enter number to spoof"
$agi->stream_file('enter_spoof');
//beep then get the resulting 10 digits - set it to spoofnumber
$result = $agi->get_data('beep', 3000, 10);
$spoofnumber= $result['result'];
$agi->verbose("Spoof Number:".$spoofnumber);
//streamfile that says "enter number to call"
$agi->stream_file('call_spoof');
//beep then get the resulting 10 digits - set it to callnumber
$result = $agi->get_data('beep', 3000, 10);
$callnumber= $result['result'];
$agi->verbose("Number to call:".$callnumber);
// set caller id to the spoofnumber
$agi->set_callerid($spoofnumber);

//call the number using whatever you got
//notice i have placed the 1 before the callnumber. this is so that i can keep everything ten digits. and cuz i am lazy
$agi->exec("Dial IAX2/yourpassword@provider/1".$callnumber);


// That is it. simple.. scary and easy
?>

domingo, 22 de marzo de 2020

phpagi conference system

#!/usr/bin/php -q
<?php
set_time_limit(30);
require('/var/www/html/project1/phpagi-2.20/phpagi.php');

error_reporting(E_ALL);
$agi = new AGI();
$agi->answer();
//http://php.net/manual/en/function.date.php
$time=date('a');

$agi->stream_file("welcome");

 $cid = $agi->parse_callerid();
$agi->verbose($cid[username]);

$agi->verbose($time);
$agi->set_variable("CONFBRIDGE(user,pin)",1212);
$agi->set_variable("CONFBRIDGE(bridge,max_members)",2);

//ConfBridge(conference[,bridge_profile[,user_profile[,menu]]])

$agi->exec("ConfBridge","111");

//$agi->exec_goto('from-internal',$value,1);
?>


[outboundtest]
exten=>100,1,answer()
;same=>n,Set(CONFBRIDGE(user,pin)=1111)
;same=>n,Set(CONFBRIDGE(bridge,max_members)=2)
exten=>100,n,agi(/var/www/html/conference/conf.php)
same=>n,hangup()

martes, 3 de marzo de 2020

Len Execif

${LEN(${CALLERID(num)})}
 ${LEN(${CALLERID(num)})}

same=>n,ExecIf($[${LEN(${CALLERID(num)})}> 2]?Set(CALLERID(num)=${CALLERID(num):1}))