XFileSharing Pro - help me limit users to download 1 file every x minutes
help me limit users to download 1 file every x minutes
Help me do this please, what line do i edit and what code can i add, it would be very usefull for everyone being able to set 1 file every 15 minutes.
- PilgrimX182
- Posts: 2186
- Joined: Mar 22, 2006 1:39 pm
I think this code will do the thing: in index.cgi:
replace
with
Oh, and edit message so there won't be real timeout, but something like "You can't download cause downloaded last 15 mins already", cause message will be always "wait 15 mins" after mod.
replace
Code: Select all
my $last = $db->SelectRow("SELECT *, UNIX_TIMESTAMP()-UNIX_TIMESTAMP(created) as dt
FROM IP2Files WHERE $cond
ORDER BY created DESC LIMIT 1");
my $wait = int($c->{add_download_delay}*$last->{size}/(100*1048576)) - $last->{dt};
Code: Select all
my $last = $db->SelectOne("SELECT created FROM IP2Files WHERE $cond AND created>NOW()-INTERVAL 15 MINUTE");
my $wait = 15*60 if $last;
Well.. he can extend this function and count minutes to wait too.PilgrimX182 wrote:I think this code will do the thing: in index.cgi:
replacewithCode: Select all
my $last = $db->SelectRow("SELECT *, UNIX_TIMESTAMP()-UNIX_TIMESTAMP(created) as dt FROM IP2Files WHERE $cond ORDER BY created DESC LIMIT 1"); my $wait = int($c->{add_download_delay}*$last->{size}/(100*1048576)) - $last->{dt};
Oh, and edit message so there won't be real timeout, but something like "You can't download cause downloaded last 15 mins already", cause message will be always "wait 15 mins" after mod.Code: Select all
my $last = $db->SelectOne("SELECT created FROM IP2Files WHERE $cond AND created>NOW()-INTERVAL 15 MINUTE"); my $wait = 15*60 if $last;
Here is my ugly part of code for this function. Might be useable for others customers:
Code: Select all
if($c->{add_download_delay})
{
my $cond = $ses->getUser ? "usr_id=".$ses->getUserId : "ip=INET_ATON('".$ses->getIP."')";
# my $last = $db->SelectRow("SELECT *, UNIX_TIMESTAMP()-UNIX_TIMESTAMP(created) as dt
# FROM IP2Files WHERE $cond
# ORDER BY created DESC LIMIT 1");
# my $wait = int($c->{add_download_delay}*$last->{size}/(100*1048576)) - $last->{dt};
my $last = $db->SelectRow("SELECT created FROM IP2Files WHERE $cond AND created>NOW()-INTERVAL 15 MINUTE");
my $wait = 15*60 if $last;
if($wait>0)
{
my ($y, $m, $d, $hh, $mm, $ss) = (localtime)[5,4,3,2,1,0]; $y += 1900; $m++;
my $iso_now = sprintf("%d-%02d-%02d %02d:%02d:%02d", $y, $m, $d, $hh, $mm, $ss);
my $timeDiffStr = &timeDiff( date1 => $last->{created}, date2 => $iso_now );
sub timeDiff (%) {
my %args = @_;
my @offset_days = qw(0 31 59 90 120 151 181 212 243 273 304 334);
my $year1 = substr($args{'date1'}, 0, 4);
my $month1 = substr($args{'date1'}, 5, 2);
my $day1 = substr($args{'date1'}, 8, 2);
my $hh1 = substr($args{'date1'},11, 2) || 0;
my $mm1 = substr($args{'date1'},14, 2) || 0;
my $ss1 = substr($args{'date1'},17, 2) if (length($args{'date1'}) > 16);
$ss1 ||= 0;
my $year2 = substr($args{'date2'}, 0, 4);
my $month2 = substr($args{'date2'}, 5, 2);
my $day2 = substr($args{'date2'}, 8, 2);
my $hh2 = substr($args{'date2'},11, 2) || 0;
my $mm2 = substr($args{'date2'},14, 2) || 0;
my $ss2 = substr($args{'date2'},17, 2) if (length($args{'date2'}) > 16);
$ss2 ||= 0;
my $total_days1 = $offset_days[$month1 - 1] + $day1 + 365 * $year1;
my $total_days2 = $offset_days[$month2 - 1] + $day2 + 365 * $year2;
my $days_diff = $total_days2 - $total_days1;
my $seconds1 = $total_days1 * 86400 + $hh1 * 3600 + $mm1 * 60 + $ss1;
my $seconds2 = $total_days2 * 86400 + $hh2 * 3600 + $mm2 * 60 + $ss2;
my $ssDiff = $seconds2 - $seconds1;
my $dd = int($ssDiff / 86400);
my $hh = int($ssDiff / 3600) - $dd * 24;
my $mm = int($ssDiff / 60) - $dd * 1440 - $hh * 60;
my $ss = int($ssDiff / 1) - $dd * 86400 - $hh * 3600 - $mm * 60;
"$mm";
}
my $czekam = 15 - $timeDiffStr;
$file->{message} = "<font color=red>You have reached the download limit for free-users.</font><br>You can wait download for $czekam minutes or upgrade to premium. ";
}
Have a fun and enjoy. I think this part of code might be add to the 1.6 release with the option: Delay between downloads.
What do you think ?