FreePBX extensions to Yealink Phone book can someone who knows python make htis better
-
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:
And is assigned to a DSS Key like this.
-
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
-
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)
-
And now I have a better thing thanks to George Kanicki over on SW.
-
@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?
-
@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 -
Awesome, I wrote our XML remote phonebook by hand with the YeaLink template. This is going to be fun!
-
@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