Пример #1
0
function commit_post($text, $jsCrypt, $lifetime_seconds, $short = false)
{
    do {
        $urlKey = PasswordGenerator::getAlphaNumericPassword($short ? 8 : 22);
    } while (retrieve_post($urlKey) !== false);
    $id = get_database_id($urlKey);
    $encryptionKey = get_encryption_key($urlKey);
    $iv = mcrypt_create_iv(IV_BYTES, MCRYPT_DEV_URANDOM);
    $encrypted = SafeEncode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $encryptionKey, $text, MCRYPT_MODE_CBC, $iv));
    $jsCrypted = $jsCrypt ? 1 : 0;
    $time = (int) (time() + $lifetime_seconds);
    mysql_query("INSERT INTO pastes (token, data, time, jscrypt) \n        VALUES('{$id}', '{$encrypted}', '{$time}', '{$jsCrypted}')");
    return $urlKey;
}
Пример #2
0
   die();
}

delete_expired_posts();

/*
 * Instead of rewrite rules, just handle post retrieval here
 * /view.php?key=postkey
 */
if (!isset($_GET['key'])) {
    echo "Error: Sorry, the paste you were looking for could not be found.";
    die();
}
$urlKey = $_GET['key'];

$postInfo = retrieve_post($urlKey);

if (isset($_GET['raw']) && $_GET['raw'] == "true") {
    header('Content-Type: text/plain');
    if ($postInfo['jscrypt'] == false) {
        echo $postInfo['text'];
    } else {
        echo "ERROR: This paste was encrypted with client-side encryption.";
    }
    die();
}

//Disable caching of viewed posts:
header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Mon, 01 Jan 1990 00:00:00 GMT");