예제 #1
0
    def input(self, args, key):
        """Override input so that we can launch the VNC password spoke"""

        try:
            keyid = int(key) - 1
            if 0 <= keyid < len(self._choices):
                choice = self._choices[keyid]
                if choice == _(USETEXT):
                    self._usevnc = False
                else:
                    self._usevnc = True
                    newspoke = VNCPassSpoke(self.app, self.data, self.storage,
                                            self.payload, self.instclass)
                    self.app.switch_screen_modal(newspoke)

                self.apply()
                self.close()
            return INPUT_PROCESSED
        except ValueError:
            pass

        # TRANSLATORS: 'q' to quit
        if key.lower() == C_('TUI|Spoke Navigation', 'q'):
            d = YesNoDialog(self.app, _(self.app.quit_message))
            self.app.switch_screen_modal(d)
            if d.answer:
                ipmi_abort(scripts=self.data.scripts)
                if can_touch_runtime_system("Quit and Reboot"):
                    execWithRedirect("systemctl", ["--no-wall", "reboot"])
                else:
                    sys.exit(1)
        else:
            return super(AskVNCSpoke, self).input(args, key)
예제 #2
0
파일: askvnc.py 프로젝트: LiuCan01/anaconda
    def input(self, args, key):
        """Override input so that we can launch the VNC password spoke"""

        try:
            keyid = int(key) - 1
            if 0 <= keyid < len(self._choices):
                choice = self._choices[keyid]
                if choice == _(USETEXT):
                    self._usevnc = False
                else:
                    self._usevnc = True
                    newspoke = VNCPassSpoke(self.app, self.data, self.storage,
                                            self.payload, self.instclass)
                    self.app.switch_screen_modal(newspoke)

                self.apply()
                self.close()
            return INPUT_PROCESSED
        except ValueError:
            pass

        if key.lower() == _('q'):
            d = YesNoDialog(self.app, _(self.app.quit_message))
            self.app.switch_screen_modal(d)
            if d.answer:
                from pyanaconda.flags import can_touch_runtime_system
                if can_touch_runtime_system("reboot"):
                    execWithRedirect("systemctl", ["--no-wall", "reboot"])
                else:
                    sys.exit(1)
        else:
            return key
예제 #3
0
    def prompt(self, entry):
        if entry.aux == self.PASSWORD:
            pw = self._app.raw_input(_("%s: ") % entry.title, hidden=True)
            confirm = self._app.raw_input(_("%s (confirm): ") % entry.title,
                                          hidden=True)
            error = None
            # just returning an error is either blank or mismatched
            # passwords.  Raising is because of poor quality.
            try:
                error = validatePassword(pw, confirm)
                if error:
                    print(error)
                    return None
                strength = checkPassword(pw)
                if strength < 50:
                    raise PWQError("The password you have provided is weak.")
            except PWQError as e:
                error = _("You have provided a weak password: %s. " %
                          e.message)
                error += _("\nWould you like to use it anyway?")
                question_window = YesNoDialog(self._app, error)
                self._app.switch_screen_modal(question_window)
                if not question_window.answer:
                    return None

            self.value = cryptPassword(pw)
            return None
        else:
            return _(
                "Enter new value for '%s' and press enter\n") % entry.title
