diff --git a/update_firmware.sh b/update_firmware.sh index d09f96c..658ea6f 100755 --- a/update_firmware.sh +++ b/update_firmware.sh @@ -81,6 +81,32 @@ sudo chmod 755 /var/www/nebuleair_pro_4g/MPPT/*.py 2>/dev/null sudo chmod 755 /var/www/nebuleair_pro_4g/wifi/*.py 2>/dev/null check_status "File permissions update" +# Step 3b: Ensure Apache/PHP config allows file uploads +APACHE_MAIN_CONF="/etc/apache2/apache2.conf" +if grep -q '' "$APACHE_MAIN_CONF"; then + if ! sed -n '//,/<\/Directory>/p' "$APACHE_MAIN_CONF" | grep -q "AllowOverride All"; then + sed -i '//,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' "$APACHE_MAIN_CONF" + print_status "✓ AllowOverride All enabled for Apache" + APACHE_CHANGED=true + fi +fi + +PHP_INI=$(php -r "echo php_ini_loaded_file();" 2>/dev/null) +if [ -n "$PHP_INI" ]; then + CURRENT_UPLOAD=$(grep -oP 'upload_max_filesize = \K\d+' "$PHP_INI" 2>/dev/null) + if [ -n "$CURRENT_UPLOAD" ] && [ "$CURRENT_UPLOAD" -lt 50 ]; then + sed -i 's/upload_max_filesize = .*/upload_max_filesize = 50M/' "$PHP_INI" + sed -i 's/post_max_size = .*/post_max_size = 55M/' "$PHP_INI" + print_status "✓ PHP upload limits set to 50M" + APACHE_CHANGED=true + fi +fi + +if [ "${APACHE_CHANGED:-false}" = true ]; then + systemctl reload apache2 2>/dev/null + print_status "✓ Apache reloaded" +fi + # Step 4: Restart critical services if they exist print_status "" print_status "Step 4: Managing system services..." diff --git a/update_firmware_from_file.sh b/update_firmware_from_file.sh index 5e4bcfd..a80bb2a 100644 --- a/update_firmware_from_file.sh +++ b/update_firmware_from_file.sh @@ -118,6 +118,32 @@ chmod 755 "$TARGET_DIR/MPPT/"*.py 2>/dev/null chmod 755 "$TARGET_DIR/wifi/"*.py 2>/dev/null check_status "File permissions update" +# Step 4b: Ensure Apache/PHP config allows file uploads (.htaccess + php.ini) +APACHE_MAIN_CONF="/etc/apache2/apache2.conf" +if grep -q '' "$APACHE_MAIN_CONF"; then + if ! sed -n '//,/<\/Directory>/p' "$APACHE_MAIN_CONF" | grep -q "AllowOverride All"; then + sed -i '//,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' "$APACHE_MAIN_CONF" + print_status "✓ AllowOverride All enabled for Apache" + APACHE_CHANGED=true + fi +fi + +PHP_INI=$(php -r "echo php_ini_loaded_file();" 2>/dev/null) +if [ -n "$PHP_INI" ]; then + CURRENT_UPLOAD=$(grep -oP 'upload_max_filesize = \K\d+' "$PHP_INI" 2>/dev/null) + if [ -n "$CURRENT_UPLOAD" ] && [ "$CURRENT_UPLOAD" -lt 50 ]; then + sed -i 's/upload_max_filesize = .*/upload_max_filesize = 50M/' "$PHP_INI" + sed -i 's/post_max_size = .*/post_max_size = 55M/' "$PHP_INI" + print_status "✓ PHP upload limits set to 50M" + APACHE_CHANGED=true + fi +fi + +if [ "${APACHE_CHANGED:-false}" = true ]; then + systemctl reload apache2 2>/dev/null + print_status "✓ Apache reloaded" +fi + # Step 5: Restart critical services print_status "" print_status "Step 5: Managing system services..."