Revision b8d29217
Added by Martin Milata over 9 years ago
app/assets/javascripts/abrt_reports.js | ||
---|---|---|
// Place all the behaviors and hooks related to the matching controller here.
|
||
// All this logic will automatically be available in application.js.
|
||
$(function () {
|
||
var button = $("#forward_auth_button")
|
||
var dialog = $("#forward_auth")
|
||
|
||
dialog.modal({
|
||
backdrop: 'static',
|
||
show: false
|
||
})
|
||
|
||
button.on('click', function () {
|
||
dialog.modal('show')
|
||
});
|
||
});
|
app/controllers/abrt_reports_controller.rb | ||
---|---|---|
redirect_to abrt_report_url(@abrt_report)
|
||
|
||
begin
|
||
response = send_to_abrt_server @abrt_report
|
||
response = send_to_abrt_server @abrt_report, params[:username], params[:password]
|
||
rescue => e
|
||
error _("Server rejected our report: #{e.message}") and return
|
||
end
|
app/helpers/abrt_reports_helper.rb | ||
---|---|---|
attr_reader :path, :content_type
|
||
end
|
||
|
||
def send_to_abrt_server(abrt_report)
|
||
def send_to_abrt_server(abrt_report, username = nil, password = nil)
|
||
request_params = {
|
||
:timeout => 60,
|
||
:open_timeout => 10,
|
||
... | ... | |
request_params[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(Setting[:abrt_server_ssl_priv_key]))
|
||
end
|
||
|
||
# basic auth
|
||
if username && password
|
||
request_params[:user] = username
|
||
request_params[:password] = password
|
||
end
|
||
|
||
resource = RestClient::Resource.new(Setting[:abrt_server_url], request_params)
|
||
report_file = StringIOWithPath.new(abrt_report.json, '*buffer*', 'application/json')
|
||
response = resource['reports/new/'].post({ :file => report_file, :multipart => true }, :content_type => :json, :accept => :json)
|
||
... | ... | |
reason
|
||
end
|
||
end
|
||
|
||
def using_redhat_server
|
||
match = %r{^https://[^/]*access\.redhat\.com/}.match(Setting[:abrt_server_url])
|
||
!!match
|
||
end
|
||
|
||
def display_forward_button(abrt_report)
|
||
if Setting[:abrt_server_requires_basic_auth] || using_redhat_server
|
||
button_tag _('Send for analysis'), :id => 'forward_auth_button', :class => 'btn btn-success'
|
||
else
|
||
options = { :class => 'btn btn-success', :method => :post }
|
||
if abrt_report.forwarded_at
|
||
options[:confirm] = _('The report has already been sent. Sending it again will overwrite the previous response.')
|
||
end
|
||
link_to _('Send for analysis'), forward_abrt_report_path(abrt_report), options
|
||
end
|
||
end
|
||
|
||
def forward_auth_title
|
||
if using_redhat_server
|
||
_('Please provide Red Hat Customer Portal credentials')
|
||
else
|
||
_('Please provide ABRT server credentials')
|
||
end
|
||
end
|
||
|
||
def forward_auth_login
|
||
if using_redhat_server
|
||
_('Red Hat Login')
|
||
else
|
||
_('Login')
|
||
end
|
||
end
|
||
|
||
def forward_auth_text
|
||
if using_redhat_server
|
||
_('The problem report will be sent to Red Hat in order to determine if a solution exists. '\
|
||
'You need to provide your Red Hat Customer Portal login and password in order to proceed.')
|
||
else
|
||
_('Your ABRT server is configured to require login and password.')
|
||
end
|
||
end
|
||
end
|
app/models/setting/abrt.rb | ||
---|---|---|
class Setting::Abrt < ::Setting
|
||
BLANK_ATTRS << "abrt_server_ssl_certificate"
|
||
BLANK_ATTRS << "abrt_server_ssl_priv_key"
|
||
BLANK_ATTRS << "abrt_server_ssl_ca_file"
|
||
URI_ATTRS << "abrt_server_url"
|
||
|
||
def self.load_defaults
|
||
return unless super
|
||
... | ... | |
self.set('abrt_server_ssl_priv_key', N_('SSL private key path that Foreman would use to communicate with ABRT server'), ''),
|
||
self.set('abrt_server_ssl_ca_file', N_('SSL CA file that Foreman will use to communicate with ABRT server'), ''),
|
||
self.set('abrt_automatically_forward', N_('Automatically send every report to an ABRT server for analysis?'), false),
|
||
self.set('abrt_server_requires_basic_auth', N_('Does the server require authentication through username and password?'), false),
|
||
].compact.each { |s| self.create s.update(:category => 'Setting::Abrt') }
|
||
end
|
||
|
app/views/abrt_reports/_basic_auth_modal.html.erb | ||
---|---|---|
<div id="forward_auth" class="modal fade hide">
|
||
<div class="modal-dialog modal-sm">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<%= alert_close('modal') %>
|
||
<h4 class="modal-title"><%= forward_auth_title %></h4>
|
||
</div>
|
||
<div class="modal-body">
|
||
<% if forward_auth_text %>
|
||
<p><%= forward_auth_text %></p><br>
|
||
<% end %>
|
||
<%= form_tag forward_abrt_report_path(@abrt_report), :class => 'form form-horizontal' do %>
|
||
<div class="form-group">
|
||
<%= label_tag :username, forward_auth_login, :class => 'col-sm-3 control-label' %>
|
||
<div class="col-sm-9">
|
||
<%= text_field_tag :username, nil, :class => 'form-control' %>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<%= label_tag :password, _("Password"), :class => 'col-sm-3 control-label' %>
|
||
<div class="col-sm-9">
|
||
<%= password_field_tag :password, nil, :class => 'form-control' %>
|
||
</div>
|
||
</div>
|
||
<% if @abrt_report.forwarded_at %>
|
||
<div class="alert alert-warning">
|
||
<%= _('The report has already been sent. Sending it again will overwrite the previous response.') %>
|
||
</div>
|
||
<% end %>
|
||
<div class="form-group">
|
||
<div class="col-sm-offset-3 col-sm-9">
|
||
<%= submit_tag _('Send for analysis'), :class => 'btn btn-success' %>
|
||
<%= modal_close 'modal', _('Cancel') %>
|
||
</div>
|
||
</div>
|
||
<% end %>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
app/views/abrt_reports/show.html.erb | ||
---|---|---|
<% javascript 'abrt_reports' %>
|
||
<% title @abrt_report.host.to_s %>
|
||
|
||
<%= title_actions link_to(_('Host details'), @abrt_report.host),
|
||
link_to(_('Other reports for this host'), host_abrt_reports_path(@abrt_report.host)),
|
||
link_to(_('Send for analysis'),
|
||
forward_abrt_report_path(@abrt_report),
|
||
:class => 'btn btn-success',
|
||
:method => :post,
|
||
:confirm => @abrt_report.forwarded_at ? _('The report has already been sent. Send again and overwrite the previous response?') : nil),
|
||
display_forward_button(@abrt_report),
|
||
display_delete_if_authorized(hash_for_abrt_report_path(:id => @abrt_report), :class => 'btn btn-danger')
|
||
%>
|
||
|
||
... | ... | |
</div>
|
||
</div>
|
||
<% end %>
|
||
|
||
<% if ask_for_auth? %>
|
||
<%= render :partial => 'basic_auth_modal' %>
|
||
<% end %>
|
Also available in: Unified diff
Implement HTTP basic auth for forwarding reports