I'm running into situations where, at seemingly random instances, we are getting an "FATAL ERROR: - invalid encryption!" for XML that is being encrypted on-the-fly leveraging the "-out=stdout" parameter with krpanotools -encrypt.
When I say random, I mean a user will run into this error on a particular scene, reload the tour, go back to the same exact scene, and all is good. If the error was present each time a user went to the scene, then there would be an issue with my XML generation.
Here is a link to a tour on our "preview" domain with the full-encryption code in-place where I can confirm users have run into this issue.
https://www.createvtour.com/mammoth-mountain
I personally have not run into this in my testing, but one user running into this is one too many.
When I say encrypting on-the-fly, I mean leveraging PHP to handle the encrypting of XML at time of request/load.
My sequence goes like this:
- The xml is generated & loaded into the output-buffer
- Krpanotools is registered ( ensuring it is registered ).
- If registration is successful we proceed, else we output the buffer and exit, basically rendering unencrypted XML.
- If we are successful with putting the output-buffer into a temporary xml file, we proceed, else we output the buffer and exit, basically rendering unencrypted XML.
- If we are successful with encryption, the encrypted XML is rendered and we remove the temporary XML file.
- The encrypted XML is loaded into the tour.
I'm assuming that when an encryption error happens, in my case, the unlink ( file delete ) does not occur. That is why I have several XML files in the directory the temporary XML files is placed.
I've run these files through XML validators ( multiple, to make sure that this is a valid test ) to check their integrity and they come out clean as a whistle.
I could put an encrypt-error handler in-place at step 5 ( above ) but I don't know what the
exact output/return, if any, would be in the case of an error.
Here is the code-block that handles this:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
ob_start();
include_once XP_LIBRARY . "xml/get_scene_xml.php";
$obContent = ob_get_contents();
ob_end_clean();
$reg_code = "my_reg_code";
$output = array();
$return_var = 0;
exec( KRTOOLS_PATH . ' register ' . $reg_code, $output, $return_var );
if ( !empty($output) && $output[1] == 'Code registered.' ) {
$my_filename = "scene_xml_";
if ( isset( $_COOKIE['sess_ref'] ) && !empty( $_COOKIE['sess_ref'] ) ) {
$my_filename .= $_COOKIE['sess_ref'];
} else {
$my_filename .= $tour_ID;
}
$my_filename .= ".xml";
if(file_put_contents( $my_filename, $obContent )){
$my_file_path = KRENC_PATH;
$my_file_path .= $my_filename;
$theoutput = system( KRTOOLS_PATH . ' encrypt -p -in=' . $my_file_path . ' -out=stdout' );
if ( $theoutput ) {
unlink( $my_filename );
};
} else {
echo $obContent;
};
} else {
echo $obContent;
};
exit();
|