Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Is Limesurvey able to detect the used device?

More
2 years 9 months ago - 2 years 9 months ago #233924 by Masalas
The superadmin now deactivated xss protection for testing purposes, but I still can't get it to work. I created a question type "multiple short texts", created 8 subquestions (named the first few after joffm's screenshot), switched to source code editor, pasted the code below, set condition to 0, switched on always hide. After saving the question, everything above
Code:
{QID}').hide();
is gone, and so is the trailing </script> line.

I tried activating/deactivating the // comment-command hiding the question, tried inserting or deleting or moving the duplicate }); -- all to no avail. I'm out of ideas.

Attached is an lsq (German installation).  

File Attachment:

File Name: limesurvey...7887.lsq
File Size:14.76 KB

Code:
<script type="text/javascript" charset="utf-8">
    /**
     * JavaScript Client Detection
     * (C) viazenetti GmbH (Christian Ludwig)
     */
    (function (window) {
        {
            var unknown = '-';
 
            // screen
            var screenSize = '';
            if (screen.width) {
                width = (screen.width) ? screen.width : '';
                height = (screen.height) ? screen.height : '';
                screenSize += '' + width + " x " + height;
            }
var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var vph = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
            // browser
            var nVer = navigator.appVersion;
            var nAgt = navigator.userAgent;
            var browser = navigator.appName;
            var version = '' + parseFloat(navigator.appVersion);
            var majorVersion = parseInt(navigator.appVersion, 10);
            var nameOffset, verOffset, ix;
 
            // Opera
            if ((verOffset = nAgt.indexOf('Opera')) != -1) {
                browser = 'Opera';
                version = nAgt.substring(verOffset + 6);
                if ((verOffset = nAgt.indexOf('Version')) != -1) {
                    version = nAgt.substring(verOffset + 8);
                }
            }
            // Opera Next
            if ((verOffset = nAgt.indexOf('OPR')) != -1) {
                browser = 'Opera';
                version = nAgt.substring(verOffset + 4);
            }
            // MSIE
            else if ((verOffset = nAgt.indexOf('MSIE')) != -1) {
                browser = 'Microsoft Internet Explorer';
                version = nAgt.substring(verOffset + 5);
            }
            // Chrome
            else if ((verOffset = nAgt.indexOf('Chrome')) != -1) {
                browser = 'Chrome';
                version = nAgt.substring(verOffset + 7);
            }
            // Safari
            else if ((verOffset = nAgt.indexOf('Safari')) != -1) {
                browser = 'Safari';
                version = nAgt.substring(verOffset + 7);
                if ((verOffset = nAgt.indexOf('Version')) != -1) {
                    version = nAgt.substring(verOffset + 8);
                }
            }
            // Firefox
            else if ((verOffset = nAgt.indexOf('Firefox')) != -1) {
                browser = 'Firefox';
                version = nAgt.substring(verOffset + 8);
            }
            // MSIE 11+
            else if (nAgt.indexOf('Trident/') != -1) {
                browser = 'Microsoft Internet Explorer';
                version = nAgt.substring(nAgt.indexOf('rv:') + 3);
            }
            // Other browsers
            else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
                browser = nAgt.substring(nameOffset, verOffset);
                version = nAgt.substring(verOffset + 1);
                if (browser.toLowerCase() == browser.toUpperCase()) {
                    browser = navigator.appName;
                }
            }
            // trim the version string
            if ((ix = version.indexOf(';')) != -1) version = version.substring(0, ix);
            if ((ix = version.indexOf(' ')) != -1) version = version.substring(0, ix);
            if ((ix = version.indexOf(')')) != -1) version = version.substring(0, ix);
 
            majorVersion = parseInt('' + version, 10);
            if (isNaN(majorVersion)) {
                version = '' + parseFloat(navigator.appVersion);
                majorVersion = parseInt(navigator.appVersion, 10);
            }
 
            // mobile version
            var mobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(nVer);
 
            // cookie
            var cookieEnabled = (navigator.cookieEnabled) ? true : false;
 
            if (typeof navigator.cookieEnabled == 'undefined' &amp;&amp; !cookieEnabled) {
                document.cookie = 'testcookie';
                cookieEnabled = (document.cookie.indexOf('testcookie') != -1) ? true : false;
            }
 
            // system
            var os = unknown;
            var clientStrings = [
                { s:'Windows 10', r:/(Windows 10.0|Windows NT 10.0)/ },
                { s:'Windows 8.1', r:/(Windows 8.1|Windows NT 6.3)/ },
                { s:'Windows 8', r:/(Windows 8|Windows NT 6.2)/ },
                { s:'Windows 7', r:/(Windows 7|Windows NT 6.1)/ },
                { s:'Windows Vista', r:/Windows NT 6.0/ },
                { s:'Windows Server 2003', r:/Windows NT 5.2/ },
                { s:'Windows XP', r:/(Windows NT 5.1|Windows XP)/ },
                { s:'Windows 2000', r:/(Windows NT 5.0|Windows 2000)/ },
                { s:'Windows ME', r:/(Win 9x 4.90|Windows ME)/ },
                { s:'Windows 98', r:/(Windows 98|Win98)/ },
                { s:'Windows 95', r:/(Windows 95|Win95|Windows_95)/ },
                { s:'Windows NT 4.0', r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/ },
                { s:'Windows CE', r:/Windows CE/ },
                { s:'Windows 3.11', r:/Win16/ },
                { s:'Android', r:/Android/ },
                { s:'Open BSD', r:/OpenBSD/ },
                { s:'Sun OS', r:/SunOS/ },
                { s:'Linux', r:/(Linux|X11)/ },
                { s:'iOS', r:/(iPhone|iPad|iPod)/ },
                { s:'Mac OS X', r:/Mac OS X/ },
                { s:'Mac OS', r:/(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
                { s:'QNX', r:/QNX/ },
                { s:'UNIX', r:/UNIX/ },
                { s:'BeOS', r:/BeOS/ },
                { s:'OS/2', r:/OS\/2/ },
                { s:'Search Bot', r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ }
            ];
            for (var id in clientStrings) {
                var cs = clientStrings[id];
                if (cs.r.test(nAgt)) {
                    os = cs.s;
                    break;
                }
            }
 
            var osVersion = unknown;
 
            if (/Windows/.test(os)) {
                osVersion = /Windows (.*)/.exec(os)[1];
                os = 'Windows';
            }
 
            switch (os) {
                case 'Mac OS X':
                    osVersion = /Mac OS X (10[\.\_\d]+)/.exec(nAgt)[1];
                    break;
 
                case 'Android':
                    osVersion = /Android ([\.\_\d]+)/.exec(nAgt)[1];
                    break;
 
                case 'iOS':
                    osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
                    osVersion = osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0);
                    break;
            }
 
            // flash (you'll need to include swfobject)
            /* script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" */
            var flashVersion = 'no check';
            if (typeof swfobject != 'undefined') {
                var fv = swfobject.getFlashPlayerVersion();
                if (fv.major > 0) {
                    flashVersion = fv.major + '.' + fv.minor + ' r' + fv.release;
                }
                else  {
                    flashVersion = unknown;
                }
            }
        }
 
        window.jscd = {
            screen: screenSize,
            browser: browser,
            browserVersion: version,
            browserMajorVersion: majorVersion,
            mobile: mobile,
            os: os,
            osVersion: osVersion,
            cookies: cookieEnabled,
            flashVersion: flashVersion,
            vieww : vpw,
            viewh: vph
        };
    }(this));
 
 
