1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#!/usr/bin/env ruby
# tb.rb $Revision: 1.9 $
#
# Copyright (c) 2003 Junichiro KITA <kita@kitaj.no-ip.com>
# Distributed under the GPL
#
# derived from sheepman's tb.rb. Thanks to sheepman <sheepman@tcn.zaq.ne.jp>
#
BEGIN { $defout.binmode }
$KCODE = 'n'
begin
if FileTest::symlink?( __FILE__ ) then
org_path = File::dirname( File::readlink( __FILE__ ) )
else
org_path = File::dirname( __FILE__ )
end
$:.unshift org_path.untaint
require 'tdiary'
@cgi = CGI::new
conf = TDiary::Config::new
tdiary = nil
begin
if /POST/i =~ @cgi.request_method and @cgi.valid?( 'url' ) and
! @cgi.referer and
/^Mozilla\// !~ @cgi.user_agent then
tdiary = TDiary::TDiaryTrackBackReceive::new( @cgi, 'day.rhtml', conf )
elsif @cgi.valid?( '__mode') and @cgi.params['__mode'][0] == 'rss'
tdiary = TDiary::TDiaryTrackBackRSS::new( @cgi, nil, conf )
end
rescue TDiary::TDiaryError
end
tdiary = TDiary::TDiaryTrackBackShow::new( @cgi, nil, conf ) unless tdiary
head = {
#'type' => 'application/xml',
'type' => 'text/xml',
'Vary' => 'User-Agent'
}
body = ''
begin
body = tdiary.eval_rhtml
head['charset'] = conf.encoding
head['Content-Length'] = body.size.to_s
head['Pragma'] = 'no-cache'
head['Cache-Control'] = 'no-cache'
print @cgi.header( head )
print body
rescue TDiary::TDiaryTrackBackError
head = {
#'type' => 'application/xml',
'type' => 'text/xml'
}
print @cgi.header( head )
print TDiary::TDiaryTrackBackBase::fail_response($!.message)
rescue TDiary::ForceRedirect
head = {
#'Location' => $!.path
'type' => 'text/html',
}
head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
print @cgi.header( head )
print %Q[
<html>
<head>
<meta http-equiv="refresh" content="0;url=#{$!.path}">
<title>moving...</title>
</head>
<body>Wait or <a href="#{$!.path}">Click here!</a></body>
</html>]
end
rescue Exception
puts "Content-Type: text/plain\n\n"
puts "#$! (#{$!.class})"
puts ""
puts $@.join( "\n" )
end
# vim: ts=3
|