apiotics 0.1.106 → 0.1.107
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apiotics/server.rb +68 -71
- data/lib/apiotics/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 606275f78d00c05a5b3e8bfb9c34fa9d81b398d2
|
4
|
+
data.tar.gz: c4b3f245703a2302c564e5b933688b8ab0dd90f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fcc519a262b242561bb0c6e3359e498d633e604f1115bbe48cca49949b6361eac1dad8b569201cb0a7813c1ea852d51d910dd5394d14809ffbe8c4b7bce4e04
|
7
|
+
data.tar.gz: 2ceff891f833d0adf9742b0ac6446033acc8091b1ec1884d4845c49185b3fc635dc145a5c34d8b9b0058b88062482566742a6963c0b03f4fc06e6679aacee8ed
|
data/lib/apiotics/server.rb
CHANGED
@@ -10,85 +10,82 @@ require "redis"
|
|
10
10
|
module Apiotics
|
11
11
|
class Server
|
12
12
|
def initialize
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@error_msg = nil
|
19
|
-
server_details = Server.lookup
|
20
|
-
rgs = ApioticsSetting.find_by(key: "server")
|
21
|
-
rgs_port = ApioticsSetting.find_by(key: "port")
|
22
|
-
if rgs == nil
|
23
|
-
if server_details["status"] == "ok"
|
24
|
-
rgs = server_details["ip"]
|
25
|
-
c = ApioticsSetting.new
|
26
|
-
c.key = "server"
|
27
|
-
c.value = rgs
|
28
|
-
c.save
|
29
|
-
rgs_port = server_details["port"]
|
30
|
-
c = ApioticsSetting.new
|
31
|
-
c.key = "port"
|
32
|
-
c.value = rgs_port
|
33
|
-
c.save
|
34
|
-
else
|
35
|
-
@error_msg = server_details["status_msg"]
|
13
|
+
begin
|
14
|
+
Thread.abort_on_exception = true
|
15
|
+
hive_public_key = ApioticsSetting.find_by(key: "hive_public_key")
|
16
|
+
if hive_public_key == nil || hive_public_key.value != Apiotics.configuration.public_key
|
17
|
+
Server.clear_db_settings
|
36
18
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
19
|
+
@error_msg = nil
|
20
|
+
server_details = Server.lookup
|
21
|
+
rgs = ApioticsSetting.find_by(key: "server")
|
22
|
+
rgs_port = ApioticsSetting.find_by(key: "port")
|
23
|
+
if rgs == nil
|
24
|
+
if server_details["status"] == "ok"
|
25
|
+
rgs = server_details["ip"]
|
26
|
+
c = ApioticsSetting.new
|
27
|
+
c.key = "server"
|
28
|
+
c.value = rgs
|
29
|
+
c.save
|
30
|
+
rgs_port = server_details["port"]
|
31
|
+
c = ApioticsSetting.new
|
32
|
+
c.key = "port"
|
33
|
+
c.value = rgs_port
|
34
|
+
c.save
|
35
|
+
else
|
36
|
+
@error_msg = server_details["status_msg"]
|
37
|
+
end
|
45
38
|
else
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
ca_tempfile.write Server.ca_cert.to_pem
|
57
|
-
ca_tempfile.rewind
|
58
|
-
context.ca_file = ca_tempfile.path
|
59
|
-
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
39
|
+
if server_details["status"] == "ok"
|
40
|
+
rgs.value = server_details["ip"]
|
41
|
+
rgs.save
|
42
|
+
rgs = rgs.value
|
43
|
+
rgs_port.value = server_details["port"]
|
44
|
+
rgs_port.save
|
45
|
+
rgs_port = rgs_port.value
|
46
|
+
else
|
47
|
+
@error_msg = server_details["status_msg"]
|
48
|
+
end
|
60
49
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
50
|
+
if Apiotics.configuration.tls == true
|
51
|
+
socket = TCPSocket.new(rgs, rgs_port)
|
52
|
+
context = OpenSSL::SSL::SSLContext.new
|
53
|
+
context.key = Server.key
|
54
|
+
context.cert = Server.cert
|
55
|
+
if Apiotics.configuration.verify_peer == true
|
56
|
+
ca_tempfile = Tempfile.new
|
57
|
+
ca_tempfile.write Server.ca_cert.to_pem
|
58
|
+
ca_tempfile.rewind
|
59
|
+
context.ca_file = ca_tempfile.path
|
60
|
+
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
61
|
+
end
|
62
|
+
server = OpenSSL::SSL::SSLSocket.new socket, context
|
63
|
+
server.sync_close = true
|
64
64
|
server.connect
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if Apiotics.configuration.verify_peer == true
|
70
|
-
ca_tempfile.close(true)
|
71
|
-
end
|
72
|
-
else
|
73
|
-
begin
|
65
|
+
if Apiotics.configuration.verify_peer == true
|
66
|
+
ca_tempfile.close(true)
|
67
|
+
end
|
68
|
+
else
|
74
69
|
server = TCPSocket.open(rgs, rgs_port)
|
75
|
-
|
70
|
+
end
|
71
|
+
@server = server
|
72
|
+
@localport = Apiotics.configuration.local_port
|
73
|
+
listen_remote
|
74
|
+
@heartbeat_state = Hash.new
|
75
|
+
heartbeat = {
|
76
|
+
"action" => "set-request",
|
77
|
+
"instance" => "0000000000000000000000000000000000000000000000000000000000000000",
|
78
|
+
"driver" => "Core::Heartbeat",
|
79
|
+
"interface" => nil
|
80
|
+
}
|
81
|
+
send_heartbeat(heartbeat)
|
82
|
+
listen_local
|
83
|
+
rescue => e
|
84
|
+
if server != nil
|
76
85
|
server.close
|
77
|
-
raise e
|
78
86
|
end
|
87
|
+
raise e
|
79
88
|
end
|
80
|
-
@server = server
|
81
|
-
@localport = Apiotics.configuration.local_port
|
82
|
-
listen_remote
|
83
|
-
@heartbeat_state = Hash.new
|
84
|
-
heartbeat = {
|
85
|
-
"action" => "set-request",
|
86
|
-
"instance" => "0000000000000000000000000000000000000000000000000000000000000000",
|
87
|
-
"driver" => "Core::Heartbeat",
|
88
|
-
"interface" => nil
|
89
|
-
}
|
90
|
-
send_heartbeat(heartbeat)
|
91
|
-
listen_local
|
92
89
|
end
|
93
90
|
|
94
91
|
def send(msg)
|
data/lib/apiotics/version.rb
CHANGED