$(document).ready(function() {    
 
        // Hide this question (remove double slash below to hide)
        $('#question{QID}').hide();
 
var thisQuestion = $('#question{QID}');
// Fill the array
       $('input[type=text]:eq(0)', thisQuestion).val(jscd.os +' '+ jscd.osVersion);
       $('input[type=text]:eq(1)', thisQuestion).val(jscd.browser +' '+ jscd.browserMajorVersion +
          ' (' + jscd.browserVersion + ')' );
       $('input[type=text]:eq(2)', thisQuestion).val( jscd.vieww );
       $('input[type=text]:eq(3)', thisQuestion).val( jscd.viewh );
    });
    });
</script>
Last edit: 2 years 9 months ago by Masalas. Reason: added script code

Please Log in to join the conversation.

More
2 years 9 months ago #233931 by holch
No LSQ or LSG, only LSS files. Help us to help you by making life easier for us.

switched on always hide


If you switch on "always hide" for the question via the GUI, Javascript can't access the question to write it. If you use Javascript, the questions involved (where the code is and where the script should write data to) need to be hidden via Javascript or CSS.

Because the GUI hides the question completely from the HTML code and thus Javascript can't use the question or can't run, because it was never rendered/there.

Anyway, hiding the questions is also something you do once everything is tested thoroughly.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

