Add admin for plain http scanner, make job id clickable in user message.

parent 55451cca
......@@ -48,6 +48,8 @@ class Job(models.Model):
"""Celery task to store result of task after it has completed."""
print(result, job_id)
job = Job.objects.get(id=job_id)
if not result:
result = '-- task generated no result object --'
job.result = result
job.status = 'completed'
job.finished_on = datetime.datetime.now()
......
......@@ -4,3 +4,13 @@
<!-- Inject admin action dropdown conversion to button for all admin pages. -->
<script type="text/javascript" src="{% static 'js/action_buttons.js' %}"></script>
{% endblock %}
<!-- Override user message logic to allow html in messages (Admin Action Job Links) -->
{% block messages %}
{% if messages %}
<ul class="messagelist">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message|capfirst|safe }}</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
......@@ -3,6 +3,7 @@ from datetime import datetime
import pytz
from django.contrib import admin
from django.urls import reverse
from jet.admin import CompactInline
from failmap_admin.map.determineratings import (OrganizationRating, UrlRating, rate_organization,
......@@ -174,8 +175,13 @@ class UrlAdmin(admin.ModelAdmin):
actions.append('security_headers')
def plain_http_scan(self, request, queryset):
plain_http_scan_urls([url for url in queryset])
self.message_user(request, "Scan Plain Http: done")
urls = list(queryset)
task = plain_http_scan_urls(urls=urls, execute=False)
print(task)
name = "Scan Plain Http (%s) " % str(urls)
job = Job.create(task, name, request)
link = reverse('admin:app_job_change', args=(job.id,))
self.message_user(request, '%s: job created, id: <a href="%s">%s</a>' % (name, link, str(job)))
plain_http_scan.short_description = "🔬 Scan Plain Http"
actions.append('plain_http_scan')
......
......@@ -7,10 +7,13 @@ future.
"""
import logging
from celery import group
from failmap_admin.organizations.models import Url
from failmap_admin.scanners.endpoint_scan_manager import EndpointScanManager
from failmap_admin.scanners.scanner_http import scan_urls as scanner_http_scan_urls
from ..celery import app
from .models import Endpoint
logger = logging.getLogger(__package__)
......@@ -36,11 +39,15 @@ def scan_all_urls():
scan_url(url)
def scan_urls(urls):
for url in urls:
scan_url(url)
def scan_urls(urls, execute=True):
task = group([scan_url.s(url) for url in urls])
if execute:
task.apply_async()
else:
return task
@app.task
def scan_url(url):
scan_manager = EndpointScanManager
logger.debug("Checking for http only sites on: %s" % url)
......@@ -109,6 +116,7 @@ def scan_url(url):
scan_manager.add_scan("plain_https", http_endpoint, 0,
"Has a secure equivalent, which wasn't so in the"
"past.")
return 'done'
def verify_is_secure(url):
......
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