Added notifiaction for user (virus found, ...)
authorft
Mon, 09 Dec 2013 15:19:05 +0100
changeset 9cc99197f1e08
parent 8 0a5ba0ef1058
child 10 b97aad470500
Added notifiaction for user (virus found, ...)
src/OsecFS.py
     1.1 --- a/src/OsecFS.py	Mon Dec 09 10:12:57 2013 +0100
     1.2 +++ b/src/OsecFS.py	Mon Dec 09 15:19:05 2013 +0100
     1.3 @@ -222,7 +222,7 @@
     1.4      remote_ip = netaddr.IPNetwork("%s/%s" %(netifaces.ifaddresses("eth0")[2][0]["addr"], netifaces.ifaddresses("eth0")[2][0]["netmask"]))[1]
     1.5      
     1.6      url_options = {"type" : type, "message" : message }
     1.7 -    url = ("http://%s/notification?%s" %(remote_ip, urllib.urlencode(url_options)))
     1.8 +    url = ("http://%s:8090/notification?%s" %(remote_ip, urllib.urlencode(url_options)))
     1.9      
    1.10      LOG.debug ("Send notification to \"%s\"" %(url, ))
    1.11      
    1.12 @@ -238,6 +238,9 @@
    1.13      else:
    1.14          LOG.error("Server returned errorcode: %s" %(response.status,))
    1.15  
    1.16 +def sendReadOnlyNotification():
    1.17 +    sendNotification("critical", "Filesystem is in read only mode. If you want to export files please initialize an encrypted filesystem.")
    1.18 +
    1.19  class OsecFS (Fuse):
    1.20  
    1.21      __rootpath = None
    1.22 @@ -247,6 +250,7 @@
    1.23          self.__rootpath = rootpath
    1.24          Fuse.__init__ (self, *args, **kw)
    1.25          LOG.debug ("Init complete.")
    1.26 +        sendNotification("information", "Filesystem successfully mounted.")
    1.27  
    1.28      # defines that our working directory will be the __rootpath
    1.29      def fsinit(self):
    1.30 @@ -268,30 +272,35 @@
    1.31      def chmod (self, path, mode):
    1.32          LOG.debug ("*** chmod %s %s" % (path, oct(mode)))
    1.33          if (config.get("Main", "ReadOnly") == "true"):
    1.34 +            sendReadOnlyNotification()
    1.35              return -errno.EACCES
    1.36          os.chmod (fixPath (path), mode)
    1.37  
    1.38      def chown (self, path, uid, gid):
    1.39          LOG.debug ("*** chown %s %s %s" % (path, uid, gid))
    1.40          if (config.get("Main", "ReadOnly") == "true"):
    1.41 +            sendReadOnlyNotification()
    1.42              return -errno.EACCES
    1.43          os.chown (fixPath (path), uid, gid)
    1.44  
    1.45      def link (self, targetPath, linkPath):
    1.46          LOG.debug ("*** link %s %s" % (targetPath, linkPath))
    1.47          if (config.get("Main", "ReadOnly") == "true"):
    1.48 +            sendReadOnlyNotification()
    1.49              return -errno.EACCES
    1.50          os.link (fixPath (targetPath), fixPath (linkPath))
    1.51  
    1.52      def mkdir (self, path, mode):
    1.53          LOG.debug ("*** mkdir %s %s" % (path, oct(mode)))
    1.54          if (config.get("Main", "ReadOnly") == "true"):
    1.55 +            sendReadOnlyNotification()
    1.56              return -errno.EACCES
    1.57          os.mkdir (fixPath (path), mode)
    1.58  
    1.59      def mknod (self, path, mode, dev):
    1.60          LOG.debug ("*** mknod %s %s %s" % (path, oct (mode), dev))
    1.61          if (config.get("Main", "ReadOnly") == "true"):
    1.62 +            sendReadOnlyNotification()
    1.63              return -errno.EACCES
    1.64          os.mknod (fixPath (path), mode, dev)
    1.65  
    1.66 @@ -305,11 +314,13 @@
    1.67          #infected = scanFileClamAV (rootPath(self.__rootpath, path))
    1.68          if (infected == True):
    1.69              self.file.close ()
    1.70 +            sendNotification("critical", "Virus found. Access denied.")
    1.71              return -errno.EACCES
    1.72          
    1.73          whitelisted = whitelistFile (rootPath(self.__rootpath, path))
    1.74          if (whitelisted == False):
    1.75              self.file.close ()
    1.76 +            sendNotification("critical", "File not in whitelist. Access denied.")
    1.77              return -errno.EACCES
    1.78  
    1.79      def read (self, path, length, offset):
    1.80 @@ -328,12 +339,14 @@
    1.81      def rename (self, oldPath, newPath):
    1.82          LOG.debug ("*** rename %s %s %s" % (oldPath, newPath, config.get("Main", "ReadOnly")))
    1.83          if (config.get("Main", "ReadOnly") == "true"):
    1.84 +            sendReadOnlyNotification()
    1.85              return -errno.EACCES
    1.86          os.rename (fixPath (oldPath), fixPath (newPath))
    1.87  
    1.88      def rmdir (self, path):
    1.89          LOG.debug ("*** rmdir %s %s" % (path, config.get("Main", "ReadOnly")))
    1.90          if (config.get("Main", "ReadOnly") == "true"):
    1.91 +            sendReadOnlyNotification()
    1.92              return -errno.EACCES
    1.93          os.rmdir (fixPath (path))
    1.94  
    1.95 @@ -344,12 +357,14 @@
    1.96      def symlink (self, targetPath, linkPath):
    1.97          LOG.debug ("*** symlink %s %s %s" % (targetPath, linkPath, config.get("Main", "ReadOnly")))
    1.98          if (config.get("Main", "ReadOnly") == "true"):
    1.99 +            sendReadOnlyNotification()
   1.100              return -errno.EACCES
   1.101          os.symlink (fixPath (targetPath), fixPath (linkPath))
   1.102  
   1.103      def truncate (self, path, length):
   1.104          LOG.debug ("*** truncate %s %s %s" % (path, length, config.get("Main", "ReadOnly")))
   1.105          if (config.get("Main", "ReadOnly") == "true"):
   1.106 +            sendReadOnlyNotification()
   1.107              return -errno.EACCES
   1.108          f = open (fixPath (path), "a")
   1.109          f.truncate (length)
   1.110 @@ -358,6 +373,7 @@
   1.111      def unlink (self, path):
   1.112          LOG.debug ("*** unlink %s %s" % (path, config.get("Main", "ReadOnly")))
   1.113          if (config.get("Main", "ReadOnly") == "true"):
   1.114 +            sendReadOnlyNotification()
   1.115              return -errno.EACCES
   1.116          os.unlink (fixPath (path))
   1.117  
   1.118 @@ -369,6 +385,7 @@
   1.119          LOG.debug ("*** write %s %s %s %s" % (path, buf, offset, config.get("Main", "ReadOnly")))
   1.120          if (config.get("Main", "ReadOnly") == "true"):
   1.121              self.file.close()
   1.122 +            sendReadOnlyNotification()
   1.123              return -errno.EACCES
   1.124          self.file.seek (offset)
   1.125          self.file.write (buf)
   1.126 @@ -382,6 +399,7 @@
   1.127      def create (self, path, flags, mode):
   1.128          LOG.debug ("*** create %s %s %s %s %s" % (fixPath (path), oct (flags), oct (mode), flag2mode (flags), config.get("Main", "ReadOnly")))
   1.129          if (config.get("Main", "ReadOnly") == "true"):
   1.130 +            sendReadOnlyNotification()
   1.131              return -errno.EACCES
   1.132          self.file = os.fdopen (os.open (fixPath (path), flags, mode), flag2mode (flags))
   1.133          self.fd = self.file.fileno ()
   1.134 @@ -410,11 +428,5 @@
   1.135      osecfs.flags = 0
   1.136      osecfs.multithreaded = 0
   1.137  
   1.138 -    # osecfs.parser.add_option (mountopt=config.get("Main", "Mountpoint"),
   1.139 -    #                      metavar="PATH",
   1.140 -    #                      default=config.get("Main", "Rootpath"),
   1.141 -    #                      help="mirror filesystem from under PATH [default: %default]")
   1.142 -    # osecfs.parse(values=osecfs, errex=1)
   1.143 -
   1.144      fuse_args = [sys.argv[0], config.get ("Main", "Mountpoint")];
   1.145      osecfs.main (fuse_args)