Beispiel #1
0
def report():
    # Create LogParser instance for this report
    logparser = LogParser(gi, KEYWORDS)

    filename = request.args.get("filename")
    if "/" in filename:  # Prevent directory traversal attacks
        return "Go away!"

    path = os.path.join("/home/malyhass/log-parser", filename)
    logparser.parse_file(
        gzip.open(path) if path.endswith(".gz") else open(path))

    return env.get_template("report.html").render({
        "map_svg":
        render_map(open(os.path.join(PROJECT_ROOT, "templates", "map.svg")),
                   logparser.countries),
        "humanize":
        humanize.naturalsize,
        "keyword_hits":
        sorted(logparser.d.items(), key=lambda i: i[1], reverse=True),
        "url_hits":
        sorted(logparser.urls.items(), key=lambda i: i[1], reverse=True),
        "user_bytes":
        sorted(logparser.user_bytes.items(),
               key=lambda item: item[1],
               reverse=True)
    })
Beispiel #2
0
def report():
    # Create LogParser instance for this report
    logparser = LogParser(gi, KEYWORDS)

    filename = request.args.get("filename")
    if "/" in filename: # Prevent directory traversal attacks
        return "Go away!"

    path = os.path.join("/home/ebarrier/Documents/Python/logs", filename)
    logparser.parse_file(gzip.open(path) if path.endswith(".gz") else open(path))

    return env.get_template("report.html").render({
            "map_svg": render_map(open(os.path.join(PROJECT_ROOT, "templates", "map.svg")), logparser.countries),
            "humanize": humanize.naturalsize,
            "keyword_hits": sorted(logparser.d.items(), key=lambda i:i[1], reverse=True),
            "url_hits": sorted(logparser.urls.items(), key=lambda i:i[1], reverse=True),
            "user_bytes": sorted(logparser.user_bytes.items(), key = lambda item:item[1], reverse=True)
        })
Beispiel #3
0
for filename in os.listdir(args.path):
    if not filename.startswith("access."):
        continue

    if filename.endswith(".gz"):
        if args.skip_compressed:
            continue
        fh = gzip.open(os.path.join(args.path, filename))
    else:
        fh = open(os.path.join(args.path, filename))

    if args.verbose:
        print "Parsing:", filename

    logparser.parse_file(fh)

if not logparser.urls:
    print "No log entries!"
    exit(254)


def humanize(bytes):
    if bytes < 1024:
        return "%d B" % bytes
    elif bytes < 1024**2:
        return "%.1f kB" % (bytes / 1024.0)
    elif bytes < 1024**3:
        return "%.1f MB" % (bytes / 1024.0**2)
    else:
        return "%.1f GB" % (bytes / 1024.0**3)
Beispiel #4
0
for filename in os.listdir(args.path):
    if not filename.startswith("access."):
        continue

    if filename.endswith(".gz"):
        if args.skip_compressed:
            continue
        fh = gzip.open(os.path.join(args.path, filename))
    else:
        fh = open(os.path.join(args.path, filename))

    if args.verbose:
        print "Parsing:", filename

    logparser.parse_file(fh)

if not logparser.urls:
    print "No log entries!"
    exit(254)


def humanize(bytes):
    if bytes < 1024:
        return "%d B" % bytes
    elif bytes < 1024 ** 2:
        return "%.1f kB" % (bytes / 1024.0)
    elif bytes < 1024 ** 3:
        return "%.1f MB" % (bytes / 1024.0 ** 2)
    else:
        return "%.1f GB" % (bytes / 1024.0 ** 3)