diff --git a/app/views/hosts/_host.html.erb b/app/views/hosts/_host.html.erb index 393086c..3049628 100644 --- a/app/views/hosts/_host.html.erb +++ b/app/views/hosts/_host.html.erb @@ -1,17 +1,17 @@ <tr> <td><%= link_to host.name, host_path(host) %></td> <td><%= host.fqdn %></td> <td><%= host.port %></td> - <td><%= host.password %></td> + <td>**********</td> <td><%= host.file_retention %></td> <td><%= host.job_retention %></td> <td><%= host.auto_prune_human %></td> <td> <% if host.verified? %> <span class="label label-success">yes</span> <% else %> <span class="label label-danger">no</span> <% end %> </td> <td><%= I18n.l(host.created_at, format: :long) %></td> </tr> diff --git a/app/views/hosts/_host_details.html.erb b/app/views/hosts/_host_details.html.erb index 7fb774e..5a3d21c 100644 --- a/app/views/hosts/_host_details.html.erb +++ b/app/views/hosts/_host_details.html.erb @@ -1,77 +1,77 @@ <div class="col-xs-4"> <div class="table-responsive"> <table class="table table-striped table-bordered table-condensed"> <tr> <td><b>Name</b></td> <td><%= @host.name %></td> </tr> <tr> <td><b>FQDN</b></td> <td><%= @host.fqdn %></td> </tr> <tr> <td><b>FDPort</b></td> <td><%= @host.port %></td> </tr> <tr> <td><b>Password</b></td> - <td><%= @host.password %></td> + <td>********</td> </tr> <tr> <td><b>File Retention</b></td> <td><%= @host.file_retention %> days</td> </tr> <tr> <td><b>Job Retention</b></td> <td><%= @host.job_retention %> days</td> </tr> <tr> <td><b>Auto Prune</b></td> <td><%= @host.auto_prune_human %></td> </tr> <tr> <td><b>Verified</b></td> <td> <% if @host.verified? %> <span class="label label-success">yes</span> <% else %> <span class="label label-danger">no</span> <% end %> </td> </tr> <tr> <td><b>Created</b></td> <td><%= I18n.l(@host.created_at, format: :long) %></td> </tr> </table> </div> <div class='row'> <div class='col-xs-2'> <%= link_to 'Edit', edit_host_path(@host), class: "btn btn-primary", role: "button" %> </div> <% if @host.needs_dispatch? %> <div class='col-xs-4 pull-right text-right'> <%= link_to 'Deploy Changes', submit_config_host_path(@host), method: :post, class: 'btn btn-success', role: 'button' %> </div> <% end %> <% if @host.needs_revoke? %> <div class='col-xs-4 pull-right text-right'> <%= link_to 'Remove From Bacula', revoke_host_path(@host), method: :delete, class: 'btn btn-danger', role: 'button' %> </div> <% end %> </div> <br /> <div class='row'> <% if @host.client %> <div class='col-xs-12 text-right'> <%= link_to "Back to <b>#{@host.name}</b> client".html_safe, client_path(@host.client) %> </div> <% end %> </div> </div> diff --git a/lib/configuration/host.rb b/lib/configuration/host.rb index f01362e..f370233 100644 --- a/lib/configuration/host.rb +++ b/lib/configuration/host.rb @@ -1,121 +1,121 @@ module Configuration # Helper module to add configuration getters for Host module Host # Constructs the final Bacula configuration for the host by appending configs for # # * Client # * Jobs # * Schedules # * Filesets # # by calling their `to_bacula_config_array` methods. # # @return [Array] containing each element's configuration line by line def baculize_config templates = job_templates.includes(:fileset, :schedule) result = [self] + templates.map {|x| [x, x.fileset, x.schedule] }.flatten.compact.uniq result.map(&:to_bacula_config_array) end # Constructs the final Bacula configuration for the host by appending configs for # # * Client # * Jobs # * Schedules # * Filesets # # by calling their `to_bacula_config_array` methods. # # It hides the password. # # @return [Array] containing each element's configuration line by line def baculize_config_no_pass baculize_config.join("\n").gsub(/Password = ".*"$/, 'Password = "*************"') end # Constructs an array where each element is a line for the Client's bacula config # # @return [Array] def to_bacula_config_array [ "Client {", " Name = #{name}", " Address = #{fqdn}", " FDPort = #{port}", " Catalog = #{client_settings[:catalog]}", " Password = \"#{password}\"", " File Retention = #{file_retention} #{file_retention_period_type}", " Job Retention = #{job_retention} #{job_retention_period_type}", " AutoPrune = #{auto_prune_human}", "}" ] + message_config end # Constructs the messages bacula resource # # @return [Array] def message_config return [] if email_recipients.empty? [ "Messages {", " Name = message_#{name}", " mailcommand = \"#{mail_command}\"", " operatorcommand = \"#{operator_command}\"", " mail = root = all, !skipped", " operator = root = mount", " console = all, !skipped, !saved", " append = \"/var/log/bacula/bacula.log\" = all, !skipped", " catalog = all", "}" ] end # Fetches the Director resource for the file-deamon configuration # file def bacula_fd_director_config [ 'Director {', " Name = \"#{Archiving.settings[:director_name]}\"", - " Password = \"#{password}\"", + " Password = \"*********\"", '}' ].join("\n") end # Fetches the FileDeamon resource for the file-deamon configuration def bacula_fd_filedeamon_config [ 'FileDeamon {', " Name = #{name}", " FDport = #{port}", ' WorkingDirectory = /var/lib/bacula', ' Pid Directory = /var/run/bacula', ' Maximum Concurrent Jobs = 10', ' FDAddress = 0.0.0.0', '}' ].join("\n") end private def mail_command "#{mail_general} -u \\\"\[Bacula\]: %t %e of %c %l\\\" -m \\\"Bacula Report %r\\\"" end def operator_command "#{mail_general} -u \\\"\[Bacula\]: Intervention needed for %j\\\" -m \\\"Intervention needed %r\\\"" end def mail_general "/usr/bin/sendEmail -f #{settings[:default_sender]}" << " -t #{email_recipients.join(' ')}" << " -s #{settings[:address]}:#{settings[:port]}" << " -o tls=yes -xu #{settings[:user_name]} -xp #{settings[:password]}" end def settings Archiving.settings[:mail_settings] end end end diff --git a/spec/lib/configuration/host_spec.rb b/spec/lib/configuration/host_spec.rb index 04d440f..18cf845 100644 --- a/spec/lib/configuration/host_spec.rb +++ b/spec/lib/configuration/host_spec.rb @@ -1,121 +1,121 @@ require 'spec_helper' describe Configuration::Host do describe '#to_bacula_config_array' do let(:host) { FactoryGirl.create(:host) } it "is a valid client directive" do expect(host.to_bacula_config_array).to include('Client {') expect(host.to_bacula_config_array).to include('}') end it "contains Address directive" do expect(host.to_bacula_config_array).to include(" Address = #{host.fqdn}") end it "contains FDPort directive" do expect(host.to_bacula_config_array).to include(" FDPort = #{host.port}") end it "contains Catalog directive" do expect(host.to_bacula_config_array). to include(" Catalog = #{ConfigurationSetting.current_client_settings[:catalog]}") end it "contains Password directive" do expect(host.to_bacula_config_array).to include(" Password = \"#{host.password}\"") end it "contains File Retention directive" do expect(host.to_bacula_config_array). to include(" File Retention = #{host.file_retention} days") end it "contains Job Retention directive" do expect(host.to_bacula_config_array). to include(" Job Retention = #{host.job_retention} days") end it "contains AutoPrune directive" do expect(host.to_bacula_config_array).to include(" AutoPrune = yes") end end describe '#baculize_config' do let!(:host) { FactoryGirl.create(:host) } let!(:fileset) { FactoryGirl.create(:fileset, host: host) } let!(:other_fileset) { FactoryGirl.create(:fileset, host: host) } let!(:schedule) { FactoryGirl.create(:schedule) } let!(:other_schedule) { FactoryGirl.create(:schedule) } let!(:enabled_job) do FactoryGirl.create(:job_template, host: host, schedule: schedule, fileset: fileset, enabled: true) end let!(:disabled_job) do FactoryGirl.create(:job_template, host: host, schedule: other_schedule, fileset: other_fileset, enabled: false) end subject { host.baculize_config } it 'includes the client\'s config' do expect(subject).to include(host.to_bacula_config_array) end it 'includes the all the job template\'s configs' do expect(subject).to include(enabled_job.to_bacula_config_array) expect(subject).to include(disabled_job.to_bacula_config_array) end it 'includes all the used schedules\'s configs' do expect(subject).to include(schedule.to_bacula_config_array) expect(subject).to include(other_schedule.to_bacula_config_array) end it 'includes all the used filesets\'s configs' do expect(subject).to include(fileset.to_bacula_config_array) expect(subject).to include(other_fileset.to_bacula_config_array) end end describe '#bacula_fd_director_config' do let!(:host) { FactoryGirl.build(:host) } subject { host.bacula_fd_director_config } it 'opens and closes a Director part' do expect(subject).to match(/^Director {$/) expect(subject).to match(/^}$/) end it 'includes the client\'s Name' do expect(subject).to match(" Name = \"#{Archiving.settings[:director_name]}\"") end it 'includes the client\'s Password' do - expect(subject).to match(" Password = \"#{host.password}\"") + expect(subject).to match(" Password = \"[*]+\"") end end describe '#bacula_fd_filedeamon_config' do let!(:host) { FactoryGirl.build(:host) } subject { host.bacula_fd_filedeamon_config } it 'opens and closes a FileDeamon part' do expect(subject).to match(/^FileDeamon {$/) expect(subject).to match(/^}$/) end it 'includes the client\'s Port' do expect(subject).to match("FDport = #{host.port}") end it 'includes the client\'s Name' do expect(subject).to match("Name = #{host.name}") end end end