Skip to content

Commit

Permalink
Merge pull request cve-search#63 from PidgeyL/master
Browse files Browse the repository at this point in the history
Error Handling
  • Loading branch information
adulau committed Mar 13, 2015
2 parents 2d7add2 + 94ccd1f commit 0ca5c14
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
6 changes: 5 additions & 1 deletion lib/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Copyright (c) 2014-2015 Pieter-Jan Moreels - pieterjan.moreels@gmail.com

# imports
import sys
import os
runPath = os.path.dirname(os.path.realpath(__file__))

Expand Down Expand Up @@ -73,7 +74,10 @@ def getMongoConnection(cls):
mongoHost = cls.readSetting("Mongo", "Host", cls.default['mongoHost'])
mongoPort = cls.readSetting("Mongo", "Port", cls.default['mongoPort'])
mongoDB = cls.getMongoDB()
connect = pymongo.MongoClient(mongoHost, mongoPort)
try:
connect = pymongo.MongoClient(mongoHost, mongoPort)
except:
sys.exit("Unable to connect to Mongo. Is it running on %s:%s?"%(mongoHost,mongoPort))
return connect[mongoDB]

# Redis
Expand Down
50 changes: 31 additions & 19 deletions web/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from flask.ext.login import LoginManager, current_user, login_user, logout_user, login_required
from werkzeug import secure_filename
from passlib.hash import pbkdf2_sha256
from redis import exceptions as redisExceptions

import json
from dateutil import tz
Expand Down Expand Up @@ -425,12 +426,17 @@ def cve(cveid):
@app.route('/browse/<vendor>')
@app.route('/browse/')
def browse(vendor=None):
if vendor is not None:
vendor = urllib.parse.quote_plus(vendor).lower()
browseList = getBrowseList(vendor)
vendor = browseList["vendor"]
product = browseList["product"]
return render_template('browse.html', product=product, vendor=vendor)
try:
if vendor is not None:
vendor = urllib.parse.quote_plus(vendor).lower()
browseList = getBrowseList(vendor)
vendor = browseList["vendor"]
product = browseList["product"]
return render_template('browse.html', product=product, vendor=vendor)
except redisExceptions.ConnectionError:
return render_template('error.html',
status={'except':'redis-connection',
'info':{'host':Configuration.getRedisHost(),'port':Configuration.getRedisPort()}})


@app.route('/search/<vendor>/<path:product>')
Expand All @@ -454,6 +460,7 @@ def link(vFeedMap=None,field=None,value=None):
return render_template('linked.html', vFeedMap=vFeedMap, field=field, value=value, cve=cve, stats=stats)

@app.route('/admin')
@app.route('/admin/')
def admin():
status = ["default", "none"]
if Configuration.loginRequired():
Expand Down Expand Up @@ -724,19 +731,24 @@ def listManagementAdd():
@app.route('/admin/listmanagement')
@login_required
def listManagement(vendor=None, product=None):
if product is None:
# no product selected yet, so same function as /browse can be used
if vendor:
vendor = urllib.parse.quote_plus(vendor).lower()
browseList = getBrowseList(vendor)
vendor = browseList["vendor"]
product = browseList["product"]
version = None
else:
# product selected, product versions required
version = getVersionsOfProduct(urllib.parse.quote_plus(product).lower())
status = ["default", "none"]
return render_template('listmanagement.html', status=status, vendor=vendor, product=product, version=version)
try:
if product is None:
# no product selected yet, so same function as /browse can be used
if vendor:
vendor = urllib.parse.quote_plus(vendor).lower()
browseList = getBrowseList(vendor)
vendor = browseList["vendor"]
product = browseList["product"]
version = None
else:
# product selected, product versions required
version = getVersionsOfProduct(urllib.parse.quote_plus(product).lower())
status = ["default", "none"]
return render_template('listmanagement.html', status=status, vendor=vendor, product=product, version=version)
except redisExceptions.ConnectionError:
return render_template('error.html',
status={'except':'redis-connection',
'info':{'host':Configuration.getRedisHost(),'port':Configuration.getRedisPort()}})


@app.route('/login', methods=['post'])
Expand Down
25 changes: 25 additions & 0 deletions web/templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<title>Error</title>
{% include 'defaultHead.html' %}
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<!-- Nav -->
{% include 'menu.html' %}
<div class="well">
<h1>This page can not be displayed due to an error</h1>
{% if status['except']=='redis-connection' %}
<p>Unable to connect to Redis. Is it running on {{status['info']['host']}}:{{status['info']['port']}}?</p>
{% endif %}
</div>
<!-- end content -->
</div>
</div>
</div>
</body>
</body>
</html>

0 comments on commit 0ca5c14

Please sign in to comment.