[BETA] MOD Ban_cookie: Ban users with a cookie

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

chris3471 wrote: So what happens if you ban someone and then they delete their cookies?


Asked and answered
Need custom work done? Pimp My Forum!

deadjdona
Registered User
Posts: 8
Joined: Tue Feb 28, 2006 9:09 am

try to make some free CPU cycles

Post by deadjdona »

If you want to make this mod little faster try to change

Code: Select all

 //Set the ban_cookie, time it for 1 year. The time restarts every time the user comes here 
    if ($banned_ip) setcookie($board_config['cookie_name'].'_banned_ip',$banned_ip, time()+365*24*3600); 
    if ($banned_id) setcookie($board_config['cookie_name'].'_banned_id',$banned_id, time()+365*24*3600); 
365 * 24 * 3 600 = 31 536 000

:lol:

Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

Yes theoretically you are right. However, we're dealing with a once-only calculation and the time it takes to send the finished html over the net is thousands times slower than this calculation. So I've opted to keep it very clear and the main reason: easy to change without having to figure out what the number means...
Need custom work done? Pimp My Forum!

User avatar
maxklm
Registered User
Posts: 7
Joined: Tue Jul 05, 2005 8:07 pm
Location: Russia
Contact:

Post by maxklm »

Where still changes?

User avatar
Sassy
Registered User
Posts: 95
Joined: Sat Aug 31, 2002 6:13 am

Post by Sassy »

Hi,

Do you think you can show me how to install your mod while I have Temp Banned mod install as well.

http://phpbbmodders.com/mods/tempban/tempban_1.1.1.txt

By the way, this is a cool mod as well.
:)

Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

Sassy wrote: Hi,

Do you think you can show me how to install your mod while I have Temp Banned mod install as well.

http://phpbbmodders.com/mods/tempban/tempban_1.1.1.txt

By the way, this is a cool mod as well.
:)


Thanks.

To install, just follow the instructions. If you run into conflicts, you may have a think whether you need both mods or one of them is enough.
Need custom work done? Pimp My Forum!

EzerchE
Registered User
Posts: 102
Joined: Fri Apr 08, 2005 11:22 pm

Post by EzerchE »

i am not soo good as php but i change the codes for bantron mod available:

