-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhiki.cgi
executable file
·59 lines (52 loc) · 1.68 KB
/
hiki.cgi
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
#!/usr/bin/env ruby
# $Id: hiki.cgi,v 1.36 2008-01-24 15:42:11 znz Exp $
# Copyright (C) 2002-2004 TAKEUCHI Hitoshi <[email protected]>
BEGIN { $stdout.binmode }
# FIXME encoding can be different (eg. iso-8859-1 in
# hikiconf.rb.sample.en).
Encoding.default_external = 'utf-8'
begin
if FileTest::symlink?( __FILE__ )
org_path = File.dirname( File.expand_path( File.readlink( __FILE__ ) ) )
else
org_path = File.dirname( File.expand_path( __FILE__ ) )
end
$:.unshift( org_path.untaint, "#{org_path.untaint}/hiki" )
$:.delete(".") if File.writable?(".")
require 'hiki/config'
conf = Hiki::Config.new
request = Hiki::Request.new(ENV)
if ENV['CONTENT_TYPE'] =~ %r!\Atext/xml!i and ENV['REQUEST_METHOD'] =~ /\APOST\z/i
require 'hiki/xmlrpc'
server = Hiki::XMLRPCServer.new(conf, request)
server.serve
else
# FIXME encoding can be different (eg. iso-8859-1 in
# hikiconf.rb.sample.en).
#cgi = CGI.new(:accept_charset=>"euc-jp")
response = nil
db = conf.database
db.open_db {
cmd = Hiki::Command.new(request, db, conf)
response = cmd.dispatch
}
print response.header
print response.body
end
rescue Exception => err
if request
print request.cgi.header( 'status' => '500 Internal Server Error', 'type' => 'text/html' )
else
print "Status: 500 Internal Server Error\n"
print "Content-Type: text/html\n\n"
end
require 'cgi'
puts '<html><head><title>Hiki Error</title></head><body>'
puts '<h1>Hiki Error</h1>'
puts '<pre>'
puts CGI.escapeHTML( "#{err} (#{err.class})\n" )
puts CGI.escapeHTML( err.backtrace.join( "\n" ) )
puts '</pre>'
puts "<div>#{' ' * 500}</div>"
puts '</body></html>'
end