Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

PROTÉGER DOSSIER, QUOTAT, LISTING, ANTI-LEECH, TEMPORISATION AVEC HTACCESS


Information sur la source

Catégorie :Fichier / Disque Classé sous : protéger, dossier, quotat, antileech, htaccess Niveau : Débutant Date de création : 27/12/2005 Date de mise à jour : 03/08/2008 14:29:25 Vu / téléchargé: 11 137 / 1 435

Note :
7,1 / 10 - par 10 personnes
7,10 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (17)
Ajouter un commentaire et/ou une note

Description

Cliquez pour voir la capture en taille normale
Code déposé par Benoît GRUNENBERGER
www.egrunenberger.com

Protéger dossier, Quotat, listing, Anti-Leech, Temporisation avec  HTACCESS
 

Source

  • <?php
  • /**
  • * .: INFORMATIONS :.
  • * Nom : Download Limiter
  • * Version : 1.2.0
  • * Licence : GPL
  • * Neccessite : PHP 4.1.0 +
  • */
  • /** Nom du fichier ou sont stockees les informations */
  • $INFOFILE=".htdlinfos";
  • /** Nom du fichier ou sont stockees les clients en attente */
  • $WAITFILE=".htdlwait";
  • /** Patron des fichiers a exclure */
  • $EXCLUDE="(^\..*|.*\.(php|php3|php4|php5|asp|html|htm)$)";
  • /** fichier de configuration du script */
  • $CONFIGFILE=".htdl".substr($_SERVER["SCRIPT_FILENAME"],strrpos($_SERVER["SCRIPT_FILENAME"],"/")+1);
  • function style() { ?>
  • <style>
  • body{background-color:#000000;}
  • table#main1 {width:100%;}
  • table#main1 td{background-color:#AA0000;}
  • table#main2 {width:100%;}
  • table#main2 th {background-color:#e0e0e0;color:#000077;font-size:130%;text-align:left}
  • table#main2 td {background-color:#fffff0;color:#000077;font-weight:bold;text-align:left}
  • table#info1 {width:500px;}
  • table#info1 td{background-color:#AA0000;}
  • table#info2 {width:500px;}
  • table#info2 th {background-color:#e0e0e0;color:#000077;font-size:130%;text-align:center}
  • table#info2 td {background-color:#fffff0;color:#000077;font-weight:bold;text-align:center}
  • input {background-color:#fffff0;color:#000077;}
  • </style>
  • <?php }
  • function listfolder($dossier="") {
  • $handle=opendir("./".$dossier);
  • while ($folder = readdir($handle)) {
  • if(!ereg("^\.",$folder) && is_dir($dossier.$folder) ) {
  • echo "<input type='radio' name='dossier' value='".$dossier.$folder."' />".$dossier.$folder."<br />";
  • listfolder($dossier.$folder."/");
  • }
  • }
  • }
  • // ASSISTANT de configuration
  • if( !is_file($CONFIGFILE) ) {
  • // cas de la validation du formulaire
  • if( isset($_POST['dossier']) && is_dir("./".$_POST['dossier']) && is_numeric($_POST['temps'])) {
  • // installation du htaccess
  • $file = fopen($_POST['dossier']."/.htaccess","w");
  • if( $file != FALSE ) {
  • fwrite($file,"Order deny,allow\n");
  • fwrite($file,"Deny from all\n");
  • }
  • fclose($file);
  • // generation du fichier de configuration
  • $file = fopen($CONFIGFILE,"w");
  • // dossier
  • fwrite($file,"dossier=".$_POST['dossier']."\n");
  • // quotat
  • if(isset($_POST['activerquotat']) && $_POST['activerquotat'] === "on" &&
  • isset($_POST['taillequotat']) && is_numeric($_POST['taillequotat']) &&
  • isset($_POST['heurequotat']) && is_numeric($_POST['heurequotat']) && $_POST['heurequotat'] > 0 ) {
  • fwrite($file,"taillemax=". ($_POST['taillequotat'] * 1024 * 1024 * 1024) ."\n");
  • fwrite($file,"periode=".$_POST['heurequotat']."\n");
  • }
  • else {
  • fwrite($file,"taillemax=-1\n");
  • fwrite($file,"periode=0\n");
  • }
  • // listing
  • if(isset($_POST['activerlisting']) && $_POST['activerlisting'] === "on" ) fwrite($file,"listing=on\n");
  • else fwrite($file,"listing=off\n");
  • // antileech
  • if(isset($_POST['activerantileech']) && $_POST['activerantileech'] === "on" && isset($_POST['antileech']))
  • fwrite($file,"referer=".$_POST['antileech']."\n");
  • else fwrite($file,"referer=\n");
  • // temporisation
  • if(isset($_POST['temps']) && is_numeric($_POST['temps']) ) fwrite($file,"attente=".$_POST['temps']."\n");
  • else fwrite($file,"attente=0\n");
  • fclose($file); ?>
  • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  • <html>
  • <head>
  • <title>Download Limiter : Configuration</title>
  • <?php style(); ?>
  • </head>
  • <body>
  • <table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
  • <tr>
  • <td align="center">
  • <table border="0" cellspacing="0" cellpadding="1" id="info1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="info2">
  • <tr>
  • <th>
  • Résultat
  • </th>
  • </tr>
  • <tr>
  • <td>
  • Fichier de configuration généré avec succes !
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • </body>
  • </html>
  • <?php } else { ?>
  • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  • <html>
  • <head>
  • <title>Download Limiter : Configuration</title>
  • <?php style(); ?>
  • </style>
  • </head>
  • <body>
  • <form method="post" enctype="multipart/form-data" action="<?=$_SERVER["PHP_SELF"]?>">
  • <table border="0" cellspacing="0" cellpadding="1" id="main1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="main2">
  • <tr>
  • <th>
  • Dossier à proteger
  • </th>
  • </tr>
  • <tr>
  • <td>
  • <p>Sélectionnez le dossier à proteger parmis la liste suivante :<br />
  • <?php listfolder(); ?>
  • </p>
  • <p style="font-size:small;font-style:italic;">Si le dossier que vous voulez proteger n'apparait pas,
  • c'est que le script n'est pas placé au bon endroit.</p>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • <br />
  • <table border="0" cellspacing="0" cellpadding="1" id="main1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="main2">
  • <tr>
  • <th>
  • Quotat
  • </th>
  • </tr>
  • <tr>
  • <td>
  • <p><input type='checkbox' name='activerquotat' value='on'>Activer la gestion des quotats</input></p>
  • <p>Quotat autorisé : <input type="text" name="taillequotat" value="2" size="3" />Go /
  • <input type="text" name="heurequotat" value="6" size="3" /> heures.</p>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • <br />
  • <table border="0" cellspacing="0" cellpadding="1" id="main1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="main2">
  • <tr>
  • <th>
  • Listing
  • </th>
  • </tr>
  • <tr>
  • <td>
  • <p><input type='checkbox' name='activerlisting' value='on' />Lister le contenu du dossier si
  • le script est appelé sans paramêtres.</p>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • <br />
  • <table border="0" cellspacing="0" cellpadding="1" id="main1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="main2">
  • <tr>
  • <th>
  • Anti-Leech
  • </th>
  • </tr>
  • <tr>
  • <td>
  • <p><input type='checkbox' name='activerantileech' value='on' />Activer l'anti-leech</p>
  • <p><span style="text-decoration:underline;">Seul</span> site autorisé :
  • <input type='text' name='antileech' value='http://<?=$_SERVER['HTTP_HOST']?>/' size="100" /></p>
  • <p style="font-size:small;font-style:italic;">Les utilisateurs ne venant pas d'un site commencant
  • par l'adresse ci-dessus ne seront pas autorisés à télécharger les fichiers.</p>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • <br />
  • <table border="0" cellspacing="0" cellpadding="1" id="main1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="main2">
  • <tr>
  • <th>
  • Temporisation
  • </th>
  • </tr>
  • <tr>
  • <td>
  • <p>Temps à attendre entre chaque téléchargement :
  • <input type='text' name='temps' value='30' size="3" /> secondes (0 : inactif)</p>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • <br />
  • <table border="0" cellspacing="0" cellpadding="1" id="main1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="main2">
  • <tr>
  • <td>
  • <p align="center"><input type='submit' value='Valider' />
  • <input type='reset' value='Remettre à zéro' /></p>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • </form>
  • </body>
  • </html>
  • <?php } exit();
  • } // if(!is_file($CONFIGFILE))
  • // Ici , le fichier $CONFIGFILE existe , c'est sur !
  • // Chargement de la config
  • $conffile = fopen($CONFIGFILE,"r");
  • while (!feof ($conffile)) {
  • $ligne = fgets($conffile, 512);
  • $option = substr($ligne,0,strpos($ligne,"="));
  • $valeur = substr($ligne,strpos($ligne,"=")+1,strlen($ligne)-strpos($ligne,"=")-2); /* pas de \n */
  • switch ($option) {
  • case "dossier" : $DOSSIER=$valeur; break;
  • case "taillemax" : $TAILLEMAX=$valeur; break;
  • case "periode" : $PERIODE=$valeur; break;
  • case "listing" : $LISTING=$valeur; break;
  • case "referer" : $FROMHOST=$valeur; break;
  • case "attente" : $TIMETOWAIT=$valeur; break;
  • }
  • }
  • fclose($conffile);
  • $message=0;
  • // partie de creation du fichier ".htaccess"
  • if( isset($_GET['install']) && is_dir($DOSSIER) && !is_file("$DOSSIER/.htaccess")) {
  • $htaccessfile = fopen("$DOSSIER/.htaccess","w");
  • if( $htaccessfile != FALSE ) {
  • fwrite($htaccessfile,"Order deny,allow\n");
  • fwrite($htaccessfile,"Deny from all\n");
  • }
  • echo "<html><body>Fichier .htaccess crée.</body></html>";
  • exit();
  • }
  • // si le fichier .htaccess n'existe pas : erreur (securit?)
  • if( !is_file("$DOSSIER/.htaccess") && is_dir($DOSSIER)) {
  • echo "<html><body><span style='font-weight:bold'>FATAL :</span> Le fichier .htaccess n'existe pas!<br />".
  • "Le script ne sert à rien sans ".htaccess".<br />Appelez la page ".
  • "<a href=\"http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?install".
  • "\">http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?install</a> ".
  • "pour creer le fichier .htaccess automatiquement!</body></html>";
  • exit();
  • }
  • // recuperation du parametre file = nom du fichier
  • $fichier = (isset($_GET['file'])) ? $_GET['file'] : "";
  • //securite le nom du fichier ne peut contenir de ".."
  • if (ereg("\.\.",$fichier)) $fichier="";
  • // So, cas 1 , le parametre file n'existe pas ou est vide
  • if ( $fichier === "" ) {
  • // Si le listing est permit : listing
  • if ( $LISTING === "on" && is_dir($DOSSIER) ) {
  • echo "<html><head><title>Download Limiter - Listing</title></head><body><h2>";
  • echo "Download Limiter - Ressources téléchargeables :";
  • echo "</h2><table width='100%'><tr><th style='border-bottom:2px solid #8d8d8d;".
  • "text-align:left;padding-right:20px;'>Nom</th><th style='border-bottom:2px solid ".
  • "#8d8d8d;text-align:left;width:100%'>Taille</th></tr>";
  • $handle=@opendir($DOSSIER);
  • while ($fichier = @readdir($handle)) {
  • if(is_file("$DOSSIER/$fichier") && !ereg($EXCLUDE,$fichier)) {
  • $URL = $_SERVER['PHP_SELF'] . "?file=" . urlencode($fichier);
  • echo "<tr><td style='padding-right:20px;' nowrap='nowrap'><a href=\"$URL\">$fichier</a></td>";
  • echo "<td>". round(filesize("$DOSSIER/$fichier") / 1048576,1) ." Mo</td></tr>";
  • }
  • }
  • // commenter les deux lignes suivantes si vous ne vouler pas de ligne "Powered by Download Limiter v x.x.x"
  • echo "<tr><td colspan='2' style='border-top:2px solid #8d8d8d;padding-top:3px;font-style:italic;'>".
  • "Powered by Download Limiter v 1.2.0</td></tr>";
  • echo "</table></body></html>";
  • }
  • exit();
  • }
  • // test de leech
  • if( $FROMHOST != "" && !ereg("$FROMHOST",$_SERVER['HTTP_REFERER']) ) {
  • $message="Protection Anti-Leech : Access Interdit";
  • # HTTP_REFERER peut etre masqu?e par Norton
  • if ( isset($_SERVER["HTTP________"]) ) {
  • $message.="<p><span style='font-size:small'>Attention : Il semble que vous utilisiez un ".
  • "logiciel de confidentialité. Vérifiez votre antivirus par exemple.</span></p>";
  • }
  • }
  • // test d'existence du fichier
  • elseif( $message===0 && is_file("$DOSSIER/$fichier") && !ereg($EXCLUDE,$fichier)) {
  • /* test du temps d'attente */
  • if ( $TIMETOWAIT > 0 && is_file($WAITFILE) && rename("$WAITFILE","$WAITFILE.old")) {
  • /* ouverture de ce fichier en lecture */
  • $foldfile = fopen("$WAITFILE.old","r");
  • /* creation d'un nouveau fichier */
  • $fwaitfile = fopen("$WAITFILE","w");
  • while (!feof ($foldfile)){
  • $ligne = fgets($foldfile, 100);
  • if ($ligne != FALSE) {
  • $time = substr($ligne,0,strpos($ligne,":"));
  • $ip = substr($ligne,strpos($ligne,":")+1);
  • if( time() - $time < $TIMETOWAIT ) {
  • fwrite($fwaitfile,"$time:$ip");
  • if ( $ip == $_SERVER["REMOTE_ADDR"]."\n" )
  • $message = "Vous devez attendre ".($TIMETOWAIT - ( time() - $time) ) .
  • " secondes avant le<br />prochain téléchargement.";
  • }
  • }
  • }
  • fclose($fwaitfile);
  • fclose($foldfile);
  • /* suppression du fichier .old */
  • unlink("$WAITFILE.old");
  • }
  • /* recuperation des informations sur le fichier */
  • $filesize = filesize("$DOSSIER/$fichier");
  • if ( $message === 0 && $TAILLEMAX > 0) { // si "$message != 0" le client doit attendre
  • /* attente si le fichier $INFOFILE.old existe */
  • /* 10 seconde , au dela passage force */
  • while (is_file("$INFOFILE.old") && (time()-filemtime("$INFOFILE.old")<10));
  • /* renommage du fichier en fchier.old */
  • if( is_file("$INFOFILE") && rename("$INFOFILE","$INFOFILE.old")) {
  • $compteurtaille=0;
  • /* ouverture de ce fichier en lecture */
  • $foldfile = fopen("$INFOFILE.old","r");
  • /* creation d'un nouveau fichier */
  • $finfofile = fopen("$INFOFILE","w");
  • $varTimeToWait=0;
  • while (!feof ($foldfile)){
  • $ligne = fgets($foldfile, 100);
  • if ($ligne != FALSE) {
  • $time = substr($ligne,0,strpos($ligne,":"));
  • $size = substr($ligne,strpos($ligne,":")+1);
  • if( time() - $time < $PERIODE * 3600 ) {
  • /* pour le temps d'attente restant */
  • if ( $varTimeToWait===0 )
  • $varTimeToWait=$time;
  • fwrite($finfofile,"$time:$size");
  • $compteurtaille+=$size;
  • }
  • }
  • }
  • if ($compteurtaille + $filesize >= $TAILLEMAX) {
  • // taille depassee
  • $message = "La taille maximale de téléchargement est dépassée pour ".
  • "la période en cours.<br />Merci de repasser dans ";
  • $varTimeToWait = $PERIODE * 3600 - ( time() - $varTimeToWait );
  • if ( $varTimeToWait > 3600 ) {
  • $message.= floor($varTimeToWait/3600) . "h ";
  • $varTimeToWait%=3600;
  • }
  • if ( $varTimeToWait > 60 ) {
  • $message.= floor($varTimeToWait/60) . "m ";
  • $varTimeToWait%=60;
  • }
  • $message.=$varTimeToWait."s.";
  • }
  • else {
  • // uplaod permit
  • fwrite($finfofile,time().":$filesize\n");
  • }
  • fclose($finfofile);
  • fclose($foldfile);
  • /* suppression du fichier .old */
  • unlink("$INFOFILE.old");
  • }
  • // cas du premier upload
  • else {
  • /* creation d'un nouveau fichier */
  • $finfofile = fopen("$INFOFILE","w");
  • if ($compteurtaille + $filesize >= $TAILLEMAX) {
  • // taille depassee
  • $message = "La taille maximale de téléchargement est dépassée ".
  • "pour la période en cours.<br />Merci de repasser plus tard.";
  • }
  • else {
  • // uplaod permit
  • fwrite($finfofile,time().":$filesize\n");
  • }
  • fclose($finfofile);
  • }
  • }
  • if ( $message === 0 ) {
  • // sauvegarde de l'IP et de l'heure du telechargement
  • if ( $TIMETOWAIT > 0) {
  • $fwaitfile = fopen($WAITFILE,"a+");
  • fwrite($fwaitfile,time().":".$_SERVER["REMOTE_ADDR"]."\n");
  • fclose($fwaitfile);
  • }
  • /* definition des entetes */
  • header("Cache-Control: no-store, no-cache, must-revalidate");
  • header("Cache-Control: post-check=0, pre-check=0", false);
  • header("Cache-control: private",false);
  • header("Pragma: no-cache");
  • header("Content-Length: " . $filesize);
  • header("Content-Type: application/force-download");
  • header("Content-Type: application/download",false);
  • header("Content-Type: application/octetstream",false);
  • header("Content-Type: application/octet-stream",false);
  • header("Content-Disposition: attachment; filename=\"".$fichier."\"");
  • /* envoie du fichier (via un flux) */
  • if (!@readfile("$DOSSIER/$fichier")) {
  • echo "Erreur de droit de lecture !!!";
  • }
  • exit();
  • }
  • }
  • else {
  • $message = $message===0 ? "Le fichier \"$fichier\" n'existe pas !;" : $message;
  • }
  • // Tous ce qui suit n'est affiche que si le telechargement n'est pas possible.
  • ?>
  • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  • <html>
  • <head>
  • <title>Download Limiter</title>
  • <?php style(); ?>
  • </head>
  • <body>
  • <table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
  • <tr>
  • <td align="center">
  • <table border="0" cellspacing="0" cellpadding="1" id="info1">
  • <tr>
  • <td>
  • <table border="0" cellspacing="1" cellpadding="10" id="info2">
  • <tr>
  • <th>
  • Erreur de téléchargement !
  • </th>
  • </tr>
  • <tr>
  • <td>
  • <?=$message?>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • </td>
  • </tr>
  • </table>
  • </body>
  • </html>
<?php
/**
* .: INFORMATIONS :.
* Nom : Download Limiter
* Version : 1.2.0
* Licence : GPL
* Neccessite : PHP 4.1.0 +
*/

/** Nom du fichier ou sont stockees les informations */
$INFOFILE=".htdlinfos";
/** Nom du fichier ou sont stockees les clients en attente */
$WAITFILE=".htdlwait";
/** Patron des fichiers a exclure */
$EXCLUDE="(^\..*|.*\.(php|php3|php4|php5|asp|html|htm)$)";
/** fichier de configuration du script */
$CONFIGFILE=".htdl".substr($_SERVER["SCRIPT_FILENAME"],strrpos($_SERVER["SCRIPT_FILENAME"],"/")+1);


function style() { ?>
<style>
body{background-color:#000000;}
table#main1 {width:100%;}
table#main1 td{background-color:#AA0000;}
table#main2 {width:100%;}
table#main2 th {background-color:#e0e0e0;color:#000077;font-size:130%;text-align:left}
table#main2 td {background-color:#fffff0;color:#000077;font-weight:bold;text-align:left}
table#info1 {width:500px;}
table#info1 td{background-color:#AA0000;}
table#info2 {width:500px;}
table#info2 th {background-color:#e0e0e0;color:#000077;font-size:130%;text-align:center}
table#info2 td {background-color:#fffff0;color:#000077;font-weight:bold;text-align:center}
input {background-color:#fffff0;color:#000077;}
</style>
<?php }

function listfolder($dossier="") {
$handle=opendir("./".$dossier);
while ($folder = readdir($handle)) {
if(!ereg("^\.",$folder) && is_dir($dossier.$folder) ) {
echo "<input type='radio' name='dossier' value='".$dossier.$folder."' />".$dossier.$folder."<br />";
listfolder($dossier.$folder."/");
}
}
}


// ASSISTANT de configuration
if( !is_file($CONFIGFILE) ) {

// cas de la validation du formulaire
if( isset($_POST['dossier']) && is_dir("./".$_POST['dossier']) && is_numeric($_POST['temps'])) {

// installation du htaccess
$file = fopen($_POST['dossier']."/.htaccess","w");
if( $file != FALSE ) {
fwrite($file,"Order deny,allow\n");
fwrite($file,"Deny from all\n");
}
fclose($file);

// generation du fichier de configuration
$file = fopen($CONFIGFILE,"w");

// dossier
fwrite($file,"dossier=".$_POST['dossier']."\n");

// quotat
if(isset($_POST['activerquotat']) && $_POST['activerquotat'] === "on" &&
isset($_POST['taillequotat']) && is_numeric($_POST['taillequotat']) &&
isset($_POST['heurequotat']) && is_numeric($_POST['heurequotat']) && $_POST['heurequotat'] > 0 ) {
fwrite($file,"taillemax=". ($_POST['taillequotat'] * 1024 * 1024 * 1024) ."\n");
fwrite($file,"periode=".$_POST['heurequotat']."\n");
}
else {
fwrite($file,"taillemax=-1\n");
fwrite($file,"periode=0\n");
}

// listing
if(isset($_POST['activerlisting']) && $_POST['activerlisting'] === "on" ) fwrite($file,"listing=on\n");
else fwrite($file,"listing=off\n");

// antileech
if(isset($_POST['activerantileech']) && $_POST['activerantileech'] === "on" && isset($_POST['antileech']))
fwrite($file,"referer=".$_POST['antileech']."\n");
else fwrite($file,"referer=\n");

// temporisation
if(isset($_POST['temps']) && is_numeric($_POST['temps']) ) fwrite($file,"attente=".$_POST['temps']."\n");
else fwrite($file,"attente=0\n");

fclose($file); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Download Limiter : Configuration</title>
<?php style(); ?>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="1" id="info1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="info2">
<tr>
<th>
Résultat
</th>
</tr>
<tr>
<td>
Fichier de configuration généré avec succes !
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<?php } else { ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Download Limiter : Configuration</title>
<?php style(); ?>
</style>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="<?=$_SERVER["PHP_SELF"]?>">
<table border="0" cellspacing="0" cellpadding="1" id="main1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="main2">
<tr>
<th>
Dossier à proteger
</th>
</tr>
<tr>
<td>
<p>Sélectionnez le dossier à proteger parmis la liste suivante :<br />
<?php listfolder(); ?>
</p>
<p style="font-size:small;font-style:italic;">Si le dossier que vous voulez proteger n'apparait pas,
c'est que le script n'est pas placé au bon endroit.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="1" id="main1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="main2">
<tr>
<th>
Quotat
</th>
</tr>
<tr>
<td>
<p><input type='checkbox' name='activerquotat' value='on'>Activer la gestion des quotats</input></p>
<p>Quotat autorisé : <input type="text" name="taillequotat" value="2" size="3" />Go /
<input type="text" name="heurequotat" value="6" size="3" /> heures.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="1" id="main1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="main2">
<tr>
<th>
Listing
</th>
</tr>
<tr>
<td>
<p><input type='checkbox' name='activerlisting' value='on' />Lister le contenu du dossier si
le script est appelé sans paramêtres.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="1" id="main1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="main2">
<tr>
<th>
Anti-Leech
</th>
</tr>
<tr>
<td>
<p><input type='checkbox' name='activerantileech' value='on' />Activer l'anti-leech</p>
<p><span style="text-decoration:underline;">Seul</span> site autorisé :
<input type='text' name='antileech' value='http://<?=$_SERVER['HTTP_HOST']?>/' size="100" /></p>
<p style="font-size:small;font-style:italic;">Les utilisateurs ne venant pas d'un site commencant
par l'adresse ci-dessus ne seront pas autorisés à télécharger les fichiers.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="1" id="main1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="main2">
<tr>
<th>
Temporisation
</th>
</tr>
<tr>
<td>
<p>Temps à attendre entre chaque téléchargement :
<input type='text' name='temps' value='30' size="3" /> secondes (0 : inactif)</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table border="0" cellspacing="0" cellpadding="1" id="main1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="main2">
<tr>
<td>
<p align="center"><input type='submit' value='Valider' />
<input type='reset' value='Remettre à zéro' /></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php } exit();
} // if(!is_file($CONFIGFILE))

// Ici , le fichier $CONFIGFILE existe , c'est sur !
// Chargement de la config

$conffile = fopen($CONFIGFILE,"r");
while (!feof ($conffile)) {
$ligne = fgets($conffile, 512);
$option = substr($ligne,0,strpos($ligne,"="));
$valeur = substr($ligne,strpos($ligne,"=")+1,strlen($ligne)-strpos($ligne,"=")-2); /* pas de \n */
switch ($option) {
case "dossier" : $DOSSIER=$valeur; break;
case "taillemax" : $TAILLEMAX=$valeur; break;
case "periode" : $PERIODE=$valeur; break;
case "listing" : $LISTING=$valeur; break;
case "referer" : $FROMHOST=$valeur; break;
case "attente" : $TIMETOWAIT=$valeur; break;
}
}
fclose($conffile);

$message=0;

// partie de creation du fichier ".htaccess"
if( isset($_GET['install']) && is_dir($DOSSIER) && !is_file("$DOSSIER/.htaccess")) {
$htaccessfile = fopen("$DOSSIER/.htaccess","w");
if( $htaccessfile != FALSE ) {
fwrite($htaccessfile,"Order deny,allow\n");
fwrite($htaccessfile,"Deny from all\n");
}
echo "<html><body>Fichier .htaccess crée.</body></html>";
exit();
}

// si le fichier .htaccess n'existe pas : erreur (securit?)
if( !is_file("$DOSSIER/.htaccess") && is_dir($DOSSIER)) {
echo "<html><body><span style='font-weight:bold'>FATAL :</span> Le fichier .htaccess n'existe pas!<br />".
"Le script ne sert à rien sans ".htaccess".<br />Appelez la page ".
"<a href=\"http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?install".
"\">http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?install</a> ".
"pour creer le fichier .htaccess automatiquement!</body></html>";
exit();
}

// recuperation du parametre file = nom du fichier
$fichier = (isset($_GET['file'])) ? $_GET['file'] : "";

//securite le nom du fichier ne peut contenir de ".."
if (ereg("\.\.",$fichier)) $fichier="";


// So, cas 1 , le parametre file n'existe pas ou est vide
if ( $fichier === "" ) {

// Si le listing est permit : listing
if ( $LISTING === "on" && is_dir($DOSSIER) ) {

echo "<html><head><title>Download Limiter - Listing</title></head><body><h2>";

echo "Download Limiter - Ressources téléchargeables :";

echo "</h2><table width='100%'><tr><th style='border-bottom:2px solid #8d8d8d;".
"text-align:left;padding-right:20px;'>Nom</th><th style='border-bottom:2px solid ".
"#8d8d8d;text-align:left;width:100%'>Taille</th></tr>";

$handle=@opendir($DOSSIER);

while ($fichier = @readdir($handle)) {
if(is_file("$DOSSIER/$fichier") && !ereg($EXCLUDE,$fichier)) {

$URL = $_SERVER['PHP_SELF'] . "?file=" . urlencode($fichier);
echo "<tr><td style='padding-right:20px;' nowrap='nowrap'><a href=\"$URL\">$fichier</a></td>";
echo "<td>". round(filesize("$DOSSIER/$fichier") / 1048576,1) ." Mo</td></tr>";
}
}

// commenter les deux lignes suivantes si vous ne vouler pas de ligne "Powered by Download Limiter v x.x.x"
echo "<tr><td colspan='2' style='border-top:2px solid #8d8d8d;padding-top:3px;font-style:italic;'>".
"Powered by Download Limiter v 1.2.0</td></tr>";

echo "</table></body></html>";
}

exit();
}

// test de leech
if( $FROMHOST != "" && !ereg("$FROMHOST",$_SERVER['HTTP_REFERER']) ) {
$message="Protection Anti-Leech : Access Interdit";

# HTTP_REFERER peut etre masqu?e par Norton
if ( isset($_SERVER["HTTP________"]) ) {
$message.="<p><span style='font-size:small'>Attention : Il semble que vous utilisiez un ".
"logiciel de confidentialité. Vérifiez votre antivirus par exemple.</span></p>";
}
}

// test d'existence du fichier
elseif( $message===0 && is_file("$DOSSIER/$fichier") && !ereg($EXCLUDE,$fichier)) {

/* test du temps d'attente */
if ( $TIMETOWAIT > 0 && is_file($WAITFILE) && rename("$WAITFILE","$WAITFILE.old")) {
/* ouverture de ce fichier en lecture */
$foldfile = fopen("$WAITFILE.old","r");

/* creation d'un nouveau fichier */
$fwaitfile = fopen("$WAITFILE","w");

while (!feof ($foldfile)){
$ligne = fgets($foldfile, 100);
if ($ligne != FALSE) {
$time = substr($ligne,0,strpos($ligne,":"));
$ip = substr($ligne,strpos($ligne,":")+1);
if( time() - $time < $TIMETOWAIT ) {
fwrite($fwaitfile,"$time:$ip");
if ( $ip == $_SERVER["REMOTE_ADDR"]."\n" )
$message = "Vous devez attendre ".($TIMETOWAIT - ( time() - $time) ) .
" secondes avant le<br />prochain téléchargement.";
}
}
}

fclose($fwaitfile);
fclose($foldfile);
/* suppression du fichier .old */
unlink("$WAITFILE.old");
}

/* recuperation des informations sur le fichier */
$filesize = filesize("$DOSSIER/$fichier");

if ( $message === 0 && $TAILLEMAX > 0) { // si "$message != 0" le client doit attendre

/* attente si le fichier $INFOFILE.old existe */
/* 10 seconde , au dela passage force */
while (is_file("$INFOFILE.old") && (time()-filemtime("$INFOFILE.old")<10));

/* renommage du fichier en fchier.old */
if( is_file("$INFOFILE") && rename("$INFOFILE","$INFOFILE.old")) {

$compteurtaille=0;

/* ouverture de ce fichier en lecture */
$foldfile = fopen("$INFOFILE.old","r");

/* creation d'un nouveau fichier */
$finfofile = fopen("$INFOFILE","w");

$varTimeToWait=0;

while (!feof ($foldfile)){
$ligne = fgets($foldfile, 100);
if ($ligne != FALSE) {
$time = substr($ligne,0,strpos($ligne,":"));
$size = substr($ligne,strpos($ligne,":")+1);
if( time() - $time < $PERIODE * 3600 ) {
/* pour le temps d'attente restant */
if ( $varTimeToWait===0 )
$varTimeToWait=$time;
fwrite($finfofile,"$time:$size");
$compteurtaille+=$size;
}
}
}

if ($compteurtaille + $filesize >= $TAILLEMAX) {
// taille depassee
$message = "La taille maximale de téléchargement est dépassée pour ".
"la période en cours.<br />Merci de repasser dans ";

$varTimeToWait = $PERIODE * 3600 - ( time() - $varTimeToWait );
if ( $varTimeToWait > 3600 ) {
$message.= floor($varTimeToWait/3600) . "h ";
$varTimeToWait%=3600;
}
if ( $varTimeToWait > 60 ) {
$message.= floor($varTimeToWait/60) . "m ";
$varTimeToWait%=60;
}
$message.=$varTimeToWait."s.";
}
else {
// uplaod permit
fwrite($finfofile,time().":$filesize\n");
}
fclose($finfofile);
fclose($foldfile);
/* suppression du fichier .old */
unlink("$INFOFILE.old");
}

// cas du premier upload
else {
/* creation d'un nouveau fichier */
$finfofile = fopen("$INFOFILE","w");

if ($compteurtaille + $filesize >= $TAILLEMAX) {
// taille depassee
$message = "La taille maximale de téléchargement est dépassée ".
"pour la période en cours.<br />Merci de repasser plus tard.";
}
else {
// uplaod permit
fwrite($finfofile,time().":$filesize\n");
}
fclose($finfofile);
}
}


if ( $message === 0 ) {

// sauvegarde de l'IP et de l'heure du telechargement
if ( $TIMETOWAIT > 0) {
$fwaitfile = fopen($WAITFILE,"a+");
fwrite($fwaitfile,time().":".$_SERVER["REMOTE_ADDR"]."\n");
fclose($fwaitfile);
}

/* definition des entetes */
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Cache-control: private",false);
header("Pragma: no-cache");

header("Content-Length: " . $filesize);
header("Content-Type: application/force-download");
header("Content-Type: application/download",false);
header("Content-Type: application/octetstream",false);
header("Content-Type: application/octet-stream",false);
header("Content-Disposition: attachment; filename=\"".$fichier."\"");

/* envoie du fichier (via un flux) */
if (!@readfile("$DOSSIER/$fichier")) {
echo "Erreur de droit de lecture !!!";
}

exit();
}
}
else {
$message = $message===0 ? "Le fichier \"$fichier\" n'existe pas !;" : $message;
}


// Tous ce qui suit n'est affiche que si le telechargement n'est pas possible.
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Download Limiter</title>
<?php style(); ?>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="1" id="info1">
<tr>
<td>
<table border="0" cellspacing="1" cellpadding="10" id="info2">
<tr>
<th>
Erreur de téléchargement !
</th>
</tr>
<tr>
<td>
<?=$message?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

Conclusion

Code déposé par Benoît GRUNENBERGER
www.egrunenberger.com
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Historique

19 février 2006 04:17:09 :
 
03 août 2008 14:29:26 :
Update adresse internet http://www.egrunenberger.com