Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Obfuscate
<?php
// https://github.com/pH-7/Obfuscator-Class
if (! file_exists('Obfuscator.php')) {
$content = file_get_contents('https://raw.githubusercontent.com/pH-7/Obfuscator-Class/master/src/Obfuscator.php');
$fp = fopen("Obfuscator.php", "wb");
fwrite($fp,$content);
fclose($fp);
}
require 'Obfuscator.php';
$onlyDirectory = [
'app',
'donjo-app/core',
'donjo-app/helpers',
'donjo-app/controllers',
// 'donjo-app/libraries',
'donjo-app/models',
];
$exceptDirectory = [
'donjo-app/models/migrasi',
];
$onlyFile = [
// 'donjo-app/helpers/general_helper.php',
];
$exceptFile = [
'donjo-app/helpers/general_helper.php',
];
foreach ($onlyDirectory as $list) {
cekFile($list, $exceptDirectory, $onlyFile, $exceptFile);
}
function cekFile($onlyDirectory, $exceptDirectory, $onlyFile, $exceptFile)
{
if ($onlyDirectory) {
foreach (glob($onlyDirectory . '/*') as $cek) {
if (is_file($cek) && pathinfo($cek)['extension'] === 'php') {
// Only File
if ($onlyFile && ! in_array($cek, $onlyFile)) {
continue;
}
// Except File
if ($exceptFile && in_array($cek, $exceptFile)) {
continue;
}
if (file_exists($cek)) {
$sData = file_get_contents($cek);
$sData = str_replace(array('<?php', '<?', '?>'), '', $sData); // We strip the open/close PHP tags
$sObfusationData = new Obfuscator($sData, $cek);
file_put_contents($cek, '<?php ' . "\r\n" . $sObfusationData);
}
} else {
// Except Directory
if ($exceptDirectory && in_array($cek, $exceptDirectory)) {
continue;
}
cekFile($cek, $exceptDirectory, $onlyFile, $exceptFile);
}
}
} else {
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment