# # Copyright 2006 sense.lab e.V. # # This file is part of the CryptoBox. # # The CryptoBox is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # The CryptoBox is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with the CryptoBox; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # import cryptobox.plugins.base import os class logs(cryptobox.plugins.base.CryptoBoxPlugin): pluginCapabilities = [ "system" ] pluginVisibility = [ "preferences" ] requestAuth = False rank = 90 def doAction(self, lines=50, size=3000, pattern=None): import re ## filter input try: lines = int(lines) if lines <= 0: raise(ValueError) except ValueError: lines = 50 try: size = int(size) if size <= 0: raise(ValueError) except ValueError: size = 3000 if not pattern is None: pattern = str(pattern) if re.search(u'\W', pattern): pattern = None self.hdf[self.hdf_prefix + "Content"] = self.__getLogContent(lines, size, pattern) self.hdf[self.hdf_prefix + "StyleSheetFile"] = os.path.abspath(os.path.join(self.pluginDir, "logs.css")) return "show_log" def getStatus(self): return "%s:%s:%s" % ( self.cbox.prefs["Log"]["Level"], self.cbox.prefs["Log"]["Destination"], self.cbox.prefs["Log"]["Details"]) def __getLogContent(self, lines, maxSize, pattern): import re if pattern: content = [] current_length = 0 for line in self.cbox.getLogData(): if line.find(pattern) != -1: content.append(line) current_length += len(line) if lines and len(content) >=lines: break if maxSize and current_length >=maxSize: break else: content = self.cbox.getLogData(lines, maxSize) return "
".join(content)