TextLogger / app.py
OzoneAsai's picture
Update app.py
12581a3 verified
raw
history blame
No virus
1.18 kB
import hashlib
import time
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
current_text = ""
logs = []
def get_ip_hash(ip):
return hashlib.sha256(ip.encode()).hexdigest()[:8]
def log_text(ip, text):
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
ip_hash = get_ip_hash(ip)
logs.append([timestamp, ip_hash, text])
@app.route('/')
def index():
return render_template('index.html')
@app.route('/ViewPort')
def viewport():
return render_template('viewport.html')
@app.route('/Ctrl', methods=['GET', 'POST'])
def ctrl():
global current_text
if request.method == 'POST':
new_text = request.form['text']
if new_text != current_text: # Check for duplicate content
current_text = new_text
log_text(request.remote_addr, current_text)
return '', 204
return render_template('ctrl.html')
@app.route('/get_text')
def get_text():
global current_text
return jsonify({'text': current_text})
@app.route('/log')
def log():
return render_template('log.html', log_data=logs)
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0")