WHMCS smarty.class ファイルを変更せずに、WHMCS のモジュールでionCube を使用して tpl ファイルを暗号化しようとしています。どうすればそれができるか誰にも分かりますか?
詳細については、http://www.ioncube.com/sa_encoder.php?page=smarty_patchを参照してください。
WHMCS smarty.class ファイルを変更せずに、WHMCS のモジュールでionCube を使用して tpl ファイルを暗号化しようとしています。どうすればそれができるか誰にも分かりますか?
詳細については、http://www.ioncube.com/sa_encoder.php?page=smarty_patchを参照してください。
もちろん、ionCube Php Encoder が必要です。プロジェクトを作成し、ファイルを追加してから、GUI でProject settings -> Source
TPL ファイルを右クリックし、[Encrypt non-PHP file] を選択する必要があります。ionCube のドキュメントにあるように、Smarty パッチを適用せずにそれを行う方法はありません。
Smarty クラスを拡張することもできます。
Smarty 2の場合、コードは単純になります。
<?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;
}
}
変更されたコードを使用するには、このクラスのオブジェクトを作成する必要があります。
Smarty 3の場合は、もう少し複雑です。
MyFileResource
以下のようにクラスを作成する必要があります。
<?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}'");
}
}
Smarty オブジェクトを作成した場所にコードを追加します。
次の方法で Smarty オブジェクトを作成したとします。
require '../libs/Smarty.class.php';
$smarty = new Smarty;
次のように変更する必要があります。
require '../libs/Smarty.class.php';
require('MyFileResource.php');
$smarty = new Smarty;
$smarty->registerResource('file', new MyFileResource());
このように、ファイルからテンプレートを読み取るたびに、MyFileResource クラスを使用します。このコードはテストしていませんが、動作するはずです。設定によっては、コンパイル済みのすべてのテンプレート ファイルを削除して再生成する必要がある場合があります。
PHP 以外のファイル暗号化機能を使用してテンプレート ファイルを暗号化できますが、復号化を処理するには smarty エンジンを変更する必要があります。そうしないと、暗号化されたコンテンツが表示されるだけです。これには、暗号化されたファイルと暗号化されていないファイルをシームレスに処理する ioncube_read_file() API 関数を使用します。関数を呼び出すファイルはエンコードする必要があることに注意してください。保護されていないファイルで復号化ルーチンを呼び出しても意味がないからです。