Project

General

Profile

« Previous | Next » 

Revision caa5fcf0

Added by Greg Sutcliffe about 12 years ago

  • ID caa5fcf0b6aabc8d69ceda82bf60cad060f8221d

Fix privacy leaks in stats, facts, and dashboard - fixes #1582

View differences:

app/controllers/dashboard_controller.rb
private
def prefetch_data
@hosts = Host.search_for(params[:search])
my_hosts = User.current.admin? ? Host : Host.my_hosts
@hosts = my_hosts.search_for(params[:search])
@report = {
:total_hosts => @hosts.count,
:bad_hosts => @hosts.recent.with_error.count,
app/controllers/fact_values_controller.rb
def index
begin
values = FactValue.no_timestamp_facts.search_for(params[:search],:order => params[:order])
# restrict allowed facts list based on the user permissions
my_facts = User.current.admin? ? FactValue : FactValue.my_facts
values = my_facts.no_timestamp_facts.search_for(params[:search],:order => params[:order])
rescue => e
error e.to_s
values = FactValue.no_timestamp_facts.search_for ""
app/controllers/statistics_controller.rb
class StatisticsController < ApplicationController
def index
@os_count = Host.count_distribution :operatingsystem
@arch_count = Host.count_distribution :architecture
@env_count = Host.count_distribution :environment
@klass_count = Host.count_habtm "puppetclass"
@cpu_count = FactValue.count_each "processorcount"
@model_count = FactValue.count_each "manufacturer"
@mem_size = FactValue.mem_average "memorysize"
@mem_free = FactValue.mem_average "memoryfree"
@swap_size = FactValue.mem_average "swapsize"
@swap_free = FactValue.mem_average "swapfree"
@mem_totsize = FactValue.mem_sum "memorysize"
@mem_totfree = FactValue.mem_sum "memoryfree"
my_hosts = User.current.admin? ? Host : Host.my_hosts
my_facts = User.current.admin? ? FactValue : FactValue.my_facts
@os_count = my_hosts.count_distribution :operatingsystem
@arch_count = my_hosts.count_distribution :architecture
@env_count = my_hosts.count_distribution :environment
@klass_count = my_hosts.count_habtm "puppetclass"
@cpu_count = my_facts.count_each "processorcount"
@model_count = my_facts.count_each "manufacturer"
@mem_size = my_facts.mem_average "memorysize"
@mem_free = my_facts.mem_average "memoryfree"
@swap_size = my_facts.mem_average "swapsize"
@swap_free = my_facts.mem_average "swapfree"
@mem_totsize = my_facts.mem_sum "memorysize"
@mem_totfree = my_facts.mem_sum "memoryfree"
respond_to do |format|
format.html
format.json do
app/models/fact_value.rb
scope :timestamp_facts, :joins => [:fact_name],
:conditions => ["fact_names.name = ?",:_timestamp]
scope :my_facts, lambda {
my_hosts = User.current.admin? ? Host : Host.my_hosts
conditions = sanitize_sql_for_conditions([" (fact_values.host_id in (?))",fhs = (my_hosts.map(&:id))])
{:conditions => conditions}
}
scope :distinct, { :select => 'DISTINCT "fact_values.value"' }
scope :required_fields, { :include => :host }
default_scope :order => 'LOWER(fact_values.value)'

Also available in: Unified diff