-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathirclog.cgi
executable file
·74 lines (63 loc) · 1.54 KB
/
irclog.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'cgi'
require 'date'
require_relative 'config'
require_relative 'view'
module Irclog
class App
def initialize
cgi = CGI.new
@view = View.new
if !cgi["channel"].empty?
@channel = cgi["channel"]
end
if !cgi["date"].empty?
@date = Date.parse(cgi["date"])
end
if !cgi["keyword"].empty?
@keyword = cgi["keyword"]
end
if !cgi["year"].empty?
@year = cgi["year"]
end
if !cgi["json"].empty?
@json = cgi["json"]
end
end
def run
ans = ""
if @channel && !Config::CHANNEL_LIST.assoc(@channel)
ans << html_http_header
ans << @view.error
puts ans
return
end
if @channel && @keyword && @year
ans << html_http_header
ans << @view.search(@channel, @keyword, @year)
elsif @channel && @date && @json == "true"
ans << json_http_header
ans << @view.json(@channel, @date)
elsif @channel && @date
ans << html_http_header
ans << @view.daylog(@channel, @date, @keyword)
elsif @channel
ans << html_http_header
ans << @view.channellog(@channel)
else
ans << html_http_header
ans << @view.listlog
end
puts ans
end
def html_http_header
return "Content-Type: text/html; charset=utf-8\n\n"
end
def json_http_header
return "Content-Type: application/json; charset=utf-8\n\n"
end
end
end
app = Irclog::App.new
app.run