if (isset($_GET['path']) and isset($_GET['user']) and isset($_GET['status'])) { // --> begin authentication $havePermission = false; if (isset($_GET['apikey'])) { $auth = (string) $_GET['apikey']; $havePermission = $auth == $apikey; } else { $havePermission = $_SESSION["email"] == $_GET['user']; } // --> end authentication if (!$havePermission) { echo json_encode(array("result" => "permissionDenied")); } else { $path = (string) $_GET['path']; $user = (string) $_GET['user']; $status = (string) $_GET['status']; $oldStatus = getFileStatus($path, $user); setFileStatus($path, $user, $status); if ($oldStatus == "active" and $status == "deleted") { $fileSize = getFileSize($path, $user); addUserSpaceUsage($user, -$fileSize); } if ($oldStatus == "deleted" and $status == "active") { $fileSize = getFileSize($path, $user); addUserSpaceUsage($user, $fileSize); } echo json_encode(array("result" => "ok")); } } else { echo json_encode(array("result" => "missingParams")); }
} else { /* Delete the old chunks */ $actualModification = getFileModification($path, $user); if ($modification != $actualModification) { $fileSize = getFileSize($path, $user); addUserSpaceUsage($user, -$fileSize); $space_used = getUserSpaceUsed($user); $space_limit = getUserSpaceLimit($user); if ($space_used + $size > $space_limit) { addUserSpaceUsage($user, $fileSize); $space_left = $space_limit - $space_used; echo json_encode(array("result" => "notEnoughSpace", "spaceLeft" => $space_left)); return; } setFileSize($path, $user, 0); $status = getFileStatus($path, $user); setFileModificationDate($path, $user, $dateModified); if ($status != "pending") { $who = getFileComputers($path, $user); requestFileDelete($actualModification, $who); } setFileModification($path, $user, $modification); resetFileChunks($path, $user); setFileStatus($path, $user, "pending"); } echo json_encode(array("result" => "ok")); } } } else { echo json_encode(array("result" => "missingParams")); }