From bcce809c6e628fb7c067437e98a5195c5e228532 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 5 Feb 2013 13:58:58 +0100 Subject: show dialplan variables --- app/controllers/call_routes_controller.rb | 66 ++++++++++++++++++++++++++ app/views/call_routes/show_variables.html.haml | 13 +++++ 2 files changed, 79 insertions(+) create mode 100644 app/views/call_routes/show_variables.html.haml (limited to 'app') diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 3977132..60104eb 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -51,7 +51,13 @@ class CallRoutesController < ApplicationController def update @call_route = CallRoute.find(params[:id]) spread_breadcrumbs + + logger.error "ENDPOINT TYPE: #{params[:call_route][:endpoint_type]}" + logger.error "ENDPOINT ID: #{params[:call_route][:endpoint_id]}" + logger.error "ENDPOINT STR: #{params[:call_route][:endpoint_str]}" + if @call_route.update_attributes(call_route_parameter_params) + logger.error "CALL_ROUTE: #{@call_route.inspect}" redirect_to @call_route, :notice => t('call_routes.controller.successfuly_updated') else render :edit @@ -72,6 +78,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 +104,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/, '
').html_safe -- cgit v1.2.3 From c7379b1b30043b5526aa3a5dc7f0111174a7f915 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 5 Feb 2013 14:05:40 +0100 Subject: loging removed --- app/controllers/call_routes_controller.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'app') diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 60104eb..2dcd648 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -52,12 +52,7 @@ class CallRoutesController < ApplicationController @call_route = CallRoute.find(params[:id]) spread_breadcrumbs - logger.error "ENDPOINT TYPE: #{params[:call_route][:endpoint_type]}" - logger.error "ENDPOINT ID: #{params[:call_route][:endpoint_id]}" - logger.error "ENDPOINT STR: #{params[:call_route][:endpoint_str]}" - if @call_route.update_attributes(call_route_parameter_params) - logger.error "CALL_ROUTE: #{@call_route.inspect}" redirect_to @call_route, :notice => t('call_routes.controller.successfuly_updated') else render :edit -- cgit v1.2.3