Talk:Mod lua

From FreeSWITCH Wiki
Jump to: navigation, search


I want to provide some code examples, maybe someone will incorporate them into main article (there's no "Examples" section at the moment).

LDAP lookup

Microsoft Office Communications Server does not send "DisplayName" SIP header, so other systems wouldn't show caller name. One of simple solutions - install FS on mediation server, reconfigure it as simple pass-trough gateway on non-standart ports and add this lua script for LDAP lookups:

require "lualdap"
local caller_num
if (session and session:getVariable("caller_id_number")) then
    caller_num = session:getVariable("caller_id_number")
    caller_num = "0000"
    -- would be much better fallback to session:getVariable("ani")
    -- but code above is ok for me. Others may remove entire 'if' section

ld = assert (lualdap.open_simple ("",
                "CN=AD User,OU=xxx,OU=yyy,OU=zzz,OU=AD User",

-- 'sizelimit', 'attrsonly' are optional, probably won't be needed at all in real-world usage
for dn, attribs in ld:search { attrs = { "cn" }, attrsonly = false, base = "ou=AD Users,dc=xxx,dc=yyy,dc=zzz", sizelimit = "15", filter = "telephoneNumber="..caller_num } do
     for name, values in pairs (attribs) do
            freeswitch.consoleLog("warning","Rewrite from "..caller_num.." to "..values.."\n");
            session:setVariable("effective_caller_id_name", values)

Works on Windows, requires lualdap.dll. After adding lualdap.dll - add this to lua.conf.xml:

<param name="module-directory" value="c:\FreeSWITCH\addons\?.dll "/>

(path may be different, depends from install)

Script is very simple, it looks for DisplayName in AD attribute "cn", searching by attribute "telephoneNumber". At least, some tested softphones, Cisco 7912, Cisco 7910 shows name correctly.

Destination number rewriting

The same Microsoft Office Communications Server can't do any manipulations with numbers (outgoing/incoming), so another solution was to write "lua-rewriter" with the same FS. final sample to be written soon, because i'm rewriting this from perl to lua

ABL 06:43, 8 September 2009 (UTC)