]>
git.p6c8.net - jirafeau_project.git/blob - lib/functions.php
f2a26e0858857031be5217987895c239463247fe
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
6 * Copyright (C) 2015 Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * Transform a string in a path by separating each letters by a '/'.
24 * @return path finishing with a '/'
30 for ( $i = 0 ; $i < strlen ( $s ); $i ++
) {
32 if (( $i +
1 ) %
$block_size == 0 ) {
36 if ( strlen ( $s ) %
$block_size != 0 ) {
43 * Convert base 16 to base 64
44 * @returns A string based on 64 characters (0-9, a-z, A-Z, "-" and "_")
46 function base_16_to_64 ( $num )
48 $m = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_' ;
49 $hex2bin = array ( '0000' , # 0
68 # Convert long hex string to bin.
70 for ( $i = 0 ; $i < $size ; $i ++
) {
71 $b .= $hex2bin [ hexdec ( $num [ $i ])];
73 # Convert long bin to base 64.
75 for ( $i = $size - 6 ; $i >= 0 ; $i -= 6 ) {
76 $o = $m [ bindec ( substr ( $b , $i , 6 ))] . $o ;
78 # Some few bits remaining ?
79 if ( $i < 0 && $i > - 6 ) {
80 $o = $m [ bindec ( substr ( $b , 0 , $i +
6 ))] . $o ;
86 * Generate a random code.
87 * @param $l code length
88 * @return random code.
90 function jirafeau_gen_random ( $l )
97 for ( $i = 0 ; $i < $l ; $i ++
) {
98 $code .= dechex ( rand ( 0 , 15 ));
104 function jirafeau_gen_download_pass ( $length , $allowed_chars )
110 for ( $i = 0 ; $i < $length ; $i ++
) {
111 $pass .= $allowed_chars [ rand ( 0 , strlen ( $allowed_chars ) - 1 )];
119 if ( isset ( $_SERVER [ 'HTTPS' ])) {
120 if ( 'on' == strtolower ( $_SERVER [ 'HTTPS' ]) ||
121 '1' == $_SERVER [ 'HTTPS' ]) {
124 } elseif ( isset ( $_SERVER [ 'SERVER_PORT' ]) && ( '443' == $_SERVER [ 'SERVER_PORT' ])) {
126 } elseif ( isset ( $_SERVER [ 'HTTP_X_FORWARDED_PROTO' ])) {
127 if ( $_SERVER [ 'HTTP_X_FORWARDED_PROTO' ] == 'https' ) {
134 function jirafeau_human_size ( $octets )
136 $u = array ( 'B' , 'KB' , 'MB' , 'GB' , 'TB' );
137 $o = max ( $octets , 0 );
138 $p = min ( floor (( $o ?
log ( $o ) : 0 ) / log ( 1024 )), count ( $u ) - 1 );
140 return round ( $o , 1 ) . $u [ $p ];
143 // Convert UTC timestamp to a datetime field
144 function jirafeau_get_datetimefield ( $timestamp )
146 $content = '<span class="datetime" data-datetime="' . strftime ( ' %Y - %m - %d %H : %M ' , $timestamp ) . '">'
147 . strftime ( ' %Y - %m - %d %H : %M ' , $timestamp ) . ' (GMT)</span>' ;
151 function jirafeau_fatal_error ( $errorText , $cfg = array ())
153 echo '<div class="error"><h2>Error</h2><p>' . $errorText . '</p></div>' ;
154 require ( JIRAFEAU_ROOT
. 'lib/template/footer.php' );
158 function jirafeau_clean_rm_link ( $link )
161 if ( file_exists ( VAR_LINKS
. $p . $link )) {
162 unlink ( VAR_LINKS
. $p . $link );
164 $parse = VAR_LINKS
. $p ;
166 while ( file_exists ( $parse )
167 && ( $scan = scandir ( $parse ))
168 && count ( $scan ) == 2 // '.' and '..' folders => empty.
169 && basename ( $parse ) != basename ( VAR_LINKS
)) {
171 $parse = substr ( $parse , 0 , strlen ( $parse ) - strlen ( basename ( $parse )) - 1 );
175 function jirafeau_clean_rm_file ( $hash )
178 $f = VAR_FILES
. $p . $hash ;
179 if ( file_exists ( $f ) && is_file ( $f )) {
182 if ( file_exists ( $f . '_count' ) && is_file ( $f . '_count' )) {
183 unlink ( $f . '_count' );
185 $parse = VAR_FILES
. $p ;
187 while ( file_exists ( $parse )
188 && ( $scan = scandir ( $parse ))
189 && count ( $scan ) == 2 // '.' and '..' folders => empty.
190 && basename ( $parse ) != basename ( VAR_FILES
)) {
192 $parse = substr ( $parse , 0 , strlen ( $parse ) - strlen ( basename ( $parse )) - 1 );
197 * transforms a php.ini string representing a value in an integer
198 * @param $value the value from php.ini
199 * @returns an integer for this value
201 function jirafeau_ini_to_bytes ( $value )
203 $modifier = substr ( $value , - 1 );
204 $bytes = substr ( $value , 0 , - 1 );
205 switch ( strtoupper ( $modifier )) {
207 return intval ( $value );
228 * gets the maximum upload size according to php.ini
229 * @returns the maximum upload size in bytes
231 function jirafeau_get_max_upload_size_bytes ()
234 jirafeau_ini_to_bytes ( ini_get ( 'post_max_size' )),
235 jirafeau_ini_to_bytes ( ini_get ( 'upload_max_filesize' ))
240 * gets the maximum upload size according to php.ini
241 * @returns the maximum upload size string
243 function jirafeau_get_max_upload_size ()
245 return jirafeau_human_size ( jirafeau_get_max_upload_size_bytes ());
249 * get the maximal upload size for a data chunk in async uploads
250 * @param max_upload_chunk_size_bytes
252 function jirafeau_get_max_upload_chunk_size_bytes ( $max_upload_chunk_size_bytes = 0 )
254 if ( $max_upload_chunk_size_bytes == 0 ) {
255 $size = jirafeau_get_max_upload_size_bytes ();
256 // Jirafeau must choose an arbitrary number as PHP config does not give any limit nor $max_upload_chunk_size_bytes
258 return 10000000 ; // 10MB
263 jirafeau_get_max_upload_size_bytes (),
264 $max_upload_chunk_size_bytes
267 return $max_upload_chunk_size_bytes ;
273 * gets a string explaining the error
274 * @param $code the error code
275 * @returns a string explaining the error
277 function jirafeau_upload_errstr ( $code )
280 case UPLOAD_ERR_INI_SIZE
:
281 case UPLOAD_ERR_FORM_SIZE
:
282 return t ( 'Your file exceeds the maximum authorized file size. ' );
284 case UPLOAD_ERR_PARTIAL
:
285 case UPLOAD_ERR_NO_FILE
:
287 t ( 'Your file was not uploaded correctly. You may succeed in retrying. ' );
289 case UPLOAD_ERR_NO_TMP_DIR
:
290 case UPLOAD_ERR_CANT_WRITE
:
291 case UPLOAD_ERR_EXTENSION
:
292 return t ( 'Internal error. You may not succeed in retrying. ' );
294 return t ( 'Unknown error. ' );
297 /** Remove link and it's file
298 * @param $link the link's name (hash)
301 function jirafeau_delete_link ( $link )
303 $l = jirafeau_get_link ( $link );
308 jirafeau_clean_rm_link ( $link );
314 if ( file_exists ( VAR_FILES
. $p . $hash . '_count' )) {
315 $content = file ( VAR_FILES
. $p . $hash . '_count' );
316 $counter = trim ( $content [ 0 ]);
321 $handle = fopen ( VAR_FILES
. $p . $hash . '_count' , 'w' );
322 fwrite ( $handle , $counter );
327 jirafeau_clean_rm_file ( $hash );
332 * Delete a file and it's links.
334 function jirafeau_delete_file ( $hash )
337 /* Get all links files. */
338 $stack = array ( VAR_LINKS
);
339 while (( $d = array_shift ( $stack )) && $d != null ) {
342 foreach ( $dir as $node ) {
343 if ( strcmp ( $node , '.' ) == 0 ||
strcmp ( $node , '..' ) == 0 ||
344 preg_match ( '/\.tmp/i' , " $node " )) {
348 if ( is_dir ( $d . $node )) {
349 /* Push new found directory. */
350 $stack [] = $d . $node . '/' ;
351 } elseif ( is_file ( $d . $node )) {
352 /* Read link informations. */
353 $l = jirafeau_get_link ( basename ( $node ));
357 if ( $l [ 'hash' ] == $hash ) {
359 jirafeau_delete_link ( $node );
364 jirafeau_clean_rm_file ( $hash );
369 /** hash file's content
370 * @param $method hash method, see 'file_hash' option. Valid methods are 'md5', 'md5_outside' or 'random'
371 * @param $file_path file to hash
372 * @returns hash string
374 function jirafeau_hash_file ( $method , $file_path )
378 return jirafeau_md5_outside ( $file_path );
380 return md5_file ( $file_path );
382 return jirafeau_gen_random ( 32 );
384 return md5_file ( $file_path );
387 /** hash part of file: start, end and size.
388 * This is a partial file hash, faster but weaker.
389 * @param $file_path file to hash
390 * @returns hash string
392 function jirafeau_md5_outside ( $file_path )
395 $handle = fopen ( $file_path , "r" );
396 if ( $handle === false ) {
399 $size = filesize ( $file_path );
400 if ( $size === false ) {
403 $first = fread ( $handle , 64 );
404 if ( $first === false ) {
407 if ( fseek ( $handle , $size < 64 ?
0 : $size - 64 ) == - 1 ) {
410 $last = fread ( $handle , 64 );
411 if ( $last === false ) {
414 $out = md5 ( $first . $last . $size );
421 * handles an uploaded file
422 * @param $file the file struct given by $_FILE[]
423 * @param $one_time_download is the file a one time download ?
424 * @param $key if not empty, protect the file with this key
425 * @param $time the time of validity of the file
426 * @param $ip uploader's ip
427 * @param $crypt boolean asking to crypt or not
428 * @param $link_name_length size of the link name
429 * @returns an array containing some information
430 * 'error' => information on possible errors
431 * 'link' => the link name of the uploaded file
432 * 'delete_link' => the link code to delete file
434 function jirafeau_upload ( $file , $one_time_download , $key , $time , $ip , $crypt , $link_name_length , $file_hash_method )
436 if ( empty ( $file [ 'tmp_name' ]) ||
! is_uploaded_file ( $file [ 'tmp_name' ])) {
439 array ( 'has_error' => true ,
440 'why' => jirafeau_upload_errstr ( $file [ 'error' ])),
442 'delete_link' => '' ));
445 /* array representing no error */
446 $noerr = array ( 'has_error' => false , 'why' => '' );
448 /* Crypt file if option is enabled. */
451 if ( $crypt == true && !( extension_loaded ( 'mcrypt' ) == true )) {
452 error_log ( "PHP extension mcrypt not loaded, won't encrypt in Jirafeau" );
454 if ( $crypt == true && extension_loaded ( 'mcrypt' ) == true ) {
455 $crypt_key = jirafeau_encrypt_file ( $file [ 'tmp_name' ], $file [ 'tmp_name' ]);
456 if ( strlen ( $crypt_key ) > 0 ) {
461 /* file information */
462 $hash = jirafeau_hash_file ( $file_hash_method , $file [ 'tmp_name' ]);
463 $name = str_replace ( NL
, '' , trim ( $file [ 'name' ]));
464 $mime_type = $file [ 'type' ];
465 $size = $file [ 'size' ];
467 /* does file already exist ? */
470 if ( file_exists ( VAR_FILES
. $p . $hash )) {
471 $rc = unlink ( $file [ 'tmp_name' ]);
472 } elseif (( file_exists ( VAR_FILES
. $p ) || @mkdir
( VAR_FILES
. $p , 0755 , true ))
473 && move_uploaded_file ( $file [ 'tmp_name' ], VAR_FILES
. $p . $hash )) {
479 array ( 'has_error' => true ,
480 'why' => t ( 'INTERNAL_ERROR_DEL' )),
482 'delete_link' => '' ));
485 /* Increment or create count file. */
487 if ( file_exists ( VAR_FILES
. $p . $hash . '_count' )) {
488 $content = file ( VAR_FILES
. $p . $hash . '_count' );
489 $counter = trim ( $content [ 0 ]);
492 $handle = fopen ( VAR_FILES
. $p . $hash . '_count' , 'w' );
493 fwrite ( $handle , $counter );
496 /* Create delete code. */
497 $delete_link_code = jirafeau_gen_random ( 5 );
499 /* hash password or empty. */
502 $password = md5 ( $key );
505 /* create link file */
506 $link_tmp_name = VAR_LINKS
. $hash . rand ( 0 , 10000 ) . '.tmp' ;
507 $handle = fopen ( $link_tmp_name , 'w' );
510 $name . NL
. $mime_type . NL
. $size . NL
. $password . NL
. $time .
511 NL
. $hash . NL
. ( $one_time_download ?
'O' : 'R' ) . NL
. time () .
512 NL
. $ip . NL
. $delete_link_code . NL
. ( $crypted ?
'C' : 'O' )
515 $hash_link = substr ( base_16_to_64 ( md5_file ( $link_tmp_name )), 0 , $link_name_length );
516 $l = s2p ( " $hash_link " );
517 if (! @mkdir
( VAR_LINKS
. $l , 0755 , true ) ||
518 ! rename ( $link_tmp_name , VAR_LINKS
. $l . $hash_link )) {
519 if ( file_exists ( $link_tmp_name )) {
520 unlink ( $link_tmp_name );
525 $handle = fopen ( VAR_FILES
. $p . $hash . '_count' , 'w' );
526 fwrite ( $handle , $counter );
529 jirafeau_clean_rm_file ( $hash_link );
533 array ( 'has_error' => true ,
534 'why' => t ( 'Internal error during file creation. ' )),
536 'delete_link' => '' );
538 return array ( 'error' => $noerr ,
539 'link' => $hash_link ,
540 'delete_link' => $delete_link_code ,
541 'crypt_key' => $crypt_key );
545 * Tells if a mime-type is viewable in a browser
546 * @param $mime the mime type
547 * @returns a boolean telling if a mime type is viewable
549 function jirafeau_is_viewable ( $mime )
552 $viewable = array ( 'image' , 'video' , 'audio' );
553 $decomposed = explode ( '/' , $mime );
554 if ( in_array ( $decomposed [ 0 ], $viewable ) && strpos ( $mime , 'image/svg+xml' ) === false ) {
557 $viewable = array ( 'text/plain' );
558 if ( in_array ( $mime , $viewable )) {
565 // Error handling functions.
566 //! Global array that contains all registered errors.
567 $error_list = array ();
570 * Adds an error to the list of errors.
571 * @param $title the error's title
572 * @param $description is a human-friendly description of the problem.
574 function add_error ( $title , $description )
577 $error_list [] = '<p>' . $title . '<br />' . $description . '</p>' ;
581 * Informs whether any error has been registered yet.
582 * @return true if there are errors.
587 return ! empty ( $error_list );
591 * Displays all the errors.
593 function show_errors ()
597 echo '<div class="error">' ;
598 foreach ( $error_list as $error ) {
605 function check_errors ( $cfg )
607 if (!( $cfg [ 'installation_done' ] === true )) {
608 if ( file_exists ( JIRAFEAU_ROOT
. 'install.php' )) {
609 header ( 'Location: install.php' );
612 add_error ( t ( 'INSTALL_FILE_NOT_FOUND_TITLE' ), t ( 'INSTALL_FILE_NOT_FOUND_DESC' ));
616 if (! is_writable ( VAR_FILES
)) {
617 add_error ( t ( 'FILE_DIR_W' ), VAR_FILES
);
620 if (! is_writable ( VAR_LINKS
)) {
621 add_error ( t ( 'LINK_DIR_W' ), VAR_LINKS
);
624 if (! is_writable ( VAR_ASYNC
)) {
625 add_error ( t ( 'ASYNC_DIR_W' ), VAR_ASYNC
);
628 if ( $cfg [ 'enable_crypt' ] && $cfg [ 'litespeed_workaround' ]) {
629 add_error ( t ( 'INCOMPATIBLE_OPTIONS_W' ), 'enable_crypt=true<br>litespeed_workaround=true' );
632 if ( $cfg [ 'one_time_download' ] && $cfg [ 'litespeed_workaround' ]) {
633 add_error ( t ( 'INCOMPATIBLE_OPTIONS_W' ), 'one_time_download=true<br>litespeed_workaround=true' );
638 * Read link information
639 * @return array containing information.
641 function jirafeau_get_link ( $hash )
644 $link = VAR_LINKS
. s2p ( " $hash " ) . $hash ;
646 if (! file_exists ( $link )) {
651 $out [ 'file_name' ] = trim ( $c [ 0 ]);
652 $out [ 'mime_type' ] = trim ( $c [ 1 ]);
653 $out [ 'file_size' ] = trim ( $c [ 2 ]);
654 $out [ 'key' ] = trim ( $c [ 3 ], NL
);
655 $out [ 'time' ] = trim ( $c [ 4 ]);
656 $out [ 'hash' ] = trim ( $c [ 5 ]);
657 $out [ 'onetime' ] = trim ( $c [ 6 ]);
658 $out [ 'upload_date' ] = trim ( $c [ 7 ]);
659 $out [ 'ip' ] = trim ( $c [ 8 ]);
660 $out [ 'link_code' ] = trim ( $c [ 9 ]);
661 $out [ 'crypted' ] = trim ( $c [ 10 ]) == 'C' ;
667 * List files in admin interface.
669 function jirafeau_admin_list ( $name , $file_hash , $link_hash )
671 echo '<fieldset><legend>' ;
673 echo t ( 'FILENAME' ) . ": " . jirafeau_escape ( $name );
675 if (! empty ( $file_hash )) {
676 echo t ( 'FILE' ) . ": " . jirafeau_escape ( $file_hash );
678 if (! empty ( $link_hash )) {
679 echo t ( 'LINK' ) . ": " . jirafeau_escape ( $link_hash );
681 if ( empty ( $name ) && empty ( $file_hash ) && empty ( $link_hash )) {
688 echo '<th>' . t ( 'ACTION' ) . '</th>' ;
691 /* Get all links files. */
692 $stack = array ( VAR_LINKS
);
693 while (( $d = array_shift ( $stack )) && $d != null ) {
695 foreach ( $dir as $node ) {
696 if ( strcmp ( $node , '.' ) == 0 ||
strcmp ( $node , '..' ) == 0 ||
697 preg_match ( '/\.tmp/i' , " $node " )) {
700 if ( is_dir ( $d . $node )) {
701 /* Push new found directory. */
702 $stack [] = $d . $node . '/' ;
703 } elseif ( is_file ( $d . $node )) {
704 /* Read link information. */
705 $l = jirafeau_get_link ( $node );
711 if (! empty ( $name ) && ! @preg_match
( "/ $name /i" , jirafeau_escape ( $l [ 'file_name' ]))) {
714 if (! empty ( $file_hash ) && $file_hash != $l [ 'hash' ]) {
717 if (! empty ( $link_hash ) && $link_hash != $node ) {
720 /* Print link information. */
723 '<strong><a id="upload_link" href="f.php?h=' . jirafeau_escape ( $node ) . '" title="' .
724 t ( 'DL_PAGE' ) . '">' . jirafeau_escape ( $l [ 'file_name' ]) . '</a></strong><br/>' ;
725 echo t ( 'TYPE' ) . ': ' . jirafeau_escape ( $l [ 'mime_type' ]) . '<br/>' ;
726 echo t ( 'SIZE' ) . ': ' . jirafeau_human_size ( $l [ 'file_size' ]) . '<br>' ;
727 echo t ( 'EXPIRE' ) . ': ' . ( $l [ 'time' ] == - 1 ?
'∞' : jirafeau_get_datetimefield ( $l [ 'time' ])) . '<br/>' ;
728 echo t ( 'ONETIME' ) . ': ' . ( $l [ 'onetime' ] == 'O' ?
'Yes' : 'No' ) . '<br/>' ;
729 echo t ( 'UPLOAD_DATE' ) . ': ' . jirafeau_get_datetimefield ( $l [ 'upload_date' ]) . '<br/>' ;
730 if ( strlen ( $l [ 'ip' ]) > 0 ) {
731 echo t ( 'ORIGIN' ) . ': ' . $l [ 'ip' ] . '<br/>' ;
734 echo '<form method="post">' .
735 '<input type = "hidden" name = "action" value = "download"/>' .
736 '<input type = "hidden" name = "link" value = "' . $node . '"/>' .
737 jirafeau_admin_csrf_field () .
738 '<input type = "submit" value = "' . t ( 'DL' ) . '" />' .
740 '<form method="post">' .
741 '<input type = "hidden" name = "action" value = "delete_link"/>' .
742 '<input type = "hidden" name = "link" value = "' . $node . '"/>' .
743 jirafeau_admin_csrf_field () .
744 '<input type = "submit" value = "' . t ( 'DEL_LINK' ) . '" />' .
746 '<form method="post">' .
747 '<input type = "hidden" name = "action" value = "delete_file"/>' .
748 '<input type = "hidden" name = "hash" value = "' . $l [ 'hash' ] . '"/>' .
749 jirafeau_admin_csrf_field () .
750 '<input type = "submit" value = "' . t ( 'DEL_FILE_LINKS' ) . '" />' .
757 echo '</table></fieldset>' ;
761 * Clean expired files.
762 * @return number of cleaned files.
764 function jirafeau_admin_clean ()
767 /* Get all links files. */
768 $stack = array ( VAR_LINKS
);
769 while (( $d = array_shift ( $stack )) && $d != null ) {
772 foreach ( $dir as $node ) {
773 if ( strcmp ( $node , '.' ) == 0 ||
strcmp ( $node , '..' ) == 0 ||
774 preg_match ( '/\.tmp/i' , " $node " )) {
778 if ( is_dir ( $d . $node )) {
779 /* Push new found directory. */
780 $stack [] = $d . $node . '/' ;
781 } elseif ( is_file ( $d . $node )) {
782 /* Read link information. */
783 $l = jirafeau_get_link ( basename ( $node ));
787 $p = s2p ( $l [ 'hash' ]);
788 if ( $l [ 'time' ] > 0 && $l [ 'time' ] < time () ||
// expired
789 ! file_exists ( VAR_FILES
. $p . $l [ 'hash' ]) ||
// invalid
790 ! file_exists ( VAR_FILES
. $p . $l [ 'hash' ] . '_count' )) { // invalid
791 jirafeau_delete_link ( $node );
802 * Clean old async transfers.
803 * @return number of cleaned files.
805 function jirafeau_admin_clean_async ()
808 /* Get all links files. */
809 $stack = array ( VAR_ASYNC
);
810 while (( $d = array_shift ( $stack )) && $d != null ) {
813 foreach ( $dir as $node ) {
814 if ( strcmp ( $node , '.' ) == 0 ||
strcmp ( $node , '..' ) == 0 ||
815 preg_match ( '/\.tmp/i' , " $node " )) {
819 if ( is_dir ( $d . $node )) {
820 /* Push new found directory. */
821 $stack [] = $d . $node . '/' ;
822 } elseif ( is_file ( $d . $node )) {
823 /* Read async information. */
824 $a = jirafeau_get_async_ref ( basename ( $node ));
828 /* Delete transfers older than 1 hour. */
829 if ( time () - $a [ 'last_edited' ] > 3600 ) {
830 jirafeau_async_delete ( basename ( $node ));
840 * Better strval function for debug purposes
842 function jirafeau_strval ( $value )
844 if ( gettype ( $value ) == "boolean" ) {
845 return $value ?
'true' : 'false' ;
847 return strval ( $value );
851 * Show file/folder permissions
853 function jirafeau_fileperms ( $path )
855 $out = substr ( sprintf ( " %o " , @fileperms
( $path )), - 4 ) . ", " ;
856 $out .= "read " . ( is_readable ( $path ) ?
"OK" : "KO" ) . ", " ;
857 $out .= "write " . ( is_writable ( $path ) ?
"OK" : "KO" );
862 * Show some useful informations for bug reporting.
864 function jirafeau_admin_bug_report ( $cfg )
866 $out = "<fieldset><legend>" . t ( 'REPORTING_AN_ISSUE' ) . "</legend>" ;
867 $out .= "If you have a problem related to Jirafeau, please <a href='https://gitlab.com/mojo42/Jirafeau/-/issues'>open an issue</a>, explain your problem in english and copy-paste the following content:<br/><br/><code>" ;
869 $out .= "# Jirafeau<br/>" ;
870 $out .= "- version: " . JIRAFEAU_VERSION
. "<br/>" ;
871 $jirafeau_options = [
874 'litespeed_workaround' ,
879 'maximal_upload_size' ,
881 'max_upload_chunk_size_bytes'
883 foreach ( $jirafeau_options as & $o ) {
885 $out .= "- $o : " . jirafeau_strval ( $v ) . " (" . gettype ( $v ) . ")<br/>" ;
889 $out .= "# PHP options<br/>" ;
890 $out .= "- php version: " . phpversion () . "<br/>" ;
891 $out .= "- mcrypt version: " . phpversion ( 'mcrypt' ) . "<br/>" ;
894 'upload_max_filesize' ,
896 'max_execution_time' ,
899 foreach ( $php_options as & $o ) {
901 $out .= "- $o : " . jirafeau_strval ( $v ) . " (" . gettype ( $v ). ")<br/>" ;
903 $out .= "- can set_time_limit: " . ( set_time_limit ( 0 ) ?
"yes" : "no" ) . "<br/>" ;
906 $out .= "# File permissions<br/>" ;
907 $out .= "- 'var' folder permissions: " . jirafeau_fileperms ( $cfg [ 'var_root' ]) . "<br/>" ;
908 $out .= "- 'file' folder permissions: " . jirafeau_fileperms ( VAR_FILES
) . "<br/>" ;
909 $out .= "- 'links' folder permissions: " . jirafeau_fileperms ( VAR_LINKS
) . "<br/>" ;
910 $out .= "- 'async' folder permissions: " . jirafeau_fileperms ( VAR_ASYNC
) . "<br/>" ;
913 $out .= "# Server details<br/>" ;
914 $out .= "- server software: " . $_SERVER [ "SERVER_SOFTWARE" ] . "<br/>" ;
917 $out .= "# OS details<br/>" ;
918 $out .= "- OS: " . php_uname () . "<br/>" ;
921 $out .= "# Browser details<br/>" ;
922 $out .= "<script type='text/javascript' lang='Javascript'>
923 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
924 document.write('- html5 support: ' + (check_html5_file_api() ? 'yes' : 'no') + '<br/>');
925 document.write('- user agent: ' + navigator.userAgent + '<br/>');
930 $out .= "# Memory<br/>" ;
931 $out .= "- memory_get_peak_usage: " . jirafeau_human_size ( memory_get_peak_usage ()) . "<br/>" ;
933 $out .= "</code></fieldset>" ;
938 * Read async transfer information
939 * @return array containing information.
941 function jirafeau_get_async_ref ( $ref )
944 $refinfos = VAR_ASYNC
. s2p ( " $ref " ) . " $ref " ;
946 if (! file_exists ( $refinfos )) {
950 $c = file ( $refinfos );
951 $out [ 'file_name' ] = trim ( $c [ 0 ]);
952 $out [ 'mime_type' ] = trim ( $c [ 1 ]);
953 $out [ 'key' ] = trim ( $c [ 2 ], NL
);
954 $out [ 'time' ] = trim ( $c [ 3 ]);
955 $out [ 'onetime' ] = trim ( $c [ 4 ]);
956 $out [ 'ip' ] = trim ( $c [ 5 ]);
957 $out [ 'last_edited' ] = trim ( $c [ 6 ]);
958 $out [ 'next_code' ] = trim ( $c [ 7 ]);
963 * Delete async transfer information
965 function jirafeau_async_delete ( $ref )
968 if ( file_exists ( VAR_ASYNC
. $p . $ref )) {
969 unlink ( VAR_ASYNC
. $p . $ref );
971 if ( file_exists ( VAR_ASYNC
. $p . $ref . '_data' )) {
972 unlink ( VAR_ASYNC
. $p . $ref . '_data' );
974 $parse = VAR_ASYNC
. $p ;
976 while ( file_exists ( $parse )
977 && ( $scan = scandir ( $parse ))
978 && count ( $scan ) == 2 // '.' and '..' folders => empty.
979 && basename ( $parse ) != basename ( VAR_ASYNC
)) {
981 $parse = substr ( $parse , 0 , strlen ( $parse ) - strlen ( basename ( $parse )) - 1 );
986 * Init a new asynchronous upload.
987 * @param $filename Name of the file to send
988 * @param $one_time One time upload parameter
989 * @param $key eventual password (or blank)
990 * @param $time time limit
991 * @param $ip ip address of the client
992 * @return a string containing a temporary reference followed by a code or a string starting with 'Error'
994 function jirafeau_async_init ( $filename , $type , $one_time , $key , $time , $ip )
996 /* Create temporary folder. */
999 $code = jirafeau_gen_random ( 4 );
1001 $ref = jirafeau_gen_random ( 32 );
1002 $p = VAR_ASYNC
. s2p ( $ref );
1003 } while ( file_exists ( $p ));
1004 @mkdir
( $p , 0755 , true );
1005 if (! file_exists ( $p )) {
1006 return 'Error: cannot create async folder.' ;
1009 /* touch empty data file */
1010 $w_path = $p . $ref . '_data' ;
1013 /* md5 password or empty */
1016 $password = md5 ( $key );
1019 /* Store information. */
1021 $handle = fopen ( $p , 'w' );
1024 str_replace ( NL
, '' , trim ( $filename )) . NL
.
1025 str_replace ( NL
, '' , trim ( $type )) . NL
. $password . NL
.
1026 $time . NL
. ( $one_time ?
'O' : 'R' ) . NL
. $ip . NL
.
1027 time () . NL
. $code . NL
1031 return $ref . NL
. $code ;
1035 * Append a piece of file on the asynchronous upload.
1036 * @param $ref asynchronous upload reference
1037 * @param $file piece of data
1038 * @param $code client code for this operation
1039 * @param $max_file_size maximum allowed file size
1040 * @return a string containing a next code to use or a string starting with 'Error'
1042 function jirafeau_async_push ( $ref , $data , $code , $max_file_size )
1044 /* Get async infos. */
1045 $a = jirafeau_get_async_ref ( $ref );
1047 /* Check some errors. */
1048 if ( count ( $a ) == 0 ) {
1049 return "Error: cannot find transfer" ;
1051 if ( $a [ 'next_code' ] != " $code " ) {
1052 return "Error: bad transfer code" ;
1054 if ( $data [ 'error' ] != UPLOAD_ERR_OK
) {
1055 // Check error code in https://www.php.net/manual/en/features.file-upload.errors.php
1056 $data_details = print_r ( $data , true );
1057 return "Error: upload error: { $data_details }" ;
1059 if ( empty ( $data [ 'tmp_name' ])) {
1060 return "Error: missing tmp_name" ;
1062 if (! is_uploaded_file ( $data [ 'tmp_name' ])) {
1063 return "Error: tmp_name may not be uploaded" ;
1069 $r_path = $data [ 'tmp_name' ];
1070 $w_path = VAR_ASYNC
. $p . $ref . '_data' ;
1072 /* Check that file size is not above upload limit. */
1073 if ( $max_file_size > 0 &&
1074 filesize ( $r_path ) +
filesize ( $w_path ) > $max_file_size * 1024 * 1024 ) {
1075 jirafeau_async_delete ( $ref );
1076 return "Error: file size is above upload limit" ;
1079 /* Concatenate data. */
1080 $r = fopen ( $r_path , 'r' );
1081 $w = fopen ( $w_path , 'a' );
1083 if ( fwrite ( $w , fread ( $r , 1024 )) === false ) {
1086 jirafeau_async_delete ( $ref );
1087 return "Error: cannot write file" ;
1094 /* Update async file. */
1095 $code = jirafeau_gen_random ( 4 );
1096 $handle = fopen ( VAR_ASYNC
. $p . $ref , 'w' );
1099 $a [ 'file_name' ] . NL
. $a [ 'mime_type' ] . NL
. $a [ 'key' ] . NL
.
1100 $a [ 'time' ] . NL
. $a [ 'onetime' ] . NL
. $a [ 'ip' ] . NL
.
1101 time () . NL
. $code . NL
1108 * Finalize an asynchronous upload.
1109 * @param $ref asynchronous upload reference
1110 * @param $code client code for this operation
1111 * @param $crypt boolean asking to crypt or not
1112 * @param $link_name_length link name length
1113 * @return a string containing the download reference followed by a delete code or a string starting with 'Error'
1115 function jirafeau_async_end ( $ref , $code , $crypt , $link_name_length , $file_hash_method )
1117 /* Get async infos. */
1118 $a = jirafeau_get_async_ref ( $ref );
1120 ||
$a [ 'next_code' ] != " $code " ) {
1121 return "Error: bad code for ending transfer" ;
1124 /* Generate link infos. */
1125 $p = VAR_ASYNC
. s2p ( $ref ) . $ref . "_data" ;
1126 if (! file_exists ( $p )) {
1127 return "Error: referenced file does not exist" ;
1132 if ( $crypt == true && extension_loaded ( 'mcrypt' ) == true ) {
1133 $crypt_key = jirafeau_encrypt_file ( $p , $p );
1134 if ( strlen ( $crypt_key ) > 0 ) {
1139 $hash = jirafeau_hash_file ( $file_hash_method , $p );
1140 $size = filesize ( $p );
1142 $delete_link_code = jirafeau_gen_random ( 5 );
1144 /* File already exist ? */
1145 if (! file_exists ( VAR_FILES
. $np )) {
1146 @mkdir
( VAR_FILES
. $np , 0755 , true );
1148 if (! file_exists ( VAR_FILES
. $np . $hash )) {
1149 rename ( $p , VAR_FILES
. $np . $hash );
1152 /* Increment or create count file. */
1154 if ( file_exists ( VAR_FILES
. $np . $hash . '_count' )) {
1155 $content = file ( VAR_FILES
. $np . $hash . '_count' );
1156 $counter = trim ( $content [ 0 ]);
1159 $handle = fopen ( VAR_FILES
. $np . $hash . '_count' , 'w' );
1160 fwrite ( $handle , $counter );
1164 $link_tmp_name = VAR_LINKS
. $hash . rand ( 0 , 10000 ) . '.tmp' ;
1165 $handle = fopen ( $link_tmp_name , 'w' );
1168 $a [ 'file_name' ] . NL
. $a [ 'mime_type' ] . NL
. $size . NL
.
1169 $a [ 'key' ] . NL
. $a [ 'time' ] . NL
. $hash . NL
. $a [ 'onetime' ] . NL
.
1170 time () . NL
. $a [ 'ip' ] . NL
. $delete_link_code . NL
. ( $crypted ?
'C' : 'O' )
1173 $hash_link = substr ( base_16_to_64 ( md5_file ( $link_tmp_name )), 0 , $link_name_length );
1174 $l = s2p ( " $hash_link " );
1175 if (! @mkdir
( VAR_LINKS
. $l , 0755 , true )) {
1176 return "Error: cannot create folder in LINKS" ;
1178 if (! rename ( $link_tmp_name , VAR_LINKS
. $l . $hash_link )) {
1179 return "Error: cannot rename file in LINKS" ;
1182 /* Clean async upload. */
1183 jirafeau_async_delete ( $ref );
1184 return $hash_link . NL
. $delete_link_code . NL
. urlencode ( $crypt_key );
1187 function jirafeau_crypt_create_iv ( $base , $size )
1190 while ( strlen ( $iv ) < $size ) {
1193 $iv = substr ( $iv , 0 , $size );
1198 * Crypt file and returns decrypt key.
1199 * @param $fp_src file path to the file to crypt.
1200 * @param $fp_dst file path to the file to write crypted file (could be the same).
1201 * @return decrypt key composed of the key and the iv separated by a point ('.')
1203 function jirafeau_encrypt_file ( $fp_src , $fp_dst )
1205 $fs = filesize ( $fp_src );
1206 if ( $fs === false ||
$fs == 0 ||
!( extension_loaded ( 'mcrypt' ) == true )) {
1210 /* Prepare module. */
1211 $m = mcrypt_module_open ( 'rijndael-256' , '' , 'ofb' , '' );
1213 $crypt_key = jirafeau_gen_random ( 10 );
1214 $hash_key = md5 ( $crypt_key );
1215 $iv = jirafeau_crypt_create_iv ( $hash_key , mcrypt_enc_get_iv_size ( $m ));
1217 mcrypt_generic_init ( $m , $hash_key , $iv );
1219 $r = fopen ( $fp_src , 'r' );
1220 $w = fopen ( $fp_dst , 'c' );
1222 $to_enc = fread ( $r , 1024 );
1223 if ( strlen ( $to_enc ) > 0 ) {
1224 $enc = mcrypt_generic ( $m , $to_enc );
1225 if ( fwrite ( $w , $enc ) === false ) {
1233 mcrypt_generic_deinit ( $m );
1234 mcrypt_module_close ( $m );
1240 * @param $fp_src file path to the file to decrypt.
1241 * @param $fp_dst file path to the file to write decrypted file (could be the same).
1242 * @param $k string composed of the key and the iv separated by a point ('.')
1243 * @return key used to decrypt. a string of length 0 is returned if failed.
1245 function jirafeau_decrypt_file ( $fp_src , $fp_dst , $k )
1247 $fs = filesize ( $fp_src );
1248 if ( $fs === false ||
$fs == 0 ||
extension_loaded ( 'mcrypt' ) == false ) {
1253 $m = mcrypt_module_open ( 'rijndael-256' , '' , 'ofb' , '' );
1254 /* Extract key and iv. */
1256 $hash_key = md5 ( $crypt_key );
1257 $iv = jirafeau_crypt_create_iv ( $hash_key , mcrypt_enc_get_iv_size ( $m ));
1259 $r = fopen ( $fp_src , 'r' );
1260 $w = fopen ( $fp_dst , 'c' );
1262 $dec = mdecrypt_generic ( $m , fread ( $r , 1024 ));
1263 if ( fwrite ( $w , $dec ) === false ) {
1270 mcrypt_generic_deinit ( $m );
1271 mcrypt_module_close ( $m );
1276 * Check if Jirafeau is password protected for visitors.
1277 * @return true if Jirafeau is password protected, false otherwise.
1279 function jirafeau_has_upload_password ( $cfg )
1281 return count ( $cfg [ 'upload_password' ]) > 0 ;
1285 * Challenge password for a visitor.
1286 * @param $password password to be challenged
1287 * @return true if password is valid, false otherwise.
1289 function jirafeau_challenge_upload_password ( $cfg , $password )
1291 if (! jirafeau_has_upload_password ( $cfg )) {
1294 foreach ( $cfg [ 'upload_password' ] as $p ) {
1295 if ( $password == $p ) {
1303 * Test if the given IP is whitelisted by the given list.
1305 * @param $allowedIpList array of allowed IPs
1306 * @param $challengedIp IP to be challenged
1307 * @return true if IP is authorized, false otherwise.
1309 function jirafeau_challenge_ip ( $allowedIpList , $challengedIp )
1311 foreach ( $allowedIpList as $i ) {
1312 if ( $i == $challengedIp ) {
1315 // CIDR test for IPv4 only.
1316 if ( strpos ( $i , '/' ) !== false ) {
1317 list ( $subnet , $mask ) = explode ( '/' , $i );
1318 if (( ip2long ( $challengedIp ) & ~
(( 1 << ( 32 - $mask )) - 1 )) == ip2long ( $subnet )) {
1327 * Check if Jirafeau has a restriction on the IP address for uploading.
1328 * @return true if uploading is IP restricted, false otherwise.
1330 function jirafeau_upload_has_ip_restriction ( $cfg )
1332 return count ( $cfg [ 'upload_ip' ]) > 0 ;
1336 * Test if visitor's IP is authorized to upload at all.
1338 * @param $cfg configuration
1339 * @param $challengedIp IP to be challenged
1340 * @return true if IP is authorized, false otherwise.
1342 function jirafeau_challenge_upload_ip ( $cfg , $challengedIp )
1344 // If no IP address have been listed, allow upload from any IP
1345 if (! jirafeau_upload_has_ip_restriction ( $cfg )) {
1348 return jirafeau_challenge_ip ( $cfg [ 'upload_ip' ], $challengedIp );
1352 * Test if visitor's IP is authorized to upload without a password.
1354 * @param $cfg configuration
1355 * @param $challengedIp IP to be challenged
1356 * @return true if IP is authorized, false otherwise.
1358 function jirafeau_challenge_upload_ip_without_password ( $cfg , $challengedIp )
1360 return jirafeau_challenge_ip ( $cfg [ 'upload_ip_nopassword' ], $challengedIp );
1364 * Test if visitor's IP is authorized or password is supplied and authorized
1365 * @param $ip IP to be challenged
1366 * @param $password password to be challenged
1367 * @return true if access is valid, false otherwise.
1369 function jirafeau_challenge_upload ( $cfg , $ip , $password )
1371 return jirafeau_challenge_upload_ip_without_password ( $cfg , $ip ) ||
1372 (! jirafeau_has_upload_password ( $cfg ) && ! jirafeau_upload_has_ip_restriction ( $cfg )) ||
1373 ( jirafeau_challenge_upload_password ( $cfg , $password ) && jirafeau_challenge_upload_ip ( $cfg , $ip ));
1376 /** Tell if we have some HTTP headers generated by a proxy */
1377 function has_http_forwarded ()
1380 ! empty ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]) ||
1381 ! empty ( $_SERVER [ 'http_X_forwarded_for' ]);
1385 * Generate IP list from HTTP headers generated by a proxy
1386 * @return array of IP strings
1388 function get_ip_list_http_forwarded ()
1391 if (! empty ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ])) {
1392 $l = explode ( ',' , $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]);
1396 foreach ( $l as $ip ) {
1397 array_push ( $ip_list , preg_replace ( '/\s+/' , '' , $ip ));
1400 if (! empty ( $_SERVER [ 'http_X_forwarded_for' ])) {
1401 $l = explode ( ',' , $_SERVER [ 'http_X_forwarded_for' ]);
1402 foreach ( $l as $ip ) {
1403 // Separate IP from port
1404 $ipa = explode ( ':' , $ip );
1405 if ( $ipa === false ) {
1409 array_push ( $ip_list , preg_replace ( '/\s+/' , '' , $ip ));
1416 * Get the ip address of the client from REMOTE_ADDR
1417 * or from HTTP_X_FORWARDED_FOR if behind a proxy
1418 * @returns the client ip address
1420 function get_ip_address ( $cfg )
1422 $remote = $_SERVER [ 'REMOTE_ADDR' ];
1423 if ( count ( $cfg [ 'proxy_ip' ]) == 0 ||
! has_http_forwarded ()) {
1427 $ip_list = get_ip_list_http_forwarded ();
1428 if ( count ( $ip_list ) == 0 ) {
1432 foreach ( $cfg [ 'proxy_ip' ] as $proxy_ip ) {
1433 if ( $remote != $proxy_ip ) {
1436 // Take the last IP (the one which has been set by the defined proxy).
1437 return end ( $ip_list );
1443 * Convert hexadecimal string to base64
1445 function hex_to_base64 ( $hex )
1448 foreach ( str_split ( $hex , 2 ) as $pair ) {
1449 $b .= chr ( hexdec ( $pair ));
1451 return base64_encode ( $b );
1455 * Replace markers in templates.
1457 * Available markers have the scheme "###MARKERNAME###".
1459 * @param $content string Template text with markers
1460 * @param $htmllinebreaks boolean Convert linebreaks to BR-Tags
1461 * @return Template with replaced markers
1463 function jirafeau_replace_markers ( $content , $htmllinebreaks = false )
1466 '/###ORGANISATION###/' ,
1467 '/###CONTACTPERSON###/' ,
1470 $replacements = array (
1471 $GLOBALS [ 'cfg' ][ 'organisation' ],
1472 $GLOBALS [ 'cfg' ][ 'contactperson' ],
1473 $GLOBALS [ 'cfg' ][ 'web_root' ]
1475 $content = preg_replace ( $patterns , $replacements , $content );
1477 if ( true === $htmllinebreaks ) {
1478 $content = nl2br ( $content );
1484 function jirafeau_escape ( $string )
1486 return htmlspecialchars ( $string , ENT_QUOTES
);
1489 function jirafeau_admin_session_start ()
1491 $_SESSION [ 'admin_auth' ] = true ;
1492 $_SESSION [ 'admin_csrf' ] = md5 ( uniqid ( mt_rand (), true ));
1495 function jirafeau_session_end ()
1497 $_SESSION = array ();
1501 function jirafeau_admin_session_logged ()
1503 return isset ( $_SESSION [ 'admin_auth' ]) &&
1504 isset ( $_SESSION [ 'admin_csrf' ]) &&
1505 isset ( $_POST [ 'admin_csrf' ]) &&
1506 $_SESSION [ 'admin_auth' ] === true &&
1507 $_SESSION [ 'admin_csrf' ] === $_POST [ 'admin_csrf' ];
1510 function jirafeau_admin_csrf_field ()
1512 return "<input type='hidden' name='admin_csrf' value='" . $_SESSION [ 'admin_csrf' ] . "'/>" ;
1515 function jirafeau_user_session_start ()
1517 $_SESSION [ 'user_auth' ] = true ;
1520 function jirafeau_user_session_logged ()
1522 return isset ( $_SESSION [ 'user_auth' ]) &&
1523 $_SESSION [ 'user_auth' ] === true ;
1526 function jirafeau_dir_size ( $dir )
1529 foreach ( glob ( rtrim ( $dir , '/' ). '/*' , GLOB_NOSORT
) as $entry ) {
1530 $size +
= is_file ( $entry ) ?
filesize ( $entry ) : jirafeau_dir_size ( $entry );
1535 function jirafeau_export_cfg ( $cfg )
1537 $content = '<?php' . NL
;
1538 $content .= '/* This file was generated by the install process. ' .
1539 'You can edit it. Please see config.original.php to understand the ' .
1540 'configuration items. */' . NL
;
1541 $content .= ' $cfg = ' . var_export ( $cfg , true ) . ';' ;
1543 $fileWrite = file_put_contents ( JIRAFEAU_CFG
, $content );
1545 if ( false === $fileWrite ) {
1546 jirafeau_fatal_error ( t ( 'Can not write local configuration file' ));
1550 function jirafeau_mkdir ( $path )
1552 return !(! file_exists ( $path ) && ! @mkdir
( $path , 0755 ));
1556 * Returns true whether the path is writable or we manage to make it
1557 * so, which essentially is the same thing.
1558 * @param $path is the file or directory to be tested.
1559 * @return true if $path is writable.
1561 function jirafeau_is_writable ( $path )
1563 /* "@" gets rid of error messages. */
1564 return is_writable ( $path ) || @chmod
( $path , 0777 );
1567 function jirafeau_check_var_dir ( $path )
1569 $mkdir_str1 = t ( 'CANNOT_CREATE_DIR' ) . ':' ;
1570 $mkdir_str2 = t ( 'MANUAL_CREATE' );
1571 $write_str1 = t ( 'DIR_NOT_W' ) . ':' ;
1572 $write_str2 = t ( 'You should give the write permission to the web server on ' .
1574 $solution_str = t ( 'HERE_SOLUTION' ) . ':' ;
1576 if (! jirafeau_mkdir ( $path ) ||
! jirafeau_is_writable ( $path )) {
1577 return array ( 'has_error' => true ,
1578 'why' => $mkdir_str1 . '<br /><code>' .
1579 $path . '</code><br />' . $solution_str .
1580 '<br />' . $mkdir_str2 );
1583 foreach ( array ( 'files' , 'links' , 'async' ) as $subdir ) {
1584 $subpath = $path . $subdir ;
1586 if (! jirafeau_mkdir ( $subpath ) ||
! jirafeau_is_writable ( $subpath )) {
1587 return array ( 'has_error' => true ,
1588 'why' => $mkdir_str1 . '<br /><code>' .
1589 $subpath . '</code><br />' . $solution_str .
1590 '<br />' . $mkdir_str2 );
1594 return array ( 'has_error' => false , 'why' => '' );
1597 function jirafeau_add_ending_slash ( $path )
1599 return $path . (( substr ( $path , - 1 ) == '/' ) ?
'' : '/' );
1602 function jirafeau_default_web_root ()
1604 return $_SERVER [ 'HTTP_HOST' ] . str_replace ( 'install.php' , '' , $_SERVER [ 'REQUEST_URI' ]);
patrick-canterino.de