Ideas of making u-232 ipv6 able.

Started by Tundracanine, August 29, 2017, 09:10:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

baiyou2015

Good idea, look forward to adding ipv6 support

antimidas

nice! good topic.... Will have to be addressed sooner or later


Tundracanine

This topic is about the start of making u-232 versions ipv6 able.
This is very unfinished and basically a topic about getting ideas how to do it.
Original idea started out from http://php.net/manual/en/function.ip2long.php
you will need php gmp-lib cause ipv6 is so long and also to alter in phpmyadmin all ip fields like the one in uses to 59 length or more
ALTER TABLE `failedlogins` CHANGE `ip` `ip` VARCHAR(59) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
ALTER TABLE `users` CHANGE `ip` `ip` VARCHAR(59) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;

1st off you will need these functions in bitorrent.php
this is taken from https://github.com/Arkhana/TorrentTrader2.08/blob/master/upload/backend/functions.php
function is_ipv6 ($s) {
return is_int(strpos($s, ":"));
}
// Taken from php.net comments
function ip2long6($ipv6) {
  $ip_n = inet_pton($ipv6);
  $bits = 15; // 16 x 8 bit = 128bit
  while ($bits >= 0) {
    $bin = sprintf("%08b",(ord($ip_n[$bits])));
    $ipv6long = $bin.$ipv6long;
    $bits--;
  }
  return gmp_strval(gmp_init($ipv6long,2),10);
}
function long2ip6($ipv6long) {
  $bin = gmp_strval(gmp_init($ipv6long,10),2);
  if (strlen($bin) < 128) {
    $pad = 128 - strlen($bin);
    for ($i = 1; $i <= $pad; $i++) {
    $bin = "0".$bin;
    }
  }
  $bits = 0;
  while ($bits <= 7) {
    $bin_part = substr($bin,($bits*16),16);
    $ipv6 .= dechex(bindec($bin_part)).":";
    $bits++;
  }
  // compress
  return inet_ntop(inet_pton(substr($ipv6,0,-1)));
}


replace in same file
//== check bans by djGrrr <3 pdq
function check_bans($ip, &$reason = '')
{
    global $INSTALLER09, $mc1, $c;
    //$ip_decrypt = $c->decrypt($ip);
    $key = 'bans:::' . $ip;
    if (($ban = $mc1->get_value($key)) === false && $ip != '127.0.0.1') {
        $nip = ip2long($ip);
        $ban_sql = sql_query('SELECT comment FROM bans WHERE (first <= ' . $nip . ' AND last >= ' . $nip . ') LIMIT 1');
        if (mysqli_num_rows($ban_sql)) {
            $comment = mysqli_fetch_row($ban_sql);
            $reason = 'Manual Ban (' . $comment[0] . ')';
            $mc1->cache_value($key, $reason, 86400); // 86400 // banned
            return true;
        }
        ((mysqli_free_result($ban_sql) || (is_object($ban_sql) && (get_class($ban_sql) == "mysqli_result"))) ? true : false);
        $mc1->cache_value($key, 0, 86400); // 86400 // not banned
        return false;
    } elseif (!$ban) return false;
    else {
        $reason = $ban;
        return true;
    }
}

with

//== check bans by djGrrr <3 pdq
function check_bans($ip, &$reason = '')
{
    global $INSTALLER09, $mc1, $c;
    //$ip_decrypt = $c->decrypt($ip);
    $key = 'bans:::' . $ip;


    if (($ban = $mc1->get_value($key)) === false && $ip != '127.0.0.1') {
        if (is_ipv6($ip)) {
            $nip = ip2long6($ip);
        } else {
            $nip = ip2long($ip);
        }
        $ban_sql = sql_query('SELECT comment FROM bans WHERE (first <= ' . $nip . ' AND last >= ' . $nip . ') LIMIT 1');
        if (mysqli_num_rows($ban_sql)) {
            $comment = mysqli_fetch_row($ban_sql);
            $reason = 'Manual Ban (' . $comment[0] . ')';
            $mc1->cache_value($key, $reason, 86400); // 86400 // banned
            return true;
        }
        ((mysqli_free_result($ban_sql) || (is_object($ban_sql) && (get_class($ban_sql) == "mysqli_result"))) ? true : false);
        $mc1->cache_value($key, 0, 86400); // 86400 // not banned
        return false;
    } elseif (!$ban) return false;
    else {
        $reason = $ban;
        return true;
    }
}


That should be basic ban checks it might give you ideas how to change the rest of them.
Feel free to post if you got other ideas.
If wanting support help please put bare min info like
Os:
U-232 Version:
Php Version:
Tracker type: like xbt or php
Saves on asking more questions just so people can help someone.