Code: Select all

  //START MOD Ban_cookie
  //Give banned users a cookie and check that too, in addition to the existing checks.
  //Once the cookie is in place: if it matches the database, the user is banned,
  //even if the user gets another IP or is not logged in so the user ID is unknown.

  //Get cookie ban settings.
  $ban_cookie = '';
  $banned_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'].'_banned_id']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'].'_banned_id'] : '';
  $banned_ip = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'].'_banned_ip']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'].'_banned_ip'] : '';
 
  //Yes, cookie ban settings were there. See if they match the database.
  //If not, delete cookie.
  if ($banned_ip || $banned_id)
  {
    $sql = "SELECT *
       FROM " . BANLIST_TABLE . "
        WHERE ";
      $sql .= ($banned_ip) ? " ban_ip = '" . $banned_ip . "'" : '';
      $sql .= ($banned_id) ? ($banned_ip ? ' OR ' : '') . ' ban_userid = ' . $banned_id : '';
     if ( !($result = $db->sql_query($sql)) )
     {
        message_die(CRITICAL_ERROR, 'Could not obtain ban information', '', __LINE__, __FILE__, $sql);
     }
     if ( $ban_info = $db->sql_fetchrow($result) )    
    {
      $ban_cookie =  ( $ban_info['ban_ip'] || $ban_info['ban_userid'] && ((isset ($ban_info['ban_expire_time']) && $ban_info['ban_expire_time'] >= time ()) || !isset ($ban_info['ban_expire_time'])) );
     }
    //There was a cookie but no match in the database, so the ban is lifted:
    //delete the cookie by setting the expiry time 1 hour ago   
    if (! $ban_cookie)
    {
      if ($banned_ip) setcookie($board_config['cookie_name'].'_banned_ip',$banned_ip, time()-3600);
      if ($banned_id) setcookie($board_config['cookie_name'].'_banned_id',$banned_id, time()-3600);
     }
  }   
  //Have $ban_cookie, if not empty, the user is banned via a cookie.
  //If empty, then there was no cookie, or there was no LONGER a database match so the cookie was deleted

  //Check if there is database ban info - this is roughly the original ban code
  $ban_database = '';
   $sql = "SELECT *
      FROM " . BANLIST_TABLE . "
      WHERE ban_ip IN ('" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . $user_ip_parts[4] . "', '" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . "ff', '" . $user_ip_parts[1] . $user_ip_parts[2] . "ffff', '" . $user_ip_parts[1] . "ffffff')
         OR ban_userid = $user_id";
   if ( $user_id != ANONYMOUS )
   {
      $sql .= " OR ban_email LIKE '" . str_replace("\'", "''", $userdata['user_email']) . "'
         OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'";
   }
   if ( !($result = $db->sql_query($sql)) )
   {
      message_die(CRITICAL_ERROR, 'Could not obtain ban information', '', __LINE__, __FILE__, $sql);
   }
   if ( $ban_info = $db->sql_fetchrow($result) )    
  {
    $ban_database = ( $ban_info['ban_ip'] || $ban_info['ban_userid'] || $ban_info['ban_email'] && ((isset ($ban_info['ban_expire_time']) && $ban_info['ban_expire_time'] >= time ()) || !isset ($ban_info['ban_expire_time']))  );
    //Fill these variables from database if not filled from cookie yet
    if (! $banned_ip) $banned_ip = $ban_info['ban_ip'];
    if (! $banned_id) $banned_id = $ban_info['ban_userid'];    
  }
 
  //User is banned in some way?
  if ($ban_cookie || $ban_database)
  {
    //Set the ban_cookie, time it for 1 year. The time restarts every time the user comes here
    if ($banned_ip) setcookie($board_config['cookie_name'].'_banned_ip',$banned_ip, time()+365*24*3600);
    if ($banned_id) setcookie($board_config['cookie_name'].'_banned_id',$banned_id, time()+365*24*3600);
     //Close the forum to this person
			if ($ban_info['ban_pub_reason_mode'] == '0' || !isset ($ban_info['ban_pub_reason_mode'])) {
				$reason = 'You_been_banned';
			} else if ($ban_info['ban_pub_reason_mode'] == '1') {
				$reason = str_replace ("\n", '<br />', stripslashes ($ban_info['ban_priv_reason']));
			} else if ($ban_info['ban_pub_reason_mode'] == '2') {
				$reason = str_replace ("\n", '<br />', stripslashes ($ban_info['ban_pub_reason']));
			}
				
			message_die(CRITICAL_MESSAGE, $reason);
  }
  //END MOD Ban_cookie 


Ghost_dk1
Registered User
Posts: 1
Joined: Tue Dec 12, 2006 4:24 pm

Post by Ghost_dk1 »

would it be possible to combine this mod with some sort of "must allow cokie to register" mod?

Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

Of course you can always check if there is a standard cookie set, and if not, deny access to the forum. And add a line to your registration screen explaining this.
Need custom work done? Pimp My Forum!

User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Post by igorw »

Merlin Sythove, are there any plans of submitting this to the moddb?
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

No, I don't have the time to do that. If someone else wants to invest time and effort in this respect, please get in touch.
Need custom work done? Pimp My Forum!

User avatar
Ramon Fincken
Registered User
Posts: 4835
Joined: Thu Oct 14, 2004 1:04 am
Location: NL, The Netherlands Amsterdam area @GMT +1
Contact:

Post by Ramon Fincken »

evil<3 , will you prepare it for submittal or will I :) ?
Dutch quality fully managed WordPress hosting - ManagedWPHosting.nl

Before changing a file, some code or installing a MOD >> Make a backup first!

Do you like my mods? paypal me $1 :) forumsoftware[AT}creativepulses[DOT}nl [/size]
PhpBBantispam.com || Instant find your mod here

lele710
Registered User
Posts: 66
Joined: Thu Oct 20, 2005 7:52 pm

Post by lele710 »

Hi,
nice mod but...
i want another function in that...

I want that a specific user cannot be banned...

How can i do this?


Thanks

User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Post by igorw »

lele710 wrote: Hi,
nice mod but...
i want another function in that...

I want that a specific user cannot be banned...

How can i do this?


Thanks


Start a new topic in the MOD request forums...
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

lele710
Registered User
Posts: 66
Joined: Thu Oct 20, 2005 7:52 pm

Post by lele710 »

eviL<3 wrote:
lele710 wrote:Hi,
nice mod but...
i want another function in that...

I want that a specific user cannot be banned...

How can i do this?


Thanks


Start a new topic in the MOD request forums...


Ok.

New topic is here

Post Reply

Return to “[2.0.x] MODs in Development”