[Oval-commits] r143 - in trunk/oval-server/src: . dba
Pavel Vinogradov
blaze-guest at alioth.debian.org
Fri Aug 17 14:52:53 UTC 2007
Author: blaze-guest
Date: 2007-08-17 14:52:53 +0000 (Fri, 17 Aug 2007)
New Revision: 143
Added:
trunk/oval-server/src/dba/
trunk/oval-server/src/dba/__init__.py
trunk/oval-server/src/dba/dba.py
Log:
Add database access module
Added: trunk/oval-server/src/dba/__init__.py
===================================================================
Added: trunk/oval-server/src/dba/dba.py
===================================================================
--- trunk/oval-server/src/dba/dba.py (rev 0)
+++ trunk/oval-server/src/dba/dba.py 2007-08-17 14:52:53 UTC (rev 143)
@@ -0,0 +1,78 @@
+from pysqlite2 import dbapi2 as db
+
+class dba:
+
+ __dbStruct = """
+ drop table if exists agents;
+ create table agents(
+ agentID int primary key,
+ agentName varchar(255),
+ agentStatus smallint,
+ agentTimestamp datetime
+ );
+
+ drop table if exists vulnerabilities;
+ create table vulnerabilities(
+ vulnID int primary key,
+ vulnDSA int,
+ vulnLocation carchar(255),
+ vulnTimestamp datetime
+ );
+
+ drop table if exists affected;
+ create table affected(
+ id int primary key,
+ agentID int,
+ vulnDSA int,
+ vulnTimestamp datetime,
+ status smallint
+ );"""
+
+ __dbPath = None
+ __conn = None
+ cursor = None
+
+ def __init__ (self, dbpath):
+ self.__dbPath = dbpath
+ self.__conn = db.connect(self.__dbPath)
+ self.cursor = self.__conn.cursor()
+
+ def getCursor(self):
+ if self.__conn:
+ if self.cursor:
+ return self.cursor
+ else:
+ self.cursor = self.__conn.cursor()
+
+ def __initDB(self):
+ self.cursor.executescript(self.__dbStruct)
+
+ def updateDSA(self, dsa, location, timestamp):
+ self.cursor.execute ('SELECT vulnID FROM vulnerabilities WHERE vulnDSA = %d' % dsa)
+ if self.cursor.fetchall():
+ self.cursor.execute ('UPDATE vulnerabilities set vulnLocation = \'%s\', vulnTimestamp = \'%s\' WHERE vulnDSA = %d' % (location, timestamp, dsa))
+ self.__conn.commit()
+ else:
+ self.__insertDSA(dsa, location, timestamp)
+
+ def __insertDSA(self, dsa, location, timestamp):
+ self.cursor.execute ('INSERT INTO vulnerabilities (vulnDSA, vulnLocation, vulnTimestamp) VALUES (%d, \'%s\', \'%s\')' % (dsa, location, timestamp))
+ self.__conn.commit()
+
+ def addAgent(self, agentName):
+ self.cursor.execute ('SELECT agentID FROM agents WHERE agentName = \'%s\'' % agentName)
+ if self.cursor.fetchall():
+ raise AgentAlreadyExistExiption
+ else:
+ self.cursor.execute ('INSERT INTO agents (agentName, agentTimestamp) VALUES (\'%s\', \'%s\')' %
+ (agentName, '22'))
+
+ def getDSAreport (self):
+ self.cursor.execute ('SELECT vulnDSA, vulnTimestamp from vulnerabilities;')
+ return (self.cursor.fetchall())
+
+if __name__ == "__main__":
+ sql = dba('/tmp/oval-server.db')
+ sql.updateDSA (111, '/tmp/111', '1')
+ #sql.updateDSA (112, '/tmp/111', '3')
+ print sql.getDSAreport()
\ No newline at end of file
More information about the Oval-commits
mailing list