Exemplo n.º 1
0
 def edit(self, id, host, port, type, login, password):
     self.servers[id].close()
     connection = Ssh(host, port, type, id)
     connection.set_auth(login, password)
     self.servers[id] = connection
     
     self.rewind()
Exemplo n.º 2
0
 def testSimpleConnection(self):
     # Informations de connexion au serveur
     host = '10.32.4.30'
     user = '******'
     passwd = 'test'
     # La commande demande de renvoyer le login de l'utilisateur
     # Soit "test" suivi d'un retour à la ligne
     cmd = 'echo $USER'
     
     # Instanciation d'une connexion SSH
     client = Ssh(host, 22, "", 0)
     # Définition des login et password
     client.set_auth(user, passwd)
     # Connexion au serveur
     client.connect_thread()
     # Envoi de la commande et récupération du retour
     out = client.sendCommand(cmd)
     # Fermeture de la connexion
     client.close()
     
     # Vérification de la valeur récupérée
     # Si elle correspond à celle attendue (test\n)
     # Alors le test est correct
     # Sinon, il est négatif
     self.assertEqual(out, user + "\n")
Exemplo n.º 3
0
 def testInteractiveCommand(self):
     host = '10.32.4.30'
     cmd = 'sudo -S echo $USER'
     #cmd = 'sudo -S adduser machin'
     user = '******'
     passwd = 'test'
     
     client = Ssh(host, 22, "", 0)
     client.set_auth(user, passwd)
     client.connect_thread()
     out = client.sendInteractiveCommand(cmd, (passwd,))
     #out = client.sendInteractiveCommand(cmd, (passwd, 'ok', 'ok', '', '', '', '', '', 'O'))
     client.close()
     
     self.assertEqual(out, user + "\n")
Exemplo n.º 4
0
 def accept(self):
     print re.search('rm', self.ui.pteCommand.toPlainText())
     #re.compile('rm ([\-a-zA-Z]+)f').match(self.ui.pteCommand.toPlainText(), 1):
     # Checks if all the fields have been filed
     if self.ui.pteCommand.toPlainText() == '':
         QtGui.QMessageBox.information(self,
                     self.tr('Information'),
                     self.tr('You must enter a command.'))
     elif re.search('rm [\-a-zA-Z]+f', self.ui.pteCommand.toPlainText()):
         QtGui.QMessageBox.information(self,
                     self.tr('Information'),
                     self.tr('You must not use dangerous commands.'))
     else:
         # Change server's auth if needed
         auth_id, trash = self.ui.cbLoginPass.itemData(self.ui.cbLoginPass.currentIndex()).toInt()
         
         if self.default_id != auth_id:
             login, password = self.dblink.getAuthById(auth_id)
             self.server = Ssh(self.server.server.host, self.server.server.port, self.server.server.type, self.server.server.id)
             self.server.set_auth(login, password)
         
         self.hide()
         serverResponse = ServerResponse(self.dblink, self.server, self.ui.pteCommand.toPlainText(), self, self.parent)
         serverResponse.show()
Exemplo n.º 5
0
class SendCommand(QtGui.QDialog):
    def __init__(self, dblink, server, parent=None):
        super(SendCommand, self).__init__(parent)
        self.ui = Ui_SendCommand()
        self.ui.setupUi(self)
        
        self.dblink = dblink
        self.server = server
        self.parent = parent
        
        bookmarks = self.dblink.getBookmarks()
        
        self.ui.bookmarks.clear()
        for bookmark in bookmarks:
            self.ui.bookmarks.addItem(bookmark['label'], QtCore.QVariant(bookmark['command']))
        self.ui.bookmarks.setCurrentIndex(-1)
        
        # Add connector to the combobox of bookmarks
        self.connect(self.ui.bookmarks, QtCore.SIGNAL('currentIndexChanged(int)'),
                     self.on_event_bookmarks_currentIndexChanged)
        
        auths = self.dblink.getAuths()
        self.default_id, = self.dblink.getDefaultLoginIdByServer(server.server.id)
        
        i = 0
        self.ui.cbLoginPass.clear()
        for auth in auths:
            self.ui.cbLoginPass.addItem(auth['login'] + '/' + auth['password'], QtCore.QVariant(auth['id']))
            
            if self.default_id == auth['id']:
                self.ui.cbLoginPass.setCurrentIndex(i)
            i += 1
        
    def accept(self):
        print re.search('rm', self.ui.pteCommand.toPlainText())
        #re.compile('rm ([\-a-zA-Z]+)f').match(self.ui.pteCommand.toPlainText(), 1):
        # Checks if all the fields have been filed
        if self.ui.pteCommand.toPlainText() == '':
            QtGui.QMessageBox.information(self,
                        self.tr('Information'),
                        self.tr('You must enter a command.'))
        elif re.search('rm [\-a-zA-Z]+f', self.ui.pteCommand.toPlainText()):
            QtGui.QMessageBox.information(self,
                        self.tr('Information'),
                        self.tr('You must not use dangerous commands.'))
        else:
            # Change server's auth if needed
            auth_id, trash = self.ui.cbLoginPass.itemData(self.ui.cbLoginPass.currentIndex()).toInt()
            
            if self.default_id != auth_id:
                login, password = self.dblink.getAuthById(auth_id)
                self.server = Ssh(self.server.server.host, self.server.server.port, self.server.server.type, self.server.server.id)
                self.server.set_auth(login, password)
            
            self.hide()
            serverResponse = ServerResponse(self.dblink, self.server, self.ui.pteCommand.toPlainText(), self, self.parent)
            serverResponse.show()
    
    # Modify the contents of the command, thanks to a bookmark
    def on_event_bookmarks_currentIndexChanged(self, index):
        index, trash = QtCore.QVariant(index).toInt()
        text = self.ui.bookmarks.itemData(index).toString()
        self.ui.pteCommand.setPlainText(text)
Exemplo n.º 6
0
 def testConcurrentConnections(self):
     host = '10.32.4.30'
     cmd = 'echo $USER'
     
     user1 = 'test'
     passwd1 = 'test'
     
     user2 = 'test2'
     passwd2 = 'test2'
     
     # Connection 1
     client = Ssh(host, 22, "", 0)
     client.set_auth(user1, passwd1)
     client.connect_thread()
     out1 = client.sendCommand(cmd)
     client.close()
     
     # Connection 2
     client2 = Ssh(host, 22, "", 0)
     client2.set_auth(user2, passwd2)
     client2.connect_thread()
     out2 = client2.sendCommand(cmd)
     client2.close()
     
     self.assertEqual(out1,  "%s\n" % user1)
     self.assertEqual(out2,  "%s\n" % user2)