|
|
Introduction
Taskr4rails makes it possible for the Taskr scheduler to execute arbitrary code on a running Rails server. Taskr4rails (included with Taskr as of version 0.2.0) consists of two parts: a Rails plugin that must be installed on the target Rails application, and a Taskr Action selectable when the action is being created.
Usage
To execute scheduled actions in your Rails application, first install the Taskr4rails plugin:
script/plugin install http://ruby-taskr.googlecode.com/svn/trunk/taskr4rails
The above will install the plugin and add an entry to your Rails application's routes.rb file.
Now in your environment.rb file set some arbitrary authentication token. This is essentially the "password" that the Taskr server will have to use to connect to your Rails application in order to execute the remote code:
TASKR4RAILS_AUTH = "topsecret!123!!"
Then schedule a Taskr4rails action in your Taskr server. For example, use the following parameters to print "Hello World" in the console of a Rails application running on https://rails.example.foo:
{
:url => "https://rails.example.foo/taskr4rails",
:ruby_code => "puts 'Hello World'",
:auth => "topsecret!123!!"
}Note that cd #{RAILS_ROOT}; will be automatically prepended to your shell command.
API
| Parameter | Description |
| url | The URL where the taskr4rails controller responds. Normally, when the taskr4rails plugin is installed in your Rails application, an entry will be automatically created in your routes.rb file making the controller available at http://yourapp.foo/taskr4rails. You can of course change this, but be sure to adjust the url parameter to match. |
| auth | This is basically a password. It must match whatever you defined for the TASKR4RAILS_AUTH constant in your Rails application's environment.rb. |
| ruby_code | The given Ruby code will be executed on the remote Rails server, within the server's running environment. |
Security Concerns
For obvious security reasons, it is highly recommended that your Rails server runs on a secure SSL connection. Otherwise your auth token is transmitted over the clear, opening a gaping security hole in your server. You should also select a very long and very hard to guess auth token and change it as often as possible.
For additional security, it is possible to define a TASKR4RAILS_ALLOWED_HOSTS constant. This should be an array listing the IP addresses of the remote Taskr servers allowed to execute actions on this Rails application.
For example:
TASKR4RAILS_ALLOWED_HOSTS = ['127.0.0.1', '192.168.1.5']
You can also use regular expressions:
TASKR4RAILS_ALLOWED_HOSTS = ['127.0.0.1', /^192.168.[1-255].[1-255]$/]
The host must be an IP address. Hostnames are not supported.
Note that if you're running your Rails application behind an SSL reverse proxy (i.e. Pound, Apache), the remote address from the Rails application's point of view will always be the address of the proxy rather than of the Taskr server.
Sign in to add a comment
