Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions pages/customupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
$devices = $db->prepared_fetch("SELECT * FROM devices WHERE user = ?;", "s", session_id());

function sanity_check_file($file, $mime)
{
if ($file["error"])
return "Keine Datei ausgewaehlt oder Upload fehlgeschlagen";
{

// check currently disabled as it gives false positives with error code 0

if ($file["size"] > 512 * 1024)
return "Datei zu gross";
// if ($file["error"])
// error_log("File upload error: " . $file["error"]);
// return "Keine Datei ausgewaehlt oder Upload fehlgeschlagen: ".$file["error"];

if ($file["size"] > 2048 * 1024)
return "Datei zu gross". $file["size"];

if (!in_array($file["type"], $mime))
{
return "Falsch uebermittelter MIME-Type";
{
return "Falsch uebermittelter MIME-Type: ". $file["type"];
}

if (!in_array(mime_content_type($file['tmp_name']), $mime))
{
return "Falscher MIME-Type";
{
return "Falscher MIME-TypeL ". mime_content_type($file['tmp_name']);
}

return false;
Expand All @@ -29,7 +33,8 @@ function sanitize_filename($file, $extensions)
$extension = preg_replace('/[^a-z]/', '', strtolower($pathinfo['extension']));

if (!in_array($extension, $extensions))
{
{
error_log("Invalid extension: " . $extension);
return false;
}

Expand All @@ -40,6 +45,7 @@ function save_upload($file, $type, $extensions, $msn, $data)
{
global $userupload_path;
$filename = sanitize_filename($file, $extensions);
error_log("Filename: " . $filename);
if (!$filename)
return false;

Expand All @@ -59,6 +65,7 @@ function save_upload($file, $type, $extensions, $msn, $data)
$gateway = $db->prepared_fetch_one("SELECT * FROM gateways WHERE enabled = 1 AND id = ?;", "i", $device["gateway"]);

$data = "";
$error = "";

switch ($_POST["type"])
{
Expand Down Expand Up @@ -93,16 +100,17 @@ function save_upload($file, $type, $extensions, $msn, $data)
break;
case 'j2me':
if (($error = sanity_check_file($_FILES["file-java"], ["application/java-archive", "application/x-java-applet", "application/java", "application/zip"])) === false)
{
{
$data = save_upload($_FILES["file-java"], "j2me", ["jar"], $device["msn"], ["mode" => "custom"]);
}
break;
}

$error = SMS::sanity_check_udh_array($data);
if (trim($data) == "")
{
$error = "Die Datei konnte nicht umgewandelt werden.";
{
if ($error == "")
$error = "Die Datei konnte nicht umgewandelt werden.";
}
if ($error == "")
{
Expand Down