diff --git a/admin/index.php b/admin/index.php index b9ed65b..3ca0272 100644 --- a/admin/index.php +++ b/admin/index.php @@ -49,8 +49,8 @@ if ($user->isAdmin()) { $_POST["url"] = $conf->urlGelato."/uploads/".$photoName; } - if ( move_uploaded_file( $_FILES['photo']['tmp_name'], "../uploads/".$_FILES['photo']['name'] ) ) { - $_POST["url"] = $conf->urlGelato."/uploads/".$_FILES['photo']['name']; + if ( move_uploaded_file( $_FILES['photo']['tmp_name'], "../uploads/".sanitizeName($_FILES['photo']['name']) ) ) { + $_POST["url"] = $conf->urlGelato."/uploads/".sanitizeName($_FILES['photo']['name']); } unset($_POST["photo"]); @@ -359,7 +359,7 @@ if ($user->isAdmin()) { $template->cargarPlantilla($input, $output, "template_regular_post"); $template->mostrarPlantilla(); break; - case "2": + case "2": $fileName = "../uploads/".getFileName($register["url"]); $x = @getimagesize($fileName); diff --git a/classes/functions.php b/classes/functions.php index 0aef130..76e7103 100644 --- a/classes/functions.php +++ b/classes/functions.php @@ -82,8 +82,8 @@ } } - function getFile($remoteFileName) { - $fileName = "../uploads/".getFileName($remoteFileName); + function getFile($remoteFileName) { + $fileName = sanitizeName("../uploads/".$remoteFileName); $str = _file_get_contents($remoteFileName); if (!$handle = fopen($fileName, 'w')) { return false; @@ -165,7 +165,21 @@ } closedir($handle); return $dirs; - } + } + + function sanitizeName($name) { + $name = preg_replace('/[\'"]/', '', $name); + $name = preg_replace('/[^a-zA-Z0-9]+/', '-', $name); + $name = trim($name, '-'); + $name = strtolower($name); + //HACK: We need to rework the regular expression to allow the dot + $ext = substr($name, strlen($name)-3, strlen($name)); + $body = substr($name, 0, strlen($name)-4); + + $name = $body.".".$ext; + + return $name; + } function _file_get_contents($path) { // Modified function from: diff --git a/uploads/index.php b/uploads/index.php new file mode 100644 index 0000000..4e6c07c --- /dev/null +++ b/uploads/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file