Skip to content

Commit c157285

Browse files
add validate on file extensions
1 parent 7335722 commit c157285

File tree

9 files changed

+150
-140
lines changed

9 files changed

+150
-140
lines changed

build/MagnusBilling-current.tar.gz

128 Bytes
Binary file not shown.

protected/components/Util.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,20 @@ public static function calculation_price($buyrate, $duration, $initblock, $incre
294294
$ratecost = $ratecost;
295295
return $ratecost;
296296
}
297+
298+
public static function valid_extension($filename, $allowed = [])
299+
{
300+
$ext = strtolower(CFileHelper::getExtension($filename));
301+
302+
if ( ! in_array($ext, $allowed)) {
303+
echo json_encode([
304+
'success' => false,
305+
'errors' => 'File error',
306+
]);
307+
exit;
308+
}
309+
310+
return $ext;
311+
312+
}
297313
}

protected/controllers/AuthenticationController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ public function actionImportLogo()
436436
} else {
437437
$uploadfile = $uploaddir . 'logo_custom.png';
438438
}
439+
$typefile = Util::valid_extension($_FILES["logo"]["name"], ['png']);
439440

440441
move_uploaded_file($_FILES["logo"]["tmp_name"], $uploadfile);
441442
}
@@ -450,9 +451,9 @@ public function actionImportWallpapers()
450451
{
451452
if (isset($_FILES['wallpaper']['tmp_name']) && strlen($_FILES['wallpaper']['tmp_name']) > 3) {
452453

453-
$uploaddir = "resources/images/wallpapers/";
454-
$data = explode('.', $_FILES["wallpaper"]["name"]);
455-
$typefile = array_pop($data);
454+
$uploaddir = "resources/images/wallpapers/";
455+
$typefile = Util::valid_extension($_FILES["wallpaper"]["name"], ['jpg']);
456+
456457
$uploadfile = $uploaddir . 'Customization.jpg';
457458
move_uploaded_file($_FILES["wallpaper"]["tmp_name"], $uploadfile);
458459
}
@@ -480,6 +481,8 @@ public function actionImportLoginBackground()
480481

481482
if (isset($_FILES['loginbackground']['tmp_name']) && strlen($_FILES['loginbackground']['tmp_name']) > 3) {
482483

484+
$typefile = Util::valid_extension($_FILES["loginbackground"]["name"], ['jpg']);
485+
483486
$uploadfile = 'resources/images/lock-screen-background.jpg';
484487
try {
485488
move_uploaded_file($_FILES["loginbackground"]["tmp_name"], $uploadfile);

0 commit comments

Comments
 (0)