Ticket #992: upload.php-t992.diff

File upload.php-t992.diff, 6.2 KB (added by INETvisio, 9 years ago)

Beispiel patch

  • admin/includes/classes/upload.php

     admin/includes/classes/upload.php | 61 +++++++++++++++++++++++++++++----------
     1 file changed, 45 insertions(+), 16 deletions(-)
    
    diff --git a/admin/includes/classes/upload.php b/admin/includes/classes/upload.php
    index 9584e4e..1fb6112 100644
    a b defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    2626      $this->set_destination($destination);
    2727      $this->set_permissions($permissions);
    2828      $this->set_extensions($extensions);
     29      $this->set_mime_types($mime_types);
    2930
    3031      if (xtc_not_null($this->file) && xtc_not_null($this->destination)) {
    3132        if ( ($this->parse() == true) && ($this->save() == true) ) {
    defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    3738    }
    3839
    3940    function parse() {
    40       global $messageStack;
    41      
     41
    4242      $file = array();
    4343
    4444      if (isset($_FILES[$this->file])) {
    defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    6868      if (isset($file['tmp_name']) && !empty($file['tmp_name']) && ($file['tmp_name'] != 'none') && is_uploaded_file($file['tmp_name'])) {
    6969        if (sizeof($this->mime_types) > 0) {
    7070          if (!in_array(strtolower($file['type']), $this->mime_types)) {
    71             $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error');
     71            $this->set_message(ERROR_FILETYPE_NOT_ALLOWED);
    7272            return false;
    7373          }
    7474        }
    7575        if (sizeof($this->extensions) > 0) {
    7676          if (!in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), $this->extensions)) {
    77             $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error');
     77            $this->set_message(ERROR_FILETYPE_NOT_ALLOWED);
    7878            return false;
    7979          }
    8080        }
    8181        //BOF - DokuMan - 2010-08-31 - disable upload of php files and htaccess/htpasswd to avoid uploading of malicious scripts
     82        /*
    8283        if (in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), array('php', 'php3', 'php4', 'php5', 'phtml'))) {
    83             $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error');
     84            $this->set_message(ERROR_FILETYPE_NOT_ALLOWED);
    8485            return false;
    8586        }
     87        */
    8688        if ($file['name'] == '.htaccess' || $file['name'] == '.htpasswd') {
    87             $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error');
     89            $this->set_message(ERROR_FILETYPE_NOT_ALLOWED);
    8890            return false;
    8991        }
    9092        //EOF - DokuMan - 2010-08-31 - disable upload of php files and htaccess/htpasswd to avoid uploading of malicious scripts
    defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    9597        return $this->check_destination();
    9698       
    9799      } else {
    98         if ($file['tmp_name']=='none') $messageStack->add_session(WARNING_NO_FILE_UPLOADED, 'warning');
     100        if ($file['tmp_name']=='none') $this->set_message(WARNING_NO_FILE_UPLOADED, 'warning');
    99101        return false;
    100102      }
    101103    }
    102104
    103105    function save() {
    104       global $messageStack;
    105106
    106107      if (substr($this->destination, -1) != '/') $this->destination .= '/';
    107108
    defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    114115          if (strstr(PRODUCT_IMAGE_THUMBNAIL_MERGE,'.gif') ||
    115116              strstr(PRODUCT_IMAGE_INFO_MERGE,'.gif') ||
    116117              strstr(PRODUCT_IMAGE_POPUP_MERGE,'.gif')) {
    117               $messageStack->add_session(ERROR_GIF_MERGE, 'error');
     118              $this->set_message(ERROR_GIF_MERGE);
    118119              return false;
    119120          }
    120121          // check if uploaded image = .gif
    121122          if (strstr($this->filename,'.gif')) {
    122            $messageStack->add_session(ERROR_GIF_UPLOAD, 'error');
     123           $this->set_message(ERROR_GIF_UPLOAD);
    123124           return false;
    124125          }
    125126
    defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    129130
    130131      if (move_uploaded_file($this->file['tmp_name'], $this->destination . $this->filename)) {
    131132        chmod($this->destination . $this->filename, $this->permissions);
    132         $messageStack->add_session(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
     133        $this->set_message(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
    133134        return true;
    134135       
    135136      } else {
    136         $messageStack->add_session(ERROR_FILE_NOT_SAVED, 'error');
     137        $this->set_message(ERROR_FILE_NOT_SAVED);
    137138        return false;
    138139      }
    139140    }
    defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    170171      }
    171172    }
    172173
     174        /**
     175         * Set mime types.
     176         * @since 2.0.1
     177         * @param string|array $mime_types Mime type(string) or types(array).
     178         */
     179        function set_mime_types($mime_types) {
     180                if (xtc_not_null($mime_types)) {
     181                        if (is_array($mime_types)) {
     182                                $this->mime_types = $mime_types;
     183                        } else {
     184                                $this->mime_types = array($mime_types);
     185                        }
     186                } else {
     187                        $this->mime_types = array();
     188                }
     189        }
     190
    173191    function check_destination() {
    174       global $messageStack;
    175192
    176193      if (!is_writeable($this->destination)) {
    177194        if (is_dir($this->destination)) {
    178           $messageStack->add_session(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error');
     195          $this->set_message(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination));
    179196        } else {
    180           $messageStack->add_session(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error');
     197          $this->set_message(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination));
    181198        }
    182199        return false;
    183200       
    defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'  
    186203      }
    187204    }
    188205
     206        /**
     207         * Set message.
     208         * @since 2.0.1
     209         * @param string $text Message text.
     210         * @param string $type (optional) Message type.
     211         */
     212        private function set_message($text, $type = 'error') {
     213                global $messageStack;
     214                if (is_object($messageStack)) {
     215                        $messageStack->add_session($text, $type);
     216                }
     217        }
     218
    189219  }
    190 ?>
    191  No newline at end of file