@@ -195,11 +195,11 @@ public function getinfo() {
195
195
$ path = $ this ->get ['path ' ];
196
196
}
197
197
198
-
199
198
$ array = array (
200
199
'Path ' => $ path ,
201
200
'Filename ' =>$ this ->item ['filename ' ],
202
201
'File Type ' =>$ this ->item ['filetype ' ],
202
+ 'Protected ' =>$ this ->item ['protected ' ],
203
203
'Preview ' =>$ this ->item ['preview ' ],
204
204
'Properties ' =>$ this ->item ['properties ' ],
205
205
'Error ' =>"" ,
@@ -222,6 +222,12 @@ public function getfolder() {
222
222
if (!is_dir ($ current_path )) {
223
223
$ this ->error (sprintf ($ this ->lang ('DIRECTORY_NOT_EXIST ' ),$ this ->get ['path ' ]));
224
224
}
225
+
226
+ // check if file is readable
227
+ if (!$ this ->has_system_permission ($ current_path , array ('r ' ))) {
228
+ $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED_SYSTEM ' )));
229
+ }
230
+
225
231
if (!$ handle = @opendir ($ current_path )) {
226
232
$ this ->error (sprintf ($ this ->lang ('UNABLE_TO_OPEN_DIRECTORY ' ),$ this ->get ['path ' ]));
227
233
} else {
@@ -240,11 +246,22 @@ public function getfolder() {
240
246
241
247
if (is_dir ($ current_path . $ file )) {
242
248
if (!in_array ($ file , $ this ->config ['exclude ' ]['unallowed_dirs ' ]) && !preg_match ( $ this ->config ['exclude ' ]['unallowed_dirs_REGEXP ' ], $ file )) {
249
+
250
+ // check if file is writable and readable
251
+ if (!$ this ->has_system_permission ($ current_path . $ file , array ('w ' , 'r ' ))) {
252
+ $ protected = 1 ;
253
+ $ previewPath = $ this ->config ['icons ' ]['path ' ] . 'locked_ ' . $ this ->config ['icons ' ]['directory ' ];
254
+ } else {
255
+ $ protected =0 ;
256
+ $ previewPath = $ this ->config ['icons ' ]['path ' ] . $ this ->config ['icons ' ]['directory ' ];
257
+ }
258
+
243
259
$ array [$ this ->get ['path ' ] . $ file .'/ ' ] = array (
244
260
'Path ' => $ this ->get ['path ' ] . $ file .'/ ' ,
245
261
'Filename ' =>$ file ,
246
262
'File Type ' =>'dir ' ,
247
- 'Preview ' => $ this ->config ['icons ' ]['path ' ] . $ this ->config ['icons ' ]['directory ' ],
263
+ 'Protected ' =>$ protected ,
264
+ 'Preview ' => $ previewPath ,
248
265
'Properties ' =>array (
249
266
'Date Created ' => date ($ this ->config ['options ' ]['dateFormat ' ], filectime ($ this ->getFullPath ($ this ->get ['path ' ] . $ file .'/ ' ))),
250
267
'Date Modified ' => date ($ this ->config ['options ' ]['dateFormat ' ], filemtime ($ this ->getFullPath ($ this ->get ['path ' ] . $ file .'/ ' ))),
@@ -261,13 +278,15 @@ public function getfolder() {
261
278
$ this ->item = array ();
262
279
$ this ->item ['properties ' ] = $ this ->properties ;
263
280
$ this ->get_file_info ($ this ->get ['path ' ] . $ file , true );
281
+
264
282
265
283
if (!isset ($ this ->params ['type ' ]) || (isset ($ this ->params ['type ' ]) && strtolower ($ this ->params ['type ' ])=='images ' && in_array (strtolower ($ this ->item ['filetype ' ]),array_map ('strtolower ' , $ this ->config ['images ' ]['imagesExt ' ])))) {
266
284
if ($ this ->config ['upload ' ]['imagesOnly ' ]== false || ($ this ->config ['upload ' ]['imagesOnly ' ]== true && in_array (strtolower ($ this ->item ['filetype ' ]),array_map ('strtolower ' , $ this ->config ['images ' ]['imagesExt ' ])))) {
267
285
$ array [$ this ->get ['path ' ] . $ file ] = array (
268
286
'Path ' =>$ this ->get ['path ' ] . $ file ,
269
287
'Filename ' =>$ this ->item ['filename ' ],
270
288
'File Type ' =>$ this ->item ['filetype ' ],
289
+ 'Protected ' =>$ this ->item ['protected ' ],
271
290
'Preview ' =>$ this ->item ['preview ' ],
272
291
'Properties ' =>$ this ->item ['properties ' ],
273
292
'Error ' =>"" ,
@@ -289,9 +308,9 @@ public function editfile() {
289
308
290
309
$ current_path = $ this ->getFullPath ();
291
310
292
- // check if writable
293
- if (!is_writable ( $ this ->getFullPath ($ current_path ))) {
294
- $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )));
311
+ // check if file is writable
312
+ if (!$ this ->has_system_permission ($ current_path, array ( ' w ' ))) {
313
+ $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED_SYSTEM ' )));
295
314
}
296
315
297
316
if (!$ this ->has_permission ('edit ' ) || !$ this ->is_valid_path ($ current_path ) || !$ this ->is_editable ($ current_path )) {
@@ -325,7 +344,7 @@ public function savefile() {
325
344
$ this ->error ("No way. " );
326
345
}
327
346
328
- if (!is_writable ($ current_path )) {
347
+ if (!$ this -> has_system_permission ($ current_path, array ( ' w ' ) )) {
329
348
$ this ->error (sprintf ($ this ->lang ('ERROR_WRITING_PERM ' )));
330
349
}
331
350
@@ -366,9 +385,9 @@ public function rename() {
366
385
$ this ->error ("No way. " );
367
386
}
368
387
369
- // check if writable
370
- if (!is_writable ( $ this ->getFullPath ($ old_file ))) {
371
- $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )));
388
+ // check if file is writable
389
+ if (!$ this ->has_system_permission ($ old_file, array ( ' w ' ))) {
390
+ $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED_SYSTEM ' )), true );
372
391
}
373
392
374
393
// check if not requesting main FM userfiles folder
@@ -423,11 +442,12 @@ public function move() {
423
442
$ rootDir = str_replace ('// ' , '/ ' , $ rootDir );
424
443
$ oldPath = $ this ->getFullPath ($ this ->get ['old ' ]);
425
444
426
- // check if writable
427
- if (!is_writable ( $ this ->getFullPath ($ oldPath ))) {
428
- $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )));
445
+ // check if file is writable
446
+ if (!$ this ->has_system_permission ($ oldPath, array ( ' w ' ))) {
447
+ $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED_SYSTEM ' )), true );
429
448
}
430
449
450
+
431
451
// check if not requesting main FM userfiles folder
432
452
if ($ this ->is_root_folder ($ oldPath )) {
433
453
$ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )),true );
@@ -499,15 +519,16 @@ public function delete() {
499
519
$ current_path = $ this ->getFullPath ();
500
520
$ thumbnail_path = $ this ->get_thumbnail_path ($ current_path );
501
521
502
- // check if writable
503
- if (!is_writable ($ this ->getFullPath ($ current_path ))) {
504
- $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )));
505
- }
506
522
507
523
if (!$ this ->has_permission ('delete ' ) || !$ this ->is_valid_path ($ current_path )) {
508
524
$ this ->error ("No way. " );
509
525
}
510
526
527
+ // check if file is writable
528
+ if (!$ this ->has_system_permission ($ current_path , array ('w ' ))) {
529
+ $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED_SYSTEM ' )));
530
+ }
531
+
511
532
// check if not requesting main FM userfiles folder
512
533
if ($ this ->is_root_folder ($ current_path )) {
513
534
$ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )));
@@ -603,9 +624,9 @@ public function replace() {
603
624
604
625
$ current_path = $ this ->getFullPath ($ this ->post ['newfilepath ' ]);
605
626
606
- // check if writable
607
- if (!is_writable ( $ this ->getFullPath ($ current_path ))) {
608
- $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )), true );
627
+ // check if file is writable
628
+ if (!$ this ->has_system_permission ($ current_path, array ( ' w ' ))) {
629
+ $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED_SYSTEM ' )), true );
609
630
}
610
631
611
632
if (!$ this ->has_permission ('replace ' ) || !$ this ->is_valid_path ($ current_path )) {
@@ -818,15 +839,15 @@ public function download() {
818
839
819
840
$ current_path = $ this ->getFullPath ();
820
841
821
- // check if writable
822
- if (!is_writable ($ this ->getFullPath ($ current_path ))) {
823
- $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED ' )));
824
- }
825
-
826
842
if (!$ this ->has_permission ('download ' ) || !$ this ->is_valid_path ($ current_path )) {
827
843
$ this ->error ("No way. " );
828
844
}
829
845
846
+ // check if file is writable
847
+ if (!$ this ->has_system_permission ($ current_path , array ('w ' ))) {
848
+ $ this ->error (sprintf ($ this ->lang ('NOT_ALLOWED_SYSTEM ' )),true );
849
+ }
850
+
830
851
// we check if extension is allowed regarding the security Policy settings
831
852
if (is_file ($ current_path )) {
832
853
if (!$ this ->is_allowed_file_type (basename ($ current_path ))) {
@@ -936,6 +957,20 @@ private function setPermissions() {
936
957
if ($ this ->config ['edit ' ]['enabled ' ]) array_push ($ this ->allowed_actions , 'edit ' );
937
958
938
959
}
960
+
961
+ // check if system permission is granted
962
+ private function has_system_permission ($ filepath , $ perms ) {
963
+
964
+ if (in_array ('r ' , $ perms )) {
965
+ if (!is_readable ($ filepath )) return false ;
966
+ }
967
+ if (in_array ('w ' , $ perms )) {
968
+ if (!is_writable ($ filepath )) return false ;
969
+ }
970
+
971
+ return true ;
972
+
973
+ }
939
974
940
975
941
976
private function get_file_info ($ path ='' , $ thumbnail = false ) {
@@ -954,12 +989,19 @@ private function get_file_info($path='', $thumbnail = false) {
954
989
$ this ->item ['filetype ' ] = $ tmp [(sizeof ($ tmp )-1 )];
955
990
$ this ->item ['filemtime ' ] = filemtime ($ this ->getFullPath ($ current_path ));
956
991
$ this ->item ['filectime ' ] = filectime ($ this ->getFullPath ($ current_path ));
957
-
958
- $ this ->item ['preview ' ] = $ this ->config ['icons ' ]['path ' ] . $ this ->config ['icons ' ]['default ' ];
959
992
960
- // prevent Internal Server Error HTTP_CODE 500 on non readable files/folders
961
- // without returning errors
962
- if (!is_readable ($ this ->getFullPath ($ current_path ))) return ;
993
+ // check if file is writable and readable
994
+ if (!$ this ->has_system_permission ($ this ->getFullPath ($ current_path ), array ('w ' , 'r ' ))) {
995
+ $ this ->item ['protected ' ] = 1 ;
996
+ $ this ->item ['preview ' ] = $ this ->config ['icons ' ]['path ' ] . 'locked_ ' . $ this ->config ['icons ' ]['default ' ];
997
+ // prevent Internal Server Error HTTP_CODE 500 on non readable files/folders
998
+ // without returning errors
999
+ return ;
1000
+
1001
+ } else {
1002
+ $ this ->item ['protected ' ] = 0 ;
1003
+ $ this ->item ['preview ' ] = $ this ->config ['icons ' ]['path ' ] . $ this ->config ['icons ' ]['default ' ];
1004
+ }
963
1005
964
1006
if (is_dir ($ current_path )) {
965
1007
0 commit comments