[Oval-commits] r190 - in trunk/oval-server: . OvalServer dba dsa2oval
Pavel Vinogradov
blaze-guest at alioth.debian.org
Thu Aug 23 02:25:52 UTC 2007
Author: blaze-guest
Date: 2007-08-23 02:25:51 +0000 (Thu, 23 Aug 2007)
New Revision: 190
Modified:
trunk/oval-server/OvalServer/OvalHttpServer.py
trunk/oval-server/dba/dba.py
trunk/oval-server/dsa2oval/convertor.py
trunk/oval-server/oval-server.py
Log:
Fix agents definition sync
Modified: trunk/oval-server/OvalServer/OvalHttpServer.py
===================================================================
--- trunk/oval-server/OvalServer/OvalHttpServer.py 2007-08-21 09:42:59 UTC (rev 189)
+++ trunk/oval-server/OvalServer/OvalHttpServer.py 2007-08-23 02:25:51 UTC (rev 190)
@@ -3,21 +3,29 @@
from dba import dba
import os, sys, socket
import logging
+from dsa2oval import convertor
class HttpRequestHandler (SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_POST(self):
db = dba.dba ()
+ conv = convertor.Dsa2Oval(self.server.workdir)
self.server.logger.info ('httpServer: Process POST %s' % self.path)
length = int(self.headers.getheader('content-length'))
data = self.rfile.readline(length)
- client_ip = self.client_address[0]
- clientID = db.getAgentInfo(client_ip)
+ agentIP = self.client_address[0]
+ agentID = int(db.getAgentInfo(agentIP))
for status in data.split('&'):
(vulnID, vulnStatus) = status.split('=')
- db.updateAffected (int(clientID), int(vulnID), vulnStatus == 't' and 1 or 0)
+ db.updateAffected (agentID, int(vulnID), vulnStatus == 't' and 1 or 0)
+
+ self.server.logger.debug('httpThread: Agent %s - sync definitions' % agentIP)
+ files = db.makeDefList(agentID)
+ data = conv.createDefList(files)
+ conv.saveOvalDef('%s/%s.xml' % (self.server.workdir, agentIP))
+ self.server.logger.debug('httpThread: Agent %s - definitions synced' % agentIP)
self.send_response(200)
self.end_headers()
@@ -25,10 +33,11 @@
def do_GET (self):
self.server.logger.info ('httpServer: Process GET %s' % self.path)
db = dba.dba ()
- client_ip = self.client_address[0]
- if db.getAgentInfo(client_ip):
+ conv = convertor.Dsa2Oval(self.server.workdir)
+ agentIP = self.client_address[0]
+ if db.getAgentInfo(agentIP):
try:
- f = open (self.server.workdir+os.sep+client_ip+'.xml')
+ f = open (self.server.workdir+os.sep+agentIP+'.xml')
self.send_response(200)
self.send_header('Content-type', 'text/xml')
self.end_headers()
@@ -36,9 +45,16 @@
f.close()
return
except IOError:
- self.send_error(404, 'File Not Found: %s' % client_ip)
+ self.send_error(404, 'File Not Found: %s.xml' % agentIP)
else:
- db.addAgent(client_ip)
+ db.addAgent(agentIP)
+ agentID = db.getAgentInfo(agentIP)
+ self.server.logger.debug('httpThread: Agent %s - sync definitions' % agentIP)
+ files = db.makeDefList(agentID)
+ data = conv.createDefList(files)
+ conv.saveOvalDef('%s/%s.xml' % (self.server.workdir, agentIP))
+ self.server.logger.debug('httpThread: Agent %s - definitions synced' % agentIP)
+ #TODO: Make proper respond
class HttpsRequestHandler (HttpRequestHandler):
"""http request handler with QUIT stopping the server"""
Modified: trunk/oval-server/dba/dba.py
===================================================================
--- trunk/oval-server/dba/dba.py 2007-08-21 09:42:59 UTC (rev 189)
+++ trunk/oval-server/dba/dba.py 2007-08-23 02:25:51 UTC (rev 190)
@@ -4,10 +4,10 @@
class dbaNotInitialized(Exception):
pass
-class AgentAlreadyExistExiption(Exception):
+class AgentAlreadyExistException(Exception):
pass
-class AgentDoesNotExistExiption(Exception):
+class AgentDoesNotExistException(Exception):
pass
class dba:
@@ -93,7 +93,7 @@
def addAgent(self, agentName):
self.cursor.execute ('SELECT agentID FROM agents WHERE agentName = \'%s\'' % agentName)
if self.cursor.fetchall():
- raise AgentAlreadyExistExiption
+ raise AgentAlreadyExistException
else:
self.cursor.execute ('INSERT INTO agents (agentID, agentName, agentTimestamp) VALUES (NULL, \'%s\', \'%s\')' %
(agentName, datetime.now().strftime('%Y-%m-%d %H:%M')))
Modified: trunk/oval-server/dsa2oval/convertor.py
===================================================================
--- trunk/oval-server/dsa2oval/convertor.py 2007-08-21 09:42:59 UTC (rev 189)
+++ trunk/oval-server/dsa2oval/convertor.py 2007-08-23 02:25:51 UTC (rev 190)
@@ -5,14 +5,17 @@
from parser import wml
from parser import dsa
+class dsa2ovalNotInitialized(Exception):
+ pass
+
class Dsa2Oval:
inputDir = None
- outputDir = None
dsaref = {}
- def __init__ (self, input, output):
- self.inputDir = input
+ def __init__ (self, output):
+ if self.inputDir == None:
+ raise dsa2ovalNotInitialized
self.outputDir = output
def parsedir (self, directory, postfix):
@@ -79,12 +82,4 @@
xml.dom.ext.PrettyPrint (generator.createOVALDefinitions(self.dsaref), file)
file.close()
else:
- xml.dom.ext.PrettyPrint (generator.createOVALDefinitions(self.dsaref))
-
-if __name__ == '__main__':
- conv = Dsa2Oval ('/home/blaze/tmp/oval/server/dsa', '/home/blaze/tmp/oval/server/definitions')
- from dba import dba
- db = dba.dba('/tmp/oval-server.db')
- files = db.makeDefList(1)
- data = conv.createDefList(files)
- conv.saveOvalDef('stdout')
\ No newline at end of file
+ xml.dom.ext.PrettyPrint (generator.createOVALDefinitions(self.dsaref))
\ No newline at end of file
Modified: trunk/oval-server/oval-server.py
===================================================================
--- trunk/oval-server/oval-server.py 2007-08-21 09:42:59 UTC (rev 189)
+++ trunk/oval-server/oval-server.py 2007-08-23 02:25:51 UTC (rev 190)
@@ -67,7 +67,7 @@
def run (self):
self.__status = 1
self.db = dba ()
- conv = convertor.Dsa2Oval (self.storage, self.workdir)
+ conv = convertor.Dsa2Oval (self.workdir)
while self.__status:
self.logger.debug('syncThread: Run local sync')
@@ -98,7 +98,10 @@
self.config.read(cfgfile)
self.dsa_storage = self.config.get('general', 'dsa_storage')
self.db = self.config.get('general', 'db')
+ #Init static field in dba class
dba.dbPath = self.db
+ #Init static field in Dsa2Oval class
+ convertor.Dsa2Oval.inputDir = self.dsa_storage
logdirname = self.config.get('general', 'log_dir')
logfilename = self.config.get('general', 'log_file')
More information about the Oval-commits
mailing list