Ejemplo n.º 1
0
 def success(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_AUTHSUCCESS):
         logger.debug("received AUTHSUCCESS event")
         event.keydist._completed.set()
         if (event.keydist.callback_success != None):
             event.keydist.callback_success()
     event.Skip()
Ejemplo n.º 2
0
 def get_log(topology_name, num_lines=10):
     filenames = StormUI.getWorkersByTopologyName(topology_name)
     lines = ""
     if filenames:
         logger.debug("Filenames for topology " + topology_name + " -> " +
                      str(filenames))
         for filename in filenames:
             logger.info("Topology :" + topology_name + " - LogFilename: " +
                         filename)
             # get log file from storm cluster
             n_lines = int(num_lines) * 100
             content = StormUI.getFile(filename, n_lines)
             try:
                 # Remove HTML tags from Storm Log 8000 port
                 logcontent = BeautifulSoup(content, "lxml").find(
                     "pre", {"id": "logContent"})
                 if logcontent:
                     lines += "\n###################################################\n"
                     (hostname, port,
                      name) = LogViewer.parse_worker_info(filename)
                     lines += "Log from worker: " + hostname + " - " + name + "\n"
                     lines += "###################################################\n"
                     lines += logcontent.getText()
                     logger.debug("Getting " +
                                  str(len(lines.splitlines())) + " lines.")
             except Exception as e:
                 return "Error parsing data from Storm UI:" + str(e)
     return lines
 def keyLockedCallback():
     logger.debug("Callback: Key locked.")
     dlg = wx.MessageDialog(self, "Your key appears to be locked.",
                     "MASSIVE/CVL Launcher", wx.OK | wx.ICON_INFORMATION)
     dlg.ShowModal()
     self.existingPassphraseField.SetSelection(-1,-1)
     self.existingPassphraseField.SetFocus()
Ejemplo n.º 4
0
    def createKey(self):

        createNewKeyDialog = CreateNewKeyDialog(
            None,
            None,
            wx.ID_ANY,
            "Strudel Private Key",
            self.launcherMainFrame.keyModel.getPrivateKeyFilePath(),
            self.launcherMainFrame.displayStrings,
        )
        createNewKeyDialog.Center()
        if createNewKeyDialog.ShowModal() == wx.ID_OK:
            logger.debug("User pressed OK from CreateNewKeyDialog.")
            password = createNewKeyDialog.getPassphrase()

            def success():
                pass

            def failure():
                pass

            self.launcherMainFrame.keyModel.generateNewKey(password, success, failure, failure)
            createdKey = True
        else:
            logger.debug("User canceled from CreateNewKeyDialog.")
            createdKey = False

        return createdKey
Ejemplo n.º 5
0
        def run(self):

            # I have a problem where I have multiple identity files in my ~/.ssh, and I want to use only identities loaded into the agent
            # since openssh does not seem to have an option to use only an agent we have a workaround,
            # by passing the -o IdentityFile option a path that does not exist, openssh can't use any other identities, and can only use the agent.
            # This is a little "racy" in that a tempfile with the same path could conceivably be created between the unlink and openssh attempting to use it
            # but since the pub key is extracted from the agent not the identity file I can't see anyway an attacker could use this to trick a user into uploading the attackers key.
            threadid = threading.currentThread().ident
            logger.debug("testAuthThread %i: started" % threadid)
            try:
                if (self.keydistObject.authorise.testAuth(
                        keyModel=self.keydistObject.keyModel,
                        username=self.keydistObject.username,
                        host=self.keydistObject.host,
                        timeout=160)):
                    newevent = KeyDist.sshKeyDistEvent(
                        KeyDist.EVT_KEYDIST_AUTHSUCCESS, self.keydistObject)
                else:
                    newevent = KeyDist.sshKeyDistEvent(
                        KeyDist.EVT_KEYDIST_AUTHFAIL, self.keydistObject)
            except Exception as e:
                import traceback
                logger.debug("testAuth failed with exception %s" % e)
                logger.debug(traceback.format_exc())
                newevent = KeyDist.sshKeyDistEvent(
                    KeyDist.EVT_KEYDIST_AUTHFAIL, self.keydistObject)

            if (not self.stopped()):
                logger.debug(
                    "testAuthThread %i: self.stopped() == False, so posting event: "
                    % threadid + str(newevent))
                wx.PostEvent(self.keydistObject.notifywindow.GetEventHandler(),
                             newevent)
            logger.debug("testAuthThread %i: stopped" % threadid)
Ejemplo n.º 6
0
 def getPassphrase(self, reason=None):
     from CreateNewKeyDialog import CreateNewKeyDialog
     createNewKeyDialog = CreateNewKeyDialog(
         self.parentWindow,
         self.progressDialog,
         wx.ID_ANY,
         self.parentWindow.programName,
         self.keyModel.getPrivateKeyFilePath(),
         self.displayStrings,
         displayMessageBoxReportingSuccess=False)
     try:
         wx.EndBusyCursor()
         stoppedBusyCursor = True
     except:
         stoppedBusyCursor = False
     canceled = createNewKeyDialog.ShowModal() == wx.ID_CANCEL
     if stoppedBusyCursor:
         wx.BeginBusyCursor()
     if (not canceled):
         logger.debug("User didn't cancel from CreateNewKeyDialog.")
         self.password = createNewKeyDialog.getPassphrase()
         event = KeyDist.sshKeyDistEvent(
             KeyDist.EVT_KEYDIST_NEWPASS_COMPLETE, self)
         wx.PostEvent(self.notifywindow.GetEventHandler(), event)
     else:
         logger.debug(
             "KeyDist.getPassphrase: User canceled from CreateNewKeyDialog."
         )
         self.cancel()
