def _validate_activation_keys(self, activation_keys): if not activation_keys: show_error_window(_("You must enter an activation key."), self._parent.window) self.activation_key_entry.grab_focus() return False return True
def _validate_consumername(self, consumername): if not consumername: show_error_window(_("You must enter a system name."), self._parent.window) self.consumer_entry.grab_focus() return False return True
def _validate_owner_key(self, owner_key): if not owner_key: show_error_window(_("You must enter an organization."), self._parent.window) self.organization_entry.grab_focus() return False return True
def write_values(self, widget=None, dummy=None): proxy = self.proxyEntry.get_text() or "" # don't save these values if they are disabled in the gui # settings of HTTP Proxy if proxy and self.enableProxyButton.get_active(): # Remove any URI scheme provided proxy = remove_scheme(proxy) # Update the proxy entry field to show we removed any scheme self.proxyEntry.set_text(proxy) try: proxy_hostname, proxy_port = proxy.split(':') self.cfg.set("server", "proxy_hostname", proxy_hostname) self.cfg.set("server", "proxy_port", proxy_port) except ValueError: # no port? just write out the hostname and assume default self.cfg.set("server", "proxy_hostname", proxy) self.cfg.set("server", "proxy_port", rhsm.config.DEFAULT_PROXY_PORT) else: # delete config options if we disable it in the ui self.cfg.set("server", "proxy_hostname", "") self.cfg.set("server", "proxy_port", "") # settings of HTTP proxy authentication if self.enableProxyAuthButton.get_active(): if self.proxyUserEntry.get_text() is not None: self.cfg.set("server", "proxy_user", str(self.proxyUserEntry.get_text())) if self.proxyPasswordEntry.get_text() is not None: self.cfg.set("server", "proxy_password", str(self.proxyPasswordEntry.get_text())) else: self.cfg.set("server", "proxy_user", "") self.cfg.set("server", "proxy_password", "") # settings of bypass the HTTP proxy for specific host/domain if self.enableProxyBypassButton.get_active(): if self.noProxyEntry.get_text() is not None: self.cfg.set("server", "no_proxy", str(self.noProxyEntry.get_text())) else: self.cfg.set("server", "no_proxy", "") try: self.cfg.save() self.cp_provider.set_connection_info() except Exception: show_error_window( _("There was an error saving your configuration.") + _("Make sure that you own %s.") % self.cfg.fileName, parent=self.networkConfigDialog)
def _validate_account(self): # validate / check user name if self.account_login.get_text().strip() == "": show_error_window(_("You must enter a login."), self._parent.window) self.account_login.grab_focus() return False if self.account_password.get_text().strip() == "": show_error_window(_("You must enter a password."), self._parent.window) self.account_password.grab_focus() return False return True
def _online_docs_item_clicked(self, widget): browser = None for possible_browser in PREFERRED_BROWSERS: try: browser = webbrowser.get(possible_browser) break except webbrowser.Error: pass if browser is None: utils.show_error_window(NO_BROWSER_MESSAGE % (self._get_online_doc_url())) else: webbrowser.open_new(self._get_online_doc_url())
def _validate_account(self): # validate / check user name if self.account_login.get_text().strip() == "": show_error_window(_("You must enter a login."), self._parent.window) self.account_login.grab_focus() return False if self.account_password.get_text().strip() == "": show_error_window(_("You must enter a password."), self._parent.window) self.account_password.grab_focus() return False return True
def _online_docs_item_clicked(self, widget): browser = None for possible_browser in PREFERRED_BROWSERS: try: browser = webbrowser.get(possible_browser) break except webbrowser.Error: pass if browser is None: utils.show_error_window(NO_BROWSER_MESSAGE % (self._get_online_doc_url())) else: webbrowser.open_new(self._get_online_doc_url())
def write_values(self, widget=None, dummy=None): proxy = self.proxyEntry.get_text() or "" # don't save these values if they are disabled in the gui # settings of HTTP Proxy if proxy and self.enableProxyButton.get_active(): # Remove any URI scheme provided proxy = remove_scheme(proxy) # Update the proxy entry field to show we removed any scheme self.proxyEntry.set_text(proxy) try: proxy_hostname, proxy_port = proxy.split(':') self.cfg.set("server", "proxy_hostname", proxy_hostname) self.cfg.set("server", "proxy_port", proxy_port) except ValueError: # no port? just write out the hostname and assume default self.cfg.set("server", "proxy_hostname", proxy) self.cfg.set("server", "proxy_port", rhsm.config.DEFAULT_PROXY_PORT) else: # delete config options if we disable it in the ui self.cfg.set("server", "proxy_hostname", "") self.cfg.set("server", "proxy_port", "") # settings of HTTP proxy authentication if self.enableProxyAuthButton.get_active(): if self.proxyUserEntry.get_text() is not None: self.cfg.set("server", "proxy_user", str(self.proxyUserEntry.get_text())) if self.proxyPasswordEntry.get_text() is not None: self.cfg.set("server", "proxy_password", str(self.proxyPasswordEntry.get_text())) else: self.cfg.set("server", "proxy_user", "") self.cfg.set("server", "proxy_password", "") # settings of bypass the HTTP proxy for specific host/domain if self.enableProxyBypassButton.get_active(): if self.noProxyEntry.get_text() is not None: self.cfg.set("server", "no_proxy", str(self.noProxyEntry.get_text())) else: self.cfg.set("server", "no_proxy", "") try: self.cfg.save() self.cp_provider.set_connection_info() except Exception: show_error_window(_("There was an error saving your configuration.") + _("Make sure that you own %s.") % self.cfg.fileName, parent=self.networkConfigDialog)
def _contract_selected(self, pool, quantity=1): if not valid_quantity(quantity): show_error_window(_("Quantity must be a positive number."), parent=self.parent_win) return self._contract_selection_cancelled() # Start the progress bar self.pb = progress.Progress(_("Attaching"), _("Attaching subscription. Please wait.")) self.timer = ga_GObject.timeout_add(100, self.pb.pulse) self.pb.set_transient_for(self.parent_win) # Spin off a thread to handle binding the selected pool. # After it has completed the actual bind call, available # subs will be refreshed, but we won't re-run compliance # until we have serialized the certificates self.async_bind.bind(pool, quantity, bind_callback=self._async_bind_callback, cert_callback=self.backend.cs.force_cert_check, except_callback=self._async_bind_exception_callback)
def apply(self): server = self.server_entry.get_text() try: (hostname, port, prefix) = parse_server_info(server) CFG.set('server', 'hostname', hostname) CFG.set('server', 'port', port) CFG.set('server', 'prefix', prefix) try: if not is_valid_server_info(hostname, port, prefix): show_error_window(_("Unable to reach the server at %s:%s%s") % (hostname, port, prefix), self._parent.window) return DONT_CHANGE except MissingCaCertException: show_error_window(_("CA certificate for subscription service has not been installed."), self._parent.window) return DONT_CHANGE except ServerUrlParseError: show_error_window(_("Please provide a hostname with optional port and/or prefix: hostname[:port][/prefix]"), self._parent.window) return DONT_CHANGE log.info("Writing server data to rhsm.conf") CFG.save() self._backend.update() if self.activation_key_checkbox.get_active(): return ACTIVATION_KEY_PAGE else: return CREDENTIALS_PAGE
def apply(self): server = self.server_entry.get_text() try: (hostname, port, prefix) = parse_server_info(server) CFG.set('server', 'hostname', hostname) CFG.set('server', 'port', port) CFG.set('server', 'prefix', prefix) try: if not is_valid_server_info(hostname, port, prefix): show_error_window( _("Unable to reach the server at %s:%s%s") % (hostname, port, prefix), self._parent.window) return DONT_CHANGE except MissingCaCertException: show_error_window( _("CA certificate for subscription service has not been installed." ), self._parent.window) return DONT_CHANGE except ServerUrlParseError: show_error_window( _("Please provide a hostname with optional port and/or prefix: hostname[:port][/prefix]" ), self._parent.window) return DONT_CHANGE log.info("Writing server data to rhsm.conf") CFG.save() self._backend.update() if self.activation_key_checkbox.get_active(): return ACTIVATION_KEY_PAGE else: return CREDENTIALS_PAGE
def _contract_selected(self, pool, quantity=1): if not valid_quantity(quantity): show_error_window(_("Quantity must be a positive number."), parent=self.parent_win) return self._contract_selection_cancelled() # Start the progress bar self.pb = progress.Progress(_("Attaching"), _("Attaching subscription. Please wait.")) self.timer = ga_GObject.timeout_add(100, self.pb.pulse) self.pb.set_transient_for(self.parent_win) # Spin off a thread to handle binding the selected pool. # After it has completed the actual bind call, available # subs will be refreshed, but we won't re-run compliance # until we have serialized the certificates self.async_bind.bind( pool, quantity, bind_callback=self._async_bind_callback, cert_callback=self.backend.cs.force_cert_check, except_callback=self._async_bind_exception_callback)
def _validate_consumername(self, consumername): if not consumername: show_error_window(_("You must enter a system name."), self._parent.window) self.consumer_entry.grab_focus() return False return True
def _validate_activation_keys(self, activation_keys): if not activation_keys: show_error_window(_("You must enter an activation key."), self._parent.window) self.activation_key_entry.grab_focus() return False return True
def _validate_owner_key(self, owner_key): if not owner_key: show_error_window(_("You must enter an organization."), self._parent.window) self.organization_entry.grab_focus() return False return True
def _import_button_clicked(self): src_cert_files = self.dialog.get_filenames() invalid_certs = [] error_certs = [] good_certs = [] imported_certs = [] non_cert_files = [] for cert_file in src_cert_files: if not os.path.exists(cert_file): non_cert_files.append(cert_file) else: # Check to see if we have a key included in the cert file try: extractor = ImportFileExtractor(cert_file) #Verify the entitlement data. if not extractor.verify_valid_entitlement(): log.error("Invalid X509 entitlement certificate.") log.error( "Error parsing manually imported entitlement " "certificate: %s" % cert_file) invalid_certs.append(cert_file) else: extractor.write_to_disk() good_certs.append(cert_file) imported_certs.append(extractor.get_cert()) except Exception as e: # Should not get here unless something really bad happened. log.exception(e) error_certs.append(cert_file) if imported_certs: brands_installer = rhelentbranding.RHELBrandsInstaller() brands_installer.install() if len(error_certs) > 0 \ or len(invalid_certs) > 0 \ or len(non_cert_files) > 0: msg = "" if len(non_cert_files) > 0: msg += _("The following certificate files did not exist:") msg += "\n" + "\n".join(non_cert_files) if len(invalid_certs) > 0: msg += _( "The following files are not valid certificates and were not imported:" ) msg += "\n" + "\n".join(invalid_certs) if len(error_certs) > 0: if len(invalid_certs) > 0: msg += "\n\n" msg += _( "An error occurred while importing the following certificates. Please check the log file for more information." ) msg += "\n" + "\n".join(error_certs) if len(good_certs) > 0: msg += "\n\n" msg += _( "The following certificates were successfully imported:") msg += "\n" + "\n".join(good_certs) show_error_window(msg, parent=self._parent) else: #if we get to this point, the import was successful messageWindow.InfoDialog(_("Certificate import was successful."), parent=self._parent) self.dialog.hide() self.dialog.unselect_all()
class ImportSubDialog(object): """ Dialog to manually import an entitlement certificate for this machine. Generally used for disconnected (unregistered) systems. """ def __init__(self): self._parent = None self.dialog = gtk.FileChooserDialog(_("Import Certificates"), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, _("Import"), gtk.RESPONSE_OK)) self.dialog.set_default_response(gtk.RESPONSE_OK) self.dialog.set_modal(True) self.dialog.set_local_only(True) self.dialog.set_select_multiple(True) self.dialog.set_icon_name('subscription-manager') afilter = gtk.FileFilter() afilter.set_name(_("Certificates")) afilter.add_pattern("*.pem") self.dialog.add_filter(afilter) afilter = gtk.FileFilter() afilter.set_name(_("All files")) afilter.add_pattern("*") self.dialog.add_filter(afilter) self.dialog.connect("response", self._on_dialog_response) self.dialog.connect("delete-event", self._delete_event) def _on_dialog_response(self, dialog, response_id): if response_id == gtk.RESPONSE_CANCEL: return self._cancel_button_clicked() elif response_id == gtk.RESPONSE_OK: return self._import_button_clicked() # other response is on dialog destroy, we don't act on that. def _cancel_button_clicked(self): self.dialog.hide() return True def show(self): self.dialog.present() def _delete_event(self, event, data=None): return self._cancel_button_clicked() def _import_button_clicked(self): src_cert_files = self.dialog.get_filenames() invalid_certs = [] error_certs = [] good_certs = [] imported_certs = [] non_cert_files = [] for cert_file in src_cert_files: if not os.path.exists(cert_file): non_cert_files.append(cert_file) else: # Check to see if we have a key included in the cert file try: extractor = ImportFileExtractor(cert_file) #Verify the entitlement data. if not extractor.verify_valid_entitlement(): log.error("Invalid X509 entitlement certificate.") log.error("Error parsing manually imported entitlement " "certificate: %s" % cert_file) invalid_certs.append(cert_file) else: extractor.write_to_disk() good_certs.append(cert_file) imported_certs.append(extractor.get_cert()) except Exception, e: # Should not get here unless something really bad happened. log.exception(e) error_certs.append(cert_file) if imported_certs: brands_installer = rhelentbranding.RHELBrandsInstaller() brands_installer.install() if len(error_certs) > 0 \ or len(invalid_certs) > 0 \ or len(non_cert_files) > 0: msg = "" if len(non_cert_files) > 0: msg += _("The following certificate files did not exist:") msg += "\n" + "\n".join(non_cert_files) if len(invalid_certs) > 0: msg += _("The following files are not valid certificates and were not imported:") msg += "\n" + "\n".join(invalid_certs) if len(error_certs) > 0: if len(invalid_certs) > 0: msg += "\n\n" msg += _("An error occurred while importing the following certificates. Please check the log file for more information.") msg += "\n" + "\n".join(error_certs) if len(good_certs) > 0: msg += "\n\n" msg += _("The following certificates were successfully imported:") msg += "\n" + "\n".join(good_certs) show_error_window(msg, parent=self._parent) else: #if we get to this point, the import was successful messageWindow.InfoDialog(_("Certificate import was successful."), parent=self._parent) self.dialog.hide() self.dialog.unselect_all()