]> jfr.im git - uguu.git/commitdiff
Merge pull request #36 from thxo/remove-dot-suffix-randomname
authorEric Johansson (neku) <redacted>
Sun, 15 Dec 2019 00:16:01 +0000 (01:16 +0100)
committerGitHub <redacted>
Sun, 15 Dec 2019 00:16:01 +0000 (01:16 +0100)
Ensure no trailing dot in random filenames

1  2 
includes/core.php

diff --combined includes/core.php
index 5aca11bbfb753d4bf7a23c0efe4136ab093dfbb6,5e915478074103c83c7efd21f2a5769c67619019..8f48a5145ecfb710516429fc8ebdaeda9ac75b85
@@@ -9,7 -9,14 +9,7 @@@ function save_file ($file, $name, $arg
          case 'random':
              $ext = pathinfo($file.$name, PATHINFO_EXTENSION);
              $ext = strtolower($ext);
 -            if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){
 -              if($type==='normal'){
 -                include_once(CONFIG_ROOT_PATH.'error_meow.php');
 -                exit(0);
 -              }else{
 -                exit('File type not allowed.');
 -              }
 -            }
 +            verify_extension($ext, $type);
              $file_name = gen_name('random', $ext);
              while(file_exists(CONFIG_FILES_PATH.$file_name)){
                $file_name = gen_name('random', $ext);
                  $file_name = gen_name('custom_original', $name);
                  $ext = pathinfo($file_name, PATHINFO_EXTENSION);
                  $ext = strtolower($ext);
 -                if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){
 -                 if($type==='normal'){
 -                   include_once(CONFIG_ROOT_PATH.'error_meow.php');
 -                   exit(0);
 -                 }else{
 -                   exit('File type not allowed.');
 -                 }
 -                }
 +                verify_extension($ext, $type);
              while(file_exists(CONFIG_FILES_PATH.$file_name)){
                  $file_name = gen_name('custom_original', $name);
              }
@@@ -55,28 -69,13 +55,31 @@@ function gen_name($arg, $in)
          }
      switch($arg){
          case 'random':
-             return $name.'.'.$in;
+             if($in){
+                 return $name.'.'.$in;
+             }
+             return $name;
              break;
          case 'custom_original':
              return $name.'_'.$in;
              break;
      }
  }
 +
 +//Verify that the extension is allowed
 +function verify_extension($ext, $type){
 +    if(CONFIG_EXTENSION_BLOCKING_MODE === "WHITELIST") {
 +        $allowed = in_array($ext, unserialize(CONFIG_ALLOWED_EXTENSIONS));
 +    }else{
 +        $allowed = !in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS));
 +    }
 +
 +    if(!$allowed){
 +        if($type==='normal'){
 +            include_once(CONFIG_ROOT_PATH.'error_meow.php');
 +            exit(0);
 +        }else{
 +            exit('File type not allowed.');
 +        }
 +    }
 +}