Skip to content

Commit

Permalink
fix(tracker): 有关tracker获取IPv6地址的小修正
Browse files Browse the repository at this point in the history
1. 增强IPv6判断,修改IPv6地址获取顺序,以解决汇报本地地址的问题;
2. 为校内用户移除teredo隧道,避免因其偷跑流量(然而我感觉还是会跑,能避免一点是一点吧)
  • Loading branch information
tongyifan committed Aug 8, 2019
1 parent d2245e1 commit bc26c1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
$query_ip['ip'] = $_GET ['ip'] ?? "";

// handle IPv6 address
// `ipv6` param in query, then `ip` param, then remote ip
if (validateIPv6($query_ip['ipv6'])) {
// client may send local ipv6 address to server, so we use `remote addr` first, then query param
if (validateIPv6($ip)) {
$ipv6 = $ip;
} else if (validateIPv6($query_ip['ipv6'])) {
$ipv6 = $query_ip['ipv6'];
} else if (validateIPv6($query_ip['ip'])) {
$ipv6 = $query_ip['ip'];
} else if (validateIPv6($ip)) {
$ipv6 = $ip;
}

// IPv4 same with IPv6
Expand All @@ -77,10 +77,12 @@
$res = sql_query("SELECT * FROM bans WHERE $nip >= first AND $nip <= last") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) > 0) err("403-该IP被封禁,请与{$REPORTMAIL}联系!");

// warn the user who enables `public4` in campus
// warn the user who enables `public4` in campus
if (check_tjuip($nip) && $az['enablepublic4'] == 'yes' && $az['showtjuipnotice'] == 'no')
sql_query("UPDATE users SET showtjuipnotice = 'yes' WHERE id = " . sqlesc($az['id']));

// drop teredo IPv6 address for campus users
if (check_tjuip($nip) && substr($ipv6, 0, 7) == '2001:0:') unset ($ipv6);
}

// check banned IPv6 address
Expand Down Expand Up @@ -265,8 +267,8 @@
$ipv4 = $self ['ipv4'];

// min announce time
if (isset ( $self ) && $self ['prevts'] > (TIMENOW - $announce_wait) && $event != "stopped" && $event != "completed")
err ( '008-您的刷新过于频繁,请等候 ' . $announce_wait . ' 秒再尝试' );
if (isset ($self) && $self ['prevts'] > (TIMENOW - $announce_wait) && $event != "stopped" && $event != "completed")
err('008-您的刷新过于频繁,请等候 ' . $announce_wait . ' 秒再尝试');

// current peer_id, or you could say session with tracker not found in table `peers`
if (!isset ($self)) {
Expand Down
2 changes: 1 addition & 1 deletion include/globalfunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getip()

function validateIPv6($IP)
{
return filter_var($IP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
return filter_var($IP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
}

function validateIPv4($IP)
Expand Down

0 comments on commit bc26c1d

Please sign in to comment.