/** * Clean expired files. * @return number of cleaned files. */ function Pingouin_admin_clean() { $count = 0; /* Get all links files. */ $stack = array(VAR_LINKS); while (($d = array_shift($stack)) && $d != NULL) { $dir = scandir($d); foreach ($dir as $node) { if (strcmp($node, '.') == 0 || strcmp($node, '..') == 0 || preg_match('/\\.tmp/i', "{$node}")) { continue; } if (is_dir($d . $node)) { /* Push new found directory. */ $stack[] = $d . $node . '/'; } elseif (is_file($d . $node)) { /* Read link informations. */ $l = Pingouin_get_link(basename($node)); if (!count($l)) { continue; } $p = s2p($l['md5']); if ($l['time'] > 0 && $l['time'] < time() || !file_exists(VAR_FILES . $p . $l['md5']) || !file_exists(VAR_FILES . $p . $l['md5'] . '_count')) { Pingouin_delete_link($node); $count++; } } } } return $count; }
if ($link['crypted']) { /* Init module */ $m = mcrypt_module_open('rijndael-256', '', 'ofb', ''); /* Extract key and iv. */ $md5_key = md5($crypt_key); $iv = Pingouin_crypt_create_iv($md5_key, mcrypt_enc_get_iv_size($m)); /* Init module. */ mcrypt_generic_init($m, $md5_key, $iv); /* Decrypt file. */ $r = fopen(VAR_FILES . $p . $link['md5'], 'r'); while (!feof($r)) { $dec = mdecrypt_generic($m, fread($r, 1024)); print $dec; ob_flush(); } fclose($r); /* Cleanup. */ mcrypt_generic_deinit($m); mcrypt_module_close($m); } else { $r = fopen(VAR_FILES . $p . $link['md5'], 'r'); while (!feof($r)) { print fread($r, 1024); ob_flush(); } fclose($r); } if ($link['onetime'] == 'O') { Pingouin_delete_link($link_name); } exit;
} elseif (strcmp($_POST['action'], 'clean_async') == 0) { $total = Pingouin_admin_clean_async(); echo '<div class="message">' . NL; echo '<p>'; echo t('Number of cleaned files') . ' : ' . $total; echo '</p></div>'; } elseif (strcmp($_POST['action'], 'list') == 0) { Pingouin_admin_list("", "", ""); } elseif (strcmp($_POST['action'], 'search_by_name') == 0) { Pingouin_admin_list($_POST['name'], "", ""); } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) { Pingouin_admin_list("", $_POST['hash'], ""); } elseif (strcmp($_POST['action'], 'search_link') == 0) { Pingouin_admin_list("", "", $_POST['link']); } elseif (strcmp($_POST['action'], 'delete_link') == 0) { Pingouin_delete_link($_POST['link']); echo '<div class="message">' . NL; echo '<p>' . t('Link deleted') . '</p></div>'; } elseif (strcmp($_POST['action'], 'delete_file') == 0) { $count = Pingouin_delete_file($_POST['md5']); echo '<div class="message">' . NL; echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>'; } elseif (strcmp($_POST['action'], 'download') == 0) { $l = Pingouin_get_link($_POST['link']); if (!count($l)) { return; } $p = s2p($l['md5']); header('Content-Length: ' . $l['file_size']); header('Content-Type: ' . $l['mime_type']); header('Content-Disposition: attachment; filename="' . $l['file_name'] . '"');