From patricrt at gmail.com Fri May 8 04:11:43 2009 From: patricrt at gmail.com (Patric) Date: Fri, 08 May 2009 10:11:43 +0200 Subject: [Backgroundrb-devel] Backgroundrb in shared hosting environment Message-ID: <4A03E93F.5000102@gmail.com> Hi all, I am running a linux shared hosting environment, and one of my users would like to make use of an app (Coupra Express) which uses backgroundrb to process certain tasks. This requires that I run backgroundrb as a service so that it is always available to the client. What I am trying to assess is if there are potential security risks in running this in a shared hosting environment. I assume that this service would be available to other users on the same server as well - if so are there any security issues that I should be aware of there? I read on http://www.ruby-forum.com/topic/69440 that backgroundrb can be configured to only accept connections from localhost (I believe this was the default behaviour)? Any information would be very much appreciated. Unfortunately I am completely unfamiliar with ruby, rake or backgroundrb and am attempting to pick up as much as possible as I research this topic, so if I have misspoken please feel free to correct me. Many thanks Patric From wchrisjohnson at gmail.com Tue May 12 19:23:01 2009 From: wchrisjohnson at gmail.com (Chris Johnson) Date: Tue, 12 May 2009 19:23:01 -0400 Subject: [Backgroundrb-devel] Problem passing multiple arguments as hash to enq_method Message-ID: Hi, I'm having trouble calling the enq_* method on my worker and passing in multiple arguments via hash. I CAN pass in an an array of arguments and it works; but the hash syntax does not seem to work. My worker is loaded automatically when the BDRB process is started. This works: WORKER: ----------------------------------------------------------------------------- class ReportingWorker < BackgrounDRb::MetaWorker set_worker_name :reporting_worker set_no_auto_load false def create(args=nil) logger.info "ReportingWorker started." end def create_export(args) work_order_id = args[0] user_id = args[1] .... # do stuff end # create_export end SCRIPT/CONSOLE MiddleMan.worker(:reporting_worker). create_export(:arg => [2887,1], :job_key => 2887, :scheduled_at => Time.now) ----------------------------------------------------------------------------- This does not work: WORKER: ----------------------------------------------------------------------------- class ReportingWorker < BackgrounDRb::MetaWorker set_worker_name :reporting_worker set_no_auto_load false def create(args=nil) logger.info "ReportingWorker started." end def create_export(args) work_order_id = args["work_order_id"] user_id = args["user_id"] .... # do stuff end # create_export end SCRIPT/CONSOLE MiddleMan.worker(:reporting_worker). create_export(:arg => [{:work_order_id => 2887, :user_id => 1}], :job_key => 2887, :scheduled_at => Time.now) MiddleMan.worker(:reporting_worker). create_export(:arg => {:work_order_id => 2887, :user_id => 1}, :job_key => 2887, :scheduled_at => Time.now) (neither works) ----------------------------------------------------------------------------- I should also note that I'm currently using the async_* technique to kick off these report jobs (similar to the FIRST example noted above) and that works OK; I WOULD like to be able to track jobs via the queue though; hence my desire to get this enq_* stuff working consistently. Thanks in advance for any help! Chris From wchrisjohnson at gmail.com Tue May 12 23:50:15 2009 From: wchrisjohnson at gmail.com (Chris Johnson) Date: Tue, 12 May 2009 23:50:15 -0400 Subject: [Backgroundrb-devel] How do you mark a queued job as finished? ( ????? "persistent_job.finish!" ?????) Message-ID: Hi, As I understand from reading the list, when you queue a task to be executed, you need to issue some variation of the above command to mark the task as completed. Given that I am queuing the task from my rails app, and the task runs within my worker, I assume I need to mark the job as finished in the method of that same worker class that does the work. Could someone give me a better example of how (syntax-wise) to issue that command properly? For example, here's my worker: class ReportingWorker < BackgrounDRb::MetaWorker set_worker_name :reporting_worker set_no_auto_load false def create(args=nil) logger.info "ReportingWorker started." end def create_export(args) work_order_id = args[0] user_id = args[1] # DO STUFF HERE # FINISHED! # HOW DO I MARK IT AS FINISHED IN THE QUEUE ????? persistent_job.finish! end # create_export end So, how do I mark the job as finished? ??? self.finish! ??? Chris From adamsubscribe at googlemail.com Thu May 14 05:19:44 2009 From: adamsubscribe at googlemail.com (Adam Akhtar) Date: Thu, 14 May 2009 18:19:44 +0900 Subject: [Backgroundrb-devel] Application Design Message-ID: <2d303f170905140219v564bfbd0jc538c0dcbecbeb85@mail.gmail.com> Im new to background processes in general and threads for that matter. Ive been googling away like mad trying to find more info but I believe a process is a slot for a program to run and for each process there are threads available for concurrent processing. Am I right on that? Anyway im making a simple app which takes a users search term and scrapes several sites rss feeds for relevant results. The scrape can take upto 10seconds. I want to make this a background process so I can update the user with the scrapes status("currently scraping site x") and present results as they are scraped. Im a little confused as to how to the overall setup of workers to do this? Do I create one worker only for the whole site which all my users will share at a given time and there requests with be threaded by it? OR do I create a worker for each user as they request a search? Do creations of a worker need to be destroyed when not in use? If anyone could provide some tips that would be great. (i know what code i need to put in the worker by for the scraping part - dont worry im not asking you to code my app ;-) just the direction i should be taking. Many thanks Adam From d.meyers at lancaster.ac.uk Thu May 14 11:20:08 2009 From: d.meyers at lancaster.ac.uk (Meyers, Dan) Date: Thu, 14 May 2009 16:20:08 +0100 Subject: [Backgroundrb-devel] Scheduling async jobs to workers, and checking if workers are currently running a job Message-ID: <9FFF610D5DF89A4CAC9CB450C7565663028F045E@exchange-be4.lancs.local> I'm trying to schedule jobs from our own database scheduling system that we hook BackgrounDRb into. I assign a job to a worker asynchronously using MiddleMan.worker(worker).async_wrapper(:job_key => jobkey, :arg => task.id) This gets called whenever I have a job scheduled to start according to my db. The behaviour in an older version of BackgrounDRb was that if that worker was already running a job then the new job didn't get started or queued, it just disappeared. This was exactly what I wanted, as I would periodically check my db and attempt to start all workers scheduled to do so using this method. Any that were still processing the previous run of the job just didn't run. For example I have a job scheduled to run every 5 seconds on a specific worker written just for it, for an indefinite period of time. There should only ever be one copy of it running. Normally it takes 3 or 4 seconds to run, so this is fine. Sometimes it gets a sudden backlog of data to deal with, and takes 30 seconds to process it all. Using the old version of BackgrounDRb after the 30 second job was up it would start a new job on the next 5 second 'tick' of our scheduler, but all the jobs it had tried to start while the worker was already handling a job would have disappeared. The behaviour using the new version seems to be to queue up the next run of the job on a call to async_*. The result now becomes that any time I have a backlog I get the one 30 second job run that actually processes the data, then immediately it finishes I get 6 or so other runs of the job which have no data to process, so execute in almost no time but fill my logging table with 'started...stopped' messages. These jobs were queued up to run, 1 per 5 second tick, while the 30 second job was still executing. I hoped I could use MiddleMan.worker(worker).worker_info[:status] To check whether the job was running or not. This *seemed* to work on the jobs that I started manually (rather than starting on BackgrounDRb load) by putting 'set_no_auto_load true' at the top of the worker file and then calling MiddleMan.new_worker(:worker => worker, :worker_key => key) to create the worker before giving it work to do. However this seems to sometimes get out of sync. It will always return status :stopped if a worker or job doesn't exist, but I had a worker running and outputting data, and worker_info was still claiming it was stopped. I have also had worker_info continue to claim that a worker is running after it has finished processing data and disappeared from the process list. Is there any way to be sure the data returned from worker_info is current and valid? Secondly, worker_info seems to *always* return :running if the worker is started on BackgrounDRb load, instead of being spawned using new_worker by my own code. This is one of my problems in the example of the indefinite task above. I cannot use worker_info to see whether the worker is currently running a job (even if worker_info reliably returned correct information), and not call async_wrapper if it is, because worker_info *always* says the task is running. Is there any way that I can find out if a worker started on BackgrounDRb load is currently executing a job or not? -- Dan Meyers Network Specialist, Lancaster University E-Mail: d.meyers at lancaster.ac.uk From Cary.Fitzhugh at itt.com Thu May 14 14:04:27 2009 From: Cary.Fitzhugh at itt.com (Fitzhugh, Cary) Date: Thu, 14 May 2009 14:04:27 -0400 Subject: [Backgroundrb-devel] Scheduling async jobs to workers, and checking if workers are currently running a job In-Reply-To: <9FFF610D5DF89A4CAC9CB450C7565663028F045E@exchange-be4.lancs.local> References: <9FFF610D5DF89A4CAC9CB450C7565663028F045E@exchange-be4.lancs.local> Message-ID: <306BB208804183479F3A1E013148D21C24395912C5@IIWCBO-EMB1.iiw.de.ittind.com> Don't know if this helps, but I would assume that, based on your description, that a worker knows where to get the data, without an argument coming in. If that's the case, then you might try add_periodic_timer http://backgroundrb.rubyforge.org/scheduling/ I'm not sure, but it might do what you want out of the box. If not, then you could make a thread pool of size 1, and in your method, check if the thread pool has a threadavailable, then you could defer or not to the thread_pool. Something like: pool_size 1 def create(args=nil) add_periodic_timer(5) {my_method} end def my_method(arg) if @thread_pool.work_queue.size == 0 thread_pool.defer(:do_my_method, arg) end end def do_my_method(arg) ........ end Though - the scheduling time is held in backgroundrb then, and not the main application. So you could dump the periodic_timer and just call my_method async. But testing the work_queue size is probably what you're looking for. I don't know about the status returning invalid and all that though. Thanks, Cary -----Original Message----- From: backgroundrb-devel-bounces at rubyforge.org [mailto:backgroundrb-devel-bounces at rubyforge.org] On Behalf Of Meyers, Dan Sent: Thursday, May 14, 2009 11:20 AM To: backgroundrb-devel at rubyforge.org Subject: [Backgroundrb-devel] Scheduling async jobs to workers, and checking if workers are currently running a job I'm trying to schedule jobs from our own database scheduling system that we hook BackgrounDRb into. I assign a job to a worker asynchronously using MiddleMan.worker(worker).async_wrapper(:job_key => jobkey, :arg => task.id) This gets called whenever I have a job scheduled to start according to my db. The behaviour in an older version of BackgrounDRb was that if that worker was already running a job then the new job didn't get started or queued, it just disappeared. This was exactly what I wanted, as I would periodically check my db and attempt to start all workers scheduled to do so using this method. Any that were still processing the previous run of the job just didn't run. For example I have a job scheduled to run every 5 seconds on a specific worker written just for it, for an indefinite period of time. There should only ever be one copy of it running. Normally it takes 3 or 4 seconds to run, so this is fine. Sometimes it gets a sudden backlog of data to deal with, and takes 30 seconds to process it all. Using the old version of BackgrounDRb after the 30 second job was up it would start a new job on the next 5 second 'tick' of our scheduler, but all the jobs it had tried to start while the worker was already handling a job would have disappeared. The behaviour using the new version seems to be to queue up the next run of the job on a call to async_*. The result now becomes that any time I have a backlog I get the one 30 second job run that actually processes the data, then immediately it finishes I get 6 or so other runs of the job which have no data to process, so execute in almost no time but fill my logging table with 'started...stopped' messages. These jobs were queued up to run, 1 per 5 second tick, while the 30 second job was still executing. I hoped I could use MiddleMan.worker(worker).worker_info[:status] To check whether the job was running or not. This *seemed* to work on the jobs that I started manually (rather than starting on BackgrounDRb load) by putting 'set_no_auto_load true' at the top of the worker file and then calling MiddleMan.new_worker(:worker => worker, :worker_key => key) to create the worker before giving it work to do. However this seems to sometimes get out of sync. It will always return status :stopped if a worker or job doesn't exist, but I had a worker running and outputting data, and worker_info was still claiming it was stopped. I have also had worker_info continue to claim that a worker is running after it has finished processing data and disappeared from the process list. Is there any way to be sure the data returned from worker_info is current and valid? Secondly, worker_info seems to *always* return :running if the worker is started on BackgrounDRb load, instead of being spawned using new_worker by my own code. This is one of my problems in the example of the indefinite task above. I cannot use worker_info to see whether the worker is currently running a job (even if worker_info reliably returned correct information), and not call async_wrapper if it is, because worker_info *always* says the task is running. Is there any way that I can find out if a worker started on BackgrounDRb load is currently executing a job or not? -- Dan Meyers Network Specialist, Lancaster University E-Mail: d.meyers at lancaster.ac.uk _______________________________________________ Backgroundrb-devel mailing list Backgroundrb-devel at rubyforge.org http://rubyforge.org/mailman/listinfo/backgroundrb-devel This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail. From gael.sechaud at dev-ruby.zefiris.org Mon May 25 12:10:35 2009 From: gael.sechaud at dev-ruby.zefiris.org (=?ISO-8859-1?Q?Ga=EBl?= SECHAUD) Date: Mon, 25 May 2009 18:10:35 +0200 Subject: [Backgroundrb-devel] Backgroundrb in shared hosting environment In-Reply-To: <4A03E93F.5000102@gmail.com> Message-ID: <1243267835.22552.33.camel@Archer> Hi, > I am running a linux shared hosting environment, and one of my users > would like to make use of an app (Coupra Express) which uses > backgroundrb to process certain tasks. This requires that I run > backgroundrb as a service so that it is always available to the client. I recently had the same problem: at first I thought of setting iptables rules, but it comes to be a pain, as I needed to set one rule by user running on my environment. An other solution was to patch the kernel with GRSec, but I'm not fond of this solution. So I come with a third solution: patching backgroundrb with a modification of mine (you will find the patch and the revision to which its applied), adding a password support. It's quite a temporary solution, as I haven't figured an other solution. > What I am trying to assess is if there are potential security risks in > running this in a shared hosting environment. I assume that this service > would be available to other users on the same server as well - if so are > there any security issues that I should be aware of there? I read on > http://www.ruby-forum.com/topic/69440 that backgroundrb can be > configured to only accept connections from localhost (I believe this was > the default behaviour)? You can configure backgroundrb to only accept connections from localhost, but I think it won't solve your problem if you have multiples clients running on your host: even if backgroundrb is binded to localhost, other client who have solution on your host can still access other instance of backgroundrb, by tweaking their backgroundrb.yml (which I consider to be a security issue). Regards. -- SECHAUD Ga?l ----- How To ----- To add password support, just patch backgroundrb and add the following entry in your backgrounrb config (commonly RAILS_ROOT/config/backgroundrb.yml) :backgroundrb: [..] :password: Your_Password ----- revision info ----- svn info Path: . URL: http://svn.devjavu.com/backgroundrb/trunk Repository Root: http://svn.devjavu.com/backgroundrb Repository UUID: 69d54aea-511f-0410-a924-81c4482807e4 Revision: 331 Node Kind: directory Schedule: normal Last Changed Author: gethemant at gmail.com Last Changed Rev: 330 Last Changed Date: 2008-10-14 12:51:23 +0200 (Tue, 14 Oct 2008) ----- patch ----- diff -crB backgroundrb/lib/backgroundrb/bdrb_connection.rb backgroundrb-patched/lib/backgroundrb/bdrb_connection.rb *** backgroundrb/lib/backgroundrb/bdrb_connection.rb 2009-05-25 17:18:35.000000000 +0200 --- backgroundrb-patched/lib/backgroundrb/bdrb_connection.rb 2009-05-25 16:48:48.000000000 +0200 *************** *** 8,13 **** --- 8,14 ---- @server_port = port @cluster_conn = cluster_conn @connection_status = true + @password = BDRB_CONFIG[:backgroundrb][:password].nil? ? false : BDRB_CONFIG[:backgroundrb][:password] end *************** *** 66,71 **** --- 67,73 ---- end def dump_object data + data[:password] = @password establish_connection raise BackgrounDRb::BdrbConnError.new("Error while connecting to the backgroundrb server #{server_info}") unless @connection_status diff -crB backgroundrb/server/lib/master_worker.rb backgroundrb-patched/server/lib/master_worker.rb *** backgroundrb/server/lib/master_worker.rb 2009-05-25 17:18:35.000000000 +0200 --- backgroundrb-patched/server/lib/master_worker.rb 2009-05-25 16:50:53.000000000 +0200 *************** *** 25,31 **** end class MasterWorker ! attr_accessor :debug_logger include BackgrounDRb::BdrbServerHelper # receives requests from rails and based on request type invoke appropriate method def receive_data p_data --- 25,31 ---- end class MasterWorker ! attr_accessor :debug_logger,:password include BackgrounDRb::BdrbServerHelper # receives requests from rails and based on request type invoke appropriate method def receive_data p_data *************** *** 33,38 **** --- 33,45 ---- begin t_data = load_data b_data if t_data + # check password + if @password && t_data[:password] != @password + debug_logger.info("Invalid password : #{t_data.inspect}") + error_password(t_data) + return + end + case t_data[:type] # async method invocation when :async_invoke: async_method_invoke(t_data) *************** *** 55,60 **** --- 62,76 ---- end end + # Send password require info to the user + def error_password(t_data) + worker_name_key = gen_worker_key(t_data[:worker],t_data[:worker_key]) + worker_instance = reactor.live_workers[worker_name_key] + info_response = { :error => "Password required / Wrong password" } + worker_instance ? (info_response[:status] = :running) : (info_response[:status] = :stopped) + send_object(info_response) + end + # Send worker info to the user def pass_worker_info(t_data) worker_name_key = gen_worker_key(t_data[:worker],t_data[:worker_key]) *************** *** 163,168 **** --- 179,185 ---- # called whenever a new connection is made.Initializes binary data parser def post_init @tokenizer = Packet::BinParser.new + @password = BDRB_CONFIG[:backgroundrb][:password].nil? ? false : BDRB_CONFIG[:backgroundrb][:password] end def connection_completed; end end From gael.sechaud at dev-ruby.zefiris.org Thu May 28 11:16:22 2009 From: gael.sechaud at dev-ruby.zefiris.org (=?ISO-8859-1?Q?Ga=EBl?= SECHAUD) Date: Thu, 28 May 2009 17:16:22 +0200 Subject: [Backgroundrb-devel] Backgroundrb in shared hosting environment In-Reply-To: <1243267835.22552.33.camel@Archer> Message-ID: <1243523782.4506.26.camel@Archer> Hi, Considering the problem of backgroundrb in shared hosting environment, I've come with another temporary patch, which allow encrypted communication between the MiddleMan and the server. I still haven't found a better way to secure backgroundrb in shared hosting environment, but at least, it's better than nothing. Regards. ----- revision info ----- svn info Path: . URL: http://svn.devjavu.com/backgroundrb/trunk Repository Root: http://svn.devjavu.com/backgroundrb Repository UUID: 69d54aea-511f-0410-a924-81c4482807e4 Revision: 331 Node Kind: directory Schedule: normal Last Changed Author: gethemant at gmail.com Last Changed Rev: 330 Last Changed Date: 2008-10-14 12:51:23 +0200 (Tue, 14 Oct 2008) ----- patch ----- diff -crB backgroundrb/lib/backgroundrb/bdrb_connection.rb backgroundrb-patched/lib/backgroundrb/bdrb_connection.rb *** backgroundrb/lib/backgroundrb/bdrb_connection.rb 2009-05-25 17:18:35.000000000 +0200 --- backgroundrb-patched/lib/backgroundrb/bdrb_connection.rb 2009-05-28 16:38:44.000000000 +0200 *************** *** 8,13 **** --- 8,15 ---- @server_port = port @cluster_conn = cluster_conn @connection_status = true + @password = BDRB_CONFIG[:backgroundrb][:password].nil? ? false : BDRB_CONFIG[:backgroundrb][:password] + @key = Digest::MD5.hexdigest(File.read(File.join(RAILS_ROOT, "config", "backgroundrb.yml"))) end *************** *** 65,74 **** end end def dump_object data establish_connection raise BackgrounDRb::BdrbConnError.new("Error while connecting to the backgroundrb server #{server_info}") unless @connection_status ! object_dump = Marshal.dump(data) dump_length = object_dump.length.to_s length_str = dump_length.rjust(9,'0') --- 67,121 ---- end end + def decrypt_data(t_data) + if @key && t_data + data = Base64.decode64(t_data) + res = OpenSSL::Cipher::Cipher.new("aes-256-cbc") + res.decrypt + res.key = Digest::SHA2.hexdigest(@key) + decrypt_data = res.update(data) + decrypt_data << res.final + decrypt_data = Base64.decode64(decrypt_data) + tdata = decrypt_data.split("\b") + + t_data = [] + tdata.each do |t| + data = {} + t.split("\a").each do |e| + key_data = e.split("\r") + if key_data[1] + data[key_data[0].to_sym] = key_data[1].to_sym + else + data[key_data[0].to_sym] = "" + end + end + t_data << data + end + end + return t_data + end + def encrypt_data(data) + if @key + tdata = "" + data.each do |key, d| + tdata << "#{key}\r#{d}\a" + end + tdata = Base64.encode64(tdata) + res = OpenSSL::Cipher::Cipher.new("aes-256-cbc") + res.encrypt + res.key = Digest::SHA2.hexdigest(@key) + encrypt_data = res.update(tdata) + encrypt_data << res.final + data = Base64.encode64(encrypt_data) + end + return data + end + def dump_object data + data[:password] = @password establish_connection raise BackgrounDRb::BdrbConnError.new("Error while connecting to the backgroundrb server #{server_info}") unless @connection_status ! data = encrypt_data(data) object_dump = Marshal.dump(data) dump_length = object_dump.length.to_s length_str = dump_length.rjust(9,'0') *************** *** 100,106 **** bdrb_response = nil @mutex.synchronize { bdrb_response = read_from_bdrb() } close_connection ! bdrb_response end def all_worker_info --- 147,153 ---- bdrb_response = nil @mutex.synchronize { bdrb_response = read_from_bdrb() } close_connection ! decrypt_data(bdrb_response) end def all_worker_info *************** *** 110,116 **** bdrb_response = nil @mutex.synchronize { bdrb_response = read_from_bdrb() } close_connection ! bdrb_response end def delete_worker p_data --- 157,163 ---- bdrb_response = nil @mutex.synchronize { bdrb_response = read_from_bdrb() } close_connection ! decrypt_data(bdrb_response) end def delete_worker p_data *************** *** 148,153 **** --- 195,201 ---- bdrb_response = nil @mutex.synchronize { bdrb_response = read_from_bdrb() } close_connection + bdrb_response = decrypt_data(bdrb_response) bdrb_response ? bdrb_response[:data] : nil end end *************** *** 170,175 **** --- 218,224 ---- bdrb_response = nil @mutex.synchronize { bdrb_response = read_from_bdrb(nil) } close_connection + bdrb_response = decrypt_data(bdrb_response) bdrb_response ? bdrb_response[:data] : nil end end diff -crB backgroundrb/server/lib/master_worker.rb backgroundrb-patched/server/lib/master_worker.rb *** backgroundrb/server/lib/master_worker.rb 2009-05-25 17:18:35.000000000 +0200 --- backgroundrb-patched/server/lib/master_worker.rb 2009-05-28 16:38:39.000000000 +0200 *************** *** 25,38 **** end class MasterWorker ! attr_accessor :debug_logger include BackgrounDRb::BdrbServerHelper # receives requests from rails and based on request type invoke appropriate method def receive_data p_data @tokenizer.extract(p_data) do |b_data| begin t_data = load_data b_data if t_data case t_data[:type] # async method invocation when :async_invoke: async_method_invoke(t_data) --- 25,94 ---- end class MasterWorker ! attr_accessor :debug_logger,:password, :key include BackgrounDRb::BdrbServerHelper + + def decrypt_data(t_data) + if @key && t_data + data = Base64.decode64(t_data) + res = OpenSSL::Cipher::Cipher.new("aes-256-cbc") + res.decrypt + res.key = Digest::SHA2.hexdigest(@key) + decrypt_data = res.update(data) + decrypt_data << res.final + decrypt_data = Base64.decode64(decrypt_data) + t_data = {} + tdata = decrypt_data.split("\a") + tdata.each do |e| + key_data = e.split("\r") + t_data[key_data[0].to_sym] = key_data[1].to_sym + end + end + return t_data + end + def encrypt_data(data) + if @key && data + if data.is_a?(Array) + tdata = [] + data.each do |e| + sdata = "" + e.each do |key, d| + sdata << "#{key}\r#{d}\a" + end + tdata << sdata + end + tdata = tdata.join("\b") + else + tdata = "" + data.each do |key, d| + tdata << "#{key}\r#{d}\a" + end + end + tdata = Base64.encode64(tdata) + res = OpenSSL::Cipher::Cipher.new("aes-256-cbc") + res.encrypt + res.key = Digest::SHA2.hexdigest(@key) + encrypt_data = res.update(tdata) + encrypt_data << res.final + data = Base64.encode64(encrypt_data) + end + return data + end + # receives requests from rails and based on request type invoke appropriate method def receive_data p_data @tokenizer.extract(p_data) do |b_data| begin t_data = load_data b_data if t_data + t_data = decrypt_data(t_data) + # check password + if @password && t_data[:password].to_s != @password + debug_logger.info("Invalid password : #{t_data.inspect}") + error_password(t_data) + return + end + case t_data[:type] # async method invocation when :async_invoke: async_method_invoke(t_data) *************** *** 55,67 **** end end # Send worker info to the user def pass_worker_info(t_data) worker_name_key = gen_worker_key(t_data[:worker],t_data[:worker_key]) worker_instance = reactor.live_workers[worker_name_key] info_response = { :worker => t_data[:worker],:worker_key => t_data[:worker_key]} worker_instance ? (info_response[:status] = :running) : (info_response[:status] = :stopped) ! send_object(info_response) end # collect all worker info in an array and send to the user --- 111,132 ---- end end + # Send password require info to the user + def error_password(t_data) + worker_name_key = gen_worker_key(t_data[:worker],t_data[:worker_key]) + worker_instance = reactor.live_workers[worker_name_key] + info_response = { :error => "Password required / Wrong password" } + worker_instance ? (info_response[:status] = :running) : (info_response[:status] = :stopped) + send_object(encrypt_data(info_response)) + end + # Send worker info to the user def pass_worker_info(t_data) worker_name_key = gen_worker_key(t_data[:worker],t_data[:worker_key]) worker_instance = reactor.live_workers[worker_name_key] info_response = { :worker => t_data[:worker],:worker_key => t_data[:worker_key]} worker_instance ? (info_response[:status] = :running) : (info_response[:status] = :stopped) ! send_object(encrypt_data(info_response)) end # collect all worker info in an array and send to the user *************** *** 71,77 **** worker_key = (value.worker_key.to_s).gsub(/#{value.worker_name}_?/,"") info_response << { :worker => value.worker_name,:worker_key => worker_key,:status => :running } end ! send_object(info_response) end # Delete the worker. Sends TERM signal to the worker process and removes --- 136,142 ---- worker_key = (value.worker_key.to_s).gsub(/#{value.worker_name}_?/,"") info_response << { :worker => value.worker_name,:worker_key => worker_key,:status => :running } end ! send_object(encrypt_data(info_response)) end # Delete the worker. Sends TERM signal to the worker process and removes *************** *** 155,161 **** # Receieve responses from workers and dispatch them back to the client def worker_receive p_data ! send_object(p_data) end def unbind; end --- 220,226 ---- # Receieve responses from workers and dispatch them back to the client def worker_receive p_data ! send_object(encrypt_data(p_data)) end def unbind; end *************** *** 163,168 **** --- 228,235 ---- # called whenever a new connection is made.Initializes binary data parser def post_init @tokenizer = Packet::BinParser.new + @password = BDRB_CONFIG[:backgroundrb][:password].nil? ? false : BDRB_CONFIG[:backgroundrb][:password] + @key = Digest::MD5.hexdigest(File.read(File.join(RAILS_ROOT, "config", "backgroundrb.yml"))) end def connection_completed; end end -- SECHAUD Ga?l -------------- next part -------------- A non-text attachment was scrubbed... Name: backgroundrb.patch Type: text/x-patch Size: 10506 bytes Desc: not available URL: