[Freeswitch-svn] [commit] r11473 - freeswitch/trunk/scripts/contrib/Phil/pylons
FreeSWITCH SVN
Phil at freeswitch.org
Fri Jan 23 15:08:59 PST 2009
Author: Phil
Date: Fri Jan 23 17:08:59 2009
New Revision: 11473
Log:
pylons controllers for FS
Added:
freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchcdr.py
freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchdialplan.py
freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchdirectory.py
Added: freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchcdr.py
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchcdr.py Fri Jan 23 17:08:59 2009
@@ -0,0 +1,60 @@
+import logging
+
+from freeswitch.lib.base import *
+
+
+import xml
+from xml.sax.handler import ContentHandler
+
+
+log = logging.getLogger(__name__)
+
+
+class FreeswitchcdrController(BaseController):
+
+
+ # simple method to display the uuid of a call that got terminated
+ def cdr(self):
+
+ next = 0
+ uuid = []
+
+ try:
+ cdr = request.POST.getone('cdr')
+ # needs to be casted to a string as the unicode string can't be parsed correctly by the sax parser
+ cdr = str(cdr)
+
+ cdrHandler = CDR_XML_Handler()
+ xml.sax.parseString(cdr, cdrHandler)
+ uuid = cdrHandler.uuid
+ print uuid
+
+
+ except KeyError, e:
+ print e
+ return
+
+
+
+
+class CDR_XML_Handler(ContentHandler):
+
+ def __init__(self):
+ self.uuid = []
+ self.uuidString = ""
+ self.isUuidElement = 0
+
+ def startElement(self, name, attrs):
+
+ if name == 'uuid':
+ self.isUuidElement = 1
+ uuidString = ""
+
+ def characters(self, ch):
+ if self.isUuidElement == 1:
+ self.uuidString += ch
+
+ def endElement(self, name):
+ if name == 'uuid':
+ self.isUuidElement= 0
+ self.uuid.append(self.uuidString)
Added: freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchdialplan.py
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchdialplan.py Fri Jan 23 17:08:59 2009
@@ -0,0 +1,154 @@
+import logging
+
+from freeswitch.lib.base import *
+
+
+
+log = logging.getLogger(__name__)
+
+class FreeswitchdialplanController(BaseController):
+
+
+
+
+ # needs to be checked what's the best return string when an error occures
+ error = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="dialplan" description="RE Dial Plan For FreeSwitch">\n'''\
+ '''</section>\n'''\
+ '''</document>'''
+
+
+
+ # the name forward is a bit confusing as it is actually a FS bridge
+ # the next two methods allow you to forward a single call to n number of outbound calls
+ def forwardCreate(self, number, gateway, forwardString):
+ if forwardString != '':
+ forwardString = forwardString + ','
+
+ return forwardString + '''sofia/gateway/%s/%s''' % (gateway, number)
+
+
+
+ def forwardFinishCreate(self, didNumber, forwardString):
+ return '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="dialplan" description="RE Dial Plan For FreeSwitch">\n'''\
+ '''<context name="public">\n'''\
+ '''<extension name="extension%s">\n'''\
+ '''<condition field="destination_number" expression="^(%s)$">\n'''\
+ '''<action application="bridge" data="%s"/>\n'''\
+ '''</condition>\n'''\
+ '''</extension>\n'''\
+ '''</context>\n'''\
+ '''</section>\n'''\
+ '''</document>\n''' % (didNumber, didNumber, forwardString)
+
+
+ # bridge one inbound call with a single outbound call
+ def bridge(self, didNumber, outboundNumber, gateway):
+
+ return '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="dialplan" description="RE Dial Plan For FreeSwitch">\n'''\
+ '''<context name="public">\n'''\
+ '''<extension name="extension%s">\n'''\
+ '''<condition field="destination_number" expression="^(%s)$">\n'''\
+ '''<action application="bridge" data="sofia/gateway/%s/%s"/>\n'''\
+ '''</condition>\n'''\
+ '''</extension>\n'''\
+ '''</context>\n'''\
+ '''</section>\n'''\
+ '''</document>\n''' % (didNumber, didNumber, gateway, outboundNumber)
+
+
+
+ def voicemail(self, didNumber, mailbox_id):
+
+ return '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="dialplan" description="RE Dial Plan For FreeSwitch">\n'''\
+ '''<context name="public">\n'''\
+ '''<extension name="voicemail%s">\n'''\
+ '''<condition field="destination_number" expression="^(%s)$">\n'''\
+ '''<action application="voicemail" data="default $${domain} %s"/>\n'''\
+ '''</condition>\n'''\
+ '''</extension>\n'''\
+ '''</context>\n'''\
+ '''</section>\n'''\
+ '''</document>''' % (didNumber, didNumber, mailbox_id)
+
+ def checkVoicemail(self, didNumber, mailbox_id):
+
+ return '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="dialplan" description="RE Dial Plan For FreeSwitch">\n'''\
+ '''<context name="public">\n'''\
+ '''<extension name="voicemail%s">\n'''\
+ '''<condition field="destination_number" expression="^(%s)$">\n'''\
+ '''<action application="voicemail" data="check default $${domain} %s"/>\n'''\
+ '''</condition>\n'''\
+ '''</extension>\n'''\
+ '''</context>\n'''\
+ '''</section>\n'''\
+ '''</document>''' % (didNumber, didNumber, mailbox_id)
+
+
+ # if you hungup the call before it has been answered a busy is issued
+ def busy(self, didNumber):
+ return '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="dialplan" description="RE Dial Plan For FreeSwitch">\n'''\
+ '''<context name="public">\n'''\
+ '''<extension name="extension%s">\n'''\
+ '''<condition field="destination_number" expression="^(%s)$">\n'''\
+ '''<action application="hungup" data=""/>\n'''\
+ '''</condition>\n'''\
+ '''</extension>\n'''\
+ '''</context>\n'''\
+ '''</section>\n'''\
+ '''</document>\n''' % (destinationNumber, didNumber)
+
+
+
+
+ def dialplan(self):
+
+ action = "voicemail"
+
+ # replace with your sofia gateway
+ gateway = 'sipgate2'
+
+ # replace with phone numbers
+ forwards = ['the did number extension - gateway', 'the number to forward to']
+
+ # that is the username of the mailbox
+ mailbox_id = 'test'
+
+
+ didNumber = str(request.POST.getone('Caller-Destination-Number'))
+
+
+ # ------------------------------------------------------------ Forward -------------------------------------------------------
+ # if the action is forward, we forward to all numbers in forwards
+ if action == "forward":
+
+ forwardString = ''
+ for f in forwards:
+ forwardString = self.forwardCreate(f, gateway, forwardString)
+
+ return self.forwardFinishCreate(didNumber, forwardString)
+
+
+
+ elif action == "checkVoicemail":
+
+ return self.checkVoicemail(didNumber, mailbox_id)
+
+
+
+ elif action == "voicemail":
+
+ return self.voicemail(didNumber, mailbox_id)
+
+
Added: freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchdirectory.py
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/Phil/pylons/freeswitchdirectory.py Fri Jan 23 17:08:59 2009
@@ -0,0 +1,67 @@
+import logging
+
+from freeswitch.lib.base import *
+
+
+
+
+log = logging.getLogger(__name__)
+
+class FreeswitchdirectoryController(BaseController):
+
+ bootReply = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="directory" description="arbitrary stuff here">\n'''\
+ '''</section>\n'''\
+ '''</document>'''
+
+ error = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="dialplan" description="RE Dial Plan For FreeSwitch">\n'''\
+ '''</section>\n'''\
+ '''</document>'''
+
+ def user(self, didNumber, domain, mailbox_id):
+ test = '''<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'''\
+ '''<document type="freeswitch/xml">\n'''\
+ '''<section name="directory" description="arbitrary stuff here">\n'''\
+ '''<domain name="%s">\n'''\
+ '''<groups>\n'''\
+ '''<group name="default">\n'''\
+ '''<users>\n'''\
+ '''<user id="%s" mailbox="%s">\n'''\
+ '''<params>\n'''\
+ '''<param name="password" value="1234"/>\n'''\
+ '''<param name="vm-password" value="0000"/>\n'''\
+ '''</params>\n'''\
+ '''<variables>\n'''\
+ '''<variable name="accountcode" value="%s"/>\n'''\
+ '''<variable name="user_context" value="default"/>\n'''\
+ '''<variable name="vm_extension" value="%s"/>\n'''\
+ '''<variable name="max_calls" value="1"/>\n'''\
+ '''<variable name="fail_over" value="415"/>\n'''\
+ '''<variable name="cringback" value="us-ring"/>\n'''\
+ '''</variables>\n'''\
+ '''</user>\n'''\
+ '''</users>\n'''\
+ '''</group>\n'''\
+ '''</groups>\n'''\
+ '''</domain>\n'''\
+ '''</section>\n'''\
+ '''</document>''' % (domain, mailbox_id, mailbox_id, mailbox_id, mailbox_id)
+
+ return test
+
+
+ # a very simple reply that creates a user for the voicemail.
+ def directory(self):
+
+ try:
+ return self.user(request.POST.getone('mailbox'), request.POST.getone('domain'), request.POST.getone('user'))
+
+ except KeyError, e:
+ pass
+
+ return self.bootReply
+
+
More information about the Freeswitch-svn
mailing list