More
2 years 9 months ago #233932 by Joffm
Some first remarks:
1. And most important:
a. DO NOT HIDE the question by "Diese Frage immer verstecken".
b. DO NOT EXCLUDE it by a relevance equation "0"

Either use this line in the script
$('#question{QID}').hide();
Or hide the question with the css class "hidden"

2. At the end of the script there is a surplus });
    });
    });
</script>
Remove it.
Was ist a copy/paste mistake?
Thank god it is not in the sample file of the Tutorial.


Okay, this all does not solve your general javascript problem.
Does the small javascript test work?

As I get the same - your - result for an admin with XSS filter ON.
So double check this setting.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
2 years 9 months ago #233937 by Masalas
So, the major issue seemed to be that "Disable question script for XSS restricted user" also had to be deactivated although the manual says otherwise (" If you disable XSS protection : then this settings are not used. " Not sure whether this is a bug in this particular version or still like this.

Anyway, the question still doesn't write anything to the answers table, despite condition==1 and "always hide" being off. Will upload an lss later tonight. Thank you and Thank you in advance!

Please Log in to join the conversation.

More
2 years 9 months ago #233938 by Joffm

Anyway, the question still doesn't write anything to the answers table, despite condition==1 and "always hide" being off. Will upload an lss later tonight.

Of course, not.
At first you have to solve the script problem. As long as the script doesn't work, you will get not results.

My remarks were "on top". It wouldn't have worked, as@holch also mentioned with these settings as in this case the whole question is not available in the DOM.
But if the script is not removed by the filter you won't see the messy script in your question text.

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
2 years 9 months ago - 2 years 9 months ago #233944 by Masalas
Although I'm afraid I can't quite follow you, Joffm*, it now works correctly after logging out, back in again and pasting the script once more.
*All scripting for regular users had already been allowed in the superadmin panel at the time of my last post; the script had also already been correctly displayed in the question sourcecode window after saving the question; and the question had already been unhidden via GUI (German: "Diese Frage immer verstecken" ist aus und die "Bedingung" in den allgemeinen Einstellungen ist "1"). The duplicate }); had also been gone. It really seemed to be an issue of logging out and in again once more after the option "disable question script for xss restricted users" had been turned off.


For all who might read this in the future and are LimeSurvey/script beginners like I am, here are my takeaways:
  1. Allowing (disabling) "Filter HTML for XSS" in the global settings/Security is not enough. At least for LimeSurvey 5.2.7, superadmin needs to additionally allow (disable) "Disable question script for XSS restricted user" -- although the manual explicitly says otherwise.
  2. As is noted in the postings above, you have to activate sourcecode view in the question editor before pasting the code.
  3. As holch and Joffm noted, you must not hide the question via any other means than deleting // where it is written in the code (right before $('#question{QID}').hide(); ). And you most probably do want to hide the question.

    The following bulletin points are for users only who want to use the "multiple short text" question type:
  4. Where Joffm explains what to replace in order to use the script in a multiple short text question, he accidently did not include the last }); in the part that has to be deleted but then included this in the part that has to be added. In order for the script to work, it has to be there exactly once.
  5. Joffm in his code omitted several of the properties that the original script displays. Adding them back again is easy, though: just look a few lines above Joffm's code snippet where all properties are listed (screensize, browser, version, majorVersion, etc.) and add corresponding lines in Joffm's code. You can use my script below for added screen resolution, mobile status and full user agent (cookies status is not yet in there, and neither is flash, for obvious reasons).
  6. You need to create as many sub questions as you have properties. For my example below, it's 7 subquestions. It doesn't matter how you label them but it may be helpful to name them after what they assess. The script doesn't do that for you.

Cheers all.



