Пример #1
0
def importCertificateDialog(repView):
    """
    Let the user import a certificate. First brings up a file selection
    dialog, then asks for trust settings for the certificate being imported.
    """
    certificate = None
    app = wx.GetApp()
    res = Util.showFileDialog(app.mainFrame,
                              _(u"Choose a certificate to import"), u"", u"",
                              _(u"PEM files|*.pem;*.crt|All files (*.*)|*.*"),
                              wx.OPEN)

    (cmd, dir, filename) = res

    if cmd == wx.ID_OK:
        # dir and filename are unicode
        path = os.path.join(dir, filename)

        try:
            x509 = X509.load_cert(path)

            fprint = utils.fingerprint(x509)
            purpose = certificatePurpose(x509)
            # Note: the order of choices must match the selections code below
            choices = [_(u"Trust this certificate.")]
            if purpose & constants.PURPOSE_CA:
                choices += [
                    _(u"Trust this certificate to sign site certificates.")
                ]

            dlg = dialogs.ImportCertificateDialog(app.mainFrame, purpose,
                                                  fprint, x509, choices)
            trust = constants.TRUST_NONE
            if dlg.ShowModal() == wx.ID_OK:
                selections = dlg.GetSelections()
                # Note: this code must match the choices above
                for sel in selections:
                    if sel == 0:
                        trust |= constants.TRUST_AUTHENTICITY
                    if sel == 1:
                        trust |= constants.TRUST_SERVER
                certificate = importCertificate(x509, fprint, trust, repView)
            dlg.Destroy()

        except utils.CertificateException, e:
            wx.MessageBox(e.__unicode__(),
                          messages.ERROR,
                          parent=wx.GetApp().mainFrame)

        except Exception, e:
            log.exception(e)
            wx.MessageBox(_(
                u"Could not add certificate from: %(path)s\nCheck the path and try again."
            ) % {'path': path},
                          messages.ERROR,
                          parent=wx.GetApp().mainFrame)
Пример #2
0
def importCertificateDialog(repView):
    """
    Let the user import a certificate. First brings up a file selection
    dialog, then asks for trust settings for the certificate being imported.
    """
    certificate = None
    app = wx.GetApp()
    res = Util.showFileDialog(app.mainFrame,
                              _(u"Choose a certificate to import"),
                              u"",
                              u"",
                              _(u"PEM files|*.pem;*.crt|All files (*.*)|*.*"),
                              wx.OPEN)

    (cmd, dir, filename) = res

    if cmd  == wx.ID_OK:
        # dir and filename are unicode
        path = os.path.join(dir, filename)

        try:
            x509 = X509.load_cert(path)

            fprint = utils.fingerprint(x509)
            purpose = certificatePurpose(x509)
            # Note: the order of choices must match the selections code below
            choices = [_(u"Trust this certificate.")]
            if purpose & constants.PURPOSE_CA:
                choices += [_(u"Trust this certificate to sign site certificates.")]

            dlg = dialogs.ImportCertificateDialog(app.mainFrame,
                                       purpose,
                                       fprint,
                                       x509,
                                       choices)
            trust = constants.TRUST_NONE
            if dlg.ShowModal() == wx.ID_OK:
                selections = dlg.GetSelections()
                # Note: this code must match the choices above
                for sel in selections:
                    if sel == 0:
                        trust |= constants.TRUST_AUTHENTICITY
                    if sel == 1:
                        trust |= constants.TRUST_SERVER
                certificate = importCertificate(x509, fprint, trust, repView)
            dlg.Destroy()

        except utils.CertificateException, e:
            wx.MessageBox (e.__unicode__(), messages.ERROR,
                           parent=wx.GetApp().mainFrame)

        except Exception, e:
            log.exception(e)
            wx.MessageBox (_(u"Could not add certificate from: %(path)s\nCheck the path and try again.") % {'path': path},
                           messages.ERROR,
                           parent=wx.GetApp().mainFrame)
Пример #3
0
    def onSaveFileEvent(self, event):
        """
        Open a file to associate with this script, or save an existing
        script to a file.
        """
        if not self._item.body:
            # no script body, open and overwrite existing model data
            title = _(u"Open Script File")
            flags = wx.OPEN
        else:
            # model data exists, we need a place to write it
            title =_(u"Save Script File As")
            flags = wx.SAVE | wx.OVERWRITE_PROMPT

        if self._item.filePath:
            # already have a file, default to that name and path
            # dirname returns unicode here since the filePath variable is unicode
            path = os.path.dirname(self._item.filePath)
            name = self._item.filePath.split(os.sep)[-1]
        else:
            # no file yet, point to scripts directory, use display name
            name = self._item.displayName+u".py"
            # dirname returns an str of bytes since the __file__ variable is bytes
            path = os.path.dirname(schema.ns('osaf.app', self).scripts.__file__)
            # convert the path bytes to unicode
            path = unicode(path, sys.getfilesystemencoding())

        # present the Open/Save dialog
        result = Util.showFileDialog(wx.GetApp().mainFrame, 
                                     title,
                                     path,
                                     name,
                                     _(u"Python files|*.py|") + _(u"All files (*.*)|*.*"),
                                     flags)
        cmd, dir, fileName = result

        if cmd == wx.ID_OK:
            preferFile = len(self._item.body) == 0
            self._item.filePath = os.path.join(dir, fileName)
            self._item.sync_file_with_model(preferFile=preferFile)
            resyncEvent = schema.ns('osaf.views.detail', self).Resynchronize
            Block.Block.post(resyncEvent, {}, self)
            self.postEventByName('ResyncDetailParent', {})