Commit 60d80fa0 authored by Edvard Rejthar's avatar Edvard Rejthar

MDM re-integration

parent 024d2761
......@@ -25,8 +25,8 @@ class Config:
browser = 'firefox' # iceweasel, firefox. What browser gets launched.
config_file = '/opt/mdmaug/.cache/mdmaug-scans/_tmp/queue.cache' # RAM disk was too small: '/tmp/mdm/queue.cache'
APP_PORT = 5000
APP_IP = "127.0.0.1" # 217.31.202.41
APP_HOST = f'http://{APP_IP}:{APP_PORT}' # Xhttps
APP_IP = "127.0.0.1" # CHANGE HERE IF NOT RUN ON LOCALHOST
APP_HOST = f'http://{APP_IP}:{APP_PORT}' # YOU MAY NEED TO CHANGE **https**
LOG_DIR = "/opt/mdmaug/.cache/mdmaug-scans/_tmp/"
CACHE_DIR = "/opt/mdmaug/.cache/mdmaug-scans/"
ALLOWED_DESTINATION = {"mdm.nic.cz": "https://mdm.nic.cz",
......
......@@ -136,7 +136,12 @@ def controller(request_url):
if "destination" in request:
if request["destination"] in Config.ALLOWED_DESTINATION:
# send everything up, we are in an iframe
return render_template("_message.html", contents=output, url=request_url,
try:
# this is not very nice workaround - MDM needs to know if it called 'vote' or 'analyze' command
cmd = list(request.keys())[3]
except:
cmd = "unknown"
return render_template("_message.html", contents=output, url=request_url, cmd=cmd,
destination=Config.ALLOWED_DESTINATION[request['destination']])
else:
return "Wrong destination: " + escape(request["destination"])
......
......@@ -171,7 +171,7 @@ class Encounter(DbModel):
logger.error(f"domain {host} should have been inserted in the database, but it hasn't been")
raise
ip_list = list(set([o.ip for o in rows if o.ip is not None]))
count = 0
count = 0
if ip_list:
count += Encounter.update(status=str(status)).where(Encounter.ip << ip_list).execute()
# ovlivnit i host s IP = NULL
......
......@@ -14,32 +14,14 @@ const LOCAL_DESTINATION = new URL(location.href);
const VOTING_SELECTOR = ".analysis > form > [data-group] > .web > .voting > input[type=radio]";
const RELATED_SELECTOR = ".analysis > form > [data-group] > .web > .addresses > .related > a";
const SCAN_SELECTOR = ".analysis > form > .scans > span";
//const APP_HOST = must be defined before // "https://217.31.202.41:8000";
APP_HOST = (typeof(APP_HOST) !== "undefined") ? APP_HOST : (new URL(document.querySelector("script[data-mdmaug]").src)).origin; //const APP_HOST is defined before in MDMaug, on MDM, it's in the <script src>
var $analysis_panel;
//var $analysis;
var KEY = {
DOWN: 40,
UP: 38,
LEFT: 37,
RIGHT: 39,
ALT: 17,
C: 67,
L: 76,
N: 78,
W: 87,
N1: 49,
N2: 50,
N3: 51,
N4: 52,
N5: 53,
N6: 54,
N7: 55,
N8: 56,
N9: 57,
F: 70,
S: 83
};
let KEY = {
DOWN: 40, UP: 38, LEFT: 37, RIGHT: 39, ALT: 17, C: 67, L: 76, N: 78, W: 87,
N1: 49, N2: 50, N3: 51, N4: 52, N5: 53, N6: 54, N7: 55, N8: 56, N9: 57, F: 70, S: 83
};
/**
* Zmeni hodnotu hlasovani.
......@@ -65,12 +47,9 @@ changeVote = function ($radio, propagate) {
$("body").append("<iframe class='cors' width='10px' height='10px' src='" + APP_HOST + "/destination=" + LOCAL_DESTINATION.hostname + "/api/vote=" + str + "/" + domain + "'></iframe>");
// send to siblings on the page (there may be another analysis with the same domain encountered present)
console.log('Line 43 "Seznam"(): ', "Seznam");
$("{0}[name='{1}'][value='{2}']".format(VOTING_SELECTOR, domain, $radio.val())).each(function () {
console.log('Line 44 "going to change..."(): ', "going to change...", this);
$(`${VOTING_SELECTOR}[name='${domain}'][value='${$radio.val()}']`).each(function () {
//$(this).val($radio.val());
if (this === $radio[0]) {
console.log('Line 48 "JA"(): ', "JA");
return;
}
changeVote($(this).prop("checked", true), "shuffle");
......@@ -79,7 +58,7 @@ changeVote = function ($radio, propagate) {
//podminka slouzi k tomuhle: kdyz uzivatel hlasuje, propaguje se jeho volba do materskeho tabu a odtamtud zase zpet sem.
// Kdyz klikne uzivatel, nechceme mu zmenit poradi pod nosem.
let group = ($radio.val() == "n/a" && $webEl.attr("data-sfb") == 1) ? "suspicious" : $radio.val();
$webEl.appendTo($("[data-group='{0}']".format(group), $radio.closest(".analysis")));
$webEl.appendTo($(`[data-group='{group}']`, $radio.closest(".analysis")));
// if ($radio.val() == "allow") {//zmenit poradi
// $webEl.appendTo($("[data-group=allow]"));
......@@ -99,28 +78,124 @@ changeVote = function ($radio, propagate) {
$webEl.attr("data-vote", $radio.val());//stav materskeho tagu .web
};
if (document.location.href.indexOf("/detail/") !== -1) { // ex: https://mdm.nic.cz/details/
if (typeof j === "function") { // load jQuery from MDM's local variable 'j'
$ = j;
$(function () {
// vote for remote host maliciousness
$analysis_panel = $("#analysis-result-panel");
//$analysis_panel = $("<div/>", {id: "analysis"}).appendTo($analysis_panel);
$("#analysis-result-panel").on("change", VOTING_SELECTOR, function () {
console.log("VOTING CHANGE");
changeVote($(this), true);
})
// we can click on a domain from "related" list
$("#analysis-result-panel").on("click", RELATED_SELECTOR, function () {
if (typeof(launch_request) === "undefined") {
alert("Seeing older analyses not implemented yet in MDM, only in MDMaug.");
return false;
}
let url = $(this).text();
let $a = $(`#requests-panel .input-group .form-control a:contains(${url})`);
if ($a.length) { // we have this scan on the very page → navigate there
$a.closest(".input-group").find("button").click();
} else { // query for scan results
launch_request("/scan=" + url, url);
}
return false;
})
// click on another scan to go there
$("#analysis-result-panel").on("click", SCAN_SELECTOR, function () {
if (typeof(launch_request) === "undefined") {
alert("Not implemented yet in MDM, only in MDMaug.");
return false;
}
let domain = new URL($(this).closest(".analysis").find("> form > h2").text()).hostname;
let scan = $(this).attr("data-scan");
let url = domain + " " + scan;
let $a = $(`#requests-panel .input-group .form-control a:contains(${url})`);
if ($a.length) { // we have this scan on the very page → navigate there
$a.closest(".input-group").find("button").click();
} else { // query for scan results
launch_request(`/scan=${domain}/time=${scan}/`, url);
}
})
/**
* Focus next .web element. If there is none, focus next cousin * [data-group] > .web
* @param direction 0=prev, 1=next
*/
function focus_next_web(direction = 1) {
let method = ["next", "prev"][direction];
let $selected = $(":focus").closest(".web");
if ($selected.length) { // there is already a focused .web
if (!($el = $selected[method](".web")).length) {
// there isn't any .web directly next to current; check cousins in another 'data-group's
let prev, next;
let items = document.querySelectorAll(".web");
let selected = $selected[0];
for (let i = 0; i < items.length; i++) {// loops the items
if (selected.isSameNode(items[i])) {// this is our selected item in the DOM
prev = items[Math.max(i - 1, 0)];
next = items[Math.min(i + 1, items.length - 1)];
break;
}
}
$el = $([next, prev][direction]).focus();
}
$el = $("input:checked", $el).focus();
} else {
$(".web input:checked:first").focus();
}
}
// quickly browse results (if results are focused)
$('#analysis-result-panel').on("keydown", function (e) {
if (KEY.DOWN == e.keyCode) {
focus_next_web(0);
} else if (KEY.UP == e.keyCode) {
focus_next_web(1);
// if ($(":focus").closest(".web").length) {
// $("input:checked", $($(":focus").closest(".web")).prev(".web")).focus();
// } else {
// $(".web input:checked:first").focus();
// }
} else {
return true;
}
return false;
});
})
if (document.location.href.indexOf("/detail/") !== -1) { // ex: https://mdm.nic.cz/details/
// if (typeof j === "function") { // load jQuery from MDM's local variable 'j'
// $ = j;
// }
$(function () {
$('#detail_tabs').tabs('option', 'active', 3);//XX nejprve jdeme na tab korespondence (nevim, jestli tohle funguje)
$('#detail_tabs').tabs('option', 'active', 3); // go to "correspondence" tab
let $analysisTabHeader = $("li a[href='#analysis-result-panel']");
$analysisTabHeader.data("text", $analysisTabHeader.text())
// Add the MDMaug tab to the MDM application
$("div#detail_tabs ul").prepend("<li class='ui-state-default ui-corner-top'><a href='#analysis-result-panel'>Analýza <span id='analysis-info'></span></a></li>");
/*$("div#detail_tabs ul").prepend("<li class='ui-state-default ui-corner-top'><a href='#analysis-result-panel'>Analysis <span id='analysis-info'></span></a></li>");
$("div#detail_tabs").append($("<div />", {
id: 'analysis-result-panel',
class: 'ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide'
}));
$("div#detail_tabs").tabs("refresh");
$("<h1>MDMaug analýza</h1><p>(Alt+↕ pohybuje mezi hlasováním)</p>").prependTo("#analysis-result-panel");
*/
//$("<h1>MDMaug analysis</h1><p>(Alt+↕ pohybuje mezi hlasováním)</p>").prependTo("#analysis-result-panel");
Analysis = function () {
//vypis analyzy
$reanalyzeButton = $("<button>reanalyze</button>").appendTo($analysis_panel).click(function () {
cache.reanalyze();
alert("Not yet implemented in MDM. Go to MDMaug page: " + APP_HOST);
//cache.reanalyze();
}).hide();
//listener analyzy - analyze keyword
......@@ -129,14 +204,14 @@ if (document.location.href.indexOf("/detail/") !== -1) { // ex: https://mdm.nic.
console.log("event", e);
if (e.data.analyze) {//jedna se o zpravu pro me
// dat vedet uzivateli
$("#analysis-info").text("");
$analysisTabHeader[0].firstChild.data = $analysisTabHeader.data("text") + ""; // change text without affecting <u>number</u> shortcut-hint
//$("#analysis-info").text("✓");
$('#detail_tabs').tabs('option', 'active', 0);//překliknout na daný tab
$analysis_panel.prepend(e.data.analyze);
//ulozit do sessionStorage (pri prostem refreshi nedojde k narocne reanalyze)
if (e.data.url !== "refresh") {//neukladame do storage, protoze tohle je load ze storage, nikoli fresh analyza
let analysisHost = $(".analysis:eq(0)", $analysis_panel).attr("data-host");
console.log("HOST", analysisHost);
if (typeof analysisHost === "undefined") {//mdmaug skoncil chybou, zkusime host dostat z URL iframu
// "/destination=mdm.nic.cz/api/analyze=cached/http://www.klein-automotive.cz/aktuality/page/2/" -> http://...
var path = e.data.url.split("/");
......@@ -146,7 +221,7 @@ if (document.location.href.indexOf("/detail/") !== -1) { // ex: https://mdm.nic.
analysisHost = path.join("/");
}
//<iframe width='10px' height='10px' src='" + APP_HOST + "/api/analyze" + (typeof forceServer === 'undefined' ? "=cached" : "") + "/" + url + "'></iframe>
cache.add(analysisHost, e.data.analyze);
//cache.add(analysisHost, e.data.analyze);
}
// add the safebrowsing icon to the main page header
......@@ -173,7 +248,7 @@ if (document.location.href.indexOf("/detail/") !== -1) { // ex: https://mdm.nic.
// let's vote
// focus voting from suspicious (undecided for Safebrowsing) or n/a (undecided);
// (there is no reason in focusing 'allow', jeste nekomu ujede ruka)
$("[data-group=suspicious], [data-group='n/a']").find(".voting:eq(0) input:eq(0)").focus();
$("[data-group=suspicious], [data-group='n/a']").find(".voting:eq(0) input:checked").focus();
} else if (e.data.voted) {//ve vedlejsim tabu se hlasovalo, zmen hodnotu i zde
changeVote($("[type=radio][value='" + e.data.voted + "']", $(".web .domain:contains('" + e.data.domain + "'):eq(0)").siblings(".voting")).prop("checked", true), false);//hlasovat
}
......@@ -188,391 +263,66 @@ if (document.location.href.indexOf("/detail/") !== -1) { // ex: https://mdm.nic.
* @returns {undefined}
*/
analyze = function (url, forceServer) {
if ((str = cache.get(url)) === null) {
//analyza: ziskat linkovane stranky z MDM-aug stroje.
$("#analysis-result-panel > h1:eq(0)").append(" " + url);
$("#analysis-info").text("...");
$("#content").before("<iframe width='10px' height='10px' src='" + APP_HOST + "/destination=" + LOCAL_DESTINATION.hostname + "/api/analyze" + (typeof forceServer === 'undefined' ? "=cached" : "") + "/" + url + "'></iframe>");
} else {//pouzit starou analyzu
window.postMessage({"analyze": str, "url": "refresh"}, LOCAL_DESTINATION.origin);
//reanalyzeButton.show();
}
//if ((str = cache.get(url)) === null) {
//analyza: ziskat linkovane stranky z MDM-aug stroje.
$("#analysis-result-panel > h1:eq(0)").append(" " + url);
$analysisTabHeader[0].firstChild.data = $analysisTabHeader.data("text") + "..."; // change text without affecting <u>number</u> shortcut-hint
//$("#analysis-info").text("...");
$("#content").before("<iframe width='10px' height='10px' src='" + APP_HOST + "/destination=" + LOCAL_DESTINATION.hostname + "/api/analyze" + (typeof forceServer === 'undefined' ? "=cached" : "") + "/" + url + "'></iframe>");
// } else {//pouzit starou analyzu
// window.postMessage({"analyze": str, "url": "refresh"}, LOCAL_DESTINATION.origin);
// //reanalyzeButton.show();
// }
$reanalyzeButton.show();
};
/**
* Interni session storage, kam se ukladaji jednotlive analyzy.
*/
cache = function () {
get = function (url) {
return (sessionStorage.getItem("analysis_" + url));
};
/**
* Ulozit do sessionStorage (pri prostem refreshi nedojde k narocne reanalyze)
*/
add = function (url, contents) {
console.log("ukladam");
console.log(url);
sessionStorage.setItem("analysis_" + url, contents);
};
/**
* Vsechna url v cachi reanalyzujeme.
* Projdeme vsechny item, ktere zacinaji na prefix "analysis_" a znovu je analyzujeme.
* @returns {undefined}
*/
reanalyze = function () {
for (var i = 0; i < sessionStorage.length; i++) {
if (sessionStorage.key(i).indexOf("analysis_") === 0) {//ma nas prefix
console.log(i);
item = sessionStorage.key(i);
console.log(item);
sessionStorage.removeItem(item);
console.log(item.substring("analysis_".length), item.substring(1));
Analysis.analyze(item.substring("analysis_".length), true);
i--;//ukazatel se neposune
}
}
};
return {
get: get,
add: add,
reanalyze: reanalyze
};
}();
// /**
// * Interni session storage, kam se ukladaji jednotlive analyzy.
// */
// cache = function () {
// get = function (url) {
// return (sessionStorage.getItem("analysis_" + url));
// };
//
// /**
// * Ulozit do sessionStorage (pri prostem refreshi nedojde k narocne reanalyze)
// */
// add = function (url, contents) {
// console.log("ukladam");
// console.log(url);
// sessionStorage.setItem("analysis_" + url, contents);
// };
// /**
// * Vsechna url v cachi reanalyzujeme.
// * Projdeme vsechny item, ktere zacinaji na prefix "analysis_" a znovu je analyzujeme.
// * @returns {undefined}
// */
// reanalyze = function () {
// for (var i = 0; i < sessionStorage.length; i++) {
// if (sessionStorage.key(i).indexOf("analysis_") === 0) {//ma nas prefix
// console.log(i);
// item = sessionStorage.key(i);
// console.log(item);
// sessionStorage.removeItem(item);
// console.log(item.substring("analysis_".length), item.substring(1));
// Analysis.analyze(item.substring("analysis_".length), true);
// i--;//ukazatel se neposune
// }
// }
// };
//
// return {
// get: get,
// add: add,
// reanalyze: reanalyze
//
// };
//
// }();
return {analyze: analyze};
}();
Controls = function () {
//variables
urlQueryUrl = "";
sucuriNetUrl = "";
daphneUrl = "";
virtualMachineUrl = "";
safebrowsingUrl = "";
screenshotUrl = "";
correspondenceCount = "";
correspondenceUrl = "";
/**
* preklikneme na tab "status" a skrolujeme na konec textarey
*/
getStatus = function () {
$('#detail_tabs').tabs('option', 'active', 3); //X select
$("textarea").focus();//jedina textarea je statusova
setTimeout(function () {//odrolovat textareu dolu
$("textarea").scrollTop($("textarea")[0].scrollHeight - $("textarea").height());
}, 500);
};
/**
* prida linky na externi sluzby
*/
refreshControls = function () {
//Controls
console.log($("td[abbr=uri]:first"));
url = $("td[abbr=uri]:first").text();
domain = $('<a>').prop('href', url).prop('hostname');
/*
urlQueryUrl = "http://urlquery.net/#search=" + url;
sucuriNetUrl = "http://sitecheck.sucuri.net/#search=" + domain;
daphneUrl = "https://manager.nic.cz/domain/filter/?save_input=name&presention%7CHandle=000&Handle=" + domain;
virtualMachineUrl = "http://web.edvard.cz/mdm_vm/?push=" + url;//domain;//pres externi zasobnik lze snadno otevrit vice domen v bezpecne VM
safebrowsingUrl = "http://www.google.com/safebrowsing/diagnostic?site=" + url;
screenshotUrl = "https://www.url2png.com/?url=" + url;
$("<a href='" + urlQueryUrl + "'>uq </a> ", {title: "urlquery"}).css("fontSize", "200%").insertBefore($("#detail_tabs"));//.appendTo(this);
$("<a href='" + sucuriNetUrl + "'>sc </a>").css("fontSize", "200%").insertBefore($("#detail_tabs"));
$("<a href='" + daphneUrl + "'>da </a>").css("fontSize", "200%").insertBefore($("#detail_tabs"));
$("<a href='" + virtualMachineUrl + "'>vm </a>").css("fontSize", "200%").insertBefore($("#detail_tabs"));
$("<a href='" + safebrowsingUrl + "' title=safebrowsing>sf </a>").css("fontSize", "200%").insertBefore($("#detail_tabs"));
$("<a href='" + screenshotUrl + "'>img </a>").css("fontSize", "200%").insertBefore($("#detail_tabs"));*/
setMessageLink = function () {
//korespondence - message
correspondenceCount = $("#ticket > div").length;
if ($(".reply:last").length) {//uz probehla konverzace
correspondenceUrl = $(".reply:last a").attr("href");
dateParts = ($(".caption:last").contents().filter(function () {//datum z textu
return this.nodeType !== 1;
}).text()).split("-");
d = new Date(dateParts[0], dateParts[1] - 1, dateParts[2].substr(0, 2));
correspondenceDays = Math.floor(((new Date) - d) / (24 * 60 * 60 * 1000));//kolik dni je zprava stara
corrText = "počet: " + correspondenceCount + ", dnů: " + correspondenceDays;
} else {//jeste zadna konverzace, pisme novou zpravu
correspondenceUrl = $("#correspondence > div > a").attr("href") + "#send";
correspondenceDays = "-";
corrText = "žádná";
}
}();
// setMessageLink();//refresh url odkazu. Protoze GM je nekdy rychlejsi nez $.tabs.
$("li a[href=#correspondence]").append(" (" + corrText + ", <u>w</u>)");
//uzivatel se muze rozhodnout analyzovat jeste dalsi stranku, kdyz se na prvni vir nenachazel
$("td[abbr=uri]").each(function () {
$("<button>add to analysis</button>").appendTo(this).click(function () {
Analysis.analyze($("a", $(this).parent()).text());
});
});
};
/**
* Vykona akce, ktere jsou ulozene v hashi - posle zpravu, pocka na analyzu, zobrazi telefonni cislo.
*/
parseHash = function () {
keepTabOpen = true;
var hash = location.hash.replace(/^.*?#/, '').split("&");
//zaslani zpravy
if ((pos = hash.indexOf("message")) !== -1) {//ma se poslat automaticky email
hash.push($("table tbody td:nth-child(5) img:eq(0)").attr("alt")); //+Phishtank
hash.splice(pos, 1);//pri refreshi stranky neposleme druhy email
if (correspondenceCount < 3) { //pocet udalosti v bugtracku je mensi nez tri -> zadna zprava se doposavad nedeslala (e-mail je nejdrive 3. polozka v trackeru)
hash.push("send");
Analysis.analyze(url);//po odeslani zpravy se uz analyze znovu nespusti, je treba ji spustit rovnou
location = correspondenceUrl + "#" + hash.join("&");//presmerovani k odeslani zpravy
} else if (correspondenceDays > 70) {
//veteran -> musime se zorientovat, jestli vlastnik domeny nereagoval (pak by byla debilni chyba na nasi strane, mu znovu poslat jen automaticky mail)
//tab korespondence
$('#detail_tabs').tabs('option', 'active', 3);
//pridame tlacitko, kterym muzeme znovuodeslat automatickou fresh-message
($("<button>fresh resend</button>").prependTo($("#correspondence")).click(function () {
location = correspondenceUrl + "#" + hash.join("&") + "&send";
}).focus());
} else {//ani stare, ani nove hlaseni
keepTabOpen = false;//nechceme-li analyzovat ani kontaktovat, nemame duvod okno nezavrit
}
}
//zprava zaslana
if (hash.indexOf("sent") !== -1 && $(".info:eq(1)").text() === "Zpráva byla úspěšně odeslána.") {
console.log("zprava byla uspesne odeslana");
console.log("stary hash:");
console.log(hash);
if ((pos = hash.indexOf("contact")) !== -1) {//urcite nechceme telefonovat nekomu, komu jsme prave psali; storno defaultniho contact-flagu
hash.splice(pos, 1);
}
console.log("novy hash (mel by se vyhodit kontakt):");
console.log(hash);
keepTabOpen = false;
}
//analyza
if (hash.indexOf("analyze") !== -1) {//chceme nyni vyhodnocovat vysledky analyzy
keepTabOpen = true;
}
//telefonovat
if (hash.indexOf("contact") !== -1) {//chceme zobrazit telefonni cislo
console.log(" contact found - keepTabOpen = true");
keepTabOpen = true;
//tab korespondence - zobrazit status a messages
$('#detail_tabs').tabs('option', 'active', 2);
//propojit s Daphne
da = "https://manager.nic.cz/domain/filter/?save_input=name&presention%7CHandle=000&Handle=" + domain;
$("<iframe width='10px' height='10px' src='" + da + "'></iframe>").prependTo($("#content")); //prednacteni iframu
window.addEventListener("message", function (e) {
console.log(e);
if (e.data.phoneTable) {
$("#content").prepend(e.data.phoneTable);
$("tbody td.left_label:contains('Phone:')+td").css({"fontSize": "200%"});//telefonni cislo ztucnit
}
});
}
//$("<iframe height=40 src='"+daphne+"'></iframe>").insertBefore($("#detail_tabs"));
//otevirat zpravu - dole v iframu //$("#content").after("<iframe width='100%' height='1000px' src='"+correspondenceUrl+"'></iframe>");
if (keepTabOpen === false) {//nechci analyzovat a nemam na praci nic dalsiho, analyza probehla -> projdu si ji pak hromadne
console.log("zaviram okno...");
if (window.opener) {
window.opener.postMessage({"close": "close"}, LOCAL_DESTINATION.origin);
}
window.close();//pro jistotu zkusime zavrit i zde, kdyby parent okno selhalo (ve FF musi byt povoleno about:config allow_scripts_to_close_windows)
} else {
console.log("nezaviram okno...");
if (window.opener) {
window.opener.postMessage({"open": "ok"}, LOCAL_DESTINATION.origin);
}
//prehazet dopisy - nejnovejsi reakce navrch
$("#ticket > div").each(function () {
$(this).prependTo($(this).parent());
});
//do korespondence pripojime info z tabu status, at nemusime informace shanet po nekolika tabech
statusText = $("#status textarea").text()
.replace(/\d\d\d\d-(\d)?\d-(\d)?\d \d\d:\d\d:\d\d - user .* changed status from .* to/g, "")//vyskrtne vsechny "2014-11-03 09:30:13 - user Edvard Rejthar changed status from new to"
.replace(/\d\d\d\d-(\d)?\d-(\d)?\d \d\d:\d\d:\d\d - status změněn z '.*' na /g, "")//2011-04-04 13:22:45 - status změněn z 'dřívější' na 'nový'
.replace(/\d\d\d\d-(\d)?\d-(\d)?\d \d\d:\d\d:\d\d - uživatel .* změnil status z '.*' na/g, "");//2011-05-18 15:37:54 - uživatel update_daemon změnil status z 'nový' na 'dřívější'
$("<span title='Vyhodnoť, zda vlastník nepsal, a pakliže ne, zašli mu fresh mail.'><i>Status + korespondence</i></span>")
.prependTo($("#correspondence"))
.append(statusText);
//analyzu chceme iniciovat v kazdem pripade, byt ji ted nechceme vyhodnocovat
Analysis.analyze(url);
}
};
/**
* zkratky
*/
hotkeys = function () {
//napoveda - hotkeys
let num = 0;
$("#detail_tabs li a").each(function () {
$(this).append(" <u>" + (++num) + "</u>");
});
//hotkeys pro ovladani tabu
$('body').keydown(function (e) {
if (e.altKey) {
if (KEY.N1 <= e.keyCode && e.keyCode <= KEY.N6) {
$('#detail_tabs').tabs('option', 'active', e.keyCode - KEY.N1);
e.preventDefault();
}
if (KEY.W == e.keyCode) {//moznost rovnou psat zpravu
location.href = correspondenceUrl;
e.preventDefault();
}
}
});
};
/**
* //autoloader tridy
*/
init = function () {
//style();
hotkeys();
refreshControls();
parseHash();
}();
};
$(window).load(function () {
//Ihned zavřít a ignorovat veleznámé sity
if (location.hash.replace(/^.*?#/, '').split("&").indexOf("wellknownfree") !== -1) {
domain = $("h1:first").text().substr(8);
wellknown = ["webzdarma.cz", "wz.cz", "chytrak.cz", "volny.cz", "kvalitne.cz", "mujweb.cz", "centrum.cz"];
if (wellknown.indexOf(domain) !== -1) {
console.log("znama domena...");
if (window.opener) {
window.opener.postMessage({"close": "wellknown"}, LOCAL_DESTINATION.origin);
}
window.close();
return;
}
}
/**
* nacteni ceka tracker korespondence, muze trvat nekolik vterin, nez se nacte
*/
loadedCounter = 0;
initWhenLoaded = function () {
console.log("loaded?");
if ($("#correspondence > div > a").attr("href") !== undefined
&& $("td[abbr=uri]:first").length > 0
) {
console.log("launching controls");
Controls();
} else {
console.log("not loaded " + (loadedCounter++));
//console.log(($("#correspondence > div > a").attr("href")));
setTimeout(initWhenLoaded, 1000); //zpozdeni;
}
};
initWhenLoaded();
});
});
}
$(function () {
// vote for remote host maliciousness
$analysis_panel = $("#analysis-result-panel");
//$analysis_panel = $("<div/>", {id: "analysis"}).appendTo($analysis_panel);
$("#analysis-result-panel").on("change", VOTING_SELECTOR, function () {
console.log("VOTING CHANGE");
changeVote($(this), true);
})
// we can click on a domain from "related" list
$("#analysis-result-panel").on("click", RELATED_SELECTOR, function () {
if (typeof(launch_request) === "undefined") {
alert("Not implemented yet in MDM, only in MDMaug.");
return false;
}
let url = $(this).text();
let $a = $("#requests-panel .input-group .form-control a:contains({0})".format(url));
if ($a.length) { // we have this scan on the very page → navigate there
$a.closest(".input-group").find("button").click();
} else { // query for scan results
launch_request("/scan=" + url, url);
}
return false;
})
// click on another scan to go there
$("#analysis-result-panel").on("click", SCAN_SELECTOR, function () {
if (typeof(launch_request) === "undefined") {
alert("Not implemented yet in MDM, only in MDMaug.");
return false;
}
let domain = new URL($(this).closest(".analysis").find("> form > h2").text()).hostname;
let scan = $(this).attr("data-scan");
let url = domain + " " + scan;
let $a = $("#requests-panel .input-group .form-control a:contains({0})".format(url));
if ($a.length) { // we have this scan on the very page → navigate there
$a.closest(".input-group").find("button").click();
} else { // query for scan results
launch_request("/scan={0}/time={1}/".format(domain, scan), url);
}
})
// quickly browse results (if results are focused)
$('#analysis-result-panel').on("keydown", function (e) {
console.log('Line 554 start, e(): ', e);
//if (e.altKey) {
if (KEY.DOWN == e.keyCode) {
if ($(":focus").closest(".web").length) {
$("input:checked", $($(":focus").closest(".web")).next(".web")).focus();
} else {
$(".web input:checked:first").focus();
}
}