From 4be12aa378f1142e4b7266e68037029e360017b4 Mon Sep 17 00:00:00 2001 From: Matthias Strubel Date: Mon, 5 Mar 2018 20:32:01 +0100 Subject: [PATCH] PHP Upload feature - series of bugfixes - Fixed a bunch of config file generation bugs - Increased static file upload in lighttpd to 3GB (for now static) - Set the new stream setting for upload - Clean up the tmp file on "share" as well - Ingore Warning if chmod feat. disabled (on FAT32 USB Stick relevant) --- piratebox/piratebox/bin/generate_config_files.sh | 12 ++++++------ piratebox/piratebox/conf/lighttpd/lighttpd.conf | 3 ++- .../piratebox/conf/piratebox_config.php.template | 2 +- piratebox/piratebox/init.d/piratebox | 1 + piratebox/piratebox/init.d/piratebox_alt | 1 + piratebox/piratebox/{ => www}/default/tpl_upload.php | 0 piratebox/piratebox/www/upload_handler/upload.php | 5 +++++ 7 files changed, 16 insertions(+), 8 deletions(-) rename piratebox/piratebox/{ => www}/default/tpl_upload.php (100%) diff --git a/piratebox/piratebox/bin/generate_config_files.sh b/piratebox/piratebox/bin/generate_config_files.sh index a1b6368..4a2dc3c 100755 --- a/piratebox/piratebox/bin/generate_config_files.sh +++ b/piratebox/piratebox/bin/generate_config_files.sh @@ -169,7 +169,7 @@ generate_lighttpd_env() { ) var.PIRATEBOX_HOSTNAME = \"$HOSTNAME\" - var.CONFDIR = \"$CONFDIR\" + var.CONFDIR = \"$CONFIG_PATH\" " > $LIGHTTPD_ENV_CONFIG } @@ -181,9 +181,9 @@ php_ini_entry(){ in_parm=$1 in_val=$2 - if grep -q "$in_parm" "$work_php_ini" ; + if grep -q "$in_parm" "$work_php_ini" ; then old_val=$( grep "$in_parm" "$work_php_ini" | head -n 1 ) - sed -e "s|${old_val}|${in_parm} = ${in_val}|g" "$work_php_ini" + sed -i -e "s|${old_val}|${in_parm} = ${in_val}|g" "$work_php_ini" else echo "ERROR php.ini : Old val. $in_parm not found" fi @@ -198,8 +198,8 @@ generate_php_ini(){ -e 's|^upload_max_filesize|;upload_max_filesize|g' \ -e 's|^post_max_size|;post_max_size|g' \ -e 's|^max_file_uploads|;max_file_uploads|g' \ - "${PIRATEBOX_FOLDER}/tmp/php.ini.original" > "$CONFDIR/php.ini" - work_php_ini="$CONFDIR/php.ini" + "${PIRATEBOX_FOLDER}/tmp/php.ini.original" > "$CONFIG_PATH/php.ini" + work_php_ini="$CONFIG_PATH/php.ini" php_ini_entry 'upload_tmp_dir' "$UPLOAD_TMP_FOLDER" php_ini_entry 'upload_max_filesize' "$UPLOAD_MAX_SIZE" @@ -215,7 +215,7 @@ generate_piratebox_php(){ -e "s|####OVERWRITE####|${UPLOAD_ALLOW_OVERWRITE}|g" \ -e "s|####DO_CHMOD####|${UPLOAD_DO_CHMOD}|g" \ -e "s|####CHMOD####|${UPLOAD_CHMOD}|g" \ - "$CONFDIR/piratebox_config.php.template" > "${PIRATEBOX_FOLDER}/www" + "$CONFIG_PATH/piratebox_config.php.template" > "${PIRATEBOX_FOLDER}/www/piratebox_config.php" } if [ -z $1 ] ; then diff --git a/piratebox/piratebox/conf/lighttpd/lighttpd.conf b/piratebox/piratebox/conf/lighttpd/lighttpd.conf index da2b112..e4e17fe 100644 --- a/piratebox/piratebox/conf/lighttpd/lighttpd.conf +++ b/piratebox/piratebox/conf/lighttpd/lighttpd.conf @@ -16,7 +16,8 @@ server.document-root = "/opt/piratebox/www" ## the device from dieing because OUT-OF-RAM exceptions ## in KB => 5MB server.upload-dirs = ( "/tmp" ) -server.max-request-size = 5120 +server.max-request-size = 3221225472 +server.stream-request-body = 2 server.errorlog = "/opt/piratebox/tmp/error.log" server.breakagelog = "/opt/piratebox/tmp/break.log" diff --git a/piratebox/piratebox/conf/piratebox_config.php.template b/piratebox/piratebox/conf/piratebox_config.php.template index 7447851..bed522d 100644 --- a/piratebox/piratebox/conf/piratebox_config.php.template +++ b/piratebox/piratebox/conf/piratebox_config.php.template @@ -8,7 +8,7 @@ # Upload enabled $config['upload_enabled'] = '####UPLOAD_ENABLED####' ; # Where to store -$config['upload_folder'] = ""####UPLOAD_FOLDER####; +$config['upload_folder'] = "####UPLOAD_FOLDER####"; # Rename dublicate files with suffix or overwrite it $config['allow_overwrite'] = '####OVERWRITE####' ; # Set permissions afterwards diff --git a/piratebox/piratebox/init.d/piratebox b/piratebox/piratebox/init.d/piratebox index 74f41f8..4a0e6b2 100755 --- a/piratebox/piratebox/init.d/piratebox +++ b/piratebox/piratebox/init.d/piratebox @@ -92,6 +92,7 @@ case "$1" in echo "Empty tmp folder" find $PIRATEBOX/tmp/ -mindepth 1 -exec rm {} \; + find $PIRATEBOX/share/tmp/ -mindepth 1 -exec rm {} \; # Captive Portal Housekeeping file in /tmp (ram) "$PIRATEBOX/bin/captive_notify_lease.sh" refresh diff --git a/piratebox/piratebox/init.d/piratebox_alt b/piratebox/piratebox/init.d/piratebox_alt index 21a25fa..3e4678c 100755 --- a/piratebox/piratebox/init.d/piratebox_alt +++ b/piratebox/piratebox/init.d/piratebox_alt @@ -85,6 +85,7 @@ case "$1" in echo "Empty tmp folder" find $PIRATEBOX/tmp/ -mindepth 1 -exec rm {} \; + find $PIRATEBOX/share/tmp/ -mindepth 1 -exec rm {} \; # Captive Portal Housekeeping file in /tmp (ram) "$PIRATEBOX/bin/captive_notify_lease.sh" refresh diff --git a/piratebox/piratebox/default/tpl_upload.php b/piratebox/piratebox/www/default/tpl_upload.php similarity index 100% rename from piratebox/piratebox/default/tpl_upload.php rename to piratebox/piratebox/www/default/tpl_upload.php diff --git a/piratebox/piratebox/www/upload_handler/upload.php b/piratebox/piratebox/www/upload_handler/upload.php index b2d8cac..53981b7 100755 --- a/piratebox/piratebox/www/upload_handler/upload.php +++ b/piratebox/piratebox/www/upload_handler/upload.php @@ -91,6 +91,11 @@ try { } $path = $config['upload_folder']. "/" . $filename ; + if ( $config['do_chmod'] == 'no' ) { + /* Ok, we want whatever a filepermission and we want to ignore Warnings from + * move_uploaded_file */ + error_reporting(E_ERROR | E_PARSE); + } if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) { if ( $config['do_chmod'] == 'yes' ) { // set proper permissions on the new file