Upgrade openssl-1.0.1 on Debian 6

Freeswitch 를 설치하는데 openssl-1.0 이상 버전을 요구했다.

현재 운용중인 서버 버전은 Debian-6.0
apt-get 으로 설치 가능한 openssl 버전은 0.9.x 버전이었다.

 

즉, openssl 버전 문제로 정상적인 설치가 안되는 상황.
openssl 최신버전이야 소스 설치를 하면 되겠는데.. 문제는 이미 사용중인 openssl-0.9.x 버전은 어떻게 하느냐였다.
이미 많은 수의 패키지들이 라이브러리를 참조하고 있었다.
실제로 apt-get remove 명령어로 해당 패키지를 지워볼까 생각도 했는데, 의존성 문제로 상당히 많은 수의 패키지들을 같이 지워야 해서 관두었다.

어쩔까…
Linux HanIRC 채널에 문의를 해보니 다행히 답변이 나왔다.

그냥 덮어쓰면 된다는 것.

 wget http://openssl.org/source/openssl-1.0.1.tar.gz 
 tar xfz openssl-1.0.1.tar.gz 
 cd openssl-* 
 ./config --prefix=/usr zlib-dynamic --openssldir=/etc/ssl shared 
 make 
 sudo make install

 

출처 : http://mariobrandt.de/archives/linux/upgrading-openssl-on-debian-6-squeeze-or-ubuntu-8-04-hardy-456

[Freeswitch] Making freeswitch python script

실행되는 기본 함수

Freeswitch 에서 Python 스크립트를 호출할 때, 호출하는 주체가 어디냐에 따라 자동으로 실행되는 Default 함수가 달라진다.

 

– Dialplan 내에서 <action application=”python” data=”mod_fstest.python_example”/> 와 같은 형식으로 호출되는 경우.

호출되는 스크립트 내, handler() 함수가 호출된다.

handler() 함수의 모습은

# APPLICATION
#
# default name for apps is "handler" it can be overridden with <modname>::<function>
# session is a session object
# args is all the args passed after the module name
def handler(session, args):

	consoleLog('info', 'Answering call from Python.n')

처럼 되어야 한다.

 

– fs_cli 등에서 python 명령으로 호출되는 스크립트의 경우.
호출되는 스크립트 내의 fsapi() 함수가 호출된다.

fsapi() 함수의 모습은

# FSAPI CALL FROM CLI, DP HTTP etc
#
# default name for python FSAPI is "fsapi" it can be overridden with <modname>::<function>
# stream is a switch_stream, anything written with stream.write() is returned to the caller
# env is a switch_event
# args is all the args passed after the module name
# session is a session object when called from the dial plan or the string "na" when not.
def fsapi(session, stream, env, args):

	stream.write("w00t!n" + env.serialize())

처럼 되어야 한다.

 

– fs_cli 등에서 pyrun 명령으로 호출되는 스크립트의 경우,

호출되는 스크립트 내의 runtime() 함수가 호출된다.

runtime() 함수의 모습은

# RUN A FUNCTION IN A THREAD
#
# default name for pyrun is "runtime" it can be overridden with <modname>::<function>
# args is all the args passed after the module name
def runtime(args):

	print args + "n"

처럼 되어야 한다.

 

지원 API

mod_python 모듈을 이용하여 스크립트 작성시, freeswitch 에서 제공하는 여러가지 API 들을 이용하여 편리하게 프로그래밍을 할 수 있다.
지원하는 API 내용은 mod_lua 와 똑같은 내용의 API 를 지원하며 자세한 기능 및 API 일람은 아래의 링크에서 확인할 수 있다.

mod_lua API 목록: https://wiki.freeswitch.org/wiki/Mod_lua

 

예제 python Script

예제로 사용한 python script 이다. 원본은 https://wiki.freeswitch.org/wiki/Mod_python#Sample_Python_Scripts 에서 구할 수 있다.

import os
from freeswitch import *

# HANGUP HOOK
#
# session is a session object
# what is "hangup" or "transfer"
# if you pass an extra arg to setInputCallback then append 'arg' to get that value
# def hangup_hook(session, what, arg):
def hangup_hook(session, what):

	consoleLog("info","hangup hook for %s!!nn" % what)
	return


