unreliable data from XML to DHTML

Using XMLHttpRequest() to configure entire ToolBook pages.

unreliable data from XML to DHTML

Postby John Robin Dove » Mon Oct 21, 2019 6:56 am

Hi Clifton,
This latest problem has been driving me nuts for several days now! :x I am using an HTML/Javascript encryption system http://www.vincentcheung.ca/jsencryption/ to create security codes for my Médiacours exercise files. In my original VB.NET program I load this into a webBrowser object which is an embedded version of IE. I chose to create my codes this way so that they would be compatible with both versions of my program. There have never problems with the VB.NET version which I find surprising as it is pretty clunky! The HTML file is an invisible resource that I copy onto the disk when required. I then navigate to this local file in the webBrowser. VB.NET allows you to reference elements of the loaded html so I can manipulate the form invisibly to encrypt and decrypt. When I have finished I simply delete the HTML file to avoid anyone discovering how the system works.

I thought using this in the DHTML version would be easier as it uses HTML and javascript but no such luck so far. I have put this code in my "sharedActions" XML file.
Code: Select all
 <function name="createDistributionCode" event="" params="">
        <![CDATA[
        var mySchool = this.myArray[4];
        var exName = this.myArray[2];
        var A = tbfunction_pgExecuteRemote("response", "encryptMyText", mySchool + ",someKey");
        var codeKey;
          if (mySchool.length > 4)
          {
          var ADetail = [];
          ADetail = Array.from(mySchool);
          codeKey = ADetail[3] + ADetail[4] + ADetail[1] + ADetail[0] + ADetail[2];
          }
          else
          {
          codeKey = "anotherKey";
          }
        var B = tbfunction_pgExecuteRemote("response", "encryptMyText", exName + "," + codeKey);
          if (exName.length > 3)
          {
          codeKey = exName.substring(0, 4);
          }
          else
          {
          var BDetail = [];
          BDetail = Array.from(exName);
          codeKey = BDetail[0] + "N" + BDetail[0] + "a";
          }
        var C = tbfunction_pgExecuteRemote("response", "encryptMyText", exName + "," + codeKey);
        var returnValue = "***§" + A + "§" + B + "§" + C;
                                                                //Here returnValue is always incorrect as it contains line breaks!!
        returnValue = tbfunction_pgReplace("/^\s+|\s+$/", "", returnValue, true);
        returnValue = tbfunction_pgReplace("\n", "", returnValue, true);
        alert(returnValue);                                    //The value alerted here has always been correct!!
        tbfunction_pgTBObjSet("codeBar", "text", returnValue);  //This has sometimes worked but is not reliable!!
        // return returnValue This has never worked!!                   
        ]]>
    </function> 

The problem is getting the encypted strings from the XML function to the Toolbook part of the program intact. If I use return to send them they always arrive corrupted. There are spaces and characters missing which renders them useless. It's slightly better if I use pgTBObjectSet to put them into the text of a TB field but this is also unreliable. I have tried putting the 3 codes into an array but this fails. I have also tried writing the string to a cookie but the string is never written correctly. However if I use the alert in the code above to manually copy the code and paste it into the destination file it always works.
Here is a picture of what I get before the 2 pgReplace lines.

Image

And here is a picture of a correct result after the 2 pgReplace lines.

Image

Unfortunately even if I repeat the pgReplace lines in the subsequent TB actions sequence I rarely get the desired result although it must be said that from time to time it works!

What can I do to make sure the strings arrive intact so that I can write them into the file correctly? I'd be most grateful if you have any suggestions. Thanks for your time.
John
Last edited by John Robin Dove on Tue Oct 22, 2019 3:27 am, edited 1 time in total.
John Robin Dove
 
Posts: 484
Joined: Thu Jan 23, 2014 4:35 am

Re: unreliable data from XML to DHTML

Postby Clifton » Mon Oct 21, 2019 1:51 pm

Have you tried the PowerPac function pgStringEncrypt()?
My latest typing course uses this function to much of what you are doing with your application. I save encrypted strings as session cookies instead of disk cookies to prevent the browser from manipulating the encrypted results. You might want to try saving your strings in the session storage and see if that helps give you consistent results. I'm not surprised that putting encrypted strings in fields using pgTBObjSet() caused problems as backslashes often get interpreted as escape characters (e.g.: "\n" in a field will often result in a carriage return). The problem with normal document cookies is the "=" character will often mess with reading and writing the cookie. Session cookies on the other hand will just use the raw data and will be more reliable with encryption methods. When you view your encrypted string in a alert box, you are basically viewing the raw data so this tells me you may be benefited by using session storage. In the PowerPac, you access session storage using the same cookie functions. Just adjust the useSession parameter to the value "session".

