#!/usr/bin/env python3 import os, sys import http, cgi import glob import datetime import funct import sql from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/')) template = env.get_template('logs.html') form = cgi.FieldStorage() if form.getvalue('grep') is None: grep = "" else: grep = form.getvalue('grep') if form.getvalue('rows') is None: rows = 10 else: rows = form.getvalue('rows') print('Content-type: text/html\n') funct.check_login() funct.page_for_admin() log_path = funct.get_config_var('main', 'log_path') time_storage = sql.get_setting('log_time_storage') time_storage = int(time_storage) try: time_storage_hours = time_storage * 24 for dirpath, dirnames, filenames in os.walk(log_path): for file in filenames: curpath = os.path.join(dirpath, file) file_modified = datetime.datetime.fromtimestamp(os.path.getmtime(curpath)) if datetime.datetime.now() - file_modified > datetime.timedelta(hours=time_storage_hours): os.remove(curpath) except: print('