# INPUT CALLBACK
#
# session is a session object
# what is "dtmf" or "event"
# obj is a dtmf object or an event object depending on the 'what' var.
# if you pass an extra arg to setInputCallback then append 'arg' to get that value
# def input_callback(session, what, obj, arg):
def input_callback(session, what, obj):

	if (what == "dtmf"):
		consoleLog("info", what + " " + obj.digit + "n")
	else:
		consoleLog("info", what + " " + obj.serialize() + "n")		
	return "pause"

# APPLICATION
#
# default name for apps is "handler" it can be overridden with <modname>::<function>
# session is a session object
# args is all the args passed after the module name
def handler(session, args):

	consoleLog('info', 'Answering call from Python.n')
	consoleLog('info', 'Arguments: %sn' % args)

	session.answer()
	session.setHangupHook(hangup_hook)
	session.setInputCallback(input_callback)
	session.execute("playback", session.getVariable("hold_music"))

# FSAPI CALL FROM CLI, DP HTTP etc
#
# default name for python FSAPI is "fsapi" it can be overridden with <modname>::<function>
# stream is a switch_stream, anything written with stream.write() is returned to the caller
# env is a switch_event
# args is all the args passed after the module name
# session is a session object when called from the dial plan or the string "na" when not.
def fsapi(session, stream, env, args):

	stream.write("w00t!n" + env.serialize())
	

# RUN A FUNCTION IN A THREAD
#
# default name for pyrun is "runtime" it can be overridden with <modname>::<function>
# args is all the args passed after the module name
def runtime(args):

	print args + "n"

# BIND TO AN XML LOOKUP
#
# default name for binding to an XML lookup is "xml_fetch" it can be overridden with <modname>::<function>
# params a switch_event with all the relevant data about what is being searched for in the XML registry.
#
def xml_fetch(params):

	xml = '''
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="freeswitch/xml">
  <section name="dialplan" description="RE Dial Plan For FreeSWITCH">
    <context name="default">
      <extension name="generated">
        <condition>
         <action application="answer"/>
         <action application="playback" data="${hold_music}"/>
        </condition>
      </extension>
    </context>
  </section>
</document>
'''

	return xml

 

예제로 사용한 dialplan 이다. “5555555”로 전화를 걸면 스크립트가 사용된다.

<include>
  <extension name="python_test">
    <condition field="destination_number" expression="^(5555555)$">
      <!--
      If you're hosting multiple domains you will want to set the
      target_domain on these calls so they hit the proper domain after you
      transfer the caller into the default context. 
      
      $${domain} is the default domain set from vars.xml but you can set it
      to any domain you have setup in your user directory.

      -->
      <action application="info"/>
      <action application="python" data="mod_fstest.python_example"/>
      <!--<action application="set" data="domain_name=$${domain}"/>-->
      <!-- This example maps the DID 5551212 to ring 1000 in the default context -->
      <!--<action application="transfer" data="1000 XML default"/>-->
    </condition>
  </extension>
</include>

 

작성한 Python 스크립트를 dialplan 에서 호출하기 위해서는, 당연하겠지만 Dialplan 내에서 어떤 스크립트를 호출할지를 지정해 주어야 한다.

<action application=”python” data=”foo.bar”/>

위에 입력한 foo.bar 는 foo package 에 있는 bar 모듈을 호출한다는 설정이다. 뒤에 확장자 .py 를 붙이지 않도록 주의하자.
이 경우, 사용하게 되는 함수는 ‘handler’ 함수이다.

2014-05-06 17:55:40.838121 [NOTICE] mod_python.c:212 Invoking py module: mod_fstest.python_example
2014-05-06 17:55:40.838121 [DEBUG] mod_python.c:281 Call python script 
2014-05-06 17:55:40.838121 [INFO] switch_cpp.cpp:1293 Answering call from Python.
2014-05-06 17:55:40.838121 [INFO] switch_cpp.cpp:1293 Arguments:

handler 함수.

# APPLICATION
#
# default name for apps is "handler" it can be overridden with <modname>::<function>
# session is a session object
# args is all the args passed after the module name
def handler(session, args):

	consoleLog('info', 'Answering call from Python.n')
	consoleLog('info', 'Arguments: %sn' % args)

	session.answer()
	session.setHangupHook(hangup_hook)
	session.setInputCallback(input_callback)
	session.execute("playback", session.getVariable("hold_music"))

인자 값으로 session 과 args 를 입력받는다.
session 은 python 스크립트 내에서 사용되는 freeswitch interface 객체이며, args 는 모듈 호출시 넘겨지는 인자값들이다.

 

또한, fs_cli 에서 바로 작성한 python 스크립트를 호출할 수 있다. 이 경우, 사용한 명령어에 따라 호출되는 함수가 달라지는데, python 명령으로 호출할 경우, 스크립트 내, ‘fsapi’ 함수가 바로 호출이 된다.

freeswitch@192.168.200.10@internal> python mod_fstest.python_example
w00t!
'Event-Name: API
Core-UUID: 86d48a48-6f22-475c-89ac-146e6d0217d9
FreeSWITCH-Hostname: MyDebian
FreeSWITCH-Switchname: MyDebian
FreeSWITCH-IPv4: 10.0.2.10
FreeSWITCH-IPv6: %3A%3A1
Event-Date-Local: 2014-05-06%2017%3A43%3A01
Event-Date-GMT: Tue,%2006%20May%202014%2015%3A43%3A01%20GMT
Event-Date-Timestamp: 1399390981818146
Event-Calling-File: switch_loadable_module.c
Event-Calling-Function: switch_api_execute
Event-Calling-Line-Number: 2406
Event-Sequence: 4158
API-Command: python
API-Command-Argument: mod_fstest.python_example

'
2014-05-06 17:43:01.818146 [NOTICE] mod_python.c:212 Invoking py module: mod_fstest.python_example
2014-05-06 17:43:01.818146 [DEBUG] mod_python.c:281 Call python script 
2014-05-06 17:43:01.818146 [DEBUG] mod_python.c:284 Finished calling python script

 

참조 : https://wiki.freeswitch.org/wiki/Mod_python#Sample_Python_Scripts

 

 

[Freeswitch] Support language

Freeswitch 에서 제공하는 Dialplan 기능 중에서는 다른 언어를 사용할 수 있도록 해주는 기능들이 있다.

지원 가능한 언어 목록은 다음과 같다.

Languages

Languages for Call Control explained.

Languages (unsupported / out of tree)

특이할 점은 php 와 ruby 는 공식적으로는 지원하지 않는다는 점이다.

Dialplan 작성시, Freeswitch 에서 제공하는 Dialplan 기능뿐만 아니라, 다른 언어들까지 활용하여 Dialplan 을 작성한다면 보다 더 강력한 기능을 발휘할 수 있다.
당장 DB 연동만 생각해봐도 정말 강력하다는 것을 알 수 있을 것이다.

 

참조 : https://wiki.freeswitch.org/wiki/Modules

Could not get python modules list…

사용가능한 Python 모듈들을 알아보기 위해 python 인터프리터에서 전체 모듈보기 명령어를 입력했는데, 다음과 같은 오류 메시지를 확인했다.

pchero@MyDebian:/usr/lib/pymodules/python2.7$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help('modules')

Please wait a moment while I gather a list of all available modules...

/usr/lib/python2.7/dist-packages/gobject/constants.py:24: Warning: g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
  import gobject._gobject
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
/usr/lib/python2.7/dist-packages/gi/module.py:142: Warning: cannot register existing type `GtkWidget'
  g_type = info.get_g_type()
/usr/lib/python2.7/dist-packages/gi/module.py:142: Warning: cannot add class private field to invalid type '<invalid>'
  g_type = info.get_g_type()
/usr/lib/python2.7/dist-packages/gi/module.py:142: Warning: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
  g_type = info.get_g_type()
/usr/lib/python2.7/dist-packages/gi/module.py:142: Warning: cannot register existing type `GtkBuildable'
  g_type = info.get_g_type()
/usr/lib/python2.7/dist-packages/gi/module.py:142: Warning: g_type_interface_add_prerequisite: assertion `G_TYPE_IS_INTERFACE (interface_type)' failed
  g_type = info.get_g_type()
/usr/lib/python2.7/dist-packages/gi/module.py:142: Warning: g_once_init_leave: assertion `result != 0' failed
  g_type = info.get_g_type()
