function parsePastes($path = './data') { // Directories or files to ignore $ignore = array('.', '..', 'salt.php', 'trafic_limiter.php', '.htaccess'); // Open the directory $dh = @opendir($path); while (($file = readdir($dh)) !== false) { // Check if this file or directory is not to be ignored if (!in_array($file, $ignore)) { // If it's a directory, then parse it if (is_dir("{$path}/{$file}")) { parsePastes("{$path}/{$file}"); } else { // Check if the file's name is valid if (preg_match('/\\A[a-f\\d]{16}\\z/', $file)) { echo "<li>{$path}/{$file} : "; // Check if the content is JSON if (($content = json_decode(file_get_contents($path . '/' . $file))) != null) { // If contains the expire_date property if (isset($content->meta->expire_date)) { // If the expiration time is left if ($content->meta->expire_date < time()) { echo "<strong>Paste expired "; deletePaste($path . '/' . $file); // Delete the paste echo "</strong>"; $GLOBALS['expired']++; } else { echo "Paste not already expired !"; } } else { echo "<u>No expiration</u> !"; $GLOBALS['unlimited']++; } } echo "</li>\n"; $GLOBALS['files']++; } } } } closedir($dh); }
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, '', ''); }
$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($dataid); } } } else { $ERRORMESSAGE = 'Paste does not exist or has expired.'; } } } require_once "lib/rain.tpl.class.php"; header('Content-Type: text/html; charset=utf-8'); $page = new RainTPL(); $page->assign('CIPHERDATA', htmlspecialchars($CIPHERDATA, ENT_NOQUOTES)); // We escape it here because ENT_NOQUOTES can't be used in RainTPL templates. $page->assign('VERSION', $VERSION); $page->assign('ERRORMESSAGE', $ERRORMESSAGE); $page->draw('page');