コード例 #1
0
ファイル: path.py プロジェクト: mobay7777/baboossh
 def save(self):
     c = dbConn.get().cursor()
     if self.id is not None:
         #If we have an ID, the user is already saved in the database : UPDATE
         c.execute(
             '''UPDATE paths 
             SET
                 src = ?,
                 dst = ?
             WHERE id = ?''',
             (self.src.getId() if self.src is not None else 0,
              self.dst.getId(), self.id))
     else:
         #The user doesn't exists in database : INSERT
         c.execute(
             '''INSERT INTO paths(src,dst)
             VALUES (?,?) ''',
             (self.src.getId() if self.src is not None else 0,
              self.dst.getId()))
         c.close()
         c = dbConn.get().cursor()
         c.execute('SELECT id FROM paths WHERE src=? AND dst=?',
                   (self.src.getId() if self.src is not None else 0,
                    self.dst.getId()))
         self.id = c.fetchone()[0]
     c.close()
     dbConn.get().commit()
コード例 #2
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def save(self):
     c = dbConn.get().cursor()
     if self.id is not None:
         #If we have an ID, the endpoint is already saved in the database : UPDATE
         c.execute(
             '''UPDATE connections 
             SET
                 endpoint= ?,
                 user = ?,
                 cred = ?,
                 tested = ?,
                 working = ?,
                 root = ?
             WHERE id = ?''',
             (self.endpoint.getId(), self.user.getId(), self.cred.getId(),
              self.tested, self.working, self.root, self.id))
     else:
         #The endpoint doesn't exists in database : INSERT
         c.execute(
             '''INSERT INTO connections(endpoint,user,cred,tested,working,root)
             VALUES (?,?,?,?,?,?) ''',
             (self.endpoint.getId(), self.user.getId(), self.cred.getId(),
              self.tested, self.working, self.root))
         c.close()
         c = dbConn.get().cursor()
         c.execute(
             'SELECT id FROM connections WHERE endpoint=? AND user=? AND cred=?',
             (self.endpoint.getId(), self.user.getId(), self.cred.getId()))
         self.id = c.fetchone()[0]
     c.close()
     dbConn.get().commit()
コード例 #3
0
 def save(self):
     c = dbConn.get().cursor()
     if self.id is not None:
         #If we have an ID, the host is already saved in the database : UPDATE
         c.execute(
             '''UPDATE hosts 
             SET
                 name = ?,
                 uname = ?,
                 issue = ?,
                 machineid = ?,
                 macs = ?
             WHERE id = ?''',
             (self.name, self.uname, self.issue, self.machineId,
              json.dumps(self.macs), self.id))
     else:
         #The host doesn't exists in database : INSERT
         c.execute(
             '''INSERT INTO hosts(name,uname,issue,machineid,macs)
             VALUES (?,?,?,?,?) ''',
             (self.name, self.uname, self.issue, self.machineId,
              json.dumps(self.macs)))
         c.close()
         c = dbConn.get().cursor()
         c.execute(
             'SELECT id FROM hosts WHERE name=? AND uname=? AND issue=? AND machineid=? AND macs=?',
             (self.name, self.uname, self.issue, self.machineId,
              json.dumps(self.macs)))
         self.id = c.fetchone()[0]
     c.close()
     dbConn.get().commit()
コード例 #4
0
 def save(self):
     c = dbConn.get().cursor()
     if self.id is not None:
         #If we have an ID, the user is already saved in the database : UPDATE
         c.execute(
             '''UPDATE users 
             SET
                 username = ?,
                 scope = ?,
                 found = ?
             WHERE id = ?''',
             (self.name, self.scope,
              self.found.getId() if self.found is not None else None,
              self.id))
     else:
         #The user doesn't exists in database : INSERT
         c.execute(
             '''INSERT INTO users(username,scope,found)
             VALUES (?,?,?) ''',
             (self.name, self.scope,
              self.found.getId() if self.found is not None else None))
         c.close()
         c = dbConn.get().cursor()
         c.execute('SELECT id FROM users WHERE username=?', (self.name, ))
         self.id = c.fetchone()[0]
     c.close()
     dbConn.get().commit()
コード例 #5
0
 def save(self):
     c = dbConn.get().cursor()
     if self.id is not None:
         #If we have an ID, the creds is already saved in the database : UPDATE
         c.execute(
             '''UPDATE creds 
             SET
                 type = ?,
                 content = ?,
                 identifier = ?,
                 scope = ?,
                 found = ?
             WHERE id = ?''',
             (self.credsType,
              self.credsContent, self.obj.getIdentifier(), self.scope,
              self.found.getId() if self.found is not None else None,
              self.id))
     else:
         #The creds doesn't exists in database : INSERT
         c.execute(
             '''INSERT INTO creds(type,content,identifier,scope,found)
             VALUES (?,?,?,?,?) ''',
             (self.credsType,
              self.credsContent, self.obj.getIdentifier(), self.scope,
              self.found.getId() if self.found is not None else None))
         c.close()
         c = dbConn.get().cursor()
         c.execute('SELECT id FROM creds WHERE type=? and identifier=?',
                   (self.credsType, self.obj.getIdentifier()))
         self.id = c.fetchone()[0]
     c.close()
     dbConn.get().commit()
