XFileSharing Pro - help me limit users to download 1 file every x minutes

Message
Author
Eskick
Posts: 86
Joined: Mar 10, 2009 11:47 am

help me limit users to download 1 file every x minutes

#1 Postby Eskick » Jul 01, 2009 11:10 pm

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.

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#2 Postby PilgrimX182 » Jul 02, 2009 12:58 pm

Download you mean?

Eskick
Posts: 86
Joined: Mar 10, 2009 11:47 am

#3 Postby Eskick » Jul 03, 2009 12:16 am

Yeah thats what i mean

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#4 Postby PilgrimX182 » Jul 03, 2009 6:20 am

I think this code will do the thing: in index.cgi:
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};
with

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;
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.

Eskick
Posts: 86
Joined: Mar 10, 2009 11:47 am

#5 Postby Eskick » Jul 03, 2009 10:12 am

thanks but i cant find the first line, are you sure it exists?

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#6 Postby PilgrimX182 » Jul 03, 2009 11:22 am

Exist in 1.5

Eskick
Posts: 86
Joined: Mar 10, 2009 11:47 am

#7 Postby Eskick » Jul 03, 2009 11:28 am

what line should i modify in 1.4, you didnt provide an upgrade package so it was impossible for a working site to upgrade to 1.5

dzimi83
Posts: 66
Joined: Mar 09, 2009 1:08 pm

#8 Postby dzimi83 » Jul 05, 2009 12:00 am

PilgrimX182 wrote:I think this code will do the thing: in index.cgi:
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};
with

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;
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.
Well.. he can extend this function and count minutes to wait too.
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. ";
      }
It's rewrote functions found on the internet, that's why it's ugly and need to be rewrite.
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 ?