Skip to content

Commit 938e2b9

Browse files
authored
Update index.php
1 parent fbc8427 commit 938e2b9

File tree

1 file changed

+56
-7
lines changed

1 file changed

+56
-7
lines changed

public/index.php

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ function cleanArray($didYouMeans){
5252
mkdir(dirname($priv_key_file), 0755, true);
5353
}
5454

55-
if(!file_exists($pub_key_file) || !file_exists($priv_key_file) ){
56-
$config = array(
55+
$password = 'chANgeThisToYourPassword';
56+
$expires = 28 * 24 * 60 * 60;
57+
58+
if(!file_exists($pub_key_file) || !file_exists($priv_key_file) || filemtime($pub_key_file) < time() - $expires){
59+
$config = array(
5760
"digest_alg" => "sha512",
5861
"private_key_bits" => 4096,
5962
"private_key_type" => \OPENSSL_KEYTYPE_RSA,
@@ -63,7 +66,7 @@ function cleanArray($didYouMeans){
6366
$res = openssl_pkey_new($config);
6467

6568
// Extract the private key from $res to $privKey
66-
openssl_pkey_export($res, $privKey);
69+
openssl_pkey_export($res, $privKey, $password);
6770

6871
// Extract the public key from $res to $pubKey
6972
$pubKey = openssl_pkey_get_details($res);
@@ -81,9 +84,9 @@ function cleanArray($didYouMeans){
8184
//openssl_private_decrypt($encrypted, $decrypted, $privKey);
8285
}
8386

84-
8587
if(isset($_GET['source']) && '@server.key'===$_GET['source']){
8688
header('Content-Type: text/plain');
89+
header('X-Frdlweb-Source-Expires: '.(filemtime($pub_key_file) + $expires));
8790
echo file_get_contents($pub_key_file);
8891
exit;
8992
}
@@ -117,7 +120,53 @@ function cleanArray($didYouMeans){
117120
}
118121

119122

120-
123+
$moduleDirs = [
124+
__DIR__ . \DIRECTORY_SEPARATOR. '..'. \DIRECTORY_SEPARATOR.'php-node_modules'. \DIRECTORY_SEPARATOR,
125+
];
126+
127+
$uri = substr($_SERVER['REQUEST_URI'], strlen('/'.basename(__DIR__)), strlen($_SERVER['REQUEST_URI']) );
128+
129+
$u = explode('?', $uri);
130+
$uri = $u[0];
131+
$uri = str_replace(['/./', '/../'], ['', ''], $uri);
132+
if('/' !== $uri){
133+
foreach($moduleDirs as $moduleDir){
134+
$file = $moduleDir . str_replace('/', \DIRECTORY_SEPARATOR, $uri);
135+
if(file_exists($file)){
136+
137+
$outPut = file_get_contents($file);
138+
139+
$outPut = false === strpos($outPut, base64_decode('X19oYWx0X2NvbXBpbGVyKCk7'))
140+
? $loader->sign($outPut,[ file_get_contents($priv_key_file), $password], 'X19oYWx0X2NvbXBpbGVyKCk7')
141+
: $outPut;
142+
// if(isset($_GET['test']))die($loader->verify($outPut,file_get_contents($pub_key_file),'X19oYWx0X2NvbXBpbGVyKCk7'));
143+
144+
145+
if((isset($_SERVER['HTTP_X_SOURCE_ENCODING']) && 'b64' === $_SERVER['HTTP_X_SOURCE_ENCODING'])
146+
||
147+
(isset($_GET['source-encoding']) && 'b64' === $_GET['source-encoding'] )
148+
){
149+
$outPut = base64_encode($outPut);
150+
}
151+
152+
header('Content-Type: text/plain');
153+
154+
$hash_check = strlen($outPut).'.'.sha1($outPut);
155+
$userHash_check = sha1(((isset($_GET['salt']))?$_GET['salt']:null) .$hash_check);
156+
header('X-Content-Hash: '.$hash_check);
157+
header('X-User-Hash: '.$userHash_check);
158+
159+
header('Content-Md5: '.md5($outPut));
160+
header('Content-Sha1: '.sha1($outPut));
161+
162+
echo $outPut;
163+
return;
164+
}
165+
}
166+
167+
header( $_SERVER['SERVER_PROTOCOL']." 404 Not Found", true );
168+
$content .= 'Not found';
169+
}
121170

122171

123172
$didYouMeans = [];
@@ -228,7 +277,7 @@ function cleanArray($didYouMeans){
228277

229278

230279
$code = false === strpos($code, base64_decode('X19oYWx0X2NvbXBpbGVyKCk7'))
231-
? $loader->sign($code, file_get_contents($priv_key_file), 'X19oYWx0X2NvbXBpbGVyKCk7')
280+
? $loader->sign($code, [ file_get_contents($priv_key_file), $password], 'X19oYWx0X2NvbXBpbGVyKCk7')
232281
: $code;
233282

234283
if((isset($_SERVER['HTTP_X_SOURCE_ENCODING']) && 'b64' === $_SERVER['HTTP_X_SOURCE_ENCODING'])
@@ -321,7 +370,7 @@ function cleanArray($didYouMeans){
321370

322371

323372
$outPut = false === strpos($outPut, base64_decode('X19oYWx0X2NvbXBpbGVyKCk7'))
324-
? $loader->sign($outPut, file_get_contents($priv_key_file), 'X19oYWx0X2NvbXBpbGVyKCk7')
373+
? $loader->sign($outPut, [ file_get_contents($priv_key_file), $password], 'X19oYWx0X2NvbXBpbGVyKCk7')
325374
: $outPut;
326375

327376

0 commit comments

Comments
 (0)