cron.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. ignore_user_abort(true);
  3. set_time_limit(120);
  4. $toots = [];
  5. $mastodon_servers = ['your.server.fqdn' => 'https://your.server.fqdn/write_this_block_yourself', 'yours2.fqdn' => 'https://...'];
  6. shuffle_assoc($mastodon_servers);
  7. $date_ym = gmdate('Ym');
  8. $sqlme = @new mysqli('localhost', 'sseeccrreett', 'sseeccrreett', 'sseeccrreett');
  9. if ($sqlme->connect_errno)
  10. {
  11. exit;
  12. }
  13. foreach ($mastodon_servers as $svF => $svU)
  14. {
  15. $got = @json_decode(wget($svU) , true);
  16. if (!is_array($got) || count($got) < 10 || !isset($got[0]))
  17. {
  18. continue;
  19. }
  20. foreach ($got as $g)
  21. {
  22. if (!isset($g['url']) || !preg_match("/write_this_block_yourself/", $g['url']))
  23. {
  24. continue;
  25. }
  26. if (!isset($g['content']) || strlen($g['content']) < 8)
  27. {
  28. continue;
  29. }
  30. if (!isset($g['account']) || !isset($g['account']['acct']) || !preg_match("/write_this_block_yourself/", $g['account']['acct']))
  31. {
  32. continue;
  33. }
  34. if (strpos($g['account']['acct'], '@') === false)
  35. {
  36. $g['account']['acct'] = $g['account']['acct'] . '@' . $svF;
  37. }
  38. $txt = array_unique(array_filter(array_map(function ($l)
  39. {
  40. $isURL = (preg_match("/write_this_block_yourself/", $l) && !preg_match("/write_this_block_yourself/", $l)) ? true : false;
  41. return $isURL ? explode('/', explode('://', $l, 2) [1], 2) [0] : '';
  42. }
  43. , explode('"', strip_tags($g['content'], '<a>')))));
  44. if (count($txt) == 0)
  45. {
  46. continue;
  47. }
  48. $cfFound = 0;
  49. foreach ($txt as $fqdn)
  50. {
  51. $tmp_id2 = sha1($g['url'] . ';' . $fqdn);
  52. $junk = $sqlme->query("INSERT IGNORE INTO toot_sharefqdn (id,fqdn,ym) VALUES ('{$tmp_id2}','{$fqdn}','{$date_ym}');");
  53. if (is_known_cf(get_domainname($fqdn) [1]))
  54. {
  55. $cfFound = 1;
  56. }
  57. else
  58. {
  59. $junk = $sqlme->query("INSERT IGNORE INTO toot_notcf_fqdn (fqdn,dl) VALUES ('{$fqdn}','0');");
  60. }
  61. }
  62. $toots[sha1($g['url']) ] = [$g['account']['acct'], $g['url'], $cfFound];
  63. }
  64. }
  65. foreach ($toots as $k => $v)
  66. {
  67. $junk = $sqlme->query("INSERT IGNORE INTO toot_scanned (id,who,iscf,ym) VALUES ('{$k}','{$v[0]}','{$v[2]}','{$date_ym}');");
  68. if ($v[2] == 1)
  69. {
  70. $junk = $sqlme->query("INSERT IGNORE INTO toot_cfsaid (id,who,url,ym) VALUES ('{$k}','{$v[0]}','{$v[1]}','{$date_ym}');");
  71. }
  72. }
  73. if (gmdate('G') == 0)
  74. {
  75. $date_ym = gmdate('Ym', strtotime('7 months ago'));
  76. $junk = $sqlme->query("DELETE FROM toot_scanned WHERE ym = '{$date_ym}';");
  77. $junk = $sqlme->query("DELETE FROM toot_cfsaid WHERE ym = '{$date_ym}';");
  78. $junk = $sqlme->query("DELETE FROM toot_sharefqdn WHERE ym = '{$date_ym}';");
  79. }
  80. file_put_contents('/onion/sseeccrreett/data/mastodon.toot.scan', '');