[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

[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

[Freeswitch] modules.conf.xml

Freeswitch 에서 사용하는 Module On/Off 를 설정하는 파일.

fs_cli 로 접속하여 load 명령어로도 On/Off 가 가능하지만, Freeswitch 재 시작 후, 매번 load 명령어를 날려줘야만 하는 불편함이 있다.

이럴 경우, modules.conf.xml 파일에 Freeswitch 시작시 자동 load module을 설정해 놓으면 편리하다.

pchero@MyDebian:/usr/local/freeswitch/conf/autoload_configs$ cat modules.conf.xml 
<configuration name="modules.conf" description="Modules">
  <modules>
    
    <!-- Loggers (I'd load these first) -->
    <load module="mod_console"/>
    <load module="mod_logfile"/>
    <!-- <load module="mod_syslog"/> -->

    <!--<load module="mod_yaml"/>-->

    <!-- Multi-Faceted -->
    <!-- mod_enum is a dialplan interface, an application interface and an api command interface -->
    <load module="mod_enum"/>

    <!-- XML Interfaces -->
    <!-- <load module="mod_xml_rpc"/> -->
    <!-- <load module="mod_xml_curl"/> -->
    <!-- <load module="mod_xml_cdr"/> -->
    <!-- <load module="mod_xml_scgi"/> -->

    <!-- Event Handlers -->
    <load module="mod_cdr_csv"/>
    <!-- <load module="mod_cdr_sqlite"/> -->
    <!-- <load module="mod_event_multicast"/> -->
    <load module="mod_event_socket"/>
    <!-- <load module="mod_event_zmq"/> -->
    <!-- <load module="mod_zeroconf"/> -->
    <!-- <load module="mod_erlang_event"/> -->
    <!-- <load module="mod_snmp"/> -->

    <!-- Directory Interfaces -->
    <!-- <load module="mod_ldap"/> -->

    <!-- Endpoints -->
    <!-- <load module="mod_dingaling"/> -->
    <!-- <load module="mod_portaudio"/> -->
    <!-- <load module="mod_alsa"/> -->
    <load module="mod_sofia"/>
    <load module="mod_loopback"/>
    <!-- <load module="mod_woomera"/> -->
    <!-- <load module="mod_freetdm"/> -->
    <!-- <load module="mod_openzap"/> -->
    <!-- <load module="mod_unicall"/> -->
    <!-- <load module="mod_skinny"/> -->
    <!-- <load module="mod_khomp"/>   -->
    <!-- <load module="mod_rtmp"/>   -->

    <!-- Applications -->
    <load module="mod_commands"/>
    <load module="mod_conference"/>
    <!-- <load module="mod_curl"/> -->
    <load module="mod_db"/>
    <load module="mod_dptools"/>
    <load module="mod_expr"/>
    <load module="mod_fifo"/>
    <load module="mod_hash"/>
    <load module="mod_voicemail"/>
    <!--<load module="mod_directory"/>-->
    <!--<load module="mod_distributor"/>-->
    <!--<load module="mod_lcr"/>-->
    <load module="mod_esf"/>
    <load module="mod_fsv"/>
    <load module="mod_cluechoo"/>
    <load module="mod_valet_parking"/>
    <!--<load module="mod_fsk"/>-->
    <!--<load module="mod_spy"/>-->
    <!--<load module="mod_random"/>-->
    <load module="mod_httapi"/>
    <!--<load module="mod_translate"/>-->

    <!-- SNOM Module -->
    <!--<load module="mod_snom"/>-->

    <!-- This one only works on Linux for now -->
    <!--<load module="mod_ladspa"/>-->

    <!-- Dialplan Interfaces -->
    <!-- <load module="mod_dialplan_directory"/> -->
    <load module="mod_dialplan_xml"/>
    <load module="mod_dialplan_asterisk"/>

    <!-- Codec Interfaces -->
    <load module="mod_spandsp"/>
    <load module="mod_g723_1"/>
    <load module="mod_g729"/>
    <load module="mod_amr"/>
    <!--<load module="mod_ilbc"/>-->
    <load module="mod_h26x"/>
    <load module="mod_vp8"/>
    <load module="mod_b64"/>
    <!--<load module="mod_siren"/>-->
    <!--<load module="mod_isac"/>-->
    <!--<load module="mod_celt"/>-->
    <!--<load module="mod_opus"/>-->

    <!-- File Format Interfaces -->
    <load module="mod_sndfile"/>
    <load module="mod_native_file"/>
    <!-- <load module="mod_shell_stream"/> -->
    <!--For icecast/mp3 streams/files-->
    <!--<load module="mod_shout"/>-->
    <!--For local streams (play all the files in a directory)-->
    <load module="mod_local_stream"/>
    <load module="mod_tone_stream"/>

    <!-- Timers -->
    <!-- <load module="mod_timerfd"/> -->
    <!-- <load module="mod_posix_timer"/> -->

    <!-- 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"/>

    <!-- ASR /TTS -->
    <!-- <load module="mod_flite"/> -->
    <!-- <load module="mod_pocketsphinx"/> -->
    <!-- <load module="mod_cepstral"/> -->
    <!-- <load module="mod_tts_commandline"/> -->
    <!-- <load module="mod_rss"/> -->
    
    <!-- Say -->
    <load module="mod_say_en"/>
    <!-- <load module="mod_say_ru"/> -->
    <!-- <load module="mod_say_zh"/> -->
    <!-- <load module="mod_say_sv"/> -->

    <!-- Third party modules -->
    <!--<load module="mod_nibblebill"/>-->
    <!--<load module="mod_callcenter"/>-->

  </modules>
</configuration>

 

[Freeswitch] fs_cli/event_socket.conf.xml

Freeswitch에서 asterisk -r 과 같은 Command line interpreter 역할을 하는 것이 fs_cli  이다.

기본적으로 Freeswitch 를 설치하게 되면 fs_cli 도 같이 사용할 수 있도록 설정되어 있다. 그러나, 보안상의 이유로 이 기능을 On/Off 해야 하는 경우가 생긴다.

이 경우, Freeswitch Server 에서 fs_cli 지원 모듈을 On/Off 해주면 된다.

modules.conf.xml 파일에서 mod_event_socket 모듈을 load/unload 하게 되면 fs_cli 기능을 On/Off 할 수 있다.

<configuration name="modules.conf" description="Modules">
  <modules>

    <!-- Loggers (I'd load these first) -->
    <load module="mod_console"/>
    <load module="mod_logfile"/>
    <!-- <load module="mod_syslog"/> -->

    <!--<load module="mod_yaml"/>-->

    <!-- Multi-Faceted -->
    <!-- mod_enum is a dialplan interface, an application interface and an api command interface -->
    <load module="mod_enum"/>

    <!-- XML Interfaces -->
    <!-- <load module="mod_xml_rpc"/> -->
    <!-- <load module="mod_xml_curl"/> -->
    <!-- <load module="mod_xml_cdr"/> -->
    <!-- <load module="mod_xml_scgi"/> -->

    <!-- Event Handlers -->
    <load module="mod_cdr_csv"/>
    <!-- <load module="mod_cdr_sqlite"/> -->
    <!-- <load module="mod_event_multicast"/> -->
    <load module="mod_event_socket"/>
    <!-- <load module="mod_event_zmq"/> -->

기본적으로 Freeswitch 를 설치하게 되면 fs_cli 도 같이 사용할 수 있도록 설정되어 있다. 그러나, 보안상의 이유로 이 기능을 On/Off 해야 하는 경우가 생긴다.
이 경우, Freeswitch Server 에서 fs_cli 지원 모듈을 On/Off 해주면 된다.

그리고, fs_cli 의 접속 권한과 같은 부분들을 관리 하고자 한다면 event_socket.conf.xml 파일을 수정하면 된다.

pchero@MyDebian:/usr/local/freeswitch/conf/autoload_configs$ cat event_socket.conf.xml

<configuration name="event_socket.conf" description="Socket Client">
  <settings>
    <param name="nat-map" value="false"/>
    <!--<param name="listen-ip" value="127.0.0.1"/>-->
    <param name="listen-ip" value="0.0.0.0"/>
    <param name="listen-port" value="8021"/>
    <param name="password" value="ClueCon"/>
    <param name="apply-inbound-acl" value="local_net"/>
    <!--<param name="apply-inbound-acl" value="lan"/>-->
    <!--<param name="stop-on-bind-error" value="true"/>-->
  </settings>
</configuration>

[Freeswitch] How to change Freeswitch ip address

Freeswtich 설치 이후, 테스트를 진행하는데 SIP 클라이언트 접속이 안되는 문제가 발생했다.

telnet/netstat 으로 확인해보니 포트가 안뚫려있었다. Freeswitch listen IP가 localhost 로만 설정되어 있는 상황.

따라서, Freeswitch Server Ip 설정을 변경해주니 잘 작동하였다.

/usr/local/freeswitch/conf/vars.xml 파일 내용에서 다음 부분을 수정해주었다.(local_ip_v4 항목을 추가)

  <X-PRE-PROCESS cmd="set" data="sound_prefix=$${sounds_dir}/en/us/callie"/>

  <!--
      This setting is what sets the default domain FreeSWITCH will use if all else fails.

      FreeSWICH will default to $${local_ip_v4} unless changed.  Changing this setting does
      affect the sip authentication.  Please review conf/directory/default.xml for more
      information on this topic.
  -->
  <X-PRE-PROCESS cmd="set" data="local_ip_v4=192.168.200.10"/>
  <X-PRE-PROCESS cmd="set" data="domain=$${local_ip_v4}"/>
  <X-PRE-PROCESS cmd="set" data="domain_name=$${domain}"/>
  <X-PRE-PROCESS cmd="set" data="hold_music=local_stream://moh"/>
  <X-PRE-PROCESS cmd="set" data="use_profile=internal"/>

보통은 위의 설정이 없이도, 자동으로 local_ip_v4 에 IP 가 설정이 된다. 그러나, 만약 두개 이상의 NIC 가 달려 있는 서버라면.. 문제가 발생한다. 이 경우 위의 설정이 필요하다.

참조: http://wiki.freeswitch.org/wiki/Getting_Started_Guide#Some_stuff_to_try_out.21