class MainController < ApplicationController def index @msg = [] @skip, @install, @check, @disabled = [], [], [], [] preset, queryserver, server, action, setting, reset, ok = nil, nil, nil, nil, nil, false, true grab = false save_fav = true @system_setting = SystemSetting.singleton @autoskip = @system_setting.autoskip @autoskip = true if @autoskip.nil? @beta = @system_setting.beta @server_bool = @system_setting.server_bool @server_check = false @inweb = @system_setting.inweb @queryserver = Queryserver.new if @system_setting.synchronized_at ok = false if @system_setting.synchronized_at > 30.minutes.ago end if ok @msg << "Auto Synchronize: " + begin @system_setting.sync rescue => e logger.debug "ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}" "FAILURE: #{$!}" end + "
" end gs_ok, gs_geo = true, true if @system_setting.gamespied_at gs_ok = false if @system_setting.gamespied_at > 30.minutes.ago end params["commit"] = "synchronize" if params["portalsync"] params["commit"] = "update_gamespy" if params["serversync"] unless params["commit"] params["commit"] = if gs_ok gs_geo = false "update_gamespy" else "none" end end case params["commit"].downcase when "none" grab = true save_fav = false when "exec" save_fav = false params["commit"] = "execute" when "synchronize" if !ok @msg << @system_setting.sync + "
" end grab = true when "show status" grab = true params["all"] = "" when "reset skip status" reset = true when "reset all mods skip status" reset = true grab = true params["all"] = "" when "update_gamespy" gslist_installed = begin %x[gslist -h] $? == 0 rescue false end if gslist_installed @msg << "Updating Gamespy...This will take a while, please wait until done!
" if gs_geo @system_setting.update_gamespy #(true) else @system_setting.update_gamespy_nogeo #(true) end else @msg << "ERROR: gslist tool is missing!
Please download from Six Updater Wagn, and put in #{SixUpdaterWeb::TOOL_PATH}
" end when "prune_gamespy" @msg << "Pruning Gamespy" Queryserver.prune when "clean_gamespy" @msg << "Cleaning Gamespy" Queryserver.clean when "purge_gamespy" d = false if params["really"] if params["really"]["sure"] == "1" Queryserver.purge @msg << "Purged Gamespy...
" d = true end end @msg << "ERROR: Please confirm by checking the checkbox
" if !d end begin preset = Sixconfig.find(@system_setting.favorite_preset) rescue begin preset = Sixconfig.find(:first) # Auto select preset? rescue end end begin queryserver = Queryserver.find(@system_setting.favorite_server) #server = Server.find(@system_setting.favorite_server) rescue end begin setting = Appsetting.find(@system_setting.favorite_settings_profile) rescue end begin action = Action.find(@system_setting.favorite_action) rescue end preset = fetch_param([:config], Sixconfig, preset) #server = fetch_param([:server], Server, server) action = fetch_param([:act], Action, action) setting = fetch_param([:setting], Appsetting, setting) queryserver = fetch_param([:gamespy], Queryserver, queryserver) if queryserver @queryserver = queryserver server = queryserver.dynamic_server end if params[:system] @beta = (params[:system][:beta] == "1") @server_bool = (params[:system][:server_bool] == "1") @autoskip = (params[:system][:autoskip] == "1") @inweb = (params[:system][:inweb] == "1") end if save_fav @system_setting.favorite_server = if queryserver #server queryserver.id unless queryserver.new_record? else nil end @system_setting.favorite_preset = if preset preset.id unless preset.new_record? else nil end @system_setting.favorite_action = if action action.id unless action.new_record? else nil end @system_setting.favorite_settings_profile = if setting setting.id unless setting.new_record? else nil end @system_setting.beta = @beta @system_setting.server_bool = @server_bool @system_setting.autoskip = @autoskip @system_setting.inweb = @inweb @system_setting.save end if grab if params["all"] preset = Sixconfig.new preset.name = "Dynamic" preset.mods += Mod.find(:all) end end if preset @msg << "Using preset: #{preset.name}" else @msg << "No preset selected!" act(setting, preset, action, server) return end unless params["all"] if server @msg << "Override server: #{queryserver.to_label}" else if preset.get_server server = preset.get_server @msg << "Preset server: #{server.to_label}" end end end if setting setting.beta = @beta setting.server = @server_bool @msg << "Override settings profile: #{setting.label}" else if preset.appsetting setting = preset.appsetting setting.beta = @beta setting.server = @server_bool @msg << "Preset settings profile: #{setting.label}" end end if action @msg << "Override action: #{action.name}" else if preset.action action = preset.action @msg << "Preset action: #{action.name}" end end if setting if setting.type.nil? || setting.type.empty? || setting.type == "Appsetting" setting.type = "Arma2Appsetting" setting.save setting = Appsetting.find(setting.id) end else setting = Arma2Appsetting.new(:beta => @beta, :server => @server_bool) end @msg << "Resetting skip status." if reset if setting.real_path unless File.directory?(setting.real_path) @msg << "
WARNING: ArmA folder not set or non existent: #{setting.real_path}" end else @msg << "
WARNING: ArmA folder not set or non existent: #{setting.real_path}" end if setting.modpath unless File.directory?(setting.real_modpath) @msg << "
WARNING: Mod installation folder not set or non existent: #{setting.real_modpath}" end end procs = setting.processes unless procs.empty? @msg << "
WARNING: There seem to be open arma processes: #{setting.real_exe}
Pids: #{procs}" end preset.all_mods(server).each do |mod| mod.update_version(setting.real_path) # TODO: this already runs in updater_yml, but there doesn't run if autoskip is disabled if reset && !@autoskip mod.skip = false else mod.update_skip if @autoskip end mod.save unless mod.new_record? mod.disabled = true if !mod.version_match?(setting) if mod.disabled @disabled << mod next end if mod.installed? || mod.exists?(setting) if mod.skip @skip << mod else @check << mod end else @install << mod end end case params["commit"].downcase when "edit preset" redirect_to "/sixconfigs/edit/#{preset.id}" return when "edit server" redirect_to "/queryservers/edit/#{queryserver.id}" return when "edit action" redirect_to "/actions/edit/#{action.id}" return when "edit setting" redirect_to "/appsettings/edit/#{setting.id}" return when "edit userconfig" redirect_to "/config/?setting=#{setting.id}" return when "server mod check" @server_check = true @signatures = queryserver.signatures @allowed, @disallowed, @garbage = *setting.allowance(@signatures) when "save" preset.output_yml(setting, server) @msg << "
Saved six-updater.yml!" when "execute" preset.execute(action, setting, server, @autoskip, @inweb) if @inweb sleep 1 redirect_to :action => 'logoutput' return end @msg << "
Saved six-updater.yml!
A window should open displaying the update process progress" when "stop game" setting.processes.each { |entry| @msg << "Process to be killed: #{entry}" } setting.kill! when "read mods" Mod.read_modfolders(setting) end @skip.sort! { |a, b| a.name <=> b.name } @check.sort! { |a, b| a.name <=> b.name } @install.sort! { |a, b| a.name <=> b.name } @disabled.sort! { |a, b| a.name <=> b.name } act(setting, preset, action, server) end def fetch @system_setting = SystemSetting.singleton setting = nil setting = Sixconfig.find(@system_setting.favorite_preset).appsetting unless @system_setting.favorite_preset.empty? setting = Arma2Appsetting.new unless setting @msg = [] case params["commit"].downcase when "rpt" lf = setting.logfile if lf.nil? @msg << "No logfile found!" else send_file(lf, {:filename => "#{setting.rpt}_#{Time.now.to_i}.log"}) end when "updater" f = "six-updater.log" lf = File.join(SixUpdaterWeb::DATA_PATH, "logs", f) if File.exists?(lf) send_file(lf, {:filename => "#{f}_#{Time.now.to_i}.log"}) else @msg << "No logfile found!" end when "updater-web" f = "six-updater-web.log" lf = File.join(SixUpdaterWeb::DATA_PATH, "logs", f) if File.exists?(lf) send_file(lf, {:filename => "#{f}_#{Time.now.to_i}.log"}) else @msg << "No logfile found!" end end end def reset @system_setting = SystemSetting.singleton @content = "" if params["system_setting"] @system_setting.server_username = params["system_setting"]["server_username"].strip @system_setting.server_password = params["system_setting"]["server_password"].strip @system_setting.save @content = @system_setting.sync end end def reset_act @msg = "" if params[:configuration] if params[:configuration][:reset] == "1" logger.info "Reloading configuration data!" @msg << "Reloaded configuration data!" Six::Dbmanager.reload_data end end if params[:system] if params[:system][:reset] == "1" logger.info "Reloading system data!" @msg << "Reloaded system data!" Six::Dbmanager.reload_system end end end def modlogs path = Appsetting.find(:first).real_modpath @cloghash = Hash.new Mod.find(:all).each do |mod| clog = File.join(path, mod.real_name, "changelog.txt") @cloghash[mod.real_name] = File.open(clog) { |f| f.readlines } if File.exists?(clog) end end def logoutput end def wave @waveid = "w+Qkgr-pVcG" end private def act(setting, preset, action, server) @current_setting = setting ? setting : Arma2Appsetting.new @preset = if @system_setting.favorite_preset begin Sixconfig.find(@system_setting.favorite_preset.to_s) rescue Sixconfig.new end else Sixconfig.new end @server = if @system_setting.favorite_server begin Server.find(@system_setting.favorite_server.to_s) rescue Server.new end else Server.new end @action = if @system_setting.favorite_action begin Action.find(@system_setting.favorite_action.to_s) rescue Action.new end else Action.new end @setting = if @system_setting.favorite_settings_profile begin Appsetting.find(@system_setting.favorite_settings_profile.to_s) rescue Appsetting.new end else Appsetting.new end =begin @preset = preset ? preset : Sixconfig.new @server = server ? server : Queryserver.new @action = action ? action : Action.new @setting = setting ? setting : Arma2Appsetting.new =end end 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 end