/usr/lib/python2.7/dist-packages/gi/module.py:146: Warning: g_type_get_qdata: assertion `node != NULL' failed
  type_ = g_type.pytype

그리고 Hang 이 걸린듯 더이상 진행되지 않았다.

해결법을 찾던 도중, http://blog.rabbitvcs.org/archives/312 에서 비슷한 현상에 대한 해결법을 찾았는데 뭔가 완벽하진 않았다.
http://stackoverflow.com/questions/13301100/python-fail-to-display-list-of-modules 여기도 역시…
내용인 즉, help(‘modules’) 를 입력하기 전에 gtk 모듈을 먼저 load 하라는 것인데.. 깔끔하지 않았다.

pchero@MyDebian:/etc$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtk
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
>>> 
>>> 
>>> help('modules')

Please wait a moment while I gather a list of all available modules...

/usr/lib/python2.7/dist-packages/keybinder/__init__.py:26: GtkWarning: IA__gdk_keymap_get_for_display: assertion `GDK_IS_DISPLAY (display)' failed
  from _keybinder import *
/usr/lib/python2.7/dist-packages/keybinder/__init__.py:26: GtkWarning: IA__gdk_screen_get_root_window: assertion `GDK_IS_SCREEN (screen)' failed
  from _keybinder import *

** (.:7702): WARNING **: keybinder_init: Unable to open display
ANSI                _codecs_iso2022     fdpexpect           pyatspi
ArgImagePlugin      _codecs_jp          feedparser          pyclbr
BaseHTTPServer      _codecs_kr          filecmp             pycurl
Bastion             _codecs_tw          fileinput           pydoc
BdfFontFile         _collections        fnmatch             pydoc_data
BeautifulSoup       _csv                formatter           pyexpat
BeautifulSoupTests  _ctypes             fpconst             pygtk
BmpImagePlugin      _ctypes_test        fpectl              pynotify
BufrStubImagePlugin _curses             fpformat            quopri
CDROM               _curses_panel       fractions           random
CGIHTTPServer       _dbus_bindings      freeswitch          re
Canvas              _dbus_glib_bindings ftplib              readline
ConfigParser        _elementtree        functools           reportbug
ContainerIO         _functools          future_builtins     reportlab
Cookie              _hashlib            gc                  repr
CurImagePlugin      _heapq              gconf               resource
DLFCN               _hotshot            genericpath         rexec
DcxImagePlugin      _imaging            getopt              rfc822
Dialog              _imagingcms         getpass             rlcompleter
DocXMLRPCServer     _imagingft          gettext             robotparser
EpsImagePlugin      _imagingmath        gi                  runpy
ExifTags            _io                 gio                 scanext
FSM                 _json               glib                sched
FileDialog          _locale             glob                screen
FitsStubImagePlugin _lsprof             gnome               select
FixTk               _multibytecodec     gnome_sudoku        serial
FliImagePlugin      _multiprocessing    gnomecanvas         sets
FontFile            _pyio               gnomevfs            setuptools
FpxImagePlugin      _random             gobject             sgmllib
GbrImagePlugin      _renderPM           grp                 sgmlop
GdImageFile         _rl_accel           gtk                 sha
GifImagePlugin      _socket             gtkunixprint        shelve
GimpGradientFile    _sqlite3            gtweak              shlex
GimpPaletteFile     _sre                gzip                shutil
GnuPGInterface      _ssl                hamster             signal
GribStubImagePlugin _strptime           hashlib             site
HTMLParser          _struct             heapq               sitecustomize
Hdf5StubImagePlugin _symtable           hmac                smtpd
HelloModule         _sysconfigdata      hotshot             smtplib
IN                  _sysconfigdata_nd   hpmudext            sndhdr
IcnsImagePlugin     _testcapi           htmlentitydefs      socket
IcoImagePlugin      _threading_local    htmllib             softwareproperties
ImImagePlugin       _warnings           httplib             speechd
Image               _weakref            httplib2            speechd_config
ImageChops          _weakrefset         ihooks              spwd
ImageCms            abc                 imaplib             sqlite3
ImageColor          aifc                imghdr              sre
ImageDraw           antigravity         imp                 sre_compile
ImageDraw2          anydbm              importlib           sre_constants
ImageEnhance        apt                 imputil             sre_parse
ImageFile           apt_inst            inspect             ssl
ImageFileIO         apt_pkg             invest              starpy
ImageFilter         aptdaemon           io                  stat
ImageFont           aptsources          itertools           statvfs
ImageGL             argparse            json                string
ImageGrab           array               keybinder           stringold
ImageMath           ast                 keyword             stringprep
ImageMode           asynchat            lib2to3             strop
ImageOps            asyncore            libxml2             struct
ImagePalette        atexit              libxml2mod          subprocess
ImagePath           atk                 linecache           sunau
ImageQt             audiodev            linuxaudiodev       sunaudio
ImageSequence       audioop             locale              symbol
ImageShow           axi                 logging             symtable
ImageStat           base64              louis               sys
ImageTransform      bdb                 lsb_release         sysconfig
ImageWin            binascii            macpath             syslog
ImtImagePlugin      binhex              macurl2path         tabnanny
IptcImagePlugin     bisect              mailbox             tarfile
JpegImagePlugin     bonobo              mailcap             telnetlib
McIdasImagePlugin   brlapi              mako                tempfile
MicImagePlugin      bsddb               markupbase          termios
MimeWriter          bz2                 markupsafe          test
MpegImagePlugin     cPickle             marshal             test1
MspImagePlugin      cProfile            math                textwrap
ORBit               cStringIO           md5                 this
OleFileIO           cairo               mhlib               thread
OpenSSL             calendar            mimetools           threading
PAM                 caribou             mimetypes           tidy
PIL                 cgi                 mimify              time
PSDraw              cgitb               mmap                timeit
PaletteFile         chardet             mod_fstest          tkColorChooser
PalmImagePlugin     chunk               mod_test            tkCommonDialog
PcdImagePlugin      cmath               modulefinder        tkFileDialog
PcfFontFile         cmd                 multifile           tkFont
PcxImagePlugin      code                multiprocessing     tkMessageBox
PdfImagePlugin      codecs              mutex               tkSimpleDialog
PixarImagePlugin    codeop              netrc               toaiff
PngImagePlugin      collections         new                 token
PpmImagePlugin      colorsys            nis                 tokenize
PsdImagePlugin      commands            nntplib             trace
Queue               compileall          ntpath              traceback
SOAPpy              compiler            nturl2path          ttk
ScrolledText        contextlib          numbers             tty
SgiImagePlugin      cookielib           numpy               turtle
SimpleDialog        copy                opcode              twisted
SimpleHTTPServer    copy_reg            operator            types
SimpleXMLRPCServer  crypt               optparse            unicodedata
SocketServer        csv                 orca                unittest
SpiderImagePlugin   ctypes              os                  uno
StringIO            cupsext             os2emxpath          unohelper
SunImagePlugin      curl                ossaudiodev         urllib
TYPES               curses              packagekit          urllib2
TarIO               datetime            pango               urlparse
TgaImagePlugin      dbhash              pangocairo          user
TiffImagePlugin     dbm                 parser              uu
TiffTags            dbus                pcardext            uuid
Tix                 deb822              pdb                 vte
Tkconstants         debconf             pexpect             warnings
Tkdnd               debian              pickle              wave
Tkinter             debian_bundle       pickletools         weakref
UserDict            debianbts           pip                 webbrowser
UserList            decimal             pipes               whichdb
UserString          defer               pkg_resources       wnck
WalImageFile        difflib             pkgutil             wsgiref
WmfImagePlugin      dircache            platform            xapian
XVThumbImagePlugin  dis                 plistlib            xdg
XbmImagePlugin      distutils           popen2              xdrlib
XpmImagePlugin      doctest             poplib              xml
_LWPCookieJar       drv_libxml2         posix               xmllib
_MozillaCookieJar   dsextras            posixfile           xmlrpclib
__builtin__         dumbdbm             posixpath           xxsubtype
__future__          dummy_thread        pprint              zeitgeist
_abcoll             dummy_threading     profile             zipfile
_ast                easy_install        pstats              zipimport
_bisect             email               pty                 zlib
_bsddb              encodings           pwd                 zope
_codecs             errno               pxssh               
_codecs_cn          exceptions          pyHnj               
_codecs_hk          fcntl               py_compile          

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".

[Freeswitch] Enable python script.

Freeswitch-python module install & configuration

Debian Linux/Freeswitch source 설치 기준으로 설명한다.

Freeswitch Python 모듈인 mod_pythom 을 설치해야 한다.
Source Directory 로 이동하자.

$ cd /usr/local/src/freeswitch.git

Freeswitch 는 설치시 모든 모듈을 컴파일하지 않는다. 아무런 추가 설정이 없다면 기본 모듈만을 설치한다.
따라서, 다른 추가 모듈들이 필요하다면 별도의 설정 후, 다시 컴파일을 진행해 주어야 한다.
정확히는 컴파일 시, Source 디렉토리 내의 modules.conf 파일을 참조하여 컴파일을 해야하는 모듈들을 확인한 다음에 컴파일을 진행한다.
따라서, modules.conf 파일을 수정하면 추가적인 모듈 설치가 가능하다.
python module compile 을 활성화 시키기 위해서 modules.conf 파일을 수정한다.

$ vi modules.conf

mod_python 부분을 찾아서 주석 해제한다.

#languages/mod_python
languages/mod_python

make & make install.

$ make && make install

python-freeswitch 모듈이 제대로 설치되었는지 확인해야 한다.
아래의 예제처럼 python 시작후, 전체 모듈 검색에서 freeswitch 모듈이 확인되어야 한다.
만약 확인되지 않으면 수동으로 freeswitch 모듈을 옮겨 주어야 한다.

pchero@MyDebian:/etc$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> help('modules')

ANSI                _codecs_iso2022     fdpexpect           pyatspi
ArgImagePlugin      _codecs_jp          feedparser          pyclbr
BaseHTTPServer      _codecs_kr          filecmp             pycurl
Bastion             _codecs_tw          fileinput           pydoc
BdfFontFile         _collections        fnmatch             pydoc_data
BeautifulSoup       _csv                formatter           pyexpat
BeautifulSoupTests  _ctypes             fpconst             pygtk
BmpImagePlugin      _ctypes_test        fpectl              pynotify
BufrStubImagePlugin _curses             fpformat            quopri
CDROM               _curses_panel       fractions           random
CGIHTTPServer       _dbus_bindings      freeswitch          re
Canvas              _dbus_glib_bindings ftplib              readline
ConfigParser        _elementtree        functools           reportbug
ContainerIO         _functools          future_builtins     reportlab
...

만약 확인되지 않는다면 수동으로 freeswitch 모듈을 설치해 주어야 한다.
아래의 예제는 Debian Linux/Python2.7 설치 기준이다.
리눅스 배포판/Python 버전에 따라 모듈 설치 디렉토리가 달라지므로 주의하자.

pchero@MyDebian:/usr/local/src/freeswitch.git/src/mod/languages/mod_python$ pwd
/usr/local/src/freeswitch.git/src/mod/languages/mod_python

pchero@MyDebian:/usr/local/src/freeswitch.git/src/mod/languages/mod_python$ sudo cp ./freeswitch.py /usr/lib/python2.7/dist-packages/

 

Python 에서 freeswitch 모듈을 확인했다면, 이제는 Freeswitch 에서 Python 모듈이 사용가능한지 확인해야 한다.

modules.conf.xml 파일에서 매번 자동으로 mod_python module 을 load 하도록 설정해주자.
<load_module=”mod_python”> 부분을 주석 해제하거나 추가해주자.

    <!-- Languages -->
    <!-- <load module="mod_spidermonkey"/> -->
    <load module="mod_v8"/>
    <!-- <load module="mod_perl"/> -->
    <load module="mod_python"/>
    <!-- <load module="mod_java"/> -->
    <load module="mod_lua"/>

freeswitch cli(fs_cli) 에서 mod_python 모듈을 load 하고, 정상적으로 load 되었는지 확인하자.

freeswitch@192.168.200.10@internal> load mod_python
+OK Reloading XML

freeswitch@192.168.200.10@internal> module_exists mod_python
true

Using python script on freeswitch.

이제 실제로 sample python script 를 작성 및 사용해 보자. mod_python 소스 디렉토리에는 훌륭한 예제 스크립트가 있다. 사용하도록 하자.

cp /usr/local/src/freeswitch.git/src/mod/languages/mod_python/python_example.py /usr/lib/pymodules/python2.7

마지막으로 실제 Dialplan 내에서 python 모듈을 호출하도록 설정해야 한다.

<include>
  <extension name="python_test">
    <condition field="destination_number" expression="^(5555555)$">
      <!--
      If you're hosting multiple domains you will want to set the
      target_domain on these calls so they hit the proper domain after you
      transfer the caller into the default context. 
      
      $${domain} is the default domain set from vars.xml but you can set it
      to any domain you have setup in your user directory.

      -->
      <action application="info"/>
      <action application="python" data="python_example"/>
      <!--<action application="set" data="domain_name=$${domain}"/>-->
      <!-- This example maps the DID 5551212 to ring 1000 in the default context -->
      <!--<action application="transfer" data="1000 XML default"/>-->
    </condition>
  </extension>
</include>

 

참조 : https://wiki.freeswitch.org/wiki/Mod_python#Sample_Python_Scripts