{ "'": { "": ">" }, "\"----SIGNATURE": { "": "----\"," }, "\"----ATTACHMENT": { "": "----\"," }, "ATTACHMENT": { "": "base64_decode($ATTACHMENT);" }, "JS": { "": "\\Webfan\\CommonJavascript::getInstance('default',[" } }
This is based on the idea of https://github.com/olivierphi/CommonJSForPHP
$publicKeyChanged = false;
$increaseTimelimit = true;
$setPublicKey = function($baseUrl, $expFile, $pubKeyFile){
if(file_exists($expFile)){
$expires = intval(file_get_contents($expFile));
}else{
$expires = 0;
}
if(!is_dir(dirname($expFile))){
mkdir(dirname($expFile), 0755, true);
}
if(!is_dir(dirname($pubKeyFile))){
mkdir(dirname($pubKeyFile), 0755, true);
}
if($expires > 0 && ($expires === time() || ($expires > time() - 3 && $expires < time() + 3))){
sleep(3);
}
if($expires <= time() || !file_exists($pubKeyFile) ){
$opts =[
'http'=>[
'method'=>'GET',
//'header'=>"Accept-Encoding: deflate, gzip\r\n",
],
];
$context = stream_context_create($opts);
$key = file_get_contents($baseUrl.'?source=@server.key', false, $context);
foreach($http_response_header as $i => $header){
$h = explode(':', $header);
if('x-frdlweb-source-expires' === strtolower(trim($h[0]))){
file_put_contents($expFile, trim($h[1]) );
break;
}
}
file_put_contents($pubKeyFile, $key);
}
};
$getDefaultValidatorForUrl = function($baseUrl, $cacheDir, $increaseTimelimit = true) use($setPublicKey, &$publicKeyChanged) {
$expFile = rtrim($cacheDir, '\\/ ') . \DIRECTORY_SEPARATOR.'validator-'.sha1($baseUrl).strlen($baseUrl).'.expires.txt';
$pubKeyFile = rtrim($cacheDir, '\\/ ') . \DIRECTORY_SEPARATOR.'validator-'.sha1($baseUrl).strlen($baseUrl).'.public-key.txt';
$setPublicKey($baseUrl, $expFile, $pubKeyFile);
$condition = function($url) use($baseUrl, $increaseTimelimit){
if($increaseTimelimit){
set_time_limit(min(180, intval(ini_get('max_execution_time')) + 90));
}
if($baseUrl === substr($url, 0, strlen($baseUrl) ) ){
return true;
}else{
return false;
}
};
$filter = function($code) use($baseUrl, $expFile, $pubKeyFile, $setPublicKey, &$publicKeyChanged) {
$sep = 'X19oYWx0X2NvbXBpbGVyKCk7';
$my_signed_data=$code;
$public_key = file_get_contents($pubKeyFile);
list($plain_data,$sigdata) = explode(base64_decode($sep), $my_signed_data, 2);
list($nullVoid,$old_sig_1) = explode("----SIGNATURE:----", $sigdata, 2);
list($old_sig,$ATTACHMENT) = explode("----ATTACHMENT:----", $old_sig_1, 2);
$old_sig = base64_decode($old_sig);
$ATTACHMENT = base64_decode($ATTACHMENT);
if(empty($old_sig)){
return new \Exception("ERROR -- unsigned data");
}
\openssl_public_decrypt($old_sig, $decrypted_sig, $public_key);
$data_hash = sha1($plain_data.$ATTACHMENT).substr(str_pad(strlen($plain_data.$ATTACHMENT).'', 128, strlen($plain_data.$ATTACHMENT) % 10, \STR_PAD_LEFT), 0, 128);
if($decrypted_sig === $data_hash && strlen($data_hash)>0){
return $plain_data;
}else{
if(!$publicKeyChanged){
$publicKeyChanged = true;
unlink($pubKeyFile);
unlink($expFile);
$setPublicKey($baseUrl, $expFile, $pubKeyFile);
}
return new \Exception("ERROR -- untrusted signature");
}
};
return [$condition, $filter];
};
$getDefaultValidators = function($cacheDir, $increaseTimelimit = true) use($getDefaultValidatorForUrl) {
return [
$getDefaultValidatorForUrl('https://webfan.de/install/stable/', $cacheDir, $increaseTimelimit),
$getDefaultValidatorForUrl('https://webfan.de/install/latest/', $cacheDir, $increaseTimelimit),
$getDefaultValidatorForUrl('https://webfan.de/install/modules/', $cacheDir, $increaseTimelimit),
];
};
$commonJS =\Webfan\CommonJavascript::getInstance('default',[
'tmpPath' => \sys_get_temp_dir(),
// 'basePath' => __DIR__,
'basePath' =>[
$ContainerBuilder->getAppKernel()->getDir('modules'),
getcwd(),
'https://webfan.de/install/modules/',
'https://webfan.de/install/stable/',
'https://webfan.de/install/latest/',
],
'modulesExt' => '.php',
'folderAsModuleFileName' => 'index.php',
'packageInfoFileName' => 'package.php',
// 'autoNamespacing' => false,
'autoNamespacing' => true,
'autoNamespacingCacheExpires' => 24*60*60,
'validators' => $getDefaultValidators($ContainerBuilder->getAppKernel()->getDir('cache')
.'prune-month'.\DIRECTORY_SEPARATOR, true),
],
[
'json' => __DIR__ . '/plugins/commonsjs-plugin.json.php',
'yaml' => __DIR__ . '/plugins/commonsjs-plugin.yaml.php',
]
);
$commonJS['exec'] = function(\callable | \closure $callback, array $params = []) use(&$commonJS){
extract($commonJS);
$args = [$define, $require, &$exports, &$module];
foreach($params as $param){
array_push($args, $param);
}
return call_user_func_array($callback, $args);
};
extract($commonJS);
$define('logger', function($require) {
return function($msg) {
//syslog(LOG_DEBUG, $msg);
print_r($msg);
};
});
$logger = $require('logger');
$logger('Hihallihallo');
$test= $require('test');
print_r(array_merge([$App->getDir('modules')], [
$test,
'https://webfan.de/install/modules/',
]));
//return;
$exec(function($define, $require, &$exports, &$module, ...$args){
echo implode(' ', $args);
}, ['Hello', ' ', 'World!']);
The übergeordnete Zertifizierungsstelle hat keine Zertifizierungsstelle für diesen PHP-Namensräume festgelegt.
ID | RA | Kommentar | Erstellt | Geändert |
---|---|---|---|---|
Keine Einträge vorhanden |
Statischer Link zu dieser Seite