forked from mycard/ygopro-images-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthorize.rb
38 lines (34 loc) · 765 Bytes
/
Authorize.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
# Check the command is legal or not
require 'json'
require 'digest/md5'
require File.dirname(__FILE__) + "/Log.rb"
module Authorize
module_function
@@command_password = "7c7cc75c2822cb592e7783d9b92825ac"
def md5(source)
Digest::MD5.hexdigest source
end
def md5_file(source)
begin
content = File.open(source) {|f| f.read}
self.md5 content
rescue Exception => e
Log.logger.error e.inspect
nil
end
end
def get_command(text)
begin
json = JSON.parse text
return 401 if json['password'].nil?
pw = Authorize.md5('password')
return 403 if @@command_password != pw
return json['content']
rescue Exception => e
return 400
end
end
def change_password(password)
@@command_password = Aunthorize.md5(password)
end
end