Code:
<script type="text/javascript" charset="utf-8">
    /**
     * JavaScript Client Detection
     * (C) viazenetti GmbH (Christian Ludwig)
     */
    (function (window) {
        {
            var unknown = '-';
 
            // screen
            var screenSize = '';
            if (screen.width) {
                width = (screen.width) ? screen.width : '';
                height = (screen.height) ? screen.height : '';
                screenSize += '' + width + " x " + height;
            }
var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var vph = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
            // browser
            var nVer = navigator.appVersion;
            var nAgt = navigator.userAgent;
            var browser = navigator.appName;
            var version = '' + parseFloat(navigator.appVersion);
            var majorVersion = parseInt(navigator.appVersion, 10);
            var nameOffset, verOffset, ix;
 
            // Opera
            if ((verOffset = nAgt.indexOf('Opera')) != -1) {
                browser = 'Opera';
                version = nAgt.substring(verOffset + 6);
                if ((verOffset = nAgt.indexOf('Version')) != -1) {
                    version = nAgt.substring(verOffset + 8);
                }
            }
            // Opera Next
            if ((verOffset = nAgt.indexOf('OPR')) != -1) {
                browser = 'Opera';
                version = nAgt.substring(verOffset + 4);
            }
            // MSIE
            else if ((verOffset = nAgt.indexOf('MSIE')) != -1) {
                browser = 'Microsoft Internet Explorer';
                version = nAgt.substring(verOffset + 5);
            }
            // Chrome
            else if ((verOffset = nAgt.indexOf('Chrome')) != -1) {
                browser = 'Chrome';
                version = nAgt.substring(verOffset + 7);
            }
            // Safari
            else if ((verOffset = nAgt.indexOf('Safari')) != -1) {
                browser = 'Safari';
                version = nAgt.substring(verOffset + 7);
                if ((verOffset = nAgt.indexOf('Version')) != -1) {
                    version = nAgt.substring(verOffset + 8);
                }
            }
            // Firefox
            else if ((verOffset = nAgt.indexOf('Firefox')) != -1) {
                browser = 'Firefox';
                version = nAgt.substring(verOffset + 8);
            }
            // MSIE 11+
            else if (nAgt.indexOf('Trident/') != -1) {
                browser = 'Microsoft Internet Explorer';
                version = nAgt.substring(nAgt.indexOf('rv:') + 3);
            }
            // Other browsers
            else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
                browser = nAgt.substring(nameOffset, verOffset);
                version = nAgt.substring(verOffset + 1);
                if (browser.toLowerCase() == browser.toUpperCase()) {
                    browser = navigator.appName;
                }
            }
            // trim the version string
            if ((ix = version.indexOf(';')) != -1) version = version.substring(0, ix);
            if ((ix = version.indexOf(' ')) != -1) version = version.substring(0, ix);
            if ((ix = version.indexOf(')')) != -1) version = version.substring(0, ix);
 
            majorVersion = parseInt('' + version, 10);
            if (isNaN(majorVersion)) {
                version = '' + parseFloat(navigator.appVersion);
                majorVersion = parseInt(navigator.appVersion, 10);
            }
 
            // mobile version
            var mobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(nVer);
 
            // cookie
            var cookieEnabled = (navigator.cookieEnabled) ? true : false;
 
            if (typeof navigator.cookieEnabled == 'undefined' &amp;&amp; !cookieEnabled) {
                document.cookie = 'testcookie';
                cookieEnabled = (document.cookie.indexOf('testcookie') != -1) ? true : false;
            }
 
            // system
            var os = unknown;
            var clientStrings = [
                { s:'Windows 10', r:/(Windows 10.0|Windows NT 10.0)/ },
                { s:'Windows 8.1', r:/(Windows 8.1|Windows NT 6.3)/ },
                { s:'Windows 8', r:/(Windows 8|Windows NT 6.2)/ },
                { s:'Windows 7', r:/(Windows 7|Windows NT 6.1)/ },
                { s:'Windows Vista', r:/Windows NT 6.0/ },
                { s:'Windows Server 2003', r:/Windows NT 5.2/ },
                { s:'Windows XP', r:/(Windows NT 5.1|Windows XP)/ },
                { s:'Windows 2000', r:/(Windows NT 5.0|Windows 2000)/ },
                { s:'Windows ME', r:/(Win 9x 4.90|Windows ME)/ },
                { s:'Windows 98', r:/(Windows 98|Win98)/ },
                { s:'Windows 95', r:/(Windows 95|Win95|Windows_95)/ },
                { s:'Windows NT 4.0', r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/ },
                { s:'Windows CE', r:/Windows CE/ },
                { s:'Windows 3.11', r:/Win16/ },
                { s:'Android', r:/Android/ },
                { s:'Open BSD', r:/OpenBSD/ },
                { s:'Sun OS', r:/SunOS/ },
                { s:'Linux', r:/(Linux|X11)/ },
                { s:'iOS', r:/(iPhone|iPad|iPod)/ },
                { s:'Mac OS X', r:/Mac OS X/ },
                { s:'Mac OS', r:/(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
                { s:'QNX', r:/QNX/ },
                { s:'UNIX', r:/UNIX/ },
                { s:'BeOS', r:/BeOS/ },
                { s:'OS/2', r:/OS\/2/ },
                { s:'Search Bot', r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ }
            ];
            for (var id in clientStrings) {
                var cs = clientStrings[id];
                if (cs.r.test(nAgt)) {
                    os = cs.s;
                    break;
                }
            }
 
            var osVersion = unknown;
 
            if (/Windows/.test(os)) {
                osVersion = /Windows (.*)/.exec(os)[1];
                os = 'Windows';
            }
 
            switch (os) {
                case 'Mac OS X':
                    osVersion = /Mac OS X (10[\.\_\d]+)/.exec(nAgt)[1];
                    break;
 
                case 'Android':
                    osVersion = /Android ([\.\_\d]+)/.exec(nAgt)[1];
                    break;
 
                case 'iOS':
                    osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
                    osVersion = osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0);
                    break;
            }
 
            // flash (you'll need to include swfobject)
            /* script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" */
            var flashVersion = 'no check';
            if (typeof swfobject != 'undefined') {
                var fv = swfobject.getFlashPlayerVersion();
                if (fv.major > 0) {
                    flashVersion = fv.major + '.' + fv.minor + ' r' + fv.release;
                }
                else  {
                    flashVersion = unknown;
                }
            }
        }
 
        window.jscd = {
            screen: screenSize,
            browser: browser,
            browserVersion: version,
            browserMajorVersion: majorVersion,
            mobile: mobile,
            os: os,
            osVersion: osVersion,
            cookies: cookieEnabled,
            flashVersion: flashVersion,
            vieww : vpw,
            viewh: vph
        };
    }(this));
 
 
