-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
executable file
·157 lines (124 loc) · 2.32 KB
/
app.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
require 'sinatra'
require 'sinatra/reloader'
require 'json'
require 'curb'
require 'colorize'
require 'socket'
require_relative 'response_logic'
require_relative 'params_manager'
set :bind, Socket.ip_address_list.find { |ai|
ai.ipv4? && !ai.ipv4_loopback? }.ip_address
set :port, 9494
set :logging, true
$responses_path = '/responses/responses.json'
configure do
register Sinatra::Reloader
end
post '/validateJson' do
validate_json_reply
end
post '/getConfigJson' do
get_config_json
end
post '/getGlobalDelayFrom' do
get_global_delay_from
end
post '/getGlobalDelayTo' do
get_global_delay_to
end
post '/setServerAddress' do
set_server_address
status 200
end
post '/getServerAddress' do
get_server_address
end
post '/resetServerAddress' do
reset_server_address
status 200
end
post '/setGlobalDelay' do
set_global_delay
status 200
end
post '/resetGlobalDelay' do
reset_global_delay
status 200
end
post '/setReply' do
set_reply
status 200
end
post '/resetReply' do
reset_reply
status 200
end
post '/saveFakeFile' do
save_fake_file
redirect to('/setconfig')
end
post '/getFakeImages' do
get_fake_images
end
post '/getFakeFiles' do
get_fake_files
end
post '/resetFakeImages' do
reset_fake_images
status 200
end
post '/resetFakeFiles' do
reset_fake_files
status 200
end
post '/applyConfigFile' do
apply_config_file
redirect to('/setconfig')
end
post '/addConfigFile' do
add_config_file
redirect to('/setconfig')
end
post '/applyTextAreaConfig' do
apply_textarea_config
end
post '/dowloadFile' do
attachment "config.json"
get_config_json
end
post '/resetAll' do
reset_config
redirect to('/setconfig')
end
post '/saveAsTemplate' do
save_as_template
end
post '/setConfigFromTemplate' do
set_config_from_template
status 200
end
post '/delConfigFromTemplate' do
del_config_from_template
end
post '/getConfigTemplates' do
obj = get_config_templates.to_json
obj
end
get '/__sinatra__/:image.png' do
filename = File.dirname(__FILE__) + "/public/favicon.ico"
content_type :ico
send_file filename
end
get '/setconfigfromfile/:filename' do
set_config_from_template
end
get '/setconfig' do
get_config_templates
erb :form
end
get '/fakefile/:path/:file_name' do
send_file "./responses/#{params[:path]}/#{params[:file_name]}"
end
get '/*' do
get_response
end