summaryrefslogtreecommitdiff
path: root/misc/freeswitch
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-22 15:33:06 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-22 15:33:06 +0100
commit39aa7132ceed3d4beab3a9b828e571bbfc67c07e (patch)
tree6c88289c9f99be0af8635636fcdf64102090e5ec /misc/freeswitch
parent5ad8203ce4f1bfea997960d0b52c626dea24b944 (diff)
parent6f69c1a85055ec7c2515719d79d2a7a4e60cec50 (diff)
Merge branch 'develop'5.1-beta1
Diffstat (limited to 'misc/freeswitch')
-rw-r--r--misc/freeswitch/conf/freeswitch.xml106
-rw-r--r--misc/freeswitch/scripts/acd_wait.lua2
-rw-r--r--misc/freeswitch/scripts/common/call_forwarding.lua2
-rw-r--r--misc/freeswitch/scripts/common/call_history.lua2
-rw-r--r--misc/freeswitch/scripts/common/conference.lua6
-rw-r--r--misc/freeswitch/scripts/common/configuration_file.lua2
-rw-r--r--misc/freeswitch/scripts/common/configuration_table.lua46
-rw-r--r--misc/freeswitch/scripts/common/database.lua123
-rw-r--r--misc/freeswitch/scripts/common/fapi.lua2
-rw-r--r--misc/freeswitch/scripts/common/gateway.lua168
-rw-r--r--misc/freeswitch/scripts/common/ipcalc.lua2
-rw-r--r--misc/freeswitch/scripts/common/log.lua2
-rw-r--r--misc/freeswitch/scripts/common/phone_number.lua2
-rw-r--r--misc/freeswitch/scripts/common/routing_tables.lua66
-rw-r--r--misc/freeswitch/scripts/common/sip_account.lua2
-rw-r--r--misc/freeswitch/scripts/common/str.lua24
-rw-r--r--misc/freeswitch/scripts/common/sync_log.lua2
-rw-r--r--misc/freeswitch/scripts/configuration.lua399
-rw-r--r--misc/freeswitch/scripts/configuration/freeswitch_xml.lua307
-rw-r--r--misc/freeswitch/scripts/configuration/simple_xml.lua50
-rw-r--r--misc/freeswitch/scripts/configuration/sip.lua8
-rw-r--r--misc/freeswitch/scripts/dialplan/acd.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/cdr.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/dialplan.lua228
-rw-r--r--misc/freeswitch/scripts/dialplan/fax.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/functions.lua74
-rw-r--r--misc/freeswitch/scripts/dialplan/geo_number.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/hunt_group.lua39
-rw-r--r--misc/freeswitch/scripts/dialplan/phone_book.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/presence.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/route.lua265
-rw-r--r--misc/freeswitch/scripts/dialplan/router.lua187
-rw-r--r--misc/freeswitch/scripts/dialplan/session.lua6
-rw-r--r--misc/freeswitch/scripts/dialplan/sip_call.lua18
-rw-r--r--misc/freeswitch/scripts/dialplan/tenant.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/user.lua4
-rw-r--r--misc/freeswitch/scripts/dialplan/voicemail.lua4
-rw-r--r--misc/freeswitch/scripts/dialplan_default.lua51
-rw-r--r--misc/freeswitch/scripts/event/call_history_save.lua2
-rw-r--r--misc/freeswitch/scripts/event/cdr_save.lua2
-rw-r--r--misc/freeswitch/scripts/event/event.lua10
-rw-r--r--misc/freeswitch/scripts/event/perimeter.lua5
-rw-r--r--misc/freeswitch/scripts/event_manager.lua5
-rw-r--r--misc/freeswitch/scripts/fax_daemon.lua2
-rw-r--r--misc/freeswitch/scripts/ini/conferences.ini27
-rw-r--r--misc/freeswitch/scripts/ini/database.ini11
-rw-r--r--misc/freeswitch/scripts/ini/dialplan.ini14
-rw-r--r--misc/freeswitch/scripts/ini/events.ini8
-rw-r--r--misc/freeswitch/scripts/ini/gateways.ini.example23
-rw-r--r--misc/freeswitch/scripts/ini/perimeter.ini9
-rw-r--r--misc/freeswitch/scripts/ini/routes.ini77
-rw-r--r--misc/freeswitch/scripts/ini/sip_accounts.ini10
-rw-r--r--misc/freeswitch/scripts/ini/sofia.ini55
-rw-r--r--misc/freeswitch/scripts/phones/phone.lua2
-rw-r--r--misc/freeswitch/scripts/phones/siemens.lua2
-rw-r--r--misc/freeswitch/scripts/phones/snom.lua2
-rw-r--r--misc/freeswitch/scripts/send_fax.lua50
57 files changed, 1177 insertions, 1352 deletions
diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml
index 04369a7..3c098fc 100644
--- a/misc/freeswitch/conf/freeswitch.xml
+++ b/misc/freeswitch/conf/freeswitch.xml
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="freeswitch/xml">
<X-PRE-PROCESS cmd="set" data="sound_prefix=/opt/freeswitch/sounds/en/us/callie"/>
- <X-PRE-PROCESS cmd="set" data="hold_music=local_stream://moh"/>
- <X-PRE-PROCESS cmd="set" data="use_profile=internal"/>
- <X-PRE-PROCESS cmd="set" data="send_silence_when_idle=400"/>
- <X-PRE-PROCESS cmd="set" data="de-ring=%(1000,4000,425.0)"/>
<section name="languages" description="Language Management">
<language name="en" say-module="en" sound-prefix="/opt/freeswitch/sounds/en/us/callie">
<phrases>
@@ -495,29 +491,22 @@
<param name="listen-port" value="8021"/>
</settings>
</configuration>
- <configuration name="fifo.conf" description="FIFO Configuration">
- <settings>
- <param name="delete-all-outbound-member-on-startup" value="false"/>
- </settings>
- <fifos>
- </fifos>
- </configuration>
<configuration name="local_stream.conf" description="stream files from local dir">
- <directory name="default" path="/opt/freeswitch/sounds/music/16000">
- <param name="rate" value="16000"/>
+ <directory name="default" path="/opt/freeswitch/sounds/music/8000">
+ <param name="rate" value="8000"/>
<param name="shuffle" value="true"/>
<param name="channels" value="1"/>
<param name="interval" value="20"/>
<param name="timer-name" value="soft"/>
</directory>
- <directory name="moh" path="/opt/freeswitch/sounds/music/16000">
+ <directory name="mohh" path="/opt/freeswitch/sounds/music/16000">
<param name="rate" value="16000"/>
<param name="shuffle" value="true"/>
<param name="channels" value="1"/>
<param name="interval" value="20"/>
<param name="timer-name" value="soft"/>
</directory>
- <directory name="mohl" path="/opt/freeswitch/sounds/music/8000">
+ <directory name="moh" path="/opt/freeswitch/sounds/music/8000">
<param name="rate" value="8000"/>
<param name="shuffle" value="true"/>
<param name="channels" value="1"/>
@@ -541,30 +530,13 @@
</profile>
</profiles>
</configuration>
- <configuration name="xml_rpc.conf" description="XML RPC">
- <settings>
- <param name="http-port" value="228080"/>
- <param name="auth-realm" value="gemeinschaft"/>
- <param name="auth-user" value="7ff020f74d99a1b88bd2"/>
- <param name="auth-pass" value="85d13b5a56c55f7261cc"/>
- </settings>
- </configuration>
<configuration name="switch.conf" description="Core Configuration">
<cli-keybindings>
</cli-keybindings>
<settings>
- <param name="colorize-console" value="true"/>
- <param name="max-sessions" value="1000"/>
- <param name="sessions-per-second" value="30"/>
- <param name="loglevel" value="debug"/>
- <param name="mailer-app" value="sendmail"/>
- <param name="mailer-app-args" value="-t"/>
<param name="dump-cores" value="yes"/>
<param name="auto-create-schemas" value="true"/>
- <param name="rtp-enable-zrtp" value="false"/>
- <param name="rtp-start-port" value="16384" />
- <param name="rtp-end-port" value="32768" />
- <param name="core-db-dsn" value="gemeinschaft:gemeinschaft:gemeinschaft"/>
+ <param name="core-db-dsn" value="gemeinschaft:gemeinschaft:gemeinschaft"/>
</settings>
</configuration>
<configuration name="spandsp.conf" description="Tone detector descriptors">
@@ -635,8 +607,8 @@
<param name="verbose" value="true"/>
<param name="disable-v17" value="false"/>
<param name="ident" value=""/>
- <param name="header" value="GS4"/>
- <param name="spool-dir" value="/opt/GS5/misc/fax"/>
+ <param name="header" value="Gemeinschaft"/>
+ <param name="spool-dir" value="/var/spool/freeswitch"/>
<param name="file-prefix" value="fax_in_"/>
</settings>
</configuration>
@@ -645,8 +617,6 @@
<load module="mod_console"/>
<load module="mod_logfile"/>
<load module="mod_lua"/>
- <!-- <load module="mod_xml_rpc"/> -->
- <!-- <load module="mod_cdr_csv"/> -->
<load module="mod_event_socket"/>
<load module="mod_sofia"/>
<load module="mod_loopback"/>
@@ -654,12 +624,8 @@
<load module="mod_conference"/>
<load module="mod_dptools"/>
<load module="mod_expr"/>
- <!-- <load module="mod_fifo"/> -->
<load module="mod_voicemail"/>
- <!-- <load module="mod_esf"/> -->
- <!-- <load module="mod_fsv"/> -->
<load module="mod_valet_parking"/>
- <!-- <load module="mod_curl"/> -->
<load module="mod_dialplan_xml"/>
<load module="mod_sndfile"/>
<load module="mod_native_file"/>
@@ -668,63 +634,7 @@
<load module="mod_say_en"/>
<load module="mod_spandsp"/>
</modules>
- </configuration>
- <configuration name="post_load_modules.conf" description="Modules">
- <modules>
- </modules>
- </configuration>
- <configuration name="voicemail.conf" description="Voicemail">
- <settings>
- </settings>
- <profiles>
- <profile name="default">
- <param name="file-extension" value="wav"/>
- <param name="terminator-key" value="#"/>
- <param name="max-login-attempts" value="3"/>
- <param name="digit-timeout" value="10000"/>
- <param name="min-record-len" value="3"/>
- <param name="max-record-len" value="300"/>
- <param name="max-retries" value="3"/>
- <param name="tone-spec" value="%(1000, 0, 640)"/>
- <param name="callback-dialplan" value="XML"/>
- <param name="callback-context" value="default"/>
- <param name="play-new-messages-key" value="1"/>
- <param name="play-saved-messages-key" value="2"/>
- <param name="login-keys" value="0"/>
- <param name="main-menu-key" value="0"/>
- <param name="config-menu-key" value="5"/>
- <param name="record-greeting-key" value="1"/>
- <param name="choose-greeting-key" value="2"/>
- <param name="change-pass-key" value="6"/>
- <param name="record-name-key" value="3"/>
- <param name="record-file-key" value="3"/>
- <param name="listen-file-key" value="1"/>
- <param name="save-file-key" value="2"/>
- <param name="delete-file-key" value="7"/>
- <param name="undelete-file-key" value="8"/>
- <param name="email-key" value="4"/>
- <param name="pause-key" value="0"/>
- <param name="restart-key" value="1"/>
- <param name="ff-key" value="6"/>
- <param name="rew-key" value="4"/>
- <param name="skip-greet-key" value="#"/>
- <param name="record-silence-threshold" value="200"/>
- <param name="record-silence-hits" value="2"/>
- <param name="web-template-file" value="web-vm.tpl"/>
- <param name="operator-extension" value="operator XML default"/>
- <param name="operator-key" value="9"/>
- <param name="vmain-extension" value="vmain XML default"/>
- <param name="vmain-key" value="*"/>
- <param name="odbc-dsn" value="gemeinschaft:gemeinschaft:gemeinschaft"/>
- <email>
- <param name="notify-template-file" value="notify-voicemail.tpl"/>
- <param name="template-file" value="voicemail.tpl"/>
- <param name="date-fmt" value="%A, %B %d %Y, %I %M %p"/>
- <param name="email-from" value="${voicemail_account}@${voicemail_domain}"/>
- </email>
- </profile>
- </profiles>
- </configuration>
+ </configuration>
<configuration name="lua.conf" description="LUA Configuration">
<settings>
<param name="script-directory" value="$${base_dir}/scripts/?.lua"/>
diff --git a/misc/freeswitch/scripts/acd_wait.lua b/misc/freeswitch/scripts/acd_wait.lua
index fd16bea..c05cc24 100644
--- a/misc/freeswitch/scripts/acd_wait.lua
+++ b/misc/freeswitch/scripts/acd_wait.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5: acd call handler
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
local caller_uuid = argv[1];
diff --git a/misc/freeswitch/scripts/common/call_forwarding.lua b/misc/freeswitch/scripts/common/call_forwarding.lua
index 3942d05..400fcde 100644
--- a/misc/freeswitch/scripts/common/call_forwarding.lua
+++ b/misc/freeswitch/scripts/common/call_forwarding.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: call forwarding class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/call_history.lua b/misc/freeswitch/scripts/common/call_history.lua
index 7a9ac07..7e1e22b 100644
--- a/misc/freeswitch/scripts/common/call_history.lua
+++ b/misc/freeswitch/scripts/common/call_history.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: call_history class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/conference.lua b/misc/freeswitch/scripts/common/conference.lua
index d2bf829..ca5fa62 100644
--- a/misc/freeswitch/scripts/common/conference.lua
+++ b/misc/freeswitch/scripts/common/conference.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: conference class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -103,8 +103,9 @@ function Conference.enter(self, caller, domain)
end;
end
+ require 'common.str'
-- Check if conference is within time frame
- if self.record.start and self.record['end'] then
+ if not common.str.blank(self.record.start) and not common.str.blank(self.record['end']) then
local d = {}
_,_,d.year,d.month,d.day,d.hour,d.min,d.sec=string.find(self.record.start, "(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)");
@@ -122,7 +123,6 @@ function Conference.enter(self, caller, domain)
end
end
- require 'common.str'
-- Owner ist always moderator
if (tonumber(self.record.conferenceable_id) == caller.account_owner_id) and (self.record.conferenceable_type == caller.account_owner_type) then
table.insert(flags, 'moderator');
diff --git a/misc/freeswitch/scripts/common/configuration_file.lua b/misc/freeswitch/scripts/common/configuration_file.lua
index 67e1f3b..3b3efbc 100644
--- a/misc/freeswitch/scripts/common/configuration_file.lua
+++ b/misc/freeswitch/scripts/common/configuration_file.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: configuration file
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua
new file mode 100644
index 0000000..85bc014
--- /dev/null
+++ b/misc/freeswitch/scripts/common/configuration_table.lua
@@ -0,0 +1,46 @@
+-- Gemeinschaft 5 module: configuration table
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+-- retrieve configuration from database
+function get(database, entity, section)
+ if not database or not entity then
+ return {};
+ end
+
+ require 'common.str'
+
+ local sql_query = 'SELECT * FROM `gs_parameters` WHERE `entity` = "' .. entity .. '"';
+ if section then
+ sql_query = sql_query .. ' AND `section` = "' .. section .. '"';
+ end
+
+ local root = {}
+ local parameter_class = '';
+
+ database:query(sql_query, function(parameters)
+ local p_section = common.str.strip(parameters.section):lower();
+ local p_class_type = common.str.strip(parameters.class_type):lower();
+ local p_name = common.str.strip(parameters.name);
+
+ if not root[p_section] then
+ root[p_section] = {};
+ end
+
+ if p_class_type == 'boolean' then
+ root[p_section][p_name] = common.str.to_b(parameters.value);
+ elseif p_class_type == 'integer' then
+ root[p_section][p_name] = common.str.to_i(parameters.value);
+ else
+ root[p_section][p_name] = tostring(parameters.value);
+ end
+ end)
+
+ if section then
+ return root[section];
+ end
+
+ return root;
+end
diff --git a/misc/freeswitch/scripts/common/database.lua b/misc/freeswitch/scripts/common/database.lua
index 3692f84..1f39135 100644
--- a/misc/freeswitch/scripts/common/database.lua
+++ b/misc/freeswitch/scripts/common/database.lua
@@ -1,12 +1,12 @@
-- Gemeinschaft 5 module: database class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2013
--
module(...,package.seeall)
Database = {}
-DATABASE_DRIVER = 'mysql'
+DATABASE_DSN = 'gemeinschaft';
function Database.new(self, arg)
arg = arg or {}
@@ -20,117 +20,49 @@ function Database.new(self, arg)
end
-function Database.connect(self, database_name, user_name, password, host_name)
- local database_driver = nil;
- if not (database_name and user_name and password) then
- require 'common.configuration_file'
- local config = common.configuration_file.get('/opt/freeswitch/scripts/ini/database.ini');
- if config then
- database_driver = config[true].driver
- database_name = config[database_driver].database
- user_name = config[database_driver].user
- password = config[database_driver].password
- host_name = config[database_driver].host
- end
- end
+function Database.connect(self)
+ self.dsn = DATABASE_DSN;
- host_name = host_name or 'localhost';
- database_driver = database_driver or DATABASE_DRIVER;
+ require 'common.configuration_file'
+ local dsn = common.configuration_file.get('/var/lib/freeswitch/.odbc.ini', self.dsn);
- if database_driver == 'mysql' then
- require "luasql.mysql"
- self.env = luasql.mysql();
- elseif database_driver == 'odbc' then
- require "luasql.odbc"
- self.env = luasql.odbc();
- end
+ self.database_name = dsn.DATABASE;
+ self.user_name = dsn.USER;
+ self.password = dsn.PASSWORD;
+ self.host_name = dsn.HOST;
- self.conn = self.env:connect(database_name, user_name, password, host_name);
+ self.conn = freeswitch.Dbh(self.dsn, self.user_name, self.password);
self.conn_id = tostring(self.conn);
- self.database_name = database_name;
- self.user_name = user_name;
- self.password = password;
- self.host_name = host_name;
-
- -- self.log:debug('DATABASE_CONNECT - connection: ', self.conn_id, ', environment: ', self.env);
-
- return self;
-end
-
-
-function Database.reconnect(self)
- self.conn = self.env:connect(self.database_name, self.user_name, self.password, self.host_name);
- self.conn_id = tostring(self.conn);
-
- if self.log then
- self.log:info('DATABASE_RECONNECT - connection: ', self.conn_id, ', environment: ', self.env);
- end
return self;
end
function Database.connected(self)
- return self.conn;
+ return self.conn:connected();
end
function Database.query(self, sql_query, call_function)
- local cursor = self.conn:execute(sql_query);
-
- if cursor == nil and not self.conn:execute('SELECT @@VERSION') then
- if self.log then
- self.log:error('DATABASE_QUERY - lost connection: ', self.conn_id, ', environment: ', self.env, ', query: ', sql_query);
- end
- self:reconnect();
-
- if call_function then
- cursor = self.conn:execute(sql_query);
- self.log:notice('DATABASE_QUERY - retry: ', sql_query);
- end
- end
-
- if cursor and call_function then
- repeat
- row = cursor:fetch({}, 'a');
- if row then
- call_function(row);
- end
- until not row;
+ if call_function then
+ return self.conn:query(sql_query, call_function);
+ else
+ return self.conn:query(sql_query);
end
-
- if type(cursor) == 'userdata' then
- cursor:close();
- end
-
- return cursor;
end
function Database.query_return_value(self, sql_query)
- local cursor = self.conn:execute(sql_query);
+ local result = nil;
- if cursor == nil and not self.conn:execute('SELECT @@VERSION') then
- if self.log then
- self.log:error('DATABASE_QUERY - lost connection: ', self.conn_id, ', environment: ', self.env, ', query: ', sql_query);
+ self.conn:query(sql_query, function(row)
+ for key, value in pairs(row) do
+ result = value;
+ return result;
end
- self:reconnect();
- cursor = self.conn:execute(sql_query);
- self.log:notice('DATABASE_QUERY - retry: ', sql_query);
- end
-
- if type(cursor) == 'userdata' then
- local row = cursor:fetch({}, 'n');
- cursor:close();
-
- if not row then
- return row;
- else
- return row[1];
- end
- end
+ end)
- return cursor;
+ return result;
end
@@ -139,13 +71,8 @@ function Database.last_insert_id(self)
end
-function Database.release(self, sql_query, call_function)
+function Database.release(self)
if self.conn then
- self.conn:close();
- end
- if self.env then
- self.env:close();
+ self.conn:release();
end
-
- -- self.log:debug('DATABASE_RELEASE - connection: ', self.conn_id, ', status: ', self.env, ', ', self.conn);
end
diff --git a/misc/freeswitch/scripts/common/fapi.lua b/misc/freeswitch/scripts/common/fapi.lua
index 0a05155..5b96633 100644
--- a/misc/freeswitch/scripts/common/fapi.lua
+++ b/misc/freeswitch/scripts/common/fapi.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: FS api class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua
new file mode 100644
index 0000000..e50c763
--- /dev/null
+++ b/misc/freeswitch/scripts/common/gateway.lua
@@ -0,0 +1,168 @@
+-- Gemeinschaft 5 module: gateway class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+Gateway = {}
+
+-- Create Gateway object
+function Gateway.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.class = 'gateway';
+ self.log = arg.log;
+ self.database = arg.database;
+ self.record = arg.record;
+ self.GATEWAY_PREFIX = 'gateway';
+ return object;
+end
+
+
+function Gateway.list(self, technology)
+ technology = technology or 'sip';
+ local sql_query = 'SELECT * FROM `gateways` WHERE (`outbound` IS TRUE OR `inbound` IS TRUE) AND `technology` = "' .. technology .. '"';
+ local gateways = {};
+ self.database:query(sql_query, function(entry)
+ table.insert(gateways, entry);
+ end)
+
+ return gateways;
+end
+
+
+function Gateway.find_by_id(self, id)
+ local sql_query = 'SELECT * FROM `gateways` WHERE `id`= ' .. tonumber(id) .. ' LIMIT 1';
+
+ local gateway = nil;
+ self.database:query(sql_query, function(entry)
+ gateway = Gateway:new(self);
+ gateway.record = entry;
+ gateway.id = tonumber(entry.id);
+ gateway.name = entry.name;
+ end)
+
+ if gateway then
+ gateway.settings = self:config_table_get('gateway_settings', gateway.id);
+ end
+
+ return gateway;
+end
+
+
+function Gateway.find_by_name(self, name)
+ local gateway_name = name:gsub('([^%a%d%._%+])', '');
+
+ local sql_query = 'SELECT * FROM `gateways` WHERE `name`= "' .. gateway_name .. '" LIMIT 1';
+
+ local gateway = nil;
+ self.database:query(sql_query, function(entry)
+ gateway = Gateway:new(self);
+ gateway.record = entry;
+ gateway.id = tonumber(entry.id);
+ gateway.name = entry.name;
+ end)
+
+ if gateway then
+ gateway.settings = self:config_table_get('gateway_settings', gateway.id);
+ end
+
+ return gateway;
+end
+
+
+function Gateway.authenticate(self, technology, caller)
+ local sql_query = 'SELECT `c`.`name`, `c`.`id`, `a`.`value` `auth_source`, `b`.`value` `auth_pattern` \
+ FROM `gateway_settings` `a` \
+ INNER JOIN `gateway_settings` `b` \
+ ON (`a`.`gateway_id` = `b`.`gateway_id` AND `a`.`name` = "auth_source" AND `b`.`name` = "auth_pattern" ) \
+ LEFT JOIN `gateways` `c` \
+ ON (`a`.`gateway_id` = `c`.`id`) \
+ WHERE `c`.`inbound` IS TRUE AND `c`.`technology` = "' .. tostring(technology) .. '"';
+
+ local gateway = false;
+
+ self.database:query(sql_query, function(entry)
+ if caller:to_s(entry.auth_source):match(entry.auth_pattern) then
+ gateway = entry;
+ return;
+ end
+ end)
+
+ return gateway;
+end
+
+
+function Gateway.profile_get(self, gateway_id)
+ local sql_query = 'SELECT `value` FROM `gateway_settings` WHERE `gateway_id` = ' .. tonumber(gateway_id) .. ' AND `name` = "profile" LIMIT 1';
+
+ return self.database:query_return_value(sql_query);
+end
+
+
+function Gateway.config_table_get(self, config_table, gateway_id)
+ require 'common.str'
+
+ local sql_query = 'SELECT * FROM `'.. config_table ..'` WHERE `gateway_id` = ' .. tonumber(gateway_id);
+
+ local settings = {};
+ self.database:query(sql_query, function(entry)
+ local p_class_type = common.str.strip(entry.class_type):lower();
+ local p_name = common.str.strip(entry.name):lower();
+
+ if p_class_type == 'boolean' then
+ settings[p_name] = common.str.to_b(entry.value);
+ elseif p_class_type == 'integer' then
+ settings[p_name] = common.str.to_i(entry.value);
+ else
+ settings[p_name] = tostring(entry.value);
+ end
+ end)
+
+ return settings
+end
+
+
+function Gateway.parameters_build(self, gateway_id)
+ local settings = self:config_table_get('gateway_settings', gateway_id);
+ local parameters = {
+ realm = settings.domain,
+ extension = 'auto_to_user',
+ };
+
+ require 'common.str'
+
+ if common.str.blank(settings.username) then
+ parameters.username = 'gateway' .. gateway_id;
+ parameters.register = false;
+ else
+ parameters.username = settings.username;
+ parameters.register = true;
+ end
+
+ if not common.str.blank(settings.register) then
+ parameters.register = common.str.to_b(settings.register);
+ end
+
+ if common.str.blank(settings.password) then
+ parameters.password = 'gateway' .. gateway_id;
+ else
+ parameters.password = settings.password;
+ end
+
+ parameters['extension-in-contact'] = true;
+
+ if common.str.blank(settings.contact) then
+ parameters['extension'] = 'gateway' .. gateway_id;
+ else
+ parameters['extension'] = settings.contact;
+ end
+
+ for key, value in pairs(self:config_table_get('gateway_parameters', gateway_id)) do
+ parameters[key] = value;
+ end
+
+ return parameters;
+end
diff --git a/misc/freeswitch/scripts/common/ipcalc.lua b/misc/freeswitch/scripts/common/ipcalc.lua
index 5c19d20..49cb56c 100644
--- a/misc/freeswitch/scripts/common/ipcalc.lua
+++ b/misc/freeswitch/scripts/common/ipcalc.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: ip calculation functions
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/log.lua b/misc/freeswitch/scripts/common/log.lua
index d0d13dc..5aff2b8 100644
--- a/misc/freeswitch/scripts/common/log.lua
+++ b/misc/freeswitch/scripts/common/log.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: log
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/phone_number.lua b/misc/freeswitch/scripts/common/phone_number.lua
index 4df0d57..6635296 100644
--- a/misc/freeswitch/scripts/common/phone_number.lua
+++ b/misc/freeswitch/scripts/common/phone_number.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: phone number class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/routing_tables.lua b/misc/freeswitch/scripts/common/routing_tables.lua
deleted file mode 100644
index 34d0143..0000000
--- a/misc/freeswitch/scripts/common/routing_tables.lua
+++ /dev/null
@@ -1,66 +0,0 @@
--- Gemeinschaft 5 module: routing table functions
--- (c) AMOOMA GmbH 2012
---
-
-module(...,package.seeall)
-
-function expand_variables(line, variables_list)
- variables_list = variables_list or {};
-
- return (line:gsub('{([%a%d_]+)}', function(captured)
- return variables_list[captured] or '';
- end))
-end
-
-
-function match_route(entry, search_str, variables_list)
- if not entry or not search_str then
- return { error = 'No input values' };
- end
-
- local result = nil;
- local success = nil;
- success, result = pcall(string.find, search_str, entry[1]);
-
- if not success then
- return { error = result, line = line }
- elseif result then
- local route = {
- pattern = entry[1],
- value = search_str:gsub(entry[1], expand_variables(entry[#entry], variables_list)),
- }
-
- for index = 2, #entry-1 do
- local attribute = entry[index]:match('^(.-)%s*=');
- if attribute then
- route[attribute] = entry[index]:match('=%s*(.-)$');
- end
- end
-
- return route;
- end
-
- return {};
-end
-
-
-function match_caller_id(entry, search_str, variables_list)
- if not entry or not search_str then
- return { error = 'No input values' };
- end
- local result = nil;
- local success = nil;
- success, result = pcall(string.find, search_str, entry[1]);
- if not success then
- return { error = result, line = line }
- elseif result then
- return {
- value = search_str:gsub(entry[1], expand_variables(entry[4], variables_list)),
- class = entry[2],
- endpoint = entry[3],
- pattern = entry[1],
- }
- end
-
- return {};
-end
diff --git a/misc/freeswitch/scripts/common/sip_account.lua b/misc/freeswitch/scripts/common/sip_account.lua
index 28a00df..8dd432b 100644
--- a/misc/freeswitch/scripts/common/sip_account.lua
+++ b/misc/freeswitch/scripts/common/sip_account.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: sip account class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua
index ca6dcd9..32f054e 100644
--- a/misc/freeswitch/scripts/common/str.lua
+++ b/misc/freeswitch/scripts/common/str.lua
@@ -1,27 +1,17 @@
-- Gemeinschaft 5 module: string functions
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
function try(array, arguments)
- local argument = arguments:match('^(.-)%.') or arguments;
- local remaining_arguments = arguments:match('%.(.-)$');
- argument = tonumber(argument) or argument;
+ local result = array;
- if argument and type(array) == 'table' then
- if remaining_arguments then
- if type(array[argument]) == 'table' then
- return try(array[argument], remaining_arguments);
- else
- return nil;
- end
- else
- return array[argument];
- end
- end
-
- return nil;
+ arguments:gsub('([^%.]+)', function(entry)
+ local success, result = pcall(function() result = (result[tonumber(entry) or entry]); end);
+ end);
+
+ return result;
end
-- to number
diff --git a/misc/freeswitch/scripts/common/sync_log.lua b/misc/freeswitch/scripts/common/sync_log.lua
index 05b0dcf..3fdb646 100644
--- a/misc/freeswitch/scripts/common/sync_log.lua
+++ b/misc/freeswitch/scripts/common/sync_log.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: sync log class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua
index 906d3f8..9e62bb6 100644
--- a/misc/freeswitch/scripts/configuration.lua
+++ b/misc/freeswitch/scripts/configuration.lua
@@ -1,8 +1,11 @@
-- Gemeinschaft 5 dynamic freeswitch configuration
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
function nodes(database, local_node_id)
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
+
local gateways_xml = '';
require 'common.node'
@@ -14,86 +17,162 @@ function nodes(database, local_node_id)
node_parameters['proxy'] = node_record.ip_address;
node_parameters['register'] = 'false';
log:debug('NODE_GATEWAY ', node_record.id, ' - name: ', node_record.name, ', address: ', node_record.ip_address);
- gateways_xml = gateways_xml .. xml:gateway(node_record.name, node_parameters);
+ gateways_xml = gateways_xml .. xml:element{
+ 'gateway',
+ name = node_record.name,
+ xml:from_hash('param', node_parameters, 'name', 'value'),
+ };
end
end
return gateways_xml;
end
-function gateways(profile_name)
- local gateways_xml = '';
- local gateways = common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', false);
- if not gateways then
- return '';
- end
+function gateways(database, profile_name)
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
+
+ require 'common.str'
- for sofia_gateway, gateway_parameters in pairs(gateways) do
- if tostring(gateway_parameters.profile) == profile_name then
- log:debug('GATEWAY - name: ', sofia_gateway, ', address: ', gateway_parameters.proxy);
- gateways_xml = gateways_xml .. xml:gateway(sofia_gateway, gateway_parameters);
+ require 'common.gateway'
+ local gateway_class = common.gateway.Gateway:new{ log = log, database = database};
+ local gateways = gateway_class:list('sip');
+
+ local gateways_xml = '';
+ for index=1, #gateways do
+ local gateway = gateways[index];
+ local gateway_profile = gateway_class:profile_get(gateway.id);
+ if tostring(gateway_profile) == profile_name or (profile_name == 'gemeinschaft' and common.str.blank(gateway_profile)) then
+ log:debug('GATEWAY - name: ', gateway.name);
+ local parameters = gateway_class:parameters_build(gateway.id);
+
+ gateways_xml = gateways_xml .. xml:element{
+ 'gateway',
+ name = gateway_class.GATEWAY_PREFIX .. gateway.id,
+ xml:from_hash('param', parameters, 'name', 'value'),
+ };
end
end
return gateways_xml;
end
+
function profile(database, sofia_ini, profile_name, index, domains, node_id)
- local profile_parameters = sofia_ini['profile:' .. profile_name];
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
+
+ local parameters = sofia_ini['profile:' .. profile_name];
- if not profile_parameters then
+ if not parameters then
log:error('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no parameters');
return '';
end
+
+ if tostring(parameters['odbc-dsn']) == 'default' then
+ parameters['odbc-dsn'] = 'gemeinschaft:' .. tostring(database.user_name) .. ':' .. tostring(database.password);
+ end
+
-- set local bind address
if domains[index] then
- profile_parameters['sip-ip'] = domains[index]['host'];
- profile_parameters['rtp-ip'] = domains[index]['host'];
- profile_parameters['force-register-domain'] = domains[index]['host'];
- profile_parameters['force-subscription-domain'] = domains[index]['host'];
- profile_parameters['force-register-db-domain'] = domains[index]['host'];
- log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ', domain: ', domains[index]['host'], ', sip_bind: ', profile_parameters['sip-ip'], ':', profile_parameters['sip-port']);
+ parameters['sip-ip'] = domains[index]['host'];
+ parameters['rtp-ip'] = domains[index]['host'];
+ parameters['force-register-domain'] = domains[index]['host'];
+ parameters['force-subscription-domain'] = domains[index]['host'];
+ parameters['force-register-db-domain'] = domains[index]['host'];
+ log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ', domain: ', domains[index]['host'], ', sip_bind: ', parameters['sip-ip'], ':', parameters['sip-port']);
else
- log:error('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no domains');
+ log:debug('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no domains');
end
- local gateways_xml = gateways(profile_name);
+ local gateways_xml = gateways(database, profile_name);
if index == 1 then
gateways_xml = gateways_xml .. nodes(database, node_id);
end
- return xml:sofia_profile(profile_name, profile_parameters, gateways_xml);
+ local profile_xml = xml:element{
+ 'profile',
+ name = profile_name,
+ xml:element{
+ 'gateways',
+ gateways_xml,
+ },
+ xml:element{
+ 'domains',
+ xml:element{
+ 'domain',
+ name = 'all',
+ alias = 'true',
+ parse = 'false',
+ },
+ },
+ xml:element{
+ 'settings',
+ xml:from_hash('param', parameters, 'name', 'value'),
+ },
+ };
+
+ return profile_xml;
end
+
-- generate sofia.conf
function conf_sofia(database)
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
+
+ require 'common.configuration_table'
local sofia_profile = "gemeinschaft";
- require 'common.configuration_file'
- local sofia_ini = common.configuration_file.get('/opt/freeswitch/scripts/ini/sofia.ini');
- local dialplan_parameters = common.configuration_file.get('/opt/freeswitch/scripts/ini/dialplan.ini', 'parameters');
+ local sofia_ini = common.configuration_table.get(database, 'sofia');
+ local dialplan_parameters = common.configuration_table.get(database, 'dialplan', 'parameters');
- local local_node_id = tonumber(dialplan_parameters['node_id']) or 1;
+ local local_node_id = tonumber(dialplan_parameters.node_id) or 1;
require 'configuration.sip'
local domains = configuration.sip.Sip:new{ log = log, database = database}:domains();
sofia_profiles_xml = '';
- for index, profile_name in ipairs(sofia_ini.profiles) do
- sofia_profiles_xml = sofia_profiles_xml .. profile(database, sofia_ini, profile_name, index, domains, local_node_id);
+ for profile_name, index in pairs(sofia_ini.profiles) do
+ if tonumber(index) and tonumber(index) > 0 then
+ sofia_profiles_xml = sofia_profiles_xml .. profile(database, sofia_ini, profile_name, tonumber(index), domains, local_node_id);
+ end
end
- XML_STRING = xml:document(xml:sofia(sofia_ini.parameters, sofia_profiles_xml))
+ XML_STRING = xml:element{
+ 'document',
+ ['type'] = 'freeswitch/xml',
+ xml:element{
+ 'section',
+ name = 'configuration',
+ description = 'Gemeinschaft 5 FreeSWITCH configuration',
+ xml:element{
+ 'configuration',
+ name = 'sofia.conf',
+ description = 'Sofia configuration',
+ xml:element{
+ 'global_settings',
+ xml:from_hash('param', sofia_ini.parameters, 'name', 'value'),
+ },
+ xml:element{
+ 'profiles',
+ sofia_profiles_xml,
+ },
+ },
+ },
+ };
+
end
function conf_conference(database)
- XML_STRING = xml:document(xml:conference());
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
- require 'common.configuration_file'
- local conference_ini = common.configuration_file.get('/opt/freeswitch/scripts/ini/conferences.ini');
- local conference_parameters = conference_ini.parameters;
+ require 'common.configuration_table'
+ local config = common.configuration_table.get(database, 'conferences');
+ local profiles = nil;
local event_name = params:getHeader("Event-Name")
if event_name == 'COMMAND' then
@@ -105,8 +184,15 @@ function conf_conference(database)
conference = common.conference.Conference:new{log=log, database=database}:find_by_id(conf_name);
if conference then
log:debug('CONFIG_CONFERENCE ', conf_name, ' name: ', conference.record.name, ', profile: ', profile_name);
- conference_parameters['caller-id-name'] = conference.record.name or '';
- XML_STRING = xml:document(xml:conference(xml:conference_profile(profile_name, conference_parameters)));
+ config.parameters['caller-id-name'] = conference.record.name or '';
+ profiles = xml:element{
+ 'profiles',
+ xml:element{
+ 'profile',
+ name = profile_name,
+ xml:from_hash('param', config.parameters, 'name', 'value'),
+ },
+ };
else
log:error('CONFIG_CONFERENCE ', conf_name, ' - conference not found');
end
@@ -116,61 +202,251 @@ function conf_conference(database)
else
log:debug('CONFIG_CONFERENCE ', conf_name, ' - event: ', event_name);
end
+
+ XML_STRING = xml:element{
+ 'document',
+ ['type'] = 'freeswitch/xml',
+ xml:element{
+ 'section',
+ name = 'configuration',
+ description = 'Gemeinschaft 5 FreeSWITCH configuration',
+ xml:element{
+ 'configuration',
+ name = 'conference.conf',
+ description = 'Conference configuration',
+ xml:element{
+ 'caller-controls',
+ xml:element{
+ 'group',
+ name = 'speaker',
+ xml:from_hash('control', config.controls_speaker, 'action', 'digits'),
+ },
+ xml:element{
+ 'group',
+ name = 'moderator',
+ xml:from_hash('control', config.controls_moderator, 'action', 'digits'),
+ },
+ },
+ profiles,
+ },
+ },
+ };
+end
+
+function conf_voicemail(database)
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
+
+ require 'common.configuration_table';
+ local parameters = common.configuration_table.get(database, 'voicemail', 'parameters');
+
+ if tostring(parameters['odbc-dsn']) == 'default' then
+ parameters['odbc-dsn'] = 'gemeinschaft:' .. tostring(database.user_name) .. ':' .. tostring(database.password);
+ end
+
+ XML_STRING = xml:element{
+ 'document',
+ ['type'] = 'freeswitch/xml',
+ xml:element{
+ 'section',
+ name = 'configuration',
+ description = 'Gemeinschaft 5 FreeSWITCH configuration',
+ xml:element{
+ 'configuration',
+ name = 'voicemail.conf',
+ description = 'Voicemail configuration',
+ xml:element{
+ 'profiles',
+ xml:element{
+ 'profile',
+ name = 'default',
+ xml:from_hash('param', parameters, 'name', 'value'),
+ },
+ },
+ },
+ },
+ };
+end
+
+function conf_post_switch(database)
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
+
+ require 'common.configuration_table';
+ local parameters = common.configuration_table.get(database, 'post_load_switch', 'settings');
+
+ XML_STRING = xml:element{
+ 'document',
+ ['type'] = 'freeswitch/xml',
+ xml:element{
+ 'section',
+ name = 'configuration',
+ description = 'Gemeinschaft 5 FreeSWITCH configuration',
+ xml:element{
+ 'configuration',
+ name = 'post_load_switch.conf',
+ description = 'Switch configuration',
+ xml:element{
+ 'settings',
+ xml:from_hash('param', parameters, 'name', 'value'),
+ },
+ },
+ },
+ };
end
function directory_sip_account(database)
+ require 'configuration.simple_xml'
+ local xml = configuration.simple_xml.SimpleXml:new();
+
local key = params:getHeader('key');
local auth_name = params:getHeader('user');
local domain = params:getHeader('domain');
local purpose = params:getHeader('purpose');
+ local user_xml = nil;
+
if auth_name and auth_name ~= '' then
-- sip account or gateway
if string.len(auth_name) > 3 and auth_name:sub(1, 3) == 'gw+' then
local gateway_name = auth_name:sub(4);
domain = domain or freeswitch.API():execute('global_getvar', 'domain');
- require 'configuration.sip'
- log:notice('DATABASE: ', database);
- local sip_gateway = configuration.sip.Sip:new{ log = log, database = database}:find_gateway_by_name(gateway_name);
- if sip_gateway ~= nil and next(sip_gateway) ~= nil then
+ require 'common.gateway'
+ local sip_gateway = common.gateway.Gateway:new{ log = self.log, database = self.database }:find_by_name(gateway_name);
+ if sip_gateway then
log:debug('DIRECTORY_GATEWAY - name: ', gateway_name, ', auth_name: ', auth_name);
- XML_STRING = xml:document(xml:directory(xml:gateway_user(sip_gateway, gateway_name, auth_name), domain));
+
+ local user_variables = {
+ user_context = "default",
+ gs_from_gateway = "true",
+ gs_gateway_name = gateway_name,
+ gs_gateway_id = sip_gateway.id,
+ }
+
+ user_xml = xml:element{
+ 'user',
+ id = auth_name,
+ xml:element{
+ 'params',
+ xml:element{
+ 'param',
+ password = sip_gateway.record.password,
+ }
+ },
+ xml:element{
+ 'variables',
+ xml:from_hash('variable', user_variables, 'name', 'value'),
+ },
+ };
else
log:debug('DIRECTORY_GATEWAY - gateway not found - name: ', gateway_name, ', auth_name: ', auth_name);
end
else
require 'common.sip_account'
local sip_account = common.sip_account.SipAccount:new{ log = log, database = database}:find_by_auth_name(auth_name, domain);
+
+ require 'common.configuration_table'
+ local user_parameters = common.configuration_table.get(database, 'sip_accounts', 'parameters');
+
if sip_account ~= nil then
+ user_parameters['password'] = sip_account.record.password;
+ user_parameters['vm-password'] = sip_account.record.voicemail_pin;
+
+ local user_variables = {
+ user_context = "default",
+ gs_from_gateway = "false",
+ gs_account_id = sip_account.record.id,
+ gs_account_uuid = sip_account.record.uuid,
+ gs_account_type = "SipAccount",
+ gs_account_state = sip_account.record.state,
+ gs_account_caller_name = sip_account.record.caller_name,
+ gs_account_owner_type = sip_account.record.sip_accountable_type,
+ gs_account_owner_id = sip_account.record.sip_accountable_id
+ }
+
if tostring(purpose) == 'publish-vm' then
log:debug('DIRECTORY_SIP_ACCOUNT - purpose: VoiceMail, auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain);
- XML_STRING = xml:document(xml:directory(xml:group_default(xml:user(sip_account.record)), domain));
+ user_xml = xml:element{
+ 'groups',
+ xml:element{
+ 'group',
+ name = 'default',
+ xml:element{
+ 'users',
+ xml:element{
+ 'user',
+ id = sip_account.record.auth_name,
+ xml:element{
+ 'params',
+ xml:from_hash('param', user_parameters, 'name', 'value'),
+ },
+ xml:element{
+ 'variables',
+ xml:from_hash('variable', user_variables, 'name', 'value'),
+ },
+ },
+ },
+ },
+ };
else
log:debug('DIRECTORY_SIP_ACCOUNT - auth_name: ', sip_account.record.auth_name, ', caller_name: ', sip_account.record.caller_name, ', domain: ', domain);
- XML_STRING = xml:document(xml:directory(xml:user(sip_account.record), domain));
+
+ user_xml = xml:element{
+ 'user',
+ id = sip_account.record.auth_name,
+ xml:element{
+ 'params',
+ xml:from_hash('param', user_parameters, 'name', 'value'),
+ },
+ xml:element{
+ 'variables',
+ xml:from_hash('variable', user_variables, 'name', 'value'),
+ },
+ };
end
else
log:debug('DIRECTORY_SIP_ACCOUNT - sip account not found - auth_name: ', auth_name, ', domain: ', domain);
-- fake sip_account configuration
- sip_account = {
- auth_name = auth_name,
- id = 0,
- uuid = '',
- password = tostring(math.random(0, 65534)),
- voicemail_pin = '',
- state = 'inactive',
- caller_name = '',
- sip_accountable_type = 'none',
- sip_accountable_id = 0,
- }
- XML_STRING = xml:document(xml:directory(xml:user(sip_account), domain))
+ user_parameters['password'] = tostring(math.random(0, 65534));
+ user_parameters['vm-password'] = '';
+
+ user_xml = xml:element{
+ 'user',
+ id = auth_name,
+ xml:element{
+ 'params',
+ xml:from_hash('param', user_parameters, 'name', 'value'),
+ },
+ };
end
end
elseif tostring(XML_REQUEST.key_name) == 'name' and tostring(XML_REQUEST.key_value) ~= '' then
log:debug('DOMAIN_DIRECTORY - domain: ', XML_REQUEST.key_value);
XML_STRING = xml:document(xml:directory(nil, XML_REQUEST.key_value));
end
+
+ XML_STRING = xml:element{
+ 'document',
+ ['type'] = 'freeswitch/xml',
+ xml:element{
+ 'section',
+ name = 'directory',
+ xml:element{
+ 'domain',
+ name = domain,
+ xml:element{
+ 'params',
+ xml:element{
+ 'param',
+ name = 'dial-string',
+ value = '${sofia_contact(${dialed_user}@${dialed_domain})}',
+ },
+ },
+ user_xml,
+ },
+ },
+ };
end
@@ -182,9 +458,12 @@ log = common.log.Log:new();
log.prefix = '#C# [' .. log_identifier .. '] ';
-- return a valid xml document
-require 'configuration.freeswitch_xml'
-xml = configuration.freeswitch_xml.FreeSwitchXml:new();
-XML_STRING = xml:document();
+require 'configuration.simple_xml'
+local xml = configuration.simple_xml.SimpleXml:new();
+XML_STRING = xml:element{
+ 'document',
+ ['type'] = 'freeswitch/xml',
+};
local database = nil;
@@ -203,6 +482,10 @@ if XML_REQUEST.section == 'configuration' and XML_REQUEST.tag_name == 'configura
conf_sofia(database);
elseif XML_REQUEST.key_value == "conference.conf" then
conf_conference(database);
+ elseif XML_REQUEST.key_value == "voicemail.conf" then
+ conf_voicemail(database);
+ elseif XML_REQUEST.key_value == "post_load_switch.conf" then
+ conf_post_switch(database);
end
elseif XML_REQUEST.section == 'directory' and XML_REQUEST.tag_name == '' then
log:debug('SIP_ACCOUNT_DIRECTORY - initialization phase');
diff --git a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua b/misc/freeswitch/scripts/configuration/freeswitch_xml.lua
deleted file mode 100644
index c81bf50..0000000
--- a/misc/freeswitch/scripts/configuration/freeswitch_xml.lua
+++ /dev/null
@@ -1,307 +0,0 @@
--- ConfigurationModule: FreeSwitchXml
---
-module(...,package.seeall)
-
-FreeSwitchXml = {}
-
--- Create FreeSwitchXml object
-function FreeSwitchXml.new(self, object)
- object = object or {}
- setmetatable(object, self)
- self.__index = self
- return object
-end
-
-function FreeSwitchXml.param(self, name, value)
- return '<param name="' .. name .. '" value="' .. value .. '"/>'
-end
-
-function FreeSwitchXml.variable(self, name, value)
- return '<variable name="' .. name .. '" value="' .. value .. '"/>'
-end
-
-function FreeSwitchXml.document(self, sections_xml)
- if type(sections_xml) == "string" then
- sections_xml = { sections_xml }
- elseif type(sections_xml) == "nil" then
- sections_xml = { "" }
- end
-
- local xml_string=
-[[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="freeswitch/xml">
-]] .. table.concat(sections_xml, "\n") .. [[
-
-</document>]]
-
- return xml_string
-end
-
-function FreeSwitchXml.directory(self, entries_xml, domain)
- if type(entries_xml) == "string" then
- entries_xml = { entries_xml }
- elseif type(entries_xml) == "nil" then
- entries_xml = { "" }
- end
-
- local xml_string =
-[[
-<section name="directory">
-<domain name="]] .. domain .. [[">
-<params>
-<param name="dial-string" value="${sofia_contact(${dialed_user}@${dialed_domain})}"/>
-</params>
-]] .. table.concat(entries_xml, "\n") .. [[
-
-</domain>
-</section>]]
- return xml_string
-end
-
-function FreeSwitchXml.group_default(self, entries_xml)
- if type(entries_xml) == "string" then
- entries_xml = { entries_xml }
- elseif type(entries_xml) == "nil" then
- entries_xml = { "" }
- end
-
- local xml_string =
-[[
-<groups>
-<group name="default">
-<users>
-]] .. table.concat(entries_xml, "\n") .. [[
-
-</users>
-</group>
-</groups>]]
- return xml_string
-end
-
-function FreeSwitchXml.user(self, user)
- require 'common.configuration_file'
- local params = common.configuration_file.get('/opt/freeswitch/scripts/ini/sip_accounts.ini', 'parameters');
-
- params['password'] = user.password;
- params['vm-password'] = user.voicemail_pin;
-
- local variables = {
- user_context = "default",
- gs_from_gateway = "false",
- gs_account_id = user.id,
- gs_account_uuid = user.uuid,
- gs_account_type = "SipAccount",
- gs_account_state = user.state,
- gs_account_caller_name = user.caller_name,
- gs_account_owner_type = user.sip_accountable_type,
- gs_account_owner_id = user.sip_accountable_id
- }
-
- local params_xml = {}
- for name, value in pairs(params) do
- params_xml[#params_xml+1] = self:param(name, value)
- end
-
- local variables_xml = {}
- for name, value in pairs(variables) do
- variables_xml[#variables_xml+1] = self:variable(name, value)
- end
-
- local xml_string =
-[[
-<user id="]] .. user.auth_name .. [[">
-<params>
-]] .. table.concat(params_xml, "\n") .. [[
-
-</params>
-<variables>
-]] .. table.concat(variables_xml, "\n") .. [[
-
-</variables>
-</user>]]
- return xml_string
-end
-
-function FreeSwitchXml.gateway_user(self, user, gateway_name, auth_name)
- user.id = user.id or 0
-
- local params = {
- ['password'] = user.password,
- }
-
- local variables = {
- user_context = "default",
- gs_from_gateway = "true",
- gs_gateway_name = gateway_name,
- gs_gateway_id = user.id
- }
-
- local params_xml = {}
- for name, value in pairs(params) do
- params_xml[#params_xml+1] = self:param(name, value)
- end
-
- local variables_xml = {}
- for name, value in pairs(variables) do
- variables_xml[#variables_xml+1] = self:variable(name, value)
- end
-
- local xml_string =
-[[
-<user id="]] .. auth_name .. [[">
-<params>
-]] .. table.concat(params_xml, "\n") .. [[
-
-</params>
-<variables>
-]] .. table.concat(variables_xml, "\n") .. [[
-
-</variables>
-</user>]]
- return xml_string
-end
-
-function FreeSwitchXml.sofia(self, parameters, profiles_xml)
- if type(profiles_xml) == "string" then
- profiles_xml = { profiles_xml }
- elseif type(profiles_xml) == "nil" then
- profiles_xml = { "" }
- end
-
- local params_xml = {}
- for name, value in pairs(parameters) do
- params_xml[#params_xml+1] = self:param(name, value)
- end
-
- local xml_string =
-[[
-<section name="configuration" description="FreeSwitch configuration for Sofia Profile">
-<configuration name="sofia.conf" description="Sofia SIP Configuration">
-<global_settings>
-]] .. table.concat(params_xml, "\n") .. [[
-
-</global_settings>
-<profiles>
-]] .. table.concat(profiles_xml, "\n") .. [[
-
-</profiles>
-</configuration>
-</section>]]
- return xml_string
-end
-
-function FreeSwitchXml.sofia_profile(self, profile_name, parameters, gateways_xml)
- params_xml = {}
- for name, value in pairs(parameters) do
- params_xml[#params_xml+1] = self:param(name, value)
- end
-
- if type(gateways_xml) == "string" then
- gateways_xml = { gateways_xml }
- elseif type(gateways_xml) == "nil" then
- gateways_xml = { "" }
- end
-
- local xml_string =
-[[
-<profile name="]] .. profile_name .. [[">
-<aliases>
-</aliases>
-<gateways>
-]] .. table.concat(gateways_xml, "\n") .. [[
-
-</gateways>
-<domains>
-<domain name="all" alias="true" parse="false"/>
-</domains>
-<settings>
-]] .. table.concat(params_xml, "\n") .. [[
-
-</settings>
-</profile>]]
- return xml_string
-end
-
-function FreeSwitchXml.gateway(self, gateway_name, parameters)
- local params_xml = {}
- if parameters then
- for name, value in pairs(parameters) do
- params_xml[#params_xml+1] = self:param(name, value)
- end
- end
-
- local xml_string =
-[[
-<gateway name="]] .. gateway_name .. [[">
-]] .. table.concat(params_xml, "\n") .. [[
-
-</gateway>]]
- return xml_string
-end
-
-function FreeSwitchXml.conference(self, profiles_xml)
- if type(profiles_xml) == "string" then
- profiles_xml = { profiles_xml }
- elseif type(profiles_xml) == "nil" then
- profiles_xml = { "" }
- end
-
- local xml_string =
-[[
-<section name="configuration" description="FreeSwitch configuration for Sofia Profile">
-<configuration name="conference.conf" description="Conference configuration">
-<advertise>
-</advertise>
-<caller-controls>
-<group name="speaker">
-<control action="mute"/>
-<control action="deaf mute" digits="*"/>
-<control action="energy up" digits="9"/>
-<control action="energy equ" digits="8"/>
-<control action="energy dn" digits="7"/>
-<control action="vol talk up" digits="3"/>
-<control action="vol talk zero" digits="2"/>
-<control action="vol talk dn" digits="1"/>
-<control action="vol listen up" digits="6"/>
-<control action="vol listen zero" digits="5"/>
-<control action="vol listen dn" digits="4"/>
-<control action="hangup" digits="#"/>
-</group>
-<group name="moderator">
-<control action="mute" digits="0"/>
-<control action="deaf mute" digits="*"/>
-<control action="energy up" digits="9"/>
-<control action="energy equ" digits="8"/>
-<control action="energy dn" digits="7"/>
-<control action="vol talk up" digits="3"/>
-<control action="vol talk zero" digits="2"/>
-<control action="vol talk dn" digits="1"/>
-<control action="vol listen up" digits="6"/>
-<control action="vol listen zero" digits="5"/>
-<control action="vol listen dn" digits="4"/>
-<control action="hangup" digits="#"/>
-</group>
-</caller-controls>
-<profiles>
-]] .. table.concat(profiles_xml, "\n") .. [[
-
-</profiles>
-</configuration>
-</section>]]
- return xml_string
-end
-
-function FreeSwitchXml.conference_profile(self, profile_name, parameters)
- params_xml = {}
- for name, value in pairs(parameters) do
- params_xml[#params_xml+1] = self:param(name, value)
- end
-
- local xml_string =
-[[
-<profile name="]] .. profile_name .. [[">
-]] .. table.concat(params_xml, "\n") .. [[
-
-</profile>]]
- return xml_string
-end
diff --git a/misc/freeswitch/scripts/configuration/simple_xml.lua b/misc/freeswitch/scripts/configuration/simple_xml.lua
new file mode 100644
index 0000000..f04dd1e
--- /dev/null
+++ b/misc/freeswitch/scripts/configuration/simple_xml.lua
@@ -0,0 +1,50 @@
+-- Gemeinschaft 5 simple xml gererator class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+SimpleXml = {}
+
+-- Create SimpleXml object
+function SimpleXml.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.class = 'simplexml';
+ return object;
+end
+
+function SimpleXml.element(self, arg)
+ local xml_tag = '<' .. tostring(arg[1]);
+ for key, value in pairs(arg) do
+ if type(key) == 'string' then
+ xml_tag = xml_tag .. ' ' .. tostring(key) .. '="' .. tostring(value) .. '"';
+ end
+ end
+ xml_tag = xml_tag .. '>';
+
+ for key=2, #arg do
+ xml_tag = xml_tag .. '\n' .. tostring(arg[key]) .. '\n';
+ end
+
+ return xml_tag .. '</' .. tostring(arg[1]) .. '>';
+end
+
+
+function SimpleXml.from_hash(self, element_name, parameter_hash, key_name, value_name)
+ local params_xml = '';
+ for key, value in pairs(parameter_hash) do
+ local arguments = { [1] = element_name };
+ if key_name and value_name then
+ arguments[key_name] = key;
+ arguments[value_name] = value;
+ else
+ arguments[key] = value;
+ end
+ params_xml = params_xml .. tostring(self:element(arguments)) .. '\n';
+ end
+
+ return params_xml;
+end
diff --git a/misc/freeswitch/scripts/configuration/sip.lua b/misc/freeswitch/scripts/configuration/sip.lua
index 78143bc..6f5b204 100644
--- a/misc/freeswitch/scripts/configuration/sip.lua
+++ b/misc/freeswitch/scripts/configuration/sip.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: sip configuration class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -18,12 +18,6 @@ function Sip.new(self, arg)
return object;
end
--- find gateway by name
-function Sip.find_gateway_by_name(self, name)
- require 'common.configuration_file'
- return common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', name);
-end
-
-- list sip domains
function Sip.domains(self)
local sql_query = 'SELECT * FROM `sip_domains`';
diff --git a/misc/freeswitch/scripts/dialplan/acd.lua b/misc/freeswitch/scripts/dialplan/acd.lua
index 563d836..f4b298e 100644
--- a/misc/freeswitch/scripts/dialplan/acd.lua
+++ b/misc/freeswitch/scripts/dialplan/acd.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: acd class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/dialplan/cdr.lua b/misc/freeswitch/scripts/dialplan/cdr.lua
index 55a7889..d0fdede 100644
--- a/misc/freeswitch/scripts/dialplan/cdr.lua
+++ b/misc/freeswitch/scripts/dialplan/cdr.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: cdr class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua
index 391f5bf..b92dc70 100644
--- a/misc/freeswitch/scripts/dialplan/dialplan.lua
+++ b/misc/freeswitch/scripts/dialplan/dialplan.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: dialplan class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -7,7 +7,6 @@ module(...,package.seeall)
Dialplan = {}
-- local constants
-local CONFIG_FILE_NAME = '/opt/freeswitch/scripts/ini/dialplan.ini';
local DIAL_TIMEOUT = 120;
local MAX_LOOPS = 20;
local DIALPLAN_FUNCTION_PATTERN = '^f[_%-].*';
@@ -74,22 +73,22 @@ function Dialplan.domain_get(self, domain)
end
-function Dialplan.configuration_read(self, file_name)
+function Dialplan.configuration_read(self)
require 'common.str'
- require 'common.configuration_file'
+ require 'common.configuration_table'
-- dialplan configuration
- self.config = common.configuration_file.get(file_name or CONFIG_FILE_NAME);
+ self.config = common.configuration_table.get(self.database, 'dialplan');
self.node_id = common.str.to_i(self.config.parameters.node_id);
self.domain = self:domain_get(self.config.parameters.domain);
self.dial_timeout = tonumber(self.config.parameters.dial_timeout) or DIAL_TIMEOUT;
self.max_loops = tonumber(self.config.parameters.max_loops) or MAX_LOOPS;
self.user_image_url = common.str.to_s(self.config.parameters.user_image_url);
self.phone_book_entry_image_url = common.str.to_s(self.config.parameters.phone_book_entry_image_url);
- self.phonebook_number_lookup = common.str.to_b(self.config.parameters.phonebook_number_lookup);
- self.geo_number_lookup = common.str.to_b(self.config.parameters.geo_number_lookup);
+ self.phonebook_number_lookup = self.config.parameters.phonebook_number_lookup;
+ self.geo_number_lookup = self.config.parameters.geo_number_lookup;
self.default_language = self.config.parameters.default_language or 'en';
- self.send_ringing_to_gateways = common.str.to_b(self.config.parameters.send_ringing_to_gateways);
+ self.send_ringing_to_gateways = self.config.parameters.send_ringing_to_gateways;
if tonumber(self.config.parameters.default_ringtone) then
self.default_ringtone = 'http://amooma.de;info=Ringer' .. self.config.parameters.default_ringtone .. ';x-line-id=0';
@@ -113,57 +112,34 @@ function Dialplan.hangup(self, code, phrase, cause)
end
-function Dialplan.check_auth(self)
- local authenticated = false;
-
- require 'common.str'
- if self.caller.from_node then
- self.log:info('AUTH_FIRST_STAGE - node authenticated - node_id: ', self.caller.node_id);
- authenticated = true;
- elseif not common.str.blank(self.caller.auth_account_type) then
- self.log:info('AUTH_FIRST_STAGE - sipaccount autheticated by name/password: ', self.caller.auth_account_type, '=', self.caller.account_id, '/', self.caller.account_uuid);
- authenticated = true;
- elseif self.caller.from_gateway then
- self.log:info('AUTH_FIRST_STAGE - gateway autheticated by name/password: gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name);
- authenticated = true;
- else
- local gateways = common.configuration_file.get('/opt/freeswitch/scripts/ini/gateways.ini', false);
- if not gateways then
- return false;
- end
- for gateway, gateway_parameters in pairs(gateways) do
- if common.str.to_s(gateway_parameters.proxy) == self.caller.sip_contact_host then
- self.caller.gateway_name = gateway;
- self.caller.from_gateway = true;
- self.log:info('AUTH_FIRST_STAGE - gateway autheticated by ip: gateway=', self.caller.gateway_id, ', name: ', self.caller.gateway_name, ', ip: ', self.caller.sip_contact_host);
- authenticated = true;
- end
- end
- end
-
- return authenticated;
-end
-
-
-function Dialplan.check_auth_node(self)
+function Dialplan.auth_node(self)
require 'common.node'
local node = common.node.Node:new{ log = self.log, database = self.database }:find_by_address(self.caller.sip_contact_host);
- return (node ~= nil);
+ if node then
+ self.log:info('AUTH_NODE - node_id: ', self.caller.node_id, ', contact address:', self.caller.sip_contact_host);
+ return true;
+ end
end
-function Dialplan.check_auth_ip(self)
- self.log:info('AUTH - node: ', self.caller.from_node, ', auth_account: ', self.caller.auth_account_type, ', gateway: ', self.caller.from_gateway);
+function Dialplan.auth_sip_account(self)
require 'common.str'
- if self.caller.from_node then
+ if not common.str.blank(self.caller.auth_account_type) then
+ self.log:info('AUTH_SIP_ACCOUNT - ', self.caller.auth_account_type, '=', self.caller.account_id, '/', self.caller.account_uuid);
return true;
- elseif not common.str.blank(self.caller.auth_account_type) then
- return true;
- elseif self.caller.from_gateway then
- return true;
- else
- return nil;
+ end
+end
+
+
+function Dialplan.auth_gateway(self)
+ require 'common.gateway'
+ local gateway_class = common.gateway.Gateway:new{ log = self.log, database = self.database};
+ local gateway = gateway_class:authenticate('sip', self.caller);
+
+ if gateway then
+ log:info('AUTH_GATEWAY - ', gateway.auth_source, ' ~ ', gateway.auth_pattern, ', gateway=', gateway.id, ', name: ', gateway.name, ', ip: ', self.caller.sip_contact_host);
+ return gateway_class:find_by_id(gateway.id);
end
end
@@ -258,19 +234,21 @@ end
function Dialplan.retrieve_caller_data(self)
- self.caller.caller_phone_numbers_hash = {}
-
require 'common.str'
- local dialed_sip_user = self.caller:to_s('dialed_user');
+ self.caller.caller_phone_numbers_hash = {}
-- TODO: Set auth_account on transfer initiated by calling party
- if not common.str.blank(dialed_sip_user) then
- self.caller.auth_account = self:object_find('sipaccount', self.caller:to_s('dialed_domain'), dialed_sip_user);
- self.caller:set_auth_account(self.caller.auth_account);
+ if not common.str.blank(self.caller.dialed_sip_user) then
+ self.caller.auth_account = self:object_find('sipaccount', self.caller.dialed_domain, dialed_sip_user);
+ if self.caller.set_auth_account then
+ self.caller:set_auth_account(self.caller.auth_account);
+ end
elseif not common.str.blank(self.caller.auth_account_type) and not common.str.blank(self.caller.auth_account_uuid) then
self.caller.auth_account = self:object_find(self.caller.auth_account_type, self.caller.auth_account_uuid);
- self.caller:set_auth_account(self.caller.auth_account);
+ if self.caller.set_auth_account then
+ self.caller:set_auth_account(self.caller.auth_account);
+ end
end
if self.caller.auth_account then
@@ -299,7 +277,7 @@ function Dialplan.retrieve_caller_data(self)
self.log:error('CALLER_DATA - caller owner not found');
end
- if not self.caller.clir then
+ if not self.caller.clir and self.caller.set_caller_id then
self.caller:set_caller_id(self.caller.caller_phone_numbers[1], self.caller.account.record.caller_name or self.caller.account.record.name);
end
else
@@ -366,12 +344,6 @@ function Dialplan.destination_new(self, arg)
end
-function Dialplan.routes_get(self, destination)
- require 'dialplan.route'
- return dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }:outbound(self.caller, destination.number);
-end
-
-
function Dialplan.set_caller_picture(self, entry_id, entry_type, image)
entry_type = entry_type:lower();
if entry_type == 'user' then
@@ -466,16 +438,13 @@ function Dialplan.dial(self, destination)
end
end
- if common.str.to_b(self.config.parameters.bypass_media) then
- self.caller:set_variable('bypass_media', true);
- end
-
require 'dialplan.sip_call'
return dialplan.sip_call.SipCall:new{ log = self.log, database = self.database, caller = self.caller }:fork(
destinations,
{ timeout = self.dial_timeout_active,
send_ringing = ( self.send_ringing_to_gateways and self.caller.from_gateway ),
bypass_media_network = self.config.parameters.bypass_media_network,
+ update_callee_display = self.config.parameters.update_callee_display,
}
);
end
@@ -655,9 +624,11 @@ function Dialplan.callthrough(self, destination)
return { continue = false, code = 404, phrase = 'No destination' }
end
- local route = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }:prerouting(self.caller, destination_number);
- if route and route.value then
- destination_number = route.value;
+ require 'dialplan.router'
+ local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', true);
+
+ if route and route.destination_number then
+ destination_number = route.destination_number;
end
if not callthrough:whitelist(destination_number) then
@@ -786,16 +757,30 @@ function Dialplan.switch(self, destination)
return self:dialplanfunction(destination);
elseif not common.str.blank(destination.number) then
local result = { continue = false, code = 404, phrase = 'No route' }
- local routes = self:routes_get(destination);
+
+ local clip_no_screening = common.str.try(caller, 'account.record.clip_no_screening');
+ self.caller.caller_id_numbers = {}
+ if not common.str.blank(clip_no_screening) then
+ for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do
+ table.insert(self.caller.caller_id_numbers, number);
+ end
+ end
+ for index, number in ipairs(self.caller.caller_phone_numbers) do
+ table.insert(self.caller.caller_id_numbers, number);
+ end
+ self.log:info('CALLER_ID_NUMBERS - clir: ', self.caller.clir, ', numbers: ', table.concat(self.caller.caller_id_numbers, ','));
+
+ destination.callee_id_number = destination.number;
+ destination.callee_id_name = nil;
+
+ require 'dialplan.router'
+ local routes = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('outbound');
if not routes or #routes == 0 then
self.log:notice('SWITCH - no route - number: ', destination.number);
return { continue = false, code = 404, phrase = 'No route' }
end
- destination.callee_id_number = destination.number;
- destination.callee_id_name = nil;
-
if self.phonebook_number_lookup then
require 'common.str'
local user_id = common.str.try(self.caller, 'account.owner.id');
@@ -828,26 +813,26 @@ function Dialplan.switch(self, destination)
self.caller:set_callee_id(destination.callee_id_number, destination.callee_id_name);
for index, route in ipairs(routes) do
- if route.class == 'hangup' then
+ if route.endpoint_type == 'hangup' then
return { continue = false, code = route.endpoint, phrase = route.phrase, cause = route.value }
end
- if route.class == 'forward' then
+ if route.endpoint_type == 'forward' then
return { continue = true, call_forwarding = { number = route.value, service = 'route', type = 'phonenumber' }}
end
- destination.gateway = route.endpoint;
- destination.type = route.class;
- destination.number = route.value;
- destination.caller_id_number = route.caller_id_number;
- destination.caller_id_name = route.caller_id_name;
+
+ for key, value in pairs(route) do
+ destination[key] = value;
+ end
+
result = self:dial(destination);
if result.continue == false then
break;
end
- if common.str.to_b(self.routes.failover[tostring(result.code)]) == true then
+ if common.str.to_b(self.route_failover[tostring(result.code)]) == true then
self.log:info('SWITCH - failover - code: ', result.code);
- elseif common.str.to_b(self.routes.failover[tostring(result.cause)]) == true then
+ elseif common.str.to_b(self.route_failover[tostring(result.cause)]) == true then
self.log:info('SWITCH - failover - cause: ', result.cause);
else
self.log:info('SWITCH - no failover - cause: ', result.cause, ', code: ', result.code);
@@ -864,10 +849,11 @@ end
function Dialplan.run(self, destination)
+ require 'common.str';
+ require 'dialplan.router';
+
self.caller:set_variable('hangup_after_bridge', false);
- self.caller:set_variable('ringback', self.config.parameters.ringback);
self.caller:set_variable('bridge_early_media', 'true');
- self.caller:set_variable('send_silence_when_idle', 0);
self.caller:set_variable('default_language', self.default_language);
self.caller:set_variable('gs_save_cdr', true);
self.caller:set_variable('gs_call_service', 'dial');
@@ -875,30 +861,69 @@ function Dialplan.run(self, destination)
self.caller.date = os.date('%y%m%d%w');
self.caller.time = os.date('%H%M%S');
- self.routes = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini');
+ if type(self.config.variables) == 'table' then
+ for key, value in pairs(self.config.variables) do
+ self.caller:set_variable(key, value);
+ end
+ end
+
self.caller.domain_local = self.domain;
self:retrieve_caller_data();
+ self.route_failover = common.configuration_table.get(self.database, 'call_route', 'failover');
if not destination or destination.type == 'unknown' then
- require 'dialplan.route'
local route = nil;
+ if self.caller.gateway then
+ if not common.str.blank(self.caller.gateway.settings.number_source) then
+ self.log:debug('INBOUND_NUMBER: number_source: ', self.caller.gateway.settings.number_source, ', number: ', self.caller:to_s(self.caller.gateway.settings.number_source));
+ self.caller.destination_number = self.caller:to_s(self.caller.gateway.settings.number_source);
+ end
- if self.caller.from_gateway then
- local route_object = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes };
- route = route_object:inbound(self.caller, self.caller.destination_number);
- local inbound_caller_id_number = route_object:inbound_cid_number(self.caller, self.caller.gateway_name, 'gateway');
- route_object.expandable.caller_id_number = inbound_caller_id_number;
- local inbound_caller_id_name = route_object:inbound_cid_name(self.caller, self.caller.gateway_name, 'gateway');
- self.log:info('INBOUND_CALLER_ID_REWRITE - number: ', inbound_caller_id_number, ', name: ', inbound_caller_id_name);
- self.caller.caller_id_number = inbound_caller_id_number or self.caller.caller_id_number;
- self.caller.caller_id_name = inbound_caller_id_name or self.caller.caller_id_name;
- self.caller.caller_phone_numbers[1] = self.caller.caller_id_number;
+ route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('inbound', true);
+ if route then
+ local ignore_keys = {
+ id = true,
+ gateway = true,
+ ['type'] = true,
+ channel_variables = true,
+ };
+
+ for key, value in pairs(route) do
+ if not ignore_keys[key] then
+ self.caller[key] = value;
+ end
+ end
+
+ self.caller.caller_phone_numbers[1] = self.caller.caller_id_number;
+ else
+ self.log:notice('INBOUND - no route');
+ end
else
- route = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = self.routes }:prerouting(self.caller, self.caller.destination_number);
+ route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = self.caller, variables = self.caller }:route_run('prerouting', true);
+ if route then
+ local ignore_keys = {
+ id = true,
+ gateway = true,
+ ['type'] = true,
+ channel_variables = true,
+ };
+
+ for key, value in pairs(route) do
+ if not ignore_keys[key] then
+ self.caller[key] = value;
+ end
+ end
+ end
end
if route then
- destination = self:destination_new{ number = route.value }
+ if type(route.channel_variables) == 'table' then
+ for key, value in pairs(route.channel_variables) do
+ self.caller:set_variable(key, value);
+ end
+ end
+
+ destination = self:destination_new{ ['type'] = route.type, id = route.id, number = route.destination_number }
self.caller.destination_number = destination.number;
self.caller.destination = destination;
elseif not destination or destination.type == 'unknown' then
@@ -979,6 +1004,7 @@ function Dialplan.run(self, destination)
self.log:info('LOOP ', loop, ' NEW_DESTINATION_NUMBER - number: ', result.number );
destination = self:destination_new{ number = result.number }
self.caller.destination = destination;
+ self.caller.destination_number = destination.number;
end
end
diff --git a/misc/freeswitch/scripts/dialplan/fax.lua b/misc/freeswitch/scripts/dialplan/fax.lua
index 2a40620..aa29ff6 100644
--- a/misc/freeswitch/scripts/dialplan/fax.lua
+++ b/misc/freeswitch/scripts/dialplan/fax.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: fax class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua
index 9a89857..2ca51c8 100644
--- a/misc/freeswitch/scripts/dialplan/functions.lua
+++ b/misc/freeswitch/scripts/dialplan/functions.lua
@@ -51,10 +51,16 @@ function Functions.dialplan_function(self, caller, dialed_number)
result = self:user_auto_logout(caller, true);
elseif fid == "loaoff" then
result = self:user_auto_logout(caller, false);
+ elseif fid == "redial" then
+ result = self:redial(caller);
elseif fid == "dcliroff" then
result = self:dial_clir_off(caller, parameters[3]);
elseif fid == "dcliron" then
result = self:dial_clir_on(caller, parameters[3]);
+ elseif fid == "cliron" then
+ result = self:clir_on(caller);
+ elseif fid == "cliroff" then
+ result = self:clir_off(caller);
elseif fid == "clipon" then
result = self:clip_on(caller);
elseif fid == "clipoff" then
@@ -503,6 +509,30 @@ function Functions.user_auto_logout(self, caller, auto_logout)
caller:sleep(1000);
end
+function Functions.redial(self, caller)
+ -- Ensure a valid sip account
+ local caller_sip_account = self:ensure_caller_sip_account(caller);
+ if not caller_sip_account then
+ return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true }
+ end
+
+ local sql_query = 'SELECT `destination_number` \
+ FROM `call_histories` \
+ WHERE `entry_type` = "dialed" \
+ AND `call_historyable_type` = "SipAccount" \
+ AND `call_historyable_id` = ' .. caller_sip_account.record.id .. ' \
+ ORDER BY `start_stamp` DESC LIMIT 1';
+
+ local phone_number = self.database:query_return_value(sql_query);
+
+ common_str = require 'common.str';
+ if common_str.blank(phone_number) then
+ return { continue = false, code = 404, phrase = 'No phone number saved', no_cdr = true }
+ end
+
+ return { continue = true, number = phone_number }
+end
+
function Functions.dial_clir_off(self, caller, phone_number)
-- Ensure a valid sip account
local caller_sip_account = self:ensure_caller_sip_account(caller);
@@ -565,6 +595,48 @@ function Functions.callwaiting_off(self, caller)
return { continue = false, code = 200, phrase = 'OK', no_cdr = true }
end
+function Functions.clir_on(self, caller)
+ -- Find caller's SipAccount
+ local caller_sip_account = self:ensure_caller_sip_account(caller);
+ if not caller_sip_account then
+ return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true }
+ end
+
+ local sql_query = 'UPDATE `sip_accounts` SET `clir` = TRUE WHERE `id` = ' .. caller_sip_account.record.id;
+
+ if not self.database:query(sql_query) then
+ self.log:notice("CLIR could not be set");
+ return { continue = false, code = 500, phrase = 'CLIR could not be set', no_cdr = true }
+
+ end
+
+ caller:answer();
+ caller:send_display('CLIR on');
+ caller:sleep(1000);
+ return { continue = false, code = 200, phrase = 'OK', no_cdr = true }
+end
+
+function Functions.clir_off(self, caller)
+ -- Find caller's SipAccount
+ local caller_sip_account = self:ensure_caller_sip_account(caller);
+ if not caller_sip_account then
+ return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true }
+ end
+
+ local sql_query = 'UPDATE `sip_accounts` SET `clir` = FALSE WHERE `id` = ' .. caller_sip_account.record.id;
+
+ if not self.database:query(sql_query) then
+ self.log:notice("CLIR could not be set");
+ return { continue = false, code = 500, phrase = 'CLIR could not be set', no_cdr = true }
+
+ end
+
+ caller:answer();
+ caller:send_display('CLIR off');
+ caller:sleep(1000);
+ return { continue = false, code = 200, phrase = 'OK', no_cdr = true }
+end
+
function Functions.clip_on(self, caller)
-- Find caller's SipAccount
local caller_sip_account = self:ensure_caller_sip_account(caller);
@@ -586,6 +658,7 @@ function Functions.clip_on(self, caller)
return { continue = false, code = 200, phrase = 'OK', no_cdr = true }
end
+
function Functions.clip_off(self, caller)
-- Find caller's SipAccount
local caller_sip_account = self:ensure_caller_sip_account(caller);
@@ -607,7 +680,6 @@ function Functions.clip_off(self, caller)
return { continue = false, code = 200, phrase = 'OK', no_cdr = true }
end
-
function Functions.call_forwarding_off(self, caller, call_forwarding_service, delete)
local defaults = {log = self.log, database = self.database, domain = caller.domain}
diff --git a/misc/freeswitch/scripts/dialplan/geo_number.lua b/misc/freeswitch/scripts/dialplan/geo_number.lua
index 06bfd62..76cc01b 100644
--- a/misc/freeswitch/scripts/dialplan/geo_number.lua
+++ b/misc/freeswitch/scripts/dialplan/geo_number.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: geonumber class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua
index 87f86f1..2c73bf8 100644
--- a/misc/freeswitch/scripts/dialplan/hunt_group.lua
+++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: hunt group class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -98,21 +98,33 @@ function HuntGroup.run(self, dialplan_object, caller, destination)
self.log:info('HUNTGROUP ', self.record.id, ' - name: ', self.record.name, ', strategy: ', self.record.strategy,', members: ', #hunt_group_members);
+ local save_destination = caller.destination;
+
local destinations = {}
for index, hunt_group_member in ipairs(hunt_group_members) do
local destination = dialplan_object:destination_new{ number = hunt_group_member.number };
if destination.type == 'unknown' then
- require 'dialplan.route'
- local routes = dialplan.route.Route:new{ log = self.log, database = self.database, routing_table = dialplan_object.routes }:outbound(caller, destination.number);
- if routes and #routes > 0 then
- destination.callee_id_number = destination.number;
- destination.callee_id_name = nil;
- local route = routes[1];
- destination.gateway = route.endpoint;
- destination.type = route.class;
- destination.number = route.value;
- destination.caller_id_number = route.caller_id_number;
- destination.caller_id_name = route.caller_id_name;
+
+ caller.destination_number = destination.number;
+
+ require 'dialplan.router'
+ local route = dialplan.router.Router:new{ log = self.log, database = self.database, caller = caller, variables = caller }:route_run('outbound', true);
+
+ if route then
+ destination = dialplan_object:destination_new{ ['type'] = route.type, id = route.id, number = route.destination_number }
+
+ local ignore_keys = {
+ id = true,
+ ['type'] = true,
+ channel_variables = true,
+ };
+
+ for key, value in pairs(route) do
+ if not ignore_keys[key] then
+ destination[key] = value;
+ end
+ end
+
table.insert(destinations, destination);
end
else
@@ -120,6 +132,9 @@ function HuntGroup.run(self, dialplan_object, caller, destination)
end
end
+ caller.destination = save_destination;
+ caller.destination_number = save_destination.number;
+
local forwarding_destination = nil;
if caller.forwarding_service == 'assistant' and caller.auth_account then
forwarding_destination = dialplan_object:destination_new{ type = caller.auth_account.class, id = caller.auth_account.id, number = forwarding_number }
diff --git a/misc/freeswitch/scripts/dialplan/phone_book.lua b/misc/freeswitch/scripts/dialplan/phone_book.lua
index 089f115..6653789 100644
--- a/misc/freeswitch/scripts/dialplan/phone_book.lua
+++ b/misc/freeswitch/scripts/dialplan/phone_book.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: phone book class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/dialplan/presence.lua b/misc/freeswitch/scripts/dialplan/presence.lua
index 234b908..0f63ce9 100644
--- a/misc/freeswitch/scripts/dialplan/presence.lua
+++ b/misc/freeswitch/scripts/dialplan/presence.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: presence class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/dialplan/route.lua b/misc/freeswitch/scripts/dialplan/route.lua
deleted file mode 100644
index 2243cbe..0000000
--- a/misc/freeswitch/scripts/dialplan/route.lua
+++ /dev/null
@@ -1,265 +0,0 @@
--- Gemeinschaft 5 module: routing class
--- (c) AMOOMA GmbH 2012
---
-
-module(...,package.seeall)
-
-Route = {}
-
--- create route object
-function Route.new(self, arg)
- arg = arg or {}
- object = arg.object or {}
- setmetatable(object, self);
- self.__index = self;
- self.log = arg.log;
- self.database = arg.database;
- self.routing_table = arg.routing_table;
- self.expandable = arg.expandable or {};
- return object;
-end
-
--- find matching routes
-function Route.prerouting(self, caller, number)
- require 'common.routing_tables'
-
- for index, routing_entry in pairs(self.routing_table.prerouting) do
- local route = common.routing_tables.match_route(routing_entry, number);
- if route.error then
- self.log:error('PREROUTE - error: ', route.error);
- elseif route.value then
- self.log:info('ROUTE_PREROUTING - called number: ', number, ', value: ', route.value, ', pattern: ', route.pattern);
- return route;
- end
- end
-end
-
--- find matching routes
-function Route.outbound(self, caller, number)
- local routes = {};
- require 'common.routing_tables'
- require 'common.str'
-
- local ignore_arguments = {
- class=true,
- endpoint=true,
- pattern=true,
- value=true,
- group=true,
- phrase=true,
- }
-
- local clip_no_screening = common.str.try(caller, 'account.record.clip_no_screening');
- local caller_id_numbers = {}
- if not common.str.blank(clip_no_screening) then
- for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do
- table.insert(caller_id_numbers, number);
- end
- end
- for index, number in ipairs(caller.caller_phone_numbers) do
- table.insert(caller_id_numbers, number);
- end
- self.log:info('CALLER_ID_NUMBER - caller_id_numbers: ', table.concat(caller_id_numbers, ','));
-
- for index, routing_entry in pairs(self.routing_table.outbound) do
- local route = common.routing_tables.match_route(routing_entry, number);
- if route.error then
- self.log:error('ROUTE_OUTBOUND - error: ', route.error);
- elseif route.value then
- local valid_route = true;
-
- for argument, value in pairs(route) do
- if not ignore_arguments[argument] then
- local table_value = common.str.downcase(tostring(common.str.try(caller, argument)));
- value = common.str.downcase(tostring(value));
- if table_value:match(value) then
- self.log:info('ROUTE_OUTBOUND_POSITIVE - ', argument, '=', value, ' ~ ', table_value, ', pattern: ', route.pattern);
- else
- self.log:info('ROUTE_OUTBOUND_NEGATIVE - ', argument, '=', value, ' !~ ', table_value, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
- end
-
- if route.group then
- if common.str.try(caller.auth_account, 'owner.groups.' .. tostring(route.group)) then
- self.log:info('ROUTE_OUTBOUND_POSITIVE - group=', route.group, ', pattern: ', route.pattern);
- else
- self.log:info('ROUTE_OUTBOUND_NEGATIVE - group=', route.group, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
-
- if route.cidn then
- if caller.caller_id_number:match(route.cidn) then
- self.log:info('ROUTE_OUTBOUND_POSITIVE - cidn=', route.cidn, ' ~ ', caller.caller_id_number,', pattern: ', route.pattern);
- else
- self.log:info('ROUTE_OUTBOUND_NEGATIVE - cidn=', route.cidn, ' !~ ', caller.caller_id_number, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
-
- if valid_route then
- if route.class ~= 'hangup' then
- route.caller_id_number = self:outbound_cid_number(caller, caller_id_numbers, route.endpoint, route.class);
- self.expandable.caller_id_number = route.caller_id_number;
- route.caller_id_name = self:outbound_cid_name(caller, route.endpoint, route.class);
- end
- table.insert(routes, route);
- self.log:info('ROUTE_OUTBOUND ', #routes,' - ', route.class, '=', route.endpoint, ', value: ', route.value, ', caller_id_number: ', route.caller_id_number, ', caller_id_name: ', route.caller_id_name);
- end
- end
- end
-
- return routes;
-end
-
-
-function Route.inbound(self, caller, number)
- require 'common.routing_tables'
-
- local ignore_arguments = {
- class=true,
- endpoint=true,
- pattern=true,
- value=true,
- group=true,
- phrase=true,
- }
-
- for index, routing_entry in pairs(self.routing_table.inbound) do
- local route = common.routing_tables.match_route(routing_entry, number);
- if route.error then
- self.log:error('ROUTE_INBOUND - error: ', route.error);
- elseif route.value then
- local valid_route = true;
-
- for argument, value in pairs(route) do
- if not ignore_arguments[argument] then
- local table_value = common.str.downcase(tostring(common.str.try(caller, argument)));
- value = common.str.downcase(tostring(value));
- if table_value:match(value) then
- self.log:info('ROUTE_INBOUND_POSITIVE - ', argument, '=', value, ' ~ ', table_value, ', pattern: ', route.pattern);
- else
- self.log:info('ROUTE_INBOUND_NEGATIVE - ', argument, '=', value, ' !~ ', table_value, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
- end
-
- if route.class and route.endpoint then
- if route.class == 'gateway' and caller.gateway_name:match(route.endpoint) then
- self.log:info('ROUTE_INBOUND_POSITIVE - ', route.class, '=', route.endpoint, ' ~ ', caller.gateway_name, ', pattern: ', route.pattern);
- else
- self.log:info('ROUTE_INBOUND_NEGATIVE - ', route.class, '=', route.endpoint, ' !~ ', caller.gateway_name, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
-
- if valid_route then
- self.log:info('ROUTE_INBOUND - called number: ', number, ', value: ', route.value, ', pattern: ', route.pattern);
- return route;
- end
- end
- end
-end
-
--- find caller id
-function Route.caller_id(self, caller, cid_entry, search_str, endpoint, class)
- local ignore_arguments = {
- class=true,
- endpoint=true,
- pattern=true,
- value=true,
- group=true,
- phrase=true,
- }
-
- local route = common.routing_tables.match_route(cid_entry, search_str, self.expandable);
- if route.error then
- self.log:error('CALLER_ID - error: ', route.error);
- elseif route.value then
- local valid_route = true;
-
- for argument, value in pairs(route) do
- if not ignore_arguments[argument] then
- local table_value = common.str.downcase(tostring(common.str.try(caller, argument)));
- value = common.str.downcase(tostring(value));
- if table_value:match(value) then
- self.log:debug('CALLER_ID_POSITIVE - ', argument, '=', value, ' ~ ', table_value, ', pattern: ', route.pattern);
- else
- self.log:debug('CALLER_ID_NEGATIVE - ', argument, '=', value, ' !~ ', table_value, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
- end
-
- if route.group then
- if common.str.try(caller.auth_account, 'owner.groups.' .. tostring(route.group)) then
- self.log:debug('CALLER_ID_POSITIVE - group=', route.group, ', pattern: ', route.pattern);
- else
- self.log:debug('CALLER_ID_NEGATIVE - group=', route.group, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
-
- endpoint = tostring(endpoint);
- if route.class and route.endpoint then
- if route.class == 'gateway' and endpoint:match(route.endpoint) then
- self.log:debug('CALLER_ID_POSITIVE - ', route.class, '=', route.endpoint, ' ~ ', endpoint, ', pattern: ', route.pattern);
- else
- self.log:debug('CALLER_ID_NEGATIVE - ', route.class, '=', route.endpoint, ' !~ ', endpoint, ', pattern: ', route.pattern);
- valid_route = false;
- end
- end
-
- if valid_route then
- self.log:debug('CALLER_ID ', route.class, '=', route.endpoint, ', value: ', route.value);
- return route.value;
- end
- end
-
- return nil;
-end
-
--- find matching caller id number
-function Route.outbound_cid_number(self, caller, caller_id_numbers, endpoint, class)
- for route_index, cid_entry in pairs(self.routing_table.outbound_cid_number) do
- for index, number in ipairs(caller_id_numbers) do
- local route = self:caller_id(caller, cid_entry, number, endpoint, class);
- if route then
- return route;
- end
- end
- end
-end
-
--- find matching caller id name
-function Route.outbound_cid_name(self, caller, endpoint, class)
- for route_index, cid_entry in pairs(self.routing_table.outbound_cid_name) do
- local route = self:caller_id(caller, cid_entry, caller.caller_id_name, endpoint, class);
- if route then
- return route;
- end
- end
-end
-
--- find matching caller id number
-function Route.inbound_cid_number(self, caller, endpoint, class)
- for route_index, cid_entry in pairs(self.routing_table.inbound_cid_number) do
- local route = self:caller_id(caller, cid_entry, caller.caller_id_number, endpoint, class);
- if route then
- return route;
- end
- end
-end
-
--- find matching caller id name
-function Route.inbound_cid_name(self, caller, endpoint, class)
- for route_index, cid_entry in pairs(self.routing_table.inbound_cid_name) do
- local route = self:caller_id(caller, cid_entry, caller.caller_id_name, endpoint, class);
- if route then
- return route;
- end
- end
-end
diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua
new file mode 100644
index 0000000..7e64d7b
--- /dev/null
+++ b/misc/freeswitch/scripts/dialplan/router.lua
@@ -0,0 +1,187 @@
+-- Gemeinschaft 5 module: call router class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+Router = {}
+
+-- create route object
+function Router.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.class = 'router';
+ self.log = arg.log;
+ self.database = arg.database;
+ self.routes = arg.routes or {};
+ self.caller = arg.caller;
+ self.variables = arg.variables or {};
+ return object;
+end
+
+
+function Router.read_table(self, table_name)
+ local routing_table = {};
+
+ local sql_query = 'SELECT * \
+ FROM `call_routes` `a` \
+ JOIN `route_elements` `b` ON `a`.`id` = `b`.`call_route_id`\
+ WHERE `a`.`routing_table` = "' .. table_name .. '" \
+ ORDER BY `a`.`position`, `b`.`position`';
+
+ local last_id = 0;
+ self.database:query(sql_query, function(route)
+ if last_id ~= tonumber(route.call_route_id) then
+ last_id = tonumber(route.call_route_id);
+ table.insert(routing_table, {id = route.call_route_id, name = route.name, endpoint_type = route.endpoint_type , endpoint_id = route.endpoint_id, elements = {} });
+ end
+
+ table.insert(routing_table[#routing_table].elements, {
+ var_in = route.var_in,
+ var_out = route.var_out,
+ pattern = route.pattern,
+ replacement = route.replacement,
+ action = route.action,
+ mandatory = common.str.to_b(route.mandatory),
+ });
+ end);
+
+ return routing_table;
+end
+
+
+function Router.expand_variables(self, line, variables)
+ return (line:gsub('{([%a%d%._]+)}', function(captured)
+ return common.str.try(variables, captured) or '';
+ end))
+end
+
+
+function Router.element_match(self, pattern, search_string, replacement)
+ local success, result = pcall(string.find, search_string, pattern);
+
+ if not success then
+ self.log:error('ELEMENT_MATCH - table error - pattern: ', pattern, ', search_string: ', search_string);
+ elseif result then
+ return true, search_string:gsub(pattern, self:expand_variables(replacement, self.variables));
+ end
+
+ return false;
+end
+
+
+function Router.element_match_group(self, pattern, groups, replacement, use_key)
+ if type(groups) ~= 'table' then
+ return false;
+ end
+
+ for key, value in pairs(groups) do
+ if use_key then
+ value = key;
+ end
+ result, replaced_value = self:element_match(pattern, tostring(value), replacement);
+ if result then
+ return true, replaced_value;
+ end
+ end
+end
+
+
+function Router.route_match(self, route)
+ local destination = {
+ gateway = 'gateway' .. route.endpoint_id,
+ ['type'] = route.endpoint_type,
+ id = route.endpoint_id,
+ channel_variables = {}
+ };
+
+ local route_matches = false;
+
+ for index=1, #route.elements do
+ local result = false;
+ local replacement = nil;
+
+ local element = route.elements[index];
+
+ if element.action ~= 'none' then
+ if common.str.blank(element.var_in) or common.str.blank(element.pattern) and element.action == 'set' then
+ result = true;
+ replacement = self:expand_variables(element.replacement, self.variables);
+ else
+ local command, variable_name = common.str.partition(element.var_in, ':');
+
+ if not command or not variable_name or command == 'var' then
+ local search_string = tostring(common.str.try(self.caller, element.var_in))
+ result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement));
+ elseif command == 'key' or command == 'val' then
+ local groups = common.str.try(self.caller, variable_name);
+ result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key');
+ elseif command == 'chv' then
+ local search_string = self.caller:to_s(variable_name);
+ result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement));
+ elseif command == 'hdr' then
+ local search_string = self.caller:to_s('sip_h_' .. variable_name);
+ result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement));
+ end
+ end
+
+ if element.action == 'not_match' then
+ result = not result;
+ end
+
+ if not result then
+ if element.mandatory then
+ return false;
+ end
+ else
+ if not common.str.blank(element.var_out) then
+ local command, variable_name = common.str.partition(element.var_out, ':');
+ if not command or not variable_name or command == 'var' then
+ destination[element.var_out] = replacement;
+ elseif command == 'chv' then
+ destination.channel_variables[variable_name] = replacement;
+ elseif command == 'hdr' then
+ destination.channel_variables['sip_h_' .. variable_name] = replacement;
+ end
+ end
+
+ if element.action == 'match' or element.action == 'not_match' then
+ route_matches = true;
+ end
+ end
+ end
+ end
+
+ if route_matches then
+ return destination;
+ end;
+
+ return nil;
+end
+
+
+function Router.route_run(self, table_name, find_first)
+ local routing_table = self:read_table(table_name);
+ local routes = {};
+
+ if type(routing_table) == 'table' then
+ for index=1, #routing_table do
+ local route = self:route_match(routing_table[index]);
+ if route then
+ table.insert(routes, route);
+ self.log:info('ROUTE ', #routes,' - ', table_name,'=', routing_table[index].id, '/', routing_table[index].name, ', destination: ', route.type, '=', route.id, ', destination_number: ', route.destination_number);
+ if find_first then
+ return route;
+ end
+ else
+ self.log:debug('ROUTE_NO_MATCH - ', table_name, '=', routing_table[index].id, '/', routing_table[index].name);
+ end
+ end
+ end
+
+ if not find_first then
+ return routes;
+ end
+end
diff --git a/misc/freeswitch/scripts/dialplan/session.lua b/misc/freeswitch/scripts/dialplan/session.lua
index 7174b24..7de85ca 100644
--- a/misc/freeswitch/scripts/dialplan/session.lua
+++ b/misc/freeswitch/scripts/dialplan/session.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: caller session class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -43,9 +43,13 @@ function Session.init_channel_variables(self)
self.from_gateway = true;
end
+ self.dialed_sip_user = self:to_s('dialed_user');
+ self.dialed_domain = self:to_s('dialed_domain');
+
self.account_uuid = self:to_s('gs_account_uuid');
self.account_type = self:to_s('gs_account_type');
self.sip_contact_host = self:to_s('sip_contact_host');
+ self.sip_network_ip = self:to_s('sip_network_ip');
self.clir = self:to_b('gs_clir');
self.call_timeout = self:to_i('gs_call_timeout');
self.auth_account_type = self:to_s('gs_auth_account_type');
diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua
index 57f92c6..3f56753 100644
--- a/misc/freeswitch/scripts/dialplan/sip_call.lua
+++ b/misc/freeswitch/scripts/dialplan/sip_call.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: sip call class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall);
@@ -79,6 +79,8 @@ function SipCall.fork(self, destinations, arg )
local dial_strings = {}
require 'common.sip_account'
+ require 'common.str'
+
local sip_account_class = common.sip_account.SipAccount:new{ log = self.log, database = self.database };
local call_result = { code = 404, phrase = 'No destination' };
@@ -87,7 +89,12 @@ function SipCall.fork(self, destinations, arg )
for index, destination in ipairs(destinations) do
local origination_variables = { 'gs_fork_index=' .. index }
- self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.gateway or destination.uuid, '@', destination.node_id, ', number: ', destination.number);
+ self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.gateway or destination.uuid, '@', destination.node_id, ', number: ', destination.number, ', caller_id: "', destination.caller_id_name, '" <', destination.caller_id_number, '>');
+
+ if not common.str.to_b(arg.update_callee_display) then
+ table.insert(origination_variables, 'ignore_display_updates=true');
+ end
+
if not destination.node_local or destination.type == 'node' then
require 'common.node'
local node = nil;
@@ -128,7 +135,12 @@ function SipCall.fork(self, destinations, arg )
if destination.caller_id_name then
table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'");
end
- table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. destination.gateway .. '/' .. destination.number);
+ if destination.channel_variables then
+ for key, value in pairs(destination.channel_variables) do
+ table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'");
+ end
+ end
+ table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. tostring(destination.gateway) .. '/' .. tostring(destination.number));
elseif destination.type == 'dial' then
if destination.caller_id_number then
table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'");
diff --git a/misc/freeswitch/scripts/dialplan/tenant.lua b/misc/freeswitch/scripts/dialplan/tenant.lua
index 8d6436c..904609e 100644
--- a/misc/freeswitch/scripts/dialplan/tenant.lua
+++ b/misc/freeswitch/scripts/dialplan/tenant.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: user class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/dialplan/user.lua b/misc/freeswitch/scripts/dialplan/user.lua
index 3b483c8..b536600 100644
--- a/misc/freeswitch/scripts/dialplan/user.lua
+++ b/misc/freeswitch/scripts/dialplan/user.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: user class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -62,7 +62,7 @@ function User.list_groups(self, id)
local groups = {};
self.database:query(sql_query, function(entry)
- groups[common.str.downcase(entry.name)] = true;
+ table.insert(groups, common.str.downcase(entry.name));
end);
return groups;
diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua
index b9dab79..5d79ba3 100644
--- a/misc/freeswitch/scripts/dialplan/voicemail.lua
+++ b/misc/freeswitch/scripts/dialplan/voicemail.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: voicemail class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -128,7 +128,7 @@ end
function Voicemail.send_notify(self, caller)
self.log:debug('VOICEMAIL_NOTIFY - account: ' .. self.record.auth_name .. ", id: " .. tostring(caller.uuid));
- local file = io.popen("/opt/GS5/script/voicemail_new.sh '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1");
+ local file = io.popen("/opt/GS5/script/voicemail_new '" .. tostring(self.record.auth_name) .. "' '" .. tostring(caller.uuid) .. "' 2>&1");
self.log:debug('VOICEMAIL_NOTIFY - result: ' .. tostring(file:read("*a")));
file:close();
diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua
index ee4a88f..7caff57 100644
--- a/misc/freeswitch/scripts/dialplan_default.lua
+++ b/misc/freeswitch/scripts/dialplan_default.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 default dialplan
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
@@ -23,33 +23,50 @@ log = common.log.Log:new{ prefix = '### [' .. session:get_uuid() .. '] ' };
require 'dialplan.session'
start_caller = dialplan.session.Session:new{ log = log, session = session };
+-- connect to database
+require 'common.database'
+local database = common.database.Database:new{ log = log }:connect();
+if not database:connected() then
+ log:critical('DIALPLAN_DEFAULT - database connect failed');
+ return;
+end
+
-- dialplan object
require 'dialplan.dialplan'
-start_dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = start_caller };
+local start_dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = start_caller, database = database };
start_dialplan:configuration_read();
start_caller.local_node_id = start_dialplan.node_id;
start_caller:init_channel_variables();
--- session:execute('info','notice');
-
-if not start_dialplan:check_auth() then
- log:debug('AUTHENTICATION_REQUIRED - domain: ', start_dialplan.domain);
- start_dialplan:hangup(407, start_dialplan.domain);
- return false;
+if start_dialplan.config.parameters.dump_variables then
+ start_caller:execute('info', 'notice');
end
--- connect to database
-require 'common.database'
-local database = common.database.Database:new{ log = log }:connect();
-if not database:connected() then
- log:critical('DIALPLAN_DEFAULT - database connect failed');
- return;
-end
+if start_caller.from_node and not start_dialplan:auth_node() then
+ log:debug('DIALPLAN_DEFAULT - node unauthorized - node_id: ', start_caller.node_id, ', domain: ', start_dialplan.domain);
+ start_dialplan:hangup(401, start_dialplan.domain);
+else
+ if not start_dialplan:auth_sip_account() then
+ local gateway = start_dialplan:auth_gateway()
-start_dialplan.database = database;
+ if gateway then
+ start_caller.gateway_name = gateway.name;
+ start_caller.gateway_id = gateway.id;
+ start_caller.from_gateway = true;
+ start_caller.gateway = gateway;
+ else
+ log:debug('AUTHENTICATION_REQUIRED_SIP_ACCOUNT - contact host: ' , start_caller.sip_contact_host, ', ip: ', start_caller.sip_network_ip, ', domain: ', start_dialplan.domain);
+ start_dialplan:hangup(407, start_dialplan.domain);
+ if database then
+ database:release();
+ end
+ return;
+ end
+ end
+end
-if start_caller.from_node and not start_dialplan:check_auth_node() then
+if start_caller.from_node then
log:debug('AUTHENTICATION_REQUIRED_NODE - node_id: ', start_caller.node_id, ', domain: ', start_dialplan.domain);
start_dialplan:hangup(407, start_dialplan.domain);
else
diff --git a/misc/freeswitch/scripts/event/call_history_save.lua b/misc/freeswitch/scripts/event/call_history_save.lua
index 057ca16..ba7a8f6 100644
--- a/misc/freeswitch/scripts/event/call_history_save.lua
+++ b/misc/freeswitch/scripts/event/call_history_save.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: call_history event handler class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/event/cdr_save.lua b/misc/freeswitch/scripts/event/cdr_save.lua
index ed53aa3..e7ac64a 100644
--- a/misc/freeswitch/scripts/event/cdr_save.lua
+++ b/misc/freeswitch/scripts/event/cdr_save.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: cdr event handler class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/event/event.lua b/misc/freeswitch/scripts/event/event.lua
index 8e67bc9..08d8bfe 100644
--- a/misc/freeswitch/scripts/event/event.lua
+++ b/misc/freeswitch/scripts/event/event.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: event manager class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -28,10 +28,8 @@ end
function EventManager.load_event_modules(self)
- local CONFIG_FILE_NAME = '/opt/freeswitch/scripts/ini/events.ini';
-
- require 'common.configuration_file'
- self.config = common.configuration_file.get(CONFIG_FILE_NAME);
+ require 'common.configuration_table'
+ self.config = common.configuration_table.get(self.database, 'events');
return self.config.modules;
end
@@ -40,7 +38,7 @@ end
function EventManager.load_event_handlers(self, event_modules)
event_handlers = {}
- for index, event_module_name in ipairs(event_modules) do
+ for event_module_name, index in pairs(event_modules) do
event_module = require('event.' .. event_module_name);
if event_module then
self.log:info('[event] EVENT_MANAGER - loading handler module: ', event_module_name);
diff --git a/misc/freeswitch/scripts/event/perimeter.lua b/misc/freeswitch/scripts/event/perimeter.lua
index 3babba6..5bbb032 100644
--- a/misc/freeswitch/scripts/event/perimeter.lua
+++ b/misc/freeswitch/scripts/event/perimeter.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: cdr event handler class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
@@ -40,7 +40,8 @@ end
function Perimeter.init(self)
- local config = common.configuration_file.get('/opt/freeswitch/scripts/ini/perimeter.ini');
+ require 'common.configuration_table';
+ local config = common.configuration_table.get(self.database, 'perimeter');
if config and config.general then
self.malicious_contact_count = tonumber(config.general.malicious_contact_count) or MALICIOUS_CONTACT_COUNT;
self.malicious_contact_time_span = tonumber(config.general.malicious_contact_time_span) or MALICIOUS_CONTACT_TIME_SPAN;
diff --git a/misc/freeswitch/scripts/event_manager.lua b/misc/freeswitch/scripts/event_manager.lua
index 0e3c0e0..4e78ccf 100644
--- a/misc/freeswitch/scripts/event_manager.lua
+++ b/misc/freeswitch/scripts/event_manager.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5.0 event handler
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
-- Set logger
@@ -17,10 +17,9 @@ if not database:connected() then
end
require "configuration.sip"
-local sip = configuration.sip.Sip:new{ log = log, database = database }
+local domains = configuration.sip.Sip:new{ log = log, database = database }:domains();
local domain = '127.0.0.1';
-local domains = sip:domains();
if domains[1] then
domain = domains[1]['host'];
else
diff --git a/misc/freeswitch/scripts/fax_daemon.lua b/misc/freeswitch/scripts/fax_daemon.lua
index cfe7c4e..6609fe6 100644
--- a/misc/freeswitch/scripts/fax_daemon.lua
+++ b/misc/freeswitch/scripts/fax_daemon.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5.0 fax daemon
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
local MAIN_LOOP_SLEEP_TIME = 30;
diff --git a/misc/freeswitch/scripts/ini/conferences.ini b/misc/freeswitch/scripts/ini/conferences.ini
deleted file mode 100644
index d8d0817..0000000
--- a/misc/freeswitch/scripts/ini/conferences.ini
+++ /dev/null
@@ -1,27 +0,0 @@
-; Gemeinschaft 5 conferences configuration file
-; (c) AMOOMA GmbH 2012
-;
-
-[parameters]
-caller-controls = speaker
-moderator-controls = moderator
-max-members = 100
-rate = 16000
-interval = 20
-energy-level = 300
-sound-prefix = /opt/freeswitch/sounds/en/us/callie
-muted-sound = conference/conf-muted.wav
-unmuted-sound = conference/conf-unmuted.wav
-alone-sound = conference/conf-alone.wav
-moh-sound = local_stream://moh
-enter-sound = tone_stream://%(200,0,500,600,700)
-exit-sound = tone_stream://%(500,0,300,200,100,50,25)
-kicked-sound = conference/conf-kicked.wav
-locked-sound = conference/conf-locked.wav
-is-locked-sound = conference/conf-is-locked.wav
-is-unlocked-sound = conference/conf-is-unlocked.wav
-pin-sound = conference/conf-pin.wav
-bad-pin-sound = conference/conf-bad-pin.wav
-caller-id-name = Conference
-caller-id-number =
-comfort-noise = true
diff --git a/misc/freeswitch/scripts/ini/database.ini b/misc/freeswitch/scripts/ini/database.ini
deleted file mode 100644
index 1652118..0000000
--- a/misc/freeswitch/scripts/ini/database.ini
+++ /dev/null
@@ -1,11 +0,0 @@
-; Gemeinschaft 5 database configuration
-; (c) AMOOMA GmbH 2012
-;
-
-driver = mysql
-
-[mysql]
-host = localhost
-database = gemeinschaft
-user = gemeinschaft
-password = gemeinschaft
diff --git a/misc/freeswitch/scripts/ini/dialplan.ini b/misc/freeswitch/scripts/ini/dialplan.ini
deleted file mode 100644
index aab8353..0000000
--- a/misc/freeswitch/scripts/ini/dialplan.ini
+++ /dev/null
@@ -1,14 +0,0 @@
-; Gemeinschaft 5 dialplan configuration file
-; (c) AMOOMA GmbH 2012
-;
-
-[parameters]
-node_id = 1
-phone_book_entry_image_url = http://192.168.0.150/uploads/phone_book_entry/image
-user_image_url = http://192.168.0.150/uploads/user/image
-ringtone_url = http://192.168.0.150
-ringback = %(2000,4000,440.0,480.0)
-tone_busy = %(500,500,480,620);loops=4
-
-phonebook_number_lookup = true
-geo_number_lookup = true \ No newline at end of file
diff --git a/misc/freeswitch/scripts/ini/events.ini b/misc/freeswitch/scripts/ini/events.ini
deleted file mode 100644
index e63eb73..0000000
--- a/misc/freeswitch/scripts/ini/events.ini
+++ /dev/null
@@ -1,8 +0,0 @@
-; Gemeinschaft 5 routing configuration file
-; (c) AMOOMA GmbH 2012
-;
-
-[modules]
-cdr_save
-call_history_save
-presence_update
diff --git a/misc/freeswitch/scripts/ini/gateways.ini.example b/misc/freeswitch/scripts/ini/gateways.ini.example
deleted file mode 100644
index b6ae018..0000000
--- a/misc/freeswitch/scripts/ini/gateways.ini.example
+++ /dev/null
@@ -1,23 +0,0 @@
-; Gemeinschaft 5 gateways configuration file
-; (c) AMOOMA GmbH 2012
-;
-
-[gateway1]
-profile = gemeinschaft
-name = gateway1
-username = gateway1
-realm = gemeinschaft
-password = freeswitch
-extension = default
-proxy = 192.168.0.1
-expire-seconds = 600
-register = true
-
-[gateway2]
-profile = gemeinschaft
-name = sipgate
-username = 1234567e0
-password = ABCdeF
-proxy = sipgate.com
-register = true
-extension = {sip_to_user}
diff --git a/misc/freeswitch/scripts/ini/perimeter.ini b/misc/freeswitch/scripts/ini/perimeter.ini
deleted file mode 100644
index ecbb032..0000000
--- a/misc/freeswitch/scripts/ini/perimeter.ini
+++ /dev/null
@@ -1,9 +0,0 @@
-; Gemeinschaft 5 perimeter defense configuration file
-; (c) AMOOMA GmbH 2012
-;
-
-[general]
-malicious_contact_count = 20
-malicious_contact_time_span = 2
-ban_futile = 5
-execute = sudo /usr/local/bin/ban_ip.sh {ip_address}
diff --git a/misc/freeswitch/scripts/ini/routes.ini b/misc/freeswitch/scripts/ini/routes.ini
deleted file mode 100644
index 1334e7b..0000000
--- a/misc/freeswitch/scripts/ini/routes.ini
+++ /dev/null
@@ -1,77 +0,0 @@
-; Gemeinschaft 5 routing configuration file
-; (c) AMOOMA GmbH 2012
-;
-
-[general]
-
-
-[prerouting]
-^%*0%*$ , f-li
-^%*0%*(%d+)#*$ , f-li-%1
-^%*0%*(%d+)%*(%d+)#*$ , f-li-%1-%2
-^#0#$ , f-lo
-^%*30#$ , f-clipon
-^#30#$ , f-clipoff
-^%*31#(%d+)$ , f-dclirof, f-%1
-^#31#(%d+)$ , f-dcliron-%1
-^%*43#$ , f-cwaon
-^#43#$ , f-cwaoff
-^#002#$ , f-cfoff
-^##002#$ , f-cfdel
-^%*21#$ , f-cfu
-^%*21%*(%d+)#$ , f-cfu-%1
-^%*%*21%*(%d+)#$ , f-cfu-%1
-^#21#$ , f-cfuoff
-^##21#$ , f-cfudel
-^%*61#$ , f-cfn
-^%*61%*(%d+)#$ , f-cfn-%1
-^%*%*61%*(%d+)#$ , f-cfn-%1
-^%*61%*(%d+)%*(%d+)#$ , f-cfn-%1-%2
-^%*%*61%*(%d+)%*(%d+)#$ , f-cfn-%1-%2
-^#61#$ , f-cfnoff
-^##61#$ , f-cfndel
-^%*62#$ , f-cfo
-^%*62%*(%d+)#$ , f-cfo-%1
-^%*%*62%*(%d+)#$ , f-cfo-%1
-^#62#$ , f-cfooff
-^##62#$ , f-cfodel
-^%*67#$ , f-cfb
-^%*67%*(%d+)#$ , f-cfb-%1
-^%*%*67%*(%d+)#$ , f-cfb-%1
-^#67#$ , f-cfboff
-^##67#$ , f-cfbdel
-^%*98$ , f-vmcheck
-^%*98#$ , f-vmcheck
-^%*98%*(%d+)#$ , f-vmcheck-%1
-^%*1337%*1%*1#$ , f-loaon
-^%*1337%*1%*0#$ , f-loaoff
-
-^00(%d+)$ , +%1
-^0(%d+)$ , +49%1
-
-
-[outbound]
-^%+(%d+)$ , class=gateway, endpoint=gateway1, group=users, %1
-^([1-9]%d+)$ , class=gateway, endpoint=gateway1, group=users, %1
-
-
-[failover]
-UNALLOCATED_NUMBER = true
-NORMAL_TEMPORARY_FAILURE = true
-
-
-[outbound_cid_number]
-
-
-[outbound_cid_name]
-
-
-[inbound]
-^00(%d+)$ , +%1
-^0(%d+)$ , +49%1
-
-[inbound_cid_number]
-^00(%d+)$ , +%1
-^0(%d+)$ , +49%1
-
-[inbound_cid_name]
diff --git a/misc/freeswitch/scripts/ini/sip_accounts.ini b/misc/freeswitch/scripts/ini/sip_accounts.ini
deleted file mode 100644
index 73a5fae..0000000
--- a/misc/freeswitch/scripts/ini/sip_accounts.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-; Gemeinschaft 5 sip accounts default parameters
-; (c) AMOOMA GmbH 2012
-;
-
-[parameters]
-vm-enabled = true
-vm-email-all-messages = false
-vm-attach-file = false
-vm-mailto =
-
diff --git a/misc/freeswitch/scripts/ini/sofia.ini b/misc/freeswitch/scripts/ini/sofia.ini
deleted file mode 100644
index 5c99dbd..0000000
--- a/misc/freeswitch/scripts/ini/sofia.ini
+++ /dev/null
@@ -1,55 +0,0 @@
-; Gemeinschaft 5 sofia configuration file
-; (c) AMOOMA GmbH 2012
-;
-
-[profiles]
-gemeinschaft
-
-[parameters]
-log-level = 3
-debug-presence = 0
-
-[profile:gemeinschaft]
-user-agent-string = Gemeinschaft5
-debug = 0
-sip-trace = no
-log-auth-failures = false
-context = default
-rfc2833-pt = 101
-pass-rfc2833 = true
-sip-port = 5060
-dialplan = XML
-dtmf-duration = 2000
-rtp-timer-name = soft
-inbound-codec-prefs = PCMA,G7221@32000h,G7221@16000h,G722,PCMU,GSM
-outbound-codec-prefs = PCMA,G7221@32000h,G7221@16000h,G722,PCMU,GSM
-inbound-codec-negotiation = greedy
-ext-rtp-ip = auto-nat
-ext-sip-ip = auto-nat
-hold-music = local_stream://moh
-manage-presence = true
-tls = false
-tls-sip-port = 5061
-tls-cert-dir = /opt/freeswitch/conf/ssl
-accept-blind-reg = false
-accept-blind-auth = false
-nonce-ttl = 60
-disable-transcoding = false
-manual-redirect = true
-disable-transfer = false
-disable-register = false
-auth-calls = false
-inbound-reg-force-matching-username = true
-auth-all-packets = false
-rtp-timeout-sec = 300
-rtp-hold-timeout-sec = 1800
-force-subscription-expires = 3600
-sip-force-expires = 3000
-sip-expires-max-deviation = 600;
-challenge-realm = auto_from
-rtp-rewrite-timestamps = true
-inbound-use-callid-as-uuid = false
-outbound-use-callid-as-uuid = false
-context = default
-record-template = ${user_name}_${uuid}_${strftime(%Y-%m-%d-%H-%M-%S)}.wav
-odbc-dsn = gemeinschaft:gemeinschaft:gemeinschaft
diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua
index bc2aa3d..856398b 100644
--- a/misc/freeswitch/scripts/phones/phone.lua
+++ b/misc/freeswitch/scripts/phones/phone.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: phone class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/phones/siemens.lua b/misc/freeswitch/scripts/phones/siemens.lua
index 71bb40a..ad2447a 100644
--- a/misc/freeswitch/scripts/phones/siemens.lua
+++ b/misc/freeswitch/scripts/phones/siemens.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: general siemens model class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/phones/snom.lua b/misc/freeswitch/scripts/phones/snom.lua
index 80d1fce..096ccb7 100644
--- a/misc/freeswitch/scripts/phones/snom.lua
+++ b/misc/freeswitch/scripts/phones/snom.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5 module: general snom model class
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua
index 321a5b1..11cd1d7 100644
--- a/misc/freeswitch/scripts/send_fax.lua
+++ b/misc/freeswitch/scripts/send_fax.lua
@@ -1,5 +1,5 @@
-- Gemeinschaft 5.0
--- (c) AMOOMA GmbH 2012
+-- (c) AMOOMA GmbH 2012-2013
--
local FAX_FILE_PATH = "/opt/GS5/public/uploads/fax_document/tiff/";
@@ -80,36 +80,34 @@ local session = nil
if phone_number then
session = freeswitch.Session("[" .. table.concat(origination_variables, ",") .. "]loopback/" .. destination_number .. "/default");
else
- local owner_class = common.str.downcase(fax_account.record.fax_accountable_type);
-
- local caller = {}
- caller.caller_phone_numbers = phone_number_class:list_by_owner(fax_account.record.id, 'FaxAccount');
- caller.account = fax_account;
- caller.auth_account = fax_account;
- caller.caller_id_name = fax_account.record.station_id;
-
- if owner_class == 'user' then
- require 'dialplan.user'
- caller.auth_account.owner = dialplan.user.User:new{ log = log, database = database }:find_by_id(fax_account.record.fax_accountable_id);
- if caller.auth_account.owner then
- caller.auth_account.owner.groups = caller.auth_account.owner:list_groups();
- end
- elseif owner_class == 'tenant' then
- require 'dialplan.tenant'
- caller.auth_account.owner = dialplan.tenant.Tenant:new{ log = log, database = database }:find_by_id(fax_account.record.fax_accountable_id);
- end
+ local caller = {
+ destination_number = destination_number,
+ caller_id_name = fax_account.record.station_id,
+ account_type = 'faxaccount',
+ account_uuid = fax_account.uuid,
+ auth_account_type = 'faxaccount',
+ auth_account_uuid = fax_account.uuid,
+ }
- require 'common.configuration_file'
- local routing_table = common.configuration_file.get('/opt/freeswitch/scripts/ini/routes.ini');
- require 'dialplan.route'
- local routes = dialplan.route.Route:new{ log = log, database = database, routing_table = routing_table }:outbound(caller, destination_number);
+ require 'dialplan.dialplan'
+ local dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = caller, database = database };
+ local result = dialplan:retrieve_caller_data();
+
+ local dialplan_router = require('dialplan.router');
+ local routes = dialplan_router.Router:new{ log = log, database = database, caller = caller, variables = caller }:route_run('outbound');
+
+ if not routes or #routes == 0 then
+ log:notice('SWITCH - no route - number: ', destination_number);
+ return { continue = false, code = 404, phrase = 'No route' }
+ end
for index, route in ipairs(routes) do
- log:info('FAX_SEND - ', route.class, '=', route.endpoint, ', number: ', route.value);
- if route.class == 'gateway' then
+ log:info('FAX_SEND - ', route.type, '=', route.id, '/', route.gateway,', number: ', route.destination_number);
+ if route.type == 'gateway' then
table.insert(origination_variables, "origination_caller_id_number='" .. (route.caller_id_number or caller.caller_phone_numbers[1]) .. "'");
table.insert(origination_variables, "origination_caller_id_name='" .. (route.caller_id_name or fax_account.record.station_id) .. "'");
- session = freeswitch.Session('[' .. table.concat(origination_variables, ',') .. ']sofia/gateway/' .. route.endpoint .. '/' .. route.value);
+ session = freeswitch.Session('[' .. table.concat(origination_variables, ',') .. ']sofia/gateway/' .. route.gateway .. '/' .. route.destination_number);
+ log:notice('SESSION: ', session);
break;
end
end