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 @@ ...@@ -96,7 +96,7 @@
</li> </li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <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"> <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> <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"> <div class="dropdown-menu" aria-labelledby="navbarDropdown3">
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
{% endif %} {% endif %}
<h2>Currently open</h2> <h2>Currently open</h2>
<table class="table"> <table class="table table-sm table-striped table-bordered table-hover">
<thead> <thead>
<tr> <tr>
<th width="10%"></th> <th width="10%"></th>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
</table> </table>
<h2>Upcoming</h2> <h2>Upcoming</h2>
<table class="table"> <table class="table table-sm table-striped table-bordered table-hover">
<thead> <thead>
<tr> <tr>
<th width="10%"></th> <th width="10%"></th>
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
</table> </table>
<h2>Expired</h2> <h2>Expired</h2>
<table class="table"> <table class="table table-sm table-striped table-bordered table-hover">
<thead> <thead>
<tr> <tr>
<th width="10%"></th> <th width="10%"></th>
......
{% extends 'game/base.html' %} {% extends 'game/base.html' %}
{% block content %} {% block content %}
<h1>Scores</h1> <p style="width: 100%; text-align: center; font-size: 10vw;">{{ contest.name | truncatechars:16 }}</p>
<p>Contest: {{ contest.name }}, from {{ contest.from_moment }} until {{ contest.until_moment }}.</p>
<p>This contest targets {{ contest.target_country }}.</p> <p style="width: 100%; text-align: center; font-size: 2em;">Starts at {{ contest.from_moment }}. Deadline: {{ contest.until_moment }}.</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>
{% for score in scores %} {% for score in scores %}
<tr style="{% if team.name == score.team %} font-weight: bold; background-color: #ddffdd;{% endif %}"> <table class="table table-sm table-striped table-bordered table-hover" style="width: 29%; float:left; margin: 20px;">
<td>{{ forloop.counter }}</td> <tbody>
<td style="background-color: {{ score.team_color }};">{{ score.team }}</td>
<td>{{ score.high }} * {{ score.high_multiplier }} = {{ score.high_score }}</td> <tr><td colspan="3" style="font-weight: bold; font-family: impact, sans-serif; font-size: 6em; text-align: center;"># {{ forloop.counter }}</td></tr>
<td>{{ score.medium }} * {{ score.medium_multiplier }} = {{ score.medium_score }}</td> <tr><td colspan="3" style="font-size: 3em; text-align: center;">{{ score.team | truncatechars:12 }}</td></tr>
<td>{{ score.low }} * {{ score.low_multiplier }} = {{ score.low_score }}</td> <tr><td>Total score</td> <td colspan="2" style="text-align: center; font-size: 2em;">{{ score.total_score }}</td></tr>
<td>{{ score.rejected }} * -{{ score.rejected_multiplier }} = -{{ score.rejected_score }}</td> <tr><td>Organizations</td> <td>{{ score.added_organizations }}</td><td><small>* {{ score.added_organizations_multiplier }} = {{ score.added_organizations_score }}</small></td></tr>
<td>{{ score.added_organizations }} * {{ score.added_organizations_multiplier }} = {{ score.added_organizations_score }}</td> <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>
<td>{{ score.total_score }}</td> <tr><td>Urls</td> <td>{{ score.added_urls }}</td><td><small>* {{ score.added_urls_multiplier }} = {{ score.added_urls_score }}</small></td></tr>
</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>
{% empty %} <tr><td>High risk</td> <td>{{ score.high }}</td><td><small>* {{ score.high_multiplier }} = {{ score.high_score }}</small></td></tr>
<tr><td colspan="5">-</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 %} {% endfor %}
</tbody>
</table> <br style="clear: both">
<p>This contest targets {{ contest.target_country }}.</p>
{% if team.name %} {% if team.name %}
<a href="/game/submit_organization" role="button" class="btn btn-success">Submit Organization</a> <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 ...@@ -17,7 +17,8 @@ from failmap.game.forms import ContestForm, OrganisationSubmissionForm, TeamForm
from failmap.game.models import Contest, OrganizationSubmission, Team, UrlSubmission from failmap.game.models import Contest, OrganizationSubmission, Team, UrlSubmission
from failmap.map.calculate import get_calculation from failmap.map.calculate import get_calculation
from failmap.organizations.models import Organization, OrganizationType, Url 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__) log = logging.getLogger(__package__)
...@@ -140,26 +141,24 @@ def scores(request): ...@@ -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 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. 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__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(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
)) ))
scans += list(UrlGenericScan.objects.all().filter( scans += list(UrlGenericScan.objects.all().filter(
url__urlsubmission__added_by_team=team.id, 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_organizations = OrganizationSubmission.objects.all().filter(
added_by_team=team.id, added_by_team=team.id,
has_been_accepted=True, has_been_accepted=True,
...@@ -167,6 +166,12 @@ def scores(request): ...@@ -167,6 +166,12 @@ def scores(request):
).count() ).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( rejected_urls = UrlSubmission.objects.all().filter(
added_by_team=team.id, added_by_team=team.id,
has_been_accepted=False, has_been_accepted=False,
...@@ -181,7 +186,6 @@ def scores(request): ...@@ -181,7 +186,6 @@ def scores(request):
for scan in scans: for scan in scans:
temp_calculation = get_calculation(scan) temp_calculation = get_calculation(scan)
final_calculation['high'] += temp_calculation['high'] final_calculation['high'] += temp_calculation['high']
final_calculation['medium'] += temp_calculation['medium'] final_calculation['medium'] += temp_calculation['medium']
final_calculation['low'] += temp_calculation['low'] final_calculation['low'] += temp_calculation['low']
...@@ -190,8 +194,10 @@ def scores(request): ...@@ -190,8 +194,10 @@ def scores(request):
'low': 100, 'low': 100,
'medium': 250, 'medium': 250,
'high': 1000, 'high': 1000,
'rejected': 1337, 'rejected_organization': 1337,
'rejected_url': 1337,
'organization': 500, 'organization': 500,
'url': 250,
} }
score = { score = {
...@@ -209,13 +215,24 @@ def scores(request): ...@@ -209,13 +215,24 @@ def scores(request):
'added_organizations': added_organizations, 'added_organizations': added_organizations,
'added_organizations_multiplier': score_multiplier['organization'], 'added_organizations_multiplier': score_multiplier['organization'],
'added_organizations_score': added_organizations * score_multiplier['organization'], 'added_organizations_score': added_organizations * score_multiplier['organization'],
'rejected': rejected_urls, 'added_urls': added_urls,
'rejected_multiplier': score_multiplier['rejected'], 'added_urls_multiplier': score_multiplier['url'],
'rejected_score': rejected_urls * score_multiplier['rejected'], 'added_urls_score': added_urls * score_multiplier['url'],
'total_score': final_calculation['high'] * score_multiplier['high'] + 'rejected_organizations': rejected_organizations,
final_calculation['medium'] * score_multiplier['medium'] + 'rejected_organizations_multiplier': score_multiplier['rejected_organization'],
final_calculation['low'] * score_multiplier['low'] + 'rejected_organizations_score': rejected_organizations * score_multiplier['rejected_organization'],
added_organizations * score_multiplier['organization'] - rejected_urls * score_multiplier['rejected'] '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) scores.append(score)
...@@ -225,7 +242,8 @@ def scores(request): ...@@ -225,7 +242,8 @@ def scores(request):
return render(request, 'game/scores.html', {'team': get_team_info(request), return render(request, 'game/scores.html', {'team': get_team_info(request),
'scores': scores, 'scores': scores,
'contest': contest}) 'contest': contest,
'menu_selected': 'scores'})
def contests(request): def contests(request):
......
...@@ -239,6 +239,9 @@ calculation_methods = { ...@@ -239,6 +239,9 @@ calculation_methods = {
def get_calculation(scan): def get_calculation(scan):
# Can be probably more efficient by adding some methods to 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) calculation = calculation_methods[scan.type](scan)
# handle comply or explain # 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