renderIcon($e['ipv4'], $e['userid']); $address[] = $loc_pub . $seedBoxIcon; $ips[] = $e['ipv4']; } if (!empty($e['ipv6'])) { list($loc_pub, $loc_mod) = get_ip_location($e['ipv6']); $seedBoxIcon = $seedBoxRep->renderIcon($e['ipv6'], $e['userid']); $address[] = $loc_pub . $seedBoxIcon; $ips[] = $e['ipv6']; } if ($canView) { $title = sprintf('%s%s%s', $lang_functions['text_user_ip'], ': ', implode(', ', $ips)); } else { $title = ''; } $addressStr = implode('
', $address); $location = '
'.$addressStr.'
'; } else { if (!empty($e['ipv4'])) { $ips[] = $e['ipv4'] . $seedBoxRep->renderIcon($e['ipv4'], $e['userid']); } if (!empty($e['ipv6'])) { $ips[] = $e['ipv6'] . $seedBoxRep->renderIcon($e['ipv6'], $e['userid']); } $location = '
'.implode('
', $ips).'
'; } if ($isStrongPrivacy) { $result = '
'.$lang_viewpeerlist['text_anonymous'].'
'; if ($canView) { $result = $location . $result; } } else { $result = $location; } return "
" . $result . "
\n"; } function get_username_seed_box_icon($e): string { global $seedBoxRep; foreach (array_filter([$e['ipv4'], $e['ipv6']]) as $ip) { $icon = $seedBoxRep->renderIcon($ip, $e['userid']); if (!empty($icon)) { return $icon; } } return ''; } if(isset($CURUSER)) { function dltable($name, $arr, $torrent) { global $lang_viewpeerlist,$viewanonymous_class,$userprofile_class,$enablelocation_tweak; global $CURUSER; global $lang_functions, $seedBoxRep; $s = "" . count($arr) . " $name\n"; $showLocationColumn = $enablelocation_tweak == 'yes' || user_can('userprofile'); if (!count($arr)) return $s; $s .= "\n"; $s .= "\n"; $s .= "" . ($showLocationColumn ? "" : ""). "". "". "" . "" . "" . "" . "" . "" . "" . "\n"; $now = time(); $num = 0; $privacyData = \App\Models\User::query()->whereIn('id', array_column($arr, 'userid'))->get(['id', 'privacy'])->keyBy('id'); foreach ($arr as $e) { $privacy = $privacyData->get($e['userid'])->privacy ?? ''; ++$num; $highlight = $CURUSER["id"] == $e['userid'] ? " bgcolor=#BBAF9B" : ""; $s .= "\n"; $secs = max(1, ($e["la"] - $e["st"])); $columnLocation = $usernameSeedBoxIcon = ''; $isStrongPrivacy = $privacy == "strong" || ($torrent['anonymous'] == 'yes' && $e['userid'] == $torrent['owner']); $canView = user_can('viewanonymous') || $e['userid'] == $CURUSER['id']; if ($showLocationColumn) { $columnLocation = get_location_column($e, $isStrongPrivacy, $canView); } else { $usernameSeedBoxIcon = get_username_seed_box_icon($e); } if ($isStrongPrivacy) { $columnUsername = ""; } else { $columnUsername = ""; } $s .= $columnUsername . $columnLocation; $s .= "\n"; $s .= "\n"; $s .= "\n"; $s .= "\n"; if ($e["seeder"] == "no") $s .= "\n"; else $s .= "\n"; if ($e["downloaded"]) { $ratio = floor(($e["uploaded"] / $e["downloaded"]) * 1000) / 1000; $s .= "\n"; } elseif ($e["uploaded"]) $s .= "\n"; else $s .= "\n"; $s .= "\n"; $s .= "\n"; $s .= "\n"; $s .= "\n"; $s .= "\n"; } $s .= "
".$lang_viewpeerlist['col_user_ip']."".$lang_viewpeerlist['col_location']."".$lang_viewpeerlist['col_connectable']."".$lang_viewpeerlist['col_uploaded']."".$lang_viewpeerlist['col_rate']."".$lang_viewpeerlist['col_downloaded']."".$lang_viewpeerlist['col_rate']."".$lang_viewpeerlist['col_ratio']."".$lang_viewpeerlist['col_complete']."".$lang_viewpeerlist['col_connected']."".$lang_viewpeerlist['col_idle']."".$lang_viewpeerlist['col_client']."
".$lang_viewpeerlist['text_anonymous']."".$usernameSeedBoxIcon; if ($canView) { $columnUsername .= "
(" . get_username($e['userid']) . ")"; } $columnUsername .= "
" . get_username($e['userid']).$usernameSeedBoxIcon."" . ($e['connectable'] == "yes" ? $lang_viewpeerlist['text_yes'] : "".$lang_viewpeerlist['text_no']."") . "" . mksize($e["uploaded"]) . "" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s" . mksize($e["downloaded"]) . "" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e['st'])) . "/s" . number_format($ratio, 3) . "".$lang_viewpeerlist['text_inf']."---" . sprintf("%.2f%%", 100 * (1 - ($e["to_go"] / $torrent["size"]))) . "" . mkprettytime($now - $e["st"]) . "" . mkprettytime($now - $e["la"]) . "" . htmlspecialchars(get_agent($e["peer_id"],$e["agent"])) . "
\n"; return $s; } $downloaders = array(); $seeders = array(); $torrent = \App\Models\Torrent::query()->findOrFail($id, ['id', 'seeders', 'leechers']); $subres = sql_query("SELECT seeder, finishedat, downloadoffset, uploadoffset, ip, ipv4, ipv6, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr(); while ($subrow = mysql_fetch_array($subres)) { if ($subrow["seeder"] == "yes") $seeders[] = $subrow; else $downloaders[] = $subrow; } $seedersCount = count($seeders); $leechersCount = count($downloaders); if ($torrent->seeders != $seedersCount || $torrent->leechers != $leechersCount) { $update = [ 'seeders' => $seedersCount, 'leechers' => $leechersCount, ]; $torrent->update($update); do_log("[UPDATE_TORRENT_SEEDERS_LEECHERS], torrent: $id, original: " . $torrent->toJson() . ", update: " . json_encode($update)); } function leech_sort($a,$b) { $x = $a["to_go"]; $y = $b["to_go"]; if ($x == $y) return 0; if ($x < $y) return -1; return 1; } function seed_sort($a,$b) { $x = $a["uploaded"]; $y = $b["uploaded"]; if ($x == $y) return 0; if ($x < $y) return 1; return -1; } $res = sql_query("SELECT torrents.id, torrents.owner, torrents.size, torrents.anonymous FROM torrents WHERE torrents.id = $id LIMIT 1") or sqlerr(); $row = mysql_fetch_array($res); usort($seeders, "seed_sort"); usort($downloaders, "leech_sort"); print(dltable($lang_viewpeerlist['text_seeders'], $seeders, $row)); print(dltable($lang_viewpeerlist['text_leechers'], $downloaders, $row)); } ?>