예제 #4
0
    def prompt(self, entry=None):
        if not entry:
            return None

        if entry.aux == self.PASSWORD:
            pw = self._app.raw_input(_("%s: ") % entry.title, hidden=True)
            confirm = self._app.raw_input(_("%s (confirm): ") % entry.title, hidden=True)

            if (pw and not confirm) or (confirm and not pw):
                print(_("You must enter your root password and confirm it by typing"
                        " it a second time to continue."))
                return None
            if (pw != confirm):
                print(_(PASSWORD_CONFIRM_ERROR_TUI))
                return None

            # If an empty password was provided, unset the value
            if not pw:
                self.value = ""
                return None

            valid, strength, message = validatePassword(pw, user=None, minlen=self.policy.minlen)

            if not valid:
                print(message)
                return None

            if strength < self.policy.minquality:
                if self.policy.strict:
                    done_msg = ""
                else:
                    done_msg = _("\nWould you like to use it anyway?")

                if message:
                    error = _(PASSWORD_WEAK_WITH_ERROR) % message + " " + done_msg
                else:
                    error = _(PASSWORD_WEAK) % done_msg

                if not self.policy.strict:
                    question_window = YesNoDialog(self._app, error)
                    self._app.switch_screen_modal(question_window)
                    if not question_window.answer:
                        return None
                else:
                    print(error)
                    return None

            if any(char not in PW_ASCII_CHARS for char in pw):
                print(_("You have provided a password containing non-ASCII characters.\n"
                        "You may not be able to switch between keyboard layouts to login.\n"))

            self.value = cryptPassword(pw)
            return None
        else:
            return tui.Prompt(_("Enter a new value for '%(title)s' and press %(enter)s") % {
                # TRANSLATORS: 'title' as a title of the entry
                "title": entry.title,
                # TRANSLATORS: 'enter' as the key ENTER
                "enter": tui.Prompt.ENTER
            })
예제 #5
0
    def input(self, args, key):
        """Override any input so we can launch rescue mode."""
        try:
            keyid = int(key) - 1
        except ValueError:
            pass

        if keyid == 3:
            # quit/reboot
            d = YesNoDialog(self.app, _(self.app.quit_message))
            self.app.switch_screen_modal(d)
            if d.answer:
                self._rescue.reboot = True
                self._rescue.finish()
        elif keyid == 2:
            # skip to/run shell
            self._show_result_and_prompt_for_shell()
        elif keyid == 1 or keyid == 0:
            # user chose 0 (continue/rw-mount) or 1 (ro-mount)
            self._rescue.mount = True
            if keyid == 1:
                self._rescue.ro = True
            self._mount_root()
            self._show_result_and_prompt_for_shell()
        else:
            # user entered some invalid number choice
            return key

        return INPUT_PROCESSED
예제 #6
0
    def _showYesNoQuestion(self, message):
        """Internal helper function that MUST BE CALLED FROM THE MAIN THREAD"""

        if flags.automatedInstall and not flags.ksprompt:
            # If we're in cmdline mode, just say no.
            return False

        question_window = YesNoDialog(self._app, message)
        self._app.switch_screen_modal(question_window)

        return question_window.answer
예제 #7
0
    def input(self, args, key):
        """Override any input so we can launch rescue mode."""
        try:
            keyid = int(key) - 1
        except ValueError:
            pass

        if keyid == 3:
            # quit/reboot
            d = YesNoDialog(self.app, _(self.app.quit_message))
            self.app.switch_screen_modal(d)
            if d.answer:
                iutil.execWithRedirect("systemctl", ["--no-wall", "reboot"])
        elif keyid == 2:
            # skip to/run shell
            run_shell()
        elif (keyid == 1 or keyid == 0):
            # user chose 0 (continue/rw-mount) or 1 (ro-mount)
            # decrypt any luks devices
            self._unlock_devices()

            # this sleep may look pointless, but it seems necessary, in
            # order for some task to complete; otherwise no existing
            # installations are discovered. IOW, this is a hack.
            time.sleep(2)
            # attempt to find previous installations
            roots = find_existing_installations(self.storage.devicetree)
            if len(roots) == 1:
                self._root = roots[0]
            elif len(roots) > 1:
                # have to prompt user for which root to mount
                rootspoke = RootSpoke(self.app, self.data, self.storage,
                                      self.payload, self.instclass, roots)
                self.app.switch_screen_modal(rootspoke)
                self._root = rootspoke.root

            # if only one root detected, or user has chosen which root
            # to mount, go ahead and do that
            newspoke = RescueMountSpoke(self.app, self.data, self.storage,
                                        self.payload, self.instclass, keyid,
                                        self._root)
            self.app.switch_screen_modal(newspoke)
            self.close()
        else:
            # user entered some invalid number choice
            return key

        return INPUT_PROCESSED
