diff --git a/tool/mastodonwch/index.php b/tool/mastodonwch/index.php index 4d57320d..39503053 100644 --- a/tool/mastodonwch/index.php +++ b/tool/mastodonwch/index.php @@ -1,80 +1,136 @@ 'https://your.server.fqdn/write_this_block_yourself', 'yours2.fqdn' => 'https://...']; -shuffle_assoc($mastodon_servers); -$date_ym = gmdate('Ym'); $sqlme = @new mysqli('localhost', 'sseeccrreett', 'sseeccrreett', 'sseeccrreett'); if ($sqlme->connect_errno) { exit; } -foreach ($mastodon_servers as $svF => $svU) +$count_all = - 1; +if ($r = $sqlme->query("SELECT count(id) FROM toot_scanned;")) { - $got = @json_decode(wget($svU) , true); - if (!is_array($got) || count($got) < 10 || !isset($got[0])) - { - continue; - } - foreach ($got as $g) - { - if (!isset($g['url']) || !preg_match("/write_this_block_yourself/", $g['url'])) - { - continue; - } - if (!isset($g['content']) || strlen($g['content']) < 8) - { - continue; - } - if (!isset($g['account']) || !isset($g['account']['acct']) || !preg_match("/write_this_block_yourself/", $g['account']['acct'])) - { - continue; - } - if (strpos($g['account']['acct'], '@') === false) - { - $g['account']['acct'] = $g['account']['acct'] . '@' . $svF; - } - $txt = array_unique(array_filter(array_map(function ($l) - { - $isURL = (preg_match("/write_this_block_yourself/", $l) && !preg_match("/write_this_block_yourself/", $l)) ? true : false; - return $isURL ? explode('/', explode('://', $l, 2) [1], 2) [0] : ''; - } - , explode('"', strip_tags($g['content'], ''))))); - if (count($txt) == 0) - { - continue; - } - $cfFound = 0; - foreach ($txt as $fqdn) - { - $tmp_id2 = sha1($g['url'] . ';' . $fqdn); - $junk = $sqlme->query("INSERT IGNORE INTO toot_sharefqdn (id,fqdn,ym) VALUES ('{$tmp_id2}','{$fqdn}','{$date_ym}');"); - if (is_known_cf(get_domainname($fqdn) [1])) - { - $cfFound = 1; - } - else - { - $junk = $sqlme->query("INSERT IGNORE INTO toot_notcf_fqdn (fqdn,dl) VALUES ('{$fqdn}','0');"); - } - } - $toots[sha1($g['url']) ] = [$g['account']['acct'], $g['url'], $cfFound]; - } + $rr = mysqli_fetch_assoc($r); + $r->free(); + $count_all = $rr['count(id)']; } -foreach ($toots as $k => $v) +$count_cf = - 1; +if ($r = $sqlme->query("SELECT count(id) FROM toot_scanned WHERE iscf=1;")) { - $junk = $sqlme->query("INSERT IGNORE INTO toot_scanned (id,who,iscf,ym) VALUES ('{$k}','{$v[0]}','{$v[2]}','{$date_ym}');"); - if ($v[2] == 1) - { - $junk = $sqlme->query("INSERT IGNORE INTO toot_cfsaid (id,who,url,ym) VALUES ('{$k}','{$v[0]}','{$v[1]}','{$date_ym}');"); - } + $rr = mysqli_fetch_assoc($r); + $r->free(); + $count_cf = $rr['count(id)']; } -if (gmdate('G') == 0) +if ($count_all == - 1 || $count_cf == - 1) { - $date_ym = gmdate('Ym', strtotime('7 months ago')); - $junk = $sqlme->query("DELETE FROM toot_scanned WHERE ym = '{$date_ym}';"); - $junk = $sqlme->query("DELETE FROM toot_cfsaid WHERE ym = '{$date_ym}';"); - $junk = $sqlme->query("DELETE FROM toot_sharefqdn WHERE ym = '{$date_ym}';"); + exit; } -file_put_contents('/onion/sseeccrreett/data/mastodon.toot.scan', ''); \ No newline at end of file +$count_acpct = round(($count_cf * 100) / $count_all, 2); +$count_all = number_format($count_all); +$count_cf = number_format($count_cf); +$count_waitask = - 1; +if ($r = $sqlme->query("SELECT count(fqdn) FROM toot_notcf_fqdn WHERE dl=0;")) +{ + $rr = mysqli_fetch_assoc($r); + $r->free(); + $count_waitask = $rr['count(fqdn)']; +} +$count_waitask = number_format($count_waitask); +$lastuptime = humanTiming(filemtime('/onion/sseeccrreett/data/mastodon.toot.scan')); +$var_who = htmlspecialchars($_GET['who'], ENT_QUOTES); +$resultHTML = ''; +if (write_this_block_yourself) +{ + $var_who = ''; +} +if (preg_match("/write_this_block_yourself/", $var_who)) +{ + $resultHTML .= '
'; + $person_a = 0; + if ($r = $sqlme->query("SELECT count(id) FROM toot_scanned WHERE who='{$var_who}';")) + { + $rr = mysqli_fetch_assoc($r); + $r->free(); + $person_a = $rr['count(id)']; + } + $person_b = 0; + if ($r = $sqlme->query("SELECT count(id) FROM toot_scanned WHERE who='{$var_who}' AND iscf=1;")) + { + $rr = mysqli_fetch_assoc($r); + $r->free(); + $person_b = $rr['count(id)']; + } + $person_c = round(($person_b * 100) / $person_a, 2); + if (is_nan($person_c)) + { + $person_c = 0; + } + $person_a = number_format($person_a); + $person_b = number_format($person_b); + $resultHTML .= ""; + $resultHTML .= ""; + $resultHTML .= ""; + $resultHTML .= ""; + if ($r = $sqlme->query("SELECT url FROM toot_cfsaid WHERE who='{$var_who}' LIMIT 100;")) + { + while ($row = mysqli_fetch_assoc($r)) + { + $vurl = htmlspecialchars($row['url'], ENT_QUOTES); + $resultHTML .= ""; + } + } + $resultHTML .= '
About{$var_who}
Toots has links{$person_a}
⮡ Toots has Cloudflare link{$person_b} [{$person_c}%]
Detected (LIMIT 100)
{$vurl}
'; +} +elseif ($var_who == 'a') +{ + $resultHTML .= '
'; + if ($r = $sqlme->query("SELECT who,count(*) as count FROM toot_scanned GROUP BY who ORDER BY count DESC LIMIT 100;")) + { + while ($row = mysqli_fetch_assoc($r)) + { + $rcount = number_format($row['count']); + $resultHTML .= ""; + } + } + $resultHTML .= '
Shared any linksToots
{$row['who']}{$rcount}
'; +} +elseif ($var_who == 'c') +{ + $resultHTML .= '
'; + if ($r = $sqlme->query("SELECT who,count(*) as count FROM toot_scanned WHERE iscf=1 GROUP BY who ORDER BY count DESC LIMIT 100;")) + { + while ($row = mysqli_fetch_assoc($r)) + { + $rcount = number_format($row['count']); + $resultHTML .= ""; + } + } + $resultHTML .= '
Shared Cloudflare linksToots
{$row['who']}{$rcount}
'; +} +elseif ($var_who == 'f') +{ + $resultHTML .= '
'; + if ($r = $sqlme->query("SELECT fqdn,count(*) as count FROM toot_sharefqdn GROUP BY fqdn ORDER BY count DESC LIMIT 50;")) + { + while ($row = mysqli_fetch_assoc($r)) + { + $rcount = number_format($row['count']); + $riscf = is_known_cf(get_domainname($row['fqdn']) [1]) ? 'Yes' : 'No'; + $resultHTML .= ""; + } + } + $resultHTML .= '
Shared FQDNCloudflareFound in Toots
{$row['fqdn']}{$riscf}{$rcount}
'; +} +else +{ + $resultHTML .= '
'; +} +$finalpage = <<Shared on Mastodon

+[ INDEX ] Update {$lastuptime} ago
+Toots has links: {$count_all}
+⮡ Toots has Cloudflare link: {$count_cf} [{$count_acpct}%]
+Pending Investigation: {$count_waitask}
+
{$resultHTML}
+HTMLRESULT; +echo (str_replace("\n", '', $finalpage)); \ No newline at end of file