Project

General

Profile

Download (3.91 KB) Statistics
| Branch: | Tag: | Revision:
5563217a Ohad Levy
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
protect_from_forgery # See ActionController::RequestForgeryProtection for details

816b9c22 Ohad Levy
filter_parameter_logging :root_pass
a98d5dcf Ohad Levy
7fcd9832 Ohad Levy
# standard layout to all controllers
a944fa00 Ohad Levy
layout 'standard'
55ed30c7 Ohad Levy
helper 'layout'
46ac4aa8 Ohad Levy
6c6713de Ohad Levy
before_filter :require_ssl, :require_login
452d6329 Paul Kelly
before_filter :load_tabs, :manage_tabs
1ba05a93 Ohad Levy
46ac4aa8 Ohad Levy
def self.active_scaffold_controller_for(klass)
return FactNamesController if klass == Puppet::Rails::FactName
return FactValuesController if klass == Puppet::Rails::FactValue
return "#{klass}ScaffoldController".constantize rescue super
end
1ba05a93 Ohad Levy
cdd8bb6f Paul Kelly
# host list AJAX methods
# its located here, as it might be requested from the dashboard controller or via the hosts controller
def fact_selected
@fact_name_id = params[:search_fact_values_fact_name_id_eq].to_i
@fact_values = FactValue.find(:all, :select => 'DISTINCT value', :conditions => {
:fact_name_id => @fact_name_id }, :order => 'value ASC') if @fact_name_id > 0
render :partial => 'common/fact_selected', :layout => false
end

5f6b2196 Paul Kelly
def import_environments
ec, pc = Environment.count, Puppetclass.count
Environment.importClasses

flash[:foreman_notice] = "Environments old:#{ec} current:#{Environment.count}<br>PuppetClasses old:#{pc} current:#{Puppetclass.count}"
redirect_to :back
end

f2b00c3c Ohad Levy
protected
6c6713de Ohad Levy
def require_ssl
# if SSL is not configured, don't bother forcing it.
return true unless SETTINGS[:require_ssl]
# don't force SSL on localhost
return true if request.host=~/localhost|127.0.0.1/
# finally - redirect
redirect_to :protocol => 'https' and return if request.protocol != 'https' and not request.ssl?
end


1ba05a93 Ohad Levy
#Force a user to login if ldap authentication is enabled
def require_login
9c3ffb6b Ohad Levy
return true unless SETTINGS[:ldap]
1ba05a93 Ohad Levy
unless (session[:user] and (@user = User.find(session[:user])))
session[:original_uri] = request.request_uri
6874bbd9 Paul Kelly
redirect_to login_users_path
1ba05a93 Ohad Levy
end
end

f2b00c3c Ohad Levy
# returns current user
aa5a2230 Ohad Levy
def current_user
9925f8cf Ohad Levy
@user
aa5a2230 Ohad Levy
end

0265427b Ohad Levy
def invalid_request
cdd8bb6f Paul Kelly
render :text => 'Invalid query', :status => 400 and return
0265427b Ohad Levy
end

c6f1b718 Ohad Levy
def setgraph chart, data, options = {}
data[:labels].each {|l| chart.add_column *l }
chart.add_rows data[:values]
defaults = { :width => 400, :height => 240, :is3D => true,
:backgroundColor => "#E6DFCF", :legendBackgroundColor => "#E6DFCF" }

defaults.merge(options).each {|k,v| chart.send "#{k}=",v if chart.respond_to? k}
return chart
end

cdd8bb6f Paul Kelly
private
452d6329 Paul Kelly
def active_tab=(value); @active_tab = session[:controller_active_tabs][controller_name] = value; end

cdd8bb6f Paul Kelly
def load_tabs
452d6329 Paul Kelly
controller_tabs = session[:controller_tabs] ||= {}
@tabs = controller_tabs[controller_name] ||= {}
controller_active_tabs = session[:controller_active_tabs] ||= {}
@active_tab = controller_active_tabs[controller_name] ||= ""
cdd8bb6f Paul Kelly
end

def manage_tabs
452d6329 Paul Kelly
# Clear the active tab if jumping between different controller's
@controller_changed = session[:last_controller] != controller_name
session[:last_controller] = controller_name
self.active_tab = "" if @controller_changed

return if params[:tab_name].empty? or params[:action] != "index"
cdd8bb6f Paul Kelly
452d6329 Paul Kelly
if params[:tab_name] == "Reset"
self.active_tab = ""
elsif params[:remove_me] and @tabs.has_key? params[:tab_name]
cdd8bb6f Paul Kelly
@tabs.delete params[:tab_name]
452d6329 Paul Kelly
# If we delete the active tab then clear the active tab selection
if @active_tab == params[:tab_name]
self.active_tab = ""
else
# And redirect back as we do not want to perform the deleted tab's search
redirect_to :back
end
cdd8bb6f Paul Kelly
else
452d6329 Paul Kelly
self.active_tab = params[:tab_name]
cdd8bb6f Paul Kelly
@tabs[@active_tab] = params[:search]
end
end

5563217a Ohad Levy
end