Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 419 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Encrypting smarty tpl module file in WHMCS

#1
I am trying to encrypt a tpl file with ionCube in my module in WHMCS without modifying WHMCS smarty.class file. Anyone have any idea how can I do that?

For further information see

[To see links please register here]

Reply

#2
You can encrypt the template files using the non-PHP file encryption feature, but the smarty engine needs to be modified in order to handle the decryption. Without doing so you will just see encrypted contents displayed. Use the ioncube_read_file() API function for this, which will seamlessly handle encrypted and non-encrypted files. Note that the file calling the function must be encoded as there would be no point in having an unprotected file calling a decryption routine.
Reply

#3
Of course you need to have ionCube Php Encoder, you need to create project, add files and then in GUI in `Project settings -> Source` you should right click on your TPL file and select "Encrypt non-PHP file". There is no way you can do it without applying Smarty patch as in ionCube documentation.

You can also extend Smarty class.

For **Smarty 2** the code will be simple:

<?php

class MyTemplate extends Smarty {

// Replacement function for _read_file() in Smarty.class.php to add support
// for reading both ionCube encrypted templates and plain text templates.
// Smarty.class.php must be encoded by the creator of the templates for
// ioncube_read_file() to decode encrypted template files

function _read_file($filename)
{
$res = false;

if (file_exists($filename)) {
if (function_exists('ioncube_read_file')) {
$res = ioncube_read_file($filename);
if (is_int($res)) $res = false;
}
else if ( ($fd = @fopen($filename, 'rb')) ) {
$res = ($size = filesize($filename)) ? fread($fd, $size) : '';
fclose($fd);
}
}

return $res;
}
}

and you should create object of this class to use modified code.


For **Smarty 3** it's a bit more complex.

You need to create `MyFileResource` class as below:


<?php
//MyFileResource.php

class MyFileResource extends Smarty_Internal_Resource_File {

/**
* Load template's source from file into current template object
*
* @param Smarty_Template_Source $source source object
* @return string template source
* @throws SmartyException if source cannot be loaded
*/
public function getContent(Smarty_Template_Source $source)
{
if ($source->timestamp) {

if (file_exists($source->filepath) && function_exists('ioncube_read_file')) {
$res = ioncube_read_file($source->filepath);
if (is_int($res)) {
$res = false;
}
return $res;
}
else {
return file_get_contents($source->filepath);
}
}

if ($source instanceof Smarty_Config_Source) {
throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
}
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
}

}

And in place where you created Smarty object add some code.

Assume you created Smarty object this way:

require '../libs/Smarty.class.php';

$smarty = new Smarty;

You should change it into:

require '../libs/Smarty.class.php';

require('MyFileResource.php');

$smarty = new Smarty;

$smarty->registerResource('file', new MyFileResource());



This way each time you read templates from files you use your MyFileResource class. I haven't tested this code but it should work. Depending on your settings it's possible you will need to remove all your compiled template files to regenerate them again.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through