Sie sind nicht angemeldet.

Lieber Besucher, herzlich willkommen bei: krpano.com Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.

1

Donnerstag, 17. März 2016, 14:38

how to protect JS file

Hi,

I feel stupid, but can't seem to encrypt a simple JS file. This file only has some js functions, being called from a button on the HTML page with the embed viewer.
Perhaps that's the reason, should this JS file comply with certain standards (like the template for plugins )?

It works perfectly without this encryption. Only necessary for HTML5.
I am using the 1.19-pr3 (tried also 1.18), have the licenses included, just plain encryption (no private) and also created the viewer files with the same version.

What am I doing wrong or not seeing, please?

If it's not possible, what other solution would I have to not publicly show these functions?

Thanks!

Tuur

Erleuchteter

Beiträge: 3 017

Wohnort: Netherlands

Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Nachricht senden

2

Donnerstag, 17. März 2016, 14:58

Hi,

did you use <!-- --> in your js file somewhere?
Don't!
use //

Hope it helps

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

3

Donnerstag, 17. März 2016, 15:42

Yep, I did. I will have a go at it straight away, will let you know.

Thanks Tuur!

4

Donnerstag, 17. März 2016, 16:08

Nope, that doesn't make a difference, still not working :-(

Cleaned of all comments, including the //
1. Tried with encrypted cleaned file: still no go.
2. Tried to compress clean file first with http://closure-compiler.appspot.com/home and then encrypt: nope, still no go..

What else could be missing?

5

Donnerstag, 17. März 2016, 16:29


6

Donnerstag, 17. März 2016, 16:37

Thanks for joining in Umalo, but no, unfortunately that doesn't change things either...
(btw, it's -h5 right?).

Any other suggestions?

First of all, it should be possible right? Just a simpel JS file with only a (couple of) functions?

7

Donnerstag, 17. März 2016, 17:21

BTW, I tried it with another JS file as well, same problem. Similar stuff, just a couple of functions.

Are there any other ways?
I am now trying an Obfuscator, but would rather encrypt it of course..

8

Donnerstag, 17. März 2016, 22:49

Tried cleaning up even further (replacing double quotes with single ones, etc.), but still no luck. Tried all settings for the encrypttool via commandline, as well as krpanotools32 and krpanotools64 (I am on a 64bit machine), but still to no avail.

I can't get it to work unfortunately...
Has anybody actually been able to encrypt JS files successfully?

Tuur

Erleuchteter

Beiträge: 3 017

Wohnort: Netherlands

Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Nachricht senden

9

Donnerstag, 17. März 2016, 23:55

yes i did
did you use the 'red iconed' Krpanotools encryption tool from the 19.pr3 package?
Maybe post your js file.. so we can see.

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

10

Freitag, 18. März 2016, 09:10

Hi Tuur, thanks again for following up, much appreciated!

Yes, I did use the 'red iconed' Krpanotools, as well as via commandline with krpanotools32 and krpanotools64 directly.

You asking me for the code got me thinking to go back to basics, as I just tested a very simple Hello World script. Even this didn't work!
So, I am either missing something in the JS file, or I am calling it the wrong way, or I need to include it in a different way.

This is what I have, which works as long it is not encrypted:
1. JS file, only 1 function:

Quellcode

1
2
3
4
function down_img()
{
   alert ("Hello World!");
}


2. include in HTML HEAD:

Quellcode

1
<script src="../js/script.js"></script>


3. calling via a button in vtourskin:

Quellcode

1
<layer name="skin_btn_img" style="skin_img|skin_tooltips" tooltip="JPG Snapshot" align="left" x="125" y="0" scale="0.5" onclick="js(down_img());" devices="html5" />

Tuur

Erleuchteter

Beiträge: 3 017

Wohnort: Netherlands

Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Nachricht senden

11

Freitag, 18. März 2016, 10:20

Try including the js file in the krpano xml instead of putting it in the index.html.
Then it will be read by krpano, and understands the encryption.
Not, sure but i think that is the problem.

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

12

Freitag, 18. März 2016, 13:20

Thanks Tuur, that sounds very logical. I will have a go at it as soon as possible and let you know..

Thanks!

Tuur

Erleuchteter

Beiträge: 3 017

Wohnort: Netherlands

Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Nachricht senden

13

Freitag, 18. März 2016, 14:19

Sorry.. that is probably not gonna work.

try to put the javascript in the xml, like:

Quellcode

1
2
3
4
5
<action name="test" type="Javascript" autorun="">
	<![CDATA[
		alert("Cheers from Holland");
	]]>
</action>



Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Tuur« (18. März 2016, 14:51)


14

Freitag, 18. März 2016, 15:49

Mmmm, I am afraid that's gonna be difficult. Just tested it and a simple alert does indeed work, but my original script already fails on the second line:

var mycanvas = $('div canvas:first-child').get(0);
try{ ...... etc

(the try{ is not understood)

I will probably need to rewrite the whole script to 'krpano-speak' ? Does it accept normal Javascript?
This script is not too difficult (I hope) to rearrange, but I have another one with all kinds of calculations which will be much more difficult if I need to rewrite that...

15

Freitag, 18. März 2016, 19:01

HANG ON! That's perfectly working!

I only had to remove a couple of 'return;' statements in the script, apparently those are not allowed. And to change 'function' by '<action etc.>' of course.

I am now going to try my big script with a lot of functions. Will let you know.

Still would like to know why I cannot encrypt the JS files though, even if it's only with 1 alert it won't work...

Thanks so far, you're a star!

16

Samstag, 19. März 2016, 14:23

Like I feared, stuck on the functions...

I can successfully call the following without a problem:

Quellcode

1
2
3
4
5
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
alert('cheers');
]]>
</action>


from a button with

Quellcode

1
onclick="down_img();"


I can also successfully pass an argument like so:

Quellcode

1
2
3
4
5
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
alert(args[1]);
]]>
</action>


