[Function] Quick_Ban()

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

[Function] Quick_Ban()

Post by afterlife_69 » Fri Jul 15, 2005 1:07 pm

About: Lets you quickly ban using modes: IP, USER or EMAIL

Code: Select all

function quick_ban($entry, $mode)
{
   global $db, $lang;
   if( $mode == 'USER' )
   {
      $sql = "SELECT COUNT(user_id) FROM ".USER_TABLE." WHERE user_id = '".$entry."'";
      if ( !$result = $db->sql_query($sql) )
      {
         message_die(GENERAL_ERROR, $lang['qb_nouq'], "", __LINE__, __FILE__, $sql);
      }
      if ( is_null(array_pop($db->sql_fetchrow($result))) )
      {
         message_die(GENERAL_MESSAGE,$lang['qb_nouid'].$entry." exists.");
      }
      $type = 'ban_userid';
   }
   elseif( $mode == 'MAIL' )
   {
      $type = 'ban_email';
   }
   elseif( $mode == 'IP' )
   {
      if ( preg_match("/[^0-9\.*]/",$entry) )
      {
         message_die(GENERAL_MESSAGE,$lang['qb_iip'] . $entry);
      }
      $type = 'ban_ip';
   }
   else
   {
      message_die(GENERAL_ERROR, $lang['qb_imode']);
   }
   if( empty($entry) || $entry == "-1" )
   {
      message_die(GENERAL_ERROR, $lang['qb_ientry']);
   }
   $sql = "INSERT INTO ".BANLIST_TABLE." (`" . $type . "`) VALUES ('" . $entry . "')";
   if ( !$db->sql_query($sql) )
   {
      message_die(GENERAL_ERROR, "Couldn't insert " . $type . " entry into database.", "", __LINE__, __FILE__, $sql);
   }
}
Lang Entrys:

Code: Select all

$lang['qb_ientry'] = 'Invalid entry!';
$lang['qb_imode'] = 'Invalid Mode!';
$lang['qb_iip'] = 'Invalid IP Address: ';
$lang['qb_nouid'] = 'No user with id ';
$lang['qb_nouq'] = 'Could not query user table.';
Examples:

Code: Select all

quick_ban($userdata['user_id'], 'USER');

Code: Select all

quick_ban($userdata['user_email'], 'MAIL');

Code: Select all

quick_ban(GetHostByName($REMOTE_ADDR), 'IP');
Modes:

Code: Select all

'USER' - Bans by UserID
'EMAIL' - Bans by Email address
'IP' - Bans by ip address

~ Thanks Flaming_Cows for touching up the code.
Last edited by afterlife_69 on Sat Jul 16, 2005 6:41 am, edited 2 times in total.

User avatar
battye
Extension Customisations
Extension Customisations
Posts: 10798
Joined: Wed Feb 11, 2004 11:02 am
Location: Australia
Contact:

Post by battye » Fri Jul 15, 2005 1:41 pm

For something like:

Code: Select all

   $message = "Error!";
You could make it a lang variable for lang_main.php and make it more detailed, then:

REPLACE:

Code: Select all

  global $db; 
With

Code: Select all

  global $db, $lang; 
And you don't interfere with $lang requirements :)
Customisations Team Member

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Fri Jul 15, 2005 2:16 pm

meh, feeling bit lazy now - i just made the SAI and that took 3 and a half hours.

User avatar
Flaming_cows
Registered User
Posts: 761
Joined: Sat Jul 05, 2003 1:43 am
Contact:

Re: [Function] Quick_Ban()

Post by Flaming_cows » Fri Jul 15, 2005 2:54 pm

I cleaned it up a bunch, mostly fixed validation of fields and formatting:

Code: Select all

function quick_ban($entry, $mode)
{
	global $db;
	if( $mode == 'USER' )
	{
		$sql = "SELECT COUNT(user_id) FROM ".USER_TABLE." WHERE user_id = '".$entry."'";
		if ( !$result = $db->sql_query($sql) )
		{
			message_die{GENERAL_ERROR,"Could not query user table.","",__LINE__,__FILE__,$sql);
		}
		if ( is_null(array_pop($db->sql_fetchrow($result))) )
		{
			message_die{GENERAL_MESSAGE,"No user with id ".$entry." exists.");
		}
		$type = 'ban_userid';
	}
	elseif( $mode == 'MAIL' )
	{
		$type = 'ban_email';
	}
	elseif( $mode == 'IP' )
	{
		if ( preg_match("/[^0-9\.*]/",$entry) )
		{
			message_die(GENERAL_MESSAGE,"Invalid IP Address: ".$entry);
			}
		$type = 'ban_ip';
	}
	else
	{
		message_die(GENERAL_ERROR, "Invalid Mode");
	}
	if( empty($entry) || $entry == "-1" )
	{
		message_die(GENERAL_ERROR, "Invalid entry!");
	}
	$sql = "INSERT INTO ".BANLIST_TABLE." (`".$type."`) VALUES ('".$entry."')";
	if ( !$db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "Couldn't insert ".$type." entry into database.", "", __LINE__, __FILE__, $sql);
	}
}
You should also use $lang variables, as stated above.

afterlife_69
I've Been Banned!
Posts: 630
Joined: Tue Nov 30, 2004 10:35 am

Post by afterlife_69 » Fri Jul 15, 2005 3:55 pm

Thanks, and ill add lang entrys :D

d-iivil
Registered User
Posts: 15
Joined: Thu Aug 22, 2002 11:51 am
Location: FINLAND
Contact:

Re: [Function] Quick_Ban()

Post by d-iivil » Wed May 23, 2007 7:07 am

Could someone please give me a short lesson about how to use this?

I would like to add a button in user's post that will only be shown to admins and then give desired user instant ban.

It's so damn frustrating to go every time to admin panel, because our forum is so large and we have to ban a lot of users every day.

This would be a life saver mod.
-=Perkele=-

User avatar
battye
Extension Customisations
Extension Customisations
Posts: 10798
Joined: Wed Feb 11, 2004 11:02 am
Location: Australia
Contact:

Re: [Function] Quick_Ban()

Post by battye » Wed May 23, 2007 11:05 am

This is more or less a function that MOD authors can use in their MOD's. This isn't actually a MOD in itself.
Customisations Team Member

Post Reply

Return to “[2.0.x] MOD Writers Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests