Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 86 lines (82 sloc) 2.313 kb
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 82 83 84 85 86
#!/usr/bin/env ruby
# index.rb $Revision: 1.11 $
$KCODE= 'e'
BEGIN { $defout.binmode }

begin
if FileTest::symlink?( __FILE__ ) then
org_path = File::dirname( File::readlink( __FILE__ ) )
else
org_path = File::dirname( __FILE__ )
end
$:.unshift org_path
require 'tdiary'

@cgi = CGI::new
conf = TDiary::Config::new
tdiary = nil
status = nil
if %r[/\d{6,8}\.html?$] =~ ENV['REDIRECT_URL'] and not @cgi.valid?( 'date' ) then
@cgi.params['date'] = [ENV['REDIRECT_URL'].sub( /.*\/(\d+)\.html$/, '\1' )]
status = '200 OK'
end

begin
if @cgi.valid?( 'comment' ) then
tdiary = TDiary::TDiaryComment::new( @cgi, "day.rhtml", conf )
elsif @cgi.valid?( 'date' )
date, = @cgi['date']
if /^\d{8}$/ =~ date then
tdiary = TDiary::TDiaryDay::new( @cgi, "day.rhtml", conf )
elsif /^\d{6}$/ =~ date then
tdiary = TDiary::TDiaryMonth::new( @cgi, "month.rhtml", conf )
end
else
tdiary = TDiary::TDiaryLatest::new( @cgi, "latest.rhtml", conf )
end
rescue TDiary::PermissionError
raise
rescue TDiary::TDiaryError
end
tdiary = TDiary::TDiaryLatest::new( @cgi, "latest.rhtml", conf ) if not tdiary

begin
head = {
'type' => 'text/html',
'Last-Modified' => CGI::rfc1123_date( tdiary.last_modified ),
'Vary' => 'User-Agent'
}
head['status'] = status if status
body = ''
if @cgi.mobile_agent? then
body = tdiary.eval_rhtml( 'i.' ).to_sjis
head['charset'] = conf.charset( true )
head['Content-Length'] = body.size.to_s
else
body = tdiary.eval_rhtml
head['charset'] = conf.charset
head['Content-Length'] = body.size.to_s
head['Pragma'] = 'no-cache'
head['Cache-Control'] = 'no-cache'
end
head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
print @cgi.header( head )
print body if /HEAD/i !~ @cgi.request_method
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
print "Content-Type: text/plain\n\n"
puts "#$! (#{$!.type})"
puts ""
puts $@.join( "\n" )
end
Something went wrong with that request. Please try again.