예제 #8
0
    def run_dasdfmt(self, to_format):
        """
        This generates the list of DASDs requiring dasdfmt and runs dasdfmt
        against them.
        """
        # if the storage thread is running, wait on it to complete before taking
        # any further actions on devices; most likely to occur if user has
        # zerombr in their ks file
        threadMgr.wait(THREAD_STORAGE)

        # ask user to verify they want to format if zerombr not in ks file
        if not self.data.zerombr.zerombr:
            # prepare our msg strings; copied directly from dasdfmt.glade
            summary = _(
                "The following unformatted DASDs have been detected on your system. You can choose to format them now with dasdfmt or cancel to leave them unformatted. Unformatted DASDs can not be used during installation.\n\n"
            )

            warntext = _(
                "Warning: All storage changes made using the installer will be lost when you choose to format.\n\nProceed to run dasdfmt?\n"
            )

            displaytext = summary + "\n".join(
                "/dev/" + d for d in to_format) + "\n" + warntext

            # now show actual prompt; note -- in cmdline mode, auto-answer for
            # this is 'no', so unformatted DASDs will remain so unless zerombr
            # is added to the ks file
            question_window = YesNoDialog(self._app, displaytext)
            self._app.switch_screen_modal(question_window)
            if not question_window.answer:
                # no? well fine then, back to the storage spoke with you;
                return None

        for disk in to_format:
            try:
                print(_("Formatting /dev/%s. This may take a moment.") % disk)
                format_dasd(disk)
            except DasdFormatError as err:
                # Log errors if formatting fails, but don't halt the installer
                log.error(str(err))
                continue

        # when finished formatting we need to reinitialize storage
        protectedNames = [d.name for d in self.storage.protectedDevices]
        storageInitialize(self.storage, self.data, protectedNames)
예제 #9
0
    def prompt(self, entry=None):
        if not entry:
            return None

        if entry.aux == self.PASSWORD:
            pw = self._app.raw_input(_("%s: ") % entry.title, hidden=True)
            confirm = self._app.raw_input(_("%s (confirm): ") % entry.title,
                                          hidden=True)

            if (pw and not confirm) or (confirm and not pw):
                print(
                    _("You must enter your root password and confirm it by typing"
                      " it a second time to continue."))
                return None
            if (pw != confirm):
                print(_(PASSWORD_CONFIRM_ERROR_TUI))
                return None

            valid, strength, message = validatePassword(pw, user=None)

            if not valid:
                print(message)
                return None

            if strength < 50:
                if message:
                    error = _("You have provided a weak password: %s\n"
                              "Would you like to use it anyway?") % message
                else:
                    error = _("You have provided a weak password.\n"
                              "Would you like to use it anyway?")
                question_window = YesNoDialog(self._app, error)
                self._app.switch_screen_modal(question_window)
                if not question_window.answer:
                    return None

            self.value = cryptPassword(pw)
            return None
        else:
            return _(
                "Enter new value for '%s' and press enter\n") % entry.title