$(document).ready(function() {    
 
        // Hide this question (remove double slash below to hide)
         $('#question{QID}').hide();
 
var thisQuestion = $('#question{QID}');
// Fill the array
       $('input[type=text]:eq(0)', thisQuestion).val(jscd.os +' '+ jscd.osVersion);
       $('input[type=text]:eq(1)', thisQuestion).val(jscd.browser +' '+ jscd.browserMajorVersion +
          ' (' + jscd.browserVersion + ')' );
       $('input[type=text]:eq(2)', thisQuestion).val( jscd.vieww );
       $('input[type=text]:eq(3)', thisQuestion).val( jscd.viewh );
       $('input[type=text]:eq(4)', thisQuestion).val( jscd.screen );
       $('input[type=text]:eq(5)', thisQuestion).val( jscd.mobile );
       $('input[type=text]:eq(6)', thisQuestion).val( navigator.userAgent );
    });
</script>
Last edit: 2 years 9 months ago by Masalas.

Please Log in to join the conversation.

More
2 years 9 months ago #233952 by jelo

Allowing (disabling) "Filter HTML for XSS" in the global settings/Security is not enough. At least for LimeSurvey 5.2.7, superadmin needs to additionally allow (disable) "Disable question script for XSS restricted user" -- although the manual explicitly says otherwise.
 
The manual might not reflect the added feature. There was a time where there was only a global XSS on/off setting.

 

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

More
2 years 9 months ago - 2 years 9 months ago #233956 by Masalas
nope - the manual describes the added feature, but the switch in the gui seems to not do what the manual says it does (at least for LS 5.2.7).
Last edit: 2 years 9 months ago by Masalas.

Please Log in to join the conversation.

More
2 years 8 months ago #239182 by holch
@oriator: Happy Christmas! For being a bad boy and spamming the forum, Santa has just given you a forum ban for Christmas...

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose