# # 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 # """The logs feature of the CryptoBox. """ __revision__ = "$Id" import cryptobox.plugins.base import os class logs(cryptobox.plugins.base.CryptoBoxPlugin): """The logs feature of the CryptoBox. """ plugin_capabilities = [ "system" ] plugin_visibility = [ "preferences" ] request_auth = False rank = 90 def do_action(self, lines=50, size=3000, pattern=None): """Show the latest part of the log file. """ 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.__get_log_content( lines, size, pattern) self.hdf[self.hdf_prefix + "StyleSheetFile"] = os.path.abspath(os.path.join( self.plugin_dir, "logs.css")) return "show_log" def get_status(self): """The current status includes the log configuration details. """ return "%s:%s:%s" % ( self.cbox.prefs["Log"]["Level"], self.cbox.prefs["Log"]["Destination"], self.cbox.prefs["Log"]["Details"]) def __get_log_content(self, lines, max_size, pattern): """Filter, sort and shorten the log content. """ if pattern: content = [] current_length = 0 for line in self.cbox.get_log_data(): if line.find(pattern) != -1: content.append(line) current_length += len(line) if lines and len(content) >= lines: break if max_size and current_length >= max_size: break else: content = self.cbox.get_log_data(lines, max_size) return "
".join(content)