Ruby GTK3移行後のメインリポジトリ
Revisão | f274fde46b071cef002b369ff99d18d75e7459b5 (tree) |
---|---|
Hora | 2015-02-05 23:56:41 |
Autor | Shyouzou Sugitani <shy@user...> |
Commiter | Shyouzou Sugitani |
add sstp.rb
@@ -26,7 +26,7 @@ module EntryDB | ||
26 | 26 | def add(key, script) |
27 | 27 | if @__db.has_key?(key) |
28 | 28 | entries = @__db[key] |
29 | - elsif | |
29 | + else | |
30 | 30 | entries = [] |
31 | 31 | end |
32 | 32 | entries << script |
@@ -0,0 +1,665 @@ | ||
1 | +# -*- coding: utf-8 -*- | |
2 | +# | |
3 | +# Copyright (C) 2001, 2002 by Tamito KAJIYAMA | |
4 | +# Copyright (C) 2002, 2003 by MATSUMURA Namihiko <nie@counterghost.net> | |
5 | +# Copyright (C) 2002-2015 by Shyouzou Sugitani <shy@users.sourceforge.jp> | |
6 | +# | |
7 | +# This program is free software; you can redistribute it and/or modify it | |
8 | +# under the terms of the GNU General Public License (version 2) as | |
9 | +# published by the Free Software Foundation. It is distributed in the | |
10 | +# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | |
11 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
12 | +# PURPOSE. See the GNU General Public License for more details. | |
13 | +# | |
14 | + | |
15 | +require "ninix/entry_db" | |
16 | +require "ninix/script" | |
17 | +require "ninix/version" | |
18 | +require "ninix/sstplib" | |
19 | + | |
20 | + | |
21 | +module SSTP | |
22 | + | |
23 | + class SSTPServer < SSTPLib::AsynchronousSSTPServer | |
24 | + | |
25 | + def initialize(address) | |
26 | + @parent = nil | |
27 | + super(address) | |
28 | + @request_handler = nil | |
29 | + end | |
30 | + | |
31 | +# def shutdown_request(request) | |
32 | +# if @request_handler != nil | |
33 | +# # XXX: send_* methods can be called from outside of the handler | |
34 | +# pass # keep alive | |
35 | +# else | |
36 | +# super(request) #AsynchronousSSTPServer.shutdown_request(self, request) | |
37 | +# end | |
38 | +# end | |
39 | + | |
40 | + def set_responsible(parent) | |
41 | + @parent = parent | |
42 | + end | |
43 | + | |
44 | + def handle_request(event_type, event, *arglist, **argdict) | |
45 | + if @parent != nil | |
46 | + @parent.handle_request(event_type, event, *arglist, **argdict) | |
47 | + end | |
48 | + end | |
49 | + | |
50 | + def set_request_handler(handler) ## FIXME | |
51 | + @request_handler = handler | |
52 | + end | |
53 | + | |
54 | + def has_request_handler | |
55 | + if @request_handler != nil | |
56 | + return true | |
57 | + else | |
58 | + return false | |
59 | + end | |
60 | + end | |
61 | + | |
62 | + def send_response(code, data=nil) | |
63 | + begin | |
64 | + @request_handler.send_response(code) | |
65 | + if data != nil | |
66 | +# @request_handler.wfile.write(data) | |
67 | + @request_handler.write(data) # FIXME | |
68 | + end | |
69 | +# @request_handler.force_finish() | |
70 | + @request_handler.shutdown(Socket::SHUT_WR) # XXX | |
71 | + rescue #except IOError: | |
72 | + #pass | |
73 | + end | |
74 | + @request_handler = nil | |
75 | + end | |
76 | + | |
77 | + def send_answer(value) | |
78 | + charset = @request_handler.get_charset | |
79 | + answer = [value.encode(charset, :invalid => :replace), "\r\n\r\n"].join("") | |
80 | + send_response(200, answer) # OK | |
81 | + end | |
82 | + | |
83 | + def send_no_content | |
84 | + send_response(204) # No Content | |
85 | + end | |
86 | + | |
87 | + def send_sstp_break | |
88 | + send_response(210) # Break | |
89 | + end | |
90 | + | |
91 | + def send_timeout | |
92 | + send_response(408) # Request Timeout | |
93 | + end | |
94 | + | |
95 | + def close | |
96 | + socket.close() | |
97 | + end | |
98 | + end | |
99 | + | |
100 | + class SSTPRequestHandler < SSTPLib::BaseSSTPRequestHandler | |
101 | + | |
102 | + def handle(line) | |
103 | + if not @server.handle_request('GET', 'get_sakura_cantalk') | |
104 | + @error = @version = nil | |
105 | + if not parse_request(line) | |
106 | + return | |
107 | + end | |
108 | + send_error(512) | |
109 | + else | |
110 | + super(line) | |
111 | + end | |
112 | + end | |
113 | + | |
114 | +# def force_finish | |
115 | +# BaseSSTPRequestHandler.finish(self) | |
116 | +# end | |
117 | + | |
118 | +# def finish | |
119 | +# if @server.request_handler == nil | |
120 | +# BaseSSTPRequestHandler.finish(self) | |
121 | +# end | |
122 | +# end | |
123 | + | |
124 | + # SEND | |
125 | + def do_SEND_1_0 | |
126 | + handle_send(1.0) | |
127 | + end | |
128 | + | |
129 | + def do_SEND_1_1 | |
130 | + handle_send(1.1) | |
131 | + end | |
132 | + | |
133 | + def do_SEND_1_2 | |
134 | + handle_send(1.2) | |
135 | + end | |
136 | + | |
137 | + def do_SEND_1_3 | |
138 | + handle_send(1.3) | |
139 | + end | |
140 | + | |
141 | + def do_SEND_1_4 | |
142 | + handle_send(1.4) | |
143 | + end | |
144 | + | |
145 | + def handle_send(version) | |
146 | + if not check_decoder() | |
147 | + return | |
148 | + end | |
149 | + sender = get_sender() | |
150 | + if sender == nil | |
151 | + return | |
152 | + end | |
153 | + if version == 1.3 | |
154 | + handle = get_handle() | |
155 | + if handle == nil | |
156 | + return | |
157 | + end | |
158 | + else | |
159 | + handle = nil | |
160 | + end | |
161 | + script_odict = get_script_odict() | |
162 | + if script_odict == nil | |
163 | + return | |
164 | + end | |
165 | + if [1.0, 1.1].include?(version) | |
166 | + entry_db = nil | |
167 | + elsif [1.2, 1.3, 1.4].include?(version) | |
168 | + entry_db = get_entry_db() | |
169 | + if entry_db == nil | |
170 | + return | |
171 | + end | |
172 | + end | |
173 | + enqueue_request(sender, nil, handle, script_odict, entry_db) | |
174 | + end | |
175 | + | |
176 | + # NOTIFY | |
177 | + def do_NOTIFY_1_0 | |
178 | + handle_notify(1.0) | |
179 | + end | |
180 | + | |
181 | + def do_NOTIFY_1_1 | |
182 | + handle_notify(1.1) | |
183 | + end | |
184 | + | |
185 | + def handle_notify(version) | |
186 | + if not check_decoder() | |
187 | + return | |
188 | + end | |
189 | + sender = get_sender() | |
190 | + if sender == nil | |
191 | + return | |
192 | + end | |
193 | + event = get_event() | |
194 | + if event == nil | |
195 | + return | |
196 | + end | |
197 | + if version == 1.0 | |
198 | + entry_db = nil | |
199 | + elsif version == 1.1 | |
200 | + script_odict = get_script_odict() | |
201 | + if script_odict == nil | |
202 | + return | |
203 | + end | |
204 | + entry_db = get_entry_db() | |
205 | + if entry_db == nil | |
206 | + return | |
207 | + end | |
208 | + end | |
209 | + enqueue_request(sender, event, nil, script_odict, entry_db) | |
210 | + end | |
211 | + | |
212 | + def enqueue_request(sender, event, handle, script_odict, entry_db) | |
213 | + sock_domain, remote_port, remote_hostname, remote_ip = @fp.peeraddr | |
214 | + address = remote_hostname # XXX | |
215 | + if entry_db == nil or entry_db.is_empty() | |
216 | + send_response(200) # OK | |
217 | + show_sstp_marker, use_translator = get_options() | |
218 | + @server.handle_request( | |
219 | + 'NOTIFY', 'enqueue_request', | |
220 | + event, script_odict, sender, handle, | |
221 | + address, show_sstp_marker, use_translator, | |
222 | + entry_db, nil) | |
223 | + elsif @server.has_request_handler | |
224 | + send_response(409) # Conflict | |
225 | + else | |
226 | + show_sstp_marker, use_translator = get_options() | |
227 | + @server.handle_request( | |
228 | + 'NOTIFY', 'enqueue_request', | |
229 | + event, script_odict, sender, handle, | |
230 | + address, show_sstp_marker, use_translator, | |
231 | + entry_db, @server) | |
232 | + @server.set_request_handler(self) # keep alive | |
233 | + end | |
234 | + end | |
235 | + | |
236 | + PROHIBITED_TAGS = ['\j', '\-', '\+', '\_+', '\!', '\8', '\_v', '\C'] | |
237 | + | |
238 | + def check_script(script) | |
239 | + if not local_request() | |
240 | + parser = Script::Parser.new | |
241 | + nodes = [] | |
242 | + while 1 | |
243 | + begin | |
244 | + nodes.concat(parser.parse(script)) | |
245 | + rescue #except ninix.script.ParserError as e: | |
246 | + done, script = e ## FIXME | |
247 | + nodes.concat(done) | |
248 | + else | |
249 | + break | |
250 | + end | |
251 | + end | |
252 | + for node in nodes | |
253 | + if node[0] == Script::SCRIPT_TAG and \ | |
254 | + PROHIBITED_TAGS.include?(node[1]) | |
255 | + send_response(400) # Bad Request | |
256 | + log_error('Script: tag ' + node[1].to_s + ' not allowed') | |
257 | + return true | |
258 | + end | |
259 | + end | |
260 | + end | |
261 | + return false | |
262 | + end | |
263 | + | |
264 | +# def get_script | |
265 | +# script = @headers.get('Script', nil) | |
266 | +# if script == nil | |
267 | +# send_response(400) # Bad Request | |
268 | +# log_error('Script: header field not found') | |
269 | +# return nil | |
270 | +# end | |
271 | +# return script | |
272 | +# end | |
273 | + | |
274 | + def get_script_odict | |
275 | + script_odict = {} #OrderedDict() | |
276 | + if_ghost = nil | |
277 | + for item in @headers | |
278 | + name, value = item | |
279 | + if name != 'Script' | |
280 | + if name == ('IfGhost') | |
281 | + if_ghost = value | |
282 | + else | |
283 | + if_ghost = nil | |
284 | + end | |
285 | + next | |
286 | + end | |
287 | + script = value.to_s | |
288 | + if check_script(script) | |
289 | + return | |
290 | + end | |
291 | + if if_ghost == nil | |
292 | + script_odict[''] = script | |
293 | + else | |
294 | + script_odict[if_ghost] = script | |
295 | + end | |
296 | + if_ghost = nil | |
297 | + end | |
298 | + return script_odict | |
299 | + end | |
300 | + | |
301 | +# def get_script_if_ghost(current=0) | |
302 | +# default = nil | |
303 | +# if_ghost = nil | |
304 | +# for header, value in @headers.items() | |
305 | +# if header == 'IfGhost' | |
306 | +# if_ghost = value.strip() | |
307 | +# continue | |
308 | +# elsif header == 'Script' | |
309 | +# if if_ghost == nil | |
310 | +# continue | |
311 | +# end | |
312 | +# script = value.strip() | |
313 | +# else | |
314 | +# if_ghost = nil | |
315 | +# continue | |
316 | +# end | |
317 | +# if current # NOTIFY | |
318 | +# ghost = @server.request_parent('GET', 'get_ghost_name') | |
319 | +# if ghost == if_ghost | |
320 | +# return script, if_ghost | |
321 | +# end | |
322 | +# else # SEND | |
323 | +# if @server.request_parent('GET', 'if_ghost', if_ghost) | |
324 | +# return script, if_ghost | |
325 | +# end | |
326 | +# end | |
327 | +# if default == nil | |
328 | +# default = script, if_ghost | |
329 | +# end | |
330 | +# end | |
331 | +# if default == nil | |
332 | +# script = @headers.get('Script', nil) | |
333 | +# default = script, nil | |
334 | +# end | |
335 | +# return default | |
336 | +# end | |
337 | + | |
338 | + def get_entry_db | |
339 | + entry_db = EntryDB::EntryDatabase.new | |
340 | + for item in @headers | |
341 | + key, value = item | |
342 | + if key == "Entry" | |
343 | + entry = value.split(',', 2) | |
344 | + if entry.length != 2 | |
345 | + send_response(400) # Bad Request | |
346 | + return nil | |
347 | + end | |
348 | + entry_db.add(entry[0].strip(), entry[1].strip()) | |
349 | + end | |
350 | + end | |
351 | + return entry_db | |
352 | + end | |
353 | + | |
354 | + def get_event | |
355 | + if @headers.assoc("Event") != nil | |
356 | + event = @headers.reverse.assoc("Event")[1] | |
357 | + else | |
358 | + event = nil | |
359 | + end | |
360 | + if event == nil | |
361 | + send_response(400) # Bad Request | |
362 | + log_error('Event: header field not found') | |
363 | + return nil | |
364 | + end | |
365 | + buf = [event] | |
366 | + for i in 0..7 | |
367 | + key = ['Reference', i.to_s].join("") | |
368 | + if @headers.assoc(key) != nil | |
369 | + value = @headers.reverse.assoc(key)[1] | |
370 | + else | |
371 | + value = nil | |
372 | + end | |
373 | + buf << value | |
374 | + end | |
375 | + return buf | |
376 | + end | |
377 | + | |
378 | + def get_sender | |
379 | + if @headers.assoc('Sender') != nil | |
380 | + sender = @headers.reverse.assoc('Sender')[1] | |
381 | + else | |
382 | + sender = nil | |
383 | + end | |
384 | + if sender == nil | |
385 | + send_response(400) # Bad Request | |
386 | + log_error('Sender: header field not found') | |
387 | + return nil | |
388 | + end | |
389 | + return sender | |
390 | + end | |
391 | + | |
392 | + def get_handle | |
393 | + if @headers.assoc("HWnd") != nil | |
394 | + path = @headers.assoc("HWnd") | |
395 | + else | |
396 | + path = nil | |
397 | + end | |
398 | + if path == nil | |
399 | + send_response(400) # Bad Request | |
400 | + log_error('HWnd: header field not found') | |
401 | + return nil | |
402 | + end | |
403 | +# handle = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
404 | + handle = nil # FIXME | |
405 | +# begin | |
406 | +# handle.connect(path) | |
407 | +# rescue #except socket.error: | |
408 | +# handle = nil # discard socket object | |
409 | +# logging.error('cannot open Unix socket: {0}'.format(path)) | |
410 | +# end | |
411 | +# if handle == nil | |
412 | +# send_response(400) # Bad Request | |
413 | +# log_error('Invalid HWnd: header field') | |
414 | +# return nil | |
415 | +# end | |
416 | + return handle | |
417 | + end | |
418 | + | |
419 | + def get_charset | |
420 | + if @headers.assoc('Charset') != nil | |
421 | + charset = @headers.reverse.assoc('Charset')[1] # XXX | |
422 | + else | |
423 | + charset = 'Shift_JIS' | |
424 | + end | |
425 | + return charset | |
426 | + end | |
427 | + | |
428 | + def check_decoder | |
429 | + if @headers.assoc('Charset') != nil | |
430 | + charset = @headers.reverse.assoc('Charset')[1] # XXX | |
431 | + else | |
432 | + charset = 'Shift_JIS' | |
433 | + end | |
434 | + if not Encoding.name_list.include?(charset) | |
435 | + send_response(420, 'Refuse (unsupported charset)') | |
436 | + log_error('Unsupported charset {0}'.format(repr(charset))) | |
437 | + else | |
438 | + return true | |
439 | + end | |
440 | + return false | |
441 | + end | |
442 | + | |
443 | + def get_options | |
444 | + show_sstp_marker = use_translator = 1 | |
445 | + if @headers.assoc("Option") != nil | |
446 | + options = @headers.reverse.assoc("Option")[1].split(",") | |
447 | + for option in options | |
448 | + option = option.strip() | |
449 | + if option == 'nodescript' and local_request() | |
450 | + show_sstp_marker = 0 | |
451 | + elsif option == 'notranslate' | |
452 | + use_translator = 0 | |
453 | + end | |
454 | + end | |
455 | + end | |
456 | + return show_sstp_marker, use_translator | |
457 | + end | |
458 | + | |
459 | + def local_request | |
460 | + sock_domain, remote_port, remote_hostname, remote_ip = @fp.peeraddr | |
461 | + if remote_ip == "127.0.0.1" | |
462 | + return true | |
463 | + else | |
464 | + return false | |
465 | + end | |
466 | + end | |
467 | + | |
468 | + # EXECUTE | |
469 | + def do_EXECUTE_1_0 | |
470 | + handle_command() | |
471 | + end | |
472 | + | |
473 | + def do_EXECUTE_1_2 | |
474 | + handle_command() | |
475 | + end | |
476 | + | |
477 | + def do_EXECUTE_1_3 | |
478 | + if not local_request() | |
479 | + sock_domain, remote_port, remote_hostname, remote_ip = @fp.peeraddr | |
480 | + send_response(420) | |
481 | + log_error( | |
482 | + 'Unauthorized EXECUTE/1.3 request from ' + remote_hostname) | |
483 | + return | |
484 | + end | |
485 | + handle_command() | |
486 | + end | |
487 | + | |
488 | + def shutdown(how) | |
489 | + @fp.shutdown(how) | |
490 | + end | |
491 | + | |
492 | + def write(data) | |
493 | + @fp.write(data) | |
494 | + end | |
495 | + | |
496 | + def handle_command | |
497 | + if not check_decoder() | |
498 | + return | |
499 | + end | |
500 | + sender = get_sender() | |
501 | + if sender == nil | |
502 | + return | |
503 | + end | |
504 | + command = get_command() | |
505 | + if @headers.assoc('Charset') != nil | |
506 | + charset = @headers.reverse.assoc('Charset')[1] # XXX | |
507 | + else | |
508 | + charset = 'Shift_JIS' | |
509 | + end | |
510 | + charset = charset.to_s | |
511 | + if command == nil | |
512 | + return | |
513 | + elsif command == 'getname' | |
514 | + send_response(200) | |
515 | + name = @server.handle_request('GET', 'get_ghost_name') | |
516 | + @fp.write([name.encode(charset, :invalid => :replace), | |
517 | + "\r\n"].join("")) | |
518 | + @fp.write("\r\n") | |
519 | + elsif command == 'getversion' | |
520 | + send_response(200) | |
521 | + @fp.write(['ninix-aya ', | |
522 | + Version.VERSION.encode(charset), | |
523 | + "\r\n"].join("")) | |
524 | + @fp.write("\r\n") | |
525 | + elsif command == 'quiet' | |
526 | + send_response(200) | |
527 | + @server.handle_request('NOTIFY', 'keep_silence', true) | |
528 | + elsif command == 'restore' | |
529 | + send_response(200) | |
530 | + @server.handle_request('NOTIFY', 'keep_silence', false) | |
531 | + elsif command == 'getnames' | |
532 | + send_response(200) | |
533 | + for name in @server.handle_request('GET', 'get_ghost_names') | |
534 | + @fp.write( | |
535 | + [name.encode(charset, :invalid => :replace), "\r\n"].join("")) | |
536 | + end | |
537 | + @fp.write("\r\n") | |
538 | + elsif command == 'checkqueue' | |
539 | + send_response(200) | |
540 | + count, total = @server.handle_request( | |
541 | + 'GET', 'check_request_queue', sender) | |
542 | + @fp.write([count.to_s.encode(charset), "\r\n"].join("")) | |
543 | + @fp.write([total.to_s.encode(charset), "\r\n"].join("")) | |
544 | + @fp.write("\r\n") | |
545 | + else | |
546 | + send_response(501) # Not Implemented | |
547 | + log_error('Not Implemented (' + command + ')') | |
548 | + end | |
549 | + end | |
550 | + | |
551 | + def get_command | |
552 | + if @headers.assoc('Command') | |
553 | + command = @headers.reverse.assoc('Command')[1] | |
554 | + else | |
555 | + command = nil | |
556 | + end | |
557 | + if command == nil | |
558 | + send_response(400) # Bad Request | |
559 | + log_error('Command: header field not found') | |
560 | + return nil | |
561 | + end | |
562 | + return command.downcase | |
563 | + end | |
564 | + | |
565 | + def do_COMMUNICATE_1_1 | |
566 | + if not check_decoder() | |
567 | + return | |
568 | + end | |
569 | + sender = get_sender() | |
570 | + if sender == nil | |
571 | + return | |
572 | + end | |
573 | + sentence = get_sentence() | |
574 | + if sentence == nil | |
575 | + return | |
576 | + end | |
577 | + send_response(200) # OK | |
578 | + @server.handle_request( | |
579 | + 'NOTIFY', 'enqueue_event', 'OnCommunicate', sender, sentence) | |
580 | + return | |
581 | + end | |
582 | + | |
583 | + def get_sentence | |
584 | + if @headers.assoc("Sentence") | |
585 | + sentence = @headers.reverse.assoc("Sentence")[1] | |
586 | + else | |
587 | + sentence = nil | |
588 | + end | |
589 | + if sentence == nil | |
590 | + send_response(400) # Bad Request | |
591 | + log_error('Sentence: header field not found') | |
592 | + return nil | |
593 | + end | |
594 | + return sentence | |
595 | + end | |
596 | + end | |
597 | + | |
598 | + class TEST | |
599 | + | |
600 | + def initialize | |
601 | + port = 9801 | |
602 | + sstpd = SSTPServer.new(port) | |
603 | + sstpd.set_responsible(self) | |
604 | +# @request_handler = nil | |
605 | + print('Serving SSTP on port ' + port.to_i.to_s + ' ...' + "\n") | |
606 | + opt = sstpd.getsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR) | |
607 | + print('Allow reuse address: ' + opt.int.to_s + "\n") | |
608 | + @cantalk = 0 | |
609 | + while true | |
610 | + s = sstpd.accept | |
611 | + handler = SSTPRequestHandler.new(sstpd, s) | |
612 | + buffer = s.gets | |
613 | + handler.handle(buffer) | |
614 | + if sstpd.has_request_handler | |
615 | + #sstpd.send_answer("TEST") | |
616 | + #sstpd.send_no_content | |
617 | + #sstpd.send_sstp_break | |
618 | + #sstpd.send_response(511) | |
619 | + sstpd.send_timeout | |
620 | + end | |
621 | + s.close | |
622 | + end | |
623 | + #serv.shutdown_request("TEST") | |
624 | + end | |
625 | + | |
626 | +# def has_request_handler | |
627 | +# if @request_handler != nil | |
628 | +# return true | |
629 | +# else | |
630 | +# return false | |
631 | +# end | |
632 | +# end | |
633 | +# | |
634 | +# def set_request_handler(handler) ## FIXME | |
635 | +# @request_handler = handler | |
636 | +# end | |
637 | + | |
638 | + def handle_request(event, *args) | |
639 | + if event == "GET" | |
640 | + print("ARGS: ", args, "\n") | |
641 | + if args[0] == "get_sakura_cantalk" | |
642 | +# print("CANTALK :", @cantalk, "\n") | |
643 | + if @cantalk == 1 | |
644 | + @cantalk = 0 | |
645 | + return true | |
646 | + else | |
647 | + @cantalk = 1 | |
648 | + return false | |
649 | + end | |
650 | + elsif args[0] == "get_ghost_names" | |
651 | + return ["A", "B", "C"] | |
652 | + elsif args[0] == "check_request_queue" | |
653 | + return [100, 200] | |
654 | + else | |
655 | + return "日本語テスト" | |
656 | + end | |
657 | + elsif event == "NOTIFY" | |
658 | + print("NOTIFY: ", args, "\n") | |
659 | + return 1 | |
660 | + end | |
661 | + end | |
662 | + end | |
663 | +end | |
664 | + | |
665 | +SSTP::TEST.new |
@@ -54,7 +54,8 @@ module SSTPLib | ||
54 | 54 | 512 => 'Invisible', |
55 | 55 | } |
56 | 56 | |
57 | - def initialize(fp) | |
57 | + def initialize(server, fp) | |
58 | + @server = server | |
58 | 59 | @fp = fp |
59 | 60 | end |
60 | 61 |
@@ -75,21 +76,24 @@ module SSTPLib | ||
75 | 76 | end |
76 | 77 | headers << line |
77 | 78 | end |
78 | - message = {} | |
79 | + message = [] | |
79 | 80 | for h in headers |
80 | 81 | if h.include?(":") |
81 | 82 | key, value = h.split(":", 2) |
82 | - message[key] = value.strip | |
83 | + message << [key, value.strip] | |
83 | 84 | end |
84 | 85 | end |
85 | - if message.keys.include?("Charset") | |
86 | - charset = message["Charset"] | |
86 | + if message.assoc("Charset") != nil | |
87 | + charset = message.reverse.assoc("Charset")[1] # XXX | |
87 | 88 | else |
88 | 89 | charset = "Shift_JIS" |
89 | 90 | end |
90 | - for key in message.keys | |
91 | - message[key] = message[key].force_encoding(charset).encode("UTF-8", :invalid => :replace) | |
91 | + new_list = [] | |
92 | + for item in message | |
93 | + key, value = item | |
94 | + new_list << [key, value.force_encoding(charset).encode("UTF-8", :invalid => :replace)] ## FIXME | |
92 | 95 | end |
96 | + message = new_list | |
93 | 97 | return message |
94 | 98 | end |
95 | 99 |
@@ -157,16 +161,11 @@ module SSTPLib | ||
157 | 161 | |
158 | 162 | def client_hostname |
159 | 163 | begin |
160 | - host, port = self.client_address | |
164 | + sock_domain, remote_port, remote_hostname, remote_ip = @fp.peeraddr | |
165 | + return remote_hostname | |
161 | 166 | rescue #except: |
162 | 167 | return 'localhost' |
163 | 168 | end |
164 | - begin | |
165 | - hostname, aliaslist, ipaddrlist = socket.gethostbyaddr(host) | |
166 | - rescue #except socket.error: | |
167 | - hostname = host | |
168 | - end | |
169 | - return hostname | |
170 | 169 | end |
171 | 170 | |
172 | 171 | def timestamp |
@@ -190,12 +189,17 @@ module SSTPLib | ||
190 | 189 | print('Allow reuse address: ' + opt.int.to_s + "\n") |
191 | 190 | while true |
192 | 191 | s = sstpd.accept |
193 | - handler = BaseSSTPRequestHandler.new(s) | |
192 | + handler = BaseSSTPRequestHandler.new(self, s) | |
194 | 193 | buffer = s.gets |
195 | 194 | handler.handle(buffer) |
196 | 195 | s.close |
197 | 196 | end |
198 | 197 | end |
198 | + | |
199 | + def request_parent(args) | |
200 | + print("ARGS: ", args, "\n") | |
201 | + return 1 | |
202 | + end | |
199 | 203 | end |
200 | 204 | end |
201 | 205 |