function processPasteDelete($pasteid, $deletetoken) { if (preg_match('/\\A[a-f\\d]{16}\\z/', $pasteid)) { $filename = dataid2path($pasteid) . $pasteid; if (!is_file($filename)) { return array('', 'Paste does not exist, has expired or has been deleted.', ''); } } if ($deletetoken != hash_hmac('sha1', $pasteid, getServerSalt())) { return array('', 'Wrong deletion token. Paste was not deleted.', ''); } // Paste exists and deletion token is valid: Delete the paste. deletePaste($pasteid); return array('', '', 'Paste was properly deleted.'); }
$meta = array(); if ($error) { echo json_encode(array('status' => 1, 'message' => 'Invalid data.')); exit; } // We just want a small hash to avoid collisions: Half-MD5 (64 bits) will do the trick. $dataid = substr(hash('md5', $data), 0, 16); $storage = array('data' => $data); $storagedir = dataid2path($dataid); if (!is_dir($storagedir)) { mkdir($storagedir, $mode = 0705, $recursive = true); } if (is_file($storagedir . $dataid)) { // Oups... improbable collision. echo json_encode(array('status' => 1, 'message' => 'Infite improbability drive activated! Try again, please.')); exit; } // New paste file_put_contents($storagedir . $dataid, json_encode($storage), LOCK_EX); // Generate the "delete" token. // The token is the hmac of the pasteid signed with the server salt. // The paste can be delete by calling http://myserver.com/zerobin/?pasteid=<pasteid>&deletetoken=<deletetoken> $deletetoken = hash_hmac('sha1', $dataid, getServerSalt()); echo json_encode(array('status' => 0, 'id' => $dataid, 'deletetoken' => $deletetoken)); // 0 = no error exit; echo json_encode(array('status' => 1, 'message' => 'Server error.')); exit; } else { echo json_encode(array('status' => 1, 'message' => 'No data.')); }
function __construct() { $this->width = 16; $this->height = 16; $this->salt = getServerSalt(); }
function processPasteDelete($pasteid, $deletetoken) { if (preg_match('/\\A[a-f\\d]{16}\\z/', $pasteid)) { $filename = dataid2path($pasteid) . $pasteid; if (!is_file($filename)) { return array('', 'Paste existiert nicht, ist ausgelaufen oder wurde gelöscht.', ''); } } else { return array('', 'Invalide Daten', ''); } if ($deletetoken != hash_hmac('sha1', $pasteid, getServerSalt())) { return array('', 'Falscher Lösch-Token. Paste wurde nicht gelöscht.', ''); } // Paste exists and deletion token is valid: Delete the paste. deletePaste($pasteid); return array('', '', 'Paste wurde erfolgreich gelöscht!'); }