From ff5278e3e26ccee1d77e93949edb0ad72068569b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Centuri=C3=B3n?= Date: Mon, 11 Nov 2019 18:40:32 -0300 Subject: [PATCH] Add IP field to the add sensor page --- server/mhn/api/views.py | 6 +++++- server/mhn/static/js/main.js | 5 +++-- server/mhn/templates/ui/add-sensor.html | 10 ++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/server/mhn/api/views.py b/server/mhn/api/views.py index 81a60e7e..0c8cb5b5 100644 --- a/server/mhn/api/views.py +++ b/server/mhn/api/views.py @@ -35,7 +35,11 @@ def create_sensor(): else: sensor = Sensor(**request.json) sensor.uuid = str(uuid1()) - sensor.ip = request.remote_addr + try: + if request.json['ip'] == "": + sensor.ip = request.remote_addr + except KeyError: + sensor.ip = request.remote_addr Clio().authkey.new(**sensor.new_auth_dict()).post() try: db.session.add(sensor) diff --git a/server/mhn/static/js/main.js b/server/mhn/static/js/main.js index b2bc2fbd..79f7b312 100644 --- a/server/mhn/static/js/main.js +++ b/server/mhn/static/js/main.js @@ -21,7 +21,8 @@ $(document).ready(function() { var sensorObj = { name: $('#name').val(), hostname: $('#hostname').val(), - honeypot: $('#honeypot').val() + honeypot: $('#honeypot').val(), + ip: $('#ip').val() }; $('#alert-row').hide(); @@ -385,7 +386,7 @@ $(document).ready(function() { $('#error-txt').html(resp.responseJSON.error); $('#msg-container').show(); } - }); + }); } else { $('#alert-text').removeClass('success').addClass('warning'); $('#error-txt').html('Not a valid email address'); diff --git a/server/mhn/templates/ui/add-sensor.html b/server/mhn/templates/ui/add-sensor.html index 58e71027..7c29de9f 100644 --- a/server/mhn/templates/ui/add-sensor.html +++ b/server/mhn/templates/ui/add-sensor.html @@ -14,9 +14,12 @@

Add a Sensor

-
+
+
+ +
@@ -29,7 +32,10 @@

Add a Sensor

-
+
+ +
+