Commit a71cbce8 authored by Adam Wujek's avatar Adam Wujek 💬

[Bug: 1219] rootfs/www: fix problem with uploading the firmware

PHP code of the web interface was updating values of "upload_max_filesize"
and "post_max_size" in the /etc/php.ini. Besides it is extremely bad idea to
do that, such changes to take place require restart of lighttpd, which was
never performed. Luckily after the update of /etc/php.ini it was also copied
to flash at the location /usr/etc/php.ini. Because of this update via
webinterface worked only when:
--firmware.php was opened via web browser
--restart of a switch was performed

The fix contains a patch to set these values in the php.ini and remove
the update of php.ini by php code.

Set maximum upload limit size to 30M in php.ini.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 7061b6f7
From 9547e0de3053813d72df79462c45b9b4db668669 Mon Sep 17 00:00:00 2001
From: Adam Wujek <adam.wujek@cern.ch>
Date: Tue, 6 Sep 2016 17:06:45 +0200
Subject: [PATCH] packages/php: increase the maximum allowed size of upload
files
Signed-off-by: Adam Wujek <adam.wujek@cern.ch>
---
...duction-increase-post_max_size-and-upload.patch | 48 ++++++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 package/php/0007-php.ini-production-increase-post_max_size-and-upload.patch
diff --git a/package/php/0007-php.ini-production-increase-post_max_size-and-upload.patch b/package/php/0007-php.ini-production-increase-post_max_size-and-upload.patch
new file mode 100644
index 0000000..be1dde3
--- /dev/null
+++ b/package/php/0007-php.ini-production-increase-post_max_size-and-upload.patch
@@ -0,0 +1,48 @@
+From 4bfab0ec8d534906d9252b9f5d300917b1bebe6d Mon Sep 17 00:00:00 2001
+From: Adam Wujek <adam.wujek@cern.ch>
+Date: Tue, 6 Sep 2016 17:03:57 +0200
+Subject: [PATCH] php.ini-production: increase post_max_size and
+ upload_max_filesize to 30M
+
+Also reduce memory_limit to 50M. On wr-switch we have only 64MB of RAM
+
+Signed-off-by: Adam Wujek <adam.wujek@cern.ch>
+---
+ php.ini-production | 7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/php.ini-production b/php.ini-production
+index dc483f7..9939f5c 100644
+--- a/php.ini-production
++++ b/php.ini-production
+@@ -390,7 +390,8 @@ max_input_time = 60
+
+ ; Maximum amount of memory a script may consume (128MB)
+ ; http://php.net/memory-limit
+-memory_limit = 128M
++; on wrs we have 64MB of RAM
++memory_limit = 50M
+
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ; Error handling and logging ;
+@@ -657,7 +658,7 @@ auto_globals_jit = On
+ ; Its value may be 0 to disable the limit. It is ignored if POST data reading
+ ; is disabled through enable_post_data_reading.
+ ; http://php.net/post-max-size
+-post_max_size = 8M
++post_max_size = 30M
+
+ ; Automatically add files before PHP document.
+ ; http://php.net/auto-prepend-file
+@@ -806,7 +807,7 @@ file_uploads = On
+
+ ; Maximum allowed size for uploaded files.
+ ; http://php.net/upload-max-filesize
+-upload_max_filesize = 2M
++upload_max_filesize = 30M
+
+ ; Maximum number of files that can be uploaded via a single request
+ max_file_uploads = 20
+--
+1.9.1
+
--
1.9.1
......@@ -20,7 +20,12 @@
<?php
session_is_started();
if(wrs_php_filesize()<30) php_file_transfer_size(30);
$size=wrs_php_filesize();
if (wrs_php_filesize() < 30) {
echo '<p align=center ><font color="red">';
echo 'Warning upload_max_filesize in php.ini is set to '.$size.'M. Upload probably will not work!';
echo '</font></p>';
}
?>
<table border="0" align="center">
......
......@@ -11,7 +11,6 @@ $vlancolor = array("#27DE2A", "#B642A8", "#6E42B6", "#425DB6" , "#428DB6", "#468
$MAX_PHP_FILESIZE = 40;
$phpusersfile="/usr/etc/phpusers";
$profilefile="/usr/etc/profile";
$phpinifile="/etc/php.ini";
$interfacesfile = "/usr/etc/network/interfaces";
$kconfigfile = "/wr/etc/dot-config";
$kconfigfilename = "dot-config";
......@@ -424,40 +423,6 @@ function wrs_check_ptp_status(){
return ($output>2) ? 1 : 0;
}
/*
* It modifies filesize transfer value.
*
* @author José Luis Gutiérrez <jlgutierrez@ugr.es>
*
* It modifies filesize transfer value in php.ini. Two variables must be
* modified: upload_max_filesize and post_max_size
*
* @param string $size New PHP sent filename value.
*
*/
function php_file_transfer_size($size){
// We remove the blank space
$size=trim($size);
// We modify fist upload_max_filesize in php.ini
$prev_size = shell_exec("cat ".$GLOBALS['phpinifile']." | grep upload_max_filesize | awk '{print $3}'");
$prev_size=trim($prev_size);
$cmd = "sed -i 's/upload_max_filesize = ".$prev_size."/upload_max_filesize = ".$size."M/g' ".$GLOBALS['phpinifile'];
shell_exec($cmd);
// We modify post_max_size in php.ini
$prev_size = shell_exec("cat ".$GLOBALS['phpinifile']." | grep post_max_size | awk '{print $3}'");
$prev_size=trim($prev_size);
$cmd ="sed -i 's/post_max_size = ".$prev_size."/post_max_size = ".$size."M/g' ".$GLOBALS['phpinifile'];
shell_exec($cmd);
shell_exec("cat ".$GLOBALS['phpinifile']." >/usr/etc/php.ini"); //We store it in /usr/etc/php.ini copy. Just in case
//echo '<p align=center>File upload size changed to '.$size.'</p>';
}
/*
* It modifies each endpoint configuration
*
......@@ -586,11 +551,9 @@ function wr_show_endpoint_rt_show(){
*
*/
function wrs_php_filesize(){
$size=shell_exec("cat ".$GLOBALS['phpinifile']." | grep upload_max_filesize | awk '{print $3}'");
$size=substr($size, 0, -2);
$size=ini_get('upload_max_filesize');
$size=substr($size, 0, -1);
return $size;
}
/*
......@@ -659,12 +622,7 @@ function wrs_load_files(){
}
echo "</pre>";
} else if (!empty($_POST["size"])){
php_file_transfer_size(htmlspecialchars($_POST["size"]));
header ('Location: load.php');
}
}
/*
......
......@@ -38,21 +38,6 @@
</tr>
</table>
<!--
<br><br><br><center>Max. filesize is now <?php //echo shell_exec("cat /etc/php.ini | grep upload_max_filesize | awk '{print $3}'");
?></center>
<table border="0" align="center">
<tr>
<form align="center" method="post">
<th>New PHP Filesize: </th><th><INPUT type="text" name="size" > </th>
<th><input type="submit" value="Change" class="btn"></th>
</tr>
</form>
</table>
-->
<div id="bottommsg">
<center>
*NOTE: After loading a FPGA or lm32 binary the switch will reboot.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment