Commit 287edd1b authored by Emanuele Santoro's avatar Emanuele Santoro

Detect X-Forwarded-For (and true ip of client)

parent 58cf63c4
......@@ -30,11 +30,11 @@ class Link(db.Model):
id = db.Column(db.Integer, primary_key=True)
short_url = db.Column(db.String(), unique=True)
full_url = db.Column(db.String(), unique=True)
def __init__(self, short, full):
self.full_url = full
self.short_url = short
def __repr__(self):
return "<Link '%s' -> '%s'" % (self.short_url, self.full_url)
......@@ -47,8 +47,10 @@ def index() :
def saveLink() :
now = time.strftime("%d-%b-%Y %H:%m")
remote_ip = request.remote_addr
if request.headers.getlist("X-Forwarded-For"):
remote_ip = request.headers.getlist("X-Forwarded-For")[0]
url = request.form["url"]
hash = hashlib.new('sha1')
hash = hashlib.new('sha1')
hash.update(url.encode('ascii','ignore'))
digest = hash.hexdigest()
short_url = digest[0:8]
......
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