Parcourir la source

Introduce unique ID for results, for privacy reasons

Baptiste Jonglez il y a 10 ans
Parent
commit
7cf77b2d00
2 fichiers modifiés avec 7 ajouts et 4 suppressions
  1. 6 3
      peerfinder.py
  2. 1 1
      templates/submit.html

+ 6 - 3
peerfinder.py

@@ -33,12 +33,15 @@ def resolve_name(hostname):
 class Target(db.Model):
     """Target IP to ping"""
     id = db.Column(db.Integer, primary_key=True)
+    # Unique ID for accessing the results (privacy reasons)
+    unique_id = db.Column(db.String)
     # IP addresses are encoded as their binary representation
     ip = db.Column(db.BINARY(length=16))
     # Date at which a user asked for measurements to this target
     submitted = db.Column(db.DateTime)
 
     def __init__(self, ip):
+        self.unique_id = str(uuid4())
         self.ip = IPAddress(ip).packed
         self.submitted = datetime.now()
 
@@ -203,9 +206,9 @@ def report_result(uuid):
     else:
         return "Invalid arguments\n"
 
-@app.route('/result/show/<int:target_id>')
-def show_results(target_id):
-    target = Target.query.get_or_404(target_id)
+@app.route('/result/show/<target_uniqueid>')
+def show_results(target_uniqueid):
+    target = Target.query.filter_by(unique_id=target_uniqueid).first_or_404()
     results = target.results.order_by('rtt').all()
     return render_template('results.html', target=target, results=results)
 

+ 1 - 1
templates/submit.html

@@ -6,7 +6,7 @@ specified targets.</p>
 <p>
   <ul>
     {% for t in targets %}
-    <li><a href="/result/show/{{ t.id }}">result for {{ t }}</a></li>
+    <li><a href="/result/show/{{ t.unique_id }}">Result for {{ t }}</a></li>
     {% endfor %}
   </ul>
 </p>