From 165efc47510a4f9bb51c11b81e8897c012d395c3 Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Tue, 12 Dec 2017 13:43:12 +0100 Subject: [PATCH 1/9] Taking server host and port from config --- server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 6866f60..5b79c53 100755 --- a/server.py +++ b/server.py @@ -19,6 +19,9 @@ configfile = os.path.join(os.environ['DASH_CONFIG'], 'config.cfg') cfg = configparser.ConfigParser() cfg.read(configfile) +server_host = cfg.get("Server", "host") +server_port = cfg.getint("Server", "port") + app = Flask(__name__) redis_server_log = redis.StrictRedis( @@ -541,4 +544,4 @@ def getTypeaheadData(): return jsonify(data) if __name__ == '__main__': - app.run(host='localhost', port=8001, threaded=True) + app.run(host=server_host, port=server_port, threaded=True) From fb9e49a61287b98a2a642736704d6a33edce218e Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Tue, 12 Dec 2017 13:43:51 +0100 Subject: [PATCH 2/9] Adding default server fields --- config/config.cfg.default | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/config.cfg.default b/config/config.cfg.default index 6b3b46b..3cff6f1 100644 --- a/config/config.cfg.default +++ b/config/config.cfg.default @@ -1,3 +1,7 @@ +[Server] +host = localhost +port = 9001 + [Dashboard] #hours graph_log_refresh_rate = 1 From b4f0aeb3af03954b13bc7d956f5c0cdeb227dbac Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Tue, 12 Dec 2017 16:48:54 +0100 Subject: [PATCH 3/9] Fix: config default port back to 9001 --- config/config.cfg.default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.cfg.default b/config/config.cfg.default index 3cff6f1..c564753 100644 --- a/config/config.cfg.default +++ b/config/config.cfg.default @@ -1,6 +1,6 @@ [Server] host = localhost -port = 9001 +port = 8001 [Dashboard] #hours From 12b078a2e9265400c89ded9c277c70849319407d Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Fri, 15 Dec 2017 16:05:25 +0100 Subject: [PATCH 4/9] wsgi definition for Apache mod_wsgi --- misp-dashboard.wsgi | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 misp-dashboard.wsgi diff --git a/misp-dashboard.wsgi b/misp-dashboard.wsgi new file mode 100644 index 0000000..47924c5 --- /dev/null +++ b/misp-dashboard.wsgi @@ -0,0 +1,4 @@ +import sys,os,os.path +sys.path.insert(0, os.path.dirname(__file__)) +os.environ["DASH_CONFIG"] = os.path.join(os.path.dirname(__file__), "config") +from server import app as application From 9d0406df26e687a601da36ee1856b3656bffcc3c Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Fri, 15 Dec 2017 16:15:01 +0100 Subject: [PATCH 5/9] Added: Deploy in production using mod_wsgi --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index b854bf4..1e2f2c3 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,47 @@ optional arguments: The URL to connect to ``` +## Deploy in production using mod_wsgi + +Install Apache's mod-wsgi for Python3 + +```bash +sudo apt-get install libapache2-mod-wsgi-py3 +``` + +Caveat: If you already have mod-wsgi installed for Python2, it will be replaced! + +```bash +The following packages will be REMOVED: + libapache2-mod-wsgi +The following NEW packages will be installed: + libapache2-mod-wsgi-py3 +``` + +Configuration file `/etc/apache2/sites-available/misp-dashboard.conf` assumes that `misp-dashboard` is cloned into `var/www/misp-dashboard`. It runs as user `misp` in this example. Change the permissions to folder and files accordingly. + +``` + + ServerAdmin admin@misp.local + ServerName misp.local + + DocumentRoot /var/www/misp-dashboard + WSGIDaemonProcess misp-dashboard user=misp group=misp threads=5 python-home=/var/www/misp-dashboard/DASHENV + WSGIScriptAlias / /var/www/misp-dashboard/misp-dashboard.wsgi + + + WSGIProcessGroup misp-dashboard + WSGIApplicationGroup %{GLOBAL} + Require all granted + + + LogLevel info + ErrorLog /var/log/apache2/misp-dashboard.local_error.log + CustomLog /var/log/apache2/misp-dashboard.local_access.log combined + ServerSignature Off + +``` + # License Images and logos are handmade for: - rankingMISPOrg/ From fcdc520273cdc2be400a5430c81a308124ed8080 Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Fri, 15 Dec 2017 16:16:39 +0100 Subject: [PATCH 6/9] Fix: deploy header level --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e2f2c3..0b7df43 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ optional arguments: The URL to connect to ``` -## Deploy in production using mod_wsgi +# Deploy in production using mod_wsgi Install Apache's mod-wsgi for Python3 From 7ee1d12902f60eecf66155a4e6b8b529decd2538 Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Mon, 18 Dec 2017 15:20:37 +0100 Subject: [PATCH 7/9] Fix: Freeze issue --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b7df43..9d29aa8 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,30 @@ Configuration file `/etc/apache2/sites-available/misp-dashboard.conf` assumes th ServerName misp.local DocumentRoot /var/www/misp-dashboard - WSGIDaemonProcess misp-dashboard user=misp group=misp threads=5 python-home=/var/www/misp-dashboard/DASHENV + + WSGIDaemonProcess misp-dashboard \ + user=misp group=misp \ + threads=5 \ + python-home=/var/www/misp-dashboard/DASHENV \ + processes=1 \ + threads=15 \ + maximum-requests=5000 \ + listen-backlog=100 \ + queue-timeout=45 \ + socket-timeout=60 \ + connect-timeout=15 \ + request-timeout=60 \ + inactivity-timeout=0 \ + deadlock-timeout=60 \ + graceful-timeout=15 \ + eviction-timeout=0 \ + shutdown-timeout=5 \ + send-buffer-size=0 \ + receive-buffer-size=0 \ + header-buffer-size=0 \ + response-buffer-size=0 \ + server-metrics=Off + WSGIScriptAlias / /var/www/misp-dashboard/misp-dashboard.wsgi From d3041abc39abdf449b5f255508e582ed9c7ebe7a Mon Sep 17 00:00:00 2001 From: Steffen Sauler Date: Mon, 18 Dec 2017 15:29:08 +0100 Subject: [PATCH 8/9] Fix: remove redundant threads definition --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9d29aa8..d522f1c 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,6 @@ Configuration file `/etc/apache2/sites-available/misp-dashboard.conf` assumes th WSGIDaemonProcess misp-dashboard \ user=misp group=misp \ - threads=5 \ python-home=/var/www/misp-dashboard/DASHENV \ processes=1 \ threads=15 \ From 763ad16fec0ec012e4db8fbee087dc887491bf33 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 19 Dec 2017 09:32:28 +0100 Subject: [PATCH 9/9] fix: tries to get coordinate from ISO_CODE if 'location' is not in the geoip.database response --- helpers/geo_helper.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/helpers/geo_helper.py b/helpers/geo_helper.py index 8169fe8..c6d9fec 100644 --- a/helpers/geo_helper.py +++ b/helpers/geo_helper.py @@ -172,8 +172,15 @@ class Geo_helper: def ip_to_coord(self, ip): resp = self.reader.city(ip) - lat = float(resp.location.latitude) - lon = float(resp.location.longitude) + try: + lat = float(resp.location.latitude) + lon = float(resp.location.longitude) + except TypeError: # No location, try to use iso_code instead + self.logger.info('no location in geIP.database response for ip: {}'.format(ip)) + iso_code = resp.registered_country.iso_code #if no iso_code, throws + coord = self.country_code_to_coord[iso_code.lower()] # countrycode is in upper case + lat = float(coord['lat']) + lon = float(coord['long']) # 0.0001 correspond to ~10m # Cast the float so that it has the correct float format lat_corrected = float("{:.4f}".format(lat))