Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Importing SMF IPv6 mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy D committed Sep 28, 2011
0 parents commit 36ad49f
Show file tree
Hide file tree
Showing 6 changed files with 841 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,24 @@
Copyright (c) 2011, SleePy (smf-mods-license@sleepycode.com)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 changes: 18 additions & 0 deletions README.txt
@@ -0,0 +1,18 @@
IPv6 support for SMF 2.0+ Only. I will not backport these changes to 1.1.

This customization will add support for the IPv6 enabled clients in SMF 2.0. Specifically posts, ip tracking and ban management have been changed. Member search from the admin panel does support this by default.

Due to the size and necessity of the changes, please do not continue with installation if any change should fail the test. This may lead to unexpected results or a unusable forum.

Note: During uninstallation, all IPv6 enabled bans will be disabled. This customization makes attempts to track those changes in columns it adds to the ban_items table. If you remove the database changes, this tracking will be lost. In addition upon reinstallation this customization makes attempts to re-enable those bans that should still be active.

Note: Currently you are unable to link via iurl/url or auto linking ipv6 urls. This is due to the square brackets that ipv6 addresses are enclosed in. However this doesn't affect domains.

Thanks to [url=http://www.soucy.org]Ray Soucy[/url]'s for his IPv6 functions he wrote and allowing usage of them in this customization.

This customization is released under the BSD 3-Clause license. The terms of the license are including in this package (LICENSE.txt) or available on Simple Machines website at http://www.simplemachines.org/about/smf/license.php.

ChangeLog:

Version 1.0
! Release
108 changes: 108 additions & 0 deletions database_install.php
@@ -0,0 +1,108 @@
<?php
error_reporting(E_ALL);

// Hopefully we have the goodies.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
{
$using_ssi = true;
require_once(dirname(__FILE__) . '/SSI.php');
}
elseif (!defined('SMF'))
exit('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

global $db_prefix, $modSettings, $func, $smcFunc;

// Fields to add
$new_fields = array(
'is_ipv6' => array('name'=> 'is_ipv6', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_low5' => array('name'=> 'ip_low5', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_high5' => array('name'=> 'ip_high5', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_low6' => array('name'=> 'ip_low6', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_high6' => array('name'=> 'ip_high6', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_low7' => array('name'=> 'ip_low7', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_high7' => array('name'=> 'ip_high7', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_low8' => array('name'=> 'ip_low8', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
'ip_high8' => array('name'=> 'ip_high8', 'type'=>'SMALLINT(255)', 'unsigned' => true, 'default' => 0),
);

$changed_fields = array(
'ip_low1' => array('name'=> 'ip_low1', 'type'=>'SMALLINT(255)'),
'ip_high1' => array('name'=> 'ip_high1', 'type'=>'SMALLINT(255)'),
'ip_low2' => array('name'=> 'ip_low2', 'type'=>'SMALLINT(255)'),
'ip_high2' => array('name'=> 'ip_high2', 'type'=>'SMALLINT(255)'),
'ip_low3' => array('name'=> 'ip_low3', 'type'=>'SMALLINT(255)'),
'ip_high3' => array('name'=> 'ip_high3', 'type'=>'SMALLINT(255)'),
'ip_low4' => array('name'=> 'ip_low4', 'type'=>'SMALLINT(255)'),
'ip_high4' => array('name'=> 'ip_high4', 'type'=>'SMALLINT(255)'),
);

// Load up the board info, we will only add these once.
$table_columns = $smcFunc['db_list_columns']($db_prefix . 'ban_items');

// Do the loopy, loop, loe.
foreach ($new_fields as $column_name => $column_attributes)
if (!in_array($column_name, $table_columns))
$smcFunc['db_add_column']($db_prefix . 'ban_items', $column_attributes);

// Do the loopy, loop, loe.
foreach ($changed_fields as $column_name => $column_attributes)
$smcFunc['db_change_column']($db_prefix . 'ban_items', $column_attributes);

// Find any IPv6 bans and reenable them again.
// !!! Note, We changed is_ipv6 to the time stamp of when it is supposed of expired, 1 if it was a perm ban.
$result = $smcFunc['db_query']('', '
SELECT id_ban_group, is_ipv6
FROM {db_prefix}ban_items
WHERE is_ipv6 < {int:is_ipv6}',
array(
'is_ipv6' => '1'
));

$enabled_bans = array();
$disabled_bans = array();
$lost_bans = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['is_ipv6'] == 1)
$enabled_bans[] = $row['id_ban_group'];
elseif ($row['is_ipv6'] > 1 && time() < $row['is_ipv6'])
$enabled_bans[] = $row['id_ban_group'];
elseif ($row['is_ipv6'] > 1 && time() > $row['is_ipv6'])
$disabled_bans[] = $row['id_ban_group'];
// Where did you come from?
else
$lost_bans[] = $row['id_ban_group'];

// Not the best way, but will do the job.
$smcFunc['db_query']('', '
UPDATE {db_prefix}ban_groups
SET expire_time = {raw:expire}
WHERE id_ban_group = {int:ban_group}',
array(
'expire' => $row['is_ipv6'] == 1 ? 'NULL' : $row['is_ipv6'],
'ban_group' => $row['id_ban_group'],
));
}

// Ok, We just re-enable these.
$smcFunc['db_query']('', '
UPDATE {db_prefix}ban_items
SET is_ipv6 = {int:enabled}
WHERE is_ipv6 < {int:enabled}',
array(
'enabled' => '1',
));

// Handle our lost bans.
if (!empty($lost_bans) && !empty($using_ssi))
echo 'We had some bans that we could not properly enable. Please check these ban ids:', implode(', ', $lost_bans), '<br />';

// For debugging/support purposes.
if (!empty($lost_bans))
log_error('Lost bans during IPV6 re-enabling:', implode(', ', $lost_bans), 'critical');

// Update our ban time, forcing rechecks to occur.
updateSettings(array('banLastUpdated' => time()));

if(!empty($using_ssi))
echo 'If no errors, Success!';
56 changes: 56 additions & 0 deletions database_remove.php
@@ -0,0 +1,56 @@
<?php
error_reporting(E_ALL);

// Hopefully we have the goodies.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
{
$using_ssi = true;
require_once(dirname(__FILE__) . '/SSI.php');
}
elseif (!defined('SMF'))
exit('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

global $db_prefix, $modSettings, $func, $smcFunc;

// Find any IPv6 bans.
$result = $smcFunc['db_query']('', '
SELECT bi.id_ban_group, bi.is_ipv6, bg.expire_time
FROM {db_prefix}ban_items AS bi
INNER JOIN {db_prefix}ban_groups AS bg ON (bi.id_ban_group = bg.id_ban_group)
WHERE bi.is_ipv6 = {int:is_ipv6}',
array(
'is_ipv6' => '1'
));

$ipv6_bans = array();
while($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['expire_time'] != 'NULL')
$smcFunc['db_query']('', '
UPDATE {db_prefix}ban_items
SET is_ipv6 = {raw:expire_time}
WHERE id_ban_group = {int:ban_group}',
array(
'expire_time' => $row['expire_time'],
'ban_group' => $row['id_ban_group'],
));

$ipv6_bans[] = $row['id_ban_group'];
}

// Do a mass update to disable these bans.
$smcFunc['db_query']('', '
UPDATE {db_prefix}ban_groups
SET expire_time = {int:expired_time}
WHERE id_ban_group IN ({array_int:bans})',
array(
'expired_time' => time() - 60, // 1 minute ago should do.
'bans' => $ipv6_bans
));

// Update our ban time, forcing rechecks to occur.
updateSettings(array('banLastUpdated' => time()));

if(!empty($using_ssi))
echo 'If no errors, Success!';
?>

0 comments on commit 36ad49f

Please sign in to comment.