ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    FreePBX extensions to Yealink Phone book can someone who knows python make htis better

    IT Discussion
    python freepbx extensions contacts
    3
    8
    2.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch
      last edited by JaredBusch

      I keep getting asked for a way to output the extensions from FreePBX.

      There are two ways that Yealink phones will take address book files.
      One is designed for the local address book and I would rather not mess up user input stuff.

      So the other method is a remote address book. The output is a simple XML file like this.

      <?xml version="1.0" encoding="utf-8"?>
      <CompanyIPPhoneDirectory>
          <DirectoryEntry>
              <Name>Jared Busch</Name>
              <Telephone>103</Telephone>
          </DirectoryEntry>
          <DirectoryEntry>
              <Name>Another Person</Name>
              <Telephone>106</Telephone>
          </DirectoryEntry>
      </CompanyIPPhoneDirectory>
      

      I modified an old script that someone used to pull CID info into a json to pull extensions.

      It dumps the file to /var/www/html which all phones should have access to.

      But I really expect this little script can be done much more efficiently. I am not a python coder.

      #!/usr/bin/env python
      import subprocess
      extension = {}
      output = []
      output.append('<?xml version="1.0" encoding="utf-8"?>')
      output.append('<CompanyIPPhoneDirectory>')
      p = subprocess.Popen(["asterisk", "-rx", "database show"], stdout=subprocess.PIPE)
      out =  p.communicate()
      out = out[0].splitlines()
      for line in out:
          if line.startswith('/AMPUSER'):
              if line.find('/cidname') > 1:
                  key,value = line.split(':')
                  key = key.strip()
                  key = key.split('/')[2]
                  value = value.strip()
                  extension[key] = value
                  output.append('    <DirectoryEntry>')
                  output.append('        <Name>' + value + '</Name>')
                  output.append('        <Telephone>' + key + '</Telephone>')
                  output.append('    </DirectoryEntry>')
      output.append('</CompanyIPPhoneDirectory>')
      
      contactfile = open('/var/www/html/contacts.xml', 'w')
      for item in output:
          contactfile.write("%s\n" % item)
      

      It goes in the phone like this:
      0_1512418800076_94d61e53-43e9-4217-9a50-b0de99e26342-image.png

      And is assigned to a DSS Key like this.
      0_1512418686192_e661b242-d65f-4622-911d-d8431d998425-image.png

      1 Reply Last reply Reply Quote 3
      • JaredBuschJ
        JaredBusch
        last edited by JaredBusch

        The source data from the asterisk command outputs a ton of data, but this is the entry for a single extension.

        I just grabbed the one line containing the CID Name.

        /AMPUSER/103/answermode                           : disabled                 
        /AMPUSER/103/cfringtimer                          : 0                        
        /AMPUSER/103/cidname                              : Jared Busch              
        /AMPUSER/103/cidnum                               : 103                      
        /AMPUSER/103/concurrency_limit                    : 3                        
        /AMPUSER/103/device                               : 99103&103                
        /AMPUSER/103/dictate/email                        :                          
        /AMPUSER/103/dictate/enabled                      : disabled                 
        /AMPUSER/103/dictate/format                       : ogg                      
        /AMPUSER/103/dictate/from                         : 
        /AMPUSER/103/followme/annmsg                      :                          
        /AMPUSER/103/followme/changecid                   : default                  
        /AMPUSER/103/followme/ddial                       : DIRECT                   
        /AMPUSER/103/followme/dring                       :                          
        /AMPUSER/103/followme/fixedcid                    :                          
        /AMPUSER/103/followme/grpconf                     : DISABLED                 
        /AMPUSER/103/followme/grplist                     : 103-314NXXXXXX#          
        /AMPUSER/103/followme/grppre                      :                          
        /AMPUSER/103/followme/grptime                     : 26                       
        /AMPUSER/103/followme/postdest                    : ext-local,103,dest       
        /AMPUSER/103/followme/prering                     : 10                       
        /AMPUSER/103/followme/remotealertmsg              :                          
        /AMPUSER/103/followme/ringing                     : Ring                     
        /AMPUSER/103/followme/rvolume                     :                          
        /AMPUSER/103/followme/strategy                    : ringallv2                
        /AMPUSER/103/followme/toolatemsg                  :                          
        /AMPUSER/103/hint                                 : PJSIP/103&SIP/99103&Custom:DND103,CustomPresence:103
        /AMPUSER/103/intercom                             : enabled                  
        /AMPUSER/103/intercom/override                    : reject                   
        /AMPUSER/103/language                             :                          
        /AMPUSER/103/noanswer                             :                          
        /AMPUSER/103/novmpw                               : yes                      
        /AMPUSER/103/novmstar                             : yes                      
        /AMPUSER/103/outboundcid                          :                          
        /AMPUSER/103/password                             :                          
        /AMPUSER/103/queues/qnostate                      : usestate                 
        /AMPUSER/103/recording                            :                          
        /AMPUSER/103/recording/in/external                : dontcare                 
        /AMPUSER/103/recording/in/internal                : dontcare                 
        /AMPUSER/103/recording/ondemand                   : disabled                 
        /AMPUSER/103/recording/out/external               : dontcare                 
        /AMPUSER/103/recording/out/internal               : dontcare                 
        /AMPUSER/103/recording/priority                   : 10                       
        /AMPUSER/103/ringtimer                            : 0                        
        /AMPUSER/103/rvolume                              :                          
        /AMPUSER/103/voicemail                            : default          
        
        1 Reply Last reply Reply Quote 0
        • JaredBuschJ
          JaredBusch
          last edited by

          The other choice would be to use the MariaDB information. But for that you need to store get the root password.

          But that is available in etc/freepbx.conf

          [root@fpbx ~]# cat /etc/freepbx.conf 
          <?php
          $amp_conf['AMPDBUSER'] = 'freepbxuser';
          $amp_conf['AMPDBPASS'] = 'somerandom5hash';
          $amp_conf['AMPDBHOST'] = 'localhost';
          $amp_conf['AMPDBNAME'] = 'asterisk';
          $amp_conf['AMPDBENGINE'] = 'mysql';
          $amp_conf['datasource'] = ''; //for sqlite3
          
          require_once('/var/www/html/admin/bootstrap.php');
          ?>
          
          MariaDB [asterisk]> select * from devices;
          +---------+--------+-------------+------------+-------+---------------------+---------------+
          | id      | tech   | dial        | devicetype | user  | description         | emergency_cid |
          +---------+--------+-------------+------------+-------+---------------------+---------------+
          | 103     | pjsip  | PJSIP/103   | fixed      | 103   | Jared Busch         |               |
          +---------+--------+-------------+------------+-------+---------------------+---------------+
          12 rows in set (0.00 sec)
          
          1 Reply Last reply Reply Quote 0
          • JaredBuschJ
            JaredBusch
            last edited by JaredBusch

            And now I have a better thing thanks to George Kanicki over on SW.

            scottalanmillerS 1 Reply Last reply Reply Quote 1
            • scottalanmillerS
              scottalanmiller @JaredBusch
              last edited by

              @jaredbusch said in FreePBX extensions to Yealink Phone book can someone who knows python make htis better:

              And now I have a better thing thanks to George Kanicki over on SW.

              What was his solution?

              JaredBuschJ 1 Reply Last reply Reply Quote 0
              • JaredBuschJ
                JaredBusch @scottalanmiller
                last edited by

                @scottalanmiller said in FreePBX extensions to Yealink Phone book can someone who knows python make htis better:

                @jaredbusch said in FreePBX extensions to Yealink Phone book can someone who knows python make htis better:

                And now I have a better thing thanks to George Kanicki over on SW.

                What was his solution?

                His solution is on a new github repo I just setup, along with my new version of it. Making a how to post shortly.
                https://github.com/sorvani/freepbx-helper-scripts

                1 Reply Last reply Reply Quote 2
                • SmithErickS
                  SmithErick
                  last edited by

                  Awesome, I wrote our XML remote phonebook by hand with the YeaLink template. This is going to be fun!

                  JaredBuschJ 1 Reply Last reply Reply Quote 1
                  • JaredBuschJ
                    JaredBusch @SmithErick
                    last edited by

                    @smitherick said in FreePBX extensions to Yealink Phone book can someone who knows python make htis better:

                    Awesome, I wrote our XML remote phonebook by hand with the YeaLink template. This is going to be fun!

                    Follow this post.
                    https://mangolassi.it/topic/15759/use-a-php-file-to-create-a-dynamic-yealink-remote-address-book-of-freepbx-extensions

                    1 Reply Last reply Reply Quote 3
                    • 1 / 1
                    • First post
                      Last post