Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: cgi-lib.rb
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: cgi-lib is deprecated after Ruby 1.8.1; use cgi instead"
[0] Fix | Delete
[1] Fix | Delete
=begin
[2] Fix | Delete
[3] Fix | Delete
= simple CGI support library
[4] Fix | Delete
[5] Fix | Delete
= example
[6] Fix | Delete
[7] Fix | Delete
== get form values
[8] Fix | Delete
[9] Fix | Delete
require "cgi-lib.rb"
[10] Fix | Delete
query = CGI.new
[11] Fix | Delete
query['field'] # <== value of 'field'
[12] Fix | Delete
query.keys # <== array of fields
[13] Fix | Delete
[14] Fix | Delete
and query has Hash class methods
[15] Fix | Delete
[16] Fix | Delete
[17] Fix | Delete
== get cookie values
[18] Fix | Delete
[19] Fix | Delete
require "cgi-lib.rb"
[20] Fix | Delete
query = CGI.new
[21] Fix | Delete
query.cookie['name'] # <== cookie value of 'name'
[22] Fix | Delete
query.cookie.keys # <== all cookie names
[23] Fix | Delete
[24] Fix | Delete
and query.cookie has Hash class methods
[25] Fix | Delete
[26] Fix | Delete
[27] Fix | Delete
== print HTTP header and HTML string to $>
[28] Fix | Delete
[29] Fix | Delete
require "cgi-lib.rb"
[30] Fix | Delete
CGI::print{
[31] Fix | Delete
CGI::tag("HTML"){
[32] Fix | Delete
CGI::tag("HEAD"){ CGI::tag("TITLE"){"TITLE"} } +
[33] Fix | Delete
CGI::tag("BODY"){
[34] Fix | Delete
CGI::tag("FORM", {"ACTION"=>"test.rb", "METHOD"=>"POST"}){
[35] Fix | Delete
CGI::tag("INPUT", {"TYPE"=>"submit", "VALUE"=>"submit"})
[36] Fix | Delete
} +
[37] Fix | Delete
CGI::tag("HR")
[38] Fix | Delete
}
[39] Fix | Delete
}
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
[43] Fix | Delete
== make raw cookie string
[44] Fix | Delete
[45] Fix | Delete
require "cgi-lib.rb"
[46] Fix | Delete
cookie1 = CGI::cookie({'name' => 'name',
[47] Fix | Delete
'value' => 'value',
[48] Fix | Delete
'path' => 'path', # optional
[49] Fix | Delete
'domain' => 'domain', # optional
[50] Fix | Delete
'expires' => Time.now, # optional
[51] Fix | Delete
'secure' => true # optional
[52] Fix | Delete
})
[53] Fix | Delete
[54] Fix | Delete
CGI::print("Content-Type: text/html", cookie1, cookie2){ "string" }
[55] Fix | Delete
[56] Fix | Delete
[57] Fix | Delete
== print HTTP header and string to $>
[58] Fix | Delete
[59] Fix | Delete
require "cgi-lib.rb"
[60] Fix | Delete
CGI::print{ "string" }
[61] Fix | Delete
# == CGI::print("Content-Type: text/html"){ "string" }
[62] Fix | Delete
CGI::print("Content-Type: text/html", cookie1, cookie2){ "string" }
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
=== NPH (no-parse-header) mode
[66] Fix | Delete
[67] Fix | Delete
require "cgi-lib.rb"
[68] Fix | Delete
CGI::print("nph"){ "string" }
[69] Fix | Delete
# == CGI::print("nph", "Content-Type: text/html"){ "string" }
[70] Fix | Delete
CGI::print("nph", "Content-Type: text/html", cookie1, cookie2){ "string" }
[71] Fix | Delete
[72] Fix | Delete
[73] Fix | Delete
== make HTML tag string
[74] Fix | Delete
[75] Fix | Delete
require "cgi-lib.rb"
[76] Fix | Delete
CGI::tag("element", {"attribute_name"=>"attribute_value"}){"content"}
[77] Fix | Delete
[78] Fix | Delete
[79] Fix | Delete
== make HTTP header string
[80] Fix | Delete
[81] Fix | Delete
require "cgi-lib.rb"
[82] Fix | Delete
CGI::header # == CGI::header("Content-Type: text/html")
[83] Fix | Delete
CGI::header("Content-Type: text/html", cookie1, cookie2)
[84] Fix | Delete
[85] Fix | Delete
[86] Fix | Delete
=== NPH (no-parse-header) mode
[87] Fix | Delete
[88] Fix | Delete
CGI::header("nph") # == CGI::header("nph", "Content-Type: text/html")
[89] Fix | Delete
CGI::header("nph", "Content-Type: text/html", cookie1, cookie2)
[90] Fix | Delete
[91] Fix | Delete
[92] Fix | Delete
== escape url encode
[93] Fix | Delete
[94] Fix | Delete
require "cgi-lib.rb"
[95] Fix | Delete
url_encoded_string = CGI::escape("string")
[96] Fix | Delete
[97] Fix | Delete
[98] Fix | Delete
== unescape url encoded
[99] Fix | Delete
[100] Fix | Delete
require "cgi-lib.rb"
[101] Fix | Delete
string = CGI::unescape("url encoded string")
[102] Fix | Delete
[103] Fix | Delete
[104] Fix | Delete
== escape HTML &"<>
[105] Fix | Delete
[106] Fix | Delete
require "cgi-lib.rb"
[107] Fix | Delete
CGI::escapeHTML("string")
[108] Fix | Delete
[109] Fix | Delete
[110] Fix | Delete
=end
[111] Fix | Delete
[112] Fix | Delete
require "delegate"
[113] Fix | Delete
[114] Fix | Delete
class CGI < SimpleDelegator
[115] Fix | Delete
[116] Fix | Delete
CR = "\015"
[117] Fix | Delete
LF = "\012"
[118] Fix | Delete
EOL = CR + LF
[119] Fix | Delete
[120] Fix | Delete
RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
[121] Fix | Delete
RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
[122] Fix | Delete
[123] Fix | Delete
# make rfc1123 date string
[124] Fix | Delete
def CGI::rfc1123_date(time)
[125] Fix | Delete
t = time.clone.gmtime
[126] Fix | Delete
return format("%s, %.2d %s %d %.2d:%.2d:%.2d GMT",
[127] Fix | Delete
RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
[128] Fix | Delete
t.hour, t.min, t.sec)
[129] Fix | Delete
end
[130] Fix | Delete
[131] Fix | Delete
# escape url encode
[132] Fix | Delete
def CGI::escape(str)
[133] Fix | Delete
str.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
[134] Fix | Delete
end
[135] Fix | Delete
[136] Fix | Delete
# unescape url encoded
[137] Fix | Delete
def CGI::unescape(str)
[138] Fix | Delete
str.gsub(/\+/, ' ').gsub(/%([0-9a-fA-F]{2})/){ [$1.hex].pack("c") }
[139] Fix | Delete
end
[140] Fix | Delete
[141] Fix | Delete
# escape HTML
[142] Fix | Delete
def CGI::escapeHTML(str)
[143] Fix | Delete
str.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
# offline mode. read name=value pairs on standard input.
[147] Fix | Delete
def read_from_cmdline
[148] Fix | Delete
require "shellwords.rb"
[149] Fix | Delete
words = Shellwords.shellwords(
[150] Fix | Delete
if not ARGV.empty?
[151] Fix | Delete
ARGV.join(' ')
[152] Fix | Delete
else
[153] Fix | Delete
STDERR.print "(offline mode: enter name=value pairs on standard input)\n" if STDIN.tty?
[154] Fix | Delete
readlines.join(' ').gsub(/\n/, '')
[155] Fix | Delete
end.gsub(/\\=/, '%3D').gsub(/\\&/, '%26'))
[156] Fix | Delete
[157] Fix | Delete
if words.find{|x| x =~ /=/} then words.join('&') else words.join('+') end
[158] Fix | Delete
end
[159] Fix | Delete
[160] Fix | Delete
def initialize(input = $stdin)
[161] Fix | Delete
[162] Fix | Delete
@inputs = {}
[163] Fix | Delete
@cookie = {}
[164] Fix | Delete
[165] Fix | Delete
case ENV['REQUEST_METHOD']
[166] Fix | Delete
when "GET"
[167] Fix | Delete
ENV['QUERY_STRING'] or ""
[168] Fix | Delete
when "POST"
[169] Fix | Delete
input.read(Integer(ENV['CONTENT_LENGTH'])) or ""
[170] Fix | Delete
else
[171] Fix | Delete
read_from_cmdline
[172] Fix | Delete
end.split(/[&;]/).each do |x|
[173] Fix | Delete
key, val = x.split(/=/,2).collect{|x|CGI::unescape(x)}
[174] Fix | Delete
if @inputs.include?(key)
[175] Fix | Delete
@inputs[key] += "\0" + (val or "")
[176] Fix | Delete
else
[177] Fix | Delete
@inputs[key] = (val or "")
[178] Fix | Delete
end
[179] Fix | Delete
end
[180] Fix | Delete
[181] Fix | Delete
super(@inputs)
[182] Fix | Delete
[183] Fix | Delete
if ENV.has_key?('HTTP_COOKIE') or ENV.has_key?('COOKIE')
[184] Fix | Delete
(ENV['HTTP_COOKIE'] or ENV['COOKIE']).split(/; /).each do |x|
[185] Fix | Delete
key, val = x.split(/=/,2)
[186] Fix | Delete
key = CGI::unescape(key)
[187] Fix | Delete
val = val.split(/&/).collect{|x|CGI::unescape(x)}.join("\0")
[188] Fix | Delete
if @cookie.include?(key)
[189] Fix | Delete
@cookie[key] += "\0" + val
[190] Fix | Delete
else
[191] Fix | Delete
@cookie[key] = val
[192] Fix | Delete
end
[193] Fix | Delete
end
[194] Fix | Delete
end
[195] Fix | Delete
end
[196] Fix | Delete
[197] Fix | Delete
attr("inputs")
[198] Fix | Delete
attr("cookie")
[199] Fix | Delete
[200] Fix | Delete
# make HTML tag string
[201] Fix | Delete
def CGI::tag(element, attributes = {})
[202] Fix | Delete
"<" + escapeHTML(element) + attributes.collect{|name, value|
[203] Fix | Delete
" " + escapeHTML(name) + '="' + escapeHTML(value) + '"'
[204] Fix | Delete
}.to_s + ">" +
[205] Fix | Delete
(iterator? ? yield.to_s + "</" + escapeHTML(element) + ">" : "")
[206] Fix | Delete
end
[207] Fix | Delete
[208] Fix | Delete
# make raw cookie string
[209] Fix | Delete
def CGI::cookie(options)
[210] Fix | Delete
"Set-Cookie: " + options['name'] + '=' + escape(options['value']) +
[211] Fix | Delete
(options['domain'] ? '; domain=' + options['domain'] : '') +
[212] Fix | Delete
(options['path'] ? '; path=' + options['path'] : '') +
[213] Fix | Delete
(options['expires'] ? '; expires=' + rfc1123_date(options['expires']) : '') +
[214] Fix | Delete
(options['secure'] ? '; secure' : '')
[215] Fix | Delete
end
[216] Fix | Delete
[217] Fix | Delete
# make HTTP header string
[218] Fix | Delete
def CGI::header(*options)
[219] Fix | Delete
if defined?(MOD_RUBY)
[220] Fix | Delete
options.each{|option|
[221] Fix | Delete
option.sub(/(.*?): (.*)/){
[222] Fix | Delete
Apache::request.headers_out[$1] = $2
[223] Fix | Delete
}
[224] Fix | Delete
}
[225] Fix | Delete
Apache::request.send_http_header
[226] Fix | Delete
''
[227] Fix | Delete
else
[228] Fix | Delete
if options.delete("nph") or (ENV['SERVER_SOFTWARE'] =~ /IIS/)
[229] Fix | Delete
[(ENV['SERVER_PROTOCOL'] or "HTTP/1.0") + " 200 OK",
[230] Fix | Delete
"Date: " + rfc1123_date(Time.now),
[231] Fix | Delete
"Server: " + (ENV['SERVER_SOFTWARE'] or ""),
[232] Fix | Delete
"Connection: close"] +
[233] Fix | Delete
(options.empty? ? ["Content-Type: text/html"] : options)
[234] Fix | Delete
else
[235] Fix | Delete
options.empty? ? ["Content-Type: text/html"] : options
[236] Fix | Delete
end.join(EOL) + EOL + EOL
[237] Fix | Delete
end
[238] Fix | Delete
end
[239] Fix | Delete
[240] Fix | Delete
# print HTTP header and string to $>
[241] Fix | Delete
def CGI::print(*options)
[242] Fix | Delete
$>.print CGI::header(*options) + yield.to_s
[243] Fix | Delete
end
[244] Fix | Delete
[245] Fix | Delete
# print message to $>
[246] Fix | Delete
def CGI::message(message, title = "", header = ["Content-Type: text/html"])
[247] Fix | Delete
if message.kind_of?(Hash)
[248] Fix | Delete
title = message['title']
[249] Fix | Delete
header = message['header']
[250] Fix | Delete
message = message['body']
[251] Fix | Delete
end
[252] Fix | Delete
CGI::print(*header){
[253] Fix | Delete
CGI::tag("HTML"){
[254] Fix | Delete
CGI::tag("HEAD"){ CGI.tag("TITLE"){ title } } +
[255] Fix | Delete
CGI::tag("BODY"){ message }
[256] Fix | Delete
}
[257] Fix | Delete
}
[258] Fix | Delete
true
[259] Fix | Delete
end
[260] Fix | Delete
[261] Fix | Delete
# print error message to $> and exit
[262] Fix | Delete
def CGI::error
[263] Fix | Delete
CGI::message({'title'=>'ERROR', 'body'=>
[264] Fix | Delete
CGI::tag("PRE"){
[265] Fix | Delete
"ERROR: " + CGI::tag("STRONG"){ escapeHTML($!.to_s) } + "\n" + escapeHTML($@.join("\n"))
[266] Fix | Delete
}
[267] Fix | Delete
})
[268] Fix | Delete
exit
[269] Fix | Delete
end
[270] Fix | Delete
end
[271] Fix | Delete
[272] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function