Soporte & Consultoria

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

miércoles, 8 de junio de 2016

Setting up the CISCO 7940 with SIP/Asterisk

Introduction

This is another guide that was born out of extreem frustration. After spending weeks trying to get my CISCO 7940g to work with Asterisk, I decided to document the event for future generations.

The phones can be picked up cheap on eBay and also work nicely with Asterisk after some fiddling. However, there are a few points to bear in mind:

  • The phones are designed for enterprise VoIP deployments. If you buy one they are unlikely to come with a power supply as they expect to be deploying into a PoE environment. You can either buy a 48V PSU for the phone although it's probably cheaper to get a standard PoE injector. Also the phones rely upon infrastructure. To get the phones working it needs to get files from a TFTP server. You also need a web server to serve things like custom logos and a phone directory if you want to use those features.
  • The phones are designed to work with CISCO Call Manager and use the SCCP protocol rather than SIP. Asterisk has support for SCCP though it's said that you are better off using SIP. CISCO do a SIP firmware for the 7940g. This requires you to upgrade to a new firmware.

  • Rebooting the phone

    The first thing you probably want to know is how to reboot the phone. Hold down "*", "6" and "settings". The settings button is the bottom right of the group of four buttons around a circular, green question mark button. It has a box with a tick in it on the button.

    Upgrading to SIP firmware

    I don't want to cover this in too much detail as it's repeatadly documented all over the Internet. There are a few points to bear in mind:

  • The firmware is upgraded using config files and firmware images on the TFTP server. This process and the files used changes from version to version. Also you cannot directly upgrade from old firmware to the latest firmware. Version 6.3 is a significan release and I think you need to go to one of the 7 releases before you can upgrade to version 8.
  • Also please be aware that you have to download the firmware files from CISCO and for this you require a CISCO login. You can get this by putting the phone on CISCO support for about $40 a year.
  • Beat in mind that you need to downloadn the SIP firmware not the SCCP firmwar!
  • There have been many reports of not being able to get 8.10 to boot. I certinaly can't and decided to use 8.9 instead

  • Configuring the phone to connect to Asterisk or another SIP provider

    Let's start by assuming that you have managed to get a firmware upgrade to the lastest version of the SIP firmware. Now you need to configure the phone. When the phone boots, it downloads the firmware from the TFTP server and also pulls down some config files. You need the following files on the TFTP server (assuming you are using 8.9):
  • P0S3-08-9-00.loads
  • P0S3-08-9-00.sb2
  • P003-08-9-00.bin
  • P003-08-9-00.sbn
  • SIPDefault.cnf
  • SIP<mac>.cnf
  • There are two configuration files to use. SIPDefault contains settings that apply to all phones. SIP<mac>.cnf contains settings that apply to a single phone, indentified by MAC address. The following is an example of the minimal configuration needed to get the phone to register to either Asterisk or another SIP provider:

    SIPDefault.cnf

    #image_version shows the firmware image to get from the TFTP server. Note this shouls start P0S and not P00.
    image_version: P0S3-08-9-00

    #Proxy server address should probably be more accuratly be called the SIP server
    proxy1_address: x.x.x.x
    #proxy_register tell it to connect to the SIP server (why would you want to set this to 0?!
    proxy_register: 1

    SIP<MAC>.cnf

    #The following lines contain the authenication details
    line1_name: line1
    line1_authname: "line1"
    line1_displayname: "line1"
    line1_password: "supersecret"

    So now you should be able to boot your phone and make and receive calls. Good for you!

    Setting the time

    This is a bit of a mission. You set the NTP server and timezone but also have to set the details of when Daylight Saving Time starts and finishes. Fortunatly the rules are available here and it seems that DST is stardardised across the EU. The following example goes in SIPDefault.cnf and should get you going for the UK. Change the time zone for Europe. Change something else for the rest of the world
    sntp_server: "pool.ntp.orgt"
    sntp_mode: unicast
    time_zone: GMT
    dst_offset: 1
    dst_start_month: March
    dst_start_day_of_week: Sun
    dst_start_week_of_month: 8
    dst_start_time: 01
    dst_stop_month: Oct
    dst_stop_day_of_week: Sun
    dst_stop_week_of_month: 8
    dst_stop_time: 02
    dst_auto_adjust: 1
    time_format_24hr: 1
    date_format : D/M/Y

    Phone directory

    The CISCO phone directory is stored in an XML file that can hold 32 numbers. You can either get the phone directory XML file directly or use a form to send a search criteria to a script that returns matching results. Firstly you have to assign a button to the phone directory. There are various programmable buttons on the phone that you could use but since one is marked "directory" it makes sense to use that. First you add an entry to the SIPDefault.cnf, telling it what to do when the directory button is pressed. In the example below, pressing the button will GET directory.xml via HTTP:

    SIPDefault.cnf

    #The directory_url contains a URL to the directory XML file
    directory_url: "http://www.example.com/directory.xml"

    directory.xml could just contain a phonebook in XML, like the example directory file below. This is fine if you don't want to search and don't have more than 32 entries. If you do, you have to do things a little differently. You can add the following to directory.xml:
    <CiscoIPPhoneInput>
        <Title>Phone book</Title>
        <Prompt>Prompt text.</Prompt>
        <URL>http://www.example.com/phonebook.pl</URL>
        <InputItem>
                <DisplayName>search</DisplayName>
                <QueryStringParam>search</QueryStringParam>
                <InputFlags></InputFlags>
                <DefaultValue></DefaultValue>
        </InputItem>
    </CiscoIPPhoneInput>
        
    Now, when you press the directory button, you will be presented with a search screen. You can enter a name and press search. It will then try to GET /phonebook.pl?search=name from the HTTP server. Thus you will have to write a script that searches for the string in your phone directory and returns the results using the CISCO XML format below. This is obviously a lot more work but hey, these are enterprise phones!

    Example directory file

    <CiscoIPPhoneDirectory>
    <Title>Directory</Title>
    <Prompt>Who you gonna call?</Prompt>
    <DirectoryEntry>
         <Name>Tom</Name>
         <Telephone>6905</Telephone>
    </DirectoryEntry>
    <DirectoryEntry>
         <Name>Dick</Name>
         <Telephone>6906</Telephone>
    </DirectoryEntry>
    </CiscoIPPhoneDirectory>
        

    Voicemail number

    The 7940 has a voicemail button that dials your viocemail. Sound clever? It's just a config directive that tells it which number to dial when thebutton is pressed. Add the following to your SIPDefault.cnf:messages_uri: "8500"
    So, when you hit the message button it dials 8500, which, as we all know is the default main voicemail number for Asterisk. We can also go a step further and create a number that dials the voice mail. Change the number in the mesasges_uri to 8501 and create the following extention in extentionss.conf:
    exten => 8501,1,VoicemailMain(${CALLERID(number)})
    exten => 8501,n,Hangup

    This means that when you press the message button it will dial 8501 which Asterisk will call voicemail and pass the number of your phone to the Voicemail. This will go stagiht to that mailbox number without having to enter it. If the voicemail box for that phone does not match the phone's callerID num, you could pass it statically, of course.

    Message Waiting Indicator

    Asterisk can turn on and off the Message Waiting Indicator on phones. This is simply a case of adding "mailbox " to the phone definition in the sip.conf file. Then, when there is a new message in that mailbox, it will turn on the MWI on the phone. When there is no voicemail it will be turned off.

    viernes, 13 de mayo de 2016

    freepbx ami calling

    1. <?php
    2. $pbx="14.238.148.19";
    3. $trunk="commpeak";
    4. $timeout=45;
    5. $exten=$_GET['exten'];
    6. $cid=$_GET['cid'];
    7. $dest=$_GET['dest'];
    8. $socket = fsockopen($pbx,"5038", $errno, $errstr, $timeout);
    9.  fputs($socket, "Action: Login\r\n");
    10.  fputs($socket, "UserName: admin\r\n");     //
    11.  fputs($socket, "Secret:  x3tss4\r\n\r\n");  //
    12.                                             //
    13.      $wrets=fgets($socket,128);
    14.               echo $wrets;
    15.                 fputs($socket, "Action: Originate\r\n" );
    16.                 #fputs($socket, "Channel: Local/$dest@local\r\n" );
    17.                fputs($socket, "Channel: SIP/$exten\r\n" );
    18.                #fputs($socket, "Channel: SIP/$trunk/$exten\r\n" );
    19.                fputs($socket, "Exten: $dest\r\n" );
    20.                fputs($socket, "Context: from-internal\r\n" );
    21.                fputs($socket, "Priority: 1\r\n" );
    22.                fputs($socket, "CallerID: $cid\r\n" );
    23.                 fputs($socket, "Variable: __var1=$dest\r\n" );
    24.                fputs($socket, "Variable: __var2=$exten\r\n" );
    25.              fputs($socket, "Async: yes\r\n\r\n" );
    26.               fputs($socket, "Action: Logoff\r\n\r\n");
    27.  sleep (1);
    28.  $wrets=fgets($socket,128);
    29. ?>
    30. URL de ejemplo
    31. exten numero a llamar
    32. dest numero de destino
    33. cid  caller id
    34. http://5.181.118.22/dialer/dialer_test.php?exten=200&dest=18007143030&cid=18007143030

    domingo, 8 de mayo de 2016

    allowing access to specifc ip to spefic ports

    1. iptables -I INPUT 2 -m state --state NEW -m tcp -p tcp --dport 80  -s 177.44.7.14 -j ACCEPT
    2. iptables -I INPUT 2 -m state --state NEW -m udp -p udp --dport 5060  -s 177.44.7.14 -j ACCEPT
    3. iptables -I INPUT 2 -m state --state NEW -m udp -p udp --dport 10000:20000  -s 177.44.7.14 -j ACCEPT
    4.  by range
    5. iptables -I INPUT 2 -m state --state NEW -m tcp -p tcp --dport 80  -s 186.150.197.0/24 -j ACCEPT

    1.  iptables -I INPUT 2 -m state --state NEW -m udp -p udp --dport 5060  -s 186.150.197.0/24 -j ACCEPT


    iptables -I INPUT 2 -m state --state NEW -m udp -p udp --dport 10000:20000  -s 186.150.197.0/24 -j ACCEPT

    service iptables save

    sábado, 16 de abril de 2016

    asterisl realtime notes

    http://www.voip-info.org/wiki/view/Asterisk+RealTime+Sip
    https://wiki.asterisk.org/wiki/display/AST/Realtime+Database+Configuration#RealtimeDatabaseConfiguration-Notesonuseofthesipregsfamily
    http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/I_section12_tt1465.html

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

    http://www.open-voip.org/index.php?title=Asterisk_Full_RealTime_example





    mysql> INSERT INTO asterisk.sippeers (  NAME, defaultuser, secret, context, HOST, nat, qualify, TYPE)  VALUES (  '1005', '1005', '0111234', 'from-internal', 'dynamic', 'yes', 'no', 'friend');
    Query OK, 1 row affected (0.00 sec)

    Update : use "sip prune realtime PEERNAME" then "sip show peer PEERNAME load" to flush the peer and reload from db - (Voicemeup)

     523  cd ..
      524  cd ..
      525  cd ast-db-manage/
      526  ls
      527  nano config.ini.sample
      528  nano config.ini.sample
      529  clear
      530  cp config.ini.sample config.ini
      531  alembic -c config.ini upgrade head
      532  pip install alembic
      533  alembic -c config.ini upgrade head
      534  mysql -u root -p -D asterisk


    /etc/asterisk/extconfig

    ;iaxusers => odbc,asterisk
    ;iaxpeers => odbc,asterisk
     sippeers => odbc,asterisk
    ;sipregs => odbc,asterisk ; (avoid sipregs if possible, e.g. by using a view)
    ;ps_endpoints => odbc,asterisk
    ;ps_auths => odbc,asterisk
    ;ps_aors => odbc,asterisk
    ;ps_domain_aliases => odbc,asterisk
    ;ps_endpoint_id_ips => odbc,asterisk
    ;voicemail => odbc,asterisk
    ;extensions => odbc,asterisk
    ;meetme => mysql,general
    ;queues => odbc,asterisk
    ;queue_members => odbc,asterisk
    ;queue_rules => odbc,asterisk
    ;acls => odbc,asterisk
    ;musiconhold => mysql,general
    ;queue_log => mysql,general


    res_odbc.conf
    [asterisk]
    enabled => yes
    dsn => asterisk-mysql
    username => root
    password => 12223
    pre-connect => ye



    /etc/asterisk/sip.conf
    [general]
    switch => Realtime


    cd /usr/src/asterisk-13.8.1/contrib/realtime/mysql


    mysql -p1234 asterisk < mysql_config.sql

    jueves, 7 de abril de 2016

    Dialing based on CID

    #!/usr/bin/php -q
    <?php
    set_time_limit(30);
    require('/var/lib/asterisk/agi-bin/phpagi-2.20/phpagi.php');
    error_reporting(E_ALL);
    $agi = new AGI();
    $cid = $agi->parse_callerid();
    $agi->stream_file("welcome");
    $agi->exec("sayalpha","$cid[username]");
    //$result = $agi->get_data('agent-pass',8000,3);
    $str =$cid[username];
    $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);

    $num=0;
    $letters=0;

    foreach($chars as $elements){

      if (is_numeric($elements)) {
     $num+=1;

      }



     else{
     $letters+=1;

      }



    }

    $agi->exec("sayalpha","$num");
    $agi->exec("sayalpha","$letters");

    if($num==4){
    $agi->exec_goto("cidialout","$argv[1]","_777");
    }


    if($num==5){
    $agi->exec_goto("cidialout","$argv[1]","_888");
    }

    ?>


    [cidialout]
    exten=>_x.,1,Noop( Dialing to ${EXTEN})
    same=>n(_555 ),Dial(SIP/rapidvox/555${EXTEN},25)
    same=>n,Hangup()
    same=>n(_666),Dial(SIP/${TRUNK}/666${EXTEN},25)
    same=>n,Hangup()
    same=>n(_777),Dial(SIP/rapidvox/777${EXTEN},25)
    same=>n,Hangup()
    same=>n(_888),Dial(SIP/${TRUNK}/888${EXTEN},25)
    same=>n,Hangup()



    miércoles, 6 de abril de 2016

    Record During Dial()

    record (monitor to a file) the inbound audio of incoming calls up until the point that those calls are answered. In other words, only record up until the point the dial() command finishes executing and a call is either connected/bridged or sent somewhere else (like voicemail).



    :one: The dial() command should look something like this:

    exten => 300,n,Dial(SIP/110,30,itTm(stdmusic)M(answered^${CHANNEL}))

    :two: The macro should look something like this:

    [macro-answered]
    exten => s,1,AGI(stop_monitor.agi,${ARG1})

    :three: The stop_monitor.agi script should look something like this:

    #!/usr/bin/php -q
    <?php
    $channel = $argv[1];
    $socket = fsockopen("localhost","5038", $errno, $errstr, 2);
    fputs($socket, "Action: Login\r\n");
    fputs($socket, "UserName: <AMI username>\r\n");
    fputs($socket, "Secret: <AMI password>\r\n\r\n");
    fputs($socket, "Action: StopMonitor\r\n");
    fputs($socket, "Channel: $channel\r\n\r\n");
    fputs($socket, "Action: Logoff\r\n\r\n");
    $wrets=fgets($socket,128);
    while (!feof($socket)) { $wrets .= fread($socket, 8192); }
    fclose($socket);
    ?>
    https://community.asterisk.org/t/record-during-dial-unusual-problem-requires-creative-solution/65974

    martes, 5 de abril de 2016

    setting the caller caller on outbound call foward

    create a misc destination on the GUI like 00818097142323  then  on outbound route on the GUI  with  1NXXNXXXXX


    [from-internal-custom]
    exten => 1234,1,Playback(demo-congrats)         ; extensions can dial 1234
    exten => 1234,2,Hangup()
    exten => h,1,Hangup()


    exten=>_001NXXNXXXXXX,1,Noop( ${CALLERID(num)})
    same=>n,Set(CALLERID(num)=${CALLERID(num)})
    same=>n,Goto(from-internal,${EXTEN:2},1)