from flask import Flask, jsonify, render_template_string
import os, json, re
import string
app = Flask(__name__)
RESULTS_DIR = "." # same folder as JSON files
ANSI_ESCAPE = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
HTML_TEMPLATE = """
TruffleHog Dashboard
TruffleHog Full Log
File
Line
"""
@app.route('/')
def index():
return render_template_string(HTML_TEMPLATE)
@app.route('/api/findings')
def get_findings():
all_lines = []
for fname in os.listdir(RESULTS_DIR):
if fname.endswith(".json"):
fpath = os.path.join(RESULTS_DIR, fname)
with open(fpath, 'r', encoding='utf-8', errors='replace') as f:
for line in f:
# Remove non-printable characters
line = ''.join(c for c in line if c in string.printable).strip()
if not line:
continue
# Strip ANSI escape codes
line_clean = ANSI_ESCAPE.sub('', line)
pretty = line_clean # default
highlight = False
red = False
# Try JSON parsing for pretty-print
try:
data = json.loads(line_clean)
pretty = json.dumps(data, indent=2, ensure_ascii=False)
highlight = 'SourceMetadata' in data
red = highlight and data.get('Verified') is False
except json.JSONDecodeError:
pass
all_lines.append({
"file": fname,
"raw": pretty,
"highlight": highlight,
"red": red
})
return jsonify(all_lines)
if __name__ == "__main__":
app.run(debug=True)