File: hiki.cgi

package info (click to toggle)
hiki 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,812 kB
  • ctags: 2,033
  • sloc: ruby: 14,572; lisp: 926; sh: 19; makefile: 16
file content (62 lines) | stat: -rwxr-xr-x 1,764 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env ruby
# $Id: hiki.cgi,v 1.36 2008-01-24 15:42:11 znz Exp $
# Copyright (C) 2002-2004 TAKEUCHI Hitoshi <hitoshi@namaraii.com>

BEGIN { $stdout.binmode }
begin
  # FIXME encoding can be different (eg. iso-8859-1 in
  # hikiconf.rb.sample.en).
  Encoding.default_external = 'utf-8'
rescue NameError
  $KCODE = 'e'
end

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