#!{{ python_executable }} import cgi import cgitb import json import os import subprocess import logTools import codecs cgitb.enable(display=0, logdir="/tmp/cgi.log") form = cgi.FieldStorage() base_folder_list = {{ base_folder_list }} script_path = "{{ script_path }}" logpath = form.getvalue("path", "") action = form.getvalue("action", "tail") size = int(form.getvalue("size", "200")) print """ """ if not logpath: print """

Select file(s) in the list bellow

""" else: path_list = [x for x in logpath.split('#') if x] log_content = "" title = "" pattern = "" for filepath in path_list: if os.path.exists(filepath) and os.path.isfile(filepath): title += " " + filepath.split('/')[-1:][0] try: if action == "tail": pattern = form.getvalue("pattern", "") content = logTools.tail(codecs.open(filepath, "r", "utf_8"), size, pattern) elif action == "grep": pattern = form.getvalue("pattern") content = logTools.grep(filepath, pattern) else: content = "" except Exception, e: content = str(e) if content: log_content += "%s FILE %s >>>>\n\n" % (action.upper(), filepath) log_content += content + "\n\n\n" print """

Tail: %s

""" % (script_path, logpath, action, pattern, size, title, log_content) if pattern: print "

Pattern string is: %s

" % pattern print """ """