RegisterRegister    SearchSearch   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AJAX upload progress bar

File sharing script

File mirror script

Newsletter script
help me limit users to download 1 file every x minutes

 
Post new topic   Reply to topic    SibSoft Ltd Forum Index -> XFileSharing Pro
View previous topic :: View next topic  
Author Message
Eskick



Joined: 10 Mar 2009
Posts: 81

PostPosted: Jul 01, 2009 11:10 pm    Post subject: help me limit users to download 1 file every x minutes Reply with quote

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.
Back to top
View user's profile Send private message
PilgrimX182



Joined: 22 Mar 2006
Posts: 2106
Location: UFO Lab

PostPosted: Jul 02, 2009 12:58 pm    Post subject: Reply with quote

Download you mean?
Back to top
View user's profile Send private message Visit poster's website
Eskick



Joined: 10 Mar 2009
Posts: 81

PostPosted: Jul 03, 2009 12:16 am    Post subject: Reply with quote

Yeah thats what i mean
Back to top
View user's profile Send private message
PilgrimX182



Joined: 22 Mar 2006
Posts: 2106
Location: UFO Lab

PostPosted: Jul 03, 2009 6:20 am    Post subject: Reply with quote

I think this code will do the thing: in index.cgi:
replace
Code:
      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:
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.
Back to top
View user's profile Send private message Visit poster's website
Eskick



Joined: 10 Mar 2009
Posts: 81

PostPosted: Jul 03, 2009 10:12 am    Post subject: Reply with quote

thanks but i cant find the first line, are you sure it exists?
Back to top
View user's profile Send private message
PilgrimX182



Joined: 22 Mar 2006
Posts: 2106
Location: UFO Lab

PostPosted: Jul 03, 2009 11:22 am    Post subject: Reply with quote

Exist in 1.5
Back to top
View user's profile Send private message Visit poster's website
Eskick



Joined: 10 Mar 2009
Posts: 81

PostPosted: Jul 03, 2009 11:28 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
dzimi83



Joined: 09 Mar 2009
Posts: 66

PostPosted: Jul 05, 2009 12:00 am    Post subject: Reply with quote

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

   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 ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SibSoft Ltd Forum Index -> XFileSharing Pro All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group