def _validate_consumername(self, consumername):
     if not consumername:
         errorWindow(_("You must enter a system name."),
                     self._parent.window)
         self.consumer_name.grab_focus()
         return False
     return True
 def validate_consumername(self, consumername):
     if not consumername:
         errorWindow(_("You must enter a system name."),
                     parent=self.registerWin)
         self.consumer_name.grab_focus()
         return False
     return True
    def validate_account(self):
        # validate / check user name
        if self.uname.get_text().strip() == "":
            errorWindow(_("You must enter a login."), parent=self.registerWin)
            self.uname.grab_focus()
            return False

        if self.passwd.get_text().strip() == "":
            errorWindow(_("You must enter a password."), parent=self.registerWin)
            self.passwd.grab_focus()
            return False
        return True
    def _validate_account(self):
        # validate / check user name
        if self.account_login.get_text().strip() == "":
            errorWindow(_("You must enter a login."), self._parent.window)
            self.account_login.grab_focus()
            return False

        if self.account_password.get_text().strip() == "":
            errorWindow(_("You must enter a password."), self._parent.window)
            self.account_password.grab_focus()
            return False
        return True
    def _validate_account(self):
        # validate / check user name
        if self.account_login.get_text().strip() == "":
            errorWindow(_("You must enter a login."), self._parent.window)
            self.account_login.grab_focus()
            return False

        if self.account_password.get_text().strip() == "":
            errorWindow(_("You must enter a password."), self._parent.window)
            self.account_password.grab_focus()
            return False
        return True
    def validate_account(self):
        # validate / check user name
        if self.uname.get_text().strip() == "":
            errorWindow(_("You must enter a login."), parent=self.registerWin)
            self.uname.grab_focus()
            return False

        if self.passwd.get_text().strip() == "":
            errorWindow(_("You must enter a password."),
                        parent=self.registerWin)
            self.passwd.grab_focus()
            return False
        return True
