예제 #1
0
파일: index.php 프로젝트: jymannob/ZeroBin2
function processPasteFetch($pasteid)
{
    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.', '');
        }
    }
    // Get the paste itself.
    $paste = json_decode(file_get_contents($filename));
    // See if paste has expired.
    if (isset($paste->meta->expire_date) && $paste->meta->expire_date < time()) {
        deletePaste($pasteid);
        // Delete the paste
        return array('', 'Paste does not exist, has expired or has been deleted.', '');
    }
    // We kindly provide the remaining time before expiration (in seconds)
    if (property_exists($paste->meta, 'expire_date')) {
        $paste->meta->remaining_time = $paste->meta->expire_date - time();
    }
    $messages = array($paste);
    // The paste itself is the first in the list of encrypted messages.
    // If it's a discussion, get all comments.
    if (property_exists($paste->meta, 'opendiscussion') && $paste->meta->opendiscussion) {
        $comments = array();
        $datadir = dataid2discussionpath($pasteid);
        if (!is_dir($datadir)) {
            mkdir($datadir, $mode = 0705, $recursive = true);
        }
        $dhandle = opendir($datadir);
        while (false !== ($filename = readdir($dhandle))) {
            if (is_file($datadir . $filename)) {
                $comment = json_decode(file_get_contents($datadir . $filename));
                // Filename is in the form pasteid.commentid.parentid:
                // - pasteid is the paste this reply belongs to.
                // - commentid is the comment identifier itself.
                // - parentid is the comment this comment replies to (It can be pasteid)
                $items = explode('.', $filename);
                $comment->meta->commentid = $items[1];
                // Add some meta information not contained in file.
                $comment->meta->parentid = $items[2];
                $comments[$comment->meta->postdate] = $comment;
                // Store in table
            }
        }
        closedir($dhandle);
        ksort($comments);
        // Sort comments by date, oldest first.
        $messages = array_merge($messages, $comments);
    }
    $CIPHERDATA = json_encode($messages);
    // If the paste was meant to be read only once, delete it.
    if (property_exists($paste->meta, 'burnafterreading') && $paste->meta->burnafterreading) {
        deletePaste($pasteid);
    }
    return array($CIPHERDATA, '', '');
}
예제 #2
0
파일: index.php 프로젝트: nichdu/ZeroBin
function deletePaste($pasteid)
{
    // Delete the paste itself
    unlink(dataid2path($pasteid) . $pasteid);
    // Delete discussion if it exists.
    $discdir = dataid2discussionpath($pasteid);
    if (is_dir($discdir)) {
        // Delete all files in discussion directory
        $dhandle = opendir($discdir);
        while (false !== ($filename = readdir($dhandle))) {
            if (is_file($discdir . $filename)) {
                unlink($discdir . $filename);
            }
        }
        closedir($dhandle);
        // Delete the discussion directory.
        rmdir($discdir);
    }
}