1.1 --- a/src/OsecFS.py Tue Oct 29 15:13:44 2013 +0100
1.2 +++ b/src/OsecFS.py Tue Nov 26 16:13:18 2013 +0100
1.3 @@ -12,15 +12,23 @@
1.4 import errno
1.5
1.6 # ToDo replace with ikarus
1.7 -import pyclamav
1.8 +#import pyclamav
1.9 import subprocess
1.10
1.11 -MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath"]}
1.12 +import requests
1.13 +
1.14 +
1.15 +MINOPTS = { "Main" : ["Logfile", "Mountpoint", "Rootpath", "LocalScanserverURL", "RemoteScanserverURL"]}
1.16
1.17 CONFIG_NOT_READABLE = "Configfile is not readable"
1.18 CONFIG_WRONG = "Something is wrong with the config"
1.19 CONFIG_MISSING = "Section: \"%s\" Option: \"%s\" in configfile is missing"
1.20 LOG = None
1.21 +LOCAL_SCANSERVER_URL = ""
1.22 +REMOTE_SCANSERVER_URL = ""
1.23 +STATUS_CODE_OK = 200
1.24 +STATUS_CODE_INFECTED = 210
1.25 +STATUS_CODE_NOT_FOUND = 404
1.26
1.27 SYSTEM_FILE_COMMAND = "file"
1.28
1.29 @@ -92,21 +100,64 @@
1.30
1.31 return m
1.32
1.33 +def scanFileIkarus(path, fileobject):
1.34 + files = {'up_file': (path, fileobject)}
1.35 +
1.36 + try:
1.37 + #TODO: chance to remote server
1.38 + r = requests.post(LOCAL_SCANSERVER_URL, files=files)
1.39 + except requests.exceptions.ConnectionError:
1.40 + LOG.info("Remote scan server unreachable, using local scan server.")
1.41
1.42 + # TODO:
1.43 + # Here the local scan server should be contacted.
1.44 + # The requests package does not upload content in the second post request,
1.45 + # so no fallback server can be used right now (bug?)
1.46 + # I did not a find a solution yet, maybe another http package has to be used.
1.47 + # Disabled for now.
1.48
1.49 -def scanFile (path):
1.50 + #try:
1.51 + # r = requests.post(LOCAL_SCANSERVER_URL, files=files)
1.52 + #except requests.exceptions.ConnectionError:
1.53 + # return 2
1.54 + return 2
1.55 +
1.56 + if r.status_code == STATUS_CODE_OK:
1.57 + return 0
1.58 + elif r.status_code == STATUS_CODE_INFECTED:
1.59 + # Parse xml for info if desired
1.60 + #contentXML = r.content
1.61 + #root = ET.fromstring(contentXML)
1.62 + #status = root[1][2].text
1.63 + return 1
1.64 + else:
1.65 + return 2
1.66 +
1.67 +def scanFile (path, fileobject):
1.68 infected = False
1.69
1.70 LOG.debug ("Scan File: %s" % (path))
1.71
1.72 # ToDo implement ikarus
1.73 - result = pyclamav.scanfile (path)
1.74 + #result = pyclamav.scanfile (path)
1.75 + #LOG.debug ("Result of file \"%s\": %s" % (path, result))
1.76 + #if (result[0] != 0):
1.77 + # infected = True
1.78 +
1.79 + #if (infected == True):
1.80 + # LOG.error ("Virus found deny Access %s" % (result,))
1.81 +
1.82 + result = scanFileIkarus(path, fileobject)
1.83 LOG.debug ("Result of file \"%s\": %s" % (path, result))
1.84 - if (result[0] != 0):
1.85 +
1.86 + if (result == 2):
1.87 + LOG.error ("Connection to scan server could not be established.")
1.88 +
1.89 + if (result == 1):
1.90 infected = True
1.91
1.92 if (infected == True):
1.93 - LOG.error ("Virus found deny Access %s" % (result,))
1.94 + LOG.error ("Virus found deny Access %s" % (result))
1.95
1.96 return infected
1.97
1.98 @@ -181,7 +232,7 @@
1.99 self.file = os.fdopen (os.open (fixPath (path), flags), flag2mode (flags))
1.100 self.fd = self.file.fileno ()
1.101
1.102 - infected = scanFile (rootPath(self.__rootpath, path))
1.103 + infected = scanFile (rootPath(self.__rootpath, path), self.file)
1.104 if (infected == True):
1.105 self.file.close ()
1.106 return -errno.EACCES
1.107 @@ -259,6 +310,9 @@
1.108 config = loadConfig ()
1.109 initLog (config)
1.110
1.111 + LOCAL_SCANSERVER_URL = config.get("Main", "LocalScanserverURL")
1.112 + REMOTE_SCANSERVER_URL = config.get("Main", "RemoteScanserverURL")
1.113 +
1.114 osecfs = OsecFS (config.get ("Main", "Rootpath"))
1.115 osecfs.flags = 0
1.116 osecfs.multithreaded = 0