Changeset 962

Show
Ignore:
Timestamp:
03/04/2008 12:40:40 AM (3 years ago)
Author:
DotMG
Message:

This ticket can be seen as a COORDINATION ticket for #692 to trunk. But since {{files}} action in 1.1.7 is a somewhat enhanced version, the issue is taken differently.

  • actions/files/files.php : porting #692 to trunk
  • handlers/files.xml/files.xml.php : porting #692 to trunk and adding error messages.
  • lang/en/en.inc.php : More error messages.

refs #696

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/actions/files/files.php

    r736 r962  
    2727 * @uses        Wakka::HasAccess() 
    2828 * @uses        Wakka::IsAdmin() 
    29  * @uses        Wakka::MiniHref() 
    3029 * @uses        Wakka::htmlspecialchars_ent() 
     30 * @uses        Wakka::FormOpen() 
     31 * @uses        Wakka::FormClose() 
     32 * @uses        Wakka::SetConfigValue() 
     33 * @uses        Wakka::ReturnSafeHTML() 
     34 * @uses        Config::$upload_path 
    3135 * 
    3236 * @todo security: check file type, not only extension 
  • trunk/handlers/files.xml/files.xml.php

    r738 r962  
    1717 * @filesource 
    1818 * 
    19  * @uses        Wakka::GetConfigValue() 
     19 * @uses        mkdir_r() 
     20 * @uses        Wakka::SetConfigValue() 
    2021 * @uses        Wakka::GetPageTag() 
    2122 * @uses        Wakka::HasAccess() 
    2223 * @uses        Wakka::Href() 
    2324 * @uses        Wakka::IsAdmin() 
    24  * @uses        Wakka::redirect() 
     25 * @uses        Wakka::SetRedirectMessage() 
     26 * @uses        Wakka::Redirect() 
    2527 * @uses        Config::$upload_path 
     28 * @uses        Config::$root_page 
     29 * @uses        WIKKA_ERROR_ACL_READ_INFO 
     30 * 
    2631 * @todo        make shared download code for this and grab code handler 
    2732 */ 
     
    3843} 
    3944 
     45if (!isset($_GET['file']) || !isset($_GET['action']) || !is_string($_GET['file'])) 
     46{ 
     47        // invocation of files.xml must provide $_GET['file'] and $_GET['action']. 
     48        // todo: add an error message here: probably, ERROR_BAD_PARAMETERS should be splitted. 
     49        $this->Redirect(''); 
     50} 
     51if ('.' == $_GET['file']{0}) 
     52{ 
     53        $this->Redirect($this->Href(), ERROR_FILETYPE_NOT_ALLOWED); 
     54} 
    4055// do the action 
    4156switch ($_GET['action'])        # #312 
     
    4964                header("Content-Type: application/x-download"); 
    5065                header("Content-Disposition: attachment; filename=\"".urldecode($filename)."\""); 
    51                 if ($this->HasAccess('read')) 
     66                if (!file_exists($path)) 
    5267                { 
    53                         if (isset($_SERVER['HTTP_RANGE']) && 
    54                                 (preg_match('/^.*bytes[= ]+(\d+)-(\d+)\s*$/', $_SERVER['HTTP_RANGE'], $range)) && 
    55                                 ((int) $range[2] >= (int) $range[1]) 
    56                            ) 
    57                         { 
    58                                 $rstart = $range[1]; 
    59                                 $rend = $range[2]; 
    60                                 $fp = fopen($path, 'rb'); 
    61                                 fseek($fp, $rstart+SEEK_SET); 
    62                                 $data = fread($fp, $rend - $rstart + 1); 
    63                                 fclose($fp); 
    64                                 header('Content-Range: bytes '.$rstart.'-'.$rend.'/'.filesize($path)); 
    65                                 header('HTTP/1.1 206 Partial content'); 
    66                                 echo $data; 
    67                                 exit(); 
    68                         } 
    69                         //Header("Content-Length: ".filesize($path)); 
    70                         //Header("Connection: close"); 
    71                         @ob_end_clean(); 
    72                         @ob_end_clean(); 
     68                        $this->Redirect($this->Href(), sprintf(ERROR_NONEXISTENT_FILE, $_GET['file'])); 
     69                } 
     70                if (!$this->HasAccess('read')) 
     71                { 
     72                        // The user may have followed a link from email or external site, but he has no access to the page. 
     73                        // We redirect this user to the HomePage. 
     74                        $this->Redirect($this->Href('', $this->GetConfigValue('root_page')), WIKKA_ERROR_ACL_READ_INFO); 
     75                } 
     76                if (isset($_SERVER['HTTP_RANGE']) && 
     77                        (preg_match('/^.*bytes[= ]+(\d+)-(\d+)\s*$/', $_SERVER['HTTP_RANGE'], $range)) && 
     78                        ((int) $range[2] >= (int) $range[1]) 
     79                   ) 
     80                { 
     81                        $rstart = $range[1]; 
     82                        $rend = $range[2]; 
    7383                        $fp = fopen($path, 'rb'); 
    74                         while (!feof($fp)) 
    75                         { 
    76                                 $data = fread($fp, 4096); 
    77                                 echo $data; 
    78                         } 
     84                        fseek($fp, $rstart+SEEK_SET); 
     85                        $data = fread($fp, $rend - $rstart + 1); 
    7986                        fclose($fp); 
     87                        header('Content-Range: bytes '.$rstart.'-'.$rend.'/'.filesize($path)); 
     88                        header('HTTP/1.1 206 Partial content'); 
     89                        echo $data; 
    8090                        exit(); 
    8191                } 
     92                //Header("Content-Length: ".filesize($path)); 
     93                //Header("Connection: close"); 
     94                @ob_end_clean(); 
     95                @ob_end_clean(); 
     96                $fp = fopen($path, 'rb'); 
     97                while (!feof($fp)) 
     98                { 
     99                        $data = fread($fp, 4096); 
     100                        echo $data; 
     101                } 
     102                fclose($fp); 
     103                exit(); 
    82104        case 'delete': 
    83105                if ($this->IsAdmin()) 
    84106                { 
    85                         @unlink($upload_path.DIRECTORY_SEPARATOR.$_GET['file']); # #89, #312 // TODO if this is admin-only, why hide any errors? 
     107                        $delete_success = @unlink($upload_path.DIRECTORY_SEPARATOR.$_GET['file']); # #89, #312  
     108                        if (!$delete_success) 
     109                        { 
     110                                $this->SetRedirectMessage(ERROR_FILE_NOT_DELETED); 
     111                        } 
    86112                } 
    87                 print $this->redirect($this->Href()); 
    88113} 
     114print $this->Redirect($this->Href()); 
    89115?> 
  • trunk/lang/en/en.inc.php

    r953 r962  
    234234 
    235235/**#@+ 
    236  * Language constant used by the {@link files.php files} action 
     236 * Language constant used by the {@link files.php files action} and {@link handlers/files.xml/files.xml.php files.xml handler} 
    237237 */ 
    238238// files 
     
    244244define('ERROR_FILE_ALREADY_EXISTS', 'Sorry, a file named %s already exists.'); // %s - file name ref 
    245245define('ERROR_EXTENSION_NOT_ALLOWED', 'Sorry, files with this extension are not allowed.'); 
     246define('ERROR_FILETYPE_NOT_ALLOWED', 'Sorry, files of this type are not allowed.'); 
     247define('ERROR_FILE_NOT_DELETED', 'Sorry, the file could not be deleted!'); 
    246248define('ERROR_FILE_TOO_BIG', 'Attempted file upload was too big. Maximum allowed size is %s.'); // %s - allowed filesize 
    247249define('ERROR_NO_FILE_SELECTED', 'No file selected.');