Commit 4c935fd3 authored by Elger Jonker's avatar Elger Jonker

[wip] fixing game issues from #112, complete scores + better score view


Former-commit-id: 04f34e71
parent a28f09af
......@@ -96,7 +96,7 @@
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item"><a class="nav-link" href="/game/rules_help/">? Rules / Help</a></li>
<li class="nav-item"><a class="nav-link" href="/game/rules_help/">? Help / FAQ</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Log on/off<span class="caret"></span></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown3">
......
......@@ -20,7 +20,7 @@
{% endif %}
<h2>Currently open</h2>
<table class="table">
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="10%"></th>
......@@ -52,7 +52,7 @@
</table>
<h2>Upcoming</h2>
<table class="table">
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="10%"></th>
......@@ -84,7 +84,7 @@
</table>
<h2>Expired</h2>
<table class="table">
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="10%"></th>
......
{% extends 'game/base.html' %}
{% block content %}
<h1>Scores</h1>
<p>Contest: {{ contest.name }}, from {{ contest.from_moment }} until {{ contest.until_moment }}.</p>
<p>This contest targets {{ contest.target_country }}.</p>
<table class="table">
<thead>
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th colspan="3" style="background-color: lightgrey">Issues found per severity</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<tr>
<th>Rank</th>
<th>Team</th>
<th>High</th>
<th>Medium</th>
<th>Low</th>
<th>Rejected</th>
<th>Added organizations</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<p style="width: 100%; text-align: center; font-size: 10vw;">{{ contest.name | truncatechars:16 }}</p>
<p style="width: 100%; text-align: center; font-size: 2em;">Starts at {{ contest.from_moment }}. Deadline: {{ contest.until_moment }}.</p>
{% for score in scores %}
<tr style="{% if team.name == score.team %} font-weight: bold; background-color: #ddffdd;{% endif %}">
<td>{{ forloop.counter }}</td>
<td style="background-color: {{ score.team_color }};">{{ score.team }}</td>
<td>{{ score.high }} * {{ score.high_multiplier }} = {{ score.high_score }}</td>
<td>{{ score.medium }} * {{ score.medium_multiplier }} = {{ score.medium_score }}</td>
<td>{{ score.low }} * {{ score.low_multiplier }} = {{ score.low_score }}</td>
<td>{{ score.rejected }} * -{{ score.rejected_multiplier }} = -{{ score.rejected_score }}</td>
<td>{{ score.added_organizations }} * {{ score.added_organizations_multiplier }} = {{ score.added_organizations_score }}</td>
<td>{{ score.total_score }}</td>
</tr>
{% empty %}
<tr><td colspan="5">-</td></tr>
<table class="table table-sm table-striped table-bordered table-hover" style="width: 29%; float:left; margin: 20px;">
<tbody>
<tr><td colspan="3" style="font-weight: bold; font-family: impact, sans-serif; font-size: 6em; text-align: center;"># {{ forloop.counter }}</td></tr>
<tr><td colspan="3" style="font-size: 3em; text-align: center;">{{ score.team | truncatechars:12 }}</td></tr>
<tr><td>Total score</td> <td colspan="2" style="text-align: center; font-size: 2em;">{{ score.total_score }}</td></tr>
<tr><td>Organizations</td> <td>{{ score.added_organizations }}</td><td><small>* {{ score.added_organizations_multiplier }} = {{ score.added_organizations_score }}</small></td></tr>
<tr><td><small>Rejected</small></td> <td><small>{{ score.rejected_organizations }}</small></td><td><small>* -{{ score.rejected_organizations_multiplier }} = -{{ score.rejected_organizations_score }}</small></td></tr>
<tr><td>Urls</td> <td>{{ score.added_urls }}</td><td><small>* {{ score.added_urls_multiplier }} = {{ score.added_urls_score }}</small></td></tr>
<tr><td><small>Rejected</small></td> <td><small>{{ score.rejected_urls }}</small></td><td><small>* -{{ score.rejected_urls_multiplier }} = -{{ score.rejected_urls_score }}</small></td></tr>
<tr><td>High risk</td> <td>{{ score.high }}</td><td><small>* {{ score.high_multiplier }} = {{ score.high_score }}</small></td></tr>
<tr><td>Medium risk</td> <td>{{ score.medium }}</td><td><small> * {{ score.medium_multiplier }} = {{ score.medium_score }}</small></td></tr>
<tr><td>Low risk</td> <td>{{ score.low }}</td><td><small>* {{ score.low_multiplier }} = {{ score.low_score }}</small></td></tr>
</tbody>
</table>
{% endfor %}
</tbody>
</table>
<br style="clear: both">
<p>This contest targets {{ contest.target_country }}.</p>
{% if team.name %}
<a href="/game/submit_organization" role="button" class="btn btn-success">Submit Organization</a>
......
......@@ -17,7 +17,8 @@ from failmap.game.forms import ContestForm, OrganisationSubmissionForm, TeamForm
from failmap.game.models import Contest, OrganizationSubmission, Team, UrlSubmission
from failmap.map.calculate import get_calculation
from failmap.organizations.models import Organization, OrganizationType, Url
from failmap.scanners.models import EndpointGenericScan, TlsQualysScan, TlsScan, UrlGenericScan
from failmap.scanners.models import EndpointGenericScan, UrlGenericScan
from failmap.scanners.types import ENDPOINT_SCAN_TYPES, URL_SCAN_TYPES
log = logging.getLogger(__package__)
......@@ -140,26 +141,24 @@ def scores(request):
will change in a day or two. On the long run it might increase the score a bit when incorrect fixes are applied
or a new error is found. If the discovered issue is fixed it doesn't deliver additional points.
"""
scans = list(TlsQualysScan.objects.all().filter(
scans = list(EndpointGenericScan.objects.all().filter(
endpoint__url__urlsubmission__added_by_team=team.id,
endpoint__url__urlsubmission__has_been_accepted=True
))
scans += list(TlsScan.objects.all().filter(
endpoint__url__urlsubmission__added_by_team=team.id,
endpoint__url__urlsubmission__has_been_accepted=True
))
scans += list(EndpointGenericScan.objects.all().filter(
endpoint__url__urlsubmission__added_by_team=team.id,
endpoint__url__urlsubmission__has_been_accepted=True
endpoint__url__urlsubmission__has_been_accepted=True,
type__in=ENDPOINT_SCAN_TYPES
))
scans += list(UrlGenericScan.objects.all().filter(
url__urlsubmission__added_by_team=team.id,
url__urlsubmission__has_been_accepted=True
url__urlsubmission__has_been_accepted=True,
type__in=URL_SCAN_TYPES
))
added_urls = UrlSubmission.objects.all().filter(
added_by_team=team.id,
has_been_accepted=True,
has_been_rejected=False
).count()
added_organizations = OrganizationSubmission.objects.all().filter(
added_by_team=team.id,
has_been_accepted=True,
......@@ -167,6 +166,12 @@ def scores(request):
).count()
rejected_organizations = OrganizationSubmission.objects.all().filter(
added_by_team=team.id,
has_been_accepted=False,
has_been_rejected=True,
).count()
rejected_urls = UrlSubmission.objects.all().filter(
added_by_team=team.id,
has_been_accepted=False,
......@@ -181,7 +186,6 @@ def scores(request):
for scan in scans:
temp_calculation = get_calculation(scan)
final_calculation['high'] += temp_calculation['high']
final_calculation['medium'] += temp_calculation['medium']
final_calculation['low'] += temp_calculation['low']
......@@ -190,8 +194,10 @@ def scores(request):
'low': 100,
'medium': 250,
'high': 1000,
'rejected': 1337,
'rejected_organization': 1337,
'rejected_url': 1337,
'organization': 500,
'url': 250,
}
score = {
......@@ -209,13 +215,24 @@ def scores(request):
'added_organizations': added_organizations,
'added_organizations_multiplier': score_multiplier['organization'],
'added_organizations_score': added_organizations * score_multiplier['organization'],
'rejected': rejected_urls,
'rejected_multiplier': score_multiplier['rejected'],
'rejected_score': rejected_urls * score_multiplier['rejected'],
'total_score': final_calculation['high'] * score_multiplier['high'] +
final_calculation['medium'] * score_multiplier['medium'] +
final_calculation['low'] * score_multiplier['low'] +
added_organizations * score_multiplier['organization'] - rejected_urls * score_multiplier['rejected']
'added_urls': added_urls,
'added_urls_multiplier': score_multiplier['url'],
'added_urls_score': added_urls * score_multiplier['url'],
'rejected_organizations': rejected_organizations,
'rejected_organizations_multiplier': score_multiplier['rejected_organization'],
'rejected_organizations_score': rejected_organizations * score_multiplier['rejected_organization'],
'rejected_urls': rejected_urls,
'rejected_urls_multiplier': score_multiplier['rejected_url'],
'rejected_urls_score': rejected_urls * score_multiplier['rejected_url'],
'total_score':
final_calculation['high'] * score_multiplier['high'] +
final_calculation['medium'] * score_multiplier['medium'] +
final_calculation['low'] * score_multiplier['low'] +
added_organizations * score_multiplier['organization'] +
added_urls * score_multiplier['url'] - (
rejected_urls * score_multiplier['rejected_url'] +
rejected_organizations * score_multiplier['rejected_organization']
)
}
scores.append(score)
......@@ -225,7 +242,8 @@ def scores(request):
return render(request, 'game/scores.html', {'team': get_team_info(request),
'scores': scores,
'contest': contest})
'contest': contest,
'menu_selected': 'scores'})
def contests(request):
......
......@@ -239,6 +239,9 @@ calculation_methods = {
def get_calculation(scan):
# Can be probably more efficient by adding some methods to scan.
if not calculation_methods.get(scan.type, None):
raise ValueError("No calculation available for this scan type: %s" % scan.type)
calculation = calculation_methods[scan.type](scan)
# handle comply or explain
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment