Skip to content

Commit 13c343c

Browse files
authored
Merge pull request #40 from flask-dashboard/development
Multiple guest passwords, plot updates, improved security against guests downloading data
2 parents c14418a + 58daea1 commit 13c343c

File tree

6 files changed

+36
-28
lines changed

6 files changed

+36
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The following things can be configured:
4747
USERNAME=admin
4848
PASSWORD=admin
4949
GUEST_USERNAME=guest
50-
GUEST_PASSWORD=dashboardguest!
50+
GUEST_PASSWORD=['dashboardguest!', 'second_pw!']
5151
DATABASE=sqlite:////<path to your project>/dashboard.db
5252
GIT=/<path to your project>/dashboard/.git/
5353
TEST_DIR=/<path to your project>/dashboard/tests/

dashboard/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self):
2020
self.username = 'admin'
2121
self.password = 'admin'
2222
self.guest_username = 'guest'
23-
self.guest_password = 'guest_password'
23+
self.guest_password = ['guest_password']
2424
self.outlier_detection_constant = 2.5
2525
self.colors = {}
2626

@@ -97,7 +97,7 @@ def from_file(self, config_file):
9797
if parser.has_option('dashboard', 'GUEST_USERNAME'):
9898
self.guest_username = parser.get('dashboard', 'GUEST_USERNAME')
9999
if parser.has_option('dashboard', 'GUEST_PASSWORD'):
100-
self.guest_password = parser.get('dashboard', 'GUEST_PASSWORD')
100+
self.guest_password = ast.literal_eval(parser.get('dashboard', 'GUEST_PASSWORD'))
101101

102102
# when an outlier detection constant has been set up:
103103
if parser.has_option('dashboard', 'OUTLIER_DETECTION_CONSTANT'):

dashboard/routings/measurements.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dashboard.database.endpoint import get_last_accessed_times, get_num_requests
99
from dashboard.database.function_calls import get_times, get_reqs_endpoint_day, get_versions, get_data_per_version, \
1010
get_endpoints, get_data_per_endpoint
11-
from dashboard.security import secure
11+
from dashboard.security import secure, is_admin
1212
from dashboard.colors import get_color
1313

1414

@@ -18,8 +18,9 @@ def overview():
1818
colors = {}
1919
for result in get_times():
2020
colors[result.endpoint] = get_color(result.endpoint)
21-
return render_template('dashboard/measurement-overview.html', link=config.link, curr=2, times=get_times(), colors=colors,
22-
access=get_last_accessed_times(), session=session, index=0)
21+
return render_template('dashboard/measurement-overview.html', link=config.link, curr=2, times=get_times(),
22+
colors=colors, access=get_last_accessed_times(), session=session, index=0,
23+
is_admin=is_admin())
2324

2425

2526
@blueprint.route('/measurements/heatmap')

dashboard/routings/result.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import math
23
import plotly
34
import plotly.graph_objs as go
45

@@ -18,6 +19,10 @@
1819
from dashboard.colors import get_color
1920

2021

22+
# Constants
23+
BUBBLE_SIZE_RATIO = 1250
24+
25+
2126
@blueprint.route('/result/<end>/heatmap')
2227
@secure
2328
def result_heatmap(end):
@@ -197,7 +202,8 @@ def get_hits_per_hour(end):
197202
def get_time_per_version_per_user(end, versions):
198203
user_data = {}
199204
data = [t.execution_time for t in get_all_measurement(end)]
200-
average = sum(data) / len(data)
205+
# compute the average for determining the size of the bubbles in the plot
206+
average = math.sqrt(sum(data) / len(data)) / BUBBLE_SIZE_RATIO
201207

202208
for d in [str(c.group_by) for c in get_endpoint_column(end, FunctionCall.group_by)]:
203209
user_data[d] = {}
@@ -228,9 +234,9 @@ def get_time_per_version_per_user(end, versions):
228234
name=d,
229235
mode='markers',
230236
marker=dict(
231-
color=[get_color(h) for h in versions],
232-
size=data,
233-
sizeref=average/1250, # larger sizeref decreases size of the dot
237+
color=[get_color(d)] * len(versions),
238+
size=[math.sqrt(d) for d in data],
239+
sizeref=average,
234240
sizemode='area'
235241
)
236242
))
@@ -283,7 +289,8 @@ class SelectionForm(FlaskForm):
283289
def get_time_per_version_per_ip(end, versions):
284290
ip_data = {}
285291
data = [t.execution_time for t in get_all_measurement(end)]
286-
average = sum(data) / len(data)
292+
# compute the average for determining the default size
293+
average = math.sqrt(sum(data) / len(data)) / 1250
287294
for d in [str(c.ip) for c in get_endpoint_column(end, FunctionCall.ip)]:
288295
ip_data[d] = {}
289296
for v in versions:
@@ -314,9 +321,9 @@ def get_time_per_version_per_ip(end, versions):
314321
name=d,
315322
mode='markers',
316323
marker=dict(
317-
color=[get_color(h) for h in versions],
318-
size=data,
319-
sizeref=average / 1250, # larger sizeref decreases size of the dot
324+
color=[get_color(d)] * len(versions),
325+
size=[math.sqrt(d) for d in data],
326+
sizeref=average,
320327
sizemode='area'
321328
)
322329
))
@@ -354,7 +361,7 @@ def get_time_per_version(end, versions):
354361
data.append(go.Box(
355362
x=values,
356363
marker=dict(
357-
color=get_color(v.version)
364+
color=get_color(end)
358365
),
359366
name="{0} {1}".format(v.version, v.startedUsingOn.strftime("%b %d %H:%M"))))
360367

dashboard/security.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@ def wrapper(*args, **kwargs):
3636
return wrapper
3737

3838

39-
def security(admin_only=False):
40-
def decorator(f):
41-
print(admin_only)
42-
return f
43-
return decorator
39+
def is_admin():
40+
return session and session.get(config.link + '_admin')
4441

4542

4643
def check_login(name, password):
4744
if name == config.username and password == config.password:
4845
on_login(admin=True)
4946
return True
50-
elif name == config.guest_username and password == config.guest_password:
47+
elif name == config.guest_username and password in config.guest_password:
5148
on_login(admin=False)
5249
return True
5350
return False

dashboard/templates/dashboard/measurement-overview.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
href="{{ url_for('dashboard.page_boxplot_per_endpoint') }}">Time per endpoint</a></li>
1818
</ul>
1919

20-
<div class="panel-heading">
21-
Overview
22-
<a href="{{ url_for('dashboard.download_csv') }}" class="btn btn-primary btn-sm right-align-custom">Download
23-
CSV</a>
24-
<a href="{{ url_for('dashboard.export_data') }}" class="btn btn-primary btn-sm right-align-custom">View
25-
CSV</a>
26-
</div>
20+
{% if is_admin %}
21+
<div class="panel-heading">
22+
Overview
23+
<a href="{{ url_for('dashboard.download_csv') }}" class="btn btn-primary btn-sm right-align-custom">Download
24+
CSV</a>
25+
<a href="{{ url_for('dashboard.export_data') }}" class="btn btn-primary btn-sm right-align-custom">View
26+
CSV</a>
27+
</div>
28+
{% endif %}
29+
2730
<br/>
2831
<div class="panel-body">
2932
<div class="table-responsive">

0 commit comments

Comments
 (0)