Here is a better version of this https://torrenttrader.uk/post/1951.
SQL:
In admincp.php, drop this in somewhere
then create a link for it up near the top in the nav section
No extra files needed like the old one. All contained in the admincp.php
SQL:
CREATE TABLE IF NOT EXISTS `notconnectablepmlog` (
`id` int(10) unsigned NOT NULL auto_increment,
`user` int(10) unsigned NOT NULL default '0',
`date` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;In admincp.php, drop this in somewhere
// begin unconnectable peers section
if ($_GET['action'] == "listunconnectable") {
$res2 = SQL_Query_exec("SELECT userid, seeder, torrent, client FROM peers WHERE connectable='no' ORDER BY userid DESC") or sqlerr();
stdhead("Peers that are unconnectable");
begin_frame("Unconnectable");
print("<br/><a href=admincp.php?action=sendpmunconnectable>Send all not connectable users a PM</a>");
print("<br/><a href=admincp.php?action=viewlogsunconnectable>View the Log (Check this before PMing users)</a>");
print("<br/>Peers that are Not Connectable");
print("<br/>This is only users that are active on the torrents right now.");
print("<br/><font color=red>*</font> means the user is seeding.<p>");
$result = SQL_Query_exec("SELECT DISTINCT userid FROM peers WHERE connectable = 'no'");
$count = mysqli_num_rows($result);
print ("$count unique users that are not connectable ");
$result2 = SQL_Query_exec("SELECT DISTINCT torrent FROM peers WHERE connectable = 'no'");
$count2 = mysqli_num_rows($result2);
print ("on $count2 torrents.");
@mysqli_free_result($result);
if (mysqli_num_rows($res2) == 0) {
print("<p align=center><b>All Peers Are Connectable!</b></p>\n");
} else {
// Group torrents per user
$users = [];
while ($row = mysqli_fetch_assoc($res2)) {
$users[$row['userid']][] = $row;
}
print("<table border=1 cellspacing=0 cellpadding=5>");
print("<tr>
<td class=colhead>User</td>
<td class=colhead>Torrents</td>
<td class=colhead>Client(s)</td>
</tr>");
foreach ($users as $userid => $torrents) {
// Fetch username once per user
$u = SQL_Query_exec("SELECT username FROM users WHERE id = $userid");
$user = mysqli_fetch_assoc($u);
print("<tr>");
// Username
print("<td>
<a href='account-details.php?id=$userid'>{$user['username']}</a>
</td>");
// Torrent dropdown
print("<td>");
print("<select onchange=\"if(this.value) window.location=this.value\">");
print("<option value=''>Select torrent…</option>");
foreach ($torrents as $t) {
$label = $t['torrent'];
if ($t['seeder'] === 'yes') {
$label .= " *";
}
print("<option value='torrents-details.php?id={$t['torrent']}&dllist=1#seeders'>
$label
</option>");
}
print("</select>");
print("</td>");
// Client list (unique, clean)
$clients = array_unique(array_column($torrents, 'client'));
print("<td>" . implode("<br>", array_map('htmlspecialchars', $clients)) . "</td>");
print("</tr>");
}
print("</table>");
}
end_frame();
navmenu();
stdfoot();
}
if (isset($_GET["returnto"]) || isset($_SERVER["HTTP_REFERER"])) {
$returnto = isset($_GET["returnto"]) ? $_GET["returnto"] : $_SERVER["HTTP_REFERER"];
$returnto = htmlspecialchars($returnto, ENT_QUOTES, 'UTF-8');
}
?>
<input type="hidden" name="returnto" value="<?php echo $returnto; ?>" />
<?php
if ($_GET['action'] == "sendpmunconnectable") {
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$msg = trim($_POST['msg']);
if ($msg === '') {
show_error_msg("Error", "Please Type In Some Text.", 1);
}
// Send PM to all unconnectable users
$res = SQL_Query_exec("
SELECT DISTINCT userid
FROM peers
WHERE connectable = 'no'
") or sqlerr(__FILE__, __LINE__);
while ($row = mysqli_fetch_assoc($res)) {
SQL_Query_exec("
INSERT INTO messages (sender, receiver, added, msg, subject)
VALUES (
0,
{$row['userid']},
'" . get_date_time() . "',
" . sqlesc($msg) . ",
'Firewall / NAT Connectivity Issue'
)
") or sqlerr(__FILE__, __LINE__);
}
// Log the action
$dt = sqlesc(get_date_time());
SQL_Query_exec("
INSERT INTO notconnectablepmlog (user, date)
VALUES ({$CURUSER['id']}, $dt)
") or sqlerr(__FILE__, __LINE__);
write_log("A PM was sent to unconnectable users by ({$CURUSER['username']})");
// Redirect to log page
header("Location: admincp.php?action=viewlogsunconnectable");
exit;
}
stdhead("Peers that are unconnectable");
begin_frame("Send PM");
// Default message
$body = "The tracker detected that your client is firewalled or behind NAT, so it can’t accept incoming connections. This limits who can connect to you and may reduce speeds.\n\nTo fix this, port forward the same port range set in your torrent client on your router or firewall. Setup varies by router—see PortForward.com for guides.\n\nIf you need help, post in the forums or shoutbox and we’ll help you figure it out.";
?>
<table class="main" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="embedded">
<div align="center">
<h1>Mass Message to All Non-Connectable Users</h1>
<form method="post" action="admincp.php?action=sendpmunconnectable">
<table cellspacing="0" cellpadding="5">
<tr>
<td>
Send Mass Message To All Users Currently Marked As Not Connectable
</td>
</tr>
<tr>
<td>
<textarea name="msg" cols="120" rows="15"><?php echo htmlspecialchars($body); ?></textarea>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Send PM" class="btn">
</td>
</tr>
</table>
</form>
</div>
</td>
</tr>
</table>
<?php
end_frame();
navmenu();
stdfoot();
}
if ($_GET['action'] == "viewlogsunconnectable") {
stdhead("Unconnectable Peers Mass PM Log");
begin_frame("Unconnectable PM Logs");
// Handle clearing logs
if (isset($_GET['clear']) && $_GET['clear'] === 'all') {
SQL_Query_exec("TRUNCATE TABLE notconnectablepmlog") or sqlerr();
write_log("Admin ({$CURUSER['username']}) cleared the Unconnectable PM log");
header("Location: admincp.php?action=viewlogsunconnectable");
exit;
}
if (isset($_GET['clear']) && $_GET['clear'] === 'old') {
SQL_Query_exec("DELETE FROM notconnectablepmlog WHERE date < NOW() - INTERVAL 30 DAY") or sqlerr();
write_log("Admin ({$CURUSER['username']}) pruned the Unconnectable PM log older than 30 days");
header("Location: admincp.php?action=viewlogsunconnectable");
exit;
}
$getlog = SQL_Query_exec("
SELECT user, date
FROM notconnectablepmlog
ORDER BY date DESC
LIMIT 100
");
print("Unconnectable Peers Mass PM Log");
print("<br/><br/><a href='admincp.php?action=sendpmunconnectable'><b>* Send all not connectable users a PM</b></a>");
print("<br/><a href='admincp.php?action=listunconnectable'><b>* List Unconnectable Users</b></a>");
print("<br/><br/>Please don't use the mass PM too often. We don't want to spam the users, just let them know they are unconnectable.<br/>Every week would be ok.<br/><br/>");
print("<a href='admincp.php?action=viewlogsunconnectable&clear=all' onclick='return confirm(\"Are you sure you want to clear ALL logs?\")'>Clear All Logs</a> | ");
print("<a href='admincp.php?action=viewlogsunconnectable&clear=old' onclick='return confirm(\"Delete logs older than 30 days?\")'>Prune Old Logs</a><br><br>");
// Group logs by admin
$admins = [];
while ($row = mysqli_fetch_assoc($getlog)) {
$admins[$row['user']][] = $row['date'];
}
print("<table border=1 cellspacing=0 cellpadding=5>");
print("<tr><td class=colhead>Admin</td><td class=colhead>PM Sends</td></tr>");
foreach ($admins as $userid => $dates) {
$r2 = SQL_Query_exec("SELECT username FROM users WHERE id=$userid") or sqlerr();
$a2 = mysqli_fetch_assoc($r2);
print("<tr>");
print("<td><a href='account-details.php?id=$userid'>{$a2['username']}</a></td>");
print("<td>");
print("<select onchange='if(this.value) window.location=this.value'>");
print("<option value=''>Show PM sent…</option>");
foreach ($dates as $date) {
// Get users who received the PM on this date
$users_sent_res = SQL_Query_exec("
SELECT receiver
FROM messages
WHERE sender = 0
AND msg LIKE '%firewalled or behind NAT%'
AND added = '" . $date . "'
");
$usernames = [];
while ($u = mysqli_fetch_assoc($users_sent_res)) {
$r3 = SQL_Query_exec("SELECT username FROM users WHERE id={$u['receiver']}") or sqlerr();
$a3 = mysqli_fetch_assoc($r3);
$usernames[] = $a3['username'];
}
// Truncate long user lists
$total = count($usernames);
if ($total > 5) {
$display_users = implode(", ", array_slice($usernames, 0, 5)) . " …and " . ($total - 5) . " more";
} else {
$display_users = implode(", ", $usernames);
}
$elapsed = get_elapsed_time(sql_timestamp_to_unix_timestamp($date));
print("<option value='#'>{$date} ({$elapsed} ago) – Users: {$display_users}</option>");
}
print("</select>");
print("</td>");
print("</tr>");
}
print("</table>");
end_frame();
navmenu();
stdfoot();
}
// end unconnectable peers sectionthen create a link for it up near the top in the nav section
<td align="center"><a href="admincp.php?action=viewlogsunconnectable"><img src="images/admin/connectable.png" border="0" width="118" height="80" alt="" /><br /><?php echo T_("NOT_CONNECT"); ?><br /></a></td>No extra files needed like the old one. All contained in the admincp.php
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)