Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2011, 03:28 PM
Kaemon Kaemon is offline
 
Join Date: Nov 2004
Location: Camp Hill, PA
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Blocking an IP Address without HTACCESS

I want to block any traffic coming from 119.63.196.x but I can't use an HTACCESS file because I'm on a Windows Server (we have an ASP.Net website).

To block the IP address, I want to run this PHP script on every page:

Code:
if(substr($_SERVER['REMOTE_ADDR'], 0, 10) == "119.63.196"){exit;}
To be honest, I haven't quite figured out how to write PHP code into the style template header yet. The layer of abstraction using IF CONDITION = is new to me and I haven't run across the tutorial or manual explaining it yet. ?????

Should I add this code to the global.php file? (I'm using vBulletin 3.7.4)

In case you were wondering, 119.63.196 are Baiduspider bots. Baidu is China's search engine (like Google) and they have dozens of spiders constantly indexing our site.
Reply With Quote
  #2  
Old 08-03-2011, 03:56 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you talked to your host about other methods to block ips? What about iptables?
Reply With Quote
  #3  
Old 08-03-2011, 03:59 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Isn't there an option for that already?

AdminCP > Options > User Banning > Banned IP Addresses
Quote:
Use this option to prevent certain IP addresses from accessing any part of your board.

If you enter a complete IP address (242.21.11.7), only that IP will be banned.
If you enter a partial IP (243.21.11. or 243.21.11), any IPs that begin with the partial IP will be banned. For example, banning 243.21.11 will prevent 243.21.11.7 from accessing your board. However, 243.21.115.7 would still be able to access your board.

You may also use an '*' as a wildcard for increased flexibility. For example, if you enter 243.21.11*, many IPs will be banned including: 243.21.11.7, 243.21.115.7, 243.21.119.225.

Place a space or a line break between each IP address.
Reply With Quote
  #4  
Old 08-04-2011, 03:20 PM
Kaemon Kaemon is offline
 
Join Date: Nov 2004
Location: Camp Hill, PA
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adrian Schneider View Post
Isn't there an option for that already?

AdminCP > Options > User Banning > Banned IP Addresses
Yes, we did ban that IP range through the ACP but whenever we look at "Who's Online", 80% are bots from that IP. I suspect that they are just indexing our site for China's search engine but our head forum admin wants to block them anyway to be safe.

Normally, this would be as easy as adding a line of code to the header template (see above).

So if I wanted to add the code below to the top of every page, how would I do it if I can't write PHP in the style templates area? Can someone point me to a manual or tutorial?

Code:
<php? ECHO "hello world"; ?>
--------------- Added [DATE]1312474978[/DATE] at [TIME]1312474978[/TIME] ---------------

Quote:
Originally Posted by Lynne View Post
Have you talked to your host about other methods to block ips? What about iptables?
Our site is on GoDaddy and they had no solution since we are on a Windows server. I can use a web.config file to block IP addresses from accessing our ASP.Net website but that won't work for our PHP forum. I've never heard of using IPtables to block traffic. ??
Reply With Quote
  #5  
Old 08-04-2011, 03:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There is a free spam blocking product called zbblock which works in the same way (code is inserted at the top of each page). Their instructions say to do this:

Code:
<php? ECHO "hello world"; ?><?php

where the <?php in red is the existing one at the beginning of global.php. I think the reason for having them on the same line is that if you put a newline between them, the newline character will get sent as part of the document and you'll get "header already sent" errors. You could also just put your code on line two so that it was inside the existing <?php tag, but I think they figured this way would keep their added code separate.

BTW, zbblock is a product that does something similar to what you're trying to do, except that it builds up a list of ips to block by scanning for attacks (and I believe it blocks spiders). We used it for a while and it was pretty good except that it was too aggressive about blocking some legit users, mostly because it thought some search result urls were SQL injection attempts. If I had had more time I think I could have tried to solve that issue myself (or asked for help on their forum). In any case they may have done something about that since I tried it
Reply With Quote
  #6  
Old 08-04-2011, 04:22 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Add the following to your htaccess. Both of the IPs listed are for the Baidu spider. I had a similar issue a few days ago and this stopped them dead in their tracks.

Code:
<Files *.*>
        order allow,deny
        allow from all
        deny from 119.63.196.
        deny from 220.181.108.	
</Files>
Reply With Quote
  #7  
Old 08-04-2011, 06:07 PM
Kaemon Kaemon is offline
 
Join Date: Nov 2004
Location: Camp Hill, PA
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Boofo View Post
Add the following to your htaccess. Both of the IPs listed are for the Baidu spider. I had a similar issue a few days ago and this stopped them dead in their tracks.

Code:
<Files *.*>
        order allow,deny
        allow from all
        deny from 119.63.196.
        deny from 220.181.108.	
</Files>
thanks for the suggestion but, as I understand it, an htaccess file doesn't work on our windows-based server (IIS). We hope to develop a new website in PHP that replaces our ASP.Net website so we can move to apache. That might be a long while though...

--------------- Added [DATE]1312485012[/DATE] at [TIME]1312485012[/TIME] ---------------

Quote:
Originally Posted by kh99 View Post
There is a free spam blocking product called zbblock which works in the same way (code is inserted at the top of each page).
Thanks! I think we'll try that.

Another admin just tried adding this within the vBulletin header template.

Code:
<!-- Block specific IP from continuing -->
<if condition=user[ipaddress] = "119.63.196.***" meta HTTP-EQUIV="REFRESH" content="0; 
url=http://www.msxlabs.org/banned.php"> 
<!-- End Block of specific IP -->
All of the users/bots from that IP address currently show that they are viewing an error message. At this point, I'm not sure if that's from my code or his code...or if it was there before.
Reply With Quote
  #8  
Old 08-04-2011, 06:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I'm not sure about the meta tag thing, but the template conditional should be something like:

HTML Code:
<!-- Block specific IP from continuing -->
<if condition="user[ipaddress] == '119.63.196.***'">
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.msxlabs.org/banned.php"> 
</if>
<!-- End Block of specific IP -->

But even with that, I don't think that comparison with wildcards would work. And unfortunately there is a short list of functions you're allowed to use in a condition, and none of them let you compare substrings. So if you really wanted to go that route you'd have to do the comparison in a plugin and set a variable to use in the condition. Hope that makes sense
Reply With Quote
  #9  
Old 08-04-2011, 07:07 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Add a plugin to init_startup

PHP Code:
if (strpos($_SERVER['REMOTE_ADDR'], '119.63.196.') === 0)
{
    exit;

This says:
Code:
if IP starts with "119.63.196." 
then spit out a blank page
Reply With Quote
  #10  
Old 08-04-2011, 07:41 PM
Kaemon Kaemon is offline
 
Join Date: Nov 2004
Location: Camp Hill, PA
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Adrian Schneider View Post
Add a plugin to init_startup
It worked! Dude! You rock! Thanks!!! :up:

That was my first plugin btw. Everything makes so much more sense now.


Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:00 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04864 seconds
  • Memory Usage 2,266KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete