diff --git a/.gitignore b/.gitignore
index 116b86805b0..179ad1679cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,14 +1,10 @@
*~
+.bundle
db/*.sqlite3
+log/*.log
+tmp/
db/schema.rb
-log/*
-nbproject/*
-tmp/*
config/settings.yaml
config/email.yaml
-tftp
-public/images/active_scaffold
-public/javascripts/active_scaffold
-public/stylesheets/active_scaffold
*.sw?
-.idea/*
+.idea
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 00000000000..ae0b70a9e34
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,32 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.10'
+gem "jquery-rails"
+gem 'json'
+gem 'rest-client', :require => 'rest_client'
+gem "acts_as_audited", "2.0.0"
+gem "has_many_polymorphs", :git => "https://github.com/jystewart/has_many_polymorphs.git"
+gem "will_paginate", "~> 3.0.2"
+gem "ancestry", "~> 1.2.4"
+
+gem 'sqlite3', :require => 'sqlite3'
+
+gem 'scoped_search', '>= 2.3.4'
+#group :provisioning do
+ gem "safemode", "1.0", :git => "https://github.com/svenfuchs/safemode.git"
+ gem "ruby2ruby"
+ gem "ruby_parser"
+ gem "virt", ">= 0.2.0"
+#end
+
+group :authentication do
+ gem 'net-ldap'
+end
+
+group :test, :development do
+ # To use debugger
+ gem 'ruby-debug'
+ gem 'mocha'
+ gem 'shoulda'
+ gem 'rr'
+end
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 00000000000..2957a0d6415
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,140 @@
+GIT
+ remote: https://github.com/jystewart/has_many_polymorphs.git
+ revision: 36f15d24ca4200f657a5203d9fc0253b58477705
+ specs:
+ has_many_polymorphs (3.0.0.beta1)
+ activerecord
+
+GIT
+ remote: https://github.com/svenfuchs/safemode.git
+ revision: 77d53c3c52718ec4634bc6e71ccd230188ba6c90
+ specs:
+ safemode (1.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.10)
+ actionpack (= 3.0.10)
+ mail (~> 2.2.19)
+ actionpack (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.5.0)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.10)
+ activesupport (= 3.0.10)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ arel (~> 2.0.10)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ activesupport (3.0.10)
+ acts_as_audited (2.0.0)
+ rails (>= 3.0.3)
+ ancestry (1.2.4)
+ activerecord (>= 2.2.2)
+ arel (2.0.10)
+ builder (2.1.2)
+ columnize (0.3.4)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ jquery-rails (1.0.16)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.1)
+ linecache (0.46)
+ rbx-require-relative (> 0.0.4)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ mocha (0.9.12)
+ net-ldap (0.2.2)
+ polyglot (0.3.3)
+ rack (1.2.4)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.10)
+ actionmailer (= 3.0.10)
+ actionpack (= 3.0.10)
+ activerecord (= 3.0.10)
+ activeresource (= 3.0.10)
+ activesupport (= 3.0.10)
+ bundler (~> 1.0)
+ railties (= 3.0.10)
+ railties (3.0.10)
+ actionpack (= 3.0.10)
+ activesupport (= 3.0.10)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.4)
+ rake (0.9.2.2)
+ rbx-require-relative (0.0.5)
+ rdoc (3.11)
+ json (~> 1.4)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rr (1.0.2)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ ruby2ruby (1.3.1)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
+ ruby_parser (2.3.1)
+ sexp_processor (~> 3.0)
+ scoped_search (2.3.5)
+ activerecord (>= 2.1.0)
+ sexp_processor (3.0.7)
+ shoulda (2.11.3)
+ sqlite3 (1.3.4)
+ thor (0.14.6)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ virt (0.2.0)
+ will_paginate (3.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ acts_as_audited (= 2.0.0)
+ ancestry (~> 1.2.4)
+ has_many_polymorphs!
+ jquery-rails
+ json
+ mocha
+ net-ldap
+ rails (= 3.0.10)
+ rest-client
+ rr
+ ruby-debug
+ ruby2ruby
+ ruby_parser
+ safemode (= 1.0)!
+ scoped_search (>= 2.3.4)
+ shoulda
+ sqlite3
+ virt (>= 0.2.0)
+ will_paginate (~> 3.0.2)
diff --git a/Rakefile b/Rakefile
index 3bb0e8592a4..0ca48f1bf07 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,10 +1,5 @@
-# Add your own tasks in files placed in lib/tasks ending in .rake,
-# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
-
+require File.expand_path('../config/application', __FILE__)
require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
+include Rake::DSL
-require 'tasks/rails'
+Foreman::Application.load_tasks
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0783d9195e8..29d1570bf43 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,10 +1,9 @@
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
+require 'foreman/controller/auto_complete_search'
class ApplicationController < ActionController::Base
protect_from_forgery # See ActionController::RequestForgeryProtection for details
rescue_from ScopedSearch::QueryNotSupported, :with => :invalid_search_query
- rescue_from Exception, :with => :generic_exception
+ #rescue_from Exception, :with => :generic_exception
rescue_from ActiveRecord::RecordNotFound, :with => :not_found
# standard layout to all controllers
@@ -60,10 +59,10 @@ def require_login
# JSON requests (REST API calls) use basic http authenitcation and should not use/store cookies
user = authenticate_or_request_with_http_basic { |u, p| User.try_to_login(u, p) }
User.current = user.is_a?(User) ? user : nil
- logger.warn("Failed authentcation from #{request.remote_ip} #{user}") if User.current.nil?
+ logger.warn("Failed authentication from #{request.remote_ip} #{user}") if User.current.nil?
return !User.current.nil?
end
- session[:original_uri] = request.request_uri # keep the old request uri that we can redirect later on
+ session[:original_uri] = request.fullpath # keep the old request uri that we can redirect later on
redirect_to login_users_path and return
else
# We assume we always have a user logged in, if authentication is disabled, the user is the build-in admin account.
@@ -76,7 +75,7 @@ def require_login
end
end
- # this method is returns the active user which gets used to puplate the audits table
+ # this method is returns the active user which gets used to populate the audits table
def current_user
User.current
end
@@ -129,6 +128,10 @@ def error error
flash[:error] = error
end
+ def warning warning
+ flash[:warning] = warning
+ end
+
# this method is used with nested resources, where obj_id is passed into the parameters hash.
# it automatically updates the search text box with the relevant relationship
# e.g. /hosts/fqdn/reports # would add host = fqdn to the search bar
@@ -174,7 +177,7 @@ def no_puppetclass_documentation_handler(exception)
if exception.message =~ /No route matches "\/puppet\/rdoc\/([^\/]+)\/classes\/(.+?)\.html/
render :template => "puppetclasses/no_route", :locals => {:environment => $1, :name => $2.gsub("/","::")}, :layout => false
else
- local_request? ? rescue_action_locally(exception) : rescue_action_in_public(exception)
+ request.local? ? request.rescue_action_locally(exception) : rescue_action_in_public(exception)
end
end
@@ -203,7 +206,7 @@ def process_error hash = {}
else
hash[:redirect] ||= eval("#{controller_name}_url")
end
- hash[:error_msg] ||= hash[:object].errors.on_base.to_a
+ hash[:error_msg] ||= hash[:object].errors[:base]
hash[:json_code] ||= :unprocessable_entity
logger.info "Failed to save: #{hash[:object].errors.full_messages.join(", ")}"
diff --git a/app/controllers/auth_source_ldaps_controller.rb b/app/controllers/auth_source_ldaps_controller.rb
index 8eb29a00470..6d42d27bb0b 100644
--- a/app/controllers/auth_source_ldaps_controller.rb
+++ b/app/controllers/auth_source_ldaps_controller.rb
@@ -1,6 +1,4 @@
class AuthSourceLdapsController < ApplicationController
- filter_parameter_logging :account_password
-
def index
@auth_source_ldaps = AuthSourceLdap.all
respond_to do |format|
diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb
index dcd3428bb24..cc9d024ff57 100644
--- a/app/controllers/bookmarks_controller.rb
+++ b/app/controllers/bookmarks_controller.rb
@@ -2,7 +2,7 @@ class BookmarksController < ApplicationController
before_filter :find_by_name, :only => %w{show edit update destroy}
def index
- @bookmarks = Bookmark.all.paginate(:page => params[:page])
+ @bookmarks = Bookmark.paginate(:page => params[:page])
respond_to do |format|
format.html
diff --git a/app/controllers/config_templates_controller.rb b/app/controllers/config_templates_controller.rb
index 6fe1e8bc858..5a4b0486a91 100644
--- a/app/controllers/config_templates_controller.rb
+++ b/app/controllers/config_templates_controller.rb
@@ -114,7 +114,7 @@ def build_pxe_default
# generated for
def pxe_default_combos
combos = []
- ConfigTemplate.template_kind_name_eq("provision").each do |template|
+ ConfigTemplate.joins(:template_kind).where("template_kinds.name" => "provision").each do |template|
template.template_combinations.each do |combination|
hostgroup = combination.hostgroup
if hostgroup and hostgroup.operatingsystem and hostgroup.architecture and hostgroup.medium
diff --git a/app/controllers/environments_controller.rb b/app/controllers/environments_controller.rb
index 5f4d08be339..569f4de7ef4 100644
--- a/app/controllers/environments_controller.rb
+++ b/app/controllers/environments_controller.rb
@@ -1,3 +1,5 @@
+require 'foreman/controller/environments'
+
class EnvironmentsController < ApplicationController
include Foreman::Controller::Environments
include Foreman::Controller::AutoCompleteSearch
diff --git a/app/controllers/fact_values_controller.rb b/app/controllers/fact_values_controller.rb
index e692817df67..1e4eeabbf4c 100644
--- a/app/controllers/fact_values_controller.rb
+++ b/app/controllers/fact_values_controller.rb
@@ -8,9 +8,6 @@ class FactValuesController < ApplicationController
before_filter :set_admin_user, :only => :create
before_filter :setup_search_options, :only => :index
- # avoids storing the facts data in the log files
- filter_parameter_logging :facts
-
def index
begin
values = FactValue.no_timestamp_facts.search_for(params[:search],:order => params[:order])
diff --git a/app/controllers/hostgroups_controller.rb b/app/controllers/hostgroups_controller.rb
index 59a4a8740e3..a08eafd6a5b 100644
--- a/app/controllers/hostgroups_controller.rb
+++ b/app/controllers/hostgroups_controller.rb
@@ -1,8 +1,9 @@
+require 'foreman/controller/host_details'
+
class HostgroupsController < ApplicationController
include Foreman::Controller::HostDetails
include Foreman::Controller::AutoCompleteSearch
- filter_parameter_logging :root_pass
before_filter :find_hostgroup, :only => [:show, :edit, :update, :destroy, :clone]
def index
diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb
index dbac4466601..3232e239f1d 100644
--- a/app/controllers/hosts_controller.rb
+++ b/app/controllers/hosts_controller.rb
@@ -1,3 +1,5 @@
+require 'foreman/controller/host_details'
+
class HostsController < ApplicationController
include Foreman::Controller::HostDetails
include Foreman::Controller::AutoCompleteSearch
@@ -10,7 +12,6 @@ class HostsController < ApplicationController
before_filter :set_admin_user, :only => ANONYMOUS_ACTIONS
before_filter :find_hosts, :only => :query
- before_filter :ajax_methods, :only => [:hostgroup_or_environment_selected]
before_filter :find_multiple, :only => [:update_multiple_parameters, :multiple_build,
:select_multiple_hostgroup, :select_multiple_environment, :multiple_parameters, :multiple_destroy,
:multiple_enable, :multiple_disable, :submit_multiple_disable, :submit_multiple_enable, :update_multiple_hostgroup,
@@ -18,7 +19,6 @@ class HostsController < ApplicationController
before_filter :find_by_name, :only => %w[show edit update destroy puppetrun setBuild cancelBuild report
reports facts storeconfig_klasses clone pxe_config toggle_manage]
- filter_parameter_logging :root_pass
helper :hosts, :reports
def index (title = nil)
@@ -35,8 +35,6 @@ def index (title = nil)
@hosts = search.paginate :page => params[:page], :include => included_associations
# SQL optimizations queries
@last_reports = Report.maximum(:id, :group => :host_id, :conditions => {:host_id => @hosts})
- @fact_kernels = FactValue.all(:select => "host_id, fact_values.value", :joins => [:host, :fact_name],
- :conditions => {"fact_values.host_id" => @hosts, "fact_names.name" => 'kernel'})
# rendering index page for non index page requests (out of sync hosts etc)
render :index if title and @title = title
end
@@ -79,8 +77,7 @@ def clone
new.puppetclasses = @host.puppetclasses
# Clone any parameters as well
@host.host_parameters.each{|param| new.host_parameters << param.clone}
- flash[:error_customisation] = {:header_message => nil, :class => "flash notice", :id => nil,
- :message => "The following fields will need reviewing:" }
+ flash[:warning] = "The following fields will need reviewing"
new.valid?
@host = new
render :action => :new
@@ -121,11 +118,13 @@ def destroy
end
# form AJAX methods
-
def hostgroup_or_environment_selected
- @environment = Environment.find(params[:environment_id]) if params[:environment_id].to_i > 0
- @hostgroup = Hostgroup.find(params[:hostgroup_id]) if params[:hostgroup_id].to_i > 0
- if @environment or @hostgroup
+ return head(:method_not_allowed) unless request.xhr?
+
+ @environment = Environment.find(params[:environment_id]) unless params[:environment_id].empty?
+ @hostgroup = Hostgroup.find(params[:hostgroup_id]) unless params[:hostgroup_id].empty?
+ @host = Host.find(params[:host_id]) if params[:host_id].to_i > 0
+ if @environment or @hostgroup
@host ||= Host.new
@host.hostgroup = @hostgroup if @hostgroup
@host.environment = @environment if @environment
@@ -262,7 +261,7 @@ def update_multiple_hostgroup
#update the hosts
@hosts.each do |host|
host.hostgroup=hg
- host.save(false)
+ host.save(:validate => false)
end
notice 'Updated hosts: Changed Hostgroup'
@@ -284,7 +283,7 @@ def update_multiple_environment
#update the hosts
@hosts.each do |host|
host.environment=ev
- host.save(false)
+ host.save(:validate => false)
end
notice 'Updated hosts: Changed Environment'
@@ -374,16 +373,15 @@ def process_hostgroup
@host.set_hostgroup_defaults
render :update do |page|
- page['host_environment_id'].value = @hostgroup.environment_id if @hostgroup.environment_id
+ page['*[id*=environment_id]'].val(@hostgroup.environment_id) if @hostgroup.environment_id
# process_hostgroup is only ever called for new host records therefore the assigned value can never be @hostgroup.puppetmaster_name
# This means that we should use the puppetproxy display type as new hosts should use this feature
- page['host_puppetproxy_id'].value = @hostgroup.puppetca? ? @hostgroup.puppetmaster.id : ""
- if @environment
- page.replace_html :puppet_klasses, :partial => 'puppetclasses/class_selection', :locals => {:obj => @host}
- end
+ page['*[id*=puppetproxy_id]'].val(@hostgroup.puppetca? ? @hostgroup.puppetmaster.id : "")
+
+ page['#puppet_klasses'].html(render(:partial => 'puppetclasses/class_selection', :locals => {:obj => @host})) if @environment
if SETTINGS[:unattended]
- page['host_root_pass'].value = @hostgroup.root_pass
+ page['*[id*=root_pass]'].val(@hostgroup.root_pass)
if (@hypervisor = @hostgroup.hypervisor)
@hypervisor.connect
# we are in a view context
@@ -392,19 +390,18 @@ def process_hostgroup
end
if @architecture
- page.replace_html :architecture_select, :partial => 'common/os_selection/architecture', :locals => {:item => @host}
- page['host_architecture_id'].value = @architecture.id
- end
- if @operatingsystem
- page.replace_html :operatingsystem_select, :partial => 'common/os_selection/operatingsystem', :locals => {:item => @host}
+ page['#os_select'].html(render(:partial => 'common/os_selection/architecture', :locals => {:item => @host}))
+ page['#*[id*=architecture_id]'].val(@architecture.id)
end
+
+ page['#media_select'].html(render(:partial => 'common/os_selection/operatingsystem', :locals => {:item => @host})) if @operatingsystem
+
if @domain
- page['host_domain_id'].value = @domain.id
+ page['*[id*=domain_id]'].val(@domain.id)
if @subnet
- page.replace_html(:host_subnet, :partial => 'common/domain', :locals => {:item => @host})
- page['host_subnet_id'].val("0").change
- page['host_subnet_id'].val("#{@subnet.id}").change
- page.replace_html(:sp_subnet, :partial => 'hosts/sp_subnet', :locals => {:item => @host})
+ page['#subnet_select'].html(render(:partial => 'common/domain', :locals => {:item => @host}))
+ page['#host_subnet_id'].val(@subnet.id).change
+ page['#sp_subnet'].html(render(:partial => 'hosts/sp_subnet', :locals => {:item => @host}))
end
end
end
@@ -459,7 +456,7 @@ def find_hosts
end unless klass.nil?
group.each do |k|
- list = Host.hostgroup_name_eq(k).send(state).map(&:name)
+ list = Host.joins(:hostgroup).where("hostgroups.name" => k).send(state).map(&:name)
@hosts = counter == 0 ? list : @hosts & list
counter +=1
end unless group.nil?
@@ -467,11 +464,6 @@ def find_hosts
not_found if @hosts.empty?
end
- def ajax_methods
- return head(:method_not_allowed) unless request.xhr?
- @host = Host.find(params[:id]) unless params[:id].empty?
- end
-
def load_vars_for_ajax
return unless @host
@environment = @host.environment
diff --git a/app/controllers/hypervisors/guests_controller.rb b/app/controllers/hypervisors/guests_controller.rb
index 63a291cbe4e..fbc70d94c0d 100644
--- a/app/controllers/hypervisors/guests_controller.rb
+++ b/app/controllers/hypervisors/guests_controller.rb
@@ -1,4 +1,4 @@
-require_dependency 'hypervisor/guest'
+require 'hypervisor/guest'
class Hypervisors::GuestsController < ApplicationController
before_filter :find_hypervisor
diff --git a/app/controllers/lookup_values_controller.rb b/app/controllers/lookup_values_controller.rb
index baa1c194623..176c814855b 100644
--- a/app/controllers/lookup_values_controller.rb
+++ b/app/controllers/lookup_values_controller.rb
@@ -3,7 +3,6 @@ class LookupValuesController < ApplicationController
before_filter :reject_non_json_requests
before_filter :find_by_id, :except => [:index, :create]
before_filter :setup_search_options, :only => :index
- filter_parameter_logging :value # might contain sensative information
def index
begin
diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb
index b8d7dc629ce..38fefc77e69 100644
--- a/app/controllers/media_controller.rb
+++ b/app/controllers/media_controller.rb
@@ -6,7 +6,7 @@ def index
values = Medium.search_for(params[:search], :order => params[:order])
respond_to do |format|
format.html { @media = values.paginate(:page => params[:page], :include => [:operatingsystems]) }
- format.json { render :json => values.as_json }
+ format.json { render :json => values }
end
end
diff --git a/app/controllers/operatingsystems_controller.rb b/app/controllers/operatingsystems_controller.rb
index 4fde5891839..6b0464731c4 100644
--- a/app/controllers/operatingsystems_controller.rb
+++ b/app/controllers/operatingsystems_controller.rb
@@ -35,7 +35,9 @@ def create
def edit
# Generates default OS template entries
@operatingsystem.config_templates.map(&:template_kind_id).uniq.each do |kind|
- @operatingsystem.os_default_templates.build(:template_kind_id => kind) if @operatingsystem.os_default_templates.template_kind_id_eq(kind).blank?
+ if @operatingsystem.os_default_templates.where(:template_kind_id => kind).blank?
+ @operatingsystem.os_default_templates.build(:template_kind_id => kind)
+ end
end if SETTINGS[:unattended]
end
diff --git a/app/controllers/puppetclasses_controller.rb b/app/controllers/puppetclasses_controller.rb
index 7cfac0ed322..617fd18d1bb 100644
--- a/app/controllers/puppetclasses_controller.rb
+++ b/app/controllers/puppetclasses_controller.rb
@@ -1,3 +1,5 @@
+require 'foreman/controller/environments'
+
class PuppetclassesController < ApplicationController
include Foreman::Controller::Environments
include Foreman::Controller::AutoCompleteSearch
@@ -56,23 +58,4 @@ def destroy
redirect_to puppetclasses_url
end
- # AJAX methods
-
- # adds a puppetclass to an existing host or hostgroup
- #
- # We assign the new puppetclasses (e.g. in the context of a Host or a Host Group)
- # via ajax and not java script as rendering javascript for each and every class
- # seems to be much longer than the average roundtrip time to the server
- # TODO: convert this to pure javascript then AJAX will not be required.
- def assign
- return unless request.xhr?
-
- type = params[:type]
- render :update do |page|
- page.insert_html :bottom, :selected_classes, :partial => 'selectedClasses', :locals => {:klass => @puppetclass, :type => type}
- page["selected_puppetclass_#{@puppetclass.id}"].highlight(5000)
- page["puppetclass_#{@puppetclass.id}"].hide
- end
- end
-
end
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb
index d697b8f6623..bf8bb2aa328 100644
--- a/app/controllers/reports_controller.rb
+++ b/app/controllers/reports_controller.rb
@@ -8,9 +8,6 @@ class ReportsController < ApplicationController
before_filter :set_admin_user, :only => :create
before_filter :setup_search_options, :only => :index
- # avoids storing the report data in the log files
- filter_parameter_logging :report
-
def index
values = Report.search_for(params[:search], :order => params[:order])
pagination_opts = { :page => params[:page], :per_page => params[:per_page] }
diff --git a/app/controllers/subnets_controller.rb b/app/controllers/subnets_controller.rb
index 299bd6adf1d..2e959c1fd5f 100644
--- a/app/controllers/subnets_controller.rb
+++ b/app/controllers/subnets_controller.rb
@@ -53,9 +53,8 @@ def freeip
respond_to do |format|
format.html do
render :update do |page|
- page['host_ip'].value = ip
- page['indicator'].hide
- page['host_ip'].visual_effect :highlight
+ page['#host_ip'].val(ip)
+ page['#host_ip'].show('highlight', 5000)
end
end
format.json { render :json => {:ip => ip} }
diff --git a/app/controllers/unattended_controller.rb b/app/controllers/unattended_controller.rb
index b42c3c2bba8..ebb62715eb5 100644
--- a/app/controllers/unattended_controller.rb
+++ b/app/controllers/unattended_controller.rb
@@ -2,14 +2,14 @@ class UnattendedController < ApplicationController
layout nil
# Methods which return configuration files for syslinux(pxe), pxegrub or g/ipxe
- PXE_CONFIG_URLS = [:pxe_kickstart_config, :pxe_debian_config, :pxemenu] + TemplateKind.name_like("pxelinux").map(&:name)
- PXEGRUB_CONFIG_URLS = [:pxe_jumpstart_config] + TemplateKind.name_like("pxegrub").map(&:name)
- GPXE_CONFIG_URLS = [:gpxe_kickstart_config] + TemplateKind.name_like("gpxe").map(&:name)
+ PXE_CONFIG_URLS = [:pxe_kickstart_config, :pxe_debian_config, :pxemenu] + TemplateKind.where("name LIKE ?","pxelinux").map(&:name)
+ PXEGRUB_CONFIG_URLS = [:pxe_jumpstart_config] + TemplateKind.where("name LIKE ?", "pxegrub").map(&:name)
+ GPXE_CONFIG_URLS = [:gpxe_kickstart_config] + TemplateKind.where("name LIKE ?", "gpxe").map(&:name)
CONFIG_URLS = PXE_CONFIG_URLS + GPXE_CONFIG_URLS + PXEGRUB_CONFIG_URLS
# Methods which return valid provision instructions, used by the OS
- PROVISION_URLS = [:kickstart, :preseed, :jumpstart ] + TemplateKind.name_like("provision").map(&:name)
+ PROVISION_URLS = [:kickstart, :preseed, :jumpstart ] + TemplateKind.where("name LIKE ?", "provision").map(&:name)
# Methods which returns post install instructions for OS's which require it
- FINISH_URLS = [:preseed_finish, :jumpstart_finish] + TemplateKind.name_like("finish").map(&:name)
+ FINISH_URLS = [:preseed_finish, :jumpstart_finish] + TemplateKind.where("name LIKE ?", "finish").map(&:name)
# We dont require any of these methods for provisioning
skip_before_filter :require_ssl, :require_login, :authorize
@@ -151,7 +151,7 @@ def unattended_local
safe_render config and return
end
type = "unattended_local/#{request.path.gsub("/#{controller_name}/","")}.local"
- render :template => type if File.exists?("#{RAILS_ROOT}/app/views/#{type}.rhtml")
+ render :template => type if File.exists?("#{Rails.root}/app/views/#{type}.rhtml")
end
def set_content_type
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 142cb271abb..3544be3fb27 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,7 +1,6 @@
class UsersController < ApplicationController
include Foreman::Controller::AutoCompleteSearch
- filter_parameter_logging :password, :password_confirmation
skip_before_filter :require_login, :only => [:login, :logout]
skip_before_filter :authorize, :only => [:login, :logout]
@@ -117,9 +116,9 @@ def logout
def auth_source_selected
render :update do |page|
if params[:auth_source_id] and AuthSource.find(params[:auth_source_id]).can_set_password?
- page.show 'password'
+ page['#password'].show
else
- page.hide 'password'
+ page['#password'].hide
end
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 4cadd8dcfb7..f6654854409 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -29,7 +29,7 @@ def link_to_add_fields(name, f, association, partial = nil, options = {})
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render((partial.nil? ? association.to_s.singularize + "_fields" : partial), :f => builder)
end
- link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"), options.merge({:class => "btn small info"}) )
+ link_to_function(name, ("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")").html_safe, options.merge({:class => "btn small info"}) )
end
def toggle_div divs
@@ -48,20 +48,11 @@ def toggle_div divs
end
def link_to_remove_puppetclass klass
- link_to_function "",:class=>"ui-icon ui-icon-minus" do |page|
- page["selected_puppetclass_#{klass.id}"].remove
- #TODO if the class is already selected, removing it will not add it to the avail class list
- page << "if ($('puppetclass_#{klass.id}')) {"
- page["puppetclass_#{klass.id}"].show
- page << "}"
- end
+ link_to_function "","remove_puppet_class(this)", :'data-class-id'=>klass.id, :class=>"ui-icon ui-icon-minus"
end
def link_to_add_puppetclass klass, type
- # link to remote is faster than inline js when having many classes
- link_to_remote "",
- {:url => assign_puppetclass_path(klass, :type => type),
- :position => {:after => {:success => "selected_classes" }}},{:class=>"ui-icon ui-icon-plus"}
+ link_to_function "", "add_puppet_class(this)", :'data-class-id'=>klass.id, :class=>"ui-icon ui-icon-plus"
end
def check_all_links(form_name)
@@ -146,7 +137,7 @@ def auto_complete_search(method, val,tag_options = {}, completion_options = {})
end
def help_path
- link_to "Help", :action => "help"
+ link_to "Help", :action => "welcome"
end
def edit_textfield(object, property, options={})
diff --git a/app/helpers/audits_helper.rb b/app/helpers/audits_helper.rb
index fafb91a6f88..598cfe34cf2 100644
--- a/app/helpers/audits_helper.rb
+++ b/app/helpers/audits_helper.rb
@@ -13,11 +13,11 @@ def audit_title audit
end
def audit_parent audit
- audit.try(:auditable_parent).try(:name)
+ audit.try(:associated).try(:name)
end
- def auditable_type audit
- audit.auditable_type.split("::").last
+ def association_type audit
+ audit.association_type.split("::").last if audit.association_type
end
def change_order action, value
diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb
index dbf3128e5f9..af0f865ecee 100644
--- a/app/helpers/dashboard_helper.rb
+++ b/app/helpers/dashboard_helper.rb
@@ -32,4 +32,10 @@ def render_run_distribution data, options = {}
data[:counter],
options
end
+
+ def searchable_links name, search
+ search += " and #{params[:search]}" unless params[:search].blank?
+ link_to name, hosts_path(:search => search)
+ end
+
end
diff --git a/app/helpers/hosts_helper.rb b/app/helpers/hosts_helper.rb
index 6864236c961..25e36ecd2d6 100644
--- a/app/helpers/hosts_helper.rb
+++ b/app/helpers/hosts_helper.rb
@@ -101,14 +101,6 @@ def selected? host
session[:selected].include?(host.id.to_s)
end
- def update_details_from_hostgroup
- return nil unless @host.new_record?
- remote_function(:url => { :action => "process_hostgroup" },
- :method => :post, :loading => "$('#indicator1').show()",
- :complete => "$('#indicator1').hide()",
- :with => "'hostgroup_id=' + value")
- end
-
def report_status_chart name, title, subtitle, data, options = {}
content_tag(:div, nil,
{ :id => name,
@@ -139,11 +131,10 @@ def runtime_chart name, title, subtitle, data, options = {}
def reports_show
return unless @host.reports.size > 0
form_tag @host, :id => 'days_filter', :method => :get do
- content_tag(:p, {}) { "Reports from the last " +
- select(nil, 'range', 1..days_ago(@host.reports.first.reported_at),
- {:selected => @range}, {:class=>"mini", :onchange =>"$('#days_filter').submit();$(this).disabled();"}) +
- " days - #{@host.reports.recent(@range.days.ago).count} reports found"
- }
+ content_tag(:span, "Reports from the last ") +
+ select(nil, 'range', 1..days_ago(@host.reports.first.reported_at),
+ {:selected => @range}, {:class=>"mini", :onchange =>"$('#days_filter').submit();$(this).disabled();"}).html_safe +
+ " days - #{@host.reports.recent(@range.days.ago).count} reports found"
end
end
diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb
index eee3642ee19..8057c880184 100644
--- a/app/helpers/layout_helper.rb
+++ b/app/helpers/layout_helper.rb
@@ -1,15 +1,15 @@
module LayoutHelper
def title(page_title, page_header = nil)
- @content_for_title = page_title.to_s
+ content_for(:title, page_title.to_s)
@page_header = page_header || @content_for_title
end
def title_actions *elements
- content_for(:title_actions) { elements.join(" ") }
+ content_for(:title_actions) { elements.join(" ").html_safe }
end
def search_bar *elements
- content_for(:search_bar) { elements.join(" ") }
+ content_for(:search_bar) { elements.join(" ").html_safe }
end
def stylesheet(*args)
@@ -20,25 +20,6 @@ def javascript(*args)
content_for(:head) { javascript_include_tag(*args) }
end
- def will_paginate(collection = nil, options = {})
- options.merge!(:class=>"span10 pagination fr")
- options[:renderer] ||= "WillPaginate::ViewHelpers::BootstrapLinkRenderer"
- options[:inner_window] ||= 3
- options[:outer_window] ||= 0
- super collection, options
- end
-
- def page_entries_info(collection, options = {})
- html = super(collection, options)
- html += options[:more] if options[:more]
- content_tag(
- :div,content_tag(
- :ul, content_tag(
- :li, link_to(html, "#")
- ), :style=>"float: left;"
- ), :class => "span6 pagination")
- end
-
def text_f(f, attr, options = {})
field(f, attr, options) do
f.text_field attr, options
@@ -83,29 +64,28 @@ def selectable_f(f, attr, array, select_options = {}, html_options = {})
def field(f, attr, options = {})
obj = f.object
- error = obj.errors.on(attr)
+ error = obj.errors[attr]
+ help_inline = content_tag(:span, (error.empty? ? options.delete(:help_inline) : error.to_sentence.html_safe), :class => "help-inline")
+ help_block = content_tag(:span, options.delete(:help_block), :class => "help-block")
content_tag :div, :class => "clearfix #{error.empty? ? "" : 'error'}" do
- f.label(attr, options.delete(:label)) +
+ f.label(attr, options.delete(:label)).html_safe +
content_tag(:div, :class => "input") do
- raw = ""
- raw += content_tag(:span, (error.empty? ? options[:help_inline] : error.to_a.to_sentence), :class => "help-inline")
- raw += content_tag(:span, options[:help_block], :class => "help-block")
- yield + raw
- end
+ yield.html_safe + help_inline.html_safe + help_block.html_safe
+ end.html_safe
end
end
def submit_or_cancel f
- "
" + content_tag(:p, :class => "ra") do
+ "
".html_safe + content_tag(:p, :class => "ra") do
link_to("Cancel", eval("#{controller_name}_path"), :class => "btn") + " " +
f.submit("Submit", :class => "btn primary")
end
end
def base_errors_for obj
- if errors = obj.errors.on(:base)
+ unless obj.errors[:base].blank?
content_tag(:div, :class => "alert-message block-message error base in fade", "data-alert" => true) do
- '×' + "
Old | New | ||||
---|---|---|---|---|---|
<%= h name.humanize %> | -<%= h audit_parent @audit %> | +<%= name.humanize %> | +<%= audit_parent @audit %> | <%# TODO: Refactor this whole code away from here -%> <% record = true if name =~ /.*_id$/ -%> <% if change.is_a?(Array) %> @@ -21,7 +21,7 @@ <% end -%> <% else -%> <% change = id_to_label(name,change) if record -%> - <%= change_order(@audit.action, change).map {|v| "#{h v} | "} -%> + <%= change_order(@audit.action, change).map{|v| "#{v} | "}.join.html_safe -%> <% end -%>
Data | ||
---|---|---|
<%= link_to 'Hosts that had performed modifications', active_hosts_path %> | +<%= searchable_links 'Hosts that had performed modifications', "last_report > \"#{Setting[:puppet_interval] + 5} minutes ago\" and (status.applied > 0 or status.restarted > 0)" %> | <%= @report[:active_hosts] %> |
<%= link_to 'Hosts in Error State', errors_hosts_path %> | +<%= searchable_links 'Hosts in Error State', "last_report > \"#{Setting[:puppet_interval] + 5} minutes ago\" and (status.failed > 0 or status.failed_restarts > 0)" %> | <%= @report[:bad_hosts] %> |
<%=link_to "Good Host Reports in the last #{Setting[:puppet_interval]} minutes", "hosts?search=last_report+>+'#{Setting[:puppet_interval]} minutes ago'+and+status.enabled+%3D+true+and+status.interesting++%3D+false"%> | +<%=searchable_links "Good Host Reports in the last #{Setting[:puppet_interval]} minutes", "last_report > \"#{Setting[:puppet_interval]} minutes ago\" and status.enabled = true and status.interesting=false" %> | <%= "#{@report[:good_hosts]} / #{@report[:total_hosts]}" %> hosts (<%= @report[:percentage] %>%) |
<%= link_to 'Out Of Sync Hosts', out_of_sync_hosts_path %> | +<%= searchable_links 'Out Of Sync Hosts', "last_report < \"#{Setting[:puppet_interval] + 5} minutes ago\" and status.enabled = true" %> | <%= @report[:out_of_sync_hosts] %> |
<%= link_to 'Hosts With No Reports', 'hosts?search=not+has+last_report' %> | +<%= searchable_links 'Hosts With No Reports', "not has last_report" %> | <%= @report[:reports_missing] %> |
<%= link_to 'Hosts With Alerts Disabled', disabled_hosts_path %> | +<%= searchable_links 'Hosts With Alerts Disabled', "status.enabled = false" %> | <%= @report[:disabled_hosts] %> |
<%= link_to "Back to host list", hosts_path %>
<% else -%> - <% form_tag update_multiple_parameters_hosts_path({:host_ids => params[:host_ids]}) do %> + <%= form_tag update_multiple_parameters_hosts_path({:host_ids => params[:host_ids]}) do %> <% for param in @parameters %><%= h title %> | +<%= title %> | <%= metric value %> |
Total | <%= metric (@totaltime || @report.runtime) %> |
---|
diff --git a/config.ru b/config.ru new file mode 100644 index 00000000000..be8d864a718 --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Foreman::Application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 00000000000..26c684c979f --- /dev/null +++ b/config/application.rb @@ -0,0 +1,57 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +# If you have a Gemfile, require the gems listed there, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) if defined?(Bundler) + +require File.expand_path('../../lib/timed_cached_store.rb', __FILE__) +require File.expand_path('../../lib/core_extensions', __FILE__) + +module Foreman + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Custom directories with classes and modules you want to be autoloadable. + # config.autoload_paths += %W(#{config.root}/extras) + config.autoload_paths += %W(#{config.root}/lib) + + # Only load the plugins named here, in the order given (default is alphabetical). + # :all can be used as a placeholder for all plugins not explicitly named. + # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + # Activate observers that should always be running. + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + config.active_record.observers = :host_observer + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + config.time_zone = 'UTC' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + # JavaScript files you want as :defaults (application.js is always included). + config.action_view.javascript_expansions[:defaults] = %w(jquery) + #config.action_view.javascript_expansions[:defaults] = %w(jquery rails) + + # Disable fieldWithErrors divs + config.action_view.field_error_proc = Proc.new {|html_tag, instance| "#{html_tag}" } + + # Configure the default encoding used in templates for Ruby 1.9. + config.encoding = "utf-8" + + # Configure sensitive parameters which will be filtered from the log file. + config.filter_parameters += [:password, :account_password, :facts, :root_pass, :value, :report, :password_confirmation] + + config.session_store :active_record_store + + # enables in memory cache store with ttl + config.cache_store = TimedCachedStore.new + end +end diff --git a/config/boot.rb b/config/boot.rb index 0ad0f787f86..4489e58688c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,110 +1,6 @@ -# Don't change this file! -# Configure your app in config/environment.rb and config/environments/*.rb +require 'rubygems' -RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -module Rails - class << self - def boot! - unless booted? - preinitialize - pick_boot.run - end - end - - def booted? - defined? Rails::Initializer - end - - def pick_boot - (vendor_rails? ? VendorBoot : GemBoot).new - end - - def vendor_rails? - File.exist?("#{RAILS_ROOT}/vendor/rails") - end - - def preinitialize - load(preinitializer_path) if File.exist?(preinitializer_path) - end - - def preinitializer_path - "#{RAILS_ROOT}/config/preinitializer.rb" - end - end - - class Boot - def run - load_initializer - Rails::Initializer.run(:set_load_path) - end - end - - class VendorBoot < Boot - def load_initializer - require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" - Rails::Initializer.run(:install_gem_spec_stubs) - Rails::GemDependency.add_frozen_gem_path - end - end - - class GemBoot < Boot - def load_initializer - self.class.load_rubygems - load_rails_gem - require 'initializer' - end - - def load_rails_gem - if version = self.class.gem_version - gem 'rails', version - else - gem 'rails' - end - rescue Gem::LoadError => load_error - $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) - exit 1 - end - - class << self - def rubygems_version - Gem::RubyGemsVersion rescue nil - end - - def gem_version - if defined? RAILS_GEM_VERSION - RAILS_GEM_VERSION - elsif ENV.include?('RAILS_GEM_VERSION') - ENV['RAILS_GEM_VERSION'] - else - parse_gem_version(read_environment_rb) - end - end - - def load_rubygems - require 'rubygems' - min_version = '1.3.1' - unless rubygems_version >= min_version - $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) - exit 1 - end - - rescue LoadError - $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) - exit 1 - end - - def parse_gem_version(text) - $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ - end - - private - def read_environment_rb - File.read("#{RAILS_ROOT}/config/environment.rb") - end - end - end -end - -# All that for this: -Rails.boot! +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/config/database.yml b/config/database.yml index 025d62a8d81..90d87cc295f 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,5 +1,5 @@ # SQLite version 3.x -# gem install sqlite3-ruby (not necessary on OS X Leopard) +# gem install sqlite3 development: adapter: sqlite3 database: db/development.sqlite3 diff --git a/config/environment.rb b/config/environment.rb index 97d12af3018..b2569e3dbe1 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,51 +1,5 @@ -# Be sure to restart your server when you modify this file +# Load the rails application +require File.expand_path('../application', __FILE__) -# Specifies gem version of Rails to use when vendor/rails is not present -RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION - -# Bootstrap the Rails environment, frameworks, and default configuration -require File.join(File.dirname(__FILE__), 'boot') - -Rails::Initializer.run do |config| - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{RAILS_ROOT}/extras ) - - # Specify gems that this application depends on and have them installed with rake gems:install - config.gem "safemode" - config.gem "rack", :version => '1.1.0' - config.gem "rest-client", :version => '>=1.4.0', :lib => "restclient" - config.gem "json" - # config.gem "bj" - # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" - # config.gem "sqlite3-ruby", :lib => "sqlite3" - # config.gem "aws-s3", :lib => "aws/s3" - - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - - # Skip frameworks you're not going to use. To use Rails without a database, - # you must remove the Active Record framework. - # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] - - # Activate observers that should always be running - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - config.active_record.observers = :host_observer - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. - config.time_zone = 'UTC' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] - # config.i18n.default_locale = :de - - # enables in memory cache store with ttl - config.cache_store = :timed_cached_store - # Disable fieldWithErrors divs - config.action_view.field_error_proc = Proc.new {|html_tag, instance| "#{html_tag}" } -end +# Initialize the rails application +Foreman::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 5ba272b08de..daf06c7ccb4 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,18 +1,26 @@ -# Settings specified here will take precedence over those in config/environment.rb +Foreman::Application.configure do + # Settings specified here will take precedence over those in config/application.rb -# In the development environment your application's code is reloaded on -# every request. This slows down response time but is perfect for development -# since you don't have to restart the webserver when you make code changes. -# Audit trail reads from cache, therefor for debugging this is required -config.cache_classes = false + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the webserver when you make code changes. + config.cache_classes = false -# Log error messages when you accidentally call methods on nil. -config.whiny_nils = true + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true -# Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true -config.action_view.debug_rjs = true -config.action_controller.perform_caching = false + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_view.debug_rjs = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Only use best-standards-support built into browsers + config.action_dispatch.best_standards_support = :builtin +end -# Don't care if the mailer can't send -config.action_mailer.raise_delivery_errors = false diff --git a/config/environments/production.rb b/config/environments/production.rb index 27119d2d18b..73e2507ec46 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,28 +1,49 @@ -# Settings specified here will take precedence over those in config/environment.rb +Foreman::Application.configure do + # Settings specified here will take precedence over those in config/application.rb -# The production environment is meant for finished, "live" apps. -# Code is not reloaded between requests -config.cache_classes = true + # The production environment is meant for finished, "live" apps. + # Code is not reloaded between requests + config.cache_classes = true -# Full error reports are disabled and caching is turned on -config.action_controller.consider_all_requests_local = false -config.action_controller.perform_caching = true -config.action_view.cache_template_loading = true + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true -# See everything in the log (default is :info) -# config.log_level = :debug + # Specifies the header that your server uses for sending files + config.action_dispatch.x_sendfile_header = "X-Sendfile" -# Use a different logger for distributed setups -# config.logger = SyslogLogger.new + # For nginx: + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' -# Use a different cache store in production -# config.cache_store = :mem_cache_store + # If you have no front-end server that supports something like X-Sendfile, + # just comment this out and Rails will serve the files -# Enable serving of images, stylesheets, and javascripts from an asset server -# config.action_controller.asset_host = "http://assets.example.com" + # See everything in the log (default is :info) + # config.log_level = :debug -# Disable delivery errors, bad email addresses will be ignored -# config.action_mailer.raise_delivery_errors = false + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new -# Enable threaded mode -# config.threadsafe! \ No newline at end of file + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # Disable Rails's static asset server + # In production, Apache or nginx will already do this + config.serve_static_assets = true + + # Enable serving of images, stylesheets, and javascripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable threaded mode + # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify +end diff --git a/config/environments/test.rb b/config/environments/test.rb index d9148ee88da..6c0688abe3f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,27 +1,35 @@ -# Settings specified here will take precedence over those in config/environment.rb -# The test environment is used exclusively to run your application's -# test suite. You never need to work with it otherwise. Remember that -# your test database is "scratch space" for the test suite and is wiped -# and recreated between test runs. Don't rely on the data there! -config.cache_classes = true - -# Log error messages when you accidentally call methods on nil. -config.whiny_nils = true - -# Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true -config.action_controller.perform_caching = false -config.action_view.cache_template_loading = true - -# Disable request forgery protection in test environment -config.action_controller.allow_forgery_protection = false - -# Tell Action Mailer not to deliver emails to the real world. -# The :test delivery method accumulates sent emails in the -# ActionMailer::Base.deliveries array. -config.action_mailer.delivery_method = :test - -# Use SQL instead of Active Record's schema dumper when creating the test database. -# This is necessary if your schema can't be completely dumped by the schema dumper, -# like if you have constraints or database-specific column types -# config.active_record.schema_format = :sql +Foreman::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + # Print deprecation notices to the stderr + config.active_support.deprecation = :stderr +end diff --git a/config/initializers/fix_already_loading_missing_dependencies.rb b/config/initializers/fix_already_loading_missing_dependencies.rb deleted file mode 100644 index f96dac016f4..00000000000 --- a/config/initializers/fix_already_loading_missing_dependencies.rb +++ /dev/null @@ -1,21 +0,0 @@ -module ActiveSupport - module Dependencies - extend self - - #def load_missing_constant(from_mod, const_name) - - def forgiving_load_missing_constant( from_mod, const_name ) - begin - old_load_missing_constant(from_mod, const_name) - rescue ArgumentError => arg_err - if arg_err.message == "#{from_mod} is not missing constant #{const_name}!" - return from_mod.const_get(const_name) - else - raise - end - end - end - alias :old_load_missing_constant :load_missing_constant - alias :load_missing_constant :forgiving_load_missing_constant - end -end \ No newline at end of file diff --git a/config/initializers/foreman.rb b/config/initializers/foreman.rb index 95c40f544c4..1a55ee4afcf 100644 --- a/config/initializers/foreman.rb +++ b/config/initializers/foreman.rb @@ -1,12 +1,10 @@ -require 'core_extensions' -require 'access_permissions' +require 'foreman' require 'puppet' require 'puppet/rails' - # import settings file -SETTINGS= YAML.load_file("#{RAILS_ROOT}/config/settings.yaml") +SETTINGS= YAML.load_file("#{Rails.root}/config/settings.yaml") -SETTINGS[:version] = "0.4" +SETTINGS[:version] = "0.5" SETTINGS[:unattended] = SETTINGS[:unattended].nil? || SETTINGS[:unattended] Puppet[:config] = SETTINGS[:puppetconfdir] || "/etc/puppet/puppet.conf" @@ -22,7 +20,7 @@ SETTINGS[:libvirt] = false end rescue LoadError - RAILS_DEFAULT_LOGGER.debug "Libvirt binding are missing - hypervisor management is disabled" + Rails.logger.debug "Libvirt binding are missing - hypervisor management is disabled" SETTINGS[:libvirt] = false end @@ -31,3 +29,5 @@ # We load the default settings for the roles if they are not already present Foreman::DefaultData::Loader.load(false) + +WillPaginate.per_page = Setting.entries_per_page rescue 20 diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index d531b8bb825..9e8b0131f8f 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format +# Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' diff --git a/config/initializers/new_rails_defaults.rb b/config/initializers/new_rails_defaults.rb deleted file mode 100644 index 8ec3186c84d..00000000000 --- a/config/initializers/new_rails_defaults.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# These settings change the behavior of Rails 2 apps and will be defaults -# for Rails 3. You can remove this initializer when Rails 3 is released. - -if defined?(ActiveRecord) - # Include Active Record class name as root for JSON serialized output. - ActiveRecord::Base.include_root_in_json = true - - # Store the full class name (including module namespace) in STI type column. - ActiveRecord::Base.store_full_sti_class = true -end - -# Use ISO 8601 format for JSON serialized times and dates. -ActiveSupport.use_standard_json_time_format = true - -# Don't escape HTML entities in JSON, leave that for the #json_escape helper. -# if you're including raw json in an HTML page. -ActiveSupport.escape_html_entities_in_json = false \ No newline at end of file diff --git a/config/initializers/puppet.rb b/config/initializers/puppet.rb index 689ced460a0..acba5626c35 100644 --- a/config/initializers/puppet.rb +++ b/config/initializers/puppet.rb @@ -12,8 +12,8 @@ class Puppet::Rails::FactName has_many :user_facts has_many :users, :through => :user_facts - named_scope :no_timestamp_fact, :conditions => ["fact_names.name <> ?",:_timestamp] - named_scope :timestamp_facts, :conditions => ["fact_names.name = ?", :_timestamp] + scope :no_timestamp_fact, :conditions => ["fact_names.name <> ?",:_timestamp] + scope :timestamp_facts, :conditions => ["fact_names.name = ?", :_timestamp] default_scope :order => 'LOWER(fact_names.name)' diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb new file mode 100644 index 00000000000..327b4073158 --- /dev/null +++ b/config/initializers/secret_token.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +Foreman::Application.config.secret_token = '1d53dcb00e724f72a15823d6939a2ee6f3b3ab3af7c47d074cefb1c9d3fe197cce3d0e2050a68d593f9275242d01658f3e9badd6221cf0e76e18896e4862358c' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 91c4a5a72ea..afea5dcdeaa 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,15 +1,8 @@ # Be sure to restart your server when you modify this file. -# Your secret key for verifying cookie session data integrity. -# If you change this key, all old sessions will become invalid! -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -ActionController::Base.session = { - :key => '_Foreman_session', - :secret => '4fe1a103699cf36976181cb4d343e6cb27d7904113c9a2113862c53b51f12357f413c996e820e6e544464242915d643d32b698a9679bbfe63f6eedfd9bf67961' -} +# Foreman::Application.config.session_store :cookie_store, :key => '_foreman_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information -# (create the session table with "rake db:sessions:create") -ActionController::Base.session_store = :active_record_store +# (create the session table with "rails generate session_migration") +Foreman::Application.config.session_store :active_record_store diff --git a/config/initializers/will_paginate.rb b/config/initializers/will_paginate.rb index 3482de9d9b9..9b397dcb90a 100644 --- a/config/initializers/will_paginate.rb +++ b/config/initializers/will_paginate.rb @@ -1,36 +1,27 @@ # config/initializers/will_paginate.rb +require 'will_paginate/array' module WillPaginate - module ViewHelpers + module ActionView class BootstrapLinkRenderer < LinkRenderer + protected - def to_html - links = @options[:page_links] ? visible_page_numbers.map {|n| page_link_or_span(n, '')} : [] - html = add_prev_next(links).join(@options[:separator]) - @options[:container] ? @template.content_tag(:div, @template.content_tag(:ul, html), html_attributes) : html + def html_container(html) + tag :div, tag(:ul, html), container_attributes end - protected - - # previous/next buttons - def add_prev_next(links) - prev_class = "prev" - next_class = "next" - prev_class += " disabled" if visible_page_numbers.first == current_page - next_class += " disabled" if visible_page_numbers.last == current_page - links.unshift page_link_or_span(visible_page_numbers.first == current_page ? current_page : @collection.previous_page, prev_class, @options[:previous_label]) - links.push page_link_or_span(visible_page_numbers.last == current_page ? current_page : @collection.next_page, next_class, @options[:next_label]) + def page_number(page) + tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page) end - def page_link_or_span(page, span_class, text = nil) - span_class ||="" - span_class += " active" if page and page == current_page - page_link page, text ||= page.to_s, :rel => rel_value(page), :class => span_class + def previous_or_next_page(page, text, classname) + tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('disabled' unless page)].join(' ') end - def page_link(page, text, attributes = {}) - @template.content_tag(:li, @template.link_to(text, url_for(page), attributes) ,attributes) + def gap + tag :li, link(super, '#'), :class => 'disabled' end + end end -end \ No newline at end of file +end diff --git a/config/locales/en.yml b/config/locales/en.yml index f265c068d89..a747bfa6987 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,4 +2,4 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: - hello: "Hello world" \ No newline at end of file + hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb index 953b1d6d3b3..702ff785f00 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,80 +1,235 @@ -ActionController::Routing::Routes.draw do |map| - map.root :controller => "dashboard" - - map.connect ':controller/help', :action => 'welcome' - - map.resources :reports, :collection => { :auto_complete_search => :get } - map.connect "node/:name", :controller => 'hosts', :action => 'externalNodes', - :requirements => { :name => /[^\.][\w\.-]+/ } - map.resources :hosts, - :requirements => {:id => /[^\/]+/}, - :member => { :report => :get, :clone => :get, :toggle_manage => :put, - :environment_selected => :post, :architecture_selected => :post, :os_selected => :post, - :storeconfig_klasses => :get, :externalNodes => :get, :setBuild => :get, :cancelBuild => :get, - :puppetrun => :get, :facts => :get, :pxe_config => :get }, - :collection => { :show_search => :get, :multiple_actions => :get, :multiple_parameters => :get, - :update_multiple_parameters => :post, :select_multiple_hostgroup => :get, - :update_multiple_hostgroup => :post, :select_multiple_environment => :get, :update_multiple_environment => :post, - :multiple_destroy => :get, :submit_multiple_destroy => :post, :multiple_build => :get, :submit_multiple_build => :post, - :reset_multiple => :get, :multiple_disable => :get, :submit_multiple_disable => :post, - :multiple_enable => :get, :submit_multiple_enable => :post, :auto_complete_search => :get, :template_used => :get, - :query => :get, :active => :get, :out_of_sync => :get, :errors => :get, :disabled => :get } do |hosts| - hosts.resources :reports, :requirements => {:host_id => /[^\/]+/}, :only => [:index, :show] - hosts.resources :facts, :requirements => {:host_id => /[^\/]+/}, :only => :index, :controller => :fact_values - hosts.resources :puppetclasses, :requirements => {:host_id => /[^\/]+/}, :only => :index - hosts.resources :lookup_keys, :requirements => {:host_id => /[^\/]+/}, :only => :show +Foreman::Application.routes.draw do + #ENC requests goes here + match "node/:name" => 'hosts#externalNodes', :constraints => { :name => /[^\.][\w\.-]+/ } + post "reports/create" + post "fact_values/create" + + resources :reports, :only => [:index, :show, :destroy] do + collection do + get 'auto_complete_search' + end end - map.dashboard '/dashboard', :controller => 'dashboard' - map.dashboard_auto_completer '/dashboard/auto_complete_search', :controller => 'hosts', :action => :auto_complete_search - map.statistics '/statistics', :controller => 'statistics' - map.resources :notices, :only => :destroy - map.resources :audits, :collection => {:auto_complete_search => :get} - if SETTINGS[:login] - map.resources :usergroups - map.resources :users, :collection => {:login => [:get, :post], :logout => :get, :auth_source_selected => :get, :auto_complete_search => :get} - map.resources :roles, :collection => {:report => [:get, :post], :auto_complete_search => :get} + + match '(:controller)/help', :action => 'welcome', :as => "help" + constraints(:id => /[^\/]+/) do + resources :hosts do + member do + get 'clone' + get 'storeconfig_klasses' + get 'externalNodes' + get 'setBuild' + get 'cancelBuild' + get 'puppetrun' + get 'pxe_config' + put 'toggle_manage' + post 'environment_selected' + end + collection do + get 'show_search' + get 'multiple_actions' + get 'multiple_parameters' + post 'update_multiple_parameters' + get 'select_multiple_hostgroup' + post 'update_multiple_hostgroup' + get 'select_multiple_environment' + post 'update_multiple_environment' + get 'multiple_destroy' + post 'submit_multiple_destroy' + get 'multiple_build' + post 'submit_multiple_build' + get 'reset_multiple' + get 'multiple_disable' + post 'submit_multiple_disable' + get 'multiple_enable' + post 'submit_multiple_enable' + get 'auto_complete_search' + get 'template_used' + get 'query' # Legacy query interface + get 'active' + get 'out_of_sync' + get 'errors' + get 'disabled' + post 'process_hostgroup' + post 'hostgroup_or_environment_selected' + post 'hypervisor_selected' + post 'architecture_selected' + post 'os_selected' + post 'domain_selected' + end + + constraints(:host_id => /[^\/]+/) do + resources :reports ,:only => [:index, :show] + resources :facts ,:only => :index, :controller => :fact_values + resources :puppetclasses ,:only => :index + resources :lookup_keys ,:only => :show + end + end + + resources :bookmarks, :except => [:show] + resources :lookup_keys, :except => [:new, :create] do + resources :lookup_values, :only => [:index, :create, :update, :destroy] + end + + resources :facts, :only => [:index, :show] do + constraints(:id => /[^\/]+/) do + resources :values, :only => :index, :controller => :fact_values, :as => "host_fact_values" + end + end + + resources :hypervisors do + constraints(:id => /[^\/]+/) do + resources :guests, :controller => "Hypervisors::Guests", :except => [:edit] do + member do + put 'power' + end + end + end + end if SETTINGS[:libvirt] end - if SETTINGS[:unattended] - map.resources :domains, :requirements => {:id => /[^\/]+/}, :collection => {:auto_complete_search => :get} - map.resources :operatingsystems, :member => {:bootfiles => :get}, :collection => {:auto_complete_search => :get} - map.resources :media, :collection => {:auto_complete_search => :get} - map.resources :models, :collection => {:auto_complete_search => :get} - map.resources :architectures, :collection => {:auto_complete_search => :get} - map.resources :ptables, :collection => {:auto_complete_search => :get} - map.resources :config_templates, :except => [:show], :collection => { :auto_complete_search => :get }, :requirements => { :id => /[^\/]+/ } - map.resources :subnets, :except => [:show], :collection => {:auto_complete_search => :get, :import => :get, :create_multiple => :post} - map.connect 'unattended/template/:id/:hostgroup', :controller => "unattended", :action => "template" + resources :settings, :only => [:index, :update] + resources :common_parameters do + collection do + get 'auto_complete_search' + end + end + resources :environments do + collection do + get 'import_environments' + post 'obsolete_and_new' + get 'auto_complete_search' + end + end + + resources :hostgroups do + member do + get 'nest' + get 'clone' + end + collection do + get 'auto_complete_search' + end + end + + resources :puppetclasses do + collection do + get 'import_environments' + get 'auto_complete_search' + end + constraints(:id => /[^\/]+/) do + resources :hosts + resources :lookup_keys, :except => [:show, :new, :create] + end + end + + resources :smart_proxies, :except => [:show] do + constraints(:id => /[^\/]+/) do + resources :puppetca, :controller => "SmartProxies::Puppetca", :only => [:index, :update, :destroy] + resources :autosign, :controller => "SmartProxies::Autosign", :only => [:index, :new, :create, :destroy] + end end - map.resources :lookup_keys, :except => [:new, :create], :requirements => {:id => /[^\/]+/} do |keys| - keys.resources :lookup_values, :only => [:index, :create, :update, :destroy] + resources :fact_values, :only => [:index] do + collection do + get 'auto_complete_search' + end end - map.resources :puppetclasses, :member => { :assign => :post }, :collection => {:import_environments => :get, :auto_complete_search => :get} do |pc| - pc.resources :hosts, :requirements => {:id => /[^\/]+/} - pc.resources :lookup_keys, :except => [:show, :new, :create], :requirements => {:id => /[^\/]+/} + + resources :notices, :only => :destroy + resources :audits do + collection do + get 'auto_complete_search' + end end - map.resources :hostgroups, :member => { :nest => :get, :clone => :get }, :collection => { :auto_complete_search => :get } - map.resources :common_parameters, :collection => {:auto_complete_search => :get} - map.resources :environments, :collection => {:import_environments => :get, :obsolete_and_new => :post, :auto_complete_search => :get} - map.resources :fact_values, :only => [:create, :index], :collection => { :auto_complete_search => :get } - map.resources :facts, :only => [:index, :show], :requirements => {:id => /[^\/]+/} do |facts| - facts.resources :values, :requirements => {:id => /[^\/]+/}, :only => :index, :controller => :fact_values + + if SETTINGS[:login] + resources :usergroups + resources :users do + collection do + get 'login' + post 'login' + get 'logout' + get 'auth_source_selected' + get 'auto_complete_search' + end + end + resources :roles do + collection do + get 'report' + post 'report' + get 'auto_complete_search' + end + end + + resources :auth_source_ldaps end - map.resources :auth_source_ldaps - map.resources :smart_proxies, :except => [:show] do |proxy| - proxy.resources :puppetca, :controller => "SmartProxies::Puppetca", :only => [:index, :update, :destroy], :requirements => { :id => /[^\.][\w\.-]+/ } - proxy.resources :autosign, :controller => "SmartProxies::Autosign", :only => [:index, :new, :create, :destroy], :requirements => { :id => /[^\.][\w\.-]+/ } + + if SETTINGS[:unattended] + constraints(:id => /[^\/]+/) do + resources :domains do + collection do + get 'auto_complete_search' + end + end + resources :config_templates, :except => [:show] do + collection do + get 'auto_complete_search' + get 'build_pxe_default' + end + end + end + + resources :operatingsystems do + member do + get 'bootfiles' + end + collection do + get 'auto_complete_search' + end + end + resources :media do + collection do + get 'auto_complete_search' + end + end + + resources :models do + collection do + get 'auto_complete_search' + end + end + + resources :architectures do + collection do + get 'auto_complete_search' + end + end + + resources :ptables do + collection do + get 'auto_complete_search' + end + end + + resources :subnets, :except => [:show] do + collection do + get 'auto_complete_search' + get 'import' + post 'create_multiple' + post 'freeip' + end + end + + match 'unattended/template/:id/:hostgroup', :to => "unattended#template" end - map.resources :hypervisors, :requirements => { :id => /[^\/]+/ } do |hypervisor| - hypervisor.resources :guests, :controller => "Hypervisors::Guests", :except => [:edit], - :member => {:power => :put}, :requirements => { :id => /[^\.][\w\.-]+/ } - end if SETTINGS[:libvirt] - map.resources :bookmarks, :except => [:show], :requirements => { :id => /[^\/]+/ } - map.resources :settings, :only => [:index, :update] - map.connect '/status', :controller => "home", :action => "status" - - #default - map.connect ':controller/:action/:id' - map.connect ':controller/:action/:id.:format' + + root :to => 'dashboard#index' + match 'dashboard', :to => 'dashboard#index', :as => "dashboard" + match 'dashboard/auto_complete_search', :to => 'hosts#auto_complete_search', :as => "auto_complete_search_dashboards" + match 'statistics', :to => 'statistics#index', :as => "statistics" + match 'home/status', :to => 'home#status' + + # match for all unattended scripts + match 'unattended/(:action/(:id(.format)))', :controller => 'unattended' + end diff --git a/config/routes.rb.rails2 b/config/routes.rb.rails2 new file mode 100644 index 00000000000..72f502fd6ba --- /dev/null +++ b/config/routes.rb.rails2 @@ -0,0 +1,8 @@ +ActionController::Routing::Routes.draw do |map| + + map.connect '/status', :controller => "home", :action => "status" + + #default + map.connect ':controller/:action/:id' + map.connect ':controller/:action/:id.:format' +end diff --git a/config/settings.yaml b/config/settings.yaml deleted file mode 100644 index a9fcf8341ea..00000000000 --- a/config/settings.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -#:modulepath: /etc/puppet/modules/ -:tftppath: tftp/ -#:rrd_report_url: report/ -#:ldap: true -#your default puppet server - can be overridden in the host level -#if none specified, plain "puppet" will be used. -#:puppet_server: puppet -#:unattended: false -#use the following setting to override the default 30 minutes puppet run interval - value must be in minutes -#:puppet_interval: 60 -#:document_root: /var/www diff --git a/db/migrate/20090715143858_create_architectures.rb b/db/migrate/20090715143858_create_architectures.rb index 77eedfda4b7..0f29b204753 100644 --- a/db/migrate/20090715143858_create_architectures.rb +++ b/db/migrate/20090715143858_create_architectures.rb @@ -10,8 +10,6 @@ def self.up t.references :operatingsystem, :null => false end - Architecture.create :name => "x86_64" - Architecture.create :name => "i386" end def self.down diff --git a/db/migrate/20100629093200_create_roles.rb b/db/migrate/20100629093200_create_roles.rb index 24d9be0f583..8f6cd6313e3 100644 --- a/db/migrate/20100629093200_create_roles.rb +++ b/db/migrate/20100629093200_create_roles.rb @@ -2,15 +2,15 @@ class CreateRoles < ActiveRecord::Migration def self.up add_column :users, :role_id, :integer create_table "roles", :force => true do |t| - t.column "name", :string, :limit => 30 - t.column "builtin", :integer - t.column "permissions", :text + t.string "name", :limit => 30 + t.integer "builtin" + t.text "permissions" end create_table :user_roles do |t| - t.column :user_id, :integer - t.column :role_id, :integer - t.columm :inherited_from, :integer + t.integer :user_id + t.integer :role_id + t.integer :inherited_from end end diff --git a/db/migrate/20111124095053_rename_changes_to_audited_changes.rb b/db/migrate/20111124095053_rename_changes_to_audited_changes.rb new file mode 100644 index 00000000000..f0bde3df0c4 --- /dev/null +++ b/db/migrate/20111124095053_rename_changes_to_audited_changes.rb @@ -0,0 +1,9 @@ +class RenameChangesToAuditedChanges < ActiveRecord::Migration + def self.up + rename_column :audits, :changes, :audited_changes + end + + def self.down + rename_column :audits, :audited_changes, :changes + end +end diff --git a/db/migrate/20111124095054_add_remote_address_to_audits.rb b/db/migrate/20111124095054_add_remote_address_to_audits.rb new file mode 100644 index 00000000000..0dcf94d6d6e --- /dev/null +++ b/db/migrate/20111124095054_add_remote_address_to_audits.rb @@ -0,0 +1,10 @@ +class AddRemoteAddressToAudits < ActiveRecord::Migration + def self.up + add_column :audits, :remote_address, :string + end + + def self.down + remove_column :audits, :remote_address + end +end + diff --git a/db/migrate/20111124095055_rename_parent_to_association.rb b/db/migrate/20111124095055_rename_parent_to_association.rb new file mode 100644 index 00000000000..b298d65cd4e --- /dev/null +++ b/db/migrate/20111124095055_rename_parent_to_association.rb @@ -0,0 +1,11 @@ +class RenameParentToAssociation < ActiveRecord::Migration + def self.up + rename_column :audits, :auditable_parent_id, :association_id + rename_column :audits, :auditable_parent_type, :association_type + end + + def self.down + rename_column :audits, :association_type, :auditable_parent_type + rename_column :audits, :association_id, :auditable_parent_id + end +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 00000000000..a5500da3155 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,9 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) +# Mayor.create(:name => 'Daley', :city => cities.first) +Architecture.create :name => "x86_64" +Architecture.create :name => "i386" diff --git a/doc/README_FOR_APP b/doc/README_FOR_APP new file mode 100644 index 00000000000..fe41f5cc24d --- /dev/null +++ b/doc/README_FOR_APP @@ -0,0 +1,2 @@ +Use this README file to introduce your application and point to useful places in the API for learning more. +Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. diff --git a/lib/core_extensions.rb b/lib/core_extensions.rb index 5c3f3c9f78c..12e6fd6667a 100644 --- a/lib/core_extensions.rb +++ b/lib/core_extensions.rb @@ -27,16 +27,18 @@ def update_single_attribute(attribute, value) "#{self.class.name} Attribute Update" ) end - class Ensure_not_used_by - def initialize(*attribute) + + # ActiveRecord Callback class + class EnsureNotUsedBy + def initialize *attribute @klasses = attribute - @logger = RAILS_DEFAULT_LOGGER + @logger = Rails.logger end def before_destroy(record) for klass in @klasses - for what in eval "record.#{klass.to_s}" - record.errors.add_to_base(record.to_label + " is used by " + what.to_s) + for what in record.send(klass.to_sym) + record.errors.add :base, "#{record} is used by #{what}" end end unless record.errors.empty? @@ -54,16 +56,14 @@ def id_and_type alias_attribute :to_label, :name alias_attribute :to_s, :to_label - def self.per_page - Setting["entries_per_page"] - end - def self.unconfigured? first.nil? end end + + module ExemptedFromLogging def process(request, *args) logger.silence { super } @@ -86,16 +86,3 @@ def to_gb end end end -module ActionView::Helpers::ActiveRecordHelper - def error_messages_for_with_customisation(*params) - if flash[:error_customisation] - if params[-1].is_a? Hash - params[-1].update flash[:error_customisation] - else - params << flash[:error_customisation] - end - end - error_messages_for_without_customisation(*params) - end - alias_method_chain :error_messages_for, :customisation -end diff --git a/lib/foreman.rb b/lib/foreman.rb new file mode 100644 index 00000000000..2920ff93bbe --- /dev/null +++ b/lib/foreman.rb @@ -0,0 +1,9 @@ +require 'foreman/access_permissions' +require 'foreman/default_data/loader' +require 'foreman/default_settings/loader' +require 'foreman/renderer' +require 'foreman/controller' +require 'net' + +module Foreman +end diff --git a/lib/access_permissions.rb b/lib/foreman/access_permissions.rb similarity index 100% rename from lib/access_permissions.rb rename to lib/foreman/access_permissions.rb diff --git a/lib/foreman/controller.rb b/lib/foreman/controller.rb new file mode 100644 index 00000000000..7356a843d1b --- /dev/null +++ b/lib/foreman/controller.rb @@ -0,0 +1,2 @@ +module Foreman::Controller +end diff --git a/lib/foreman/controller/environments.rb b/lib/foreman/controller/environments.rb index 07c96398844..e5c44c95b54 100644 --- a/lib/foreman/controller/environments.rb +++ b/lib/foreman/controller/environments.rb @@ -5,7 +5,7 @@ module Foreman::Controller::Environments def import_environments @changed = Environment.importClasses if @changed["new"].size > 0 or @changed["obsolete"].size > 0 - render :partial => "common/puppetclasses_or_envs_changed", :layout => true + render "common/_puppetclasses_or_envs_changed" else notice "No changes to your environments detected" redirect_to "/" + controller_path diff --git a/lib/foreman/controller/host_details.rb b/lib/foreman/controller/host_details.rb index a6343fdcbfc..d6de790c482 100644 --- a/lib/foreman/controller/host_details.rb +++ b/lib/foreman/controller/host_details.rb @@ -40,7 +40,7 @@ def use_image_selected end def hypervisor_selected - hypervisor_id = params["#{item_name}_hypervisor_id".to_sym].to_i + hypervisor_id = params["hypervisor_id".to_sym].to_i # bare metal selected hypervisor_defaults and return if hypervisor_id == 0 @@ -88,7 +88,7 @@ def item_object end def update_hypervisor_details item, page - page.replace_html :virtual_machine, :partial => "common/hypervisor", :locals => { :item => item } + page['#virtual_machine'].html(render(:partial => "common/hypervisor", :locals => { :item => item })) page << "if ($('#host_mac')) $('#host_mac').parentsUntil('.clearfix').parent().remove()" end diff --git a/lib/foreman/default_data/loader.rb b/lib/foreman/default_data/loader.rb index aca32cedc01..f9dd537410f 100644 --- a/lib/foreman/default_data/loader.rb +++ b/lib/foreman/default_data/loader.rb @@ -35,27 +35,27 @@ def load(reset=false) Role.count rescue return Role.transaction do # Roles - manager = Role.name_is("Manager").empty? ? Role.create(:name => "Manager") : Role.name_is("Manager")[0] + manager = Role.where(:name => "Manager").empty? ? Role.create(:name => "Manager") : Role.where(:name => "Manager")[0] if reset or manager.permissions.empty? manager.update_attribute :permissions, manager.setable_permissions.collect {|p| p.name} end - ptable_editor = Role.name_is("Edit partition tables").empty? ? Role.create(:name => "Edit partition tables") : Role.name_is("Edit partition tables")[0] + ptable_editor = Role.where(:name => "Edit partition tables").empty? ? Role.create(:name => "Edit partition tables") : Role.where(:name => "Edit partition tables")[0] if reset or ptable_editor.permissions.empty? ptable_editor.update_attribute :permissions, [:view_ptables, :create_ptables, :edit_ptables, :destroy_ptables] end - hosts_reader = Role.name_is("View hosts").empty? ? Role.create(:name => "View hosts") : Role.name_is("View hosts")[0] + hosts_reader = Role.where(:name => "View hosts").empty? ? Role.create(:name => "View hosts") : Role.where(:name => "View hosts")[0] if reset or hosts_reader.permissions.empty? hosts_reader.update_attribute :permissions, [:view_hosts] end - hosts_editor = Role.name_is("Edit hosts").empty? ? Role.create(:name => "Edit hosts") : Role.name_is("Edit hosts")[0] + hosts_editor = Role.where(:name => "Edit hosts").empty? ? Role.create(:name => "Edit hosts") : Role.where(:name => "Edit hosts")[0] if reset or hosts_editor.permissions.empty? hosts_editor.update_attribute :permissions, [:view_hosts, :edit_hosts, :create_hosts, :destroy_hosts, :build_hosts] end - viewer = Role.name_is("Viewer").empty? ? Role.create(:name => "Viewer") : Role.name_is("Viewer")[0] + viewer = Role.where(:name => "Viewer").empty? ? Role.create(:name => "Viewer") : Role.where(:name => "Viewer")[0] if reset or viewer.permissions.empty? viewer.update_attribute :permissions, [:view_hosts, :view_puppetclasses, @@ -83,7 +83,7 @@ def load(reset=false) :view_audit_logs] end - siteman = Role.name_is("Site manager").empty? ? Role.create(:name => "Site manager") : Role.name_is("Site manager")[0] + siteman = Role.where(:name => "Site manager").empty? ? Role.create(:name => "Site manager") : Role.where(:name => "Site manager")[0] if reset or siteman.permissions.empty? siteman.update_attribute :permissions, [ :view_architectures, :view_audit_logs, diff --git a/lib/foreman/default_settings/loader.rb b/lib/foreman/default_settings/loader.rb index 5fcfd874233..4c220dd4bbe 100644 --- a/lib/foreman/default_settings/loader.rb +++ b/lib/foreman/default_settings/loader.rb @@ -44,7 +44,7 @@ def load(reset=false) set('puppet_interval', "Puppet interval in minutes", 30 ), set('default_puppet_environment',"The Puppet environment foreman would default to in case it can't auto detect it", "production"), set('modulepath',"The Puppet default module path in case that Foreman can't auto detect it", "/etc/puppet/modules"), - set('document_root', "Document root where puppetdoc files should be created", "#{RAILS_ROOT}/public/puppet/rdoc"), + set('document_root', "Document root where puppetdoc files should be created", "#{Rails.root}/public/puppet/rdoc"), set('puppetrun', "Enables Puppetrun Support", false), set('puppet_server', "Default Puppet Server hostname", "puppet"), set('failed_report_email_notification', "Enable Email Alerts per each failed puppet report", false), diff --git a/lib/foreman/renderer.rb b/lib/foreman/renderer.rb index 28fd585d13d..7241abb4e5c 100644 --- a/lib/foreman/renderer.rb +++ b/lib/foreman/renderer.rb @@ -9,6 +9,7 @@ def render_safe template, allowed_methods = [], allowed_vars = {} ERB.new(template, nil, '-').result(binding) end end + #returns the URL for Foreman Built status (when a host has finished the OS installation) def foreman_url(action = "built") url_for :only_path => false, :controller => "unattended", :action => action @@ -16,7 +17,7 @@ def foreman_url(action = "built") # provide embedded snippets support as simple erb templates def snippets(file) - unless ConfigTemplate.name_eq(file).snippet_eq(true).empty? + unless ConfigTemplate.where(:name => file, :snippet => true).empty? return snippet(file.gsub(/^_/,"")) else render :partial => "unattended/snippets/#{file}" @@ -24,7 +25,7 @@ def snippets(file) end def snippet name - if template = ConfigTemplate.name_eq(name).snippet_eq(true).first + if template = ConfigTemplate.where(:name => name, :snippet => true).first logger.debug "rendering snippet #{template.name}" begin return unattended_render(template.template) diff --git a/lib/net.rb b/lib/net.rb index 5f3910046fe..698010f3cd1 100644 --- a/lib/net.rb +++ b/lib/net.rb @@ -1,3 +1,5 @@ +require "net/validations" + module Net class Record include Net::Validations diff --git a/lib/proxy_api.rb b/lib/proxy_api.rb index 5a7bad7288a..68c0231e0e7 100644 --- a/lib/proxy_api.rb +++ b/lib/proxy_api.rb @@ -31,7 +31,7 @@ def initialize(args) @resource = RestClient::Resource.new(url, connect_params) end - def logger; RAILS_DEFAULT_LOGGER; end + def logger; Rails.logger; end private diff --git a/lib/tasks/.gitkeep b/lib/tasks/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/lib/tasks/convert.rake b/lib/tasks/convert.rake index 269dc383f84..9f2e39e4db8 100644 --- a/lib/tasks/convert.rake +++ b/lib/tasks/convert.rake @@ -98,7 +98,7 @@ namespace :db do models.each do |model| new_model = DevelopmentModelClass.new(model.attributes) new_model.id = model.id - new_model.save(false) + new_model.save(:validate => false) end end break if args.records and args.records.to_i > offset diff --git a/lib/tasks/model.rake b/lib/tasks/model.rake index 4e1415f7ae1..10dffcf337f 100644 --- a/lib/tasks/model.rake +++ b/lib/tasks/model.rake @@ -66,7 +66,7 @@ def consolidate mappings, dryrun end unless dryrun model.hosts << valid_hosts - model.save(false) + model.save(:validate => false) if model.errors.empty? original.delete if original.hosts.count == 0 else diff --git a/lib/timed_cached_store.rb b/lib/timed_cached_store.rb index b7eceed9fa9..348602764b9 100644 --- a/lib/timed_cached_store.rb +++ b/lib/timed_cached_store.rb @@ -3,7 +3,7 @@ # it has a similar behaviour to memcached, but does not require memcache # however this will not clean up automatically, only upon request -class TimedCachedStore < ActiveSupport::Cache::SynchronizedMemoryStore +class TimedCachedStore < ActiveSupport::Cache::MemoryStore def exist?(name, options = nil) delete_if_expired name super @@ -52,4 +52,4 @@ def ts_field name "#{name}_timestamp" end -end \ No newline at end of file +end diff --git a/log/.gitkeep b/log/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/public/404.html b/public/404.html index eff660b90c3..9a48320a5f1 100644 --- a/public/404.html +++ b/public/404.html @@ -1,23 +1,19 @@ - - - - + + - |
t |
Ruby | -<%=h frames.first.filename %> : in <%=h frames.first.function %> , line <%=h frames.first.lineno %> |
-
---|---|
Web | -<%=h req.request_method %> <%=h(req.host + path)%> |
-
<%=h frame.filename %>
: in <%=h frame.function %>
-
- <% if frame.context_line %>
- Variable | -Value | -
---|---|
<%=h key %> | -<%=h val.inspect %> |
-
No GET data.
- <% end %> - -Variable | -Value | -
---|---|
<%=h key %> | -<%=h val.inspect %> |
-
No POST data.
- <% end %> - - -Variable | -Value | -
---|---|
<%=h key %> | -<%=h val.inspect %> |
-
No cookie data.
- <% end %> - -Variable | -Value | -
---|---|
<%=h key %> | -<%=h val %> |
-
- You're seeing this error because you use Rack::ShowExceptions
.
-
Request Method: | -<%=h req.request_method %> | -
---|---|
Request URL: | -<%=h req.url %> | -
<%= detail %>
-
- You're seeing this error because you use Rack::ShowStatus
.
-
s(:lit, 1)
-# SexpProcessor will call #process_lit, if it is defined.
-#
-# You can also specify a default method to call for any Sexp types
-# without a process_