From f5cddb733550b16851a36b50f9b3f861c1f0de89 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 29 Jan 2013 11:06:46 +0100 Subject: profile --- app/models/gateway_setting.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/gateway_setting.rb b/app/models/gateway_setting.rb index e3eaadb..381dde5 100644 --- a/app/models/gateway_setting.rb +++ b/app/models/gateway_setting.rb @@ -10,6 +10,7 @@ class GatewaySetting < ActiveRecord::Base 'auth_source' => 'String', 'auth_pattern' => 'String', 'number_source' => 'String', + 'profile' => 'String', }, 'xmpp' => { 'server' => 'String', -- cgit v1.2.3 From e1e45b9d4859099ef314dda9101d1d59d4a91917 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 29 Jan 2013 11:07:57 +0100 Subject: profiles order --- misc/freeswitch/scripts/configuration.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 062cf5d..18f4ef2 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -134,8 +134,15 @@ function conf_sofia(database) require 'configuration.sip' local domains = configuration.sip.Sip:new{ log = log, database = database}:domains(); - sofia_profiles_xml = ''; + local sofia_profiles = {}; for profile_name, index in pairs(sofia_ini.profiles) do + if tonumber(index) and tonumber(index) > 0 then + sofia_profiles[index] = profile_name; + end + end + + local sofia_profiles_xml = ''; + for index, profile_name in ipairs(sofia_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 -- cgit v1.2.3 From bebf1d99a7a81ffd5cc3276acbf8b0317182a1af Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 29 Jan 2013 16:28:13 +0100 Subject: set variable function added --- misc/freeswitch/scripts/common/str.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index 793c191..72ff388 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -18,6 +18,23 @@ function try(array, arguments) return result; end + +function set(array, arguments, value) + local nop, arguments_count = arguments:gsub('%.', ''); + local structure = array; + arguments:gsub('([^%.]+)', function(entry) + if arguments_count <= 0 then + structure[entry] = value; + elseif type(structure[entry]) == 'table' then + structure = structure[entry]; + else + structure[entry] = {}; + structure = structure[entry]; + end + arguments_count = arguments_count - 1; + end); +end + -- to number function to_n(value) value = tostring(value):gsub('[^%d%.%+%-]', ''); -- cgit v1.2.3 From a9be92fdc62d55e6b6a8da80f0fe959ad90fa678 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 29 Jan 2013 16:28:50 +0100 Subject: use str function set --- misc/freeswitch/scripts/dialplan/router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index cdcb58b..68989fa 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -143,7 +143,7 @@ function Router.route_match(self, route) 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; + common.str.set(destination, element.var_out, replacement); elseif command == 'chv' then destination.channel_variables[variable_name] = replacement; elseif command == 'hdr' then -- cgit v1.2.3 From 75fb68c4d1eb647a268890c080da2dc3875c0e77 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 29 Jan 2013 16:44:47 +0100 Subject: Get rid of @current_user. The use of current_user is better. --- app/controllers/application_controller.rb | 12 ++++++------ app/controllers/call_forwards_controller.rb | 4 ++-- app/controllers/gui_functions_controller.rb | 2 +- app/controllers/softkeys_controller.rb | 2 +- app/controllers/tenants_controller.rb | 8 ++++---- app/views/phone_numbers/_form_core.html.haml | 4 ++-- test/unit/callthrough_test.rb | 12 ++++++------ 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e4165f3..2d49890 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -106,7 +106,7 @@ class ApplicationController < ActionController::Base end rescue_from CanCan::AccessDenied do |exception| - if @current_user + if current_user redirect_to root_url, :alert => 'Access denied! Please ask your admin to grant you the necessary rights.' else if Tenant.count == 0 && User.count == 0 @@ -121,13 +121,13 @@ class ApplicationController < ActionController::Base private - def current_user - begin - @current_user ||= User.find(session[:user_id]) if session[:user_id] - rescue ActiveRecord::RecordNotFound + def current_user + if session[:user_id] && User.where(:id => session[:user_id]).any? + return User.where(:id => session[:user_id]).first + else session[:user_id] = nil + return nil end - @current_user end def go_to_setup_if_new_installation diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb index 001ed60..b1ced87 100644 --- a/app/controllers/call_forwards_controller.rb +++ b/app/controllers/call_forwards_controller.rb @@ -28,7 +28,7 @@ class CallForwardsController < ApplicationController @available_call_forward_cases = [] CallForwardCase.all.each do |available_call_forward_case| - if GuiFunction.display?("call_forward_case_#{available_call_forward_case.value}_field_in_call_forward_form", @current_user) + if GuiFunction.display?("call_forward_case_#{available_call_forward_case.value}_field_in_call_forward_form", current_user) @available_call_forward_cases << available_call_forward_case end end @@ -112,7 +112,7 @@ class CallForwardsController < ApplicationController voice_mail_destination, ] - if GuiFunction.display?('huntgroup_in_destination_field_in_call_forward_form', @current_user) + if GuiFunction.display?('huntgroup_in_destination_field_in_call_forward_form', current_user) HuntGroup.all.each do |hunt_group| hunt_group_destination = CallForwardingDestination.new() hunt_group_destination.id = "#{hunt_group.id}:HuntGroup" diff --git a/app/controllers/gui_functions_controller.rb b/app/controllers/gui_functions_controller.rb index 0cb7898..4b57322 100644 --- a/app/controllers/gui_functions_controller.rb +++ b/app/controllers/gui_functions_controller.rb @@ -58,7 +58,7 @@ class GuiFunctionsController < ApplicationController private def load_user_groups - @user_groups = Tenant.find(@current_user.current_tenant).user_groups.order(:position) + @user_groups = Tenant.find(current_user.current_tenant).user_groups.order(:position) end def spread_breadcrumbs diff --git a/app/controllers/softkeys_controller.rb b/app/controllers/softkeys_controller.rb index d2a2bb9..8f363cd 100644 --- a/app/controllers/softkeys_controller.rb +++ b/app/controllers/softkeys_controller.rb @@ -61,7 +61,7 @@ class SoftkeysController < ApplicationController @softkey_functions = [] SoftkeyFunction.accessible_by(current_ability, :read).each do |softkey_function| - if GuiFunction.display?("softkey_function_#{softkey_function.name.downcase}_field_in_softkey_form", @current_user) + if GuiFunction.display?("softkey_function_#{softkey_function.name.downcase}_field_in_softkey_form", current_user) @softkey_functions << softkey_function end end diff --git a/app/controllers/tenants_controller.rb b/app/controllers/tenants_controller.rb index 37874b2..f30246b 100644 --- a/app/controllers/tenants_controller.rb +++ b/app/controllers/tenants_controller.rb @@ -27,17 +27,17 @@ class TenantsController < ApplicationController if @tenant.save # Become a member of this tenant. # - @tenant.tenant_memberships.create(:user_id => @current_user.id) + @tenant.tenant_memberships.create(:user_id => current_user.id) # Groups # admin_group = @tenant.user_groups.create(:name => t('gemeinschaft_setups.initial_setup.admin_group_name')) - admin_group.users << @current_user + admin_group.users << current_user user_group = @tenant.user_groups.create(:name => t('gemeinschaft_setups.initial_setup.user_group_name')) - user_group.users << @current_user + user_group.users << current_user - @current_user.update_attributes!(:current_tenant_id => @tenant.id) + current_user.update_attributes!(:current_tenant_id => @tenant.id) # Generate the internal_extensions # diff --git a/app/views/phone_numbers/_form_core.html.haml b/app/views/phone_numbers/_form_core.html.haml index a1ce1f3..a0a69db 100644 --- a/app/views/phone_numbers/_form_core.html.haml +++ b/app/views/phone_numbers/_form_core.html.haml @@ -4,7 +4,7 @@ = f.input :name, :collection => ['Office', 'Home', 'Mobile', 'Fax'], :include_blank => false, :label => t('phone_numbers.form.name.label'), :hint => conditional_hint('phone_numbers.form.name.hint') = f.input :number, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :autofocus => true - else - - if @callthrough || @hunt_group_member || @access_authorization || @current_user.current_tenant.array_of_available_internal_extensions_and_dids.count == 0 || @current_user.current_tenant.array_of_available_internal_extensions_and_dids.count > 250 + - if @callthrough || @hunt_group_member || @access_authorization || current_user.current_tenant.array_of_available_internal_extensions_and_dids.count == 0 || current_user.current_tenant.array_of_available_internal_extensions_and_dids.count > 250 = f.input :number, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :autofocus => true - else - = f.input :number, :collection => @current_user.current_tenant.array_of_available_internal_extensions_and_dids, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :include_blank => false, :autofocus => true + = f.input :number, :collection => current_user.current_tenant.array_of_available_internal_extensions_and_dids, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :include_blank => false, :autofocus => true diff --git a/test/unit/callthrough_test.rb b/test/unit/callthrough_test.rb index 5764c0d..2e8cc56 100644 --- a/test/unit/callthrough_test.rb +++ b/test/unit/callthrough_test.rb @@ -12,7 +12,7 @@ class CallthroughTest < ActiveSupport::TestCase @gemeinschaft_setup.country = Country.first @gemeinschaft_setup.language = Language.first - @current_user = @gemeinschaft_setup.build_user( + current_user = @gemeinschaft_setup.build_user( :user_name => I18n.t('gemeinschaft_setups.initial_setup.admin_name'), :male => true, :email => 'admin@localhost', @@ -52,18 +52,18 @@ class CallthroughTest < ActiveSupport::TestCase @tenant.did_list = '02622-70648-x, 02622-706480' @tenant.save - @tenant.tenant_memberships.create(:user_id => @current_user.id) - @current_user.update_attributes!(:current_tenant_id => @tenant.id) + @tenant.tenant_memberships.create(:user_id => current_user.id) + current_user.update_attributes!(:current_tenant_id => @tenant.id) # The first user becomes a member of the 'admin' UserGroup # admin_group = @tenant.user_groups.create(:name => I18n.t('gemeinschaft_setups.initial_setup.admin_group_name')) - admin_group.users << @current_user + admin_group.users << current_user # User group # user_group = @tenant.user_groups.create(:name => I18n.t('gemeinschaft_setups.initial_setup.user_group_name')) - user_group.users << @current_user + user_group.users << current_user # Generate the internal_extensions # @@ -84,7 +84,7 @@ class CallthroughTest < ActiveSupport::TestCase # assert @gemeinschaft_setup.valid? assert @sip_domain.valid? - assert @current_user.valid? + assert current_user.valid? assert @tenant.valid? -- cgit v1.2.3 From bf3af8f8a444365f3040da2928837986409fa016 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 29 Jan 2013 18:43:06 +0100 Subject: Single Sign On via a ENV['USER_NAME'] mechanism. --- app/controllers/application_controller.rb | 18 ++++++++++++++---- db/migrate/20130129154700_add_sso_key.rb | 9 +++++++++ db/schema.rb | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20130129154700_add_sso_key.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2d49890..2aadf19 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -122,11 +122,21 @@ class ApplicationController < ActionController::Base private def current_user - if session[:user_id] && User.where(:id => session[:user_id]).any? - return User.where(:id => session[:user_id]).first + if session[:user_id] || GsParameter.get('SingleSignOnEnvUserNameKey').blank? + if session[:user_id] && User.where(:id => session[:user_id]).any? + return User.where(:id => session[:user_id]).first + else + session[:user_id] = nil + return nil + end else - session[:user_id] = nil - return nil + if User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).any? + auth_user = User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).first + session[:user_id] = auth_user.id + return auth_user + else + return nil + end end end diff --git a/db/migrate/20130129154700_add_sso_key.rb b/db/migrate/20130129154700_add_sso_key.rb new file mode 100644 index 0000000..2e47f39 --- /dev/null +++ b/db/migrate/20130129154700_add_sso_key.rb @@ -0,0 +1,9 @@ +class AddSsoKey < ActiveRecord::Migration + def up + GsParameter.create(:name => 'SingleSignOnEnvUserNameKey', :section => 'Generic', :value => '', :class_type => 'Nil', :description => 'When set to a string this env variable will be used to authenticate the user. e.g. REMOTE_USER') + end + + def down + GsParameter.create(:name => 'SingleSignOnEnvUserNameKey').destroy_all + end +end diff --git a/db/schema.rb b/db/schema.rb index 7bae5fd..e1bed77 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130128121800) do +ActiveRecord::Schema.define(:version => 20130129154700) do create_table "access_authorizations", :force => true do |t| t.string "access_authorizationable_type" -- cgit v1.2.3 From 5d84248cf177635a19f033f53abbca87ac5c87bc Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 29 Jan 2013 18:55:07 +0100 Subject: Fixed hidden-phone bug. --- .../shared/_index_view_edit_destroy_part.html.haml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/views/shared/_index_view_edit_destroy_part.html.haml b/app/views/shared/_index_view_edit_destroy_part.html.haml index 6bb1e7b..d396460 100644 --- a/app/views/shared/_index_view_edit_destroy_part.html.haml +++ b/app/views/shared/_index_view_edit_destroy_part.html.haml @@ -4,17 +4,20 @@ - if can? :show, child %a.btn.btn-small.btn-success{:href => method( :"#{parent.class.name.underscore}_#{child.class.name.underscore}_path" ).(parent, child) } %i.icon-info-sign.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.show") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.show") - if can? :edit, child %a.btn.btn-small.btn-warning{:href => method( :"edit_#{parent.class.name.underscore}_#{child.class.name.underscore}_path" ).(parent, child) } %i.icon-edit.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.edit") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.edit") - if can? :destroy, child %a.btn.btn-small.btn-danger{"data-confirm" => t("#{child.class.name.underscore.pluralize}.index.actions.confirm_destroy"), "data-method" => "delete", :href => method( :"#{parent.class.name.underscore}_#{child.class.name.underscore}_path" ).(parent, child), :rel => "nofollow"} %i.icon-remove.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") - elsif !(defined? child).nil? %td @@ -22,15 +25,18 @@ - if can? :show, child %a.btn.btn-small.btn-success{:href => method( :"#{child.class.name.underscore}_path" ).(child) } %i.icon-info-sign.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.show") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.show") - if can? :edit, child %a.btn.btn-small.btn-warning{:href => method( :"edit_#{child.class.name.underscore}_path" ).(child) } %i.icon-edit.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.edit") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.edit") - if can? :destroy, child %a.btn.btn-small.btn-danger{"data-confirm" => t("#{child.class.name.underscore.pluralize}.index.actions.confirm_destroy"), "data-method" => "delete", :href => method( :"#{child.class.name.underscore}_path" ).(child), :rel => "nofollow"} %i.icon-trash.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") \ No newline at end of file -- cgit v1.2.3 From 9928e509175ec6dbb9cd77aaeb06168c0de99d38 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 29 Jan 2013 20:59:06 +0100 Subject: destination.number vs. destination.destination_number --- misc/freeswitch/scripts/dialplan/router.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 68989fa..0813a37 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -159,6 +159,7 @@ function Router.route_match(self, route) end if route_matches then + destination.number = destination.number or destination.destination_number; return destination; end; -- cgit v1.2.3 From 98e26f3e5b7bb7e282a25a7f7ce9af1294a3d3ed Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 30 Jan 2013 10:00:46 +0100 Subject: mysql vs. odbc driver issue --- misc/freeswitch/scripts/dialplan/acd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/dialplan/acd.lua b/misc/freeswitch/scripts/dialplan/acd.lua index f4b298e..5ed8979 100644 --- a/misc/freeswitch/scripts/dialplan/acd.lua +++ b/misc/freeswitch/scripts/dialplan/acd.lua @@ -194,7 +194,7 @@ function AutomaticCallDistributor.agents_available(self, strategy) local accounts = {} self.database:query(sql_query, function(entry) - if not entry.callstate then + if common.str.blank(entry.callstate) then table.insert(accounts, entry); end end); -- cgit v1.2.3 From 0dc0b4d44907b51f859e125a00c8b5dbc39c1a6f Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 30 Jan 2013 10:01:35 +0100 Subject: disable passing of custom headers to gateway --- db/migrate/20130130185300_add_no_copy_headers.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 db/migrate/20130130185300_add_no_copy_headers.rb diff --git a/db/migrate/20130130185300_add_no_copy_headers.rb b/db/migrate/20130130185300_add_no_copy_headers.rb new file mode 100644 index 0000000..c2c5c90 --- /dev/null +++ b/db/migrate/20130130185300_add_no_copy_headers.rb @@ -0,0 +1,9 @@ +class AddNoCopyHeaders < ActiveRecord::Migration + def up + GsParameter.create(:entity => 'dialplan', :section => 'variables', :name => 'sip_copy_custom_headers', :value => 'false', :class_type => 'Boolean', :description => 'Controls passing SIP headers from one call leg to another.') + end + + def down + GsParameter.create(:entity => 'dialplan', :section => 'variables', :name => 'sip_copy_custom_headers').destroy_all + end +end -- cgit v1.2.3 From 8e1b469080890f61c1dd5d20e6f4b31838e6b486 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 30 Jan 2013 10:19:50 +0100 Subject: pass GS variables to node --- misc/freeswitch/scripts/dialplan/sip_call.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index d1557e9..a235fb3 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -95,17 +95,22 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, 'ignore_display_updates=true'); end - if not destination.node_local then + if not destination.node_local or destination.type == 'node' then require 'common.node' - local node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(destination.node_id); - if node then - table.insert(origination_variables, 'sip_h_X-GS_node_id=' .. self.caller.local_node_id); - table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. node.record.name .. '/' .. destination.number); + local node = nil; + + if not destination.node_local then + node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(destination.node_id); + else + node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(destination.id); end - elseif destination.type == 'node' then - local node = common.node.Node:new{ log = self.log, database = self.database }:find_by_id(destination.id); if node then table.insert(origination_variables, 'sip_h_X-GS_node_id=' .. self.caller.local_node_id); + table.insert(origination_variables, 'sip_h_X-GS_account_uuid=' .. tostring(self.caller.account_uuid)); + table.insert(origination_variables, 'sip_h_X-GS_account_type' .. tostring(self.caller.account_type)); + table.insert(origination_variables, 'sip_h_X-GS_auth_account_type' .. tostring(self.caller.auth_account_type)); + table.insert(origination_variables, 'sip_h_X-GS_auth_account_uuid' .. tostring(self.caller.auth_account_uuid)); + table.insert(origination_variables, 'sip_h_X-GS_loop_count' .. tostring(self.caller.loop_count)); table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. node.record.name .. '/' .. destination.number); end elseif destination.type == 'sipaccount' then @@ -169,11 +174,6 @@ function SipCall.fork(self, destinations, arg ) end self.caller:set_callee_id(arg.callee_id_number, arg.callee_id_name); - self.caller:set_header('X-GS_account_uuid', self.caller.account_uuid); - self.caller:set_header('X-GS_account_type', self.caller.account_type); - self.caller:set_header('X-GS_auth_account_type', self.caller.auth_account_type); - self.caller:set_header('X-GS_auth_account_uuid', self.caller.auth_account_uuid); - self.caller:set_header('X-GS_loop_count', self.caller.loop_count); self.caller:set_variable('call_timeout', arg.timeout ); self.log:info('FORK DIAL - destinations: ', #dial_strings, ', timeout: ', arg.timeout); -- cgit v1.2.3 From d959f30fbfde9d10811f04da6ab4891e2b94fdd7 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 30 Jan 2013 10:27:40 +0100 Subject: equality sign --- misc/freeswitch/scripts/dialplan/sip_call.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index a235fb3..806c72c 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -107,10 +107,10 @@ function SipCall.fork(self, destinations, arg ) if node then table.insert(origination_variables, 'sip_h_X-GS_node_id=' .. self.caller.local_node_id); table.insert(origination_variables, 'sip_h_X-GS_account_uuid=' .. tostring(self.caller.account_uuid)); - table.insert(origination_variables, 'sip_h_X-GS_account_type' .. tostring(self.caller.account_type)); - table.insert(origination_variables, 'sip_h_X-GS_auth_account_type' .. tostring(self.caller.auth_account_type)); - table.insert(origination_variables, 'sip_h_X-GS_auth_account_uuid' .. tostring(self.caller.auth_account_uuid)); - table.insert(origination_variables, 'sip_h_X-GS_loop_count' .. tostring(self.caller.loop_count)); + table.insert(origination_variables, 'sip_h_X-GS_account_type=' .. tostring(self.caller.account_type)); + table.insert(origination_variables, 'sip_h_X-GS_auth_account_type=' .. tostring(self.caller.auth_account_type)); + table.insert(origination_variables, 'sip_h_X-GS_auth_account_uuid=' .. tostring(self.caller.auth_account_uuid)); + table.insert(origination_variables, 'sip_h_X-GS_loop_count=' .. tostring(self.caller.loop_count)); table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. node.record.name .. '/' .. destination.number); end elseif destination.type == 'sipaccount' then -- cgit v1.2.3 From 44337fb9a2bcbb8766e7c2b508cf2206afa09c05 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 30 Jan 2013 15:57:07 +0100 Subject: route endpoints --- misc/freeswitch/scripts/dialplan/dialplan.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index ff4adc6..6e9bf68 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -814,11 +814,13 @@ 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.endpoint_type == 'hangup' then - return { continue = false, code = route.endpoint, phrase = route.phrase, cause = route.value } + if route.type == 'hangup' then + self.log:notice('SWITCH_HANGUP - code: ', route.code, ', phrase: ', route.phrase, ', cause: ', route.cause); + return { continue = false, code = route.code or '404', phrase = route.phrase, cause = route.cause } end - if route.endpoint_type == 'forward' then - return { continue = true, call_forwarding = { number = route.value, service = 'route', type = 'phonenumber' }} + if route.type == 'forward' then + self.log:notice('SWITCH_CALL_FORWARDING - number: ', route.number); + return { continue = true, call_forwarding = { number = route.number, service = 'route', type = 'phonenumber' }} end for key, value in pairs(route) do -- cgit v1.2.3 From d4a664a0495bd183b16a239aeb4c342e1ca739fa Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 30 Jan 2013 15:59:52 +0100 Subject: select route endpoint --- app/controllers/call_routes_controller.rb | 11 +++++++++++ app/models/call_route.rb | 4 ++++ app/views/call_routes/_form_core.html.haml | 3 +-- config/locales/views/call_routes/de.yml | 5 +---- config/locales/views/call_routes/en.yml | 5 +---- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 0259a10..653fd55 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -1,6 +1,12 @@ class CallRoutesController < ApplicationController authorize_resource :call_route + before_filter { |controller| + if !params[:call_route].blank? and !params[:call_route][:endpoint_str].blank? + params[:call_route][:endpoint_type], delimeter, params[:call_route][:endpoint_id] = params[:call_route][:endpoint_str].partition('=') + end + } + def index @call_routes = CallRoute.order([:routing_table, :position]) @routing_tables = @call_routes.pluck(:routing_table).uniq.sort @@ -29,6 +35,11 @@ class CallRoutesController < ApplicationController def edit @call_route = CallRoute.find(params[:id]) + @endpoints = Gateway.all.collect {|r| [ "gateway: #{r.to_s}", "gateway=#{r.id}" ] } + @endpoints << [ 'phonenumber', 'phonenumber' ] + @endpoints << [ 'dialplanfunction', 'dialplanfunction' ] + @endpoints << [ 'hangup', 'hangup' ] + @endpoints << [ 'unknown', 'unknown' ] spread_breadcrumbs end diff --git a/app/models/call_route.rb b/app/models/call_route.rb index b4496ab..1c3f70a 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -239,6 +239,10 @@ class CallRoute < ActiveRecord::Base end end + def endpoint_str + "#{endpoint_type}=#{endpoint_id}" + end + def endpoint if self.endpoint_id.to_i > 0 begin diff --git a/app/views/call_routes/_form_core.html.haml b/app/views/call_routes/_form_core.html.haml index b64d660..6679a7b 100644 --- a/app/views/call_routes/_form_core.html.haml +++ b/app/views/call_routes/_form_core.html.haml @@ -1,5 +1,4 @@ .inputs = f.input :routing_table, :collection => CallRoute::ROUTING_TABLES, :label => t('call_routes.form.table.label'), :hint => conditional_hint('call_routes.form.table.hint'), :include_blank => false, :autofocus => true = f.input :name, :label => t('call_routes.form.name.label'), :hint => conditional_hint('call_routes.form.name.hint') - = f.input :endpoint_type, :label => t('call_routes.form.endpoint_type.label'), :hint => conditional_hint('call_routes.form.endpoint_type.hint') - = f.input :endpoint_id, :label => t('call_routes.form.endpoint_id.label'), :hint => conditional_hint('call_routes.form.endpoint_id.hint') + = f.input :endpoint_str, :collection => @endpoints, :label => t('call_routes.form.endpoint.label'), :hint => conditional_hint('call_routes.form.endpoint.hint'), :include_blank => false diff --git a/config/locales/views/call_routes/de.yml b/config/locales/views/call_routes/de.yml index a8d6f4b..77b597b 100644 --- a/config/locales/views/call_routes/de.yml +++ b/config/locales/views/call_routes/de.yml @@ -46,10 +46,7 @@ de: name: label: 'Name' hint: '' - endpoint_type: - label: 'Endpoint type' - hint: '' - endpoint_id: + endpoint: label: 'Endpoint' hint: '' position: diff --git a/config/locales/views/call_routes/en.yml b/config/locales/views/call_routes/en.yml index 8596474..c37773d 100644 --- a/config/locales/views/call_routes/en.yml +++ b/config/locales/views/call_routes/en.yml @@ -46,10 +46,7 @@ en: name: label: 'Name' hint: '' - endpoint_type: - label: 'Endpoint type' - hint: '' - endpoint_id: + endpoint: label: 'Endpoint' hint: '' position: -- cgit v1.2.3 From 83120928fc2dabe225215668943452065d8bc52f Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 30 Jan 2013 16:05:20 +0100 Subject: equality sign --- app/controllers/call_routes_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 653fd55..7cc50ab 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -36,10 +36,10 @@ class CallRoutesController < ApplicationController def edit @call_route = CallRoute.find(params[:id]) @endpoints = Gateway.all.collect {|r| [ "gateway: #{r.to_s}", "gateway=#{r.id}" ] } - @endpoints << [ 'phonenumber', 'phonenumber' ] - @endpoints << [ 'dialplanfunction', 'dialplanfunction' ] - @endpoints << [ 'hangup', 'hangup' ] - @endpoints << [ 'unknown', 'unknown' ] + @endpoints << [ 'phonenumber', 'phonenumber=' ] + @endpoints << [ 'dialplanfunction', 'dialplanfunction=' ] + @endpoints << [ 'hangup', 'hangup=' ] + @endpoints << [ 'unknown', 'unknown=' ] spread_breadcrumbs end -- cgit v1.2.3 From a174fadb492cb2a88bd39dbc9b6d77955b878ccf Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 31 Jan 2013 11:22:13 +0100 Subject: control dtmf detection --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 6e9bf68..a9b3a66 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -445,6 +445,8 @@ function Dialplan.dial(self, destination) 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, + detect_dtmf_after_bridge_caller = self.detect_dtmf_after_bridge_caller, + detect_dtmf_after_bridge_callee = self.detect_dtmf_after_bridge_callee, } ); end -- cgit v1.2.3 From 09c5d6929a20bda3972c80ee62e9f4ad2f25e9cf Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 31 Jan 2013 11:26:35 +0100 Subject: clip_no_screening fixed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index a9b3a66..55f714b 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -761,7 +761,7 @@ function Dialplan.switch(self, destination) elseif not common.str.blank(destination.number) then local result = { continue = false, code = 404, phrase = 'No route' } - local clip_no_screening = common.str.try(caller, 'account.record.clip_no_screening'); + local clip_no_screening = common.str.try(self.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 -- cgit v1.2.3 From 8da882cf3ec53f9057b17bd8dd39c2eadb2a88c2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 31 Jan 2013 11:39:25 +0100 Subject: Fixed single sign on. #145 --- app/controllers/application_controller.rb | 61 +++++++++++------------ app/controllers/gemeinschaft_setups_controller.rb | 4 +- app/controllers/page_controller.rb | 14 ------ app/views/layouts/_navbar.html.haml | 7 +-- config/routes.rb | 5 +- db/schema.rb | 2 +- 6 files changed, 36 insertions(+), 57 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2aadf19..d1d918e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,26 +2,21 @@ class ApplicationController < ActionController::Base protect_from_forgery - before_filter :set_locale + before_filter :start_setup_if_new_installation - before_filter :go_to_setup_if_new_installation - before_filter :home_breadcrumb - + before_filter :set_locale helper_method :current_user - + helper_method :guess_local_ip_address helper_method :guess_local_host - + + before_filter :home_breadcrumb + helper_method :'have_https?' + helper_method :'single_sign_on_system?' helper_method :random_pin - - #TODO Add check_authorization. See - # https://github.com/ryanb/cancan - # https://github.com/ryanb/cancan/wiki/Ensure-Authorization - # and Gemeinschaft 4 - # Generate a new name for an Object # def generate_a_new_name(parent, child = nil) @@ -56,6 +51,8 @@ class ApplicationController < ActionController::Base def random_pin if GsParameter.get('MINIMUM_PIN_LENGTH') > 0 (1..GsParameter.get('MINIMUM_PIN_LENGTH')).map{|i| (0 .. 9).to_a.sample}.join + else + (1..8).map{|i| (0 .. 9).to_a.sample}.join end end @@ -109,40 +106,38 @@ class ApplicationController < ActionController::Base if current_user redirect_to root_url, :alert => 'Access denied! Please ask your admin to grant you the necessary rights.' else - if Tenant.count == 0 && User.count == 0 - # This is a brand new system. We need to run a setup first. - redirect_to wizards_new_initial_setup_path - else - # You need to login first. - redirect_to log_in_path, :alert => 'Access denied! You need to login first.' - end + # You need to login first. + redirect_to log_in_path, :alert => 'Access denied! You need to login first.' end end private def current_user - if session[:user_id] || GsParameter.get('SingleSignOnEnvUserNameKey').blank? + if session[:user_id].nil? && single_sign_on_system? + auth_user = User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).first + else if session[:user_id] && User.where(:id => session[:user_id]).any? - return User.where(:id => session[:user_id]).first + auth_user = User.where(:id => session[:user_id]).first else - session[:user_id] = nil - return nil + auth_user = nil end + end + session[:user_id] = auth_user.try(:id) + return auth_user + end + + def single_sign_on_system? + if GsParameter.get('SingleSignOnEnvUserNameKey').blank? + false else - if User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).any? - auth_user = User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).first - session[:user_id] = auth_user.id - return auth_user - else - return nil - end + true end - end + end - def go_to_setup_if_new_installation + def start_setup_if_new_installation if Rails.env != 'test' - if GemeinschaftSetup.all.count == 0 + if GemeinschaftSetup.count == 0 redirect_to new_gemeinschaft_setup_path end end diff --git a/app/controllers/gemeinschaft_setups_controller.rb b/app/controllers/gemeinschaft_setups_controller.rb index 4f4a72a..cff652d 100644 --- a/app/controllers/gemeinschaft_setups_controller.rb +++ b/app/controllers/gemeinschaft_setups_controller.rb @@ -4,9 +4,9 @@ class GemeinschaftSetupsController < ApplicationController # caches_page :new, :gzip => :best_compression - load_and_authorize_resource :gemeinschaft_setup + skip_before_filter :start_setup_if_new_installation - skip_before_filter :go_to_setup_if_new_installation + load_and_authorize_resource :gemeinschaft_setup def new @user = @gemeinschaft_setup.build_user( diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb index 8f4fa88..ed48e3c 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/page_controller.rb @@ -2,7 +2,6 @@ class PageController < ApplicationController # load_and_authorize_resource :class => false # CanCan doesn't work here really good because Page is not a resource. - before_filter :if_fresh_system_then_go_to_wizard skip_before_filter :home_breadcrumb, :only => [:index] def index @@ -14,18 +13,5 @@ class PageController < ApplicationController def help end - - private - def if_fresh_system_then_go_to_wizard - if Tenant.count == 0 && User.count == 0 - # This is a brand new system. We need to run a setup first. - redirect_to wizards_new_initial_setup_path - else - if current_user.nil? - # You need to login first. - redirect_to log_in_path, :alert => I18n.t('pages.controller.access_denied_login_first') - end - end - end end diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index c2d9946..9350de0 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -48,7 +48,8 @@ %a.navbar-link{:href => tenant_user_path(current_user.current_tenant, current_user)} = current_user - %li - %a.navbar-link{:href => log_out_path} - %i.icon-off.icon-white + - if single_sign_on_system? == false + %li + %a.navbar-link{:href => log_out_path} + %i.icon-off.icon-white diff --git a/config/routes.rb b/config/routes.rb index 9d47efc..a0ac93a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,7 +112,7 @@ Gemeinschaft42c::Application.routes.draw do end resources :gemeinschaft_setups, :only => [:new, :create] - + resources :phone_number_ranges, :only => [] do resources :phone_numbers do member do @@ -228,9 +228,6 @@ Gemeinschaft42c::Application.routes.draw do root :to => "page#index" - get "wizards/new_initial_setup" - post "wizards/create_initial_setup" - resources :users do # Display all phone books that the current user owns: resources :phone_books diff --git a/db/schema.rb b/db/schema.rb index e1bed77..31d4063 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130129154700) do +ActiveRecord::Schema.define(:version => 20130130185300) do create_table "access_authorizations", :force => true do |t| t.string "access_authorizationable_type" -- cgit v1.2.3 From ea436f31b3462b837d6b092d7bc655f7ea1f72f5 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 31 Jan 2013 12:02:36 +0100 Subject: Added DelayedJob stuff. --- Gemfile | 4 ++-- Gemfile.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index f0fd360..f65e118 100644 --- a/Gemfile +++ b/Gemfile @@ -58,8 +58,8 @@ gem "mini_magick" # Pagination https://github.com/mislav/will_paginate/wiki/Installation gem 'will_paginate' -# DelayedJob -gem 'delayed_job' +# DelayedJob https://github.com/collectiveidea/delayed_job +gem 'daemons' gem 'delayed_job_active_record' # Private Pub http://railscasts.com/episodes/316-private-pub diff --git a/Gemfile.lock b/Gemfile.lock index 33e77ff..6bb234f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -210,8 +210,8 @@ DEPENDENCIES carrierwave coffee-rails (~> 3.2.1) compass-rails + daemons dalli - delayed_job delayed_job_active_record factory_girl factory_girl_rails -- cgit v1.2.3 From 495582824eda0b3e69e88e52be2fabecba650bfa Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 31 Jan 2013 11:55:54 +0100 Subject: Added the backup gem. --- Gemfile | 3 +++ Gemfile.lock | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Gemfile b/Gemfile index f65e118..58523e1 100644 --- a/Gemfile +++ b/Gemfile @@ -79,6 +79,9 @@ gem 'unicorn' gem 'thin' +# Backup https://github.com/meskyanichi/backup +gem 'backup' + # Local Variables: # mode: ruby # End: diff --git a/Gemfile.lock b/Gemfile.lock index 6bb234f..64b9f6f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,6 +31,9 @@ GEM acts_as_list (0.1.9) addressable (2.3.2) arel (3.0.2) + backup (3.0.27) + open4 (~> 1.3.0) + thor (>= 0.15.4, < 2) bcrypt-ruby (3.0.1) better_errors (0.3.2) coderay (>= 1.0.0) @@ -119,6 +122,7 @@ GEM multi_json (1.5.0) mysql2 (0.3.11) nokogiri (1.5.6) + open4 (1.3.0) polyglot (0.3.3) private_pub (1.0.3) faye @@ -201,6 +205,7 @@ PLATFORMS DEPENDENCIES acts_as_list + backup bcrypt-ruby better_errors binding_of_caller -- cgit v1.2.3 From 68f0f677c5cba6775622d0e50c4315e6361ff5c9 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 31 Jan 2013 12:26:47 +0100 Subject: First test setup for the backup. --- app/models/gs5_backup.rb | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ config/backup.rb | 32 +++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 app/models/gs5_backup.rb create mode 100644 config/backup.rb diff --git a/app/models/gs5_backup.rb b/app/models/gs5_backup.rb new file mode 100644 index 0000000..928245f --- /dev/null +++ b/app/models/gs5_backup.rb @@ -0,0 +1,53 @@ +# encoding: utf-8 + +## +# Backup Generated: gs5_backup +# Once configured, you can run the backup with the following command: +# +# $ backup perform -t gs5_backup [-c ] +# +Backup::Model.new(:gs5_backup, 'GS5 backup') do + ## + # Split [Splitter] + # + # Split the backup file in to chunks of 250 megabytes + # if the backup file size exceeds 250 megabytes + # + split_into_chunks_of 640 + + ## + # MySQL [Database] + # + database MySQL do |db| + # To dump all databases, set `db.name = :all` (or leave blank) + db.name = system_odbc_configuration['gemeinschaft']['DATABASE'] + db.username = system_odbc_configuration['gemeinschaft']['USER'] + db.password = system_odbc_configuration['gemeinschaft']['PASSWORD'] + db.host = "localhost" + db.port = 3306 + db.socket = "/tmp/mysql.sock" + # Note: when using `skip_tables` with the `db.name = :all` option, + # table names should be prefixed with a database name. + # e.g. ["db_name.table_to_skip", ...] + db.skip_tables = ["skip", "these", "tables"] + db.only_tables = ["only", "these" "tables"] + db.additional_options = ["--quick", "--single-transaction"] + # Optional: Use to set the location of this utility + # if it cannot be found by name in your $PATH + # db.mysqldump_utility = "/opt/local/bin/mysqldump" + end + + ## + # Local (Copy) [Storage] + # + store_with Local do |local| + local.path = "/var/backups/gs5" + local.keep = 5 + end + + ## + # Gzip [Compressor] + # + compress_with Gzip + +end diff --git a/config/backup.rb b/config/backup.rb new file mode 100644 index 0000000..a7d98c3 --- /dev/null +++ b/config/backup.rb @@ -0,0 +1,32 @@ +# encoding: utf-8 + +## +# Backup +# Generated Main Config Template +# +# For more information: +# +# View the Git repository at https://github.com/meskyanichi/backup +# View the Wiki/Documentation at https://github.com/meskyanichi/backup/wiki +# View the issue log at https://github.com/meskyanichi/backup/issues + +## +# Global Configuration +# Add more (or remove) global configuration below +# +# Backup::Storage::S3.defaults do |s3| +# s3.access_key_id = "my_access_key_id" +# s3.secret_access_key = "my_secret_access_key" +# end +# +# Backup::Encryptor::OpenSSL.defaults do |encryption| +# encryption.password = "my_password" +# encryption.base64 = true +# encryption.salt = true +# end + +## +# Load all models from the models directory (after the above global configuration blocks) +Dir[File.join(File.dirname(Config.config_file), "models", "*.rb")].each do |model| + instance_eval(File.read(model)) +end -- cgit v1.2.3 From d3af3a902ef110b50abcc599962bc856eefe4428 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 31 Jan 2013 14:42:20 +0100 Subject: Fixed the backup config. --- app/models/gs5_backup.rb | 53 --------------------------------------- config/backup.rb | 65 ++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 80 deletions(-) delete mode 100644 app/models/gs5_backup.rb diff --git a/app/models/gs5_backup.rb b/app/models/gs5_backup.rb deleted file mode 100644 index 928245f..0000000 --- a/app/models/gs5_backup.rb +++ /dev/null @@ -1,53 +0,0 @@ -# encoding: utf-8 - -## -# Backup Generated: gs5_backup -# Once configured, you can run the backup with the following command: -# -# $ backup perform -t gs5_backup [-c ] -# -Backup::Model.new(:gs5_backup, 'GS5 backup') do - ## - # Split [Splitter] - # - # Split the backup file in to chunks of 250 megabytes - # if the backup file size exceeds 250 megabytes - # - split_into_chunks_of 640 - - ## - # MySQL [Database] - # - database MySQL do |db| - # To dump all databases, set `db.name = :all` (or leave blank) - db.name = system_odbc_configuration['gemeinschaft']['DATABASE'] - db.username = system_odbc_configuration['gemeinschaft']['USER'] - db.password = system_odbc_configuration['gemeinschaft']['PASSWORD'] - db.host = "localhost" - db.port = 3306 - db.socket = "/tmp/mysql.sock" - # Note: when using `skip_tables` with the `db.name = :all` option, - # table names should be prefixed with a database name. - # e.g. ["db_name.table_to_skip", ...] - db.skip_tables = ["skip", "these", "tables"] - db.only_tables = ["only", "these" "tables"] - db.additional_options = ["--quick", "--single-transaction"] - # Optional: Use to set the location of this utility - # if it cannot be found by name in your $PATH - # db.mysqldump_utility = "/opt/local/bin/mysqldump" - end - - ## - # Local (Copy) [Storage] - # - store_with Local do |local| - local.path = "/var/backups/gs5" - local.keep = 5 - end - - ## - # Gzip [Compressor] - # - compress_with Gzip - -end diff --git a/config/backup.rb b/config/backup.rb index a7d98c3..4a48ac5 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -1,32 +1,43 @@ # encoding: utf-8 -## -# Backup -# Generated Main Config Template -# -# For more information: -# -# View the Git repository at https://github.com/meskyanichi/backup -# View the Wiki/Documentation at https://github.com/meskyanichi/backup/wiki -# View the issue log at https://github.com/meskyanichi/backup/issues +require 'inifile' +SYSTEM_ODBC_CONFIGURATION = IniFile.load('/var/lib/freeswitch/.odbc.ini') -## -# Global Configuration -# Add more (or remove) global configuration below -# -# Backup::Storage::S3.defaults do |s3| -# s3.access_key_id = "my_access_key_id" -# s3.secret_access_key = "my_secret_access_key" -# end -# -# Backup::Encryptor::OpenSSL.defaults do |encryption| -# encryption.password = "my_password" -# encryption.base64 = true -# encryption.salt = true -# end +Backup::Model.new(:gs5, 'GS5 backup') do + + ## + # Split [Splitter] + # + # Split the backup file in to chunks of 2 GB + # if the backup file size exceeds 2 GB + # + split_into_chunks_of 2048 + + ## + # MySQL [Database] + # + database MySQL do |db| + # To dump all databases, set `db.name = :all` (or leave blank) + db.name = SYSTEM_ODBC_CONFIGURATION['gemeinschaft']['DATABASE'] + db.username = SYSTEM_ODBC_CONFIGURATION['gemeinschaft']['USER'] + db.password = SYSTEM_ODBC_CONFIGURATION['gemeinschaft']['PASSWORD'] + db.host = "localhost" + db.port = 3306 + db.socket = "/var/run/mysqld/mysqld.sock" + end + + ## + # Local (Copy) [Storage] + # + store_with Local do |local| + local.path = "/var/backups/" + local.keep = 5 + end + + ## + # Gzip [Compressor] + # + compress_with Gzip -## -# Load all models from the models directory (after the above global configuration blocks) -Dir[File.join(File.dirname(Config.config_file), "models", "*.rb")].each do |model| - instance_eval(File.read(model)) end + -- cgit v1.2.3 From b3e0cb6887d48374d528227230d0a5a2511f99df Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 31 Jan 2013 20:00:48 +0100 Subject: sip_copy_custom_headers affects Call-Info headers --- misc/freeswitch/scripts/dialplan/dialplan.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 55f714b..72503e5 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -350,10 +350,10 @@ function Dialplan.set_caller_picture(self, entry_id, entry_type, image) require 'dialplan.user' local user = dialplan.user.User:new{ log = self.log, database = self.database }:find_by_id(entry_id); if user then - self.caller:set_variable('sip_h_Call-Info', '<' .. self.user_image_url .. '/' .. tonumber(entry_id) .. '/snom_caller_picture_' .. tostring(user.record.image) .. '>;purpose=icon'); + self.caller:export_variable('sip_h_Call-Info', '<' .. self.user_image_url .. '/' .. tonumber(entry_id) .. '/snom_caller_picture_' .. tostring(user.record.image) .. '>;purpose=icon'); end elseif entry_type == 'phonebookentry' and image then - self.caller:set_variable('sip_h_Call-Info', '<' .. self.phone_book_entry_image_url .. '/' .. tonumber(entry_id) .. '/snom_caller_picture_' .. tostring(image) .. '>;purpose=icon'); + self.caller:export_variable('sip_h_Call-Info', '<' .. self.phone_book_entry_image_url .. '/' .. tonumber(entry_id) .. '/snom_caller_picture_' .. tostring(image) .. '>;purpose=icon'); end end -- cgit v1.2.3 From 3c0290515e4c097b97ee4fb4d807f9f86c2985a2 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 31 Jan 2013 20:07:17 +0100 Subject: destinations drop down menu --- app/controllers/call_routes_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 7cc50ab..894dd61 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -20,6 +20,11 @@ class CallRoutesController < ApplicationController def new @call_route = CallRoute.new + @endpoints = Gateway.all.collect {|r| [ "gateway: #{r.to_s}", "gateway=#{r.id}" ] } + @endpoints << [ 'phonenumber', 'phonenumber=' ] + @endpoints << [ 'dialplanfunction', 'dialplanfunction=' ] + @endpoints << [ 'hangup', 'hangup=' ] + @endpoints << [ 'unknown', 'unknown=' ] spread_breadcrumbs end -- cgit v1.2.3 From c744a4aca7b45a654d842c1b41aeabf86a406f62 Mon Sep 17 00:00:00 2001 From: Sascha Daniels Date: Thu, 31 Jan 2013 20:14:42 +0100 Subject: Better transfer behaviour --- app/views/config_snom/show.xml.haml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/config_snom/show.xml.haml b/app/views/config_snom/show.xml.haml index 5f53802..30bee56 100644 --- a/app/views/config_snom/show.xml.haml +++ b/app/views/config_snom/show.xml.haml @@ -40,7 +40,11 @@ %mwi_notification{:perm => 'RW'}= 'silent' %mwi_dialtone{:perm => 'RW'}= 'normal' %prefer_saved_over_received_photo{:perm => 'RW'}= 'off' - %no_dnd{:perm => 'RW'}= 'on' + %no_dnd{:perm => 'RW'}= 'off' + %transfer_on_hangup{:perm => 'RW'}= 'on' + %transfer_on_hangup_non_pots{:perm => 'RW'}= 'on' + %call_join_xfer{:perm => 'RW'}= 'on' + %conf_hangup{:perm => 'RW'}= 'on' %logon_wizard{:perm => 'RW'}= 'off' %disable_deflection{:perm => 'RW'}= 'off' %csta_control{:perm => 'RW'}= 'on' -- cgit v1.2.3 From 4acda4279f11dc917b43aa7505ecb07d2161f0f6 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 1 Feb 2013 08:11:16 +0100 Subject: position added --- app/views/call_routes/_form_core.html.haml | 1 + app/views/call_routes/_index_core.html.haml | 2 ++ app/views/call_routes/show.html.haml | 3 +++ 3 files changed, 6 insertions(+) diff --git a/app/views/call_routes/_form_core.html.haml b/app/views/call_routes/_form_core.html.haml index 6679a7b..926c985 100644 --- a/app/views/call_routes/_form_core.html.haml +++ b/app/views/call_routes/_form_core.html.haml @@ -2,3 +2,4 @@ = f.input :routing_table, :collection => CallRoute::ROUTING_TABLES, :label => t('call_routes.form.table.label'), :hint => conditional_hint('call_routes.form.table.hint'), :include_blank => false, :autofocus => true = f.input :name, :label => t('call_routes.form.name.label'), :hint => conditional_hint('call_routes.form.name.hint') = f.input :endpoint_str, :collection => @endpoints, :label => t('call_routes.form.endpoint.label'), :hint => conditional_hint('call_routes.form.endpoint.hint'), :include_blank => false + = f.input :position, :label => t('call_routes.form.position.label'), :hint => conditional_hint('call_routes.form.position.hint') \ No newline at end of file diff --git a/app/views/call_routes/_index_core.html.haml b/app/views/call_routes/_index_core.html.haml index f0acebb..52a45ba 100644 --- a/app/views/call_routes/_index_core.html.haml +++ b/app/views/call_routes/_index_core.html.haml @@ -2,6 +2,7 @@ %table.table.table-striped %thead %tr + %th %th= t('call_routes.index.name') %th= t('route_elements.index.pattern') %th= t('call_routes.index.endpoint') @@ -10,6 +11,7 @@ - for call_route in call_routes - cache(['call_route_single_table_row', call_route, call_routes.count]) do %tr + %td= call_route.position %td= call_route.name %td - if call_route.route_elements.any? diff --git a/app/views/call_routes/show.html.haml b/app/views/call_routes/show.html.haml index 09daf53..a33a29b 100644 --- a/app/views/call_routes/show.html.haml +++ b/app/views/call_routes/show.html.haml @@ -1,5 +1,8 @@ - content_for :title, t("call_routes.show.page_title") +%p + %strong= t('call_routes.show.position') + ":" + = @call_route.position %p %strong= t('call_routes.show.table') + ":" = @call_route.routing_table -- cgit v1.2.3 From d355193428c9e74180f1b278f88c7b56f3cd6bda Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 1 Feb 2013 09:12:56 +0100 Subject: order by position --- app/controllers/route_elements_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/route_elements_controller.rb b/app/controllers/route_elements_controller.rb index c4e4c1a..9c6f2b7 100644 --- a/app/controllers/route_elements_controller.rb +++ b/app/controllers/route_elements_controller.rb @@ -5,7 +5,7 @@ class RouteElementsController < ApplicationController before_filter :spread_breadcrumbs def index - @route_elements = @call_route.route_elements + @route_elements = @call_route.route_elements.order([:position]) end def show -- cgit v1.2.3 From f46bfd1618f85842913dd967133f111ec2628fef Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 1 Feb 2013 09:13:30 +0100 Subject: position added --- app/views/route_elements/_form_core.html.haml | 1 + app/views/route_elements/_index_core.html.haml | 2 ++ app/views/route_elements/show.html.haml | 3 +++ 3 files changed, 6 insertions(+) diff --git a/app/views/route_elements/_form_core.html.haml b/app/views/route_elements/_form_core.html.haml index a9a38a7..d22467e 100644 --- a/app/views/route_elements/_form_core.html.haml +++ b/app/views/route_elements/_form_core.html.haml @@ -4,4 +4,5 @@ = f.input :pattern, :label => t('route_elements.form.pattern.label'), :hint => conditional_hint('route_elements.form.pattern.hint') = f.input :replacement, :label => t('route_elements.form.replacement.label'), :hint => conditional_hint('route_elements.form.replacement.hint') = f.input :action, :collection => RouteElement::ELEMENT_ACTIONS, :label => t('route_elements.form.action.label'), :hint => conditional_hint('route_elements.form.action.hint'), :include_blank => false + = f.input :position, :label => t('route_elements.form.position.label'), :hint => conditional_hint('route_elements.form.position.hint') = f.input :mandatory, :label => t('route_elements.form.mandatory.label'), :hint => conditional_hint('route_elements.form.mandatory.hint') diff --git a/app/views/route_elements/_index_core.html.haml b/app/views/route_elements/_index_core.html.haml index 37c0656..f68a9ba 100644 --- a/app/views/route_elements/_index_core.html.haml +++ b/app/views/route_elements/_index_core.html.haml @@ -1,6 +1,7 @@ %table.table.table-striped %thead %tr + %th %th= t('route_elements.index.var_in') %th= t('route_elements.index.var_out') %th= t('route_elements.index.pattern') @@ -11,6 +12,7 @@ %tbody - for route_element in route_elements %tr + %td= route_element.position %td= route_element.var_in %td= route_element.var_out %td= route_element.pattern diff --git a/app/views/route_elements/show.html.haml b/app/views/route_elements/show.html.haml index 808f2a0..1d07cbc 100644 --- a/app/views/route_elements/show.html.haml +++ b/app/views/route_elements/show.html.haml @@ -1,5 +1,8 @@ - content_for :title, t("route_elements.show.page_title") +%p + %strong= t('route_elements.show.position') + ":" + = @route_element.position %p %strong= t('route_elements.show.var_in') + ":" = @route_element.var_in -- cgit v1.2.3 From aad8a03991fe616f84fa18ed1db81831220f8d64 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 1 Feb 2013 15:36:59 +0100 Subject: Added faxes and voicemails to the backup job. --- config/backup.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config/backup.rb b/config/backup.rb index 4a48ac5..c3da9bc 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -26,6 +26,21 @@ Backup::Model.new(:gs5, 'GS5 backup') do db.socket = "/var/run/mysqld/mysqld.sock" end + ## + # Faxes + # + archive :faxes do |archive| + archive.add '/opt/gemeinschaft/public/uploads/fax_document/' + archive.add '/opt/gemeinschaft/public/uploads/fax_thumbnail/' + end + + ## + # Voicemails + # + archive :voicemails do |archive| + archive.add '/var/opt/gemeinschaft/freeswitch/voicemail/' + end + ## # Local (Copy) [Storage] # -- cgit v1.2.3 From ba5b2737365592cc511a526a3b14be46c3a75467 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sat, 2 Feb 2013 11:42:52 +0100 Subject: Created a sortable table for the call_routes. #151 --- app/assets/javascripts/application.js | 1 + app/assets/javascripts/call_route.js.coffee | 6 +++ app/assets/stylesheets/application.css | 1 + app/assets/stylesheets/call_routes.css.scss | 5 +++ app/controllers/call_routes_controller.rb | 27 ++++++-------- app/views/call_routes/_index_core.html.haml | 58 +++++++++++++++-------------- app/views/call_routes/index.html.haml | 11 ++---- config/routes.rb | 12 +----- 8 files changed, 60 insertions(+), 61 deletions(-) create mode 100644 app/assets/javascripts/call_route.js.coffee create mode 100644 app/assets/stylesheets/call_routes.css.scss diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9097d83..c6f4107 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,5 +11,6 @@ // GO AFTER THE REQUIRES BELOW. // //= require jquery +//= require jquery-ui //= require jquery_ujs //= require_tree . diff --git a/app/assets/javascripts/call_route.js.coffee b/app/assets/javascripts/call_route.js.coffee new file mode 100644 index 0000000..f41d65b --- /dev/null +++ b/app/assets/javascripts/call_route.js.coffee @@ -0,0 +1,6 @@ +jQuery -> + $("table tbody").sortable + axis: 'y' + handle: '.handle' + update: -> + $.post('call_routes/sort', $(this).sortable('serialize')) \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 9093f8e..999afb5 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -12,4 +12,5 @@ *= require bootstrap/bootstrap *= require bootstrap/bootstrap-responsive *= require gemeinschaft-generic + *= require call_routes */ diff --git a/app/assets/stylesheets/call_routes.css.scss b/app/assets/stylesheets/call_routes.css.scss new file mode 100644 index 0000000..7face3b --- /dev/null +++ b/app/assets/stylesheets/call_routes.css.scss @@ -0,0 +1,5 @@ +#call_routes .handle { + font-size: 12px; + color: #777; + cursor: move; +} \ No newline at end of file diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 894dd61..779e23c 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -1,11 +1,11 @@ class CallRoutesController < ApplicationController authorize_resource :call_route - before_filter { |controller| - if !params[:call_route].blank? and !params[:call_route][:endpoint_str].blank? - params[:call_route][:endpoint_type], delimeter, params[:call_route][:endpoint_id] = params[:call_route][:endpoint_str].partition('=') - end - } + # before_filter { |controller| + # if !params[:call_route].blank? and !params[:call_route][:endpoint_str].blank? + # params[:call_route][:endpoint_type], delimeter, params[:call_route][:endpoint_id] = params[:call_route][:endpoint_str].partition('=') + # end + # } def index @call_routes = CallRoute.order([:routing_table, :position]) @@ -64,21 +64,16 @@ class CallRoutesController < ApplicationController redirect_to call_routes_url, :notice => t('call_routes.controller.successfuly_destroyed') end - def move_higher - @call_route = CallRoute.find(params[:id]) - @call_route.move_higher - redirect_to :back - end - - def move_lower - @call_route = CallRoute.find(params[:id]) - @call_route.move_lower - redirect_to :back + def sort + params[:call_route].each_with_index do |id, index| + CallRoute.update_all({position: index+1}, {id: id}) + end + render nothing: true end private def call_route_parameter_params - params.require(:call_route).permit(:routing_table, :name, :endpoint_type, :endpoint_id) + params.require(:call_route).permit(:routing_table, :name, :endpoint_type, :endpoint_id, :position) end def spread_breadcrumbs diff --git a/app/views/call_routes/_index_core.html.haml b/app/views/call_routes/_index_core.html.haml index 52a45ba..9eae9ee 100644 --- a/app/views/call_routes/_index_core.html.haml +++ b/app/views/call_routes/_index_core.html.haml @@ -1,29 +1,31 @@ -- cache(['call_routes_table', call_routes.count, call_routes.reorder(:updated_at).last]) do - %table.table.table-striped - %thead - %tr - %th - %th= t('call_routes.index.name') - %th= t('route_elements.index.pattern') - %th= t('call_routes.index.endpoint') +/ - cache(['call_routes_table', call_routes.count, call_routes.reorder(:updated_at).last]) do +%table.table.table-striped{ :id => "call_routes" } + %thead + %tr + %th + %th= t('call_routes.index.name') + %th= t('route_elements.index.pattern') + %th= t('call_routes.index.endpoint') - %tbody - - for call_route in call_routes - - cache(['call_route_single_table_row', call_route, call_routes.count]) do - %tr - %td= call_route.position - %td= call_route.name - %td - - if call_route.route_elements.any? - = call_route.route_elements.first.pattern - - if call_route.route_elements.count > 1 - = ', ...' - - else - = '-' - %td - - endpoint = call_route.endpoint - - if endpoint - = endpoint - - else - = call_route.endpoint_type - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => call_route} + %tbody + - for call_route in call_routes + / - cache(['call_route_single_table_row', call_route, call_routes.count]) do + = content_tag_for :tr, call_route do + %td + %span.handle + %i.icon-resize-vertical + %td= call_route.name + %td + - if call_route.route_elements.any? + = call_route.route_elements.first.pattern + - if call_route.route_elements.count > 1 + = ', ...' + - else + = '-' + %td + - endpoint = call_route.endpoint + - if endpoint + = endpoint + - else + = call_route.endpoint_type + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => call_route} diff --git a/app/views/call_routes/index.html.haml b/app/views/call_routes/index.html.haml index 488e1c7..d5181e3 100644 --- a/app/views/call_routes/index.html.haml +++ b/app/views/call_routes/index.html.haml @@ -1,11 +1,8 @@ - content_for :title, t("call_routes.index.page_title") -- if @call_routes && @call_routes.count > 0 - %table.table.table-striped - - @routing_tables.each do |routing_table| - %tr - %td{:colspan => 3} - %h3= routing_table - = render "index_core", :call_routes => @call_routes.where(:routing_table => routing_table) +- if @call_routes && @call_routes.any? + - @routing_tables.each do |routing_table| + %h3= routing_table + = render "index_core", :call_routes => @call_routes.where(:routing_table => routing_table) = render :partial => 'shared/create_link', :locals => {:child_class => CallRoute} diff --git a/config/routes.rb b/config/routes.rb index a0ac93a..9a3b3a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,16 +6,8 @@ Gemeinschaft42c::Application.routes.draw do end resources :call_routes do - resources :route_elements do - member do - put 'move_higher' - put 'move_lower' - end - end - member do - put 'move_higher' - put 'move_lower' - end + collection { post :sort } + resources :route_elements end resources :gateways do -- cgit v1.2.3 From 30d3aa5178e237e49a37f6ee8d0dcb25ac501e24 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sat, 2 Feb 2013 15:04:45 +0100 Subject: Add version number to a new issue. --- app/views/layouts/_footer.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 97bf483..3d4658b 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -14,6 +14,6 @@ %li = link_to 'GS5 Google Group', "https://groups.google.com/group/gs5-users/" %li - =link_to t('misc.send_a_bugreport'), URI::escape("https://github.com/amooma/GS5/issues/new?title=Bugreport&body=URL which triggered the bugreport is: #{request.fullpath}\nGS5 buildname: #{(GsParameter.get('GEMEINSCHAFT_BUILDNAME').blank? ? 'unknown' : GsParameter.get('GEMEINSCHAFT_BUILDNAME'))}\n\nPlease provide your bugreport below this line and update the title of this issue to a more specific one.") + =link_to t('misc.send_a_bugreport'), URI::escape("https://github.com/amooma/GS5/issues/new?title=Bugreport&body=URL which triggered the bugreport is: #{request.fullpath}\nGS5 buildname: #{(GsParameter.get('GEMEINSCHAFT_BUILDNAME').blank? ? 'unknown' : GsParameter.get('GEMEINSCHAFT_BUILDNAME'))} (#{GsParameter.get('GEMEINSCHAFT_VERSION')})\n\nPlease provide your bugreport below this line and update the title of this issue to a more specific one.") %li{:class => 'pull-right'} = link_to 'brought to you by AMOOMA GmbH', 'http://amooma.de' \ No newline at end of file -- cgit v1.2.3 From 2e5789bcaf38a7c2b8b6ffabe9140b4517dcffc8 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sat, 2 Feb 2013 15:36:41 +0100 Subject: Set a trunk_access_code during setup. #126 --- app/controllers/gemeinschaft_setups_controller.rb | 3 ++- app/views/gemeinschaft_setups/new.de.html.haml | 1 + app/views/gemeinschaft_setups/new.html.haml | 1 + config/locales/views/gemeinschaft_setups/de.yml | 3 +++ config/locales/views/gemeinschaft_setups/en.yml | 3 +++ .../20130202140927_add_trunk_access_code_to_gemeinschaft_setup.rb | 5 +++++ db/schema.rb | 3 ++- 7 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20130202140927_add_trunk_access_code_to_gemeinschaft_setup.rb diff --git a/app/controllers/gemeinschaft_setups_controller.rb b/app/controllers/gemeinschaft_setups_controller.rb index cff652d..a62df99 100644 --- a/app/controllers/gemeinschaft_setups_controller.rb +++ b/app/controllers/gemeinschaft_setups_controller.rb @@ -23,6 +23,7 @@ class GemeinschaftSetupsController < ApplicationController @gemeinschaft_setup.default_company_name = generate_a_new_name(Tenant.new) @gemeinschaft_setup.default_system_email = 'admin@localhost' + @gemeinschaft_setup.trunk_access_code = '0' end def create @@ -52,7 +53,7 @@ class GemeinschaftSetupsController < ApplicationController CallRoute.factory_defaults_prerouting(@gemeinschaft_setup.country.country_code, @gemeinschaft_setup.country.trunk_prefix, @gemeinschaft_setup.country.international_call_prefix, - '', + @gemeinschaft_setup.trunk_access_code, @gemeinschaft_setup.default_area_code ) diff --git a/app/views/gemeinschaft_setups/new.de.html.haml b/app/views/gemeinschaft_setups/new.de.html.haml index cf1f207..f977291 100644 --- a/app/views/gemeinschaft_setups/new.de.html.haml +++ b/app/views/gemeinschaft_setups/new.de.html.haml @@ -14,6 +14,7 @@ = f.association :country, :label => t('gemeinschaft_setups.form.country_id.label'), :hint => conditional_hint('gemeinschaft_setups.form.country_id.hint'), :include_blank => false = f.association :language, :label => t('gemeinschaft_setups.form.language_id.label'), :hint => conditional_hint('gemeinschaft_setups.form.language_id.hint'), :include_blank => false = f.input :default_area_code, :label => t('gemeinschaft_setups.form.default_area_code.label'), :hint => conditional_hint('gemeinschaft_setups.form.default_area_code.hint') + = f.input :trunk_access_code, :label => t('gemeinschaft_setups.form.trunk_access_code.label'), :hint => conditional_hint('gemeinschaft_setups.form.trunk_access_code.hint') = f.input :default_company_name, :label => t('gemeinschaft_setups.form.default_company_name.label'), :hint => conditional_hint('gemeinschaft_setups.form.default_company_name.hint') diff --git a/app/views/gemeinschaft_setups/new.html.haml b/app/views/gemeinschaft_setups/new.html.haml index 5e2434e..44d9c5b 100644 --- a/app/views/gemeinschaft_setups/new.html.haml +++ b/app/views/gemeinschaft_setups/new.html.haml @@ -14,6 +14,7 @@ = f.association :country, :label => t('gemeinschaft_setups.form.country_id.label'), :hint => conditional_hint('gemeinschaft_setups.form.country_id.hint'), :include_blank => false = f.association :language, :label => t('gemeinschaft_setups.form.language_id.label'), :hint => conditional_hint('gemeinschaft_setups.form.language_id.hint'), :include_blank => false = f.input :default_area_code, :label => t('gemeinschaft_setups.form.default_area_code.label'), :hint => conditional_hint('gemeinschaft_setups.form.default_area_code.hint') + = f.input :trunk_access_code, :label => t('gemeinschaft_setups.form.trunk_access_code.label'), :hint => conditional_hint('gemeinschaft_setups.form.trunk_access_code.hint') = f.input :default_company_name, :label => t('gemeinschaft_setups.form.default_company_name.label'), :hint => conditional_hint('gemeinschaft_setups.form.default_company_name.hint') diff --git a/config/locales/views/gemeinschaft_setups/de.yml b/config/locales/views/gemeinschaft_setups/de.yml index 57bc7e6..eb0145c 100644 --- a/config/locales/views/gemeinschaft_setups/de.yml +++ b/config/locales/views/gemeinschaft_setups/de.yml @@ -28,6 +28,9 @@ de: default_area_code: label: 'Standard Ortsvorwahl' hint: '030 für Berlin, 0261 für Koblenz, 02631 für Neuwied, usw.' + trunk_access_code: + label: 'Amtsholungsziffer' + hint: '' default_company_name: label: 'Name der Organisation' hint: 'z.B. Firmenname' diff --git a/config/locales/views/gemeinschaft_setups/en.yml b/config/locales/views/gemeinschaft_setups/en.yml index 9d5f965..3a1ac39 100644 --- a/config/locales/views/gemeinschaft_setups/en.yml +++ b/config/locales/views/gemeinschaft_setups/en.yml @@ -28,6 +28,9 @@ en: default_area_code: label: 'Default area code' hint: '' + trunk_access_code: + label: 'Trunk access code' + hint: '' default_company_name: label: 'Name of the organisation' hint: 'e.g. name of the company' diff --git a/db/migrate/20130202140927_add_trunk_access_code_to_gemeinschaft_setup.rb b/db/migrate/20130202140927_add_trunk_access_code_to_gemeinschaft_setup.rb new file mode 100644 index 0000000..82fa3ad --- /dev/null +++ b/db/migrate/20130202140927_add_trunk_access_code_to_gemeinschaft_setup.rb @@ -0,0 +1,5 @@ +class AddTrunkAccessCodeToGemeinschaftSetup < ActiveRecord::Migration + def change + add_column :gemeinschaft_setups, :trunk_access_code, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 31d4063..5d4b5e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130130185300) do +ActiveRecord::Schema.define(:version => 20130202140927) do create_table "access_authorizations", :force => true do |t| t.string "access_authorizationable_type" @@ -540,6 +540,7 @@ ActiveRecord::Schema.define(:version => 20130130185300) do t.string "default_area_code" t.string "default_company_name" t.string "default_system_email" + t.string "trunk_access_code" end create_table "gs_cluster_sync_log_entries", :force => true do |t| -- cgit v1.2.3 From 10a7536f6e142e371de9256e0ad28694c63faf4c Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 2 Feb 2013 22:40:58 +0100 Subject: fallback_sip_account added --- app/controllers/config_polycom_controller.rb | 69 +++++++++++++++------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/app/controllers/config_polycom_controller.rb b/app/controllers/config_polycom_controller.rb index 9d44e51..fd730e3 100644 --- a/app/controllers/config_polycom_controller.rb +++ b/app/controllers/config_polycom_controller.rb @@ -26,12 +26,15 @@ class ConfigPolycomController < ApplicationController if ! params[:sip_account].blank? @sip_account = @phone.sip_accounts.where({ :id => params[:sip_account].to_i }).first + if ! @sip_account && @phone.fallback_sip_account && @phone.fallback_sip_account.id == params[:sip_account].to_i + @sip_account = @phone.fallback_sip_account + end if ! @sip_account render( :status => 404, :layout => false, :content_type => 'text/plain', - :text => "", + :text => "", ) return false end @@ -113,37 +116,41 @@ class ConfigPolycomController < ApplicationController softkey_index = 1 blf_index = 0 - @phone.sip_accounts.each do |sip_account| - sip_account_index = 0 - if (sip_account.sip_accountable_type == @phone.phoneable_type) and (sip_account.sip_accountable_id == @phone.phoneable_id) - sip_account_index += 1 - if sip_account_index == 1 - xml_applications_url = "#{request.protocol}#{request.host_with_port}/config_polycom/#{@phone.id}/#{sip_account.id}" - @settings['voIpProt.SIP.outboundProxy.address'] = sip_account.host - @settings['voIpProt.SIP.outboundProxy.port'] = SIP_DEFAULT_PORT - end + phone_sip_accounts = Array.new() + if @phone.sip_accounts && @phone.sip_accounts.count > 0 + phone_sip_accounts = @phone.sip_accounts + elsif @phone.fallback_sip_account + phone_sip_accounts.push( @phone.fallback_sip_account ) + end + sip_account_index = 0 + phone_sip_accounts.each do |sip_account| + sip_account_index += 1 + if sip_account_index == 1 + xml_applications_url = "#{request.protocol}#{request.host_with_port}/config_polycom/#{@phone.id}/#{sip_account.id}" + @settings['voIpProt.SIP.outboundProxy.address'] = sip_account.host + @settings['voIpProt.SIP.outboundProxy.port'] = SIP_DEFAULT_PORT + end - @settings["reg.#{sip_account_index}.address"] = "#{sip_account.auth_name}@#{sip_account.host}" - @settings["reg.#{sip_account_index}.auth.password"] = sip_account.password - @settings["reg.#{sip_account_index}.auth.userId"] = sip_account.auth_name - @settings["reg.#{sip_account_index}.displayName"] = 'Call' - @settings["reg.#{sip_account_index}.label"] = sip_account.caller_name - @settings["voIpProt.server.#{sip_account_index}.address"] = sip_account.host - @settings["voIpProt.server.#{sip_account_index}.port"] = SIP_DEFAULT_PORT - @settings["call.missedCallTracking.#{sip_account_index}.enabled"] = 0 - - sip_account.softkeys.order(:position).each do |softkey| - softkey_index += 1 - if softkey.softkey_function - softkey_function = softkey.softkey_function.name - end - case softkey_function - when 'blf' - blf_index += 1 - @settings["lineKey.#{softkey_index}.category"] = 'BLF' - @settings["attendant.resourceList.#{blf_index}.address"] = "#{softkey.number}@#{sip_account.host}" - @settings["attendant.resourceList.#{blf_index}.label"] = softkey.label - end + @settings["reg.#{sip_account_index}.address"] = "#{sip_account.auth_name}@#{sip_account.host}" + @settings["reg.#{sip_account_index}.auth.password"] = sip_account.password + @settings["reg.#{sip_account_index}.auth.userId"] = sip_account.auth_name + @settings["reg.#{sip_account_index}.displayName"] = 'Call' + @settings["reg.#{sip_account_index}.label"] = sip_account.caller_name + @settings["voIpProt.server.#{sip_account_index}.address"] = sip_account.host + @settings["voIpProt.server.#{sip_account_index}.port"] = SIP_DEFAULT_PORT + @settings["call.missedCallTracking.#{sip_account_index}.enabled"] = 0 + + sip_account.softkeys.order(:position).each do |softkey| + softkey_index += 1 + if softkey.softkey_function + softkey_function = softkey.softkey_function.name + end + case softkey_function + when 'blf' + blf_index += 1 + @settings["lineKey.#{softkey_index}.category"] = 'BLF' + @settings["attendant.resourceList.#{blf_index}.address"] = "#{softkey.number}@#{sip_account.host}" + @settings["attendant.resourceList.#{blf_index}.label"] = softkey.label end end end -- cgit v1.2.3 From 602c13c8d767bb0f723b66522f6b88bdbc263f81 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:29:27 +0100 Subject: perimeter class added --- misc/freeswitch/scripts/common/perimeter.lua | 214 +++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 misc/freeswitch/scripts/common/perimeter.lua diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua new file mode 100644 index 0000000..d930514 --- /dev/null +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -0,0 +1,214 @@ +-- Gemeinschaft 5 module: perimeter class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + + +Perimeter = {} + + +function Perimeter.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.log = arg.log; + self.class = 'perimeter' + self.database = arg.database; + self.domain = arg.domain; + self.sources = {}; + + self.checks_available = { + check_frequency = self.check_frequency, + check_username_scan = self.check_username_scan, + check_bad_headers = self.check_bad_headers, + }; + + return object; +end + + +function Perimeter.setup(self, event) + require 'common.configuration_table'; + local config = common.configuration_table.get(self.database, 'perimeter'); + + self.contact_count_threshold = 10; + self.contact_span_threshold = 2; + self.name_changes_threshold = 2; + self.blacklist_file = '/var/opt/gemeinschaft/firewall/blacklist'; + self.blacklist_file_comment = '# PERIMETER_BAN - points: {points}, generated: {date}'; + self.blacklist_file_entry = '{received_ip} udp 5060'; + self.ban_command = 'sudo /sbin/service shorewall refresh'; + self.ban_threshold = 20; + self.ban_tries = 1; + + if config and config.general then + for key, value in pairs(config.general) do + self[key] = value; + end + end + + self.checks = config.checks; + self.bad_headers = config.bad_headers; + + self.log:info('[perimeter] PERIMETER - setup perimeter defense'); +end + + +function Perimeter.record_load(self, event) + if not self.sources[event.key] then + self.sources[event.key] = { + contact_first = event.timestamp, + contact_last = event.timestamp, + contact_count = 0, + span_contact_count = 0, + span_start = event.timestamp, + points = 0, + banned = 0, + } + end + + return self.sources[event.key]; +end + + +function Perimeter.format_date(self, value) + local epoch = tonumber(tostring(value/1000000):match('^(%d-)%.')); + return os.date('%Y-%m-%d %X', tonumber(epoch)) .. '.' .. (value-(epoch*1000000)); +end + + +function Perimeter.record_update(self, event) + event.record.contact_last = event.timestamp; + event.record.contact_count = event.record.contact_count + 1; + event.record.points = event.points or event.record.points; + event.record.span_start = event.span_start or event.record.span_start; + event.record.span_contact_count = (event.span_contact_count or event.record.span_contact_count) + 1; + event.record.users = event.users or event.record.users; +end + + +function Perimeter.check(self, event) + event.record = self:record_load(event); + -- self.log:debug('[', event.sequence, '] PERIMETER_CHECK - received: ', event.received_ip, ':', event.received_port, ', contacts: ', event.record.contact_count, ', since: ', self:format_date(event.record.contact_first), ', points: ', event.record.points); + + if event.record.banned <= self.ban_tries then + for check_name, check_points in pairs(self.checks) do + if self.checks_available[check_name] then + local result = self.checks_available[check_name](self, event); + if tonumber(result) then + event.points = (event.points or event.record.points) + result * check_points; + end + end + end + end + + if (event.points or event.record.points) > self.ban_threshold and event.record.banned <= self.ban_tries then + if event.record.banned > 0 and event.record.banned == self.ban_tries then + self.log:warning('[', event.sequence, '] PERIMETER_BAN_FUTILE - points: ', event.points,', event: ', event.class, ', ip: ', event.received_ip, ', to: ', event.to_user, '@', event.to_host); + else + self.log:notice('[', event.sequence, '] PERIMETER_BAN - threshold reached: ', event.points,', event: ', event.class, ', ip: ', event.received_ip, ', to: ', event.to_user, '@', event.to_host); + if event.record.banned == 0 then + self:append_blacklist_file(event); + end + self:execute_ban(event); + end + + event.record.banned = event.record.banned + 1; + event.span_start = event.timestamp; + event.span_contact_count = 0; + event.points = 0; + end + + self:record_update(event); +end + + +function Perimeter.check_frequency(self, event) + if event.record.span_contact_count >= self.contact_count_threshold then + self.log:info('[', event.sequence, '] PERIMETER_FREQUENCY_CHECK - contacts: ', event.record.span_contact_count, ' in < ', (event.timestamp - event.record.span_start)/1000000, ' sec, threshold: ', self.contact_count_threshold, ' in ', self.contact_span_threshold, ' sec'); + event.span_contact_count = 0; + event.span_start = event.timestamp; + return 1; + elseif (event.timestamp - event.record.span_start) > (self.contact_span_threshold * 1000000) then + event.span_contact_count = 0; + event.span_start = event.timestamp; + end +end + + +function Perimeter.check_username_scan(self, event) + if not event.to_user then + return; + end + + if not event.record.users then + event.users = { event.to_user }; + return; + end + + if #event.record.users >= self.name_changes_threshold then + self.log:info('[', event.sequence, '] PERIMETER_USER_SCAN - user names: ', #event.record.users, ', threshold: ', self.name_changes_threshold); + event.users = {}; + return 1; + else + for index=1, #event.record.users do + if event.record.users[index] == tostring(event.to_user) then + return + end + end + + if not event.users then + event.users = event.record.users or {}; + end + table.insert(event.users, tostring(event.to_user)); + end +end + + +function Perimeter.check_bad_headers(self, event) + local points = nil; + for name, pattern in pairs(self.bad_headers) do + local success, result = pcall(string.find, event[name], pattern); + if success and result then + self.log:info('[', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); + points = (points or 0) + 1; + end + end + + return points; +end + + +function Perimeter.append_blacklist_file(self, event) + local blacklist = io.open(self.blacklist_file, 'a'); + if not blacklist then + self.log:error('[', event.sequence, '] PERIMETER_APPEND_BLACKLIST - could not open file: ', self.blacklist_file); + return false; + end + + event.date = self:format_date(event.timestamp); + + if self.blacklist_file_comment then + blacklist:write(self:expand_variables(self.blacklist_file_comment, event), '\n'); + end + + self.log:debug('[', event.sequence, '] PERIMETER_APPEND_BLACKLIST - ip: ', event.received_ip); + blacklist:write(self:expand_variables(self.blacklist_file_entry, event), '\n'); + blacklist:close(); +end + + +function Perimeter.execute_ban(self, event) + local command = self:expand_variables(self.ban_command, event); + self.log:debug('[', event.sequence, '] PERIMETER_EXECUTE_BAN - ip: ', event.received_ip, ', command: ', command); + local result = os.execute(command); +end + + +function Perimeter.expand_variables(self, line, variables) + return (line:gsub('{([%a%d%._]+)}', function(captured) + return variables[captured] or ''; + end)) +end -- cgit v1.2.3 From b7368f4471cb4be3ea81f1ade5962e039ce4ef9f Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:29:46 +0100 Subject: perimeter defense class added --- .../freeswitch/scripts/event/perimeter_defense.lua | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 misc/freeswitch/scripts/event/perimeter_defense.lua diff --git a/misc/freeswitch/scripts/event/perimeter_defense.lua b/misc/freeswitch/scripts/event/perimeter_defense.lua new file mode 100644 index 0000000..c93eb13 --- /dev/null +++ b/misc/freeswitch/scripts/event/perimeter_defense.lua @@ -0,0 +1,77 @@ +-- Gemeinschaft 5 module: perimeter defense event handler class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +function handler_class() + return PerimeterDefense +end + +PerimeterDefense = {} + +function PerimeterDefense.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.log = arg.log; + self.class = 'perimeterdefense' + self.database = arg.database; + self.domain = arg.domain; + + require 'common.perimeter'; + self.perimeter = common.perimeter.Perimeter:new(arg); + self.perimeter:setup(); + + return object; +end + + +function PerimeterDefense.event_handlers(self) + return { CUSTOM = { + ['sofia::pre_register'] = self.sofia_pre_register, + ['sofia::register_attempt'] = self.sofia_register_attempt, + ['sofia::register_failure'] = self.sofia_register_failure, + } } +end + + +function PerimeterDefense.to_record(self, event, class) + return { + class = class, + key = event:getHeader('network-ip'), + sequence = tonumber(event:getHeader('Event-Sequence')), + timestamp = tonumber(event:getHeader('Event-Date-Timestamp')), + received_ip = event:getHeader('network-ip'), + received_port = event:getHeader('network-port'), + from_user = event:getHeader('from-user'), + from_host = event:getHeader('from-host'), + to_user = event:getHeader('to-user'), + to_host = event:getHeader('to-host'), + user_agent = event:getHeader('user-agent'), + user_agent = event:getHeader('user-agent'), + username = event:getHeader('username'), + realm = event:getHeader('realm'), + auth_result = event:getHeader('auth-result'), + contact = event:getHeader('contact'), + }; +end + + +function PerimeterDefense.sofia_pre_register(self, event) + local record = self:to_record(event, 'pre_register'); + self.perimeter:check(record); +end + + +function PerimeterDefense.sofia_register_attempt(self, event) + local record = self:to_record(event, 'register_attempt'); + self.perimeter:check(record); +end + + +function PerimeterDefense.sofia_register_failure(self, event) + local record = self:to_record(event, 'register_failure'); + self.perimeter:check(record); +end -- cgit v1.2.3 From 775dc19b31c8d9304c571187464f936f4f337064 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:30:15 +0100 Subject: perimeter parameters added --- .../20130203165800_add_perimeter_parameters.rb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 db/migrate/20130203165800_add_perimeter_parameters.rb diff --git a/db/migrate/20130203165800_add_perimeter_parameters.rb b/db/migrate/20130203165800_add_perimeter_parameters.rb new file mode 100644 index 0000000..9ef41d0 --- /dev/null +++ b/db/migrate/20130203165800_add_perimeter_parameters.rb @@ -0,0 +1,23 @@ +class AddPerimeterParameters < ActiveRecord::Migration + def up + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'contact_count_threshold', :value => '10', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'contact_span_threshold', :value => '2', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'name_changes_threshold', :value => '2', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_threshold', :value => '20', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_tries', :value => '2', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'blacklist_file', :value => '/var/opt/gemeinschaft/firewall/blacklist', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'blacklist_file_comment', :value => '# PERIMETER_BAN - points: {points}, generated: {date}', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'blacklist_file_entry', :value => '{received_ip} udp 5060', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_command', :value => 'sudo /sbin/service shorewall refresh', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks', :name => 'check_frequency', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks', :name => 'check_username_scan', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks', :name => 'check_bad_headers', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers', :name => 'user_agent', :value => '^friendly.scanner$', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers', :name => 'to_user', :value => '^%d+', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers', :name => 'auth_result', :value => '^FORBIDDEN$', :class_type => 'String', :description => '') + end + + def down + GsParameter.where(:entity => 'perimeter').destroy_all + end +end -- cgit v1.2.3 From f0716d611fd0cdf332ab5a11189034876a69b2df Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:30:51 +0100 Subject: migration fixed --- db/migrate/20130130185300_add_no_copy_headers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20130130185300_add_no_copy_headers.rb b/db/migrate/20130130185300_add_no_copy_headers.rb index c2c5c90..aa96653 100644 --- a/db/migrate/20130130185300_add_no_copy_headers.rb +++ b/db/migrate/20130130185300_add_no_copy_headers.rb @@ -4,6 +4,6 @@ class AddNoCopyHeaders < ActiveRecord::Migration end def down - GsParameter.create(:entity => 'dialplan', :section => 'variables', :name => 'sip_copy_custom_headers').destroy_all + GsParameter.where(:entity => 'dialplan', :section => 'variables', :name => 'sip_copy_custom_headers').destroy_all end end -- cgit v1.2.3 From 7eaa39014d7934e8cc19001dc0da95095a73a632 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:32:55 +0100 Subject: old perimeter version removed --- misc/freeswitch/scripts/event/perimeter.lua | 107 ---------------------------- 1 file changed, 107 deletions(-) delete mode 100644 misc/freeswitch/scripts/event/perimeter.lua diff --git a/misc/freeswitch/scripts/event/perimeter.lua b/misc/freeswitch/scripts/event/perimeter.lua deleted file mode 100644 index 5bbb032..0000000 --- a/misc/freeswitch/scripts/event/perimeter.lua +++ /dev/null @@ -1,107 +0,0 @@ --- Gemeinschaft 5 module: cdr event handler class --- (c) AMOOMA GmbH 2012-2013 --- - -module(...,package.seeall) - - -function handler_class() - return Perimeter -end - - - -Perimeter = {} - -MALICIOUS_CONTACT_COUNT = 20; -MALICIOUS_CONTACT_TIME_SPAN = 2; -BAN_FUTILE = 2; - -function Perimeter.new(self, arg) - arg = arg or {} - object = arg.object or {} - setmetatable(object, self); - self.__index = self; - self.log = arg.log; - self.class = 'cdrsave' - self.database = arg.database; - self.domain = arg.domain; - - self.ip_address_table = {} - self:init(); - - return object; -end - - -function Perimeter.event_handlers(self) - return { CUSTOM = { ['sofia::pre_register'] = self.sofia_pre_register } } -end - - -function Perimeter.init(self) - 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; - self.ban_futile = tonumber(config.general.ban_futile) or BAN_FUTILE; - self.execute = config.general.execute; - end - - self.log:info('[perimeter] PERIMETER - setup perimeter defense - config: ', self.malicious_contact_count, '/', self.malicious_contact_time_span, ', execute: ', self.execute); -end - - -function Perimeter.sofia_pre_register(self, event) - local ip_address = event:getHeader('network-ip'); - self:check_ip(ip_address); -end - - -function Perimeter.check_ip(self, ip_address) - local event_time = os.time(); - - if not self.ip_address_table[ip_address] then - self.ip_address_table[ip_address] = { last_contact = event_time, contact_count = 0, start_stamp = event_time, banned = 0 } - end - - local ip_record = self.ip_address_table[ip_address]; - ip_record.last_contact = event_time; - ip_record.contact_count = ip_record.contact_count + 1; - - if ip_record.contact_count > MALICIOUS_CONTACT_COUNT then - if (event_time - ip_record.start_stamp) <= MALICIOUS_CONTACT_TIME_SPAN then - self.log:warning('[', ip_address, '] PERIMETER - too many registration attempts'); - ip_record.start_stamp = event_time; - ip_record.contact_count = 0; - if ip_record.banned < BAN_FUTILE then - ip_record.banned = ip_record.banned + 1; - self:ban_ip(ip_address); - else - self.log:error('[', ip_address, '] PERIMETER - ban futile'); - end - end - end -end - - -function Perimeter.ban_ip(self, ip_address) - self.ip_address = ip_address; - - if self.execute then - local command = self:expand_variables(self.execute); - self.log:debug('[', ip_address, '] PERIMETER - execute: ', command); - local result = os.execute(command); - if tostring(result) == '0' then - self.log:warning('[', ip_address, '] PERIMETER - IP banned'); - end - end -end - - -function Perimeter.expand_variables(self, line) - return (line:gsub('{([%a%d_-]+)}', function(captured) - return self[captured]; - end)) -end -- cgit v1.2.3 From 8ba73e0d84c74e22ee91dcdd7c855514d0dd0e99 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:45:59 +0100 Subject: remove_perimeter_parameters migration added --- db/migrate/20130203164500_remove_perimeter_parameters.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 db/migrate/20130203164500_remove_perimeter_parameters.rb diff --git a/db/migrate/20130203164500_remove_perimeter_parameters.rb b/db/migrate/20130203164500_remove_perimeter_parameters.rb new file mode 100644 index 0000000..15838bb --- /dev/null +++ b/db/migrate/20130203164500_remove_perimeter_parameters.rb @@ -0,0 +1,10 @@ +class StartPerimeterDefense < ActiveRecord::Migration + def up + module_index = GsParameter.where(:entity => 'events', :section => 'modules').all.count + 1; + GsParameter.create(:entity => 'events', :section => 'modules', :name => 'perimeter_defense', :value => module_index, :class_type => 'Integer') + end + + def down + GsParameter.where(:entity => 'events', :section => 'modules', :name => 'perimeter_defense').destroy_all + end +end -- cgit v1.2.3 From b8576b59e912905f3e30e0d69ca2d4df013bc313 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:46:22 +0100 Subject: start perimeter migration added --- db/migrate/20130203174300_start_perimeter_defense.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 db/migrate/20130203174300_start_perimeter_defense.rb diff --git a/db/migrate/20130203174300_start_perimeter_defense.rb b/db/migrate/20130203174300_start_perimeter_defense.rb new file mode 100644 index 0000000..15838bb --- /dev/null +++ b/db/migrate/20130203174300_start_perimeter_defense.rb @@ -0,0 +1,10 @@ +class StartPerimeterDefense < ActiveRecord::Migration + def up + module_index = GsParameter.where(:entity => 'events', :section => 'modules').all.count + 1; + GsParameter.create(:entity => 'events', :section => 'modules', :name => 'perimeter_defense', :value => module_index, :class_type => 'Integer') + end + + def down + GsParameter.where(:entity => 'events', :section => 'modules', :name => 'perimeter_defense').destroy_all + end +end -- cgit v1.2.3 From 53fcddfc40f84d8fd12872e751233cb034e2832f Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 18:50:10 +0100 Subject: remove_perimeter_parameters migration fixed --- db/migrate/20130203164500_remove_perimeter_parameters.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/db/migrate/20130203164500_remove_perimeter_parameters.rb b/db/migrate/20130203164500_remove_perimeter_parameters.rb index 15838bb..8c37174 100644 --- a/db/migrate/20130203164500_remove_perimeter_parameters.rb +++ b/db/migrate/20130203164500_remove_perimeter_parameters.rb @@ -1,10 +1,16 @@ -class StartPerimeterDefense < ActiveRecord::Migration +class RemovePerimeterParameters < ActiveRecord::Migration def up - module_index = GsParameter.where(:entity => 'events', :section => 'modules').all.count + 1; - GsParameter.create(:entity => 'events', :section => 'modules', :name => 'perimeter_defense', :value => module_index, :class_type => 'Integer') + GsParameter.where(:entity => 'perimeter', :section => 'general', :name => 'malicious_contact_count').destroy_all + GsParameter.where(:entity => 'perimeter', :section => 'general', :name => 'malicious_contact_time_span').destroy_all + GsParameter.where(:entity => 'perimeter', :section => 'general', :name => 'ban_futile').destroy_all + GsParameter.where(:entity => 'perimeter', :section => 'general', :name => 'execute').destroy_all + end def down - GsParameter.where(:entity => 'events', :section => 'modules', :name => 'perimeter_defense').destroy_all + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'malicious_contact_count', :value => 20, :class_type => 'Integer') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'malicious_contact_time_span', :value => 2, :class_type => 'Integer') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_futile', :value => 5, :class_type => 'Integer') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'execute', :value => 'sudo /usr/local/bin/ban_ip.sh {ip_address}', :class_type => 'String') end end -- cgit v1.2.3 From 077234ab170416d8aac9bf5887aa2093b2d9c5c9 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 19:31:18 +0100 Subject: better logging --- misc/freeswitch/scripts/common/perimeter.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index d930514..5623b40 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -91,7 +91,7 @@ end function Perimeter.check(self, event) event.record = self:record_load(event); - -- self.log:debug('[', event.sequence, '] PERIMETER_CHECK - received: ', event.received_ip, ':', event.received_port, ', contacts: ', event.record.contact_count, ', since: ', self:format_date(event.record.contact_first), ', points: ', event.record.points); + -- self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_CHECK - received: ', event.received_ip, ':', event.received_port, ', contacts: ', event.record.contact_count, ', since: ', self:format_date(event.record.contact_first), ', points: ', event.record.points); if event.record.banned <= self.ban_tries then for check_name, check_points in pairs(self.checks) do @@ -106,9 +106,9 @@ function Perimeter.check(self, event) if (event.points or event.record.points) > self.ban_threshold and event.record.banned <= self.ban_tries then if event.record.banned > 0 and event.record.banned == self.ban_tries then - self.log:warning('[', event.sequence, '] PERIMETER_BAN_FUTILE - points: ', event.points,', event: ', event.class, ', ip: ', event.received_ip, ', to: ', event.to_user, '@', event.to_host); + self.log:warning('[', event.key, '/', event.sequence, '] PERIMETER_BAN_FUTILE - points: ', event.points,', event: ', event.class, ', from: ', event.from_user, '@', event.from_host, ', to: ', event.to_user, '@', event.to_host); else - self.log:notice('[', event.sequence, '] PERIMETER_BAN - threshold reached: ', event.points,', event: ', event.class, ', ip: ', event.received_ip, ', to: ', event.to_user, '@', event.to_host); + self.log:notice('[', event.key, '/', event.sequence, '] PERIMETER_BAN - threshold reached: ', event.points,', event: ', event.class, ', from: ', event.from_user, '@', event.from_host, ', to: ', event.to_user, '@', event.to_host); if event.record.banned == 0 then self:append_blacklist_file(event); end @@ -127,7 +127,7 @@ end function Perimeter.check_frequency(self, event) if event.record.span_contact_count >= self.contact_count_threshold then - self.log:info('[', event.sequence, '] PERIMETER_FREQUENCY_CHECK - contacts: ', event.record.span_contact_count, ' in < ', (event.timestamp - event.record.span_start)/1000000, ' sec, threshold: ', self.contact_count_threshold, ' in ', self.contact_span_threshold, ' sec'); + self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_FREQUENCY_CHECK - contacts: ', event.record.span_contact_count, ' in < ', (event.timestamp - event.record.span_start)/1000000, ' sec, threshold: ', self.contact_count_threshold, ' in ', self.contact_span_threshold, ' sec'); event.span_contact_count = 0; event.span_start = event.timestamp; return 1; @@ -149,7 +149,7 @@ function Perimeter.check_username_scan(self, event) end if #event.record.users >= self.name_changes_threshold then - self.log:info('[', event.sequence, '] PERIMETER_USER_SCAN - user names: ', #event.record.users, ', threshold: ', self.name_changes_threshold); + self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_USER_SCAN - user names: ', #event.record.users, ', threshold: ', self.name_changes_threshold); event.users = {}; return 1; else @@ -172,7 +172,7 @@ function Perimeter.check_bad_headers(self, event) for name, pattern in pairs(self.bad_headers) do local success, result = pcall(string.find, event[name], pattern); if success and result then - self.log:info('[', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); + self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); points = (points or 0) + 1; end end @@ -184,7 +184,7 @@ end function Perimeter.append_blacklist_file(self, event) local blacklist = io.open(self.blacklist_file, 'a'); if not blacklist then - self.log:error('[', event.sequence, '] PERIMETER_APPEND_BLACKLIST - could not open file: ', self.blacklist_file); + self.log:error('[', event.key, '/', event.sequence, '] PERIMETER_APPEND_BLACKLIST - could not open file: ', self.blacklist_file); return false; end @@ -194,7 +194,7 @@ function Perimeter.append_blacklist_file(self, event) blacklist:write(self:expand_variables(self.blacklist_file_comment, event), '\n'); end - self.log:debug('[', event.sequence, '] PERIMETER_APPEND_BLACKLIST - ip: ', event.received_ip); + self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_APPEND_BLACKLIST - file: ', self.blacklist_file); blacklist:write(self:expand_variables(self.blacklist_file_entry, event), '\n'); blacklist:close(); end @@ -202,7 +202,7 @@ end function Perimeter.execute_ban(self, event) local command = self:expand_variables(self.ban_command, event); - self.log:debug('[', event.sequence, '] PERIMETER_EXECUTE_BAN - ip: ', event.received_ip, ', command: ', command); + self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_EXECUTE_BAN - command: ', command); local result = os.execute(command); end -- cgit v1.2.3 From ecdbd88b2059ccfcf79e000d07efb9ffddde9aed Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 20:03:28 +0100 Subject: try to ban only once --- db/migrate/20130203165800_add_perimeter_parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20130203165800_add_perimeter_parameters.rb b/db/migrate/20130203165800_add_perimeter_parameters.rb index 9ef41d0..d229b29 100644 --- a/db/migrate/20130203165800_add_perimeter_parameters.rb +++ b/db/migrate/20130203165800_add_perimeter_parameters.rb @@ -4,7 +4,7 @@ class AddPerimeterParameters < ActiveRecord::Migration GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'contact_span_threshold', :value => '2', :class_type => 'Integer', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'name_changes_threshold', :value => '2', :class_type => 'Integer', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_threshold', :value => '20', :class_type => 'Integer', :description => '') - GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_tries', :value => '2', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_tries', :value => '1', :class_type => 'Integer', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'blacklist_file', :value => '/var/opt/gemeinschaft/firewall/blacklist', :class_type => 'String', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'blacklist_file_comment', :value => '# PERIMETER_BAN - points: {points}, generated: {date}', :class_type => 'String', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'blacklist_file_entry', :value => '{received_ip} udp 5060', :class_type => 'String', :description => '') -- cgit v1.2.3 From f1ccee494495e4149d0b892743b0d60612d8d790 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 20:04:16 +0100 Subject: reset username list after successful registration --- misc/freeswitch/scripts/common/perimeter.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index 5623b40..5de86bf 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -143,7 +143,7 @@ function Perimeter.check_username_scan(self, event) return; end - if not event.record.users then + if not event.record.users or tostring(event.auth_result) == 'SUCCESS' or tostring(event.auth_result) == 'RENEWED' then event.users = { event.to_user }; return; end -- cgit v1.2.3 From 947d4a71a17518b734c32a148617bef15a42fed1 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 3 Feb 2013 22:03:45 +0100 Subject: threshold changed --- db/migrate/20130203165800_add_perimeter_parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20130203165800_add_perimeter_parameters.rb b/db/migrate/20130203165800_add_perimeter_parameters.rb index d229b29..23e0157 100644 --- a/db/migrate/20130203165800_add_perimeter_parameters.rb +++ b/db/migrate/20130203165800_add_perimeter_parameters.rb @@ -2,7 +2,7 @@ class AddPerimeterParameters < ActiveRecord::Migration def up GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'contact_count_threshold', :value => '10', :class_type => 'Integer', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'contact_span_threshold', :value => '2', :class_type => 'Integer', :description => '') - GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'name_changes_threshold', :value => '2', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'name_changes_threshold', :value => '5', :class_type => 'Integer', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_threshold', :value => '20', :class_type => 'Integer', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_tries', :value => '1', :class_type => 'Integer', :description => '') GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'blacklist_file', :value => '/var/opt/gemeinschaft/firewall/blacklist', :class_type => 'String', :description => '') -- cgit v1.2.3 From 0db4c7250feab288018d42cbd5c7d12657d60e3a Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 4 Feb 2013 09:39:42 +0100 Subject: check calls --- .../20130204065900_split_perimeter_parameters.rb | 30 +++++++++++++ misc/freeswitch/scripts/common/perimeter.lua | 23 ++++++---- .../freeswitch/scripts/event/perimeter_defense.lua | 51 +++++++++++++++++++--- 3 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20130204065900_split_perimeter_parameters.rb diff --git a/db/migrate/20130204065900_split_perimeter_parameters.rb b/db/migrate/20130204065900_split_perimeter_parameters.rb new file mode 100644 index 0000000..b29bb29 --- /dev/null +++ b/db/migrate/20130204065900_split_perimeter_parameters.rb @@ -0,0 +1,30 @@ +class SplitPerimeterParameters < ActiveRecord::Migration + def up + GsParameter.where(:entity => 'perimeter', :section => 'checks').destroy_all + GsParameter.where(:entity => 'perimeter', :section => 'bad_headers').destroy_all + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'ban_command', :value => 'sudo /sbin/service shorewall refresh', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks_register', :name => 'check_frequency', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks_register', :name => 'check_username_scan', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks_register', :name => 'check_bad_headers', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks_call', :name => 'check_frequency', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks_call', :name => 'check_bad_headers', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers_register', :name => 'user_agent', :value => '^friendly.scanner$', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers_register', :name => 'to_user', :value => '^%d+', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers_register', :name => 'auth_result', :value => '^FORBIDDEN$', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers_call', :name => 'user_agent', :value => '^friendly.scanner$', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers_call', :name => 'hangup_cause', :value => '^MANDATORY_IE_MISSING', :class_type => 'String', :description => '') + end + + def down + GsParameter.where(:entity => 'perimeter', :section => 'checks_register').destroy_all + GsParameter.where(:entity => 'perimeter', :section => 'checks_call').destroy_all + GsParameter.where(:entity => 'perimeter', :section => 'bad_headers_register').destroy_all + GsParameter.where(:entity => 'perimeter', :section => 'bad_headers_call').destroy_all + GsParameter.create(:entity => 'perimeter', :section => 'checks', :name => 'check_frequency', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks', :name => 'check_username_scan', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'checks', :name => 'check_bad_headers', :value => '1', :class_type => 'Integer', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers', :name => 'user_agent', :value => '^friendly.scanner$', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers', :name => 'to_user', :value => '^%d+', :class_type => 'String', :description => '') + GsParameter.create(:entity => 'perimeter', :section => 'bad_headers', :name => 'auth_result', :value => '^FORBIDDEN$', :class_type => 'String', :description => '') + end +end diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index 5de86bf..0670fee 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -42,6 +42,8 @@ function Perimeter.setup(self, event) self.ban_command = 'sudo /sbin/service shorewall refresh'; self.ban_threshold = 20; self.ban_tries = 1; + self.checks = { register = {}, call = {} }; + self.bad_headers = { register = {}, call = {} }; if config and config.general then for key, value in pairs(config.general) do @@ -49,8 +51,10 @@ function Perimeter.setup(self, event) end end - self.checks = config.checks; - self.bad_headers = config.bad_headers; + self.checks.register = config.checks_register or {}; + self.checks.call = config.checks_call or {}; + self.bad_headers.register = config.bad_headers_register; + self.bad_headers.call = config.bad_headers_call; self.log:info('[perimeter] PERIMETER - setup perimeter defense'); end @@ -66,7 +70,7 @@ function Perimeter.record_load(self, event) span_start = event.timestamp, points = 0, banned = 0, - } + }; end return self.sources[event.key]; @@ -90,11 +94,14 @@ end function Perimeter.check(self, event) - event.record = self:record_load(event); - -- self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_CHECK - received: ', event.received_ip, ':', event.received_port, ', contacts: ', event.record.contact_count, ', since: ', self:format_date(event.record.contact_first), ', points: ', event.record.points); - + if not event or not event.key then + self.log:warning('[perimeter] PERIMETER_CHECK - no event/key'); + return; + end + + event.record = self:record_load(event); if event.record.banned <= self.ban_tries then - for check_name, check_points in pairs(self.checks) do + for check_name, check_points in pairs(self.checks[event.action]) do if self.checks_available[check_name] then local result = self.checks_available[check_name](self, event); if tonumber(result) then @@ -169,7 +176,7 @@ end function Perimeter.check_bad_headers(self, event) local points = nil; - for name, pattern in pairs(self.bad_headers) do + for name, pattern in pairs(self.bad_headers[event.action]) do local success, result = pcall(string.find, event[name], pattern); if success and result then self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); diff --git a/misc/freeswitch/scripts/event/perimeter_defense.lua b/misc/freeswitch/scripts/event/perimeter_defense.lua index c93eb13..acdfa8d 100644 --- a/misc/freeswitch/scripts/event/perimeter_defense.lua +++ b/misc/freeswitch/scripts/event/perimeter_defense.lua @@ -29,16 +29,20 @@ end function PerimeterDefense.event_handlers(self) - return { CUSTOM = { + return { + CUSTOM = { ['sofia::pre_register'] = self.sofia_pre_register, ['sofia::register_attempt'] = self.sofia_register_attempt, ['sofia::register_failure'] = self.sofia_register_failure, - } } + }, + CHANNEL_HANGUP = { [true] = self.channel_hangup }, + }; end -function PerimeterDefense.to_record(self, event, class) +function PerimeterDefense.to_register_record(self, event, class) return { + action = 'register', class = class, key = event:getHeader('network-ip'), sequence = tonumber(event:getHeader('Event-Sequence')), @@ -50,7 +54,6 @@ function PerimeterDefense.to_record(self, event, class) to_user = event:getHeader('to-user'), to_host = event:getHeader('to-host'), user_agent = event:getHeader('user-agent'), - user_agent = event:getHeader('user-agent'), username = event:getHeader('username'), realm = event:getHeader('realm'), auth_result = event:getHeader('auth-result'), @@ -59,19 +62,53 @@ function PerimeterDefense.to_record(self, event, class) end +function PerimeterDefense.to_call_record(self, event, class) + return { + action = 'call', + class = class, + key = event:getHeader('Caller-Network-Addr'), + sequence = tonumber(event:getHeader('Event-Sequence')), + timestamp = tonumber(event:getHeader('Event-Date-Timestamp')), + received_ip = event:getHeader('Caller-Network-Addr'), + received_port = event:getHeader('variable_sip_network_port'), + hangup_cause = event:getHeader('Hangup-Cause'), + endpoint_disposition = event:getHeader('variable_endpoint_disposition'), + direction = event:getHeader('Call-Direction'), + destination_number = event:getHeader('Caller-Destination-Number'); + caller_id_name = event:getHeader('Caller-Caller-ID-Name'); + caller_id_number = event:getHeader('Caller-Caller-ID-Number'); + from_user = event:getHeader('variable_sip_from_user'), + from_host = event:getHeader('variable_sip_from_host'), + to_user = event:getHeader('variable_sip_to_user'), + to_host = event:getHeader('variable_sip_to_host'), + req_user = event:getHeader('variable_sip_req_user'), + req_host = event:getHeader('variable_sip_req_host'), + user_agent = event:getHeader('variable_sip_user_agent'), + username = event:getHeader('Caller-Username'), + contact = event:getHeader('variable_sip_contact_uri'), + }; +end + + function PerimeterDefense.sofia_pre_register(self, event) - local record = self:to_record(event, 'pre_register'); + local record = self:to_register_record(event, 'pre_register'); self.perimeter:check(record); end function PerimeterDefense.sofia_register_attempt(self, event) - local record = self:to_record(event, 'register_attempt'); + local record = self:to_register_record(event, 'register_attempt'); self.perimeter:check(record); end function PerimeterDefense.sofia_register_failure(self, event) - local record = self:to_record(event, 'register_failure'); + local record = self:to_register_record(event, 'register_failure'); + self.perimeter:check(record); +end + + +function PerimeterDefense.channel_hangup(self, event) + local record = self:to_call_record(event, 'channel_hangup'); self.perimeter:check(record); end -- cgit v1.2.3 From 4594ac1559c6ecd534834b41b31d61c281d3401d Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 4 Feb 2013 10:01:40 +0100 Subject: expand variables --- misc/freeswitch/scripts/common/perimeter.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index 0670fee..d1eecd1 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -177,6 +177,7 @@ end function Perimeter.check_bad_headers(self, event) local points = nil; for name, pattern in pairs(self.bad_headers[event.action]) do + pattern = self:expand_variables(pattern, event); local success, result = pcall(string.find, event[name], pattern); if success and result then self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); -- cgit v1.2.3 From 66a53a49705c269d73f9d51bb0d4a51283049c71 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 4 Feb 2013 13:00:45 +0100 Subject: Changed softkey table to be sortable. #150 --- app/assets/javascripts/softkey.js.coffee | 6 ++++++ app/assets/stylesheets/application.css | 1 + app/assets/stylesheets/softkeys.css.scss | 5 +++++ app/controllers/softkeys_controller.rb | 21 +++++++++++---------- app/models/sip_account.rb | 2 +- app/views/sip_accounts/show.html.haml | 8 ++++---- app/views/softkeys/_index_core.html.haml | 32 ++++++++++++++++++-------------- config/environments/development.rb | 2 +- config/routes.rb | 11 +++++------ 9 files changed, 52 insertions(+), 36 deletions(-) create mode 100644 app/assets/javascripts/softkey.js.coffee create mode 100644 app/assets/stylesheets/softkeys.css.scss diff --git a/app/assets/javascripts/softkey.js.coffee b/app/assets/javascripts/softkey.js.coffee new file mode 100644 index 0000000..19103f0 --- /dev/null +++ b/app/assets/javascripts/softkey.js.coffee @@ -0,0 +1,6 @@ +jQuery -> + $("table tbody").sortable + axis: 'y' + handle: '.handle' + update: -> + $.post('/softkeys/sort', $(this).sortable('serialize')) \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 999afb5..128a391 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,4 +13,5 @@ *= require bootstrap/bootstrap-responsive *= require gemeinschaft-generic *= require call_routes + *= require softkeys */ diff --git a/app/assets/stylesheets/softkeys.css.scss b/app/assets/stylesheets/softkeys.css.scss new file mode 100644 index 0000000..425c6f1 --- /dev/null +++ b/app/assets/stylesheets/softkeys.css.scss @@ -0,0 +1,5 @@ +#softkeys .handle { + font-size: 12px; + color: #777; + cursor: move; +} \ No newline at end of file diff --git a/app/controllers/softkeys_controller.rb b/app/controllers/softkeys_controller.rb index 8f363cd..c9e8c20 100644 --- a/app/controllers/softkeys_controller.rb +++ b/app/controllers/softkeys_controller.rb @@ -1,9 +1,9 @@ class SoftkeysController < ApplicationController - load_and_authorize_resource :sip_account - load_and_authorize_resource :softkey, :through => [:sip_account] + load_and_authorize_resource :sip_account, :except => [:sort] + load_and_authorize_resource :softkey, :through => [:sip_account], :except => [:sort] before_filter :set_available_call_forwards_and_softkey_functions, :only => [ :new, :edit, :update ] - before_filter :spread_breadcrumbs + before_filter :spread_breadcrumbs, :except => [:sort] def index end @@ -44,16 +44,17 @@ class SoftkeysController < ApplicationController redirect_to sip_account_softkeys_path(@softkey.sip_account), :notice => t('softkeys.controller.successfuly_destroyed') end - def move_higher - @softkey.move_higher - redirect_to :back - end + def sort + sip_account = Softkey.find(params[:softkey].first).sip_account + + params[:softkey].each do |softkey_id| + sip_account.softkeys.find(softkey_id).move_to_bottom + end - def move_lower - @softkey.move_lower - redirect_to :back + render nothing: true end + private def set_available_call_forwards_and_softkey_functions diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 444eb12..9ba1f8b 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -21,7 +21,7 @@ class SipAccount < ActiveRecord::Base belongs_to :tenant belongs_to :sip_domain - has_many :softkeys, :dependent => :destroy + has_many :softkeys, :dependent => :destroy, :order => :position has_many :voicemail_messages, :foreign_key => 'username', :primary_key => 'auth_name' diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index 72e10df..f48d927 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -65,16 +65,16 @@ = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @sip_account.sip_accountable, :child => @sip_account } -- if @sip_account.phone_numbers.count > 0 || can?(:create, @sip_account.phone_numbers.build) +- if @sip_account.phone_numbers.any? || can?(:create, @sip_account.phone_numbers.build) %h2= t('phone_numbers.index.page_title') - - if @sip_account.phone_numbers.count > 0 + - if @sip_account.phone_numbers.any? = render "phone_numbers/index_core", :phone_numbers => @sip_account.phone_numbers %br = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => PhoneNumber } -- if @sip_account.softkeys.count > 0 || can?(:create, @sip_account.softkeys.build) +- if @sip_account.softkeys.any? || can?(:create, @sip_account.softkeys.build) %h2= t("softkeys.index.page_title") - - if @sip_account.softkeys.count > 0 + - if @sip_account.softkeys.any? = render "softkeys/index_core", :softkeys => @sip_account.softkeys %br = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Softkey } \ No newline at end of file diff --git a/app/views/softkeys/_index_core.html.haml b/app/views/softkeys/_index_core.html.haml index 398ee51..4ebb29c 100644 --- a/app/views/softkeys/_index_core.html.haml +++ b/app/views/softkeys/_index_core.html.haml @@ -1,15 +1,19 @@ -%table.table.table-striped - %thead - %tr - %th= t('softkeys.index.function') - %th= t('softkeys.index.number') - %th= t('softkeys.index.label') - - %tbody - - for softkey in softkeys.order(:position) +- cache(['softkeys', I18n.locale, current_user, softkeys]) do + %table.table.table-striped{ :id => "softkeys" } + %thead %tr - %td - =softkey.to_s - %td= softkey.number - %td= softkey.label - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => softkey.sip_account, :child => softkey} \ No newline at end of file + %th + %th= t('softkeys.index.function') + %th= t('softkeys.index.number') + %th= t('softkeys.index.label') + + %tbody + - for softkey in softkeys + = content_tag_for :tr, softkey do + %td + %span.handle + %i.icon-resize-vertical + %td= softkey.function + %td= softkey.number + %td= softkey.label + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => softkey.sip_account, :child => softkey} \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index e677834..1a3acae 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,7 +13,7 @@ Gemeinschaft42c::Application.configure do config.consider_all_requests_local = true # Enable caching for development - config.action_controller.perform_caching = false + config.action_controller.perform_caching = true CacheDigests::TemplateDigestor.cache = ActiveSupport::Cache::NullStore.new # Don't care if the mailer can't send diff --git a/config/routes.rb b/config/routes.rb index 9a3b3a3..1ad621e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -271,6 +271,10 @@ Gemeinschaft42c::Application.routes.draw do end end + resources :softkeys, :only => [ :sort ] do + collection { post :sort } + end + resources :sip_accounts, :only => [] do resources :phones_sip_accounts resources :phone_numbers do @@ -279,12 +283,7 @@ Gemeinschaft42c::Application.routes.draw do put 'move_lower' end end - resources :softkeys do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :softkeys resources :call_histories do collection do delete 'destroy_multiple' -- cgit v1.2.3 From 242470bdb4fa67780e7467c6889b7869dff05d1c Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 4 Feb 2013 13:10:52 +0100 Subject: better logging --- misc/freeswitch/scripts/common/perimeter.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index d1eecd1..de3f993 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -111,6 +111,14 @@ function Perimeter.check(self, event) end end + if tonumber(event.points) and event.points < 0 then + event.points = 0; + end + + if event.points then + self.log:info('[', event.key, '/', event.sequence, '] PERIMETER suspicion rising - points: ', event.points,', ', event.action, '=', event.class, ', from: ', event.from_user, '@', event.from_host, ', to: ', event.to_user, '@', event.to_host, ', user_agent: ', event.user_agent); + end + if (event.points or event.record.points) > self.ban_threshold and event.record.banned <= self.ban_tries then if event.record.banned > 0 and event.record.banned == self.ban_tries then self.log:warning('[', event.key, '/', event.sequence, '] PERIMETER_BAN_FUTILE - points: ', event.points,', event: ', event.class, ', from: ', event.from_user, '@', event.from_host, ', to: ', event.to_user, '@', event.to_host); @@ -134,7 +142,7 @@ end function Perimeter.check_frequency(self, event) if event.record.span_contact_count >= self.contact_count_threshold then - self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_FREQUENCY_CHECK - contacts: ', event.record.span_contact_count, ' in < ', (event.timestamp - event.record.span_start)/1000000, ' sec, threshold: ', self.contact_count_threshold, ' in ', self.contact_span_threshold, ' sec'); + self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_FREQUENCY_CHECK - contacts: ', event.record.span_contact_count, ' in < ', (event.timestamp - event.record.span_start)/1000000, ' sec, threshold: ', self.contact_count_threshold, ' in ', self.contact_span_threshold, ' sec'); event.span_contact_count = 0; event.span_start = event.timestamp; return 1; @@ -156,7 +164,7 @@ function Perimeter.check_username_scan(self, event) end if #event.record.users >= self.name_changes_threshold then - self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_USER_SCAN - user names: ', #event.record.users, ', threshold: ', self.name_changes_threshold); + self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_USER_SCAN - user names: ', #event.record.users, ', threshold: ', self.name_changes_threshold); event.users = {}; return 1; else @@ -180,7 +188,7 @@ function Perimeter.check_bad_headers(self, event) pattern = self:expand_variables(pattern, event); local success, result = pcall(string.find, event[name], pattern); if success and result then - self.log:info('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); + self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern); points = (points or 0) + 1; end end -- cgit v1.2.3 From 636be20a183fac10637fea700f55f89bc371577b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 4 Feb 2013 13:51:15 +0100 Subject: Refactoring and bugfixes. --- app/assets/javascripts/call_route.js.coffee | 4 +- app/assets/javascripts/softkey.js.coffee | 4 +- app/controllers/call_routes_controller.rb | 3 +- app/views/call_routes/_index_core.html.haml | 60 ++++++++++++++--------------- app/views/softkeys/_index_core.html.haml | 23 +++++------ config/environments/development.rb | 2 +- 6 files changed, 49 insertions(+), 47 deletions(-) diff --git a/app/assets/javascripts/call_route.js.coffee b/app/assets/javascripts/call_route.js.coffee index f41d65b..91d62ca 100644 --- a/app/assets/javascripts/call_route.js.coffee +++ b/app/assets/javascripts/call_route.js.coffee @@ -1,6 +1,6 @@ jQuery -> - $("table tbody").sortable + $('#call_routes').sortable axis: 'y' handle: '.handle' update: -> - $.post('call_routes/sort', $(this).sortable('serialize')) \ No newline at end of file + $.post($(this).data('update-url'), $(this).sortable('serialize')) \ No newline at end of file diff --git a/app/assets/javascripts/softkey.js.coffee b/app/assets/javascripts/softkey.js.coffee index 19103f0..a8d2d0c 100644 --- a/app/assets/javascripts/softkey.js.coffee +++ b/app/assets/javascripts/softkey.js.coffee @@ -1,6 +1,6 @@ jQuery -> - $("table tbody").sortable + $('#softkeys').sortable axis: 'y' handle: '.handle' update: -> - $.post('/softkeys/sort', $(this).sortable('serialize')) \ No newline at end of file + $.post($(this).data('update-url'), $(this).sortable('serialize')) \ No newline at end of file diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 779e23c..661ceba 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -1,5 +1,5 @@ class CallRoutesController < ApplicationController - authorize_resource :call_route + authorize_resource :call_route, :except => [:sort] # before_filter { |controller| # if !params[:call_route].blank? and !params[:call_route][:endpoint_str].blank? @@ -67,6 +67,7 @@ class CallRoutesController < ApplicationController def sort params[:call_route].each_with_index do |id, index| CallRoute.update_all({position: index+1}, {id: id}) + #CallRoute.find(:id).move_to_bottom end render nothing: true end diff --git a/app/views/call_routes/_index_core.html.haml b/app/views/call_routes/_index_core.html.haml index 9eae9ee..b6c5d33 100644 --- a/app/views/call_routes/_index_core.html.haml +++ b/app/views/call_routes/_index_core.html.haml @@ -1,31 +1,31 @@ -/ - cache(['call_routes_table', call_routes.count, call_routes.reorder(:updated_at).last]) do -%table.table.table-striped{ :id => "call_routes" } - %thead - %tr - %th - %th= t('call_routes.index.name') - %th= t('route_elements.index.pattern') - %th= t('call_routes.index.endpoint') +- cache(['call_routes_table', I18n.locale, call_routes.count, call_routes.reorder(:updated_at).last]) do + %table.table.table-striped + %thead + %tr + %th + %th= t('call_routes.index.name') + %th= t('route_elements.index.pattern') + %th= t('call_routes.index.endpoint') - %tbody - - for call_route in call_routes - / - cache(['call_route_single_table_row', call_route, call_routes.count]) do - = content_tag_for :tr, call_route do - %td - %span.handle - %i.icon-resize-vertical - %td= call_route.name - %td - - if call_route.route_elements.any? - = call_route.route_elements.first.pattern - - if call_route.route_elements.count > 1 - = ', ...' - - else - = '-' - %td - - endpoint = call_route.endpoint - - if endpoint - = endpoint - - else - = call_route.endpoint_type - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => call_route} + %tbody{ :id => "call_routes", :'data-update-url' => sort_call_routes_url} + - for call_route in call_routes + - cache(['call_route_single_table_row', I18n.locale, call_route]) do + = content_tag_for :tr, call_route do + %td + %span.handle + %i.icon-resize-vertical + %td= call_route.name + %td + - if call_route.route_elements.any? + = call_route.route_elements.first.pattern + - if call_route.route_elements.count > 1 + = ', ...' + - else + = '-' + %td + - endpoint = call_route.endpoint + - if endpoint + = endpoint + - else + = call_route.endpoint_type + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => call_route} diff --git a/app/views/softkeys/_index_core.html.haml b/app/views/softkeys/_index_core.html.haml index 4ebb29c..70c96bc 100644 --- a/app/views/softkeys/_index_core.html.haml +++ b/app/views/softkeys/_index_core.html.haml @@ -1,5 +1,5 @@ -- cache(['softkeys', I18n.locale, current_user, softkeys]) do - %table.table.table-striped{ :id => "softkeys" } +- cache(['softkeys_table', I18n.locale, current_user, softkeys]) do + %table.table.table-striped %thead %tr %th @@ -7,13 +7,14 @@ %th= t('softkeys.index.number') %th= t('softkeys.index.label') - %tbody + %tbody{ :id => "softkeys", :'data-update-url' => sort_softkeys_url} - for softkey in softkeys - = content_tag_for :tr, softkey do - %td - %span.handle - %i.icon-resize-vertical - %td= softkey.function - %td= softkey.number - %td= softkey.label - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => softkey.sip_account, :child => softkey} \ No newline at end of file + - cache(['softkeys_table_tr', I18n.locale, current_user, softkey]) do + = content_tag_for :tr, softkey do + %td + %span.handle + %i.icon-resize-vertical + %td= softkey.function + %td= softkey.number + %td= softkey.label + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => softkey.sip_account, :child => softkey} \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 1a3acae..e677834 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,7 +13,7 @@ Gemeinschaft42c::Application.configure do config.consider_all_requests_local = true # Enable caching for development - config.action_controller.perform_caching = true + config.action_controller.perform_caching = false CacheDigests::TemplateDigestor.cache = ActiveSupport::Cache::NullStore.new # Don't care if the mailer can't send -- cgit v1.2.3 From 5a58c0c41de983a72cdacd06c5be80f120d1e080 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 4 Feb 2013 13:58:20 +0100 Subject: Bugfix #157 --- app/controllers/call_routes_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index 661ceba..3977132 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -1,11 +1,11 @@ class CallRoutesController < ApplicationController authorize_resource :call_route, :except => [:sort] - # before_filter { |controller| - # if !params[:call_route].blank? and !params[:call_route][:endpoint_str].blank? - # params[:call_route][:endpoint_type], delimeter, params[:call_route][:endpoint_id] = params[:call_route][:endpoint_str].partition('=') - # end - # } + before_filter { |controller| + if !params[:call_route].blank? && !params[:call_route][:endpoint_str].blank? + params[:call_route][:endpoint_type], delimeter, params[:call_route][:endpoint_id] = params[:call_route][:endpoint_str].partition('=') + end + } def index @call_routes = CallRoute.order([:routing_table, :position]) -- cgit v1.2.3 From 3dead8f9bd964c7330f193cbec82afe44db4149d Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 4 Feb 2013 14:23:26 +0100 Subject: intermediate step --- app/assets/javascripts/phone_number.js.coffee | 6 ++ app/assets/stylesheets/application.css | 1 + app/assets/stylesheets/phone_numbers.css.scss | 5 ++ app/controllers/phone_numbers_controller.rb | 45 +++++++-------- app/views/phone_numbers/_index_core.html.haml | 8 ++- config/routes.rb | 83 +++++---------------------- 6 files changed, 54 insertions(+), 94 deletions(-) create mode 100644 app/assets/javascripts/phone_number.js.coffee create mode 100644 app/assets/stylesheets/phone_numbers.css.scss diff --git a/app/assets/javascripts/phone_number.js.coffee b/app/assets/javascripts/phone_number.js.coffee new file mode 100644 index 0000000..ee983ee --- /dev/null +++ b/app/assets/javascripts/phone_number.js.coffee @@ -0,0 +1,6 @@ +jQuery -> + $('#phone_numbers').sortable + axis: 'y' + handle: '.handle' + update: -> + $.post($(this).data('update-url'), $(this).sortable('serialize')) \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 128a391..3e1cc66 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -14,4 +14,5 @@ *= require gemeinschaft-generic *= require call_routes *= require softkeys + *= require phone_numbers */ diff --git a/app/assets/stylesheets/phone_numbers.css.scss b/app/assets/stylesheets/phone_numbers.css.scss new file mode 100644 index 0000000..141a1f7 --- /dev/null +++ b/app/assets/stylesheets/phone_numbers.css.scss @@ -0,0 +1,5 @@ +#phone_numbers .handle { + font-size: 12px; + color: #777; + cursor: move; +} \ No newline at end of file diff --git a/app/controllers/phone_numbers_controller.rb b/app/controllers/phone_numbers_controller.rb index c562954..67c4922 100644 --- a/app/controllers/phone_numbers_controller.rb +++ b/app/controllers/phone_numbers_controller.rb @@ -1,22 +1,22 @@ class PhoneNumbersController < ApplicationController - load_resource :phone_book_entry - load_resource :sip_account - load_resource :conference - load_resource :fax_account - load_resource :phone_number_range - load_resource :callthrough - load_resource :whitelist - load_resource :access_authorization - load_resource :hunt_group - load_resource :hunt_group_member - load_resource :automatic_call_distributor - load_and_authorize_resource :phone_number, :through => [:phone_book_entry, :sip_account, :conference, + load_resource :phone_book_entry, :except => [:sort] + load_resource :sip_account, :except => [:sort] + load_resource :conference, :except => [:sort] + load_resource :fax_account, :except => [:sort] + load_resource :phone_number_range, :except => [:sort] + load_resource :callthrough, :except => [:sort] + load_resource :whitelist, :except => [:sort] + load_resource :access_authorization, :except => [:sort] + load_resource :hunt_group, :except => [:sort] + load_resource :hunt_group_member, :except => [:sort] + load_resource :automatic_call_distributor, :except => [:sort] + load_and_authorize_resource :phone_number, :except => [:sort], :through => [:phone_book_entry, :sip_account, :conference, :fax_account, :phone_number_range, :callthrough, :whitelist, :access_authorization, :hunt_group, :hunt_group_member, :automatic_call_distributor] - before_filter :set_and_authorize_parent - before_filter :spread_breadcrumbs + before_filter :set_and_authorize_parent, :except => [:sort] + before_filter :spread_breadcrumbs, :except => [:sort] def index end @@ -67,16 +67,6 @@ class PhoneNumbersController < ApplicationController redirect_to m.(), :notice => t('phone_numbers.controller.successfuly_destroyed') end - def move_higher - @phone_number.move_higher - redirect_to :back - end - - def move_lower - @phone_number.move_lower - redirect_to :back - end - def call sip_account = nil current_user.sip_accounts.each do |user_sip_account| @@ -94,6 +84,13 @@ class PhoneNumbersController < ApplicationController redirect_to(:back) end + def sort + params[:phone_number].each_with_index do |id, index| + PhoneNumber.update_all({position: index+1}, {id: id}) + end + render nothing: true + end + private def set_and_authorize_parent @parent = @phone_book_entry || @sip_account || @conference || @fax_account || diff --git a/app/views/phone_numbers/_index_core.html.haml b/app/views/phone_numbers/_index_core.html.haml index 80a1608..b68e5af 100644 --- a/app/views/phone_numbers/_index_core.html.haml +++ b/app/views/phone_numbers/_index_core.html.haml @@ -1,13 +1,17 @@ %table.table.table-striped %thead %tr + %th - if phone_numbers.count > 1 && phone_numbers.first.phone_numberable_type == 'PhoneBookEntry' %th= t('phone_numbers.index.name') %th= t('phone_numbers.index.number') - %tbody + %tbody{ :id => "phone_numbers", :'data-update-url' => sort_phone_numbers_url} - for phone_number in phone_numbers.order(:position) - %tr + = content_tag_for :tr, phone_number do + %td + %span.handle + %i.icon-resize-vertical - if phone_number.phone_numberable_type == 'PhoneBookEntry' %td= phone_number.name %td= phone_number diff --git a/config/routes.rb b/config/routes.rb index 1ad621e..fbb32f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,95 +33,54 @@ Gemeinschaft42c::Application.routes.draw do resources :rows end + resources :phone_numbers, :only => [:sort] do + collection { post :sort } + end + resources :acd_agents, :only => [] do - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end resources :automatic_call_distributors, :only => [] do resources :acd_agents - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end resources :hunt_group_members, :only => [] do - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end resources :hunt_groups, :only => [] do resources :hunt_group_members - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end if GsParameter.get('CALLTHROUGH_HAS_WHITELISTS') == true resources :whitelists, :only => [] do - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end end resources :access_authorizations, :only => [] do - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end resources :fax_documents resources :fax_accounts, :only => [] do resources :fax_documents - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end resources :gemeinschaft_setups, :only => [:new, :create] resources :phone_number_ranges, :only => [] do - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end resources :conferences, :only => [] do resources :conference_invitees - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers end resources :phone_numbers, :only => [] do @@ -260,12 +219,7 @@ Gemeinschaft42c::Application.routes.draw do resources :callthroughs, :only => [] do resources :access_authorizations - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers if GsParameter.get('CALLTHROUGH_HAS_WHITELISTS') == true resources :whitelists end @@ -277,12 +231,7 @@ Gemeinschaft42c::Application.routes.draw do resources :sip_accounts, :only => [] do resources :phones_sip_accounts - resources :phone_numbers do - member do - put 'move_higher' - put 'move_lower' - end - end + resources :phone_numbers resources :softkeys resources :call_histories do collection do @@ -313,8 +262,6 @@ Gemeinschaft42c::Application.routes.draw do resources :phone_book_entries, :only => [ :index, :show ] do resources :phone_numbers do member do - put 'move_higher' - put 'move_lower' put 'call' end end -- cgit v1.2.3 From 87634e025711be508501cce8c05f23085dad8f9d Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 4 Feb 2013 14:31:12 +0100 Subject: Bugfixes --- app/views/phone_numbers/_index_core.html.haml | 5 +++-- app/views/sip_accounts/show.html.haml | 8 ++++---- app/views/softkeys/_index_core.html.haml | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/phone_numbers/_index_core.html.haml b/app/views/phone_numbers/_index_core.html.haml index b68e5af..85982da 100644 --- a/app/views/phone_numbers/_index_core.html.haml +++ b/app/views/phone_numbers/_index_core.html.haml @@ -10,8 +10,9 @@ - for phone_number in phone_numbers.order(:position) = content_tag_for :tr, phone_number do %td - %span.handle - %i.icon-resize-vertical + - if phone_numbers.count > 1 + %span.handle + %i.icon-resize-vertical - if phone_number.phone_numberable_type == 'PhoneBookEntry' %td= phone_number.name %td= phone_number diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index f48d927..72e10df 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -65,16 +65,16 @@ = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @sip_account.sip_accountable, :child => @sip_account } -- if @sip_account.phone_numbers.any? || can?(:create, @sip_account.phone_numbers.build) +- if @sip_account.phone_numbers.count > 0 || can?(:create, @sip_account.phone_numbers.build) %h2= t('phone_numbers.index.page_title') - - if @sip_account.phone_numbers.any? + - if @sip_account.phone_numbers.count > 0 = render "phone_numbers/index_core", :phone_numbers => @sip_account.phone_numbers %br = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => PhoneNumber } -- if @sip_account.softkeys.any? || can?(:create, @sip_account.softkeys.build) +- if @sip_account.softkeys.count > 0 || can?(:create, @sip_account.softkeys.build) %h2= t("softkeys.index.page_title") - - if @sip_account.softkeys.any? + - if @sip_account.softkeys.count > 0 = render "softkeys/index_core", :softkeys => @sip_account.softkeys %br = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Softkey } \ No newline at end of file diff --git a/app/views/softkeys/_index_core.html.haml b/app/views/softkeys/_index_core.html.haml index 70c96bc..e2cb16c 100644 --- a/app/views/softkeys/_index_core.html.haml +++ b/app/views/softkeys/_index_core.html.haml @@ -12,8 +12,9 @@ - cache(['softkeys_table_tr', I18n.locale, current_user, softkey]) do = content_tag_for :tr, softkey do %td - %span.handle - %i.icon-resize-vertical + - if softkeys.count > 1 + %span.handle + %i.icon-resize-vertical %td= softkey.function %td= softkey.number %td= softkey.label -- cgit v1.2.3 From b96d198d486cebad9eb803088de39262bef2e4d7 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 4 Feb 2013 15:48:30 +0100 Subject: sip_expiry_seconds --- app/controllers/config_snom_controller.rb | 4 +++- app/views/config_snom/show.xml.haml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb index e797a43..33b63da 100644 --- a/app/controllers/config_snom_controller.rb +++ b/app/controllers/config_snom_controller.rb @@ -247,6 +247,7 @@ class ConfigSnomController < ApplicationController elsif @phone.fallback_sip_account phone_sip_accounts.push( @phone.fallback_sip_account ) end + expiry_seconds = GsParameter.get('SIP_EXPIRY_SECONDS') phone_sip_accounts.each do |sip_account| if (sip_account.sip_accountable_type == @phone.phoneable_type) and (sip_account.sip_accountable_id == @phone.phoneable_id) snom_sip_account = { @@ -259,7 +260,8 @@ class ConfigSnomController < ApplicationController :name => sip_account.auth_name, :realname => 'Call', :idle_text => sip_account.caller_name, - :mailbox => "" + :mailbox => "", + :expiry => expiry_seconds, } @sip_accounts.push(snom_sip_account) sip_account_index = @sip_accounts.length diff --git a/app/views/config_snom/show.xml.haml b/app/views/config_snom/show.xml.haml index 30bee56..53b300c 100644 --- a/app/views/config_snom/show.xml.haml +++ b/app/views/config_snom/show.xml.haml @@ -121,7 +121,7 @@ %user_realname{:idx => index, :perm => 'R'}= sip_account[:realname] %user_idle_text{:idx => index, :perm => 'R'}= sip_account[:idle_text] %user_mailbox{:idx => index, :perm => 'R'}= sip_account[:mailbox] - %user_expiry{:idx => index, :perm => 'R'}= '' + %user_expiry{:idx => index, :perm => 'R'}= sip_account[:expiry] %user_server_type{:idx => index, :perm => 'R'}= 'default' %user_send_local_name{:idx => index, :perm => 'RW'}= 'on' %user_dtmf_info{:idx => index, :perm => 'RW'}= 'off' -- cgit v1.2.3 From e13f041741fd3a44f407b623da0274d9748c5c54 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 4 Feb 2013 16:54:43 +0100 Subject: hunt group routing fixed --- misc/freeswitch/scripts/dialplan/hunt_group.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua index 2c73bf8..fa3c05b 100644 --- a/misc/freeswitch/scripts/dialplan/hunt_group.lua +++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua @@ -98,6 +98,18 @@ 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 clip_no_screening = common.str.try(caller, 'account.record.clip_no_screening'); + 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(caller.caller_id_numbers, number); + end + end + for index, number in ipairs(caller.caller_phone_numbers) do + table.insert(caller.caller_id_numbers, number); + end + self.log:info('CALLER_ID_NUMBERS - clir: ', caller.clir, ', numbers: ', table.concat(caller.caller_id_numbers, ',')); + local save_destination = caller.destination; local destinations = {} @@ -172,6 +184,7 @@ function HuntGroup.run(self, dialplan_object, caller, destination) self.log:info('HUNTGROUP ', self.record.id, ' - all members busy'); run_queue = false; end + caller:sleep(500); end else if forwarding_destination then -- cgit v1.2.3 From e7968236a06c1be8c3ac23b5e63b7840659a334d Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 5 Feb 2013 11:27:14 +0100 Subject: added restart capablity --- misc/freeswitch/scripts/event_manager.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/misc/freeswitch/scripts/event_manager.lua b/misc/freeswitch/scripts/event_manager.lua index 1e61baf..3d558e5 100644 --- a/misc/freeswitch/scripts/event_manager.lua +++ b/misc/freeswitch/scripts/event_manager.lua @@ -7,12 +7,12 @@ require "common.log" local log = common.log.Log:new() log.prefix = "#E# " -log:info('[event] EVENT_MANAGER start'); +log:info('[event] EVENT_MANAGER_LOADER start'); require 'common.database' local database = common.database.Database:new{ log = log }:connect(); if not database:connected() then - log:error('[event] EVENT_MANAGER - cannot connect to Gemeinschaft database'); + log:error('[event] EVENT_MANAGER_LOADER - cannot connect to Gemeinschaft database'); return; end @@ -23,16 +23,21 @@ local domain = '127.0.0.1'; if domains[1] then domain = domains[1]['host']; else - log:error('[event] EVENT_MANAGER - No SIP domains found!'); + log:error('[event] EVENT_MANAGER_LOADER - No SIP domains found!'); end -require 'event.event' -local event_manager = event.event.EventManager:new{ log = log, database = database, domain = domain } -event_manager:run(); +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 } + freeswitch.setGlobalVariable('gs_event_manager', 'true'); + event_manager:run(); +end -- ensure database handle is released on exit if database then database:release(); end -log:info('[event] EVENT_MANAGER exit'); +log:info('[event] EVENT_MANAGER_LOADER exit'); -- cgit v1.2.3 From 676eab5ba9c2a542b9a86e1d9665cdcd7ece9cac Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 5 Feb 2013 11:28:18 +0100 Subject: reload modules from files --- misc/freeswitch/scripts/event/event.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/misc/freeswitch/scripts/event/event.lua b/misc/freeswitch/scripts/event/event.lua index 08d8bfe..c98b534 100644 --- a/misc/freeswitch/scripts/event/event.lua +++ b/misc/freeswitch/scripts/event/event.lua @@ -27,18 +27,26 @@ function EventManager.register(self) end -function EventManager.load_event_modules(self) - require 'common.configuration_table' - self.config = common.configuration_table.get(self.database, 'events'); +function EventManager.load_event_modules(self, modules) + local event_modules = {}; + + for module_name, index in pairs(modules) do + if tonumber(index) and index > 0 then + event_modules[index] = module_name; + self.log:debug('[event] EVENT_MANAGER - enabled handler module: ', module_name); + else + self.log:debug('[event] EVENT_MANAGER - disabled handler module: ', module_name); + end + end - return self.config.modules; + return event_modules; end function EventManager.load_event_handlers(self, event_modules) event_handlers = {} - - for event_module_name, index in pairs(event_modules) do + for index, event_module_name in ipairs(event_modules) do + package.loaded['event.' .. event_module_name] = nil; event_module = require('event.' .. event_module_name); if event_module then self.log:info('[event] EVENT_MANAGER - loading handler module: ', event_module_name); @@ -71,8 +79,12 @@ end function EventManager.run(self) + require 'common.configuration_table' + self.config = common.configuration_table.get(self.database, 'events'); + + local event_modules = self:load_event_modules(self.config.modules); + self.log:info('[event] EVENT_MANAGER_START - handler modules: ', #event_modules); - local event_modules = self:load_event_modules(); local event_handlers = self:load_event_handlers(event_modules); if not event_handlers then @@ -104,4 +116,7 @@ function EventManager.run(self) end end end + + self.consumer = nil; + self.log:info('[event] EVENT_MANAGER_EXIT - action: ', freeswitch.getGlobalVariable('gs_event_manager')); end -- cgit v1.2.3 From bb8168c33f9501fe877345a7bbc7b7f7b64cdfc7 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 5 Feb 2013 12:40:42 +0100 Subject: Added a BackupJob scaffold. --- app/controllers/backup_jobs_controller.rb | 43 ++++++++++++++++++ app/helpers/backup_jobs_helper.rb | 2 + app/models/backup_job.rb | 14 ++++++ app/views/backup_jobs/_form.html.haml | 7 +++ app/views/backup_jobs/_form_core.html.haml | 6 +++ app/views/backup_jobs/_index_core.html.haml | 17 +++++++ app/views/backup_jobs/edit.html.haml | 3 ++ app/views/backup_jobs/index.html.haml | 6 +++ app/views/backup_jobs/new.html.haml | 3 ++ app/views/backup_jobs/show.html.haml | 19 ++++++++ config/backup.rb | 12 ++--- config/locales/views/backup_jobs/de.yml | 60 +++++++++++++++++++++++++ config/locales/views/backup_jobs/en.yml | 60 +++++++++++++++++++++++++ config/routes.rb | 2 + db/migrate/20130205102838_create_backup_jobs.rb | 16 +++++++ test/functional/backup_jobs_controller_test.rb | 49 ++++++++++++++++++++ test/unit/backup_job_test.rb | 7 +++ 17 files changed, 320 insertions(+), 6 deletions(-) create mode 100644 app/controllers/backup_jobs_controller.rb create mode 100644 app/helpers/backup_jobs_helper.rb create mode 100644 app/models/backup_job.rb create mode 100644 app/views/backup_jobs/_form.html.haml create mode 100644 app/views/backup_jobs/_form_core.html.haml create mode 100644 app/views/backup_jobs/_index_core.html.haml create mode 100644 app/views/backup_jobs/edit.html.haml create mode 100644 app/views/backup_jobs/index.html.haml create mode 100644 app/views/backup_jobs/new.html.haml create mode 100644 app/views/backup_jobs/show.html.haml create mode 100644 config/locales/views/backup_jobs/de.yml create mode 100644 config/locales/views/backup_jobs/en.yml create mode 100644 db/migrate/20130205102838_create_backup_jobs.rb create mode 100644 test/functional/backup_jobs_controller_test.rb create mode 100644 test/unit/backup_job_test.rb diff --git a/app/controllers/backup_jobs_controller.rb b/app/controllers/backup_jobs_controller.rb new file mode 100644 index 0000000..e500f4c --- /dev/null +++ b/app/controllers/backup_jobs_controller.rb @@ -0,0 +1,43 @@ +class BackupJobsController < ApplicationController + def index + @backup_jobs = BackupJob.all + end + + def show + @backup_job = BackupJob.find(params[:id]) + end + + def new + @backup_job = BackupJob.new + end + + def create +# @backup_job = BackupJob.new(params[:backup_job]) + @backup_job = BackupJob.new(:started_at => Time.now) + + if @backup_job.save + redirect_to @backup_job, :notice => t('backup_jobs.controller.successfuly_created') + else + render :new + end + end + + # def edit + # @backup_job = BackupJob.find(params[:id]) + # end + + # def update + # @backup_job = BackupJob.find(params[:id]) + # if @backup_job.update_attributes(params[:backup_job]) + # redirect_to @backup_job, :notice => t('backup_jobs.controller.successfuly_updated') + # else + # render :edit + # end + # end + + def destroy + @backup_job = BackupJob.find(params[:id]) + @backup_job.destroy + redirect_to backup_jobs_url, :notice => t('backup_jobs.controller.successfuly_destroyed') + end +end diff --git a/app/helpers/backup_jobs_helper.rb b/app/helpers/backup_jobs_helper.rb new file mode 100644 index 0000000..06d8b9b --- /dev/null +++ b/app/helpers/backup_jobs_helper.rb @@ -0,0 +1,2 @@ +module BackupJobsHelper +end diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb new file mode 100644 index 0000000..d579b79 --- /dev/null +++ b/app/models/backup_job.rb @@ -0,0 +1,14 @@ +class BackupJob < ActiveRecord::Base + attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup + + after_save :start_the_backup + + private + def start_the_backup + if self.finished_at.nil? + sh "backup perform --trigger gs5 --config_file #{Rails.root.join('config','backup.rb')}" + self.finished_at = Time.now + self.save + end + end +end diff --git a/app/views/backup_jobs/_form.html.haml b/app/views/backup_jobs/_form.html.haml new file mode 100644 index 0000000..e0adceb --- /dev/null +++ b/app/views/backup_jobs/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for(@backup_job) do |f| + = f.error_notification + + = render "form_core", :f => f + + .actions + = f.button :submit, conditional_t('backup_jobs.form.submit') \ No newline at end of file diff --git a/app/views/backup_jobs/_form_core.html.haml b/app/views/backup_jobs/_form_core.html.haml new file mode 100644 index 0000000..536fb18 --- /dev/null +++ b/app/views/backup_jobs/_form_core.html.haml @@ -0,0 +1,6 @@ +.inputs + = f.input :started_at, :label => t('backup_jobs.form.started_at.label'), :hint => conditional_hint('backup_jobs.form.started_at.hint') + = f.input :finished_at, :label => t('backup_jobs.form.finished_at.label'), :hint => conditional_hint('backup_jobs.form.finished_at.hint') + = f.input :state, :label => t('backup_jobs.form.state.label'), :hint => conditional_hint('backup_jobs.form.state.hint') + = f.input :directory, :label => t('backup_jobs.form.directory.label'), :hint => conditional_hint('backup_jobs.form.directory.hint') + = f.input :size_of_the_backup, :label => t('backup_jobs.form.size_of_the_backup.label'), :hint => conditional_hint('backup_jobs.form.size_of_the_backup.hint') diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml new file mode 100644 index 0000000..6babf3e --- /dev/null +++ b/app/views/backup_jobs/_index_core.html.haml @@ -0,0 +1,17 @@ +%table.table.table-striped + %tr + %th= t('backup_jobs.index.started_at') + %th= t('backup_jobs.index.finished_at') + %th= t('backup_jobs.index.state') + %th= t('backup_jobs.index.directory') + %th= t('backup_jobs.index.size_of_the_backup') + + + - for backup_job in backup_jobs + %tr + %td= backup_job.started_at + %td= backup_job.finished_at + %td= backup_job.state + %td= backup_job.directory + %td= backup_job.size_of_the_backup + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => backup_job} \ No newline at end of file diff --git a/app/views/backup_jobs/edit.html.haml b/app/views/backup_jobs/edit.html.haml new file mode 100644 index 0000000..7892edb --- /dev/null +++ b/app/views/backup_jobs/edit.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("backup_jobs.edit.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/backup_jobs/index.html.haml b/app/views/backup_jobs/index.html.haml new file mode 100644 index 0000000..0bb4747 --- /dev/null +++ b/app/views/backup_jobs/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("backup_jobs.index.page_title") + +- if @backup_jobs && @backup_jobs.count > 0 + = render "index_core", :backup_jobs => @backup_jobs + += render :partial => 'shared/create_link', :locals => {:child_class => BackupJob} \ No newline at end of file diff --git a/app/views/backup_jobs/new.html.haml b/app/views/backup_jobs/new.html.haml new file mode 100644 index 0000000..65efd4f --- /dev/null +++ b/app/views/backup_jobs/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("backup_jobs.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml new file mode 100644 index 0000000..7f021bb --- /dev/null +++ b/app/views/backup_jobs/show.html.haml @@ -0,0 +1,19 @@ +- content_for :title, t("backup_jobs.show.page_title") + +%p + %strong= t('backup_jobs.show.started_at') + ":" + = @backup_job.started_at +%p + %strong= t('backup_jobs.show.finished_at') + ":" + = @backup_job.finished_at +%p + %strong= t('backup_jobs.show.state') + ":" + = @backup_job.state +%p + %strong= t('backup_jobs.show.directory') + ":" + = @backup_job.directory +%p + %strong= t('backup_jobs.show.size_of_the_backup') + ":" + = @backup_job.size_of_the_backup + += render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job } \ No newline at end of file diff --git a/config/backup.rb b/config/backup.rb index c3da9bc..4e5cbf2 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -29,10 +29,10 @@ Backup::Model.new(:gs5, 'GS5 backup') do ## # Faxes # - archive :faxes do |archive| - archive.add '/opt/gemeinschaft/public/uploads/fax_document/' - archive.add '/opt/gemeinschaft/public/uploads/fax_thumbnail/' - end + #archive :faxes do |archive| + # archive.add '/opt/gemeinschaft/public/uploads/fax_document/' + # archive.add '/opt/gemeinschaft/public/uploads/fax_thumbnail/' + #end ## # Voicemails @@ -45,8 +45,8 @@ Backup::Model.new(:gs5, 'GS5 backup') do # Local (Copy) [Storage] # store_with Local do |local| - local.path = "/var/backups/" - local.keep = 5 + local.path = "/var/backups/GS5/" + local.keep = 3 end ## diff --git a/config/locales/views/backup_jobs/de.yml b/config/locales/views/backup_jobs/de.yml new file mode 100644 index 0000000..b81b532 --- /dev/null +++ b/config/locales/views/backup_jobs/de.yml @@ -0,0 +1,60 @@ +de: + backup_jobs: + name: 'Backup job' + controller: + successfuly_created: 'Backup job wurde angelegt.' + successfuly_updated: 'Backup job wurde aktualisiert.' + successfuly_destroyed: 'Backup job wurde gelöscht.' + index: + page_title: 'Übersicht von Backup job' + started_at: 'Started at' + finished_at: 'Finished at' + state: 'State' + directory: 'Directory' + size_of_the_backup: 'Size of the backup' + actions: + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Backup job' + destroy: 'Löschen' + edit: 'Bearbeiten' + show: 'Anzeigen' + create: 'Neu anlegen' + create_for: 'Backup job neu anlegen für %{resource}' + show: + page_title: 'Backup job bearbeiten' + started_at: 'Started at' + finished_at: 'Finished at' + state: 'State' + directory: 'Directory' + size_of_the_backup: 'Size of the backup' + actions: + confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?' + destroy: 'Löschen' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + new: + page_title: 'Backup job neu anlegen' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: + page_title: 'Backup job bearbeiten' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + form: + started_at: + label: 'Started at' + hint: '' + finished_at: + label: 'Finished at' + hint: '' + state: + label: 'State' + hint: '' + directory: + label: 'Directory' + hint: '' + size_of_the_backup: + label: 'Size of the backup' + hint: '' + submit: 'Absenden' \ No newline at end of file diff --git a/config/locales/views/backup_jobs/en.yml b/config/locales/views/backup_jobs/en.yml new file mode 100644 index 0000000..83f4388 --- /dev/null +++ b/config/locales/views/backup_jobs/en.yml @@ -0,0 +1,60 @@ +en: + backup_jobs: + name: 'Backup job' + controller: + successfuly_created: 'Successfully created Backup job.' + successfuly_updated: 'Successfully updated Backup job.' + successfuly_destroyed: 'Successfully destroyed Backup job.' + index: + page_title: 'Listing Backup job' + started_at: 'Started at' + finished_at: 'Finished at' + state: 'State' + directory: 'Directory' + size_of_the_backup: 'Size of the backup' + actions: + confirm_destroy: 'Are you sure you want to delete this Backup job?' + destroy: 'Delete' + edit: 'Edit' + show: 'View' + create: 'New' + create_for: 'New Backup job for %{resource}' + show: + page_title: 'Show Backup job' + started_at: 'Started at' + finished_at: 'Finished at' + state: 'State' + directory: 'Directory' + size_of_the_backup: 'Size of the backup' + actions: + confirm_destroy: 'Are you sure you want to delete this element?' + destroy: 'Delete' + edit: 'Edit' + view_all: 'View All' + new: + page_title: 'New Backup job' + actions: + back_to_list: 'Back to Index' + edit: + page_title: 'Editing Backup job' + actions: + back_to_list: 'Back to Index' + edit: 'Edit' + view_all: 'View All' + form: + started_at: + label: 'Started at' + hint: '' + finished_at: + label: 'Finished at' + hint: '' + state: + label: 'State' + hint: '' + directory: + label: 'Directory' + hint: '' + size_of_the_backup: + label: 'Size of the backup' + hint: '' + submit: 'Submit' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index fbb32f6..3c3928f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Gemeinschaft42c::Application.routes.draw do + resources :backup_jobs, :except => [:edit, :update] + scope :constraints => lambda{|req|%w(127.0.0.1).include? req.remote_addr} do get "trigger/voicemail" get "trigger/fax" diff --git a/db/migrate/20130205102838_create_backup_jobs.rb b/db/migrate/20130205102838_create_backup_jobs.rb new file mode 100644 index 0000000..0d71421 --- /dev/null +++ b/db/migrate/20130205102838_create_backup_jobs.rb @@ -0,0 +1,16 @@ +class CreateBackupJobs < ActiveRecord::Migration + def self.up + create_table :backup_jobs do |t| + t.datetime :started_at + t.datetime :finished_at + t.string :state + t.string :directory + t.string :size_of_the_backup + t.timestamps + end + end + + def self.down + drop_table :backup_jobs + end +end diff --git a/test/functional/backup_jobs_controller_test.rb b/test/functional/backup_jobs_controller_test.rb new file mode 100644 index 0000000..17a0caf --- /dev/null +++ b/test/functional/backup_jobs_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class BackupJobsControllerTest < ActionController::TestCase + setup do + @backup_job = backup_jobs(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:backup_jobs) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create backup_job" do + assert_difference('BackupJob.count') do + post :create, backup_job: @backup_job.attributes + end + + assert_redirected_to backup_job_path(assigns(:backup_job)) + end + + test "should show backup_job" do + get :show, id: @backup_job.to_param + assert_response :success + end + + test "should get edit" do + get :edit, id: @backup_job.to_param + assert_response :success + end + + test "should update backup_job" do + put :update, id: @backup_job.to_param, backup_job: @backup_job.attributes + assert_redirected_to backup_job_path(assigns(:backup_job)) + end + + test "should destroy backup_job" do + assert_difference('BackupJob.count', -1) do + delete :destroy, id: @backup_job.to_param + end + + assert_redirected_to backup_jobs_path + end +end diff --git a/test/unit/backup_job_test.rb b/test/unit/backup_job_test.rb new file mode 100644 index 0000000..a63c219 --- /dev/null +++ b/test/unit/backup_job_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BackupJobTest < ActiveSupport::TestCase + def test_should_be_valid + assert BackupJob.new.valid? + end +end -- cgit v1.2.3 From 6d4de81a703b11f75792790a1b41f963240bd839 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 5 Feb 2013 12:47:18 +0100 Subject: Added navigation I18n for "Admin-Docu". #142 --- app/views/layouts/_navbar.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index 9350de0..335dd3d 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -14,10 +14,10 @@ - if current_user && GemeinschaftSetup.any? && current_user.admin? - if current_page?(page_help_path) %li.active - =link_to 'Admin-Doku', page_help_path + =link_to t('navigation.admin_docu'), page_help_path - else %li - =link_to 'Admin-Doku', page_help_path + =link_to t('navigation.admin_docu'), page_help_path - if current_user && current_user.sip_accounts.any? %li %a{:href => sip_account_call_histories_path(current_user.sip_accounts.first)} -- cgit v1.2.3 From dbb0715f4622ad55fce36e51e3a5d046180a0ea7 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 5 Feb 2013 12:54:11 +0100 Subject: Translations for tenant#show view (admin mode). #137 --- app/views/tenants/_admin_area.de.html.haml | 40 ++++++++++++++++++++++++++++++ app/views/tenants/_admin_area.en.html.haml | 40 ++++++++++++++++++++++++++++++ app/views/tenants/_admin_area.html.haml | 40 ------------------------------ config/locales/navigation.de.yml | 3 +++ config/locales/navigation.en.yml | 3 +++ 5 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 app/views/tenants/_admin_area.de.html.haml create mode 100644 app/views/tenants/_admin_area.en.html.haml delete mode 100644 app/views/tenants/_admin_area.html.haml create mode 100644 config/locales/navigation.de.yml create mode 100644 config/locales/navigation.en.yml diff --git a/app/views/tenants/_admin_area.de.html.haml b/app/views/tenants/_admin_area.de.html.haml new file mode 100644 index 0000000..98809d1 --- /dev/null +++ b/app/views/tenants/_admin_area.de.html.haml @@ -0,0 +1,40 @@ + +.row + .span12 + = render :partial => 'tenants/table_of_sip_accounts', :locals => {:tenant => tenant} + - if SipAccount.any? + = render :partial => 'tenants/table_of_phones', :locals => {:tenant => tenant} + + - if SipAccount.any? || Gateway.any? + = render :partial => 'tenants/table_of_conferences', :locals => {:tenant => tenant} + = render :partial => 'tenants/table_of_callthroughs', :locals => {:tenant => tenant} + = render :partial => 'tenants/table_of_hunt_groups', :locals => {:tenant => tenant} + = render :partial => 'tenants/table_of_automatic_call_distributors', :locals => {:tenant => tenant} + + = render :partial => 'tenants/users_table', :locals => {:tenant => tenant} + = render :partial => 'tenants/user_groups_table', :locals => {:tenant => tenant} + + = render :partial => 'tenants/table_of_phone_books', :locals => {:tenant => tenant} + + .well + %h2 Gemeinschaft Konfiguration + = render :partial => 'tenants/gs_parameter_table', :locals => {:tenant => tenant} + + %p + Das System kann + = PhoneModel.count + verschiedene Telefonmodelle von den folgenden Herstellern automatisch provisionieren: + - Manufacturer.all.each do |manufacturer| + - if manufacturer != Manufacturer.last && manufacturer != Manufacturer.limit(Manufacturer.count - 1).last + = succeed ', ' do + =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) + - elsif manufacturer == Manufacturer.limit(Manufacturer.count - 1).last + = succeed ' und ' do + =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) + - else + = succeed '.' do + =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) + + = render :partial => 'call_routes', :locals => {:tenant => tenant} + + = render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} \ No newline at end of file diff --git a/app/views/tenants/_admin_area.en.html.haml b/app/views/tenants/_admin_area.en.html.haml new file mode 100644 index 0000000..4f0032c --- /dev/null +++ b/app/views/tenants/_admin_area.en.html.haml @@ -0,0 +1,40 @@ + +.row + .span12 + = render :partial => 'tenants/table_of_sip_accounts', :locals => {:tenant => tenant} + - if SipAccount.any? + = render :partial => 'tenants/table_of_phones', :locals => {:tenant => tenant} + + - if SipAccount.any? || Gateway.any? + = render :partial => 'tenants/table_of_conferences', :locals => {:tenant => tenant} + = render :partial => 'tenants/table_of_callthroughs', :locals => {:tenant => tenant} + = render :partial => 'tenants/table_of_hunt_groups', :locals => {:tenant => tenant} + = render :partial => 'tenants/table_of_automatic_call_distributors', :locals => {:tenant => tenant} + + = render :partial => 'tenants/users_table', :locals => {:tenant => tenant} + = render :partial => 'tenants/user_groups_table', :locals => {:tenant => tenant} + + = render :partial => 'tenants/table_of_phone_books', :locals => {:tenant => tenant} + + .well + %h2 Gemeinschaft Configuration + = render :partial => 'tenants/gs_parameter_table', :locals => {:tenant => tenant} + + %p + This system can provision a total of + = PhoneModel.count + different phone models of the following manufacturers: + - Manufacturer.all.each do |manufacturer| + - if manufacturer != Manufacturer.last && manufacturer != Manufacturer.limit(Manufacturer.count - 1).last + = succeed ', ' do + =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) + - elsif manufacturer == Manufacturer.limit(Manufacturer.count - 1).last + = succeed ' and ' do + =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) + - else + = succeed '.' do + =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) + + = render :partial => 'call_routes', :locals => {:tenant => tenant} + + = render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} \ No newline at end of file diff --git a/app/views/tenants/_admin_area.html.haml b/app/views/tenants/_admin_area.html.haml deleted file mode 100644 index 28a8273..0000000 --- a/app/views/tenants/_admin_area.html.haml +++ /dev/null @@ -1,40 +0,0 @@ - -.row - .span12 - = render :partial => 'tenants/table_of_sip_accounts', :locals => {:tenant => tenant} - - if SipAccount.any? - = render :partial => 'tenants/table_of_phones', :locals => {:tenant => tenant} - - - if SipAccount.any? || Gateway.any? - = render :partial => 'tenants/table_of_conferences', :locals => {:tenant => tenant} - = render :partial => 'tenants/table_of_callthroughs', :locals => {:tenant => tenant} - = render :partial => 'tenants/table_of_hunt_groups', :locals => {:tenant => tenant} - = render :partial => 'tenants/table_of_automatic_call_distributors', :locals => {:tenant => tenant} - - = render :partial => 'tenants/users_table', :locals => {:tenant => tenant} - = render :partial => 'tenants/user_groups_table', :locals => {:tenant => tenant} - - = render :partial => 'tenants/table_of_phone_books', :locals => {:tenant => tenant} - - .well - %h2 Gemeinschaft Konfiguration - = render :partial => 'tenants/gs_parameter_table', :locals => {:tenant => tenant} - - %p - Das System kann - = PhoneModel.count - verschiedene Telefonmodelle von den folgenden Herstellern verwalten: - - Manufacturer.all.each do |manufacturer| - - if manufacturer != Manufacturer.last && manufacturer != Manufacturer.limit(Manufacturer.count - 1).last - = succeed ', ' do - =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) - - elsif manufacturer == Manufacturer.limit(Manufacturer.count - 1).last - = succeed ' und ' do - =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) - - else - = succeed '.' do - =link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer) - - = render :partial => 'call_routes', :locals => {:tenant => tenant} - - = render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} \ No newline at end of file diff --git a/config/locales/navigation.de.yml b/config/locales/navigation.de.yml new file mode 100644 index 0000000..779248c --- /dev/null +++ b/config/locales/navigation.de.yml @@ -0,0 +1,3 @@ +de: + navigation: + admin_docu: 'Admin-Doku' \ No newline at end of file diff --git a/config/locales/navigation.en.yml b/config/locales/navigation.en.yml new file mode 100644 index 0000000..82e901b --- /dev/null +++ b/config/locales/navigation.en.yml @@ -0,0 +1,3 @@ +en: + navigation: + admin_docu: 'Admin-Docu' \ No newline at end of file -- cgit v1.2.3 From c7389cb6f1a305bc7e5cfefd9548c1e1bf7b6018 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 5 Feb 2013 13:44:10 +0100 Subject: Bugfix --- app/models/backup_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index d579b79..5149553 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -1,12 +1,12 @@ class BackupJob < ActiveRecord::Base attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup - after_save :start_the_backup + after_create :start_the_backup private def start_the_backup if self.finished_at.nil? - sh "backup perform --trigger gs5 --config_file #{Rails.root.join('config','backup.rb')}" + system "backup perform --trigger gs5 --config_file #{Rails.root.join('config','backup.rb')}" self.finished_at = Time.now self.save end -- cgit v1.2.3 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 +++++ config/routes.rb | 5 +- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/views/call_routes/show_variables.html.haml 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 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 -- cgit v1.2.3 From 11c0c5bb51d58a6d33848806a29a9a4e0d241cbd Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 5 Feb 2013 14:02:56 +0100 Subject: dump_variables event module added --- misc/freeswitch/scripts/event/dump_variables.lua | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 misc/freeswitch/scripts/event/dump_variables.lua 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 -- 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(-) 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 From e22d3f5cb2791b70a9fcfe6befdeca233772688d Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 5 Feb 2013 14:30:30 +0100 Subject: preserve event consumer --- misc/freeswitch/scripts/event/event.lua | 6 ++++-- misc/freeswitch/scripts/event_manager.lua | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 -- cgit v1.2.3 From 75b36967fed9db8268391ac10b02f5c0870c32ca Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 5 Feb 2013 15:11:56 +0100 Subject: Finetuning backup. --- app/models/ability.rb | 4 ++++ app/models/backup_job.rb | 3 ++- config/backup.rb | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 0d13dab..01f26aa 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -64,6 +64,10 @@ class Ability # cannot [:edit, :update], FaxDocument + # Backups can't be edited + # + cannot [:edit, :update], BackupJob + # Can manage GsNodes # can :manage, GsNode diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index 5149553..b0a588f 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -6,8 +6,9 @@ class BackupJob < ActiveRecord::Base private def start_the_backup if self.finished_at.nil? - system "backup perform --trigger gs5 --config_file #{Rails.root.join('config','backup.rb')}" + system "backup perform --trigger GS5 --config_file #{Rails.root.join('config','backup.rb')}" self.finished_at = Time.now + self.status = 'done' self.save end end diff --git a/config/backup.rb b/config/backup.rb index 4e5cbf2..46ef058 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -3,7 +3,7 @@ require 'inifile' SYSTEM_ODBC_CONFIGURATION = IniFile.load('/var/lib/freeswitch/.odbc.ini') -Backup::Model.new(:gs5, 'GS5 backup') do +Backup::Model.new(:GS5, 'GS5 backup') do ## # Split [Splitter] @@ -45,7 +45,7 @@ Backup::Model.new(:gs5, 'GS5 backup') do # Local (Copy) [Storage] # store_with Local do |local| - local.path = "/var/backups/GS5/" + local.path = "/var/backups/" local.keep = 3 end -- cgit v1.2.3 From b1f9f3b2c39d31d0621da36420318406f33a1f92 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 5 Feb 2013 16:21:02 +0100 Subject: DelayedJob table upgrade. --- app/models/backup_job.rb | 21 ++++++++++++++++----- .../20130205151844_add_queue_to_delayed_jobs.rb | 9 +++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20130205151844_add_queue_to_delayed_jobs.rb diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index b0a588f..a90726c 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -1,14 +1,25 @@ class BackupJob < ActiveRecord::Base attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup - after_create :start_the_backup + after_create :initiate_backup private - def start_the_backup - if self.finished_at.nil? + def initiate_backup + self.delay.make_a_backup + end + + def make_a_backup + if self.finished_at.nil? + original_directories = Dir.glob('/var/backups/GS5/*') system "backup perform --trigger GS5 --config_file #{Rails.root.join('config','backup.rb')}" - self.finished_at = Time.now - self.status = 'done' + self.directory = (Dir.glob('/var/backups/GS5/*') - original_directories).first + if self.directory.blank? + self.state = 'unsuccessful' + else + self.size_of_the_backup = (`du -hs #{new_directory}`).split(/\t/).first + self.finished_at = Time.now + self.state = 'successful' + end self.save end end diff --git a/db/migrate/20130205151844_add_queue_to_delayed_jobs.rb b/db/migrate/20130205151844_add_queue_to_delayed_jobs.rb new file mode 100644 index 0000000..072c8d4 --- /dev/null +++ b/db/migrate/20130205151844_add_queue_to_delayed_jobs.rb @@ -0,0 +1,9 @@ +class AddQueueToDelayedJobs < ActiveRecord::Migration + def self.up + add_column :delayed_jobs, :queue, :string + end + + def self.down + remove_column :delayed_jobs, :queue + end +end -- cgit v1.2.3 From e5b247ccefe499f61bdadef186e34d03ded3035a Mon Sep 17 00:00:00 2001 From: Sascha Daniels Date: Wed, 6 Feb 2013 03:23:20 +0100 Subject: Stupid setting removed --- app/views/config_snom/show.xml.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/config_snom/show.xml.haml b/app/views/config_snom/show.xml.haml index 53b300c..33204dc 100644 --- a/app/views/config_snom/show.xml.haml +++ b/app/views/config_snom/show.xml.haml @@ -42,7 +42,7 @@ %prefer_saved_over_received_photo{:perm => 'RW'}= 'off' %no_dnd{:perm => 'RW'}= 'off' %transfer_on_hangup{:perm => 'RW'}= 'on' - %transfer_on_hangup_non_pots{:perm => 'RW'}= 'on' + %transfer_on_hangup_non_pots{:perm => 'RW'}= 'off' %call_join_xfer{:perm => 'RW'}= 'on' %conf_hangup{:perm => 'RW'}= 'on' %logon_wizard{:perm => 'RW'}= 'off' -- cgit v1.2.3 From 9a140ffba197b1b09350509169c229abc82ecec0 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 10:05:31 +0100 Subject: sip based phone resync fixed --- misc/freeswitch/scripts/dialplan/functions.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 2ca51c8..61c86aa 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -264,7 +264,7 @@ function Functions.account_node_change(self, caller) -- resync caller phones for index, phone_caller in ipairs(caller_phones) do - local result = phone_caller:resync{ auth_name = caller_sip_account.auth_name, domain = caller.domain }; + local result = phone_caller:resync{ auth_name = caller_sip_account.record.auth_name, domain = caller_sip_account.record.host }; self.log:info('NODE_CHANGE - resync phone - mac: ', phone_caller.record.mac_address, ', ip_address: ', phone_caller.record.ip_address, ', result: ', result); end @@ -374,13 +374,13 @@ function Functions.user_login(self, caller, number, pin) -- resync destination phones for index, phone_destination in ipairs(destination_phones) do - local result = phone_destination:resync{ auth_name = destination_sip_account.auth_name, domain = caller.domain_local }; + local result = phone_destination:resync{ auth_name = destination_sip_account.record.auth_name, domain = destination_sip_account.record.host }; self.log:info('LOGIN - resync destination phone - mac: ', phone_destination.record.mac_address, ', ip_address: ', phone_destination.record.ip_address, ', result: ', result); end -- resync caller phones for index, phone_caller in ipairs(caller_phones) do - local result = phone_caller:resync{ auth_name = caller_sip_account.auth_name, domain = caller.domain }; + local result = phone_caller:resync{ auth_name = caller_sip_account.record.auth_name, domain = caller_sip_account.record.host }; self.log:info('LOGIN - resync caller phone - mac: ', phone_caller.record.mac_address, ', ip_address: ', phone_caller.record.ip_address, ', result: ', result); end @@ -426,7 +426,7 @@ function Functions.user_logout(self, caller) -- resync caller phones for index, phone_caller in ipairs(caller_phones) do - local result = phone_caller:resync{ auth_name = caller_sip_account.auth_name, domain = caller.domain }; + local result = phone_caller:resync{ auth_name = caller_sip_account.record.auth_name, domain = caller_sip_account.record.host }; self.log:info('LOGIN - resync caller phone - mac: ', phone_caller.record.mac_address, ', ip_address: ', phone_caller.record.ip_address, ', result: ', result); end -- cgit v1.2.3 From 64912b6266ae449a2052f51e769ce59950b70da8 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 10:27:46 +0100 Subject: try to resync if phone not found --- misc/freeswitch/scripts/dialplan/functions.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 61c86aa..32fad78 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -302,6 +302,7 @@ function Functions.user_login(self, caller, number, pin) if not caller_phone then self.log:notice('LOGIN - caller phone not found or not hot-deskable'); + local result = phone_class:resync{ auth_name = caller_sip_account.record.auth_name, domain = caller_sip_account.record.host }; return { continue = false, code = 403, phrase = 'Phone not hot-deskable', no_cdr = true } end @@ -409,8 +410,9 @@ function Functions.user_logout(self, caller) local caller_phones = phone_class:find_all_hot_deskable_by_account(caller_sip_account.id); - if caller_phones == 0 then + if #caller_phones == 0 then self.log:notice('LOGOUT - caller phones not found or not hot-deskable'); + local result = phone_class:resync{ auth_name = caller_sip_account.record.auth_name, domain = caller_sip_account.record.host }; return { continue = false, code = 403, phrase = 'Phone not hot-deskable', no_cdr = true } end -- cgit v1.2.3 From 500ef315442a7fad3647f9b58ae59ab70c45c4b8 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 10:28:11 +0100 Subject: try to resync if phone model not found --- misc/freeswitch/scripts/phones/phone.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/misc/freeswitch/scripts/phones/phone.lua b/misc/freeswitch/scripts/phones/phone.lua index 6da20f0..57997ba 100644 --- a/misc/freeswitch/scripts/phones/phone.lua +++ b/misc/freeswitch/scripts/phones/phone.lua @@ -115,8 +115,9 @@ end function Phone.resync(self, arg) if not self.model then - self.log:notice('PHONE_RESYNC - unsupported phone model'); - return false; + self.log:notice('PHONE_RESYNC phone model not found - trying Snom resync'); + require 'phones.snom' + return phones.snom.Snom:new{ log = self.log }:resync(arg); end arg.ip_address = arg.ip_address or self.record.ip_address; -- cgit v1.2.3 From 3edd6e58ea3f5d25068ea9d47f639ae89e5f2c0c Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 6 Feb 2013 11:07:04 +0100 Subject: Improved the backup. --- app/models/backup_job.rb | 23 ++++++++++++++++++++--- app/views/backup_jobs/_index_core.html.haml | 19 +++++++++++++++---- app/views/backup_jobs/show.html.haml | 2 +- config/backup.rb | 1 - db/migrate/20130205102838_create_backup_jobs.rb | 2 +- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index a90726c..c9bde2b 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -1,26 +1,43 @@ class BackupJob < ActiveRecord::Base attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup + before_create :set_state_to_queued after_create :initiate_backup + after_destroy :delete_the_backup_directory private + def set_state_to_queued + self.state = 'queued' + self.started_at = Time.now + end + def initiate_backup self.delay.make_a_backup end def make_a_backup - if self.finished_at.nil? + if self.finished_at.nil? && self.state == 'queued' + self.state = 'running' + self.save original_directories = Dir.glob('/var/backups/GS5/*') system "backup perform --trigger GS5 --config_file #{Rails.root.join('config','backup.rb')}" self.directory = (Dir.glob('/var/backups/GS5/*') - original_directories).first if self.directory.blank? - self.state = 'unsuccessful' + self.state = 'failed' else - self.size_of_the_backup = (`du -hs #{new_directory}`).split(/\t/).first + file = File::Stat.new(self.directory) + self.size_of_the_backup = file.size self.finished_at = Time.now self.state = 'successful' end self.save end end + + def delete_the_backup_directory + if !self.directory.blank? + require 'fileutils' + FileUtils.rm_rf self.directory + end + end end diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml index 6babf3e..a1bf0d0 100644 --- a/app/views/backup_jobs/_index_core.html.haml +++ b/app/views/backup_jobs/_index_core.html.haml @@ -8,10 +8,21 @@ - for backup_job in backup_jobs - %tr - %td= backup_job.started_at - %td= backup_job.finished_at + - if backup_job.state == 'queued' + - row_marker = 'warning' + - else + - if backup_job.state == 'failed' + - row_marker = 'error' + - else + - row_marker = '' + %tr{:class => row_marker} + %td + - if backup_job.finished_at.blank? + = time_ago_in_words(backup_job.finished_at) + - else + = l backup_job.started_at, :format => :short + %td= l backup_job.finished_at, :format => :short %td= backup_job.state %td= backup_job.directory - %td= backup_job.size_of_the_backup + %td= number_to_human_size(backup_job.size_of_the_backup, :precision => 2) =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => backup_job} \ No newline at end of file diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index 7f021bb..65091b8 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -14,6 +14,6 @@ = @backup_job.directory %p %strong= t('backup_jobs.show.size_of_the_backup') + ":" - = @backup_job.size_of_the_backup + = number_to_human_size(@backup_job.size_of_the_backup, :precision => 2) = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job } \ No newline at end of file diff --git a/config/backup.rb b/config/backup.rb index 46ef058..d57a47e 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -46,7 +46,6 @@ Backup::Model.new(:GS5, 'GS5 backup') do # store_with Local do |local| local.path = "/var/backups/" - local.keep = 3 end ## diff --git a/db/migrate/20130205102838_create_backup_jobs.rb b/db/migrate/20130205102838_create_backup_jobs.rb index 0d71421..0994939 100644 --- a/db/migrate/20130205102838_create_backup_jobs.rb +++ b/db/migrate/20130205102838_create_backup_jobs.rb @@ -5,7 +5,7 @@ class CreateBackupJobs < ActiveRecord::Migration t.datetime :finished_at t.string :state t.string :directory - t.string :size_of_the_backup + t.integer :size_of_the_backup t.timestamps end end -- cgit v1.2.3 From 16a2074982644614f3ef13c15681b5c89feb586b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 6 Feb 2013 11:24:14 +0100 Subject: HTML fix. --- app/views/backup_jobs/_index_core.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml index a1bf0d0..aceeb5b 100644 --- a/app/views/backup_jobs/_index_core.html.haml +++ b/app/views/backup_jobs/_index_core.html.haml @@ -5,6 +5,7 @@ %th= t('backup_jobs.index.state') %th= t('backup_jobs.index.directory') %th= t('backup_jobs.index.size_of_the_backup') + %th{:colspan => '2'} - for backup_job in backup_jobs -- cgit v1.2.3 From c26e4b9d27218378f34175ac3410eab5b12a5713 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 6 Feb 2013 12:19:23 +0100 Subject: View improvements. --- app/views/backup_jobs/_index_core.html.haml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml index aceeb5b..a706424 100644 --- a/app/views/backup_jobs/_index_core.html.haml +++ b/app/views/backup_jobs/_index_core.html.haml @@ -3,7 +3,6 @@ %th= t('backup_jobs.index.started_at') %th= t('backup_jobs.index.finished_at') %th= t('backup_jobs.index.state') - %th= t('backup_jobs.index.directory') %th= t('backup_jobs.index.size_of_the_backup') %th{:colspan => '2'} @@ -17,13 +16,16 @@ - else - row_marker = '' %tr{:class => row_marker} - %td - - if backup_job.finished_at.blank? - = time_ago_in_words(backup_job.finished_at) - - else + - if backup_job.finished_at.blank? + %td{:colspan => '2'} + = time_ago_in_words(backup_job.started_at) + - else + %td = l backup_job.started_at, :format => :short - %td= l backup_job.finished_at, :format => :short + %td + = l backup_job.finished_at, :format => :short %td= backup_job.state - %td= backup_job.directory - %td= number_to_human_size(backup_job.size_of_the_backup, :precision => 2) + %td + - if !backup_job.size_of_the_backup.blank? + = number_to_human_size(backup_job.size_of_the_backup, :precision => 2) =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => backup_job} \ No newline at end of file -- cgit v1.2.3 From 120d1ddc2b4213dd30b0a863ea65be4e0decf404 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 15:11:11 +0100 Subject: logging --- misc/freeswitch/scripts/send_fax.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/misc/freeswitch/scripts/send_fax.lua b/misc/freeswitch/scripts/send_fax.lua index 9b6ffce..4898cb8 100644 --- a/misc/freeswitch/scripts/send_fax.lua +++ b/misc/freeswitch/scripts/send_fax.lua @@ -6,9 +6,9 @@ local FAX_FILE_PATH = "/opt/GS5/public/uploads/fax_document/tiff/"; local FAX_ANSWERING_TIMEOUT = 20; -- Set logger -require "common.log" +require 'common.log' local log = common.log.Log:new() -log.prefix = "### [sendfax] " +log.prefix = '#F# [sendfax] ' local document_id = argv[1]; @@ -16,12 +16,12 @@ require 'common.database' local database = common.database.Database:new{ log = log }:connect(); if not database:connected() then - log:error('cannot connect to Gemeinschaft database'); + log:error('FAX_SEND - cannot connect to Gemeinschaft database'); return end if not tonumber(document_id) then - log:error('document id not specified'); + log:error('FAX_SEND - document id not specified'); return end @@ -32,7 +32,7 @@ local fax_class = dialplan.fax.Fax:new(defaults); local fax_document = fax_class:find_document_by_id(document_id); if not fax_document then - log:error('document ' .. document_id .. ' not found'); + log:error('FAX_SEND - document ' .. document_id .. ' not found'); return end @@ -45,14 +45,14 @@ end local fax_account = fax_class:find_by_id(fax_document.fax_account_id); if not fax_account then - log:error('fax account ' .. fax_document.fax_account_id .. ' not found'); + log:error('FAX_SEND - fax account ' .. fax_document.fax_account_id .. ' not found'); return end local destination_number = fax_class:destination_number(document_id); if not destination_number or tostring(destination_number) == '' then - log:error('destination number not found'); + log:error('FAX_SEND - destination number not found'); return end -- cgit v1.2.3 From 98b822e2d139ad2c2779ce292f597d25ff6f936c Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 15:12:02 +0100 Subject: persistent database connection --- misc/freeswitch/scripts/fax_daemon.lua | 43 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/misc/freeswitch/scripts/fax_daemon.lua b/misc/freeswitch/scripts/fax_daemon.lua index 94d343a..0784890 100644 --- a/misc/freeswitch/scripts/fax_daemon.lua +++ b/misc/freeswitch/scripts/fax_daemon.lua @@ -5,38 +5,37 @@ local MAIN_LOOP_SLEEP_TIME = 30; -- Set logger -require "common.log" +require 'common.log' local log = common.log.Log:new() -log.prefix = "### [faxdaemon] " +log.prefix = '#F# [faxdaemon] ' -log:debug('Starting fax daemon'); +log:info('FAX_DAEMON start'); -local database = nil; -local api = freeswitch.API(); +require 'common.database' +local database = common.database.Database:new{ log = log }:connect(); +if not database:connected() then + log:error('FAX_DAEMON - cannot connect to Gemeinschaft database'); + return; +end +local api = freeswitch.API(); +require 'dialplan.fax' freeswitch.setGlobalVariable('gs_fax_daemon', 'true'); + while freeswitch.getGlobalVariable("gs_fax_daemon") == 'true' do - require 'common.database' - local database = common.database.Database:new{ log = log }:connect(); - - if not database:connected() then - log:error("connection to Gemeinschaft database lost - retry in " .. MAIN_LOOP_SLEEP_TIME .. " seconds") - else - require 'dialplan.fax' - local fax_documents = dialplan.fax.Fax:new{log=log, database=database}:queued_for_sending(); - - for key, fax_document in pairs(fax_documents) do - if table.getn(fax_document.destination_numbers) > 0 and tonumber(fax_document.retry_counter) > 0 then - log:debug('FAX_DAEMON_LOOP - fax_document=', fax_document.id, '/', fax_document.uuid, ', number: ' .. fax_document.destination_numbers[1]); - local result = api:executeString('luarun send_fax.lua ' .. fax_document.id); - end + local fax_documents = dialplan.fax.Fax:new{log=log, database=database}:queued_for_sending(); + + for key, fax_document in pairs(fax_documents) do + if table.getn(fax_document.destination_numbers) > 0 and tonumber(fax_document.retry_counter) > 0 then + log:debug('FAX_DAEMON_LOOP - fax_document=', fax_document.id, '/', fax_document.uuid, ', number: ' .. fax_document.destination_numbers[1]); + local result = api:executeString('luarun send_fax.lua ' .. fax_document.id); end end - database:release(); - + if freeswitch.getGlobalVariable("gs_fax_daemon") == 'true' then freeswitch.msleep(MAIN_LOOP_SLEEP_TIME * 1000); end end -log:debug('Exiting fax daemon'); +database:release(); +log:info('FAX_DAEMON exit'); -- cgit v1.2.3 From 87c71a3b6f33d28b03a8bde95cc3f921400dc8ae Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 15:51:27 +0100 Subject: module-directory added --- misc/freeswitch/conf/freeswitch.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index fd6ab67..2ecb618 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -639,6 +639,7 @@ + -- cgit v1.2.3 From 07d49f54067cfb8666f650323c7ffefe1e860b24 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 6 Feb 2013 16:03:43 +0100 Subject: Use CarrierWave to store the backup file. --- app/models/backup_job.rb | 27 +++++++---- app/uploaders/backup_file_uploader.rb | 55 ++++++++++++++++++++++ config/backup.rb | 2 +- ...20130206144829_add_backup_file_to_backup_job.rb | 5 ++ db/schema.rb | 23 ++++++++- 5 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 app/uploaders/backup_file_uploader.rb create mode 100644 db/migrate/20130206144829_add_backup_file_to_backup_job.rb diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index c9bde2b..c1f12e4 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -1,6 +1,8 @@ class BackupJob < ActiveRecord::Base attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup + mount_uploader :backup_file, BackupFileUploader + before_create :set_state_to_queued after_create :initiate_backup after_destroy :delete_the_backup_directory @@ -16,17 +18,26 @@ class BackupJob < ActiveRecord::Base end def make_a_backup + backup_directory = '/var/backups/GS5' + backup_name_prefix = 'GS5-backup-' if self.finished_at.nil? && self.state == 'queued' self.state = 'running' self.save - original_directories = Dir.glob('/var/backups/GS5/*') + original_directories = Dir.glob("#{backup_directory}/*") system "backup perform --trigger GS5 --config_file #{Rails.root.join('config','backup.rb')}" - self.directory = (Dir.glob('/var/backups/GS5/*') - original_directories).first - if self.directory.blank? + tmp_backup_directory = (Dir.glob("#{backup_directory}/*") - original_directories).first + if tmp_backup_directory.blank? self.state = 'failed' else - file = File::Stat.new(self.directory) + system "cd #{backup_directory} && tar czf #{backup_name_prefix}#{tmp_backup_directory}.tar.gz #{tmp_backup_directory}" + require 'fileutils' + FileUtils.rm_rf tmp_backup_directory + file = File::Stat.new("#{backup_directory}/#{backup_name_prefix}#{tmp_backup_directory}.tar.gz") + self.size_of_the_backup = file.size + + self.backup_file = File.open("#{backup_directory}/#{backup_name_prefix}#{tmp_backup_directory}.tar.gz") + self.finished_at = Time.now self.state = 'successful' end @@ -35,9 +46,9 @@ class BackupJob < ActiveRecord::Base end def delete_the_backup_directory - if !self.directory.blank? - require 'fileutils' - FileUtils.rm_rf self.directory - end + # if !tmp_backup_directory.blank? + # require 'fileutils' + # FileUtils.rm_rf tmp_backup_directory + # end end end diff --git a/app/uploaders/backup_file_uploader.rb b/app/uploaders/backup_file_uploader.rb new file mode 100644 index 0000000..8b126a9 --- /dev/null +++ b/app/uploaders/backup_file_uploader.rb @@ -0,0 +1,55 @@ +# encoding: utf-8 + +class BackupFileUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: + # include Sprockets::Helpers::RailsHelper + # include Sprockets::Helpers::IsolatedHelper + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process :scale => [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_white_list + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/config/backup.rb b/config/backup.rb index d57a47e..d1cbcdc 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -11,7 +11,7 @@ Backup::Model.new(:GS5, 'GS5 backup') do # Split the backup file in to chunks of 2 GB # if the backup file size exceeds 2 GB # - split_into_chunks_of 2048 + # split_into_chunks_of 2048 ## # MySQL [Database] diff --git a/db/migrate/20130206144829_add_backup_file_to_backup_job.rb b/db/migrate/20130206144829_add_backup_file_to_backup_job.rb new file mode 100644 index 0000000..e02f2b3 --- /dev/null +++ b/db/migrate/20130206144829_add_backup_file_to_backup_job.rb @@ -0,0 +1,5 @@ +class AddBackupFileToBackupJob < ActiveRecord::Migration + def change + add_column :backup_jobs, :backup_file, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5d4b5e3..5e51305 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130202140927) do +ActiveRecord::Schema.define(:version => 20130206144829) do create_table "access_authorizations", :force => true do |t| t.string "access_authorizationable_type" @@ -124,6 +124,26 @@ ActiveRecord::Schema.define(:version => 20130202140927) do t.string "music" end + create_table "backup_jobs", :force => true do |t| + t.datetime "started_at" + t.datetime "finished_at" + t.string "state" + t.string "directory" + t.integer "size_of_the_backup" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "backup_file" + end + + create_table "backups", :force => true do |t| + t.datetime "start_at" + t.datetime "end_at" + t.string "directory" + t.string "size" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "call_forward_cases", :force => true do |t| t.string "value" t.datetime "created_at", :null => false @@ -358,6 +378,7 @@ ActiveRecord::Schema.define(:version => 20130202140927) do t.string "locked_by" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "queue" end add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" -- cgit v1.2.3 From 5016e204cd2026b11aef79e3a3aa10907aa9e739 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 18:50:50 +0100 Subject: increase verbosity when request fails --- misc/freeswitch/scripts/http_request.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/http_request.lua b/misc/freeswitch/scripts/http_request.lua index 1d6f791..a74b4d8 100644 --- a/misc/freeswitch/scripts/http_request.lua +++ b/misc/freeswitch/scripts/http_request.lua @@ -29,7 +29,7 @@ end local success, result, response_headers = http.request{url = url, headers = headers }; -if success then +if success and tostring(result) == '200' then log:debug('HTTP_REQUEST - url: ', url, ', auth: ', tostring(headers.Authorization ~= nil), ', result: ', result); else log:notice('HTTP_REQUEST - url: ', url, ', auth: ', tostring(headers.Authorization ~= nil), ', result: ', result); -- cgit v1.2.3 From df663953901e5d4192cb38e56f5b6e27d6daf3fb Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 6 Feb 2013 18:53:46 +0100 Subject: inband dtmf code detection --- misc/freeswitch/scripts/dialplan/sip_call.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 806c72c..1b5c6e1 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -195,6 +195,12 @@ function SipCall.fork(self, destinations, arg ) fork_index = tonumber(session_callee:getVariable('gs_fork_index')) or 0; local destination = destinations[fork_index]; + if arg.detect_dtmf_after_bridge_caller then + session:execute('start_dtmf'); + end + if arg.detect_dtmf_after_bridge_callee then + session_callee:execute('start_dtmf'); + end if arg.bypass_media_network then local callee_uuid = session_callee:get_uuid(); -- cgit v1.2.3 From 72f100c680ddcf9c36448ae3ee367eab19052adc Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Feb 2013 09:27:43 +0100 Subject: Use CarrierWave to store the tar.gz. Removed size_of_the_backup attribute. --- app/models/backup_job.rb | 15 ++++----------- ...207082728_remove_size_of_the_backup_from_backup_job.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20130207082728_remove_size_of_the_backup_from_backup_job.rb diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index c1f12e4..78d95a7 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -5,7 +5,6 @@ class BackupJob < ActiveRecord::Base before_create :set_state_to_queued after_create :initiate_backup - after_destroy :delete_the_backup_directory private def set_state_to_queued @@ -29,14 +28,14 @@ class BackupJob < ActiveRecord::Base if tmp_backup_directory.blank? self.state = 'failed' else - system "cd #{backup_directory} && tar czf #{backup_name_prefix}#{tmp_backup_directory}.tar.gz #{tmp_backup_directory}" + system "cd #{backup_directory} && tar czf #{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz #{File.basename(tmp_backup_directory)}" require 'fileutils' FileUtils.rm_rf tmp_backup_directory - file = File::Stat.new("#{backup_directory}/#{backup_name_prefix}#{tmp_backup_directory}.tar.gz") + file = File::Stat.new("#{backup_directory}/#{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz") - self.size_of_the_backup = file.size + self.directory = File.basename(tmp_backup_directory) - self.backup_file = File.open("#{backup_directory}/#{backup_name_prefix}#{tmp_backup_directory}.tar.gz") + self.backup_file = File.open("#{backup_directory}/#{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz") self.finished_at = Time.now self.state = 'successful' @@ -45,10 +44,4 @@ class BackupJob < ActiveRecord::Base end end - def delete_the_backup_directory - # if !tmp_backup_directory.blank? - # require 'fileutils' - # FileUtils.rm_rf tmp_backup_directory - # end - end end diff --git a/db/migrate/20130207082728_remove_size_of_the_backup_from_backup_job.rb b/db/migrate/20130207082728_remove_size_of_the_backup_from_backup_job.rb new file mode 100644 index 0000000..a902fd2 --- /dev/null +++ b/db/migrate/20130207082728_remove_size_of_the_backup_from_backup_job.rb @@ -0,0 +1,9 @@ +class RemoveSizeOfTheBackupFromBackupJob < ActiveRecord::Migration + def up + remove_column :backup_jobs, :size_of_the_backup + end + + def down + add_column :backup_jobs, :size_of_the_backup, :string + end +end -- cgit v1.2.3 From 5e8237d8a8cf17009189fcf0259fb1b8a50ab429 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Feb 2013 10:49:01 +0100 Subject: Bugfixes. --- app/models/backup_job.rb | 2 +- app/views/backup_jobs/_form_core.html.haml | 1 - app/views/backup_jobs/_index_core.html.haml | 4 ++-- app/views/backup_jobs/show.html.haml | 3 ++- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index 78d95a7..8bb7959 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -1,5 +1,5 @@ class BackupJob < ActiveRecord::Base - attr_accessible :started_at, :finished_at, :state, :directory, :size_of_the_backup + attr_accessible :started_at, :finished_at, :state, :directory mount_uploader :backup_file, BackupFileUploader diff --git a/app/views/backup_jobs/_form_core.html.haml b/app/views/backup_jobs/_form_core.html.haml index 536fb18..9d439c5 100644 --- a/app/views/backup_jobs/_form_core.html.haml +++ b/app/views/backup_jobs/_form_core.html.haml @@ -3,4 +3,3 @@ = f.input :finished_at, :label => t('backup_jobs.form.finished_at.label'), :hint => conditional_hint('backup_jobs.form.finished_at.hint') = f.input :state, :label => t('backup_jobs.form.state.label'), :hint => conditional_hint('backup_jobs.form.state.hint') = f.input :directory, :label => t('backup_jobs.form.directory.label'), :hint => conditional_hint('backup_jobs.form.directory.hint') - = f.input :size_of_the_backup, :label => t('backup_jobs.form.size_of_the_backup.label'), :hint => conditional_hint('backup_jobs.form.size_of_the_backup.hint') diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml index a706424..9eebefd 100644 --- a/app/views/backup_jobs/_index_core.html.haml +++ b/app/views/backup_jobs/_index_core.html.haml @@ -26,6 +26,6 @@ = l backup_job.finished_at, :format => :short %td= backup_job.state %td - - if !backup_job.size_of_the_backup.blank? - = number_to_human_size(backup_job.size_of_the_backup, :precision => 2) + - if backup_job.backup_file? + = number_to_human_size(backup_job.backup_file.size, :precision => 2) =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => backup_job} \ No newline at end of file diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index 65091b8..5d85bbc 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -14,6 +14,7 @@ = @backup_job.directory %p %strong= t('backup_jobs.show.size_of_the_backup') + ":" - = number_to_human_size(@backup_job.size_of_the_backup, :precision => 2) + - if @backup_job.backup_file? + = number_to_human_size(@backup_job.backup_file.size, :precision => 2) = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job } \ No newline at end of file -- cgit v1.2.3 From a41d928d0f7a0db062214532e6df6f9db410756e Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Feb 2013 11:15:42 +0100 Subject: Added faxes to the backup. --- config/backup.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/config/backup.rb b/config/backup.rb index d1cbcdc..3bb0d30 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -29,10 +29,9 @@ Backup::Model.new(:GS5, 'GS5 backup') do ## # Faxes # - #archive :faxes do |archive| - # archive.add '/opt/gemeinschaft/public/uploads/fax_document/' - # archive.add '/opt/gemeinschaft/public/uploads/fax_thumbnail/' - #end + archive :faxes do |archive| + archive.add '/opt/gemeinschaft/public/uploads/fax_document' + end ## # Voicemails -- cgit v1.2.3 From 45761a957746f9787ffe438b14014a6913cfabcf Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Feb 2013 11:39:53 +0100 Subject: Check if the directories exist (otherwise tar starts to cry like a baby). --- config/backup.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config/backup.rb b/config/backup.rb index 3bb0d30..0057f01 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -30,14 +30,18 @@ Backup::Model.new(:GS5, 'GS5 backup') do # Faxes # archive :faxes do |archive| - archive.add '/opt/gemeinschaft/public/uploads/fax_document' + if File.exists?('/opt/gemeinschaft/public/uploads/fax_document') + archive.add '/opt/gemeinschaft/public/uploads/fax_document' + end end ## # Voicemails # archive :voicemails do |archive| - archive.add '/var/opt/gemeinschaft/freeswitch/voicemail/' + if File.exists?('/var/opt/gemeinschaft/freeswitch/voicemail') + archive.add '/var/opt/gemeinschaft/freeswitch/voicemail' + end end ## -- cgit v1.2.3 From 26eae9e70097be1cbff8baba9c3641512bcf6635 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Feb 2013 11:46:39 +0100 Subject: Different syntax. --- config/backup.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/backup.rb b/config/backup.rb index 0057f01..e5816c1 100644 --- a/config/backup.rb +++ b/config/backup.rb @@ -29,8 +29,8 @@ Backup::Model.new(:GS5, 'GS5 backup') do ## # Faxes # - archive :faxes do |archive| - if File.exists?('/opt/gemeinschaft/public/uploads/fax_document') + if File.exists?('/opt/gemeinschaft/public/uploads/fax_document') + archive :faxes do |archive| archive.add '/opt/gemeinschaft/public/uploads/fax_document' end end @@ -38,8 +38,8 @@ Backup::Model.new(:GS5, 'GS5 backup') do ## # Voicemails # - archive :voicemails do |archive| - if File.exists?('/var/opt/gemeinschaft/freeswitch/voicemail') + if File.exists?('/var/opt/gemeinschaft/freeswitch/voicemail') + archive :voicemails do |archive| archive.add '/var/opt/gemeinschaft/freeswitch/voicemail' end end -- cgit v1.2.3 From 9890298bbdfd909ab1fe5f35e53c9652d1371acd Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 14:23:26 +0100 Subject: cache routing tables --- misc/freeswitch/scripts/dialplan/router.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 0813a37..bda80a7 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -18,11 +18,16 @@ function Router.new(self, arg) self.routes = arg.routes or {}; self.caller = arg.caller; self.variables = arg.variables or {}; + self.routing_tables = {}; return object; end -function Router.read_table(self, table_name) +function Router.read_table(self, table_name, force_reload) + if not force_reload and self.routing_tables[table_name] then + return self.routing_tables[table_name]; + end + local routing_table = {}; local sql_query = 'SELECT * \ @@ -48,6 +53,8 @@ function Router.read_table(self, table_name) }); end); + self.routing_tables[table_name] = routing_table; + return routing_table; end -- cgit v1.2.3 From 515dcaf96c05e4b5d6aaaf4ff1e438ebf9a3c56a Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Feb 2013 14:30:21 +0100 Subject: Breadcrumbs for BackupJobs. --- app/controllers/backup_jobs_controller.rb | 32 +++++++++++++++---------------- app/models/backup_job.rb | 4 ++++ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/backup_jobs_controller.rb b/app/controllers/backup_jobs_controller.rb index e500f4c..4f242ba 100644 --- a/app/controllers/backup_jobs_controller.rb +++ b/app/controllers/backup_jobs_controller.rb @@ -1,10 +1,14 @@ class BackupJobsController < ApplicationController + load_and_authorize_resource :backup_job + + before_filter :spread_breadcrumbs + def index - @backup_jobs = BackupJob.all + # @backup_jobs = BackupJob.all end def show - @backup_job = BackupJob.find(params[:id]) + # @backup_job = BackupJob.find(params[:id]) end def new @@ -12,7 +16,6 @@ class BackupJobsController < ApplicationController end def create -# @backup_job = BackupJob.new(params[:backup_job]) @backup_job = BackupJob.new(:started_at => Time.now) if @backup_job.save @@ -22,22 +25,17 @@ class BackupJobsController < ApplicationController end end - # def edit - # @backup_job = BackupJob.find(params[:id]) - # end - - # def update - # @backup_job = BackupJob.find(params[:id]) - # if @backup_job.update_attributes(params[:backup_job]) - # redirect_to @backup_job, :notice => t('backup_jobs.controller.successfuly_updated') - # else - # render :edit - # end - # end - def destroy - @backup_job = BackupJob.find(params[:id]) + # @backup_job = BackupJob.find(params[:id]) @backup_job.destroy redirect_to backup_jobs_url, :notice => t('backup_jobs.controller.successfuly_destroyed') end + + private + def spread_breadcrumbs + add_breadcrumb t("backup_jobs.index.page_title"), backup_jobs_path + if @backup_job && !@backup_job.new_record? + add_breadcrumb @backup_job, @backup_job + end + end end diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index 8bb7959..96574a7 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -6,6 +6,10 @@ class BackupJob < ActiveRecord::Base before_create :set_state_to_queued after_create :initiate_backup + def to_s + self.started_at.to_s + end + private def set_state_to_queued self.state = 'queued' -- cgit v1.2.3 From fa243f49c53d05c8b5510cd6ba062517cbc952cf Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 15:11:53 +0100 Subject: dtmf handling class added --- misc/freeswitch/scripts/dialplan/dtmf.lua | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 misc/freeswitch/scripts/dialplan/dtmf.lua diff --git a/misc/freeswitch/scripts/dialplan/dtmf.lua b/misc/freeswitch/scripts/dialplan/dtmf.lua new file mode 100644 index 0000000..0094d05 --- /dev/null +++ b/misc/freeswitch/scripts/dialplan/dtmf.lua @@ -0,0 +1,69 @@ +-- Gemeinschaft 5 module: dtmf class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Dtmf = {} + +-- create dtmf object +function Dtmf.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'Dtmf'; + self.log = arg.log; + self.bleg = arg.bleg + self.digit_timeout = arg.digit_timeout or 5; + self.router = arg.router; + + return object; +end + + +function Dtmf.detect(self, caller, sequence, digit, duration, calee) + local timestamp = os.time(); + if timestamp - sequence.updated > self.digit_timeout then + sequence.digits = digit; + else + sequence.digits = sequence.digits .. digit; + end + + caller.dtmf_digits = sequence.digits; + + if calee then + self.log:info('DTMF_RECEIVER callee - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); + else + self.log:info('DTMF_RECEIVER caller - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); + end + + local route = self.router:route_run('dtmf', true); + sequence.updated = timestamp; + + if not route then + return; + end + + if route.type == 'dialplanfunction' or route.type == 'phonenumber' or route.type == 'unknown' then + self:transfer(caller, route.destination_number, calee) + else + self.log:notice('DTMF_RECEIVER - unhandled destination: ', route.type, '=', route.id); + end +end + + +function Dtmf.transfer(self, caller, destination, calee) + require 'common.fapi' + local fapi = common.fapi.FApi:new{ log = log }; + local callee_uuid = caller:to_s('bridge_to'); + + self.log:notice('DTMF_RECEIVER_TRANSFER - destination: ', destination, ', uuid: ', caller.uuid, ', callee_uuid: ', callee_uuid, ', callee_initiated: ', calee); + if calee then + caller:execute('transfer', destination); + fapi:execute('uuid_kill', callee_uuid); + else + fapi:execute('uuid_transfer', callee_uuid .. ' ' .. destination); + caller.session:hangup(); + end +end -- cgit v1.2.3 From 3ea1b7bf7b808a88c6d5f05ea9c5071a5fcfb082 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 15:12:49 +0100 Subject: rudimentary call parking added --- misc/freeswitch/scripts/dialplan/functions.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 32fad78..4430be1 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -111,6 +111,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = "+" .. tostring(parameters[3]); elseif fid == "hangup" then result = self:hangup(caller, parameters[3], parameters[4]); + elseif fid == "park" then + result = self:park(caller, parameters[3]); end return result; @@ -911,3 +913,9 @@ function Functions.hangup(self, caller, code, phrase) self.log:info("FUNCTION_HANGUP code: ", code, ', phrase: ', phrase); return { continue = false, code = code, phrase = phrase:gsub('_', ' '), no_cdr = true } end + +function Functions.park(self, caller, lot) + self.log:info("FUNCTION_PARK lot: ", lot); + caller:execute("valet_park", 'valet_lot ' .. lot); + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end -- cgit v1.2.3 From 50f1c25d6ae641e48d29cc4a6742dd12ce60d4a9 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 15:13:14 +0100 Subject: dtmf routing table added --- app/models/call_route.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/call_route.rb b/app/models/call_route.rb index 1c3f70a..6e0dcab 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -2,7 +2,7 @@ class CallRoute < ActiveRecord::Base # https://github.com/rails/strong_parameters include ActiveModel::ForbiddenAttributesProtection - ROUTING_TABLES = ['prerouting', 'outbound', 'inbound'] + ROUTING_TABLES = ['prerouting', 'outbound', 'inbound', 'dtmf'] has_many :route_elements, :dependent => :destroy -- cgit v1.2.3 From ea8703cec6c82edefc65fe35fc60a1d4c0a7c1a3 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Feb 2013 20:48:24 +0100 Subject: Added whenever gem and an example daily rake task. --- Gemfile | 3 +++ Gemfile.lock | 5 +++++ config/schedule.rb | 24 ++++++++++++++++++++++++ lib/tasks/backup.rake | 6 ++++++ 4 files changed, 38 insertions(+) create mode 100644 config/schedule.rb create mode 100644 lib/tasks/backup.rake diff --git a/Gemfile b/Gemfile index 58523e1..f273864 100644 --- a/Gemfile +++ b/Gemfile @@ -82,6 +82,9 @@ gem 'thin' # Backup https://github.com/meskyanichi/backup gem 'backup' +# Cronjobs +gem 'whenever' + # Local Variables: # mode: ruby # End: diff --git a/Gemfile.lock b/Gemfile.lock index 64b9f6f..6d348e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,6 +47,7 @@ GEM carrierwave (0.8.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) + chronic (0.9.0) chunky_png (1.2.7) coderay (1.0.8) coffee-rails (3.2.2) @@ -197,6 +198,9 @@ GEM raindrops (~> 0.7) uuid (2.3.6) macaddr (~> 1.0) + whenever (0.8.2) + activesupport (>= 2.3.4) + chronic (>= 0.6.3) will_paginate (3.0.4) yajl-ruby (1.1.0) @@ -242,4 +246,5 @@ DEPENDENCIES uglifier (>= 1.3.0) unicorn uuid + whenever will_paginate diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 0000000..0b5f0ca --- /dev/null +++ b/config/schedule.rb @@ -0,0 +1,24 @@ +# Use this file to easily define all of your cron jobs. +# +# It's helpful, but not entirely necessary to understand cron before proceeding. +# http://en.wikipedia.org/wiki/Cron + +# Example: +# +# set :output, "/path/to/my/cron_log.log" +# +# every 2.hours do +# command "/usr/bin/some_great_command" +# runner "MyModel.some_method" +# rake "some:great:rake:task" +# end +# +# every 4.days do +# runner "AnotherModel.prune_old_records" +# end + +every 1.day, :at => '4:00 am' do + rake "backup:daily_backup" +end + +# Learn more: http://github.com/javan/whenever diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake new file mode 100644 index 0000000..c285e1f --- /dev/null +++ b/lib/tasks/backup.rake @@ -0,0 +1,6 @@ +namespace :backup do + desc "Backup the system" + task :daily_backup => :environment do + # This would be the daily backup. + end +end \ No newline at end of file -- cgit v1.2.3 From 5aefe7bb21d7b18f5653db439c61f7540e04e4e5 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 23:57:45 +0100 Subject: log level --- misc/freeswitch/scripts/dialplan/dtmf.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/freeswitch/scripts/dialplan/dtmf.lua b/misc/freeswitch/scripts/dialplan/dtmf.lua index 0094d05..4dbd35f 100644 --- a/misc/freeswitch/scripts/dialplan/dtmf.lua +++ b/misc/freeswitch/scripts/dialplan/dtmf.lua @@ -33,9 +33,9 @@ function Dtmf.detect(self, caller, sequence, digit, duration, calee) caller.dtmf_digits = sequence.digits; if calee then - self.log:info('DTMF_RECEIVER callee - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); + self.log:debug('DTMF_RECEIVER callee - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); else - self.log:info('DTMF_RECEIVER caller - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); + self.log:debug('DTMF_RECEIVER caller - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); end local route = self.router:route_run('dtmf', true); -- cgit v1.2.3 From 5be2f0dca65491915f97e1ddd334e8d08a3603a1 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 23:58:24 +0100 Subject: set input callback --- misc/freeswitch/scripts/dialplan/sip_call.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 1b5c6e1..61d4f76 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -232,10 +232,15 @@ function SipCall.fork(self, destinations, arg ) self.caller:set_variable('gs_destination_id', destination.id); self.caller:set_variable('gs_destination_uuid', destination.uuid); + if arg.detect_dtmf_after_bridge_callee then + session_callee:setInputCallback('input_call_back_callee', 'session_callee'); + end + self.log:info('FORK ', fork_index, ' BRIDGE - destination: ', destination.type, '=', destination.id, '/', destination.uuid,'@', destination.node_id, ', number: ', destination.number, ', dial_time: ', os.time() - start_time); + freeswitch.bridge(self.caller.session, session_callee); self:wait_hangup(self.caller.session, session_callee); end -- cgit v1.2.3 From ef562b407c14e9b145e500e64424ccd5bd31dbb4 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 23:59:27 +0100 Subject: caller input callback --- misc/freeswitch/scripts/dialplan_default.lua | 37 +++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/dialplan_default.lua b/misc/freeswitch/scripts/dialplan_default.lua index 7caff57..8fb9057 100644 --- a/misc/freeswitch/scripts/dialplan_default.lua +++ b/misc/freeswitch/scripts/dialplan_default.lua @@ -8,13 +8,28 @@ function hangup_hook_caller(s, status, arg) if tostring(status) == 'transfer' then if start_caller and start_caller.destination then log:info('CALL_TRANSFERRED - destination was: ', start_caller.destination.type, '=', start_caller.destination.id,', number: ' .. tostring(start_caller.destination.number) .. ', to: ' .. start_caller:to_s('sip_refer_to')); - start_caller.auth_account = start_dialplan:object_find(start_caller.destination.type, start_caller.destination.id); + start_caller.auth_account = start_caller.dialplan:object_find(start_caller.destination.type, start_caller.destination.id); start_caller.forwarding_number = start_caller.destination.number; start_caller.forwarding_service = 'transfer'; end end end +function input_call_back_caller(s, object_type, object_data, arg) + if object_type == 'dtmf' then + require 'dialplan.dtmf' + local dtmf = dialplan.dtmf.Dtmf:new{ log = log, router = dtmf_router }:detect(start_caller, start_caller.dtmf, object_data.digit, object_data.duration); + end +end + +function input_call_back_callee(s, object_type, object_data, arg) + if object_type == 'dtmf' then + require 'dialplan.dtmf' + local dtmf = dialplan.dtmf.Dtmf:new{ log = log, router = dtmf_router }:detect(start_caller, start_caller.dtmf_callee, object_data.digit, object_data.duration, true); + end +end + + -- initialize logging require 'common.log' log = common.log.Log:new{ prefix = '### [' .. session:get_uuid() .. '] ' }; @@ -36,8 +51,17 @@ require 'dialplan.dialplan' local start_dialplan = dialplan.dialplan.Dialplan:new{ log = log, caller = start_caller, database = database }; start_dialplan:configuration_read(); +start_caller.dialplan = start_dialplan; start_caller.local_node_id = start_dialplan.node_id; start_caller:init_channel_variables(); +start_caller.dtmf = { + updated = os.time(), + digits = ''; +}; +start_caller.dtmf_callee = { + updated = os.time(), + digits = ''; +}; if start_dialplan.config.parameters.dump_variables then start_caller:execute('info', 'notice'); @@ -72,6 +96,17 @@ if start_caller.from_node then else start_destination = { type = 'unknown' } start_caller.session:setHangupHook('hangup_hook_caller', 'destination_number'); + + require 'dialplan.router' + dtmf_router = dialplan.router.Router:new{ log = log, database = database, caller = start_caller, variables = start_caller }; + start_dialplan.dtmf_detection = #dtmf_router:read_table('dtmf') > 0; + + if start_dialplan.dtmf_detection then + start_dialplan.detect_dtmf_after_bridge_caller = true; + start_dialplan.detect_dtmf_after_bridge_callee = true; + start_caller.session:setInputCallback('input_call_back_caller', 'start_dialplan'); + end + start_dialplan:run(start_destination); end -- cgit v1.2.3 From cd909970e8443ca86ad0be09b26cf5fb616ea303 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 8 Feb 2013 10:06:34 +0100 Subject: softkey.softkey_function vs. softkey.function --- app/views/softkeys/_form_core.html.haml | 2 +- app/views/softkeys/_index_core.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/softkeys/_form_core.html.haml b/app/views/softkeys/_form_core.html.haml index b833aad..2863d5c 100644 --- a/app/views/softkeys/_form_core.html.haml +++ b/app/views/softkeys/_form_core.html.haml @@ -7,6 +7,6 @@ .inputs = f.input :softkey_function_id, :as => :select, :collection => @softkey_functions.map {|x| [I18n.t("softkeys.functions.#{x}"), x.id] }, :label => t('softkeys.form.function.label'), :hint => conditional_hint('softkeys.form.function.hint'), :include_blank => false - if @available_call_forwards && @available_call_forwards.count > 0 - = f.association :call_forward, :collection => @available_call_forwards, :label => t('softkeys.form.call_forward.label'), :hint => conditional_hint('softkeys.form.call_forward.hint'), :include_blank => false + = f.association :softkeyable, :collection => @available_call_forwards, :label => t('softkeys.form.call_forward.label'), :hint => conditional_hint('softkeys.form.call_forward.hint'), :include_blank => false = f.input :number, :label => t('softkeys.form.number.label'), :hint => conditional_hint('softkeys.form.number.hint') = f.input :label, :label => t('softkeys.form.label.label'), :hint => conditional_hint('softkeys.form.label.hint') diff --git a/app/views/softkeys/_index_core.html.haml b/app/views/softkeys/_index_core.html.haml index e2cb16c..4a06c72 100644 --- a/app/views/softkeys/_index_core.html.haml +++ b/app/views/softkeys/_index_core.html.haml @@ -15,7 +15,7 @@ - if softkeys.count > 1 %span.handle %i.icon-resize-vertical - %td= softkey.function + %td= t("softkeys.functions.#{softkey.softkey_function}") %td= softkey.number %td= softkey.label =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => softkey.sip_account, :child => softkey} \ No newline at end of file -- cgit v1.2.3 From 9e723519982c3b442aa90f3728bfddd4025d4a69 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 8 Feb 2013 10:41:18 +0100 Subject: softkey-call_forward relation polymorphic --- app/controllers/config_siemens_controller.rb | 12 ++++-- app/controllers/config_snom_controller.rb | 44 +++++++++++++++++----- app/models/call_forward.rb | 2 +- app/models/softkey.rb | 19 +++------- app/views/gs_nodes/sync.xml.haml | 2 +- app/views/softkeys/show.html.haml | 4 +- .../20130208065700_add_softkeyable_to_softkey.rb | 16 ++++++++ lib/tasks/gs_cluster.rake | 8 +++- 8 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 db/migrate/20130208065700_add_softkeyable_to_softkey.rb diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb index b7fa107..bbeba46 100644 --- a/app/controllers/config_siemens_controller.rb +++ b/app/controllers/config_siemens_controller.rb @@ -610,15 +610,21 @@ class ConfigSiemensController < ApplicationController @new_settings << ['stimulus-led-control-uri', key_idx, '' ] @new_settings << ['stimulus-DTMF-sequence', key_idx, '' ] when 'call_forwarding' + if sk.softkeyable.class == CallForward then @new_settings << ['function-key-def', key_idx, '63'] - @new_settings << ['stimulus-led-control-uri', key_idx, "f-cftg-#{sk.call_forward_id}" ] + @new_settings << ['stimulus-led-control-uri', key_idx, "f-cftg-#{sk.softkeyable.id}" ] @new_settings << ['send-url-address', key_idx, request.host] @new_settings << ['send-url-protocol', key_idx, 3] @new_settings << ['send-url-port', key_idx, '80'] @new_settings << ['send-url-path', key_idx, "/config_siemens/#{@phone.id}/#{@sip_account.id}/call_forwarding.xml"] - @new_settings << ['send-url-query', key_idx, "id=#{sk.call_forward_id}&function=toggle"] + @new_settings << ['send-url-query', key_idx, "id=#{sk.softkeyable.id}&function=toggle"] @new_settings << ['send-url-method', key_idx, '0'] @new_settings << ['blf-popup', key_idx, 'false'] + else + @new_settings << ['function-key-def', key_idx, '0'] + @new_settings << ['stimulus-led-control-uri', key_idx, '' ] + @new_settings << ['stimulus-DTMF-sequence', key_idx, '' ] + end when 'call_forwarding_always' phone_number = PhoneNumber.where(:number => sk.number, :phone_numberable_type => 'SipAccount').first if phone_number @@ -887,7 +893,7 @@ class ConfigSiemensController < ApplicationController if @call_forwarding_id call_forwarding = @sip_account.call_forwards.where(:id => @call_forwarding_id).first - if !call_forwarding and @sip_account.softkeys.where(:call_forward_id => @call_forwarding_id).count > 0 + if !call_forwarding and @sip_account.softkeys.where(:softkeyable_id => @call_forwarding_id, :softkeyable_type => 'CallForward').count > 0 call_forwarding = CallForward.where(:id => @call_forwarding_id).first end diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb index 33b63da..58cced2 100644 --- a/app/controllers/config_snom_controller.rb +++ b/app/controllers/config_snom_controller.rb @@ -282,23 +282,47 @@ class ConfigSnomController < ApplicationController @softkeys.push({:context => sip_account_index, :label => softkey.label, :data => "speed f-li-#{softkey.number}"}) when 'conference' @softkeys.push({:context => sip_account_index, :label => softkey.label, :data => "blf |f-ta-"}) - when 'call_forwarding' + when 'call_parking' @softkeys.push({ :context => sip_account_index, - :function => softkey.function, + :function => softkey.softkey_function.name, :label => softkey.label, :softkey => softkey, :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"), :subscription => { - :to => "f-cftg-#{softkey.call_forward_id}@#{sip_account.host}", + :to => "park+#{@softkeys.softkeyable_id}@#{sip_account.host}", :for => "#{sip_account.auth_name}@#{sip_account.host}" }, :actions => [{ - :type => :url, - :target => "#{request.protocol}#{request.host_with_port}/config_snom/#{@phone.id}/#{snom_sip_account[:id]}/call_forwarding.xml?id=#{softkey.call_forward_id}&function=toggle", + :type => :dial, + :target => "f-tpark-#{@softkeys.softkeyable_id}", + :when => 'on press', + :states => 'connected,holding', + },{ + :type => :dial, + :target => "f-park-#{@softkeys.softkeyable_id}", :when => 'on press', }], }) + when 'call_forwarding' + if softkey.softkeyable.class == CallForward then + @softkeys.push({ + :context => sip_account_index, + :function => softkey.softkey_function.name, + :label => softkey.label, + :softkey => softkey, + :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"), + :subscription => { + :to => "f-cftg-#{softkey.softkeyable_id}@#{sip_account.host}", + :for => "#{sip_account.auth_name}@#{sip_account.host}" + }, + :actions => [{ + :type => :url, + :target => "#{request.protocol}#{request.host_with_port}/config_snom/#{@phone.id}/#{snom_sip_account[:id]}/call_forwarding.xml?id=#{softkey.softkeyable_id}&function=toggle", + :when => 'on press', + }], + }) + end when 'call_forwarding_always' phone_number = PhoneNumber.where(:number => softkey.number, :phone_numberable_type => 'SipAccount').first if phone_number @@ -310,7 +334,7 @@ class ConfigSnomController < ApplicationController @softkeys.push({ :context => sip_account_index, - :function => softkey.function, + :function => softkey.softkey_function.name, :label => softkey.label, :softkey => softkey, :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"), @@ -335,7 +359,7 @@ class ConfigSnomController < ApplicationController @softkeys.push({ :context => sip_account_index, - :function => softkey.function, + :function => softkey.softkey_function.name, :label => softkey.label, :softkey => softkey, :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"), @@ -375,7 +399,7 @@ class ConfigSnomController < ApplicationController if hunt_group_member @softkeys.push({ :context => sip_account_index, - :function => softkey.function, + :function => softkey.softkey_function.name, :label => softkey.label, :softkey => softkey, :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"), @@ -405,7 +429,7 @@ class ConfigSnomController < ApplicationController if acd_agent @softkeys.push({ :context => sip_account_index, - :function => softkey.function, + :function => softkey.softkey_function.name, :label => softkey.label, :softkey => softkey, :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"), @@ -924,7 +948,7 @@ AAAA' if @call_forwarding_id call_forwarding = @sip_account.call_forwards.where(:id => @call_forwarding_id).first - if !call_forwarding and @sip_account.softkeys.where(:call_forward_id => @call_forwarding_id).count > 0 + if !call_forwarding and @sip_account.softkeys.where(:softkeyable_id => @call_forwarding_id, :softkeyable_type => 'CallForward').count > 0 call_forwarding = CallForward.where(:id => @call_forwarding_id).first end diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb index 8a8d1df..c668993 100644 --- a/app/models/call_forward.rb +++ b/app/models/call_forward.rb @@ -145,7 +145,7 @@ class CallForward < ActiveRecord::Base softkey_function_deactivated = SoftkeyFunction.find_by_name('deactivated') self.softkeys.each do |softkey| if softkey.softkey_function_id != softkey_function_deactivated.id - softkey.update_attributes(:call_forward_id => nil, :softkey_function_id => softkey_function_deactivated.id) + softkey.update_attributes(:softkeyable_id => nil, :softkeyable_type => nil, :softkey_function_id => softkey_function_deactivated.id) end end end diff --git a/app/models/softkey.rb b/app/models/softkey.rb index a709036..f038acd 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -1,13 +1,11 @@ class Softkey < ActiveRecord::Base - attr_accessible :softkey_function_id, :number, :label, :call_forward_id, :uuid + attr_accessible :softkey_function_id, :number, :label, :uuid, :softkeyable_type, :softkeyable_id belongs_to :sip_account belongs_to :softkey_function - belongs_to :call_forward + belongs_to :softkeyable, :polymorphic => true - # Any CallForward BLF must have a valid softkey_call_forward_id. - # - validates_presence_of :call_forward_id, :if => Proc.new{ |softkey| self.softkey_function_id != nil && + validates_presence_of :softkeyable_id, :if => Proc.new{ |softkey| self.softkey_function_id != nil && self.softkey_function_id == SoftkeyFunction.find_by_name('call_forwarding').try(:id) } # These functions need a number to act. @@ -21,7 +19,6 @@ class Softkey < ActiveRecord::Base acts_as_list :scope => :sip_account before_validation :clean_up_and_leave_only_values_which_make_sense_for_the_current_softkey_function_id - after_validation :save_function_name_in_function, :if => Proc.new{ |softkey| self.call_forward_id.blank? } after_save :resync_phone after_destroy :resync_phone @@ -52,7 +49,7 @@ class Softkey < ActiveRecord::Base def to_s if (['call_forwarding'].include?(self.softkey_function.name)) - "#{self.call_forward}" + "#{self.softkeyable}" else if ['log_out', 'log_in'].include?(self.softkey_function.name) I18n.t("softkeys.functions.#{self.softkey_function.name}") @@ -78,18 +75,14 @@ class Softkey < ActiveRecord::Base end private - - def save_function_name_in_function - self.function = self.softkey_function.name - end - # Make sure that no number is set when there is no need for one. # And make sure that there is no CallForward connected when not needed. # def clean_up_and_leave_only_values_which_make_sense_for_the_current_softkey_function_id if self.softkey_function_id != nil if ['blf','speed_dial','dtmf','conference'].include?(self.softkey_function.name) - self.call_forward_id = nil + self.softkeyable_id = nil + self.softkeyable_type = nil end if ['call_forwarding'].include?(self.softkey_function.name) self.number = nil diff --git a/app/views/gs_nodes/sync.xml.haml b/app/views/gs_nodes/sync.xml.haml index 0f097f8..a2fa71a 100644 --- a/app/views/gs_nodes/sync.xml.haml +++ b/app/views/gs_nodes/sync.xml.haml @@ -60,7 +60,7 @@ - if !@softkeys.blank? %softkeys - @softkeys.each do |softkey| - %softkey{ :uuid => softkey.uuid, :function => softkey.softkey_function.try(:name), :number => softkey.number, :label => softkey.label, :position => softkey.position, :created_at => softkey.created_at, :updated_at => softkey.updated_at, :sip_account_uuid => softkey.sip_account.try(:uuid), :call_forward_uuid => softkey.call_forward.try(:uuid) } + %softkey{ :uuid => softkey.uuid, :function => softkey.softkey_function.try(:name), :number => softkey.number, :label => softkey.label, :position => softkey.position, :created_at => softkey.created_at, :updated_at => softkey.updated_at, :sip_account_uuid => softkey.sip_account.try(:uuid), :softkeyable_uuid => softkey.softkeyable.try(:uuid), :softkeyable_type => softkey.softkeyable_type) } - if !@ringtones.blank? %ringtones diff --git a/app/views/softkeys/show.html.haml b/app/views/softkeys/show.html.haml index d0db111..7c068ae 100644 --- a/app/views/softkeys/show.html.haml +++ b/app/views/softkeys/show.html.haml @@ -1,7 +1,7 @@ - content_for :title, t("softkeys.show.page_title") %p - %strong= t('softkeys.show.function') + ":" + %strong= t("softkeys.functions.#{@softkey.softkey_function}") + ":" =@softkey.to_s -= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @softkey.sip_account, :child => @softkey } \ No newline at end of file += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @softkey.sip_account, :child => @softkey } diff --git a/db/migrate/20130208065700_add_softkeyable_to_softkey.rb b/db/migrate/20130208065700_add_softkeyable_to_softkey.rb new file mode 100644 index 0000000..deae9a0 --- /dev/null +++ b/db/migrate/20130208065700_add_softkeyable_to_softkey.rb @@ -0,0 +1,16 @@ +class AddSoftkeyableToSoftkey < ActiveRecord::Migration + def up + add_column :softkeys, :softkeyable_type, :string + add_column :softkeys, :softkeyable_id, :integer + Softkey.where('call_forward_id > 0').each do |softkey| + softkey.update_attributes( :softkeyable_type => 'CallForward', :softkeyable_id => softkey.call_forward_id ) + end + remove_column :softkeys, :call_forward_id + end + + def down + remove_column :softkeys, :softkeyable_type + remove_column :softkeys, :softkeyable_id + add_column :softkeys, :call_forward_id, :integer + end +end diff --git a/lib/tasks/gs_cluster.rake b/lib/tasks/gs_cluster.rake index 7b49ebb..c248c32 100644 --- a/lib/tasks/gs_cluster.rake +++ b/lib/tasks/gs_cluster.rake @@ -201,10 +201,14 @@ namespace :gs_cluster do remote_objects(remote_site, local_node_id, last_sync, Softkey).each do |remote_object| attributes = make_hash(remote_object.attributes) attributes[:sip_account_id] = SipAccount.where(:uuid => attributes[:sip_account_uuid]).first.try(:id) - attributes[:call_forward_id] = CallForward.where(:uuid => attributes[:call_forward_uuid]).first.try(:id) + + if ! attributes[:softkeyable_uuid].blank? + attributes[:softkeyable_id] = attributes[:softkeyable_type].constantize.where(:uuid => attributes[:softkeyable_uuid]).first.try(:id) + end + attributes[:softkey_function_id] = SoftkeyFunction.where(:name => attributes[:function]).first.try(:id) attributes.delete(:sip_account_uuid) - attributes.delete(:call_forward_uuid) + attributes.delete(:softkeyable_uuid) attributes.delete(:softkey_function) process_object(Softkey, Softkey, Softkey.where(:uuid => attributes[:uuid]).first, attributes) end -- cgit v1.2.3 From 901eb1ce8bdbfcd85678e06086cce5a0d7b50123 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 8 Feb 2013 11:51:55 +0100 Subject: set softkeyable --- app/models/softkey.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/softkey.rb b/app/models/softkey.rb index f038acd..3ae7e95 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -85,6 +85,7 @@ class Softkey < ActiveRecord::Base self.softkeyable_type = nil end if ['call_forwarding'].include?(self.softkey_function.name) + self.softkeyable = CallForward.where(:id => self.softkeyable_id).first self.number = nil end end -- cgit v1.2.3 From af5179a4a59bc21467448f292c752082dd8927b8 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 8 Feb 2013 12:06:16 +0100 Subject: set softkeyable --- app/models/softkey.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 3ae7e95..83c88ab 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -79,14 +79,18 @@ class Softkey < ActiveRecord::Base # And make sure that there is no CallForward connected when not needed. # def clean_up_and_leave_only_values_which_make_sense_for_the_current_softkey_function_id - if self.softkey_function_id != nil - if ['blf','speed_dial','dtmf','conference'].include?(self.softkey_function.name) - self.softkeyable_id = nil - self.softkeyable_type = nil - end - if ['call_forwarding'].include?(self.softkey_function.name) + if self.softkey_function_id != nil + case self.softkey_function.name + when 'blf' + self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'SipAccount').first.try(:phone_numberable) + when 'conference' + self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'Conference').first.try(:phone_numberable) + when 'call_forwarding' self.softkeyable = CallForward.where(:id => self.softkeyable_id).first self.number = nil + else + self.softkeyable_id = nil + self.softkeyable_type = nil end end end -- cgit v1.2.3 From 72e22a8aaf7ad212ed888b7d5a7c94d1c9cbd6b2 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 8 Feb 2013 23:25:20 +0100 Subject: return result --- misc/freeswitch/scripts/common/fapi.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/misc/freeswitch/scripts/common/fapi.lua b/misc/freeswitch/scripts/common/fapi.lua index 5b96633..b749a69 100644 --- a/misc/freeswitch/scripts/common/fapi.lua +++ b/misc/freeswitch/scripts/common/fapi.lua @@ -32,8 +32,10 @@ function FApi.return_result(self, result, positive, negative, unspecified) return negative; elseif result:match('^+OK') then return positive; - else + elseif type(unspecified) ~= 'nil' then return unspecified; + else + return result; end end @@ -75,6 +77,7 @@ function FApi.create_uuid(self, uuid) end function FApi.execute(self, function_name, function_parameters) + function_parameters = function_parameters or ''; local result = self.fs_api:execute(function_name, function_parameters); return self:return_result(result, true); end -- cgit v1.2.3 From db31cc867b1e99b4d388b1835dbaec2ad845c29a Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 9 Feb 2013 09:50:54 +0100 Subject: gateway has routes --- app/models/gateway.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/gateway.rb b/app/models/gateway.rb index a8df41f..eea1e33 100644 --- a/app/models/gateway.rb +++ b/app/models/gateway.rb @@ -5,6 +5,7 @@ class Gateway < ActiveRecord::Base has_many :gateway_settings, :dependent => :destroy has_many :gateway_parameters, :dependent => :destroy + has_many :call_routes, :as => :endpoint, :dependent => :nullify validates :name, :presence => true, -- cgit v1.2.3 From ff67b61369dba20747babfb642fb2086bbaff4a9 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 9 Feb 2013 09:51:22 +0100 Subject: gateway xml view added --- app/views/gateways/show.xml.haml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/views/gateways/show.xml.haml diff --git a/app/views/gateways/show.xml.haml b/app/views/gateways/show.xml.haml new file mode 100644 index 0000000..5e2806d --- /dev/null +++ b/app/views/gateways/show.xml.haml @@ -0,0 +1,17 @@ +!!! XML +%gateway{ :id => @gateway.id, :name => @gateway.name, :technology => @gateway.technology, :inbound => @gateway.inbound.to_s, :outbound => @gateway.outbound.to_s, :description => @gateway.description } + + %gateway_settings{ :count => @gateway.gateway_settings.count } + - @gateway.gateway_settings.each do |setting| + %setting{ :name => setting.name, :value => setting.value, :class_type => setting.class_type, :description => setting.description } + + %gateway_parameters{ :count => @gateway.gateway_parameters.count } + - @gateway.gateway_parameters.each do |parameter| + %parameter{ :name => parameter.name, :value => parameter.value, :class_type => parameter.class_type, :description => parameter.description } + + %call_routes{ :count => @gateway.call_routes.count } + - @gateway.call_routes.each do |call_route| + %call_route{ :name => call_route.name, :routing_table => call_route.routing_table, :position => call_route.position } + %route_elements{ :count => call_route.route_elements.count } + - call_route.route_elements.each do |route_element| + %route_element{ :var_in => route_element.var_in, :var_out => route_element.var_out, :pattern => route_element.pattern, :replacement => route_element.replacement, :action => route_element.action, :mandatory => route_element.mandatory.to_s, :position => route_element.position } -- cgit v1.2.3 From 42a8e4808e343975042730ab3847303184d73b92 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 9 Feb 2013 10:05:00 +0100 Subject: identifier added --- app/models/gateway.rb | 5 +++++ app/views/gateways/show.xml.haml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/gateway.rb b/app/models/gateway.rb index eea1e33..2f17b57 100644 --- a/app/models/gateway.rb +++ b/app/models/gateway.rb @@ -1,5 +1,6 @@ class Gateway < ActiveRecord::Base TECHNOLOGIES = ['sip', 'xmpp'] + GATEWAY_PREFIX = 'gateway' attr_accessible :name, :technology, :inbound, :outbound, :description @@ -22,6 +23,10 @@ class Gateway < ActiveRecord::Base name end + def identifier + "#{GATEWAY_PREFIX}#{self.id}" + end + private def downcase_technology self.technology = self.technology.downcase if !self.technology.blank? diff --git a/app/views/gateways/show.xml.haml b/app/views/gateways/show.xml.haml index 5e2806d..e0ff21a 100644 --- a/app/views/gateways/show.xml.haml +++ b/app/views/gateways/show.xml.haml @@ -1,5 +1,5 @@ !!! XML -%gateway{ :id => @gateway.id, :name => @gateway.name, :technology => @gateway.technology, :inbound => @gateway.inbound.to_s, :outbound => @gateway.outbound.to_s, :description => @gateway.description } +%gateway{ :identifier => @gateway.identifier, :name => @gateway.name, :technology => @gateway.technology, :inbound => @gateway.inbound.to_s, :outbound => @gateway.outbound.to_s, :description => @gateway.description } %gateway_settings{ :count => @gateway.gateway_settings.count } - @gateway.gateway_settings.each do |setting| -- cgit v1.2.3 From e497de90ccf55b3cbec1de7890e20220fa8e603f Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 9 Feb 2013 10:27:24 +0100 Subject: call_route xml view added --- app/views/call_routes/show.xml.haml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/views/call_routes/show.xml.haml diff --git a/app/views/call_routes/show.xml.haml b/app/views/call_routes/show.xml.haml new file mode 100644 index 0000000..5800816 --- /dev/null +++ b/app/views/call_routes/show.xml.haml @@ -0,0 +1,5 @@ +!!! XML +%call_route{ :name => @call_route.name, :routing_table => @call_route.routing_table, :position => @call_route.position, :endpoint => @call_route.endpoint, :endpoint_type => @call_route.endpoint_type } + %route_elements{ :count => @call_route.route_elements.count } + - @call_route.route_elements.each do |route_element| + %route_element{ :var_in => route_element.var_in, :var_out => route_element.var_out, :pattern => route_element.pattern, :replacement => route_element.replacement, :action => route_element.action, :mandatory => route_element.mandatory.to_s, :position => route_element.position } -- cgit v1.2.3 From cc4dda2b37119e1364cf0a5362aedfae639bcbc7 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 9 Feb 2013 11:12:57 +0100 Subject: duplicate ids fixed --- app/views/call_routes/_index_core.html.haml | 2 +- app/views/call_routes/index.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/call_routes/_index_core.html.haml b/app/views/call_routes/_index_core.html.haml index b6c5d33..6f2eadd 100644 --- a/app/views/call_routes/_index_core.html.haml +++ b/app/views/call_routes/_index_core.html.haml @@ -7,7 +7,7 @@ %th= t('route_elements.index.pattern') %th= t('call_routes.index.endpoint') - %tbody{ :id => "call_routes", :'data-update-url' => sort_call_routes_url} + %tbody{ :id => "call_routes_#{routing_table}", :'data-update-url' => sort_call_routes_url} - for call_route in call_routes - cache(['call_route_single_table_row', I18n.locale, call_route]) do = content_tag_for :tr, call_route do diff --git a/app/views/call_routes/index.html.haml b/app/views/call_routes/index.html.haml index d5181e3..0108322 100644 --- a/app/views/call_routes/index.html.haml +++ b/app/views/call_routes/index.html.haml @@ -3,6 +3,6 @@ - if @call_routes && @call_routes.any? - @routing_tables.each do |routing_table| %h3= routing_table - = render "index_core", :call_routes => @call_routes.where(:routing_table => routing_table) + = render "index_core", :call_routes => @call_routes.where(:routing_table => routing_table), :routing_table => routing_table = render :partial => 'shared/create_link', :locals => {:child_class => CallRoute} -- cgit v1.2.3 From 5fba89e83722e11232b1130a1a939d55aed94387 Mon Sep 17 00:00:00 2001 From: spag Date: Sat, 9 Feb 2013 11:24:36 +0100 Subject: multiple css ids bug fixed --- app/assets/javascripts/call_route.js.coffee | 2 +- app/assets/stylesheets/call_routes.css.scss | 2 +- app/views/call_routes/_index_core.html.haml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/call_route.js.coffee b/app/assets/javascripts/call_route.js.coffee index 91d62ca..fab7f10 100644 --- a/app/assets/javascripts/call_route.js.coffee +++ b/app/assets/javascripts/call_route.js.coffee @@ -1,5 +1,5 @@ jQuery -> - $('#call_routes').sortable + $('.call_routes').sortable axis: 'y' handle: '.handle' update: -> diff --git a/app/assets/stylesheets/call_routes.css.scss b/app/assets/stylesheets/call_routes.css.scss index 7face3b..d39e1d1 100644 --- a/app/assets/stylesheets/call_routes.css.scss +++ b/app/assets/stylesheets/call_routes.css.scss @@ -1,4 +1,4 @@ -#call_routes .handle { +.call_routes .handle { font-size: 12px; color: #777; cursor: move; diff --git a/app/views/call_routes/_index_core.html.haml b/app/views/call_routes/_index_core.html.haml index 6f2eadd..a62a9c4 100644 --- a/app/views/call_routes/_index_core.html.haml +++ b/app/views/call_routes/_index_core.html.haml @@ -7,7 +7,7 @@ %th= t('route_elements.index.pattern') %th= t('call_routes.index.endpoint') - %tbody{ :id => "call_routes_#{routing_table}", :'data-update-url' => sort_call_routes_url} + %tbody{ :class => "call_routes", :id => "call_routes_#{routing_table}", :'data-update-url' => sort_call_routes_url} - for call_route in call_routes - cache(['call_route_single_table_row', I18n.locale, call_route]) do = content_tag_for :tr, call_route do -- cgit v1.2.3 From 4c9cc92c0a49ec34c8bf00e31d1710450fb533fa Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sun, 10 Feb 2013 08:09:05 +0000 Subject: firewall blacklist model added --- app/controllers/intruders_controller.rb | 41 ++++++++++ app/helpers/intruders_helper.rb | 2 + app/models/intruder.rb | 3 + app/views/intruders/_form.html.haml | 7 ++ app/views/intruders/_form_core.html.haml | 16 ++++ app/views/intruders/_index_core.html.haml | 37 +++++++++ app/views/intruders/edit.html.haml | 3 + app/views/intruders/index.html.haml | 6 ++ app/views/intruders/new.html.haml | 3 + app/views/intruders/show.html.haml | 49 ++++++++++++ config/locales/views/intruders/de.yml | 110 ++++++++++++++++++++++++++ config/locales/views/intruders/en.yml | 110 ++++++++++++++++++++++++++ config/routes.rb | 2 + db/migrate/20130210075617_create_intruders.rb | 26 ++++++ test/functional/intruders_controller_test.rb | 49 ++++++++++++ test/unit/intruder_test.rb | 7 ++ 16 files changed, 471 insertions(+) create mode 100644 app/controllers/intruders_controller.rb create mode 100644 app/helpers/intruders_helper.rb create mode 100644 app/models/intruder.rb create mode 100644 app/views/intruders/_form.html.haml create mode 100644 app/views/intruders/_form_core.html.haml create mode 100644 app/views/intruders/_index_core.html.haml create mode 100644 app/views/intruders/edit.html.haml create mode 100644 app/views/intruders/index.html.haml create mode 100644 app/views/intruders/new.html.haml create mode 100644 app/views/intruders/show.html.haml create mode 100644 config/locales/views/intruders/de.yml create mode 100644 config/locales/views/intruders/en.yml create mode 100644 db/migrate/20130210075617_create_intruders.rb create mode 100644 test/functional/intruders_controller_test.rb create mode 100644 test/unit/intruder_test.rb diff --git a/app/controllers/intruders_controller.rb b/app/controllers/intruders_controller.rb new file mode 100644 index 0000000..eb34f2b --- /dev/null +++ b/app/controllers/intruders_controller.rb @@ -0,0 +1,41 @@ +class IntrudersController < ApplicationController + def index + @intruders = Intruder.all + end + + def show + @intruder = Intruder.find(params[:id]) + end + + def new + @intruder = Intruder.new + end + + def create + @intruder = Intruder.new(params[:intruder]) + if @intruder.save + redirect_to @intruder, :notice => t('intruders.controller.successfuly_created') + else + render :new + end + end + + def edit + @intruder = Intruder.find(params[:id]) + end + + def update + @intruder = Intruder.find(params[:id]) + if @intruder.update_attributes(params[:intruder]) + redirect_to @intruder, :notice => t('intruders.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @intruder = Intruder.find(params[:id]) + @intruder.destroy + redirect_to intruders_url, :notice => t('intruders.controller.successfuly_destroyed') + end +end diff --git a/app/helpers/intruders_helper.rb b/app/helpers/intruders_helper.rb new file mode 100644 index 0000000..7243cf3 --- /dev/null +++ b/app/helpers/intruders_helper.rb @@ -0,0 +1,2 @@ +module IntrudersHelper +end diff --git a/app/models/intruder.rb b/app/models/intruder.rb new file mode 100644 index 0000000..192d64d --- /dev/null +++ b/app/models/intruder.rb @@ -0,0 +1,3 @@ +class Intruder < ActiveRecord::Base + attr_accessible :list_type, :key, :points, :bans, :ban_last, :ban_end, :contact_ip, :contact_port, :contact_count, :contact_last, :contacts_per_second, :contacts_per_second_max, :user_agent, :to_user, :comment +end diff --git a/app/views/intruders/_form.html.haml b/app/views/intruders/_form.html.haml new file mode 100644 index 0000000..26aab1c --- /dev/null +++ b/app/views/intruders/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for(@intruder) do |f| + = f.error_notification + + = render "form_core", :f => f + + .actions + = f.button :submit, conditional_t('intruders.form.submit') \ No newline at end of file diff --git a/app/views/intruders/_form_core.html.haml b/app/views/intruders/_form_core.html.haml new file mode 100644 index 0000000..ae2da39 --- /dev/null +++ b/app/views/intruders/_form_core.html.haml @@ -0,0 +1,16 @@ +.inputs + = f.input :list_type, :label => t('intruders.form.list_type.label'), :hint => conditional_hint('intruders.form.list_type.hint') + = f.input :key, :label => t('intruders.form.key.label'), :hint => conditional_hint('intruders.form.key.hint') + = f.input :points, :label => t('intruders.form.points.label'), :hint => conditional_hint('intruders.form.points.hint') + = f.input :bans, :label => t('intruders.form.bans.label'), :hint => conditional_hint('intruders.form.bans.hint') + = f.input :ban_last, :label => t('intruders.form.ban_last.label'), :hint => conditional_hint('intruders.form.ban_last.hint') + = f.input :ban_end, :label => t('intruders.form.ban_end.label'), :hint => conditional_hint('intruders.form.ban_end.hint') + = f.input :contact_ip, :label => t('intruders.form.contact_ip.label'), :hint => conditional_hint('intruders.form.contact_ip.hint') + = f.input :contact_port, :label => t('intruders.form.contact_port.label'), :hint => conditional_hint('intruders.form.contact_port.hint') + = f.input :contact_count, :label => t('intruders.form.contact_count.label'), :hint => conditional_hint('intruders.form.contact_count.hint') + = f.input :contact_last, :label => t('intruders.form.contact_last.label'), :hint => conditional_hint('intruders.form.contact_last.hint') + = f.input :contacts_per_second, :label => t('intruders.form.contacts_per_second.label'), :hint => conditional_hint('intruders.form.contacts_per_second.hint') + = f.input :contacts_per_second_max, :label => t('intruders.form.contacts_per_second_max.label'), :hint => conditional_hint('intruders.form.contacts_per_second_max.hint') + = f.input :user_agent, :label => t('intruders.form.user_agent.label'), :hint => conditional_hint('intruders.form.user_agent.hint') + = f.input :to_user, :label => t('intruders.form.to_user.label'), :hint => conditional_hint('intruders.form.to_user.hint') + = f.input :comment, :label => t('intruders.form.comment.label'), :hint => conditional_hint('intruders.form.comment.hint') diff --git a/app/views/intruders/_index_core.html.haml b/app/views/intruders/_index_core.html.haml new file mode 100644 index 0000000..0070c4d --- /dev/null +++ b/app/views/intruders/_index_core.html.haml @@ -0,0 +1,37 @@ +%table.table.table-striped + %tr + %th= t('intruders.index.list_type') + %th= t('intruders.index.key') + %th= t('intruders.index.points') + %th= t('intruders.index.bans') + %th= t('intruders.index.ban_last') + %th= t('intruders.index.ban_end') + %th= t('intruders.index.contact_ip') + %th= t('intruders.index.contact_port') + %th= t('intruders.index.contact_count') + %th= t('intruders.index.contact_last') + %th= t('intruders.index.contacts_per_second') + %th= t('intruders.index.contacts_per_second_max') + %th= t('intruders.index.user_agent') + %th= t('intruders.index.to_user') + %th= t('intruders.index.comment') + + + - for intruder in intruders + %tr + %td= intruder.list_type + %td= intruder.key + %td= intruder.points + %td= intruder.bans + %td= intruder.ban_last + %td= intruder.ban_end + %td= intruder.contact_ip + %td= intruder.contact_port + %td= intruder.contact_count + %td= intruder.contact_last + %td= intruder.contacts_per_second + %td= intruder.contacts_per_second_max + %td= intruder.user_agent + %td= intruder.to_user + %td= intruder.comment + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => intruder} \ No newline at end of file diff --git a/app/views/intruders/edit.html.haml b/app/views/intruders/edit.html.haml new file mode 100644 index 0000000..1b5a31b --- /dev/null +++ b/app/views/intruders/edit.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("intruders.edit.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/intruders/index.html.haml b/app/views/intruders/index.html.haml new file mode 100644 index 0000000..72b8882 --- /dev/null +++ b/app/views/intruders/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("intruders.index.page_title") + +- if @intruders && @intruders.count > 0 + = render "index_core", :intruders => @intruders + += render :partial => 'shared/create_link', :locals => {:child_class => Intruder} \ No newline at end of file diff --git a/app/views/intruders/new.html.haml b/app/views/intruders/new.html.haml new file mode 100644 index 0000000..a24b55f --- /dev/null +++ b/app/views/intruders/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("intruders.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/intruders/show.html.haml b/app/views/intruders/show.html.haml new file mode 100644 index 0000000..fa5f59b --- /dev/null +++ b/app/views/intruders/show.html.haml @@ -0,0 +1,49 @@ +- content_for :title, t("intruders.show.page_title") + +%p + %strong= t('intruders.show.list_type') + ":" + = @intruder.list_type +%p + %strong= t('intruders.show.key') + ":" + = @intruder.key +%p + %strong= t('intruders.show.points') + ":" + = @intruder.points +%p + %strong= t('intruders.show.bans') + ":" + = @intruder.bans +%p + %strong= t('intruders.show.ban_last') + ":" + = @intruder.ban_last +%p + %strong= t('intruders.show.ban_end') + ":" + = @intruder.ban_end +%p + %strong= t('intruders.show.contact_ip') + ":" + = @intruder.contact_ip +%p + %strong= t('intruders.show.contact_port') + ":" + = @intruder.contact_port +%p + %strong= t('intruders.show.contact_count') + ":" + = @intruder.contact_count +%p + %strong= t('intruders.show.contact_last') + ":" + = @intruder.contact_last +%p + %strong= t('intruders.show.contacts_per_second') + ":" + = @intruder.contacts_per_second +%p + %strong= t('intruders.show.contacts_per_second_max') + ":" + = @intruder.contacts_per_second_max +%p + %strong= t('intruders.show.user_agent') + ":" + = @intruder.user_agent +%p + %strong= t('intruders.show.to_user') + ":" + = @intruder.to_user +%p + %strong= t('intruders.show.comment') + ":" + = @intruder.comment + += render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @intruder } \ No newline at end of file diff --git a/config/locales/views/intruders/de.yml b/config/locales/views/intruders/de.yml new file mode 100644 index 0000000..42ece4b --- /dev/null +++ b/config/locales/views/intruders/de.yml @@ -0,0 +1,110 @@ +de: + intruders: + name: 'Intruder' + controller: + successfuly_created: 'Intruder wurde angelegt.' + successfuly_updated: 'Intruder wurde aktualisiert.' + successfuly_destroyed: 'Intruder wurde gelöscht.' + index: + page_title: 'Übersicht von Intruder' + list_type: 'List type' + key: 'Key' + points: 'Points' + bans: 'Bans' + ban_last: 'Ban last' + ban_end: 'Ban end' + contact_ip: 'Contact ip' + contact_port: 'Contact port' + contact_count: 'Contact count' + contact_last: 'Contact last' + contacts_per_second: 'Contacts per second' + contacts_per_second_max: 'Contacts per second max' + user_agent: 'User agent' + to_user: 'To user' + comment: 'Comment' + actions: + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Intruder' + destroy: 'Löschen' + edit: 'Bearbeiten' + show: 'Anzeigen' + create: 'Neu anlegen' + create_for: 'Intruder neu anlegen für %{resource}' + show: + page_title: 'Intruder bearbeiten' + list_type: 'List type' + key: 'Key' + points: 'Points' + bans: 'Bans' + ban_last: 'Ban last' + ban_end: 'Ban end' + contact_ip: 'Contact ip' + contact_port: 'Contact port' + contact_count: 'Contact count' + contact_last: 'Contact last' + contacts_per_second: 'Contacts per second' + contacts_per_second_max: 'Contacts per second max' + user_agent: 'User agent' + to_user: 'To user' + comment: 'Comment' + actions: + confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?' + destroy: 'Löschen' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + new: + page_title: 'Intruder neu anlegen' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: + page_title: 'Intruder bearbeiten' + actions: + back_to_list: 'Zurück zur Übersicht' + edit: 'Bearbeiten' + view_all: 'Alle anzeigen' + form: + list_type: + label: 'List type' + hint: '' + key: + label: 'Key' + hint: '' + points: + label: 'Points' + hint: '' + bans: + label: 'Bans' + hint: '' + ban_last: + label: 'Ban last' + hint: '' + ban_end: + label: 'Ban end' + hint: '' + contact_ip: + label: 'Contact ip' + hint: '' + contact_port: + label: 'Contact port' + hint: '' + contact_count: + label: 'Contact count' + hint: '' + contact_last: + label: 'Contact last' + hint: '' + contacts_per_second: + label: 'Contacts per second' + hint: '' + contacts_per_second_max: + label: 'Contacts per second max' + hint: '' + user_agent: + label: 'User agent' + hint: '' + to_user: + label: 'To user' + hint: '' + comment: + label: 'Comment' + hint: '' + submit: 'Absenden' \ No newline at end of file diff --git a/config/locales/views/intruders/en.yml b/config/locales/views/intruders/en.yml new file mode 100644 index 0000000..99c2dcb --- /dev/null +++ b/config/locales/views/intruders/en.yml @@ -0,0 +1,110 @@ +en: + intruders: + name: 'Intruder' + controller: + successfuly_created: 'Successfully created Intruder.' + successfuly_updated: 'Successfully updated Intruder.' + successfuly_destroyed: 'Successfully destroyed Intruder.' + index: + page_title: 'Listing Intruder' + list_type: 'List type' + key: 'Key' + points: 'Points' + bans: 'Bans' + ban_last: 'Ban last' + ban_end: 'Ban end' + contact_ip: 'Contact ip' + contact_port: 'Contact port' + contact_count: 'Contact count' + contact_last: 'Contact last' + contacts_per_second: 'Contacts per second' + contacts_per_second_max: 'Contacts per second max' + user_agent: 'User agent' + to_user: 'To user' + comment: 'Comment' + actions: + confirm_destroy: 'Are you sure you want to delete this Intruder?' + destroy: 'Delete' + edit: 'Edit' + show: 'View' + create: 'New' + create_for: 'New Intruder for %{resource}' + show: + page_title: 'Show Intruder' + list_type: 'List type' + key: 'Key' + points: 'Points' + bans: 'Bans' + ban_last: 'Ban last' + ban_end: 'Ban end' + contact_ip: 'Contact ip' + contact_port: 'Contact port' + contact_count: 'Contact count' + contact_last: 'Contact last' + contacts_per_second: 'Contacts per second' + contacts_per_second_max: 'Contacts per second max' + user_agent: 'User agent' + to_user: 'To user' + comment: 'Comment' + actions: + confirm_destroy: 'Are you sure you want to delete this element?' + destroy: 'Delete' + edit: 'Edit' + view_all: 'View All' + new: + page_title: 'New Intruder' + actions: + back_to_list: 'Back to Index' + edit: + page_title: 'Editing Intruder' + actions: + back_to_list: 'Back to Index' + edit: 'Edit' + view_all: 'View All' + form: + list_type: + label: 'List type' + hint: '' + key: + label: 'Key' + hint: '' + points: + label: 'Points' + hint: '' + bans: + label: 'Bans' + hint: '' + ban_last: + label: 'Ban last' + hint: '' + ban_end: + label: 'Ban end' + hint: '' + contact_ip: + label: 'Contact ip' + hint: '' + contact_port: + label: 'Contact port' + hint: '' + contact_count: + label: 'Contact count' + hint: '' + contact_last: + label: 'Contact last' + hint: '' + contacts_per_second: + label: 'Contacts per second' + hint: '' + contacts_per_second_max: + label: 'Contacts per second max' + hint: '' + user_agent: + label: 'User agent' + hint: '' + to_user: + label: 'To user' + hint: '' + comment: + label: 'Comment' + hint: '' + submit: 'Submit' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 653b811..05d09dc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Gemeinschaft42c::Application.routes.draw do + resources :intruders + resources :backup_jobs, :except => [:edit, :update] scope :constraints => lambda{|req|%w(127.0.0.1).include? req.remote_addr} do diff --git a/db/migrate/20130210075617_create_intruders.rb b/db/migrate/20130210075617_create_intruders.rb new file mode 100644 index 0000000..bd4db0b --- /dev/null +++ b/db/migrate/20130210075617_create_intruders.rb @@ -0,0 +1,26 @@ +class CreateIntruders < ActiveRecord::Migration + def self.up + create_table :intruders do |t| + t.string :list_type + t.string :key + t.integer :points + t.integer :bans + t.datetime :ban_last + t.datetime :ban_end + t.string :contact_ip + t.integer :contact_port + t.integer :contact_count + t.datetime :contact_last + t.float :contacts_per_second + t.float :contacts_per_second_max + t.string :user_agent + t.string :to_user + t.string :comment + t.timestamps + end + end + + def self.down + drop_table :intruders + end +end diff --git a/test/functional/intruders_controller_test.rb b/test/functional/intruders_controller_test.rb new file mode 100644 index 0000000..0896022 --- /dev/null +++ b/test/functional/intruders_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class IntrudersControllerTest < ActionController::TestCase + setup do + @intruder = intruders(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:intruders) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create intruder" do + assert_difference('Intruder.count') do + post :create, intruder: @intruder.attributes + end + + assert_redirected_to intruder_path(assigns(:intruder)) + end + + test "should show intruder" do + get :show, id: @intruder.to_param + assert_response :success + end + + test "should get edit" do + get :edit, id: @intruder.to_param + assert_response :success + end + + test "should update intruder" do + put :update, id: @intruder.to_param, intruder: @intruder.attributes + assert_redirected_to intruder_path(assigns(:intruder)) + end + + test "should destroy intruder" do + assert_difference('Intruder.count', -1) do + delete :destroy, id: @intruder.to_param + end + + assert_redirected_to intruders_path + end +end diff --git a/test/unit/intruder_test.rb b/test/unit/intruder_test.rb new file mode 100644 index 0000000..f1b7963 --- /dev/null +++ b/test/unit/intruder_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class IntruderTest < ActiveSupport::TestCase + def test_should_be_valid + assert Intruder.new.valid? + end +end -- cgit v1.2.3 From 33e88d16edc4d9f8047ef1a2087134c54f169c21 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 10 Feb 2013 09:52:31 +0100 Subject: key index added --- db/migrate/20130210075617_create_intruders.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20130210075617_create_intruders.rb b/db/migrate/20130210075617_create_intruders.rb index bd4db0b..fc944cc 100644 --- a/db/migrate/20130210075617_create_intruders.rb +++ b/db/migrate/20130210075617_create_intruders.rb @@ -18,6 +18,8 @@ class CreateIntruders < ActiveRecord::Migration t.string :comment t.timestamps end + + add_index :intruders, :key, :unique => true end def self.down -- cgit v1.2.3 From 70a6449fa176059e603a16a21699c8f5c60765e1 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 10 Feb 2013 16:59:57 +0100 Subject: intruder updated --- app/models/intruder.rb | 23 +++++++++++++++++++++++ app/views/intruders/_form_core.html.haml | 15 ++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/models/intruder.rb b/app/models/intruder.rb index 192d64d..c013ee8 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -1,3 +1,26 @@ class Intruder < ActiveRecord::Base attr_accessible :list_type, :key, :points, :bans, :ban_last, :ban_end, :contact_ip, :contact_port, :contact_count, :contact_last, :contacts_per_second, :contacts_per_second_max, :user_agent, :to_user, :comment + + LIST_TYPES = ['blacklist', 'whitelist'] + + validates :list_type, + :presence => true, + :inclusion => { :in => LIST_TYPES } + + validates :key, + :presence => true, + :uniqueness => true + + validates :contact_ip, + :presence => true, + :uniqueness => true + + before_validation :set_key_if_empty + + private + def set_key_if_empty + if self.key.blank? + self.key = self.contact_ip + end + end end diff --git a/app/views/intruders/_form_core.html.haml b/app/views/intruders/_form_core.html.haml index ae2da39..780d8cd 100644 --- a/app/views/intruders/_form_core.html.haml +++ b/app/views/intruders/_form_core.html.haml @@ -1,16 +1,5 @@ .inputs - = f.input :list_type, :label => t('intruders.form.list_type.label'), :hint => conditional_hint('intruders.form.list_type.hint') - = f.input :key, :label => t('intruders.form.key.label'), :hint => conditional_hint('intruders.form.key.hint') - = f.input :points, :label => t('intruders.form.points.label'), :hint => conditional_hint('intruders.form.points.hint') - = f.input :bans, :label => t('intruders.form.bans.label'), :hint => conditional_hint('intruders.form.bans.hint') - = f.input :ban_last, :label => t('intruders.form.ban_last.label'), :hint => conditional_hint('intruders.form.ban_last.hint') - = f.input :ban_end, :label => t('intruders.form.ban_end.label'), :hint => conditional_hint('intruders.form.ban_end.hint') + = f.input :list_type, :collection => Intruder::LIST_TYPES, :label => t('intruders.form.list_type.label'), :hint => conditional_hint('intruders.form.list_type.hint'), :include_blank => false = f.input :contact_ip, :label => t('intruders.form.contact_ip.label'), :hint => conditional_hint('intruders.form.contact_ip.hint') - = f.input :contact_port, :label => t('intruders.form.contact_port.label'), :hint => conditional_hint('intruders.form.contact_port.hint') - = f.input :contact_count, :label => t('intruders.form.contact_count.label'), :hint => conditional_hint('intruders.form.contact_count.hint') - = f.input :contact_last, :label => t('intruders.form.contact_last.label'), :hint => conditional_hint('intruders.form.contact_last.hint') - = f.input :contacts_per_second, :label => t('intruders.form.contacts_per_second.label'), :hint => conditional_hint('intruders.form.contacts_per_second.hint') - = f.input :contacts_per_second_max, :label => t('intruders.form.contacts_per_second_max.label'), :hint => conditional_hint('intruders.form.contacts_per_second_max.hint') - = f.input :user_agent, :label => t('intruders.form.user_agent.label'), :hint => conditional_hint('intruders.form.user_agent.hint') - = f.input :to_user, :label => t('intruders.form.to_user.label'), :hint => conditional_hint('intruders.form.to_user.hint') + = f.input :ban_end, :label => t('intruders.form.ban_end.label'), :hint => conditional_hint('intruders.form.ban_end.hint') = f.input :comment, :label => t('intruders.form.comment.label'), :hint => conditional_hint('intruders.form.comment.hint') -- cgit v1.2.3 From d84e7208ae138e5e85a13286739e4364e02446e9 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 10 Feb 2013 17:00:42 +0100 Subject: database update or create added --- misc/freeswitch/scripts/common/database.lua | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/misc/freeswitch/scripts/common/database.lua b/misc/freeswitch/scripts/common/database.lua index 1f39135..345f69d 100644 --- a/misc/freeswitch/scripts/common/database.lua +++ b/misc/freeswitch/scripts/common/database.lua @@ -16,6 +16,7 @@ function Database.new(self, arg) self.class = 'database'; self.log = arg.log; self.conn = nil; + self.ignore_on_update = arg.ignore_on_update or {}; return object; end @@ -71,6 +72,45 @@ function Database.last_insert_id(self) end +function Database.insert_or_update(self, db_table, record, use_on_update) + ignore_on_update = ignore_on_update or self.ignore_on_update; + local record_sql_create = {}; + local record_sql_update = {}; + + for key, value in pairs(record) do + if ignore_on_update[key] ~= false then + table.insert(record_sql_update, self:key_value(key, value)); + end + table.insert(record_sql_create, self:key_value(key, value)); + end + + local sql_query = 'INSERT INTO `' .. db_table .. '` SET ' .. table.concat(record_sql_create, ', ') .. ' ON DUPLICATE KEY UPDATE ' .. table.concat(record_sql_update, ', '); + + return self:query(sql_query); +end + + +function Database.key_value(self, key, value) + return self:escape(key, '`') .. ' = ' .. self:escape(value, '"'); +end + + +function Database.escape(self, value, str_quotes) + str_quotes = str_quotes or ''; + if type(value) == 'boolean' then + return tostring(value):upper(); + elseif type(value) == 'number' then + return tostring(value); + elseif type(value) == 'string' then + return str_quotes .. value:gsub('"', '\\"'):gsub("'", "\\'") .. str_quotes; + elseif type(value) == 'table' and value.raw then + return tostring(value[1]); + else + return 'NULL'; + end +end + + function Database.release(self) if self.conn then self.conn:release(); -- cgit v1.2.3 From 0225c74753b20bd62e535cfcc2f7bec23266798e Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 10 Feb 2013 17:02:05 +0100 Subject: intruder class added --- misc/freeswitch/scripts/common/intruder.lua | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 misc/freeswitch/scripts/common/intruder.lua diff --git a/misc/freeswitch/scripts/common/intruder.lua b/misc/freeswitch/scripts/common/intruder.lua new file mode 100644 index 0000000..083ec37 --- /dev/null +++ b/misc/freeswitch/scripts/common/intruder.lua @@ -0,0 +1,51 @@ +-- Gemeinschaft 5 module: intruder class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + + +Intruder = {} + + +function Intruder.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.log = arg.log; + self.class = 'intruder' + self.database = arg.database; + + return object; +end + + +function Intruder.update_blacklist(self, event) + local intruder_record = { + list_type = 'blacklist', + key = event.key, + points = event.points, + bans = event.record.banned, + contact_ip = event.received_ip, + contact_port = event.received_port, + contact_count = event.record.contact_count + 1, + contact_last = { 'FROM_UNIXTIME(' .. tostring(math.floor(event.timestamp/1000000)) .. ')', raw = true }, + contacts_per_second = event.contacts_per_second, + contacts_per_second_max = event.contacts_per_second_max, + user_agent = event.user_agent, + to_user = event.to_user, + comment = 'Permimeter', + created_at = {'NOW()', raw = true }, + updated_at = {'NOW()', raw = true }, + }; + + if tonumber(event.ban_time) then + intruder_record.ban_last = { 'FROM_UNIXTIME(' .. event.ban_time .. ')', raw = true }; + end + if tonumber(event.ban_end) then + intruder_record.ban_end = { 'FROM_UNIXTIME(' .. event.ban_end .. ')', raw = true }; + end + + self.database:insert_or_update('intruders', intruder_record, { created_at = false, comment = false }); +end -- cgit v1.2.3 From af16d6106e5b4c81a8b167397c0fffd728762fa0 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 10 Feb 2013 17:02:55 +0100 Subject: update intruder --- misc/freeswitch/scripts/common/perimeter.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua index de3f993..0815d33 100644 --- a/misc/freeswitch/scripts/common/perimeter.lua +++ b/misc/freeswitch/scripts/common/perimeter.lua @@ -128,6 +128,7 @@ function Perimeter.check(self, event) self:append_blacklist_file(event); end self:execute_ban(event); + event.ban_time = os.time(); end event.record.banned = event.record.banned + 1; @@ -136,6 +137,10 @@ function Perimeter.check(self, event) event.points = 0; end + if event.points then + self:update_intruder(event); + end + self:record_update(event); end @@ -145,6 +150,7 @@ function Perimeter.check_frequency(self, event) self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_FREQUENCY_CHECK - contacts: ', event.record.span_contact_count, ' in < ', (event.timestamp - event.record.span_start)/1000000, ' sec, threshold: ', self.contact_count_threshold, ' in ', self.contact_span_threshold, ' sec'); event.span_contact_count = 0; event.span_start = event.timestamp; + event.contacts_per_second = event.record.span_contact_count / ((event.timestamp - event.record.span_start)/1000000) return 1; elseif (event.timestamp - event.record.span_start) > (self.contact_span_threshold * 1000000) then event.span_contact_count = 0; @@ -222,6 +228,11 @@ function Perimeter.execute_ban(self, event) local result = os.execute(command); end +function Perimeter.update_intruder(self, event) + require 'common.intruder'; + local result = common.intruder.Intruder:new{ log = self.log, database = self.database }:update_blacklist(event); +end + function Perimeter.expand_variables(self, line, variables) return (line:gsub('{([%a%d%._]+)}', function(captured) -- cgit v1.2.3 From 586c407a2acf54cd7d0dd0af67eaa3d59c1f1bb4 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 09:40:45 +0100 Subject: mv cvs_user_import.rake csv_user_import.rake --- lib/tasks/csv_user_import.rake | 331 +++++++++++++++++++++++++++++++++++++++++ lib/tasks/cvs_user_import.rake | 331 ----------------------------------------- 2 files changed, 331 insertions(+), 331 deletions(-) create mode 100644 lib/tasks/csv_user_import.rake delete mode 100644 lib/tasks/cvs_user_import.rake diff --git a/lib/tasks/csv_user_import.rake b/lib/tasks/csv_user_import.rake new file mode 100644 index 0000000..81959d5 --- /dev/null +++ b/lib/tasks/csv_user_import.rake @@ -0,0 +1,331 @@ +namespace :user_import do + desc "Import users from a CSV file." + task :csv => :environment do + require 'csv' + require 'digest/md5' + + # Example CSV format in the file: + # UserName,LastName,FirstName,AcademicTitel,PhoneOffice,VoipNr1,VoipNr2,VoipNr3,VoipTelco,CellPhone,HardFax,SoftFax,Email,PIN + # 123456,Mustermann,Max,Dr.,+49 123 1001234,20,21,22,23,+49 160 12345678,+49 123 1001238,29,max.mustermann@example.com,1324 + + # A generic hook to manipulate each given phone number with Ruby tools. + # + def regex_convert_phone_numbers(phone_number = nil) + if phone_number.class == String && !phone_number.blank? + # 123 Example + # + # if !phone_number.match(/^123(..)$/).nil? + # phone_number = phone_number.gsub(/^123(..)$/,'123'+$1) + # end + end + + phone_number + end + + # Read the CSV data and store them in the new_users hash. + # + csv_data = CSV.read(GsParameter.get('IMPORT_CSV_FILE'), encoding: GsParameter.get('IMPORT_CSV_ENCODING')) + headers = csv_data.shift.map {|i| i.to_s } + string_data = csv_data.map {|row| row.map {|cell| cell.to_s } } + new_users = string_data.map {|row| Hash[*headers.zip(row).flatten] } + gs_node_id = GsNode.where(:ip_address => GsParameter.get('HOMEBASE_IP_ADDRESS')).first.try(:id) + + if File.exists?(GsParameter.get('DOUBLE_CHECK_POSITIVE_USERS_CSV')) + csv_data = CSV.read(GsParameter.get('DOUBLE_CHECK_POSITIVE_USERS_CSV'), encoding: GsParameter.get('IMPORT_CSV_ENCODING')) + if csv_data.blank? + double_checked_user_names = [] + else + headers = csv_data.shift.map {|i| i.to_s } + string_data = csv_data.map {|row| row.map {|cell| cell.to_s } } + double_check_positiv_users = string_data.map {|row| Hash[*headers.zip(row).flatten] } + + double_checked_user_names = double_check_positiv_users.map{|user| user['UserName']} + end + else + double_checked_user_names = new_users.map{|user| user['UserName']} + end + + tenant = Tenant.find(GsParameter.get('DEFAULT_API_TENANT_ID')) + + # Destroy deleted user by making a diff of where(:importer_checksum) + # and users in the CSV file. + # + if defined?(GsParameter.get('USER_NAME_PREFIX')) && !GsParameter.get('USER_NAME_PREFIX').blank? + new_users_user_names = new_users.map{|x| GsParameter.get('USER_NAME_PREFIX').to_s + x['UserName'].to_s} + else + new_users_user_names = new_users.map{|x| x['UserName']} + end + csv_imported_user_names_in_the_database = User.where('importer_checksum != ?', '').pluck(:user_name) + + + to_be_destroyed_user_names = csv_imported_user_names_in_the_database - new_users_user_names + + User.where(:user_name => to_be_destroyed_user_names, :gs_node_id => gs_node_id).destroy_all + + # Loop through all entries in the CSV file. + # + new_users.each do |csv_user| + if !(csv_user['UserName'].blank? || csv_user['Email'].blank?) && double_checked_user_names.include?(csv_user['UserName']) + csv_user['Email'] = csv_user['Email'].downcase + if defined?(GsParameter.get('USER_NAME_PREFIX')) && !GsParameter.get('USER_NAME_PREFIX').blank? + csv_user['UserName'] = GsParameter.get('USER_NAME_PREFIX').to_s + csv_user['UserName'] + end + + md5_sum = Digest::MD5.hexdigest(csv_user.to_yaml) + user = nil + + # Check if this user already exists and has a changed checksum. + # + if tenant.users.where(:user_name => csv_user['UserName']).first.try(:importer_checksum).to_s != md5_sum.to_s + # Find or create the user + # + if tenant.users.where(:user_name => csv_user['UserName']).count > 0 + user = tenant.users.where(:user_name => csv_user['UserName']).first + if defined? IMPORT_IGNORE_PIN_ON_UPDATE && IMPORT_IGNORE_PIN_ON_UPDATE == true + user.update_attributes( + :last_name => csv_user['LastName'], + :first_name => csv_user['FirstName'], + :email => csv_user['Email'], + :importer_checksum => md5_sum, + :gs_node_id => gs_node_id, + ) + else + user.update_attributes( + :last_name => csv_user['LastName'], + :first_name => csv_user['FirstName'], + :email => csv_user['Email'], + :new_pin => csv_user['PIN'], + :new_pin_confirmation => csv_user['PIN'], + :password => csv_user['PIN'], + :password_confirmation => csv_user['PIN'], + :importer_checksum => md5_sum, + :gs_node_id => gs_node_id, + ) + end + else + if csv_user['PIN'].blank? + csv_user['PIN'] = (1..6).map{|i| (0 .. 9).to_a.sample}.join + end + user = tenant.users.create( + :user_name => csv_user['UserName'], + :last_name => csv_user['LastName'], + :first_name => csv_user['FirstName'], + :email => csv_user['Email'], + :new_pin => csv_user['PIN'], + :new_pin_confirmation => csv_user['PIN'], + :password => csv_user['PIN'], + :password_confirmation => csv_user['PIN'], + :language_id => tenant.language_id, + :importer_checksum => md5_sum, + :gs_node_id => gs_node_id, + :send_voicemail_as_email_attachment => true, + ) + end + + # Create group membership + if tenant.user_groups.exists?(:name => 'Users') + tenant.user_groups.where(:name => 'Users').first.user_group_memberships.create(:user => user) + end + end + + if user + # Find or create a sip_accounts + ['VoipNr1', 'VoipNr2', 'VoipNr3'].each_with_index do |phone_number_type, index| + + if index > 0 + auth_name = "#{csv_user['UserName']}_#{index}" + else + auth_name = csv_user['UserName'].to_s + end + + if !phone_number_type.blank? && !csv_user[phone_number_type].blank? + sip_account = user.sip_accounts.where(:auth_name => auth_name).first + if sip_account + if sip_account.caller_name.to_s != user.to_s + sip_account.update_attributes(:caller_name => user.to_s) + end + else + sip_account = user.sip_accounts.create( + :caller_name => user.to_s, + :voicemail_pin => csv_user['PIN'], + :auth_name => auth_name, + :password => csv_user['PIN'], + :clip => true, + :hotdeskable => true, + :callforward_rules_act_per_sip_account => true, + :gs_node_id => gs_node_id, + ) + end + + phone_numbers = Array.new() + phone_numbers.push(csv_user[phone_number_type].to_s.gsub(/[^0-9\+]/, '')) + + # Find or create phone numbers + converted_phone_number = regex_convert_phone_numbers(csv_user[phone_number_type]) + if converted_phone_number != csv_user[phone_number_type] + phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) + end + phone_numbers_count = sip_account.phone_numbers.count + phone_numbers.each do |phone_number_number| + phone_number = sip_account.phone_numbers.where(:number => phone_number_number).first + if !phone_number + phone_number = sip_account.phone_numbers.create(:number => phone_number_number, :gs_node_id => gs_node_id) + end + end + + # Create default call forwarding entries + if phone_numbers_count < sip_account.phone_numbers.count + call_forward_case_offline = CallForwardCase.find_by_value('offline') + if call_forward_case_offline + sip_account.phone_numbers.first.call_forwards.create(:call_forward_case_id => call_forward_case_offline.id, :call_forwardable_type => 'Voicemail', :active => true, :depth => GsParameter.get('DEFAULT_CALL_FORWARD_DEPTH')) + end + end + else + user.sip_accounts.where(:auth_name => auth_name).destroy_all + end + end + + if !csv_user['SoftFax'].blank? + phone_numbers = Array.new() + phone_numbers.push(csv_user['SoftFax'].to_s.gsub(/[^0-9\+]/, '')) + converted_phone_number = regex_convert_phone_numbers(csv_user['SoftFax']) + if converted_phone_number != csv_user['SoftFax'] + phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) + end + + fax_account = user.fax_accounts.first + if fax_account + if fax_account.name != user.to_s || fax_account.email != user.email + fax_account.update_attributes(:name => user.to_s, :email => user.email) + end + else + fax_account = user.fax_accounts.create( + :name => user.to_s, + :station_id => converted_phone_number.gsub(/[^0-9\+]/,''), + :email => user.email, + :days_till_auto_delete => 90, + :retries => 3, + ) + end + + if fax_account + fax_account.phone_numbers.each do |phone_number| + if !phone_numbers.include?(phone_number.number) + phone_number.delete + end + end + phone_numbers.each do |phone_number_number| + phone_number = fax_account.phone_numbers.where(:number => phone_number_number).first + if !phone_number + phone_number = fax_account.phone_numbers.create(:number => phone_number_number) + end + end + end + else + user.fax_accounts.destroy_all + end + + if !csv_user['HardFax'].blank? + phone_numbers = Array.new() + phone_numbers.push(csv_user['HardFax'].to_s.gsub(/[^0-9\+]/, '')) + converted_phone_number = regex_convert_phone_numbers(csv_user['HardFax']) + if converted_phone_number != csv_user['HardFax'] + phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) + end + + # Create a sip_account for a hardware fax. + # + fax_sip_account = user.sip_accounts.where(:description => 'Hardware-Fax').first + if fax_sip_account + if fax_sip_account.caller_name != "Hardware Fax of #{user.to_s}" + fax_sip_account.update_attributes(:caller_name => "Hardware Fax of #{user.to_s}") + end + else + fax_sip_account = user.sip_accounts.create( + :caller_name => "Hardware Fax of #{user.to_s}", + :description => 'Hardware-Fax', + :auth_name => 'HARDFAX' + csv_user['UserName'], + :password => csv_user['PIN'], + :clip => true, + :hotdeskable => false, + :callforward_rules_act_per_sip_account => true, + :gs_node_id => gs_node_id, + ) + end + + if fax_sip_account + fax_sip_account.phone_numbers.each do |phone_number| + if !phone_numbers.include?(phone_number.number) + phone_number.delete + end + end + phone_numbers.each do |phone_number_number| + phone_number = fax_sip_account.phone_numbers.where(:number => phone_number_number).first + if !phone_number + phone_number = fax_sip_account.phone_numbers.create(:number => phone_number_number) + end + end + end + else + user.sip_accounts.where(:description => 'Hardware-Fax').destroy_all + end + + if !csv_user['VoipTelco'].blank? + conference = user.conferences.first + if conference.nil? + # Create a conference room for this user. + # + conference = user.conferences.build + conference.name = "Default Conference for #{user.to_s}" + conference.start = nil + conference.end = nil + conference.open_for_anybody = true + conference.max_members = GsParameter.get('DEFAULT_MAX_CONFERENCE_MEMBERS') + conference.pin = (1..GsParameter.get('MINIMUM_PIN_LENGTH')).map{|i| (0 .. 9).to_a.sample}.join + conference.save + end + + phone_numbers = Array.new() + phone_numbers.push(csv_user['VoipTelco'].to_s.gsub(/[^0-9\+]/, '')) + converted_phone_number = regex_convert_phone_numbers(csv_user['VoipTelco']) + if converted_phone_number != csv_user['VoipTelco'] + phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) + end + + if conference + conference.phone_numbers.each do |phone_number| + if !phone_numbers.include?(phone_number.number) + phone_number.delete + end + end + phone_numbers.each do |phone_number_number| + phone_number = conference.phone_numbers.where(:number => phone_number_number).first + if !phone_number + phone_number = conference.phone_numbers.create(:number => phone_number_number) + end + end + end + else + user.conferences.destroy_all + end + + # Create Whitelist Entry for default Callthrough + # + cell_phone_number = csv_user['CellPhone'].to_s.gsub(/[^0-9\+]/, '') + + if !cell_phone_number.blank? + callthrough = tenant.callthroughs.find_or_create_by_name(GsParameter.get('CALLTHROUGH_NAME_TO_BE_USED_FOR_DEFAULT_ACTIVATION')) + + access_authorization = callthrough.access_authorizations.find_or_create_by_name('Cellphones') + + new_phone_number = access_authorization.phone_numbers.find_or_create_by_number(cell_phone_number, :name => user.to_s, :access_authorization_user_id => user.id) + end + end + else + # puts "#{csv_user['UserName']} (#{csv_user['Email']}) has not changed." + end + end + + + end +end \ No newline at end of file diff --git a/lib/tasks/cvs_user_import.rake b/lib/tasks/cvs_user_import.rake deleted file mode 100644 index 81959d5..0000000 --- a/lib/tasks/cvs_user_import.rake +++ /dev/null @@ -1,331 +0,0 @@ -namespace :user_import do - desc "Import users from a CSV file." - task :csv => :environment do - require 'csv' - require 'digest/md5' - - # Example CSV format in the file: - # UserName,LastName,FirstName,AcademicTitel,PhoneOffice,VoipNr1,VoipNr2,VoipNr3,VoipTelco,CellPhone,HardFax,SoftFax,Email,PIN - # 123456,Mustermann,Max,Dr.,+49 123 1001234,20,21,22,23,+49 160 12345678,+49 123 1001238,29,max.mustermann@example.com,1324 - - # A generic hook to manipulate each given phone number with Ruby tools. - # - def regex_convert_phone_numbers(phone_number = nil) - if phone_number.class == String && !phone_number.blank? - # 123 Example - # - # if !phone_number.match(/^123(..)$/).nil? - # phone_number = phone_number.gsub(/^123(..)$/,'123'+$1) - # end - end - - phone_number - end - - # Read the CSV data and store them in the new_users hash. - # - csv_data = CSV.read(GsParameter.get('IMPORT_CSV_FILE'), encoding: GsParameter.get('IMPORT_CSV_ENCODING')) - headers = csv_data.shift.map {|i| i.to_s } - string_data = csv_data.map {|row| row.map {|cell| cell.to_s } } - new_users = string_data.map {|row| Hash[*headers.zip(row).flatten] } - gs_node_id = GsNode.where(:ip_address => GsParameter.get('HOMEBASE_IP_ADDRESS')).first.try(:id) - - if File.exists?(GsParameter.get('DOUBLE_CHECK_POSITIVE_USERS_CSV')) - csv_data = CSV.read(GsParameter.get('DOUBLE_CHECK_POSITIVE_USERS_CSV'), encoding: GsParameter.get('IMPORT_CSV_ENCODING')) - if csv_data.blank? - double_checked_user_names = [] - else - headers = csv_data.shift.map {|i| i.to_s } - string_data = csv_data.map {|row| row.map {|cell| cell.to_s } } - double_check_positiv_users = string_data.map {|row| Hash[*headers.zip(row).flatten] } - - double_checked_user_names = double_check_positiv_users.map{|user| user['UserName']} - end - else - double_checked_user_names = new_users.map{|user| user['UserName']} - end - - tenant = Tenant.find(GsParameter.get('DEFAULT_API_TENANT_ID')) - - # Destroy deleted user by making a diff of where(:importer_checksum) - # and users in the CSV file. - # - if defined?(GsParameter.get('USER_NAME_PREFIX')) && !GsParameter.get('USER_NAME_PREFIX').blank? - new_users_user_names = new_users.map{|x| GsParameter.get('USER_NAME_PREFIX').to_s + x['UserName'].to_s} - else - new_users_user_names = new_users.map{|x| x['UserName']} - end - csv_imported_user_names_in_the_database = User.where('importer_checksum != ?', '').pluck(:user_name) - - - to_be_destroyed_user_names = csv_imported_user_names_in_the_database - new_users_user_names - - User.where(:user_name => to_be_destroyed_user_names, :gs_node_id => gs_node_id).destroy_all - - # Loop through all entries in the CSV file. - # - new_users.each do |csv_user| - if !(csv_user['UserName'].blank? || csv_user['Email'].blank?) && double_checked_user_names.include?(csv_user['UserName']) - csv_user['Email'] = csv_user['Email'].downcase - if defined?(GsParameter.get('USER_NAME_PREFIX')) && !GsParameter.get('USER_NAME_PREFIX').blank? - csv_user['UserName'] = GsParameter.get('USER_NAME_PREFIX').to_s + csv_user['UserName'] - end - - md5_sum = Digest::MD5.hexdigest(csv_user.to_yaml) - user = nil - - # Check if this user already exists and has a changed checksum. - # - if tenant.users.where(:user_name => csv_user['UserName']).first.try(:importer_checksum).to_s != md5_sum.to_s - # Find or create the user - # - if tenant.users.where(:user_name => csv_user['UserName']).count > 0 - user = tenant.users.where(:user_name => csv_user['UserName']).first - if defined? IMPORT_IGNORE_PIN_ON_UPDATE && IMPORT_IGNORE_PIN_ON_UPDATE == true - user.update_attributes( - :last_name => csv_user['LastName'], - :first_name => csv_user['FirstName'], - :email => csv_user['Email'], - :importer_checksum => md5_sum, - :gs_node_id => gs_node_id, - ) - else - user.update_attributes( - :last_name => csv_user['LastName'], - :first_name => csv_user['FirstName'], - :email => csv_user['Email'], - :new_pin => csv_user['PIN'], - :new_pin_confirmation => csv_user['PIN'], - :password => csv_user['PIN'], - :password_confirmation => csv_user['PIN'], - :importer_checksum => md5_sum, - :gs_node_id => gs_node_id, - ) - end - else - if csv_user['PIN'].blank? - csv_user['PIN'] = (1..6).map{|i| (0 .. 9).to_a.sample}.join - end - user = tenant.users.create( - :user_name => csv_user['UserName'], - :last_name => csv_user['LastName'], - :first_name => csv_user['FirstName'], - :email => csv_user['Email'], - :new_pin => csv_user['PIN'], - :new_pin_confirmation => csv_user['PIN'], - :password => csv_user['PIN'], - :password_confirmation => csv_user['PIN'], - :language_id => tenant.language_id, - :importer_checksum => md5_sum, - :gs_node_id => gs_node_id, - :send_voicemail_as_email_attachment => true, - ) - end - - # Create group membership - if tenant.user_groups.exists?(:name => 'Users') - tenant.user_groups.where(:name => 'Users').first.user_group_memberships.create(:user => user) - end - end - - if user - # Find or create a sip_accounts - ['VoipNr1', 'VoipNr2', 'VoipNr3'].each_with_index do |phone_number_type, index| - - if index > 0 - auth_name = "#{csv_user['UserName']}_#{index}" - else - auth_name = csv_user['UserName'].to_s - end - - if !phone_number_type.blank? && !csv_user[phone_number_type].blank? - sip_account = user.sip_accounts.where(:auth_name => auth_name).first - if sip_account - if sip_account.caller_name.to_s != user.to_s - sip_account.update_attributes(:caller_name => user.to_s) - end - else - sip_account = user.sip_accounts.create( - :caller_name => user.to_s, - :voicemail_pin => csv_user['PIN'], - :auth_name => auth_name, - :password => csv_user['PIN'], - :clip => true, - :hotdeskable => true, - :callforward_rules_act_per_sip_account => true, - :gs_node_id => gs_node_id, - ) - end - - phone_numbers = Array.new() - phone_numbers.push(csv_user[phone_number_type].to_s.gsub(/[^0-9\+]/, '')) - - # Find or create phone numbers - converted_phone_number = regex_convert_phone_numbers(csv_user[phone_number_type]) - if converted_phone_number != csv_user[phone_number_type] - phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) - end - phone_numbers_count = sip_account.phone_numbers.count - phone_numbers.each do |phone_number_number| - phone_number = sip_account.phone_numbers.where(:number => phone_number_number).first - if !phone_number - phone_number = sip_account.phone_numbers.create(:number => phone_number_number, :gs_node_id => gs_node_id) - end - end - - # Create default call forwarding entries - if phone_numbers_count < sip_account.phone_numbers.count - call_forward_case_offline = CallForwardCase.find_by_value('offline') - if call_forward_case_offline - sip_account.phone_numbers.first.call_forwards.create(:call_forward_case_id => call_forward_case_offline.id, :call_forwardable_type => 'Voicemail', :active => true, :depth => GsParameter.get('DEFAULT_CALL_FORWARD_DEPTH')) - end - end - else - user.sip_accounts.where(:auth_name => auth_name).destroy_all - end - end - - if !csv_user['SoftFax'].blank? - phone_numbers = Array.new() - phone_numbers.push(csv_user['SoftFax'].to_s.gsub(/[^0-9\+]/, '')) - converted_phone_number = regex_convert_phone_numbers(csv_user['SoftFax']) - if converted_phone_number != csv_user['SoftFax'] - phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) - end - - fax_account = user.fax_accounts.first - if fax_account - if fax_account.name != user.to_s || fax_account.email != user.email - fax_account.update_attributes(:name => user.to_s, :email => user.email) - end - else - fax_account = user.fax_accounts.create( - :name => user.to_s, - :station_id => converted_phone_number.gsub(/[^0-9\+]/,''), - :email => user.email, - :days_till_auto_delete => 90, - :retries => 3, - ) - end - - if fax_account - fax_account.phone_numbers.each do |phone_number| - if !phone_numbers.include?(phone_number.number) - phone_number.delete - end - end - phone_numbers.each do |phone_number_number| - phone_number = fax_account.phone_numbers.where(:number => phone_number_number).first - if !phone_number - phone_number = fax_account.phone_numbers.create(:number => phone_number_number) - end - end - end - else - user.fax_accounts.destroy_all - end - - if !csv_user['HardFax'].blank? - phone_numbers = Array.new() - phone_numbers.push(csv_user['HardFax'].to_s.gsub(/[^0-9\+]/, '')) - converted_phone_number = regex_convert_phone_numbers(csv_user['HardFax']) - if converted_phone_number != csv_user['HardFax'] - phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) - end - - # Create a sip_account for a hardware fax. - # - fax_sip_account = user.sip_accounts.where(:description => 'Hardware-Fax').first - if fax_sip_account - if fax_sip_account.caller_name != "Hardware Fax of #{user.to_s}" - fax_sip_account.update_attributes(:caller_name => "Hardware Fax of #{user.to_s}") - end - else - fax_sip_account = user.sip_accounts.create( - :caller_name => "Hardware Fax of #{user.to_s}", - :description => 'Hardware-Fax', - :auth_name => 'HARDFAX' + csv_user['UserName'], - :password => csv_user['PIN'], - :clip => true, - :hotdeskable => false, - :callforward_rules_act_per_sip_account => true, - :gs_node_id => gs_node_id, - ) - end - - if fax_sip_account - fax_sip_account.phone_numbers.each do |phone_number| - if !phone_numbers.include?(phone_number.number) - phone_number.delete - end - end - phone_numbers.each do |phone_number_number| - phone_number = fax_sip_account.phone_numbers.where(:number => phone_number_number).first - if !phone_number - phone_number = fax_sip_account.phone_numbers.create(:number => phone_number_number) - end - end - end - else - user.sip_accounts.where(:description => 'Hardware-Fax').destroy_all - end - - if !csv_user['VoipTelco'].blank? - conference = user.conferences.first - if conference.nil? - # Create a conference room for this user. - # - conference = user.conferences.build - conference.name = "Default Conference for #{user.to_s}" - conference.start = nil - conference.end = nil - conference.open_for_anybody = true - conference.max_members = GsParameter.get('DEFAULT_MAX_CONFERENCE_MEMBERS') - conference.pin = (1..GsParameter.get('MINIMUM_PIN_LENGTH')).map{|i| (0 .. 9).to_a.sample}.join - conference.save - end - - phone_numbers = Array.new() - phone_numbers.push(csv_user['VoipTelco'].to_s.gsub(/[^0-9\+]/, '')) - converted_phone_number = regex_convert_phone_numbers(csv_user['VoipTelco']) - if converted_phone_number != csv_user['VoipTelco'] - phone_numbers.push(converted_phone_number.gsub(/[^0-9\+]/, '')) - end - - if conference - conference.phone_numbers.each do |phone_number| - if !phone_numbers.include?(phone_number.number) - phone_number.delete - end - end - phone_numbers.each do |phone_number_number| - phone_number = conference.phone_numbers.where(:number => phone_number_number).first - if !phone_number - phone_number = conference.phone_numbers.create(:number => phone_number_number) - end - end - end - else - user.conferences.destroy_all - end - - # Create Whitelist Entry for default Callthrough - # - cell_phone_number = csv_user['CellPhone'].to_s.gsub(/[^0-9\+]/, '') - - if !cell_phone_number.blank? - callthrough = tenant.callthroughs.find_or_create_by_name(GsParameter.get('CALLTHROUGH_NAME_TO_BE_USED_FOR_DEFAULT_ACTIVATION')) - - access_authorization = callthrough.access_authorizations.find_or_create_by_name('Cellphones') - - new_phone_number = access_authorization.phone_numbers.find_or_create_by_number(cell_phone_number, :name => user.to_s, :access_authorization_user_id => user.id) - end - end - else - # puts "#{csv_user['UserName']} (#{csv_user['Email']}) has not changed." - end - end - - - end -end \ No newline at end of file -- cgit v1.2.3 From a389e71521f526d918001a00878f363314fa7027 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 11 Feb 2013 10:06:41 +0100 Subject: channel_variable_get method added --- lib/freeswitch_event.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/freeswitch_event.rb b/lib/freeswitch_event.rb index b6e5cbc..68d9df2 100644 --- a/lib/freeswitch_event.rb +++ b/lib/freeswitch_event.rb @@ -44,8 +44,8 @@ class FreeswitchEventSocket @socket.close end - def read() - return @socket.recv(1024) + def read(read_bytes=1024) + return @socket.recv(read_bytes) end def result() @@ -130,4 +130,20 @@ class FreeswitchAPI return false end + + def self.channel_variable_get(channel_uuid, variable_name) + result = nil + event = FreeswitchEventSocket.new() + if event && event.connect() + event.command( "api uuid_getvar #{channel_uuid} #{variable_name}") + event_result = event.result() + if event_result && event_result["Content-Type"] == 'api/response' && event_result["Content-Length"].to_i > 0 + result = event.read(event_result["Content-Length"].to_i) + end + event.close() + end + + return result + end + end -- cgit v1.2.3 From 7332f8e0b13ad4b5999b443b7baf36574b6d9593 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 11 Feb 2013 10:07:33 +0100 Subject: call model rewrite --- app/models/call.rb | 70 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/app/models/call.rb b/app/models/call.rb index 57961ec..c0f0f08 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -1,36 +1,72 @@ class Call < ActiveRecord::Base - self.table_name = 'channels' + self.table_name = 'detailed_calls' self.primary_key = 'uuid' - # Makes sure that this is a readonly model. def readonly? return true end - - # Prevent objects from being destroyed - def before_destroy - raise ActiveRecord::ReadOnlyRecord - end - # Prevent objects from being deleted - def self.delete_all - raise ActiveRecord::ReadOnlyRecord + def destroy + return self.delete end - # Prevent objects from being deleted def delete - raise ActiveRecord::ReadOnlyRecord + require 'freeswitch_event' + return FreeswitchAPI.execute('uuid_kill', self.uuid, true); end def sip_account - auth_name = self.name.match('^.+[/:](.+)@.+$') - if auth_name && ! auth_name[1].blank? - return SipAccount.where(:auth_name => auth_name[1]).first + result = self.presence_id.match('^(.+)@(.+)$') + + if result && ! result[1].blank? and ! result[2].blank? + domain = SipDomain.where(:host => result[2]).first + if domain + return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first + end end end - def kill + def sip_account_bleg + result = self.b_presence_id.match('^(.+)@(.+)$') + + if result && ! result[1].blank? and ! result[2].blank? + domain = SipDomain.where(:host => result[2]).first + if domain + return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first + end + end + end + + def get_variable_from_uuid(channel_uuid, variable_name) + if channel_uuid.blank? + return nil + end + require 'freeswitch_event' - return FreeswitchAPI.execute('uuid_kill', self.uuid, true); + result = FreeswitchAPI.channel_variable_get(channel_uuid, variable_name); + + if result == '_undef_' + return nil + end + + return result + end + + def get_variable(variable_name) + return get_variable_from_uuid(self.uuid, variable_name); + end + + def get_variable_bleg(variable_name) + return get_variable_from_uuid(self.b_uuid, variable_name); + end + + def is_sip + return self.name.match('^sofia') != nil + end + + def is_caller + if (self.uuid == self.call_uuid) || self.call_uuid.blank? + true + end end end -- cgit v1.2.3 From d42afaf3471b6784ac0d7cfc139c84b84698ba0d Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 10:09:30 +0100 Subject: Fixed breadcrumbs. #163 --- app/controllers/fax_documents_controller.rb | 25 ++++++++++--------------- app/views/fax_accounts/_index_core.html.haml | 4 ++-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app/controllers/fax_documents_controller.rb b/app/controllers/fax_documents_controller.rb index eff9604..5653683 100644 --- a/app/controllers/fax_documents_controller.rb +++ b/app/controllers/fax_documents_controller.rb @@ -58,23 +58,18 @@ class FaxDocumentsController < ApplicationController end private + def spread_breadcrumbs - breadcrumbs = [] - breadcrumbs = case @fax_account.fax_accountable.class.to_s - when 'User' ; [ - [@fax_account.fax_accountable.to_s, user_path(@fax_account.fax_accountable)], - [t('fax_accounts.name').pluralize, user_fax_accounts_path(@fax_account.fax_accountable)], - [t('fax_documents.name').pluralize, fax_account_fax_documents_path(@fax_account)], - ] - when 'UserGroup' ; [ - [@fax_account.fax_accountable, user_group_path(@fax_account.fax_accountable)], - [t('fax_accounts.name').pluralize, user_group_fax_accounts_path(@fax_account.fax_accountable)], - [t('fax_documents.name').pluralize, fax_account_fax_documents_path(@fax_account)], - ] + if @fax_account && @fax_account.fax_accountable.class == User + add_breadcrumb t("users.index.page_title"), tenant_users_path(@fax_account.fax_accountable.current_tenant) + add_breadcrumb @fax_account.fax_accountable, tenant_user_path(@fax_account.fax_accountable.current_tenant, @fax_account.fax_accountable) end - if !breadcrumbs.blank? - breadcrumbs.each do |breadcrumb| - add_breadcrumb breadcrumb[0], breadcrumb[1] + + if @fax_account + add_breadcrumb t("fax_accounts.index.page_title"), user_fax_accounts_path(@fax_account.fax_accountable) + add_breadcrumb @fax_account, user_fax_account_path(@fax_account.fax_accountable, @fax_account) + if @fax_document && !@fax_document.new_record? + add_breadcrumb @fax_document, fax_account_fax_document_path(@fax_account, @fax_document) end end end diff --git a/app/views/fax_accounts/_index_core.html.haml b/app/views/fax_accounts/_index_core.html.haml index d694f8f..846cda8 100644 --- a/app/views/fax_accounts/_index_core.html.haml +++ b/app/views/fax_accounts/_index_core.html.haml @@ -39,8 +39,8 @@ = time_ago_in_words(fax_account.fax_documents.order(:updated_at).last.updated_at) %td - if can?(:new, FaxDocument, :fax_account_id => fax_account.id) - %a.btn.btn-mini.btn-primary{:href => new_fax_account_fax_document_path(fax_account) } - %i.icon-print.icon-white + %a.btn.btn-small{:href => new_fax_account_fax_document_path(fax_account) } + %i.icon-print %span.hidden-phone =t('fax_accounts.index.send_a_fax') -- cgit v1.2.3 From 84ce49fcd057284225474c3197268a9f8a3c8121 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 10:14:39 +0100 Subject: Added i.icon-print to the button. --- app/views/fax_accounts/show.html.haml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/fax_accounts/show.html.haml b/app/views/fax_accounts/show.html.haml index 1a32121..454ebee 100644 --- a/app/views/fax_accounts/show.html.haml +++ b/app/views/fax_accounts/show.html.haml @@ -12,7 +12,11 @@ = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @parent, :child => @fax_account } -= render :partial => 'shared/create_link', :locals => { :parent => @fax_account, :child_class => FaxDocument } +%p + %a.btn.btn-small{:href => new_fax_account_fax_document_path(@fax_account) } + %i.icon-print + %span.hidden-phone + =t('fax_accounts.index.send_a_fax') %h2= t('phone_numbers.index.page_title') - if @fax_account.phone_numbers.count > 0 -- cgit v1.2.3 From 62ac01a8ea536718734bd911fc3642c0bd8b6bc7 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 11 Feb 2013 13:04:05 +0100 Subject: ipwhois added --- app/models/intruder.rb | 11 +++++++++++ app/views/intruders/show.html.haml | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/intruder.rb b/app/models/intruder.rb index c013ee8..db14bf8 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -17,6 +17,17 @@ class Intruder < ActiveRecord::Base before_validation :set_key_if_empty + + def whois + if ! self.contact_ip.blank? + begin + return Whois.whois(self.contact_ip) + rescue + return nil + end + end + end + private def set_key_if_empty if self.key.blank? diff --git a/app/views/intruders/show.html.haml b/app/views/intruders/show.html.haml index fa5f59b..4941e89 100644 --- a/app/views/intruders/show.html.haml +++ b/app/views/intruders/show.html.haml @@ -46,4 +46,7 @@ %strong= t('intruders.show.comment') + ":" = @intruder.comment -= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @intruder } \ No newline at end of file +%p + %pre= @intruder.whois + += render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @intruder } -- cgit v1.2.3 From 29db90c2c8a9a6a3087e77eae8615ddf0049087b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 14:40:38 +0100 Subject: Deleted PrivatePub stuff. --- Gemfile | 3 -- Gemfile.lock | 24 ----------- app/controllers/system_messages_controller.rb | 30 ------------- app/helpers/system_messages_helper.rb | 2 - app/models/ability.rb | 4 -- app/views/system_messages/_form.html.haml | 7 ---- app/views/system_messages/_form_core.html.haml | 2 - app/views/system_messages/_index_core.html.haml | 12 ------ app/views/system_messages/index.html.haml | 3 -- app/views/system_messages/new.html.haml | 3 -- app/views/system_messages/show.html.haml | 8 ---- config/locales/views/system_messages/de.yml | 38 ----------------- config/locales/views/system_messages/en.yml | 38 ----------------- private_pub.ru | 8 ---- test/functional/system_messages_controller_test.rb | 49 ---------------------- 15 files changed, 231 deletions(-) delete mode 100644 app/controllers/system_messages_controller.rb delete mode 100644 app/helpers/system_messages_helper.rb delete mode 100644 app/views/system_messages/_form.html.haml delete mode 100644 app/views/system_messages/_form_core.html.haml delete mode 100644 app/views/system_messages/_index_core.html.haml delete mode 100644 app/views/system_messages/index.html.haml delete mode 100644 app/views/system_messages/new.html.haml delete mode 100644 app/views/system_messages/show.html.haml delete mode 100644 config/locales/views/system_messages/de.yml delete mode 100644 config/locales/views/system_messages/en.yml delete mode 100644 private_pub.ru delete mode 100644 test/functional/system_messages_controller_test.rb diff --git a/Gemfile b/Gemfile index f273864..b390a28 100644 --- a/Gemfile +++ b/Gemfile @@ -62,9 +62,6 @@ gem 'will_paginate' gem 'daemons' gem 'delayed_job_active_record' -# Private Pub http://railscasts.com/episodes/316-private-pub -gem 'private_pub' - # https://github.com/iain/http_accept_language gem 'http_accept_language' diff --git a/Gemfile.lock b/Gemfile.lock index 6d348e0..ad47697 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,7 +29,6 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) acts_as_list (0.1.9) - addressable (2.3.2) arel (3.0.2) backup (3.0.27) open4 (~> 1.3.0) @@ -63,7 +62,6 @@ GEM sass (~> 3.1) compass-rails (1.0.3) compass (>= 0.12.2, < 0.14) - cookiejar (0.3.0) daemons (1.1.9) dalli (2.6.2) delayed_job (3.0.4) @@ -71,14 +69,6 @@ GEM delayed_job_active_record (0.3.3) activerecord (>= 2.1.0, < 4) delayed_job (~> 3.0) - em-http-request (1.0.3) - addressable (>= 2.2.3) - cookiejar - em-socksify - eventmachine (>= 1.0.0.beta.4) - http_parser.rb (>= 0.5.3) - em-socksify (0.2.1) - eventmachine (>= 1.0.0.beta.4) erubis (2.7.0) eventmachine (1.0.0) execjs (1.4.0) @@ -88,21 +78,11 @@ GEM factory_girl_rails (4.2.0) factory_girl (~> 4.2.0) railties (>= 3.0.0) - faye (0.8.8) - cookiejar (>= 0.3.0) - em-http-request (>= 0.3.0) - eventmachine (>= 0.12.0) - faye-websocket (>= 0.4.0) - rack (>= 1.0.0) - yajl-ruby (>= 1.0.0) - faye-websocket (0.4.6) - eventmachine (>= 0.12.0) fssm (0.2.10) haml (3.1.7) hike (1.2.1) hirb (0.7.1) http_accept_language (1.0.2) - http_parser.rb (0.5.3) i18n (0.6.1) inifile (2.0.2) journey (1.0.4) @@ -125,8 +105,6 @@ GEM nokogiri (1.5.6) open4 (1.3.0) polyglot (0.3.3) - private_pub (1.0.3) - faye quiet_assets (1.0.1) railties (~> 3.1) rack (1.4.4) @@ -202,7 +180,6 @@ GEM activesupport (>= 2.3.4) chronic (>= 0.6.3) will_paginate (3.0.4) - yajl-ruby (1.1.0) PLATFORMS ruby @@ -233,7 +210,6 @@ DEPENDENCIES mini_magick mysql2 nokogiri - private_pub quiet_assets rails (= 3.2.11) sass-rails diff --git a/app/controllers/system_messages_controller.rb b/app/controllers/system_messages_controller.rb deleted file mode 100644 index d7fe515..0000000 --- a/app/controllers/system_messages_controller.rb +++ /dev/null @@ -1,30 +0,0 @@ -class SystemMessagesController < ApplicationController - load_and_authorize_resource :user - load_and_authorize_resource :system_message, :through => [:user] - - def index - @system_messages = @system_messages.where(:created_at => Time.now - 6.hours .. Time.now) - end - - def show - end - - def new - @system_message = @user.system_messages.build - end - - def create - @system_message = @user.system_messages.build(params[:system_message]) - if @system_message.save - # Push the new message via AJAX to the browser. - # - # PrivatePub.publish_to("/users/#{@system_message.user.id}/system_messages", - # "$('#system_message').empty();$('#system_message').append('#{(I18n.l @system_message.created_at, :format => :short )} #{@system_message.content}');$('#system_message_display').fadeIn();" - # ) - - redirect_to user_system_message_path(@user, @system_message), :notice => t('system_messages.controller.successfuly_created') - else - render :new - end - end -end diff --git a/app/helpers/system_messages_helper.rb b/app/helpers/system_messages_helper.rb deleted file mode 100644 index fef2386..0000000 --- a/app/helpers/system_messages_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module SystemMessagesHelper -end diff --git a/app/models/ability.rb b/app/models/ability.rb index 01f26aa..4ec64b1 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -56,10 +56,6 @@ class Ability can :read, PhoneBookEntry, :phone_book => { :id => user_group.phone_book_ids } end - # SystemMessages - # - cannot [:destroy, :edit, :update], SystemMessage - # A FacDocument can't be changed # cannot [:edit, :update], FaxDocument diff --git a/app/views/system_messages/_form.html.haml b/app/views/system_messages/_form.html.haml deleted file mode 100644 index 036ee00..0000000 --- a/app/views/system_messages/_form.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -= simple_form_for([@user, @system_message]) do |f| - = f.error_notification - - = render "form_core", :f => f - - .actions - = f.button :submit, conditional_t('system_messages.form.submit') \ No newline at end of file diff --git a/app/views/system_messages/_form_core.html.haml b/app/views/system_messages/_form_core.html.haml deleted file mode 100644 index a85db28..0000000 --- a/app/views/system_messages/_form_core.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -.inputs - = f.input :content, :label => t('system_messages.form.content.label'), :hint => conditional_hint('system_messages.form.content.hint') diff --git a/app/views/system_messages/_index_core.html.haml b/app/views/system_messages/_index_core.html.haml deleted file mode 100644 index 7c9dab5..0000000 --- a/app/views/system_messages/_index_core.html.haml +++ /dev/null @@ -1,12 +0,0 @@ -%table.table.table-striped - %thead - %tr - %th= t('system_messages.index.created_at') - %th= t('system_messages.index.content') - - %tbody - - for system_message in system_messages - %tr - %td= system_message.created_at - %td= system_message.content - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => system_message} \ No newline at end of file diff --git a/app/views/system_messages/index.html.haml b/app/views/system_messages/index.html.haml deleted file mode 100644 index ffd3fc3..0000000 --- a/app/views/system_messages/index.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -- content_for :title, t("system_messages.index.page_title") - -= render "index_core", :system_messages => @system_messages \ No newline at end of file diff --git a/app/views/system_messages/new.html.haml b/app/views/system_messages/new.html.haml deleted file mode 100644 index 565f5c5..0000000 --- a/app/views/system_messages/new.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -- content_for :title, t("system_messages.new.page_title") - -= render "form" diff --git a/app/views/system_messages/show.html.haml b/app/views/system_messages/show.html.haml deleted file mode 100644 index 70be6f2..0000000 --- a/app/views/system_messages/show.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -- content_for :title, t("system_messages.show.page_title") - -%p - %strong= t('system_messages.show.created_at') + ":" - = @system_message.created_at -%p - %strong= t('system_messages.show.content') + ":" - = @system_message.content diff --git a/config/locales/views/system_messages/de.yml b/config/locales/views/system_messages/de.yml deleted file mode 100644 index d841d0b..0000000 --- a/config/locales/views/system_messages/de.yml +++ /dev/null @@ -1,38 +0,0 @@ -de: - system_messages: - name: 'Systemnachricht' - controller: - successfuly_created: 'Eine Systemnachricht wurde erstellt.' - successfuly_updated: 'Eine Systemnachricht wurde aktualisiert.' - successfuly_destroyed: 'Eine Systemnachricht wurde gelöscht.' - index: - page_title: 'Systemnachrichten' - user_id: 'Benutzer' - content: 'Nachricht' - actions: - confirm_destroy: 'Sind Sie sicher, dass Sie diese Systemnachricht löschen möchten?' - destroy: 'Löschen' - edit: 'Bearbeiten' - show: 'Anzeigen' - create: 'Neu anlegen' - show: - page_title: 'Systemnachricht anzeigen' - user_id: 'Benutzer' - content: 'Nachricht' - actions: - confirm_destroy: 'Sind Sie sicher, dass Sie diese Systemnachricht löschen möchten?' - destroy: 'Löschen' - edit: 'Bearbeiten' - view_all: 'Alle anzeigen' - new: - page_title: 'Neue Systemnachricht' - edit: - page_title: 'Systemnachricht bezüglich %{resource} bearbeiten' - form: - user_id: - label: 'Benutzer' - hint: '' - content: - label: 'Nachricht' - hint: '' - submit: 'Absenden' \ No newline at end of file diff --git a/config/locales/views/system_messages/en.yml b/config/locales/views/system_messages/en.yml deleted file mode 100644 index a039b10..0000000 --- a/config/locales/views/system_messages/en.yml +++ /dev/null @@ -1,38 +0,0 @@ -en: - system_messages: - name: 'System message' - controller: - successfuly_created: 'Successfully created System message.' - successfuly_updated: 'Successfully updated System message.' - successfuly_destroyed: 'Successfully destroyed System message.' - index: - page_title: 'System messages' - user_id: 'User' - content: 'Content' - actions: - confirm_destroy: 'Are you sure you want to delete this element?' - destroy: 'Delete' - edit: 'Edit' - show: 'View' - create: 'New' - show: - page_title: 'Editing System message' - user_id: 'User' - content: 'Content' - actions: - confirm_destroy: 'Are you sure you want to delete this element?' - destroy: 'Delete' - edit: 'Edit' - view_all: 'View All' - new: - page_title: 'New System message' - edit: - page_title: 'Editing System message %{resource}' - form: - user_id: - label: 'User' - hint: '' - content: - label: 'Content' - hint: '' - submit: 'Submit' \ No newline at end of file diff --git a/private_pub.ru b/private_pub.ru deleted file mode 100644 index 2db4acf..0000000 --- a/private_pub.ru +++ /dev/null @@ -1,8 +0,0 @@ -# Run with: rackup private_pub.ru -s thin -E production -require "bundler/setup" -require "yaml" -require "faye" -require "private_pub" - -PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development") -run PrivatePub.faye_app diff --git a/test/functional/system_messages_controller_test.rb b/test/functional/system_messages_controller_test.rb deleted file mode 100644 index 2894cd3..0000000 --- a/test/functional/system_messages_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class SystemMessagesControllerTest < ActionController::TestCase - setup do - @system_message = system_messages(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:system_messages) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create system_message" do - assert_difference('SystemMessage.count') do - post :create, system_message: @system_message.attributes - end - - assert_redirected_to system_message_path(assigns(:system_message)) - end - - test "should show system_message" do - get :show, id: @system_message.to_param - assert_response :success - end - - test "should get edit" do - get :edit, id: @system_message.to_param - assert_response :success - end - - test "should update system_message" do - put :update, id: @system_message.to_param, system_message: @system_message.attributes - assert_redirected_to system_message_path(assigns(:system_message)) - end - - test "should destroy system_message" do - assert_difference('SystemMessage.count', -1) do - delete :destroy, id: @system_message.to_param - end - - assert_redirected_to system_messages_path - end -end -- cgit v1.2.3 From ca8121930d7e75b9f6bac08591c6ffea3ca1fea1 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 14:42:22 +0100 Subject: Removed PrivatePub stuff. --- app/models/ability.rb | 4 ---- app/models/system_message.rb | 7 ------- db/migrate/20120127101726_create_system_messages.rb | 13 ------------- test/unit/system_message_test.rb | 7 ------- 4 files changed, 31 deletions(-) delete mode 100644 app/models/system_message.rb delete mode 100644 db/migrate/20120127101726_create_system_messages.rb delete mode 100644 test/unit/system_message_test.rb diff --git a/app/models/ability.rb b/app/models/ability.rb index 4ec64b1..4c0844c 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -156,10 +156,6 @@ class Ability # can :manage, CallForward, :phone_number_id => user.phone_number_ids - # SystemMessages - # - can :read, SystemMessage, :user_id => user.id - # SoftkeyFunctions # can :read, SoftkeyFunction diff --git a/app/models/system_message.rb b/app/models/system_message.rb deleted file mode 100644 index 0d9e862..0000000 --- a/app/models/system_message.rb +++ /dev/null @@ -1,7 +0,0 @@ -class SystemMessage < ActiveRecord::Base - attr_accessible :content - - belongs_to :user - - validates_presence_of :content -end diff --git a/db/migrate/20120127101726_create_system_messages.rb b/db/migrate/20120127101726_create_system_messages.rb deleted file mode 100644 index 830f54a..0000000 --- a/db/migrate/20120127101726_create_system_messages.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateSystemMessages < ActiveRecord::Migration - def self.up - create_table :system_messages do |t| - t.integer :user_id - t.string :content - t.timestamps - end - end - - def self.down - drop_table :system_messages - end -end diff --git a/test/unit/system_message_test.rb b/test/unit/system_message_test.rb deleted file mode 100644 index 0476ac8..0000000 --- a/test/unit/system_message_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SystemMessageTest < ActiveSupport::TestCase - # def test_should_be_valid - # assert SystemMessage.new.valid? - # end -end -- cgit v1.2.3 From c5b10519dd1ade04a25c43b100c15deb7e39b6d0 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 15:07:23 +0100 Subject: Added entity in the table. But it's fare from pretty. #136 --- app/views/gs_parameters/_index_core.html.haml | 14 ++++++++++++-- app/views/gs_parameters/index.html.haml | 12 +++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/views/gs_parameters/_index_core.html.haml b/app/views/gs_parameters/_index_core.html.haml index 11d60db..2105126 100644 --- a/app/views/gs_parameters/_index_core.html.haml +++ b/app/views/gs_parameters/_index_core.html.haml @@ -1,6 +1,9 @@ -- cache(['gs_parameters_table_section', gs_parameters.first.section, gs_parameters.reorder(:updated_at).last, gs_parameters.pluck(:id)]) do +- cache(['gs_parameter_sub_table', I18n.locale, gs_parameters.count, gs_parameters.reorder(:updated_at).first, gs_parameters.reorder(:updated_at).last]) do %thead %tr + %th + %span.hidden-phone + = t('gs_parameters.index.entity') %th= t('gs_parameters.index.name') - if !@sections %th= t('gs_parameters.index.section') @@ -8,8 +11,15 @@ %tbody - for gs_parameter in gs_parameters - - cache(['gs_parameters_table_single_row', gs_parameter]) do + - cache(['gs_parameters_table_single_row', I18n.locale, gs_parameter]) do %tr + %td + - if gs_parameter.entity.blank? + %span.hidden-phone + = '-' + - else + %span.hidden-phone + = truncate(gs_parameter.entity, :length => GsParameter.get('DESKTOP_MAX_STRING_LENGTH')) %td %span.hidden-phone = truncate(gs_parameter.name, :length => GsParameter.get('DESKTOP_MAX_STRING_LENGTH')) diff --git a/app/views/gs_parameters/index.html.haml b/app/views/gs_parameters/index.html.haml index 1189a45..8df2bb3 100644 --- a/app/views/gs_parameters/index.html.haml +++ b/app/views/gs_parameters/index.html.haml @@ -1,13 +1,11 @@ - content_for :title, t("gs_parameters.index.page_title") -- if @gs_parameters && @gs_parameters.count > 0 - - cache(['gs_parameters_table', I18n.locale, @gs_parameters_unordered.reorder(:updated_at).last, @gs_parameters_unordered.count]) do +- cache(['gs_parameter_all_tables', I18n.locale, @gs_parameters.count, @gs_parameters.reorder(:updated_at).first, @gs_parameters.reorder(:updated_at).last]) do + - if @gs_parameters && @gs_parameters.count > 0 - if @sections - %table.table.table-striped - - @sections.each do |section| - %tr - %td{:colspan => 3} - %h3= section + - @sections.each do |section| + %h3= section + %table.table.table-striped -# Template Dependency: gs_parameters/_index_core = render "index_core", :gs_parameters => @gs_parameters.where(:section => section) - else -- cgit v1.2.3 From 42ee5557a5ac11743b573b25eb8fdb60c8c13aa3 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 16:24:55 +0100 Subject: Use the copyright symbol. --- app/views/layouts/_footer.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 3d4658b..2703844 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -16,4 +16,4 @@ %li =link_to t('misc.send_a_bugreport'), URI::escape("https://github.com/amooma/GS5/issues/new?title=Bugreport&body=URL which triggered the bugreport is: #{request.fullpath}\nGS5 buildname: #{(GsParameter.get('GEMEINSCHAFT_BUILDNAME').blank? ? 'unknown' : GsParameter.get('GEMEINSCHAFT_BUILDNAME'))} (#{GsParameter.get('GEMEINSCHAFT_VERSION')})\n\nPlease provide your bugreport below this line and update the title of this issue to a more specific one.") %li{:class => 'pull-right'} - = link_to 'brought to you by AMOOMA GmbH', 'http://amooma.de' \ No newline at end of file + = link_to '© AMOOMA GmbH', 'http://amooma.de' \ No newline at end of file -- cgit v1.2.3 From da362f73cf417aa2eda9124d17c66850087ea0f6 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 16:52:24 +0100 Subject: Backup GUI improvements. --- app/controllers/backup_jobs_controller.rb | 15 ++++--- app/controllers/tenants_controller.rb | 1 + app/views/backup_jobs/_index_core.html.haml | 34 +++++++++++---- app/views/backup_jobs/show.html.haml | 4 +- app/views/tenants/_admin_area.de.html.haml | 4 +- app/views/tenants/_admin_area.en.html.haml | 4 +- app/views/tenants/_table_of_backup_jobs.html.haml | 11 +++++ app/views/tenants/show.html.haml | 2 +- config/locales/views/backup_jobs/de.yml | 51 ++++++++++++----------- config/locales/views/backup_jobs/en.yml | 19 +++++---- 10 files changed, 94 insertions(+), 51 deletions(-) create mode 100644 app/views/tenants/_table_of_backup_jobs.html.haml diff --git a/app/controllers/backup_jobs_controller.rb b/app/controllers/backup_jobs_controller.rb index 4f242ba..31b9c21 100644 --- a/app/controllers/backup_jobs_controller.rb +++ b/app/controllers/backup_jobs_controller.rb @@ -4,29 +4,34 @@ class BackupJobsController < ApplicationController before_filter :spread_breadcrumbs def index - # @backup_jobs = BackupJob.all end def show - # @backup_job = BackupJob.find(params[:id]) end def new - @backup_job = BackupJob.new + # Do the same as create. + # + @backup_job = BackupJob.new(:started_at => Time.now) + + if @backup_job.save + redirect_to backup_jobs_path, :notice => t('backup_jobs.controller.successfuly_created') + else + render :new + end end def create @backup_job = BackupJob.new(:started_at => Time.now) if @backup_job.save - redirect_to @backup_job, :notice => t('backup_jobs.controller.successfuly_created') + redirect_to backup_jobs_path, :notice => t('backup_jobs.controller.successfuly_created') else render :new end end def destroy - # @backup_job = BackupJob.find(params[:id]) @backup_job.destroy redirect_to backup_jobs_url, :notice => t('backup_jobs.controller.successfuly_destroyed') end diff --git a/app/controllers/tenants_controller.rb b/app/controllers/tenants_controller.rb index f30246b..b6a96b7 100644 --- a/app/controllers/tenants_controller.rb +++ b/app/controllers/tenants_controller.rb @@ -8,6 +8,7 @@ class TenantsController < ApplicationController def show @tenant = Tenant.find(params[:id]) @gateways = Gateway.order(:updated_at) + @backup_jobs = BackupJob.order(:finished_at).last(5) end def new diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml index 9eebefd..9dc0e92 100644 --- a/app/views/backup_jobs/_index_core.html.haml +++ b/app/views/backup_jobs/_index_core.html.haml @@ -1,12 +1,15 @@ %table.table.table-striped %tr %th= t('backup_jobs.index.started_at') - %th= t('backup_jobs.index.finished_at') + %th + %span.hidden-phone + = t('backup_jobs.index.finished_at') %th= t('backup_jobs.index.state') - %th= t('backup_jobs.index.size_of_the_backup') + %th + %span.hidden-phone + = t('backup_jobs.index.size_of_the_backup') %th{:colspan => '2'} - - for backup_job in backup_jobs - if backup_job.state == 'queued' - row_marker = 'warning' @@ -18,14 +21,29 @@ %tr{:class => row_marker} - if backup_job.finished_at.blank? %td{:colspan => '2'} - = time_ago_in_words(backup_job.started_at) + - if (Time.now - 1.day) > backup_job.started_at + = l backup_job.started_at, :format => :short + - else + - case I18n.locale + - when :de + = "vor #{time_ago_in_words(backup_job.started_at)}" + - when :en + = "#{time_ago_in_words(backup_job.started_at)} ago" + - else + = l backup_job.started_at, :format => :short - else %td = l backup_job.started_at, :format => :short %td - = l backup_job.finished_at, :format => :short + %span.hidden-phone + = l backup_job.finished_at, :format => :short %td= backup_job.state %td - - if backup_job.backup_file? - = number_to_human_size(backup_job.backup_file.size, :precision => 2) - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => backup_job} \ No newline at end of file + %span.hidden-phone + - if backup_job.backup_file? + %a{:href => backup_job.backup_file.current_path} + %i{:class => 'icon-download'} + = number_to_human_size(backup_job.backup_file.size, :precision => 2) + - else + = '-' + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => backup_job} diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index 5d85bbc..6c55320 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -15,6 +15,8 @@ %p %strong= t('backup_jobs.show.size_of_the_backup') + ":" - if @backup_job.backup_file? - = number_to_human_size(@backup_job.backup_file.size, :precision => 2) + %a{:href => backup_job.backup_file.current_path} + %i{:class => 'icon-download'} + = number_to_human_size(backup_job.backup_file.size, :precision => 2) = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job } \ No newline at end of file diff --git a/app/views/tenants/_admin_area.de.html.haml b/app/views/tenants/_admin_area.de.html.haml index 98809d1..2aed4e1 100644 --- a/app/views/tenants/_admin_area.de.html.haml +++ b/app/views/tenants/_admin_area.de.html.haml @@ -37,4 +37,6 @@ = render :partial => 'call_routes', :locals => {:tenant => tenant} - = render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} \ No newline at end of file + = render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} + + = render :partial => 'table_of_backup_jobs', :locals => {:tenant => tenant, :backup_jobs => backup_jobs} diff --git a/app/views/tenants/_admin_area.en.html.haml b/app/views/tenants/_admin_area.en.html.haml index 4f0032c..8e7bfea 100644 --- a/app/views/tenants/_admin_area.en.html.haml +++ b/app/views/tenants/_admin_area.en.html.haml @@ -37,4 +37,6 @@ = render :partial => 'call_routes', :locals => {:tenant => tenant} - = render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} \ No newline at end of file + = render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} + + = render :partial => 'table_of_backup_jobs', :locals => {:tenant => tenant, :backup_jobs => backup_jobs} \ No newline at end of file diff --git a/app/views/tenants/_table_of_backup_jobs.html.haml b/app/views/tenants/_table_of_backup_jobs.html.haml new file mode 100644 index 0000000..a585010 --- /dev/null +++ b/app/views/tenants/_table_of_backup_jobs.html.haml @@ -0,0 +1,11 @@ +-# BackupJobs +-# +- if (can?( :index, BackupJob ) && backup_jobs.count > 0 ) || can?( :create, BackupJob ) + - if backup_jobs.count == BackupJob.count + %h2= t('backup_jobs.index.page_title') + - else + %h2= t('backup_jobs.index.page_title_with_limit', :limit => '5') + + - if can?( :index, BackupJob ) && backup_jobs.count > 0 + = render "backup_jobs/index_core", :backup_jobs => backup_jobs + = render :partial => 'shared/create_link', :locals => {:child_class => BackupJob} \ No newline at end of file diff --git a/app/views/tenants/show.html.haml b/app/views/tenants/show.html.haml index 818e584..23ec81a 100644 --- a/app/views/tenants/show.html.haml +++ b/app/views/tenants/show.html.haml @@ -15,4 +15,4 @@ = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @tenant } - if @tenant.user_groups.where(:name => 'Admins').any? && @tenant.user_groups.where(:name => 'Admins').first.users.include?(current_user) - = render :partial => 'admin_area', :locals => { :tenant => @tenant, :gateways => @gateways} \ No newline at end of file + = render :partial => 'admin_area', :locals => { :tenant => @tenant, :gateways => @gateways, :backup_jobs => @backup_jobs} \ No newline at end of file diff --git a/config/locales/views/backup_jobs/de.yml b/config/locales/views/backup_jobs/de.yml index b81b532..8e23feb 100644 --- a/config/locales/views/backup_jobs/de.yml +++ b/config/locales/views/backup_jobs/de.yml @@ -1,60 +1,61 @@ de: backup_jobs: - name: 'Backup job' + name: 'Backup-Auftrag' controller: - successfuly_created: 'Backup job wurde angelegt.' - successfuly_updated: 'Backup job wurde aktualisiert.' - successfuly_destroyed: 'Backup job wurde gelöscht.' + successfuly_created: 'Backup-Auftrag wurde angelegt.' + successfuly_updated: 'Backup-Auftrag wurde aktualisiert.' + successfuly_destroyed: 'Backup-Auftrag wurde gelöscht.' index: - page_title: 'Übersicht von Backup job' - started_at: 'Started at' - finished_at: 'Finished at' - state: 'State' - directory: 'Directory' - size_of_the_backup: 'Size of the backup' + page_title: 'Liste aller Backup-Aufträge' + page_title_with_limit: 'Liste der letzten %{limit} Backup-Aufträge' + started_at: 'Start' + finished_at: 'Ende' + state: 'Status' + directory: 'Verzeichnis' + size_of_the_backup: 'Größe' actions: - confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Backup job' + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Backup-Auftrag' destroy: 'Löschen' edit: 'Bearbeiten' show: 'Anzeigen' create: 'Neu anlegen' - create_for: 'Backup job neu anlegen für %{resource}' + create_for: 'Backup-Auftrag neu anlegen für %{resource}' show: - page_title: 'Backup job bearbeiten' - started_at: 'Started at' - finished_at: 'Finished at' - state: 'State' - directory: 'Directory' - size_of_the_backup: 'Size of the backup' + page_title: 'Backup-Auftrag bearbeiten' + started_at: 'Start' + finished_at: 'Ende' + state: 'Status' + directory: 'Verzeichnis' + size_of_the_backup: 'Größe' actions: confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?' destroy: 'Löschen' edit: 'Bearbeiten' view_all: 'Alle anzeigen' new: - page_title: 'Backup job neu anlegen' + page_title: 'Backup-Auftrag neu anlegen' actions: back_to_list: 'Zurück zur Übersicht' edit: - page_title: 'Backup job bearbeiten' + page_title: 'Backup-Auftrag bearbeiten' actions: back_to_list: 'Zurück zur Übersicht' edit: 'Bearbeiten' view_all: 'Alle anzeigen' form: started_at: - label: 'Started at' + label: 'Start' hint: '' finished_at: - label: 'Finished at' + label: 'Ende' hint: '' state: - label: 'State' + label: 'Status' hint: '' directory: - label: 'Directory' + label: 'Verzeichnis' hint: '' size_of_the_backup: - label: 'Size of the backup' + label: 'Größe' hint: '' submit: 'Absenden' \ No newline at end of file diff --git a/config/locales/views/backup_jobs/en.yml b/config/locales/views/backup_jobs/en.yml index 83f4388..74d14c2 100644 --- a/config/locales/views/backup_jobs/en.yml +++ b/config/locales/views/backup_jobs/en.yml @@ -2,25 +2,26 @@ en: backup_jobs: name: 'Backup job' controller: - successfuly_created: 'Successfully created Backup job.' - successfuly_updated: 'Successfully updated Backup job.' - successfuly_destroyed: 'Successfully destroyed Backup job.' + successfuly_created: 'Successfully created backup job.' + successfuly_updated: 'Successfully updated backup job.' + successfuly_destroyed: 'Successfully destroyed backup job.' index: - page_title: 'Listing Backup job' + page_title: 'Listing backup jobs' + page_title_with_limit: 'Listing of the last %{limit} backup jobs' started_at: 'Started at' finished_at: 'Finished at' state: 'State' directory: 'Directory' size_of_the_backup: 'Size of the backup' actions: - confirm_destroy: 'Are you sure you want to delete this Backup job?' + confirm_destroy: 'Are you sure you want to delete this backup job?' destroy: 'Delete' edit: 'Edit' show: 'View' create: 'New' - create_for: 'New Backup job for %{resource}' + create_for: 'New backup job for %{resource}' show: - page_title: 'Show Backup job' + page_title: 'Show backup job' started_at: 'Started at' finished_at: 'Finished at' state: 'State' @@ -32,11 +33,11 @@ en: edit: 'Edit' view_all: 'View All' new: - page_title: 'New Backup job' + page_title: 'New backup job' actions: back_to_list: 'Back to Index' edit: - page_title: 'Editing Backup job' + page_title: 'Editing backup job' actions: back_to_list: 'Back to Index' edit: 'Edit' -- cgit v1.2.3 From 0ba495685589e99e1100af6d7af9d69ee4f40b78 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 16:59:15 +0100 Subject: Removed icons. --- app/views/layouts/_navbar.html.haml | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index 335dd3d..7084090 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -21,11 +21,9 @@ - if current_user && current_user.sip_accounts.any? %li %a{:href => sip_account_call_histories_path(current_user.sip_accounts.first)} - %i.icon-list-alt.icon-white =t("call_histories.index.page_title") %li %a{:href => sip_account_voicemail_messages_path(current_user.sip_accounts.first)} - %i.icon-volume-up.icon-white =t("voicemail_messages.index.page_title") - if current_user -- cgit v1.2.3 From b5cb8b7fa389c0a542825173b058dfcf428f6680 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 11 Feb 2013 17:44:09 +0100 Subject: Fix URL --- app/views/backup_jobs/_index_core.html.haml | 2 +- app/views/backup_jobs/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/backup_jobs/_index_core.html.haml b/app/views/backup_jobs/_index_core.html.haml index 9dc0e92..0102546 100644 --- a/app/views/backup_jobs/_index_core.html.haml +++ b/app/views/backup_jobs/_index_core.html.haml @@ -41,7 +41,7 @@ %td %span.hidden-phone - if backup_job.backup_file? - %a{:href => backup_job.backup_file.current_path} + %a{:href => backup_job.backup_file.url} %i{:class => 'icon-download'} = number_to_human_size(backup_job.backup_file.size, :precision => 2) - else diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index 6c55320..6fcb1dc 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -15,7 +15,7 @@ %p %strong= t('backup_jobs.show.size_of_the_backup') + ":" - if @backup_job.backup_file? - %a{:href => backup_job.backup_file.current_path} + %a{:href => backup_job.backup_file.url} %i{:class => 'icon-download'} = number_to_human_size(backup_job.backup_file.size, :precision => 2) -- cgit v1.2.3 From 3d817bef265f70b147455db4b0fb5e1ca3c0d379 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 12 Feb 2013 00:21:15 +0100 Subject: add german language settings --- misc/freeswitch/conf/freeswitch.xml | 465 ++++++++++++++++++++++++++++++++++++ 1 file changed, 465 insertions(+) diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 2ecb618..a7eb44d 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -466,6 +466,470 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -632,6 +1096,7 @@ + -- cgit v1.2.3 From d1145ad9d4f495d7416ed97e0dd3c17365990323 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 12 Feb 2013 08:19:00 +0100 Subject: create profile template --- db/migrate/20130212071000_default_profile_to_template.rb | 13 +++++++++++++ misc/freeswitch/scripts/configuration.lua | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20130212071000_default_profile_to_template.rb diff --git a/db/migrate/20130212071000_default_profile_to_template.rb b/db/migrate/20130212071000_default_profile_to_template.rb new file mode 100644 index 0000000..d3fd89c --- /dev/null +++ b/db/migrate/20130212071000_default_profile_to_template.rb @@ -0,0 +1,13 @@ +class DefaultProfileToTemplate < ActiveRecord::Migration + def up + GsParameter.where(:entity => 'sofia', :section => 'profile:gemeinschaft').each do |profile| + profile.update_attributes(:section => 'profile') + end + end + + def down + GsParameter.where(:entity => 'sofia', :section => 'profile').each do |profile| + profile.update_attributes(:section => 'profile:gemeinschaft') + end + end +end diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 18f4ef2..9847cc9 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -63,7 +63,12 @@ function profile(database, sofia_ini, profile_name, index, domains, node_id) require 'configuration.simple_xml' local xml = configuration.simple_xml.SimpleXml:new(); - local parameters = sofia_ini['profile:' .. profile_name]; + local profile_template = sofia_ini['profile'] or {}; + local parameters = sofia_ini['profile:' .. profile_name] or {}; + + for key, value in pairs(profile_template) do + parameters[key] = parameters[key] or value; + end if not parameters then log:error('SOFIA_PROFILE ', index,' - name: ', profile_name, ' - no parameters'); -- cgit v1.2.3 From 35c4406d4e3dd323714c05dc1f9a9aa454e6e140 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 12 Feb 2013 08:36:18 +0100 Subject: bundle update because of CVE-2013-0269 --- Gemfile.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ad47697..8491109 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -34,9 +34,9 @@ GEM open4 (~> 1.3.0) thor (>= 0.15.4, < 2) bcrypt-ruby (3.0.1) - better_errors (0.3.2) + better_errors (0.5.0) coderay (>= 1.0.0) - erubis (>= 2.7.0) + erubis (>= 2.6.6) binding_of_caller (0.6.8) breadcrumbs_on_rails (2.3.0) builder (3.0.4) @@ -64,9 +64,9 @@ GEM compass (>= 0.12.2, < 0.14) daemons (1.1.9) dalli (2.6.2) - delayed_job (3.0.4) + delayed_job (3.0.5) activesupport (~> 3.0) - delayed_job_active_record (0.3.3) + delayed_job_active_record (0.4.0) activerecord (>= 2.1.0, < 4) delayed_job (~> 3.0) erubis (2.7.0) @@ -75,7 +75,7 @@ GEM multi_json (~> 1.0) factory_girl (4.2.0) activesupport (>= 3.0.0) - factory_girl_rails (4.2.0) + factory_girl_rails (4.2.1) factory_girl (~> 4.2.0) railties (>= 3.0.0) fssm (0.2.10) @@ -86,10 +86,10 @@ GEM i18n (0.6.1) inifile (2.0.2) journey (1.0.4) - jquery-rails (2.2.0) + jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.7.6) + json (1.7.7) kgio (2.8.0) macaddr (1.6.1) systemu (~> 2.5.0) @@ -97,20 +97,20 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - mime-types (1.19) + mime-types (1.21) mini_magick (3.4) subexec (~> 0.2.1) - multi_json (1.5.0) + multi_json (1.5.1) mysql2 (0.3.11) nokogiri (1.5.6) open4 (1.3.0) polyglot (0.3.3) quiet_assets (1.0.1) railties (~> 3.1) - rack (1.4.4) + rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-ssl (1.3.2) + rack-ssl (1.3.3) rack rack-test (0.6.2) rack (>= 1.0) @@ -131,7 +131,7 @@ GEM thor (>= 0.14.6, < 2.0) raindrops (0.10.0) rake (10.0.3) - rdoc (3.12) + rdoc (3.12.1) json (~> 1.4) sass (3.2.5) sass-rails (3.2.6) @@ -170,7 +170,7 @@ GEM uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) - unicorn (4.5.0) + unicorn (4.6.0) kgio (~> 2.6) rack raindrops (~> 0.7) -- cgit v1.2.3 From 0ece4561627130eceb83deef4e5c2df00ec1664e Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 12 Feb 2013 09:41:55 +0100 Subject: support for registrations to non default profiles --- misc/freeswitch/scripts/common/sip_account.lua | 8 ++++-- misc/freeswitch/scripts/configuration.lua | 2 +- misc/freeswitch/scripts/dialplan/sip_call.lua | 36 +++++++++++++++----------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/misc/freeswitch/scripts/common/sip_account.lua b/misc/freeswitch/scripts/common/sip_account.lua index 8dd432b..d023f20 100644 --- a/misc/freeswitch/scripts/common/sip_account.lua +++ b/misc/freeswitch/scripts/common/sip_account.lua @@ -38,8 +38,12 @@ function SipAccount.find_by_sql(self, where) `a`.`sip_accountable_id`, \ `a`.`hotdeskable`, \ `a`.`gs_node_id`, \ - `b`.`host` \ - FROM `sip_accounts` `a` JOIN `sip_domains` `b` ON `a`.`sip_domain_id` = `b`.`id` \ + `b`.`host`, \ + `c`.`sip_host`, \ + `c`.`profile_name` \ + FROM `sip_accounts` `a` \ + JOIN `sip_domains` `b` ON `a`.`sip_domain_id` = `b`.`id` \ + LEFT JOIN `sip_registrations` `c` ON `a`.`auth_name` = `c`.`sip_user` \ WHERE ' .. where .. ' LIMIT 1'; local sip_account = nil; diff --git a/misc/freeswitch/scripts/configuration.lua b/misc/freeswitch/scripts/configuration.lua index 9847cc9..75d0df3 100644 --- a/misc/freeswitch/scripts/configuration.lua +++ b/misc/freeswitch/scripts/configuration.lua @@ -415,7 +415,7 @@ function directory_sip_account(database) 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); + local sip_account = common.sip_account.SipAccount:new{ log = log, database = database}:find_by_auth_name(auth_name); require 'common.configuration_table' local user_parameters = common.configuration_table.get(database, 'sip_accounts', 'parameters'); diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 61d4f76..b56f1b2 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -116,23 +116,29 @@ function SipCall.fork(self, destinations, arg ) elseif destination.type == 'sipaccount' then local callee_id_params = ''; local sip_account = sip_account_class:find_by_id(destination.id); - local call_waiting = self:call_waiting_busy(sip_account); - if not call_waiting then - destinations[index].numbers = sip_account:phone_numbers(); + if not sip_account then + self.log:notice('FORK - sip_account not found - sip_account=', destination.id); + elseif common.str.blank(sip_account.record.profile_name) or common.str.blank(sip_account.record.sip_host) then + call_result = { code = 480, phrase = 'User offline', disposition = 'USER_NOT_REGISTERED' }; + else + local call_waiting = self:call_waiting_busy(sip_account); + if not call_waiting then + destinations[index].numbers = sip_account:phone_numbers(); - if not arg.callee_id_name then - table.insert(origination_variables, "effective_callee_id_name='" .. sip_account.record.caller_name .. "'"); - end - if not arg.callee_id_number then - table.insert(origination_variables, "effective_callee_id_number='" .. destination.number .. "'"); - end - if destination.alert_info then - table.insert(origination_variables, "alert_info='" .. destination.alert_info .. "'"); + if not arg.callee_id_name then + table.insert(origination_variables, "effective_callee_id_name='" .. sip_account.record.caller_name .. "'"); + end + if not arg.callee_id_number then + table.insert(origination_variables, "effective_callee_id_number='" .. destination.number .. "'"); + end + if destination.alert_info then + table.insert(origination_variables, "alert_info='" .. destination.alert_info .. "'"); + end + table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/' .. sip_account.record.profile_name .. '/' .. sip_account.record.auth_name .. '%' .. sip_account.record.sip_host); + else + some_destinations_busy = true; + call_result = { code = 486, phrase = 'User busy', disposition = 'USER_BUSY' }; end - table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']user/' .. sip_account.record.auth_name); - else - some_destinations_busy = true; - call_result = { code = 486, phrase = 'User busy', disposition = 'USER_BUSY' }; end elseif destination.type == 'gateway' then require 'common.gateway' -- cgit v1.2.3 From dd975872925cab5dc5b1e15a31af7f5d1cc1385c Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 12 Feb 2013 09:55:54 +0100 Subject: Changed the short I18n format for datetime. --- config/locales/de.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 9d85d8e..ffc8e69 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -192,7 +192,7 @@ de: formats: default: ! '%A, %d. %B %Y, %H:%M Uhr' long: ! '%A, %d. %B %Y, %H:%M Uhr' - short: ! '%d. %B, %H:%M Uhr' + short: ! '%d.%m.%Y %H:%M Uhr' pm: nachmittags date_only: '%d.%m.%Y' misc: -- cgit v1.2.3 From b7e6ceb34069756d72c5debafff65f091b636b7d Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 12 Feb 2013 09:57:53 +0100 Subject: Use short I18n format for displaying the datetime. --- app/views/call_histories/_index_core.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/call_histories/_index_core.html.haml b/app/views/call_histories/_index_core.html.haml index 4ca340d..8bbf761 100644 --- a/app/views/call_histories/_index_core.html.haml +++ b/app/views/call_histories/_index_core.html.haml @@ -22,7 +22,7 @@ - phone_book_entry = call_history.phone_book_entry_by_number(call_history.display_number) %tr{:id => "call_history_id_#{call_history.id}_tr", :class => (call_history.duration.blank? ? 'warning' : '')} %td - = l call_history.start_stamp, :format => :date_only + = l call_history.start_stamp, :format => :short %td = l call_history.start_stamp, :format => :short %td -- cgit v1.2.3 From ff38cb3ad641ec8ceee26b3b287774e43fe19345 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 12 Feb 2013 11:01:49 +0100 Subject: german language: gespeicherte --- misc/freeswitch/conf/freeswitch.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index a7eb44d..17fc53d 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -538,7 +538,7 @@ - + -- cgit v1.2.3 From 2ff332de8a6253a5f1e9a5914171d4f772da372c Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 12 Feb 2013 11:13:20 +0100 Subject: german language: gespeichert/gespeicherte --- misc/freeswitch/conf/freeswitch.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/freeswitch/conf/freeswitch.xml b/misc/freeswitch/conf/freeswitch.xml index 17fc53d..a5fe873 100644 --- a/misc/freeswitch/conf/freeswitch.xml +++ b/misc/freeswitch/conf/freeswitch.xml @@ -538,7 +538,7 @@ - + @@ -784,7 +784,7 @@ - + -- cgit v1.2.3 From 155403327d0a4915a26aaf2f0b9e390b7e8fdb64 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 12 Feb 2013 12:23:30 +0100 Subject: Changed to if GsParameter.get('PROVISIONING_KEY_LENGTH') == 0 --- app/views/phones/_form_core.html.haml | 2 +- app/views/phones/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/phones/_form_core.html.haml b/app/views/phones/_form_core.html.haml index 17b9ca8..31f3c24 100644 --- a/app/views/phones/_form_core.html.haml +++ b/app/views/phones/_form_core.html.haml @@ -11,5 +11,5 @@ - if defined? GsParameter.get('NIGHTLY_REBOOT_OF_PHONES') && GsParameter.get('NIGHTLY_REBOOT_OF_PHONES') == true = f.input :nightly_reboot, :label => t('phones.form.nightly_reboot.label'), :hint => conditional_hint('phones.form.nightly_reboot.hint') - - if !GsParameter.get('PROVISIONING_KEY_LENGTH').nil? && GsParameter.get('PROVISIONING_KEY_LENGTH') > 0 + - if GsParameter.get('PROVISIONING_KEY_LENGTH') == 0 = f.input :provisioning_key_active, :label => t('phones.form.provisioning_key_active.label'), :hint => conditional_hint('phones.form.provisioning_key_active.hint') diff --git a/app/views/phones/show.html.haml b/app/views/phones/show.html.haml index 86ac380..e9b8b21 100644 --- a/app/views/phones/show.html.haml +++ b/app/views/phones/show.html.haml @@ -34,7 +34,7 @@ %td = @phone.nightly_reboot == true ? t('simple_form.yes') : t('simple_form.no') - - if !GsParameter.get('PROVISIONING_KEY_LENGTH').nil? && GsParameter.get('PROVISIONING_KEY_LENGTH') > 0 + - if GsParameter.get('PROVISIONING_KEY_LENGTH') == 0 %tr %td %strong= t('phones.show.provisioning_key_active') + ":" -- cgit v1.2.3 From aa5a2b806d117ffde9888e282c7100066156d94b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 12 Feb 2013 12:46:36 +0100 Subject: Misc I18n and GUI improvements. --- app/views/call_routes/show.html.haml | 47 +++++++++++++++++------------- config/locales/views/call_routes/de.yml | 24 +++++++-------- config/locales/views/phones/de.yml | 6 ++-- config/locales/views/route_elements/de.yml | 20 ++++++------- config/locales/views/sip_accounts/de.yml | 4 +-- 5 files changed, 54 insertions(+), 47 deletions(-) diff --git a/app/views/call_routes/show.html.haml b/app/views/call_routes/show.html.haml index a33a29b..998558e 100644 --- a/app/views/call_routes/show.html.haml +++ b/app/views/call_routes/show.html.haml @@ -1,26 +1,33 @@ - content_for :title, t("call_routes.show.page_title") -%p - %strong= t('call_routes.show.position') + ":" - = @call_route.position -%p - %strong= t('call_routes.show.table') + ":" - = @call_route.routing_table -%p - %strong= t('call_routes.show.name') + ":" - = @call_route.name -%p - %strong= t('call_routes.show.endpoint') + ":" - - endpoint = @call_route.endpoint - - if endpoint - = endpoint - - else - = @call_route.endpoint_type +.row + .span5 + %table.table.table-striped + %tr + %td + %strong= t('call_routes.show.table') + ":" + %td + = @call_route.routing_table + %tr + %td + %strong= t('call_routes.show.name') + ":" + %td + = @call_route.name + %tr + %td + %strong= t('call_routes.show.endpoint') + ":" + %td + - if @call_route.endpoint.blank? + = @call_route.endpoint_type + - else + = @call_route.endpoint = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @call_route } -%h3= t('route_elements.index.page_title') -- if @call_route.route_elements && @call_route.route_elements.count > 0 - = render "route_elements/index_core", :route_elements => @call_route.route_elements +.row + .span12 + %h3= t('route_elements.index.page_title') + - if @call_route.route_elements && @call_route.route_elements.count > 0 + = render "route_elements/index_core", :route_elements => @call_route.route_elements -= render :partial => 'shared/create_link', :locals => { :parent => @call_route, :child_class => RouteElement } + = render :partial => 'shared/create_link', :locals => { :parent => @call_route, :child_class => RouteElement } diff --git a/config/locales/views/call_routes/de.yml b/config/locales/views/call_routes/de.yml index 77b597b..c9df1c2 100644 --- a/config/locales/views/call_routes/de.yml +++ b/config/locales/views/call_routes/de.yml @@ -1,25 +1,25 @@ de: call_routes: - name: 'Call Route' + name: 'Call-Route' controller: - successfuly_created: 'Call Route wurde angelegt.' - successfuly_updated: 'Call Route wurde aktualisiert.' - successfuly_destroyed: 'Call Route wurde gelöscht.' + successfuly_created: 'Call-Route wurde angelegt.' + successfuly_updated: 'Call-Route wurde aktualisiert.' + successfuly_destroyed: 'Call-Route wurde gelöscht.' index: - page_title: 'Liste aller Call Routen' - routing_table: 'Routing Table' + page_title: 'Liste Call-Routen' + routing_table: 'Routing Tabelle' name: 'Name' - endpoint: 'Endpoint' + endpoint: 'Endpunkt' position: 'Position' actions: - confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Call Route' + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Call-Route' destroy: 'Löschen' edit: 'Bearbeiten' show: 'Anzeigen' create: 'Neu anlegen' - create_for: 'Call Route neu anlegen für %{resource}' + create_for: 'Call-Route neu anlegen für %{resource}' show: - page_title: 'Call Route bearbeiten' + page_title: 'Call-Route bearbeiten' routing_table: 'Routing Table' name: 'Name' endpoint: 'Endpoint' @@ -30,11 +30,11 @@ de: edit: 'Bearbeiten' view_all: 'Alle anzeigen' new: - page_title: 'Call Route neu anlegen' + page_title: 'Call-Route neu anlegen' actions: back_to_list: 'Zurück zur Übersicht' edit: - page_title: 'Call Route bearbeiten' + page_title: 'Call-Route bearbeiten' actions: back_to_list: 'Zurück zur Übersicht' edit: 'Bearbeiten' diff --git a/config/locales/views/phones/de.yml b/config/locales/views/phones/de.yml index 373db13..02875c4 100644 --- a/config/locales/views/phones/de.yml +++ b/config/locales/views/phones/de.yml @@ -9,9 +9,9 @@ de: page_title: 'Telefone' mac_address: 'MAC-Adresse' phone_model_id: 'Modell' - hot_deskable: 'Hot-Desk fähig' - ip_address: 'IP-Adresse' - last_ip_address: 'Letzte IP-Adresse' + hot_deskable: 'Hot-Desk' + ip_address: 'IP' + last_ip_address: 'Letzte IP' http_user: 'Phone WebGUI Username' http_password: 'Phone WebGUI Passwort' nightly_reboot: 'Nachts automatischer Reboot' diff --git a/config/locales/views/route_elements/de.yml b/config/locales/views/route_elements/de.yml index fe14671..70a6162 100644 --- a/config/locales/views/route_elements/de.yml +++ b/config/locales/views/route_elements/de.yml @@ -1,12 +1,12 @@ de: route_elements: - name: 'Route element' + name: 'Routen-Element' controller: - successfuly_created: 'Route element wurde angelegt.' - successfuly_updated: 'Route element wurde aktualisiert.' - successfuly_destroyed: 'Route element wurde gelöscht.' + successfuly_created: 'Routen-Element wurde angelegt.' + successfuly_updated: 'Routen-Element wurde aktualisiert.' + successfuly_destroyed: 'Routen-Element wurde gelöscht.' index: - page_title: 'Übersicht von Route element' + page_title: 'Liste Routen-Elemente' call_route_id: 'Call route' var_in: 'Var in' var_out: 'Var out' @@ -16,14 +16,14 @@ de: mandatory: 'Mandatory' position: 'Position' actions: - confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Route element' + confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Routen-Element' destroy: 'Löschen' edit: 'Bearbeiten' show: 'Anzeigen' create: 'Neu anlegen' - create_for: 'Route element neu anlegen für %{resource}' + create_for: 'Routen-Element neu anlegen für %{resource}' show: - page_title: 'Route element bearbeiten' + page_title: 'Routen-Element bearbeiten' call_route_id: 'Call route' var_in: 'Var in' var_out: 'Var out' @@ -38,11 +38,11 @@ de: edit: 'Bearbeiten' view_all: 'Alle anzeigen' new: - page_title: 'Route element neu anlegen' + page_title: 'Routen-Element neu anlegen' actions: back_to_list: 'Zurück zur Übersicht' edit: - page_title: 'Route element bearbeiten' + page_title: 'Routen-Element bearbeiten' actions: back_to_list: 'Zurück zur Übersicht' edit: 'Bearbeiten' diff --git a/config/locales/views/sip_accounts/de.yml b/config/locales/views/sip_accounts/de.yml index 2820336..8fe2300 100644 --- a/config/locales/views/sip_accounts/de.yml +++ b/config/locales/views/sip_accounts/de.yml @@ -11,11 +11,11 @@ de: caller_name: 'Caller Name' password: 'Passwort' voicemail_pin: 'Anrufbeantworter PIN' - phone_numbers: 'Telefonnummern' + phone_numbers: 'Tel.Nr.' call_waiting: 'Anklopfen' clir: 'Rufnummernunterdrückung (CLIR)' clip: 'Rufnummernanzeige (CLIP)' - hotdeskable: 'Hot-Desk fähig' + hotdeskable: 'Hot-Desk' clip_no_screening: 'Spezifische Rufnummernanzeige (CLIP -no screening-)' callforward_rules_act_per_sip_account: 'Rufweiterleitungen gelten für das gesamte SIP-Account' online: 'Online' -- cgit v1.2.3 From f8f35f666613eff24d3988bda1a22cc40ef2ab30 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 12 Feb 2013 13:26:30 +0100 Subject: Make the call_elements table sortable by drag and drop. --- app/assets/javascripts/route_element.js.coffee | 6 ++++++ app/assets/stylesheets/application.css | 1 + app/assets/stylesheets/route_elements.css.scss | 5 +++++ app/controllers/route_elements_controller.rb | 14 +++++++------- app/models/call_route.rb | 2 +- app/views/call_routes/show.html.haml | 2 +- app/views/route_elements/_form_core.html.haml | 1 - app/views/route_elements/_index_core.html.haml | 12 ++++++++---- config/routes.rb | 4 +++- 9 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 app/assets/javascripts/route_element.js.coffee create mode 100644 app/assets/stylesheets/route_elements.css.scss diff --git a/app/assets/javascripts/route_element.js.coffee b/app/assets/javascripts/route_element.js.coffee new file mode 100644 index 0000000..75dc553 --- /dev/null +++ b/app/assets/javascripts/route_element.js.coffee @@ -0,0 +1,6 @@ +jQuery -> + $('#route_elements').sortable + axis: 'y' + handle: '.handle' + update: -> + $.post($(this).data('update-url'), $(this).sortable('serialize')) \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3e1cc66..44868e4 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -15,4 +15,5 @@ *= require call_routes *= require softkeys *= require phone_numbers + *= require route_elements */ diff --git a/app/assets/stylesheets/route_elements.css.scss b/app/assets/stylesheets/route_elements.css.scss new file mode 100644 index 0000000..a0080ab --- /dev/null +++ b/app/assets/stylesheets/route_elements.css.scss @@ -0,0 +1,5 @@ +#route_elements .handle { + font-size: 12px; + color: #777; + cursor: move; +} \ No newline at end of file diff --git a/app/controllers/route_elements_controller.rb b/app/controllers/route_elements_controller.rb index 9c6f2b7..9c9033e 100644 --- a/app/controllers/route_elements_controller.rb +++ b/app/controllers/route_elements_controller.rb @@ -44,14 +44,14 @@ class RouteElementsController < ApplicationController redirect_to call_route_route_elements_path(@call_route), :notice => t('route_elements.controller.successfuly_destroyed') end - def move_higher - @route_element.move_higher - redirect_to :back - end + def sort + #call_route = RouteElement.find(params[:route_element].first).call_route + + params[:route_element].each do |route_element_id| + @call_route.route_elements.find(route_element_id).move_to_bottom + end - def move_lower - @route_element.move_lower - redirect_to :back + render nothing: true end private diff --git a/app/models/call_route.rb b/app/models/call_route.rb index 6e0dcab..8bc811a 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -4,7 +4,7 @@ class CallRoute < ActiveRecord::Base ROUTING_TABLES = ['prerouting', 'outbound', 'inbound', 'dtmf'] - has_many :route_elements, :dependent => :destroy + has_many :route_elements, :dependent => :destroy, :order => :position validates :name, :presence => true diff --git a/app/views/call_routes/show.html.haml b/app/views/call_routes/show.html.haml index 998558e..7c695c8 100644 --- a/app/views/call_routes/show.html.haml +++ b/app/views/call_routes/show.html.haml @@ -22,7 +22,7 @@ - else = @call_route.endpoint -= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @call_route } + = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @call_route } .row .span12 diff --git a/app/views/route_elements/_form_core.html.haml b/app/views/route_elements/_form_core.html.haml index d22467e..a9a38a7 100644 --- a/app/views/route_elements/_form_core.html.haml +++ b/app/views/route_elements/_form_core.html.haml @@ -4,5 +4,4 @@ = f.input :pattern, :label => t('route_elements.form.pattern.label'), :hint => conditional_hint('route_elements.form.pattern.hint') = f.input :replacement, :label => t('route_elements.form.replacement.label'), :hint => conditional_hint('route_elements.form.replacement.hint') = f.input :action, :collection => RouteElement::ELEMENT_ACTIONS, :label => t('route_elements.form.action.label'), :hint => conditional_hint('route_elements.form.action.hint'), :include_blank => false - = f.input :position, :label => t('route_elements.form.position.label'), :hint => conditional_hint('route_elements.form.position.hint') = f.input :mandatory, :label => t('route_elements.form.mandatory.label'), :hint => conditional_hint('route_elements.form.mandatory.hint') diff --git a/app/views/route_elements/_index_core.html.haml b/app/views/route_elements/_index_core.html.haml index f68a9ba..a88602f 100644 --- a/app/views/route_elements/_index_core.html.haml +++ b/app/views/route_elements/_index_core.html.haml @@ -1,7 +1,8 @@ %table.table.table-striped %thead %tr - %th + - if route_elements.count > 1 + %th %th= t('route_elements.index.var_in') %th= t('route_elements.index.var_out') %th= t('route_elements.index.pattern') @@ -9,10 +10,13 @@ %th= t('route_elements.index.action') %th= t('route_elements.index.mandatory') - %tbody + %tbody{ :id => "route_elements", :'data-update-url' => sort_call_route_route_elements_url(route_elements.first.call_route)} - for route_element in route_elements - %tr - %td= route_element.position + = content_tag_for :tr, route_element do + - if route_elements.count > 1 + %td + %span.handle + %i.icon-resize-vertical %td= route_element.var_in %td= route_element.var_out %td= route_element.pattern diff --git a/config/routes.rb b/config/routes.rb index 05d09dc..6d7a2ad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,9 @@ Gemeinschaft42c::Application.routes.draw do post :sort get :show_variables } - resources :route_elements + resources :route_elements do + collection { post :sort } + end end resources :gateways do -- cgit v1.2.3 From fb66a5e5a4c5d5f9eac4a5e8de6a286482cb55d5 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 12 Feb 2013 13:41:13 +0100 Subject: Some span.hidden-phone stuff to improve the UI on a phone. --- app/views/route_elements/_index_core.html.haml | 40 ++++++++++++++----- app/views/route_elements/show.html.haml | 54 ++++++++++++++++---------- db/schema.rb | 48 +++++++++++++---------- 3 files changed, 90 insertions(+), 52 deletions(-) diff --git a/app/views/route_elements/_index_core.html.haml b/app/views/route_elements/_index_core.html.haml index a88602f..b7d2bc1 100644 --- a/app/views/route_elements/_index_core.html.haml +++ b/app/views/route_elements/_index_core.html.haml @@ -3,12 +3,22 @@ %tr - if route_elements.count > 1 %th - %th= t('route_elements.index.var_in') - %th= t('route_elements.index.var_out') + %th + %span.hidden-phone + = t('route_elements.index.var_in') + %th + %span.hidden-phone + = t('route_elements.index.var_out') %th= t('route_elements.index.pattern') - %th= t('route_elements.index.replacement') - %th= t('route_elements.index.action') - %th= t('route_elements.index.mandatory') + %th + %span.hidden-phone + = t('route_elements.index.replacement') + %th + %span.hidden-phone + = t('route_elements.index.action') + %th + %span.hidden-phone + = t('route_elements.index.mandatory') %tbody{ :id => "route_elements", :'data-update-url' => sort_call_route_route_elements_url(route_elements.first.call_route)} - for route_element in route_elements @@ -17,10 +27,20 @@ %td %span.handle %i.icon-resize-vertical - %td= route_element.var_in - %td= route_element.var_out + %td + %span.hidden-phone + = route_element.var_in + %td + %span.hidden-phone + = route_element.var_out %td= route_element.pattern - %td= route_element.replacement - %td= route_element.action - %td= route_element.mandatory + %td + %span.hidden-phone + = route_element.replacement + %td + %span.hidden-phone + = route_element.action + %td + %span.hidden-phone + = route_element.mandatory =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => @call_route, :child => route_element} \ No newline at end of file diff --git a/app/views/route_elements/show.html.haml b/app/views/route_elements/show.html.haml index 1d07cbc..937df5e 100644 --- a/app/views/route_elements/show.html.haml +++ b/app/views/route_elements/show.html.haml @@ -1,25 +1,37 @@ - content_for :title, t("route_elements.show.page_title") -%p - %strong= t('route_elements.show.position') + ":" - = @route_element.position -%p - %strong= t('route_elements.show.var_in') + ":" - = @route_element.var_in -%p - %strong= t('route_elements.show.var_out') + ":" - = @route_element.var_out -%p - %strong= t('route_elements.show.pattern') + ":" - = @route_element.pattern -%p - %strong= t('route_elements.show.replacement') + ":" - = @route_element.replacement -%p - %strong= t('route_elements.show.action') + ":" - = @route_element.action -%p - %strong= t('route_elements.show.mandatory') + ":" - = @route_element.mandatory +.row + .span6 + %table.table.table-striped + %tr + %td + %strong= t('route_elements.show.var_in') + ":" + %td + = @route_element.var_in + %tr + %td + %strong= t('route_elements.show.var_out') + ":" + %td + = @route_element.var_out + %tr + %td + %strong= t('route_elements.show.pattern') + ":" + %td + = @route_element.pattern + %tr + %td + %strong= t('route_elements.show.replacement') + ":" + %td + = @route_element.replacement + %tr + %td + %strong= t('route_elements.show.action') + ":" + %td + = @route_element.action + %tr + %td + %strong= t('route_elements.show.mandatory') + ":" + %td + = @route_element.mandatory = render :partial => 'shared/show_edit_destroy_part', :locals => {:parent => @call_route, :child => @route_element } \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 5e51305..fc2b635 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130206144829) do +ActiveRecord::Schema.define(:version => 20130212071000) do create_table "access_authorizations", :force => true do |t| t.string "access_authorizationable_type" @@ -129,21 +129,11 @@ ActiveRecord::Schema.define(:version => 20130206144829) do t.datetime "finished_at" t.string "state" t.string "directory" - t.integer "size_of_the_backup" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "backup_file" end - create_table "backups", :force => true do |t| - t.datetime "start_at" - t.datetime "end_at" - t.string "directory" - t.string "size" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "call_forward_cases", :force => true do |t| t.string "value" t.datetime "created_at", :null => false @@ -656,6 +646,28 @@ ActiveRecord::Schema.define(:version => 20130206144829) do t.string "hostname", :limit => 256 end + create_table "intruders", :force => true do |t| + t.string "list_type" + t.string "key" + t.integer "points" + t.integer "bans" + t.datetime "ban_last" + t.datetime "ban_end" + t.string "contact_ip" + t.integer "contact_port" + t.integer "contact_count" + t.datetime "contact_last" + t.float "contacts_per_second" + t.float "contacts_per_second_max" + t.string "user_agent" + t.string "to_user" + t.string "comment" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "intruders", ["key"], :name => "index_intruders_on_key", :unique => true + create_table "languages", :force => true do |t| t.string "name" t.string "code" @@ -961,15 +973,9 @@ ActiveRecord::Schema.define(:version => 20130206144829) do t.datetime "updated_at", :null => false t.integer "sip_account_id" t.integer "softkey_function_id" - t.integer "call_forward_id" t.string "uuid" - end - - create_table "system_messages", :force => true do |t| - t.integer "user_id" - t.string "content" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "softkeyable_type" + t.integer "softkeyable_id" end create_table "tasks", :id => false, :force => true do |t| -- cgit v1.2.3