2011-06-21 17:19:10 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder logger javascript file, $Date: 2011-05-27 22:24:17 +0100 (Fri, 27 May 2011) $, $Revision: 3374 $
|
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-06-21 17:19:10 +08:00
|
|
|
//
|
2020-12-25 04:32:23 +08:00
|
|
|
$j.ajaxSetup({timeout: AJAX_TIMEOUT});
|
|
|
|
var reportLogs = true;
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( !window.console ) {
|
|
|
|
window.console =
|
2011-06-21 17:19:10 +08:00
|
|
|
{
|
2019-01-19 23:32:40 +08:00
|
|
|
init: function() {},
|
|
|
|
log: function() {},
|
|
|
|
debug: function() {},
|
|
|
|
info: function() {},
|
|
|
|
warn: function() {},
|
|
|
|
error: function() {}
|
2011-06-21 17:19:10 +08:00
|
|
|
};
|
|
|
|
}
|
2020-12-25 04:32:23 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( !console.debug ) {
|
|
|
|
// IE8 has console but doesn't have console.debug so lets alias it.
|
|
|
|
console.debug = console.log;
|
|
|
|
}
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2020-12-25 04:32:23 +08:00
|
|
|
window.onerror = function(message, url, line) {
|
2020-12-25 04:59:27 +08:00
|
|
|
logReport("ERR", message, url, line);
|
|
|
|
};
|
2020-12-25 04:32:23 +08:00
|
|
|
|
|
|
|
window.addEventListener("securitypolicyviolation", function logCSP(evt) {
|
|
|
|
var level = evt.disposition == "enforce" ? "ERR" : "DBG";
|
|
|
|
var message = evt.blockedURI + " violated CSP " + evt.violatedDirective;
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2020-12-25 04:32:23 +08:00
|
|
|
if ( evt.sample ) message += " (Sample: " + evt.sample + ")";
|
|
|
|
logReport(level, message, evt.sourceFile, evt.lineNumber);
|
|
|
|
});
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
function logReport( level, message, file, line ) {
|
2020-12-25 04:32:23 +08:00
|
|
|
if ( !reportLogs ) return;
|
2011-06-21 17:19:10 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
/* eslint-disable no-caller */
|
2019-01-22 00:12:17 +08:00
|
|
|
if ( arguments && arguments.callee && arguments.callee.caller && arguments.callee.caller.caller && arguments.callee.caller.caller.name ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
message += ' - '+arguments.callee.caller.caller.name+'()';
|
|
|
|
}
|
2020-12-25 04:32:23 +08:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
view: 'request',
|
|
|
|
request: 'log',
|
|
|
|
task: 'create',
|
|
|
|
level: level,
|
|
|
|
message: encodeURIComponent(message),
|
2021-01-08 23:32:51 +08:00
|
|
|
browser: browserInfo()
|
2020-12-25 04:32:23 +08:00
|
|
|
};
|
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( file ) {
|
2020-12-25 04:32:23 +08:00
|
|
|
data.file = file;
|
2019-01-19 23:32:40 +08:00
|
|
|
} else if ( location.search ) {
|
|
|
|
//location.search is the querystring part, so ?blah=blah but there is almost never any value to this
|
2020-12-25 04:32:23 +08:00
|
|
|
data.file = location.search;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-12-25 04:32:23 +08:00
|
|
|
|
|
|
|
if ( line ) data.line = line;
|
|
|
|
|
2021-01-12 04:22:15 +08:00
|
|
|
$j.post(thisUrl, data, null, 'json');
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 23:14:46 +08:00
|
|
|
function Panic(message) {
|
|
|
|
console.error(message);
|
|
|
|
logReport("PNC", message);
|
|
|
|
alert("PANIC: "+message);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 23:14:46 +08:00
|
|
|
function Fatal(message) {
|
|
|
|
console.error(message);
|
2019-01-19 23:32:40 +08:00
|
|
|
logReport( "FAT", message );
|
|
|
|
alert( "FATAL: "+message );
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 23:14:46 +08:00
|
|
|
function Error(message) {
|
|
|
|
console.error(message);
|
|
|
|
logReport("ERR", message);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 23:14:46 +08:00
|
|
|
function Warning(message) {
|
|
|
|
console.warn(message);
|
|
|
|
logReport("WAR", message);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 23:14:46 +08:00
|
|
|
function Info(message) {
|
|
|
|
console.info(message);
|
|
|
|
logReport("INF", message);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 23:14:46 +08:00
|
|
|
function Debug(message) {
|
|
|
|
console.debug(message);
|
|
|
|
//logReport("DBG", message);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 23:14:46 +08:00
|
|
|
function Dump(value, label) {
|
2020-12-25 04:32:23 +08:00
|
|
|
if ( label ) console.debug(label+" => ");
|
2020-04-10 23:14:46 +08:00
|
|
|
console.debug(value);
|
2011-06-21 17:19:10 +08:00
|
|
|
}
|
2021-01-08 23:32:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
JQuery has deprecated its browser object. This function implements our own
|
|
|
|
browser object. It strikes a compromise between importing a full browser
|
|
|
|
detection js library and using the js navigator object in its umodified form.
|
2021-01-08 23:35:32 +08:00
|
|
|
|
|
|
|
This function derived from the following sample on stackoverflow:
|
|
|
|
https://stackoverflow.com/a/11219680
|
2021-01-08 23:32:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
function browserInfo() {
|
|
|
|
var browser = {};
|
|
|
|
var nAgt = navigator.userAgent;
|
2021-01-09 00:10:47 +08:00
|
|
|
var browserName = navigator.appName;
|
|
|
|
var fullVersion = ''+parseFloat(navigator.appVersion);
|
|
|
|
var majorVersion = parseInt(navigator.appVersion, 10);
|
|
|
|
var nameOffset;
|
|
|
|
var verOffset;
|
|
|
|
var ix;
|
2021-01-08 23:32:51 +08:00
|
|
|
|
|
|
|
// In Opera, the true version is after "Opera" or after "Version"
|
|
|
|
if ((verOffset=nAgt.indexOf("Opera")) != -1) {
|
2021-01-09 00:10:47 +08:00
|
|
|
browserName = "Opera";
|
|
|
|
fullVersion = nAgt.substring(verOffset+6);
|
|
|
|
if ((verOffset=nAgt.indexOf("Version")) != -1) {
|
|
|
|
fullVersion = nAgt.substring(verOffset+8);
|
|
|
|
}
|
2021-01-08 23:32:51 +08:00
|
|
|
// In MSIE, the true version is after "MSIE" in userAgent
|
2021-01-09 00:45:59 +08:00
|
|
|
} else if ((verOffset=nAgt.indexOf("MSIE")) != -1) {
|
2021-01-08 23:32:51 +08:00
|
|
|
browserName = "Microsoft Internet Explorer";
|
|
|
|
fullVersion = nAgt.substring(verOffset+5);
|
2021-01-09 00:42:45 +08:00
|
|
|
// In Chrome, the true version is after "Chrome"
|
2021-01-09 00:45:59 +08:00
|
|
|
} else if ((verOffset=nAgt.indexOf("Chrome")) != -1) {
|
2021-01-08 23:32:51 +08:00
|
|
|
browserName = "Chrome";
|
|
|
|
fullVersion = nAgt.substring(verOffset+7);
|
2021-01-09 00:42:45 +08:00
|
|
|
// In Safari, the true version is after "Safari" or after "Version"
|
2021-01-09 00:45:59 +08:00
|
|
|
} else if ((verOffset=nAgt.indexOf("Safari")) != -1) {
|
2021-01-08 23:32:51 +08:00
|
|
|
browserName = "Safari";
|
|
|
|
fullVersion = nAgt.substring(verOffset+7);
|
2021-01-09 00:10:47 +08:00
|
|
|
if ((verOffset=nAgt.indexOf("Version")) != -1) {
|
2021-01-08 23:32:51 +08:00
|
|
|
fullVersion = nAgt.substring(verOffset+8);
|
2021-01-09 00:10:47 +08:00
|
|
|
}
|
2021-01-09 00:42:45 +08:00
|
|
|
// In Firefox, the true version is after "Firefox"
|
2021-01-09 00:45:59 +08:00
|
|
|
} else if ((verOffset=nAgt.indexOf("Firefox")) != -1) {
|
2021-01-08 23:32:51 +08:00
|
|
|
browserName = "Firefox";
|
|
|
|
fullVersion = nAgt.substring(verOffset+8);
|
2021-01-09 00:42:45 +08:00
|
|
|
// In most other browsers, "name/version" is at the end of userAgent
|
2021-01-09 00:45:59 +08:00
|
|
|
} else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) {
|
2021-01-09 00:42:45 +08:00
|
|
|
browserName = nAgt.substring(nameOffset, verOffset);
|
2021-01-08 23:32:51 +08:00
|
|
|
fullVersion = nAgt.substring(verOffset+1);
|
|
|
|
if (browserName.toLowerCase()==browserName.toUpperCase()) {
|
|
|
|
browserName = navigator.appName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// trim the fullVersion string at semicolon/space if present
|
2021-01-09 00:10:47 +08:00
|
|
|
if ((ix=fullVersion.indexOf(";")) != -1) {
|
2021-01-09 00:42:45 +08:00
|
|
|
fullVersion=fullVersion.substring(0, ix);
|
2021-01-09 00:10:47 +08:00
|
|
|
}
|
|
|
|
if ((ix=fullVersion.indexOf(" ")) != -1) {
|
2021-01-09 00:42:45 +08:00
|
|
|
fullVersion=fullVersion.substring(0, ix);
|
2021-01-09 00:10:47 +08:00
|
|
|
}
|
2021-01-08 23:32:51 +08:00
|
|
|
|
2021-01-09 00:42:45 +08:00
|
|
|
var majorVersion = parseInt(''+fullVersion, 10);
|
2021-01-08 23:32:51 +08:00
|
|
|
if (isNaN(majorVersion)) {
|
2021-01-09 00:42:45 +08:00
|
|
|
fullVersion = ''+parseFloat(navigator.appVersion);
|
|
|
|
majorVersion = parseInt(navigator.appVersion, 10);
|
2021-01-08 23:32:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// OSName variable is set as follows:
|
|
|
|
// "Windows" for all versions of Windows
|
|
|
|
// "MacOS" for all versions of Macintosh OS
|
|
|
|
// "Linux" for all versions of Linux
|
2021-01-09 00:42:45 +08:00
|
|
|
// "UNIX" for all other UNIX flavors
|
2021-01-08 23:32:51 +08:00
|
|
|
// "Unknown OS" indicates failure to detect the OS
|
|
|
|
var OSName="Unknown OS";
|
|
|
|
if (navigator.appVersion.indexOf("Win") != -1) OSName="Windows";
|
|
|
|
if (navigator.appVersion.indexOf("Mac") != -1) OSName="MacOS";
|
|
|
|
if (navigator.appVersion.indexOf("X11") != -1) OSName="UNIX";
|
|
|
|
if (navigator.appVersion.indexOf("Linux") != -1) OSName="Linux";
|
|
|
|
|
|
|
|
browser.name = browserName;
|
|
|
|
browser.version = fullVersion;
|
|
|
|
browser.platform = OSName;
|
|
|
|
|
|
|
|
return browser;
|
|
|
|
}
|