Skip to content

Commit

Permalink
EULA fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed May 15, 2014
1 parent cd1a778 commit db8b109
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
8 changes: 4 additions & 4 deletions package/yast2-registration.spec
Expand Up @@ -31,18 +31,18 @@ Requires: yast2 >= 3.1.26
Requires: yast2-pkg-bindings >= 2.17.20
# N_() method
Requires: yast2-ruby-bindings >= 3.1.12
Requires: rubygem-suse-connect
Requires: rubygem-suse-connect >= 0.0.16
Requires: yast2-slp >= 3.1.2
Requires: yast2-add-on >= 3.1.3
Requires: yast2-packager >= 3.1.14
Requires: yast2-packager >= 3.1.16

BuildRequires: yast2 >= 3.1.26
BuildRequires: update-desktop-files
BuildRequires: yast2-devtools >= 3.1.6
BuildRequires: rubygem-rspec
BuildRequires: rubygem-suse-connect
BuildRequires: rubygem-suse-connect >= 0.0.16
BuildRequires: yast2-slp >= 3.1.2
BuildRequires: yast2-packager >= 3.1.14
BuildRequires: yast2-packager >= 3.1.16

BuildArch: noarch

Expand Down
1 change: 1 addition & 0 deletions src/lib/registration/registration.rb
Expand Up @@ -106,6 +106,7 @@ def connect_params(params)
:language => ::Registration::Helpers.language,
:debug => ENV["SCCDEBUG"],
:verbose => ENV["Y2DEBUG"] == "1",
:product => {}, #SwMgmt.base_product_to_register,
# pass a verify_callback to get details about failed SSL verification
:verify_callback => lambda do |verify_ok, context|
# we cannot raise an exception with details here (all exceptions in
Expand Down
65 changes: 45 additions & 20 deletions src/lib/registration/ui/addon_eula_dialog.rb
Expand Up @@ -10,11 +10,17 @@ module UI
class AddonEulaDialog
include Yast::Logger
include Yast::I18n
include Yast::UIShortcuts

attr_accessor :addons

Yast.import "Report"
# name of the index file with list of available licenses
INDEX_FILE = "directory.yast"

Yast.import "Popup"
Yast.import "ProductLicense"
Yast.import "Report"
Yast.import "Wizard"

# create a new dialog for accepting importing a SSL certificate and run it
def self.run(selected_addons)
Expand All @@ -31,35 +37,49 @@ def initialize(selected_addons)
# display the EULA for each dialog and wait for a button click
# @return [Symbol] user input (:import, :cancel)
def run
Yast::Wizard.SetContents(
# dialog title
_("License Agreement"),
Label(_("Downloading Licenses...")),
"",
false,
false
)

all_accepted = addons.all? do |addon|
if addon.eula.url
if addon.eula_url
log.info "Addon '#{addon.short_name}' has an EULA at #{addon.eula_url}"
accept_eula(addon)
else
# no EULA specified => accepted
true
end
end

# go back if any EULA has not been accepted, let the user deselect the
# not accepted extension
all_accepted ? :next : :back
end

private

def accept_eula(addon)
Dir.mktmpdir("extension-eula-") do |tmpdir|
begin
download_liceses(addon.eula_url, tmpdir, insecure)
Yast::Popup.Feedback(
_("Downloading License Agreement..."),
addon.short_name
) do
download_liceses(addon.eula_url, tmpdir)
end
rescue Exception => e
log.error "Download failed: #{e.message}"
log.error "Download failed: #{e.message}: #{e.backtrace}"
# %s is an extension name, e.g. "SUSE Linux Enterprise Software Development Kit"
Yast::Report.Error(_("Downloading the license for\n%s\nfailed.") % addon.short_name)
return false
end

Yast::ProductLicense.AskLicensesAgreement(
Yast::ProductLicense.AskLicensesAgreementWithHeading(
[tmpdir],
Yast::ProductLicense.license_patterns,
# do not continue if not accepted
Expand All @@ -69,19 +89,23 @@ def accept_eula(addon)
# base product
false,
# require agreement
true
) == :next
true,
# dialog title
_("Extension or Module License Agreement"),
# %s is an extension name, e.g. "SUSE Linux Enterprise Software Development Kit"
_("%s License Agreement") % addon.short_name
) == :accepted
end
end

def download_file(file_url, insecure: false)
url = file_url.is_a?(URI) ? file_url : URI(file_url)
http = Net::HTTP.new(url.host, url.port)

# switch to HTTPS connection if needed
if url.is_a? URI::HTTPS
http.use_ssl = true
insecure = Registration::Helpers.insecure_registration
insecure = Helpers.insecure_registration
http.verify_mode = insecure ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
log.warn("Warning: SSL certificate verification disabled") if insecure
else
Expand All @@ -103,31 +127,32 @@ def download_file(file_url, insecure: false)
def download_liceses(license_url, target_dir)
# download the index file (directory.yast)
index_url = URI(license_url)

# add the index file to the URL
index_url.path = File.join(index_url.path, "directory.yast")
index_url.path = File.join(index_url.path, INDEX_FILE)

# download the index
log.info "Downloading license index: #{index_url}"
licenses = download_file(index_url).split
# the index file itself might be also present in the list, just remove it
licenses.reject!{|license| license == INDEX_FILE}
log.info "Downloaded license index: #{licenses}"

# download the files listed in the index
licenses.each do |license|
license_file_url = URI(license_url)
license_file_url.path = File.join(index_url.path, license)
license_file_url.path = File.join(license_file_url.path, license)

log.info "Downloading license from #{license_file_url}..."
license_text = download_file(license_file_url)
log.info "Downloaded license size: #{license_text.size}"

license_file_name = File.join(target_dir, license)

log.info "Saving the license to file: #{license_file_name}"
File.write(license_file_name, license_text)
end
end



end
Expand Down

0 comments on commit db8b109

Please sign in to comment.