-
Notifications
You must be signed in to change notification settings - Fork 1
/
request_handler.rb
72 lines (59 loc) · 2.11 KB
/
request_handler.rb
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
require 'mystring'
require 'rubygems'
require 'sqlite3'
require 'active_record'
require 'model/file.rb'
require 'model/owner.rb'
require 'model/mime.rb'
require 'model/folder.rb'
require 'model/index.rb'
require 'config'
class RequestHandler
attr_accessor :response
def initialize (nodeName, request)
@nodeName=nodeName
@request=request
@config = Configuration.new
handle_request
end
def handle_request
request_array = XmlSimple.xml_in(@request)
if request_array['type']=='file'
file_handler request_array
end
if request_array['type']=='search'
end
end
def search_handler request_array
end
def file_handler request_array
if @config.is_secret_key? request_array['secretkey']
access_codes=@config.access_codes
if access_codes.is_valid_access_code? request_array['access'].to_s
acces_code=request_array['access'].to_s
path=request_array['path'].to_s
name=request_array['file'].to_s.hex2s.xor("HALSECRET")
description=request_array['description'].to_s.hex2s
owner_pass = request_array['owner_pass']
owner_name = request_array['owner_name'].to_s.hex2s
Thread.new{
unless request_array['action']=='delete'
asset=Asset.create if request_array['action']=='new'
asset=Asset.find_by_name(name) if request_array['action']=='update'
asset.add path, file, acces_code, description, owner_name, owner_pass
asset.save
else
asset.Asset.find_by_name(name)
asset.delete owner_name, owner_pass
end
}
@response = "200"
else
@response = "300"
end
else
@response = "100"
end
p @response
end
end