コード例 #6
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def delete(self):
     if self.id is None:
         return
     c = dbConn.get().cursor()
     c.execute('DELETE FROM connections WHERE id = ?', (self.id, ))
     c.close()
     dbConn.get().commit()
     return
コード例 #7
0
 def delete(self):
     from baboossh.connection import Connection
     if self.id is None:
         return
     for connection in Connection.findByUser(self):
         connection.delete()
     c = dbConn.get().cursor()
     c.execute('DELETE FROM users WHERE id = ?', (self.id, ))
     c.close()
     dbConn.get().commit()
     return
コード例 #8
0
 def delete(self):
     from baboossh.path import Path
     if self.id is None:
         return
     for path in Path.findBySrc(self):
         path.delete()
     for endpoint in self.getEndpoints():
         endpoint.setHost(None)
         endpoint.save()
     c = dbConn.get().cursor()
     c.execute('DELETE FROM hosts WHERE id = ?', (self.id, ))
     c.close()
     dbConn.get().commit()
     return
コード例 #9
0
ファイル: path.py プロジェクト: mobay7777/baboossh
 def findAll(cls):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT src,dst FROM paths'):
         ret.append(Path(Host.find(row[0]), Endpoint.find(row[1])))
     c.close()
     return ret
コード例 #10
0
ファイル: path.py プロジェクト: mobay7777/baboossh
    def getAdjacencyList(cls):
        adj = {}
        adj[0] = []
        c = dbConn.get().cursor()
        for row in c.execute('SELECT dst FROM paths WHERE src=0'):
            adj[0].append(row[0])
        c.close()

        for endpoint in Endpoint.findAllWorking():
            adj[endpoint.getId()] = []
            c = dbConn.get().cursor()
            for row in c.execute('SELECT dst FROM paths WHERE src=?',
                                 (endpoint.getHost().getId(), )):
                adj[endpoint.getId()].append(row[0])
            c.close()
        return adj
コード例 #11
0
ファイル: path.py プロジェクト: mobay7777/baboossh
 def hasDirectPath(cls, dst):
     c = dbConn.get().cursor()
     c.execute('''SELECT id FROM paths WHERE src=0 and dst=?''',
               (dst.getId(), ))
     row = c.fetchone()
     c.close()
     return row is not None
コード例 #12
0
 def __init__(self, ip, port):
     self.ip = ip
     self.port = port
     self.host = None
     self.id = None
     self.scope = True
     self.scanned = False
     self.reachable = None
     self.found = None
     self.auth = []
     c = dbConn.get().cursor()
     c.execute(
         'SELECT id,host,scanned,reachable,auth,scope,found FROM endpoints WHERE ip=? AND port=?',
         (self.ip, self.port))
     savedEndpoint = c.fetchone()
     c.close()
     if savedEndpoint is not None:
         self.id = savedEndpoint[0]
         self.host = Host.find(savedEndpoint[1])
         self.scanned = savedEndpoint[2] != 0
         if savedEndpoint[3] is None:
             self.reachable = None
         else:
             self.reachable = savedEndpoint[3] != 0
         if savedEndpoint[4] is not None:
             self.auth = json.loads(savedEndpoint[4])
         self.scope = savedEndpoint[5] != 0
         if savedEndpoint[6] is not None:
             self.found = Endpoint.find(savedEndpoint[6])
コード例 #13
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def findAll(cls):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT id FROM connections'):
         ret.append(cls.find(row[0]))
     c.close()
     return ret
コード例 #14
0
ファイル: path.py プロジェクト: mobay7777/baboossh
 def findByDst(cls, dst):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT src,dst FROM paths WHERE dst=?',
                          (dst.getId(), )):
         ret.append(Path(Host.find(row[0]), Endpoint.find(row[1])))
     c.close()
     return ret
コード例 #15
0
 def find(cls, credId):
     c = dbConn.get().cursor()
     c.execute('''SELECT type,content FROM creds WHERE id=?''', (credId, ))
     row = c.fetchone()
     c.close()
     if row == None:
         return None
     return Creds(row[0], row[1])
コード例 #16
0
 def find(cls, userId):
     c = dbConn.get().cursor()
     c.execute('''SELECT username FROM users WHERE id=?''', (userId, ))
     row = c.fetchone()
     c.close()
     if row == None:
         return None
     return User(row[0])
