@ -103,7 +103,8 @@ void Request::Clear()
notify_code = 0 ;
browser_msie = false ;
redirect_to . clear ( ) ;
x_sendfile . clear ( ) ;
send_as_attachment = false ;
plugin . Call ( WINIX_REQUEST_CLEAR ) ;
}
@ -409,6 +410,9 @@ void Request::SendSessionCookie()
void Request : : SendHeaders ( bool compressing , Header header )
{
if ( send_as_attachment )
FCGX_PutS ( " Content-Disposition: attachment \r \n " , out ) ;
if ( ! redirect_to . empty ( ) )
{
FCGX_PutS ( " Status: 301 Moved Permanently \r \n " , out ) ;
@ -416,6 +420,13 @@ void Request::SendHeaders(bool compressing, Header header)
log < < log2 < < " Redirect to: " < < redirect_to < < logend ;
}
else
if ( ! x_sendfile . empty ( ) )
{
FCGX_FPrintF ( out , " X-LIGHTTPD-send-file: %s \r \n " , x_sendfile . c_str ( ) ) ;
FCGX_PutS ( " Status: 200 OK \r \n " , out ) ;
log < < log2 < < " Sending file: " < < x_sendfile < < logend ;
}
else
{
switch ( header )
{
@ -490,7 +501,7 @@ void Request::SendAll()
{
const std : : string & source = page . str ( ) ;
Header header = h_200 ;
bool compressing = data . compression & & role = = responder & &
bool compressing = data . compression & & role = = responder & & redirect_to . empty ( ) & & x_sendfile . empty ( ) & &
! browser_msie & & ! browser_konqueror & &
accept_encoding_parser . AcceptDeflate ( ) & & source . size ( ) > = 512 ;
@ -504,8 +515,8 @@ bool compressing = data.compression && role == responder &&
SendSessionCookie ( ) ;
SendHeaders ( compressing , header ) ;
if ( ! redirect_to . empty ( ) )
// if there is a redirect we do not send a content
if ( ! redirect_to . empty ( ) | | ! x_sendfile . empty ( ) )
// if there is a redirect or a file to send then we do not send a content
return ;
if ( header = = h_200 & & role = = authorizer & & is_item & & item . static_auth ! = Item : : static_none )
@ -852,8 +863,30 @@ bool Request::CanUseUpload(const Item & item, bool check_root)
if ( item . type ! = Item : : dir )
return false ;
// we must know where to store the file
if ( ! data . mounts . pmount )
return false ;
if ( data . mounts . pmount - > fs = = Mount : : simplefs & & data . static_simplefs_dir . empty ( ) )
{
log < < log1 < < " Request: can't use upload function, static_simplefs_dir must be set in the config file " < < logend ;
return false ;
}
if ( data . mounts . pmount - > fs = = Mount : : hashfs & & data . static_hashfs_dir . empty ( ) )
{
log < < log1 < < " Request: can't use upload function, static_hashfs_dir must be set in the config file " < < logend ;
return false ;
}
if ( data . static_tmp_dir . empty ( ) )
{
log < < log1 < < " Request: can't use upload function, static_tmp_dir must be set in the config file " < < logend ;
return false ;
}
if ( ! check_root & & request . session - > puser & & request . session - > puser - > super_user )
// super user can use mkdir everywhere
// super user can use upload everywhere
return true ;
if ( ! request . HasWriteAccess ( item ) )
@ -905,41 +938,105 @@ return false;
// !! dobrac lepsze nazwy dla tych dwoch metod
void Request : : MakePath ( std : : string & path )
bool Request : : MakePath SimpleFs ( std : : string & path , bool create_dir )
{
size_t i ;
path = data . static_auth_dir ;
size_t i ;
path = data . static_simplefs_dir ;
if ( path . empty ( ) )
{
log < < log1 < < " Request: static_simplefs_dir is not set in the config file " < < logend ;
return false ;
}
// skipping the first - the first is root
for ( i = 1 ; i < dir_table . size ( ) ; + + i )
{
path + = ' / ' ;
path + = dir_table [ i ] - > url ;
if ( create_dir & & ! CreateDir ( path , 0755 ) )
return false ;
}
path + = ' / ' ;
return true ;
}
bool Request : : MakeDirsOnFS ( )
// the path depends on id
bool Request : : MakePathHashFs ( std : : string & path , long id , bool create_dir )
{
size_t i ;
std : : string path = data . static_auth_dir ;
char buffer [ 50 ] ;
char * hash = buffe r;
// skipping the first - the first is root
for ( i = 1 ; i < dir_table . size ( ) ; + + i )
// get 'id' as hexadecimal
buffer [ 0 ] = ' 0 ' ;
sprintf ( buffer + 1 , " %lx " , ( unsigned long ) id ) ;
path = data . static_hashfs_dir ;
if ( path . empty ( ) )
{
path + = ' / ' ;
path + = dir_table [ i ] - > url ;
if ( ! IsFile ( path . c_str ( ) ) )
log < < log1 < < " Request: static_hashfs_dir is not set in the config file " < < logend ;
return false ;
}
path + = ' / ' ;
// make sure that the length is even
if ( ( strlen ( hash ) & 1 ) ! = 0 )
hash = buffer + 1 ; // the first character was our zero
// creating dirs without the last part
// the last part is a part of a file (not a directory)
for ( size_t i = 0 ; hash [ i ] ! = 0 ; i + = 2 )
{
path + = hash [ i ] ;
path + = hash [ i + 1 ] ;
if ( hash [ i + 2 ] ! = 0 )
{
if ( mkdir ( path . c_str ( ) , 0755 ) < 0 )
{
log < < log1 < < " Request: can't create the directory on fs: " < < path < < logend ;
if ( create_dir & & ! CreateDir ( path , 0755 ) )
return false ;
}
path + = ' / ' ;
}
}
// one character more to make sure the path is unique
// (we can have a directory without the character)
path + = " _ " ;
return true ;
}
// making a complete path to a request.item static file
bool Request : : MakePath ( std : : string & path , bool create_dir )
{
bool res ;
if ( data . mounts . pmount - > fs = = Mount : : hashfs )
{
res = MakePathHashFs ( path , request . item . id , create_dir ) ;
}
else
{
res = MakePathSimpleFs ( path , create_dir ) ;
}
if ( res )
path + = request . item . url ;
else
path . clear ( ) ;
return res ;
}