You can try grab a trial version of the typing course here:
https://learntotype.today/app/

Once you have logged into your trial version, you can explore the session cookies with the developer tools in Firefox. At least this gives you a look at the level of encryption used in this application and perhaps something similar would work for you. In this application, the session key changes with every session so the encrypted strings can never be decrypted with the same key. This is probably overdesigned but I was interested in seeing how much encryption I could achieve. In a school setting where students are always trying to break something, this approach may end of being a good one.
Clifton
Site Admin
 
Posts: 731
Joined: Tue Jan 14, 2014 1:04 am

Re: unreliable data from XML to DHTML

Postby John Robin Dove » Tue Oct 22, 2019 5:43 am

Thanks for your reply. I use pgStringEncrypt() in other parts of my program but, as I attempted to explain previously, I don't think I can use it here because I want the 'exercise files' created to be compatible with both the online and the pc version of the program. Correct me if I'm wrong but I think pgStringEncrypt can only be used in a Toolbook DHTML and therefore can only function in a webserver environment. I could of course oblige the user to have online access but I would rather not as one of the advantages of my pc version is that it will function on old offline school networks of which there are many in France and elsewhere and is compatible with XP/Vista/7/8/10. There are still a surprising number of XP systems around.

I tried to create an account for learntotype.today. I followed the instructions and received a three part code which I pasted in. After that 'Verifying account...' was displayed but then nothing else happened. :( Perhaps I did something wrong. One thing I noticed was that your form does not handle accented characters. I used Médiacours as the company name which contains é (ALT + 0233 on a pc keyboard). Could this account for the failure? If so, it might create similar problems for hispanic users.

Initially I thought that session storage had solved the problem but after several tests I found that it is also unreliable. I have a better idea of what is happening now. Certain characters cause problems. For example the + character is coverted to a space. If this were the only problem I could deal with it using pgReplace but I suspect there are sometimes other changes made. Often line breaks mysteriously appear but I have not yet discovered why.

Maybe I could write the encryption to a text file using XMLHttpRequest. I'll try this and let you know how I get on.
John Robin Dove
 
Posts: 484
Joined: Thu Jan 23, 2014 4:35 am

Re: unreliable data from XML to DHTML

Postby Clifton » Tue Oct 22, 2019 7:20 am

Thank you for the comments on the learntotype.today experience. Your online software account email seems to work fine, but I'll have to look into the other issues.

Thanks again!
 
Clifton
Site Admin
 
Posts: 731
Joined: Tue Jan 14, 2014 1:04 am

Re: unreliable data from XML to DHTML

Postby John Robin Dove » Tue Oct 22, 2019 10:51 am

Hi Clifton,

The learntotype.today worked fine when I tried to access it again this afternoon. The problem would seem to have occurred only once immediately after I completed the inscription form.

My encryptions are written correctly to a text file using XMLHttpRequest but the data is still corrupted when I try to retrieve it whatever method I use. The problem is always the same: the + character becomes a space. Maybe I'll have to settle for just correcting it with pgReplace every time but I feel a bit uneasy about that in case there are other anomalies of a similar kind.
John Robin Dove
 
Posts: 484
Joined: Thu Jan 23, 2014 4:35 am

Re: unreliable data from XML to DHTML

Postby Clifton » Tue Oct 22, 2019 1:16 pm

Can you post a sample of what you are trying to encrypt?
Clifton
Site Admin
 
Posts: 731
Joined: Tue Jan 14, 2014 1:04 am

Re: unreliable data from XML to DHTML

Postby John Robin Dove » Wed Oct 23, 2019 5:25 am

Hi Clifton,
I spent the morning making a test app to send to you only to discover that it worked every time! :o It then dawned on me that the problem was caused only when the encryption was written to a file via PHP. I compared the test app with the main app and found that in the main app I had omitted one very important line: encodeURIComponent. So, the problem is now solved. :D But don't hold your breath there'll almost certainly be a new one to solve soon. Not too soon, I hope. :)
Thanks.
John
John Robin Dove
 
Posts: 484
Joined: Thu Jan 23, 2014 4:35 am

Re: unreliable data from XML to DHTML

Postby Clifton » Wed Oct 23, 2019 8:21 am

Well this is good news.
Sometimes I find that a sticky problem can be more easily diagnosed when I make a very small test case. It makes other factors stand out and this can sometimes help solve a problem.
 
Clifton
Site Admin
 
Posts: 731
Joined: Tue Jan 14, 2014 1:04 am


Return to XML Configurations – Plugin Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron