X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/17d5977bf8d24a1b0abb5f52a8453322f21a994d..4ce96e7519f384ccd7e232db2802aa704636a560:/lib/functions.php?ds=sidebyside diff --git a/lib/functions.php b/lib/functions.php index 850386b..cf89593 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -101,6 +101,19 @@ function jirafeau_gen_random($l) return $code; } +function jirafeau_gen_download_pass($length, $allowed_chars) +{ + if ($length <= 0) { + return false; + } + $pass=""; + for ($i = 0; $i < $length; $i++) { + $pass .= $allowed_chars[rand(0, strlen($allowed_chars) - 1)]; + } + + return $pass; +} + function is_ssl() { if (isset($_SERVER['HTTPS'])) { @@ -148,6 +161,9 @@ function jirafeau_clean_rm_link($link) if (file_exists(VAR_LINKS . $p . $link)) { unlink(VAR_LINKS . $p . $link); } + if (file_exists(VAR_LINKS . $p . $link . '_download')) { + unlink(VAR_LINKS . $p . $link . '_download'); + } $parse = VAR_LINKS . $p; $scan = array(); while (file_exists($parse) @@ -693,6 +709,7 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) if (!count($l)) { continue; } + $ld = jirafeau_get_download_stats($node); /* Filter. */ if (!empty($name) && !@preg_match("/$name/i", jirafeau_escape($l['file_name']))) { @@ -717,6 +734,11 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) if (strlen($l['ip']) > 0) { echo t('ORIGIN') . ': ' . $l['ip'] . '
'; } + echo t('DOWNLOAD_COUNT') . ': ' . $ld['count'] . '
'; + if ($ld['count'] > 0) { + echo t('DOWNLOAD_DATE') . ': ' . jirafeau_get_datetimefield($ld['date']) . '
'; + echo t('DOWNLOAD_IP') . ': ' . $ld['ip'] . '
'; + } echo ''; echo '
' . '' . @@ -1205,10 +1227,13 @@ function jirafeau_encrypt_file($fp_src, $fp_dst) /* Crypt file. */ $r = fopen($fp_src, 'r'); $w = fopen($fp_dst, 'c'); - while (!feof($r)) { - $enc = mcrypt_generic($m, fread($r, 1024)); - if (fwrite($w, $enc) === false) { - return ''; + while (!feof($r)) { + $to_enc = fread($r, 1024); + if (strlen($to_enc) > 0) { + $enc = mcrypt_generic($m, $to_enc); + if (fwrite($w, $enc) === false) { + return ''; + } } } fclose($r); @@ -1587,3 +1612,32 @@ function jirafeau_default_web_root() { return $_SERVER['HTTP_HOST'] . str_replace('install.php', '', $_SERVER['REQUEST_URI']); } + +function jirafeau_get_download_stats($hash) +{ + $filename = VAR_LINKS . s2p("$hash") . $hash . '_download'; + + if (!file_exists($filename)) { + return array('count'=>0); + } + + $c = file($filename); + $data['count'] = trim($c[0]); + $data['date'] = trim($c[1]); + $data['ip'] = trim($c[2]); + + return $data; +} + +function jirafeau_write_download_stats($hash, $ip) +{ + $data = jirafeau_get_download_stats($hash); + $count = $data['count']; + $count++; + + $filename = VAR_LINKS . s2p("$hash") . $hash . '_download'; + + $handle = fopen($filename, 'w'); + fwrite($handle, $count . NL . time() . NL . $ip); + fclose($handle); +}