summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-05 15:12:20 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-05 15:12:20 +0100
commit3005e0ecb346db7b3d85d610691dea14be21f5f6 (patch)
tree2f19b96e4d70cfa1b3be703b6dd9025ffd991c2c
parent75b36967fed9db8268391ac10b02f5c0870c32ca (diff)
parente22d3f5cb2791b70a9fcfe6befdeca233772688d (diff)
Merge branch 'develop' of github.com:amooma/GS5 into develop
-rw-r--r--app/controllers/call_routes_controller.rb61
-rw-r--r--app/views/call_routes/show_variables.html.haml13
-rw-r--r--config/routes.rb5
-rw-r--r--misc/freeswitch/scripts/event/dump_variables.lua52
-rw-r--r--misc/freeswitch/scripts/event/event.lua6
-rw-r--r--misc/freeswitch/scripts/event_manager.lua4
6 files changed, 137 insertions, 4 deletions
diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb
index 3977132..2dcd648 100644
--- a/app/controllers/call_routes_controller.rb
+++ b/app/controllers/call_routes_controller.rb
@@ -51,6 +51,7 @@ class CallRoutesController < ApplicationController
def update
@call_route = CallRoute.find(params[:id])
spread_breadcrumbs
+
if @call_route.update_attributes(call_route_parameter_params)
redirect_to @call_route, :notice => t('call_routes.controller.successfuly_updated')
else
@@ -72,6 +73,20 @@ class CallRoutesController < ApplicationController
render nothing: true
end
+ def show_variables
+ @channel_variables = Hash.new()
+ file_name = '/var/log/freeswitch/variables'
+ if File.readable?(file_name)
+ File.readlines(file_name).each do |line|
+ key, delimeter, value = line.partition(': ')
+ key = to_channel_variable_name(key)
+ if !key.blank?
+ @channel_variables[key] = URI.unescape(value.gsub(/\n/, ''));
+ end
+ end
+ end
+ end
+
private
def call_route_parameter_params
params.require(:call_route).permit(:routing_table, :name, :endpoint_type, :endpoint_id, :position)
@@ -84,4 +99,50 @@ class CallRoutesController < ApplicationController
end
end
+ def to_channel_variable_name(name)
+ variables_map = {
+ 'Channel-State' => 'state',
+ 'Channel-State-Number' => 'state_number',
+ 'Channel-Name' => 'channel_name',
+ 'Unique-ID' => 'uuid',
+ 'Call-Direction' => 'direction',
+ 'Answer-State' => 'state',
+ 'Channel-Read-Codec-Name' => 'read_codec',
+ 'Channel-Read-Codec-Rate' => 'read_rate',
+ 'Channel-Write-Codec-Name' => 'write_codec',
+ 'Channel-Write-Codec-Rate' => 'write_rate',
+ 'Caller-Username' => 'username',
+ 'Caller-Dialplan' => 'dialplan',
+ 'Caller-Caller-ID-Name' => 'caller_id_name',
+ 'Caller-Caller-ID-Number' => 'caller_id_number',
+ 'Caller-ANI' => 'ani',
+ 'Caller-ANI-II' => 'aniii',
+ 'Caller-Network-Addr' => 'network_addr',
+ 'Caller-Destination-Number' => 'destination_number',
+ 'Caller-Unique-ID' => 'uuid',
+ 'Caller-Source' => 'source',
+ 'Caller-Context' => 'context',
+ 'Caller-RDNIS' => 'rdnis',
+ 'Caller-Channel-Name' => 'channel_name',
+ 'Caller-Profile-Index' => 'profile_index',
+ 'Caller-Channel-Created-Time' => 'created_time',
+ 'Caller-Channel-Answered-Time' => 'answered_time',
+ 'Caller-Channel-Hangup-Time' => 'hangup_time',
+ 'Caller-Channel-Transfer-Time' => 'transfer_time',
+ 'Caller-Screen-Bit' => 'screen_bit',
+ 'Caller-Privacy-Hide-Name' => 'privacy_hide_name',
+ 'Caller-Privacy-Hide-Number' => 'privacy_hide_number',
+ }
+
+ name = name.gsub(/[^a-zA-Z1-9_\-]/, '')
+
+ if variables_map[name]
+ return variables_map[name]
+ elsif name.match(/^variable_/)
+ return name.gsub(/^variable_/, '')
+ end
+
+ return nil
+ end
+
end
diff --git a/app/views/call_routes/show_variables.html.haml b/app/views/call_routes/show_variables.html.haml
new file mode 100644
index 0000000..4bec39d
--- /dev/null
+++ b/app/views/call_routes/show_variables.html.haml
@@ -0,0 +1,13 @@
+%h3= 'Channel Variables'
+
+%table.table.table-striped
+ %thead
+ %tr
+ %th= 'Variable'
+ %th= 'Value'
+
+ %tbody{ :id => "show_variables" }
+ - @channel_variables.each do |key, value|
+ %tr
+ %td= key
+ %td= value.gsub(/\n/, '<br/>').html_safe
diff --git a/config/routes.rb b/config/routes.rb
index 3c3928f..653b811 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -8,7 +8,10 @@ Gemeinschaft42c::Application.routes.draw do
end
resources :call_routes do
- collection { post :sort }
+ collection {
+ post :sort
+ get :show_variables
+ }
resources :route_elements
end
diff --git a/misc/freeswitch/scripts/event/dump_variables.lua b/misc/freeswitch/scripts/event/dump_variables.lua
new file mode 100644
index 0000000..96eb8f7
--- /dev/null
+++ b/misc/freeswitch/scripts/event/dump_variables.lua
@@ -0,0 +1,52 @@
+-- Gemeinschaft 5 module: dump_variables event handler class
+-- (c) AMOOMA GmbH 2012-2013
+--
+
+module(...,package.seeall)
+
+
+function handler_class()
+ return DumpVariables
+end
+
+
+DumpVariables = {}
+
+
+function DumpVariables.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.log = arg.log;
+ self.class = 'DumpVariables'
+ self.dump_file = arg.file or '/var/log/freeswitch/variables';
+
+ return object;
+end
+
+
+function DumpVariables.event_handlers(self)
+ return { CHANNEL_CREATE = { [true] = self.channel_data } }
+end
+
+
+function DumpVariables.channel_data(self, event)
+ local sequence = event:getHeader('Event-Sequence');
+ local direction = event:getHeader('Call-Direction');
+
+ if not direction or direction ~= 'inbound' then
+ return;
+ end
+
+ local file = io.open(self.dump_file, 'w');
+ if not file then
+ self.log:error('[', event.sequence, '] DUMP_VARIABLES - could not open file for writing: ', self.dump_file);
+ return;
+ end
+
+ self.log:debug('[', event.sequence, '] DUMP_VARIABLES - dumping channel data to: ', self.dump_file);
+
+ file:write(event:serialize(), '\n');
+ file:close();
+end
diff --git a/misc/freeswitch/scripts/event/event.lua b/misc/freeswitch/scripts/event/event.lua
index c98b534..652fc48 100644
--- a/misc/freeswitch/scripts/event/event.lua
+++ b/misc/freeswitch/scripts/event/event.lua
@@ -16,13 +16,16 @@ function EventManager.new(self, arg)
self.class = 'eventmanager'
self.database = arg.database;
self.domain = arg.domain;
+ self.consumer = arg.consumer;
return object;
end
function EventManager.register(self)
- self.consumer = freeswitch.EventConsumer('all');
+ if not self.consumer then
+ self.consumer = freeswitch.EventConsumer('all');
+ end
return (self.consumer ~= nil);
end
@@ -117,6 +120,5 @@ function EventManager.run(self)
end
end
- self.consumer = nil;
self.log:info('[event] EVENT_MANAGER_EXIT - action: ', freeswitch.getGlobalVariable('gs_event_manager'));
end
diff --git a/misc/freeswitch/scripts/event_manager.lua b/misc/freeswitch/scripts/event_manager.lua
index 3d558e5..3991f8f 100644
--- a/misc/freeswitch/scripts/event_manager.lua
+++ b/misc/freeswitch/scripts/event_manager.lua
@@ -26,13 +26,15 @@ else
log:error('[event] EVENT_MANAGER_LOADER - No SIP domains found!');
end
+local event_consumer = nil;
freeswitch.setGlobalVariable('gs_event_manager', 'true');
while freeswitch.getGlobalVariable('gs_event_manager') ~= 'false' do
package.loaded['event.event'] = nil;
local manager_class = require('event.event');
- local event_manager = manager_class.EventManager:new{ log = log, database = database, domain = domain }
+ local event_manager = manager_class.EventManager:new{ log = log, database = database, domain = domain, consumer = event_consumer };
freeswitch.setGlobalVariable('gs_event_manager', 'true');
event_manager:run();
+ event_consumer = event_manager.consumer;
end
-- ensure database handle is released on exit