Commit db4c1e13 authored by Edvard Rejthar's avatar Edvard Rejthar

Merge branch 'master' of gitlab.labs.nic.cz:csirt/mdmaug

parents 3db7b09e fb6ebd63
{"name": "firefox_mdmaug_writer", "description": "Firefox disk writer", "path": "/opt/mdmaug/mdmaug/bin/firefox_mdmaug_writer.py", "type": "stdio", "allowed_extensions": [ "mdmaug@csirt.cz" ] }
{"name": "firefox_mdmaug_writer", "description": "Firefox disk writer", "path": "/opt/mdmaug/firefox_mdmaug_writer.py", "type": "stdio", "allowed_extensions": [ "mdmaug@csirt.cz" ] }
......@@ -32,6 +32,8 @@ echo " ***** Copying files into" $DESTINATION
mkdir $DESTINATION
cp -r mdmaug $DESTINATION
cp -r .mozilla $DESTINATION
cp misc/production.ini $DESTINATION
cp misc/firefox_mdmaug_writer.py $DESTINATION
cp *.md $DESTINATION
cd $DESTINATION
......
......@@ -10,20 +10,17 @@ Scans a website for a sign of a parasite hosts or commands.
4. Perform installation: ```/tmp/mdmaug/INSTALL```
5. Everything should be located in `/opt/mdmaug`.
6. For testing purposes, launch it under newly created `mdmaug` user: `su - mdmaug -c 'python3 -m mdmaug'`
7. Connect in the browser at: https://127.0.0.1:5000
8. Try analysing `https://127.0.0.1:5000/static/demopage.html` on local server
9. For deployment, configure nginx properly to be used with flask
7. Connect in the browser at: https://127.0.0.1:8000
8. Try analysing `https://127.0.0.1:8000/static/demopage.html` on local server
9. For deployment, configure nginx (`sudo apt install nginx`) properly to be used with flask:
* If you are using systemd you may want to copy `misc/mdmaug.service` to `/etc/systemd/system/` so that MDMaug runs after restart (or with `sudo service mdmaug start`)
* `misc/mdmaug.nginx` can be integrated to nginx `/etc/nginx/sites-available/` (& symlinked to `/etc/nginx/sites-enabled/`)
### Notes
* If you want other count of profiles than 21, change `./INSTALL` + `mdmaug/lib/config.py` + `.mozilla/firefox/profiles.ini`
* You may put ```03 1,7,13,19 * * * ~/mdmaug-launch``` in ```crontab -e``` of user mdmaug.
* We are using Python3.6+, Firefox 62.0
## Tips
* You may use /static/demopage.html as a testing page.
* You may launch MDMaug with environmental variable `PORT` to change the port the applicaction is bound to
* You may launch MDMaug with environmental variable `PORT` to change the port the application is bound to
### Troubleshooting
......@@ -32,8 +29,8 @@ Scans a website for a sign of a parasite hosts or commands.
#### Debugging session
I'm launching it like this:
`su - mdmaug -c 'export FLASK_APP=mdmaug.__main__:app && export PYTHONPATH=/opt/mdmaug/mdmaug && ./local/bin/flask run'`
* I'm launching it like this:: `su - mdmaug -c 'LC_ALL=C.UTF-8 FLASK_ENV=development FLASK_APP=mdmaug.__main__:app flask run -h 217.31.202.41 -p 8001`
* or `su - mdmaug -c 'PORT=8001 python3 -m mdmaug`
#### Wanna see what Firefox is really doing?
......@@ -42,4 +39,4 @@ I'm launching it like this:
* If no Firefox window appears try
* `xhost +local:mdmaug` if you're on the same machine
* `root@mdmaugmachine$xauth list` on remote root and `mdmaug$xauth add ...` display cookie
* When Firefox window appear, run MDMaug with `export FIREFOX_DEBUG=1`. Now, instead of virtual display your monitor should be used.
* When Firefox window appear, run MDMaug with `FIREFOX_DEBUG=1`. Now, instead of virtual display your monitor should be used.
#!/usr/bin/env python3
Works well but process requests one by one:
from http.server import HTTPServer, BaseHTTPRequestHandler
from socketserver import ThreadingMixIn
import threading
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
message = threading.currentThread().getName()
self.wfile.write(message)
self.wfile.write('\n')
return
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
"""Handle requests in a separate thread."""
if __name__ == '__main__':
server = ThreadedHTTPServer(('localhost', 80), Handler)
print('Starting server, use <Ctrl-C> to stop')
server.serve_forever()
exit()
from http.server import HTTPServer, SimpleHTTPRequestHandler
class Server(SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write("MDMaug: dumb server used as a landing page for the browser extension. " \
"Because this needs to be loaded before any web page but needs a web page to be loaded.".encode("UTF-8"))
httpd = HTTPServer(('127.0.0.1', 80), Server)
# httpd.socket = ssl.wrap_socket(httpd.socket,
# server_side=True,
# certfile= Config.DIR + 'python.pem', # together private + cert, http://stackoverflow.com/questions/19705785/python-3-https-webserver
# ssl_version=ssl.PROTOCOL_TLSv1)
httpd.serve_forever()
Couldnt handle much requests at once
##!/usr/bin/env bash
#while true; do { echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\nMDMaug: dumb server used as a landing page for the browser extension. Because this needs to be loaded before any web page but needs a web page to be loaded." | nc -vl 80; } done
\ No newline at end of file
# XX shouldnt I delete this file?
su - mdmaug -c 'cd /home/mdmaug/mdmaug/ ; python3 mdmaug.py'
pkill python3 #pri Ctrl+C v prikazu su se uzavre jen terminal, ale ne uz python skript. Takhle to zas zabije veskery Python, ale sandboxovy-zavirovany uzivatel mdmaug stejne ma byt jen na spousteni tohohle skriptu.
\ No newline at end of file
......@@ -24,9 +24,9 @@ class Config:
profile_count = 21 # number of Firefox profiles. Its name is just a number – 0,1...
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" # CHANGE HERE IF NOT RUN ON LOCALHOST
APP_HOST = f'http://{APP_IP}:{APP_PORT}' # YOU MAY NEED TO CHANGE **https**
APP_PORT = 8000
APP_IP = "217.31.202.41" # "127.0.0.1" # CHANGE HERE IF NOT RUN ON LOCALHOST
APP_HOST = f'https://{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",
......@@ -37,10 +37,11 @@ class Config:
lock = threading.RLock()
THUMBNAIL_SIZE = 640, 640
MAX_WHOIS_DOMAIN_THREADS = 10 # spusti maximalne 10 threadu doraz, jednou mi to totiz preteklo (kazda domena spusti jeste tolik threadu, kolik ma IP, ale tech byva jen par)
MAX_BROWSER_RUN_TIME = 25 # maximum time for a browser to run
MAX_BROWSER_RUN_TIME = 45 # maximum time for a browser to run
MAX_BROWSER_EXPIRATION = 15 # seconds that we wait before killing the browser (waiting for the files to be written)
EXPORT_NOTBLOCK_TLD = ".cz" # lowercase; this TLD is ignored in the export
CRAWL_FILE = "analysis.json"
SCREENSHOT_FILE = "screenshot.base64"
@staticmethod
def connect():
......
......@@ -18,7 +18,6 @@ from ..parser.spy_parser import SpyParser
logger = logging.getLogger("mdmaug")
# from yaml import load, dump
class Crawl(defaultdict):
""" Analysis results data model"""
......
......@@ -12,7 +12,7 @@ class ScreenshotParser:
def __init__(self, crawl):
screenfile = crawl.cache_dir+'screenshot.base64'
screenfile = crawl.cache_dir + Config.SCREENSHOT_FILE
if os.path.isfile(screenfile):
with open(screenfile, "r+") as f:
data = (b64decode(f.read()))
......@@ -26,4 +26,5 @@ class ScreenshotParser:
f.write(b64encode(data.getvalue()).decode("utf-8"))
f.truncate()
#"<img class='thumbnail' src='data:image/png;base64,{}' />".format(b64encode(data.getvalue()).decode("utf-8"))
crawl.screenfile = screenfile
os.rename(screenfile, crawl.cache_dir + Config.SCREENSHOT_FILE)
crawl.screenfile = 1 # screenfile
......@@ -49,7 +49,9 @@ class TrafficLogParser:
continue
# logger.debug(Domains.url2domain(url), Domains.url2path(url), path)
crawl[url2domain(url)].urls[url2path(url)].sourcefiles.append(path)
o = crawl[url2domain(url)].urls[url2path(url)]
if f.readline() != "": # some content has been fetched
o.sourcefiles.append(path)
@staticmethod
def nicify_file(sourcefile):
......
#!/bin/bash
# This file may be launched by CRON. 03 1,7,13,19 * * * ~/mdmaug/mdmaug-launch
echo "mdmaug-launch start" >> ~/log.log
pkill -f mdmaug.py
pkill -f Xvfb
export PYTHONPATH=$PYTHONPATH:/opt/mdmaug/mdmaug/
cd /opt/mdmaug/mdmaug && ./mdmaug.py 2>&1 | /usr/bin/logger -t mdmaugtag
whoami >> ~/log.log
\ No newline at end of file
......@@ -14,7 +14,7 @@ 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";
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>
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;
......@@ -79,7 +79,6 @@ changeVote = function ($radio, propagate) {
};
$(function () {
// vote for remote host maliciousness
$analysis_panel = $("#analysis-result-panel");
......@@ -91,8 +90,8 @@ $(function () {
// 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.");
if (typeof (launch_request) === "undefined") {
alert("Seeing older analyses not implemented yet in MDM, only in MDMaug:" + APP_HOST);
return false;
}
let url = $(this).text();
......@@ -107,8 +106,8 @@ $(function () {
// 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.");
if (typeof (launch_request) === "undefined") {
alert("Not implemented yet in MDM, only in MDMaug: " + APP_HOST);
return false;
}
let domain = new URL($(this).closest(".analysis").find("> form > h2").text()).hostname;
......@@ -190,137 +189,84 @@ if (document.location.href.indexOf("/detail/") !== -1) { // ex: https://mdm.nic.
*/
//$("<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 () {
alert("Not yet implemented in MDM. Go to MDMaug page: " + APP_HOST);
//cache.reanalyze();
}).hide();
//listener analyzy - analyze keyword
window.addEventListener("message", function (e) {
//prevzit vysledky | e.data ve formatu: <div class=web><div class=domain>jedinecna domena</div></div>
console.log("event", e);
if (e.data.analyze) {//jedna se o zpravu pro me
// dat vedet uzivateli
$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");
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("/");
for (var i = 0; i < 4; i++) {
path.shift();
}
analysisHost = path.join("/");
//vypis analyzy
$reanalyzeButton = $("<button>reanalyze</button>").appendTo($analysis_panel).click(function () {
Analysis.analyze($("td[abbr=uri]:first a").text(), true);
//alert("Not yet implemented in MDM. Go to MDMaug page: " + APP_HOST);
$(this).hide();
}).hide();
//listener analyzy - analyze keyword
window.addEventListener("message", function (e) {
//prevzit vysledky | e.data ve formatu: <div class=web><div class=domain>jedinecna domena</div></div>
console.log("event", e);
if (e.data.analyze) {//jedna se o zpravu pro me
// dat vedet uzivateli
$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");
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("/");
for (var i = 0; i < 4; i++) {
path.shift();
}
//<iframe width='10px' height='10px' src='" + APP_HOST + "/api/analyze" + (typeof forceServer === 'undefined' ? "=cached" : "") + "/" + url + "'></iframe>
//cache.add(analysisHost, e.data.analyze);
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);
}
// add the safebrowsing icon to the main page header
$("body h1:eq(0)").append($("> .safebrowsing-status:eq(0)", $analysis_panel));
// help text
$("#advice").remove();
$("<p/>", {
id: "advice",
"text": "Když je to ! nebo wp a stránka není sundaná a ještě nemáme korespondenci, dát poslat."
}).insertAfter($("body h1:eq(0)"));
// add the safebrowsing icon to the main page header
$("body h1:eq(0)").append($("> .safebrowsing-status:eq(0)", $analysis_panel));
// help text
$("#advice").remove();
$("<p/>", {
id: "advice",
"text": "Když je to ! nebo wp a stránka není sundaná a ještě nemáme korespondenci, dát poslat."
}).insertAfter($("body h1:eq(0)"));
let seen = new Set()
$(".web", $analysis_panel).each(function () {
let host = $.trim($(".domain", this).text());
if (!seen.has(host)) {
seen.add(host)
} else { // this web has been seen again, this is the old result
$(this).remove();
}
});
// 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: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
}
});
let seen = new Set()
$(".web", $analysis_panel).each(function () {
let host = $.trim($(".domain", this).text());
if (!seen.has(host)) {
seen.add(host)
} else { // this web has been seen again, this is the old result
$(this).remove();
}
});
// 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: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
}
});
Analysis = function () {
/**
* Analyzovat s pomoci MDM-aug stroje.
* Analyze with MDMaug
* This method is called from mdm/static/script.js
* @param {type} url
* @param {bool} forceServer -> Nepovinny parametr. True, pokud se ma analyza provest znova.
* @returns {undefined}
* @param {bool} forceServer -> Force refresh
*/
analyze = function (url, forceServer) {
//if ((str = cache.get(url)) === null) {
//analyza: ziskat linkovane stranky z MDM-aug stroje.
analyze = function (url, forceServer = false) {
$("#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();
// }
$("#content").before("<iframe width='10px' height='10px' src='" + APP_HOST + "/destination=" + LOCAL_DESTINATION.hostname + "/api/analyze" + (forceServer ? "" : "=cached") + "/" + url + "'></iframe>");
$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
//
// };
//
// }();
return {analyze: analyze};
}();
......
// ==UserScript==
// @name mdm list hrozeb - autoopen
// @namespace mdm
// @description Hromadne otevre napadené domény. Dá jim do hashe administrátorem zvolene příznaky, co s nimi dělat (poslat maily, analyzovat, telefonovat).
// @include https://mdm.nic.cz/list/open*
// @include https://mdm.nic.cz/list/new*
// @version 1
// @grant none
// ==/UserScript==
if (document.location.href.indexOf("https://mdm.nic.cz/list/") === 0) {
$ = j;
/**
* Statisticke ukazatele
*/
Stats = function () {
openingI = 0;
openI = 0;
closedI = 0;
refresh = function () {
$("#statistics #stats-opening").text("Opening " + openingI);
$("#statistics #stats-open").text(" / Open " + openI);
$("#statistics #stats-closed").text(" / Closed " + closedI);
};
tabCreated = function () {
$("#statistics").show();//pri prvnim popupu ukazeme statistiku
openingI++;
refresh();
};
tabClosed = function () {
openingI--;
closedI++;
refresh();
};
tabOpened = function () {
openingI--;
openI++;
refresh();
};
init = function () {
//Statistika html
statistics = $("<div id=statistics />").insertBefore("h1").hide()
.append($("<span />", {id: "stats-opening"}).css({color: "blue"}))
.append($("<span />", {id: "stats-open"}).css({color: "green"}))
.append($("<span />", {id: "stats-closed"}).css({color: "red"}));
/**
* Listener informaci z otevrenych popupu.
*/
window.addEventListener("message", function (e) {
console.log(e);
//cross-site security
if (e.origin !== "https://mdm.nic.cz") {
console.log("wrong origin");
return;
}
if (e.data.close !== undefined) {//tab se zavira
tabClosed();
e.source.close();
return;
}
if (e.data.open !== undefined) {//tab zustal uspesne otevren
tabOpened();
return;
}
}, false);
};
return {
init: init,
tabOpened: tabOpened,
tabClosed: tabClosed,
tabCreated: tabCreated
};
}();
Autoopen = function () {
popupList = [];
/**
* Statisticke ukazatele
*/
Stats = function () {
openingI = 0;
openI = 0;
closedI = 0;
refresh = function () {
$("#statistics #stats-opening").text("Opening " + openingI);
$("#statistics #stats-open").text(" / Open " + openI);
$("#statistics #stats-closed").text(" / Closed " + closedI);
};
tabCreated = function () {
$("#statistics").show();//pri prvnim popupu ukazeme statistiku
openingI++;
refresh();
};
tabClosed = function () {
openingI--;
closedI++;
refresh();
};
tabOpened = function () {
openingI--;
openI++;
refresh();
};
init = function () {
//Statistika html
statistics = $("<div id=statistics />").insertBefore("h1").hide()
.append($("<span />", {id: "stats-opening"}).css({color: "blue"}))
.append($("<span />", {id: "stats-open"}).css({color: "green"}))
.append($("<span />", {id: "stats-closed"}).css({color: "red"}));
/**
* Akce odkazu - otevreni tabu, opatreneho hashFlagy.
* @returns {Boolean}
* Listener informaci z otevrenych popupu.
*/
linkClick = function () {
//Otevrit subtab
console.log("...click received");
popupList.push(window.open(this.href + getHashFlagsStr()));
window.focus();//subtab nema focus
Stats.tabCreated();//drzet prehled, kolik oken je otevrenych
window.addEventListener("message", function (e) {
console.log(e);
//cross-site security
if (e.origin !== "https://mdm.nic.cz") {
console.log("wrong origin");
return;
}
if (e.data.close !== undefined) {//tab se zavira
tabClosed();
e.source.close();
return;
}
if (e.data.open !== undefined) {//tab zustal uspesne otevren
tabOpened();
return;
}
}, false);
};
//, '_blank', 'toolbar=yes, scrollbars=yes, resizable=yes, width=1200');//j(this).click();//window.open(j(this).attr("href"), "", "menubar=yes");//abychom otevreli do noveho okna - width=1000: protoze dalsi podokna by byla zprehazena.
return false; //misto nasledovani odkazu jsme sli do subtabu
};
return {
init: init,
tabOpened: tabOpened,
tabClosed: tabClosed,
tabCreated: tabCreated
};
}();
Autoopen = function () {
popupList = [];
//Listener hlasovani
window.addEventListener("message", function (e) {
if (e.data.voted) {//v tabu se hlasovalo
for (i in popupList) {//preposlat hlasovani ostatnim tabum
popupList[i].postMessage({"voted": e.data.voted, "domain": e.data.domain}, "https://mdm.nic.cz");
}
}
});
/**
* Akce odkazu - otevreni tabu, opatreneho hashFlagy.
* @returns {Boolean}
*/
linkClick = function () {
//Otevrit subtab
console.log("...click received");
popupList.push(window.open(this.href + getHashFlagsStr()));
window.focus();//subtab nema focus
Stats.tabCreated();//drzet prehled, kolik oken je otevrenych
/**
* Vraci hash na zaklade voleb administratora v checkboxech.
* @returns {String} hash
*/
getHashFlagsStr = function () {
//Informovat subtab hashem o akcich, ktere chceme provezt
hash = [];
$("#options label input").each(function () {
if ($(this).prop('checked')) {
hash.push($(this).attr("name"));
}
});
//, '_blank', 'toolbar=yes, scrollbars=yes, resizable=yes, width=1200');//j(this).click();//window.open(j(this).attr("href"), "", "menubar=yes");//abychom otevreli do noveho okna - width=1000: protoze dalsi podokna by byla zprehazena.
return false; //misto nasledovani odkazu jsme sli do subtabu
};
return "#" + hash.join("&");
};
//Listener hlasovani
window.addEventListener("message", function (e) {
if (e.data.voted) {//v tabu se hlasovalo
for (i in popupList) {//preposlat hlasovani ostatnim tabum
popupList[i].postMessage({"voted": e.data.voted, "domain": e.data.domain}, "https://mdm.nic.cz");
}
}
});
/**
* Vraci hash na zaklade voleb administratora v checkboxech.
* @returns {String} hash
*/
getHashFlagsStr = function () {
//Informovat subtab hashem o akcich, ktere chceme provezt
hash = [];
$("#options label input").each(function () {
if ($(this).prop('checked')) {
hash.push($(this).attr("name"));
}
});
return "#" + hash.join("&");
};
//Spousteci tlacitko + limit
launchButton = j("<button>launch</button>").insertBefore(j("h1")).click(function () {//otevre jen zpravy
$(thisRef = this).text("...");
console.log("launch button click");
limit = $("#limit").val();//99;//maximalni pocet navstivenych linku - otevrenych podoken
j("#flexigrid_threats td[abbr=host] a").each(function () {
if (limit-- < 1) {
return;
}
console.log("click...");
$(this).unbind().click(linkClick).click();//musim mit jistotu, ze se flexigrid nerefreshnul, obnovuju tak svou modifikaci kliku
});
//za vterinu obnovit text na tlacitku (pri 15+ tabech oteviranych naraz muze FF chvili vypadat, ze se nekliklo)
setTimeout(function () {
$(thisRef).text("launch");
}, 5000);
}).after(
$("<label>Limit:</label>").append(
$("<input/>", {id: "limit", val: 50}).css("width", "30px").attr({alt: "Maximální počet otevřených oken"}))
);
launchButton = j("<button>launch</button>").insertBefore(j("h1")).click(function () {//otevre jen zpravy
$(thisRef = this).text("...");
console.log("launch button click");
limit = $("#limit").val();//99;//maximalni pocet navstivenych linku - otevrenych podoken
j("#flexigrid_threats td[abbr=host] a").each(function () {
if (limit-- < 1) {
return;
}
console.log("click...");
$(this).unbind().click(linkClick).click();//musim mit jistotu, ze se flexigrid nerefreshnul, obnovuju tak svou modifikaci kliku
});
//za vterinu obnovit text na tlacitku (pri 15+ tabech oteviranych naraz muze FF chvili vypadat, ze se nekliklo)
setTimeout(function () {
$(thisRef).text("launch");
}, 5000);
}).after(
$("<label>Limit:</label>").append(
$("<input/>", {id: "limit", val: 50}).css("width", "30px").attr({alt: "Maximální počet otevřených oken"}))
);
//Otevirat linky do podoken
$("#flexigrid_threats td[abbr=host] a").unbind().click(linkClick);//soucasne nacetle linky
$(".flexigrid").click(function () {//linky, ktere se do flexigridu nactou v budoucnu
$("#flexigrid_threats td[abbr=host] a").unbind().click(linkClick);
});
$("#flexigrid_threats td[abbr=host] a").unbind().click(linkClick);//soucasne nacetle linky
$(".flexigrid").click(function () {//linky, ktere se do flexigridu nactou v budoucnu
$("#flexigrid_threats td[abbr=host] a").unbind().click(linkClick);
});