with button:

Quellcode

1
onclick="down_img(cheers);"


BUT how do I pass on an argument/variable from action to action, which all contain JS scripts?

So with button:

Quellcode

1
onclick="down_img();"

And action1:

Quellcode

1
2
3
4
5
6
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
var poptext="cheers";
popup(poptext);
]]>
</action>


and action2:

Quellcode

1
2
3
4
5
<action name="popup" type="Javascript" autorun="">
<![CDATA[
alert(args[1]);
]]>
</action>


I tried all kinds of variations of calling and passing, like:
krpano.call popup(args[1]);
call popup(args[1]);
krpano.call actions.popup(args[1]);
js(popup(args[1]));
etc.

also, tried
%1
args[1]

But to no avail. Any clue what to do?

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »LMB« (19. März 2016, 14:40)


17

Sonntag, 20. März 2016, 16:24

Mmmm... I feel rather stupid. Or perhaps not, but after dreaming about functions, I think I realise now how to do it. At least, a small test confirmed my idea :-)

I don't need to put all original functions into actions of course. My main action just needs to include all those functions, in plain JS code.

So, in my example, this works:

button remains:

Quellcode

1
onclick="down_img();"


1 action in its shortest form, just to prove a point:

Quellcode

1
2
3
4
5
6
7
8
9
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
popup('cheers');

function popup(txt){
alert(txt);
}
]]>
</action>


I am happy again!

Of course, still would like to know 2 things, I hope Klaus can join in:
* why can I not encrypt JS files?
* how to pass on /arguments/variables from (JS-)action to (JS-)action?

Thanks again Tuur for keeping on the right track!

18

Montag, 21. März 2016, 13:02

still not there

Pfff... Spoke too soon... :-(

I still have a problem, and as far as I can tell, it's simply my lack of knowledge of the internal calls.

What I told before works, but only for a button inside the pano.
I actually have a button in the HTML page. Before I started fumbling around, I had the JS code inside the HTML working fine. Thát code I want to encrypt.
So at first I thought to put the code in a JS file and encrypt that. If I could that working, everything would be so easy. But I don't know how.
So, I put that code the JS-code inside an XML as 'type=javascript' and as long as I call that from a button within the pano, I am OK.

But how do I call that function from this button in the HTML? I tried simply calling the action, but since it is JS code it won't take it. Other things I tried:
js(actionfunction);
jscall(actionfunction);
krpano.call actionfunction();
etc.

What would be the syntax, please?

To reiterate what I have:
1.button in HTML:

Quellcode

1
<span id="Button" class="myButton" onclick="actionFunction();">buttontest</span>


2. XML:

Quellcode

1
2
3
4
5
<action name="actionFunction" type="Javascript" autorun="">
<![CDATA[
alert('hello');	
]]>
</action>

19

Montag, 21. März 2016, 17:31

Hi,

only krpano files (e.g. xml files or krpano html5 .js plugins) could be encrypted - these files will be loaded and decrypted by the krpano viewer and run inside krpano.

Any external .js files on .html webpage itself are outside of krpano and can't be encrypted - the browser alone wouldn't know that to do with such files.

If you want to call krpano actions from html, the JS-Interface need to be used:
http://krpano.com/docu/js/#top

e.g.
in the xml:

Quellcode

1
2
3
<action name="do_something">
...
</action>


in the html:

Quellcode

1
<span ... onclick="document.getElementById("krpanoSWFObject").call('do_something()');">...</span>



Or if you just want to project/encrypt your Javascript functions and then use them normally in the .html:
  1. make a Javascript action inside the xml
  2. set autorun="preinit"
  3. add all your functions to the 'window' object
E.g. in the (encrypted) xml:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
<action name="my_hidden_js_functions" type="Javascript" autorun="preinit"><![DATA[

window.do_something = function()
{
  ...
}

window.do_something_else = function()
{
  ...
}

]]></action>


and in the html (but only after krpano is loaded):

Quellcode

1
<span ... onclick="do_something();">...</span>


Best regards,
Klaus

20

Montag, 21. März 2016, 19:33

thanks Klaus!
It all makes sense.

I was halfway there, but still a bit guessing and stuck. Thank you so much!
And good to know I should not look further into encrypting external JS.

Since I am programming for HTML5 only, is there a simple example (other than that of the plugins template) of the JS plugin? And what makes it that a JS plugin can be encrypted, but an external JS not?

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »LMB« (21. März 2016, 21:12)