Ejemplo n.º 7
0
 def compile(base_path, quiet_mode=True):
     try:
         result = Mvn.compile_module(base_path, quiet_mode)
     except CommandException as e:
         result = e
     logger.debug('Command output: ' + str(result.log()))
     return Mvn.parse_process_result(result)
Ejemplo n.º 8
0
 def keyLockedCallback():
     logger.debug("Callback: Key locked.")
     dlg = wx.MessageDialog(self, "Your key appears to be locked.",
                            "Strudel", wx.OK | wx.ICON_INFORMATION)
     dlg.ShowModal()
     self.existingPassphraseField.SetSelection(-1, -1)
     self.existingPassphraseField.SetFocus()
Ejemplo n.º 9
0
 def authfail(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_AUTHFAIL
             and not event.keydist.canceled()):
         if (not event.keydist.keyloaded.isSet()):
             newevent = KeyDist.sshKeyDistEvent(
                 KeyDist.EVT_KEYDIST_LOADKEY, event.keydist)
             wx.PostEvent(event.keydist.notifywindow.GetEventHandler(),
                          newevent)
         else:
             # If the key is loaded into the ssh agent, then authentication failed because the public key isn't on the server.
             # *****TODO*****
             # Actually this might not be strictly true. GNOME Keychain (and possibly others) will report a key loaded even if its still locked
             # we probably need a button that says "I can't remember my old key's passphrase, please generate a new keypair"
             if (event.keydist.keycopied.isSet()):
                 newevent = KeyDist.sshKeyDistEvent(
                     KeyDist.EVT_KEYDIST_TESTAUTH, event.keydist)
                 logger.debug(
                     "received AUTHFAIL event from thread %i %s posting TESTAUTH event in response"
                     % (event.threadid, event.threadname))
                 wx.PostEvent(
                     event.keydist.notifywindow.GetEventHandler(),
                     newevent)
             else:
                 newevent = KeyDist.sshKeyDistEvent(
                     KeyDist.EVT_KEYDIST_COPYID, event.keydist)
                 logger.debug(
                     "received AUTHFAIL event from thread %i %s posting COPYID event in response"
                     % (event.threadid, event.threadname))
                 wx.PostEvent(
                     event.keydist.notifywindow.GetEventHandler(),
                     newevent)
     else:
         event.Skip()
Ejemplo n.º 10
0
 def createKey(self):
     logger.debug('in createKey method')
     if not self._stopped.isSet():
         if self.keyModel.isTemporaryKey():
             logger.debug('generating a temporary key passphrase')
             import string
             import random
             oneTimePassphrase=''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for x in range(10))
             logger.debug("tempoary key oneTimePassphrase: " + oneTimePassphrase)
             self.password = oneTimePassphrase
             self.removeKeyOnExit.set()
         else:
             logger.debug('requesting a permenant key passphrase')
             queue=Queue.queue()
             wx.CallAfter(self.getPassphrase,queue=queue)
             (canceled,self.password)=queue.get()
             if canceled:
                 self._stopped.set()
                 self.cancelMessage="canceled while requesting a new ssh key passphrase"
                 self._exit.set()
         if not self._stopped.isSet():
             def success(): 
                 logger.debug('succesfully generated a new ssh key')
                 self.keyCreated.set()
             def failure(): 
                 logger.debug("failed to generate a new ssh key")
                 self.cancelMessage="Unable to generate a new key pair"
                 self._stopped.set()
                 self._exit.set()
             if not self._stopped.isSet():
                 logger.debug('generating a new ssh key')
                 self.keyModel.generateNewKey(self.password,success,failure,failure)
Ejemplo n.º 11
0
    def processIdP(self,session,text,url,idpName,user,pw):
        p = AAF_Auth.genericForm()
        p.feed(text)
        import getpass
        import sys
        import Queue
        userRequired=False
        passwordRequired=False
        queue=Queue.Queue()
        for i in p.inputs.keys():
            if ('user' in i or 'User' in i) and p.inputs[i]==None:
                p.inputs[i] = user
            if ('pass' in i or 'Pass' in i) and p.inputs[i]==None:
                p.inputs[i] = pw
        try:
            nexturl = p.attrs['action']
        except:
            nexturl = url
        logger.debug('idp form inputs %s'%p.inputs)
        for k in p.inputs.keys():
            if 'RESET' in k.upper():
                logger.debug('deleting the input %s from the attribute release form'%k)
                del p.inputs[k]
        if  not 'http' in nexturl[0:4]:
            nexturl=url.split('/')[0]+'//'+url.split('/')[2]+nexturl

        r=session.post(nexturl,data=p.inputs,verify=False)
        return r
Ejemplo n.º 12
0
 def removeEC2Creds(self):
     from logger.Logger import logger
     import shutil
     try:
         shutil.rmtree(self.ec2path, ignore_errors=True)
     except:
         logger.debug("unable to remove ec2 credentials")
Ejemplo n.º 13
0
    def getFingerprintAndKeyTypeFromPrivateKeyFile(self):
        logger.debug("KeyModel.getFingerprintAndKeyTypeFromPrivateKeyFile")
        proc = subprocess.Popen([
            self.sshPathsObject.sshKeyGenBinary.strip('"'), "-yl", "-f",
            self.getPrivateKeyFilePath()
        ],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                universal_newlines=True,
                                startupinfo=self.startupinfo,
                                creationflags=self.creationflags)
        stdout, stderr = proc.communicate()

        publicKeyFingerprint = None
        keyType = None
        if stdout != None:
            sshKeyGenOutComponents = stdout.split(" ")
            if len(sshKeyGenOutComponents) > 1:
                publicKeyFingerprint = sshKeyGenOutComponents[1]
            if len(sshKeyGenOutComponents) > 3:
                keyType = sshKeyGenOutComponents[-1].strip().strip("(").strip(
                    ")")

        self.pubKeyFingerprint = publicKeyFingerprint

        return (publicKeyFingerprint, keyType)
Ejemplo n.º 14
0
 def startevent(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_START):
         logger.debug("received KEYDIST_START event")
         newevent = KeyDist.sshKeyDistEvent(KeyDist.EVT_KEYDIST_SCANHOSTKEYS,event.keydist)
         wx.PostEvent(event.keydist.notifywindow.GetEventHandler(),newevent)
     else:
         event.Skip()
Ejemplo n.º 15
0
    def onClose(self, e):
   
        logger.debug("ListSelectionDialog.onClose: button ID %s okButton ID %s cancelButton ID %s"%(e.GetId(),self.okButton.GetId(),self.cancelButton.GetId()))
        if (e.GetId() == self.cancelButton.GetId()):
            logger.debug("ListSelectionDialog.onClose: User canceled.")
            if self.cancelCallback != None:
                #self.cancelCallback("User canceled from ListSelectionDialog.")
                self.cancelCallback("")
            self.Destroy()
            return

        if self.listSelectionList.GetFirstSelected()==-1:
            dlg = wx.MessageDialog(self.parent, 
                self.noSelectionMessage,
                "MASSIVE/CVL Launcher", 
                wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            self.listSelectionList.SetFocus()
            return

        itemnum=self.listSelectionList.GetFocusedItem()
        item=self.listSelectionList.GetItem(itemnum,0)
        if self.okCallback != None:
            self.okCallback(item)
        self.Destroy()

        if self.closedProgressDialog:
            if self.progressDialog is not None:
                self.progressDialog.Show(True)
Ejemplo n.º 16
0
    def createKey(self):

        createNewKeyDialog = CreateNewKeyDialog(
            None, None, wx.ID_ANY, 'Strudel Private Key',
            self.launcherMainFrame.keyModel.getPrivateKeyFilePath(),
            self.launcherMainFrame.displayStrings)
        createNewKeyDialog.Center()
        if createNewKeyDialog.ShowModal() == wx.ID_OK:
            logger.debug("User pressed OK from CreateNewKeyDialog.")
            password = createNewKeyDialog.getPassphrase()

            def success():
                pass

            def failure():
                pass

            self.launcherMainFrame.keyModel.generateNewKey(
                password, success, failure, failure)
            createdKey = True
        else:
            logger.debug("User canceled from CreateNewKeyDialog.")
            createdKey = False

        return createdKey
Ejemplo n.º 17
0
    def gettoken(self):
        retry = True
        while retry:
            import Queue
            queue = Queue.Queue()
            wx.CallAfter(self.queryUserPass, queue, self.username)
            res = queue.get()
            if res == None:
                raise Exception("Login cancelled")
            else:
                (self.username, self.passwd) = res
                logger.debug('queryIdPUserPass set values for user: %s.' %
                             (self.username))
            r = self.session.post(self.destURL,
                                  auth=(self.clientusername,
                                        self.clientpasswd),
                                  data={
                                      'grant_type': 'password',
                                      'username': self.username,
                                      'password': self.passwd
                                  },
                                  verify=False)
            if r.status_code == 200:
                data = json.loads(r.text)
                retry = False
            else:
                logger.debug('AS portal reported %s %s' %
                             (r.status_code, r.text))

        return data['data']['access_token']
Ejemplo n.º 18
0
 def cancel(self,message=""):
     if (not self.canceled()):
         self._canceled.set()
         newevent = KeyDist.sshKeyDistEvent(KeyDist.EVT_KEYDIST_SHUTDOWN, self)
         newevent.arg = message
         logger.debug('sshKeyDist.cancel: setting canceled, sending EVT_KEYDIST_SHUTDOWN event.')
         wx.PostEvent(self.notifywindow.GetEventHandler(), newevent)
Ejemplo n.º 19
0
    def processIdP(self,session,text,url,idpName,user,pw):
        p = AAF_Auth.genericForm()
        p.feed(text)
        import getpass
        import sys
        import Queue
        userRequired=False
        passwordRequired=False
        queue=Queue.Queue()
        for i in p.inputs.keys():
            if ('user' in i or 'User' in i) and p.inputs[i]==None:
                p.inputs[i] = user
            if ('pass' in i or 'Pass' in i) and p.inputs[i]==None:
                p.inputs[i] = pw
        try:
            nexturl = p.attrs['action']
        except:
            nexturl = url
        #logger.debug('idp form inputs %s'%p.inputs)
        for k in p.inputs.keys():
            if 'RESET' in k.upper():
                logger.debug('deleting the input %s from the attribute release form'%k)
                del p.inputs[k]
        if  not 'http' in nexturl[0:4]:
            nexturl=url.split('/')[0]+'//'+url.split('/')[2]+nexturl

        r=session.post(nexturl,data=p.inputs,verify=False)
        return r
Ejemplo n.º 20
0
 def Refresh(self, incrementProgressDialog):
     dataDir = self.settingsModel.GetDataDirectory()
     logger.debug("UsersModel.Refresh(): Scanning " + dataDir + "...")
     usernames = os.walk(dataDir).next()[1]
     for username in usernames:
         logger.debug("\nFound subdirectory assumed to be username: "******"Didn't find a MyTardis user record for \"" + \
                 username + "\""
             dlg = wx.MessageDialog(None, message, "User not found",
                                    wx.OK | wx.ICON_ERROR)
             dlg.ShowModal()
             userRecord = UserModel(settingsModel=self.settingsModel,
                                    id=id, username=username,
                                    name="USER NOT FOUND IN MYTARDIS",
                                    email="USER NOT FOUND IN MYTARDIS")
             userRecord.SetId(id)
             self.AddRow(userRecord)
             self.foldersModel\
                 .ImportFolders(os.path.join(dataDir, username), userRecord)
         incrementProgressDialog()
Ejemplo n.º 21
0
 def run(self):
     try:
         pubKeyPath=self.keydistObject.keyModel.getPrivateKeyFilePath()+".pub"
         with open(pubKeyPath,'r') as f:
             pubkey=f.read()
         self.obj.copyID()
         logger.debug("KeyDist.CopyIDThread: copyID returned without error")
         event = KeyDist.sshKeyDistEvent(KeyDist.EVT_KEYDIST_TESTAUTH,self.keydistObject)
         # If the object represented an attempt at logging onto AAF, then we will try to get the IdP and save it for next time.
         # If its not an AAF login, we will catch the exception and pass
         try:
             idp=self.obj.getIdP()
             self.keydistObject.updateDict['idp']=idp
         except Exception as e:
             pass
         # This try catch means that if, in the course of authenticing the user, the authentication mechanism was able to tell us the username
         # That username will be updated. Example. Authenticing via AAF, I know I'm at Monash, and my Monash username is chines.
         # Monash will tell CVL what my email address is. CVL can look up my CVL username based on my email address.
         try:
             newusername=self.obj.getUsername()
             self.keydistObject.updateDict['username']=newusername
         except Exception as e:
             pass
     except Exception as e:
         logger.debug('CopyIDThread: threw exception : ' + str(e))
         self.keydistObject.cancel(message=str(e))
         return
     if (not self.stopped()):
         wx.PostEvent(self.keydistObject.notifywindow.GetEventHandler(), event)
     self.keydistObject.keyModel.copiedID.set()
     self.keydistObject.keycopied.set()
     self.keydistObject.__dict__.update(self.keydistObject.updateDict)
Ejemplo n.º 22
0
    def stopAgent(self):
        logger.debug("KeyModel.stopAgent: stopping the agent")

        logger.debug("KeyModel.stopAgent: On Windows, we will stop charade.exe or ssh-agent.exe (whichever one is running),")
        logger.debug("KeyModel.stopAgent: but we won't stop Pageant, because Pageant is what allows the user to run the")
        logger.debug("KeyModel.stopAgent: Launcher again without having to re-enter their passphrase.")

        # The code below was presumably added so that when a new Launcher version is installed, 
        # we can avoid the warning from the Setup Wizard that a Pageant process will need to be terminated
        # and then restarted after the new version is installed.  But this mechanism of allowing the Setup
        # Wizard to terminate and restart Pageant seems to work fine in my experience - JW.
        # This is not the case for the OpenSSH / Cygwin binaries and DLLs - we definitely don't want any
        # of them to be running when we try to install a new Launcher version with the Windows Setup Wizard.

        #if self.pageant!=None:
            #pageantPid=self.pageant.pid
            #self.pageant.kill()
            #self.pageant=None
        # Do no use self.sshAgentProcess.kill() the sshAgentProcess forks the real agent and exits so the kill won't get the real process
        if self.sshAgentProcess!=None:
            import signal
            try:
                os.kill(int(self.agentPid),signal.SIGTERM)
            except:
                logger.debug(traceback.format_exc())
            if 'PREVIOUS_SSH_AUTH_SOCK' in os.environ:
                os.environ['SSH_AUTH_SOCK'] = os.environ['PREVIOUS_SSH_AUTH_SOCK']
                del os.environ['PREVIOUS_SSH_AUTH_SOCK']
            else:
                del os.environ['SSH_AUTH_SOCK']
            self.sshAgentProcess=None
Ejemplo n.º 23
0
 def success(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_AUTHSUCCESS):
         logger.debug("received AUTHSUCCESS event")
         event.keydist._completed.set()
         if (event.keydist.callback_success != None):
             event.keydist.callback_success()
     event.Skip()
Ejemplo n.º 24
0
 def removeEC2Creds(self):
     from logger.Logger import logger
     import shutil
     try:
         shutil.rmtree(self.ec2path, ignore_errors=True)
     except:
         logger.debug("unable to remove ec2 credentials")
Ejemplo n.º 25
0
 def testAuth(self):
     logger.debug('skd attempting to test authorisation')
     logger.debug('usernamed set to %s' % self.jobParams['username'])
     return self.authoriser.testAuth(keyModel=self.keyModel,
                                     username=self.jobParams['username'],
                                     host=self.jobParams['loginHost'],
                                     timeout=160)
Ejemplo n.º 26
0
    def __init__(self,s,destURL,parent,idp=None):
        self.parent=parent
        self.idp=idp
        r=s.get(destURL,verify=False)
        if destURL in r.url: # We already have a valid session with the web service
            logger.debug('AAF cycle unnecessary, we\'re already auth\'d to this service')
            self.response=r
            return

        
        if r.url.startswith('https://ds'): # we've been redirected to the AAF discovery service
            logger.debug('AAF cycle sent us to the discovery service. Prompting for the correct IdP')
            p = AAF_Auth.DSForm()
            p.feed(r.text)
            import Queue
            queue=Queue.Queue()
            wx.CallAfter(self.queryIdP,p.options,queue,self.idp)
            res=queue.get()
            if res==None:
                raise Exception("Login cancled")
            else:
                (myidp,self.idp)=res
            d={}
            d['user_idp'] = myidp.encode('ascii')
            d['Select']='Select'
            nexturl = p.attrs['action']
            if  not 'http' in nexturl[0:4]:
                nexturl=r.url.split('/')[0]+'//'+r.url.split('/')[2]+nexturl
            r=s.post(nexturl,data=d,verify=False)

        else:
            logger.debug('AAF cycle bypassed the discovery service. Perhaps the web service sent us directly to an IdP? This is unusual, but within spec')

        if destURL in r.url: # If we have a session with the IdP and the IdP didn't ask to release attributes, we might already be at the destionation URL
            self.response=r
            return
        
        p=AAF_Auth.genericForm() # If we're no at the destURL we should be at either the IdP authentication page, or the IdP attribute release page
        # Not tested. I think if we already have session with the idp, the IdP may return an attribute release form rather than a login form. the method self.idp should still work.
        while (not p.inputs.has_key('SAMLResponse')):
            if destURL in r.url: # I'm puzzled by this, I though the SAMLResponse would always come as a hidden field in a form from the IdP along with a redirect, but apparently not
                self.response=r
                return
            r=self.processIdP(s,r.text,r.url)
            p=AAF_Auth.genericForm()
            p.feed(r.text)

        if destURL in r.url: # We have succeeded
            logger.debug('AAF cycle succeeded')
            self.response=r
            return
        nexturl = p.attrs['action']
        r=s.post(nexturl,data=p.inputs,verify=False) # We need one more post? This seems to be the behaviour on NeCTAR
        if destURL in r.url: # We have succeeded
            logger.debug('AAF Cycle succeeded with the extra post')
            self.response=r
            return
        else:
            raise Exception("We went through the whole AAF cycle, but didn't end up where the though we would. This is a bug. Please help us fix this up by sending an email/crash report")
Ejemplo n.º 27
0
 def privateKeyFileNotFoundCallback():
     message = "Private key file not found."
     logger.debug(
         "InspectKeyDialog.onAddKeyToOrRemoveFromAgent callback: "
         + message)
     dlg = wx.MessageDialog(self, message, "Strudel",
                            wx.OK | wx.ICON_INFORMATION)
     dlg.ShowModal()
Ejemplo n.º 28
0
 def keylocked(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_KEY_LOCKED):
         logger.debug("received KEY_LOCKED event")
         wx.CallAfter(event.keydist.GetKeyPassphrase)
     if (event.GetId() == KeyDist.EVT_KEYDIST_KEY_WRONGPASS):
         logger.debug("received KEY_WRONGPASS event")
         wx.CallAfter(event.keydist.GetKeyPassphrase,incorrect=True)
     event.Skip()
Ejemplo n.º 29
0
 def scanhostkeys(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_SCANHOSTKEYS):
         logger.debug("received SCANHOSTKEYS event")
         t = KeyDist.scanHostKeysThread(event.keydist)
         t.setDaemon(True)
         t.start()
         event.keydist.threads.append(t)
     event.Skip()
Ejemplo n.º 30
0
 def scanhostkeys(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_SCANHOSTKEYS):
         logger.debug("received SCANHOSTKEYS event")
         t = KeyDist.scanHostKeysThread(event.keydist)
         t.setDaemon(True)
         t.start()
         event.keydist.threads.append(t)
     event.Skip()
Ejemplo n.º 31
0
 def passphraseIncorrectCallback():
     message = "Passphrase incorrect."
     logger.debug(
         "InspectKeyDialog.onAddKeyToOrRemoveFromAgent callback: "
         + message)
     dlg = wx.MessageDialog(self, message, "Strudel",
                            wx.OK | wx.ICON_INFORMATION)
     dlg.ShowModal()
Ejemplo n.º 32
0
 def failedToConnectToAgentCallback():
     message = "Could not open a connection to your authentication agent."
     logger.debug(
         "InspectKeyDialog.onAddKeyToOrRemoveFromAgent callback: "
         + message)
     dlg = wx.MessageDialog(self, message, "Strudel",
                            wx.OK | wx.ICON_INFORMATION)
     dlg.ShowModal()
Ejemplo n.º 33
0
 def build_jar_with_dependencies(self, quiet_mode=False):
     result = Mvn.build_topology_jar(self.base_path, quiet_mode)
     logger.debug('Command output: ' + str(result.log()))
     result = Mvn.parse_process_result(result)
     if result:
         self.jar_name = self.topology[
             TopologyConsts.FIELD_NAME] + '-1.0-jar-with-dependencies.jar'
     return result
Ejemplo n.º 34
0
 def keylocked(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_KEY_LOCKED):
         logger.debug("received KEY_LOCKED event")
         wx.CallAfter(event.keydist.GetKeyPassphrase)
     if (event.GetId() == KeyDist.EVT_KEYDIST_KEY_WRONGPASS):
         logger.debug("received KEY_WRONGPASS event")
         wx.CallAfter(event.keydist.GetKeyPassphrase, incorrect=True)
     event.Skip()
Ejemplo n.º 35
0
    def build_module_jar(self):
        execution = Mvn.build_module_jar(self.base_path, self.name,
                                         self.version)

        output = execution.stdout
        logger.debug('Command output: ' + str(output))
        self.jar_file = os.path.join(self.base_path, 'target',
                                     self.name + '.' + self.version + '.jar')
Ejemplo n.º 36
0
    def run(self,callback,failcallback):
        from logger.Logger import logger
        q=Queue.Queue()
        wx.CallAfter(self.createProgressDialog,q)
        self.progressDialog=q.get()
        logger.debug("Running NeCTAR Provisioning")
        try:
            wx.CallAfter(self.progressDialog.Update,0, "Logging into NeCTAR Dashboard")
            if not self._canceled.isSet():
                self.loginNeCTAR()
            wx.CallAfter(self.progressDialog.Update,1, "Getting a list of your NeCTAR Projects")
            if not self._canceled.isSet():
                self.getProjects()
            if not self._canceled.isSet():
                self.queryProject()
            wx.CallAfter(self.progressDialog.Update,2, "Getting Cloud Credentials")
            if not self._canceled.isSet():
                try:
                    self.getEC2Creds()
                    self.removeEC2Creds()
                    self.connect()
                except Exception as e:
                    import traceback
                    logger.debug(traceback.format_exc())
                    raise e

            if not self._canceled.isSet():
                self.ec2key=self.getKeyPairByFP(self.keyModel.getFingerprint())
                if self.ec2key==None:
                    tmpkey=self.getKeyPairByName("%s_%s"%(self.keyModel.sshpaths.keyFileName,self.ec2_access_key))
                    if tmpkey==None:
                        self.ec2key=self.setKeyPair("%s_%s"%(self.keyModel.sshpaths.keyFileName,self.ec2_access_key),self.keyModel.getPubKey())
                    else:
                        logger.debug("A keypair exists with my default name, but its fingerprint doesn't match. Deleting and recreating")
                        self.connection.delete_key_pair("%s_%s"%(self.keyModel.sshpaths.keyFileName,self.ec2_access_key))
                        self.ec2key=self.setKeyPair("%s_%s"%(self.keyModel.sshpaths.keyFileName,self.ec2_access_key),self.keyModel.getPubKey())
            wx.CallAfter(self.progressDialog.Update,3, "Getting a list of VMs you can connect to")
            if not self._canceled.isSet():
                self.getInstances(keyname=self.ec2key.name)
            if not self._canceled.isSet():
                if len(self.instances)>0:
                    self.queryExisting()
                else:
                    self.bootNew=True
            if not self._canceled.isSet():
                if self.bootNew==True:
                    wx.CallAfter(self.progressDialog.Update,3, "Booting a new Instance")
                    self.bootVM()
            if not self._canceled.isSet():
                self.updateDict.update(self.getInstanceDetails())
            wx.CallAfter(self.progressDialog.Show,False)
            callback()
        except Exception as e:
            import traceback
            logger.debug(traceback.format_exc())
            logger.debug(e)
            self.cancel(traceback.format_exc())
            failcallback()
Ejemplo n.º 37
0
 def startevent(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_START):
         logger.debug("received KEYDIST_START event")
         newevent = KeyDist.sshKeyDistEvent(
             KeyDist.EVT_KEYDIST_SCANHOSTKEYS, event.keydist)
         wx.PostEvent(event.keydist.notifywindow.GetEventHandler(),
                      newevent)
     else:
         event.Skip()
Ejemplo n.º 38
0
 def needagent(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_NEEDAGENT and not event.keydist.canceled()):
         logger.debug("received NEEDAGENT event")
         t = KeyDist.startAgentThread(event.keydist)
         t.setDaemon(True)
         t.start()
         event.keydist.threads.append(t)
     else:
         event.Skip()
Ejemplo n.º 39
0
 def testauth(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_TESTAUTH):
         t = KeyDist.testAuthThread(event.keydist)
         t.setDaemon(True)
         t.start()
         logger.debug("received TESTAUTH event from thread %i %s, starting thread %i %s in response"%(event.threadid,event.threadname,t.ident,t.name))
         event.keydist.threads.append(t)
     else:
         event.Skip()
Ejemplo n.º 40
0
    def install_jar(self):
        if self.jar_file is None:
            self.build_module_jar()
        execution = Mvn.install_jar(self.base_path, self.jar_file, self.name,
                                    self.version)

        output = execution.stdout
        logger.debug('Command output: ' + str(output))
        return
Ejemplo n.º 41
0
 def loadkey(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_LOADKEY and not event.keydist.canceled()):
         t = KeyDist.loadKeyThread(event.keydist)
         t.setDaemon(True)
         t.start()
         logger.debug("received LOADKEY event from thread %i %s, starting thread %i %s in response"%(event.threadid,event.threadname,t.ident,t.name))
         event.keydist.threads.append(t)
     else:
         event.Skip()
Ejemplo n.º 42
0
    def OnInit(self):
        resetKeyDialog = ResetKeyDialog(None, wx.ID_ANY, 'Reset Key')
        resetKeyDialog.Center()
        if resetKeyDialog.ShowModal()==wx.ID_OK:
            logger.debug("Passphrase = " + resetKeyDialog.getPassphrase())
        else:
            logger.debug("User canceled.")
            return False

        return True
Ejemplo n.º 43
0
 def cancel(self, message=""):
     if (not self.canceled()):
         self._canceled.set()
         newevent = KeyDist.sshKeyDistEvent(KeyDist.EVT_KEYDIST_SHUTDOWN,
                                            self)
         newevent.arg = message
         logger.debug(
             'sshKeyDist.cancel: setting canceled, sending EVT_KEYDIST_SHUTDOWN event.'
         )
         wx.PostEvent(self.notifywindow.GetEventHandler(), newevent)
    def OnInit(self):
        changeKeyPassphraseDialog = ChangeKeyPassphraseDialog(None, wx.ID_ANY, 'Change Key Passphrase', os.path.join(os.path.expanduser('~'), '.ssh', "MassiveLauncherKey"))
        changeKeyPassphraseDialog.Center()
        if changeKeyPassphraseDialog.ShowModal()==wx.ID_OK:
            logger.debug("New passphrase = " + changeKeyPassphraseDialog.getNewPassphrase())
        else:
            logger.debug("User canceled.")
            return False

        return True
Ejemplo n.º 45
0
 def getPubKey(self):
     pubKeyPath = self.getPrivateKeyFilePath() + ".pub"
     try:
         with open(pubKeyPath, 'r') as f:
             pubkey = f.read()
             return pubkey
     except:
         logger.debug("KeyModel.getPubKey: %s not found" % pubKeyPath)
         return ""
     return None
Ejemplo n.º 46
0
 def needagent(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_NEEDAGENT
             and not event.keydist.canceled()):
         logger.debug("received NEEDAGENT event")
         t = KeyDist.startAgentThread(event.keydist)
         t.setDaemon(True)
         t.start()
         event.keydist.threads.append(t)
     else:
         event.Skip()
Ejemplo n.º 47
0
 def getPubKey(self):
     pubKeyPath=self.getPrivateKeyFilePath()+".pub"
     try:
         with open(pubKeyPath,'r') as f:
             pubkey=f.read()
             return pubkey
     except:
         logger.debug("KeyModel.getPubKey: %s not found"%pubKeyPath)
         return ""
     return None
Ejemplo n.º 48
0
    def OnInit(self):
        resetKeyDialog = ResetKeyDialog(None, wx.ID_ANY, 'Reset Key')
        resetKeyDialog.Center()
        if resetKeyDialog.ShowModal() == wx.ID_OK:
            logger.debug("Passphrase = " + resetKeyDialog.getPassphrase())
        else:
            logger.debug("User canceled.")
            return False

        return True
Ejemplo n.º 49
0
        def completeEvent(event):
            if (event.GetId() == KeyDist.EVT_KEYDIST_COMPLETE):
                if (event.keydist.canceled()):
                    if (event.keydist.callback_fail != None):
                        logger.debug("sshKeyDist.completeEvent: calling-back to indicate completion")
                        if event.arg!=None:
                            event.keydist.callback_fail(event.arg)
                        else:
                            event.keydist.callback_fail()

                event.keydist._completed.set()
Ejemplo n.º 50
0
 def testauth(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_TESTAUTH):
         t = KeyDist.testAuthThread(event.keydist)
         t.setDaemon(True)
         t.start()
         logger.debug(
             "received TESTAUTH event from thread %i %s, starting thread %i %s in response"
             % (event.threadid, event.threadname, t.ident, t.name))
         event.keydist.threads.append(t)
     else:
         event.Skip()
Ejemplo n.º 51
0
    def deleteKey(self):

        success = self.launcherMainFrame.keyModel.deleteKey(ignoreFailureToConnectToAgent=True)
        #success = success and self.launcherMainFrame.keyModel.removeKeyFromAgent()
        if success:
            message = "Launcher key was successfully deleted!"
            logger.debug(message)
        else:
            message = "An error occured while attempting to delete the existing key."
            logger.debug(message)

        return success
Ejemplo n.º 52
0
 def loadkey(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_LOADKEY
             and not event.keydist.canceled()):
         t = KeyDist.loadKeyThread(event.keydist)
         t.setDaemon(True)
         t.start()
         logger.debug(
             "received LOADKEY event from thread %i %s, starting thread %i %s in response"
             % (event.threadid, event.threadname, t.ident, t.name))
         event.keydist.threads.append(t)
     else:
         event.Skip()
Ejemplo n.º 53
0
 def run(self):
     logger.debug("genkeyThread: started")
     self.nextEvent=None
     def success(): 
         self.nextEvent = KeyDist.sshKeyDistEvent(KeyDist.EVT_KEYDIST_LOADKEY,self.keydistObject)
     def failure(): 
         self.keydistObject.cancel("Unable to generate a new key pair")
     self.keydistObject.keyModel.generateNewKey(self.keydistObject.password,success,failure,failure)
     self.keydistObject.keyCreated.set()
     if (not self.stopped() and self.nextEvent != None):
         logger.debug("genkeyThread: generating LOADKEY event from genkeyThread")
         wx.PostEvent(self.keydistObject.notifywindow.GetEventHandler(),self.nextEvent)
Ejemplo n.º 54
0
 def shutdownEvent(event):
     if (event.GetId() == KeyDist.EVT_KEYDIST_SHUTDOWN):
         logger.debug("received EVT_KEYDIST_SHUTDOWN event")
         nextevent = KeyDist.sshKeyDistEvent(KeyDist.EVT_KEYDIST_COMPLETE,event.keydist)
         try:
             nextevent.arg=event.arg
         except:
             pass
         event.keydist.shutdownThread=threading.Thread(target=event.keydist.shutdownReal,args=[nextevent])
         event.keydist.shutdownThread.start()
     else:
         event.Skip()
Ejemplo n.º 55
0
 def deleteRemoteKey(self,host,username):
     if self.copiedID.isSet() and self.pubKey!=None:
         import tempfile
         fd=tempfile.NamedTemporaryFile(delete=True)
         path=fd.name
         fd.close()
         cmd='{sshBinary} -A -T -o IdentityFile={nonexistantpath} -o PasswordAuthentication=no -o PubkeyAuthentication=yes -o StrictHostKeyChecking=no -l {username} {host} "sed \'\\#{key}# D\' -i ~/.ssh/authorized_keys"'
         key=self.pubKey.split(' ')[1]
         command = cmd.format(sshBinary=self.sshpaths.sshBinary,username=username,host=host,key=key,nonexistantpath=path)
         logger.debug('KeyModel.deleteRemoteKey: running %s to delete remote key'%command)
         p = subprocess.Popen(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,universal_newlines=True,startupinfo=self.startupinfo,creationflags=self.creationflags)
         (stdout,stderr) = p.communicate()
Ejemplo n.º 56
0
 def run(self):
     import os
     import hashlib
     nres=0
     while nres<self.nthreads:
         r=self.q.get()
         nres=nres+1
         if r[1]!=None:
             filename=os.path.join(self.path,hashlib.md5(r[0]).hexdigest())
             with open(filename,'w') as f:
                 logger.debug("retrieved site %s in a background download"%r[0])
                 f.write(r[1])
Ejemplo n.º 57
0
 def run(self):
     import os
     import hashlib
     nres=0
     while nres<self.nthreads:
         r=self.q.get()
         nres=nres+1
         if r[1]!=None:
             filename=os.path.join(self.path,hashlib.md5(r[0]).hexdigest())
             with open(filename,'w') as f:
                 logger.debug("retrieved site %s in a background download"%r[0])
                 f.write(r[1])
Ejemplo n.º 58
0
    def loadKey(self):
        km = self.keyModel
        self._loadKeySuccess = threading.Event()
        self._addKeyComplete = threading.Event()
        self._loadKeySuccess.clear()
        self._addKeyComplete.clear()
        if (self.password != None):
            password = self.password
        else:
            password = ""

        def incorrectCallback():
            queue = Queue.Queue()
            if self.password != None:
                wx.CallAfter(self.GetKeyPassphrase,
                             incorrect=True,
                             queue=queue)
            else:
                wx.CallAfter(self.GetKeyPassphrase,
                             incorrect=False,
                             queue=queue)
            (canceled, self.password) = queue.get()
            if canceled:
                self._stopped.set()
                self.cancelMessage = "canceled while requesting the existing ssh key passphrase"
                self._exit.set()
            self._addKeyComplete.set()

        def loadedCallback():
            self._loadKeySuccess.set()

        def failedToConnectToAgentCallback():
            self.cancelMessage = "failed to connect to agent callback"
            self._exit.set()
            self._stopped.set()

        logger.debug(
            "sshKeyDist.loadKeyThread.run: KeyModel information temporary: %s path: %s exists: %s"
            % (km.isTemporaryKey(), km.getPrivateKeyFilePath(),
               km.privateKeyExists()))
        if not os.path.exists(self.keyModel.sshPathsObject.sshKeyPath):
            if not self._stopped.isSet():
                self.createKey()
        while not self._loadKeySuccess.isSet() and not self._stopped.isSet(
        ) and not self._exit.isSet():
            logger.debug('attempting to add key to the ssh agent')
            if (self.password != None):
                password = self.password
            else:
                password = ""
            km.addKeyToAgent(password, loadedCallback, incorrectCallback, None,
                             failedToConnectToAgentCallback)
Ejemplo n.º 59
0
    def CreateDatasetIfNecessary(folderModel):
        description = folderModel.GetFolder()

        myTardisUrl = folderModel.settingsModel.GetMyTardisUrl()
        myTardisDefaultUsername = folderModel.settingsModel.GetUsername()
        myTardisDefaultUserApiKey = folderModel.settingsModel.GetApiKey()

        url = myTardisUrl + "/api/v1/dataset/?format=json" + \
            "&experiments__id=" + str(folderModel.GetExperiment().GetId())
        url = url + "&description=" + urllib.quote(description)

        headers = {"Authorization": "ApiKey " + myTardisDefaultUsername + ":" +
                   myTardisDefaultUserApiKey}

        response = requests.get(headers=headers, url=url)
        existingMatchingDatasets = response.json()
        numExistingMatchingDatasets = \
            existingMatchingDatasets['meta']['total_count']
        if numExistingMatchingDatasets == 1:
            logger.debug("Found existing dataset for folder " + description)
        elif numExistingMatchingDatasets > 1:
            logger.debug("WARNING: Found multiple datasets for folder " +
                         description)

        if numExistingMatchingDatasets == 0:
            logger.debug("Creating dataset record for folder: " + description)

            description = folderModel.GetFolder()
            experimentUri = folderModel.GetExperiment().GetResourceUri()
            immutable = False
            datasetJson = {
                "description": description,
                "experiments": [experimentUri],
                "immutable": immutable}
            data = json.dumps(datasetJson)
            headers = {"Authorization": "ApiKey " + myTardisDefaultUsername +
                       ":" + myTardisDefaultUserApiKey,
                       "Content-Type": "application/json",
                       "Accept": "application/json"}
            url = myTardisUrl + "/api/v1/dataset/"
            response = requests.post(headers=headers, url=url, data=data)
            if response.status_code >= 200 and response.status_code < 300:
                newDatasetJson = response.json()
                return DatasetModel(folderModel.settingsModel, newDatasetJson)
            else:
                logger.debug(url)
                logger.debug("response.status_code = " +
                             str(response.status_code))
                return None
        else:
            return DatasetModel(folderModel.settingsModel,
                                existingMatchingDatasets['objects'][0])
Ejemplo n.º 60
0
 def getInstances(self,keyname=None):
     # Get a list of VMs that match a) the image name b) the flavour c) the keypair
     try:
         self.instances=[]
         reservations = self.connection.get_all_reservations()
         for res in reservations:
             for instance in res.instances:
                 if instance.image_id == self.imageid:
                     if keyname !=None and keyname == instance.key_name:
                         self.instances.append(instance)
     except Exception as e:
         logger.debug(traceback.format_exc())
         logger.debug(e)