예제 #10
0
    def run_dasdfmt(self, to_format=None):
        """
        This generates the list of DASDs requiring dasdfmt and runs dasdfmt
        against them.

        to_format is an optional list of DASDs to format. This shouldn't be
        passed if run_dasdfmt is called during a ks installation, and if called
        during a manual installation, a list of DASDs needs to be passed.
        """
        if not to_format:
            # go ahead and initialize this
            to_format = []

        # if the storage thread is running, wait on it to complete before taking
        # any further actions on devices; most likely to occur if user has
        # zerombr in their ks file
        threadMgr.wait(THREAD_STORAGE)

        if flags.automatedInstall:
            # automated install case
            unformatted = []
            ldl = []

            if self.data.zerombr.zerombr:
                # unformatted DASDs
                unformatted += make_unformatted_dasd_list(
                    [d.name for d in getDisks(self.storage.devicetree)])
            if self.data.clearpart.cdl:
                # LDL DASDs
                ldl += [
                    d.name for d in self.storage.devicetree.dasd
                    if is_ldl_dasd(d.name)
                ]
            # combine into one nice list
            to_format = list(set(unformatted + ldl))
        else:
            # manual install; ask to verify they want to run dasdfmt
            # prepare our msg strings; copied directly from dasdfmt.glade
            summary = _(
                "The following unformatted or LDL DASDs have been "
                "detected on your system. You can choose to format them "
                "now with dasdfmt or cancel to leave them unformatted. "
                "Unformatted DASDs cannot be used during installation.\n\n")

            warntext = _(
                "Warning: All storage changes made using the installer will be lost when you choose to format.\n\nProceed to run dasdfmt?\n"
            )

            displaytext = summary + "\n".join(
                "/dev/" + d for d in to_format) + "\n" + warntext

            # now show actual prompt; note -- in cmdline mode, auto-answer for
            # this is 'no', so unformatted and ldl DASDs will remain so unless
            # zerombr or cdl are added to the ks file
            question_window = YesNoDialog(self._app, displaytext)
            self._app.switch_screen_modal(question_window)
            if not question_window.answer:
                # no? well fine then, back to the storage spoke with you;
                return None

        for disk in to_format:
            try:
                print(_("Formatting /dev/%s. This may take a moment.") % disk)
                format_dasd(disk)
            except DasdFormatError as err:
                # Log errors if formatting fails, but don't halt the installer
                log.error("dasdfmt /dev/%s failed: %s", disk, err)
                continue

        # need to make devicetree aware of disk changes
        self.storage.devicetree.populate()
        if not flags.automatedInstall:
            # reinit storage
            threadMgr.add(
                AnacondaThread(
                    name=THREAD_STORAGE,
                    target=storageInitialize,
                    args=(self.storage, self.data,
                          self.storage.devicetree.protectedDevNames)))
            # update the summary screen with the changes
            self._initialize()
예제 #11
0
    def prompt(self, entry=None):
        if not entry:
            return None

        if entry.aux == self.PASSWORD:
            pw = self._app.raw_input(_("%s: ") % entry.title, hidden=True)
            confirm = self._app.raw_input(_("%s (confirm): ") % entry.title,
                                          hidden=True)

            if (pw and not confirm) or (confirm and not pw):
                print(
                    _("You must enter your root password and confirm it by typing"
                      " it a second time to continue."))
                return None
            if (pw != confirm):
                print(_(PASSWORD_CONFIRM_ERROR_TUI))
                return None

            # If an empty password was provided, unset the value
            if not pw:
                self.value = ""
                return None

            pw_score, _status_text, pw_quality, error_message = validatePassword(
                pw, user=None, minlen=self.policy.minlen)

            # if the score is equal to 0 and we have an error message set
            # - ignore if the strict flag in the password policy == False
            if not pw_score and error_message and self.policy.strict:
                print(error_message)
                return None

            if pw_quality < self.policy.minquality:
                if self.policy.strict:
                    done_msg = ""
                else:
                    done_msg = _("\nWould you like to use it anyway?")

                if error_message:
                    error = _(PASSWORD_WEAK_WITH_ERROR
                              ) % error_message + " " + done_msg
                else:
                    error = _(PASSWORD_WEAK) % done_msg

                if not self.policy.strict:
                    question_window = YesNoDialog(self._app, error)
                    self._app.switch_screen_modal(question_window)
                    if not question_window.answer:
                        return None
                else:
                    print(error)
                    return None

            if any(char not in PW_ASCII_CHARS for char in pw):
                print(
                    _("You have provided a password containing non-ASCII characters.\n"
                      "You may not be able to switch between keyboard layouts to login.\n"
                      ))

            self.value = cryptPassword(pw)
            return None
        else:
            return _(
                "Enter new value for '%s' and press enter\n") % entry.title