Beispiel #7
0
    def writeValues(self, widget=None, dummy=None):
        proxy = self.xml.get_widget("proxyEntry").get_text() or ""

        # don't save these values if they are disabled in the gui
        if proxy and self.xml.get_widget("enableProxyButton").get_active():
            # Remove any URI scheme provided
            proxy = remove_scheme(proxy)
            # Update the proxy entry field to show we removed any scheme
            self.xml.get_widget("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", "")

        if self.xml.get_widget("enableProxyAuthButton").get_active():
            if self.xml.get_widget("proxyUserEntry").get_text() is not None:
                self.cfg.set(
                    "server", "proxy_user",
                    str(self.xml.get_widget("proxyUserEntry").get_text()))

            if self.xml.get_widget(
                    "proxyPasswordEntry").get_text() is not None:
                self.cfg.set(
                    "server", "proxy_password",
                    str(self.xml.get_widget("proxyPasswordEntry").get_text()))
        else:
            self.cfg.set("server", "proxy_user", "")
            self.cfg.set("server", "proxy_password", "")

        try:
            self.cfg.save()
        except:
            errorWindow(_("There was an error saving your configuration.") +
                        _("Make sure that you own %s.") % self.cfg.fileName,
                        parent=self.dlg)
    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):
                    errorWindow(
                        _("Unable to reach the server at %s:%s%s" %
                          (hostname, port, prefix)), self._parent.window)
                    return DONT_CHANGE
            except MissingCaCertException:
                errorWindow(
                    _("CA certificate for subscription service has not been installed."
                      ), self._parent.window)
                return DONT_CHANGE

        except ServerUrlParseError:
            errorWindow(
                _("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()

        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):
                    errorWindow(_("Unable to reach the server at %s:%s%s" %
                        (hostname, port, prefix)), self._parent.window)
                    return DONT_CHANGE
            except MissingCaCertException:
                errorWindow(_("CA certificate for subscription service has not been installed."),
                            self._parent.window)
                return DONT_CHANGE

        except ServerUrlParseError:
            errorWindow(_("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()

        return CREDENTIALS_PAGE
    def writeValues(self, widget=None, dummy=None):
        proxy = self.xml.get_widget("proxyEntry").get_text() or ""

        # don't save these values if they are disabled in the gui
        if proxy and self.xml.get_widget("enableProxyButton").get_active():
            # Remove any URI scheme provided
            proxy = remove_scheme(proxy)
            # Update the proxy entry field to show we removed any scheme
            self.xml.get_widget("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", "")

        if self.xml.get_widget("enableProxyAuthButton").get_active():
            if self.xml.get_widget("proxyUserEntry").get_text() is not None:
                self.cfg.set("server", "proxy_user",
                             str(self.xml.get_widget("proxyUserEntry").get_text()))

            if self.xml.get_widget("proxyPasswordEntry").get_text() is not None:
                self.cfg.set("server", "proxy_password",
                             str(self.xml.get_widget("proxyPasswordEntry").get_text()))
        else:
            self.cfg.set("server", "proxy_user", "")
            self.cfg.set("server", "proxy_password", "")

        try:
            self.cfg.save()
        except:
            errorWindow(_("There was an error saving your configuration.") +
                    _("Make sure that you own %s.") % self.cfg.fileName,
                    parent=self.dlg)
    def _server_selected(self):
        if self.rhn_radio.get_active():
            CFG.set('server', 'hostname', config.DEFAULT_HOSTNAME)
            CFG.set('server', 'port', config.DEFAULT_PORT)
            CFG.set('server', 'prefix', config.DEFAULT_PREFIX)
        elif self.offline_radio.get_active():
            # We'll signal the user set offline by setting an empty hostname:
            CFG.set('server', 'hostname', '')
            CFG.set('server', 'port', config.DEFAULT_PORT)
            CFG.set('server', 'prefix', config.DEFAULT_PREFIX)
        elif self.local_radio.get_active():
            local_server = self.local_entry.get_text()
            try:
                (hostname, port, prefix) = parse_server_info(local_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):
                        errorWindow(
                            _("Unable to reach the server at %s:%s%s" %
                              (hostname, port, prefix)))
                        return
                except MissingCaCertException:
                    errorWindow(
                        _("CA certificate for subscription service has not been installed."
                          ))
                    return

            except ServerUrlParseError:
                errorWindow(
                    _("Please provide a hostname with optional port and/or prefix: hostname[:port][/prefix]"
                      ), self.registerWin)
                return

        log.info("Writing server data to rhsm.conf")
        CFG.save()
        self.backend.update()

        if self.offline_radio.get_active():
            # Because the user selected offline, the whole registration process
            # must end here.
            self._offline_selected()
        else:
            self._show_credentials_page()
    def _server_selected(self):
        if self.rhn_radio.get_active():
            CFG.set('server', 'hostname', config.DEFAULT_HOSTNAME)
            CFG.set('server', 'port', config.DEFAULT_PORT)
            CFG.set('server', 'prefix', config.DEFAULT_PREFIX)
        elif self.offline_radio.get_active():
            # We'll signal the user set offline by setting an empty hostname:
            CFG.set('server', 'hostname', '')
            CFG.set('server', 'port', config.DEFAULT_PORT)
            CFG.set('server', 'prefix', config.DEFAULT_PREFIX)
        elif self.local_radio.get_active():
            local_server = self.local_entry.get_text()
            try:
                (hostname, port, prefix) = parse_server_info(local_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):
                        errorWindow(_("Unable to reach the server at %s:%s%s" %
                            (hostname, port, prefix)))
                        return
                except MissingCaCertException:
                    errorWindow(_("CA certificate for subscription service has not been installed."))
                    return

            except ServerUrlParseError:
                errorWindow(_("Please provide a hostname with optional port and/or prefix: hostname[:port][/prefix]"), self.registerWin)
                return

        log.info("Writing server data to rhsm.conf")
        CFG.save()
        self.backend.update()

        if self.offline_radio.get_active():
            # Because the user selected offline, the whole registration process
            # must end here.
            self._offline_selected()
        else:
            self._show_credentials_page()
 def validate_consumername(self, consumername):
     if not consumername:
         errorWindow(_("You must enter a system name."), parent=self.registerWin)
         self.consumer_name.grab_focus()
         return False
     return True
 def _validate_consumername(self, consumername):
     if not consumername:
         errorWindow(_("You must enter a system name."), self._parent.window)
         self.consumer_name.grab_focus()
         return False
     return True
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)

        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)

    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 = []

        for cert_file in src_cert_files:
            # 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)
            except Exception, e:
                # Should not get here unless something really bad happened.
                log.exception(e)
                error_certs.append(cert_file)

        if len(error_certs) > 0 or len(invalid_certs) > 0:
            msg = ""
            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)
            errorWindow(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()