#!/usr/local/bin/ruby ################################################# # # Echos back redirected HTTP requests as YAML, suitable for use with the Tap::Net::Submit # task. All HTTP parameters and headers are echoed back directly, except for the # '__original_action' parameter which is used in conjuction with the 'Referer' header to # reconstruct the original url of the request. The '__original_action' parameter is not echoed. # # For example: # __original_action Referer echoed url # http://www.example.com?key=value (any) http://www.example.com?key=value # /page http://www.example.com http://www.example.com/page # # Simply drop this script into a cgi directory, and send it a redirected request. See the # RedirectHTTP Firefox extension for a simple way of redirecting requests to this script. # # Developer: Simon Chiang, Biomolecular Structure Program # Homepage: http://tap.rubyforge.org # Licence: MIT-STYLE # # Copyright (c) 2008, Regents of the University of Colorado # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons # to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or # substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # ################################################# require 'rubygems' require 'cgi' require 'yaml' require 'net/http' require 'tap/http/helpers' # included to sort the hash keys class Hash def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.map( taguri, to_yaml_style ) do |map| sorted_keys = keys sorted_keys = begin sorted_keys.sort rescue sorted_keys.sort_by {|k| k.to_s} rescue sorted_keys end sorted_keys.each do |k| map.add( k, fetch(k) ) end end end end end cgi = CGI.new("html3") begin # # gather configs # config = {} Tap::Http::Helpers.parse_cgi_request(cgi).each_pair do |key, value| config[key.to_s] = value end original_action = config['params'].delete("__original_action").to_s referer = config['headers']['Referer'].to_s config['url'] = Tap::Http::Helpers.determine_url(original_action, referer) config['headers']['Host'] = URI.parse(config['url']).host # # format output # help = cgi.a(Tap::Http::Helpers::HELP_URL) { "help" } how_to_get_cookies = cgi.a(Tap::Http::Helpers::COOKIES_HELP_URL) { "how to get cookies" } cgi.out('text/plain') do %Q{# Copy and paste into a configuration file. Multiple configs # can be added to a single file to perform batch submission. # # If you need cookies, see #{how_to_get_cookies} or the #{help}. - #{config.to_yaml[5..-1].gsub(/\n/, "\n ")} } end rescue cgi.out("text/plain") do "Error: #{$!.message}\n" + $!.backtrace.join("\n") end end