XMB Forum Software
Not logged in [Login - Register]
Go To Bottom

Printable Version  
 Pages:  1  2
Author:

[New] IP Banning help / questions

Mouser
XMB Contributor
********


Avatar


Posts: 198
Registered: 4-14-2008
Member Is Offline

Mood: Christmasy. Yes, in September.

[*] posted on 8-31-2013 at 07:21 AM


Odd, worked fine on my tests.

When I copied from my own post, the line breaks were gone. So here it is in TXT format.


Please note, it will not ban you as an admin..

Attachment: 12345.txt (3kB)
This file has been downloaded 154 times
View user's profile View All Posts By User
quibel
Member
***




Posts: 24
Registered: 8-27-2013
Member Is Offline


[*] posted on 9-1-2013 at 09:09 PM


here is the end of my config. I placed the code at the end of the debug mode and before the end of the file.

Quote:

// Debug-mode

/**
* To turn on DEBUG mode (you can then see ALL queries done at the bottom of each screen (except buddy-list & u2u)
* just uncomment this variable. These queries are ONLY visible to the user currently loading that page
* and ONLY visible to Super Administrators. Comment first line and uncomment second line to use debug mode.
*/

define('DEBUG', FALSE);
// define('DEBUG', TRUE);

/**
* To enable logging of all MySQL errors (necessary in the case of registration, login, or captcha errors), comment first
* line and uncomment second line. Note the log file will be visible to the public unless it is protected
* by your web server configuration. The file name will be 'error_log' unless you change the PHP configuration.
* If the chmod settings of this directory prevent file Write then the log will not be created.
*/

define('LOG_MYSQL_ERRORS', FALSE);
// define('LOG_MYSQL_ERRORS', TRUE);


//IP Range Banning
$banned_ranges = array (
'1.1.1.1|10.255.255.255',
'11.1.1.1|111.255.255.255',
'112.1.1.1|211.255.255.255',
'222.1.1.1|255.255.255.255'
);


// Do not edit below this line.
// ---------------------------
return;
?>


are my IP ranges ok ... just want a blanket range while I test and will replace later with correct ranges.


in the functions file I found the last function and added the new code above the end of the file. As mentioned i renamed the function to ip_ban_range

Quote:

function nonce_use($key, $nonce, $expire = 0) {
global $db;

$key = substr($key, 0, X_NONCE_KEY_LEN);
$db->escape_fast($key);
$db->escape_fast($nonce);
$time = time() - X_NONCE_MAX_AGE;
$sql_expire = "dateline < $time";
if ($expire > 0 and $expire < X_NONCE_MAX_AGE) {
$time = time() - $expire;
$sql_expire .= " OR imagestring='$key' AND dateline < $time";
}
$db->query("DELETE FROM ".X_PREFIX."captchaimages WHERE $sql_expire");
$db->query("DELETE FROM ".X_PREFIX."captchaimages WHERE imagehash='$nonce' AND imagestring='$key'");

return ($db->affected_rows() === 1);
}

function ip_ban_range ($ip) {
global $banned_ranges;
$long_ip = ip2long ($ip);
if ($long_ip != -1) {
foreach ($banned_ranges AS $pri_addr) {
list ($start, $end) = explode('|', $pri_addr);
if ($long_ip >= ip2long ($start) && $long_ip <= ip2long ($end)) {
return true;
}
}
}

return false;
}

return;
?>



and finally header having chaned the function call to ip_ban_range as well
Quote:

// Check if the client is ip-banned
if ($SETTINGS['ip_banning'] == 'on') {
$ips = explode(".", $onlineip);
$query = $db->query("SELECT id FROM ".X_PREFIX."banned WHERE ((ip1='$ips[0]' OR ip1='-1') AND (ip2='$ips[1]' OR ip2='-1') AND (ip3='$ips[2]' OR ip3='-1') AND (ip4='$ips[3]' OR ip4='-1')) AND NOT (ip1='-1' AND ip2='-1' AND ip3='-1' AND ip4='-1')");
$result = $db->num_rows($query);
$db->free_result($query);
if ($result > 0) {
// Block all non-admins
$serror = 'ip';
}
if ( ip_ban_range($onlineip) ) {
$serror = 'ip';
}
}


one thing to note - If i only put in one range 1.1.1.1|255.255.255.255 it makes no difference and i simply get the you are not registered or logged in message

help
View user's profile View All Posts By User
quibel
Member
***




Posts: 24
Registered: 8-27-2013
Member Is Offline


[*] posted on 9-7-2013 at 08:17 PM


any ideas mouser? what range did you put in to test?

Q
View user's profile View All Posts By User
 Pages:  1  2

  Go To Top

Powered by XMB 1.9.11 (Debug Mode)
Forum Script Software by XMB © 2001-2017 The XMB Group
[Queries: 16] [PHP: 23.2% - SQL: 76.8%]
Funded with thanks to competitions website.