-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolycomer.rb
48 lines (29 loc) · 997 Bytes
/
polycomer.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
require 'sinatra'
set :port, 8080
set :static, true
set :public_folder, "static"
set :views, "views"
get '/' do
return 'Hello world'
end
get '/hello/' do
params[:mac] = ""
erb :hello_form
end
post '/hello/' do
mac = params[:mac].to_s
extension = params[:extension].to_s
voicemail = params[:voicemail].to_s
timezone = params[:timezone].to_s
file_names = ['rssets/eg-basic_EXAMPLE.cfg']
file_names.each do |file_name|
text = File.read(file_name)
new_contents = text.gsub(/AAAAAAAAAAA/, extension).gsub(/BBBBBBBBBBB/, voicemail).gsub(/TIMEZONE/, timezone)
# To merely print the contents of the file, use:
# puts new_contents
# To write changes to the file, use:
File.open(phone_configs/"reg-basic_"+mac+".cfg", "w") {|file| file.puts new_contents }
end
send_file("reg-basic_"+mac+".cfg", :filename =>"reg-basic_"+mac+".cfg", :type => 'Application/octet-stream')
redirect back
end