Exemple #1
0
def main():
    import wx

    log = None

    signal.signal(signal.SIGINT, SignalHandler)
    signal.signal(signal.SIGTERM, SignalHandler)

    m2threading.init()

    # Init the toolkit with the standard environment.
    app = WXGUIApplication()

    # build options for this application
    portOption = Option("-p",
                        "--port",
                        type="int",
                        dest="port",
                        default=0,
                        metavar="PORT",
                        help="Set the port the venueclient control interface\
                        should listen on.")
    app.AddCmdLineOption(portOption)
    pnodeOption = Option(
        "--personalNode",
        type="int",
        dest="pnode",
        default=None,
        help="Run NodeService and ServiceManager with the client.")
    app.AddCmdLineOption(pnodeOption)
    urlOption = Option("--url",
                       type="string",
                       dest="url",
                       default="",
                       metavar="URL",
                       help="URL of venue to enter on startup.")
    app.AddCmdLineOption(urlOption)

    # Try to initialize
    try:
        args = app.Initialize("VenueClient")
    except MissingDependencyError, e:
        if e.args[0] == 'SSL':
            msg = "The installed version of Python has no SSL support.  Check that you\n"\
                  "have installed Python from python.org, or ensure SSL support by\n"\
                  "some other means."
        else:
            msg = "The following dependency software is required, but not available:\n\t%s\n"\
                    "Please satisfy this dependency and restart the software"
            msg = msg % e.args[0]
        MessageDialog(None, msg, "Initialization Error", style=wx.ICON_ERROR)
        sys.exit(-1)
Exemple #2
0
def ShowResult(result, title="Package Manager"):
    if True == gUseGui:
        from AccessGrid.UIUtilities import MessageDialog
        import wx
        try:
            wxapp = wx.PySimpleApp()
        except:
            pass
        dialog = MessageDialog(None,
                               str(result),
                               title,
                               style=wx.OK | wx.ICON_INFORMATION)
    else:
        print str(result)
    def Validate(self, win):
        '''
        Checks if win has correct parameters.
        '''
        tc = self.GetWindow()
        hostName = win.hostCtrl.GetValue()
        email = win.emailCtrl.GetValue()

        if hostName == "":
            MessageDialog(None,
                          "Please enter the machine name (mcs.anl.gov).",
                          style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.hostCtrl)
            return False

        elif hostName.find('.') == -1:
            MessageDialog(
                None,
                "Please enter complete machine name (machine.mcs.anl.gov).",
                style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.hostCtrl)
            return False

        elif not self.helpClass.CheckHost(hostName):
            MessageDialog(
                None,
                "Please enter valid machine name (machine.mcs.anl.gov). \nIP address is not a valid machine name.",
                style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.hostCtrl)
            return False

        elif email == "":
            MessageDialog(None,
                          "Please enter your e-mail address.",
                          style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.emailCtrl)
            return False

        elif email.find("@") == -1:
            MessageDialog(
                None,
                "Pleas enter a valid e-mail address, for example [email protected].",
                style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.emailCtrl)
            return False

        elif not self.helpClass.CheckEmail(hostName, email):
            MessageDialog(
                None,
                "The e-mail address and machine name should be on same domain. \n\nFor machine name: video.mcs.anl.gov  \n\nValid e-mail addresses could be: \n\[email protected] or [email protected] \n",
                style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.emailCtrl)
            return False

        return True
    def OnImportCertificate(self, event):

        if self.selectedItem is None:
            return
        
        item = self.reqList[self.selectedItem]
        status = self.certStatus[self.selectedItem]

        cert = status[1]

        #
        # Write the cert out to a tempfile, then import.
        #

        hash = NewMd5Hash(cert).hexdigest()
        tempfile = os.path.join(UserConfig.instance().GetTempDir(), "%s.pem" % (hash))

        try:
            try:
                fh = open(tempfile, "w")
                fh.write(cert)
                fh.close()

                certMgr = Toolkit.Application.instance().GetCertificateManager()
                impCert = certMgr.ImportRequestedCertificate(tempfile)

                MessageDialog(self,
                              "Successfully imported certificate for\n" +
                              str(impCert.GetSubject()),
                              "Import Successful")
                self.AddCertificates()

            except RepoInvalidCertificate, e:
                log.exception("Invalid certificate")
                msg = e[0]
                ErrorDialog(self,
                            "The import of your approved certificate failed:\n"+
                            msg,
                            "Import Failed")


            except:
                log.exception("Import of requested cert failed")
                ErrorDialog(self,
                            "The import of your approved certificate failed.",
                            "Import Failed")
Exemple #5
0
def main():
    pyapp = wx.PySimpleApp()

    app = WXGUIApplication()

    try:
        app.Initialize("CertificateManager")
    except MissingDependencyError, e:
        if e.args[0] == 'SSL':
            msg = "The installed version of Python has no SSL support.  Check that you\n"\
                  "have installed Python from python.org, or ensure SSL support by\n"\
                  "some other means."
        else:
            msg = "The following dependency software is required, but not available:\n\t%s\n"\
                    "Please satisfy this dependency and restart the software"
            msg = msg % e.args[0]
        MessageDialog(None, msg, "Initialization Error", style=wx.ICON_ERROR)
        sys.exit(-1)
    def RequestCertificate(self,
                           reqInfo,
                           password,
                           proxyEnabled=0,
                           proxyHost=None,
                           proxyPort=None,
                           crsServerURL=None):
        """
        Request a certificate.

        reqInfo is an instance of CertificateManager.CertificateRequestInfo.

        Perform the actual certificate request mechanics.

        Returns 1 on success, 0 on failure.
        """

        log.debug("RequestCertificate: Create a certificate request")
        log.debug("Proxy enabled: %s value: %s:%s", proxyEnabled, proxyHost,
                  proxyPort)

        #
        # Ptui. Hardcoding name for the current AGdev CA.
        # Also hardcoding location of submission URL.
        #

        if crsServerURL is None:
            crsServerURL = "http://www.mcs.anl.gov/research/projects/accessgrid/ca/agdev/certReqServer.cgi"
        try:
            repo = self.certificateManager.GetCertificateRepository()

            name = reqInfo.GetDN()
            log.debug("Requesting certificate for dn %s", name)
            log.debug("reqinfo isident: %s info: %s",
                      reqInfo.IsIdentityRequest(), str(reqInfo))

            #
            # Service/host certs don't have encrypted private keys.
            #
            if not reqInfo.IsIdentityRequest():
                password = None

            certificateRequest = repo.CreateCertificateRequest(name, password)

            pem = certificateRequest.ExportPEM()

            log.debug("SubmitRequest:Validate: ExportPEM returns %s", pem)
            log.debug("SubmitRequest:Validate: subj is %s",
                      certificateRequest.GetSubject())
            log.debug("SubmitRequest:Validate: mod is %s",
                      certificateRequest.GetModulus())
            log.debug("SubmitRequest:Validate:modhash is %s",
                      certificateRequest.GetModulusHash())

            if proxyEnabled:
                certificateClient = CRSClient(crsServerURL, proxyHost,
                                              proxyPort)
            else:
                certificateClient = CRSClient(crsServerURL)

            try:
                requestId = certificateClient.RequestCertificate(
                    reqInfo.GetEmail(), pem)

                log.debug("SubmitRequest:Validate:Request id is %s", requestId)

                certificateRequest.SetMetadata(
                    "AG.CertificateManager.requestToken", str(requestId))
                certificateRequest.SetMetadata(
                    "AG.CertificateManager.requestURL", crsServerURL)
                certificateRequest.SetMetadata(
                    "AG.CertificateManager.requestType", reqInfo.GetType())
                certificateRequest.SetMetadata(
                    "AG.CertificateManager.creationTime",
                    str(int(time.time())))

                repo.NotifyObservers()
                return 1
            except CRSClientInvalidURL:
                MessageDialog(
                    None,
                    "Certificate request failed: invalid request URL",
                    style=wx.ICON_ERROR)
                return 0
            except CRSClientConnectionFailed:
                if proxyEnabled:
                    MessageDialog(
                        None,
                        "Certificate request failed: Connection failed.\n" +
                        "Did you specify the http proxy address correctly?",
                        style=wx.ICON_ERROR)
                else:
                    MessageDialog(
                        None,
                        "Certificate request failed: Connection failed.\n" +
                        "Do you need to configure an http proxy address?",
                        style=wx.ICON_ERROR)
                return 0
            except:
                log.exception("Unexpected error in cert request")
                MessageDialog(None,
                              "Certificate request failed",
                              style=wx.ICON_ERROR)
                return 0

        except CertificateRepository.RepoDoesNotExist:
            log.exception(
                "SubmitRequest:Validate:You do not have a certificate repository. Certificate request can not be completed."
            )

            MessageDialog(
                None,
                "You do not have a certificate repository. Certificate request can not be completed.",
                style=wx.ICON_ERROR)

        except:
            log.exception(
                "SubmitRequest:Validate: Certificate request can not be completed"
            )
            MessageDialog(
                None,
                "Error occured. Certificate request can not be completed.",
                style=wx.ICON_ERROR)
Exemple #7
0
        app.Initialize("NodeManagement")
    except MissingDependencyError, e:
        if e.args[0] == 'SSL':
            msg = "The installed version of Python has no SSL support.  Check that you\n"\
                  "have installed Python from python.org, or ensure SSL support by\n"\
                  "some other means."
        else:
            msg = "The following dependency software is required, but not available:\n\t%s\n"\
                    "Please satisfy this dependency and restart the software"
            msg = msg % e.args[0]
        MessageDialog(None, msg, "Initialization Error", style=wx.ICON_ERROR)
        sys.exit(-1)
    except Exception, e:
        print "Toolkit Initialization failed, exiting."
        print " Initialization Error: ", e
        MessageDialog(
            None,
            "The following error occurred during initialization:\n\n\t%s %s" %
            (e.__class__.__name__, e),
            "Initialization Error",
            style=wx.ICON_ERROR)
        sys.exit(-1)

    log = app.GetLog()

    nodeMgmtApp.MainLoop()


if __name__ == "__main__":
    main()
    def Validate(self, win):
        '''
        Checks if win has correct parameters.
        '''
        # Are we going back or forward?

        firstName = win.firstNameCtrl.GetValue()
        lastName = win.lastNameCtrl.GetValue()
        email = win.emailCtrl.GetValue()
        domain = win.domainCtrl.GetValue()
        password = win.passwordCtrl.GetValue()
        password2 = win.passwordVerCtrl.GetValue()

        if firstName == "":
            MessageDialog(None,
                          "Please enter your first name.",
                          style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.firstNameCtrl)
            return False

        elif lastName == "":
            MessageDialog(None,
                          "Please enter your last name.",
                          style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.lastNameCtrl)
            return False

        elif email == "":
            MessageDialog(None,
                          "Please enter your e-mail address.",
                          style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.emailCtrl)
            return False

        elif email.find("@") == -1:
            MessageDialog(
                None,
                "Pleas enter a valid e-mail address, for example [email protected].",
                style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.emailCtrl)
            return False

        elif password == "":
            MessageDialog(None,
                          "Please enter your passphrase.",
                          style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.passwordCtrl)
            return False

        elif password != password2:
            MessageDialog(
                None,
                "Your passphrase entries do not match. Please retype them.",
                style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.passwordCtrl)
            self.helpClass.SetColour(win.passwordVerCtrl)
            return False

        elif domain == "":
            MessageDialog(
                None,
                "Please enter the domain name of your home site; for example, example.com..",
                style=wx.OK | wx.ICON_INFORMATION)
            self.helpClass.SetColour(win.domainCtrl)
            return False

        return True
    def Install(self):
        """
        Install this certificate into the local repo:

            Write cert to a tempfile.
            Invoke cert mgr's import method.
            Delete the tempfile.

        """

        if not self.certReady:
            raise Exception("Certificate is not ready for installation")

        certText = self.fullStatus

        impCert = None

        hash = NewMd5Hash(certText).hexdigest()
        temp_path = os.path.join(UserConfig.instance().GetTempDir(),
                                 "%s.pem" % (hash))

        try:
            try:
                # Check to see if there's a lingering copy of the file from before.
                if os.path.isfile(temp_path):
                    log.debug(
                        "Cert import temporary file %s already exists, deleting",
                        temp_path)

                    try:
                        os.unlink(temp_path)

                    except:
                        log.exception("Unlink of tempfile %s failed",
                                      temp_path)
                        # Hmm, weird. Make up a new filename instead.
                        new_path = tempfile.mktemp(".pem")

                        # Use just the name part on the user's temp dir.
                        new_head, new_tail = os.path.split(new_path)
                        temp_path = os.path.join(
                            UserConfig.instance().GetTempDir(), new_tail)

                # back to our normal life.
                fh = open(temp_path, "wb")
                fh.write(certText)
                fh.close()

                # Be more paranoid. Ensure the file was created.
                try:
                    fileInfo = os.stat(temp_path)
                except OSError:
                    log.exception(
                        "Installing certificate: temp file %s was not created",
                        temp_path)
                    ErrorDialog(
                        self.browser,
                        "The system could not create a temporary file for this certificate import.\n"
                        +
                        "Try restarting the software or rebooting your computer."
                        "Import Failed")
                    return

                if fileInfo.st_size != len(certText):
                    log.error(
                        "File %s write did not work: fileSize=%s certSize=%s",
                        temp_path, fileInfo.st_size, len(certText))

                certMgr = self.browser.GetCertificateManager()
                impCert = certMgr.ImportRequestedCertificate(temp_path)

                certName = str(impCert.GetSubject())

                log.debug("Successfully imported certificate for %s", certName)

                MessageDialog(
                    self.browser,
                    "Successfully imported certificate for\n" + certName,
                    "Import Successful")
                self.browser.Load()

            except CertificateRepository.RepoInvalidCertificate, e:
                log.exception("Invalid certificate")
                msg = e[0]
                ErrorDialog(
                    self.browser,
                    "The import of your approved certificate failed:\n" + msg,
                    "Import Failed")

            except:
                log.exception("Import of requested cert failed")
                ErrorDialog(self.browser,
                            "The import of your approved certificate failed.",
                            "Import Failed")