Browse Source

Add a 'public' field on measurements

Baptiste Jonglez 10 years ago
parent
commit
03c3e448e4
3 changed files with 40 additions and 5 deletions
  1. 26 0
      migrations/versions/4081450598f_.py
  2. 6 3
      peerfinder.py
  3. 8 2
      templates/home.html

+ 26 - 0
migrations/versions/4081450598f_.py

@@ -0,0 +1,26 @@
+"""empty message
+
+Revision ID: 4081450598f
+Revises: 176d9148f7c
+Create Date: 2014-09-27 23:50:36.147088
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '4081450598f'
+down_revision = '176d9148f7c'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('target', sa.Column('public', sa.Boolean(), nullable=True))
+    ### end Alembic commands ###
+
+
+def downgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('target', 'public')
+    ### end Alembic commands ###

+ 6 - 3
peerfinder.py

@@ -50,11 +50,13 @@ class Target(db.Model):
     ip = db.Column(db.BINARY(length=16))
     # Date at which a user asked for measurements to this target
     submitted = db.Column(db.DateTime)
+    public = db.Column(db.Boolean)
 
-    def __init__(self, ip):
+    def __init__(self, ip, public=False):
         self.unique_id = str(uuid4())
         self.ip = IPAddress(ip).packed
         self.submitted = datetime.now()
+        self.public = public
 
     def get_ip(self):
         return IPAddress(unpack(self.ip))
@@ -210,12 +212,13 @@ def robots():
 def submit_job():
     if 'target' in request.form:
         target = request.form['target'].strip()
+        public = bool(request.form.get('public'))
         if is_valid_ip(target):
             # Explicit IP
-            targets = [Target(target)]
+            targets = [Target(target, public)]
         else:
             # DNS name, might give multiple IP
-            targets = [Target(ip) for ip in resolve_name(target)]
+            targets = [Target(ip, public) for ip in resolve_name(target)]
         if targets == []:
             return render_template('submit_error.html', target=request.form['target'])
         for t in targets:

+ 8 - 2
templates/home.html

@@ -19,10 +19,16 @@ latency from various points in the network towards you.</p>
 
 <p>
 <form action="/submit" method="POST">
-Target:
-<input type="text" name="target" />
+<label for="target">Target:</label>
+<input type="text" name="target" id="target" /><br />
+<input type="checkbox" id="public" name="public" />
+<label for="public">Public?</label><br />
 <input type="submit" value="Launch" />
 </form>
 </p>
 
+<p>If you mark your measurement as public, it will be displayed on the
+home page.  Note that the IP addresses of the target will be shown
+alongside the result.</p>
+
 {% endblock %}