Class: ConfigController
Instance Method Summary
collapse
#copy, #six_local_auto_login
#active_scaffold_render_secure_download, #assign_names_with_active_scaffold, #render_with_active_scaffold, #search_generic_view_paths?
Instance Method Details
33
34
35
36
37
38
|
# File 'lib/six-updater-web/app/controllers/config_controller.rb', line 33
def edit
setting = Appsetting.find(params["setting"])
path = setting.real_path.gsub("\\", "/")
@userconfig = File.exists?(File.join(path, params["options"]["userconfig"])) ? File.open(File.join(path, params["options"]["userconfig"])) {|a| Iconv.new("utf-8//IGNORE//TRANSLIT", "utf-8").iconv(a.read + ' ')[0..-2].split("\n").map{|e| e.sub("\r", "")}.join("\n") } : ""
@setting = setting
end
|
#fetch_param(ar, ty, default = nil) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/six-updater-web/app/controllers/config_controller.rb', line 61
def fetch_param(ar, ty, default = nil)
a = params
ar.each do |e|
if a[e]
a = a[e]
else
a = nil
break
end
end
if a
if a.empty?
return nil
else
begin
return ty.find(a)
rescue
return default
end
end
else
return default
end
end
|
TODO: Display original file, perhaps with diff, unpacked from storeuserconfig.tar or where-ever it is located? TODO: arma2.cfg, .armaprofile, bans.txt, server.cfg ?
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
|
# File 'lib/six-updater-web/app/controllers/config_controller.rb', line 4
def index
preset = nil
preset = fetch_param([:config], Sixconfig, preset)
setting = if preset && preset.appsetting
preset.appsetting
else
Appsetting.new
end
setting = fetch_param([:setting], Appsetting, setting)
path = setting.real_path.gsub("\\", "/")
@userconfigs = Dir.chdir(path) { Dir["userconfig/**/*"].reject {|e| File.directory?(e) || File.dirname(e)[/_[0-9]*$/]} }
@userconfigs += ["ban.txt"]
if setting.real_params =~ /-cfg=([\w\.]*)/
logger.info "Server Config: #{$1}"
@userconfigs += [$1]
end
cfg = params["options"] && params["options"]["userconfig"] ? params["options"]["userconfig"] : @userconfigs[0]
case params["commit"]
when "Edit"
redirect_to "/config/edit/?setting=#{params["setting"]}&options[userconfig]=#{params["options"]["userconfig"]}"
return
end
@userconfig = File.exists?(File.join(path, cfg)) ? File.open(File.join(path, cfg)) {|a| Iconv.new("utf-8//IGNORE//TRANSLIT", "utf-8").iconv(a.read + ' ')[0..-2].split("\n").map{|e| e.sub("\r", "")}.join("\n") } : ""
@setting = setting
end
|
40
41
42
43
44
45
|
# File 'lib/six-updater-web/app/controllers/config_controller.rb', line 40
def show
setting = Appsetting.find(params["setting"])
path = setting.real_path.gsub("\\", "/")
@userconfig = File.exists?(File.join(path, params["options"]["userconfig"])) ? File.open(File.join(path, params["options"]["userconfig"])) {|a| Iconv.new("utf-8//IGNORE//TRANSLIT", "utf-8").iconv(a.read + ' ')[0..-2].split("\n").map{|e| e.sub("\r", "")}.join("\n") } : ""
@setting = setting
end
|
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/six-updater-web/app/controllers/config_controller.rb', line 47
def update
path = Appsetting.find(params["setting"]).real_path.gsub("\\", "/")
case params["commit"]
when "Save"
if params["options"]
File.open(File.join(path, params["options"]["userconfig"]), 'w') {|a| a.write params["options"]["content"].gsub("\r", "") }
end
when "Reload"
redirect_to "/config/edit/?setting=#{params["setting"]}&options[userconfig]=#{params["options"]["userconfig"]}"
return
end
redirect_to "/config/show/?setting=#{params["setting"]}&options[userconfig]=#{params["options"]["userconfig"]}"
end
|