Commit 39aa5c7f authored by Emanuele Santoro's avatar Emanuele Santoro

Added some logging like remote ip, date and url being shorted

parent 86bc1d84
......@@ -3,5 +3,5 @@
export DATABASE_URL=postgresql://manu:manu@127.0.0.1:5432/musho
export DEBUG=true
export PORT=9000
export MUSHO_URL=http://localhost:$PORT/
export MUSHO_URL=http://localhost:$PORT
# export MUSHO_URL=http://musho.tk/
import os
import hashlib
import time
from flask import *
from flask_sqlalchemy import SQLAlchemy
......@@ -43,6 +45,8 @@ def index() :
@musho.route("/save", methods=['POST'])
def saveLink() :
now = time.strftime("%d-%b-%Y %H:%m")
remote_ip = request.remote_addr
url = request.form["url"]
hash = hashlib.new('sha1')
hash.update(url.encode('ascii','ignore'))
......@@ -55,6 +59,7 @@ def saveLink() :
db.session.add(new_link)
db.session.commit()
full_url = musho_url +"/l/" + short_url
print("Sortened %s -- %s -- %s " % (short_url, remote_ip, now) )
return render_template('shortened_link.html', url=full_url)
......@@ -64,7 +69,6 @@ def resolveLink(short_url):
print("Risolvo il link '%s'" % short_url)
target = Link.query.filter_by(short_url=short_url).first()
if target is not None :
print("Target is not none")
return redirect(target.full_url)
else :
return redirect("/")
......@@ -77,4 +81,6 @@ def static_proxy(path):
if __name__ == "__main__" :
if debug :
musho.debug = True
musho.run(port=port)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment