Commit f48ea5fb authored by Edvard Rejthar's avatar Edvard Rejthar

html template copied to jinja2

parent ae9cfe5c
......@@ -66,6 +66,8 @@ class Api:
if crawl:
if request["api"] == "json":
return CrawlView.output_json(crawl)
elif request["api"] == "mdmaug":
return CrawlView.output_mdmaug(crawl)
else:
return CrawlView.output_html(crawl)
......
/**
* Cache radio buttons responsivity
*/
......@@ -24,7 +23,7 @@ $("input[type=url]").val(new URL(window.location.href).searchParams.get("url"));
/**
* list scans button
$("#list-scans").click(() => {
$("#list-scans").click(() => {
let urls = get_urls();
if (urls) {
let url = urls[0];
......@@ -43,7 +42,7 @@ $("form").submit(() => {
cache = $(".active > input[type=number]").val();
}
let method = "html";
let method = "mdmaug";
for (let url of get_urls()) {
let rest_url = "/analyze={0}/{1}".format(cache, url);
launch_request(rest_url, method, url);
......@@ -81,7 +80,7 @@ $("#request-url-toggler").change(function () {
* @param {type} rest_url Part of the URI of the API.
* @returns {undefined}
*/
function launch_request(rest_url, method="json", header="Result", callback=null) {
function launch_request(rest_url, method = "json", header = "Result", callback = null) {
let counter = 0;
//let uri = "/api={0}/analyze={1}/{2}".format(method, cache, url);
let uri = "/api={0}{1}".format(method, rest_url);
......@@ -101,7 +100,7 @@ function launch_request(rest_url, method="json", header="Result", callback=null)
// start the ajax
$.ajax({
dataType: method,
dataType: (method === "mdmaug") ? "html" : method,
url: uri
}).done((data) => {
bootstrap_change_bg($el, "bg-success").find(".timer").prop("disabled", true).prepend("✓ ");
......@@ -114,9 +113,11 @@ function launch_request(rest_url, method="json", header="Result", callback=null)
} else {
s = data;
}
console.log("zdeee");
$("<div/>", {"class": "analysis", "html": "<h3>{0}</h3>".format(header) + s}).appendTo($("#analysis-result-panel"));
}
}).fail(() => {
}).fail((object, error) => {
console.warn("XHR failed:", object, error);
bootstrap_change_bg($el, "bg-danger").find(".timer").prepend("× ");
}).always(() => {
clearInterval(increase_elapsed);
......@@ -153,9 +154,9 @@ if (!String.prototype.format) {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] !== 'undefined'
? args[number]
: match
;
? args[number]
: match
;
});
};
}
......
......@@ -11,8 +11,11 @@ class CrawlView:
""" HTML output of a crawl instance """
@staticmethod
def output_json(crawl):
def output_json(crawl, expand_screenfile=False):
#print(crawl)
if expand_screenfile and crawl.screenfile:
with open(crawl.screenfile, "r") as f:
crawl.screenfile = f.read()
output = {"screenfile": crawl.screenfile,
"host": crawl.host,
"safebrowsing-suspicious": Domains.is_suspicious(crawl.host, 'attr'),
......@@ -42,11 +45,16 @@ class CrawlView:
for link in url.list_sourcefiles():
d["sourcefiles"].append(link)
# from pprint import pprint
# import ipdb; ipdb.set_trace()
# pprint(crawl)
# pprint(output)
return output
@staticmethod
def output_mdmaug(crawl):
return render_template("output_mdmaug.html", crawl=CrawlView.output_json(crawl))
return render_template("output_mdmaug.html", output=CrawlView.output_json(crawl, expand_screenfile=True))
@staticmethod
def output_html(crawl):
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
<div class="col-sm-3">
{{ output["host"] }}
</div>
<div class='analysis' data-host='{{ output["host"] }}' data-safebrowsing-suspicious='{{ output["safebrowsing-suspicious"] }}'>
{% if output["screenfile"] %}
<div class='screenshot'><img class='thumbnail' src='data:image/png;base64,{{ output["screenfile"] }}'/></div>
{% endif %}
{% for domain in output["domains"].values() -%}
<div class=web data-vote='{{ domain["vote"] }}' data-safebrowsing-suspicious='{{ domain["safebrowsing-suspicious"] }}'>
<span class=domain>{{ domain["domain"] }}</span>
<div class=addresses>
{% for address_name, address in domain["addresses"].items() -%}
<div class=address>
<span class=ip>{{ address_name }}}</span>
{% if address.country -%}}
<span class=country>{address.country}</span>
{% endif %}
{% if address.city -%}}
if address.city:
<span class=city>{address.city}</span>
{% endif %}
</div>
{% endfor %}
{% if domain["pdns"] -%}
<span class=pdns>
{% for i, pdnsDomain in enumerate(domain["pdns"]) -%}
<span>{pdnsDomain}</span>
{%- endfor %}
</span>
{%- endif %}
</div>
<ul class=urls>
{% for url_name, url in domain["urls"].items() -%}
<li>
<span class='value'>{{url_name}}</span>
{% for spyfile in url["spyfiles"] -%}
<div class='spyfile'>{{ spyfile["text"] }}</div>
{% if spyfile["full_link"] -%}
<a href='{{ spyfile["full_link"] }}' class='spyfile-full'>-></a>
{%- endif %}
{%- endfor %}
{% for link in url["sourcefiles"] -%}
<a href='{{ link }}' class='sourcefile'></a>
{%- endfor %}
</li>
{%- endfor %}
</ul>
</div>
{%- endfor %}
</div>
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