egalite 0.0.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +19 -0
- data/lib/egalite/version.rb +1 -1
- data/lib/egalite.rb +11 -2
- data/test/test_auth.rb +1 -2
- data/test/test_blank.rb +2 -3
- data/test/test_errorconsole.rb +5 -5
- data/test/test_keitai.rb +2 -2
- data/test/test_m17n.rb +1 -3
- data/test/test_template.rb +11 -0
- metadata +4 -87
- data/auth/basic.rb +0 -32
- data/blank.rb +0 -53
- data/egalite.rb +0 -742
- data/errorconsole.rb +0 -77
- data/helper.rb +0 -251
- data/keitai/keitai.rb +0 -107
- data/keitai/ketai.rb +0 -11
- data/keitai/rack/ketai/carrier/abstract.rb +0 -131
- data/keitai/rack/ketai/carrier/au.rb +0 -78
- data/keitai/rack/ketai/carrier/docomo.rb +0 -80
- data/keitai/rack/ketai/carrier/emoji/ausjisstrtoemojiid.rb +0 -1391
- data/keitai/rack/ketai/carrier/emoji/docomosjisstrtoemojiid.rb +0 -759
- data/keitai/rack/ketai/carrier/emoji/emojidata.rb +0 -836
- data/keitai/rack/ketai/carrier/emoji/softbankutf8strtoemojiid.rb +0 -1119
- data/keitai/rack/ketai/carrier/emoji/softbankwebcodetoutf8str.rb +0 -499
- data/keitai/rack/ketai/carrier/iphone.rb +0 -8
- data/keitai/rack/ketai/carrier/softbank.rb +0 -82
- data/keitai/rack/ketai/carrier.rb +0 -17
- data/keitai/rack/ketai/middleware.rb +0 -24
- data/m17n.rb +0 -193
- data/rack/auth/abstract/handler.rb +0 -37
- data/rack/auth/abstract/request.rb +0 -37
- data/rack/auth/basic.rb +0 -58
- data/rack/auth/digest/md5.rb +0 -124
- data/rack/auth/digest/nonce.rb +0 -51
- data/rack/auth/digest/params.rb +0 -55
- data/rack/auth/digest/request.rb +0 -40
- data/rack/builder.rb +0 -80
- data/rack/cascade.rb +0 -41
- data/rack/chunked.rb +0 -49
- data/rack/commonlogger.rb +0 -49
- data/rack/conditionalget.rb +0 -47
- data/rack/config.rb +0 -15
- data/rack/content_length.rb +0 -29
- data/rack/content_type.rb +0 -23
- data/rack/deflater.rb +0 -96
- data/rack/directory.rb +0 -157
- data/rack/etag.rb +0 -32
- data/rack/file.rb +0 -92
- data/rack/handler/cgi.rb +0 -62
- data/rack/handler/evented_mongrel.rb +0 -8
- data/rack/handler/fastcgi.rb +0 -89
- data/rack/handler/lsws.rb +0 -63
- data/rack/handler/mongrel.rb +0 -90
- data/rack/handler/scgi.rb +0 -59
- data/rack/handler/swiftiplied_mongrel.rb +0 -8
- data/rack/handler/thin.rb +0 -18
- data/rack/handler/webrick.rb +0 -73
- data/rack/handler.rb +0 -88
- data/rack/head.rb +0 -19
- data/rack/lint.rb +0 -567
- data/rack/lobster.rb +0 -65
- data/rack/lock.rb +0 -16
- data/rack/logger.rb +0 -20
- data/rack/methodoverride.rb +0 -27
- data/rack/mime.rb +0 -208
- data/rack/mock.rb +0 -190
- data/rack/nulllogger.rb +0 -18
- data/rack/recursive.rb +0 -61
- data/rack/reloader.rb +0 -109
- data/rack/request.rb +0 -273
- data/rack/response.rb +0 -150
- data/rack/rewindable_input.rb +0 -103
- data/rack/runtime.rb +0 -27
- data/rack/sendfile.rb +0 -144
- data/rack/server.rb +0 -271
- data/rack/session/abstract/id.rb +0 -140
- data/rack/session/cookie.rb +0 -90
- data/rack/session/memcache.rb +0 -119
- data/rack/session/pool.rb +0 -100
- data/rack/showexceptions.rb +0 -349
- data/rack/showstatus.rb +0 -106
- data/rack/static.rb +0 -38
- data/rack/urlmap.rb +0 -55
- data/rack/utils.rb +0 -662
- data/rack.rb +0 -81
- data/route.rb +0 -231
- data/sendmail.rb +0 -222
- data/sequel_helper.rb +0 -20
- data/session.rb +0 -132
- data/stringify_hash.rb +0 -63
- data/support.rb +0 -35
- data/template.rb +0 -287
data/errorconsole.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
|
2
|
-
class EgaliteErrorController < Egalite::Controller
|
3
|
-
def self.password=(pass)
|
4
|
-
@@password=pass
|
5
|
-
end
|
6
|
-
def self.database=(db)
|
7
|
-
@@database=db
|
8
|
-
end
|
9
|
-
def before_filter
|
10
|
-
return false unless @@password
|
11
|
-
Egalite::Auth::Basic.authorize(req, 'EgaliteError') { |username,password|
|
12
|
-
username == 'admin' and password == @@password
|
13
|
-
}
|
14
|
-
end
|
15
|
-
def get
|
16
|
-
hb = Egalite::HTMLTagBuilder
|
17
|
-
raw("<html><body>" +
|
18
|
-
hb.ol([ hb.a('latest','�ŐV�G���[�ꗗ'),
|
19
|
-
hb.a('frequent','���p�x�G���[�ꗗ'),
|
20
|
-
hb.a('security','�Z�L�����e�B�G���[�ꗗ'),
|
21
|
-
"<form action='detail'>�G���[�ԍ�: <input type='text' name='id'><input type='submit'></form>",
|
22
|
-
]) + "</body></html>")
|
23
|
-
end
|
24
|
-
def display(recs)
|
25
|
-
hb = Egalite::HTMLTagBuilder
|
26
|
-
raw("<body><html>" +
|
27
|
-
table_by_array(
|
28
|
-
['��ʔԍ�(�ڍ�)', '������', '���e', 'URL', '�폜'],
|
29
|
-
recs.map { |rec|
|
30
|
-
[hb.a(url_for(:action => :group, :id => rec[:md5]),rec[:md5]),
|
31
|
-
rec[:count],
|
32
|
-
rec[:text][0..50],
|
33
|
-
rec[:url][0..50],
|
34
|
-
hb.a(url_for(:action => :delete, :id => rec[:md5]),'�폜'),
|
35
|
-
]
|
36
|
-
}
|
37
|
-
) + "</body></html>")
|
38
|
-
end
|
39
|
-
def latest(lim)
|
40
|
-
lim ||= 100
|
41
|
-
display(@@database.fetch("SELECT md5, text, url, count(*) as count FROM logs WHERE checked_at is null AND severity != 'security' GROUP BY md5, text, url ORDER BY max(created_at) DESC LIMIT ?",lim.to_i))
|
42
|
-
end
|
43
|
-
def frequent(lim)
|
44
|
-
lim ||= 100
|
45
|
-
display(@@database.fetch("SELECT md5, text, url, count(*) as count FROM logs WHERE checked_at is null AND severity != 'security' GROUP BY md5, text, url ORDER BY count(*) DESC LIMIT ?",lim.to_i))
|
46
|
-
end
|
47
|
-
def security(lim)
|
48
|
-
lim ||= 100
|
49
|
-
display(@@database.fetch("SELECT md5, text, url, count(*) as count FROM logs WHERE checked_at is null AND severity == 'security' GROUP BY md5, text, url ORDER BY count(*) DESC LIMIT ?",lim.to_i))
|
50
|
-
end
|
51
|
-
def group(md5)
|
52
|
-
rec = @@database[:logs].filter(:md5 => md5).first
|
53
|
-
raw("<html><body>"+Egalite::HTMLTagBuilder.ul([
|
54
|
-
rec[:md5],
|
55
|
-
rec[:url],
|
56
|
-
rec[:text],
|
57
|
-
]) +"</body></html>")
|
58
|
-
end
|
59
|
-
def delete(md5)
|
60
|
-
@@database[:logs].filter(:md5 => md5).update(:checked_at => Time.now)
|
61
|
-
redirect :action => nil
|
62
|
-
end
|
63
|
-
def detail(id)
|
64
|
-
rec = @@database[:logs].filter(:id => id.to_i).first
|
65
|
-
return "no record found." unless rec
|
66
|
-
raw("<html><body>"+Egalite::HTMLTagBuilder.ul([
|
67
|
-
rec[:id],
|
68
|
-
rec[:severity],
|
69
|
-
rec[:created_at],
|
70
|
-
rec[:md5],
|
71
|
-
rec[:ipaddress],
|
72
|
-
rec[:url],
|
73
|
-
rec[:text],
|
74
|
-
]) +"</body></html>")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
data/helper.rb
DELETED
@@ -1,251 +0,0 @@
|
|
1
|
-
|
2
|
-
module Egalite
|
3
|
-
|
4
|
-
module HTMLTagBuilder
|
5
|
-
def escape_html(s)
|
6
|
-
s.is_a?(NonEscapeString) ? s : NonEscapeString.new(Rack::Utils.escape_html(s))
|
7
|
-
end
|
8
|
-
def _tag(name , soc, attributes)
|
9
|
-
close = soc == :close ? '/' : ''
|
10
|
-
solo = soc == :solo ? '/' : ''
|
11
|
-
|
12
|
-
atr = if attributes and not attributes.empty?
|
13
|
-
s = attributes.map { |k,v| "#{escape_html(k)}='#{escape_html(v)}'" }.join(' ')
|
14
|
-
" #{s}"
|
15
|
-
else
|
16
|
-
""
|
17
|
-
end
|
18
|
-
NonEscapeString.new("<#{close}#{escape_html(name)}#{atr}#{solo}>")
|
19
|
-
end
|
20
|
-
def tag_solo(name, attributes = {})
|
21
|
-
_tag(name, :solo, attributes)
|
22
|
-
end
|
23
|
-
def tag_open(name, attributes = {})
|
24
|
-
_tag(name, :open, attributes)
|
25
|
-
end
|
26
|
-
def tag_close(name, attributes = {})
|
27
|
-
_tag(name, :close, attributes)
|
28
|
-
end
|
29
|
-
class <<self
|
30
|
-
include Egalite::HTMLTagBuilder
|
31
|
-
def tag(tag, s, attributes = {})
|
32
|
-
tag_open(tag, attributes) + escape_html(s) + tag_close(tag, {})
|
33
|
-
end
|
34
|
-
%w[br hr].each { |t|
|
35
|
-
define_method(t) { tag_solo(t) }
|
36
|
-
}
|
37
|
-
%w[h1 h2 h3 h4 b i p html body].each { |t|
|
38
|
-
define_method(t) { |s|
|
39
|
-
tag(t, s)
|
40
|
-
}
|
41
|
-
}
|
42
|
-
def a(url, s)
|
43
|
-
tag('a', s, :href=>url)
|
44
|
-
end
|
45
|
-
def li(array)
|
46
|
-
array.map{ |s| "<li>#{escape_html(s)}</li>" }.join("\n")
|
47
|
-
end
|
48
|
-
def ol(array)
|
49
|
-
"<ol>#{li(array)}</ol>"
|
50
|
-
end
|
51
|
-
def ul(array)
|
52
|
-
"<ul>#{li(array)}</ul>"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class TableHelper
|
58
|
-
private
|
59
|
-
def self.opt(opts)
|
60
|
-
opts.map { |k,v| " #{escape_html(k)}='#{escape_html(v)}'" }.join
|
61
|
-
end
|
62
|
-
def self.escape_html(s)
|
63
|
-
s.is_a?(NonEscapeString) ? s : Rack::Utils.escape_html(s)
|
64
|
-
end
|
65
|
-
def self._table(header, content, table_opts)
|
66
|
-
head = ""
|
67
|
-
if header
|
68
|
-
head = header.map {|s| "<th>#{escape_html(s)}</th>" }.join
|
69
|
-
head = " <tr>#{head}</tr>\n"
|
70
|
-
end
|
71
|
-
body = content.map { |line| " <tr>#{yield(line)}</tr>\n" }
|
72
|
-
NonEscapeString.new("<table#{opt(table_opts)}>\n#{head}#{body}</table>")
|
73
|
-
end
|
74
|
-
public
|
75
|
-
def self.table_by_hash(keys, header, content, table_opts = {})
|
76
|
-
unless keys.size == header.size
|
77
|
-
raise ArgumentError, "key and header count mismatch"
|
78
|
-
end
|
79
|
-
|
80
|
-
_table(header, content, table_opts) { |line|
|
81
|
-
keys.map { |key| "<td>#{escape_html(line[key])}</td>"}.join
|
82
|
-
}
|
83
|
-
end
|
84
|
-
def self.table_by_array(header, content, table_opts = {})
|
85
|
-
_table(header, content, table_opts) { |line|
|
86
|
-
line.map { |s| "<td>#{escape_html(s)}</td>" }.join
|
87
|
-
}
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
class FormHelper
|
92
|
-
include HTMLTagBuilder
|
93
|
-
|
94
|
-
private
|
95
|
-
def expand_name(s)
|
96
|
-
s = "#{@param_name}[#{s}]" if @param_name
|
97
|
-
escape_html(s)
|
98
|
-
end
|
99
|
-
def raw(s)
|
100
|
-
NonEscapeString.new(s)
|
101
|
-
end
|
102
|
-
|
103
|
-
public # export just for testing
|
104
|
-
|
105
|
-
def opt(opts)
|
106
|
-
opts.map { |k,v|
|
107
|
-
next "" if [:default,:checked,:selected, :nil].member?(k)
|
108
|
-
" #{escape_html(k)}='#{escape_html(v)}'"
|
109
|
-
}.join
|
110
|
-
end
|
111
|
-
def opt_as_hash(opts)
|
112
|
-
o = opts.dup
|
113
|
-
o.each_key { |k|
|
114
|
-
o.delete(k) if [:default,:checked,:selected, :nil].member?(k)
|
115
|
-
}
|
116
|
-
o
|
117
|
-
end
|
118
|
-
|
119
|
-
public
|
120
|
-
|
121
|
-
def initialize(data = {}, param_name = nil, opts = {})
|
122
|
-
@data = lambda { |k|
|
123
|
-
if data.respond_to?(k)
|
124
|
-
data.send(k)
|
125
|
-
elsif data.respond_to?(:[])
|
126
|
-
data[k]
|
127
|
-
end
|
128
|
-
}
|
129
|
-
|
130
|
-
@param_name = param_name
|
131
|
-
@form_opts = opts
|
132
|
-
end
|
133
|
-
def form(method, url=nil)
|
134
|
-
attrs = opt_as_hash(@form_opts)
|
135
|
-
attrs[:method] = method.to_s.upcase
|
136
|
-
attrs[:action] = url if url
|
137
|
-
tag_open(:form,attrs)
|
138
|
-
end
|
139
|
-
def close
|
140
|
-
tag_close(:form,nil)
|
141
|
-
end
|
142
|
-
def _text(value, name, opts)
|
143
|
-
attrs = opt_as_hash(opts)
|
144
|
-
attrs[:value] = value if value
|
145
|
-
attrs[:size] ||= 30
|
146
|
-
attrs[:type] = 'text'
|
147
|
-
attrs[:name] = expand_name(name)
|
148
|
-
tag_solo(:input, attrs)
|
149
|
-
end
|
150
|
-
def text(name, opts = {})
|
151
|
-
_text(@data[name] || opts[:default], name, opts)
|
152
|
-
end
|
153
|
-
def timestamp_text(name, opts = {})
|
154
|
-
# todo: enable locale
|
155
|
-
# todo: could unify to text()
|
156
|
-
value = @data[name] || opts[:default]
|
157
|
-
value = value.strftime('%Y-%m-%d %H:%M:%S')
|
158
|
-
_text(value,name,opts)
|
159
|
-
end
|
160
|
-
def password(name, opts = {})
|
161
|
-
value = @data[name] || opts[:default]
|
162
|
-
attrs = opt_as_hash(opts)
|
163
|
-
attrs[:value] = value if value
|
164
|
-
attrs[:type] = "password"
|
165
|
-
attrs[:name] = expand_name(name)
|
166
|
-
tag_solo(:input,attrs)
|
167
|
-
end
|
168
|
-
def hidden(name, opts = {})
|
169
|
-
value = @data[name] || opts[:default]
|
170
|
-
attrs = opt_as_hash(opts)
|
171
|
-
attrs[:value] = value if value
|
172
|
-
attrs[:type] = "hidden"
|
173
|
-
attrs[:name] = expand_name(name)
|
174
|
-
tag_solo(:input,attrs)
|
175
|
-
end
|
176
|
-
def checkbox(name, value="true", opts = {})
|
177
|
-
checked = (@data[name] || opts[:default] || opts[:checked])
|
178
|
-
checked = false if @data[name] == false
|
179
|
-
|
180
|
-
attr_cb = opt_as_hash(opts)
|
181
|
-
attr_cb[:type] = 'checkbox'
|
182
|
-
attr_cb[:name] = expand_name(name)
|
183
|
-
attr_cb[:value] = value
|
184
|
-
attr_cb[:checked] = "checked" if checked
|
185
|
-
|
186
|
-
ucv = opts[:uncheckedvalue] || 'false'
|
187
|
-
attr_h = {:type => 'hidden', :name => expand_name(name), :value => ucv}
|
188
|
-
hidden = opts[:nohidden] ? '' : tag_solo(:input, attr_h)
|
189
|
-
|
190
|
-
raw "#{hidden}#{tag_solo(:input, attr_cb)}"
|
191
|
-
end
|
192
|
-
def radio(name, choice, opts = {})
|
193
|
-
selected = (@data[name] == choice)
|
194
|
-
selected = (opts[:default] == choice) || opts[:selected] if @data[name] == nil
|
195
|
-
|
196
|
-
attrs = opt_as_hash(opts)
|
197
|
-
attrs[:selected] = 'selected' if selected
|
198
|
-
attrs[:name] = expand_name(name)
|
199
|
-
attrs[:value] = choice
|
200
|
-
attrs[:type] = 'radio'
|
201
|
-
|
202
|
-
tag_solo(:input, attrs)
|
203
|
-
end
|
204
|
-
def textarea(name, opts = {})
|
205
|
-
value = escape_html(@data[name] || opts[:default])
|
206
|
-
raw "<textarea name='#{expand_name(name)}'#{opt(opts)}>#{value}</textarea>"
|
207
|
-
end
|
208
|
-
def file(name, opts = {})
|
209
|
-
attrs = opt_as_hash(opts)
|
210
|
-
attrs[:name] = expand_name(name)
|
211
|
-
attrs[:type] = 'file'
|
212
|
-
tag_solo(:input, attrs)
|
213
|
-
end
|
214
|
-
def submit(value = nil, name = nil, opts = {})
|
215
|
-
attrs = opt_as_hash(opts)
|
216
|
-
attrs[:name] = expand_name(name) if name
|
217
|
-
attrs[:value] = value if value
|
218
|
-
attrs[:type] = 'submit'
|
219
|
-
tag_solo(:input, attrs)
|
220
|
-
end
|
221
|
-
def image
|
222
|
-
end
|
223
|
-
def select_by_array(name, options, opts = {})
|
224
|
-
optionstr = options.map {|o|
|
225
|
-
flag = o[0] == @data[name]
|
226
|
-
a = {:value => o[0]}
|
227
|
-
a[:selected] = 'selected' if flag
|
228
|
-
"#{tag_open(:option, a)}#{escape_html(o[1])}</option>"
|
229
|
-
}.join('')
|
230
|
-
|
231
|
-
raw "<select name='#{expand_name(name)}'#{opt(opts)}>#{optionstr}</select>"
|
232
|
-
end
|
233
|
-
def select_by_association(name, options, optname, opts = {})
|
234
|
-
idname = (opts[:idname] || "id").to_sym
|
235
|
-
optionstr = options.map {|o|
|
236
|
-
flag = o[idname] == @data[name]
|
237
|
-
a = {:value => o[idname]}
|
238
|
-
a[:selected] = 'selected' if flag
|
239
|
-
"#{tag_open(:option, a)}#{escape_html(o[optname])}</option>"
|
240
|
-
}.join('')
|
241
|
-
|
242
|
-
if opts[:nil]
|
243
|
-
selected = (@data[name] == nil) ? "selected='selected'" : ''
|
244
|
-
optionstr = "<option value='' #{selected}>#{escape_html(opts[:nil])}</option>" + optionstr
|
245
|
-
end
|
246
|
-
|
247
|
-
raw "<select name='#{expand_name(name)}'#{opt(opts)}>#{optionstr}</select>"
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
end
|
data/keitai/keitai.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
require 'ketai'
|
5
|
-
require 'uri'
|
6
|
-
require 'openssl'
|
7
|
-
require 'base64'
|
8
|
-
|
9
|
-
module Egalite
|
10
|
-
module Keitai
|
11
|
-
class URLSession
|
12
|
-
def self.encrypt(s,key)
|
13
|
-
cipher = OpenSSL::Cipher.new("bf-cbc")
|
14
|
-
cipher.pkcs5_keyivgen(key)
|
15
|
-
cipher.encrypt
|
16
|
-
e = cipher.update(s) + cipher.final
|
17
|
-
Base64.encode64(e).tr('+/=','_.-').gsub!("\n","")
|
18
|
-
end
|
19
|
-
def self.decrypt(s,key)
|
20
|
-
cipher = OpenSSL::Cipher.new("bf-cbc")
|
21
|
-
cipher.pkcs5_keyivgen(key)
|
22
|
-
cipher.decrypt
|
23
|
-
e = s.tr('_.-','+/=')
|
24
|
-
e = Base64.decode64(e)
|
25
|
-
d = cipher.update(e) + cipher.final
|
26
|
-
d
|
27
|
-
end
|
28
|
-
end
|
29
|
-
module Session
|
30
|
-
def load_keitai_session(sessionid)
|
31
|
-
session.load_from_param(sessionid)
|
32
|
-
end
|
33
|
-
def modify_url_for_keitai(url,sstr)
|
34
|
-
uri = URI.parse(URI.escape(URI.unescape(url)))
|
35
|
-
return url if not uri.scheme.blank? and uri.scheme !~ /(http|https)/
|
36
|
-
if uri.host and uri.host !~ my_host
|
37
|
-
crypted_url = URLSession.encrypt(url,redirector_crypt_key)
|
38
|
-
File.join(redirector_url,crypted_url)
|
39
|
-
else
|
40
|
-
array = uri.query.to_s.split('&')
|
41
|
-
qhash = array.inject({}) { |a,s| (k,v) = s.split('=',2); a[k] = v; a }
|
42
|
-
qhash['sessionid']=sstr
|
43
|
-
uri.query = qhash.map {|k,v| "#{k}=#{v}"}.join('&')
|
44
|
-
uri.to_s
|
45
|
-
end
|
46
|
-
end
|
47
|
-
def replace_url_for_keitai(body,sstr)
|
48
|
-
body.gsub!(/<a.+?href=(?:'(.+?)'|"(.+?)").+?>/) { |s|
|
49
|
-
url = ($1 || $2)
|
50
|
-
url_after = modify_url_for_keitai(url,sstr)
|
51
|
-
s.sub(url,url_after)
|
52
|
-
}
|
53
|
-
body.gsub!(/(<form.+?>)/) { |s|
|
54
|
-
s + "\n<input type='hidden' name='sessionid' value='#{sstr}'/>\n"
|
55
|
-
}
|
56
|
-
end
|
57
|
-
def redirector_url
|
58
|
-
"/redirector"
|
59
|
-
end
|
60
|
-
def do_after_filter_for_keitai(response,session)
|
61
|
-
code = response[0]
|
62
|
-
headers = response[1]
|
63
|
-
body = response[2].join
|
64
|
-
|
65
|
-
if session and session.sstr
|
66
|
-
sstr = session.sstr
|
67
|
-
if headers['Location']
|
68
|
-
headers['Location'] = modify_url_for_keitai(headers['Location'],sstr)
|
69
|
-
end
|
70
|
-
replace_url_for_keitai(body,sstr)
|
71
|
-
response[2] = [body]
|
72
|
-
end
|
73
|
-
response
|
74
|
-
end
|
75
|
-
end
|
76
|
-
class Controller < Egalite::Controller
|
77
|
-
include Session
|
78
|
-
|
79
|
-
def before_filter
|
80
|
-
load_keitai_session(params[:sessionid])
|
81
|
-
super
|
82
|
-
end
|
83
|
-
def redirector_crypt_key
|
84
|
-
"Example1"
|
85
|
-
end
|
86
|
-
def my_host
|
87
|
-
/^www.example.com$/
|
88
|
-
end
|
89
|
-
def after_filter(response)
|
90
|
-
do_after_filter_for_keitai(response,session)
|
91
|
-
super(response)
|
92
|
-
response
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
class Redirector < Egalite::Controller
|
97
|
-
def get(crypted_url)
|
98
|
-
url = URLSession.decrypt(crypted_url, redirector_crypt_key)
|
99
|
-
"<html><body>外部サイトへ移動しようとしています。以下のリンクをクリックしてください。<br/><br/><a href='#{URI.escape(url)}'>リンク</a></body></html>"
|
100
|
-
end
|
101
|
-
def redirector_crypt_key
|
102
|
-
"Example1"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
data/keitai/ketai.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'tempfile'
|
3
|
-
require 'singleton'
|
4
|
-
require 'nkf'
|
5
|
-
require 'rack/request'
|
6
|
-
|
7
|
-
module Rack::Ketai::Carrier
|
8
|
-
class Abstract
|
9
|
-
|
10
|
-
class << self
|
11
|
-
@@filter_table = { }
|
12
|
-
def filters=(obj)
|
13
|
-
@@filter_table[self] = obj.is_a?(Array) ? obj : [obj]
|
14
|
-
end
|
15
|
-
|
16
|
-
def filters
|
17
|
-
@@filter_table[self] ||= []
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(env)
|
22
|
-
@env = env.clone
|
23
|
-
end
|
24
|
-
|
25
|
-
USER_AGENT_REGEXP = nil
|
26
|
-
|
27
|
-
def filters
|
28
|
-
self.class.filters
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def inbound_filter
|
33
|
-
end
|
34
|
-
|
35
|
-
def outbound_filter
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class Rack::Ketai::Carrier::Abstract
|
42
|
-
class Filter
|
43
|
-
include Singleton
|
44
|
-
|
45
|
-
def inbound(env)
|
46
|
-
env
|
47
|
-
end
|
48
|
-
|
49
|
-
def outbound(status, headers, body)
|
50
|
-
[status, headers, body]
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
def full_apply(*argv, &proc)
|
55
|
-
argv.each do |obj|
|
56
|
-
deep_apply(obj, &proc)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def deep_apply(obj, &proc)
|
61
|
-
case obj
|
62
|
-
when Hash
|
63
|
-
obj.each_pair do |key, value|
|
64
|
-
obj[key] = deep_apply(value, &proc)
|
65
|
-
end
|
66
|
-
obj
|
67
|
-
when Array
|
68
|
-
obj.collect!{ |value| deep_apply(value, &proc)}
|
69
|
-
when NilClass, TrueClass, FalseClass, Tempfile, StringIO
|
70
|
-
obj
|
71
|
-
else
|
72
|
-
proc.call(obj)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
class SjisFilter < Filter
|
80
|
-
|
81
|
-
def inbound(env)
|
82
|
-
request = Rack::Request.new(env)
|
83
|
-
|
84
|
-
# 最低でも1回呼んでないと query_string, form_hash等が未設定
|
85
|
-
request.params
|
86
|
-
|
87
|
-
# 同一オブジェクトが両方に入ってたりして二重にかかることがあるので
|
88
|
-
converted_objects = []
|
89
|
-
converter = lambda { |value|
|
90
|
-
unless converted_objects.include?(value)
|
91
|
-
value = NKF.nkf('-m0 -x -Sw', value)
|
92
|
-
converted_objects << value
|
93
|
-
end
|
94
|
-
value
|
95
|
-
}
|
96
|
-
|
97
|
-
full_apply(request.env["rack.request.query_hash"],
|
98
|
-
request.env["rack.request.form_hash"],
|
99
|
-
&converter)
|
100
|
-
|
101
|
-
request.env
|
102
|
-
end
|
103
|
-
|
104
|
-
def outbound(status, headers, body)
|
105
|
-
if body.is_a?(Array)
|
106
|
-
body = body.collect do |str|
|
107
|
-
NKF.nkf('-m0 -x -Ws', str)
|
108
|
-
end
|
109
|
-
else
|
110
|
-
body = NKF.nkf('-m0 -x -Ws', body)
|
111
|
-
end
|
112
|
-
|
113
|
-
case headers['Content-Type']
|
114
|
-
when /charset=(\w+)/i
|
115
|
-
headers['Content-Type'].sub!(/charset=\w+/, 'charset=shift_jis')
|
116
|
-
else
|
117
|
-
headers['Content-Type'] << "; charset=shift_jis"
|
118
|
-
end
|
119
|
-
|
120
|
-
content = (body.is_a?(Array) ? body[0] : body).to_s
|
121
|
-
headers['Content-Length'] = (content.respond_to?(:bytesize) ? content.bytesize : content.size).to_s if headers.member?('Content-Length')
|
122
|
-
|
123
|
-
[status, headers, body]
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
require 'rack/ketai/carrier/emoji/emojidata'
|
131
|
-
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'scanf'
|
3
|
-
|
4
|
-
module Rack::Ketai::Carrier
|
5
|
-
class Au < Abstract
|
6
|
-
USER_AGENT_REGEXP = /^(?:KDDI|UP.Browser\/.+?)-(.+?) /
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class Rack::Ketai::Carrier::Au
|
11
|
-
class Filter < ::Rack::Ketai::Carrier::Abstract::SjisFilter
|
12
|
-
|
13
|
-
def inbound(env)
|
14
|
-
# au SJISバイナリ -> 絵文字ID表記
|
15
|
-
request = Rack::Request.new(env)
|
16
|
-
|
17
|
-
request.params # 最低でも1回呼んでないと query_stringが未設定
|
18
|
-
|
19
|
-
converter = lambda do |value|
|
20
|
-
value.gsub(sjis_regexp) do |match|
|
21
|
-
format("[e:%03X]", EMOJI_TO_EMOJIID[match])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
deep_apply(request.env["rack.request.query_hash"], &converter)
|
25
|
-
deep_apply(request.env["rack.request.form_hash"], &converter)
|
26
|
-
|
27
|
-
# 文字コード変換
|
28
|
-
super(request.env)
|
29
|
-
end
|
30
|
-
|
31
|
-
def outbound(status, headers, body)
|
32
|
-
status, headers, body = super
|
33
|
-
|
34
|
-
return [status, headers, body] unless body[0]
|
35
|
-
|
36
|
-
body = body.collect do |str|
|
37
|
-
str.gsub(/\[e:([0-9A-F]{3})\]/) do |match|
|
38
|
-
emojiid = $1.scanf('%X').first
|
39
|
-
sjis = EMOJIID_TO_EMOJI[emojiid]
|
40
|
-
if sjis
|
41
|
-
# 絵文字があるので差替え
|
42
|
-
sjis
|
43
|
-
else
|
44
|
-
# 絵文字がないので代替文字列
|
45
|
-
emoji_data = EMOJI_DATA[emojiid]
|
46
|
-
NKF.nkf('-Ws', (emoji_data[:fallback] || emoji_data[:name] || '〓'))
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
content = (body.is_a?(Array) ? body[0] : body).to_s
|
52
|
-
headers['Content-Length'] = (content.respond_to?(:bytesize) ? content.bytesize : content.size).to_s if headers.member?('Content-Length')
|
53
|
-
|
54
|
-
[status, headers, body]
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
# 絵文字コード -> 絵文字ID 対応表から、絵文字コード検出用の正規表現をつくる
|
59
|
-
# 複数の絵文字の組み合わせのものを前におくことで
|
60
|
-
# そっちを優先的にマッチさせる
|
61
|
-
def sjis_regexp
|
62
|
-
@sjis_regexp if @sjis_regexp
|
63
|
-
matchers = if RUBY_VERSION >= '1.9.1'
|
64
|
-
EMOJI_TO_EMOJIID.keys.sort_by{ |codes| - codes.size }.collect{ |sjis| Regexp.new(Regexp.escape(sjis), nil)}
|
65
|
-
else
|
66
|
-
EMOJI_TO_EMOJIID.keys.sort_by{ |codes| - codes.size }.collect{ |sjis| Regexp.new(Regexp.escape(sjis, 's'), nil, 's')}
|
67
|
-
end
|
68
|
-
@sjis_regexp = Regexp.union(*matchers)
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# 変換テーブル読み込み
|
75
|
-
require 'rack/ketai/carrier/emoji/ausjisstrtoemojiid'
|
76
|
-
|
77
|
-
Rack::Ketai::Carrier::Au.filters = [Rack::Ketai::Carrier::Au::Filter.instance]
|
78
|
-
|