コード例 #17
0
ファイル: path.py プロジェクト: mobay7777/baboossh
 def find(cls, pathId):
     c = dbConn.get().cursor()
     c.execute('''SELECT src,dst FROM paths WHERE id=?''', (pathId, ))
     row = c.fetchone()
     c.close()
     if row == None:
         return None
     return Path(Host.find(row[0]), Endpoint.find(row[1]))
コード例 #18
0
 def findByName(cls, name):
     c = dbConn.get().cursor()
     hosts = []
     for row in c.execute('''SELECT id FROM hosts WHERE name=?''',
                          (name, )):
         hosts.append(Host.find(row[0]))
     c.close()
     return hosts
コード例 #19
0
 def findByUsername(cls, name):
     c = dbConn.get().cursor()
     c.execute('''SELECT username FROM users WHERE username=?''', (name, ))
     row = c.fetchone()
     c.close()
     if row == None:
         return None
     return User(row[0])
コード例 #20
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def findWorking(cls):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT id FROM connections where working=?',
                          (True, )):
         ret.append(cls.find(row[0]))
     c.close()
     return ret
コード例 #21
0
 def delete(self):
     from baboossh.path import Path
     from baboossh.connection import Connection
     if self.id is None:
         return
     if self.host is not None:
         endpoints = self.host.getEndpoints()
         if len(endpoints) == 1:
             self.host.delete()
     for connection in Connection.findByEndpoint(self):
         connection.delete()
     for path in Path.findByDst(self):
         path.delete()
     c = dbConn.get().cursor()
     c.execute('DELETE FROM endpoints WHERE id = ?', (self.id, ))
     c.close()
     dbConn.get().commit()
     return
コード例 #22
0
 def getEndpoints(self):
     from baboossh.endpoint import Endpoint
     endpoints = []
     c = dbConn.get().cursor()
     for row in c.execute('SELECT ip,port FROM endpoints WHERE host=?',
                          (self.id, )):
         endpoints.append(Endpoint(row[0], row[1]))
     c.close()
     return endpoints
コード例 #23
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def findByUser(cls, user):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute(
             'SELECT endpoint,cred FROM connections WHERE user=?',
         (user.getId(), )):
         ret.append(
             Connection(Endpoint.find(row[0]), user, Creds.find(row[1])))
     c.close()
     return ret
コード例 #24
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def find(cls, connectionId):
     c = dbConn.get().cursor()
     c.execute('SELECT endpoint,user,cred FROM connections WHERE id=?',
               (connectionId, ))
     row = c.fetchone()
     c.close()
     if row is None:
         return None
     return Connection(Endpoint.find(row[0]), User.find(row[1]),
                       Creds.find(row[2]))
コード例 #25
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def findByEndpoint(cls, endpoint):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute(
             'SELECT user,cred FROM connections WHERE endpoint=?',
         (endpoint.getId(), )):
         ret.append(
             Connection(endpoint, User.find(row[0]), Creds.find(row[1])))
     c.close()
     return ret
コード例 #26
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def findAllWorkingByEndpoint(cls, endpoint):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute(
             'SELECT user,cred FROM connections WHERE working=1 AND endpoint=? ORDER BY root ASC',
         (endpoint.getId(), )):
         ret.append(
             Connection(endpoint, User.find(row[0]), Creds.find(row[1])))
     c.close()
     return ret
コード例 #27
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def findWorkingByEndpoint(cls, endpoint):
     c = dbConn.get().cursor()
     c.execute(
         'SELECT user,cred FROM connections WHERE working=1 AND endpoint=? ORDER BY root ASC',
         (endpoint.getId(), ))
     row = c.fetchone()
     c.close()
     if row is None:
         return None
     return Connection(endpoint, User.find(row[0]), Creds.find(row[1]))
コード例 #28
0
ファイル: connection.py プロジェクト: mobay7777/baboossh
 def findByCreds(cls, creds):
     ret = []
     c = dbConn.get().cursor()
     for row in c.execute(
             'SELECT endpoint,user FROM connections WHERE cred=?',
         (creds.getId(), )):
         ret.append(
             Connection(Endpoint.find(row[0]), User.find(row[1]), creds))
     c.close()
     return ret
コード例 #29
0
 def find(cls, hostId):
     c = dbConn.get().cursor()
     c.execute(
         '''SELECT name,uname,issue,machineId,macs FROM hosts WHERE id=?''',
         (hostId, ))
     row = c.fetchone()
     c.close()
     if row == None:
         return None
     return Host(row[0], row[1], row[2], row[3], json.loads(row[4]))
コード例 #30
0
 def find(cls, endpointId):
     if endpointId == 0:
         return None
     c = dbConn.get().cursor()
     c.execute('''SELECT ip,port FROM endpoints WHERE id=?''',
               (endpointId, ))
     row = c.fetchone()
     c.close()
     if row == None:
         return None
     return Endpoint(row[0], row[1])