8
8
* License: GNU/GPLv2
9
9
* @see LICENSE.txt
10
10
*
11
- * This file: Upload handler (last modified: 2020.07.07 ).
11
+ * This file: Upload handler (last modified: 2020.07.11 ).
12
12
*/
13
13
14
14
namespace phpMussel \Web ;
@@ -99,7 +99,7 @@ public function __construct(\phpMussel\Core\Loader &$Loader, \phpMussel\Core\Sca
99
99
$ this ->Loader ->Events ->addHandler ('writeToUploadsLog ' , function (string $ Data ): bool {
100
100
/** Guard. */
101
101
if (
102
- empty ($ this ->Loader ->HashReference ) ||
102
+ strlen ($ this ->Loader ->HashReference ) === 0 ||
103
103
!($ File = $ this ->Loader ->buildPath ($ this ->Loader ->Configuration ['web ' ]['uploads_log ' ]))
104
104
) {
105
105
return false ;
@@ -136,18 +136,17 @@ public function scan()
136
136
return ;
137
137
}
138
138
139
- /** File upload scan start time. */
140
- $ this ->Loader ->InstanceCache ['StartTime ' ] = time () + ($ this ->Loader ->Configuration ['core ' ]['time_offset ' ] * 60 );
141
-
142
139
/** Create empty handle array. */
143
140
$ Handle = [];
144
141
145
142
/** Create an array for normalising the $_FILES data. */
146
143
$ FilesData = [];
147
144
145
+ /** Create an array to designate the scan targets. */
146
+ $ FilesToScan = [];
147
+
148
148
/** Iterate through $_FILES array and scan as necessary. */
149
149
foreach ($ _FILES as $ FileKey => $ FileData ) {
150
-
151
150
/** Guard. */
152
151
if (!isset ($ FileData ['error ' ])) {
153
152
continue ;
@@ -167,7 +166,8 @@ public function scan()
167
166
}
168
167
$ FilesCount = count ($ FilesData ['FileSet ' ]['error ' ]);
169
168
170
- for ($ Iterator = 0 , $ this ->Loader ->InstanceCache ['SkipSerial ' ] = true ; $ Iterator < $ FilesCount ; $ Iterator ++) {
169
+ /** Iterate through fileset. */
170
+ for ($ Iterator = 0 ; $ Iterator < $ FilesCount ; $ Iterator ++) {
171
171
if (!isset ($ FilesData ['FileSet ' ]['name ' ][$ Iterator ])) {
172
172
$ FilesData ['FileSet ' ]['name ' ][$ Iterator ] = '' ;
173
173
}
@@ -189,22 +189,13 @@ public function scan()
189
189
190
190
/** Handle upload errors. */
191
191
if ($ ThisError > 0 ) {
192
- if (
193
- $ this ->Loader ->Configuration ['compatibility ' ]['ignore_upload_errors ' ] ||
194
- $ ThisError > 8 ||
195
- $ ThisError === 5
196
- ) {
192
+ if ($ this ->Loader ->Configuration ['compatibility ' ]['ignore_upload_errors ' ] || $ ThisError > 8 || $ ThisError === 5 ) {
197
193
continue ;
198
194
}
199
- $ this ->Loader ->HashReference .= sprintf (
200
- "---------UPLOAD-ERROR-%d---------:%d:%s \n" ,
201
- $ ThisError ,
202
- $ FilesData ['FileSet ' ]['size ' ][$ Iterator ],
203
- $ FilesData ['FileSet ' ]['name ' ][$ Iterator ]
204
- );
205
- $ this ->Loader ->WhyFlagged .= $ this ->Loader ->L10N ->getString ((
206
- $ ThisError === 3 || $ ThisError === 4
207
- ) ? 'upload_error_34 ' : 'upload_error_ ' . $ ThisError );
195
+ $ this ->Loader ->atHit ('' , -1 , '' , sprintf (
196
+ $ this ->Loader ->L10N ->getString ('grammar_exclamation_mark ' ),
197
+ $ this ->Loader ->L10N ->getString ('upload_error_ ' . (($ ThisError === 3 || $ ThisError === 4 ) ? '34 ' : $ ThisError ))
198
+ ), -5 , -1 );
208
199
if (
209
200
($ ThisError === 1 || $ ThisError === 2 ) &&
210
201
$ this ->Loader ->Configuration ['core ' ]['delete_on_sight ' ] &&
@@ -221,23 +212,23 @@ public function scan()
221
212
!$ FilesData ['FileSet ' ]['name ' ][$ Iterator ] ||
222
213
!$ FilesData ['FileSet ' ]['tmp_name ' ][$ Iterator ]
223
214
) {
224
- $ this ->Loader ->HashReference .= "-UNAUTHORISED-UPLOAD-MISCONFIG-:?:? \n" ;
225
- $ this ->Loader ->WhyFlagged .= $ this ->Loader ->L10N ->getString ('scan_unauthorised_upload_or_misconfig ' );
215
+ $ this ->Loader ->atHit ('' , -1 , '' , sprintf (
216
+ $ this ->Loader ->L10N ->getString ('grammar_exclamation_mark ' ),
217
+ $ this ->Loader ->L10N ->getString ('scan_unauthorised_upload_or_misconfig ' )
218
+ ), -5 , -1 );
226
219
continue ;
227
220
}
228
221
229
222
/** Protection against upload spoofing (2/2). */
230
223
if (!is_uploaded_file ($ FilesData ['FileSet ' ]['tmp_name ' ][$ Iterator ])) {
231
- $ this ->Loader ->HashReference .= sprintf (
232
- "UNAUTHORISED-FILE-UPLOAD-NO-HASH:%d:%s \n" ,
233
- $ FilesData ['FileSet ' ]['size ' ][$ Iterator ],
234
- $ FilesData ['FileSet ' ]['name ' ][$ Iterator ]
235
- );
236
- $ this ->Loader ->WhyFlagged .= sprintf ($ this ->Loader ->L10N ->getString ('_exclamation ' ), sprintf (
237
- '%s (%s) ' ,
238
- $ this ->Loader ->L10N ->getString ('scan_unauthorised_upload ' ),
239
- $ FilesData ['FileSet ' ]['name ' ][$ Iterator ]
240
- ));
224
+ $ this ->Loader ->atHit ('' , $ FilesData ['FileSet ' ]['size ' ][$ Iterator ], $ FilesData ['FileSet ' ]['name ' ][$ Iterator ], sprintf (
225
+ $ this ->Loader ->L10N ->getString ('grammar_exclamation_mark ' ),
226
+ sprintf (
227
+ $ this ->Loader ->L10N ->getString ('grammar_brackets ' ),
228
+ $ this ->Loader ->L10N ->getString ('scan_unauthorised_upload ' ),
229
+ $ FilesData ['FileSet ' ]['name ' ][$ Iterator ]
230
+ )
231
+ ), -5 , -1 );
241
232
continue ;
242
233
}
243
234
@@ -246,14 +237,14 @@ public function scan()
246
237
$ this ->Loader ->Configuration ['web ' ]['max_uploads ' ] >= 1 &&
247
238
$ this ->Uploads > $ this ->Loader ->Configuration ['web ' ]['max_uploads ' ]
248
239
) {
249
- $ this ->Loader ->HashReference .=
250
- str_repeat ( ' - ' , 64 ) . ' : ' .
251
- $ FilesData [ ' FileSet ' ][ ' size ' ][ $ Iterator ] . ' : ' .
252
- $ FilesData [ ' FileSet ' ][ ' name ' ][ $ Iterator ] . "\n" ;
253
- $ this -> Loader -> WhyFlagged .= sprintf ( $ this ->Loader ->L10N ->getString ('_exclamation ' ),
254
- $ this -> Loader -> L10N -> getString ( ' upload_limit_exceeded ' ) .
255
- ' ( ' . $ FilesData [ ' FileSet ' ][ ' name ' ][ $ Iterator ] . ' ) '
256
- );
240
+ $ this ->Loader ->atHit ( '' , $ FilesData [ ' FileSet ' ][ ' size ' ][ $ Iterator ], $ FilesData [ ' FileSet ' ][ ' name ' ][ $ Iterator ], sprintf (
241
+ $ this -> Loader -> L10N -> getString ( ' grammar_exclamation_mark ' ),
242
+ sprintf (
243
+ $ this -> Loader -> L10N -> getString ( ' grammar_brackets ' ),
244
+ $ this ->Loader ->L10N ->getString ('upload_limit_exceeded ' ),
245
+ $ FilesData [ ' FileSet ' ][ ' name ' ][ $ Iterator ]
246
+ )
247
+ ), - 5 , - 1 ) ;
257
248
if (
258
249
$ this ->Loader ->Configuration ['core ' ]['delete_on_sight ' ] &&
259
250
is_uploaded_file ($ FilesData ['FileSet ' ]['tmp_name ' ][$ Iterator ]) &&
@@ -264,30 +255,20 @@ public function scan()
264
255
continue ;
265
256
}
266
257
267
- /** Used for serialised logging. */
268
- if ($ Iterator === ($ FilesCount - 1 )) {
269
- unset($ this ->Loader ->InstanceCache ['SkipSerial ' ]);
270
- }
271
-
272
- /** Execute the scan! */
273
- $ this ->Scanner ->scan (
274
- $ FilesData ['FileSet ' ]['tmp_name ' ][$ Iterator ],
275
- true ,
276
- true ,
277
- 0 ,
278
- $ FilesData ['FileSet ' ]['name ' ][$ Iterator ]
279
- );
258
+ /** Designate as scan target. */
259
+ $ FilesToScan [$ FilesData ['FileSet ' ]['name ' ][$ Iterator ]] = $ FilesData ['FileSet ' ]['tmp_name ' ][$ Iterator ];
280
260
}
281
261
}
282
262
283
- /** File upload scan finish time. */
284
- $ this ->Loader ->InstanceCache ['EndTime ' ] = time () + ($ this ->Loader ->Configuration ['core ' ]['time_offset ' ] * 60 );
285
-
286
- /** Trim trailing whitespace. */
287
- $ this ->Loader ->WhyFlagged = trim ($ this ->Loader ->WhyFlagged );
263
+ /** Check these first, because they'll reset otherwise, then execute the scan. */
264
+ if (!count ($ this ->Loader ->ScanResultsText ) && count ($ FilesToScan )) {
265
+ $ this ->Scanner ->scan ($ FilesToScan , 4 );
266
+ }
288
267
289
268
/** Begin processing file upload detections. */
290
- if ($ this ->Loader ->WhyFlagged ) {
269
+ if (count ($ this ->Loader ->ScanResultsText )) {
270
+ /** Build detections. */
271
+ $ Detections = implode ($ this ->Loader ->L10N ->getString ('grammar_spacer ' ), $ this ->Loader ->ScanResultsText );
291
272
292
273
/** A fix for correctly displaying LTR/RTL text. */
293
274
if ($ this ->Loader ->L10N ->getString ('Text Direction ' ) !== 'rtl ' ) {
@@ -298,7 +279,7 @@ public function scan()
298
279
$ TemplateData = [
299
280
'magnification ' => $ this ->Loader ->Configuration ['web ' ]['magnification ' ],
300
281
'Attache ' => $ this ->Attache ,
301
- 'detected ' => $ this -> Loader -> WhyFlagged ,
282
+ 'detected ' => $ Detections ,
302
283
'phpmusselversion ' => $ this ->Loader ->ScriptIdent ,
303
284
'favicon ' => base64_encode ($ this ->Loader ->getFavicon ()),
304
285
'xmlLang ' => $ this ->Loader ->Configuration ['core ' ]['lang ' ]
@@ -324,7 +305,7 @@ public function scan()
324
305
}
325
306
326
307
/** Log "uploads_log" data. */
327
- if (! empty ($ this ->Loader ->HashReference )) {
308
+ if (strlen ($ this ->Loader ->HashReference ) !== 0 ) {
328
309
$ Handle ['Data ' ] = sprintf (
329
310
"%s: %s \n%s: %s \n== %s == \n%s \n== %s == \n%s " ,
330
311
$ this ->Loader ->L10N ->getString ('field_date ' ),
@@ -334,7 +315,7 @@ public function scan()
334
315
$ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]]
335
316
) : $ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]]),
336
317
$ this ->Loader ->L10N ->getString ('field_header_scan_results_why_flagged ' ),
337
- $ this -> Loader -> WhyFlagged ,
318
+ $ Detections ,
338
319
$ this ->Loader ->L10N ->getString ('field_header_hash_reconstruction ' ),
339
320
$ this ->Loader ->HashReference
340
321
);
0 commit comments