class Catcher: def __init__(self, ct, filterfile, efilterfile, defcryptstring): self.ct = ct # ensure default encryption filter object is created self.efilters = EncryptionFilters(efilterfile, defcryptstring) if filterfile is not None: self.filter = Filter(filterfile) else: self.filter = None def catchDecryptByTag(self, tag): # we need to search throuh our encryption filter # and attempt to determine the plugin and options # to pass for reversal of the encryption return self.efilters.reverse(tag) def catchEncryptFilter(self, lpath, node, isDir): if self.efilters is not None: # get the encryption information we need einfo = self.efilters.check(lpath, node, isDir) # build and name some important stuff for readability etag = einfo[0] plugid = einfo[1] plugopts = einfo[2] plugtag = '%s.%s' % (plugid, plugopts) plug = getPM().getPluginInstance(plugid, plugtag, (None, plugopts)) else: # this should rarely be used.. the caller will likely be providing # the efilter object when calling this function, but it is here # in the event that they do not.. etag = b'' plug = getPM().getPluginInstance('crypt.null', '', (None, [])) plugopts = (c, []) return (etag, plug, plugopts)
class Catcher: def __init__(self, filterFile, efilterfile, defcryptstring): # ensure default encryption filter object is created self.efilters = EncryptionFilters(efilterfile, defcryptstring) if filterFile is not None: self.filter = Filter(filterFile) else: self.filter = None self.writeCount = 0 self.startCount = 0 self.finishCount = 0 self.hashGoodCount = 0 self.hashBadCount = 0 self.dateReplyCount = 0 self.sizeReplyCount = 0 self.bytesWrote = 0 self.acceptedCount = 0 self.rejectedCount = 0 self.linecnt = 0 self.smsgcnt = 0 print('\n\n\n\n\n', end='\x1b[3A') def writeline(self, txt, row=0): # write line and move back if row > 0: print('', end='\x1b[%sB' % row) print(txt, end='\x1b[1000D') if row > 0: print('', end='\x1b[%sA' % row) def event(self, *args): ename = args[0] #self.writeline(ename) if ename == 'DecryptByTag': return self.catchDecryptByTag(*args[1:]) if ename == 'EncryptFilter': return self.catchEncryptFilter(*args[1:]) if ename == 'Filter': return self.catchFilter(*args[1:]) if False: return if ename == 'FileWrite': #txt = '%s:%x:%x' % (args[1], args[2], args[3]) #txt = txt.ljust(40) #self.writeline(txt, row = 3) return if ename == 'Cycle' or ename == 'DumpCycle': return if ename == 'DataOut': ch = '#' vp = '#'.rjust(self.smsgcnt % 40) vp = vp.ljust(40) vp = 'Local: [%s]' % vp self.smsgcnt += 1 self.writeline(vp, row=1) return if ename == 'DataIn': vp = '#'.rjust(self.smsgcnt % 40) vp = vp.ljust(40) vp = 'Server:[%s]' % vp self.smsgcnt += 1 self.writeline(vp, row=2) return ignored = ('MessageOut', 'MessageIn') if ename in ignored: return lpath = args[2] txt = lpath.decode('utf8', 'ignore') if len(txt) > 40: txt = txt[-40:] txt = 'File: [%s]' % (txt.ljust(40)) self.writeline(txt) self.linecnt += 1 def catchDecryptByTag(self, tag): # we need to search throuh our encryption filter # and attempt to determine the plugin and options # to pass for reversal of the encryption return self.efilters.reverse(tag) def catchEncryptFilter(self, lpath, node, isDir): if self.efilters is not None: # get the encryption information we need einfo = self.efilters.check(lpath, node, isDir) # build and name some important stuff for readability etag = einfo[0] plugid = einfo[1] plugopts = einfo[2] plugtag = '%s.%s' % (plugid, plugopts) plug = getPM().getPluginInstance(plugid, plugtag, ( None, plugopts, )) else: # this should rarely be used.. the caller will likely be providing # the efilter object when calling this function, but it is here # in the event that they do not.. etag = b'' plug = getPM().getPluginInstance('crypt.null', '', (c, [])) plugopts = (c, []) return (etag, plug, plugopts) def catchFilter(self, lpath, node, isDir): if self.filter is None: return True result = self.filter.check(lpath, node, isDir) if result: self.acceptedCount += 1 else: self.rejectedCount += 1 print('result', result) return result
class Catcher: def __init__(self, filterFile, efilterfile, defcryptstring): # ensure default encryption filter object is created self.efilters = EncryptionFilters(efilterfile, defcryptstring) if filterFile is not None: self.filter = Filter(filterFile) else: self.filter = None self.writeCount = 0 self.startCount = 0 self.finishCount = 0 self.hashGoodCount = 0 self.hashBadCount = 0 self.dateReplyCount = 0 self.sizeReplyCount = 0 self.bytesWrote = 0 self.acceptedCount = 0 self.rejectedCount = 0 self.linecnt = 0 self.smsgcnt = 0 print('\n\n\n\n\n', end='\x1b[3A') def writeline(self, txt, row = 0): # write line and move back if row > 0: print('', end='\x1b[%sB' % row) print(txt, end = '\x1b[1000D') if row > 0: print('', end='\x1b[%sA' % row) def event(self, *args): ename = args[0] #self.writeline(ename) if ename == 'DecryptByTag': return self.catchDecryptByTag(*args[1:]) if ename == 'EncryptFilter': return self.catchEncryptFilter(*args[1:]) if ename == 'Filter': return self.catchFilter(*args[1:]) if False: return if ename == 'FileWrite': #txt = '%s:%x:%x' % (args[1], args[2], args[3]) #txt = txt.ljust(40) #self.writeline(txt, row = 3) return if ename == 'Cycle' or ename == 'DumpCycle': return if ename == 'DataOut': ch = '#' vp = '#'.rjust(self.smsgcnt % 40) vp = vp.ljust(40) vp = 'Local: [%s]' % vp self.smsgcnt += 1 self.writeline(vp, row = 1) return if ename == 'DataIn': vp = '#'.rjust(self.smsgcnt % 40) vp = vp.ljust(40) vp = 'Server:[%s]' % vp self.smsgcnt += 1 self.writeline(vp, row = 2) return ignored = ('MessageOut', 'MessageIn') if ename in ignored: return lpath = args[2] txt = lpath.decode('utf8', 'ignore') if len(txt) > 40: txt = txt[-40:] txt = 'File: [%s]' % (txt.ljust(40)) self.writeline(txt) self.linecnt += 1 def catchDecryptByTag(self, tag): # we need to search throuh our encryption filter # and attempt to determine the plugin and options # to pass for reversal of the encryption return self.efilters.reverse(tag) def catchEncryptFilter(self, lpath, node, isDir): if self.efilters is not None: # get the encryption information we need einfo = self.efilters.check(lpath, node, isDir) # build and name some important stuff for readability etag = einfo[0] plugid = einfo[1] plugopts = einfo[2] plugtag = '%s.%s' % (plugid, plugopts) plug = getPM().getPluginInstance(plugid, plugtag, (None, plugopts,)) else: # this should rarely be used.. the caller will likely be providing # the efilter object when calling this function, but it is here # in the event that they do not.. etag = b'' plug = getPM().getPluginInstance('crypt.null', '', (c, [])) plugopts = (c, []) return (etag, plug, plugopts) def catchFilter(self, lpath, node, isDir): if self.filter is None: return True result = self.filter.check(lpath, node, isDir) if result: self.acceptedCount += 1 else: self.rejectedCount += 1 print('result', result) return result