summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/call_route.rb8
-rw-r--r--app/models/route_element.rb15
-rw-r--r--app/views/call_routes/show.html.haml3
-rw-r--r--config/unicorn.rb43
-rw-r--r--db/migrate/20130116203000_set_prerouting_table.rb99
5 files changed, 143 insertions, 25 deletions
diff --git a/app/models/call_route.rb b/app/models/call_route.rb
index de0f68a..f6a3dd3 100644
--- a/app/models/call_route.rb
+++ b/app/models/call_route.rb
@@ -1,4 +1,6 @@
class CallRoute < ActiveRecord::Base
+ ROUTING_TABLES = ['prerouting', 'outbound', 'inbound']
+
attr_accessible :table, :name, :endpoint_type, :endpoint_id, :position
has_many :route_elements, :dependent => :destroy
@@ -6,6 +8,12 @@ class CallRoute < ActiveRecord::Base
validates :name,
:presence => true
+ validates :table,
+ :presence => true,
+ :inclusion => { :in => ROUTING_TABLES }
+
+ acts_as_list :scope => '`table` = \'#{table}\''
+
def to_s
name.to_s
end
diff --git a/app/models/route_element.rb b/app/models/route_element.rb
index 11bb54a..d3302ea 100644
--- a/app/models/route_element.rb
+++ b/app/models/route_element.rb
@@ -1,8 +1,23 @@
class RouteElement < ActiveRecord::Base
+ ELEMENT_ACTIONS = ['match', 'not_match', 'set_route_var', 'set_header']
+
attr_accessible :call_route_id, :var_in, :var_out, :pattern, :replacement, :action, :mandatory, :position
belongs_to :call_route
+ acts_as_list :scope => :call_route
+
+ validates :var_in,
+ :presence => true
+
+ validates :pattern,
+ :presence => true
+
+ validates :action,
+ :presence => true,
+ :inclusion => { :in => ELEMENT_ACTIONS }
+
+
def to_s
"#{var_in} #{var_out}"
end
diff --git a/app/views/call_routes/show.html.haml b/app/views/call_routes/show.html.haml
index c5c7397..8be64e6 100644
--- a/app/views/call_routes/show.html.haml
+++ b/app/views/call_routes/show.html.haml
@@ -12,9 +12,6 @@
%p
%strong= t('call_routes.show.endpoint_id') + ":"
= @call_route.endpoint_id
-%p
- %strong= t('call_routes.show.position') + ":"
- = @call_route.position
= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @call_route }
diff --git a/config/unicorn.rb b/config/unicorn.rb
index d379569..8157562 100644
--- a/config/unicorn.rb
+++ b/config/unicorn.rb
@@ -1,35 +1,34 @@
-worker_processes 2
-working_directory "/opt/GS5/"
+APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
+
+worker_processes 1
+working_directory APP_ROOT
-# This loads the application in the master process before forking
-# worker processes
-# Read more about it here:
-# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true
timeout 30
-# This is where we specify the socket.
-# We will point the upstream Nginx module to this socket later on
-listen "/opt/GS5/tmp/sockets/unicorn.sock", :backlog => 64
+listen APP_ROOT + "/tmp/sockets/unicorn.sock", :backlog => 64
-pid "/opt/GS5/tmp/pids/unicorn.pid"
+pid APP_ROOT + "/tmp/pids/unicorn.pid"
-# Set the path of the log files inside the log folder of the testapp
-stderr_path "/opt/GS5/log/unicorn.stderr.log"
-stdout_path "/opt/GS5/log/unicorn.stdout.log"
+stderr_path APP_ROOT + "/log/unicorn.stderr.log"
+stdout_path APP_ROOT + "/log/unicorn.stdout.log"
before_fork do |server, worker|
-# This option works in together with preload_app true setting
-# What is does is prevent the master process from holding
-# the database connection
- defined?(ActiveRecord::Base) and
- ActiveRecord::Base.connection.disconnect!
+ defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!
+
+ old_pid = Rails.root + '/tmp/pids/unicorn.pid.oldbin'
+ if File.exists?(old_pid) && server.pid != old_pid
+ begin
+ Process.kill("QUIT", File.read(old_pid).to_i)
+ rescue Errno::ENOENT, Errno::ESRCH
+ puts "Old master alerady dead"
+ end
+ end
end
after_fork do |server, worker|
-# Here we are establishing the connection after forking worker
-# processes
- defined?(ActiveRecord::Base) and
- ActiveRecord::Base.establish_connection
+ defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
+ child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
+ system("echo #{Process.pid} > #{child_pid}")
end
diff --git a/db/migrate/20130116203000_set_prerouting_table.rb b/db/migrate/20130116203000_set_prerouting_table.rb
new file mode 100644
index 0000000..86137a0
--- /dev/null
+++ b/db/migrate/20130116203000_set_prerouting_table.rb
@@ -0,0 +1,99 @@
+class SetPreroutingTable < ActiveRecord::Migration
+ def up
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*0%*$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*0%*$', :replacement => 'f-li', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*0%*(%d+)#*$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*0%*(%d+)#*$', :replacement => 'f-li-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*0%*(%d+)%*(%d+)#*$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*0%*(%d+)%*(%d+)#*$', :replacement => 'f-li-%1-%2', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#0#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#0#$', :replacement => 'f-lo', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*5%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*5%*(%d+)#$', :replacement => 'f-acdmtg-0-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*30#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*30#$', :replacement => 'f-clipon', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#30#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#30#$', :replacement => 'f-clipoff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*31#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*31#$', :replacement => 'f-cliroff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#31#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#31#$', :replacement => 'f-cliron', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*31#(%d+)$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*31#(%d+)$', :replacement => 'f-dcliroff-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#31#(%d+)$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#31#(%d+)$', :replacement => 'f-dcliron-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*43#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*43#$', :replacement => 'f-cwaon', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#43#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#43#$', :replacement => 'f-cwaoff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#002#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#002#$', :replacement => 'f-cfoff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^##002#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^##002#$', :replacement => 'f-cfdel', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*21#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*21#$', :replacement => 'f-cfu', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*21%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*21%*(%d+)#$', :replacement => 'f-cfu-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*%*21%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*%*21%*(%d+)#$', :replacement => 'f-cfu-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#21#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#21#$', :replacement => 'f-cfuoff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^##21#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^##21#$', :replacement => 'f-cfudel', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*61#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*61#$', :replacement => 'f-cfn', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*61%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*61%*(%d+)#$', :replacement => 'f-cfn-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*%*61%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*%*61%*(%d+)#$', :replacement => 'f-cfn-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*61%*(%d+)%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*61%*(%d+)%*(%d+)#$', :replacement => 'f-cfn-%1-%2', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*%*61%*(%d+)%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*%*61%*(%d+)%*(%d+)#$', :replacement => 'f-cfn-%1-%2', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#61#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#61#$', :replacement => 'f-cfnoff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^##61#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^##61#$', :replacement => 'f-cfndel', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*62#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*62#$', :replacement => 'f-cfo', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*62%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*62%*(%d+)#$', :replacement => 'f-cfo-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*%*62%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*%*62%*(%d+)#$', :replacement => 'f-cfo-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#62#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#62#$', :replacement => 'f-cfooff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^##62#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^##62#$', :replacement => 'f-cfodel', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*67#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*67#$', :replacement => 'f-cfb', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*67%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*67%*(%d+)#$', :replacement => 'f-cfb-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*%*67%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*%*67%*(%d+)#$', :replacement => 'f-cfb-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^#67#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^#67#$', :replacement => 'f-cfboff', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^##67#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^##67#$', :replacement => 'f-cfbdel', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*66#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*66#$', :replacement => 'f-redial', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*98$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*98$', :replacement => 'f-vmcheck', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*98#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*98#$', :replacement => 'f-vmcheck', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*98%*(%d+)#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*98%*(%d+)#$', :replacement => 'f-vmcheck-%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*1337%*1%*1#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*1337%*1%*1#$', :replacement => 'f-loaon', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'feature code ^%*1337%*1%*0#$', :endpoint_type => 'dialplanfunction').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^%*1337%*1%*0#$', :replacement => 'f-loaoff', :action => 'set_route_var', :mandatory => true)
+
+ CallRoute.create(:table => 'prerouting', :name => 'international prefix', :endpoint_type => 'phonenumber').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^00(%d+)$', :replacement => '+%1', :action => 'set_route_var', :mandatory => true)
+ CallRoute.create(:table => 'prerouting', :name => 'national prefix', :endpoint_type => 'phonenumber').route_elements.
+ create(:var_in => 'destination_number', :var_out => 'destination_number', :pattern => '^0(%d+)$', :replacement => '+49%1', :action => 'set_route_var', :mandatory => true)
+ end
+
+ def down
+ CallRoute.where(:table => "prerouting").destroy_all
+ end
+end