@@ -52,8 +52,11 @@ function cleanArray($didYouMeans){
52
52
mkdir (dirname ($ priv_key_file ), 0755 , true );
53
53
}
54
54
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 (
57
60
"digest_alg " => "sha512 " ,
58
61
"private_key_bits " => 4096 ,
59
62
"private_key_type " => \OPENSSL_KEYTYPE_RSA ,
@@ -63,7 +66,7 @@ function cleanArray($didYouMeans){
63
66
$ res = openssl_pkey_new ($ config );
64
67
65
68
// Extract the private key from $res to $privKey
66
- openssl_pkey_export ($ res , $ privKey );
69
+ openssl_pkey_export ($ res , $ privKey, $ password );
67
70
68
71
// Extract the public key from $res to $pubKey
69
72
$ pubKey = openssl_pkey_get_details ($ res );
@@ -81,9 +84,9 @@ function cleanArray($didYouMeans){
81
84
//openssl_private_decrypt($encrypted, $decrypted, $privKey);
82
85
}
83
86
84
-
85
87
if (isset ($ _GET ['source ' ]) && '@server.key ' ===$ _GET ['source ' ]){
86
88
header ('Content-Type: text/plain ' );
89
+ header ('X-Frdlweb-Source-Expires: ' .(filemtime ($ pub_key_file ) + $ expires ));
87
90
echo file_get_contents ($ pub_key_file );
88
91
exit ;
89
92
}
@@ -117,7 +120,53 @@ function cleanArray($didYouMeans){
117
120
}
118
121
119
122
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
+ }
121
170
122
171
123
172
$ didYouMeans = [];
@@ -228,7 +277,7 @@ function cleanArray($didYouMeans){
228
277
229
278
230
279
$ 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 ' )
232
281
: $ code ;
233
282
234
283
if ((isset ($ _SERVER ['HTTP_X_SOURCE_ENCODING ' ]) && 'b64 ' === $ _SERVER ['HTTP_X_SOURCE_ENCODING ' ])
@@ -321,7 +370,7 @@ function cleanArray($didYouMeans){
321
370
322
371
323
372
$ 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 ' )
325
374
: $ outPut ;
326
375
327
376
0 commit comments